2015-08-31 13:28:07 +02:00
|
|
|
// Copyright 2013 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 "libcef/renderer/media/cef_key_systems.h"
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "base/logging.h"
|
|
|
|
#include "base/strings/string16.h"
|
|
|
|
#include "base/strings/string_split.h"
|
|
|
|
#include "base/strings/utf_string_conversions.h"
|
2016-05-25 01:35:43 +02:00
|
|
|
#include "components/cdm/renderer/widevine_key_system_properties.h"
|
2015-08-31 13:28:07 +02:00
|
|
|
#include "content/public/renderer/render_thread.h"
|
|
|
|
#include "libcef/common/cef_messages.h"
|
|
|
|
#include "media/base/eme_constants.h"
|
2016-05-25 01:35:43 +02:00
|
|
|
#include "media/base/key_system_properties.h"
|
2017-03-03 23:37:23 +01:00
|
|
|
#include "media/media_features.h"
|
2016-11-23 21:54:29 +01:00
|
|
|
#include "ppapi/features/features.h"
|
2016-05-25 01:35:43 +02:00
|
|
|
|
2015-08-31 13:28:07 +02:00
|
|
|
#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
|
|
|
|
|
2016-05-25 01:35:43 +02:00
|
|
|
using media::KeySystemProperties;
|
2015-08-31 13:28:07 +02:00
|
|
|
using media::SupportedCodecs;
|
|
|
|
|
2016-07-14 03:35:07 +02:00
|
|
|
namespace {
|
|
|
|
|
2016-11-23 21:54:29 +01:00
|
|
|
#if BUILDFLAG(ENABLE_PEPPER_CDMS)
|
2016-07-14 03:35:07 +02:00
|
|
|
bool IsPepperCdmAvailable(
|
2015-08-31 13:28:07 +02:00
|
|
|
const std::string& pepper_type,
|
|
|
|
std::vector<base::string16>* additional_param_names,
|
|
|
|
std::vector<base::string16>* additional_param_values) {
|
|
|
|
bool is_available = false;
|
|
|
|
content::RenderThread::Get()->Send(
|
|
|
|
new CefViewHostMsg_IsInternalPluginAvailableForMimeType(
|
|
|
|
pepper_type,
|
|
|
|
&is_available,
|
|
|
|
additional_param_names,
|
|
|
|
additional_param_values));
|
|
|
|
|
|
|
|
return is_available;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(WIDEVINE_CDM_AVAILABLE)
|
|
|
|
// This function finds "codecs" and parses the value into the vector |codecs|.
|
|
|
|
// Converts the codec strings to UTF-8 since we only expect ASCII strings and
|
|
|
|
// this simplifies the rest of the code in this file.
|
|
|
|
void GetSupportedCodecsForPepperCdm(
|
|
|
|
const std::vector<base::string16>& additional_param_names,
|
|
|
|
const std::vector<base::string16>& additional_param_values,
|
|
|
|
std::vector<std::string>* codecs) {
|
|
|
|
DCHECK(codecs->empty());
|
|
|
|
DCHECK_EQ(additional_param_names.size(), additional_param_values.size());
|
|
|
|
for (size_t i = 0; i < additional_param_names.size(); ++i) {
|
|
|
|
if (additional_param_names[i] ==
|
|
|
|
base::ASCIIToUTF16(kCdmSupportedCodecsParamName)) {
|
|
|
|
const base::string16& codecs_string16 = additional_param_values[i];
|
|
|
|
std::string codecs_string;
|
|
|
|
if (!base::UTF16ToUTF8(codecs_string16.c_str(),
|
|
|
|
codecs_string16.length(),
|
|
|
|
&codecs_string)) {
|
|
|
|
DLOG(WARNING) << "Non-UTF-8 codecs string.";
|
|
|
|
// Continue using the best effort conversion.
|
|
|
|
}
|
|
|
|
*codecs = base::SplitString(
|
|
|
|
codecs_string, std::string(1, kCdmSupportedCodecsValueDelimiter),
|
|
|
|
base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-14 03:35:07 +02:00
|
|
|
void AddPepperBasedWidevine(
|
2016-05-25 01:35:43 +02:00
|
|
|
std::vector<std::unique_ptr<KeySystemProperties>>* concrete_key_systems) {
|
2015-08-31 13:28:07 +02:00
|
|
|
#if defined(WIDEVINE_CDM_MIN_GLIBC_VERSION)
|
2016-10-17 20:14:44 +02:00
|
|
|
base::Version glibc_version(gnu_get_libc_version());
|
2015-08-31 13:28:07 +02:00
|
|
|
DCHECK(glibc_version.IsValid());
|
2016-02-05 01:49:19 +01:00
|
|
|
if (glibc_version < base::Version(WIDEVINE_CDM_MIN_GLIBC_VERSION))
|
2015-08-31 13:28:07 +02:00
|
|
|
return;
|
|
|
|
#endif // defined(WIDEVINE_CDM_MIN_GLIBC_VERSION)
|
|
|
|
|
|
|
|
std::vector<base::string16> additional_param_names;
|
|
|
|
std::vector<base::string16> additional_param_values;
|
|
|
|
if (!IsPepperCdmAvailable(kWidevineCdmPluginMimeType,
|
|
|
|
&additional_param_names,
|
|
|
|
&additional_param_values)) {
|
|
|
|
DVLOG(1) << "Widevine CDM is not currently available.";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string> codecs;
|
|
|
|
GetSupportedCodecsForPepperCdm(additional_param_names,
|
|
|
|
additional_param_values,
|
|
|
|
&codecs);
|
|
|
|
|
|
|
|
SupportedCodecs supported_codecs = media::EME_CODEC_NONE;
|
|
|
|
|
|
|
|
// Audio codecs are always supported.
|
|
|
|
// TODO(sandersd): Distinguish these from those that are directly supported,
|
|
|
|
// as those may offer a higher level of protection.
|
|
|
|
supported_codecs |= media::EME_CODEC_WEBM_OPUS;
|
|
|
|
supported_codecs |= media::EME_CODEC_WEBM_VORBIS;
|
2017-03-03 23:37:23 +01:00
|
|
|
#if BUILDFLAG(USE_PROPRIETARY_CODECS)
|
2015-08-31 13:28:07 +02:00
|
|
|
supported_codecs |= media::EME_CODEC_MP4_AAC;
|
2017-03-03 23:37:23 +01:00
|
|
|
#endif // BUILDFLAG(USE_PROPRIETARY_CODECS)
|
2015-08-31 13:28:07 +02:00
|
|
|
|
|
|
|
for (size_t i = 0; i < codecs.size(); ++i) {
|
|
|
|
if (codecs[i] == kCdmSupportedCodecVp8)
|
|
|
|
supported_codecs |= media::EME_CODEC_WEBM_VP8;
|
2017-04-20 21:28:17 +02:00
|
|
|
if (codecs[i] == kCdmSupportedCodecVp9) {
|
2015-08-31 13:28:07 +02:00
|
|
|
supported_codecs |= media::EME_CODEC_WEBM_VP9;
|
2017-04-20 21:28:17 +02:00
|
|
|
supported_codecs |= media::EME_CODEC_COMMON_VP9;
|
|
|
|
}
|
2017-03-03 23:37:23 +01:00
|
|
|
#if BUILDFLAG(USE_PROPRIETARY_CODECS)
|
2015-08-31 13:28:07 +02:00
|
|
|
if (codecs[i] == kCdmSupportedCodecAvc1)
|
|
|
|
supported_codecs |= media::EME_CODEC_MP4_AVC1;
|
2017-03-03 23:37:23 +01:00
|
|
|
#endif // BUILDFLAG(USE_PROPRIETARY_CODECS)
|
2015-08-31 13:28:07 +02:00
|
|
|
}
|
|
|
|
|
2016-06-21 00:59:23 +02:00
|
|
|
using Robustness = cdm::WidevineKeySystemProperties::Robustness;
|
2016-05-25 01:35:43 +02:00
|
|
|
concrete_key_systems->emplace_back(new cdm::WidevineKeySystemProperties(
|
2016-03-16 03:55:59 +01:00
|
|
|
supported_codecs,
|
2016-06-21 00:59:23 +02:00
|
|
|
Robustness::SW_SECURE_CRYPTO, // Maximum audio robustness.
|
|
|
|
Robustness::SW_SECURE_DECODE, // Maximum video robustness.
|
2015-08-31 13:28:07 +02:00
|
|
|
media::EmeSessionTypeSupport::NOT_SUPPORTED, // persistent-license.
|
|
|
|
media::EmeSessionTypeSupport::
|
2016-05-25 01:35:43 +02:00
|
|
|
NOT_SUPPORTED, // persistent-release-message.
|
|
|
|
media::EmeFeatureSupport::REQUESTABLE, // Persistent state.
|
|
|
|
media::EmeFeatureSupport::NOT_SUPPORTED)); // Distinctive identifier.
|
2015-08-31 13:28:07 +02:00
|
|
|
}
|
|
|
|
#endif // defined(WIDEVINE_CDM_AVAILABLE)
|
2016-11-23 21:54:29 +01:00
|
|
|
#endif // BUILDFLAG(ENABLE_PEPPER_CDMS)
|
2015-08-31 13:28:07 +02:00
|
|
|
|
2016-07-14 03:35:07 +02:00
|
|
|
} // namespace
|
|
|
|
|
2016-05-25 01:35:43 +02:00
|
|
|
void AddCefKeySystems(
|
|
|
|
std::vector<std::unique_ptr<KeySystemProperties>>* key_systems_properties) {
|
2016-11-23 21:54:29 +01:00
|
|
|
#if BUILDFLAG(ENABLE_PEPPER_CDMS)
|
2015-08-31 13:28:07 +02:00
|
|
|
#if defined(WIDEVINE_CDM_AVAILABLE)
|
2016-05-25 01:35:43 +02:00
|
|
|
AddPepperBasedWidevine(key_systems_properties);
|
2015-08-31 13:28:07 +02:00
|
|
|
#endif // defined(WIDEVINE_CDM_AVAILABLE)
|
2016-11-23 21:54:29 +01:00
|
|
|
#endif // BUILDFLAG(ENABLE_PEPPER_CDMS)
|
2015-08-31 13:28:07 +02:00
|
|
|
}
|