blob: 4a81fe43b6c38ec4581d46941c169fadbddc4ec7 [file] [log] [blame]
Piet Schoutenb7347ea2025-05-07 23:42:311// Copyright 2025 The Chromium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "components/cdm/renderer/playready_key_system_info.h"
6
7#include "base/logging.h"
8#include "base/trace_event/trace_event.h"
9#include "components/cdm/common/buildflags.h"
10#include "components/cdm/common/playready_cdm_common.h"
11
12#if !BUILDFLAG(ENABLE_PLAYREADY)
13#error This file should only be built when PlayReady is enabled.
14#endif
15
16using media::EmeConfig;
17using media::EmeConfigRuleState;
18using media::EmeFeatureSupport;
19using media::EmeInitDataType;
20using media::EmeMediaType;
21using media::SupportedCodecs;
22
23namespace cdm {
24
25PlayReadyKeySystemInfo::PlayReadyKeySystemInfo(
26 media::SupportedCodecs hw_secure_codecs,
27 base::flat_set<media::EncryptionScheme> hw_secure_encryption_schemes)
28 : hw_secure_codecs_(hw_secure_codecs),
29 hw_secure_encryption_schemes_(std::move(hw_secure_encryption_schemes)) {}
30
31PlayReadyKeySystemInfo::~PlayReadyKeySystemInfo() = default;
32
33std::string PlayReadyKeySystemInfo::GetBaseKeySystemName() const {
34 return kPlayReadyKeySystemRecommendationDefault;
35}
36
37bool PlayReadyKeySystemInfo::IsSupportedKeySystem(
38 const std::string& key_system) const {
39 return IsPlayReadyKeySystem(key_system);
40}
41
42bool PlayReadyKeySystemInfo::ShouldUseBaseKeySystemName() const {
43 return true;
44}
45
46bool PlayReadyKeySystemInfo::IsSupportedInitDataType(
47 EmeInitDataType init_data_type) const {
48 // Here we assume that support for a container imples support for the
49 // associated initialization data type. KeySystems handles validating
50 // |init_data_type| x |container| pairings.
51
52 // To make KeySystemConfigSelector::GetSupportedConfiguration work correctly,
53 // use the hardware secure codecs since there are no supported software codecs
54 // in Chromium. If software secure codecs (aka. codecs_) is used here when
55 // the keysystem is "com.microsoft.playready.recommendation", then this will
56 // always return false which is not correct when robustness=3000.
57 const media::SupportedCodecs codecs = hw_secure_codecs_;
58
59 if (init_data_type == EmeInitDataType::WEBM) {
60 return (codecs & media::EME_CODEC_WEBM_ALL) != 0;
61 }
62 if (init_data_type == EmeInitDataType::CENC) {
63 return (codecs & media::EME_CODEC_MP4_ALL) != 0;
64 }
65 if (init_data_type == EmeInitDataType::KEYIDS) {
66 return true;
67 }
68
69 return false;
70}
71
72EmeConfig::Rule PlayReadyKeySystemInfo::GetEncryptionSchemeConfigRule(
73 media::EncryptionScheme encryption_scheme) const {
74 if (hw_secure_encryption_schemes_.count(encryption_scheme)) {
75 return EmeConfig{.hw_secure_codecs = EmeConfigRuleState::kRequired};
76 }
77
78 return EmeConfig::UnsupportedRule();
79}
80
81SupportedCodecs PlayReadyKeySystemInfo::GetSupportedCodecs() const {
82 return media::EME_CODEC_NONE;
83}
84
85SupportedCodecs PlayReadyKeySystemInfo::GetSupportedHwSecureCodecs() const {
86 return hw_secure_codecs_;
87}
88
89// `hw_secure_requirement` is not used here because the
90// implementation only supports hardware secure PlayReady
91// key systems. Software secure is not supported.
92EmeConfig::Rule PlayReadyKeySystemInfo::GetRobustnessConfigRule(
93 const std::string& key_system,
94 EmeMediaType media_type,
95 const std::string& requested_robustness,
96 const bool* hw_secure_requirement) const {
97 if (IsPlayReadyHwSecureKeySystem(key_system) &&
98 (requested_robustness.empty() || requested_robustness == "3000")) {
99 return EmeConfig{.hw_secure_codecs = EmeConfigRuleState::kRequired};
100 }
101
102 // Passing the robustness value of "3000" with the recommendation
103 // key system also implies hardware secure PlayReady.
104 if (key_system == kPlayReadyKeySystemRecommendationDefault &&
105 requested_robustness == "3000") {
106 return EmeConfig{.hw_secure_codecs = EmeConfigRuleState::kRequired};
107 }
108
109 // Software secure PlayReady is not supported in Chromium.
110 return EmeConfig::UnsupportedRule();
111}
112
113EmeConfig::Rule PlayReadyKeySystemInfo::GetPersistentLicenseSessionSupport()
114 const {
115 return EmeConfig::UnsupportedRule();
116}
117
118EmeFeatureSupport PlayReadyKeySystemInfo::GetPersistentStateSupport() const {
119 return EmeFeatureSupport::ALWAYS_ENABLED;
120}
121
122EmeFeatureSupport PlayReadyKeySystemInfo::GetDistinctiveIdentifierSupport()
123 const {
124 return EmeFeatureSupport::ALWAYS_ENABLED;
125}
126
127} // namespace cdm