зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1387798 - move initialized codes out of box constructor to another function which could be able to return error. r=kinetik
MozReview-Commit-ID: 5LJVCTYIT7o --HG-- extra : rebase_source : a87d825abb76b5c9410eee1b996f3559ca7153d7
This commit is contained in:
Родитель
9bc0b0adbc
Коммит
e707fdfbf4
|
@ -705,11 +705,19 @@ Moof::ParseTrun(Box& aBox, Tfhd& aTfhd, Mvhd& aMvhd, Mdhd& aMdhd, Edts& aEdts, u
|
|||
}
|
||||
|
||||
Tkhd::Tkhd(Box& aBox)
|
||||
{
|
||||
if (Parse(aBox)) {
|
||||
mValid = true;
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
Tkhd::Parse(Box& aBox)
|
||||
{
|
||||
BoxReader reader(aBox);
|
||||
if (!reader->CanReadType<uint32_t>()) {
|
||||
LOG(Tkhd, "Incomplete Box (missing flags)");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
uint32_t flags = reader->ReadU32();
|
||||
uint8_t version = flags >> 24;
|
||||
|
@ -718,7 +726,7 @@ Tkhd::Tkhd(Box& aBox)
|
|||
if (reader->Remaining() < need) {
|
||||
LOG(Tkhd, "Incomplete Box (have:%" PRIu64 " need:%" PRIu64 ")",
|
||||
(uint64_t)reader->Remaining(), (uint64_t)need);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
if (version == 0) {
|
||||
mCreationTime = reader->ReadU32();
|
||||
|
@ -735,16 +743,23 @@ Tkhd::Tkhd(Box& aBox)
|
|||
NS_ASSERTION(!reserved, "reserved should be 0");
|
||||
mDuration = reader->ReadU64();
|
||||
}
|
||||
// We don't care about whatever else may be in the box.
|
||||
mValid = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
Mvhd::Mvhd(Box& aBox)
|
||||
{
|
||||
if (Parse(aBox)) {
|
||||
mValid = true;
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
Mvhd::Parse(Box& aBox)
|
||||
{
|
||||
BoxReader reader(aBox);
|
||||
if (!reader->CanReadType<uint32_t>()) {
|
||||
LOG(Mdhd, "Incomplete Box (missing flags)");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
uint32_t flags = reader->ReadU32();
|
||||
uint8_t version = flags >> 24;
|
||||
|
@ -753,7 +768,7 @@ Mvhd::Mvhd(Box& aBox)
|
|||
if (reader->Remaining() < need) {
|
||||
LOG(Mvhd, "Incomplete Box (have:%" PRIu64 " need:%" PRIu64 ")",
|
||||
(uint64_t)reader->Remaining(), (uint64_t)need);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (version == 0) {
|
||||
|
@ -767,12 +782,9 @@ Mvhd::Mvhd(Box& aBox)
|
|||
mTimescale = reader->ReadU32();
|
||||
mDuration = reader->ReadU64();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
// We don't care about whatever else may be in the box.
|
||||
if (mTimescale) {
|
||||
mValid = true;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Mdhd::Mdhd(Box& aBox)
|
||||
|
@ -781,12 +793,20 @@ Mdhd::Mdhd(Box& aBox)
|
|||
}
|
||||
|
||||
Trex::Trex(Box& aBox)
|
||||
{
|
||||
if (Parse(aBox)) {
|
||||
mValid = true;
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
Trex::Parse(Box& aBox)
|
||||
{
|
||||
BoxReader reader(aBox);
|
||||
if (reader->Remaining() < 6*sizeof(uint32_t)) {
|
||||
LOG(Trex, "Incomplete Box (have:%" PRIu64 " need:%" PRIu64 ")",
|
||||
(uint64_t)reader->Remaining(), (uint64_t)6*sizeof(uint32_t));
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
mFlags = reader->ReadU32();
|
||||
mTrackId = reader->ReadU32();
|
||||
|
@ -794,11 +814,19 @@ Trex::Trex(Box& aBox)
|
|||
mDefaultSampleDuration = reader->ReadU32();
|
||||
mDefaultSampleSize = reader->ReadU32();
|
||||
mDefaultSampleFlags = reader->ReadU32();
|
||||
mValid = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
Tfhd::Tfhd(Box& aBox, Trex& aTrex)
|
||||
: Trex(aTrex)
|
||||
{
|
||||
if (Parse(aBox)) {
|
||||
mValid = true;
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
Tfhd::Parse(Box& aBox)
|
||||
{
|
||||
MOZ_ASSERT(aBox.IsType("tfhd"));
|
||||
MOZ_ASSERT(aBox.Parent()->IsType("traf"));
|
||||
|
@ -807,7 +835,7 @@ Tfhd::Tfhd(Box& aBox, Trex& aTrex)
|
|||
BoxReader reader(aBox);
|
||||
if (!reader->CanReadType<uint32_t>()) {
|
||||
LOG(Tfhd, "Incomplete Box (missing flags)");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
mFlags = reader->ReadU32();
|
||||
size_t need = sizeof(uint32_t) /* trackid */;
|
||||
|
@ -821,7 +849,7 @@ Tfhd::Tfhd(Box& aBox, Trex& aTrex)
|
|||
if (reader->Remaining() < need) {
|
||||
LOG(Tfhd, "Incomplete Box (have:%" PRIu64 " need:%" PRIu64 ")",
|
||||
(uint64_t)reader->Remaining(), (uint64_t)need);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
mTrackId = reader->ReadU32();
|
||||
mBaseDataOffset =
|
||||
|
@ -838,15 +866,24 @@ Tfhd::Tfhd(Box& aBox, Trex& aTrex)
|
|||
if (mFlags & 0x20) {
|
||||
mDefaultSampleFlags = reader->ReadU32();
|
||||
}
|
||||
mValid = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Tfdt::Tfdt(Box& aBox)
|
||||
{
|
||||
if (Parse(aBox)) {
|
||||
mValid = true;
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
Tfdt::Parse(Box& aBox)
|
||||
{
|
||||
BoxReader reader(aBox);
|
||||
if (!reader->CanReadType<uint32_t>()) {
|
||||
LOG(Tfdt, "Incomplete Box (missing flags)");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
uint32_t flags = reader->ReadU32();
|
||||
uint8_t version = flags >> 24;
|
||||
|
@ -854,29 +891,37 @@ Tfdt::Tfdt(Box& aBox)
|
|||
if (reader->Remaining() < need) {
|
||||
LOG(Tfdt, "Incomplete Box (have:%" PRIu64 " need:%" PRIu64 ")",
|
||||
(uint64_t)reader->Remaining(), (uint64_t)need);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
if (version == 0) {
|
||||
mBaseMediaDecodeTime = reader->ReadU32();
|
||||
} else if (version == 1) {
|
||||
mBaseMediaDecodeTime = reader->ReadU64();
|
||||
}
|
||||
mValid = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
Edts::Edts(Box& aBox)
|
||||
: mMediaStart(0)
|
||||
, mEmptyOffset(0)
|
||||
{
|
||||
if (Parse(aBox)) {
|
||||
mValid = true;
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
Edts::Parse(Box& aBox)
|
||||
{
|
||||
Box child = aBox.FirstChild();
|
||||
if (!child.IsType("elst")) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
BoxReader reader(child);
|
||||
if (!reader->CanReadType<uint32_t>()) {
|
||||
LOG(Edts, "Incomplete Box (missing flags)");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
uint32_t flags = reader->ReadU32();
|
||||
uint8_t version = flags >> 24;
|
||||
|
@ -885,7 +930,7 @@ Edts::Edts(Box& aBox)
|
|||
if (reader->Remaining() < need) {
|
||||
LOG(Edts, "Incomplete Box (have:%" PRIu64 " need:%" PRIu64 ")",
|
||||
(uint64_t)reader->Remaining(), (uint64_t)need);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
bool emptyEntry = false;
|
||||
uint32_t entryCount = reader->ReadU32();
|
||||
|
@ -912,16 +957,26 @@ Edts::Edts(Box& aBox)
|
|||
}
|
||||
reader->ReadU32(); // media_rate_integer and media_rate_fraction
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Saiz::Saiz(Box& aBox, AtomType aDefaultType)
|
||||
: mAuxInfoType(aDefaultType)
|
||||
, mAuxInfoTypeParameter(0)
|
||||
{
|
||||
if (Parse(aBox)) {
|
||||
mValid = true;
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
Saiz::Parse(Box& aBox)
|
||||
{
|
||||
BoxReader reader(aBox);
|
||||
if (!reader->CanReadType<uint32_t>()) {
|
||||
LOG(Saiz, "Incomplete Box (missing flags)");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
uint32_t flags = reader->ReadU32();
|
||||
uint8_t version = flags >> 24;
|
||||
|
@ -930,7 +985,7 @@ Saiz::Saiz(Box& aBox, AtomType aDefaultType)
|
|||
if (reader->Remaining() < need) {
|
||||
LOG(Saiz, "Incomplete Box (have:%" PRIu64 " need:%" PRIu64 ")",
|
||||
(uint64_t)reader->Remaining(), (uint64_t)need);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
if (flags & 1) {
|
||||
mAuxInfoType = reader->ReadU32();
|
||||
|
@ -941,26 +996,34 @@ Saiz::Saiz(Box& aBox, AtomType aDefaultType)
|
|||
if (defaultSampleInfoSize) {
|
||||
if (!mSampleInfoSize.SetLength(count, fallible)) {
|
||||
LOG(Saiz, "OOM");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
memset(mSampleInfoSize.Elements(), defaultSampleInfoSize, mSampleInfoSize.Length());
|
||||
} else {
|
||||
if (!reader->ReadArray(mSampleInfoSize, count)) {
|
||||
LOG(Saiz, "Incomplete Box (OOM or missing count:%u)", count);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
mValid = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
Saio::Saio(Box& aBox, AtomType aDefaultType)
|
||||
: mAuxInfoType(aDefaultType)
|
||||
, mAuxInfoTypeParameter(0)
|
||||
{
|
||||
if (Parse(aBox)) {
|
||||
mValid = true;
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
Saio::Parse(Box& aBox)
|
||||
{
|
||||
BoxReader reader(aBox);
|
||||
if (!reader->CanReadType<uint32_t>()) {
|
||||
LOG(Saio, "Incomplete Box (missing flags)");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
uint32_t flags = reader->ReadU32();
|
||||
uint8_t version = flags >> 24;
|
||||
|
@ -968,7 +1031,7 @@ Saio::Saio(Box& aBox, AtomType aDefaultType)
|
|||
if (reader->Remaining() < need) {
|
||||
LOG(Saio, "Incomplete Box (have:%" PRIu64 " need:%" PRIu64 ")",
|
||||
(uint64_t)reader->Remaining(), (uint64_t)need);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
if (flags & 1) {
|
||||
mAuxInfoType = reader->ReadU32();
|
||||
|
@ -979,11 +1042,11 @@ Saio::Saio(Box& aBox, AtomType aDefaultType)
|
|||
if (reader->Remaining() < need) {
|
||||
LOG(Saio, "Incomplete Box (have:%" PRIu64 " need:%" PRIu64 ")",
|
||||
(uint64_t)reader->Remaining(), (uint64_t)need);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
if (!mOffsets.SetCapacity(count, fallible)) {
|
||||
LOG(Saiz, "OOM");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
if (version == 0) {
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
|
@ -994,16 +1057,24 @@ Saio::Saio(Box& aBox, AtomType aDefaultType)
|
|||
MOZ_ALWAYS_TRUE(mOffsets.AppendElement(reader->ReadU64(), fallible));
|
||||
}
|
||||
}
|
||||
mValid = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
Sbgp::Sbgp(Box& aBox)
|
||||
{
|
||||
if (Parse(aBox)) {
|
||||
mValid = true;
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
Sbgp::Parse(Box& aBox)
|
||||
{
|
||||
BoxReader reader(aBox);
|
||||
|
||||
if (!reader->CanReadType<uint32_t>()) {
|
||||
LOG(Sbgp, "Incomplete Box (missing flags)");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t flags = reader->ReadU32();
|
||||
|
@ -1015,7 +1086,7 @@ Sbgp::Sbgp(Box& aBox)
|
|||
if (reader->Remaining() < need) {
|
||||
LOG(Sbgp, "Incomplete Box (have:%" PRIu64 ", need:%" PRIu64 ")",
|
||||
(uint64_t)reader->Remaining(), (uint64_t)need);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
mGroupingType = reader->ReadU32();
|
||||
|
@ -1031,7 +1102,7 @@ Sbgp::Sbgp(Box& aBox)
|
|||
if (reader->Remaining() < need) {
|
||||
LOG(Sbgp, "Incomplete Box (have:%" PRIu64 ", need:%" PRIu64 "). Failed to read entries",
|
||||
(uint64_t)reader->Remaining(), (uint64_t)need);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < count; i++) {
|
||||
|
@ -1041,20 +1112,27 @@ Sbgp::Sbgp(Box& aBox)
|
|||
SampleToGroupEntry entry(sampleCount, groupDescriptionIndex);
|
||||
if (!mEntries.AppendElement(entry, mozilla::fallible)) {
|
||||
LOG(Sbgp, "OOM");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
mValid = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
Sgpd::Sgpd(Box& aBox)
|
||||
{
|
||||
if (Parse(aBox)) {
|
||||
mValid = true;
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
Sgpd::Parse(Box& aBox)
|
||||
{
|
||||
BoxReader reader(aBox);
|
||||
|
||||
if (!reader->CanReadType<uint32_t>()) {
|
||||
LOG(Sgpd, "Incomplete Box (missing flags)");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t flags = reader->ReadU32();
|
||||
|
@ -1065,7 +1143,7 @@ Sgpd::Sgpd(Box& aBox)
|
|||
if (reader->Remaining() < need) {
|
||||
LOG(Sgpd, "Incomplete Box (have:%" PRIu64 " need:%" PRIu64 ")",
|
||||
(uint64_t)reader->Remaining(), (uint64_t)need);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
mGroupingType = reader->ReadU32();
|
||||
|
@ -1076,7 +1154,7 @@ Sgpd::Sgpd(Box& aBox)
|
|||
if (version == 1) {
|
||||
defaultLength = reader->ReadU32();
|
||||
if (defaultLength < entrySize && defaultLength != 0) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1089,28 +1167,27 @@ Sgpd::Sgpd(Box& aBox)
|
|||
if (reader->Remaining() < need) {
|
||||
LOG(Sgpd, "Incomplete Box (have:%" PRIu64 " need:%" PRIu64 "). Failed to read entries",
|
||||
(uint64_t)reader->Remaining(), (uint64_t)need);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
for (uint32_t i = 0; i < count; ++i) {
|
||||
if (version == 1 && defaultLength == 0) {
|
||||
uint32_t descriptionLength = reader->ReadU32();
|
||||
if (descriptionLength < entrySize) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
CencSampleEncryptionInfoEntry entry;
|
||||
bool valid = entry.Init(reader);
|
||||
if (!valid) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
if (!mEntries.AppendElement(entry, mozilla::fallible)) {
|
||||
LOG(Sgpd, "OOM");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
mValid = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CencSampleEncryptionInfoEntry::Init(BoxReader& aReader)
|
||||
|
|
|
@ -43,6 +43,9 @@ public:
|
|||
uint64_t mModificationTime;
|
||||
uint32_t mTimescale;
|
||||
uint64_t mDuration;
|
||||
|
||||
protected:
|
||||
bool Parse(Box& aBox);
|
||||
};
|
||||
|
||||
class Tkhd : public Mvhd
|
||||
|
@ -55,6 +58,9 @@ public:
|
|||
explicit Tkhd(Box& aBox);
|
||||
|
||||
uint32_t mTrackId;
|
||||
|
||||
protected:
|
||||
bool Parse(Box& aBox);
|
||||
};
|
||||
|
||||
class Mdhd : public Mvhd
|
||||
|
@ -85,6 +91,9 @@ public:
|
|||
uint32_t mDefaultSampleDuration;
|
||||
uint32_t mDefaultSampleSize;
|
||||
uint32_t mDefaultSampleFlags;
|
||||
|
||||
protected:
|
||||
bool Parse(Box& aBox);
|
||||
};
|
||||
|
||||
class Tfhd : public Trex
|
||||
|
@ -99,6 +108,9 @@ public:
|
|||
Tfhd(Box& aBox, Trex& aTrex);
|
||||
|
||||
uint64_t mBaseDataOffset;
|
||||
|
||||
protected:
|
||||
bool Parse(Box& aBox);
|
||||
};
|
||||
|
||||
class Tfdt : public Atom
|
||||
|
@ -111,6 +123,9 @@ public:
|
|||
explicit Tfdt(Box& aBox);
|
||||
|
||||
uint64_t mBaseMediaDecodeTime;
|
||||
|
||||
protected:
|
||||
bool Parse(Box& aBox);
|
||||
};
|
||||
|
||||
class Edts : public Atom
|
||||
|
@ -130,6 +145,9 @@ public:
|
|||
|
||||
int64_t mMediaStart;
|
||||
int64_t mEmptyOffset;
|
||||
|
||||
protected:
|
||||
bool Parse(Box& aBox);
|
||||
};
|
||||
|
||||
struct Sample
|
||||
|
@ -149,6 +167,9 @@ public:
|
|||
AtomType mAuxInfoType;
|
||||
uint32_t mAuxInfoTypeParameter;
|
||||
FallibleTArray<uint8_t> mSampleInfoSize;
|
||||
|
||||
protected:
|
||||
bool Parse(Box& aBox);
|
||||
};
|
||||
|
||||
class Saio final : public Atom
|
||||
|
@ -159,6 +180,9 @@ public:
|
|||
AtomType mAuxInfoType;
|
||||
uint32_t mAuxInfoTypeParameter;
|
||||
FallibleTArray<uint64_t> mOffsets;
|
||||
|
||||
protected:
|
||||
bool Parse(Box& aBox);
|
||||
};
|
||||
|
||||
struct SampleToGroupEntry
|
||||
|
@ -185,6 +209,9 @@ public:
|
|||
AtomType mGroupingType;
|
||||
uint32_t mGroupingTypeParam;
|
||||
FallibleTArray<SampleToGroupEntry> mEntries;
|
||||
|
||||
protected:
|
||||
bool Parse(Box& aBox);
|
||||
};
|
||||
|
||||
struct CencSampleEncryptionInfoEntry final
|
||||
|
@ -206,6 +233,9 @@ public:
|
|||
|
||||
AtomType mGroupingType;
|
||||
FallibleTArray<CencSampleEncryptionInfoEntry> mEntries;
|
||||
|
||||
protected:
|
||||
bool Parse(Box& aBox);
|
||||
};
|
||||
|
||||
class AuxInfo {
|
||||
|
|
Загрузка…
Ссылка в новой задаче