CDMCaps.h (2598B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 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 CDMCaps_h_ 8 #define CDMCaps_h_ 9 10 #include "SamplesWaitingForKey.h" 11 #include "mozilla/Monitor.h" 12 #include "mozilla/dom/BindingDeclarations.h" // For Optional 13 #include "mozilla/dom/MediaKeyStatusMapBinding.h" // For MediaKeyStatus 14 #include "nsString.h" 15 #include "nsTArray.h" 16 17 namespace mozilla { 18 19 // CDM capabilities; what keys a CDMProxy can use. 20 // Must be locked to access state. 21 class CDMCaps { 22 public: 23 CDMCaps(); 24 ~CDMCaps(); 25 26 struct KeyStatus { 27 KeyStatus(const CencKeyId& aId, const nsString& aSessionId, 28 dom::MediaKeyStatus aStatus) 29 : mId(aId.Clone()), mSessionId(aSessionId), mStatus(aStatus) {} 30 KeyStatus(const KeyStatus& aOther) 31 : mId(aOther.mId.Clone()), 32 mSessionId(aOther.mSessionId), 33 mStatus(aOther.mStatus) {} 34 bool operator==(const KeyStatus& aOther) const { 35 return mId == aOther.mId && mSessionId == aOther.mSessionId; 36 }; 37 38 CencKeyId mId; 39 nsString mSessionId; 40 dom::MediaKeyStatus mStatus; 41 }; 42 43 bool IsKeyUsable(const CencKeyId& aKeyId); 44 45 // Returns true if key status changed, 46 // i.e. the key status changed from usable to expired. 47 bool SetKeyStatus(const CencKeyId& aKeyId, const nsString& aSessionId, 48 const dom::Optional<dom::MediaKeyStatus>& aStatus); 49 50 void GetKeyStatusesForSession(const nsAString& aSessionId, 51 nsTArray<KeyStatus>& aOutKeyStatuses); 52 53 // Ensures all keys for a session are marked as 'unknown', i.e. removed. 54 // Returns true if a key status was changed. 55 bool RemoveKeysForSession(const nsString& aSessionId); 56 57 // Notifies the SamplesWaitingForKey when key become usable. 58 void NotifyWhenKeyIdUsable(const CencKeyId& aKey, 59 SamplesWaitingForKey* aSamplesWaiting); 60 61 private: 62 struct WaitForKeys { 63 WaitForKeys(const CencKeyId& aKeyId, SamplesWaitingForKey* aListener) 64 : mKeyId(aKeyId.Clone()), mListener(aListener) {} 65 CencKeyId mKeyId; 66 RefPtr<SamplesWaitingForKey> mListener; 67 }; 68 69 nsTArray<KeyStatus> mKeyStatuses; 70 71 nsTArray<WaitForKeys> mWaitForKeys; 72 73 // It is not safe to copy this object. 74 CDMCaps(const CDMCaps&) = delete; 75 CDMCaps& operator=(const CDMCaps&) = delete; 76 }; 77 78 } // namespace mozilla 79 80 #endif