Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 { | |
| 98 // Algorithm and mode that was used to encrypt the stream. | |
| 99 enum CipherMode { | |
| 100 kCipherModeNone, | |
| 101 kCipherModeAesCtr, | |
| 102 kCipherModeAesCbc | |
| 103 }; | |
| 104 | |
| 105 // V3 of the CENC standard will add pattern encryption, through two new | |
|
ddorwin
2016/03/01 02:17:41
s/will add/adds/
dougsteed
2016/03/02 18:07:52
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() {} | |
|
ddorwin
2016/03/01 02:17:41
Do not inline.
dougsteed
2016/03/02 18:07:52
Done.
| |
| 120 uint32_t encrypt_blocks; | |
| 121 uint32_t skip_blocks; | |
| 122 }; | |
| 123 | |
| 124 EncryptionScheme(); | |
| 125 explicit EncryptionScheme(CipherMode mode); | |
| 126 EncryptionScheme(CipherMode mode, const PatternSpec& pattern); | |
| 127 ~EncryptionScheme() {} | |
| 128 static EncryptionScheme unencrypted(); | |
| 129 | |
| 130 CipherMode mode; | |
| 131 PatternSpec pattern; | |
| 132 }; | |
| 133 | |
| 134 inline EncryptionScheme::PatternSpec::PatternSpec() | |
| 135 : encrypt_blocks(0), skip_blocks(0) { | |
| 136 } | |
| 137 | |
| 138 inline EncryptionScheme::PatternSpec::PatternSpec(uint32_t encrypt_blocks, | |
| 139 uint32_t skip_blocks) | |
| 140 : encrypt_blocks(encrypt_blocks), skip_blocks(skip_blocks) { | |
| 141 } | |
| 142 | |
| 143 inline EncryptionScheme::EncryptionScheme() | |
| 144 : mode(kCipherModeNone), pattern() { | |
| 145 } | |
| 146 | |
| 147 inline EncryptionScheme::EncryptionScheme(CipherMode mode) | |
| 148 : mode(mode), pattern() { | |
| 149 } | |
| 150 | |
| 151 inline EncryptionScheme::EncryptionScheme(CipherMode mode, | |
| 152 const PatternSpec& pattern) | |
| 153 : mode(mode), pattern(pattern) { | |
| 154 } | |
| 155 | |
| 156 inline EncryptionScheme EncryptionScheme::unencrypted() { | |
| 157 return EncryptionScheme(kCipherModeNone); | |
| 158 } | |
| 159 | |
| 160 // TODO(erickung): Remove constructor once CMA backend implementation doesn't | |
| 97 // create a new object to reset the configuration and use IsValidConfig() to | 161 // create a new object to reset the configuration and use IsValidConfig() to |
| 98 // determine if the configuration is still valid or not. | 162 // determine if the configuration is still valid or not. |
| 99 struct AudioConfig { | 163 struct AudioConfig { |
| 100 AudioConfig(); | 164 AudioConfig(); |
| 101 ~AudioConfig(); | 165 ~AudioConfig(); |
| 102 | 166 |
| 167 bool is_encrypted() const; | |
| 168 | |
| 103 // Stream id. | 169 // Stream id. |
| 104 StreamId id; | 170 StreamId id; |
| 105 // Audio codec. | 171 // Audio codec. |
| 106 AudioCodec codec; | 172 AudioCodec codec; |
| 107 // The format of each audio sample. | 173 // The format of each audio sample. |
| 108 SampleFormat sample_format; | 174 SampleFormat sample_format; |
| 109 // Number of bytes in each channel. | 175 // Number of bytes in each channel. |
| 110 int bytes_per_channel; | 176 int bytes_per_channel; |
| 111 // Number of channels in this audio stream. | 177 // Number of channels in this audio stream. |
| 112 int channel_number; | 178 int channel_number; |
| 113 // Number of audio samples per second. | 179 // Number of audio samples per second. |
| 114 int samples_per_second; | 180 int samples_per_second; |
| 115 // Extra data buffer for certain codec initialization. | 181 // Extra data buffer for certain codec initialization. |
| 116 std::vector<uint8_t> extra_data; | 182 std::vector<uint8_t> extra_data; |
| 117 // content is encrypted or not. | 183 // Encryption scheme (if any) used for the content. |
| 118 bool is_encrypted; | 184 EncryptionScheme encryption_scheme; |
| 119 }; | 185 }; |
| 120 | 186 |
| 121 inline AudioConfig::AudioConfig() | 187 inline AudioConfig::AudioConfig() |
| 122 : id(kPrimary), | 188 : id(kPrimary), |
| 123 codec(kAudioCodecUnknown), | 189 codec(kAudioCodecUnknown), |
| 124 sample_format(kUnknownSampleFormat), | 190 sample_format(kUnknownSampleFormat), |
| 125 bytes_per_channel(0), | 191 bytes_per_channel(0), |
| 126 channel_number(0), | 192 channel_number(0), |
| 127 samples_per_second(0), | 193 samples_per_second(0) { |
| 128 is_encrypted(false) { | |
| 129 } | 194 } |
| 130 | 195 |
| 131 inline AudioConfig::~AudioConfig() { | 196 inline AudioConfig::~AudioConfig() { |
| 132 } | 197 } |
| 133 | 198 |
| 199 inline bool AudioConfig::is_encrypted() const { | |
| 200 return encryption_scheme.mode != EncryptionScheme::kCipherModeNone; | |
| 201 } | |
| 202 | |
| 134 // TODO(erickung): Remove constructor once CMA backend implementation does't | 203 // TODO(erickung): Remove constructor once CMA backend implementation does't |
| 135 // create a new object to reset the configuration and use IsValidConfig() to | 204 // create a new object to reset the configuration and use IsValidConfig() to |
| 136 // determine if the configuration is still valid or not. | 205 // determine if the configuration is still valid or not. |
| 137 struct VideoConfig { | 206 struct VideoConfig { |
| 138 VideoConfig(); | 207 VideoConfig(); |
| 139 ~VideoConfig(); | 208 ~VideoConfig(); |
| 140 | 209 |
| 210 bool is_encrypted() const; | |
| 211 | |
| 141 // Stream Id. | 212 // Stream Id. |
| 142 StreamId id; | 213 StreamId id; |
| 143 // Video codec. | 214 // Video codec. |
| 144 VideoCodec codec; | 215 VideoCodec codec; |
| 145 // Video codec profile. | 216 // Video codec profile. |
| 146 VideoProfile profile; | 217 VideoProfile profile; |
| 147 // Additional video config for the video stream if available. Consumers of | 218 // Additional video config for the video stream if available. Consumers of |
| 148 // this structure should make an explicit copy of |additional_config| if it | 219 // this structure should make an explicit copy of |additional_config| if it |
| 149 // will be used after SetConfig() finishes. | 220 // will be used after SetConfig() finishes. |
| 150 VideoConfig* additional_config; | 221 VideoConfig* additional_config; |
| 151 // Extra data buffer for certain codec initialization. | 222 // Extra data buffer for certain codec initialization. |
| 152 std::vector<uint8_t> extra_data; | 223 std::vector<uint8_t> extra_data; |
| 153 // content is encrypted or not. | 224 // Encryption scheme (if any) used for the content. |
| 154 bool is_encrypted; | 225 EncryptionScheme encryption_scheme; |
| 155 }; | 226 }; |
| 156 | 227 |
| 157 inline VideoConfig::VideoConfig() | 228 inline VideoConfig::VideoConfig() |
| 158 : id(kPrimary), | 229 : id(kPrimary), |
| 159 codec(kVideoCodecUnknown), | 230 codec(kVideoCodecUnknown), |
| 160 profile(kVideoProfileUnknown), | 231 profile(kVideoProfileUnknown), |
| 161 additional_config(nullptr), | 232 additional_config(nullptr) { |
| 162 is_encrypted(false) { | |
| 163 } | 233 } |
| 164 | 234 |
| 165 inline VideoConfig::~VideoConfig() { | 235 inline VideoConfig::~VideoConfig() { |
| 166 } | 236 } |
| 167 | 237 |
| 238 inline bool VideoConfig::is_encrypted() const { | |
| 239 return encryption_scheme.mode != EncryptionScheme::kCipherModeNone; | |
| 240 } | |
| 241 | |
| 168 // TODO(erickung): Remove following two inline IsValidConfig() functions. These | 242 // TODO(erickung): Remove following two inline IsValidConfig() functions. These |
| 169 // are to keep existing CMA backend implementation consistent until the clean up | 243 // 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. | 244 // is done. These SHOULD NOT be used in New CMA backend implementation. |
| 171 inline bool IsValidConfig(const AudioConfig& config) { | 245 inline bool IsValidConfig(const AudioConfig& config) { |
| 172 return config.codec >= kAudioCodecMin && | 246 return config.codec >= kAudioCodecMin && |
| 173 config.codec <= kAudioCodecMax && | 247 config.codec <= kAudioCodecMax && |
| 174 config.codec != kAudioCodecUnknown && | 248 config.codec != kAudioCodecUnknown && |
| 175 config.sample_format >= kSampleFormatMin && | 249 config.sample_format >= kSampleFormatMin && |
| 176 config.sample_format <= kSampleFormatMax && | 250 config.sample_format <= kSampleFormatMax && |
| 177 config.sample_format != kUnknownSampleFormat && | 251 config.sample_format != kUnknownSampleFormat && |
| 178 config.channel_number > 0 && | 252 config.channel_number > 0 && |
| 179 config.bytes_per_channel > 0 && | 253 config.bytes_per_channel > 0 && |
| 180 config.bytes_per_channel <= kMaxBytesPerSample && | 254 config.bytes_per_channel <= kMaxBytesPerSample && |
| 181 config.samples_per_second > 0 && | 255 config.samples_per_second > 0 && |
| 182 config.samples_per_second <= kMaxSampleRate; | 256 config.samples_per_second <= kMaxSampleRate; |
| 183 } | 257 } |
| 184 | 258 |
| 185 inline bool IsValidConfig(const VideoConfig& config) { | 259 inline bool IsValidConfig(const VideoConfig& config) { |
| 186 return config.codec >= kVideoCodecMin && | 260 return config.codec >= kVideoCodecMin && |
| 187 config.codec <= kVideoCodecMax && | 261 config.codec <= kVideoCodecMax && |
| 188 config.codec != kVideoCodecUnknown; | 262 config.codec != kVideoCodecUnknown; |
| 189 } | 263 } |
| 190 | 264 |
| 191 } // namespace media | 265 } // namespace media |
| 192 } // namespace chromecast | 266 } // namespace chromecast |
| 193 | 267 |
| 194 #endif // CHROMECAST_PUBLIC_MEDIA_DECODER_CONFIG_H_ | 268 #endif // CHROMECAST_PUBLIC_MEDIA_DECODER_CONFIG_H_ |
| OLD | NEW |