Files
tubestation/ipc/glue/UtilityAudioDecoderChild.cpp
Norisz Fay e8c1f3da7e Backed out 9 changesets (bug 1846848) for causing bustages on UtilityAudioDecoderParent.cpp
Backed out changeset 3ef263566f4f (bug 1846848)
Backed out changeset 8499da15a162 (bug 1846848)
Backed out changeset 47ebd92f3778 (bug 1846848)
Backed out changeset 373b7ca4d079 (bug 1846848)
Backed out changeset ca7cb687ee2c (bug 1846848)
Backed out changeset bf0bebf8c994 (bug 1846848)
Backed out changeset 26cccc9b7894 (bug 1846848)
Backed out changeset d655082ad764 (bug 1846848)
Backed out changeset 4a1db8b9112c (bug 1846848)
2023-12-06 13:08:22 +02:00

177 lines
5.7 KiB
C++

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "UtilityAudioDecoderChild.h"
#include "base/basictypes.h"
#include "mozilla/AppShutdown.h"
#include "mozilla/dom/ContentParent.h"
#ifdef MOZ_WMF_MEDIA_ENGINE
# include "mozilla/StaticPrefs_media.h"
# include "mozilla/gfx/GPUProcessManager.h"
# include "mozilla/gfx/gfxVars.h"
# include "mozilla/ipc/UtilityProcessManager.h"
# include "mozilla/layers/PVideoBridge.h"
# include "mozilla/layers/VideoBridgeUtils.h"
#endif
namespace mozilla::ipc {
NS_IMETHODIMP UtilityAudioDecoderChildShutdownObserver::Observe(
nsISupports* aSubject, const char* aTopic, const char16_t* aData) {
MOZ_ASSERT(strcmp(aTopic, "ipc:utility-shutdown") == 0);
nsCOMPtr<nsIObserverService> observerService = services::GetObserverService();
if (observerService) {
observerService->RemoveObserver(this, "ipc:utility-shutdown");
}
UtilityAudioDecoderChild::Shutdown(mSandbox);
return NS_OK;
}
NS_IMPL_ISUPPORTS(UtilityAudioDecoderChildShutdownObserver, nsIObserver);
static EnumeratedArray<SandboxingKind, SandboxingKind::COUNT,
StaticRefPtr<UtilityAudioDecoderChild>>
sAudioDecoderChilds;
UtilityAudioDecoderChild::UtilityAudioDecoderChild(SandboxingKind aKind)
: mSandbox(aKind), mAudioDecoderChildStart(TimeStamp::Now()) {
MOZ_ASSERT(NS_IsMainThread());
nsCOMPtr<nsIObserverService> observerService = services::GetObserverService();
if (observerService) {
auto* obs = new UtilityAudioDecoderChildShutdownObserver(aKind);
observerService->AddObserver(obs, "ipc:utility-shutdown", false);
}
}
void UtilityAudioDecoderChild::ActorDestroy(ActorDestroyReason aReason) {
MOZ_ASSERT(NS_IsMainThread());
#ifdef MOZ_WMF_MEDIA_ENGINE
if (mSandbox == SandboxingKind::MF_MEDIA_ENGINE_CDM) {
gfx::gfxVars::RemoveReceiver(this);
}
#endif
Shutdown(mSandbox);
}
void UtilityAudioDecoderChild::Bind(
Endpoint<PUtilityAudioDecoderChild>&& aEndpoint) {
MOZ_ASSERT(NS_IsMainThread());
if (NS_WARN_IF(!aEndpoint.Bind(this))) {
MOZ_ASSERT_UNREACHABLE("Failed to bind UtilityAudioDecoderChild!");
return;
}
#ifdef MOZ_WMF_MEDIA_ENGINE
if (mSandbox == SandboxingKind::MF_MEDIA_ENGINE_CDM) {
gfx::gfxVars::AddReceiver(this);
}
#endif
}
/* static */
void UtilityAudioDecoderChild::Shutdown(SandboxingKind aKind) {
sAudioDecoderChilds[aKind] = nullptr;
}
/* static */
RefPtr<UtilityAudioDecoderChild> UtilityAudioDecoderChild::GetSingleton(
SandboxingKind aKind) {
MOZ_ASSERT(NS_IsMainThread());
bool shutdown = AppShutdown::IsInOrBeyond(ShutdownPhase::XPCOMWillShutdown);
if (!sAudioDecoderChilds[aKind] && !shutdown) {
sAudioDecoderChilds[aKind] = new UtilityAudioDecoderChild(aKind);
}
return sAudioDecoderChilds[aKind];
}
mozilla::ipc::IPCResult
UtilityAudioDecoderChild::RecvUpdateMediaCodecsSupported(
const RemoteDecodeIn& aLocation,
const media::MediaCodecsSupported& aSupported) {
dom::ContentParent::BroadcastMediaCodecsSupportedUpdate(aLocation,
aSupported);
return IPC_OK();
}
#ifdef MOZ_WMF_MEDIA_ENGINE
mozilla::ipc::IPCResult
UtilityAudioDecoderChild::RecvCompleteCreatedVideoBridge() {
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(mSandbox == SandboxingKind::MF_MEDIA_ENGINE_CDM);
mHasCreatedVideoBridge = true;
return IPC_OK();
}
bool UtilityAudioDecoderChild::HasCreatedVideoBridge() const {
MOZ_ASSERT(NS_IsMainThread());
return mHasCreatedVideoBridge;
}
void UtilityAudioDecoderChild::OnVarChanged(const gfx::GfxVarUpdate& aVar) {
MOZ_ASSERT(mSandbox == SandboxingKind::MF_MEDIA_ENGINE_CDM);
SendUpdateVar(aVar);
}
void UtilityAudioDecoderChild::OnCompositorUnexpectedShutdown() {
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(mSandbox == SandboxingKind::MF_MEDIA_ENGINE_CDM);
mHasCreatedVideoBridge = false;
CreateVideoBridge();
}
bool UtilityAudioDecoderChild::CreateVideoBridge() {
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(mSandbox == SandboxingKind::MF_MEDIA_ENGINE_CDM);
if (HasCreatedVideoBridge()) {
return true;
}
// Build content device data first; this ensure that the GPU process is fully
// ready.
gfx::ContentDeviceData contentDeviceData;
gfxPlatform::GetPlatform()->BuildContentDeviceData(&contentDeviceData);
gfx::GPUProcessManager* gpuManager = gfx::GPUProcessManager::Get();
if (!gpuManager) {
NS_WARNING("Failed to get a gpu mananger!");
return false;
}
// The child end is the producer of video frames; the parent end is the
// consumer.
base::ProcessId childPid = UtilityProcessManager::GetSingleton()
->GetProcessParent(mSandbox)
->OtherPid();
base::ProcessId parentPid = gpuManager->GPUProcessPid();
if (parentPid == base::kInvalidProcessId) {
NS_WARNING("GPU process Id is invald!");
return false;
}
ipc::Endpoint<layers::PVideoBridgeParent> parentPipe;
ipc::Endpoint<layers::PVideoBridgeChild> childPipe;
nsresult rv = layers::PVideoBridge::CreateEndpoints(parentPid, childPid,
&parentPipe, &childPipe);
if (NS_FAILED(rv)) {
NS_WARNING("Failed to create endpoints for video bridge!");
return false;
}
nsTArray<gfx::GfxVarUpdate> updates = gfx::gfxVars::FetchNonDefaultVars();
gpuManager->InitVideoBridge(
std::move(parentPipe),
layers::VideoBridgeSource::MFMediaEngineCDMProcess);
SendInitVideoBridge(std::move(childPipe), updates, contentDeviceData);
return true;
}
#endif
} // namespace mozilla::ipc