Bug 1525646 - Improve logging in MoofParser. r=jya
authorBryce Van Dyk <bvandyk@mozilla.com>
Tue, 12 Feb 2019 21:58:59 +0000
changeset 458806 bd4a1f69d272
parent 458805 65b2066efbeb
child 458807 081476483f25
push id35548
push useropoprus@mozilla.com
push dateWed, 13 Feb 2019 09:48:26 +0000
treeherdermozilla-central@93e37c529818 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya
bugs1525646
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1525646 - Improve logging in MoofParser. r=jya - Use different log levels in MoofParser. Generally Error is used for out of memory, while warnings are used for bad mp4s. - Add some new logs for parsing sample description entries. - Add logs for when we can't find a Moof or fail to read a Moov. - Have logs be more specific for the Box they're in where possible rather than just log 'Moof'. E.g., when parsing the stsd box, we now log against that box, not 'Moof'. - Log instead of asserting if we're given multiple encrypted sample description entries. This is valid per the spec, and can happen (though we don't expect it), so we shouldn't assert. Differential Revision: https://phabricator.services.mozilla.com/D19020
dom/media/mp4/MoofParser.cpp
--- a/dom/media/mp4/MoofParser.cpp
+++ b/dom/media/mp4/MoofParser.cpp
@@ -11,21 +11,30 @@
 #include "mozilla/CheckedInt.h"
 #include "mozilla/Logging.h"
 
 #if defined(MOZ_FMP4)
 extern mozilla::LogModule* GetDemuxerLog();
 
 #  define STRINGIFY(x) #  x
 #  define TOSTRING(x) STRINGIFY(x)
-#  define LOG(name, arg, ...)                          \
+#  define LOG_ERROR(name, arg, ...)                    \
+    MOZ_LOG(GetDemuxerLog(), mozilla::LogLevel::Error, \
+            (TOSTRING(name) "(%p)::%s: " arg, this, __func__, ##__VA_ARGS__))
+#  define LOG_WARN(name, arg, ...)                       \
+    MOZ_LOG(GetDemuxerLog(), mozilla::LogLevel::Warning, \
+            (TOSTRING(name) "(%p)::%s: " arg, this, __func__, ##__VA_ARGS__))
+#  define LOG_DEBUG(name, arg, ...)                    \
     MOZ_LOG(GetDemuxerLog(), mozilla::LogLevel::Debug, \
             (TOSTRING(name) "(%p)::%s: " arg, this, __func__, ##__VA_ARGS__))
+
 #else
-#  define LOG(...)
+#  define LOG_ERROR(...)
+#  define LOG_WARN(...)
+#  define LOG_DEBUG(...)
 #endif
 
 namespace mozilla {
 
 const uint32_t kKeyIdSize = 16;
 
 bool MoofParser::RebuildFragmentedIndex(const MediaByteRangeSet& aByteRanges) {
   BoxContext context(mSource, aByteRanges);
@@ -54,16 +63,17 @@ bool MoofParser::RebuildFragmentedIndex(
       mInitRange = MediaByteRange(0, box.Range().mEnd);
       ParseMoov(box);
     } else if (box.IsType("moof")) {
       Moof moof(box, mTrackParseMode, mTrex, mMvhd, mMdhd, mEdts, mSinf,
                 &mLastDecodeTime, mIsAudio);
 
       if (!moof.IsValid() && !box.Next().IsAvailable()) {
         // Moof isn't valid abort search for now.
+        LOG_WARN(Moof, "Could not find valid moof.");
         break;
       }
 
       if (!mMoofs.IsEmpty()) {
         // Stitch time ranges together in the case of a (hopefully small) time
         // range gap between moofs.
         mMoofs.LastElement().FixRounding(moof);
       }
@@ -170,30 +180,33 @@ void MoofParser::ScanForMetadata(mozilla
 }
 
 already_AddRefed<mozilla::MediaByteBuffer> MoofParser::Metadata() {
   MediaByteRange moov;
   ScanForMetadata(moov);
   CheckedInt<MediaByteBuffer::size_type> moovLength = moov.Length();
   if (!moovLength.isValid() || !moovLength.value()) {
     // No moov, or cannot be used as array size.
+    LOG_WARN(Moof,
+             "Did not get usable moov length while trying to parse Metadata.");
     return nullptr;
   }
 
   RefPtr<MediaByteBuffer> metadata = new MediaByteBuffer();
   if (!metadata->SetLength(moovLength.value(), fallible)) {
-    LOG(Moof, "OOM");
+    LOG_ERROR(Moof, "OOM");
     return nullptr;
   }
 
   RefPtr<BlockingStream> stream = new BlockingStream(mSource);
   size_t read;
   bool rv = stream->ReadAt(moov.mStart, metadata->Elements(),
                            moovLength.value(), &read);
   if (!rv || read != moovLength.value()) {
+    LOG_WARN(Moof, "Failed to read moov while trying to parse Metadata.");
     return nullptr;
   }
   return metadata.forget();
 }
 
 MP4Interval<Microseconds> MoofParser::GetCompositionRange(
     const MediaByteRangeSet& aByteRanges) {
   MP4Interval<Microseconds> compositionRange;
@@ -278,27 +291,27 @@ void MoofParser::ParseStbl(Box& aBox) {
     if (box.IsType("stsd")) {
       ParseStsd(box);
     } else if (box.IsType("sgpd")) {
       Sgpd sgpd(box);
       if (sgpd.IsValid() && sgpd.mGroupingType == "seig") {
         mTrackSampleEncryptionInfoEntries.Clear();
         if (!mTrackSampleEncryptionInfoEntries.AppendElements(
                 sgpd.mEntries, mozilla::fallible)) {
-          LOG(Moof, "OOM");
+          LOG_ERROR(Stbl, "OOM");
           return;
         }
       }
     } else if (box.IsType("sbgp")) {
       Sbgp sbgp(box);
       if (sbgp.IsValid() && sbgp.mGroupingType == "seig") {
         mTrackSampleToGroupEntries.Clear();
         if (!mTrackSampleToGroupEntries.AppendElements(sbgp.mEntries,
                                                        mozilla::fallible)) {
-          LOG(Moof, "OOM");
+          LOG_ERROR(Stbl, "OOM");
           return;
         }
       }
     }
   }
 }
 
 void MoofParser::ParseStsd(Box& aBox) {
@@ -316,22 +329,31 @@ void MoofParser::ParseStsd(Box& aBox) {
     SampleDescriptionEntry sampleDescriptionEntry{false};
     if (box.IsType("encv") || box.IsType("enca")) {
       ParseEncrypted(box);
       sampleDescriptionEntry.mIsEncryptedEntry = true;
       numberEncryptedEntries++;
     }
     if (!mSampleDescriptions.AppendElement(sampleDescriptionEntry,
                                            mozilla::fallible)) {
-      LOG(Moof, "OOM");
+      LOG_ERROR(Stsd, "OOM");
       return;
     }
   }
-  MOZ_ASSERT(numberEncryptedEntries <= 1,
-             "We don't expect or handle mulitple encrypted entries per track");
+  if (mSampleDescriptions.IsEmpty()) {
+    LOG_WARN(Stsd,
+             "No sample description entries found while parsing Stsd! This "
+             "shouldn't happen, as the spec requires one for each track!");
+  }
+  if (numberEncryptedEntries > 1) {
+    LOG_WARN(Stsd,
+             "More than one encrypted sample description entry found while "
+             "parsing track! We don't expect this, and it will likely break "
+             "during fragment look up!");
+  }
 }
 
 void MoofParser::ParseEncrypted(Box& aBox) {
   for (Box box = aBox.FirstChild(); box.IsAvailable(); box = box.Next()) {
     // Some MP4 files have been found to have multiple sinf boxes in the same
     // enc* box. This does not match spec anyway, so just choose the first
     // one that parses properly.
     if (box.IsType("sinf")) {
@@ -458,44 +480,44 @@ bool Moof::GetAuxInfo(AtomType aType,
       saio = &mSaios[i];
       break;
     }
   }
 
   if (saio->mOffsets.Length() == 1) {
     if (!aByteRanges->SetCapacity(saiz->mSampleInfoSize.Length(),
                                   mozilla::fallible)) {
-      LOG(Moof, "OOM");
+      LOG_ERROR(Moof, "OOM");
       return false;
     }
     uint64_t offset = mRange.mStart + saio->mOffsets[0];
     for (size_t i = 0; i < saiz->mSampleInfoSize.Length(); i++) {
       if (!aByteRanges->AppendElement(
               MediaByteRange(offset, offset + saiz->mSampleInfoSize[i]),
               mozilla::fallible)) {
-        LOG(Moof, "OOM");
+        LOG_ERROR(Moof, "OOM");
         return false;
       }
       offset += saiz->mSampleInfoSize[i];
     }
     return true;
   }
 
   if (saio->mOffsets.Length() == saiz->mSampleInfoSize.Length()) {
     if (!aByteRanges->SetCapacity(saiz->mSampleInfoSize.Length(),
                                   mozilla::fallible)) {
-      LOG(Moof, "OOM");
+      LOG_ERROR(Moof, "OOM");
       return false;
     }
     for (size_t i = 0; i < saio->mOffsets.Length(); i++) {
       uint64_t offset = mRange.mStart + saio->mOffsets[i];
       if (!aByteRanges->AppendElement(
               MediaByteRange(offset, offset + saiz->mSampleInfoSize[i]),
               mozilla::fallible)) {
-        LOG(Moof, "OOM");
+        LOG_ERROR(Moof, "OOM");
         return false;
       }
     }
     return true;
   }
 
   return false;
 }
@@ -530,40 +552,40 @@ void Moof::ParseTraf(Box& aBox, const Tr
       if (box.IsType("tfdt")) {
         tfdt = Tfdt(box);
       } else if (box.IsType("sgpd")) {
         Sgpd sgpd(box);
         if (sgpd.IsValid() && sgpd.mGroupingType == "seig") {
           mFragmentSampleEncryptionInfoEntries.Clear();
           if (!mFragmentSampleEncryptionInfoEntries.AppendElements(
                   sgpd.mEntries, mozilla::fallible)) {
-            LOG(Moof, "OOM");
+            LOG_ERROR(Moof, "OOM");
             return;
           }
         }
       } else if (box.IsType("sbgp")) {
         Sbgp sbgp(box);
         if (sbgp.IsValid() && sbgp.mGroupingType == "seig") {
           mFragmentSampleToGroupEntries.Clear();
           if (!mFragmentSampleToGroupEntries.AppendElements(
                   sbgp.mEntries, mozilla::fallible)) {
-            LOG(Moof, "OOM");
+            LOG_ERROR(Moof, "OOM");
             return;
           }
         }
       } else if (box.IsType("saiz")) {
         if (!mSaizs.AppendElement(Saiz(box, aSinf.mDefaultEncryptionType),
                                   mozilla::fallible)) {
-          LOG(Moof, "OOM");
+          LOG_ERROR(Moof, "OOM");
           return;
         }
       } else if (box.IsType("saio")) {
         if (!mSaios.AppendElement(Saio(box, aSinf.mDefaultEncryptionType),
                                   mozilla::fallible)) {
-          LOG(Moof, "OOM");
+          LOG_ERROR(Moof, "OOM");
           return;
         }
       }
     }
   }
   if (aTrackParseMode.is<uint32_t>() &&
       mTfhd.mTrackId != aTrackParseMode.as<uint32_t>()) {
     return;
@@ -571,17 +593,17 @@ void Moof::ParseTraf(Box& aBox, const Tr
   // Now search for TRUN boxes.
   uint64_t decodeTime =
       tfdt.IsValid() ? tfdt.mBaseMediaDecodeTime : *aDecodeTime;
   for (Box box = aBox.FirstChild(); box.IsAvailable(); box = box.Next()) {
     if (box.IsType("trun")) {
       if (ParseTrun(box, aMvhd, aMdhd, aEdts, &decodeTime, aIsAudio).isOk()) {
         mValid = true;
       } else {
-        LOG(Moof, "ParseTrun failed");
+        LOG_WARN(Moof, "ParseTrun failed");
         mValid = false;
         break;
       }
     }
   }
   *aDecodeTime = decodeTime;
 }
 
@@ -592,31 +614,32 @@ void Moof::FixRounding(const Moof& aMoof
   }
 }
 
 Result<Ok, nsresult> Moof::ParseTrun(Box& aBox, Mvhd& aMvhd, Mdhd& aMdhd,
                                      Edts& aEdts, uint64_t* aDecodeTime,
                                      bool aIsAudio) {
   if (!mTfhd.IsValid() || !aMvhd.IsValid() || !aMdhd.IsValid() ||
       !aEdts.IsValid()) {
-    LOG(Moof, "Invalid dependencies: mTfhd(%d) aMvhd(%d) aMdhd(%d) aEdts(%d)",
+    LOG_WARN(
+        Moof, "Invalid dependencies: mTfhd(%d) aMvhd(%d) aMdhd(%d) aEdts(%d)",
         mTfhd.IsValid(), aMvhd.IsValid(), aMdhd.IsValid(), !aEdts.IsValid());
     return Err(NS_ERROR_FAILURE);
   }
 
   BoxReader reader(aBox);
   if (!reader->CanReadType<uint32_t>()) {
-    LOG(Moof, "Incomplete Box (missing flags)");
+    LOG_WARN(Moof, "Incomplete Box (missing flags)");
     return Err(NS_ERROR_FAILURE);
   }
   uint32_t flags;
   MOZ_TRY_VAR(flags, reader->ReadU32());
 
   if (!reader->CanReadType<uint32_t>()) {
-    LOG(Moof, "Incomplete Box (missing sampleCount)");
+    LOG_WARN(Moof, "Incomplete Box (missing sampleCount)");
     return Err(NS_ERROR_FAILURE);
   }
   uint32_t sampleCount;
   MOZ_TRY_VAR(sampleCount, reader->ReadU32());
   if (sampleCount == 0) {
     return Ok();
   }
 
@@ -629,17 +652,17 @@ Result<Ok, nsresult> Moof::ParseTrun(Box
   uint32_t firstSampleFlags = mTfhd.mDefaultSampleFlags;
   if (flags & 0x04) {
     MOZ_TRY_VAR(firstSampleFlags, reader->ReadU32());
   }
   uint64_t decodeTime = *aDecodeTime;
   nsTArray<MP4Interval<Microseconds>> timeRanges;
 
   if (!mIndex.SetCapacity(sampleCount, fallible)) {
-    LOG(Moof, "Out of Memory");
+    LOG_ERROR(Moof, "Out of Memory");
     return Err(NS_ERROR_FAILURE);
   }
 
   for (size_t i = 0; i < sampleCount; i++) {
     uint32_t sampleDuration = mTfhd.mDefaultSampleDuration;
     if (flags & 0x100) {
       MOZ_TRY_VAR(sampleDuration, reader->ReadU32());
     }
@@ -692,17 +715,17 @@ Result<Ok, nsresult> Moof::ParseTrun(Box
   *aDecodeTime = decodeTime;
 
   return Ok();
 }
 
 Tkhd::Tkhd(Box& aBox) : mTrackId(0) {
   mValid = Parse(aBox).isOk();
   if (!mValid) {
-    LOG(Tkhd, "Parse failed");
+    LOG_WARN(Tkhd, "Parse failed");
   }
 }
 
 Result<Ok, nsresult> Tkhd::Parse(Box& aBox) {
   BoxReader reader(aBox);
   uint32_t flags;
   MOZ_TRY_VAR(flags, reader->ReadU32());
   uint8_t version = flags >> 24;
@@ -730,17 +753,17 @@ Result<Ok, nsresult> Tkhd::Parse(Box& aB
   }
   return Ok();
 }
 
 Mvhd::Mvhd(Box& aBox)
     : mCreationTime(0), mModificationTime(0), mTimescale(0), mDuration(0) {
   mValid = Parse(aBox).isOk();
   if (!mValid) {
-    LOG(Mvhd, "Parse failed");
+    LOG_WARN(Mvhd, "Parse failed");
   }
 }
 
 Result<Ok, nsresult> Mvhd::Parse(Box& aBox) {
   BoxReader reader(aBox);
 
   uint32_t flags;
   MOZ_TRY_VAR(flags, reader->ReadU32());
@@ -772,17 +795,17 @@ Trex::Trex(Box& aBox)
     : mFlags(0),
       mTrackId(0),
       mDefaultSampleDescriptionIndex(0),
       mDefaultSampleDuration(0),
       mDefaultSampleSize(0),
       mDefaultSampleFlags(0) {
   mValid = Parse(aBox).isOk();
   if (!mValid) {
-    LOG(Trex, "Parse failed");
+    LOG_WARN(Trex, "Parse failed");
   }
 }
 
 Result<Ok, nsresult> Trex::Parse(Box& aBox) {
   BoxReader reader(aBox);
 
   MOZ_TRY_VAR(mFlags, reader->ReadU32());
   MOZ_TRY_VAR(mTrackId, reader->ReadU32());
@@ -792,17 +815,17 @@ Result<Ok, nsresult> Trex::Parse(Box& aB
   MOZ_TRY_VAR(mDefaultSampleFlags, reader->ReadU32());
 
   return Ok();
 }
 
 Tfhd::Tfhd(Box& aBox, Trex& aTrex) : Trex(aTrex), mBaseDataOffset(0) {
   mValid = Parse(aBox).isOk();
   if (!mValid) {
-    LOG(Tfhd, "Parse failed");
+    LOG_WARN(Tfhd, "Parse failed");
   }
 }
 
 Result<Ok, nsresult> Tfhd::Parse(Box& aBox) {
   MOZ_ASSERT(aBox.IsType("tfhd"));
   MOZ_ASSERT(aBox.Parent()->IsType("traf"));
   MOZ_ASSERT(aBox.Parent()->Parent()->IsType("moof"));
 
@@ -828,17 +851,17 @@ Result<Ok, nsresult> Tfhd::Parse(Box& aB
   }
 
   return Ok();
 }
 
 Tfdt::Tfdt(Box& aBox) : mBaseMediaDecodeTime(0) {
   mValid = Parse(aBox).isOk();
   if (!mValid) {
-    LOG(Tfdt, "Parse failed");
+    LOG_WARN(Tfdt, "Parse failed");
   }
 }
 
 Result<Ok, nsresult> Tfdt::Parse(Box& aBox) {
   BoxReader reader(aBox);
 
   uint32_t flags;
   MOZ_TRY_VAR(flags, reader->ReadU32());
@@ -851,17 +874,17 @@ Result<Ok, nsresult> Tfdt::Parse(Box& aB
     MOZ_TRY_VAR(mBaseMediaDecodeTime, reader->ReadU64());
   }
   return Ok();
 }
 
 Edts::Edts(Box& aBox) : mMediaStart(0), mEmptyOffset(0) {
   mValid = Parse(aBox).isOk();
   if (!mValid) {
-    LOG(Edts, "Parse failed");
+    LOG_WARN(Edts, "Parse failed");
   }
 }
 
 Result<Ok, nsresult> Edts::Parse(Box& aBox) {
   Box child = aBox.FirstChild();
   if (!child.IsType("elst")) {
     return Err(NS_ERROR_FAILURE);
   }
@@ -883,38 +906,38 @@ Result<Ok, nsresult> Edts::Parse(Box& aB
       uint32_t tmp;
       MOZ_TRY_VAR(tmp, reader->ReadU32());
       segment_duration = tmp;
       int32_t tmp2;
       MOZ_TRY_VAR(tmp2, reader->Read32());
       media_time = tmp2;
     }
     if (media_time == -1 && i) {
-      LOG(Edts, "Multiple empty edit, not handled");
+      LOG_WARN(Edts, "Multiple empty edit, not handled");
     } else if (media_time == -1) {
       mEmptyOffset = segment_duration;
       emptyEntry = true;
     } else if (i > 1 || (i > 0 && !emptyEntry)) {
-      LOG(Edts,
-          "More than one edit entry, not handled. A/V sync will be wrong");
+      LOG_WARN(Edts,
+               "More than one edit entry, not handled. A/V sync will be wrong");
       break;
     } else {
       mMediaStart = media_time;
     }
     MOZ_TRY(reader->ReadU32());  // media_rate_integer and media_rate_fraction
   }
 
   return Ok();
 }
 
 Saiz::Saiz(Box& aBox, AtomType aDefaultType)
     : mAuxInfoType(aDefaultType), mAuxInfoTypeParameter(0) {
   mValid = Parse(aBox).isOk();
   if (!mValid) {
-    LOG(Saiz, "Parse failed");
+    LOG_WARN(Saiz, "Parse failed");
   }
 }
 
 Result<Ok, nsresult> Saiz::Parse(Box& aBox) {
   BoxReader reader(aBox);
 
   uint32_t flags;
   MOZ_TRY_VAR(flags, reader->ReadU32());
@@ -923,35 +946,35 @@ Result<Ok, nsresult> Saiz::Parse(Box& aB
     MOZ_TRY_VAR(mAuxInfoTypeParameter, reader->ReadU32());
   }
   uint8_t defaultSampleInfoSize;
   MOZ_TRY_VAR(defaultSampleInfoSize, reader->ReadU8());
   uint32_t count;
   MOZ_TRY_VAR(count, reader->ReadU32());
   if (defaultSampleInfoSize) {
     if (!mSampleInfoSize.SetLength(count, fallible)) {
-      LOG(Saiz, "OOM");
+      LOG_ERROR(Saiz, "OOM");
       return Err(NS_ERROR_FAILURE);
     }
     memset(mSampleInfoSize.Elements(), defaultSampleInfoSize,
            mSampleInfoSize.Length());
   } else {
     if (!reader->ReadArray(mSampleInfoSize, count)) {
-      LOG(Saiz, "Incomplete Box (OOM or missing count:%u)", count);
+      LOG_WARN(Saiz, "Incomplete Box (OOM or missing count:%u)", count);
       return Err(NS_ERROR_FAILURE);
     }
   }
   return Ok();
 }
 
 Saio::Saio(Box& aBox, AtomType aDefaultType)
     : mAuxInfoType(aDefaultType), mAuxInfoTypeParameter(0) {
   mValid = Parse(aBox).isOk();
   if (!mValid) {
-    LOG(Saio, "Parse failed");
+    LOG_WARN(Saio, "Parse failed");
   }
 }
 
 Result<Ok, nsresult> Saio::Parse(Box& aBox) {
   BoxReader reader(aBox);
 
   uint32_t flags;
   MOZ_TRY_VAR(flags, reader->ReadU32());
@@ -959,17 +982,17 @@ Result<Ok, nsresult> Saio::Parse(Box& aB
   if (flags & 1) {
     MOZ_TRY_VAR(mAuxInfoType, reader->ReadU32());
     MOZ_TRY_VAR(mAuxInfoTypeParameter, reader->ReadU32());
   }
 
   size_t count;
   MOZ_TRY_VAR(count, reader->ReadU32());
   if (!mOffsets.SetCapacity(count, fallible)) {
-    LOG(Saiz, "OOM");
+    LOG_ERROR(Saiz, "OOM");
     return Err(NS_ERROR_FAILURE);
   }
   if (version == 0) {
     uint32_t offset;
     for (size_t i = 0; i < count; i++) {
       MOZ_TRY_VAR(offset, reader->ReadU32());
       MOZ_ALWAYS_TRUE(mOffsets.AppendElement(offset, fallible));
     }
@@ -981,17 +1004,17 @@ Result<Ok, nsresult> Saio::Parse(Box& aB
     }
   }
   return Ok();
 }
 
 Sbgp::Sbgp(Box& aBox) : mGroupingTypeParam(0) {
   mValid = Parse(aBox).isOk();
   if (!mValid) {
-    LOG(Sbgp, "Parse failed");
+    LOG_WARN(Sbgp, "Parse failed");
   }
 }
 
 Result<Ok, nsresult> Sbgp::Parse(Box& aBox) {
   BoxReader reader(aBox);
 
   uint32_t flags;
   MOZ_TRY_VAR(flags, reader->ReadU32());
@@ -1012,27 +1035,27 @@ Result<Ok, nsresult> Sbgp::Parse(Box& aB
   for (uint32_t i = 0; i < count; i++) {
     uint32_t sampleCount;
     MOZ_TRY_VAR(sampleCount, reader->ReadU32());
     uint32_t groupDescriptionIndex;
     MOZ_TRY_VAR(groupDescriptionIndex, reader->ReadU32());
 
     SampleToGroupEntry entry(sampleCount, groupDescriptionIndex);
     if (!mEntries.AppendElement(entry, mozilla::fallible)) {
-      LOG(Sbgp, "OOM");
+      LOG_ERROR(Sbgp, "OOM");
       return Err(NS_ERROR_FAILURE);
     }
   }
   return Ok();
 }
 
 Sgpd::Sgpd(Box& aBox) {
   mValid = Parse(aBox).isOk();
   if (!mValid) {
-    LOG(Sgpd, "Parse failed");
+    LOG_WARN(Sgpd, "Parse failed");
   }
 }
 
 Result<Ok, nsresult> Sgpd::Parse(Box& aBox) {
   BoxReader reader(aBox);
 
   uint32_t flags;
   MOZ_TRY_VAR(flags, reader->ReadU32());
@@ -1066,17 +1089,17 @@ Result<Ok, nsresult> Sgpd::Parse(Box& aB
     }
 
     CencSampleEncryptionInfoEntry entry;
     bool valid = entry.Init(reader).isOk();
     if (!valid) {
       return Err(NS_ERROR_FAILURE);
     }
     if (!mEntries.AppendElement(entry, mozilla::fallible)) {
-      LOG(Sgpd, "OOM");
+      LOG_ERROR(Sgpd, "OOM");
       return Err(NS_ERROR_FAILURE);
     }
   }
   return Ok();
 }
 
 Result<Ok, nsresult> CencSampleEncryptionInfoEntry::Init(BoxReader& aReader) {
   // Skip a reserved byte.
@@ -1090,43 +1113,45 @@ Result<Ok, nsresult> CencSampleEncryptio
   uint8_t isEncrypted;
   MOZ_TRY_VAR(isEncrypted, aReader->ReadU8());
   mIsEncrypted = isEncrypted != 0;
 
   MOZ_TRY_VAR(mIVSize, aReader->ReadU8());
 
   // Read the key id.
   if (!mKeyId.SetLength(kKeyIdSize, fallible)) {
-    LOG(CencSampleEncryptionInfoEntry, "OOM");
+    LOG_ERROR(CencSampleEncryptionInfoEntry, "OOM");
     return Err(NS_ERROR_FAILURE);
   }
   for (uint32_t i = 0; i < kKeyIdSize; ++i) {
     MOZ_TRY_VAR(mKeyId.ElementAt(i), aReader->ReadU8());
   }
 
   if (mIsEncrypted) {
     if (mIVSize != 8 && mIVSize != 16) {
       return Err(NS_ERROR_FAILURE);
     }
   } else if (mIVSize != 0) {
     // Protected content with 0 sized IV indicates a constant IV is present.
     // This is used for the cbcs scheme.
     uint8_t constantIVSize;
     MOZ_TRY_VAR(constantIVSize, aReader->ReadU8());
     if (constantIVSize != 8 && constantIVSize != 16) {
-      LOG(CencSampleEncryptionInfoEntry, "Unexpected constantIVSize: %" PRIu8,
-          constantIVSize);
+      LOG_WARN(CencSampleEncryptionInfoEntry,
+               "Unexpected constantIVSize: %" PRIu8, constantIVSize);
       return Err(NS_ERROR_FAILURE);
     }
     if (!mConsantIV.SetLength(constantIVSize, mozilla::fallible)) {
-      LOG(CencSampleEncryptionInfoEntry, "OOM");
+      LOG_ERROR(CencSampleEncryptionInfoEntry, "OOM");
       return Err(NS_ERROR_FAILURE);
     }
     for (uint32_t i = 0; i < constantIVSize; ++i) {
       MOZ_TRY_VAR(mConsantIV.ElementAt(i), aReader->ReadU8());
     }
   }
 
   return Ok();
 }
+}  // namespace mozilla
 
-#undef LOG
-}  // namespace mozilla
+#undef LOG_DEBUG
+#undef LOG_WARN
+#undef LOG_ERROR