commit f7897b977ee8ca03b981540a849b30b7e6048c15
parent 611b8146a7984d3a82f341cae907d3ce010bf07f
Author: Arnaud Bienner <arnaud.bienner@gmail.com>
Date: Mon, 24 Nov 2025 23:56:30 +0000
Bug 2002011 - Add const to some functions and objects in MoofParser. r=karlt,media-playback-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D273846
Diffstat:
2 files changed, 24 insertions(+), 22 deletions(-)
diff --git a/dom/media/mp4/MoofParser.cpp b/dom/media/mp4/MoofParser.cpp
@@ -70,7 +70,7 @@ bool MoofParser::RebuildFragmentedIndex(BoxContext& aContext) {
ParseMoov(box);
} else if (box.IsType("moof")) {
Moof moof(box, mTrackParseMode, mTrex, mMvhd, mMdhd, mEdts, mSinf,
- &mLastDecodeTime, mIsAudio, mTracksEndCts);
+ mIsAudio, &mLastDecodeTime, mTracksEndCts);
if (!moof.IsValid()) {
continue; // Skip to next box.
@@ -430,8 +430,8 @@ class CtsComparator {
};
Moof::Moof(Box& aBox, const TrackParseMode& aTrackParseMode, Trex& aTrex,
- Mvhd& aMvhd, Mdhd& aMdhd, Edts& aEdts, const Sinf& aSinf,
- uint64_t* aDecodeTime, bool aIsAudio,
+ const Mvhd& aMvhd, const Mdhd& aMdhd, const Edts& aEdts,
+ const Sinf& aSinf, const bool aIsAudio, uint64_t* aDecodeTime,
nsTArray<TrackEndCts>& aTracksEndCts)
: mRange(aBox.Range()),
mTfhd(aTrex),
@@ -452,7 +452,7 @@ Moof::Moof(Box& aBox, const TrackParseMode& aTrackParseMode, Trex& aTrex,
for (Box box = aBox.FirstChild(); box.IsAvailable(); box = box.Next()) {
if (box.IsType("traf")) {
ParseTraf(box, aTrackParseMode, aTrex, aMvhd, aMdhd, aEdts, aSinf,
- aDecodeTime, aIsAudio);
+ aIsAudio, aDecodeTime);
}
if (box.IsType("pssh")) {
psshBoxes.AppendElement(box);
@@ -528,8 +528,8 @@ Moof::Moof(Box& aBox, const TrackParseMode& aTrackParseMode, Trex& aTrex,
TimeUnit presentationDuration =
ctsOrder.LastElement()->mCompositionRange.end -
ctsOrder[0]->mCompositionRange.start;
- auto decodeOffset =
- aMdhd.ToTimeUnit((int64_t)*aDecodeTime - aEdts.mMediaStart);
+ auto decodeOffset = aMdhd.ToTimeUnit(static_cast<int64_t>(*aDecodeTime) -
+ aEdts.mMediaStart);
auto offsetOffset = aMvhd.ToTimeUnit(aEdts.mEmptyOffset);
TimeUnit endDecodeTime =
(decodeOffset.isOk() && offsetOffset.isOk())
@@ -726,8 +726,9 @@ const CencSampleEncryptionInfoEntry* Moof::GetSampleEncryptionEntry(
}
void Moof::ParseTraf(Box& aBox, const TrackParseMode& aTrackParseMode,
- Trex& aTrex, Mvhd& aMvhd, Mdhd& aMdhd, Edts& aEdts,
- const Sinf& aSinf, uint64_t* aDecodeTime, bool aIsAudio) {
+ Trex& aTrex, const Mvhd& aMvhd, const Mdhd& aMdhd,
+ const Edts& aEdts, const Sinf& aSinf, const bool aIsAudio,
+ uint64_t* aDecodeTime) {
LOG_DEBUG(
Traf,
"Starting, aTrackParseMode=%s, track#=%" PRIu32
@@ -798,7 +799,7 @@ void Moof::ParseTraf(Box& aBox, const TrackParseMode& aTrackParseMode,
Box sencBox;
for (Box box = aBox.FirstChild(); box.IsAvailable(); box = box.Next()) {
if (box.IsType("trun")) {
- if (ParseTrun(box, aMvhd, aMdhd, aEdts, &decodeTime, aIsAudio).isOk()) {
+ if (ParseTrun(box, aMvhd, aMdhd, aEdts, aIsAudio, &decodeTime).isOk()) {
mValid = true;
} else {
LOG_WARN(Moof, "ParseTrun failed");
@@ -909,9 +910,10 @@ Result<Ok, nsresult> Moof::ParseSenc(Box& aBox, const Sinf& aSinf) {
return Ok();
}
-Result<Ok, nsresult> Moof::ParseTrun(Box& aBox, Mvhd& aMvhd, Mdhd& aMdhd,
- Edts& aEdts, uint64_t* aDecodeTime,
- bool aIsAudio) {
+Result<Ok, nsresult> Moof::ParseTrun(Box& aBox, const Mvhd& aMvhd,
+ const Mdhd& aMdhd, const Edts& aEdts,
+ const bool aIsAudio,
+ uint64_t* aDecodeTime) {
LOG_DEBUG(Trun, "Starting.");
if (!mTfhd.IsValid() || !aMvhd.IsValid() || !aMdhd.IsValid() ||
!aEdts.IsValid()) {
diff --git a/dom/media/mp4/MoofParser.h b/dom/media/mp4/MoofParser.h
@@ -37,7 +37,7 @@ class Mvhd : public Atom {
: mCreationTime(0), mModificationTime(0), mTimescale(0), mDuration(0) {}
explicit Mvhd(Box& aBox);
- Result<media::TimeUnit, nsresult> ToTimeUnit(int64_t aTimescaleUnits) {
+ Result<media::TimeUnit, nsresult> ToTimeUnit(int64_t aTimescaleUnits) const {
if (!mTimescale) {
NS_WARNING("invalid mTimescale");
return Err(NS_ERROR_FAILURE);
@@ -247,8 +247,8 @@ using TrackParseMode = Variant<ParseAllTracks, uint32_t>;
class Moof final : public Atom {
public:
Moof(Box& aBox, const TrackParseMode& aTrackParseMode, Trex& aTrex,
- Mvhd& aMvhd, Mdhd& aMdhd, Edts& aEdts, const Sinf& aSinf,
- uint64_t* aDecodeTime, bool aIsAudio,
+ const Mvhd& aMvhd, const Mdhd& aMdhd, const Edts& aEdts,
+ const Sinf& aSinf, const bool aIsAudio, uint64_t* aDecodeTime,
nsTArray<TrackEndCts>& aTracksEndCts);
void FixRounding(const Moof& aMoof);
@@ -283,12 +283,12 @@ class Moof final : public Atom {
private:
// aDecodeTime is updated to the end of the parsed TRAF on return.
void ParseTraf(Box& aBox, const TrackParseMode& aTrackParseMode, Trex& aTrex,
- Mvhd& aMvhd, Mdhd& aMdhd, Edts& aEdts, const Sinf& aSinf,
- uint64_t* aDecodeTime, bool aIsAudio);
+ const Mvhd& aMvhd, const Mdhd& aMdhd, const Edts& aEdts,
+ const Sinf& aSinf, const bool aIsAudio, uint64_t* aDecodeTime);
// aDecodeTime is updated to the end of the parsed TRUN on return.
- Result<Ok, nsresult> ParseTrun(Box& aBox, Mvhd& aMvhd, Mdhd& aMdhd,
- Edts& aEdts, uint64_t* aDecodeTime,
- bool aIsAudio);
+ Result<Ok, nsresult> ParseTrun(Box& aBox, const Mvhd& aMvhd,
+ const Mdhd& aMdhd, const Edts& aEdts,
+ const bool aIsAudio, uint64_t* aDecodeTime);
Result<Ok, nsresult> ParseSenc(Box& aBox, const Sinf& aSinf);
// Process the sample auxiliary information used by common encryption.
// aScheme is used to select the appropriate auxiliary information and should
@@ -308,7 +308,7 @@ DDLoggedTypeDeclName(MoofParser);
class MoofParser : public DecoderDoctorLifeLogger<MoofParser> {
public:
MoofParser(ByteStream* aSource, const TrackParseMode& aTrackParseMode,
- bool aIsAudio)
+ const bool aIsAudio)
: mSource(aSource),
mOffset(0),
mTrex(aTrackParseMode.is<uint32_t>() ? aTrackParseMode.as<uint32_t>()
@@ -381,7 +381,7 @@ class MoofParser : public DecoderDoctorLifeLogger<MoofParser> {
nsTArray<Moof> mMoofs;
nsTArray<MediaByteRange> mMediaRanges;
nsTArray<TrackEndCts> mTracksEndCts;
- bool mIsAudio;
+ const bool mIsAudio;
uint64_t mLastDecodeTime;
// Either a ParseAllTracks if in multitrack mode, or an integer representing
// the track_id for the track being parsed. If parsing a specific track, mTrex