Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chromecast / public / media / decoder_config.h
blob7652c3c3069b528c35e212ea05354323a4eac465
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROMECAST_PUBLIC_MEDIA_DECODER_CONFIG_H_
6 #define CHROMECAST_PUBLIC_MEDIA_DECODER_CONFIG_H_
8 #include <stdint.h>
9 #include <vector>
11 #include "stream_id.h"
13 namespace chromecast {
14 namespace media {
16 // Maximum audio bytes per sample.
17 static const int kMaxBytesPerSample = 4;
19 // Maximum audio sampling rate.
20 static const int kMaxSampleRate = 192000;
22 enum AudioCodec {
23 kAudioCodecUnknown = 0,
24 kCodecAAC,
25 kCodecMP3,
26 kCodecPCM,
27 kCodecPCM_S16BE,
28 kCodecVorbis,
29 kCodecOpus,
30 kCodecEAC3,
31 kCodecAC3,
32 kCodecDTS,
34 kAudioCodecMin = kAudioCodecUnknown,
35 kAudioCodecMax = kCodecDTS,
38 enum SampleFormat {
39 kUnknownSampleFormat = 0,
40 kSampleFormatU8, // Unsigned 8-bit w/ bias of 128.
41 kSampleFormatS16, // Signed 16-bit.
42 kSampleFormatS32, // Signed 32-bit.
43 kSampleFormatF32, // Float 32-bit.
44 kSampleFormatPlanarS16, // Signed 16-bit planar.
45 kSampleFormatPlanarF32, // Float 32-bit planar.
46 kSampleFormatPlanarS32, // Signed 32-bit planar.
48 kSampleFormatMin = kUnknownSampleFormat,
49 kSampleFormatMax = kSampleFormatPlanarS32,
52 enum VideoCodec {
53 kVideoCodecUnknown = 0,
54 kCodecH264,
55 kCodecVC1,
56 kCodecMPEG2,
57 kCodecMPEG4,
58 kCodecTheora,
59 kCodecVP8,
60 kCodecVP9,
61 kCodecHEVC,
63 kVideoCodecMin = kVideoCodecUnknown,
64 kVideoCodecMax = kCodecHEVC,
67 // Profile for Video codec.
68 enum VideoProfile {
69 kVideoProfileUnknown = 0,
70 kH264Baseline,
71 kH264Main,
72 kH264Extended,
73 kH264High,
74 kH264High10,
75 kH264High422,
76 kH264High444Predictive,
77 kH264ScalableBaseline,
78 kH264ScalableHigh,
79 kH264Stereohigh,
80 kH264MultiviewHigh,
81 kVP8ProfileAny,
82 kVP9ProfileAny,
84 kVideoProfileMin = kVideoProfileUnknown,
85 kVideoProfileMax = kVP9ProfileAny,
88 // TODO(erickung): Remove constructor once CMA backend implementation does't
89 // create a new object to reset the configuration and use IsValidConfig() to
90 // determine if the configuration is still valid or not.
91 struct AudioConfig {
92 AudioConfig()
93 : id(kPrimary),
94 codec(kAudioCodecUnknown),
95 sample_format(kUnknownSampleFormat),
96 bytes_per_channel(0),
97 channel_number(0),
98 samples_per_second(0),
99 extra_data(nullptr),
100 extra_data_size(0),
101 is_encrypted(false) {}
103 // Stream id.
104 StreamId id;
105 // Audio codec.
106 AudioCodec codec;
107 // The format of each audio sample.
108 SampleFormat sample_format;
109 // Number of bytes in each channel.
110 int bytes_per_channel;
111 // Number of channels in this audio stream.
112 int channel_number;
113 // Number of audio samples per second.
114 int samples_per_second;
115 // Pointer to extra data buffer for certain codec initialization. The memory
116 // is allocated outside this structure. Consumers of the structure should make
117 // a copy if it is expected to be used beyond the function ends.
118 const uint8_t* extra_data;
119 // Size of extra data in bytes.
120 int extra_data_size;
121 // content is encrypted or not.
122 bool is_encrypted;
125 // TODO(erickung): Remove constructor once CMA backend implementation does't
126 // create a new object to reset the configuration and use IsValidConfig() to
127 // determine if the configuration is still valid or not.
128 struct VideoConfig {
129 VideoConfig()
130 : id(kPrimary),
131 codec(kVideoCodecUnknown),
132 profile(kVideoProfileUnknown),
133 additional_config(nullptr),
134 extra_data(nullptr),
135 extra_data_size(0),
136 is_encrypted(false) {}
138 // Stream Id.
139 StreamId id;
140 // Video codec.
141 VideoCodec codec;
142 // Video codec profile.
143 VideoProfile profile;
144 // Both |additional_config| and |extra_data| are the pointers to the object
145 // memory that are allocated outside this structure. Consumers of the
146 // structure should make a copy if it is expected to be used beyond the
147 // function ends.
148 // Additional video config for the video stream if available.
149 VideoConfig* additional_config;
150 // Pointer to extra data buffer for certain codec initialization.
151 const uint8_t* extra_data;
152 // Size of extra data in bytes.
153 int extra_data_size;
154 // content is encrypted or not.
155 bool is_encrypted;
158 // TODO(erickung): Remove following two inline IsValidConfig() functions. These
159 // are to keep existing CMA backend implementation consistent until the clean up
160 // is done. These SHOULD NOT be used in New CMA backend implementation.
161 inline bool IsValidConfig(const AudioConfig& config) {
162 return config.codec >= kAudioCodecMin &&
163 config.codec <= kAudioCodecMax &&
164 config.codec != kAudioCodecUnknown &&
165 config.sample_format >= kSampleFormatMin &&
166 config.sample_format <= kSampleFormatMax &&
167 config.sample_format != kUnknownSampleFormat &&
168 config.channel_number > 0 &&
169 config.bytes_per_channel > 0 &&
170 config.bytes_per_channel <= kMaxBytesPerSample &&
171 config.samples_per_second > 0 &&
172 config.samples_per_second <= kMaxSampleRate;
175 inline bool IsValidConfig(const VideoConfig& config) {
176 return config.codec >= kVideoCodecMin &&
177 config.codec <= kVideoCodecMax &&
178 config.codec != kVideoCodecUnknown;
181 } // namespace media
182 } // namespace chromecast
184 #endif // CHROMECAST_PUBLIC_MEDIA_DECODER_CONFIG_H_