2014-07-30 10:53:28 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* 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 CDMCaps_h_
|
|
|
|
#define CDMCaps_h_
|
|
|
|
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "mozilla/Monitor.h"
|
|
|
|
#include "nsIThread.h"
|
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "mozilla/Attributes.h"
|
2014-12-11 05:59:37 +03:00
|
|
|
#include "SamplesWaitingForKey.h"
|
2015-01-31 03:22:12 +03:00
|
|
|
#include "gmp-decryption.h"
|
2014-07-30 10:53:28 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2016-05-10 01:28:38 +03:00
|
|
|
// CDM capabilities; what keys a CDMProxy can use.
|
|
|
|
// Must be locked to access state.
|
2014-07-30 10:53:28 +04:00
|
|
|
class CDMCaps {
|
|
|
|
public:
|
|
|
|
CDMCaps();
|
|
|
|
~CDMCaps();
|
|
|
|
|
2015-01-31 03:22:25 +03:00
|
|
|
struct KeyStatus {
|
|
|
|
KeyStatus(const CencKeyId& aId,
|
|
|
|
const nsString& aSessionId,
|
|
|
|
GMPMediaKeyStatus aStatus)
|
|
|
|
: mId(aId)
|
|
|
|
, mSessionId(aSessionId)
|
|
|
|
, mStatus(aStatus)
|
|
|
|
{}
|
|
|
|
KeyStatus(const KeyStatus& aOther)
|
|
|
|
: mId(aOther.mId)
|
|
|
|
, mSessionId(aOther.mSessionId)
|
|
|
|
, mStatus(aOther.mStatus)
|
|
|
|
{}
|
|
|
|
bool operator==(const KeyStatus& aOther) const {
|
|
|
|
return mId == aOther.mId &&
|
|
|
|
mSessionId == aOther.mSessionId;
|
|
|
|
};
|
|
|
|
|
|
|
|
CencKeyId mId;
|
|
|
|
nsString mSessionId;
|
|
|
|
GMPMediaKeyStatus mStatus;
|
|
|
|
};
|
|
|
|
|
2014-07-30 10:53:28 +04:00
|
|
|
// Locks the CDMCaps. It must be locked to access its shared state.
|
|
|
|
// Threadsafe when locked.
|
|
|
|
class MOZ_STACK_CLASS AutoLock {
|
|
|
|
public:
|
|
|
|
explicit AutoLock(CDMCaps& aKeyCaps);
|
|
|
|
~AutoLock();
|
|
|
|
|
|
|
|
bool IsKeyUsable(const CencKeyId& aKeyId);
|
|
|
|
|
2015-01-31 03:22:12 +03:00
|
|
|
// Returns true if key status changed,
|
|
|
|
// i.e. the key status changed from usable to expired.
|
|
|
|
bool SetKeyStatus(const CencKeyId& aKeyId, const nsString& aSessionId, GMPMediaKeyStatus aStatus);
|
2014-07-30 10:53:28 +04:00
|
|
|
|
2015-01-31 03:22:25 +03:00
|
|
|
void GetKeyStatusesForSession(const nsAString& aSessionId,
|
|
|
|
nsTArray<KeyStatus>& aOutKeyStatuses);
|
2014-07-30 10:53:28 +04:00
|
|
|
|
2015-03-26 12:57:36 +03:00
|
|
|
void GetSessionIdsForKeyId(const CencKeyId& aKeyId,
|
|
|
|
nsTArray<nsCString>& aOutSessionIds);
|
|
|
|
|
2016-04-21 23:31:18 +03:00
|
|
|
// Ensures all keys for a session are marked as 'unknown', i.e. removed.
|
|
|
|
// Returns true if a key status was changed.
|
|
|
|
bool RemoveKeysForSession(const nsString& aSessionId);
|
|
|
|
|
2014-12-11 05:59:37 +03:00
|
|
|
// Notifies the SamplesWaitingForKey when key become usable.
|
|
|
|
void NotifyWhenKeyIdUsable(const CencKeyId& aKey,
|
|
|
|
SamplesWaitingForKey* aSamplesWaiting);
|
2014-07-30 10:53:28 +04:00
|
|
|
private:
|
|
|
|
// Not taking a strong ref, since this should be allocated on the stack.
|
|
|
|
CDMCaps& mData;
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
void Lock();
|
|
|
|
void Unlock();
|
|
|
|
|
|
|
|
struct WaitForKeys {
|
|
|
|
WaitForKeys(const CencKeyId& aKeyId,
|
2014-12-11 05:59:37 +03:00
|
|
|
SamplesWaitingForKey* aListener)
|
2014-07-30 10:53:28 +04:00
|
|
|
: mKeyId(aKeyId)
|
2014-12-11 05:59:37 +03:00
|
|
|
, mListener(aListener)
|
2014-07-30 10:53:28 +04:00
|
|
|
{}
|
|
|
|
CencKeyId mKeyId;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<SamplesWaitingForKey> mListener;
|
2014-07-30 10:53:28 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
Monitor mMonitor;
|
|
|
|
|
2015-01-31 03:22:12 +03:00
|
|
|
nsTArray<KeyStatus> mKeyStatuses;
|
2014-07-30 10:53:28 +04:00
|
|
|
|
|
|
|
nsTArray<WaitForKeys> mWaitForKeys;
|
|
|
|
|
|
|
|
// It is not safe to copy this object.
|
2015-01-07 02:35:02 +03:00
|
|
|
CDMCaps(const CDMCaps&) = delete;
|
|
|
|
CDMCaps& operator=(const CDMCaps&) = delete;
|
2014-07-30 10:53:28 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif
|