Chromium Code Reviews| Index: media/formats/mp4/box_definitions.cc |
| diff --git a/media/formats/mp4/box_definitions.cc b/media/formats/mp4/box_definitions.cc |
| index 82a94709f73f5572dd0f2dc6b52fe5c41080b9fb..c23eea94ddc2fa5f1b4706e17a5d5b2643c990ba 100644 |
| --- a/media/formats/mp4/box_definitions.cc |
| +++ b/media/formats/mp4/box_definitions.cc |
| @@ -23,6 +23,12 @@ |
| namespace media { |
| namespace mp4 { |
| +namespace { |
| + |
| +const size_t kKeyIdSize = 16; |
| + |
| +} // namespace |
| + |
| FileType::FileType() {} |
| FileType::FileType(const FileType& other) = default; |
| FileType::~FileType() {} |
| @@ -240,16 +246,27 @@ FourCC TrackEncryption::BoxType() const { return FOURCC_TENC; } |
| bool TrackEncryption::Parse(BoxReader* reader) { |
| uint8_t flag; |
| - RCHECK(reader->ReadFullBoxHeader() && |
| - reader->SkipBytes(2) && |
| - reader->Read1(&flag) && |
| - reader->Read1(&default_iv_size) && |
| - reader->ReadVec(&default_kid, 16)); |
| + uint8_t possible_pattern_info; |
| + RCHECK(reader->ReadFullBoxHeader() && reader->SkipBytes(1) && |
| + reader->Read1(&possible_pattern_info) && reader->Read1(&flag) && |
| + reader->Read1(&default_iv_size) && reader->ReadVec(&default_kid, 16)); |
|
kqyang
2016/05/23 20:57:34
s/16/kKeyIdSize/
dougsteed
2016/05/25 17:23:21
Done.
|
| is_encrypted = (flag != 0); |
| - if (is_encrypted) { |
| + if (default_iv_size != 0) { |
| RCHECK(default_iv_size == 8 || default_iv_size == 16); |
| +#if BUILDFLAG(ENABLE_CENC_NEW_EDITIONS) |
|
kqyang
2016/05/23 20:57:34
I'd prefer as less preprocessor primitive in the c
ddorwin
2016/05/24 23:25:03
I'm worried about all the ifdef'd code being added
dougsteed
2016/05/25 17:23:21
Changed the name as suggested.
|
| + } else if (is_encrypted) { |
| + if (reader->version() > 0) { |
| + default_crypt_byte_block = (possible_pattern_info >> 4) & 0x0f; |
| + default_skip_byte_block = possible_pattern_info & 0x0f; |
| + } |
| + RCHECK(reader->Read1(&default_constant_iv_size) && |
| + (default_constant_iv_size == 8 || default_constant_iv_size == 16)); |
| + memset(default_constant_iv, 0, sizeof(default_constant_iv)); |
| + for (uint8_t i = 0; i < default_constant_iv_size; i++) |
| + RCHECK(reader->Read1(default_constant_iv + i)); |
| +#endif |
| } else { |
| - RCHECK(default_iv_size == 0); |
| + RCHECK(!is_encrypted); |
| } |
| return true; |
| } |
| @@ -273,7 +290,7 @@ bool ProtectionSchemeInfo::Parse(BoxReader* reader) { |
| RCHECK(reader->ScanChildren() && |
| reader->ReadChild(&format) && |
| reader->ReadChild(&type)); |
| - if (type.type == FOURCC_CENC) |
| + if (HasSupportedScheme()) |
| RCHECK(reader->ReadChild(&info)); |
| // Other protection schemes are silently ignored. Since the protection scheme |
| // type can't be determined until this box is opened, we return 'true' for |
| @@ -282,6 +299,18 @@ bool ProtectionSchemeInfo::Parse(BoxReader* reader) { |
| return true; |
| } |
| +bool ProtectionSchemeInfo::HasSupportedScheme() const { |
| + FourCC fourCC = type.type; |
| + if (fourCC == FOURCC_CENC) |
| + return true; |
| +#if BUILDFLAG(ENABLE_CENC_NEW_EDITIONS) |
| + return fourCC == FOURCC_CBC1 || fourCC == FOURCC_CBCS || |
|
ddorwin
2016/05/24 23:25:03
Are there actual use cases for the other two? If n
dougsteed
2016/05/25 17:23:21
Done.
|
| + fourCC == FOURCC_CENS; |
| +#else |
| + return false; |
| +#endif |
| +} |
| + |
| MovieHeader::MovieHeader() |
| : creation_time(0), |
| modification_time(0), |
| @@ -609,7 +638,7 @@ bool VideoSampleEntry::Parse(BoxReader* reader) { |
| if (format == FOURCC_ENCV) { |
| // Continue scanning until a recognized protection scheme is found, or until |
| // we run out of protection schemes. |
| - while (sinf.type.type != FOURCC_CENC) { |
| + while (!sinf.HasSupportedScheme()) { |
| if (!reader->ReadChild(&sinf)) |
| return false; |
| } |
| @@ -749,7 +778,7 @@ bool AudioSampleEntry::Parse(BoxReader* reader) { |
| if (format == FOURCC_ENCA) { |
| // Continue scanning until a recognized protection scheme is found, or until |
| // we run out of protection schemes. |
| - while (sinf.type.type != FOURCC_CENC) { |
| + while (!sinf.HasSupportedScheme()) { |
| if (!reader->ReadChild(&sinf)) |
| return false; |
| } |
| @@ -1094,6 +1123,32 @@ CencSampleEncryptionInfoEntry::CencSampleEncryptionInfoEntry( |
| const CencSampleEncryptionInfoEntry& other) = default; |
| CencSampleEncryptionInfoEntry::~CencSampleEncryptionInfoEntry() {} |
| +bool CencSampleEncryptionInfoEntry::Parse(BoxReader* reader) { |
| + uint8_t flag; |
| + uint8_t possible_pattern_info; |
| + RCHECK(reader->SkipBytes(1) && // reserved. |
| + reader->Read1(&possible_pattern_info) && reader->Read1(&flag) && |
| + reader->Read1(&iv_size) && reader->ReadVec(&key_id, kKeyIdSize)); |
| + |
| + is_encrypted = (flag != 0); |
| + if (iv_size != 0) { |
| + RCHECK(iv_size == 8 || iv_size == 16); |
| +#if BUILDFLAG(ENABLE_CENC_NEW_EDITIONS) |
| + } else if (is_encrypted) { |
| + crypt_byte_block = (possible_pattern_info >> 4) & 0x0f; |
| + skip_byte_block = possible_pattern_info & 0x0f; |
| + RCHECK(reader->Read1(&constant_iv_size) && |
| + (constant_iv_size == 8 || constant_iv_size == 16)); |
| + memset(constant_iv, 0, sizeof(constant_iv)); |
| + for (uint8_t i = 0; i < constant_iv_size; i++) |
| + RCHECK(reader->Read1(constant_iv + i)); |
| +#endif |
| + } else { |
| + RCHECK(!is_encrypted); |
| + } |
| + return true; |
| +} |
| + |
| SampleGroupDescription::SampleGroupDescription() : grouping_type(0) {} |
| SampleGroupDescription::SampleGroupDescription( |
| const SampleGroupDescription& other) = default; |
| @@ -1112,7 +1167,6 @@ bool SampleGroupDescription::Parse(BoxReader* reader) { |
| const uint8_t version = reader->version(); |
| - const size_t kKeyIdSize = 16; |
| const size_t kEntrySize = sizeof(uint32_t) + kKeyIdSize; |
| uint32_t default_length = 0; |
| if (version == 1) { |
| @@ -1131,19 +1185,7 @@ bool SampleGroupDescription::Parse(BoxReader* reader) { |
| RCHECK(description_length >= kEntrySize); |
| } |
| } |
| - |
| - uint8_t flag; |
| - RCHECK(reader->SkipBytes(2) && // reserved. |
| - reader->Read1(&flag) && |
| - reader->Read1(&entries[i].iv_size) && |
| - reader->ReadVec(&entries[i].key_id, kKeyIdSize)); |
| - |
| - entries[i].is_encrypted = (flag != 0); |
| - if (entries[i].is_encrypted) { |
| - RCHECK(entries[i].iv_size == 8 || entries[i].iv_size == 16); |
| - } else { |
| - RCHECK(entries[i].iv_size == 0); |
| - } |
| + RCHECK(entries[i].Parse(reader)); |
| } |
| return true; |
| } |