diff --git a/dom/media/VideoUtils.cpp b/dom/media/VideoUtils.cpp index 79c83be18761..ac8b1c912a51 100644 --- a/dom/media/VideoUtils.cpp +++ b/dom/media/VideoUtils.cpp @@ -14,6 +14,8 @@ #include "mozilla/Base64.h" #include "nsIRandomGenerator.h" #include "nsIServiceManager.h" +#include "MediaTaskQueue.h" + #include namespace mozilla { @@ -269,5 +271,24 @@ GenerateRandomPathName(nsCString& aOutSalt, uint32_t aLength) return NS_OK; } +class CreateTaskQueueTask : public nsRunnable { +public: + NS_IMETHOD Run() { + MOZ_ASSERT(NS_IsMainThread()); + mTaskQueue = new MediaTaskQueue(GetMediaDecodeThreadPool()); + return NS_OK; + } + nsRefPtr mTaskQueue; +}; + +already_AddRefed +CreateMediaDecodeTaskQueue() +{ + // We must create the MediaTaskQueue/SharedThreadPool on the main thread. + nsRefPtr t(new CreateTaskQueueTask()); + nsresult rv = NS_DispatchToMainThread(t, NS_DISPATCH_SYNC); + NS_ENSURE_SUCCESS(rv, nullptr); + return t->mTaskQueue.forget(); +} } // end namespace mozilla diff --git a/dom/media/VideoUtils.h b/dom/media/VideoUtils.h index ffef9304049d..db9e837c8df6 100644 --- a/dom/media/VideoUtils.h +++ b/dom/media/VideoUtils.h @@ -263,6 +263,11 @@ ExtractH264CodecDetails(const nsAString& aCodecs, nsresult GenerateRandomPathName(nsCString& aOutSalt, uint32_t aLength); +class MediaTaskQueue; + +already_AddRefed +CreateMediaDecodeTaskQueue(); + } // end namespace mozilla #endif diff --git a/dom/media/fmp4/PlatformDecoderModule.cpp b/dom/media/fmp4/PlatformDecoderModule.cpp index b4c5ab0c0783..d2bb0a4bd0aa 100644 --- a/dom/media/fmp4/PlatformDecoderModule.cpp +++ b/dom/media/fmp4/PlatformDecoderModule.cpp @@ -75,26 +75,6 @@ PlatformDecoderModule::Init() } #ifdef MOZ_EME -class CreateTaskQueueTask : public nsRunnable { -public: - NS_IMETHOD Run() { - MOZ_ASSERT(NS_IsMainThread()); - mTaskQueue = new MediaTaskQueue(GetMediaDecodeThreadPool()); - return NS_OK; - } - nsRefPtr mTaskQueue; -}; - -static already_AddRefed -CreateTaskQueue() -{ - // We must create the MediaTaskQueue/SharedThreadPool on the main thread. - nsRefPtr t(new CreateTaskQueueTask()); - nsresult rv = NS_DispatchToMainThread(t, NS_DISPATCH_SYNC); - NS_ENSURE_SUCCESS(rv, nullptr); - return t->mTaskQueue.forget(); -} - /* static */ PlatformDecoderModule* PlatformDecoderModule::CreateCDMWrapper(CDMProxy* aProxy, @@ -123,8 +103,7 @@ PlatformDecoderModule::CreateCDMWrapper(CDMProxy* aProxy, return new EMEDecoderModule(aProxy, pdm.forget(), cdmDecodesAudio, - cdmDecodesVideo, - CreateTaskQueue()); + cdmDecodesVideo); } #endif diff --git a/dom/media/fmp4/eme/EMEDecoderModule.cpp b/dom/media/fmp4/eme/EMEDecoderModule.cpp index 0b9577bbaeea..e60752baab18 100644 --- a/dom/media/fmp4/eme/EMEDecoderModule.cpp +++ b/dom/media/fmp4/eme/EMEDecoderModule.cpp @@ -20,6 +20,7 @@ #include "mozilla/EMELog.h" #include "EMEH264Decoder.h" #include "EMEAudioDecoder.h" +#include "mozilla/unused.h" #include namespace mozilla { @@ -31,19 +32,19 @@ public: EMEDecryptor(MediaDataDecoder* aDecoder, MediaDataDecoderCallback* aCallback, - MediaTaskQueue* aTaskQueue, CDMProxy* aProxy) : mDecoder(aDecoder) , mCallback(aCallback) - , mTaskQueue(aTaskQueue) + , mTaskQueue(CreateMediaDecodeTaskQueue()) , mProxy(aProxy) { } virtual nsresult Init() MOZ_OVERRIDE { - return mTaskQueue->SyncDispatch( - NS_NewRunnableMethod(mDecoder, - &MediaDataDecoder::Init)); + nsresult rv = mTaskQueue->SyncDispatch( + NS_NewRunnableMethod(mDecoder, &MediaDataDecoder::Init)); + unused << NS_WARN_IF(NS_FAILED(rv)); + return rv; } class RedeliverEncryptedInput : public nsRunnable { @@ -123,40 +124,44 @@ public: } void Decrypted(mp4_demuxer::MP4Sample* aSample) { - mTaskQueue->Dispatch( + nsresult rv = mTaskQueue->Dispatch( NS_NewRunnableMethodWithArg( mDecoder, &MediaDataDecoder::Input, aSample)); + unused << NS_WARN_IF(NS_FAILED(rv)); } virtual nsresult Flush() MOZ_OVERRIDE { - mTaskQueue->SyncDispatch( + nsresult rv = mTaskQueue->SyncDispatch( NS_NewRunnableMethod( mDecoder, &MediaDataDecoder::Flush)); - return NS_OK; + unused << NS_WARN_IF(NS_FAILED(rv)); + return rv; } virtual nsresult Drain() MOZ_OVERRIDE { - mTaskQueue->Dispatch( + nsresult rv = mTaskQueue->Dispatch( NS_NewRunnableMethod( mDecoder, &MediaDataDecoder::Drain)); - return NS_OK; + unused << NS_WARN_IF(NS_FAILED(rv)); + return rv; } virtual nsresult Shutdown() MOZ_OVERRIDE { - mTaskQueue->SyncDispatch( + nsresult rv = mTaskQueue->SyncDispatch( NS_NewRunnableMethod( mDecoder, &MediaDataDecoder::Shutdown)); + unused << NS_WARN_IF(NS_FAILED(rv)); mDecoder = nullptr; mTaskQueue->BeginShutdown(); mTaskQueue->AwaitShutdownAndIdle(); mTaskQueue = nullptr; mProxy = nullptr; - return NS_OK; + return rv; } private: @@ -170,11 +175,9 @@ private: EMEDecoderModule::EMEDecoderModule(CDMProxy* aProxy, PlatformDecoderModule* aPDM, bool aCDMDecodesAudio, - bool aCDMDecodesVideo, - already_AddRefed aTaskQueue) + bool aCDMDecodesVideo) : mProxy(aProxy) , mPDM(aPDM) - , mTaskQueue(aTaskQueue) , mCDMDecodesAudio(aCDMDecodesAudio) , mCDMDecodesVideo(aCDMDecodesVideo) { @@ -190,8 +193,6 @@ EMEDecoderModule::Shutdown() if (mPDM) { return mPDM->Shutdown(); } - mTaskQueue->BeginShutdown(); - mTaskQueue->AwaitShutdownAndIdle(); return NS_OK; } @@ -227,7 +228,6 @@ EMEDecoderModule::CreateVideoDecoder(const VideoDecoderConfig& aConfig, nsRefPtr emeDecoder(new EMEDecryptor(decoder, aCallback, - mTaskQueue, mProxy)); return emeDecoder.forget(); } @@ -258,7 +258,6 @@ EMEDecoderModule::CreateAudioDecoder(const AudioDecoderConfig& aConfig, nsRefPtr emeDecoder(new EMEDecryptor(decoder, aCallback, - mTaskQueue, mProxy)); return emeDecoder.forget(); } diff --git a/dom/media/fmp4/eme/EMEDecoderModule.h b/dom/media/fmp4/eme/EMEDecoderModule.h index 8bd9953800a5..cafe7ba1ba44 100644 --- a/dom/media/fmp4/eme/EMEDecoderModule.h +++ b/dom/media/fmp4/eme/EMEDecoderModule.h @@ -24,8 +24,7 @@ public: EMEDecoderModule(CDMProxy* aProxy, PlatformDecoderModule* aPDM, bool aCDMDecodesAudio, - bool aCDMDecodesVideo, - already_AddRefed aDecodeTaskQueue); + bool aCDMDecodesVideo); virtual ~EMEDecoderModule();