From ddf74ea35b77819f2427e26b71d91133444c7481 Mon Sep 17 00:00:00 2001 From: Eric Rahm Date: Fri, 8 Jul 2016 11:47:04 -0700 Subject: [PATCH] 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 | 4 ++-- dom/media/directshow/AudioSinkInputPin.cpp | 4 ++-- dom/media/directshow/DirectShowDecoder.cpp | 1 + dom/media/directshow/DirectShowReader.cpp | 18 +++++++----------- dom/media/directshow/DirectShowReader.h | 2 ++ dom/media/directshow/DirectShowUtils.cpp | 2 +- dom/media/directshow/SampleSink.cpp | 8 ++++---- dom/media/directshow/SourceFilter.cpp | 4 ++-- dom/media/directshow/moz.build | 6 +++--- 9 files changed, 24 insertions(+), 25 deletions(-) diff --git a/dom/media/directshow/AudioSinkFilter.cpp b/dom/media/directshow/AudioSinkFilter.cpp index 5682af1a5876..9f23c0e00acb 100644 --- a/dom/media/directshow/AudioSinkFilter.cpp +++ b/dom/media/directshow/AudioSinkFilter.cpp @@ -23,8 +23,8 @@ 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), diff --git a/dom/media/directshow/AudioSinkInputPin.cpp b/dom/media/directshow/AudioSinkInputPin.cpp index 285dc3ca8736..85a6e3da3e68 100644 --- a/dom/media/directshow/AudioSinkInputPin.cpp +++ b/dom/media/directshow/AudioSinkInputPin.cpp @@ -15,8 +15,8 @@ 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, diff --git a/dom/media/directshow/DirectShowDecoder.cpp b/dom/media/directshow/DirectShowDecoder.cpp index 714ed685ef23..da68b4daa1d1 100644 --- a/dom/media/directshow/DirectShowDecoder.cpp +++ b/dom/media/directshow/DirectShowDecoder.cpp @@ -6,6 +6,7 @@ #include "DirectShowDecoder.h" #include "DirectShowReader.h" +#include "DirectShowUtils.h" #include "MediaDecoderStateMachine.h" #include "mozilla/Preferences.h" #include "mozilla/WindowsVersion.h" diff --git a/dom/media/directshow/DirectShowReader.cpp b/dom/media/directshow/DirectShowReader.cpp index 9e091019200c..cacf6f8de8ed 100644 --- a/dom/media/directshow/DirectShowReader.cpp +++ b/dom/media/directshow/DirectShowReader.cpp @@ -17,13 +17,14 @@ 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), @@ -78,11 +79,6 @@ ParseMP3Headers(MP3FrameParser *aParser, MediaResource *aResource) 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) diff --git a/dom/media/directshow/DirectShowReader.h b/dom/media/directshow/DirectShowReader.h index 7f613b873a65..e1326d416e36 100644 --- a/dom/media/directshow/DirectShowReader.h +++ b/dom/media/directshow/DirectShowReader.h @@ -60,6 +60,8 @@ public: RefPtr 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 diff --git a/dom/media/directshow/DirectShowUtils.cpp b/dom/media/directshow/DirectShowUtils.cpp index a8714625b2da..b2afa7528c98 100644 --- a/dom/media/directshow/DirectShowUtils.cpp +++ b/dom/media/directshow/DirectShowUtils.cpp @@ -287,7 +287,7 @@ CanDecodeMP3UsingDirectShow() } // 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, diff --git a/dom/media/directshow/SampleSink.cpp b/dom/media/directshow/SampleSink.cpp index 1102d32f5a38..fa5dc8d19c23 100644 --- a/dom/media/directshow/SampleSink.cpp +++ b/dom/media/directshow/SampleSink.cpp @@ -14,8 +14,8 @@ 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"), @@ -65,7 +65,7 @@ SampleSink::Receive(IMediaSample* aSample) 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]", @@ -102,7 +102,7 @@ SampleSink::Extract(RefPtr& aOutSample) } 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]", diff --git a/dom/media/directshow/SourceFilter.cpp b/dom/media/directshow/SourceFilter.cpp index e563b49cf608..4c5a0882c3e1 100644 --- a/dom/media/directshow/SourceFilter.cpp +++ b/dom/media/directshow/SourceFilter.cpp @@ -20,8 +20,8 @@ namespace mozilla { //#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 diff --git a/dom/media/directshow/moz.build b/dom/media/directshow/moz.build index 07b52fb7093f..730f1a362e95 100644 --- a/dom/media/directshow/moz.build +++ b/dom/media/directshow/moz.build @@ -13,16 +13,16 @@ EXPORTS += [ ] 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