Bug 1407810 - Use DDMOZ_LOG in media stack - r?jwwang draft
authorGerald Squelart <gsquelart@mozilla.com>
Fri, 13 Oct 2017 16:31:59 +1100
changeset 708720 369fc80be72e0b64e194f11a736952f6e41d3098
parent 708719 6cf1abfbed2e5d5dd3f8e5f2ab2318bc216b7883
child 743218 88ada47b2c7c9d40ea4e01ba43ab3746bd54fd5c
push id92413
push usergsquelart@mozilla.com
push dateWed, 06 Dec 2017 23:54:05 +0000
reviewersjwwang
bugs1407810
milestone59.0a1
Bug 1407810 - Use DDMOZ_LOG in media stack - r?jwwang Mostly-mechanical replacement of MOZ_LOG with DDMOZ_LOG, usually just removing the class name and `this` pointer (as they are already implicitly recorded). Some files needed a bit more work when logging was done from helper classes or static functions. MozReview-Commit-ID: IeJJmzYqWMQ
dom/media/ADTSDemuxer.cpp
dom/media/ChannelMediaDecoder.cpp
dom/media/ChannelMediaResource.cpp
dom/media/MediaDecoder.cpp
dom/media/MediaDecoderStateMachine.cpp
dom/media/MediaFormatReader.cpp
dom/media/MediaResource.cpp
dom/media/flac/FlacDemuxer.cpp
dom/media/mediasource/ContainerParser.cpp
dom/media/mediasource/ContainerParser.h
dom/media/mediasource/MediaSource.cpp
dom/media/mediasource/MediaSourceDecoder.cpp
dom/media/mediasource/SourceBuffer.cpp
dom/media/mediasource/SourceBufferResource.cpp
dom/media/mediasource/TrackBuffersManager.cpp
dom/media/mp3/MP3Demuxer.cpp
dom/media/mp4/MP4Demuxer.cpp
dom/media/ogg/OggDemuxer.cpp
dom/media/platforms/agnostic/AOMDecoder.cpp
dom/media/platforms/agnostic/OpusDecoder.cpp
dom/media/platforms/agnostic/TheoraDecoder.cpp
dom/media/platforms/agnostic/VPXDecoder.cpp
dom/media/platforms/apple/AppleATDecoder.cpp
dom/media/platforms/apple/AppleCMLinker.cpp
dom/media/platforms/apple/AppleVTDecoder.cpp
dom/media/platforms/omx/OmxDataDecoder.cpp
dom/media/webm/WebMDemuxer.cpp
--- a/dom/media/ADTSDemuxer.cpp
+++ b/dom/media/ADTSDemuxer.cpp
@@ -7,20 +7,20 @@
 #include "ADTSDemuxer.h"
 
 #include "TimeUnits.h"
 #include "VideoUtils.h"
 #include "mozilla/UniquePtr.h"
 #include <inttypes.h>
 
 extern mozilla::LazyLogModule gMediaDemuxerLog;
-#define ADTSLOG(msg, ...) \
-  MOZ_LOG(gMediaDemuxerLog, LogLevel::Debug, ("ADTSDemuxer " msg, ##__VA_ARGS__))
-#define ADTSLOGV(msg, ...) \
-  MOZ_LOG(gMediaDemuxerLog, LogLevel::Verbose, ("ADTSDemuxer " msg, ##__VA_ARGS__))
+#define ADTSLOG(msg, ...)                                                      \
+  DDMOZ_LOG(gMediaDemuxerLog, LogLevel::Debug, msg, ##__VA_ARGS__)
+#define ADTSLOGV(msg, ...)                                                     \
+  DDMOZ_LOG(gMediaDemuxerLog, LogLevel::Verbose, msg, ##__VA_ARGS__)
 
 namespace mozilla {
 namespace adts {
 
 // adts::FrameHeader - Holds the ADTS frame header and its parsing
 // state.
 //
 // ADTS Frame Structure
--- a/dom/media/ChannelMediaDecoder.cpp
+++ b/dom/media/ChannelMediaDecoder.cpp
@@ -10,18 +10,17 @@
 #include "MediaFormatReader.h"
 #include "BaseMediaResource.h"
 #include "MediaShutdownManager.h"
 
 namespace mozilla {
 
 extern LazyLogModule gMediaDecoderLog;
 #define LOG(x, ...)                                                            \
-  MOZ_LOG(                                                                     \
-    gMediaDecoderLog, LogLevel::Debug, ("Decoder=%p " x, this, ##__VA_ARGS__))
+  DDMOZ_LOG(gMediaDecoderLog, LogLevel::Debug, x, ##__VA_ARGS__)
 
 ChannelMediaDecoder::ResourceCallback::ResourceCallback(
   AbstractThread* aMainThread)
   : mAbstractMainThread(aMainThread)
 {
   MOZ_ASSERT(aMainThread);
   DecoderDoctorLogger::LogConstructionAndBase(
     "ChannelMediaDecoder::ResourceCallback",
--- a/dom/media/ChannelMediaResource.cpp
+++ b/dom/media/ChannelMediaResource.cpp
@@ -14,18 +14,18 @@
 #include "nsNetUtil.h"
 
 static const uint32_t HTTP_PARTIAL_RESPONSE_CODE = 206;
 static const uint32_t HTTP_OK_CODE = 200;
 static const uint32_t HTTP_REQUESTED_RANGE_NOT_SATISFIABLE_CODE = 416;
 
 mozilla::LazyLogModule gMediaResourceLog("MediaResource");
 // Debug logging macro with object pointer and class name.
-#define LOG(msg, ...) MOZ_LOG(gMediaResourceLog, mozilla::LogLevel::Debug, \
-  ("%p " msg, this, ##__VA_ARGS__))
+#define LOG(msg, ...)                                                          \
+  DDMOZ_LOG(gMediaResourceLog, mozilla::LogLevel::Debug, msg, ##__VA_ARGS__)
 
 namespace mozilla {
 
 ChannelMediaResource::ChannelMediaResource(MediaResourceCallback* aCallback,
                                            nsIChannel* aChannel,
                                            nsIURI* aURI,
                                            bool aIsPrivateBrowsing)
   : BaseMediaResource(aCallback, aChannel, aURI)
--- a/dom/media/MediaDecoder.cpp
+++ b/dom/media/MediaDecoder.cpp
@@ -44,18 +44,18 @@ namespace mozilla {
 #undef GetCurrentTime
 #endif
 
 // avoid redefined macro in unified build
 #undef LOG
 #undef DUMP
 
 LazyLogModule gMediaDecoderLog("MediaDecoder");
-#define LOG(x, ...) \
-  MOZ_LOG(gMediaDecoderLog, LogLevel::Debug, ("Decoder=%p " x, this, ##__VA_ARGS__))
+#define LOG(x, ...)                                                            \
+  DDMOZ_LOG(gMediaDecoderLog, LogLevel::Debug, x, ##__VA_ARGS__)
 
 #define DUMP(x, ...) printf_stderr(x "\n", ##__VA_ARGS__)
 
 #define NS_DispatchToMainThread(...) CompileError_UseAbstractMainThreadInstead
 
 static const char*
 ToPlayStateStr(MediaDecoder::PlayState aState)
 {
@@ -838,18 +838,16 @@ MediaDecoder::ChangeState(PlayState aSta
 
   if (mNextState == aState) {
     mNextState = PLAY_STATE_PAUSED;
   }
 
   if (mPlayState != aState) {
     DDLOG(DDLogCategory::Property, "play_state", ToPlayStateStr(aState));
   }
-
-  LOG("ChangeState %s => %s", PlayStateStr(), ToPlayStateStr(aState));
   mPlayState = aState;
 
   if (mPlayState == PLAY_STATE_PLAYING) {
     GetOwner()->ConstructMediaTracks(mInfo);
   } else if (IsEnded()) {
     GetOwner()->RemoveMediaTracks();
   }
 }
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -54,24 +54,40 @@ using namespace mozilla::media;
 #undef LOGW
 #undef LOGE
 #undef SFMT
 #undef SLOG
 #undef SLOGW
 #undef SLOGE
 
 #define FMT(x, ...) "Decoder=%p " x, mDecoderID, ##__VA_ARGS__
-#define LOG(x, ...) MOZ_LOG(gMediaDecoderLog, LogLevel::Debug,   (FMT(x, ##__VA_ARGS__)))
-#define LOGV(x, ...) MOZ_LOG(gMediaDecoderLog, LogLevel::Verbose, (FMT(x, ##__VA_ARGS__)))
+#define LOG(x, ...)                                                            \
+  DDMOZ_LOG(gMediaDecoderLog,                                                  \
+            LogLevel::Debug,                                                   \
+            "Decoder=%p " x,                                                   \
+            mDecoderID,                                                        \
+            ##__VA_ARGS__)
+#define LOGV(x, ...)                                                           \
+  DDMOZ_LOG(gMediaDecoderLog,                                                  \
+            LogLevel::Verbose,                                                 \
+            "Decoder=%p " x,                                                   \
+            mDecoderID,                                                        \
+            ##__VA_ARGS__)
 #define LOGW(x, ...) NS_WARNING(nsPrintfCString(FMT(x, ##__VA_ARGS__)).get())
 #define LOGE(x, ...) NS_DebugBreak(NS_DEBUG_WARNING, nsPrintfCString(FMT(x, ##__VA_ARGS__)).get(), nullptr, __FILE__, __LINE__)
 
 // Used by StateObject and its sub-classes
 #define SFMT(x, ...) "Decoder=%p state=%s " x, mMaster->mDecoderID, ToStateStr(GetState()), ##__VA_ARGS__
-#define SLOG(x, ...) MOZ_LOG(gMediaDecoderLog, LogLevel::Debug, (SFMT(x, ##__VA_ARGS__)))
+#define SLOG(x, ...)                                                           \
+  DDMOZ_LOGEX(mMaster,                                                         \
+              gMediaDecoderLog,                                                \
+              LogLevel::Debug,                                                 \
+              "state=%s " x,                                                   \
+              ToStateStr(GetState()),                                          \
+              ##__VA_ARGS__)
 #define SLOGW(x, ...) NS_WARNING(nsPrintfCString(SFMT(x, ##__VA_ARGS__)).get())
 #define SLOGE(x, ...) NS_DebugBreak(NS_DEBUG_WARNING, nsPrintfCString(SFMT(x, ##__VA_ARGS__)).get(), nullptr, __FILE__, __LINE__)
 
 #ifdef NIGHTLY_BUILD
 #define DEBUG_SHUTDOWN(fmt, ...) printf_stderr("[DEBUG SHUTDOWN] %s: " fmt "\n", __func__, ##__VA_ARGS__)
 #else
 #define DEBUG_SHUTDOWN(...) do { } while (0)
 #endif
--- a/dom/media/MediaFormatReader.cpp
+++ b/dom/media/MediaFormatReader.cpp
@@ -26,18 +26,28 @@
 #include <map>
 #include <queue>
 
 using namespace mozilla::media;
 
 static mozilla::LazyLogModule sFormatDecoderLog("MediaFormatReader");
 mozilla::LazyLogModule gMediaDemuxerLog("MediaDemuxer");
 
-#define LOG(arg, ...) MOZ_LOG(sFormatDecoderLog, mozilla::LogLevel::Debug, ("MediaFormatReader(%p)::%s: " arg, this, __func__, ##__VA_ARGS__))
-#define LOGV(arg, ...) MOZ_LOG(sFormatDecoderLog, mozilla::LogLevel::Verbose, ("MediaFormatReader(%p)::%s: " arg, this, __func__, ##__VA_ARGS__))
+#define LOG(arg, ...)                                                          \
+  DDMOZ_LOG(sFormatDecoderLog,                                                 \
+            mozilla::LogLevel::Debug,                                          \
+            "::%s: " arg,                                                      \
+            __func__,                                                          \
+            ##__VA_ARGS__)
+#define LOGV(arg, ...)                                                         \
+  DDMOZ_LOG(sFormatDecoderLog,                                                 \
+            mozilla::LogLevel::Verbose,                                        \
+            "::%s: " arg,                                                      \
+            __func__,                                                          \
+            ##__VA_ARGS__)
 
 #define NS_DispatchToMainThread(...) CompileError_UseAbstractMainThreadInstead
 
 #ifdef NIGHTLY_BUILD
 #define DEBUG_SHUTDOWN(fmt, ...) printf_stderr("[DEBUG SHUTDOWN] %s: " fmt "\n", __func__, ##__VA_ARGS__)
 #else
 #define DEBUG_SHUTDOWN(...) do { } while (0)
 #endif
--- a/dom/media/MediaResource.cpp
+++ b/dom/media/MediaResource.cpp
@@ -14,19 +14,18 @@
 
 using mozilla::media::TimeUnit;
 
 #undef ILOG
 
 mozilla::LazyLogModule gMediaResourceIndexLog("MediaResourceIndex");
 // Debug logging macro with object pointer and class name.
 #define ILOG(msg, ...)                                                         \
-  MOZ_LOG(gMediaResourceIndexLog,                                              \
-          mozilla::LogLevel::Debug,                                            \
-          ("%p " msg, this, ##__VA_ARGS__))
+  DDMOZ_LOG(                                                                   \
+    gMediaResourceIndexLog, mozilla::LogLevel::Debug, msg, ##__VA_ARGS__)
 
 namespace mozilla {
 
 void
 MediaResource::Destroy()
 {
   // Ensures we only delete the MediaResource on the main thread.
   if (NS_IsMainThread()) {
--- a/dom/media/flac/FlacDemuxer.cpp
+++ b/dom/media/flac/FlacDemuxer.cpp
@@ -10,20 +10,20 @@
 #include "BitReader.h"
 #include "nsAutoPtr.h"
 #include "prenv.h"
 #include "FlacFrameParser.h"
 #include "VideoUtils.h"
 #include "TimeUnits.h"
 
 extern mozilla::LazyLogModule gMediaDemuxerLog;
-#define LOG(msg, ...) \
-  MOZ_LOG(gMediaDemuxerLog, LogLevel::Debug, ("FlacDemuxer " msg, ##__VA_ARGS__))
-#define LOGV(msg, ...) \
-  MOZ_LOG(gMediaDemuxerLog, LogLevel::Verbose, ("FlacDemuxer " msg, ##__VA_ARGS__))
+#define LOG(msg, ...)                                                          \
+  DDMOZ_LOG(gMediaDemuxerLog, LogLevel::Debug, msg, ##__VA_ARGS__)
+#define LOGV(msg, ...)                                                         \
+  DDMOZ_LOG(gMediaDemuxerLog, LogLevel::Verbose, msg, ##__VA_ARGS__)
 
 using namespace mozilla::media;
 
 namespace mozilla {
 namespace flac {
 
 // flac::FrameHeader - Holds the flac frame header and its parsing
 // state.
--- a/dom/media/mediasource/ContainerParser.cpp
+++ b/dom/media/mediasource/ContainerParser.cpp
@@ -25,47 +25,67 @@
 #include "nsAutoPtr.h"
 #include "SourceBufferResource.h"
 #include <algorithm>
 
 extern mozilla::LogModule* GetMediaSourceSamplesLog();
 
 #define STRINGIFY(x) #x
 #define TOSTRING(x) STRINGIFY(x)
-#define MSE_DEBUG(name, arg, ...) MOZ_LOG(GetMediaSourceSamplesLog(), mozilla::LogLevel::Debug, (TOSTRING(name) "(%p:%s)::%s: " arg, this, mType.OriginalString().Data(), __func__, ##__VA_ARGS__))
-#define MSE_DEBUGV(name, arg, ...) MOZ_LOG(GetMediaSourceSamplesLog(), mozilla::LogLevel::Verbose, (TOSTRING(name) "(%p:%s)::%s: " arg, this, mType.OriginalString().Data(), __func__, ##__VA_ARGS__))
+#define MSE_DEBUG(arg, ...)                                                    \
+  DDMOZ_LOG(GetMediaSourceSamplesLog(),                                        \
+            mozilla::LogLevel::Debug,                                          \
+            "(%s)::%s: " arg,                                                  \
+            mType.OriginalString().Data(),                                     \
+            __func__,                                                          \
+            ##__VA_ARGS__)
+#define MSE_DEBUGV(arg, ...)                                                   \
+  DDMOZ_LOG(GetMediaSourceSamplesLog(),                                        \
+            mozilla::LogLevel::Verbose,                                        \
+            "(%s)::%s: " arg,                                                  \
+            mType.OriginalString().Data(),                                     \
+            __func__,                                                          \
+            ##__VA_ARGS__)
+#define MSE_DEBUGVEX(_this, arg, ...)                                          \
+  DDMOZ_LOGEX(_this,                                                           \
+              GetMediaSourceSamplesLog(),                                      \
+              mozilla::LogLevel::Verbose,                                      \
+              "(%s)::%s: " arg,                                                \
+              mType.OriginalString().Data(),                                   \
+              __func__,                                                        \
+              ##__VA_ARGS__)
 
 namespace mozilla {
 
 ContainerParser::ContainerParser(const MediaContainerType& aType)
   : mHasInitData(false)
   , mTotalParsed(0)
   , mGlobalOffset(0)
   , mType(aType)
 {
 }
 
 ContainerParser::~ContainerParser() = default;
 
 MediaResult
 ContainerParser::IsInitSegmentPresent(MediaByteBuffer* aData)
 {
-  MSE_DEBUG(ContainerParser, "aLength=%zu [%x%x%x%x]",
+  MSE_DEBUG("aLength=%zu [%x%x%x%x]",
             aData->Length(),
             aData->Length() > 0 ? (*aData)[0] : 0,
             aData->Length() > 1 ? (*aData)[1] : 0,
             aData->Length() > 2 ? (*aData)[2] : 0,
             aData->Length() > 3 ? (*aData)[3] : 0);
   return NS_ERROR_NOT_AVAILABLE;
 }
 
 MediaResult
 ContainerParser::IsMediaSegmentPresent(MediaByteBuffer* aData)
 {
-  MSE_DEBUG(ContainerParser, "aLength=%zu [%x%x%x%x]",
+  MSE_DEBUG("aLength=%zu [%x%x%x%x]",
             aData->Length(),
             aData->Length() > 0 ? (*aData)[0] : 0,
             aData->Length() > 1 ? (*aData)[1] : 0,
             aData->Length() > 2 ? (*aData)[2] : 0,
             aData->Length() > 3 ? (*aData)[3] : 0);
   return NS_ERROR_NOT_AVAILABLE;
 }
 
@@ -182,18 +202,17 @@ public:
         (initSegment || NS_SUCCEEDED(IsMediaSegmentPresent(aData)))) {
       // The last data contained a complete cluster but we can only detect it
       // now that a new one is starting.
       // We use mOffset as end position to ensure that any blocks not reported
       // by WebMBufferParser are properly skipped.
       mCompleteMediaSegmentRange =
         MediaByteRange(mLastMapping.ref().mSyncOffset, mOffset) + mGlobalOffset;
       mLastMapping.reset();
-      MSE_DEBUG(WebMContainerParser,
-                "New cluster found at start, ending previous one");
+      MSE_DEBUG("New cluster found at start, ending previous one");
       return NS_ERROR_NOT_AVAILABLE;
     }
 
     if (initSegment) {
       mOffset = 0;
       mParser = WebMBufferedParser(0);
       mOverlappedMapping.Clear();
       mInitData = new MediaByteBuffer();
@@ -225,21 +244,20 @@ public:
         if (!mInitData->SetLength(mParser.mInitEndOffset, fallible)) {
           // Super unlikely OOM
           return NS_ERROR_OUT_OF_MEMORY;
         }
         mCompleteInitSegmentRange =
           MediaByteRange(0, mParser.mInitEndOffset) + mGlobalOffset;
         char* buffer = reinterpret_cast<char*>(mInitData->Elements());
         mResource->ReadFromCache(buffer, 0, mParser.mInitEndOffset);
-        MSE_DEBUG(WebMContainerParser, "Stashed init of %" PRId64 " bytes.",
-                  mParser.mInitEndOffset);
+        MSE_DEBUG("Stashed init of %" PRId64 " bytes.", mParser.mInitEndOffset);
         mResource = nullptr;
       } else {
-        MSE_DEBUG(WebMContainerParser, "Incomplete init found.");
+        MSE_DEBUG("Incomplete init found.");
       }
       mHasInitData = true;
     }
     mOffset += aData->Length();
     mTotalParsed += aData->Length();
 
     if (mapping.IsEmpty()) {
       return NS_ERROR_NOT_AVAILABLE;
@@ -252,17 +270,17 @@ public:
     bool foundNewCluster = false;
     while (mapping[0].mSyncOffset != mapping[endIdx].mSyncOffset) {
       endIdx -= 1;
       foundNewCluster = true;
     }
 
     int32_t completeIdx = endIdx;
     while (completeIdx >= 0 && mOffset < mapping[completeIdx].mEndOffset) {
-      MSE_DEBUG(WebMContainerParser, "block is incomplete, missing: %" PRId64,
+      MSE_DEBUG("block is incomplete, missing: %" PRId64,
                 mapping[completeIdx].mEndOffset - mOffset);
       completeIdx -= 1;
     }
 
     // Save parsed blocks for which we do not have all data yet.
     mOverlappedMapping.AppendElements(mapping.Elements() + completeIdx + 1,
                                       mapping.Length() - completeIdx - 1);
 
@@ -312,18 +330,17 @@ public:
 
     uint64_t frameDuration =
       (completeIdx + 1u < mapping.Length())
       ? mapping[completeIdx + 1].mTimecode - mapping[completeIdx].mTimecode
       : mapping[completeIdx].mTimecode - previousMapping.ref().mTimecode;
     aStart = mapping[0].mTimecode / NS_PER_USEC;
     aEnd = (mapping[completeIdx].mTimecode + frameDuration) / NS_PER_USEC;
 
-    MSE_DEBUG(WebMContainerParser,
-              "[%" PRId64 ", %" PRId64 "] [fso=%" PRId64 ", leo=%" PRId64
+    MSE_DEBUG("[%" PRId64 ", %" PRId64 "] [fso=%" PRId64 ", leo=%" PRId64
               ", l=%zu processedIdx=%u fs=%" PRId64 "]",
               aStart,
               aEnd,
               mapping[0].mSyncOffset,
               mapping[completeIdx].mEndOffset,
               mapping.Length(),
               completeIdx,
               mCompleteMediaSegmentRange.mEnd);
@@ -432,31 +449,31 @@ public:
   {
     ContainerParser::IsInitSegmentPresent(aData);
     // Each MP4 atom has a chunk size and chunk type. The root chunk in an MP4
     // file is the 'ftyp' atom followed by a file type. We just check for a
     // vaguely valid 'ftyp' atom.
     if (aData->Length() < 8) {
       return NS_ERROR_NOT_AVAILABLE;
     }
-    AtomParser parser(mType, aData, AtomParser::StopAt::eInitSegment);
+    AtomParser parser(*this, aData, AtomParser::StopAt::eInitSegment);
     if (!parser.IsValid()) {
       return MediaResult(
         NS_ERROR_FAILURE,
         RESULT_DETAIL("Invalid Top-Level Box:%s", parser.LastInvalidBox()));
     }
     return parser.StartWithInitSegment() ? NS_OK : NS_ERROR_NOT_AVAILABLE;
   }
 
   MediaResult IsMediaSegmentPresent(MediaByteBuffer* aData) override
   {
     if (aData->Length() < 8) {
       return NS_ERROR_NOT_AVAILABLE;
     }
-    AtomParser parser(mType, aData, AtomParser::StopAt::eMediaSegment);
+    AtomParser parser(*this, aData, AtomParser::StopAt::eMediaSegment);
     if (!parser.IsValid()) {
       return MediaResult(
         NS_ERROR_FAILURE,
         RESULT_DETAIL("Invalid Box:%s", parser.LastInvalidBox()));
     }
     return parser.StartWithMediaSegment() ? NS_OK : NS_ERROR_NOT_AVAILABLE;
   }
 
@@ -466,26 +483,29 @@ private:
   public:
     enum class StopAt
     {
       eInitSegment,
       eMediaSegment,
       eEnd
     };
 
-    AtomParser(const MediaContainerType& aType, const MediaByteBuffer* aData,
+    AtomParser(const MP4ContainerParser& aParser,
+               const MediaByteBuffer* aData,
                StopAt aStop = StopAt::eEnd)
     {
-      mValid = Init(aType, aData, aStop).isOk();
+      mValid = Init(aParser, aData, aStop).isOk();
     }
 
-    Result<Ok, nsresult> Init(const MediaContainerType& aType, const MediaByteBuffer* aData,
-               StopAt aStop)
+    Result<Ok, nsresult> Init(const MP4ContainerParser& aParser,
+                              const MediaByteBuffer* aData,
+                              StopAt aStop)
     {
-      const MediaContainerType mType(aType); // for logging macro.
+      const MediaContainerType mType(
+        aParser.ContainerType()); // for logging macro.
       BufferReader reader(aData);
       AtomType initAtom("moov");
       AtomType mediaAtom("moof");
       AtomType dataAtom("mdat");
 
       // Valid top-level boxes defined in ISO/IEC 14496-12 (Table 1)
       static const AtomType validBoxes[] = {
         "ftyp", "moov", // init segment
@@ -499,19 +519,23 @@ private:
 
       while (reader.Remaining() >= 8) {
         uint32_t tmp;
         MOZ_TRY_VAR(tmp, reader.ReadU32());
         uint64_t size = tmp;
         const uint8_t* typec = reader.Peek(4);
         MOZ_TRY_VAR(tmp, reader.ReadU32());
         AtomType type(tmp);
-        MSE_DEBUGV(AtomParser ,"Checking atom:'%c%c%c%c' @ %u",
-                   typec[0], typec[1], typec[2], typec[3],
-                   (uint32_t)reader.Offset() - 8);
+        MSE_DEBUGVEX(&aParser,
+                     "Checking atom:'%c%c%c%c' @ %u",
+                     typec[0],
+                     typec[1],
+                     typec[2],
+                     typec[3],
+                     (uint32_t)reader.Offset() - 8);
         if (std::find(std::begin(validBoxes), std::end(validBoxes), type)
             == std::end(validBoxes)) {
           // No valid box found, no point continuing.
           mLastInvalidBox[0] = typec[0];
           mLastInvalidBox[1] = typec[1];
           mLastInvalidBox[2] = typec[2];
           mLastInvalidBox[3] = typec[3];
           mLastInvalidBox[4] = '\0';
@@ -618,20 +642,19 @@ public:
       if (range.Length()) {
         mCompleteInitSegmentRange = range + mGlobalOffset;
         if (!mInitData->SetLength(range.Length(), fallible)) {
           // Super unlikely OOM
           return NS_ERROR_OUT_OF_MEMORY;
         }
         char* buffer = reinterpret_cast<char*>(mInitData->Elements());
         mResource->ReadFromCache(buffer, range.mStart, range.Length());
-        MSE_DEBUG(MP4ContainerParser ,"Stashed init of %" PRIu64 " bytes.",
-                  range.Length());
+        MSE_DEBUG("Stashed init of %" PRIu64 " bytes.", range.Length());
       } else {
-        MSE_DEBUG(MP4ContainerParser, "Incomplete init found.");
+        MSE_DEBUG("Incomplete init found.");
       }
       mHasInitData = true;
     }
     mTotalParsed += aData->Length();
 
     MP4Interval<Microseconds> compositionRange =
       mParser->GetCompositionRange(byteRanges);
 
@@ -649,18 +672,17 @@ public:
       return NS_ERROR_OUT_OF_MEMORY;
     }
 
     if (compositionRange.IsNull()) {
       return NS_ERROR_NOT_AVAILABLE;
     }
     aStart = compositionRange.start;
     aEnd = compositionRange.end;
-    MSE_DEBUG(MP4ContainerParser, "[%" PRId64 ", %" PRId64 "]",
-              aStart, aEnd);
+    MSE_DEBUG("[%" PRId64 ", %" PRId64 "]", aStart, aEnd);
     return NS_OK;
   }
 
   // Gaps of up to 35ms (marginally longer than a single frame at 30fps) are
   // considered to be sequential frames.
   int64_t GetRoundingError() override
   {
     return 35000;
@@ -698,33 +720,33 @@ public:
   /// Returns false if the header is invalid or incomplete,
   /// without modifying the passed-in Header object.
   bool Parse(MediaByteBuffer* aData, Header& header)
   {
     MOZ_ASSERT(aData);
 
     // ADTS initialization segments are just the packet header.
     if (aData->Length() < 7) {
-      MSE_DEBUG(ADTSContainerParser, "buffer too short for header.");
+      MSE_DEBUG("buffer too short for header.");
       return false;
     }
     // Check 0xfffx sync word plus layer 0.
     if (((*aData)[0] != 0xff) || (((*aData)[1] & 0xf6) != 0xf0)) {
-      MSE_DEBUG(ADTSContainerParser, "no syncword.");
+      MSE_DEBUG("no syncword.");
       return false;
     }
     bool have_crc = !((*aData)[1] & 0x01);
     if (have_crc && aData->Length() < 9) {
-      MSE_DEBUG(ADTSContainerParser, "buffer too short for header with crc.");
+      MSE_DEBUG("buffer too short for header with crc.");
       return false;
     }
     uint8_t frequency_index = ((*aData)[2] & 0x3c) >> 2;
     MOZ_ASSERT(frequency_index < 16);
     if (frequency_index == 15) {
-      MSE_DEBUG(ADTSContainerParser, "explicit frequency disallowed.");
+      MSE_DEBUG("explicit frequency disallowed.");
       return false;
     }
     size_t header_length = have_crc ? 9 : 7;
     size_t data_length = (((*aData)[3] & 0x03) << 11) |
                          (((*aData)[4] & 0xff) << 3) |
                          (((*aData)[5] & 0xe0) >> 5);
     uint8_t frames = ((*aData)[6] & 0x03) + 1;
     MOZ_ASSERT(frames > 0);
@@ -743,19 +765,20 @@ public:
     // Call superclass for logging.
     ContainerParser::IsInitSegmentPresent(aData);
 
     Header header;
     if (!Parse(aData, header)) {
       return NS_ERROR_NOT_AVAILABLE;
     }
 
-    MSE_DEBUGV(ADTSContainerParser, "%llu byte frame %d aac frames%s",
-        (unsigned long long)header.frame_length, (int)header.aac_frames,
-        header.have_crc ? " crc" : "");
+    MSE_DEBUGV("%llu byte frame %d aac frames%s",
+               (unsigned long long)header.frame_length,
+               (int)header.aac_frames,
+               header.have_crc ? " crc" : "");
 
     return NS_OK;
   }
 
   MediaResult IsMediaSegmentPresent(MediaByteBuffer* aData) override
   {
     // Call superclass for logging.
     ContainerParser::IsMediaSegmentPresent(aData);
@@ -794,31 +817,30 @@ public:
       MediaByteRange(0, int64_t(header.header_length));
 
     // Cache raw header in case the caller wants a copy.
     mInitData = new MediaByteBuffer(header.header_length);
     mInitData->AppendElements(aData->Elements(), header.header_length);
 
     // Check that we have enough data for the frame body.
     if (aData->Length() < header.frame_length) {
-      MSE_DEBUGV(ADTSContainerParser, "Not enough data for %llu byte frame"
-          " in %llu byte buffer.",
-          (unsigned long long)header.frame_length,
-          (unsigned long long)(aData->Length()));
+      MSE_DEBUGV("Not enough data for %llu byte frame"
+                 " in %llu byte buffer.",
+                 (unsigned long long)header.frame_length,
+                 (unsigned long long)(aData->Length()));
       return NS_ERROR_NOT_AVAILABLE;
     }
     mCompleteMediaSegmentRange = MediaByteRange(header.header_length,
                                                 header.frame_length);
     // The ADTS MediaSource Byte Stream Format document doesn't
     // define media header. Just treat it the same as the whole
     // media segment.
     mCompleteMediaHeaderRange = mCompleteMediaSegmentRange;
 
-    MSE_DEBUG(ADTSContainerParser, "[%" PRId64 ", %" PRId64 "]",
-              aStart, aEnd);
+    MSE_DEBUG("[%" PRId64 ", %" PRId64 "]", aStart, aEnd);
     // We don't update timestamps, regardless.
     return NS_ERROR_NOT_AVAILABLE;
   }
 
   // Audio shouldn't have gaps.
   // Especially when we generate the timestamps ourselves.
   int64_t GetRoundingError() override
   {
@@ -845,10 +867,11 @@ ContainerParser::CreateForMIMEType(const
   }
 #endif
 
   return new ContainerParser(aType);
 }
 
 #undef MSE_DEBUG
 #undef MSE_DEBUGV
+#undef MSE_DEBUGVEX
 
 } // namespace mozilla
--- a/dom/media/mediasource/ContainerParser.h
+++ b/dom/media/mediasource/ContainerParser.h
@@ -73,16 +73,18 @@ public:
   // or an empty range if not complete.
   MediaByteRange MediaHeaderRange();
   // Returns the byte range of the first complete media segment or an empty
   // range if not complete.
   MediaByteRange MediaSegmentRange();
 
   static ContainerParser* CreateForMIMEType(const MediaContainerType& aType);
 
+  const MediaContainerType& ContainerType() const { return mType; }
+
 protected:
   RefPtr<MediaByteBuffer> mInitData;
   RefPtr<SourceBufferResource> mResource;
   bool mHasInitData;
   uint64_t mTotalParsed;
   uint64_t mGlobalOffset;
   MediaByteRange mCompleteInitSegmentRange;
   MediaByteRange mCompleteMediaHeaderRange;
--- a/dom/media/mediasource/MediaSource.cpp
+++ b/dom/media/mediasource/MediaSource.cpp
@@ -51,18 +51,28 @@ mozilla::LogModule* GetMediaSourceLog()
 }
 
 mozilla::LogModule* GetMediaSourceAPILog()
 {
   static mozilla::LazyLogModule sLogModule("MediaSource");
   return sLogModule;
 }
 
-#define MSE_DEBUG(arg, ...) MOZ_LOG(GetMediaSourceLog(), mozilla::LogLevel::Debug, ("MediaSource(%p)::%s: " arg, this, __func__, ##__VA_ARGS__))
-#define MSE_API(arg, ...) MOZ_LOG(GetMediaSourceAPILog(), mozilla::LogLevel::Debug, ("MediaSource(%p)::%s: " arg, this, __func__, ##__VA_ARGS__))
+#define MSE_DEBUG(arg, ...)                                                    \
+  DDMOZ_LOG(GetMediaSourceLog(),                                               \
+            mozilla::LogLevel::Debug,                                          \
+            "::%s: " arg,                                                      \
+            __func__,                                                          \
+            ##__VA_ARGS__)
+#define MSE_API(arg, ...)                                                      \
+  DDMOZ_LOG(GetMediaSourceAPILog(),                                            \
+            mozilla::LogLevel::Debug,                                          \
+            "::%s: " arg,                                                      \
+            __func__,                                                          \
+            ##__VA_ARGS__)
 
 // Arbitrary limit.
 static const unsigned int MAX_SOURCE_BUFFERS = 16;
 
 namespace mozilla {
 
 // Returns true if we should enable MSE webm regardless of preferences.
 // 1. If MP4/H264 isn't supported:
@@ -387,20 +397,22 @@ MediaSource::EndOfStream(const MediaResu
 MediaSource::IsTypeSupported(const GlobalObject& aOwner, const nsAString& aType)
 {
   MOZ_ASSERT(NS_IsMainThread());
   DecoderDoctorDiagnostics diagnostics;
   nsresult rv = IsTypeSupported(aType, &diagnostics);
   nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(aOwner.GetAsSupports());
   diagnostics.StoreFormatDiagnostics(window ? window->GetExtantDoc() : nullptr,
                                      aType, NS_SUCCEEDED(rv), __func__);
-#define this nullptr
-  MSE_API("IsTypeSupported(aType=%s)%s ",
-          NS_ConvertUTF16toUTF8(aType).get(), rv == NS_OK ? "OK" : "[not supported]");
-#undef this // don't ever remove this line !
+  MOZ_LOG(GetMediaSourceAPILog(),
+          mozilla::LogLevel::Debug,
+          ("MediaSource::%s: IsTypeSupported(aType=%s) %s",
+           __func__,
+           NS_ConvertUTF16toUTF8(aType).get(),
+           rv == NS_OK ? "OK" : "[not supported]"));
   return NS_SUCCEEDED(rv);
 }
 
 /* static */ bool
 MediaSource::Enabled(JSContext* cx, JSObject* aGlobal)
 {
   return Preferences::GetBool("media.mediasource.enabled");
 }
--- a/dom/media/mediasource/MediaSourceDecoder.cpp
+++ b/dom/media/mediasource/MediaSourceDecoder.cpp
@@ -13,18 +13,28 @@
 #include "MediaSourceUtils.h"
 #include "SourceBuffer.h"
 #include "SourceBufferList.h"
 #include "VideoUtils.h"
 #include <algorithm>
 
 extern mozilla::LogModule* GetMediaSourceLog();
 
-#define MSE_DEBUG(arg, ...) MOZ_LOG(GetMediaSourceLog(), mozilla::LogLevel::Debug, ("MediaSourceDecoder(%p)::%s: " arg, this, __func__, ##__VA_ARGS__))
-#define MSE_DEBUGV(arg, ...) MOZ_LOG(GetMediaSourceLog(), mozilla::LogLevel::Verbose, ("MediaSourceDecoder(%p)::%s: " arg, this, __func__, ##__VA_ARGS__))
+#define MSE_DEBUG(arg, ...)                                                    \
+  DDMOZ_LOG(GetMediaSourceLog(),                                               \
+            mozilla::LogLevel::Debug,                                          \
+            "::%s: " arg,                                                      \
+            __func__,                                                          \
+            ##__VA_ARGS__)
+#define MSE_DEBUGV(arg, ...)                                                   \
+  DDMOZ_LOG(GetMediaSourceLog(),                                               \
+            mozilla::LogLevel::Verbose,                                        \
+            "::%s: " arg,                                                      \
+            __func__,                                                          \
+            ##__VA_ARGS__)
 
 using namespace mozilla::media;
 
 namespace mozilla {
 
 MediaSourceDecoder::MediaSourceDecoder(MediaDecoderInit& aInit)
   : MediaDecoder(aInit)
   , mMediaSource(nullptr)
--- a/dom/media/mediasource/SourceBuffer.cpp
+++ b/dom/media/mediasource/SourceBuffer.cpp
@@ -30,19 +30,37 @@
 #endif
 
 struct JSContext;
 class JSObject;
 
 extern mozilla::LogModule* GetMediaSourceLog();
 extern mozilla::LogModule* GetMediaSourceAPILog();
 
-#define MSE_DEBUG(arg, ...) MOZ_LOG(GetMediaSourceLog(), mozilla::LogLevel::Debug, ("SourceBuffer(%p:%s)::%s: " arg, this, mType.OriginalString().Data(), __func__, ##__VA_ARGS__))
-#define MSE_DEBUGV(arg, ...) MOZ_LOG(GetMediaSourceLog(), mozilla::LogLevel::Verbose, ("SourceBuffer(%p:%s)::%s: " arg, this, mType.OriginalString().Data(), __func__, ##__VA_ARGS__))
-#define MSE_API(arg, ...) MOZ_LOG(GetMediaSourceAPILog(), mozilla::LogLevel::Debug, ("SourceBuffer(%p:%s)::%s: " arg, this, mType.OriginalString().Data(), __func__, ##__VA_ARGS__))
+#define MSE_DEBUG(arg, ...)                                                    \
+  DDMOZ_LOG(GetMediaSourceLog(),                                               \
+            mozilla::LogLevel::Debug,                                          \
+            "(%s)::%s: " arg,                                                  \
+            mType.OriginalString().Data(),                                     \
+            __func__,                                                          \
+            ##__VA_ARGS__)
+#define MSE_DEBUGV(arg, ...)                                                   \
+  DDMOZ_LOG(GetMediaSourceLog(),                                               \
+            mozilla::LogLevel::Verbose,                                        \
+            "(%s)::%s: " arg,                                                  \
+            mType.OriginalString().Data(),                                     \
+            __func__,                                                          \
+            ##__VA_ARGS__)
+#define MSE_API(arg, ...)                                                      \
+  DDMOZ_LOG(GetMediaSourceAPILog(),                                            \
+            mozilla::LogLevel::Debug,                                          \
+            "(%s)::%s: " arg,                                                  \
+            mType.OriginalString().Data(),                                     \
+            __func__,                                                          \
+            ##__VA_ARGS__)
 
 namespace mozilla {
 
 using media::TimeUnit;
 typedef SourceBufferAttributes::AppendState AppendState;
 
 namespace dom {
 
--- a/dom/media/mediasource/SourceBufferResource.cpp
+++ b/dom/media/mediasource/SourceBufferResource.cpp
@@ -12,25 +12,27 @@
 
 mozilla::LogModule* GetSourceBufferResourceLog()
 {
   static mozilla::LazyLogModule sLogModule("SourceBufferResource");
   return sLogModule;
 }
 
 #define SBR_DEBUG(arg, ...)                                                    \
-  MOZ_LOG(                                                                     \
-    GetSourceBufferResourceLog(),                                              \
-    mozilla::LogLevel::Debug,                                                  \
-    ("SourceBufferResource(%p)::%s: " arg, this, __func__, ##__VA_ARGS__))
+  DDMOZ_LOG(GetSourceBufferResourceLog(),                                      \
+            mozilla::LogLevel::Debug,                                          \
+            "::%s: " arg,                                                      \
+            __func__,                                                          \
+            ##__VA_ARGS__)
 #define SBR_DEBUGV(arg, ...)                                                   \
-  MOZ_LOG(                                                                     \
-    GetSourceBufferResourceLog(),                                              \
-    mozilla::LogLevel::Verbose,                                                \
-    ("SourceBufferResource(%p)::%s: " arg, this, __func__, ##__VA_ARGS__))
+  DDMOZ_LOG(GetSourceBufferResourceLog(),                                      \
+            mozilla::LogLevel::Verbose,                                        \
+            "::%s: " arg,                                                      \
+            __func__,                                                          \
+            ##__VA_ARGS__)
 
 namespace mozilla {
 
 nsresult
 SourceBufferResource::Close()
 {
   MOZ_ASSERT(OnTaskQueue());
   SBR_DEBUG("Close");
--- a/dom/media/mediasource/TrackBuffersManager.cpp
+++ b/dom/media/mediasource/TrackBuffersManager.cpp
@@ -19,25 +19,43 @@
 #ifdef MOZ_FMP4
 #include "MP4Demuxer.h"
 #endif
 
 #include <limits>
 
 extern mozilla::LogModule* GetMediaSourceLog();
 
-#define MSE_DEBUG(arg, ...) MOZ_LOG(GetMediaSourceLog(), mozilla::LogLevel::Debug, ("TrackBuffersManager(%p:%s)::%s: " arg, this, mType.OriginalString().Data(), __func__, ##__VA_ARGS__))
-#define MSE_DEBUGV(arg, ...) MOZ_LOG(GetMediaSourceLog(), mozilla::LogLevel::Verbose, ("TrackBuffersManager(%p:%s)::%s: " arg, this, mType.OriginalString().Data(), __func__, ##__VA_ARGS__))
+#define MSE_DEBUG(arg, ...)                                                    \
+  DDMOZ_LOG(GetMediaSourceLog(),                                               \
+            mozilla::LogLevel::Debug,                                          \
+            "(%s)::%s: " arg,                                                  \
+            mType.OriginalString().Data(),                                     \
+            __func__,                                                          \
+            ##__VA_ARGS__)
+#define MSE_DEBUGV(arg, ...)                                                   \
+  DDMOZ_LOG(GetMediaSourceLog(),                                               \
+            mozilla::LogLevel::Verbose,                                        \
+            "(%s)::%s: " arg,                                                  \
+            mType.OriginalString().Data(),                                     \
+            __func__,                                                          \
+            ##__VA_ARGS__)
 
 mozilla::LogModule* GetMediaSourceSamplesLog()
 {
   static mozilla::LazyLogModule sLogModule("MediaSourceSamples");
   return sLogModule;
 }
-#define SAMPLE_DEBUG(arg, ...) MOZ_LOG(GetMediaSourceSamplesLog(), mozilla::LogLevel::Debug, ("TrackBuffersManager(%p:%s)::%s: " arg, this, mType.OriginalString().Data(), __func__, ##__VA_ARGS__))
+#define SAMPLE_DEBUG(arg, ...)                                                 \
+  DDMOZ_LOG(GetMediaSourceSamplesLog(),                                        \
+            mozilla::LogLevel::Debug,                                          \
+            "(%s)::%s: " arg,                                                  \
+            mType.OriginalString().Data(),                                     \
+            __func__,                                                          \
+            ##__VA_ARGS__)
 
 namespace mozilla {
 
 using dom::SourceBufferAppendMode;
 using media::TimeUnit;
 using media::TimeInterval;
 using media::TimeIntervals;
 typedef SourceBufferTask::AppendBufferResult AppendBufferResult;
--- a/dom/media/mp3/MP3Demuxer.cpp
+++ b/dom/media/mp3/MP3Demuxer.cpp
@@ -11,20 +11,20 @@
 #include <limits>
 
 #include "mozilla/Assertions.h"
 #include "nsAutoPtr.h"
 #include "TimeUnits.h"
 #include "VideoUtils.h"
 
 extern mozilla::LazyLogModule gMediaDemuxerLog;
-#define MP3LOG(msg, ...) \
-  MOZ_LOG(gMediaDemuxerLog, LogLevel::Debug, ("MP3Demuxer " msg, ##__VA_ARGS__))
-#define MP3LOGV(msg, ...) \
-  MOZ_LOG(gMediaDemuxerLog, LogLevel::Verbose, ("MP3Demuxer " msg, ##__VA_ARGS__))
+#define MP3LOG(msg, ...)                                                       \
+  DDMOZ_LOG(gMediaDemuxerLog, LogLevel::Debug, msg, ##__VA_ARGS__)
+#define MP3LOGV(msg, ...)                                                      \
+  DDMOZ_LOG(gMediaDemuxerLog, LogLevel::Verbose, msg, ##__VA_ARGS__)
 
 using mozilla::media::TimeUnit;
 using mozilla::media::TimeInterval;
 using mozilla::media::TimeIntervals;
 using mozilla::BufferReader;
 
 namespace mozilla {
 
@@ -768,8 +768,11 @@ MP3TrackDemuxer::AverageFrameLength() co
   if (vbr.IsComplete() && vbr.NumAudioFrames().value() + 1) {
     return static_cast<double>(vbr.NumBytes().value())
            / (vbr.NumAudioFrames().value() + 1);
   }
   return 0.0;
 }
 
 } // namespace mozilla
+
+#undef MP3LOG
+#undef MP3LOGV
--- a/dom/media/mp4/MP4Demuxer.cpp
+++ b/dom/media/mp4/MP4Demuxer.cpp
@@ -24,17 +24,22 @@
 #include "nsPrintfCString.h"
 
 extern mozilla::LazyLogModule gMediaDemuxerLog;
 mozilla::LogModule* GetDemuxerLog()
 {
   return gMediaDemuxerLog;
 }
 
-#define LOG(arg, ...) MOZ_LOG(gMediaDemuxerLog, mozilla::LogLevel::Debug, ("MP4Demuxer(%p)::%s: " arg, this, __func__, ##__VA_ARGS__))
+#define LOG(arg, ...)                                                          \
+  DDMOZ_LOG(gMediaDemuxerLog,                                                  \
+            mozilla::LogLevel::Debug,                                          \
+            "::%s: " arg,                                                      \
+            __func__,                                                          \
+            ##__VA_ARGS__)
 
 namespace mozilla {
 
 DDLoggedTypeDeclNameAndBase(MP4TrackDemuxer, MediaTrackDemuxer);
 
 class MP4TrackDemuxer
   : public MediaTrackDemuxer
   , public DecoderDoctorLifeLogger<MP4TrackDemuxer>
--- a/dom/media/ogg/OggDemuxer.cpp
+++ b/dom/media/ogg/OggDemuxer.cpp
@@ -17,17 +17,22 @@
 #include "MediaDataDemuxer.h"
 #include "nsAutoRef.h"
 #include "XiphExtradata.h"
 #include "MediaPrefs.h"
 
 #include <algorithm>
 
 extern mozilla::LazyLogModule gMediaDemuxerLog;
-#define OGG_DEBUG(arg, ...) MOZ_LOG(gMediaDemuxerLog, mozilla::LogLevel::Debug, ("OggDemuxer(%p)::%s: " arg, this, __func__, ##__VA_ARGS__))
+#define OGG_DEBUG(arg, ...)                                                    \
+  DDMOZ_LOG(gMediaDemuxerLog,                                                  \
+            mozilla::LogLevel::Debug,                                          \
+            "::%s: " arg,                                                      \
+            __func__,                                                          \
+            ##__VA_ARGS__)
 
 // Un-comment to enable logging of seek bisections.
 //#define SEEK_LOGGING
 #ifdef SEEK_LOGGING
 #define SEEK_LOG(type, msg) MOZ_LOG(gMediaDemuxerLog, type, msg)
 #else
 #define SEEK_LOG(type, msg)
 #endif
--- a/dom/media/platforms/agnostic/AOMDecoder.cpp
+++ b/dom/media/platforms/agnostic/AOMDecoder.cpp
@@ -14,27 +14,53 @@
 #include "mozilla/SyncRunnable.h"
 #include "nsError.h"
 #include "prsystem.h"
 #include "ImageContainer.h"
 
 #include <algorithm>
 
 #undef LOG
-#define LOG(arg, ...) MOZ_LOG(sPDMLog, mozilla::LogLevel::Debug, ("AOMDecoder(%p)::%s: " arg, this, __func__, ##__VA_ARGS__))
-#define LOG_RESULT(code, message, ...) MOZ_LOG(sPDMLog, mozilla::LogLevel::Debug, ("AOMDecoder::%s: %s (code %d) " message, __func__, aom_codec_err_to_string(code), (int)code, ##__VA_ARGS__))
+#define LOG(arg, ...)                                                          \
+  DDMOZ_LOG(                                                                   \
+    sPDMLog, mozilla::LogLevel::Debug, "::%s: " arg, __func__, ##__VA_ARGS__)
+#define LOG_RESULT(code, message, ...)                                         \
+  DDMOZ_LOG(sPDMLog,                                                           \
+            mozilla::LogLevel::Debug,                                          \
+            "::%s: %s (code %d) " message,                                     \
+            __func__,                                                          \
+            aom_codec_err_to_string(code),                                     \
+            (int)code,                                                         \
+            ##__VA_ARGS__)
+#define LOGEX_RESULT(_this, code, message, ...)                                \
+  DDMOZ_LOGEX(_this,                                                           \
+              sPDMLog,                                                         \
+              mozilla::LogLevel::Debug,                                        \
+              "::%s: %s (code %d) " message,                                   \
+              __func__,                                                        \
+              aom_codec_err_to_string(code),                                   \
+              (int)code,                                                       \
+              ##__VA_ARGS__)
+#define LOG_STATIC_RESULT(code, message, ...)                                  \
+  MOZ_LOG(sPDMLog,                                                             \
+          mozilla::LogLevel::Debug,                                            \
+          ("AOMDecoder::%s: %s (code %d) " message,                            \
+           __func__,                                                           \
+           aom_codec_err_to_string(code),                                      \
+           (int)code,                                                          \
+           ##__VA_ARGS__))
 
 namespace mozilla {
 
 using namespace gfx;
 using namespace layers;
 
-
 static MediaResult
-InitContext(aom_codec_ctx_t* aCtx,
+InitContext(AOMDecoder& aAOMDecoder,
+            aom_codec_ctx_t* aCtx,
             const VideoInfo& aInfo)
 {
   aom_codec_iface_t* dx = aom_codec_av1_dx();
   if (!dx) {
     return MediaResult(NS_ERROR_DOM_MEDIA_FATAL_ERR,
                        RESULT_DETAIL("Couldn't get AV1 decoder interface."));
   }
 
@@ -51,17 +77,18 @@ InitContext(aom_codec_ctx_t* aCtx,
   PodZero(&config);
   config.threads = decode_threads;
   config.w = config.h = 0; // set after decode
 
   aom_codec_flags_t flags = 0;
 
   auto res = aom_codec_dec_init(aCtx, dx, &config, flags);
   if (res != AOM_CODEC_OK) {
-    LOG_RESULT(res, "Codec initialization failed!");
+    LOGEX_RESULT(
+      &aAOMDecoder, res, "Codec initialization failed, res=%d", int(res));
     return MediaResult(NS_ERROR_DOM_MEDIA_FATAL_ERR,
                        RESULT_DETAIL("AOM error initializing AV1 decoder: %s",
                                      aom_codec_err_to_string(res)));
   }
   return NS_OK;
 }
 
 AOMDecoder::AOMDecoder(const CreateDecoderParams& aParams)
@@ -78,26 +105,26 @@ AOMDecoder::~AOMDecoder()
 
 RefPtr<ShutdownPromise>
 AOMDecoder::Shutdown()
 {
   RefPtr<AOMDecoder> self = this;
   return InvokeAsync(mTaskQueue, __func__, [self]() {
     auto res = aom_codec_destroy(&self->mCodec);
     if (res != AOM_CODEC_OK) {
-      LOG_RESULT(res, "aom_codec_destroy");
+      LOGEX_RESULT(self.get(), res, "aom_codec_destroy");
     }
     return ShutdownPromise::CreateAndResolve(true, __func__);
   });
 }
 
 RefPtr<MediaDataDecoder::InitPromise>
 AOMDecoder::Init()
 {
-  MediaResult rv = InitContext(&mCodec, mInfo);
+  MediaResult rv = InitContext(*this, &mCodec, mInfo);
   if (NS_FAILED(rv)) {
     return AOMDecoder::InitPromise::CreateAndReject(rv,
                                                     __func__);
   }
   return AOMDecoder::InitPromise::CreateAndResolve(TrackInfo::kVideoTrack,
                                                    __func__);
 }
 
@@ -333,17 +360,18 @@ AOMDecoder::IsKeyframe(Span<const uint8_
   aom_codec_stream_info_t info;
   PodZero(&info);
 
   auto res = aom_codec_peek_stream_info(aom_codec_av1_dx(),
                                         aBuffer.Elements(),
                                         aBuffer.Length(),
                                         &info);
   if (res != AOM_CODEC_OK) {
-    LOG_RESULT(res, "couldn't get keyframe flag with aom_codec_peek_stream_info");
+    LOG_STATIC_RESULT(
+      res, "couldn't get keyframe flag with aom_codec_peek_stream_info");
     return false;
   }
 
   return bool(info.is_kf);
 }
 
 /* static */
 gfx::IntSize
@@ -352,16 +380,17 @@ AOMDecoder::GetFrameSize(Span<const uint
   aom_codec_stream_info_t info;
   PodZero(&info);
 
   auto res = aom_codec_peek_stream_info(aom_codec_av1_dx(),
                                         aBuffer.Elements(),
                                         aBuffer.Length(),
                                         &info);
   if (res != AOM_CODEC_OK) {
-    LOG_RESULT(res, "couldn't get frame size with aom_codec_peek_stream_info");
+    LOG_STATIC_RESULT(
+      res, "couldn't get frame size with aom_codec_peek_stream_info");
   }
 
   return gfx::IntSize(info.w, info.h);
 }
 
 } // namespace mozilla
 #undef LOG
--- a/dom/media/platforms/agnostic/OpusDecoder.cpp
+++ b/dom/media/platforms/agnostic/OpusDecoder.cpp
@@ -16,18 +16,19 @@
 
 #include <inttypes.h>  // For PRId64
 
 #include "opus/opus.h"
 extern "C" {
 #include "opus/opus_multistream.h"
 }
 
-#define OPUS_DEBUG(arg, ...) MOZ_LOG(sPDMLog, mozilla::LogLevel::Debug, \
-    ("OpusDataDecoder(%p)::%s: " arg, this, __func__, ##__VA_ARGS__))
+#define OPUS_DEBUG(arg, ...)                                                   \
+  DDMOZ_LOG(                                                                   \
+    sPDMLog, mozilla::LogLevel::Debug, "::%s: " arg, __func__, ##__VA_ARGS__)
 
 namespace mozilla {
 
 OpusDataDecoder::OpusDataDecoder(const CreateDecoderParams& aParams)
   : mInfo(aParams.AudioConfig())
   , mTaskQueue(aParams.mTaskQueue)
   , mOpusDecoder(nullptr)
   , mSkip(0)
--- a/dom/media/platforms/agnostic/TheoraDecoder.cpp
+++ b/dom/media/platforms/agnostic/TheoraDecoder.cpp
@@ -10,17 +10,22 @@
 #include "gfx2DGlue.h"
 #include "mozilla/PodOperations.h"
 #include "nsError.h"
 #include "ImageContainer.h"
 
 #include <algorithm>
 
 #undef LOG
-#define LOG(arg, ...) MOZ_LOG(gMediaDecoderLog, mozilla::LogLevel::Debug, ("TheoraDecoder(%p)::%s: " arg, this, __func__, ##__VA_ARGS__))
+#define LOG(arg, ...)                                                          \
+  DDMOZ_LOG(gMediaDecoderLog,                                                  \
+            mozilla::LogLevel::Debug,                                          \
+            "::%s: " arg,                                                      \
+            __func__,                                                          \
+            ##__VA_ARGS__)
 
 namespace mozilla {
 
 using namespace gfx;
 using namespace layers;
 
 extern LazyLogModule gMediaDecoderLog;
 
--- a/dom/media/platforms/agnostic/VPXDecoder.cpp
+++ b/dom/media/platforms/agnostic/VPXDecoder.cpp
@@ -11,17 +11,19 @@
 #include "mozilla/SyncRunnable.h"
 #include "ImageContainer.h"
 #include "nsError.h"
 #include "prsystem.h"
 
 #include <algorithm>
 
 #undef LOG
-#define LOG(arg, ...) MOZ_LOG(sPDMLog, mozilla::LogLevel::Debug, ("VPXDecoder(%p)::%s: " arg, this, __func__, ##__VA_ARGS__))
+#define LOG(arg, ...)                                                          \
+  DDMOZ_LOG(                                                                   \
+    sPDMLog, mozilla::LogLevel::Debug, "::%s: " arg, __func__, ##__VA_ARGS__)
 
 namespace mozilla {
 
 using namespace gfx;
 using namespace layers;
 
 static VPXDecoder::Codec MimeTypeToCodec(const nsACString& aMimeType)
 {
--- a/dom/media/platforms/apple/AppleATDecoder.cpp
+++ b/dom/media/platforms/apple/AppleATDecoder.cpp
@@ -9,17 +9,19 @@
 #include "MP4Decoder.h"
 #include "Adts.h"
 #include "MediaInfo.h"
 #include "mozilla/Logging.h"
 #include "mozilla/SyncRunnable.h"
 #include "mozilla/UniquePtr.h"
 #include "VideoUtils.h"
 
-#define LOG(...) MOZ_LOG(sPDMLog, mozilla::LogLevel::Debug, (__VA_ARGS__))
+#define LOG(...) DDMOZ_LOG(sPDMLog, mozilla::LogLevel::Debug, __VA_ARGS__)
+#define LOGEX(_this, ...)                                                      \
+  DDMOZ_LOGEX(_this, sPDMLog, mozilla::LogLevel::Debug, __VA_ARGS__)
 #define FourCC2Str(n) ((char[5]){(char)(n >> 24), (char)(n >> 16), (char)(n >> 8), (char)(n), 0})
 
 namespace mozilla {
 
 AppleATDecoder::AppleATDecoder(const AudioInfo& aConfig,
                                TaskQueue* aTaskQueue)
   : mConfig(aConfig)
   , mFileStreamError(false)
@@ -617,36 +619,40 @@ static void
 _MetadataCallback(void* aAppleATDecoder,
                   AudioFileStreamID aStream,
                   AudioFileStreamPropertyID aProperty,
                   UInt32* aFlags)
 {
   AppleATDecoder* decoder = static_cast<AppleATDecoder*>(aAppleATDecoder);
   MOZ_RELEASE_ASSERT(decoder->mTaskQueue->IsCurrentThreadIn());
 
-  LOG("MetadataCallback receiving: '%s'", FourCC2Str(aProperty));
+  LOGEX(decoder, "MetadataCallback receiving: '%s'", FourCC2Str(aProperty));
   if (aProperty == kAudioFileStreamProperty_MagicCookieData) {
     UInt32 size;
     Boolean writeable;
     OSStatus rv = AudioFileStreamGetPropertyInfo(aStream,
                                                  aProperty,
                                                  &size,
                                                  &writeable);
     if (rv) {
-      LOG("Couldn't get property info for '%s' (%s)",
-          FourCC2Str(aProperty), FourCC2Str(rv));
+      LOGEX(decoder,
+            "Couldn't get property info for '%s' (%s)",
+            FourCC2Str(aProperty),
+            FourCC2Str(rv));
       decoder->mFileStreamError = true;
       return;
     }
     auto data = MakeUnique<uint8_t[]>(size);
     rv = AudioFileStreamGetProperty(aStream, aProperty,
                                     &size, data.get());
     if (rv) {
-      LOG("Couldn't get property '%s' (%s)",
-          FourCC2Str(aProperty), FourCC2Str(rv));
+      LOGEX(decoder,
+            "Couldn't get property '%s' (%s)",
+            FourCC2Str(aProperty),
+            FourCC2Str(rv));
       decoder->mFileStreamError = true;
       return;
     }
     decoder->mMagicCookie.AppendElements(data.get(), size);
   }
 }
 
 static void
@@ -704,8 +710,11 @@ AppleATDecoder::GetImplicitAACMagicCooki
     AudioFileStreamClose(mStream);
     mStream = nullptr;
   }
 
   return (mFileStreamError || status) ? NS_ERROR_FAILURE : NS_OK;
 }
 
 } // namespace mozilla
+
+#undef LOG
+#undef LOGEX
--- a/dom/media/platforms/apple/AppleCMLinker.cpp
+++ b/dom/media/platforms/apple/AppleCMLinker.cpp
@@ -99,8 +99,10 @@ AppleCMLinker::GetIOConst(const char* sy
   if (!address) {
     return nullptr;
   }
 
   return *address;
 }
 
 } // namespace mozilla
+
+#undef LOG
--- a/dom/media/platforms/apple/AppleVTDecoder.cpp
+++ b/dom/media/platforms/apple/AppleVTDecoder.cpp
@@ -15,17 +15,19 @@
 #include "mozilla/ArrayUtils.h"
 #include "H264.h"
 #include "nsAutoPtr.h"
 #include "nsThreadUtils.h"
 #include "mozilla/Logging.h"
 #include "VideoUtils.h"
 #include "gfxPlatform.h"
 
-#define LOG(...) MOZ_LOG(sPDMLog, mozilla::LogLevel::Debug, (__VA_ARGS__))
+#define LOG(...) DDMOZ_LOG(sPDMLog, mozilla::LogLevel::Debug, __VA_ARGS__)
+#define LOGEX(_this, ...)                                                      \
+  DDMOZ_LOGEX(_this, sPDMLog, mozilla::LogLevel::Debug, __VA_ARGS__)
 
 namespace mozilla {
 
 AppleVTDecoder::AppleVTDecoder(const VideoInfo& aConfig,
                                TaskQueue* aTaskQueue,
                                layers::ImageContainer* aImageContainer)
   : mExtraData(aConfig.mExtraData)
   , mPictureWidth(aConfig.mImage.width)
@@ -286,20 +288,24 @@ static void
 PlatformCallback(void* decompressionOutputRefCon,
                  void* sourceFrameRefCon,
                  OSStatus status,
                  VTDecodeInfoFlags flags,
                  CVImageBufferRef image,
                  CMTime presentationTimeStamp,
                  CMTime presentationDuration)
 {
-  LOG("AppleVideoDecoder %s status %d flags %d", __func__, static_cast<int>(status), flags);
-
   AppleVTDecoder* decoder =
     static_cast<AppleVTDecoder*>(decompressionOutputRefCon);
+  LOGEX(decoder,
+        "AppleVideoDecoder %s status %d flags %d",
+        __func__,
+        static_cast<int>(status),
+        flags);
+
   nsAutoPtr<AppleVTDecoder::AppleFrameRef> frameRef(
     static_cast<AppleVTDecoder::AppleFrameRef*>(sourceFrameRefCon));
 
   // Validate our arguments.
   if (status != noErr || !image) {
     NS_WARNING("VideoToolbox decoder returned no data");
     image = nullptr;
   } else if (flags & kVTDecodeInfo_FrameDropped) {
@@ -658,8 +664,11 @@ AppleVTDecoder::CreateOutputConfiguratio
                             &kCFTypeDictionaryKeyCallBacks,
                             &kCFTypeDictionaryValueCallBacks);
 #else
   MOZ_ASSERT_UNREACHABLE("No MacIOSurface on iOS");
 #endif
 }
 
 } // namespace mozilla
+
+#undef LOG
+#undef LOGEX
--- a/dom/media/platforms/omx/OmxDataDecoder.cpp
+++ b/dom/media/platforms/omx/OmxDataDecoder.cpp
@@ -14,24 +14,27 @@
 
 #include "mozilla/IntegerPrintfMacros.h"
 
 #ifdef LOG
 #undef LOG
 #undef LOGL
 #endif
 
-#define LOG(arg, ...) MOZ_LOG(sPDMLog, mozilla::LogLevel::Debug, ("OmxDataDecoder(%p)::%s: " arg, this, __func__, ##__VA_ARGS__))
+#define LOG(arg, ...)                                                          \
+  DDMOZ_LOG(                                                                   \
+    sPDMLog, mozilla::LogLevel::Debug, "::%s: " arg, __func__, ##__VA_ARGS__)
 
-#define LOGL(arg, ...)                                                     \
-  {                                                                        \
-    void* p = self;                                              \
-    MOZ_LOG(sPDMLog, mozilla::LogLevel::Debug,                         \
-            ("OmxDataDecoder(%p)::%s: " arg, p, __func__, ##__VA_ARGS__)); \
-  }
+#define LOGL(arg, ...)                                                         \
+  DDMOZ_LOGEX(self.get(),                                                      \
+              sPDMLog,                                                         \
+              mozilla::LogLevel::Debug,                                        \
+              "::%s: " arg,                                                    \
+              __func__,                                                        \
+              ##__VA_ARGS__)
 
 #define CHECK_OMX_ERR(err)     \
   if (err != OMX_ErrorNone) {  \
     NotifyError(err, __func__);\
     return;                    \
   }                            \
 
 namespace mozilla {
@@ -999,16 +1002,22 @@ MediaDataHelper::CreateYUV420VideoData(B
                                  0, // Filled later by caller.
                                  media::TimeUnit::Zero(), // Filled later by caller.
                                  media::TimeUnit::FromMicroseconds(1), // We don't know the duration.
                                  b,
                                  0, // Filled later by caller.
                                  media::TimeUnit::FromMicroseconds(-1),
                                  info.ImageRect());
 
-  LOG("YUV420 VideoData: disp width %d, height %d, pic width %d, height %d, time %lld",
-      info.mDisplay.width, info.mDisplay.height, info.mImage.width,
-      info.mImage.height, aBufferData->mBuffer->nTimeStamp);
+  MOZ_LOG(sPDMLog,
+          mozilla::LogLevel::Debug,
+          ("YUV420 VideoData: disp width %d, height %d, pic width %d, height "
+           "%d, time %lld",
+           info.mDisplay.width,
+           info.mDisplay.height,
+           info.mImage.width,
+           info.mImage.height,
+           aBufferData->mBuffer->nTimeStamp));
 
   return data.forget();
 }
 
 }
--- a/dom/media/webm/WebMDemuxer.cpp
+++ b/dom/media/webm/WebMDemuxer.cpp
@@ -26,17 +26,22 @@
 #include "prprf.h"           // leaving it for PR_vsnprintf()
 #include "mozilla/IntegerPrintfMacros.h"
 #include "mozilla/Sprintf.h"
 
 #include <algorithm>
 #include <numeric>
 #include <stdint.h>
 
-#define WEBM_DEBUG(arg, ...) MOZ_LOG(gMediaDemuxerLog, mozilla::LogLevel::Debug, ("WebMDemuxer(%p)::%s: " arg, this, __func__, ##__VA_ARGS__))
+#define WEBM_DEBUG(arg, ...)                                                   \
+  DDMOZ_LOG(gMediaDemuxerLog,                                                  \
+            mozilla::LogLevel::Debug,                                          \
+            "::%s: " arg,                                                      \
+            __func__,                                                          \
+            ##__VA_ARGS__)
 extern mozilla::LazyLogModule gMediaDemuxerLog;
 
 namespace mozilla {
 
 using namespace gfx;
 using media::TimeUnit;
 
 LazyLogModule gNesteggLog("Nestegg");