1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=2 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "UtilityAudioDecoderParent.h"
9 #include "GeckoProfiler.h"
10 #include "nsDebugImpl.h"
12 #include "mozilla/RemoteDecoderManagerParent.h"
13 #include "PDMFactory.h"
15 #if defined(XP_WIN) && defined(MOZ_SANDBOX)
17 # include "WMFDecoderModule.h"
18 # include "WMFUtils.h"
20 # include "mozilla/sandboxTarget.h"
21 # include "mozilla/ipc/UtilityProcessImpl.h"
22 #endif // defined(XP_WIN) && defined(MOZ_SANDBOX)
24 #ifdef MOZ_WIDGET_ANDROID
25 # include "mozilla/StaticPrefs_media.h"
26 # include "AndroidDecoderModule.h"
29 #include "mozilla/ipc/UtilityProcessChild.h"
30 #include "mozilla/RemoteDecodeUtils.h"
32 #ifdef MOZ_WMF_MEDIA_ENGINE
33 # include "mozilla/gfx/DeviceManagerDx.h"
34 # include "mozilla/gfx/gfxVars.h"
35 # include "gfxConfig.h"
38 namespace mozilla::ipc
{
40 UtilityAudioDecoderParent::UtilityAudioDecoderParent()
41 : mKind(GetCurrentSandboxingKind()),
42 mAudioDecoderParentStart(TimeStamp::Now()) {
43 #ifdef MOZ_WMF_MEDIA_ENGINE
44 if (mKind
== SandboxingKind::MF_MEDIA_ENGINE_CDM
) {
45 nsDebugImpl::SetMultiprocessMode("MF Media Engine CDM");
46 profiler_set_process_name(nsCString("MF Media Engine CDM"));
47 gfx::gfxConfig::Init();
48 gfx::gfxVars::Initialize();
49 gfx::DeviceManagerDx::Init();
53 if (GetCurrentSandboxingKind() != SandboxingKind::GENERIC_UTILITY
) {
54 nsDebugImpl::SetMultiprocessMode("Utility AudioDecoder");
55 profiler_set_process_name(nsCString("Utility AudioDecoder"));
59 UtilityAudioDecoderParent::~UtilityAudioDecoderParent() {
60 #ifdef MOZ_WMF_MEDIA_ENGINE
61 if (mKind
== SandboxingKind::MF_MEDIA_ENGINE_CDM
) {
62 gfx::gfxConfig::Shutdown();
63 gfx::gfxVars::Shutdown();
64 gfx::DeviceManagerDx::Shutdown();
70 void UtilityAudioDecoderParent::GenericPreloadForSandbox() {
71 #if defined(MOZ_SANDBOX) && defined(XP_WIN) && defined(MOZ_FFVPX)
72 // Preload AV dlls so we can enable Binary Signature Policy
73 // to restrict further dll loads.
74 UtilityProcessImpl::LoadLibraryOrCrash(L
"mozavcodec.dll");
75 UtilityProcessImpl::LoadLibraryOrCrash(L
"mozavutil.dll");
76 #endif // defined(MOZ_SANDBOX) && defined(XP_WIN) && defined(MOZ_FFVPX)
80 void UtilityAudioDecoderParent::WMFPreloadForSandbox() {
81 #if defined(MOZ_SANDBOX) && defined(XP_WIN)
82 // mfplat.dll and mf.dll will be preloaded by
83 // wmf::MediaFoundationInitializer::HasInitialized()
85 # if defined(NS_FREE_PERMANENT_DATA)
86 // WMF Shutdown requires this or it will badly crash
87 UtilityProcessImpl::LoadLibraryOrCrash(L
"ole32.dll");
88 # endif // defined(NS_FREE_PERMANENT_DATA)
90 auto rv
= wmf::MediaFoundationInitializer::HasInitialized();
92 NS_WARNING("Failed to init Media Foundation in the Utility process");
95 #endif // defined(MOZ_SANDBOX) && defined(XP_WIN)
98 void UtilityAudioDecoderParent::Start(
99 Endpoint
<PUtilityAudioDecoderParent
>&& aEndpoint
) {
100 MOZ_ASSERT(NS_IsMainThread());
102 DebugOnly
<bool> ok
= std::move(aEndpoint
).Bind(this);
105 #ifdef MOZ_WIDGET_ANDROID
106 if (StaticPrefs::media_utility_android_media_codec_enabled()) {
107 AndroidDecoderModule::SetSupportedMimeTypes();
111 auto supported
= PDMFactory::Supported();
112 Unused
<< SendUpdateMediaCodecsSupported(GetRemoteDecodeInFromKind(mKind
),
114 PROFILER_MARKER_UNTYPED("UtilityAudioDecoderParent::Start", IPC
,
115 MarkerOptions(MarkerTiming::IntervalUntilNowFrom(
116 mAudioDecoderParentStart
)));
119 mozilla::ipc::IPCResult
120 UtilityAudioDecoderParent::RecvNewContentRemoteDecoderManager(
121 Endpoint
<PRemoteDecoderManagerParent
>&& aEndpoint
) {
122 MOZ_ASSERT(NS_IsMainThread());
123 if (!RemoteDecoderManagerParent::CreateForContent(std::move(aEndpoint
))) {
124 return IPC_FAIL_NO_REASON(this);
129 #ifdef MOZ_WMF_MEDIA_ENGINE
130 mozilla::ipc::IPCResult
UtilityAudioDecoderParent::RecvInitVideoBridge(
131 Endpoint
<PVideoBridgeChild
>&& aEndpoint
,
132 nsTArray
<gfx::GfxVarUpdate
>&& aUpdates
,
133 const ContentDeviceData
& aContentDeviceData
) {
134 MOZ_ASSERT(mKind
== SandboxingKind::MF_MEDIA_ENGINE_CDM
);
135 if (!RemoteDecoderManagerParent::CreateVideoBridgeToOtherProcess(
136 std::move(aEndpoint
))) {
137 return IPC_FAIL_NO_REASON(this);
140 for (const auto& update
: aUpdates
) {
141 gfx::gfxVars::ApplyUpdate(update
);
144 gfx::gfxConfig::Inherit(
146 gfx::Feature::HW_COMPOSITING
,
147 gfx::Feature::D3D11_COMPOSITING
,
148 gfx::Feature::OPENGL_COMPOSITING
,
149 gfx::Feature::DIRECT2D
,
151 aContentDeviceData
.prefs());
153 if (gfx::gfxConfig::IsEnabled(gfx::Feature::D3D11_COMPOSITING
)) {
154 if (auto* devmgr
= gfx::DeviceManagerDx::Get()) {
155 devmgr
->ImportDeviceInfo(aContentDeviceData
.d3d11());
159 Unused
<< SendCompleteCreatedVideoBridge();
163 IPCResult
UtilityAudioDecoderParent::RecvUpdateVar(
164 const GfxVarUpdate
& aUpdate
) {
165 MOZ_ASSERT(mKind
== SandboxingKind::MF_MEDIA_ENGINE_CDM
);
166 gfx::gfxVars::ApplyUpdate(aUpdate
);
171 } // namespace mozilla::ipc