Bug 1516669 - Update gmp-clearkey to use CDM10 interface. r=cpearce

Not much changed in the interface:
- CDM initialization takes a use hardware codecs arg, we pipe this through, but
  don't do anything more with it in the clearkey CDM.
- The CDM should call the hosts OnInitialized() when it's initialized. This is
  done is now done in the clearkey CDM once the session management is ready, as
  that is the last thing done during init.

Aside from the above, it's just updating interface usage. While the new CDM
interface adds support for different encryption schemes, this is not handled
here and will be done in follow up bug 1516673.

Differential Revision: https://phabricator.services.mozilla.com/D15518

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Bryce Van Dyk 2019-01-14 16:40:04 +00:00
parent 5c977fdb7d
commit 5aecaa0a28
13 changed files with 59 additions and 48 deletions

View File

@ -4,14 +4,17 @@
using namespace cdm;
ClearKeyCDM::ClearKeyCDM(Host_9* aHost) {
ClearKeyCDM::ClearKeyCDM(Host_10* aHost) {
mHost = aHost;
mSessionManager = new ClearKeySessionManager(mHost);
}
void ClearKeyCDM::Initialize(bool aAllowDistinctiveIdentifier,
bool aAllowPersistentState) {
bool aAllowPersistentState,
bool aUseHardwareSecureCodecs) {
mSessionManager->Init(aAllowDistinctiveIdentifier, aAllowPersistentState);
// We call mHost->OnInitialized() in the session manager once it has
// initialized.
}
void ClearKeyCDM::GetStatusForPolicy(uint32_t aPromiseId,
@ -66,13 +69,13 @@ void ClearKeyCDM::TimerExpired(void* aContext) {
assert(false);
}
Status ClearKeyCDM::Decrypt(const InputBuffer_1& aEncryptedBuffer,
Status ClearKeyCDM::Decrypt(const InputBuffer_2& aEncryptedBuffer,
DecryptedBlock* aDecryptedBuffer) {
return mSessionManager->Decrypt(aEncryptedBuffer, aDecryptedBuffer);
}
Status ClearKeyCDM::InitializeAudioDecoder(
const AudioDecoderConfig_1& aAudioDecoderConfig) {
const AudioDecoderConfig_2& aAudioDecoderConfig) {
// Audio decoding is not supported by Clearkey because Widevine doesn't
// support it and Clearkey's raison d'etre is to provide test coverage
// for paths that Widevine will exercise in the wild.
@ -80,7 +83,7 @@ Status ClearKeyCDM::InitializeAudioDecoder(
}
Status ClearKeyCDM::InitializeVideoDecoder(
const VideoDecoderConfig_1& aVideoDecoderConfig) {
const VideoDecoderConfig_2& aVideoDecoderConfig) {
#ifdef ENABLE_WMF
mVideoDecoder = new VideoDecoder(mHost);
return mVideoDecoder->InitDecode(aVideoDecoderConfig);
@ -106,7 +109,7 @@ void ClearKeyCDM::ResetDecoder(StreamType aDecoderType) {
#endif
}
Status ClearKeyCDM::DecryptAndDecodeFrame(const InputBuffer_1& aEncryptedBuffer,
Status ClearKeyCDM::DecryptAndDecodeFrame(const InputBuffer_2& aEncryptedBuffer,
VideoFrame* aVideoFrame) {
#ifdef ENABLE_WMF
return mVideoDecoder->Decode(aEncryptedBuffer, aVideoFrame);
@ -116,7 +119,7 @@ Status ClearKeyCDM::DecryptAndDecodeFrame(const InputBuffer_1& aEncryptedBuffer,
}
Status ClearKeyCDM::DecryptAndDecodeSamples(
const InputBuffer_1& aEncryptedBuffer, AudioFrames* aAudioFrame) {
const InputBuffer_2& aEncryptedBuffer, AudioFrames* aAudioFrame) {
// Audio decoding is not supported by Clearkey because Widevine doesn't
// support it and Clearkey's raison d'etre is to provide test coverage
// for paths that Widevine will exercise in the wild.

View File

@ -13,7 +13,7 @@
#include "VideoDecoder.h"
#endif
class ClearKeyCDM : public cdm::ContentDecryptionModule_9 {
class ClearKeyCDM : public cdm::ContentDecryptionModule_10 {
private:
RefPtr<ClearKeySessionManager> mSessionManager;
#ifdef ENABLE_WMF
@ -21,13 +21,13 @@ class ClearKeyCDM : public cdm::ContentDecryptionModule_9 {
#endif
protected:
cdm::Host_9* mHost;
cdm::Host_10* mHost;
public:
explicit ClearKeyCDM(cdm::Host_9* mHost);
explicit ClearKeyCDM(cdm::Host_10* aHost);
void Initialize(bool aAllowDistinctiveIdentifier,
bool aAllowPersistentState) override;
void Initialize(bool aAllowDistinctiveIdentifier, bool aAllowPersistentState,
bool aUseHardwareSecureCodecs) override;
void GetStatusForPolicy(uint32_t aPromiseId,
const cdm::Policy& aPolicy) override;
@ -57,24 +57,24 @@ class ClearKeyCDM : public cdm::ContentDecryptionModule_9 {
void TimerExpired(void* aContext) override;
cdm::Status Decrypt(const cdm::InputBuffer_1& aEncryptedBuffer,
cdm::Status Decrypt(const cdm::InputBuffer_2& aEncryptedBuffer,
cdm::DecryptedBlock* aDecryptedBuffer) override;
cdm::Status InitializeAudioDecoder(
const cdm::AudioDecoderConfig_1& aAudioDecoderConfig) override;
const cdm::AudioDecoderConfig_2& aAudioDecoderConfig) override;
cdm::Status InitializeVideoDecoder(
const cdm::VideoDecoderConfig_1& aVideoDecoderConfig) override;
const cdm::VideoDecoderConfig_2& aVideoDecoderConfig) override;
void DeinitializeDecoder(cdm::StreamType aDecoderType) override;
void ResetDecoder(cdm::StreamType aDecoderType) override;
cdm::Status DecryptAndDecodeFrame(const cdm::InputBuffer_1& aEncryptedBuffer,
cdm::Status DecryptAndDecodeFrame(const cdm::InputBuffer_2& aEncryptedBuffer,
cdm::VideoFrame* aVideoFrame) override;
cdm::Status DecryptAndDecodeSamples(
const cdm::InputBuffer_1& aEncryptedBuffer,
const cdm::InputBuffer_2& aEncryptedBuffer,
cdm::AudioFrames* aAudioFrame) override;
void OnPlatformChallengeResponse(

View File

@ -32,11 +32,11 @@ class CryptoMetaData {
public:
CryptoMetaData() {}
explicit CryptoMetaData(const cdm::InputBuffer_1* aInputBuffer) {
explicit CryptoMetaData(const cdm::InputBuffer_2* aInputBuffer) {
Init(aInputBuffer);
}
void Init(const cdm::InputBuffer_1* aInputBuffer) {
void Init(const cdm::InputBuffer_2* aInputBuffer) {
if (!aInputBuffer) {
assert(!IsValid());
return;

View File

@ -89,7 +89,9 @@ void ClearKeyPersistence::WriteIndex() {
WriteData(mHost, filename, data, move(onIndexSuccess), move(onIndexFail));
}
ClearKeyPersistence::ClearKeyPersistence(Host_9* aHost) { this->mHost = aHost; }
ClearKeyPersistence::ClearKeyPersistence(Host_10* aHost) {
this->mHost = aHost;
}
void ClearKeyPersistence::EnsureInitialized(bool aPersistentStateAllowed,
function<void()>&& aOnInitialized) {

View File

@ -35,7 +35,7 @@ enum PersistentKeyState { UNINITIALIZED, LOADING, LOADED };
class ClearKeyPersistence : public RefCounted {
public:
explicit ClearKeyPersistence(cdm::Host_9* aHost);
explicit ClearKeyPersistence(cdm::Host_10* aHost);
void EnsureInitialized(bool aPersistentStateAllowed,
std::function<void()>&& aOnInitialized);
@ -49,7 +49,7 @@ class ClearKeyPersistence : public RefCounted {
void PersistentSessionRemoved(std::string& aSid);
private:
cdm::Host_9* mHost = nullptr;
cdm::Host_10* mHost = nullptr;
PersistentKeyState mPersistentKeyState = PersistentKeyState::UNINITIALIZED;

View File

@ -33,7 +33,7 @@
using namespace std;
using namespace cdm;
ClearKeySessionManager::ClearKeySessionManager(Host_9* aHost)
ClearKeySessionManager::ClearKeySessionManager(Host_10* aHost)
: mDecryptionManager(ClearKeyDecryptionManager::Get()) {
CK_LOGD("ClearKeySessionManager ctor %p", this);
AddRef();
@ -58,6 +58,11 @@ void ClearKeySessionManager::Init(bool aDistinctiveIdentifierAllowed,
func();
}
if (self->mHost) {
// The session manager should be the last thing the ClearKey CDM is
// waiting on to be initialized.
self->mHost->OnInitialized(true);
}
};
mPersistence->EnsureInitialized(aPersistentStateAllowed,
@ -529,7 +534,7 @@ void ClearKeySessionManager::SetServerCertificate(uint32_t aPromiseId,
nullptr /* message */, 0 /* messageLen */);
}
Status ClearKeySessionManager::Decrypt(const InputBuffer_1& aBuffer,
Status ClearKeySessionManager::Decrypt(const InputBuffer_2& aBuffer,
DecryptedBlock* aDecryptedBlock) {
CK_LOGD("ClearKeySessionManager::Decrypt");

View File

@ -35,7 +35,7 @@
class ClearKeySessionManager final : public RefCounted {
public:
explicit ClearKeySessionManager(cdm::Host_9* aHost);
explicit ClearKeySessionManager(cdm::Host_10* aHost);
void Init(bool aDistinctiveIdentifierAllowed, bool aPersistentStateAllowed);
@ -59,7 +59,7 @@ class ClearKeySessionManager final : public RefCounted {
void SetServerCertificate(uint32_t aPromiseId, const uint8_t* aServerCert,
uint32_t aServerCertSize);
cdm::Status Decrypt(const cdm::InputBuffer_1& aBuffer,
cdm::Status Decrypt(const cdm::InputBuffer_2& aBuffer,
cdm::DecryptedBlock* aDecryptedBlock);
void DecryptingComplete();
@ -80,7 +80,7 @@ class ClearKeySessionManager final : public RefCounted {
RefPtr<ClearKeyDecryptionManager> mDecryptionManager;
RefPtr<ClearKeyPersistence> mPersistence;
cdm::Host_9* mHost = nullptr;
cdm::Host_10* mHost = nullptr;
std::set<KeyId> mKeyIds;
std::map<std::string, ClearKeySession*> mSessions;

View File

@ -36,7 +36,7 @@ class WriteRecordClient : public FileIOClient {
* This function will take the memory ownership of the parameters and
* delete them when done.
*/
static void Write(Host_9* aHost, string& aRecordName,
static void Write(Host_10* aHost, string& aRecordName,
const vector<uint8_t>& aData, function<void()>&& aOnSuccess,
function<void()>&& aOnFailure) {
WriteRecordClient* client =
@ -71,7 +71,7 @@ class WriteRecordClient : public FileIOClient {
mOnFailure(move(aOnFailure)),
mData(aData) {}
void Do(const string& aName, Host_9* aHost) {
void Do(const string& aName, Host_10* aHost) {
// Initialize the FileIO.
mFileIO = aHost->CreateFileIO(this);
mFileIO->Open(aName.c_str(), aName.size());
@ -104,8 +104,9 @@ class WriteRecordClient : public FileIOClient {
const vector<uint8_t> mData;
};
void WriteData(Host_9* aHost, string& aRecordName, const vector<uint8_t>& aData,
function<void()>&& aOnSuccess, function<void()>&& aOnFailure) {
void WriteData(Host_10* aHost, string& aRecordName,
const vector<uint8_t>& aData, function<void()>&& aOnSuccess,
function<void()>&& aOnFailure) {
WriteRecordClient::Write(aHost, aRecordName, aData, move(aOnSuccess),
move(aOnFailure));
}
@ -116,7 +117,7 @@ class ReadRecordClient : public FileIOClient {
* This function will take the memory ownership of the parameters and
* delete them when done.
*/
static void Read(Host_9* aHost, string& aRecordName,
static void Read(Host_10* aHost, string& aRecordName,
function<void(const uint8_t*, uint32_t)>&& aOnSuccess,
function<void()>&& aOnFailure) {
(new ReadRecordClient(move(aOnSuccess), move(aOnFailure)))
@ -150,7 +151,7 @@ class ReadRecordClient : public FileIOClient {
mOnSuccess(move(aOnSuccess)),
mOnFailure(move(aOnFailure)) {}
void Do(const string& aName, Host_9* aHost) {
void Do(const string& aName, Host_10* aHost) {
mFileIO = aHost->CreateFileIO(this);
mFileIO->Open(aName.c_str(), aName.size());
}
@ -181,9 +182,9 @@ class ReadRecordClient : public FileIOClient {
function<void()> mOnFailure;
};
void ReadData(Host_9* mHost, string& aRecordName,
void ReadData(Host_10* aHost, string& aRecordName,
function<void(const uint8_t*, uint32_t)>&& aOnSuccess,
function<void()>&& aOnFailure) {
ReadRecordClient::Read(mHost, aRecordName, move(aOnSuccess),
ReadRecordClient::Read(aHost, aRecordName, move(aOnSuccess),
move(aOnFailure));
}

View File

@ -28,13 +28,13 @@
#define IO_FAILED(x) ((x) != cdm::FileIOClient::Status::kSuccess)
// Writes data to a file and fires the appropriate callback when complete.
void WriteData(cdm::Host_9* aHost, std::string& aRecordName,
void WriteData(cdm::Host_10* aHost, std::string& aRecordName,
const std::vector<uint8_t>& aData,
std::function<void()>&& aOnSuccess,
std::function<void()>&& aOnFailure);
// Reads data from a file and fires the appropriate callback when complete.
void ReadData(cdm::Host_9* aHost, std::string& aRecordName,
void ReadData(cdm::Host_10* aHost, std::string& aRecordName,
std::function<void(const uint8_t*, uint32_t)>&& aOnSuccess,
std::function<void()>&& aOnFailure);

View File

@ -27,7 +27,7 @@
using namespace wmf;
using namespace cdm;
VideoDecoder::VideoDecoder(Host_9* aHost) : mHost(aHost), mHasShutdown(false) {
VideoDecoder::VideoDecoder(Host_10* aHost) : mHost(aHost), mHasShutdown(false) {
CK_LOGD("VideoDecoder created");
// We drop the ref in DecodingComplete().
@ -42,7 +42,7 @@ VideoDecoder::VideoDecoder(Host_9* aHost) : mHost(aHost), mHasShutdown(false) {
VideoDecoder::~VideoDecoder() { CK_LOGD("VideoDecoder destroyed"); }
Status VideoDecoder::InitDecode(const VideoDecoderConfig_1& aConfig) {
Status VideoDecoder::InitDecode(const VideoDecoderConfig_2& aConfig) {
CK_LOGD("VideoDecoder::InitDecode");
if (!mDecoder) {
@ -54,7 +54,7 @@ Status VideoDecoder::InitDecode(const VideoDecoderConfig_1& aConfig) {
return Status::kSuccess;
}
Status VideoDecoder::Decode(const InputBuffer_1& aInputBuffer,
Status VideoDecoder::Decode(const InputBuffer_2& aInputBuffer,
VideoFrame* aVideoFrame) {
CK_LOGD("VideoDecoder::Decode");
// If the input buffer we have been passed has a null buffer, it means we

View File

@ -29,11 +29,11 @@
class VideoDecoder : public RefCounted {
public:
explicit VideoDecoder(cdm::Host_9* aHost);
explicit VideoDecoder(cdm::Host_10* aHost);
cdm::Status InitDecode(const cdm::VideoDecoderConfig_1& aConfig);
cdm::Status InitDecode(const cdm::VideoDecoderConfig_2& aConfig);
cdm::Status Decode(const cdm::InputBuffer_1& aEncryptedBuffer,
cdm::Status Decode(const cdm::InputBuffer_2& aEncryptedBuffer,
cdm::VideoFrame* aVideoFrame);
void Reset();
@ -60,7 +60,7 @@ class VideoDecoder : public RefCounted {
int32_t aFrameHeight,
cdm::VideoFrame* aVideoFrame);
cdm::Host_9* mHost;
cdm::Host_10* mHost;
wmf::AutoPtr<wmf::WMFH264Decoder> mDecoder;
std::queue<wmf::CComPtr<IMFSample>> mOutputQueue;

View File

@ -50,7 +50,7 @@ void* CreateCdmInstance(int cdm_interface_version, const char* key_system,
GetCdmHostFunc get_cdm_host_func, void* user_data) {
CK_LOGE("ClearKey CreateCDMInstance");
if (cdm_interface_version != cdm::ContentDecryptionModule_9::kVersion) {
if (cdm_interface_version != cdm::ContentDecryptionModule_10::kVersion) {
CK_LOGE(
"ClearKey CreateCDMInstance failed due to requesting unsupported "
"version %d.",
@ -71,7 +71,7 @@ void* CreateCdmInstance(int cdm_interface_version, const char* key_system,
}
#endif
cdm::Host_9* host = static_cast<cdm::Host_9*>(
cdm::Host_10* host = static_cast<cdm::Host_10*>(
get_cdm_host_func(cdm_interface_version, user_data));
ClearKeyCDM* clearKey = new ClearKeyCDM(host);

View File

@ -3,8 +3,8 @@
"description": "ClearKey Gecko Media Plugin",
"version": "1",
"x-cdm-module-versions": "4",
"x-cdm-interface-versions": "9",
"x-cdm-host-versions": "9",
"x-cdm-interface-versions": "10",
"x-cdm-host-versions": "10",
#ifdef ENABLE_WMF
"x-cdm-codecs": "avc1"
#else