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..9da48cc95953cca0ce57b4355680cecdd96df44b 100644 |
--- a/chromecast/public/media/decoder_config.h |
+++ b/chromecast/public/media/decoder_config.h |
@@ -93,13 +93,82 @@ 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 { |
+ CIPHER_MODE_UNENCRYPTED, |
+ CIPHER_MODE_AES_CTR, |
+ CIPHER_MODE_AES_CBC |
+ }; |
+ |
+ // CENC 3rd Edition adds pattern encryption, through two new protection |
+ // schemes: 'cens' (with AES-CTR) and 'cbcs' (with AES-CBC). |
+ // The pattern applies independently to each '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 of encrypt_blocks or skip_blocks is 0, pattern encryption is |
+ // disabled. |
+ struct Pattern { |
+ Pattern() {} |
+ Pattern(uint32_t encrypt_blocks, uint32_t skip_blocks); |
+ ~Pattern() {} |
+ bool IsInEffect() const; |
+ |
+ uint32_t encrypt_blocks = 0; |
+ uint32_t skip_blocks = 0; |
+ }; |
+ |
+ EncryptionScheme() {} |
+ explicit EncryptionScheme(CipherMode mode); |
+ EncryptionScheme(CipherMode mode, const Pattern& pattern); |
+ ~EncryptionScheme() {} |
+ bool is_encrypted() const { return mode != CIPHER_MODE_UNENCRYPTED; } |
+ |
+ CipherMode mode = CIPHER_MODE_UNENCRYPTED; |
+ Pattern pattern; |
+}; |
+ |
+inline EncryptionScheme::Pattern::Pattern(uint32_t encrypt_blocks, |
+ uint32_t skip_blocks) |
+ : encrypt_blocks(encrypt_blocks), skip_blocks(skip_blocks) { |
+} |
+ |
+inline bool EncryptionScheme::Pattern::IsInEffect() const { |
+ return encrypt_blocks != 0 && skip_blocks != 0; |
+} |
+ |
+inline EncryptionScheme::EncryptionScheme(CipherMode mode) |
+ : mode(mode), pattern() { |
+} |
+ |
+inline EncryptionScheme::EncryptionScheme(CipherMode mode, |
+ const Pattern& pattern) |
+ : mode(mode), pattern(pattern) { |
+} |
+ |
+inline EncryptionScheme Unencrypted() { |
+ return EncryptionScheme(EncryptionScheme::CIPHER_MODE_UNENCRYPTED); |
+} |
+ |
+inline EncryptionScheme AesCtrEncryptionScheme() { |
+ return EncryptionScheme(EncryptionScheme::CIPHER_MODE_AES_CTR); |
+} |
+ |
+ |
+// 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 { return encryption_scheme.is_encrypted(); } |
+ |
// Stream id. |
StreamId id; |
// Audio codec. |
@@ -114,8 +183,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,8 +193,7 @@ 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() { |
@@ -138,6 +206,8 @@ struct VideoConfig { |
VideoConfig(); |
~VideoConfig(); |
+ bool is_encrypted() const { return encryption_scheme.is_encrypted(); } |
+ |
// Stream Id. |
StreamId id; |
// Video codec. |
@@ -150,16 +220,15 @@ 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() { |