Skip to content

Commit

Permalink
Backed out 5 changesets (bug 1650996, bug 1649974) for perma failures…
Browse files Browse the repository at this point in the history
… on Android 7.0. CLOSED TREE

Backed out changeset 8f8174ba409d (bug 1650996)
Backed out changeset 374598f9c37a (bug 1650996)
Backed out changeset 236757acc073 (bug 1650996)
Backed out changeset 89d5cabfa2df (bug 1649974)
Backed out changeset 6e475ddbd18c (bug 1649974)
  • Loading branch information
Razvan Maries committed Jul 9, 2020
1 parent c18a778 commit 05fa077
Show file tree
Hide file tree
Showing 12 changed files with 150 additions and 120 deletions.
1 change: 1 addition & 0 deletions build/clang-plugin/ThreadAllows.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ ProxyResolution
RemoteLzyStream
RWLockTester
RacingServMan
RemVidChild
Sandbox Testing
SaveScripts
Socket Thread
Expand Down
33 changes: 17 additions & 16 deletions dom/media/ipc/GpuDecoderModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "GpuDecoderModule.h"

#include "base/thread.h"
#include "mozilla/layers/SynchronousTask.h"
#include "mozilla/StaticPrefs_media.h"
#include "RemoteVideoDecoder.h"
#include "RemoteDecoderManagerChild.h"

#include "RemoteMediaDataDecoder.h"
#include "RemoteVideoDecoder.h"
#include "mozilla/StaticPrefs_media.h"
#include "mozilla/SyncRunnable.h"

namespace mozilla {

Expand Down Expand Up @@ -48,20 +50,19 @@ already_AddRefed<MediaDataDecoder> GpuDecoderModule::CreateVideoDecoder(
}

RefPtr<GpuRemoteVideoDecoderChild> child = new GpuRemoteVideoDecoderChild();
SynchronousTask task("InitIPDL");
MediaResult result(NS_OK);
RefPtr<Runnable> task = NS_NewRunnableFunction(
"dom::GpuDecoderModule::CreateVideoDecoder", [&]() {
result = child->InitIPDL(
aParams.VideoConfig(), aParams.mRate.mValue, aParams.mOptions,
aParams.mKnowsCompositor->GetTextureFactoryIdentifier());
if (NS_FAILED(result)) {
// Release GpuRemoteVideoDecoderChild here, while we're on
// manager thread. Don't just let the RefPtr go out of scope.
child = nullptr;
}
});
SyncRunnable::DispatchToThread(RemoteDecoderManagerChild::GetManagerThread(),
task);
RemoteDecoderManagerChild::GetManagerThread()->Dispatch(
NS_NewRunnableFunction(
"dom::GpuDecoderModule::CreateVideoDecoder",
[&, child]() {
AutoCompleteTask complete(&task);
result = child->InitIPDL(
aParams.VideoConfig(), aParams.mRate.mValue, aParams.mOptions,
aParams.mKnowsCompositor->GetTextureFactoryIdentifier());
}),
NS_DISPATCH_NORMAL);
task.Wait();

if (NS_FAILED(result)) {
if (aParams.mError) {
Expand Down
2 changes: 1 addition & 1 deletion dom/media/ipc/RemoteDecoderChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ MediaDataDecoder::ConversionRequired RemoteDecoderChild::NeedsConversion()
}

void RemoteDecoderChild::AssertOnManagerThread() const {
MOZ_ASSERT(mThread->IsOnCurrentThread());
MOZ_ASSERT(NS_GetCurrentThread() == mThread);
}

RemoteDecoderManagerChild* RemoteDecoderChild::GetManager() {
Expand Down
2 changes: 1 addition & 1 deletion dom/media/ipc/RemoteDecoderChild.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class RemoteDecoderChild : public PRemoteDecoderChild,
MediaDataDecoder::DecodedData mDecodedData;

private:
const nsCOMPtr<nsISerialEventTarget> mThread;
RefPtr<nsIThread> mThread;

MozPromiseHolder<MediaDataDecoder::InitPromise> mInitPromise;
MozPromiseRequestHolder<PRemoteDecoderChild::InitPromise> mInitPromiseRequest;
Expand Down
112 changes: 64 additions & 48 deletions dom/media/ipc/RemoteDecoderManagerChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,23 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "RemoteDecoderManagerChild.h"

#include "base/task.h"

#include "RemoteDecoderChild.h"
#include "VideoUtils.h"
#include "mozilla/dom/ContentChild.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/gfx/DataSurfaceHelpers.h"
#include "mozilla/ipc/ProtocolUtils.h"
#include "mozilla/layers/ISurfaceAllocator.h"
#include "mozilla/layers/SynchronousTask.h"
#include "mozilla/gfx/DataSurfaceHelpers.h"
#include "mozilla/layers/ISurfaceAllocator.h"

namespace mozilla {

using namespace layers;
using namespace gfx;

// Only modified on the main-thread
StaticRefPtr<TaskQueue> sRemoteDecoderManagerChildThread;
StaticRefPtr<nsIThread> sRemoteDecoderManagerChildThread;

// Only accessed from sRemoteDecoderManagerChildThread
static StaticRefPtr<RemoteDecoderManagerChild>
Expand All @@ -35,12 +36,10 @@ void RemoteDecoderManagerChild::InitializeThread() {
MOZ_ASSERT(NS_IsMainThread());

if (!sRemoteDecoderManagerChildThread) {
// We can't use a MediaThreadType::PLAYBACK as the GpuDecoderModule and
// RemoteDecoderModule runs on it and dispatch synchronous tasks to the
// manager thread, should more than 4 concurrent videos being instantiated
// at the same time, we could end up in a deadlock.
sRemoteDecoderManagerChildThread = new TaskQueue(
GetMediaThreadPool(MediaThreadType::PLATFORM_DECODER), "RemVidChild");
RefPtr<nsIThread> childThread;
nsresult rv = NS_NewNamedThread("RemVidChild", getter_AddRefs(childThread));
NS_ENSURE_SUCCESS_VOID(rv);
sRemoteDecoderManagerChildThread = childThread;

sRecreateTasks = MakeUnique<nsTArray<RefPtr<Runnable>>>();
}
Expand All @@ -50,42 +49,45 @@ void RemoteDecoderManagerChild::InitializeThread() {
void RemoteDecoderManagerChild::InitForRDDProcess(
Endpoint<PRemoteDecoderManagerChild>&& aVideoManager) {
InitializeThread();
MOZ_ALWAYS_SUCCEEDS(sRemoteDecoderManagerChildThread->Dispatch(
sRemoteDecoderManagerChildThread->Dispatch(
NewRunnableFunction("InitForContentRunnable", &OpenForRDDProcess,
std::move(aVideoManager))));
std::move(aVideoManager)),
NS_DISPATCH_NORMAL);
}

/* static */
void RemoteDecoderManagerChild::InitForGPUProcess(
Endpoint<PRemoteDecoderManagerChild>&& aVideoManager) {
InitializeThread();
MOZ_ALWAYS_SUCCEEDS(sRemoteDecoderManagerChildThread->Dispatch(
sRemoteDecoderManagerChildThread->Dispatch(
NewRunnableFunction("InitForContentRunnable", &OpenForGPUProcess,
std::move(aVideoManager))));
std::move(aVideoManager)),
NS_DISPATCH_NORMAL);
}

/* static */
void RemoteDecoderManagerChild::Shutdown() {
MOZ_ASSERT(NS_IsMainThread());

if (sRemoteDecoderManagerChildThread) {
MOZ_ALWAYS_SUCCEEDS(
sRemoteDecoderManagerChildThread->Dispatch(NS_NewRunnableFunction(
"dom::RemoteDecoderManagerChild::Shutdown", []() {
sRemoteDecoderManagerChildThread->Dispatch(
NS_NewRunnableFunction(
"dom::RemoteDecoderManagerChild::Shutdown",
[]() {
if (sRemoteDecoderManagerChildForRDDProcess &&
sRemoteDecoderManagerChildForRDDProcess->CanSend()) {
sRemoteDecoderManagerChildForRDDProcess->Close();
sRemoteDecoderManagerChildForRDDProcess = nullptr;
}
sRemoteDecoderManagerChildForRDDProcess = nullptr;
if (sRemoteDecoderManagerChildForGPUProcess &&
sRemoteDecoderManagerChildForGPUProcess->CanSend()) {
sRemoteDecoderManagerChildForGPUProcess->Close();
sRemoteDecoderManagerChildForGPUProcess = nullptr;
}
sRemoteDecoderManagerChildForGPUProcess = nullptr;
})));
}),
NS_DISPATCH_NORMAL);

sRemoteDecoderManagerChildThread->BeginShutdown();
sRemoteDecoderManagerChildThread->AwaitShutdownAndIdle();
sRemoteDecoderManagerChildThread->Shutdown();
sRemoteDecoderManagerChildThread = nullptr;

sRecreateTasks = nullptr;
Expand All @@ -94,7 +96,7 @@ void RemoteDecoderManagerChild::Shutdown() {

void RemoteDecoderManagerChild::RunWhenGPUProcessRecreated(
already_AddRefed<Runnable> aTask) {
MOZ_ASSERT(GetManagerThread() && GetManagerThread()->IsOnCurrentThread());
MOZ_ASSERT(NS_GetCurrentThread() == GetManagerThread());

// If we've already been recreated, then run the task immediately.
if (GetGPUProcessSingleton() && GetGPUProcessSingleton() != this &&
Expand All @@ -108,18 +110,18 @@ void RemoteDecoderManagerChild::RunWhenGPUProcessRecreated(

/* static */
RemoteDecoderManagerChild* RemoteDecoderManagerChild::GetRDDProcessSingleton() {
MOZ_ASSERT(GetManagerThread() && GetManagerThread()->IsOnCurrentThread());
MOZ_ASSERT(NS_GetCurrentThread() == GetManagerThread());
return sRemoteDecoderManagerChildForRDDProcess;
}

/* static */
RemoteDecoderManagerChild* RemoteDecoderManagerChild::GetGPUProcessSingleton() {
MOZ_ASSERT(GetManagerThread() && GetManagerThread()->IsOnCurrentThread());
MOZ_ASSERT(NS_GetCurrentThread() == GetManagerThread());
return sRemoteDecoderManagerChildForGPUProcess;
}

/* static */
nsISerialEventTarget* RemoteDecoderManagerChild::GetManagerThread() {
nsIThread* RemoteDecoderManagerChild::GetManagerThread() {
return sRemoteDecoderManagerChildThread;
}

Expand Down Expand Up @@ -149,15 +151,15 @@ RemoteDecoderManagerChild::RemoteDecoderManagerChild(

void RemoteDecoderManagerChild::OpenForRDDProcess(
Endpoint<PRemoteDecoderManagerChild>&& aEndpoint) {
MOZ_ASSERT(GetManagerThread() && GetManagerThread()->IsOnCurrentThread());
MOZ_ASSERT(NS_GetCurrentThread() == GetManagerThread());
// Only create RemoteDecoderManagerChild, bind new endpoint and init
// ipdl if:
// 1) haven't init'd sRemoteDecoderManagerChild
// or
// 2) if ActorDestroy was called meaning the other end of the ipc channel was
// torn down
// 2) if ActorDestroy was called (mCanSend is false) meaning the other
// end of the ipc channel was torn down
if (sRemoteDecoderManagerChildForRDDProcess &&
sRemoteDecoderManagerChildForRDDProcess->CanSend()) {
sRemoteDecoderManagerChildForRDDProcess->mCanSend) {
return;
}
sRemoteDecoderManagerChildForRDDProcess = nullptr;
Expand Down Expand Up @@ -191,23 +193,34 @@ void RemoteDecoderManagerChild::OpenForGPUProcess(
}

void RemoteDecoderManagerChild::InitIPDL() {
mCanSend = true;
mIPDLSelfRef = this;
}

void RemoteDecoderManagerChild::ActorDestroy(ActorDestroyReason aWhy) {
mCanSend = false;
}

void RemoteDecoderManagerChild::ActorDealloc() { mIPDLSelfRef = nullptr; }

bool RemoteDecoderManagerChild::CanSend() {
MOZ_ASSERT(NS_GetCurrentThread() == GetManagerThread());
return mCanSend;
}

bool RemoteDecoderManagerChild::DeallocShmem(mozilla::ipc::Shmem& aShmem) {
if (!sRemoteDecoderManagerChildThread->IsOnCurrentThread()) {
if (NS_GetCurrentThread() != sRemoteDecoderManagerChildThread) {
RefPtr<RemoteDecoderManagerChild> self = this;
mozilla::ipc::Shmem shmem = aShmem;
MOZ_ALWAYS_SUCCEEDS(
sRemoteDecoderManagerChildThread->Dispatch(NS_NewRunnableFunction(
"RemoteDecoderManagerChild::DeallocShmem", [self, shmem]() {
if (self->CanSend()) {
mozilla::ipc::Shmem shmemCopy = shmem;
self->DeallocShmem(shmemCopy);
}
})));
sRemoteDecoderManagerChildThread->Dispatch(
NS_NewRunnableFunction("RemoteDecoderManagerChild::DeallocShmem",
[self, shmem]() {
if (self->CanSend()) {
mozilla::ipc::Shmem shmemCopy = shmem;
self->DeallocShmem(shmemCopy);
}
}),
NS_DISPATCH_NORMAL);
return true;
}
return PRemoteDecoderManagerChild::DeallocShmem(aShmem);
Expand Down Expand Up @@ -239,12 +252,14 @@ already_AddRefed<SourceSurface> RemoteDecoderManagerChild::Readback(
RefPtr<RemoteDecoderManagerChild> ref = this;
SurfaceDescriptor sd;
if (NS_FAILED(sRemoteDecoderManagerChildThread->Dispatch(
NS_NewRunnableFunction("RemoteDecoderManagerChild::Readback", [&]() {
AutoCompleteTask complete(&task);
if (ref->CanSend()) {
ref->SendReadback(aSD, &sd);
}
})))) {
NS_NewRunnableFunction("RemoteDecoderManagerChild::Readback",
[&]() {
AutoCompleteTask complete(&task);
if (ref->CanSend()) {
ref->SendReadback(aSD, &sd);
}
}),
NS_DISPATCH_NORMAL))) {
return nullptr;
}

Expand Down Expand Up @@ -273,14 +288,15 @@ void RemoteDecoderManagerChild::DeallocateSurfaceDescriptor(
const SurfaceDescriptorGPUVideo& aSD) {
RefPtr<RemoteDecoderManagerChild> ref = this;
SurfaceDescriptorGPUVideo sd = std::move(aSD);
MOZ_ALWAYS_SUCCEEDS(
sRemoteDecoderManagerChildThread->Dispatch(NS_NewRunnableFunction(
sRemoteDecoderManagerChildThread->Dispatch(
NS_NewRunnableFunction(
"RemoteDecoderManagerChild::DeallocateSurfaceDescriptor",
[ref, sd]() {
if (ref->CanSend()) {
ref->SendDeallocateSurfaceDescriptorGPUVideo(sd);
}
})));
}),
NS_DISPATCH_NORMAL);
}

void RemoteDecoderManagerChild::HandleFatalError(const char* aMsg) const {
Expand Down
13 changes: 10 additions & 3 deletions dom/media/ipc/RemoteDecoderManagerChild.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef include_dom_media_ipc_RemoteDecoderManagerChild_h
#define include_dom_media_ipc_RemoteDecoderManagerChild_h
#include "GPUVideoImage.h"
#include "mozilla/PRemoteDecoderManagerChild.h"
#include "mozilla/layers/VideoBridgeUtils.h"
#include "GPUVideoImage.h"

namespace mozilla {

Expand All @@ -25,7 +25,7 @@ class RemoteDecoderManagerChild final
static RemoteDecoderManagerChild* GetGPUProcessSingleton();

// Can be called from any thread.
static nsISerialEventTarget* GetManagerThread();
static nsIThread* GetManagerThread();

// Can be called from any thread, dispatches the request to the IPDL thread
// internally and will be ignored if the IPDL actor has been destroyed.
Expand All @@ -51,7 +51,6 @@ class RemoteDecoderManagerChild final
bool DeallocShmem(mozilla::ipc::Shmem& aShmem) override;

// Main thread only
static void InitializeThread();
static void InitForRDDProcess(
Endpoint<PRemoteDecoderManagerChild>&& aVideoManager);
static void InitForGPUProcess(
Expand All @@ -64,11 +63,13 @@ class RemoteDecoderManagerChild final
// called from the manager thread.
void RunWhenGPUProcessRecreated(already_AddRefed<Runnable> aTask);

bool CanSend();
layers::VideoBridgeSource GetSource() const { return mSource; }

protected:
void InitIPDL();

void ActorDestroy(ActorDestroyReason aWhy) override;
void ActorDealloc() override;

void HandleFatalError(const char* aMsg) const override;
Expand All @@ -81,6 +82,9 @@ class RemoteDecoderManagerChild final
bool DeallocPRemoteDecoderChild(PRemoteDecoderChild* actor);

private:
// Main thread only
static void InitializeThread();

explicit RemoteDecoderManagerChild(layers::VideoBridgeSource aSource);
~RemoteDecoderManagerChild() = default;

Expand All @@ -93,6 +97,9 @@ class RemoteDecoderManagerChild final

// The associated source of this decoder manager
layers::VideoBridgeSource mSource;

// Should only ever be accessed on the manager thread.
bool mCanSend = false;
};

} // namespace mozilla
Expand Down
Loading

0 comments on commit 05fa077

Please sign in to comment.