Bug 1274913 - Use LazyLogModule directly for DirectShow logging. r=rillian
authorEric Rahm <erahm@mozilla.com>
Fri, 08 Jul 2016 11:47:04 -0700
changeset 305568 0fadabf932c25817f2b8f218532171b82ac96280
parent 305567 d6523dfaab78d8409b2da9eac0693960c2d11904
child 305569 a46d84c52f89110162c4f292d646521bd6efc676
push id79637
push usererahm@mozilla.com
push dateTue, 19 Jul 2016 23:54:14 +0000
treeherdermozilla-inbound@0fadabf932c2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrillian
bugs1274913
milestone50.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 1274913 - Use LazyLogModule directly for DirectShow logging. r=rillian This should help fix unitialized statics crashes on Windows in the DirectShow logging code. Additional changes are included to fix unified build issues.
dom/media/directshow/AudioSinkFilter.cpp
dom/media/directshow/AudioSinkInputPin.cpp
dom/media/directshow/DirectShowDecoder.cpp
dom/media/directshow/DirectShowReader.cpp
dom/media/directshow/DirectShowReader.h
dom/media/directshow/DirectShowUtils.cpp
dom/media/directshow/SampleSink.cpp
dom/media/directshow/SourceFilter.cpp
dom/media/directshow/moz.build
--- a/dom/media/directshow/AudioSinkFilter.cpp
+++ b/dom/media/directshow/AudioSinkFilter.cpp
@@ -18,18 +18,18 @@
 
 DEFINE_GUID(CLSID_MozAudioSinkFilter, 0x1872d8c8, 0xea8d, 0x4c34, 0xae, 0x96, 0x69, 0xde,
             0xf1, 0x33, 0x7b, 0x33);
 
 using namespace mozilla::media;
 
 namespace mozilla {
 
-extern LogModule* GetDirectShowLog();
-#define LOG(...) MOZ_LOG(GetDirectShowLog(), mozilla::LogLevel::Debug, (__VA_ARGS__))
+static LazyLogModule gDirectShowLog("DirectShowDecoder");
+#define LOG(...) MOZ_LOG(gDirectShowLog, mozilla::LogLevel::Debug, (__VA_ARGS__))
 
 AudioSinkFilter::AudioSinkFilter(const wchar_t* aObjectName, HRESULT* aOutResult)
   : BaseFilter(aObjectName, CLSID_MozAudioSinkFilter),
     mFilterCritSec("AudioSinkFilter::mFilterCritSec")
 {
   (*aOutResult) = S_OK;
   mInputPin = new AudioSinkInputPin(L"AudioSinkInputPin",
                                     this,
--- a/dom/media/directshow/AudioSinkInputPin.cpp
+++ b/dom/media/directshow/AudioSinkInputPin.cpp
@@ -10,18 +10,18 @@
 #include "mozilla/Logging.h"
 
 #include <wmsdkidl.h>
 
 using namespace mozilla::media;
 
 namespace mozilla {
 
-extern LogModule* GetDirectShowLog();
-#define LOG(...) MOZ_LOG(GetDirectShowLog(), mozilla::LogLevel::Debug, (__VA_ARGS__))
+static LazyLogModule gDirectShowLog("DirectShowDecoder");
+#define LOG(...) MOZ_LOG(gDirectShowLog, mozilla::LogLevel::Debug, (__VA_ARGS__))
 
 AudioSinkInputPin::AudioSinkInputPin(wchar_t* aObjectName,
                                      AudioSinkFilter* aFilter,
                                      mozilla::CriticalSection* aLock,
                                      HRESULT* aOutResult)
   : BaseInputPin(aObjectName, aFilter, aLock, aOutResult, aObjectName),
     mSegmentStartTime(0)
 {
--- a/dom/media/directshow/DirectShowDecoder.cpp
+++ b/dom/media/directshow/DirectShowDecoder.cpp
@@ -1,16 +1,17 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim:set ts=2 sw=2 sts=2 et cindent: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "DirectShowDecoder.h"
 #include "DirectShowReader.h"
+#include "DirectShowUtils.h"
 #include "MediaDecoderStateMachine.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/WindowsVersion.h"
 
 namespace mozilla {
 
 MediaDecoderStateMachine* DirectShowDecoder::CreateStateMachine()
 {
--- a/dom/media/directshow/DirectShowReader.cpp
+++ b/dom/media/directshow/DirectShowReader.cpp
@@ -12,23 +12,24 @@
 #include "SourceFilter.h"
 #include "SampleSink.h"
 #include "VideoUtils.h"
 
 using namespace mozilla::media;
 
 namespace mozilla {
 
-LogModule*
-GetDirectShowLog() {
-  static LazyLogModule log("DirectShowDecoder");
-  return log;
-}
+// Windows XP's MP3 decoder filter. This is available on XP only, on Vista
+// and later we can use the DMO Wrapper filter and MP3 decoder DMO.
+const GUID DirectShowReader::CLSID_MPEG_LAYER_3_DECODER_FILTER =
+{ 0x38BE3000, 0xDBF4, 0x11D0, {0x86, 0x0E, 0x00, 0xA0, 0x24, 0xCF, 0xEF, 0x6D} };
 
-#define LOG(...) MOZ_LOG(GetDirectShowLog(), mozilla::LogLevel::Debug, (__VA_ARGS__))
+
+static LazyLogModule gDirectShowLog("DirectShowDecoder");
+#define LOG(...) MOZ_LOG(gDirectShowLog, mozilla::LogLevel::Debug, (__VA_ARGS__))
 
 DirectShowReader::DirectShowReader(AbstractMediaDecoder* aDecoder)
   : MediaDecoderReader(aDecoder),
     mMP3FrameParser(aDecoder->GetResource()->GetLength()),
 #ifdef DIRECTSHOW_REGISTER_GRAPH
     mRotRegister(0),
 #endif
     mNumChannels(0),
@@ -73,21 +74,16 @@ ParseMP3Headers(MP3FrameParser *aParser,
 
     aParser->Parse(reinterpret_cast<uint8_t*>(buffer), bytesRead, offset);
     offset += bytesRead;
   }
 
   return aParser->IsMP3() ? NS_OK : NS_ERROR_FAILURE;
 }
 
-// Windows XP's MP3 decoder filter. This is available on XP only, on Vista
-// and later we can use the DMO Wrapper filter and MP3 decoder DMO.
-static const GUID CLSID_MPEG_LAYER_3_DECODER_FILTER =
-{ 0x38BE3000, 0xDBF4, 0x11D0, {0x86, 0x0E, 0x00, 0xA0, 0x24, 0xCF, 0xEF, 0x6D} };
-
 nsresult
 DirectShowReader::ReadMetadata(MediaInfo* aInfo,
                                MetadataTags** aTags)
 {
   MOZ_ASSERT(OnTaskQueue());
   HRESULT hr;
   nsresult rv;
 
--- a/dom/media/directshow/DirectShowReader.h
+++ b/dom/media/directshow/DirectShowReader.h
@@ -55,16 +55,18 @@ public:
                         int64_t aTimeThreshold) override;
 
   nsresult ReadMetadata(MediaInfo* aInfo,
                         MetadataTags** aTags) override;
 
   RefPtr<SeekPromise>
   Seek(SeekTarget aTarget, int64_t aEndTime) override;
 
+  static const GUID CLSID_MPEG_LAYER_3_DECODER_FILTER;
+
 private:
   // Notifies the filter graph that playback is complete. aStatus is
   // the code to send to the filter graph. Always returns false, so
   // that we can just "return Finish()" from DecodeAudioData().
   bool Finish(HRESULT aStatus);
 
   nsresult SeekInternal(int64_t aTime);
 
--- a/dom/media/directshow/DirectShowUtils.cpp
+++ b/dom/media/directshow/DirectShowUtils.cpp
@@ -282,17 +282,17 @@ CanDecodeMP3UsingDirectShow()
                               nullptr,
                               CLSCTX_INPROC_SERVER,
                               IID_IBaseFilter,
                               getter_AddRefs(filter)))) {
     return false;
   }
 
   // Can we create either the WinXP MP3 decoder filter or the MP3 DMO decoder?
-  if (FAILED(CoCreateInstance(CLSID_MPEG_LAYER_3_DECODER_FILTER,
+  if (FAILED(CoCreateInstance(DirectShowReader::CLSID_MPEG_LAYER_3_DECODER_FILTER,
                               nullptr,
                               CLSCTX_INPROC_SERVER,
                               IID_IBaseFilter,
                               getter_AddRefs(filter))) &&
       FAILED(CreateMP3DMOWrapperFilter(getter_AddRefs(filter)))) {
     return false;
   }
 
--- a/dom/media/directshow/SampleSink.cpp
+++ b/dom/media/directshow/SampleSink.cpp
@@ -9,18 +9,18 @@
 #include "AudioSinkInputPin.h"
 #include "VideoUtils.h"
 #include "mozilla/Logging.h"
 
 using namespace mozilla::media;
 
 namespace mozilla {
 
-extern LogModule* GetDirectShowLog();
-#define LOG(...) MOZ_LOG(GetDirectShowLog(), mozilla::LogLevel::Debug, (__VA_ARGS__))
+static LazyLogModule gDirectShowLog("DirectShowDecoder");
+#define LOG(...) MOZ_LOG(gDirectShowLog, mozilla::LogLevel::Debug, (__VA_ARGS__))
 
 SampleSink::SampleSink()
   : mMonitor("SampleSink"),
     mIsFlushing(false),
     mAtEOS(false)
 {
   MOZ_COUNT_CTOR(SampleSink);
 }
@@ -60,17 +60,17 @@ SampleSink::Receive(IMediaSample* aSampl
     }
     if (mAtEOS) {
       return E_UNEXPECTED;
     }
     // Wait until the consumer thread consumes the sample.
     mon.Wait();
   }
 
-  if (MOZ_LOG_TEST(GetDirectShowLog(), LogLevel::Debug)) {
+  if (MOZ_LOG_TEST(gDirectShowLog, LogLevel::Debug)) {
     REFERENCE_TIME start = 0, end = 0;
     HRESULT hr = aSample->GetMediaTime(&start, &end);
     LOG("SampleSink::Receive() [%4.2lf-%4.2lf]",
         (double)RefTimeToUsecs(start) / USECS_PER_S,
         (double)RefTimeToUsecs(end) / USECS_PER_S);
   }
 
   mSample = aSample;
@@ -97,17 +97,17 @@ SampleSink::Extract(RefPtr<IMediaSample>
       // before reporting EOS.
       return E_UNEXPECTED;
     }
     // Wait until the producer thread gives us a sample.
     mon.Wait();
   }
   aOutSample = mSample;
 
-  if (MOZ_LOG_TEST(GetDirectShowLog(), LogLevel::Debug)) {
+  if (MOZ_LOG_TEST(gDirectShowLog, LogLevel::Debug)) {
     int64_t start = 0, end = 0;
     mSample->GetMediaTime(&start, &end);
     LOG("SampleSink::Extract() [%4.2lf-%4.2lf]",
         (double)RefTimeToUsecs(start) / USECS_PER_S,
         (double)RefTimeToUsecs(end) / USECS_PER_S);
   }
 
   mSample = nullptr;
--- a/dom/media/directshow/SourceFilter.cpp
+++ b/dom/media/directshow/SourceFilter.cpp
@@ -15,18 +15,18 @@
 using namespace mozilla::media;
 
 namespace mozilla {
 
 // Define to trace what's on...
 //#define DEBUG_SOURCE_TRACE 1
 
 #if defined (DEBUG_SOURCE_TRACE)
-extern LogModule* GetDirectShowLog();
-#define DIRECTSHOW_LOG(...) MOZ_LOG(GetDirectShowLog(), mozilla::LogLevel::Debug, (__VA_ARGS__))
+static LazyLogModule gDirectShowLog("DirectShowDecoder");
+#define DIRECTSHOW_LOG(...) MOZ_LOG(gDirectShowLog, mozilla::LogLevel::Debug, (__VA_ARGS__))
 #else
 #define DIRECTSHOW_LOG(...)
 #endif
 
 static HRESULT
 DoGetInterface(IUnknown* aUnknown, void** aInterface)
 {
   if (!aInterface)
--- a/dom/media/directshow/moz.build
+++ b/dom/media/directshow/moz.build
@@ -8,26 +8,26 @@ EXPORTS += [
     'AudioSinkFilter.h',
     'AudioSinkInputPin.h',
     'DirectShowDecoder.h',
     'DirectShowReader.h',
     'DirectShowUtils.h',
 ]
 
 UNIFIED_SOURCES += [
-    'AudioSinkInputPin.cpp',
     'DirectShowDecoder.cpp',
-    'DirectShowReader.cpp',
     'DirectShowUtils.cpp',
-    'SampleSink.cpp',
     'SourceFilter.cpp',
 ]
 
 SOURCES += [
     'AudioSinkFilter.cpp',
+    'AudioSinkInputPin.cpp',
+    'DirectShowReader.cpp',
+    'SampleSink.cpp',
 ]
 
 # If WebRTC isn't being built, we need to compile the DirectShow base classes so that
 # they're available at link time.
 if not CONFIG['MOZ_WEBRTC']:
     SOURCES += [
         '/media/webrtc/trunk/webrtc/modules/video_capture/windows/BaseFilter.cpp',
         '/media/webrtc/trunk/webrtc/modules/video_capture/windows/BaseInputPin.cpp',