1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/cdm/renderer/android_key_system_info.h"
#include <utility>
#include "base/check_op.h"
#include "base/logging.h"
#include "base/notreached.h"
#include "build/build_config.h"
#include "third_party/widevine/cdm/widevine_cdm_common.h"
#if !BUILDFLAG(IS_ANDROID)
#error This file should only be built when Android is enabled.
#endif
using media::EmeConfig;
using media::EmeConfigRuleState;
using media::EmeFeatureSupport;
using media::EmeInitDataType;
using media::EmeMediaType;
using media::EncryptionScheme;
using media::SupportedCodecs;
namespace cdm {
AndroidKeySystemInfo::AndroidKeySystemInfo(
const std::string& name,
SupportedCodecs sw_secure_codecs,
base::flat_set<EncryptionScheme> sw_secure_encryption_schemes,
SupportedCodecs hw_secure_codecs,
base::flat_set<EncryptionScheme> hw_secure_encryption_schemes)
: name_(name),
sw_secure_codecs_(sw_secure_codecs),
sw_secure_encryption_schemes_(std::move(sw_secure_encryption_schemes)),
hw_secure_codecs_(hw_secure_codecs),
hw_secure_encryption_schemes_(std::move(hw_secure_encryption_schemes)) {
DCHECK_NE(name, kWidevineKeySystem)
<< "Use WidevineKeySystemInfo for Widevine";
}
AndroidKeySystemInfo::~AndroidKeySystemInfo() = default;
std::string AndroidKeySystemInfo::GetBaseKeySystemName() const {
return name_;
}
bool AndroidKeySystemInfo::IsSupportedInitDataType(
EmeInitDataType init_data_type) const {
// Here we assume that support for a container implies support for the
// associated initialization data type. KeySystems handles validating
// |init_data_type| x |container| pairings.
switch (init_data_type) {
case EmeInitDataType::WEBM:
return (sw_secure_codecs_ & media::EME_CODEC_WEBM_ALL) != 0;
case EmeInitDataType::CENC:
return (sw_secure_codecs_ & media::EME_CODEC_MP4_ALL) != 0;
case EmeInitDataType::KEYIDS:
case EmeInitDataType::UNKNOWN:
return false;
}
NOTREACHED();
}
EmeConfig::Rule AndroidKeySystemInfo::GetEncryptionSchemeConfigRule(
EncryptionScheme encryption_scheme) const {
bool is_sw_secure_supported =
sw_secure_encryption_schemes_.contains(encryption_scheme);
bool is_hw_secure_supported =
hw_secure_encryption_schemes_.contains(encryption_scheme);
if (is_sw_secure_supported && is_hw_secure_supported) {
return EmeConfig::SupportedRule();
} else if (is_sw_secure_supported && !is_hw_secure_supported) {
return EmeConfig{.hw_secure_codecs = EmeConfigRuleState::kNotAllowed};
} else if (!is_sw_secure_supported && is_hw_secure_supported) {
return EmeConfig{.hw_secure_codecs = EmeConfigRuleState::kRequired};
} else {
return EmeConfig::UnsupportedRule();
}
}
SupportedCodecs AndroidKeySystemInfo::GetSupportedCodecs() const {
return sw_secure_codecs_;
}
SupportedCodecs AndroidKeySystemInfo::GetSupportedHwSecureCodecs() const {
return hw_secure_codecs_;
}
EmeConfig::Rule AndroidKeySystemInfo::GetRobustnessConfigRule(
const std::string& /*key_system*/,
EmeMediaType /*media_type*/,
const std::string& requested_robustness,
const bool* /*hw_secure_requirement*/) const {
// For non-Widevine key systems, we don't know what `robustness` specifies.
// `hw_secure_requirement` is ignored here because it's a temporary solution
// until a larger refactoring of the key system logic is done. It also does
// not need to account for it here because if it does introduce an
// incompatibility at this point, it will still be caught by the rule logic
// in KeySystemConfigSelector: crbug.com/1204284
if (requested_robustness.empty()) {
return EmeConfig::SupportedRule();
} else {
return EmeConfig::UnsupportedRule();
}
}
EmeConfig::Rule AndroidKeySystemInfo::GetPersistentLicenseSessionSupport()
const {
return EmeConfig::UnsupportedRule();
}
EmeFeatureSupport AndroidKeySystemInfo::GetPersistentStateSupport() const {
return EmeFeatureSupport::ALWAYS_ENABLED;
}
EmeFeatureSupport AndroidKeySystemInfo::GetDistinctiveIdentifierSupport()
const {
return EmeFeatureSupport::ALWAYS_ENABLED;
}
} // namespace cdm
|