LCOV - code coverage report
Current view: top level - dom/media/eme - CDMCaps.h (source / functions) Hit Total Coverage
Test: output.info Lines: 0 17 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 7 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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 "gmp-decryption.h"
      11             : #include "nsIThread.h"
      12             : #include "nsTArray.h"
      13             : #include "nsString.h"
      14             : #include "SamplesWaitingForKey.h"
      15             : 
      16             : #include "mozilla/Monitor.h"
      17             : #include "mozilla/Attributes.h"
      18             : #include "mozilla/dom/MediaKeyStatusMapBinding.h" // For MediaKeyStatus
      19             : #include "mozilla/dom/BindingDeclarations.h" // For Optional
      20             : 
      21             : namespace mozilla {
      22             : 
      23             : // CDM capabilities; what keys a CDMProxy can use.
      24             : // Must be locked to access state.
      25             : class CDMCaps {
      26             : public:
      27             :   CDMCaps();
      28             :   ~CDMCaps();
      29             : 
      30           0 :   struct KeyStatus {
      31           0 :     KeyStatus(const CencKeyId& aId,
      32             :               const nsString& aSessionId,
      33             :               dom::MediaKeyStatus aStatus)
      34           0 :       : mId(aId)
      35             :       , mSessionId(aSessionId)
      36           0 :       , mStatus(aStatus)
      37           0 :     {}
      38           0 :     KeyStatus(const KeyStatus& aOther)
      39           0 :       : mId(aOther.mId)
      40             :       , mSessionId(aOther.mSessionId)
      41           0 :       , mStatus(aOther.mStatus)
      42           0 :     {}
      43           0 :     bool operator==(const KeyStatus& aOther) const {
      44           0 :       return mId == aOther.mId &&
      45           0 :              mSessionId == aOther.mSessionId;
      46             :     };
      47             : 
      48             :     CencKeyId mId;
      49             :     nsString mSessionId;
      50             :     dom::MediaKeyStatus mStatus;
      51             :   };
      52             : 
      53             :   // Locks the CDMCaps. It must be locked to access its shared state.
      54             :   // Threadsafe when locked.
      55             :   class MOZ_STACK_CLASS AutoLock {
      56             :   public:
      57             :     explicit AutoLock(CDMCaps& aKeyCaps);
      58             :     ~AutoLock();
      59             : 
      60             :     bool IsKeyUsable(const CencKeyId& aKeyId);
      61             : 
      62             :     // Returns true if key status changed,
      63             :     // i.e. the key status changed from usable to expired.
      64             :     bool SetKeyStatus(const CencKeyId& aKeyId,
      65             :                       const nsString& aSessionId,
      66             :                       const dom::Optional<dom::MediaKeyStatus>& aStatus);
      67             : 
      68             :     void GetKeyStatusesForSession(const nsAString& aSessionId,
      69             :                                   nsTArray<KeyStatus>& aOutKeyStatuses);
      70             : 
      71             :     void GetSessionIdsForKeyId(const CencKeyId& aKeyId,
      72             :                                nsTArray<nsCString>& aOutSessionIds);
      73             : 
      74             :     // Ensures all keys for a session are marked as 'unknown', i.e. removed.
      75             :     // Returns true if a key status was changed.
      76             :     bool RemoveKeysForSession(const nsString& aSessionId);
      77             : 
      78             :     // Notifies the SamplesWaitingForKey when key become usable.
      79             :     void NotifyWhenKeyIdUsable(const CencKeyId& aKey,
      80             :                                SamplesWaitingForKey* aSamplesWaiting);
      81             :   private:
      82             :     // Not taking a strong ref, since this should be allocated on the stack.
      83             :     CDMCaps& mData;
      84             :   };
      85             : 
      86             : private:
      87             :   void Lock();
      88             :   void Unlock();
      89             : 
      90           0 :   struct WaitForKeys {
      91           0 :     WaitForKeys(const CencKeyId& aKeyId,
      92             :                 SamplesWaitingForKey* aListener)
      93           0 :       : mKeyId(aKeyId)
      94           0 :       , mListener(aListener)
      95           0 :     {}
      96             :     CencKeyId mKeyId;
      97             :     RefPtr<SamplesWaitingForKey> mListener;
      98             :   };
      99             : 
     100             :   Monitor mMonitor;
     101             : 
     102             :   nsTArray<KeyStatus> mKeyStatuses;
     103             : 
     104             :   nsTArray<WaitForKeys> mWaitForKeys;
     105             : 
     106             :   // It is not safe to copy this object.
     107             :   CDMCaps(const CDMCaps&) = delete;
     108             :   CDMCaps& operator=(const CDMCaps&) = delete;
     109             : };
     110             : 
     111             : } // namespace mozilla
     112             : 
     113             : #endif

Generated by: LCOV version 1.13