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

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: more ddorwin comments Created 4 years, 9 months 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 kVP9ProfileAny, 86 kVP9ProfileAny,
87 kDolbyVisionCompatible_EL_MD, 87 kDolbyVisionCompatible_EL_MD,
88 kDolbyVisionCompatible_BL_EL_MD, 88 kDolbyVisionCompatible_BL_EL_MD,
89 kDolbyVisionNonCompatible_BL_MD, 89 kDolbyVisionNonCompatible_BL_MD,
90 kDolbyVisionNonCompatible_BL_EL_MD, 90 kDolbyVisionNonCompatible_BL_EL_MD,
91 91
92 kVideoProfileMin = kVideoProfileUnknown, 92 kVideoProfileMin = kVideoProfileUnknown,
93 kVideoProfileMax = kDolbyVisionNonCompatible_BL_EL_MD, 93 kVideoProfileMax = kDolbyVisionNonCompatible_BL_EL_MD,
94 }; 94 };
95 95
96 // TODO(erickung): Remove constructor once CMA backend implementation does't 96 // Specification of whether and how the stream is encrypted (in whole or part).
97 struct EncryptionScheme {
xhwang 2016/03/03 22:33:00 Is there any reason you need to duplication this i
halliwell 2016/03/03 22:56:44 Yep, we ship just this directory (chromecast/publi
dougsteed 2016/03/04 19:07:29 Not sure what you mean by "not the same". As far a
xhwang 2016/03/04 20:00:48 Yeah, I was talking about struct/class and unencry
dougsteed 2016/03/07 17:49:13 I eliminated the unencrypted/Unencrypted distincti
98 // Algorithm and mode that was used to encrypt the stream.
99 enum CipherMode {
100 kCipherModeUnencrypted,
101 kCipherModeAesCtr,
102 kCipherModeAesCbc
103 };
104
105 // CENC 3d Edition adds pattern encryption, through two new
ddorwin 2016/03/03 18:38:04 3rd
dougsteed 2016/03/04 19:07:29 aargh. Done.
106 // protection schemes 'cens' (with AES-CTR) and 'cbcs' (with AES-CBC).
107 // The pattern applies only to the 'encrypted' part of the frame (as
108 // defined by the relevant subsample entries), and reduces further the
109 // actual encryption applied through a repeating pattern of (encrypt:skip)
110 // 16 byte blocks. For example, in a (1:9) pattern, the first block is
111 // encrypted, and the next nine are skipped. This pattern is applied
112 // repeatedly until the end of the last 16-byte block in the subsample.
113 // Any remaining bytes are left clear.
114 // If either or both of encrypt_blocks or skip_blocks is 0, pattern
115 // encryption is disabled.
116 struct PatternSpec {
117 PatternSpec();
118 PatternSpec(uint32_t encrypt_blocks, uint32_t skip_blocks);
119 ~PatternSpec();
120 bool IsInEffect() const;
121
122 uint32_t encrypt_blocks;
123 uint32_t skip_blocks;
124 };
125
126 EncryptionScheme();
127 explicit EncryptionScheme(CipherMode mode);
128 EncryptionScheme(CipherMode mode, const PatternSpec& pattern);
129 ~EncryptionScheme();
130 static EncryptionScheme unencrypted();
131 bool is_encrypted() const;
132
133 CipherMode mode;
134 PatternSpec pattern;
135 };
136
137 inline EncryptionScheme::PatternSpec::PatternSpec()
138 : encrypt_blocks(0), skip_blocks(0) {
139 }
140
141 inline EncryptionScheme::PatternSpec::PatternSpec(uint32_t encrypt_blocks,
142 uint32_t skip_blocks)
143 : encrypt_blocks(encrypt_blocks), skip_blocks(skip_blocks) {
144 }
145
146 inline EncryptionScheme::PatternSpec::~PatternSpec() {}
147
148 inline bool EncryptionScheme::PatternSpec::IsInEffect() const {
149 return encrypt_blocks != 0 && skip_blocks != 0;
150 }
151
152 inline EncryptionScheme::EncryptionScheme()
153 : mode(kCipherModeUnencrypted), pattern() {
154 }
155
156 inline EncryptionScheme::EncryptionScheme(CipherMode mode)
157 : mode(mode), pattern() {
158 }
159
160 inline EncryptionScheme::EncryptionScheme(CipherMode mode,
161 const PatternSpec& pattern)
162 : mode(mode), pattern(pattern) {
163 }
164
165 inline EncryptionScheme::~EncryptionScheme() {}
166
167 inline EncryptionScheme EncryptionScheme::unencrypted() {
168 return EncryptionScheme(kCipherModeUnencrypted);
169 }
170
171 inline bool EncryptionScheme::is_encrypted() const {
172 return mode != kCipherModeUnencrypted;
173 }
174
175 // TODO(erickung): Remove constructor once CMA backend implementation doesn't
97 // create a new object to reset the configuration and use IsValidConfig() to 176 // create a new object to reset the configuration and use IsValidConfig() to
98 // determine if the configuration is still valid or not. 177 // determine if the configuration is still valid or not.
99 struct AudioConfig { 178 struct AudioConfig {
100 AudioConfig(); 179 AudioConfig();
101 ~AudioConfig(); 180 ~AudioConfig();
102 181
182 bool is_encrypted() const;
183
103 // Stream id. 184 // Stream id.
104 StreamId id; 185 StreamId id;
105 // Audio codec. 186 // Audio codec.
106 AudioCodec codec; 187 AudioCodec codec;
107 // The format of each audio sample. 188 // The format of each audio sample.
108 SampleFormat sample_format; 189 SampleFormat sample_format;
109 // Number of bytes in each channel. 190 // Number of bytes in each channel.
110 int bytes_per_channel; 191 int bytes_per_channel;
111 // Number of channels in this audio stream. 192 // Number of channels in this audio stream.
112 int channel_number; 193 int channel_number;
113 // Number of audio samples per second. 194 // Number of audio samples per second.
114 int samples_per_second; 195 int samples_per_second;
115 // Extra data buffer for certain codec initialization. 196 // Extra data buffer for certain codec initialization.
116 std::vector<uint8_t> extra_data; 197 std::vector<uint8_t> extra_data;
117 // content is encrypted or not. 198 // Encryption scheme (if any) used for the content.
118 bool is_encrypted; 199 EncryptionScheme encryption_scheme;
119 }; 200 };
120 201
121 inline AudioConfig::AudioConfig() 202 inline AudioConfig::AudioConfig()
122 : id(kPrimary), 203 : id(kPrimary),
123 codec(kAudioCodecUnknown), 204 codec(kAudioCodecUnknown),
124 sample_format(kUnknownSampleFormat), 205 sample_format(kUnknownSampleFormat),
125 bytes_per_channel(0), 206 bytes_per_channel(0),
126 channel_number(0), 207 channel_number(0),
127 samples_per_second(0), 208 samples_per_second(0) {
128 is_encrypted(false) {
129 } 209 }
130 210
131 inline AudioConfig::~AudioConfig() { 211 inline AudioConfig::~AudioConfig() {
132 } 212 }
133 213
214 inline bool AudioConfig::is_encrypted() const {
215 return encryption_scheme.is_encrypted();
216 }
xhwang 2016/03/03 22:33:00 nit: you can implement this in line 182 directly.
dougsteed 2016/03/04 19:07:29 Done.
217
134 // TODO(erickung): Remove constructor once CMA backend implementation does't 218 // TODO(erickung): Remove constructor once CMA backend implementation does't
135 // create a new object to reset the configuration and use IsValidConfig() to 219 // create a new object to reset the configuration and use IsValidConfig() to
136 // determine if the configuration is still valid or not. 220 // determine if the configuration is still valid or not.
137 struct VideoConfig { 221 struct VideoConfig {
138 VideoConfig(); 222 VideoConfig();
139 ~VideoConfig(); 223 ~VideoConfig();
140 224
225 bool is_encrypted() const;
226
141 // Stream Id. 227 // Stream Id.
142 StreamId id; 228 StreamId id;
143 // Video codec. 229 // Video codec.
144 VideoCodec codec; 230 VideoCodec codec;
145 // Video codec profile. 231 // Video codec profile.
146 VideoProfile profile; 232 VideoProfile profile;
147 // Additional video config for the video stream if available. Consumers of 233 // Additional video config for the video stream if available. Consumers of
148 // this structure should make an explicit copy of |additional_config| if it 234 // this structure should make an explicit copy of |additional_config| if it
149 // will be used after SetConfig() finishes. 235 // will be used after SetConfig() finishes.
150 VideoConfig* additional_config; 236 VideoConfig* additional_config;
151 // Extra data buffer for certain codec initialization. 237 // Extra data buffer for certain codec initialization.
152 std::vector<uint8_t> extra_data; 238 std::vector<uint8_t> extra_data;
153 // content is encrypted or not. 239 // Encryption scheme (if any) used for the content.
154 bool is_encrypted; 240 EncryptionScheme encryption_scheme;
155 }; 241 };
156 242
157 inline VideoConfig::VideoConfig() 243 inline VideoConfig::VideoConfig()
158 : id(kPrimary), 244 : id(kPrimary),
159 codec(kVideoCodecUnknown), 245 codec(kVideoCodecUnknown),
160 profile(kVideoProfileUnknown), 246 profile(kVideoProfileUnknown),
161 additional_config(nullptr), 247 additional_config(nullptr) {
162 is_encrypted(false) {
163 } 248 }
164 249
165 inline VideoConfig::~VideoConfig() { 250 inline VideoConfig::~VideoConfig() {
166 } 251 }
167 252
253 inline bool VideoConfig::is_encrypted() const {
254 return encryption_scheme.is_encrypted();
255 }
xhwang 2016/03/03 22:33:00 ditto
dougsteed 2016/03/04 19:07:29 Done.
256
168 // TODO(erickung): Remove following two inline IsValidConfig() functions. These 257 // TODO(erickung): Remove following two inline IsValidConfig() functions. These
169 // are to keep existing CMA backend implementation consistent until the clean up 258 // are to keep existing CMA backend implementation consistent until the clean up
170 // is done. These SHOULD NOT be used in New CMA backend implementation. 259 // is done. These SHOULD NOT be used in New CMA backend implementation.
171 inline bool IsValidConfig(const AudioConfig& config) { 260 inline bool IsValidConfig(const AudioConfig& config) {
172 return config.codec >= kAudioCodecMin && 261 return config.codec >= kAudioCodecMin &&
173 config.codec <= kAudioCodecMax && 262 config.codec <= kAudioCodecMax &&
174 config.codec != kAudioCodecUnknown && 263 config.codec != kAudioCodecUnknown &&
175 config.sample_format >= kSampleFormatMin && 264 config.sample_format >= kSampleFormatMin &&
176 config.sample_format <= kSampleFormatMax && 265 config.sample_format <= kSampleFormatMax &&
177 config.sample_format != kUnknownSampleFormat && 266 config.sample_format != kUnknownSampleFormat &&
178 config.channel_number > 0 && 267 config.channel_number > 0 &&
179 config.bytes_per_channel > 0 && 268 config.bytes_per_channel > 0 &&
180 config.bytes_per_channel <= kMaxBytesPerSample && 269 config.bytes_per_channel <= kMaxBytesPerSample &&
181 config.samples_per_second > 0 && 270 config.samples_per_second > 0 &&
182 config.samples_per_second <= kMaxSampleRate; 271 config.samples_per_second <= kMaxSampleRate;
183 } 272 }
184 273
185 inline bool IsValidConfig(const VideoConfig& config) { 274 inline bool IsValidConfig(const VideoConfig& config) {
186 return config.codec >= kVideoCodecMin && 275 return config.codec >= kVideoCodecMin &&
187 config.codec <= kVideoCodecMax && 276 config.codec <= kVideoCodecMax &&
188 config.codec != kVideoCodecUnknown; 277 config.codec != kVideoCodecUnknown;
189 } 278 }
190 279
191 } // namespace media 280 } // namespace media
192 } // namespace chromecast 281 } // namespace chromecast
193 282
194 #endif // CHROMECAST_PUBLIC_MEDIA_DECODER_CONFIG_H_ 283 #endif // CHROMECAST_PUBLIC_MEDIA_DECODER_CONFIG_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698