From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- dom/media/platforms/wmf/MFCDMSession.h | 93 ++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 dom/media/platforms/wmf/MFCDMSession.h (limited to 'dom/media/platforms/wmf/MFCDMSession.h') diff --git a/dom/media/platforms/wmf/MFCDMSession.h b/dom/media/platforms/wmf/MFCDMSession.h new file mode 100644 index 0000000000..44b7c3b239 --- /dev/null +++ b/dom/media/platforms/wmf/MFCDMSession.h @@ -0,0 +1,93 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef DOM_MEDIA_PLATFORM_WMF_MFCDMSESSION_H +#define DOM_MEDIA_PLATFORM_WMF_MFCDMSESSION_H + +#include +#include +#include + +#include "MFCDMExtra.h" +#include "MediaEventSource.h" +#include "mozilla/PMFCDM.h" +#include "mozilla/KeySystemConfig.h" +#include "nsAString.h" + +namespace mozilla { + +// MFCDMSession represents a key session defined by the EME spec, it operates +// the IMFContentDecryptionModuleSession directly and forward events from +// IMFContentDecryptionModuleSession to its caller. It's not thread-safe and +// can only be used on the manager thread for now. +class MFCDMSession final { + public: + ~MFCDMSession(); + + static MFCDMSession* Create(KeySystemConfig::SessionType aSessionType, + IMFContentDecryptionModule* aCdm, + nsISerialEventTarget* aManagerThread); + + // APIs corresponding to EME APIs (MediaKeySession) + HRESULT GenerateRequest(const nsAString& aInitDataType, + const uint8_t* aInitData, uint32_t aInitDataSize); + HRESULT Load(const nsAString& aSessionId); + HRESULT Update(const nsTArray& aMessage); + HRESULT Close(); + HRESULT Remove(); + + // Session status related events + MediaEventSource& KeyMessageEvent() { + return mKeyMessageEvent; + } + MediaEventSource& KeyChangeEvent() { + return mKeyChangeEvent; + } + MediaEventSource& ExpirationEvent() { + return mExpirationEvent; + } + + const Maybe& SessionID() const { return mSessionId; } + + private: + class SessionCallbacks; + + MFCDMSession(IMFContentDecryptionModuleSession* aSession, + SessionCallbacks* aCallback, + nsISerialEventTarget* aManagerThread); + MFCDMSession(const MFCDMSession&) = delete; + MFCDMSession& operator=(const MFCDMSession&) = delete; + + bool RetrieveSessionId(); + void OnSessionKeysChange(); + void OnSessionKeyMessage(const MF_MEDIAKEYSESSION_MESSAGETYPE& aType, + const nsTArray& aMessage); + + HRESULT UpdateExpirationIfNeeded(); + + void AssertOnManagerThread() const { + MOZ_ASSERT(mManagerThread->IsOnCurrentThread()); + } + + const Microsoft::WRL::ComPtr mSession; + const nsCOMPtr mManagerThread; + + MediaEventProducer mKeyMessageEvent; + MediaEventProducer mKeyChangeEvent; + MediaEventProducer mExpirationEvent; + MediaEventListener mKeyMessageListener; + MediaEventListener mKeyChangeListener; + + // IMFContentDecryptionModuleSession's id might not be ready immediately after + // the session gets created. + Maybe mSessionId; + + // NaN when the CDM doesn't explicitly define the time or the time never + // expires. + double mExpiredTimeMilliSecondsSinceEpoch; +}; + +} // namespace mozilla + +#endif // DOM_MEDIA_PLATFORM_WMF_MFCDMSESSION_H -- cgit v1.2.3