Always generate version 1 SampleGroupDescription box

Version 0 is obsoleted. Also fixes unittest typos.

Change-Id: I0e536ba316ac07ce939dae71752e00db19e3db58
This commit is contained in:
KongQun Yang 2014-05-07 14:57:39 -07:00
parent 80a60b7ef2
commit 49dd6e49bb
2 changed files with 18 additions and 33 deletions

View File

@ -1666,7 +1666,7 @@ bool SampleGroupDescription::ReadWrite(BoxBuffer* buffer) {
if (version == 1) { if (version == 1) {
if (buffer->Reading()) { if (buffer->Reading()) {
RCHECK(buffer->ReadWriteUInt32(&default_length)); RCHECK(buffer->ReadWriteUInt32(&default_length));
RCHECK(default_length == 0 || default_length == kEntrySize); RCHECK(default_length == 0 || default_length >= kEntrySize);
} else { } else {
default_length = kEntrySize; default_length = kEntrySize;
RCHECK(buffer->ReadWriteUInt32(&default_length)); RCHECK(buffer->ReadWriteUInt32(&default_length));
@ -1681,7 +1681,7 @@ bool SampleGroupDescription::ReadWrite(BoxBuffer* buffer) {
if (buffer->Reading() && default_length == 0) { if (buffer->Reading() && default_length == 0) {
uint32 description_length = 0; uint32 description_length = 0;
RCHECK(buffer->ReadWriteUInt32(&description_length)); RCHECK(buffer->ReadWriteUInt32(&description_length));
RCHECK(description_length == kEntrySize); RCHECK(description_length >= kEntrySize);
} }
} }
@ -1707,6 +1707,8 @@ bool SampleGroupDescription::ReadWrite(BoxBuffer* buffer) {
} }
uint32 SampleGroupDescription::ComputeSize() { uint32 SampleGroupDescription::ComputeSize() {
// Version 0 is obsoleted, so always generate version 1 box.
version = 1;
// This box is optional. Skip it if it is not used. // This box is optional. Skip it if it is not used.
atom_size = 0; atom_size = 0;
if (!entries.empty()) { if (!entries.empty()) {
@ -1733,6 +1735,10 @@ bool TrackFragment::ReadWrite(BoxBuffer* buffer) {
DCHECK(buffer->reader()); DCHECK(buffer->reader());
RCHECK(buffer->reader()->TryReadChildren(&runs)); RCHECK(buffer->reader()->TryReadChildren(&runs));
// 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_to_group.grouping_type != FOURCC_SEIG && while (sample_to_group.grouping_type != FOURCC_SEIG &&
buffer->reader()->ChildExist(&sample_to_group)) { buffer->reader()->ChildExist(&sample_to_group)) {
RCHECK(buffer->reader()->ReadChild(&sample_to_group)); RCHECK(buffer->reader()->ReadChild(&sample_to_group));
@ -1741,32 +1747,6 @@ bool TrackFragment::ReadWrite(BoxBuffer* buffer) {
buffer->reader()->ChildExist(&sample_group_description)) { buffer->reader()->ChildExist(&sample_group_description)) {
RCHECK(buffer->reader()->ReadChild(&sample_group_description)); RCHECK(buffer->reader()->ReadChild(&sample_group_description));
} }
if (sample_to_group.grouping_type == FOURCC_SEIG) {
// SampleGroupDescription box can appear in either 'moov...stbl' or
// 'moov.traf'. The first case is not supported for now, so we require
// a companion SampleGroupDescription box to coexist with the
// SampleToGroup box.
if (sample_group_description.grouping_type != FOURCC_SEIG) {
NOTIMPLEMENTED()
<< "SampleGroupDescription box in 'moov' is not supported.";
return false;
}
for (std::vector<SampleToGroupEntry>::iterator it =
sample_to_group.entries.begin();
it != sample_to_group.entries.end();
++it) {
if ((it->group_description_index & 0x10000) == 0) {
NOTIMPLEMENTED()
<< "SampleGroupDescription box in 'moov' is not supported.";
return false;
}
it->group_description_index &= 0x0FFFF;
RCHECK(it->group_description_index <=
sample_group_description.entries.size());
}
} else {
RCHECK(sample_group_description.grouping_type != FOURCC_SEIG);
}
} else { } else {
for (uint32 i = 0; i < runs.size(); ++i) for (uint32 i = 0; i < runs.size(); ++i)
RCHECK(runs[i].ReadWrite(buffer)); RCHECK(runs[i].ReadWrite(buffer));

View File

@ -630,12 +630,13 @@ class BoxDefinitionsTestGeneral : public testing::Test {
sbgp->entries.resize(2); sbgp->entries.resize(2);
sbgp->entries[0].sample_count = 3; sbgp->entries[0].sample_count = 3;
sbgp->entries[0].group_description_index = 0x10002; sbgp->entries[0].group_description_index = 0x10002;
sbgp->entries[0].sample_count = 1212; sbgp->entries[1].sample_count = 1212;
sbgp->entries[0].group_description_index = 0x10001; sbgp->entries[1].group_description_index = 0x10001;
} }
void Modify(SampleToGroup* sbgp) { void Modify(SampleToGroup* sbgp) {
sbgp->entries.resize(1); sbgp->entries.resize(1);
sbgp->entries[0].sample_count = 5;
sbgp->entries[0].group_description_index = 0x10001; sbgp->entries[0].group_description_index = 0x10001;
} }
@ -649,11 +650,13 @@ class BoxDefinitionsTestGeneral : public testing::Test {
sgpd->entries[1].is_encrypted = false; sgpd->entries[1].is_encrypted = false;
sgpd->entries[1].iv_size = 0; sgpd->entries[1].iv_size = 0;
sgpd->entries[1].key_id.resize(16); sgpd->entries[1].key_id.resize(16);
sgpd->version = 1;
} }
void Modify(SampleGroupDescription* sbgp) { void Modify(SampleGroupDescription* sgpd) {
sbgp->entries.resize(1); sgpd->entries.resize(1);
sbgp->entries[0].key_id[4] = 88; sgpd->entries[0].key_id[4] = 88;
sgpd->version = 1;
} }
void Fill(TrackFragment* traf) { void Fill(TrackFragment* traf) {
@ -668,6 +671,8 @@ class BoxDefinitionsTestGeneral : public testing::Test {
void Modify(TrackFragment* traf) { void Modify(TrackFragment* traf) {
Modify(&traf->header); Modify(&traf->header);
Modify(&traf->decode_time); Modify(&traf->decode_time);
Fill(&traf->sample_to_group);
Fill(&traf->sample_group_description);
} }
void Fill(MovieFragment* moof) { void Fill(MovieFragment* moof) {