From 0f9c0d79c639edf5d561c11860025d3cfe868f18 Mon Sep 17 00:00:00 2001 From: Jean-Yves Avenard Date: Thu, 9 Jul 2020 02:46:55 +0000 Subject: [PATCH] Bug 1649974 - P2. Use a TaskQueue with media threadpool for RemoteDecoderManagerParent. r=mattwoodrow Sync dispatch are being used; due to how the background taskqueue is setup this could cause a hang if if also called from a background taskqueue. Differential Revision: https://phabricator.services.mozilla.com/D82500 --- dom/media/ipc/RemoteDecoderManagerParent.cpp | 41 ++++++++------------ 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/dom/media/ipc/RemoteDecoderManagerParent.cpp b/dom/media/ipc/RemoteDecoderManagerParent.cpp index ff5a9e990b10..638caa6caca2 100644 --- a/dom/media/ipc/RemoteDecoderManagerParent.cpp +++ b/dom/media/ipc/RemoteDecoderManagerParent.cpp @@ -9,14 +9,13 @@ # include #endif +#include "ImageContainer.h" #include "RemoteAudioDecoder.h" #include "RemoteVideoDecoder.h" #include "VideoUtils.h" // for MediaThreadType - -#include "ImageContainer.h" -#include "mozilla/layers/VideoBridgeChild.h" -#include "mozilla/layers/ImageDataSerializer.h" #include "mozilla/SyncRunnable.h" +#include "mozilla/layers/ImageDataSerializer.h" +#include "mozilla/layers/VideoBridgeChild.h" namespace mozilla { @@ -29,7 +28,7 @@ using namespace ipc; using namespace layers; using namespace gfx; -StaticRefPtr sRemoteDecoderManagerParentThread; +StaticRefPtr sRemoteDecoderManagerParentThread; SurfaceDescriptorGPUVideo RemoteDecoderManagerParent::StoreImage( Image* aImage, TextureClient* aTexture) { @@ -72,19 +71,13 @@ bool RemoteDecoderManagerParent::StartupThreads() { return false; } - nsCOMPtr managerThread; - nsresult rv = NS_CreateBackgroundTaskQueue("RemVidParent", - getter_AddRefs(managerThread)); - if (NS_FAILED(rv)) { - return false; - } - sRemoteDecoderManagerParentThread = managerThread; + sRemoteDecoderManagerParentThread = new TaskQueue( + GetMediaThreadPool(MediaThreadType::PLAYBACK), "RemVidParent"); if (XRE_IsGPUProcess()) { - sRemoteDecoderManagerParentThread->Dispatch( - NS_NewRunnableFunction( + MOZ_ALWAYS_SUCCEEDS( + sRemoteDecoderManagerParentThread->Dispatch(NS_NewRunnableFunction( "RemoteDecoderManagerParent::StartupThreads", - []() { layers::VideoBridgeChild::StartupForGPUProcess(); }), - NS_DISPATCH_NORMAL); + []() { layers::VideoBridgeChild::StartupForGPUProcess(); }))); } auto* obs = new RemoteDecoderManagerThreadShutdownObserver(); @@ -93,16 +86,14 @@ bool RemoteDecoderManagerParent::StartupThreads() { } void RemoteDecoderManagerParent::ShutdownThreads() { + sRemoteDecoderManagerParentThread->BeginShutdown(); + sRemoteDecoderManagerParentThread->AwaitShutdownAndIdle(); sRemoteDecoderManagerParentThread = nullptr; } +/* static */ void RemoteDecoderManagerParent::ShutdownVideoBridge() { if (sRemoteDecoderManagerParentThread) { - if (sRemoteDecoderManagerParentThread->IsOnCurrentThread()) { - VideoBridgeChild::Shutdown(); - return; - } - RefPtr task = NS_NewRunnableFunction( "RemoteDecoderManagerParent::ShutdownVideoBridge", []() { VideoBridgeChild::Shutdown(); }); @@ -131,8 +122,8 @@ bool RemoteDecoderManagerParent::CreateForContent( NewRunnableMethod&&>( "dom::RemoteDecoderManagerParent::Open", parent, &RemoteDecoderManagerParent::Open, std::move(aEndpoint)); - sRemoteDecoderManagerParentThread->Dispatch(task.forget(), - NS_DISPATCH_NORMAL); + MOZ_ALWAYS_SUCCEEDS( + sRemoteDecoderManagerParentThread->Dispatch(task.forget())); return true; } @@ -150,8 +141,8 @@ bool RemoteDecoderManagerParent::CreateVideoBridgeToOtherProcess( RefPtr task = NewRunnableFunction("gfx::VideoBridgeChild::Open", &VideoBridgeChild::Open, std::move(aEndpoint)); - sRemoteDecoderManagerParentThread->Dispatch(task.forget(), - NS_DISPATCH_NORMAL); + MOZ_ALWAYS_SUCCEEDS( + sRemoteDecoderManagerParentThread->Dispatch(task.forget())); return true; }