зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1271491: P6. Remove the need to call PDMFactory::Init(). r=cpearce
PDMFactory will automatically load and initialize the required frameworks upon first use. Also fix constness of some methods. MozReview-Commit-ID: HFbvTMRFAey --HG-- extra : rebase_source : ce3e7ff6cefc35b32674c9a81c3488fe21b48626
This commit is contained in:
Родитель
3a843c40d0
Коммит
cc8c8725df
|
@ -32,7 +32,6 @@ ADTSDecoder::CreateStateMachine()
|
|||
/* static */ bool
|
||||
ADTSDecoder::IsEnabled()
|
||||
{
|
||||
PDMFactory::Init();
|
||||
RefPtr<PDMFactory> platform = new PDMFactory();
|
||||
return platform->SupportsMimeType(NS_LITERAL_CSTRING("audio/mp4a-latm"),
|
||||
/* DecoderDoctorDiagnostics* */ nullptr);
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "Benchmark.h"
|
||||
#include "BufferMediaResource.h"
|
||||
#include "MediaData.h"
|
||||
#include "MediaPrefs.h"
|
||||
#include "PDMFactory.h"
|
||||
#include "WebMDemuxer.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
|
@ -45,8 +46,6 @@ VP9Benchmark::IsVP9DecodeFast()
|
|||
RefPtr<WebMDemuxer> demuxer =
|
||||
new WebMDemuxer(new BufferMediaResource(sWebMSample, sizeof(sWebMSample), nullptr,
|
||||
NS_LITERAL_CSTRING("video/webm")));
|
||||
PDMFactory::Init();
|
||||
|
||||
RefPtr<Benchmark> estimiser =
|
||||
new Benchmark(demuxer,
|
||||
{
|
||||
|
@ -135,7 +134,7 @@ Benchmark::Init()
|
|||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
PDMFactory::Init();
|
||||
MediaPrefs::GetSingleton();
|
||||
}
|
||||
|
||||
BenchmarkPlayback::BenchmarkPlayback(Benchmark* aMainThreadState,
|
||||
|
|
|
@ -31,7 +31,6 @@ MP3Decoder::CreateStateMachine() {
|
|||
/* static */
|
||||
bool
|
||||
MP3Decoder::IsEnabled() {
|
||||
PDMFactory::Init();
|
||||
RefPtr<PDMFactory> platform = new PDMFactory();
|
||||
return platform->SupportsMimeType(NS_LITERAL_CSTRING("audio/mpeg"),
|
||||
/* DecoderDoctorDiagnostics* */ nullptr);
|
||||
|
|
|
@ -172,7 +172,6 @@ nsresult
|
|||
MediaFormatReader::Init()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread(), "Must be on main thread.");
|
||||
PDMFactory::Init();
|
||||
|
||||
InitLayersBackendType();
|
||||
|
||||
|
|
|
@ -151,7 +151,6 @@ MP4Decoder::CanHandleMediaType(const nsACString& aMIMETypeExcludingCodecs,
|
|||
}
|
||||
|
||||
// Verify that we have a PDM that supports the whitelisted types.
|
||||
PDMFactory::Init();
|
||||
RefPtr<PDMFactory> platform = new PDMFactory();
|
||||
for (const nsCString& codecMime : codecMimes) {
|
||||
if (!platform->SupportsMimeType(codecMime, aDiagnostics)) {
|
||||
|
@ -230,8 +229,6 @@ CreateTestH264Decoder(layers::LayersBackend aBackend,
|
|||
aConfig.mExtraData->AppendElements(sTestH264ExtraData,
|
||||
MOZ_ARRAY_LENGTH(sTestH264ExtraData));
|
||||
|
||||
PDMFactory::Init();
|
||||
|
||||
RefPtr<PDMFactory> platform = new PDMFactory();
|
||||
RefPtr<MediaDataDecoder> decoder(
|
||||
platform->CreateDecoder(aConfig, aTaskQueue, nullptr,
|
||||
|
|
|
@ -26,9 +26,10 @@
|
|||
#endif
|
||||
#include "GMPDecoderModule.h"
|
||||
|
||||
#include "mozilla/TaskQueue.h"
|
||||
|
||||
#include "mozilla/ClearOnShutdown.h"
|
||||
#include "mozilla/SharedThreadPool.h"
|
||||
#include "mozilla/StaticPtr.h"
|
||||
#include "mozilla/TaskQueue.h"
|
||||
|
||||
#include "MediaInfo.h"
|
||||
#include "MediaPrefs.h"
|
||||
|
@ -44,42 +45,38 @@
|
|||
|
||||
#include "DecoderDoctorDiagnostics.h"
|
||||
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
extern already_AddRefed<PlatformDecoderModule> CreateAgnosticDecoderModule();
|
||||
extern already_AddRefed<PlatformDecoderModule> CreateBlankDecoderModule();
|
||||
|
||||
/* static */
|
||||
void
|
||||
PDMFactory::Init()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
static bool alreadyInitialized = false;
|
||||
if (alreadyInitialized) {
|
||||
return;
|
||||
}
|
||||
alreadyInitialized = true;
|
||||
|
||||
// Ensure MediaPrefs are initialized.
|
||||
MediaPrefs::GetSingleton();
|
||||
|
||||
class PDMFactoryImpl final {
|
||||
public:
|
||||
PDMFactoryImpl()
|
||||
{
|
||||
#ifdef XP_WIN
|
||||
WMFDecoderModule::Init();
|
||||
WMFDecoderModule::Init();
|
||||
#endif
|
||||
#ifdef MOZ_APPLEMEDIA
|
||||
AppleDecoderModule::Init();
|
||||
AppleDecoderModule::Init();
|
||||
#endif
|
||||
#ifdef MOZ_FFVPX
|
||||
FFVPXRuntimeLinker::Init();
|
||||
FFVPXRuntimeLinker::Init();
|
||||
#endif
|
||||
#ifdef MOZ_FFMPEG
|
||||
FFmpegRuntimeLinker::Init();
|
||||
FFmpegRuntimeLinker::Init();
|
||||
#endif
|
||||
GMPDecoderModule::Init();
|
||||
}
|
||||
GMPDecoderModule::Init();
|
||||
}
|
||||
};
|
||||
|
||||
StaticAutoPtr<PDMFactoryImpl> PDMFactory::sInstance;
|
||||
StaticMutex PDMFactory::sMonitor;
|
||||
|
||||
PDMFactory::PDMFactory()
|
||||
{
|
||||
EnsureInit();
|
||||
CreatePDMs();
|
||||
}
|
||||
|
||||
|
@ -87,13 +84,29 @@ PDMFactory::~PDMFactory()
|
|||
{
|
||||
}
|
||||
|
||||
void
|
||||
PDMFactory::EnsureInit() const
|
||||
{
|
||||
StaticMutexAutoLock mon(sMonitor);
|
||||
if (!sInstance) {
|
||||
sInstance = new PDMFactoryImpl();
|
||||
if (NS_IsMainThread()) {
|
||||
ClearOnShutdown(&sInstance);
|
||||
} else {
|
||||
nsCOMPtr<nsIRunnable> runnable =
|
||||
NS_NewRunnableFunction([]() { ClearOnShutdown(&sInstance); });
|
||||
NS_DispatchToMainThread(runnable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
already_AddRefed<MediaDataDecoder>
|
||||
PDMFactory::CreateDecoder(const TrackInfo& aConfig,
|
||||
FlushableTaskQueue* aTaskQueue,
|
||||
MediaDataDecoderCallback* aCallback,
|
||||
DecoderDoctorDiagnostics* aDiagnostics,
|
||||
layers::LayersBackend aLayersBackend,
|
||||
layers::ImageContainer* aImageContainer)
|
||||
layers::ImageContainer* aImageContainer) const
|
||||
{
|
||||
bool isEncrypted = mEMEPDM && aConfig.mCrypto.mValid;
|
||||
|
||||
|
@ -148,7 +161,7 @@ PDMFactory::CreateDecoderWithPDM(PlatformDecoderModule* aPDM,
|
|||
MediaDataDecoderCallback* aCallback,
|
||||
DecoderDoctorDiagnostics* aDiagnostics,
|
||||
layers::LayersBackend aLayersBackend,
|
||||
layers::ImageContainer* aImageContainer)
|
||||
layers::ImageContainer* aImageContainer) const
|
||||
{
|
||||
MOZ_ASSERT(aPDM);
|
||||
RefPtr<MediaDataDecoder> m;
|
||||
|
|
|
@ -8,12 +8,15 @@
|
|||
#define PDMFactory_h_
|
||||
|
||||
#include "PlatformDecoderModule.h"
|
||||
#include "mozilla/StaticMutex.h"
|
||||
|
||||
class CDMProxy;
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
class DecoderDoctorDiagnostics;
|
||||
class PDMFactoryImpl;
|
||||
template<class T> class StaticAutoPtr;
|
||||
|
||||
class PDMFactory final {
|
||||
public:
|
||||
|
@ -21,10 +24,6 @@ public:
|
|||
|
||||
PDMFactory();
|
||||
|
||||
// Call on the main thread to initialize the static state
|
||||
// needed by Create().
|
||||
static void Init();
|
||||
|
||||
// Factory method that creates the appropriate PlatformDecoderModule for
|
||||
// the platform we're running on. Caller is responsible for deleting this
|
||||
// instance. It's expected that there will be multiple
|
||||
|
@ -36,7 +35,7 @@ public:
|
|||
MediaDataDecoderCallback* aCallback,
|
||||
DecoderDoctorDiagnostics* aDiagnostics,
|
||||
layers::LayersBackend aLayersBackend = layers::LayersBackend::LAYERS_NONE,
|
||||
layers::ImageContainer* aImageContainer = nullptr);
|
||||
layers::ImageContainer* aImageContainer = nullptr) const;
|
||||
|
||||
bool SupportsMimeType(const nsACString& aMimeType,
|
||||
DecoderDoctorDiagnostics* aDiagnostics) const;
|
||||
|
@ -67,7 +66,7 @@ private:
|
|||
MediaDataDecoderCallback* aCallback,
|
||||
DecoderDoctorDiagnostics* aDiagnostics,
|
||||
layers::LayersBackend aLayersBackend,
|
||||
layers::ImageContainer* aImageContainer);
|
||||
layers::ImageContainer* aImageContainer) const;
|
||||
|
||||
nsTArray<RefPtr<PlatformDecoderModule>> mCurrentPDMs;
|
||||
RefPtr<PlatformDecoderModule> mEMEPDM;
|
||||
|
@ -75,6 +74,11 @@ private:
|
|||
bool mWMFFailedToLoad = false;
|
||||
bool mFFmpegFailedToLoad = false;
|
||||
bool mGMPPDMFailedToStartup = false;
|
||||
|
||||
void EnsureInit() const;
|
||||
template<class T> friend class StaticAutoPtr;
|
||||
static StaticAutoPtr<PDMFactoryImpl> sInstance;
|
||||
static StaticMutex sMonitor;
|
||||
};
|
||||
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -40,7 +40,6 @@ WaveDecoder::IsEnabled()
|
|||
if (!Preferences::GetBool("media.wave.decoder.enabled", false)) {
|
||||
return false;
|
||||
}
|
||||
PDMFactory::Init();
|
||||
RefPtr<PDMFactory> platform = new PDMFactory();
|
||||
return platform->SupportsMimeType(NS_LITERAL_CSTRING("audio/x-wav"),
|
||||
/* DecoderDoctorDiagnostics* */ nullptr);
|
||||
|
|
Загрузка…
Ссылка в новой задаче