Line data Source code
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 WidevineDecryptor_h_
7 : #define WidevineDecryptor_h_
8 :
9 : #include "stddef.h"
10 : #include "content_decryption_module.h"
11 : #include "gmp-api/gmp-decryption.h"
12 : #include "mozilla/RefPtr.h"
13 : #include "WidevineUtils.h"
14 : #include <map>
15 :
16 : namespace mozilla {
17 :
18 : class WidevineDecryptor : public GMPDecryptor
19 : , public cdm::Host_8
20 : {
21 : public:
22 :
23 0 : NS_INLINE_DECL_THREADSAFE_REFCOUNTING(WidevineDecryptor)
24 :
25 : WidevineDecryptor();
26 :
27 : void SetCDM(RefPtr<CDMWrapper> aCDM, uint32_t aDecryptorId);
28 :
29 : static RefPtr<CDMWrapper> GetInstance(uint32_t aDecryptorId);
30 :
31 : // GMPDecryptor
32 : void Init(GMPDecryptorCallback* aCallback,
33 : bool aDistinctiveIdentifierRequired,
34 : bool aPersistentStateRequired) override;
35 :
36 : void CreateSession(uint32_t aCreateSessionToken,
37 : uint32_t aPromiseId,
38 : const char* aInitDataType,
39 : uint32_t aInitDataTypeSize,
40 : const uint8_t* aInitData,
41 : uint32_t aInitDataSize,
42 : GMPSessionType aSessionType) override;
43 :
44 : void LoadSession(uint32_t aPromiseId,
45 : const char* aSessionId,
46 : uint32_t aSessionIdLength) override;
47 :
48 : void UpdateSession(uint32_t aPromiseId,
49 : const char* aSessionId,
50 : uint32_t aSessionIdLength,
51 : const uint8_t* aResponse,
52 : uint32_t aResponseSize) override;
53 :
54 : void CloseSession(uint32_t aPromiseId,
55 : const char* aSessionId,
56 : uint32_t aSessionIdLength) override;
57 :
58 : void RemoveSession(uint32_t aPromiseId,
59 : const char* aSessionId,
60 : uint32_t aSessionIdLength) override;
61 :
62 : void SetServerCertificate(uint32_t aPromiseId,
63 : const uint8_t* aServerCert,
64 : uint32_t aServerCertSize) override;
65 :
66 : void Decrypt(GMPBuffer* aBuffer,
67 : GMPEncryptedBufferMetadata* aMetadata) override;
68 :
69 : void DecryptingComplete() override;
70 :
71 :
72 : // cdm::Host_8
73 : cdm::Buffer* Allocate(uint32_t aCapacity) override;
74 : void SetTimer(int64_t aDelayMs, void* aContext) override;
75 : cdm::Time GetCurrentWallTime() override;
76 : void OnResolveNewSessionPromise(uint32_t aPromiseId,
77 : const char* aSessionId,
78 : uint32_t aSessionIdSize) override;
79 : void OnResolvePromise(uint32_t aPromiseId) override;
80 : void OnRejectPromise(uint32_t aPromiseId,
81 : cdm::Error aError,
82 : uint32_t aSystemCode,
83 : const char* aErrorMessage,
84 : uint32_t aErrorMessageSize) override;
85 : void OnSessionMessage(const char* aSessionId,
86 : uint32_t aSessionIdSize,
87 : cdm::MessageType aMessageType,
88 : const char* aMessage,
89 : uint32_t aMessageSize,
90 : const char* aLegacyDestinationUrl,
91 : uint32_t aLegacyDestinationUrlLength) override;
92 : void OnSessionKeysChange(const char* aSessionId,
93 : uint32_t aSessionIdSize,
94 : bool aHasAdditionalUsableKey,
95 : const cdm::KeyInformation* aKeysInfo,
96 : uint32_t aKeysInfoCount) override;
97 : void OnExpirationChange(const char* aSessionId,
98 : uint32_t aSessionIdSize,
99 : cdm::Time aNewExpiryTime) override;
100 : void OnSessionClosed(const char* aSessionId,
101 : uint32_t aSessionIdSize) override;
102 : void OnLegacySessionError(const char* aSessionId,
103 : uint32_t aSessionId_length,
104 : cdm::Error aError,
105 : uint32_t aSystemCode,
106 : const char* aErrorMessage,
107 : uint32_t aErrorMessageLength) override;
108 : void SendPlatformChallenge(const char* aServiceId,
109 : uint32_t aServiceIdSize,
110 : const char* aChallenge,
111 : uint32_t aChallengeSize) override;
112 : void EnableOutputProtection(uint32_t aDesiredProtectionMask) override;
113 : void QueryOutputProtectionStatus() override;
114 : void OnDeferredInitializationDone(cdm::StreamType aStreamType,
115 : cdm::Status aDecoderStatus) override;
116 : cdm::FileIO* CreateFileIO(cdm::FileIOClient* aClient) override;
117 :
118 : GMPDecryptorCallback* Callback() const { return mCallback; }
119 : RefPtr<CDMWrapper> GetCDMWrapper() const { return mCDM; }
120 : private:
121 : ~WidevineDecryptor();
122 : RefPtr<CDMWrapper> mCDM;
123 0 : cdm::ContentDecryptionModule_8* CDM() { return mCDM->GetCDM(); }
124 :
125 : GMPDecryptorCallback* mCallback;
126 : std::map<uint32_t, uint32_t> mPromiseIdToNewSessionTokens;
127 : bool mDistinctiveIdentifierRequired = false;
128 : bool mPersistentStateRequired = false;
129 : uint32_t mInstanceId = 0;
130 : };
131 :
132 : } // namespace mozilla
133 :
134 : #endif // WidevineDecryptor_h_
|