Widevine MediaCas client code that works with Android R
This commit is contained in:
87
plugin/include/widevine_cas_session.h
Normal file
87
plugin/include/widevine_cas_session.h
Normal file
@@ -0,0 +1,87 @@
|
||||
// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary
|
||||
// source code may only be used and distributed under the Widevine Master
|
||||
// License Agreement.
|
||||
|
||||
#ifndef WIDEVINE_CAS_SESSION_H
|
||||
#define WIDEVINE_CAS_SESSION_H
|
||||
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
|
||||
#include "cas_types.h"
|
||||
#include "crypto_session.h"
|
||||
#include "ecm_parser.h"
|
||||
|
||||
namespace wvcas {
|
||||
|
||||
class WidevineCasSession;
|
||||
typedef std::shared_ptr<WidevineCasSession> CasSessionPtr;
|
||||
|
||||
class CasKeySlotData {
|
||||
public:
|
||||
CasKeySlotData() {}
|
||||
~CasKeySlotData() {}
|
||||
|
||||
KeySlot& operator[](KeySlotId slot_id);
|
||||
const KeySlot& operator[](KeySlotId slot_id) const;
|
||||
|
||||
private:
|
||||
KeySlot keys_[2]; // Odd and even key slots.
|
||||
};
|
||||
|
||||
enum class ScramblingControl {
|
||||
kScrambling_Unscrambled = 0,
|
||||
kScrambling_Reserved = 1,
|
||||
kScrambling_EvenKey = 2,
|
||||
kScrambling_OddKey = 3,
|
||||
};
|
||||
|
||||
// WidevineCasSession represents an encryption context for a single ECM key
|
||||
// stream. It processes ECMs for the stream and maintains the key information.
|
||||
class WidevineCasSession {
|
||||
public:
|
||||
WidevineCasSession() {}
|
||||
virtual ~WidevineCasSession();
|
||||
|
||||
CasStatus initialize(std::shared_ptr<CryptoSession> crypto_session,
|
||||
uint32_t* session_id);
|
||||
|
||||
// Get the current key information. This method will be used by a descrambler
|
||||
// plugin to obtain the current key information.
|
||||
const KeySlot& key(KeySlotId slot_id) const;
|
||||
|
||||
// Process an ecm and extract the key slot data. Extracted data will be used
|
||||
// to update |current_ecm_| and |entitlement_key_id_| and |keys_|.
|
||||
// |parental_control_age| (if non-zero) must be greater or equal to the
|
||||
// age_restriction field specified in |ecm|. Otherwise, ECM will not be
|
||||
// processed and error will be returned.
|
||||
virtual CasStatus processEcm(const CasEcm& ecm, uint8_t parental_control_age);
|
||||
|
||||
// Returns the security level retrieved from OEMCrypto.
|
||||
const char* securityLevel();
|
||||
|
||||
// Returns current ecm age restriction value.
|
||||
uint8_t GetEcmAgeRestriction() { return ecm_age_restriction_; }
|
||||
|
||||
WidevineCasSession(const WidevineCasSession&) = delete;
|
||||
WidevineCasSession& operator=(const WidevineCasSession&) = delete;
|
||||
|
||||
private:
|
||||
// Creates an EcmParser.
|
||||
virtual std::unique_ptr<const EcmParser> getEcmParser(
|
||||
const CasEcm& ecm) const;
|
||||
|
||||
CasKeySlotData keys_; // Odd and even key slots.
|
||||
std::string entitlement_key_id_;
|
||||
std::mutex lock_;
|
||||
CasEcm current_ecm_;
|
||||
uint8_t ecm_age_restriction_ = 0;
|
||||
std::shared_ptr<CryptoSession> crypto_session_;
|
||||
// Id of the entitled key session in OEMCrypto associated with this session.
|
||||
uint32_t key_session_id_;
|
||||
};
|
||||
|
||||
} // namespace wvcas
|
||||
|
||||
#endif // WIDEVINE_CAS_SESSION_H
|
||||
Reference in New Issue
Block a user