Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: chromecast/public/media/decoder_config.h

Issue 1490613005: media config: expand is_encrypted to a struct. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: one more tweak in chromecast/common Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROMECAST_PUBLIC_MEDIA_DECODER_CONFIG_H_ 5 #ifndef CHROMECAST_PUBLIC_MEDIA_DECODER_CONFIG_H_
6 #define CHROMECAST_PUBLIC_MEDIA_DECODER_CONFIG_H_ 6 #define CHROMECAST_PUBLIC_MEDIA_DECODER_CONFIG_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 kH264ScalableHigh, 80 kH264ScalableHigh,
81 kH264Stereohigh, 81 kH264Stereohigh,
82 kH264MultiviewHigh, 82 kH264MultiviewHigh,
83 kVP8ProfileAny, 83 kVP8ProfileAny,
84 kVP9ProfileAny, 84 kVP9ProfileAny,
85 85
86 kVideoProfileMin = kVideoProfileUnknown, 86 kVideoProfileMin = kVideoProfileUnknown,
87 kVideoProfileMax = kVP9ProfileAny, 87 kVideoProfileMax = kVP9ProfileAny,
88 }; 88 };
89 89
90 // TODO(erickung): Remove constructor once CMA backend implementation does't 90 // Specification of whether and how the stream is encrypted (in whole or part).
91 struct EncryptionScheme {
92 // Algorithm and mode that was used to encrypt the stream.
93 enum CipherMode {
94 kCipherModeNone,
95 kCipherModeAesCtr,
96 kCipherModeAesCbc
97 };
98
99 // V3 of the CENC standard will add pattern encryption, through two new
100 // protection schemes 'cens' (with AES-CTR) and 'cbcs' (with AES-CBC).
101 // The pattern applies only to the 'encrypted' part of the frame (as
102 // defined by the relevant subsample entries), and reduces further the
103 // actual encryption applied through a repeating pattern of (encrypt:skip)
104 // 16 byte blocks. For example, in a (1:9) pattern, the first block is
105 // encrypted, and the next nine are skipped. This pattern is applied
106 // repeatedly until the end of the last 16-byte block in the subsample.
107 // Any remaining bytes are left clear.
108 // If either or both of encrypt_blocks or skip_blocks is 0, pattern
109 // encryption is disabled.
110 struct PatternSpec {
111 PatternSpec();
112 PatternSpec(uint32_t encrypt_blocks, uint32_t skip_blocks);
113 ~PatternSpec() {}
114 uint32_t encrypt_blocks;
115 uint32_t skip_blocks;
116 };
117
118 EncryptionScheme();
119 explicit EncryptionScheme(bool is_encrypted);
halliwell 2016/01/13 03:29:41 same comment as ::media::EncryptionScheme construc
dougsteed 2016/02/09 22:58:54 Done.
120 explicit EncryptionScheme(CipherMode mode);
121 EncryptionScheme(CipherMode mode, const PatternSpec& pattern);
122 ~EncryptionScheme() {}
123
124 CipherMode mode;
125 PatternSpec pattern;
126 };
127
128 inline EncryptionScheme::PatternSpec::PatternSpec()
129 : encrypt_blocks(0), skip_blocks(0) {
130 }
131
132 inline EncryptionScheme::PatternSpec::PatternSpec(uint32_t encrypt_blocks,
133 uint32_t skip_blocks)
134 : encrypt_blocks(encrypt_blocks), skip_blocks(skip_blocks) {
135 }
136
137 inline EncryptionScheme::EncryptionScheme()
138 : mode(kCipherModeNone), pattern() {
139 }
140
141 inline EncryptionScheme::EncryptionScheme(bool is_encrypted)
142 : mode(is_encrypted ? kCipherModeAesCtr : kCipherModeNone),
halliwell 2016/01/13 03:29:41 Don't like 'true' being implicitly AesCtr. Can we
dougsteed 2016/02/09 22:58:54 Done.
143 pattern() {
144 }
145
146 inline EncryptionScheme::EncryptionScheme(CipherMode mode)
147 : mode(mode), pattern() {
148 }
149
150 inline EncryptionScheme::EncryptionScheme(CipherMode mode,
151 const PatternSpec& pattern)
152 : mode(mode), pattern(pattern) {
153 }
154
155 // TODO(erickung): Remove constructor once CMA backend implementation doesn't
91 // create a new object to reset the configuration and use IsValidConfig() to 156 // create a new object to reset the configuration and use IsValidConfig() to
92 // determine if the configuration is still valid or not. 157 // determine if the configuration is still valid or not.
93 struct AudioConfig { 158 struct AudioConfig {
94 AudioConfig(); 159 AudioConfig();
95 ~AudioConfig(); 160 ~AudioConfig();
96 161
162 bool is_encrypted() const;
163
97 // Stream id. 164 // Stream id.
98 StreamId id; 165 StreamId id;
99 // Audio codec. 166 // Audio codec.
100 AudioCodec codec; 167 AudioCodec codec;
101 // The format of each audio sample. 168 // The format of each audio sample.
102 SampleFormat sample_format; 169 SampleFormat sample_format;
103 // Number of bytes in each channel. 170 // Number of bytes in each channel.
104 int bytes_per_channel; 171 int bytes_per_channel;
105 // Number of channels in this audio stream. 172 // Number of channels in this audio stream.
106 int channel_number; 173 int channel_number;
107 // Number of audio samples per second. 174 // Number of audio samples per second.
108 int samples_per_second; 175 int samples_per_second;
109 // Extra data buffer for certain codec initialization. 176 // Extra data buffer for certain codec initialization.
110 std::vector<uint8_t> extra_data; 177 std::vector<uint8_t> extra_data;
111 // content is encrypted or not. 178 // Encryption scheme (if any) used for the content.
112 bool is_encrypted; 179 EncryptionScheme encryption_scheme;
113 }; 180 };
114 181
115 inline AudioConfig::AudioConfig() 182 inline AudioConfig::AudioConfig()
116 : id(kPrimary), 183 : id(kPrimary),
117 codec(kAudioCodecUnknown), 184 codec(kAudioCodecUnknown),
118 sample_format(kUnknownSampleFormat), 185 sample_format(kUnknownSampleFormat),
119 bytes_per_channel(0), 186 bytes_per_channel(0),
120 channel_number(0), 187 channel_number(0),
121 samples_per_second(0), 188 samples_per_second(0),
122 is_encrypted(false) { 189 encryption_scheme(false) {
halliwell 2016/01/13 03:29:41 default initialisation of encryption_scheme should
dougsteed 2016/02/09 22:58:54 Done.
123 } 190 }
124 191
125 inline AudioConfig::~AudioConfig() { 192 inline AudioConfig::~AudioConfig() {
126 } 193 }
127 194
195 // Normally a struct would not have a simple function member like this. However,
196 // the member |encryption_scheme| replaced a simple boolean, and a lot of code
197 // sites are only interested in whether encryption has been applied or not.
halliwell 2016/01/13 03:29:41 let's just delete this comment, doesn't add any va
dougsteed 2016/02/09 22:58:54 Done.
198 inline bool AudioConfig::is_encrypted() const {
199 return encryption_scheme.mode != EncryptionScheme::kCipherModeNone;
200 }
201
128 // TODO(erickung): Remove constructor once CMA backend implementation does't 202 // TODO(erickung): Remove constructor once CMA backend implementation does't
129 // create a new object to reset the configuration and use IsValidConfig() to 203 // create a new object to reset the configuration and use IsValidConfig() to
130 // determine if the configuration is still valid or not. 204 // determine if the configuration is still valid or not.
131 struct VideoConfig { 205 struct VideoConfig {
132 VideoConfig(); 206 VideoConfig();
133 ~VideoConfig(); 207 ~VideoConfig();
134 208
209 bool is_encrypted() const;
210
135 // Stream Id. 211 // Stream Id.
136 StreamId id; 212 StreamId id;
137 // Video codec. 213 // Video codec.
138 VideoCodec codec; 214 VideoCodec codec;
139 // Video codec profile. 215 // Video codec profile.
140 VideoProfile profile; 216 VideoProfile profile;
141 // Additional video config for the video stream if available. Consumers of 217 // Additional video config for the video stream if available. Consumers of
142 // this structure should make an explicit copy of |additional_config| if it 218 // this structure should make an explicit copy of |additional_config| if it
143 // will be used after SetConfig() finishes. 219 // will be used after SetConfig() finishes.
144 VideoConfig* additional_config; 220 VideoConfig* additional_config;
145 // Extra data buffer for certain codec initialization. 221 // Extra data buffer for certain codec initialization.
146 std::vector<uint8_t> extra_data; 222 std::vector<uint8_t> extra_data;
147 // content is encrypted or not. 223 // Encryption scheme (if any) used for the content.
148 bool is_encrypted; 224 EncryptionScheme encryption_scheme;
149 }; 225 };
150 226
151 inline VideoConfig::VideoConfig() 227 inline VideoConfig::VideoConfig()
152 : id(kPrimary), 228 : id(kPrimary),
153 codec(kVideoCodecUnknown), 229 codec(kVideoCodecUnknown),
154 profile(kVideoProfileUnknown), 230 profile(kVideoProfileUnknown),
155 additional_config(nullptr), 231 additional_config(nullptr),
156 is_encrypted(false) { 232 encryption_scheme(false) {
157 } 233 }
158 234
159 inline VideoConfig::~VideoConfig() { 235 inline VideoConfig::~VideoConfig() {
160 } 236 }
161 237
238 // See comment above for AudioConfig::is_encrypted().
halliwell 2016/01/13 03:29:41 delete
dougsteed 2016/02/09 22:58:53 Done.
239 inline bool VideoConfig::is_encrypted() const {
240 return encryption_scheme.mode != EncryptionScheme::kCipherModeNone;
241 }
242
243
162 // TODO(erickung): Remove following two inline IsValidConfig() functions. These 244 // TODO(erickung): Remove following two inline IsValidConfig() functions. These
163 // are to keep existing CMA backend implementation consistent until the clean up 245 // are to keep existing CMA backend implementation consistent until the clean up
164 // is done. These SHOULD NOT be used in New CMA backend implementation. 246 // is done. These SHOULD NOT be used in New CMA backend implementation.
165 inline bool IsValidConfig(const AudioConfig& config) { 247 inline bool IsValidConfig(const AudioConfig& config) {
166 return config.codec >= kAudioCodecMin && 248 return config.codec >= kAudioCodecMin &&
167 config.codec <= kAudioCodecMax && 249 config.codec <= kAudioCodecMax &&
168 config.codec != kAudioCodecUnknown && 250 config.codec != kAudioCodecUnknown &&
169 config.sample_format >= kSampleFormatMin && 251 config.sample_format >= kSampleFormatMin &&
170 config.sample_format <= kSampleFormatMax && 252 config.sample_format <= kSampleFormatMax &&
171 config.sample_format != kUnknownSampleFormat && 253 config.sample_format != kUnknownSampleFormat &&
172 config.channel_number > 0 && 254 config.channel_number > 0 &&
173 config.bytes_per_channel > 0 && 255 config.bytes_per_channel > 0 &&
174 config.bytes_per_channel <= kMaxBytesPerSample && 256 config.bytes_per_channel <= kMaxBytesPerSample &&
175 config.samples_per_second > 0 && 257 config.samples_per_second > 0 &&
176 config.samples_per_second <= kMaxSampleRate; 258 config.samples_per_second <= kMaxSampleRate;
177 } 259 }
178 260
179 inline bool IsValidConfig(const VideoConfig& config) { 261 inline bool IsValidConfig(const VideoConfig& config) {
180 return config.codec >= kVideoCodecMin && 262 return config.codec >= kVideoCodecMin &&
181 config.codec <= kVideoCodecMax && 263 config.codec <= kVideoCodecMax &&
182 config.codec != kVideoCodecUnknown; 264 config.codec != kVideoCodecUnknown;
183 } 265 }
184 266
185 } // namespace media 267 } // namespace media
186 } // namespace chromecast 268 } // namespace chromecast
187 269
188 #endif // CHROMECAST_PUBLIC_MEDIA_DECODER_CONFIG_H_ 270 #endif // CHROMECAST_PUBLIC_MEDIA_DECODER_CONFIG_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698