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
This commit is contained in:
Jean-Yves Avenard 2020-07-09 02:46:55 +00:00
Родитель 09c6a1b3f4
Коммит 0f9c0d79c6
1 изменённых файлов: 16 добавлений и 25 удалений

Просмотреть файл

@ -9,14 +9,13 @@
# include <objbase.h>
#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<nsISerialEventTarget> sRemoteDecoderManagerParentThread;
StaticRefPtr<TaskQueue> sRemoteDecoderManagerParentThread;
SurfaceDescriptorGPUVideo RemoteDecoderManagerParent::StoreImage(
Image* aImage, TextureClient* aTexture) {
@ -72,19 +71,13 @@ bool RemoteDecoderManagerParent::StartupThreads() {
return false;
}
nsCOMPtr<nsISerialEventTarget> 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<Runnable> task = NS_NewRunnableFunction(
"RemoteDecoderManagerParent::ShutdownVideoBridge",
[]() { VideoBridgeChild::Shutdown(); });
@ -131,8 +122,8 @@ bool RemoteDecoderManagerParent::CreateForContent(
NewRunnableMethod<Endpoint<PRemoteDecoderManagerParent>&&>(
"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<Runnable> 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;
}