/src/mozilla-central/dom/media/gmp/ChromiumCDMParent.h
Line | Count | Source (jump to first uncovered line) |
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/. */ |
5 | | |
6 | | #ifndef ChromiumCDMParent_h_ |
7 | | #define ChromiumCDMParent_h_ |
8 | | |
9 | | #include "DecryptJob.h" |
10 | | #include "GMPCrashHelper.h" |
11 | | #include "GMPCrashHelperHolder.h" |
12 | | #include "GMPMessageUtils.h" |
13 | | #include "mozilla/gmp/PChromiumCDMParent.h" |
14 | | #include "mozilla/RefPtr.h" |
15 | | #include "nsDataHashtable.h" |
16 | | #include "PlatformDecoderModule.h" |
17 | | #include "ImageContainer.h" |
18 | | #include "mozilla/Span.h" |
19 | | #include "ReorderQueue.h" |
20 | | |
21 | | class ChromiumCDMCallback; |
22 | | |
23 | | namespace mozilla { |
24 | | |
25 | | class MediaRawData; |
26 | | class ChromiumCDMProxy; |
27 | | |
28 | | namespace gmp { |
29 | | |
30 | | class GMPContentParent; |
31 | | |
32 | | class ChromiumCDMParent final |
33 | | : public PChromiumCDMParent |
34 | | , public GMPCrashHelperHolder |
35 | | { |
36 | | public: |
37 | | NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ChromiumCDMParent) |
38 | | |
39 | | ChromiumCDMParent(GMPContentParent* aContentParent, uint32_t aPluginId); |
40 | | |
41 | 0 | uint32_t PluginId() const { return mPluginId; } |
42 | | |
43 | | bool Init(ChromiumCDMCallback* aCDMCallback, |
44 | | bool aAllowDistinctiveIdentifier, |
45 | | bool aAllowPersistentState, |
46 | | nsIEventTarget* aMainThread, |
47 | | nsCString& aOutFailureReason); |
48 | | |
49 | | void CreateSession(uint32_t aCreateSessionToken, |
50 | | uint32_t aSessionType, |
51 | | uint32_t aInitDataType, |
52 | | uint32_t aPromiseId, |
53 | | const nsTArray<uint8_t>& aInitData); |
54 | | |
55 | | void LoadSession(uint32_t aPromiseId, |
56 | | uint32_t aSessionType, |
57 | | nsString aSessionId); |
58 | | |
59 | | void SetServerCertificate(uint32_t aPromiseId, |
60 | | const nsTArray<uint8_t>& aCert); |
61 | | |
62 | | void UpdateSession(const nsCString& aSessionId, |
63 | | uint32_t aPromiseId, |
64 | | const nsTArray<uint8_t>& aResponse); |
65 | | |
66 | | void CloseSession(const nsCString& aSessionId, uint32_t aPromiseId); |
67 | | |
68 | | void RemoveSession(const nsCString& aSessionId, uint32_t aPromiseId); |
69 | | |
70 | | void GetStatusForPolicy(uint32_t aPromiseId, |
71 | | const nsCString& aMinHdcpVersion); |
72 | | |
73 | | RefPtr<DecryptPromise> Decrypt(MediaRawData* aSample); |
74 | | |
75 | | // TODO: Add functions for clients to send data to CDM, and |
76 | | // a Close() function. |
77 | | RefPtr<MediaDataDecoder::InitPromise> InitializeVideoDecoder( |
78 | | const gmp::CDMVideoDecoderConfig& aConfig, |
79 | | const VideoInfo& aInfo, |
80 | | RefPtr<layers::ImageContainer> aImageContainer); |
81 | | |
82 | | RefPtr<MediaDataDecoder::DecodePromise> DecryptAndDecodeFrame( |
83 | | MediaRawData* aSample); |
84 | | |
85 | | RefPtr<MediaDataDecoder::FlushPromise> FlushVideoDecoder(); |
86 | | |
87 | | RefPtr<MediaDataDecoder::DecodePromise> Drain(); |
88 | | |
89 | | RefPtr<ShutdownPromise> ShutdownVideoDecoder(); |
90 | | |
91 | | void Shutdown(); |
92 | | |
93 | | protected: |
94 | 0 | ~ChromiumCDMParent() {} |
95 | | |
96 | | ipc::IPCResult Recv__delete__() override; |
97 | | ipc::IPCResult RecvOnResolvePromiseWithKeyStatus( |
98 | | const uint32_t& aPromiseId, |
99 | | const uint32_t& aKeyStatus) override; |
100 | | ipc::IPCResult RecvOnResolveNewSessionPromise( |
101 | | const uint32_t& aPromiseId, |
102 | | const nsCString& aSessionId) override; |
103 | | ipc::IPCResult RecvResolveLoadSessionPromise( |
104 | | const uint32_t& aPromiseId, |
105 | | const bool& aSuccessful) override; |
106 | | ipc::IPCResult RecvOnResolvePromise(const uint32_t& aPromiseId) override; |
107 | | ipc::IPCResult RecvOnRejectPromise(const uint32_t& aPromiseId, |
108 | | const uint32_t& aError, |
109 | | const uint32_t& aSystemCode, |
110 | | const nsCString& aErrorMessage) override; |
111 | | ipc::IPCResult RecvOnSessionMessage(const nsCString& aSessionId, |
112 | | const uint32_t& aMessageType, |
113 | | nsTArray<uint8_t>&& aMessage) override; |
114 | | ipc::IPCResult RecvOnSessionKeysChange( |
115 | | const nsCString& aSessionId, |
116 | | nsTArray<CDMKeyInformation>&& aKeysInfo) override; |
117 | | ipc::IPCResult RecvOnExpirationChange( |
118 | | const nsCString& aSessionId, |
119 | | const double& aSecondsSinceEpoch) override; |
120 | | ipc::IPCResult RecvOnSessionClosed(const nsCString& aSessionId) override; |
121 | | ipc::IPCResult RecvDecrypted(const uint32_t& aId, |
122 | | const uint32_t& aStatus, |
123 | | ipc::Shmem&& aData) override; |
124 | | ipc::IPCResult RecvDecryptFailed(const uint32_t& aId, |
125 | | const uint32_t& aStatus) override; |
126 | | ipc::IPCResult RecvOnDecoderInitDone(const uint32_t& aStatus) override; |
127 | | ipc::IPCResult RecvDecodedShmem(const CDMVideoFrame& aFrame, |
128 | | ipc::Shmem&& aShmem) override; |
129 | | ipc::IPCResult RecvDecodedData(const CDMVideoFrame& aFrame, |
130 | | nsTArray<uint8_t>&& aData) override; |
131 | | ipc::IPCResult RecvDecodeFailed(const uint32_t& aStatus) override; |
132 | | ipc::IPCResult RecvShutdown() override; |
133 | | ipc::IPCResult RecvResetVideoDecoderComplete() override; |
134 | | ipc::IPCResult RecvDrainComplete() override; |
135 | | ipc::IPCResult RecvIncreaseShmemPoolSize() override; |
136 | | void ActorDestroy(ActorDestroyReason aWhy) override; |
137 | | bool SendBufferToCDM(uint32_t aSizeInBytes); |
138 | | |
139 | | void ReorderAndReturnOutput(RefPtr<VideoData>&& aFrame); |
140 | | |
141 | | void RejectPromise(uint32_t aPromiseId, |
142 | | nsresult aError, |
143 | | const nsCString& aErrorMessage); |
144 | | |
145 | | void ResolvePromise(uint32_t aPromiseId); |
146 | | |
147 | | bool InitCDMInputBuffer(gmp::CDMInputBuffer& aBuffer, MediaRawData* aSample); |
148 | | |
149 | | bool PurgeShmems(); |
150 | | bool EnsureSufficientShmems(size_t aVideoFrameSize); |
151 | | already_AddRefed<VideoData> CreateVideoFrame(const CDMVideoFrame& aFrame, |
152 | | Span<uint8_t> aData); |
153 | | |
154 | | const uint32_t mPluginId; |
155 | | GMPContentParent* mContentParent; |
156 | | // Note: this pointer is a weak reference as ChromiumCDMProxy has a strong reference to the |
157 | | // ChromiumCDMCallback. |
158 | | ChromiumCDMCallback* mCDMCallback = nullptr; |
159 | | nsDataHashtable<nsUint32HashKey, uint32_t> mPromiseToCreateSessionToken; |
160 | | nsTArray<RefPtr<DecryptJob>> mDecrypts; |
161 | | |
162 | | MozPromiseHolder<MediaDataDecoder::InitPromise> mInitVideoDecoderPromise; |
163 | | MozPromiseHolder<MediaDataDecoder::DecodePromise> mDecodePromise; |
164 | | |
165 | | RefPtr<layers::ImageContainer> mImageContainer; |
166 | | VideoInfo mVideoInfo; |
167 | | uint64_t mLastStreamOffset = 0; |
168 | | |
169 | | MozPromiseHolder<MediaDataDecoder::FlushPromise> mFlushDecoderPromise; |
170 | | |
171 | | size_t mVideoFrameBufferSize = 0; |
172 | | |
173 | | // Count of the number of shmems in the set used to return decoded video |
174 | | // frames from the CDM to Gecko. |
175 | | uint32_t mVideoShmemsActive = 0; |
176 | | // Maximum number of shmems to use to return decoded video frames. |
177 | | uint32_t mVideoShmemLimit; |
178 | | |
179 | | bool mIsShutdown = false; |
180 | | bool mVideoDecoderInitialized = false; |
181 | | bool mActorDestroyed = false; |
182 | | bool mAbnormalShutdown = false; |
183 | | |
184 | | // The H.264 decoder in Widevine CDM versions 970 and later output in decode |
185 | | // order rather than presentation order, so we reorder in presentation order |
186 | | // before presenting. mMaxRefFrames is non-zero if we have an initialized |
187 | | // decoder and we are decoding H.264. If so, it stores the maximum length of |
188 | | // the reorder queue that we need. Note we may have multiple decoders for the |
189 | | // life time of this object, but never more than one active at once. |
190 | | uint32_t mMaxRefFrames = 0; |
191 | | ReorderQueue mReorderQueue; |
192 | | |
193 | | // The main thread associated with the root document. Must be set in Init(). |
194 | | nsCOMPtr<nsIEventTarget> mMainThread; |
195 | | }; |
196 | | |
197 | | } // namespace gmp |
198 | | } // namespace mozilla |
199 | | |
200 | | #endif // ChromiumCDMParent_h_ |