Chromium Code Reviews| Index: chromecast/public/media/decoder_config.h |
| diff --git a/chromecast/public/media/decoder_config.h b/chromecast/public/media/decoder_config.h |
| index e2cf78dcbc6118608f4295c31ae9ff9e939c23ab..d3fc9de85949dca163817dfe25a2668693e49919 100644 |
| --- a/chromecast/public/media/decoder_config.h |
| +++ b/chromecast/public/media/decoder_config.h |
| @@ -87,13 +87,80 @@ enum VideoProfile { |
| kVideoProfileMax = kVP9ProfileAny, |
| }; |
| -// TODO(erickung): Remove constructor once CMA backend implementation does't |
| +// Specification of whether and how the stream is encrypted (in whole or part). |
| +struct EncryptionScheme { |
| + // Algorithm and mode that was used to encrypt the stream. |
| + enum CipherMode { |
| + kCipherModeNone, |
| + kCipherModeAesCtr, |
| + kCipherModeAesCbc |
| + }; |
| + |
| + // V3 of the CENC standard will add pattern encryption, through two new |
| + // protection schemes 'cens' (with AES-CTR) and 'cbcs' (with AES-CBC). |
| + // The pattern applies only to the 'encrypted' part of the frame (as |
| + // defined by the relevant subsample entries), and reduces further the |
| + // actual encryption applied through a repeating pattern of (encrypt:skip) |
| + // 16 byte blocks. For example, in a (1:9) pattern, the first block is |
| + // encrypted, and the next nine are skipped. This pattern is applied |
| + // repeatedly until the end of the last 16-byte block in the subsample. |
| + // Any remaining bytes are left clear. |
| + // If either or both of encrypt_blocks or skip_blocks is 0, pattern |
| + // encryption is disabled. |
| + struct PatternSpec { |
| + PatternSpec(); |
| + PatternSpec(uint32_t encrypt_blocks, uint32_t skip_blocks); |
| + ~PatternSpec() {} |
| + uint32_t encrypt_blocks; |
| + uint32_t skip_blocks; |
| + }; |
| + |
| + EncryptionScheme(); |
| + 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.
|
| + explicit EncryptionScheme(CipherMode mode); |
| + EncryptionScheme(CipherMode mode, const PatternSpec& pattern); |
| + ~EncryptionScheme() {} |
| + |
| + CipherMode mode; |
| + PatternSpec pattern; |
| +}; |
| + |
| +inline EncryptionScheme::PatternSpec::PatternSpec() |
| + : encrypt_blocks(0), skip_blocks(0) { |
| +} |
| + |
| +inline EncryptionScheme::PatternSpec::PatternSpec(uint32_t encrypt_blocks, |
| + uint32_t skip_blocks) |
| + : encrypt_blocks(encrypt_blocks), skip_blocks(skip_blocks) { |
| +} |
| + |
| +inline EncryptionScheme::EncryptionScheme() |
| + : mode(kCipherModeNone), pattern() { |
| +} |
| + |
| +inline EncryptionScheme::EncryptionScheme(bool is_encrypted) |
| + : 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.
|
| + pattern() { |
| +} |
| + |
| +inline EncryptionScheme::EncryptionScheme(CipherMode mode) |
| + : mode(mode), pattern() { |
| +} |
| + |
| +inline EncryptionScheme::EncryptionScheme(CipherMode mode, |
| + const PatternSpec& pattern) |
| + : mode(mode), pattern(pattern) { |
| +} |
| + |
| +// TODO(erickung): Remove constructor once CMA backend implementation doesn't |
| // create a new object to reset the configuration and use IsValidConfig() to |
| // determine if the configuration is still valid or not. |
| struct AudioConfig { |
| AudioConfig(); |
| ~AudioConfig(); |
| + bool is_encrypted() const; |
| + |
| // Stream id. |
| StreamId id; |
| // Audio codec. |
| @@ -108,8 +175,8 @@ struct AudioConfig { |
| int samples_per_second; |
| // Extra data buffer for certain codec initialization. |
| std::vector<uint8_t> extra_data; |
| - // content is encrypted or not. |
| - bool is_encrypted; |
| + // Encryption scheme (if any) used for the content. |
| + EncryptionScheme encryption_scheme; |
| }; |
| inline AudioConfig::AudioConfig() |
| @@ -119,12 +186,19 @@ inline AudioConfig::AudioConfig() |
| bytes_per_channel(0), |
| channel_number(0), |
| samples_per_second(0), |
| - is_encrypted(false) { |
| + encryption_scheme(false) { |
|
halliwell
2016/01/13 03:29:41
default initialisation of encryption_scheme should
dougsteed
2016/02/09 22:58:54
Done.
|
| } |
| inline AudioConfig::~AudioConfig() { |
| } |
| +// Normally a struct would not have a simple function member like this. However, |
| +// the member |encryption_scheme| replaced a simple boolean, and a lot of code |
| +// 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.
|
| +inline bool AudioConfig::is_encrypted() const { |
| + return encryption_scheme.mode != EncryptionScheme::kCipherModeNone; |
| +} |
| + |
| // TODO(erickung): Remove constructor once CMA backend implementation does't |
| // create a new object to reset the configuration and use IsValidConfig() to |
| // determine if the configuration is still valid or not. |
| @@ -132,6 +206,8 @@ struct VideoConfig { |
| VideoConfig(); |
| ~VideoConfig(); |
| + bool is_encrypted() const; |
| + |
| // Stream Id. |
| StreamId id; |
| // Video codec. |
| @@ -144,8 +220,8 @@ struct VideoConfig { |
| VideoConfig* additional_config; |
| // Extra data buffer for certain codec initialization. |
| std::vector<uint8_t> extra_data; |
| - // content is encrypted or not. |
| - bool is_encrypted; |
| + // Encryption scheme (if any) used for the content. |
| + EncryptionScheme encryption_scheme; |
| }; |
| inline VideoConfig::VideoConfig() |
| @@ -153,12 +229,18 @@ inline VideoConfig::VideoConfig() |
| codec(kVideoCodecUnknown), |
| profile(kVideoProfileUnknown), |
| additional_config(nullptr), |
| - is_encrypted(false) { |
| + encryption_scheme(false) { |
| } |
| inline VideoConfig::~VideoConfig() { |
| } |
| +// See comment above for AudioConfig::is_encrypted(). |
|
halliwell
2016/01/13 03:29:41
delete
dougsteed
2016/02/09 22:58:53
Done.
|
| +inline bool VideoConfig::is_encrypted() const { |
| + return encryption_scheme.mode != EncryptionScheme::kCipherModeNone; |
| +} |
| + |
| + |
| // TODO(erickung): Remove following two inline IsValidConfig() functions. These |
| // are to keep existing CMA backend implementation consistent until the clean up |
| // is done. These SHOULD NOT be used in New CMA backend implementation. |