 Chromium Code Reviews
 Chromium Code Reviews Issue 260963002:
  Support parsing of sgpd and sbgp boxes  (Closed) 
  Base URL: http://git.chromium.org/chromium/src.git@temp
    
  
    Issue 260963002:
  Support parsing of sgpd and sbgp boxes  (Closed) 
  Base URL: http://git.chromium.org/chromium/src.git@temp| Index: media/formats/mp4/box_definitions.cc | 
| diff --git a/media/formats/mp4/box_definitions.cc b/media/formats/mp4/box_definitions.cc | 
| index 1912aaeb640fef0a46d07579f70a51eaad78559b..a76b7923d4b43197dcef2d0d1b76908b0c1d37bf 100644 | 
| --- a/media/formats/mp4/box_definitions.cc | 
| +++ b/media/formats/mp4/box_definitions.cc | 
| @@ -760,19 +760,113 @@ bool TrackFragmentRun::Parse(BoxReader* reader) { | 
| return true; | 
| } | 
| +SampleToGroup::SampleToGroup() : grouping_type(0), grouping_type_parameter(0) {} | 
| +SampleToGroup::~SampleToGroup() {} | 
| +FourCC SampleToGroup::BoxType() const { return FOURCC_SBGP; } | 
| + | 
| +bool SampleToGroup::Parse(BoxReader* reader) { | 
| + RCHECK(reader->ReadFullBoxHeader() && | 
| + reader->Read4(&grouping_type)); | 
| + | 
| + if (reader->version() == 1) | 
| + RCHECK(reader->Read4(&grouping_type_parameter)); | 
| + | 
| + if (grouping_type != FOURCC_SEIG) { | 
| + DLOG(WARNING) << "SampleToGroup box with grouping_type '" << grouping_type | 
| + << "' is not supported."; | 
| + return true; | 
| + } | 
| + | 
| + uint32 count; | 
| + RCHECK(reader->Read4(&count)); | 
| + entries.resize(count); | 
| + for (uint32 i = 0; i < count; ++i) { | 
| + RCHECK(reader->Read4(&entries[i].sample_count) && | 
| + reader->Read4(&entries[i].group_description_index)); | 
| + } | 
| + return true; | 
| +} | 
| + | 
| +CencSampleEncryptionInfoEntry::CencSampleEncryptionInfoEntry() | 
| + : is_encrypted(false), iv_size(0) {} | 
| +CencSampleEncryptionInfoEntry::~CencSampleEncryptionInfoEntry() {} | 
| + | 
| +SampleGroupDescription::SampleGroupDescription() : grouping_type(0) {} | 
| +SampleGroupDescription::~SampleGroupDescription() {} | 
| +FourCC SampleGroupDescription::BoxType() const { return FOURCC_SGPD; } | 
| + | 
| +bool SampleGroupDescription::Parse(BoxReader* reader) { | 
| + RCHECK(reader->ReadFullBoxHeader() && | 
| + reader->Read4(&grouping_type)); | 
| + | 
| + if (grouping_type != FOURCC_SEIG) { | 
| + DLOG(WARNING) << "SampleGroupDescription box with grouping_type '" | 
| + << grouping_type << "' is not supported."; | 
| + return true; | 
| + } | 
| + | 
| + const uint8 version = reader->version(); | 
| + | 
| + const size_t kKeyIdSize = 16; | 
| + const size_t kEntrySize = sizeof(uint32) + kKeyIdSize; | 
| + uint32 default_length = 0; | 
| + if (version == 1) { | 
| + RCHECK(reader->Read4(&default_length)); | 
| + RCHECK(default_length == 0 || default_length == kEntrySize); | 
| + } | 
| + | 
| + uint32 count; | 
| + RCHECK(reader->Read4(&count)); | 
| + entries.resize(count); | 
| + for (uint32 i = 0; i < count; ++i) { | 
| + if (version == 1) { | 
| + if (default_length == 0) { | 
| + uint32 description_length = 0; | 
| + RCHECK(reader->Read4(&description_length)); | 
| + RCHECK(description_length == kEntrySize); | 
| + } | 
| + } | 
| + | 
| + uint8 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); | 
| + } | 
| + } | 
| + return true; | 
| +} | 
| + | 
| TrackFragment::TrackFragment() {} | 
| TrackFragment::~TrackFragment() {} | 
| FourCC TrackFragment::BoxType() const { return FOURCC_TRAF; } | 
| bool TrackFragment::Parse(BoxReader* reader) { | 
| - return reader->ScanChildren() && | 
| + RCHECK(reader->ScanChildren() && | 
| reader->ReadChild(&header) && | 
| // Media Source specific: 'tfdt' required | 
| reader->ReadChild(&decode_time) && | 
| reader->MaybeReadChildren(&runs) && | 
| reader->MaybeReadChild(&auxiliary_offset) && | 
| reader->MaybeReadChild(&auxiliary_size) && | 
| - reader->MaybeReadChild(&sdtp); | 
| + reader->MaybeReadChild(&sdtp)); | 
| + | 
| + // Continue reading until SEIG is found, or until run out of child boxes. | 
| + while (sample_group_description.grouping_type != FOURCC_SEIG && | 
| + reader->HasChild(&sample_group_description)) { | 
| + RCHECK(reader->ReadChild(&sample_group_description)); | 
| + } | 
| + while (sample_to_group.grouping_type != FOURCC_SEIG && | 
| + reader->HasChild(&sample_to_group)) { | 
| + RCHECK(reader->ReadChild(&sample_to_group)); | 
| + } | 
| 
xhwang
2014/05/01 19:11:28
Why can't we use MaybeReadChild? Is it because the
 
kqyang
2014/05/01 20:26:35
Yes, MaybeReadChild does not tell us whether it re
 | 
| + return true; | 
| } | 
| MovieFragment::MovieFragment() {} |