Merge mozilla-central to autoland on a CLOSED TREE
[gecko.git] / ipc / glue / UtilityAudioDecoderParent.cpp
blob901604ed05e5e4fc24b6d67d1e8471fe0a43fe74
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)
16 # include "WMF.h"
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"
27 #endif
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"
36 #endif
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();
50 return;
52 #endif
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();
66 #endif
69 /* static */
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)
79 /* static */
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()
84 // WMF Shutdown requires this or it will badly crash
85 UtilityProcessImpl::LoadLibraryOrCrash(L"ole32.dll");
87 auto rv = wmf::MediaFoundationInitializer::HasInitialized();
88 if (!rv) {
89 NS_WARNING("Failed to init Media Foundation in the Utility process");
90 return;
92 #endif // defined(MOZ_SANDBOX) && defined(XP_WIN)
95 void UtilityAudioDecoderParent::Start(
96 Endpoint<PUtilityAudioDecoderParent>&& aEndpoint) {
97 MOZ_ASSERT(NS_IsMainThread());
99 DebugOnly<bool> ok = std::move(aEndpoint).Bind(this);
100 MOZ_ASSERT(ok);
102 #ifdef MOZ_WIDGET_ANDROID
103 if (StaticPrefs::media_utility_android_media_codec_enabled()) {
104 AndroidDecoderModule::SetSupportedMimeTypes(
105 AndroidDecoderModule::GetSupportedMimeTypes());
107 #endif
109 auto supported = PDMFactory::Supported();
110 Unused << SendUpdateMediaCodecsSupported(GetRemoteDecodeInFromKind(mKind),
111 supported);
112 PROFILER_MARKER_UNTYPED("UtilityAudioDecoderParent::Start", IPC,
113 MarkerOptions(MarkerTiming::IntervalUntilNowFrom(
114 mAudioDecoderParentStart)));
117 mozilla::ipc::IPCResult
118 UtilityAudioDecoderParent::RecvNewContentRemoteDecoderManager(
119 Endpoint<PRemoteDecoderManagerParent>&& aEndpoint) {
120 MOZ_ASSERT(NS_IsMainThread());
121 if (!RemoteDecoderManagerParent::CreateForContent(std::move(aEndpoint))) {
122 return IPC_FAIL_NO_REASON(this);
124 return IPC_OK();
127 #ifdef MOZ_WMF_MEDIA_ENGINE
128 mozilla::ipc::IPCResult UtilityAudioDecoderParent::RecvInitVideoBridge(
129 Endpoint<PVideoBridgeChild>&& aEndpoint,
130 nsTArray<gfx::GfxVarUpdate>&& aUpdates,
131 const ContentDeviceData& aContentDeviceData) {
132 MOZ_ASSERT(mKind == SandboxingKind::MF_MEDIA_ENGINE_CDM);
133 if (!RemoteDecoderManagerParent::CreateVideoBridgeToOtherProcess(
134 std::move(aEndpoint))) {
135 return IPC_FAIL_NO_REASON(this);
138 for (const auto& update : aUpdates) {
139 gfx::gfxVars::ApplyUpdate(update);
142 gfx::gfxConfig::Inherit(
144 gfx::Feature::HW_COMPOSITING,
145 gfx::Feature::D3D11_COMPOSITING,
146 gfx::Feature::OPENGL_COMPOSITING,
147 gfx::Feature::DIRECT2D,
149 aContentDeviceData.prefs());
151 if (gfx::gfxConfig::IsEnabled(gfx::Feature::D3D11_COMPOSITING)) {
152 if (auto* devmgr = gfx::DeviceManagerDx::Get()) {
153 devmgr->ImportDeviceInfo(aContentDeviceData.d3d11());
157 Unused << SendCompleteCreatedVideoBridge();
158 return IPC_OK();
161 IPCResult UtilityAudioDecoderParent::RecvUpdateVar(
162 const GfxVarUpdate& aUpdate) {
163 MOZ_ASSERT(mKind == SandboxingKind::MF_MEDIA_ENGINE_CDM);
164 gfx::gfxVars::ApplyUpdate(aUpdate);
165 return IPC_OK();
167 #endif
169 } // namespace mozilla::ipc