From d024ce20420095f3b755848cb8198854039af063 Mon Sep 17 00:00:00 2001 From: Jean-Yves Avenard Date: Mon, 5 Oct 2015 21:08:56 +1100 Subject: [PATCH] Bug 1206977: P2. Wrap PDM creation in a new PDMFactory class. r=cpearce There is no change of behaviour from the original PlatformDecoderModule. --- dom/media/MediaFormatReader.cpp | 6 +- dom/media/platforms/PDMFactory.cpp | 244 ++++++++++++++++++ dom/media/platforms/PDMFactory.h | 80 ++++++ dom/media/platforms/PlatformDecoderModule.cpp | 226 +--------------- dom/media/platforms/PlatformDecoderModule.h | 24 +- .../platforms/ffmpeg/FFmpegDecoderModule.h | 3 +- .../platforms/ffmpeg/FFmpegRuntimeLinker.cpp | 6 + .../platforms/ffmpeg/FFmpegRuntimeLinker.h | 2 + dom/media/platforms/moz.build | 1 + 9 files changed, 346 insertions(+), 246 deletions(-) create mode 100644 dom/media/platforms/PDMFactory.cpp create mode 100644 dom/media/platforms/PDMFactory.h diff --git a/dom/media/MediaFormatReader.cpp b/dom/media/MediaFormatReader.cpp index 812fa159f2b..f33848c5882 100644 --- a/dom/media/MediaFormatReader.cpp +++ b/dom/media/MediaFormatReader.cpp @@ -240,15 +240,13 @@ MediaFormatReader::IsWaitingOnCDMResource() { bool MediaFormatReader::IsSupportedAudioMimeType(const nsACString& aMimeType) { - return mPlatform && (mPlatform->SupportsMimeType(aMimeType) || - PlatformDecoderModule::AgnosticMimeType(aMimeType)); + return mPlatform && mPlatform->SupportsMimeType(aMimeType); } bool MediaFormatReader::IsSupportedVideoMimeType(const nsACString& aMimeType) { - return mPlatform && (mPlatform->SupportsMimeType(aMimeType) || - PlatformDecoderModule::AgnosticMimeType(aMimeType)); + return mPlatform && mPlatform->SupportsMimeType(aMimeType); } nsRefPtr diff --git a/dom/media/platforms/PDMFactory.cpp b/dom/media/platforms/PDMFactory.cpp new file mode 100644 index 00000000000..a2e5f23d64e --- /dev/null +++ b/dom/media/platforms/PDMFactory.cpp @@ -0,0 +1,244 @@ +/* -*- 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 "PDMFactory.h" + +#ifdef XP_WIN +#include "WMFDecoderModule.h" +#endif +#ifdef MOZ_FFMPEG +#include "FFmpegRuntimeLinker.h" +#endif +#ifdef MOZ_APPLEMEDIA +#include "AppleDecoderModule.h" +#endif +#ifdef MOZ_GONK_MEDIACODEC +#include "GonkDecoderModule.h" +#endif +#ifdef MOZ_WIDGET_ANDROID +#include "AndroidDecoderModule.h" +#endif +#include "GMPDecoderModule.h" + +#include "mozilla/Preferences.h" +#include "mozilla/TaskQueue.h" + +#include "mozilla/SharedThreadPool.h" + +#include "MediaInfo.h" +#include "FuzzingWrapper.h" +#include "H264Converter.h" + +#include "OpusDecoder.h" +#include "VorbisDecoder.h" +#include "VPXDecoder.h" + +namespace mozilla { + +extern already_AddRefed CreateAgnosticDecoderModule(); +extern already_AddRefed CreateBlankDecoderModule(); + +bool PDMFactory::sUseBlankDecoder = false; +bool PDMFactory::sGonkDecoderEnabled = false; +bool PDMFactory::sAndroidMCDecoderEnabled = false; +bool PDMFactory::sAndroidMCDecoderPreferred = false; +bool PDMFactory::sGMPDecoderEnabled = false; +bool PDMFactory::sEnableFuzzingWrapper = false; +uint32_t PDMFactory::sVideoOutputMinimumInterval_ms = 0; +bool PDMFactory::sDontDelayInputExhausted = false; + +/* static */ +void +PDMFactory::Init() +{ + MOZ_ASSERT(NS_IsMainThread()); + static bool alreadyInitialized = false; + if (alreadyInitialized) { + return; + } + alreadyInitialized = true; + + Preferences::AddBoolVarCache(&sUseBlankDecoder, + "media.fragmented-mp4.use-blank-decoder"); +#ifdef MOZ_GONK_MEDIACODEC + Preferences::AddBoolVarCache(&sGonkDecoderEnabled, + "media.fragmented-mp4.gonk.enabled", false); +#endif +#ifdef MOZ_WIDGET_ANDROID + Preferences::AddBoolVarCache(&sAndroidMCDecoderEnabled, + "media.fragmented-mp4.android-media-codec.enabled", false); + Preferences::AddBoolVarCache(&sAndroidMCDecoderPreferred, + "media.fragmented-mp4.android-media-codec.preferred", false); +#endif + + Preferences::AddBoolVarCache(&sGMPDecoderEnabled, + "media.fragmented-mp4.gmp.enabled", false); + + Preferences::AddBoolVarCache(&sEnableFuzzingWrapper, + "media.decoder.fuzzing.enabled", false); + Preferences::AddUintVarCache(&sVideoOutputMinimumInterval_ms, + "media.decoder.fuzzing.video-output-minimum-interval-ms", 0); + Preferences::AddBoolVarCache(&sDontDelayInputExhausted, + "media.decoder.fuzzing.dont-delay-inputexhausted", false); + +#ifdef XP_WIN + WMFDecoderModule::Init(); +#endif +#ifdef MOZ_APPLEMEDIA + AppleDecoderModule::Init(); +#endif +#ifdef MOZ_FFMPEG + FFmpegRuntimeLinker::Link(); +#endif +} + +PDMFactory::PDMFactory() + : mCurrentPDM(CreatePDM()) +{ + if (!mCurrentPDM || NS_FAILED(mCurrentPDM->Startup())) { + mCurrentPDM = CreateAgnosticDecoderModule(); + } +} + +PDMFactory::~PDMFactory() +{ +} + +already_AddRefed +PDMFactory::CreateDecoder(const TrackInfo& aConfig, + FlushableTaskQueue* aTaskQueue, + MediaDataDecoderCallback* aCallback, + layers::LayersBackend aLayersBackend, + layers::ImageContainer* aImageContainer) +{ + MOZ_ASSERT(mCurrentPDM); + + nsRefPtr m; + + bool hasPlatformDecoder = mCurrentPDM->SupportsMimeType(aConfig.mMimeType); + + if (aConfig.GetAsAudioInfo()) { + if (!hasPlatformDecoder && VorbisDataDecoder::IsVorbis(aConfig.mMimeType)) { + m = new VorbisDataDecoder(*aConfig.GetAsAudioInfo(), + aTaskQueue, + aCallback); + } else if (!hasPlatformDecoder && OpusDataDecoder::IsOpus(aConfig.mMimeType)) { + m = new OpusDataDecoder(*aConfig.GetAsAudioInfo(), + aTaskQueue, + aCallback); + } else { + m = mCurrentPDM->CreateAudioDecoder(*aConfig.GetAsAudioInfo(), + aTaskQueue, + aCallback); + } + return m.forget(); + } + + if (!aConfig.GetAsVideoInfo()) { + return nullptr; + } + + MediaDataDecoderCallback* callback = aCallback; + nsRefPtr callbackWrapper; + if (sEnableFuzzingWrapper) { + callbackWrapper = new DecoderCallbackFuzzingWrapper(aCallback); + callbackWrapper->SetVideoOutputMinimumInterval( + TimeDuration::FromMilliseconds(sVideoOutputMinimumInterval_ms)); + callbackWrapper->SetDontDelayInputExhausted(sDontDelayInputExhausted); + callback = callbackWrapper.get(); + } + + if (H264Converter::IsH264(aConfig)) { + nsRefPtr h + = new H264Converter(mCurrentPDM, + *aConfig.GetAsVideoInfo(), + aLayersBackend, + aImageContainer, + aTaskQueue, + callback); + const nsresult rv = h->GetLastError(); + if (NS_SUCCEEDED(rv) || rv == NS_ERROR_NOT_INITIALIZED) { + // The H264Converter either successfully created the wrapped decoder, + // or there wasn't enough AVCC data to do so. Otherwise, there was some + // problem, for example WMF DLLs were missing. + m = h.forget(); + } + } else if (!hasPlatformDecoder && VPXDecoder::IsVPX(aConfig.mMimeType)) { + m = new VPXDecoder(*aConfig.GetAsVideoInfo(), + aImageContainer, + aTaskQueue, + callback); + } else { + m = mCurrentPDM->CreateVideoDecoder(*aConfig.GetAsVideoInfo(), + aLayersBackend, + aImageContainer, + aTaskQueue, + callback); + } + + if (callbackWrapper && m) { + m = new DecoderFuzzingWrapper(m.forget(), callbackWrapper.forget()); + } + + return m.forget(); +} + +bool +PDMFactory::SupportsMimeType(const nsACString& aMimeType) +{ + MOZ_ASSERT(mCurrentPDM); + return mCurrentPDM->SupportsMimeType(aMimeType) || + VPXDecoder::IsVPX(aMimeType) || + OpusDataDecoder::IsOpus(aMimeType) || + VorbisDataDecoder::IsVorbis(aMimeType); +} + +already_AddRefed +PDMFactory::CreatePDM() +{ + if (sGMPDecoderEnabled) { + nsRefPtr m(new GMPDecoderModule()); + return m.forget(); + } +#ifdef MOZ_WIDGET_ANDROID + if(sAndroidMCDecoderPreferred && sAndroidMCDecoderEnabled){ + nsRefPtr m(new AndroidDecoderModule()); + return m.forget(); + } +#endif + if (sUseBlankDecoder) { + return CreateBlankDecoderModule(); + } +#ifdef XP_WIN + nsRefPtr m(new WMFDecoderModule()); + return m.forget(); +#endif +#ifdef MOZ_FFMPEG + nsRefPtr mffmpeg = FFmpegRuntimeLinker::CreateDecoderModule(); + if (mffmpeg) { + return mffmpeg.forget(); + } +#endif +#ifdef MOZ_APPLEMEDIA + nsRefPtr m(new AppleDecoderModule()); + return m.forget(); +#endif +#ifdef MOZ_GONK_MEDIACODEC + if (sGonkDecoderEnabled) { + nsRefPtr m(new GonkDecoderModule()); + return m.forget(); + } +#endif +#ifdef MOZ_WIDGET_ANDROID + if(sAndroidMCDecoderEnabled){ + nsRefPtr m(new AndroidDecoderModule()); + return m.forget(); + } +#endif + return nullptr; +} + +} // namespace mozilla diff --git a/dom/media/platforms/PDMFactory.h b/dom/media/platforms/PDMFactory.h new file mode 100644 index 00000000000..2cd70a83bfc --- /dev/null +++ b/dom/media/platforms/PDMFactory.h @@ -0,0 +1,80 @@ +/* -*- 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/. */ + +#if !defined(PDMFactory_h_) +#define PDMFactory_h_ + +#include "PlatformDecoderModule.h" + +namespace mozilla { + +class PDMFactory : public PlatformDecoderModule { +public: + PDMFactory(); + virtual ~PDMFactory(); + + // Call on the main thread to initialize the static state + // needed by Create(). + static void Init(); + + already_AddRefed + CreateDecoder(const TrackInfo& aConfig, + FlushableTaskQueue* aTaskQueue, + MediaDataDecoderCallback* aCallback, + layers::LayersBackend aLayersBackend = layers::LayersBackend::LAYERS_NONE, + layers::ImageContainer* aImageContainer = nullptr) override; + + bool SupportsMimeType(const nsACString& aMimeType) override; + + ConversionRequired + DecoderNeedsConversion(const TrackInfo& aConfig) const override + { + MOZ_CRASH("Should never reach this function"); + return ConversionRequired::kNeedNone; + } + +protected: + // Decode thread. + already_AddRefed + CreateVideoDecoder(const VideoInfo& aConfig, + layers::LayersBackend aLayersBackend, + layers::ImageContainer* aImageContainer, + FlushableTaskQueue* aVideoTaskQueue, + MediaDataDecoderCallback* aCallback) override + { + MOZ_CRASH("Should never reach this function"); + return nullptr; + } + + // Decode thread. + already_AddRefed + CreateAudioDecoder(const AudioInfo& aConfig, + FlushableTaskQueue* aAudioTaskQueue, + MediaDataDecoderCallback* aCallback) override + { + MOZ_CRASH("Should never reach this function"); + return nullptr; + } + +private: + already_AddRefed CreatePDM(); + + // Caches pref media.fragmented-mp4.use-blank-decoder + static bool sUseBlankDecoder; + static bool sGonkDecoderEnabled; + static bool sAndroidMCDecoderPreferred; + static bool sAndroidMCDecoderEnabled; + static bool sGMPDecoderEnabled; + static bool sEnableFuzzingWrapper; + static uint32_t sVideoOutputMinimumInterval_ms; + static bool sDontDelayInputExhausted; + + nsRefPtr mCurrentPDM; +}; + +} // namespace mozilla + +#endif /* PDMFactory_h_ */ diff --git a/dom/media/platforms/PlatformDecoderModule.cpp b/dom/media/platforms/PlatformDecoderModule.cpp index 70294c9c1a0..fdb495744f8 100644 --- a/dom/media/platforms/PlatformDecoderModule.cpp +++ b/dom/media/platforms/PlatformDecoderModule.cpp @@ -5,40 +5,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "PlatformDecoderModule.h" - -#ifdef XP_WIN -#include "WMFDecoderModule.h" -#endif -#ifdef MOZ_FFMPEG -#include "FFmpegRuntimeLinker.h" -#endif -#ifdef MOZ_APPLEMEDIA -#include "AppleDecoderModule.h" -#endif -#ifdef MOZ_GONK_MEDIACODEC -#include "GonkDecoderModule.h" -#endif -#ifdef MOZ_WIDGET_ANDROID -#include "AndroidDecoderModule.h" -#endif -#include "GMPDecoderModule.h" - -#include "mozilla/Preferences.h" -#include "mozilla/TaskQueue.h" - +#include "PDMFactory.h" #ifdef MOZ_EME #include "EMEDecoderModule.h" #include "mozilla/CDMProxy.h" #endif -#include "mozilla/SharedThreadPool.h" - -#include "MediaInfo.h" -#include "FuzzingWrapper.h" -#include "H264Converter.h" - -#include "OpusDecoder.h" -#include "VorbisDecoder.h" -#include "VPXDecoder.h" PRLogModuleInfo* GetPDMLog() { static PRLogModuleInfo* log = nullptr; @@ -50,65 +21,12 @@ PRLogModuleInfo* GetPDMLog() { namespace mozilla { -extern already_AddRefed CreateAgnosticDecoderModule(); -extern already_AddRefed CreateBlankDecoderModule(); - -bool PlatformDecoderModule::sUseBlankDecoder = false; -bool PlatformDecoderModule::sFFmpegDecoderEnabled = false; -bool PlatformDecoderModule::sGonkDecoderEnabled = false; -bool PlatformDecoderModule::sAndroidMCDecoderEnabled = false; -bool PlatformDecoderModule::sAndroidMCDecoderPreferred = false; -bool PlatformDecoderModule::sGMPDecoderEnabled = false; -bool PlatformDecoderModule::sEnableFuzzingWrapper = false; -uint32_t PlatformDecoderModule::sVideoOutputMinimumInterval_ms = 0; -bool PlatformDecoderModule::sDontDelayInputExhausted = false; - /* static */ void PlatformDecoderModule::Init() { MOZ_ASSERT(NS_IsMainThread()); - static bool alreadyInitialized = false; - if (alreadyInitialized) { - return; - } - alreadyInitialized = true; - - Preferences::AddBoolVarCache(&sUseBlankDecoder, - "media.fragmented-mp4.use-blank-decoder"); - Preferences::AddBoolVarCache(&sFFmpegDecoderEnabled, - "media.fragmented-mp4.ffmpeg.enabled", false); - -#ifdef MOZ_GONK_MEDIACODEC - Preferences::AddBoolVarCache(&sGonkDecoderEnabled, - "media.fragmented-mp4.gonk.enabled", false); -#endif -#ifdef MOZ_WIDGET_ANDROID - Preferences::AddBoolVarCache(&sAndroidMCDecoderEnabled, - "media.fragmented-mp4.android-media-codec.enabled", false); - Preferences::AddBoolVarCache(&sAndroidMCDecoderPreferred, - "media.fragmented-mp4.android-media-codec.preferred", false); -#endif - - Preferences::AddBoolVarCache(&sGMPDecoderEnabled, - "media.fragmented-mp4.gmp.enabled", false); - - Preferences::AddBoolVarCache(&sEnableFuzzingWrapper, - "media.decoder.fuzzing.enabled", false); - Preferences::AddUintVarCache(&sVideoOutputMinimumInterval_ms, - "media.decoder.fuzzing.video-output-minimum-interval-ms", 0); - Preferences::AddBoolVarCache(&sDontDelayInputExhausted, - "media.decoder.fuzzing.dont-delay-inputexhausted", false); - -#ifdef XP_WIN - WMFDecoderModule::Init(); -#endif -#ifdef MOZ_APPLEMEDIA - AppleDecoderModule::Init(); -#endif -#ifdef MOZ_FFMPEG - FFmpegRuntimeLinker::Link(); -#endif + PDMFactory::Init(); } #ifdef MOZ_EME @@ -142,135 +60,7 @@ already_AddRefed PlatformDecoderModule::Create() { // Note: This (usually) runs on the decode thread. - - nsRefPtr m(CreatePDM()); - - if (m && NS_SUCCEEDED(m->Startup())) { - return m.forget(); - } - return CreateAgnosticDecoderModule(); -} - -/* static */ -already_AddRefed -PlatformDecoderModule::CreatePDM() -{ - if (sGMPDecoderEnabled) { - nsRefPtr m(new GMPDecoderModule()); - return m.forget(); - } -#ifdef MOZ_WIDGET_ANDROID - if(sAndroidMCDecoderPreferred && sAndroidMCDecoderEnabled){ - nsRefPtr m(new AndroidDecoderModule()); - return m.forget(); - } -#endif - if (sUseBlankDecoder) { - return CreateBlankDecoderModule(); - } -#ifdef XP_WIN - nsRefPtr m(new WMFDecoderModule()); - return m.forget(); -#endif -#ifdef MOZ_FFMPEG - nsRefPtr mffmpeg = FFmpegRuntimeLinker::CreateDecoderModule(); - if (mffmpeg) { - return mffmpeg.forget(); - } -#endif -#ifdef MOZ_APPLEMEDIA - nsRefPtr m(new AppleDecoderModule()); - return m.forget(); -#endif -#ifdef MOZ_GONK_MEDIACODEC - if (sGonkDecoderEnabled) { - nsRefPtr m(new GonkDecoderModule()); - return m.forget(); - } -#endif -#ifdef MOZ_WIDGET_ANDROID - if(sAndroidMCDecoderEnabled){ - nsRefPtr m(new AndroidDecoderModule()); - return m.forget(); - } -#endif - return nullptr; -} - -already_AddRefed -PlatformDecoderModule::CreateDecoder(const TrackInfo& aConfig, - FlushableTaskQueue* aTaskQueue, - MediaDataDecoderCallback* aCallback, - layers::LayersBackend aLayersBackend, - layers::ImageContainer* aImageContainer) -{ - nsRefPtr m; - - bool hasPlatformDecoder = SupportsMimeType(aConfig.mMimeType); - - if (aConfig.GetAsAudioInfo()) { - if (!hasPlatformDecoder && VorbisDataDecoder::IsVorbis(aConfig.mMimeType)) { - m = new VorbisDataDecoder(*aConfig.GetAsAudioInfo(), - aTaskQueue, - aCallback); - } else if (!hasPlatformDecoder && OpusDataDecoder::IsOpus(aConfig.mMimeType)) { - m = new OpusDataDecoder(*aConfig.GetAsAudioInfo(), - aTaskQueue, - aCallback); - } else { - m = CreateAudioDecoder(*aConfig.GetAsAudioInfo(), - aTaskQueue, - aCallback); - } - return m.forget(); - } - - if (!aConfig.GetAsVideoInfo()) { - return nullptr; - } - - MediaDataDecoderCallback* callback = aCallback; - nsRefPtr callbackWrapper; - if (sEnableFuzzingWrapper) { - callbackWrapper = new DecoderCallbackFuzzingWrapper(aCallback); - callbackWrapper->SetVideoOutputMinimumInterval( - TimeDuration::FromMilliseconds(sVideoOutputMinimumInterval_ms)); - callbackWrapper->SetDontDelayInputExhausted(sDontDelayInputExhausted); - callback = callbackWrapper.get(); - } - - if (H264Converter::IsH264(aConfig)) { - nsRefPtr h - = new H264Converter(this, - *aConfig.GetAsVideoInfo(), - aLayersBackend, - aImageContainer, - aTaskQueue, - callback); - const nsresult rv = h->GetLastError(); - if (NS_SUCCEEDED(rv) || rv == NS_ERROR_NOT_INITIALIZED) { - // The H264Converter either successfully created the wrapped decoder, - // or there wasn't enough AVCC data to do so. Otherwise, there was some - // problem, for example WMF DLLs were missing. - m = h.forget(); - } - } else if (!hasPlatformDecoder && VPXDecoder::IsVPX(aConfig.mMimeType)) { - m = new VPXDecoder(*aConfig.GetAsVideoInfo(), - aImageContainer, - aTaskQueue, - callback); - } else { - m = CreateVideoDecoder(*aConfig.GetAsVideoInfo(), - aLayersBackend, - aImageContainer, - aTaskQueue, - callback); - } - - if (callbackWrapper && m) { - m = new DecoderFuzzingWrapper(m.forget(), callbackWrapper.forget()); - } - + nsRefPtr m = new PDMFactory; return m.forget(); } @@ -282,14 +72,4 @@ PlatformDecoderModule::SupportsMimeType(const nsACString& aMimeType) aMimeType.EqualsLiteral("video/avc"); } -/* static */ -bool -PlatformDecoderModule::AgnosticMimeType(const nsACString& aMimeType) -{ - return VPXDecoder::IsVPX(aMimeType) || - OpusDataDecoder::IsOpus(aMimeType) || - VorbisDataDecoder::IsVorbis(aMimeType); -} - - } // namespace mozilla diff --git a/dom/media/platforms/PlatformDecoderModule.h b/dom/media/platforms/PlatformDecoderModule.h index 4bebc973ac4..e8d4426354d 100644 --- a/dom/media/platforms/PlatformDecoderModule.h +++ b/dom/media/platforms/PlatformDecoderModule.h @@ -63,8 +63,6 @@ public: // PlatformDecoderModule created per MP4Reader. // This is called on the decode task queue. static already_AddRefed Create(); - // As Create() but do not initialize the created PlatformDecoderModule. - static already_AddRefed CreatePDM(); // Perform any per-instance initialization. // This is called on the decode task queue. @@ -87,7 +85,10 @@ public: FlushableTaskQueue* aTaskQueue, MediaDataDecoderCallback* aCallback, layers::LayersBackend aLayersBackend = layers::LayersBackend::LAYERS_NONE, - layers::ImageContainer* aImageContainer = nullptr); + layers::ImageContainer* aImageContainer = nullptr) + { + MOZ_CRASH(); + } // An audio decoder module must support AAC by default. // A video decoder must support H264 by default. @@ -95,10 +96,6 @@ public: // to be extended virtual bool SupportsMimeType(const nsACString& aMimeType); - // MimeType can be decoded with shipped decoders if no platform decoders exist - static bool AgnosticMimeType(const nsACString& aMimeType); - - enum ConversionRequired { kNeedNone, kNeedAVCC, @@ -115,6 +112,8 @@ protected: virtual ~PlatformDecoderModule() {} friend class H264Converter; + friend class PDMFactory; + // Creates a Video decoder. The layers backend is passed in so that // decoders can determine whether hardware accelerated decoding can be used. // Asynchronous decoding of video should be done in runnables dispatched @@ -147,17 +146,6 @@ protected: CreateAudioDecoder(const AudioInfo& aConfig, FlushableTaskQueue* aAudioTaskQueue, MediaDataDecoderCallback* aCallback) = 0; - - // Caches pref media.fragmented-mp4.use-blank-decoder - static bool sUseBlankDecoder; - static bool sFFmpegDecoderEnabled; - static bool sGonkDecoderEnabled; - static bool sAndroidMCDecoderPreferred; - static bool sAndroidMCDecoderEnabled; - static bool sGMPDecoderEnabled; - static bool sEnableFuzzingWrapper; - static uint32_t sVideoOutputMinimumInterval_ms; - static bool sDontDelayInputExhausted; }; // A callback used by MediaDataDecoder to return output/errors to the diff --git a/dom/media/platforms/ffmpeg/FFmpegDecoderModule.h b/dom/media/platforms/ffmpeg/FFmpegDecoderModule.h index 24322d2da54..ef9973d1ce2 100644 --- a/dom/media/platforms/ffmpeg/FFmpegDecoderModule.h +++ b/dom/media/platforms/ffmpeg/FFmpegDecoderModule.h @@ -10,6 +10,7 @@ #include "PlatformDecoderModule.h" #include "FFmpegAudioDecoder.h" #include "FFmpegH264Decoder.h" +#include "FFmpegRuntimeLinker.h" namespace mozilla { @@ -23,7 +24,7 @@ public: { uint32_t major, minor; GetVersion(major, minor); - if (major < 54 && !sFFmpegDecoderEnabled) { + if (major < 54 && !FFmpegRuntimeLinker::sFFmpegDecoderEnabled) { return nullptr; } nsRefPtr pdm = new FFmpegDecoderModule(); diff --git a/dom/media/platforms/ffmpeg/FFmpegRuntimeLinker.cpp b/dom/media/platforms/ffmpeg/FFmpegRuntimeLinker.cpp index ca3d9fea75e..a60851de21c 100644 --- a/dom/media/platforms/ffmpeg/FFmpegRuntimeLinker.cpp +++ b/dom/media/platforms/ffmpeg/FFmpegRuntimeLinker.cpp @@ -9,12 +9,15 @@ #include "FFmpegRuntimeLinker.h" #include "mozilla/ArrayUtils.h" #include "FFmpegLog.h" +#include "mozilla/Preferences.h" #define NUM_ELEMENTS(X) (sizeof(X) / sizeof((X)[0])) namespace mozilla { +bool FFmpegRuntimeLinker::sFFmpegDecoderEnabled = false; + FFmpegRuntimeLinker::LinkStatus FFmpegRuntimeLinker::sLinkStatus = LinkStatus_INIT; @@ -59,6 +62,9 @@ FFmpegRuntimeLinker::Link() return sLinkStatus == LinkStatus_SUCCEEDED; } + Preferences::AddBoolVarCache(&sFFmpegDecoderEnabled, + "media.fragmented-mp4.ffmpeg.enabled", false); + MOZ_ASSERT(NS_IsMainThread()); for (size_t i = 0; i < ArrayLength(sLibs); i++) { diff --git a/dom/media/platforms/ffmpeg/FFmpegRuntimeLinker.h b/dom/media/platforms/ffmpeg/FFmpegRuntimeLinker.h index 68e42f15ce6..5e098dfa1f1 100644 --- a/dom/media/platforms/ffmpeg/FFmpegRuntimeLinker.h +++ b/dom/media/platforms/ffmpeg/FFmpegRuntimeLinker.h @@ -22,6 +22,8 @@ public: static void Unlink(); static already_AddRefed CreateDecoderModule(); + static bool sFFmpegDecoderEnabled; + private: static void* sLinkedLib; static const AvCodecLib* sLib; diff --git a/dom/media/platforms/moz.build b/dom/media/platforms/moz.build index 66e17091aa0..ae84d1f0144 100644 --- a/dom/media/platforms/moz.build +++ b/dom/media/platforms/moz.build @@ -18,6 +18,7 @@ UNIFIED_SOURCES += [ 'agnostic/OpusDecoder.cpp', 'agnostic/VorbisDecoder.cpp', 'agnostic/VPXDecoder.cpp', + 'PDMFactory.cpp', 'PlatformDecoderModule.cpp', 'wrappers/FuzzingWrapper.cpp', 'wrappers/H264Converter.cpp'