tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

MFCDMSession.h (3396B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 #ifndef DOM_MEDIA_PLATFORM_WMF_MFCDMSESSION_H
      6 #define DOM_MEDIA_PLATFORM_WMF_MFCDMSESSION_H
      7 
      8 #include <wrl.h>
      9 #include <wrl/client.h>
     10 
     11 #include "MFCDMExtra.h"
     12 #include "MediaEventSource.h"
     13 #include "mozilla/KeySystemConfig.h"
     14 #include "mozilla/PMFCDM.h"
     15 #include "mozilla/dom/MediaKeySessionBinding.h"
     16 #include "nsAString.h"
     17 
     18 namespace mozilla {
     19 
     20 // MFCDMSession represents a key session defined by the EME spec, it operates
     21 // the IMFContentDecryptionModuleSession directly and forward events from
     22 // IMFContentDecryptionModuleSession to its caller. It's not thread-safe and
     23 // can only be used on the manager thread for now.
     24 class MFCDMSession final {
     25 public:
     26  ~MFCDMSession();
     27 
     28  static MFCDMSession* Create(KeySystemConfig::SessionType aSessionType,
     29                              IMFContentDecryptionModule* aCdm,
     30                              nsISerialEventTarget* aManagerThread);
     31 
     32  // APIs corresponding to EME APIs (MediaKeySession)
     33  HRESULT GenerateRequest(const nsAString& aInitDataType,
     34                          const uint8_t* aInitData, uint32_t aInitDataSize);
     35  HRESULT Load(const nsAString& aSessionId);
     36  HRESULT Update(const nsTArray<uint8_t>& aMessage);
     37  HRESULT Close(dom::MediaKeySessionClosedReason aReason);
     38  HRESULT Remove();
     39 
     40  // Session status related events
     41  MediaEventSource<MFCDMKeyMessage>& KeyMessageEvent() {
     42    return mKeyMessageEvent;
     43  }
     44  MediaEventSource<MFCDMKeyStatusChange>& KeyChangeEvent() {
     45    return mKeyChangeEvent;
     46  }
     47  MediaEventSource<MFCDMKeyExpiration>& ExpirationEvent() {
     48    return mExpirationEvent;
     49  }
     50  MediaEventSource<MFCDMSessionClosedResult>& ClosedEvent() {
     51    return mClosedEvent;
     52  }
     53 
     54  const Maybe<nsString>& SessionID() const { return mSessionId; }
     55 
     56 private:
     57  class SessionCallbacks;
     58 
     59  MFCDMSession(IMFContentDecryptionModuleSession* aSession,
     60               SessionCallbacks* aCallback,
     61               nsISerialEventTarget* aManagerThread);
     62  MFCDMSession(const MFCDMSession&) = delete;
     63  MFCDMSession& operator=(const MFCDMSession&) = delete;
     64 
     65  bool RetrieveSessionId();
     66  void OnSessionKeysChange();
     67  void OnSessionKeyMessage(const MF_MEDIAKEYSESSION_MESSAGETYPE& aType,
     68                           const nsTArray<uint8_t>& aMessage);
     69 
     70  HRESULT UpdateExpirationIfNeeded();
     71 
     72  void AssertOnManagerThread() const {
     73    MOZ_ASSERT(mManagerThread->IsOnCurrentThread());
     74  }
     75 
     76  const Microsoft::WRL::ComPtr<IMFContentDecryptionModuleSession> mSession;
     77  const nsCOMPtr<nsISerialEventTarget> mManagerThread;
     78 
     79  MediaEventProducer<MFCDMKeyMessage> mKeyMessageEvent;
     80  MediaEventProducer<MFCDMKeyStatusChange> mKeyChangeEvent;
     81  MediaEventProducer<MFCDMKeyExpiration> mExpirationEvent;
     82  MediaEventProducer<MFCDMSessionClosedResult> mClosedEvent;
     83  MediaEventListener mKeyMessageListener;
     84  MediaEventListener mKeyChangeListener;
     85 
     86  // IMFContentDecryptionModuleSession's id might not be ready immediately after
     87  // the session gets created.
     88  Maybe<nsString> mSessionId;
     89 
     90  bool mIsClosed = false;
     91 
     92  // NaN when the CDM doesn't explicitly define the time or the time never
     93  // expires.
     94  double mExpiredTimeMilliSecondsSinceEpoch;
     95 };
     96 
     97 }  // namespace mozilla
     98 
     99 #endif  // DOM_MEDIA_PLATFORM_WMF_MFCDMSESSION_H