tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 6d841bcf77022a23cf06707e79b3f4f9f70da542
parent 475391209e7ed897fa60bd82ac0c3634132289a0
Author: Karl Tomlinson <karlt+@karlt.net>
Date:   Wed, 10 Dec 2025 20:57:03 +0000

Bug 2004858 Declare remaining Box reference parameters in Moof as const r=ArnaudBienner,media-playback-reviewers,chunmin

Depends on D275551

Differential Revision: https://phabricator.services.mozilla.com/D275740

Diffstat:
Mdom/media/mp4/MoofParser.cpp | 55++++++++++++++++++++++++++++---------------------------
Mdom/media/mp4/MoofParser.h | 56++++++++++++++++++++++++++++----------------------------
Mdom/media/mp4/SinfParser.cpp | 10+++++-----
Mdom/media/mp4/SinfParser.h | 10+++++-----
4 files changed, 66 insertions(+), 65 deletions(-)

diff --git a/dom/media/mp4/MoofParser.cpp b/dom/media/mp4/MoofParser.cpp @@ -259,7 +259,7 @@ bool MoofParser::ReachedEnd() { return mSource->Length(&length) && mOffset == length; } -void MoofParser::ParseMoov(Box& aBox) { +void MoofParser::ParseMoov(const Box& aBox) { LOG_DEBUG(Moof, "Starting."); for (Box box = aBox.FirstChild(); box.IsAvailable(); box = box.Next()) { if (box.IsType("mvhd")) { @@ -273,7 +273,7 @@ void MoofParser::ParseMoov(Box& aBox) { LOG_DEBUG(Moof, "Done."); } -void MoofParser::ParseTrak(Box& aBox) { +void MoofParser::ParseTrak(const Box& aBox) { LOG_DEBUG(Trak, "Starting."); Tkhd tkhd; for (Box box = aBox.FirstChild(); box.IsAvailable(); box = box.Next()) { @@ -293,7 +293,7 @@ void MoofParser::ParseTrak(Box& aBox) { LOG_DEBUG(Trak, "Done."); } -void MoofParser::ParseMdia(Box& aBox) { +void MoofParser::ParseMdia(const Box& aBox) { LOG_DEBUG(Mdia, "Starting."); for (Box box = aBox.FirstChild(); box.IsAvailable(); box = box.Next()) { if (box.IsType("mdhd")) { @@ -305,7 +305,7 @@ void MoofParser::ParseMdia(Box& aBox) { LOG_DEBUG(Mdia, "Done."); } -void MoofParser::ParseMvex(Box& aBox) { +void MoofParser::ParseMvex(const Box& aBox) { LOG_DEBUG(Mvex, "Starting."); for (Box box = aBox.FirstChild(); box.IsAvailable(); box = box.Next()) { if (box.IsType("trex")) { @@ -319,7 +319,7 @@ void MoofParser::ParseMvex(Box& aBox) { LOG_DEBUG(Mvex, "Done."); } -void MoofParser::ParseMinf(Box& aBox) { +void MoofParser::ParseMinf(const Box& aBox) { LOG_DEBUG(Minf, "Starting."); for (Box box = aBox.FirstChild(); box.IsAvailable(); box = box.Next()) { if (box.IsType("stbl")) { @@ -329,7 +329,7 @@ void MoofParser::ParseMinf(Box& aBox) { LOG_DEBUG(Minf, "Done."); } -void MoofParser::ParseStbl(Box& aBox) { +void MoofParser::ParseStbl(const Box& aBox) { LOG_DEBUG(Stbl, "Starting."); for (Box box = aBox.FirstChild(); box.IsAvailable(); box = box.Next()) { if (box.IsType("stsd")) { @@ -359,7 +359,7 @@ void MoofParser::ParseStbl(Box& aBox) { LOG_DEBUG(Stbl, "Done."); } -void MoofParser::ParseStsd(Box& aBox) { +void MoofParser::ParseStsd(const Box& aBox) { LOG_DEBUG(Stsd, "Starting."); if (mTrackParseMode.is<ParseAllTracks>()) { // It is not a sane operation to try and map sample description boxes from @@ -402,7 +402,7 @@ void MoofParser::ParseStsd(Box& aBox) { numberEncryptedEntries, mSampleDescriptions.Length()); } -void MoofParser::ParseEncrypted(Box& aBox) { +void MoofParser::ParseEncrypted(const Box& aBox) { LOG_DEBUG(Moof, "Starting."); for (Box box = aBox.FirstChild(); box.IsAvailable(); box = box.Next()) { // Some MP4 files have been found to have multiple sinf boxes in the same @@ -1009,14 +1009,14 @@ Result<Ok, nsresult> Moof::ParseTrun(const Box& aBox, const Mvhd& aMvhd, return Ok(); } -Tkhd::Tkhd(Box& aBox) : mTrackId(0) { +Tkhd::Tkhd(const Box& aBox) : mTrackId(0) { mValid = Parse(aBox).isOk(); if (!mValid) { LOG_WARN(Tkhd, "Parse failed"); } } -Result<Ok, nsresult> Tkhd::Parse(Box& aBox) { +Result<Ok, nsresult> Tkhd::Parse(const Box& aBox) { BoxReader reader(aBox); uint32_t flags = MOZ_TRY(reader->ReadU32()); uint8_t version = flags >> 24; @@ -1042,7 +1042,7 @@ Result<Ok, nsresult> Tkhd::Parse(Box& aBox) { return Ok(); } -Mvhd::Mvhd(Box& aBox) +Mvhd::Mvhd(const Box& aBox) : mCreationTime(0), mModificationTime(0), mTimescale(0), mDuration(0) { mValid = Parse(aBox).isOk(); if (!mValid) { @@ -1050,7 +1050,7 @@ Mvhd::Mvhd(Box& aBox) } } -Result<Ok, nsresult> Mvhd::Parse(Box& aBox) { +Result<Ok, nsresult> Mvhd::Parse(const Box& aBox) { BoxReader reader(aBox); uint32_t flags = MOZ_TRY(reader->ReadU32()); @@ -1075,7 +1075,7 @@ Result<Ok, nsresult> Mvhd::Parse(Box& aBox) { return Ok(); } -Mdhd::Mdhd(Box& aBox) : Mvhd(aBox) {} +Mdhd::Mdhd(const Box& aBox) : Mvhd(aBox) {} Trex::Trex(const Box& aBox) : mFlags(0), @@ -1103,14 +1103,15 @@ Result<Ok, nsresult> Trex::Parse(const Box& aBox) { return Ok(); } -Tfhd::Tfhd(Box& aBox, const Trex& aTrex) : Trex(aTrex), mBaseDataOffset(0) { +Tfhd::Tfhd(const Box& aBox, const Trex& aTrex) + : Trex(aTrex), mBaseDataOffset(0) { mValid = Parse(aBox).isOk(); if (!mValid) { LOG_WARN(Tfhd, "Parse failed"); } } -Result<Ok, nsresult> Tfhd::Parse(Box& aBox) { +Result<Ok, nsresult> Tfhd::Parse(const Box& aBox) { MOZ_ASSERT(aBox.IsType("tfhd")); MOZ_ASSERT(aBox.Parent()->IsType("traf")); MOZ_ASSERT(aBox.Parent()->Parent()->IsType("moof")); @@ -1139,14 +1140,14 @@ Result<Ok, nsresult> Tfhd::Parse(Box& aBox) { return Ok(); } -Tfdt::Tfdt(Box& aBox) : mBaseMediaDecodeTime(0) { +Tfdt::Tfdt(const Box& aBox) : mBaseMediaDecodeTime(0) { mValid = Parse(aBox).isOk(); if (!mValid) { LOG_WARN(Tfdt, "Parse failed"); } } -Result<Ok, nsresult> Tfdt::Parse(Box& aBox) { +Result<Ok, nsresult> Tfdt::Parse(const Box& aBox) { BoxReader reader(aBox); uint32_t flags = MOZ_TRY(reader->ReadU32()); @@ -1159,14 +1160,14 @@ Result<Ok, nsresult> Tfdt::Parse(Box& aBox) { return Ok(); } -Edts::Edts(Box& aBox) : mMediaStart(0), mEmptyOffset(0) { +Edts::Edts(const Box& aBox) : mMediaStart(0), mEmptyOffset(0) { mValid = Parse(aBox).isOk(); if (!mValid) { LOG_WARN(Edts, "Parse failed"); } } -Result<Ok, nsresult> Edts::Parse(Box& aBox) { +Result<Ok, nsresult> Edts::Parse(const Box& aBox) { Box child = aBox.FirstChild(); if (!child.IsType("elst")) { return Err(NS_ERROR_FAILURE); @@ -1210,7 +1211,7 @@ Result<Ok, nsresult> Edts::Parse(Box& aBox) { return Ok(); } -Saiz::Saiz(Box& aBox, AtomType aDefaultType) +Saiz::Saiz(const Box& aBox, AtomType aDefaultType) : mAuxInfoType(aDefaultType), mAuxInfoTypeParameter(0) { mValid = Parse(aBox).isOk(); if (!mValid) { @@ -1218,7 +1219,7 @@ Saiz::Saiz(Box& aBox, AtomType aDefaultType) } } -Result<Ok, nsresult> Saiz::Parse(Box& aBox) { +Result<Ok, nsresult> Saiz::Parse(const Box& aBox) { BoxReader reader(aBox); uint32_t flags = MOZ_TRY(reader->ReadU32()); @@ -1244,7 +1245,7 @@ Result<Ok, nsresult> Saiz::Parse(Box& aBox) { return Ok(); } -Saio::Saio(Box& aBox, AtomType aDefaultType) +Saio::Saio(const Box& aBox, AtomType aDefaultType) : mAuxInfoType(aDefaultType), mAuxInfoTypeParameter(0) { mValid = Parse(aBox).isOk(); if (!mValid) { @@ -1252,7 +1253,7 @@ Saio::Saio(Box& aBox, AtomType aDefaultType) } } -Result<Ok, nsresult> Saio::Parse(Box& aBox) { +Result<Ok, nsresult> Saio::Parse(const Box& aBox) { BoxReader reader(aBox); uint32_t flags = MOZ_TRY(reader->ReadU32()); @@ -1281,14 +1282,14 @@ Result<Ok, nsresult> Saio::Parse(Box& aBox) { return Ok(); } -Sbgp::Sbgp(Box& aBox) : mGroupingTypeParam(0) { +Sbgp::Sbgp(const Box& aBox) : mGroupingTypeParam(0) { mValid = Parse(aBox).isOk(); if (!mValid) { LOG_WARN(Sbgp, "Parse failed"); } } -Result<Ok, nsresult> Sbgp::Parse(Box& aBox) { +Result<Ok, nsresult> Sbgp::Parse(const Box& aBox) { BoxReader reader(aBox); uint32_t flags = MOZ_TRY(reader->ReadU32()); @@ -1315,14 +1316,14 @@ Result<Ok, nsresult> Sbgp::Parse(Box& aBox) { return Ok(); } -Sgpd::Sgpd(Box& aBox) { +Sgpd::Sgpd(const Box& aBox) { mValid = Parse(aBox).isOk(); if (!mValid) { LOG_WARN(Sgpd, "Parse failed"); } } -Result<Ok, nsresult> Sgpd::Parse(Box& aBox) { +Result<Ok, nsresult> Sgpd::Parse(const Box& aBox) { BoxReader reader(aBox); uint32_t flags = MOZ_TRY(reader->ReadU32()); diff --git a/dom/media/mp4/MoofParser.h b/dom/media/mp4/MoofParser.h @@ -35,7 +35,7 @@ class Mvhd : public Atom { public: Mvhd() : mCreationTime(0), mModificationTime(0), mTimescale(0), mDuration(0) {} - explicit Mvhd(Box& aBox); + explicit Mvhd(const Box& aBox); Result<media::TimeUnit, nsresult> ToTimeUnit(int64_t aTimescaleUnits) const { if (!mTimescale) { @@ -51,24 +51,24 @@ class Mvhd : public Atom { uint64_t mDuration; protected: - Result<Ok, nsresult> Parse(Box& aBox); + Result<Ok, nsresult> Parse(const Box& aBox); }; class Tkhd : public Mvhd { public: Tkhd() : mTrackId(0) {} - explicit Tkhd(Box& aBox); + explicit Tkhd(const Box& aBox); uint32_t mTrackId; protected: - Result<Ok, nsresult> Parse(Box& aBox); + Result<Ok, nsresult> Parse(const Box& aBox); }; class Mdhd : public Mvhd { public: Mdhd() = default; - explicit Mdhd(Box& aBox); + explicit Mdhd(const Box& aBox); }; class Trex : public Atom { @@ -99,29 +99,29 @@ class Tfhd : public Trex { explicit Tfhd(const Trex& aTrex) : Trex(aTrex), mBaseDataOffset(0) { mValid = aTrex.IsValid(); } - Tfhd(Box& aBox, const Trex& aTrex); + Tfhd(const Box& aBox, const Trex& aTrex); uint64_t mBaseDataOffset; protected: - Result<Ok, nsresult> Parse(Box& aBox); + Result<Ok, nsresult> Parse(const Box& aBox); }; class Tfdt : public Atom { public: Tfdt() : mBaseMediaDecodeTime(0) {} - explicit Tfdt(Box& aBox); + explicit Tfdt(const Box& aBox); uint64_t mBaseMediaDecodeTime; protected: - Result<Ok, nsresult> Parse(Box& aBox); + Result<Ok, nsresult> Parse(const Box& aBox); }; class Edts : public Atom { public: Edts() : mMediaStart(0), mEmptyOffset(0) {} - explicit Edts(Box& aBox); + explicit Edts(const Box& aBox); virtual bool IsValid() const override { // edts is optional return true; @@ -131,7 +131,7 @@ class Edts : public Atom { int64_t mEmptyOffset; protected: - Result<Ok, nsresult> Parse(Box& aBox); + Result<Ok, nsresult> Parse(const Box& aBox); }; struct Sample { @@ -152,26 +152,26 @@ struct Sample { class Saiz final : public Atom { public: - Saiz(Box& aBox, AtomType aDefaultType); + Saiz(const Box& aBox, AtomType aDefaultType); AtomType mAuxInfoType; uint32_t mAuxInfoTypeParameter; FallibleTArray<uint8_t> mSampleInfoSize; protected: - Result<Ok, nsresult> Parse(Box& aBox); + Result<Ok, nsresult> Parse(const Box& aBox); }; class Saio final : public Atom { public: - Saio(Box& aBox, AtomType aDefaultType); + Saio(const Box& aBox, AtomType aDefaultType); AtomType mAuxInfoType; uint32_t mAuxInfoTypeParameter; FallibleTArray<uint64_t> mOffsets; protected: - Result<Ok, nsresult> Parse(Box& aBox); + Result<Ok, nsresult> Parse(const Box& aBox); }; struct SampleToGroupEntry { @@ -190,14 +190,14 @@ struct SampleToGroupEntry { class Sbgp final : public Atom // SampleToGroup box. { public: - explicit Sbgp(Box& aBox); + explicit Sbgp(const Box& aBox); AtomType mGroupingType; uint32_t mGroupingTypeParam; FallibleTArray<SampleToGroupEntry> mEntries; protected: - Result<Ok, nsresult> Parse(Box& aBox); + Result<Ok, nsresult> Parse(const Box& aBox); }; // Stores information form CencSampleEncryptionInformationGroupEntry (seig). @@ -221,13 +221,13 @@ struct CencSampleEncryptionInfoEntry final { class Sgpd final : public Atom // SampleGroupDescription box. { public: - explicit Sgpd(Box& aBox); + explicit Sgpd(const Box& aBox); AtomType mGroupingType; FallibleTArray<CencSampleEncryptionInfoEntry> mEntries; protected: - Result<Ok, nsresult> Parse(Box& aBox); + Result<Ok, nsresult> Parse(const Box& aBox); }; // Audio/video entries from the sample description box (stsd). We only need to @@ -335,15 +335,15 @@ class MoofParser : public DecoderDoctorLifeLogger<MoofParser> { MP4Interval<media::TimeUnit> GetCompositionRange( const mozilla::MediaByteRangeSet& aByteRanges); bool ReachedEnd(); - void ParseMoov(Box& aBox); - void ParseTrak(Box& aBox); - void ParseMdia(Box& aBox); - void ParseMvex(Box& aBox); - - void ParseMinf(Box& aBox); - void ParseStbl(Box& aBox); - void ParseStsd(Box& aBox); - void ParseEncrypted(Box& aBox); + void ParseMoov(const Box& aBox); + void ParseTrak(const Box& aBox); + void ParseMdia(const Box& aBox); + void ParseMvex(const Box& aBox); + + void ParseMinf(const Box& aBox); + void ParseStbl(const Box& aBox); + void ParseStsd(const Box& aBox); + void ParseEncrypted(const Box& aBox); // Similar to RebuildFragmentedIndex(), but advance only as far as the next // moof, only if there is a next moof, and block, waiting for the read, if diff --git a/dom/media/mp4/SinfParser.cpp b/dom/media/mp4/SinfParser.cpp @@ -11,14 +11,14 @@ namespace mozilla { -Sinf::Sinf(Box& aBox) : mDefaultIVSize(0) { +Sinf::Sinf(const Box& aBox) : mDefaultIVSize(0) { SinfParser parser(aBox); if (parser.GetSinf().IsValid()) { *this = parser.GetSinf(); } } -SinfParser::SinfParser(Box& aBox) { +SinfParser::SinfParser(const Box& aBox) { for (Box box = aBox.FirstChild(); box.IsAvailable(); box = box.Next()) { if (box.IsType("schm")) { (void)ParseSchm(box); @@ -28,7 +28,7 @@ SinfParser::SinfParser(Box& aBox) { } } -Result<Ok, nsresult> SinfParser::ParseSchm(Box& aBox) { +Result<Ok, nsresult> SinfParser::ParseSchm(const Box& aBox) { BoxReader reader(aBox); if (reader->Remaining() < 8) { @@ -40,7 +40,7 @@ Result<Ok, nsresult> SinfParser::ParseSchm(Box& aBox) { return Ok(); } -Result<Ok, nsresult> SinfParser::ParseSchi(Box& aBox) { +Result<Ok, nsresult> SinfParser::ParseSchi(const Box& aBox) { for (Box box = aBox.FirstChild(); box.IsAvailable(); box = box.Next()) { if (box.IsType("tenc") && ParseTenc(box).isErr()) { return Err(NS_ERROR_FAILURE); @@ -49,7 +49,7 @@ Result<Ok, nsresult> SinfParser::ParseSchi(Box& aBox) { return Ok(); } -Result<Ok, nsresult> SinfParser::ParseTenc(Box& aBox) { +Result<Ok, nsresult> SinfParser::ParseTenc(const Box& aBox) { BoxReader reader(aBox); if (reader->Remaining() < 24) { diff --git a/dom/media/mp4/SinfParser.h b/dom/media/mp4/SinfParser.h @@ -20,7 +20,7 @@ class Sinf : public Atom { mDefaultCryptByteBlock(0), mDefaultSkipByteBlock(0) {} - explicit Sinf(Box& aBox); + explicit Sinf(const Box& aBox); bool IsValid() const override { return !!mDefaultEncryptionType && // Should have an encryption scheme @@ -38,14 +38,14 @@ class Sinf : public Atom { class SinfParser { public: - explicit SinfParser(Box& aBox); + explicit SinfParser(const Box& aBox); Sinf& GetSinf() { return mSinf; } private: - Result<Ok, nsresult> ParseSchm(Box& aBox); - Result<Ok, nsresult> ParseSchi(Box& aBox); - Result<Ok, nsresult> ParseTenc(Box& aBox); + Result<Ok, nsresult> ParseSchm(const Box& aBox); + Result<Ok, nsresult> ParseSchi(const Box& aBox); + Result<Ok, nsresult> ParseTenc(const Box& aBox); Sinf mSinf; };