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