Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 1561179 - P6: Handle shutdown of the GPU process and reconnect PV…
Browse files Browse the repository at this point in the history
…ideoBridge. r=mattwoodrow

Add an observer to restart the PVideoBridge connection when GPU process
restarts.

Differential Revision: https://phabricator.services.mozilla.com/D50403
  • Loading branch information
djg committed Nov 4, 2019
1 parent c3cb13c commit 357ad64
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 10 deletions.
19 changes: 19 additions & 0 deletions dom/media/ipc/RDDChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "RDDChild.h"

#include "mozilla/RDDProcessManager.h"
#include "mozilla/dom/MemoryReportRequest.h"
#include "mozilla/ipc/CrashReporterHost.h"
#include "mozilla/gfx/gfxVars.h"
#include "mozilla/gfx/GPUProcessManager.h"

#if defined(XP_LINUX) && defined(MOZ_SANDBOX)
# include "mozilla/SandboxBroker.h"
Expand Down Expand Up @@ -57,6 +59,10 @@ bool RDDChild::Init(bool aStartMacSandbox) {
#endif

gfxVars::AddReceiver(this);
auto* gpm = gfx::GPUProcessManager::Get();
if (gpm) {
gpm->AddListener(this);
}

return true;
}
Expand All @@ -71,6 +77,13 @@ bool RDDChild::SendRequestMemoryReport(const uint32_t& aGeneration,
return true;
}

void RDDChild::OnCompositorUnexpectedShutdown() {
auto* rddm = RDDProcessManager::Get();
if (rddm) {
rddm->CreateVideoBridge();
}
}

void RDDChild::OnVarChanged(const GfxVarUpdate& aVar) { SendUpdateVar(aVar); }

mozilla::ipc::IPCResult RDDChild::RecvAddMemoryReport(
Expand All @@ -95,6 +108,12 @@ void RDDChild::ActorDestroy(ActorDestroyReason aWhy) {
GenerateCrashReport(OtherPid());
}

auto* gpm = gfx::GPUProcessManager::Get();
if (gpm) {
// Note: the manager could have shutdown already.
gpm->RemoveListener(this);
}

gfxVars::RemoveReceiver(this);
mHost->OnChannelClosed();
}
Expand Down
5 changes: 4 additions & 1 deletion dom/media/ipc/RDDChild.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "mozilla/ipc/CrashReporterHelper.h"
#include "mozilla/UniquePtr.h"
#include "mozilla/gfx/gfxVarReceiver.h"
#include "mozilla/gfx/GPUProcessListener.h"

namespace mozilla {

Expand All @@ -25,7 +26,8 @@ class RDDProcessHost;

class RDDChild final : public PRDDChild,
public ipc::CrashReporterHelper<GeckoProcessType_RDD>,
public gfx::gfxVarReceiver {
public gfx::gfxVarReceiver,
public gfx::GPUProcessListener {
typedef mozilla::dom::MemoryReportRequestHost MemoryReportRequestHost;

public:
Expand All @@ -34,6 +36,7 @@ class RDDChild final : public PRDDChild,

bool Init(bool aStartMacSandbox);

void OnCompositorUnexpectedShutdown() override;
void OnVarChanged(const GfxVarUpdate& aVar) override;

void ActorDestroy(ActorDestroyReason aWhy) override;
Expand Down
2 changes: 2 additions & 0 deletions dom/media/ipc/RDDProcessManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class RDDChild;
// objects that may live in another process. Currently, it provides access
// to the RDD process via ContentParent.
class RDDProcessManager final : public RDDProcessHost::Listener {
friend class RDDChild;

public:
static void Initialize();
static void Shutdown();
Expand Down
6 changes: 3 additions & 3 deletions dom/media/ipc/RemoteDecoderManagerParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,9 @@ bool RemoteDecoderManagerParent::CreateVideoBridgeToOtherProcess(
return false;
}

RefPtr<Runnable> task = NewRunnableFunction(
"gfx::VideoBridgeChild::Open", &VideoBridgeChild::Open,
std::move(aEndpoint));
RefPtr<Runnable> task =
NewRunnableFunction("gfx::VideoBridgeChild::Open",
&VideoBridgeChild::Open, std::move(aEndpoint));
sRemoteDecoderManagerParentThread->Dispatch(task.forget(),
NS_DISPATCH_NORMAL);
return true;
Expand Down
8 changes: 5 additions & 3 deletions dom/media/ipc/RemoteVideoDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ class KnowsCompositorVideo : public layers::KnowsCompositor {
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(KnowsCompositorVideo, override)

layers::TextureForwarder* GetTextureForwarder() override {
return VideoBridgeChild::GetSingleton();
auto* vbc = VideoBridgeChild::GetSingleton();
return (vbc && vbc->CanSend()) ? vbc : nullptr;
}
layers::LayersIPCActor* GetLayersIPCActor() override {
return GetTextureForwarder();
Expand Down Expand Up @@ -309,13 +310,14 @@ MediaResult RemoteVideoDecoderParent::ProcessDecodedData(
DecodedOutputIPDL& aDecodedData) {
MOZ_ASSERT(OnManagerThread());

nsTArray<RemoteVideoDataIPDL> array;

// If the video decoder bridge has shut down, stop.
if (mKnowsCompositor && !mKnowsCompositor->GetTextureForwarder()) {
aDecodedData = std::move(array);
return NS_OK;
}

nsTArray<RemoteVideoDataIPDL> array;

for (const auto& data : aData) {
MOZ_ASSERT(data->mType == MediaData::Type::VIDEO_DATA,
"Can only decode videos using RemoteDecoderParent!");
Expand Down
9 changes: 6 additions & 3 deletions gfx/layers/ipc/VideoBridgeChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "VideoBridgeChild.h"
#include "VideoBridgeParent.h"
#include "CompositorThread.h"
#include "mozilla/dom/ContentChild.h"

namespace mozilla {
namespace layers {
Expand All @@ -27,9 +28,7 @@ void VideoBridgeChild::StartupForGPUProcess() {
}

void VideoBridgeChild::Open(Endpoint<PVideoBridgeChild>&& aEndpoint) {
// TODO(djg): This is for testing and probably incorrect. What happens when
// the IPC fails and is rebound?
MOZ_ASSERT(!sVideoBridge);
MOZ_ASSERT(!sVideoBridge || !sVideoBridge->CanSend());
sVideoBridge = new VideoBridgeChild();

if (!aEndpoint.Bind(sVideoBridge)) {
Expand Down Expand Up @@ -104,5 +103,9 @@ bool VideoBridgeChild::IsSameProcess() const {
return OtherPid() == base::GetCurrentProcId();
}

void VideoBridgeChild::HandleFatalError(const char* aMsg) const {
dom::ContentChild::FatalErrorIfNotUsingGPUProcess(aMsg, OtherPid());
}

} // namespace layers
} // namespace mozilla
3 changes: 3 additions & 0 deletions gfx/layers/ipc/VideoBridgeChild.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ class VideoBridgeChild final : public PVideoBridgeChild,

static void Open(Endpoint<PVideoBridgeChild>&& aEndpoint);

protected:
void HandleFatalError(const char* aMsg) const override;

private:
VideoBridgeChild();
virtual ~VideoBridgeChild();
Expand Down

0 comments on commit 357ad64

Please sign in to comment.