Chromium Code Reviews| Index: media/formats/mp4/mp4_stream_parser.cc |
| diff --git a/media/formats/mp4/mp4_stream_parser.cc b/media/formats/mp4/mp4_stream_parser.cc |
| index dbd736df941a6542415faa81490e0bb290ec448f..dc785d2ee87c5beb322abd7e863ea36240dc302e 100644 |
| --- a/media/formats/mp4/mp4_stream_parser.cc |
| +++ b/media/formats/mp4/mp4_stream_parser.cc |
| @@ -17,6 +17,7 @@ |
| #include "base/time/time.h" |
| #include "build/build_config.h" |
| #include "media/base/audio_decoder_config.h" |
| +#include "media/base/encryption_scheme.h" |
| #include "media/base/media_tracks.h" |
| #include "media/base/media_util.h" |
| #include "media/base/stream_parser_buffer.h" |
| @@ -33,6 +34,41 @@ |
| namespace media { |
| namespace mp4 { |
| +namespace { |
| + |
| +EncryptionScheme GetEncryptionScheme(const ProtectionSchemeInfo& sinf) { |
| + if (!sinf.HasSupportedScheme()) |
| + return Unencrypted(); |
|
ddorwin
2016/06/17 23:32:41
Is that the best way to handle this? We know it is
dougsteed
2016/10/10 18:18:01
Done.
|
| + FourCC fourCC = sinf.type.type; |
| + EncryptionScheme::CipherMode mode = EncryptionScheme::CIPHER_MODE_UNENCRYPTED; |
| + EncryptionScheme::Pattern pattern; |
| + bool pattern_encryption = false; |
|
ddorwin
2016/06/17 23:32:41
nit: is_/uses_...
dougsteed
2016/10/10 18:18:02
Done.
|
| + switch (fourCC) { |
| + case FOURCC_CENC: |
| + mode = EncryptionScheme::CIPHER_MODE_AES_CTR; |
| + break; |
| +#if BUILDFLAG(ENABLE_CBCS_ENCRYPTION_SCHEME) |
| + case FOURCC_CBCS: |
| + mode = EncryptionScheme::CIPHER_MODE_AES_CBC; |
| + pattern_encryption = true; |
| + break; |
| +#endif |
| + default: |
| + DLOG(WARNING) << "Unsupported encryption scheme: " << fourCC; |
|
ddorwin
2016/06/17 23:32:40
Should this be a DCHECK based on line 40?
dougsteed
2016/10/10 18:18:02
Done.
|
| + break; |
| + } |
| +#if BUILDFLAG(ENABLE_CBCS_ENCRYPTION_SCHEME) |
| + if (pattern_encryption) { |
| + uint8_t crypt = sinf.info.track_encryption.default_crypt_byte_block; |
|
ddorwin
2016/06/17 23:32:40
ditto on "crypt"
dougsteed
2016/10/10 18:18:01
as mentioned above, this is the term used in the s
|
| + uint8_t skip = sinf.info.track_encryption.default_skip_byte_block; |
| + pattern = EncryptionScheme::Pattern(crypt, skip); |
| + } |
| +#endif |
| + return EncryptionScheme(mode, pattern); |
| +} |
| + |
| +} // namespace |
| + |
| MP4StreamParser::MP4StreamParser(const std::set<int>& audio_object_types, |
| bool has_sbr) |
| : state_(kWaitingForInit), |
| @@ -316,7 +352,8 @@ bool MP4StreamParser::ParseMoov(BoxReader* reader) { |
| DVLOG(1) << "is_audio_track_encrypted_: " << is_audio_track_encrypted_; |
| audio_config.Initialize( |
| codec, sample_format, channel_layout, sample_per_second, extra_data, |
| - is_audio_track_encrypted_ ? AesCtrEncryptionScheme() : Unencrypted(), |
| + is_audio_track_encrypted_ ? GetEncryptionScheme(entry.sinf) |
|
ddorwin
2016/06/17 23:32:40
Continuing from line 41, we know it's encrypted, b
dougsteed
2016/10/10 18:18:01
Done.
|
| + : Unencrypted(), |
| base::TimeDelta(), 0); |
| has_audio_ = true; |
| audio_track_id_ = track->header.track_id; |
| @@ -368,7 +405,8 @@ bool MP4StreamParser::ParseMoov(BoxReader* reader) { |
| // No decoder-specific buffer needed for AVC; |
| // SPS/PPS are embedded in the video stream |
| EmptyExtraData(), |
| - is_video_track_encrypted_ ? AesCtrEncryptionScheme() : Unencrypted()); |
| + is_video_track_encrypted_ ? GetEncryptionScheme(entry.sinf) |
| + : Unencrypted()); |
| has_video_ = true; |
| video_track_id_ = track->header.track_id; |
| media_tracks->AddVideoTrack( |
| @@ -574,11 +612,9 @@ bool MP4StreamParser::EnqueueSample(BufferQueue* audio_buffers, |
| if (decrypt_config) { |
| if (!subsamples.empty()) { |
| - // Create a new config with the updated subsamples. |
| - decrypt_config.reset(new DecryptConfig( |
| - decrypt_config->key_id(), |
| - decrypt_config->iv(), |
| - subsamples)); |
| + // Create a new config with the updated subsamples. |
| + decrypt_config.reset(new DecryptConfig(decrypt_config->key_id(), |
| + decrypt_config->iv(), subsamples)); |
| } |
| // else, use the existing config. |
| } else if ((audio && is_audio_track_encrypted_) || |