WMFCDMProxy.h (5281B)
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim:set ts=2 sw=2 sts=2 et cindent: */ 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 file, 5 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef DOM_MEDIA_EME_MEDIAFOUNDATION_WMFCDMPROXY_H_ 8 #define DOM_MEDIA_EME_MEDIAFOUNDATION_WMFCDMPROXY_H_ 9 10 #include "mozilla/CDMCaps.h" 11 #include "mozilla/CDMProxy.h" 12 #include "mozilla/MozPromise.h" 13 #include "mozilla/RefPtr.h" 14 #include "mozilla/WMFCDMImpl.h" 15 #include "mozilla/dom/BindingDeclarations.h" 16 #include "mozilla/dom/MediaKeySession.h" 17 #include "mozilla/dom/MediaKeys.h" 18 #include "nsString.h" 19 20 namespace dom { 21 struct MediaKeySystemMediaCapability; 22 }; 23 24 namespace mozilla { 25 26 class WMFCDMProxyCallback; 27 28 class WMFCDMProxy : public CDMProxy { 29 public: 30 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(WMFCDMProxy, override) 31 32 WMFCDMProxy(dom::MediaKeys* aKeys, const nsAString& aKeySystem, 33 const dom::MediaKeySystemConfiguration& aConfig); 34 35 // CDMProxy interface 36 void Init(PromiseId aPromiseId, const nsAString& aOrigin, 37 const nsAString& aTopLevelOrigin, const nsAString& aName) override; 38 39 void CreateSession(uint32_t aCreateSessionToken, 40 dom::MediaKeySessionType aSessionType, 41 PromiseId aPromiseId, const nsAString& aInitDataType, 42 nsTArray<uint8_t>& aInitData) override; 43 44 void LoadSession(PromiseId aPromiseId, dom::MediaKeySessionType aSessionType, 45 const nsAString& aSessionId) override; 46 47 void SetServerCertificate(PromiseId aPromiseId, 48 nsTArray<uint8_t>& aCert) override; 49 50 void UpdateSession(const nsAString& aSessionId, PromiseId aPromiseId, 51 nsTArray<uint8_t>& aResponse) override; 52 53 void CloseSession(const nsAString& aSessionId, PromiseId aPromiseId) override; 54 55 void RemoveSession(const nsAString& aSessionId, 56 PromiseId aPromiseId) override; 57 58 void QueryOutputProtectionStatus() override {} 59 60 void NotifyOutputProtectionStatus( 61 OutputProtectionCheckStatus aCheckStatus, 62 OutputProtectionCaptureStatus aCaptureStatus) override {} 63 64 void Shutdown() override; 65 66 void Terminated() override; 67 68 void OnSetSessionId(uint32_t aCreateSessionToken, 69 const nsAString& aSessionId) override {} 70 71 void OnResolveLoadSessionPromise(uint32_t aPromiseId, 72 bool aSuccess) override {} 73 74 void OnSessionMessage(const nsAString& aSessionId, 75 dom::MediaKeyMessageType aMessageType, 76 const nsTArray<uint8_t>& aMessage) override; 77 78 void OnExpirationChange(const nsAString& aSessionId, 79 UnixTime aExpiryTime) override; 80 81 void OnSessionClosed(const nsAString& aSessionId, 82 dom::MediaKeySessionClosedReason aReason) override; 83 84 void OnSessionError(const nsAString& aSessionId, nsresult aException, 85 uint32_t aSystemCode, const nsAString& aMsg) override {} 86 87 void OnRejectPromise(uint32_t aPromiseId, ErrorResult&& aException, 88 const nsCString& aMsg) override {} 89 90 RefPtr<DecryptPromise> Decrypt(MediaRawData* aSample) override { 91 return nullptr; 92 } 93 void OnDecrypted(uint32_t aId, DecryptStatus aResult, 94 const nsTArray<uint8_t>& aDecryptedData) override {} 95 96 void ResolvePromise(PromiseId aId) override; 97 void RejectPromise(PromiseId aId, ErrorResult&& aException, 98 const nsCString& aReason) override; 99 100 void OnKeyStatusesChange(const nsAString& aSessionId) override; 101 102 void GetStatusForPolicy(PromiseId aPromiseId, 103 const dom::HDCPVersion& aMinHdcpVersion) override; 104 105 #ifdef DEBUG 106 bool IsOnOwnerThread() override { 107 return NS_GetCurrentThread() == mOwnerThread; 108 } 109 #endif 110 111 WMFCDMProxy* AsWMFCDMProxy() override { return this; } 112 113 bool IsHardwareDecryptionSupported() const override; 114 115 // Can only be called after initialization succeeded. 116 uint64_t GetCDMProxyId() const; 117 118 private: 119 virtual ~WMFCDMProxy(); 120 121 template <typename T> 122 void ResolvePromiseWithResult(PromiseId aId, const T& aResult) {} 123 void RejectPromiseOnMainThread(PromiseId aId, 124 CopyableErrorResult&& aException, 125 const nsCString& aReason); 126 // Reject promise with an InvalidStateError and the given message. 127 void RejectPromiseWithStateError(PromiseId aId, const nsCString& aReason); 128 129 // For HDCP GetStatusForPolicy usage. 130 void ResolvePromiseWithKeyStatus(const PromiseId& aId, 131 const dom::MediaKeyStatus& aStatus); 132 133 CopyableTArray<MFCDMMediaCapability> GenerateMFCDMMediaCapabilities( 134 const dom::Sequence<dom::MediaKeySystemMediaCapability>& aCapabilities, 135 const Maybe<nsString>& forcedRobustness = Nothing()); 136 137 RefPtr<WMFCDMImpl> mCDM; 138 139 const dom::MediaKeySystemConfiguration mConfig; 140 141 RefPtr<WMFCDMProxyCallback> mProxyCallback; 142 143 // It can only be used on the main thread. 144 bool mIsShutdown = false; 145 }; 146 147 } // namespace mozilla 148 149 #endif // DOM_MEDIA_EME_MEDIAFOUNDATION_WMFCDMPROXY_H_