1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef ChromiumCDMChild_h_
7 #define ChromiumCDMChild_h_
9 #include "content_decryption_module.h"
10 #include "mozilla/gmp/PChromiumCDMChild.h"
11 #include "SimpleMap.h"
12 #include "WidevineVideoFrame.h"
14 namespace mozilla::gmp
{
16 class GMPContentChild
;
18 class ChromiumCDMChild
: public PChromiumCDMChild
, public cdm::Host_10
{
20 // Mark AddRef and Release as `final`, as they overload pure virtual
21 // implementations in PChromiumCDMChild.
22 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ChromiumCDMChild
, final
);
24 explicit ChromiumCDMChild(GMPContentChild
* aPlugin
);
26 void Init(cdm::ContentDecryptionModule_10
* aCDM
,
27 const nsACString
& aStorageId
);
29 void TimerExpired(void* aContext
);
31 // cdm::Host_10 implementation
32 cdm::Buffer
* Allocate(uint32_t aCapacity
) override
;
33 void SetTimer(int64_t aDelayMs
, void* aContext
) override
;
34 cdm::Time
GetCurrentWallTime() override
;
35 void OnResolveKeyStatusPromise(uint32_t aPromiseId
,
36 cdm::KeyStatus aKeyStatus
) override
;
37 void OnResolveNewSessionPromise(uint32_t aPromiseId
, const char* aSessionId
,
38 uint32_t aSessionIdSize
) override
;
39 void OnResolvePromise(uint32_t aPromiseId
) override
;
40 void OnRejectPromise(uint32_t aPromiseId
, cdm::Exception aException
,
41 uint32_t aSystemCode
, const char* aErrorMessage
,
42 uint32_t aErrorMessageSize
) override
;
43 void OnSessionMessage(const char* aSessionId
, uint32_t aSessionIdSize
,
44 cdm::MessageType aMessageType
, const char* aMessage
,
45 uint32_t aMessageSize
) override
;
46 void OnSessionKeysChange(const char* aSessionId
, uint32_t aSessionIdSize
,
47 bool aHasAdditionalUsableKey
,
48 const cdm::KeyInformation
* aKeysInfo
,
49 uint32_t aKeysInfoCount
) override
;
50 void OnExpirationChange(const char* aSessionId
, uint32_t aSessionIdSize
,
51 cdm::Time aNewExpiryTime
) override
;
52 void OnSessionClosed(const char* aSessionId
,
53 uint32_t aSessionIdSize
) override
;
54 void SendPlatformChallenge(const char* aServiceId
, uint32_t aServiceIdSize
,
55 const char* aChallenge
,
56 uint32_t aChallengeSize
) override
{}
57 void EnableOutputProtection(uint32_t aDesiredProtectionMask
) override
{}
58 void QueryOutputProtectionStatus() override
;
59 void OnDeferredInitializationDone(cdm::StreamType aStreamType
,
60 cdm::Status aDecoderStatus
) override
{}
61 void RequestStorageId(uint32_t aVersion
) override
;
62 cdm::FileIO
* CreateFileIO(cdm::FileIOClient
* aClient
) override
;
63 void OnInitialized(bool aSuccess
) override
;
64 // end cdm::Host_10 specific methods
66 void GiveBuffer(ipc::Shmem
&& aBuffer
);
71 bool OnResolveNewSessionPromiseInternal(uint32_t aPromiseId
,
72 const nsACString
& aSessionId
);
74 bool IsOnMessageLoopThread();
76 void ActorDestroy(ActorDestroyReason aReason
) override
;
78 ipc::IPCResult
RecvGiveBuffer(ipc::Shmem
&& aShmem
) override
;
79 ipc::IPCResult
RecvPurgeShmems() override
;
81 ipc::IPCResult
RecvInit(const bool& aAllowDistinctiveIdentifier
,
82 const bool& aAllowPersistentState
,
83 InitResolver
&& aResolver
) override
;
84 ipc::IPCResult
RecvSetServerCertificate(
85 const uint32_t& aPromiseId
, nsTArray
<uint8_t>&& aServerCert
) override
;
86 ipc::IPCResult
RecvCreateSessionAndGenerateRequest(
87 const uint32_t& aPromiseId
, const uint32_t& aSessionType
,
88 const uint32_t& aInitDataType
, nsTArray
<uint8_t>&& aInitData
) override
;
89 ipc::IPCResult
RecvLoadSession(const uint32_t& aPromiseId
,
90 const uint32_t& aSessionType
,
91 const nsACString
& aSessionId
) override
;
92 ipc::IPCResult
RecvUpdateSession(const uint32_t& aPromiseId
,
93 const nsACString
& aSessionId
,
94 nsTArray
<uint8_t>&& aResponse
) override
;
95 ipc::IPCResult
RecvCloseSession(const uint32_t& aPromiseId
,
96 const nsACString
& aSessionId
) override
;
97 ipc::IPCResult
RecvRemoveSession(const uint32_t& aPromiseId
,
98 const nsACString
& aSessionId
) override
;
99 ipc::IPCResult
RecvCompleteQueryOutputProtectionStatus(
100 const bool& aSuccess
, const uint32_t& aLinkMask
,
101 const uint32_t& aProtectionMask
) override
;
102 ipc::IPCResult
RecvGetStatusForPolicy(
103 const uint32_t& aPromiseId
,
104 const cdm::HdcpVersion
& aMinHdcpVersion
) override
;
105 ipc::IPCResult
RecvDecrypt(const uint32_t& aId
,
106 const CDMInputBuffer
& aBuffer
) override
;
107 ipc::IPCResult
RecvInitializeVideoDecoder(
108 const CDMVideoDecoderConfig
& aConfig
) override
;
109 ipc::IPCResult
RecvDeinitializeVideoDecoder() override
;
110 ipc::IPCResult
RecvResetVideoDecoder() override
;
111 ipc::IPCResult
RecvDecryptAndDecodeFrame(
112 const CDMInputBuffer
& aBuffer
) override
;
113 ipc::IPCResult
RecvDrain() override
;
114 ipc::IPCResult
RecvDestroy() override
;
116 void ReturnOutput(WidevineVideoFrame
& aFrame
);
117 bool HasShmemOfSize(size_t aSize
) const;
119 template <typename MethodType
, typename
... ParamType
>
120 void CallMethod(MethodType
, ParamType
&&...);
122 template <typename MethodType
, typename
... ParamType
>
123 void CallOnMessageLoopThread(const char* const, MethodType
, ParamType
&&...);
125 GMPContentChild
* mPlugin
= nullptr;
126 cdm::ContentDecryptionModule_10
* mCDM
= nullptr;
128 typedef SimpleMap
<int64_t, uint64_t, ThreadSafePolicy
> DurationMap
;
129 DurationMap mFrameDurations
;
130 nsTArray
<uint32_t> mLoadSessionPromiseIds
;
132 cdm::Size mCodedSize
= {0, 0};
133 nsTArray
<ipc::Shmem
> mBuffers
;
135 bool mDecoderInitialized
= false;
136 bool mPersistentStateAllowed
= false;
137 bool mDestroyed
= false;
138 nsCString mStorageId
;
140 typedef MozPromise
<bool, nsresult
, /* IsExclusive = */ true> InitPromise
;
141 // Created when we RecvInit, should be resolved once the CDM is initialized
142 // or rejected if init fails.
143 MozPromiseHolder
<InitPromise
> mInitPromise
;
146 } // namespace mozilla::gmp
148 #endif // ChromiumCDMChild_h_