Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Unified Diff: media/formats/mp4/box_definitions.cc

Issue 260963002: Support parsing of sgpd and sbgp boxes (Closed) Base URL: http://git.chromium.org/chromium/src.git@temp
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/formats/mp4/box_definitions.h ('k') | media/formats/mp4/box_reader.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/formats/mp4/box_definitions.cc
diff --git a/media/formats/mp4/box_definitions.cc b/media/formats/mp4/box_definitions.cc
index 5b67633252c58565a15da78626f328e7237351cd..f3d8db24a244b21c01ddaa8a4697771f47492ec1 100644
--- a/media/formats/mp4/box_definitions.cc
+++ b/media/formats/mp4/box_definitions.cc
@@ -771,19 +771,116 @@ 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));
+
+ // There could be multiple SampleGroupDescription and SampleToGroup boxes with
+ // different grouping types. For common encryption, the relevant grouping type
+ // is 'seig'. Continue reading until 'seig' is found, or until running 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));
+ }
+ return true;
}
MovieFragment::MovieFragment() {}
« no previous file with comments | « media/formats/mp4/box_definitions.h ('k') | media/formats/mp4/box_reader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698