build: [gn] widevine cdm support behind flag (3-0-x) (#14497)

This commit is contained in:
Shelley Vohr 2018-09-07 22:43:39 -07:00 committed by GitHub
parent 893f866c05
commit 8fd31a3e07
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 405 additions and 215 deletions

View file

@ -13,116 +13,66 @@
#include "base/strings/string16.h"
#include "base/strings/string_split.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#if 0
#include "chrome/renderer/chrome_render_thread_observer.h"
#endif
#include "components/cdm/renderer/external_clear_key_key_system_properties.h"
#include "components/cdm/renderer/widevine_key_system_properties.h"
#include "content/public/renderer/render_thread.h"
#include "media/base/eme_constants.h"
#include "media/base/key_system_properties.h"
#include "media/media_features.h"
#include "third_party/widevine/cdm/widevine_cdm_common.h"
#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
#include "base/feature_list.h"
#include "content/public/renderer/key_system_support.h"
#include "media/base/media_switches.h"
#include "media/base/video_codecs.h"
#endif
#include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR.
// The following must be after widevine_cdm_version.h.
#if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_MIN_GLIBC_VERSION)
#include <gnu/libc-version.h>
#include "base/version.h"
#endif
using media::EmeFeatureSupport;
using media::EmeSessionTypeSupport;
using media::KeySystemProperties;
using media::SupportedCodecs;
#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
static const char kExternalClearKeyPepperType[] =
"application/x-ppapi-clearkey-cdm";
// KeySystemProperties implementation for external Clear Key systems.
class ExternalClearKeyProperties : public KeySystemProperties {
public:
explicit ExternalClearKeyProperties(const std::string& key_system_name)
: key_system_name_(key_system_name) {}
std::string GetKeySystemName() const override { return key_system_name_; }
bool IsSupportedInitDataType(
media::EmeInitDataType init_data_type) const override {
switch (init_data_type) {
case media::EmeInitDataType::WEBM:
case media::EmeInitDataType::KEYIDS:
return true;
case media::EmeInitDataType::CENC:
#if BUILDFLAG(USE_PROPRIETARY_CODECS)
return true;
#else
return false;
#endif // BUILDFLAG(USE_PROPRIETARY_CODECS)
case media::EmeInitDataType::UNKNOWN:
return false;
}
NOTREACHED();
return false;
}
SupportedCodecs GetSupportedCodecs() const override {
#if BUILDFLAG(USE_PROPRIETARY_CODECS)
return media::EME_CODEC_MP4_ALL | media::EME_CODEC_WEBM_ALL;
#else
return media::EME_CODEC_WEBM_ALL;
#endif
}
media::EmeConfigRule GetRobustnessConfigRule(
media::EmeMediaType media_type,
const std::string& requested_robustness) const override {
return requested_robustness.empty() ? media::EmeConfigRule::SUPPORTED
: media::EmeConfigRule::NOT_SUPPORTED;
}
// Persistent license sessions are faked.
media::EmeSessionTypeSupport GetPersistentLicenseSessionSupport()
const override {
return media::EmeSessionTypeSupport::SUPPORTED;
}
media::EmeSessionTypeSupport GetPersistentReleaseMessageSessionSupport()
const override {
return media::EmeSessionTypeSupport::NOT_SUPPORTED;
}
media::EmeFeatureSupport GetPersistentStateSupport() const override {
return media::EmeFeatureSupport::REQUESTABLE;
}
media::EmeFeatureSupport GetDistinctiveIdentifierSupport() const override {
return media::EmeFeatureSupport::NOT_SUPPORTED;
}
std::string GetPepperType() const override {
return kExternalClearKeyPepperType;
}
private:
const std::string key_system_name_;
};
// External Clear Key (used for testing).
static void AddExternalClearKey(
std::vector<std::unique_ptr<KeySystemProperties>>* concrete_key_systems) {
// TODO(xhwang): Move these into an array so we can use a for loop to add
// supported key systems below.
static const char kExternalClearKeyKeySystem[] =
"org.chromium.externalclearkey";
static const char kExternalClearKeyDecryptOnlyKeySystem[] =
"org.chromium.externalclearkey.decryptonly";
static const char kExternalClearKeyMessageTypeTestKeySystem[] =
"org.chromium.externalclearkey.messagetypetest";
static const char kExternalClearKeyFileIOTestKeySystem[] =
"org.chromium.externalclearkey.fileiotest";
static const char kExternalClearKeyOutputProtectionTestKeySystem[] =
"org.chromium.externalclearkey.outputprotectiontest";
static const char kExternalClearKeyPlatformVerificationTestKeySystem[] =
"org.chromium.externalclearkey.platformverificationtest";
static const char kExternalClearKeyInitializeFailKeySystem[] =
"org.chromium.externalclearkey.initializefail";
static const char kExternalClearKeyCrashKeySystem[] =
"org.chromium.externalclearkey.crash";
static const char kExternalClearKeyVerifyCdmHostTestKeySystem[] =
"org.chromium.externalclearkey.verifycdmhosttest";
static const char kExternalClearKeyStorageIdTestKeySystem[] =
"org.chromium.externalclearkey.storageidtest";
static const char kExternalClearKeyDifferentGuidTestKeySystem[] =
"org.chromium.externalclearkey.differentguid";
static const char kExternalClearKeyCdmProxyTestKeySystem[] =
"org.chromium.externalclearkey.cdmproxytest";
std::vector<media::VideoCodec> supported_video_codecs;
bool supports_persistent_license;
@ -133,32 +83,107 @@ static void AddExternalClearKey(
}
concrete_key_systems->emplace_back(
new ExternalClearKeyProperties(kExternalClearKeyKeySystem));
new cdm::ExternalClearKeyProperties(kExternalClearKeyKeySystem));
// Add support of decrypt-only mode in ClearKeyCdm.
concrete_key_systems->emplace_back(
new ExternalClearKeyProperties(kExternalClearKeyDecryptOnlyKeySystem));
concrete_key_systems->emplace_back(new cdm::ExternalClearKeyProperties(
kExternalClearKeyDecryptOnlyKeySystem));
// A key system that triggers FileIO test in ClearKeyCdm.
concrete_key_systems->emplace_back(
new ExternalClearKeyProperties(kExternalClearKeyFileIOTestKeySystem));
// A key system that triggers various types of messages in ClearKeyCdm.
concrete_key_systems->emplace_back(new cdm::ExternalClearKeyProperties(
kExternalClearKeyMessageTypeTestKeySystem));
// A key system that triggers the FileIO test in ClearKeyCdm.
concrete_key_systems->emplace_back(new cdm::ExternalClearKeyProperties(
kExternalClearKeyFileIOTestKeySystem));
// A key system that triggers the output protection test in ClearKeyCdm.
concrete_key_systems->emplace_back(new cdm::ExternalClearKeyProperties(
kExternalClearKeyOutputProtectionTestKeySystem));
// A key system that triggers the platform verification test in ClearKeyCdm.
concrete_key_systems->emplace_back(new cdm::ExternalClearKeyProperties(
kExternalClearKeyPlatformVerificationTestKeySystem));
// A key system that Chrome thinks is supported by ClearKeyCdm, but actually
// will be refused by ClearKeyCdm. This is to test the CDM initialization
// failure case.
concrete_key_systems->emplace_back(
new ExternalClearKeyProperties(kExternalClearKeyInitializeFailKeySystem));
concrete_key_systems->emplace_back(new cdm::ExternalClearKeyProperties(
kExternalClearKeyInitializeFailKeySystem));
// A key system that triggers a crash in ClearKeyCdm.
concrete_key_systems->emplace_back(
new ExternalClearKeyProperties(kExternalClearKeyCrashKeySystem));
new cdm::ExternalClearKeyProperties(kExternalClearKeyCrashKeySystem));
// A key system that triggers the verify host files test in ClearKeyCdm.
concrete_key_systems->emplace_back(new cdm::ExternalClearKeyProperties(
kExternalClearKeyVerifyCdmHostTestKeySystem));
// A key system that fetches the Storage ID in ClearKeyCdm.
concrete_key_systems->emplace_back(new cdm::ExternalClearKeyProperties(
kExternalClearKeyStorageIdTestKeySystem));
// A key system that is registered with a different CDM GUID.
concrete_key_systems->emplace_back(new cdm::ExternalClearKeyProperties(
kExternalClearKeyDifferentGuidTestKeySystem));
// A key system that triggers CDM Proxy test in ClearKeyCdm.
concrete_key_systems->emplace_back(new cdm::ExternalClearKeyProperties(
kExternalClearKeyCdmProxyTestKeySystem));
}
#if defined(WIDEVINE_CDM_AVAILABLE)
// Returns persistent-license session support.
EmeSessionTypeSupport GetPersistentLicenseSupport(bool supported_by_the_cdm) {
#if 0
// Do not support persistent-license if the process cannot persist data.
// TODO(crbug.com/457487): Have a better plan on this. See bug for details.
if (ChromeRenderThreadObserver::is_incognito_process()) {
DVLOG(2) << __func__ << ": Not supported in incognito process.";
return EmeSessionTypeSupport::NOT_SUPPORTED;
}
#endif
if (!supported_by_the_cdm) {
DVLOG(2) << __func__ << ": Not supported by the CDM.";
return EmeSessionTypeSupport::NOT_SUPPORTED;
}
// On ChromeOS, platform verification is similar to CDM host verification.
#if BUILDFLAG(ENABLE_CDM_HOST_VERIFICATION) || defined(OS_CHROMEOS)
bool cdm_host_verification_potentially_supported = true;
#else
bool cdm_host_verification_potentially_supported = false;
#endif
// If we are sure CDM host verification is NOT supported, we should not
// support persistent-license.
if (!cdm_host_verification_potentially_supported) {
DVLOG(2) << __func__ << ": Not supported without CDM host verification.";
return EmeSessionTypeSupport::NOT_SUPPORTED;
}
#if defined(OS_CHROMEOS)
// On ChromeOS, platform verification (similar to CDM host verification)
// requires identifier to be allowed.
// TODO(jrummell): Currently the ChromeOS CDM does not require storage ID
// to support persistent license. Update this logic when the new CDM requires
// storage ID.
return EmeSessionTypeSupport::SUPPORTED_WITH_IDENTIFIER;
#elif BUILDFLAG(ENABLE_CDM_STORAGE_ID)
// On other platforms, we require storage ID to support persistent license.
return EmeSessionTypeSupport::SUPPORTED;
#else
// Storage ID not implemented, so no support for persistent license.
DVLOG(2) << __func__ << ": Not supported without CDM storage ID.";
return EmeSessionTypeSupport::NOT_SUPPORTED;
#endif // defined(OS_CHROMEOS)
}
static void AddPepperBasedWidevine(
std::vector<std::unique_ptr<KeySystemProperties>>* concrete_key_systems) {
#if defined(WIDEVINE_CDM_MIN_GLIBC_VERSION)
Version glibc_version(gnu_get_libc_version());
base::Version glibc_version(gnu_get_libc_version());
DCHECK(glibc_version.IsValid());
if (glibc_version < base::Version(WIDEVINE_CDM_MIN_GLIBC_VERSION))
return;
@ -205,27 +230,28 @@ static void AddPepperBasedWidevine(
}
}
EmeSessionTypeSupport persistent_license_support =
GetPersistentLicenseSupport(supports_persistent_license);
using Robustness = cdm::WidevineKeySystemProperties::Robustness;
concrete_key_systems->emplace_back(new cdm::WidevineKeySystemProperties(
supported_codecs,
#if defined(OS_CHROMEOS)
media::EmeRobustness::HW_SECURE_ALL, // Maximum audio robustness.
media::EmeRobustness::HW_SECURE_ALL, // Maximim video robustness.
media::EmeSessionTypeSupport::
SUPPORTED_WITH_IDENTIFIER, // Persistent-license.
media::EmeSessionTypeSupport::
NOT_SUPPORTED, // Persistent-release-message.
media::EmeFeatureSupport::REQUESTABLE, // Persistent state.
media::EmeFeatureSupport::REQUESTABLE)); // Distinctive identifier.
#else // (Desktop)
Robustness::SW_SECURE_CRYPTO, // Maximum audio robustness.
Robustness::SW_SECURE_DECODE, // Maximum video robustness.
media::EmeSessionTypeSupport::NOT_SUPPORTED, // persistent-license.
media::EmeSessionTypeSupport::
NOT_SUPPORTED, // persistent-release-message.
media::EmeFeatureSupport::REQUESTABLE, // Persistent state.
media::EmeFeatureSupport::NOT_SUPPORTED)); // Distinctive identifier.
#endif // defined(OS_CHROMEOS)
Robustness::HW_SECURE_ALL, // Maximum audio robustness.
Robustness::HW_SECURE_ALL, // Maximum video robustness.
persistent_license_support, // Persistent-license.
EmeSessionTypeSupport::NOT_SUPPORTED, // Persistent-release-message.
EmeFeatureSupport::REQUESTABLE, // Persistent state.
EmeFeatureSupport::REQUESTABLE)); // Distinctive identifier.
#else // Desktop
Robustness::SW_SECURE_CRYPTO, // Maximum audio robustness.
Robustness::SW_SECURE_DECODE, // Maximum video robustness.
persistent_license_support, // persistent-license.
EmeSessionTypeSupport::NOT_SUPPORTED, // persistent-release-message.
EmeFeatureSupport::REQUESTABLE, // Persistent state.
EmeFeatureSupport::NOT_SUPPORTED)); // Distinctive identifier.
#endif // defined(OS_CHROMEOS)
}
#endif // defined(WIDEVINE_CDM_AVAILABLE)
#endif // BUILDFLAG(ENABLE_LIBRARY_CDMS)
@ -233,10 +259,12 @@ static void AddPepperBasedWidevine(
void AddChromeKeySystems(
std::vector<std::unique_ptr<KeySystemProperties>>* key_systems_properties) {
#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
AddExternalClearKey(key_systems_properties);
if (base::FeatureList::IsEnabled(media::kExternalClearKeyForTesting))
AddExternalClearKey(key_systems_properties);
#if defined(WIDEVINE_CDM_AVAILABLE)
AddPepperBasedWidevine(key_systems_properties);
#endif // defined(WIDEVINE_CDM_AVAILABLE)
#endif // BUILDFLAG(ENABLE_LIBRARY_CDMS)
}

View file

@ -0,0 +1,78 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/renderer/media/chrome_key_systems_provider.h"
#include "base/time/default_tick_clock.h"
#include "chrome/renderer/media/chrome_key_systems.h"
#include "third_party/widevine/cdm/widevine_cdm_common.h"
ChromeKeySystemsProvider::ChromeKeySystemsProvider()
: has_updated_(false),
is_update_needed_(true),
tick_clock_(base::DefaultTickClock::GetInstance()) {}
ChromeKeySystemsProvider::~ChromeKeySystemsProvider() {}
void ChromeKeySystemsProvider::AddSupportedKeySystems(
std::vector<std::unique_ptr<media::KeySystemProperties>>* key_systems) {
DCHECK(key_systems);
DCHECK(thread_checker_.CalledOnValidThread());
if (!test_provider_.is_null()) {
test_provider_.Run(key_systems);
} else {
AddChromeKeySystems(key_systems);
}
has_updated_ = true;
last_update_time_ticks_ = tick_clock_->NowTicks();
// Check whether all potentially supported key systems are supported. If so,
// no need to update again.
#if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT)
for (const auto& properties : *key_systems) {
if (properties->GetKeySystemName() == kWidevineKeySystem) {
is_update_needed_ = false;
}
}
#else
is_update_needed_ = false;
#endif
}
bool ChromeKeySystemsProvider::IsKeySystemsUpdateNeeded() {
DCHECK(thread_checker_.CalledOnValidThread());
// Always needs update if we have never updated, regardless the
// |last_update_time_ticks_|'s initial value.
if (!has_updated_) {
DCHECK(is_update_needed_);
return true;
}
if (!is_update_needed_)
return false;
// The update could be expensive. For example, it could involve a sync IPC to
// the browser process. Use a minimum update interval to avoid unnecessarily
// frequent update.
static const int kMinUpdateIntervalInMilliseconds = 1000;
if ((tick_clock_->NowTicks() - last_update_time_ticks_).InMilliseconds() <
kMinUpdateIntervalInMilliseconds) {
return false;
}
return true;
}
void ChromeKeySystemsProvider::SetTickClockForTesting(
base::TickClock* tick_clock) {
tick_clock_ = tick_clock;
}
void ChromeKeySystemsProvider::SetProviderDelegateForTesting(
const KeySystemsProviderDelegate& test_provider) {
test_provider_ = test_provider;
}

View file

@ -0,0 +1,64 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_RENDERER_MEDIA_CHROME_KEY_SYSTEMS_PROVIDER_H_
#define CHROME_RENDERER_MEDIA_CHROME_KEY_SYSTEMS_PROVIDER_H_
#include <memory>
#include <vector>
#include "base/callback.h"
#include "base/threading/thread_checker.h"
#include "base/time/tick_clock.h"
#include "base/time/time.h"
#include "media/base/key_system_properties.h"
typedef std::vector<std::unique_ptr<media::KeySystemProperties>>
KeySystemPropertiesVector;
typedef base::Callback<void(KeySystemPropertiesVector*)>
KeySystemsProviderDelegate;
class ChromeKeySystemsProvider {
public:
ChromeKeySystemsProvider();
~ChromeKeySystemsProvider();
// Adds properties for supported key systems.
void AddSupportedKeySystems(KeySystemPropertiesVector* key_systems);
// Returns whether client key systems properties should be updated.
// TODO(chcunningham): Refactor this to a proper change "observer" API that is
// less fragile (don't assume AddSupportedKeySystems has just one caller).
bool IsKeySystemsUpdateNeeded();
void SetTickClockForTesting(base::TickClock* tick_clock);
void SetProviderDelegateForTesting(
const KeySystemsProviderDelegate& test_provider);
private:
// Whether AddSupportedKeySystems() has ever been called.
bool has_updated_;
// Whether a future update is needed. For example, when some potentially
// supported key systems are NOT supported yet. This could happen when the
// required component for a key system is not yet available.
bool is_update_needed_;
// Throttle how often we signal an update is needed to avoid unnecessary high
// frequency of expensive IPC calls.
base::TimeTicks last_update_time_ticks_;
base::TickClock* tick_clock_;
// Ensure all methods are called from the same (Main) thread.
base::ThreadChecker thread_checker_;
// For unit tests to inject their own key systems. Will bypass adding default
// Chrome key systems when set.
KeySystemsProviderDelegate test_provider_;
DISALLOW_COPY_AND_ASSIGN(ChromeKeySystemsProvider);
};
#endif // CHROME_RENDERER_MEDIA_CHROME_KEY_SYSTEMS_PROVIDER_H_