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/. */
6 #ifndef _include_ipc_glue_UtilityAudioDecoderChild_h__
7 #define _include_ipc_glue_UtilityAudioDecoderChild_h__
9 #include "mozilla/ProcInfo.h"
10 #include "mozilla/ProfilerMarkers.h"
11 #include "mozilla/RefPtr.h"
13 #include "mozilla/ipc/Endpoint.h"
14 #include "mozilla/ipc/UtilityProcessParent.h"
15 #include "mozilla/ipc/UtilityProcessSandboxing.h"
16 #include "mozilla/ipc/UtilityAudioDecoder.h"
17 #include "mozilla/ipc/PUtilityAudioDecoderChild.h"
19 #ifdef MOZ_WMF_MEDIA_ENGINE
20 # include "mozilla/gfx/GPUProcessListener.h"
21 # include "mozilla/gfx/gfxVarReceiver.h"
24 #include "PDMFactory.h"
26 namespace mozilla::ipc
{
28 class UtilityAudioDecoderChildShutdownObserver
: public nsIObserver
{
30 explicit UtilityAudioDecoderChildShutdownObserver(SandboxingKind aKind
)
35 NS_IMETHOD
Observe(nsISupports
* aSubject
, const char* aTopic
,
36 const char16_t
* aData
) override
;
39 virtual ~UtilityAudioDecoderChildShutdownObserver() = default;
41 const SandboxingKind mSandbox
;
44 // This controls performing audio decoding on the utility process and it is
45 // intended to live on the main process side
46 class UtilityAudioDecoderChild final
: public PUtilityAudioDecoderChild
47 #ifdef MOZ_WMF_MEDIA_ENGINE
49 public gfx::gfxVarReceiver
,
50 public gfx::GPUProcessListener
54 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(UtilityAudioDecoderChild
, override
);
55 mozilla::ipc::IPCResult
RecvUpdateMediaCodecsSupported(
56 const RemoteDecodeIn
& aLocation
,
57 const media::MediaCodecsSupported
& aSupported
);
59 UtilityActorName
GetActorName() { return GetAudioActorName(mSandbox
); }
61 nsresult
BindToUtilityProcess(RefPtr
<UtilityProcessParent
> aUtilityParent
) {
62 Endpoint
<PUtilityAudioDecoderChild
> utilityAudioDecoderChildEnd
;
63 Endpoint
<PUtilityAudioDecoderParent
> utilityAudioDecoderParentEnd
;
64 nsresult rv
= PUtilityAudioDecoder::CreateEndpoints(
65 aUtilityParent
->OtherPid(), base::GetCurrentProcId(),
66 &utilityAudioDecoderParentEnd
, &utilityAudioDecoderChildEnd
);
69 MOZ_ASSERT(false, "Protocol endpoints failure");
70 return NS_ERROR_FAILURE
;
73 if (!aUtilityParent
->SendStartUtilityAudioDecoderService(
74 std::move(utilityAudioDecoderParentEnd
))) {
75 MOZ_ASSERT(false, "StartUtilityAudioDecoder service failure");
76 return NS_ERROR_FAILURE
;
79 Bind(std::move(utilityAudioDecoderChildEnd
));
81 PROFILER_MARKER_UNTYPED(
82 "UtilityAudioDecoderChild::BindToUtilityProcess", IPC
,
84 MarkerTiming::IntervalUntilNowFrom(mAudioDecoderChildStart
)));
88 void ActorDestroy(ActorDestroyReason aReason
) override
;
90 void Bind(Endpoint
<PUtilityAudioDecoderChild
>&& aEndpoint
);
92 static void Shutdown(SandboxingKind aKind
);
94 static RefPtr
<UtilityAudioDecoderChild
> GetSingleton(SandboxingKind aKind
);
96 #ifdef MOZ_WMF_MEDIA_ENGINE
97 mozilla::ipc::IPCResult
RecvCompleteCreatedVideoBridge();
99 bool HasCreatedVideoBridge() const;
101 void OnVarChanged(const gfx::GfxVarUpdate
& aVar
) override
;
103 void OnCompositorUnexpectedShutdown() override
;
105 // True if creating a video bridge sucessfully. Currently only used for media
107 bool CreateVideoBridge();
111 explicit UtilityAudioDecoderChild(SandboxingKind aKind
);
112 ~UtilityAudioDecoderChild() = default;
114 const SandboxingKind mSandbox
;
116 #ifdef MOZ_WMF_MEDIA_ENGINE
117 // True if the utility process has created a video bridge with the GPU prcess.
118 // Currently only used for media egine cdm. Main thread only.
119 bool mHasCreatedVideoBridge
= false;
122 TimeStamp mAudioDecoderChildStart
;
125 } // namespace mozilla::ipc
127 #endif // _include_ipc_glue_UtilityAudioDecoderChild_h__