Index: chromecast/public/media/decoder_config.h |
diff --git a/chromecast/public/media/decoder_config.h b/chromecast/public/media/decoder_config.h |
index 261b3f1fa575667196ef681dedec74f7bacdb49b..7094629a142dff39cd33397631c2893f13baae14 100644 |
--- a/chromecast/public/media/decoder_config.h |
+++ b/chromecast/public/media/decoder_config.h |
@@ -93,13 +93,94 @@ enum VideoProfile { |
kVideoProfileMax = kDolbyVisionNonCompatible_BL_EL_MD, |
}; |
-// 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 { |
+ kCipherModeUnencrypted, |
+ kCipherModeAesCtr, |
+ kCipherModeAesCbc |
+ }; |
+ |
+ // V3 of the CENC standard adds pattern encryption, through two new |
ddorwin
2016/03/02 23:24:05
nit: CENC 3rd edition adds...
dougsteed
2016/03/03 04:45:00
Done.
|
+ // 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(); |
+ bool IsInEffect() const; |
+ |
+ uint32_t encrypt_blocks; |
+ uint32_t skip_blocks; |
+ }; |
+ |
+ EncryptionScheme(); |
+ explicit EncryptionScheme(CipherMode mode); |
+ EncryptionScheme(CipherMode mode, const PatternSpec& pattern); |
+ ~EncryptionScheme(); |
+ static EncryptionScheme unencrypted(); |
+ bool is_encrypted() const; |
+ |
+ 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::PatternSpec::~PatternSpec() {} |
ddorwin
2016/03/02 23:24:05
Hmm. I didn't realize there was so much inlined in
halliwell
2016/03/02 23:39:53
This file (actually, this directory) has to be inl
ddorwin
2016/03/03 18:38:04
Acknowledged.
|
+ |
+inline bool EncryptionScheme::PatternSpec::IsInEffect() const { |
+ return encrypt_blocks != 0 && skip_blocks != 0; |
+} |
+ |
+inline EncryptionScheme::EncryptionScheme() |
+ : mode(kCipherModeUnencrypted), pattern() { |
+} |
+ |
+inline EncryptionScheme::EncryptionScheme(CipherMode mode) |
+ : mode(mode), pattern() { |
+} |
+ |
+inline EncryptionScheme::EncryptionScheme(CipherMode mode, |
+ const PatternSpec& pattern) |
+ : mode(mode), pattern(pattern) { |
+} |
+ |
+inline EncryptionScheme::~EncryptionScheme() {} |
+ |
+inline EncryptionScheme EncryptionScheme::unencrypted() { |
+ return EncryptionScheme(kCipherModeUnencrypted); |
+} |
+ |
+inline bool EncryptionScheme::is_encrypted() const { |
+ return mode != kCipherModeUnencrypted; |
+} |
+ |
+// 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. |
@@ -114,8 +195,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() |
@@ -124,13 +205,16 @@ inline AudioConfig::AudioConfig() |
sample_format(kUnknownSampleFormat), |
bytes_per_channel(0), |
channel_number(0), |
- samples_per_second(0), |
- is_encrypted(false) { |
+ samples_per_second(0) { |
} |
inline AudioConfig::~AudioConfig() { |
} |
+inline bool AudioConfig::is_encrypted() const { |
+ return encryption_scheme.mode != EncryptionScheme::kCipherModeUnencrypted; |
ddorwin
2016/03/02 23:24:05
Just call is_encrypted()?
dougsteed
2016/03/03 04:45:00
Done.
|
+} |
+ |
// 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. |
@@ -138,6 +222,8 @@ struct VideoConfig { |
VideoConfig(); |
~VideoConfig(); |
+ bool is_encrypted() const; |
+ |
// Stream Id. |
StreamId id; |
// Video codec. |
@@ -150,21 +236,24 @@ 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() |
: id(kPrimary), |
codec(kVideoCodecUnknown), |
profile(kVideoProfileUnknown), |
- additional_config(nullptr), |
- is_encrypted(false) { |
+ additional_config(nullptr) { |
} |
inline VideoConfig::~VideoConfig() { |
} |
+inline bool VideoConfig::is_encrypted() const { |
+ return encryption_scheme.mode != EncryptionScheme::kCipherModeUnencrypted; |
ddorwin
2016/03/02 23:24:05
ditto
dougsteed
2016/03/03 04:45:00
Done.
|
+} |
+ |
// 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. |