gecko-dev/dom/media/gmp/ChromiumCDMAdapter.cpp
Chris Pearce a6d74267e5 Bug 1315850 - Add ChromiumAdapter which we can use instead of WidevineAdapter. r=gerald
We currently use an adapter object to adapt plugins that don't conform to the
GMP interface to the GMP interface.

We use the WidevineAdapter to talk to the CDM from the two GMP IPDL protocols.
We will be using a single protocol to talk to the Chromium CDM, so we need a
new adapter which handles that.

MozReview-Commit-ID: F7hnZ9oo9mJ

--HG--
rename : dom/media/gmp/widevine-adapter/WidevineAdapter.cpp => dom/media/gmp/ChromiumCDMAdapter.cpp
rename : dom/media/gmp/widevine-adapter/WidevineAdapter.h => dom/media/gmp/ChromiumCDMAdapter.h
extra : rebase_source : 7c08edea3c11d41eb3ecfa9c7a8ef65cf3b8ddb0
2017-03-13 16:59:34 +13:00

134 lines
3.6 KiB
C++

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#include "ChromiumCDMAdapter.h"
#include "content_decryption_module.h"
#include "VideoUtils.h"
#include "gmp-api/gmp-entrypoints.h"
#include "gmp-api/gmp-decryption.h"
#include "gmp-api/gmp-video-codec.h"
#include "gmp-api/gmp-platform.h"
#include "WidevineUtils.h"
#include "GMPLog.h"
// Declared in WidevineAdapter.cpp.
extern const GMPPlatformAPI* sPlatform;
namespace mozilla {
void
ChromiumCDMAdapter::SetAdaptee(PRLibrary* aLib)
{
mLib = aLib;
}
void*
ChromiumCdmHost(int aHostInterfaceVersion, void* aUserData)
{
CDM_LOG("ChromiumCdmHostFunc(%d, %p)", aHostInterfaceVersion, aUserData);
if (aHostInterfaceVersion != cdm::Host_8::kVersion) {
return nullptr;
}
return static_cast<cdm::Host_8*>(aUserData);
}
#define STRINGIFY(s) _STRINGIFY(s)
#define _STRINGIFY(s) #s
GMPErr
ChromiumCDMAdapter::GMPInit(const GMPPlatformAPI* aPlatformAPI)
{
CDM_LOG("ChromiumCDMAdapter::GMPInit");
sPlatform = aPlatformAPI;
if (!mLib) {
return GMPGenericErr;
}
auto init = reinterpret_cast<decltype(::INITIALIZE_CDM_MODULE)*>(
PR_FindFunctionSymbol(mLib, STRINGIFY(INITIALIZE_CDM_MODULE)));
if (!init) {
return GMPGenericErr;
}
CDM_LOG(STRINGIFY(INITIALIZE_CDM_MODULE)"()");
init();
return GMPNoErr;
}
GMPErr
ChromiumCDMAdapter::GMPGetAPI(const char* aAPIName,
void* aHostAPI,
void** aPluginAPI,
uint32_t aDecryptorId)
{
CDM_LOG("ChromiumCDMAdapter::GMPGetAPI(%s, 0x%p, 0x%p, %u) this=0x%p",
aAPIName,
aHostAPI,
aPluginAPI,
aDecryptorId,
this);
if (!strcmp(aAPIName, CHROMIUM_CDM_API)) {
auto create = reinterpret_cast<decltype(::CreateCdmInstance)*>(
PR_FindFunctionSymbol(mLib, "CreateCdmInstance"));
if (!create) {
CDM_LOG("ChromiumCDMAdapter::GMPGetAPI(%s, 0x%p, 0x%p, %u) this=0x%p "
"FAILED to find CreateCdmInstance",
aAPIName,
aHostAPI,
aPluginAPI,
aDecryptorId,
this);
return GMPGenericErr;
}
auto cdm = reinterpret_cast<cdm::ContentDecryptionModule*>(
create(cdm::ContentDecryptionModule::kVersion,
kEMEKeySystemWidevine.get(),
kEMEKeySystemWidevine.Length(),
&ChromiumCdmHost,
aHostAPI));
if (!cdm) {
CDM_LOG("ChromiumCDMAdapter::GMPGetAPI(%s, 0x%p, 0x%p, %u) this=0x%p "
"FAILED to create cdm",
aAPIName,
aHostAPI,
aPluginAPI,
aDecryptorId,
this);
return GMPGenericErr;
}
CDM_LOG("cdm: 0x%p", cdm);
*aPluginAPI = cdm;
}
return *aPluginAPI ? GMPNoErr : GMPNotImplementedErr;
}
void
ChromiumCDMAdapter::GMPShutdown()
{
CDM_LOG("ChromiumCDMAdapter::GMPShutdown()");
decltype(::DeinitializeCdmModule)* deinit;
deinit = (decltype(deinit))(PR_FindFunctionSymbol(mLib, "DeinitializeCdmModule"));
if (deinit) {
CDM_LOG("DeinitializeCdmModule()");
deinit();
}
}
/* static */
bool
ChromiumCDMAdapter::Supports(int32_t aModuleVersion,
int32_t aInterfaceVersion,
int32_t aHostVersion)
{
return aModuleVersion == CDM_MODULE_VERSION &&
aInterfaceVersion == cdm::ContentDecryptionModule::kVersion &&
aHostVersion == cdm::Host_8::kVersion;
}
} // namespace mozilla