37 return type == MediaKeySessionType::PersistentLicense;
40 bool SupportsContentType(
const std::string& content_type) {
44 bool GetSupportedConfiguration(
45 std::shared_ptr<ImplementationFactory> implementation,
46 const MediaKeySystemConfiguration& candidate_config,
47 MediaKeySystemConfiguration* supported_config) {
54 supported_config->label = candidate_config.label;
58 if (!candidate_config.initDataTypes.empty()) {
60 supported_config->initDataTypes.clear();
63 for (
auto& init_data_type : candidate_config.initDataTypes) {
68 if (implementation->SupportsInitDataType(init_data_type))
69 supported_config->initDataTypes.push_back(init_data_type);
73 if (supported_config->initDataTypes.empty()) {
74 VLOG(1) <<
"None of the init data types are supported";
82 candidate_config.distinctiveIdentifier;
88 switch (distinctive_identifier) {
89 case MediaKeysRequirement::Required:
90 if (implementation->DistinctiveIdentifier() ==
91 MediaKeysRequirement::NotAllowed) {
92 VLOG(1) <<
"Distinctive identifier is required by app, but unsupported " 97 case MediaKeysRequirement::Optional:
99 case MediaKeysRequirement::NotAllowed:
100 if (implementation->DistinctiveIdentifier() ==
101 MediaKeysRequirement::Required) {
102 VLOG(1) <<
"Distinctive identifier is required by implementation, but " 103 "app doesn't allow it";
111 supported_config->distinctiveIdentifier = distinctive_identifier;
121 switch (persistent_state) {
122 case MediaKeysRequirement::Required:
123 if (implementation->PersistentState() ==
124 MediaKeysRequirement::NotAllowed) {
125 VLOG(1) <<
"Persistent state is required by app, but unsupported by " 130 case MediaKeysRequirement::Optional:
132 case MediaKeysRequirement::NotAllowed:
133 if (implementation->PersistentState() == MediaKeysRequirement::Required) {
134 VLOG(1) <<
"Persistent state is required by implementation, but app " 143 supported_config->persistentState = persistent_state;
147 std::vector<MediaKeySessionType> session_types =
148 candidate_config.sessionTypes;
149 if (session_types.empty())
150 session_types.push_back(MediaKeySessionType::Temporary);
153 for (
auto& session_type : session_types) {
159 if (supported_config->persistentState == MediaKeysRequirement::NotAllowed &&
160 IsPersistentSessionType(session_type)) {
161 VLOG(1) <<
"Request for persistent session but persistentState is " 169 if (!implementation->SupportsSessionType(session_type)) {
170 VLOG(1) <<
"Implementation doesn't support session type";
178 if (IsPersistentSessionType(session_type)) {
181 supported_config->persistentState = MediaKeysRequirement::Required;
187 supported_config->sessionTypes = session_types;
191 if (candidate_config.audioCapabilities.empty() &&
192 candidate_config.videoCapabilities.empty()) {
193 VLOG(1) <<
"No audio/video capabilities given";
198 if (!candidate_config.videoCapabilities.empty()) {
199 for (
auto& video_cap : candidate_config.videoCapabilities) {
200 if (SupportsContentType(video_cap.contentType) &&
201 implementation->SupportsVideoRobustness(video_cap.robustness)) {
202 supported_config->videoCapabilities.push_back(video_cap);
206 if (supported_config->videoCapabilities.empty()) {
207 VLOG(1) <<
"None of the video capabilities are supported";
213 if (!candidate_config.audioCapabilities.empty()) {
214 for (
auto& audio_cap : candidate_config.audioCapabilities) {
215 if (SupportsContentType(audio_cap.contentType) &&
216 implementation->SupportsAudioRobustness(audio_cap.robustness)) {
217 supported_config->audioCapabilities.push_back(audio_cap);
221 if (supported_config->audioCapabilities.empty()) {
222 VLOG(1) <<
"None of the audio capabilities are supported";
230 if (supported_config->distinctiveIdentifier ==
231 MediaKeysRequirement::Optional) {
232 if (implementation->DistinctiveIdentifier() ==
233 MediaKeysRequirement::Required) {
234 supported_config->distinctiveIdentifier = MediaKeysRequirement::Required;
236 supported_config->distinctiveIdentifier =
237 MediaKeysRequirement::NotAllowed;
243 if (supported_config->persistentState == MediaKeysRequirement::Optional) {
244 if (implementation->PersistentState() == MediaKeysRequirement::Required) {
245 supported_config->persistentState = MediaKeysRequirement::Required;
247 supported_config->persistentState = MediaKeysRequirement::NotAllowed;
259 std::vector<MediaKeySystemConfiguration> configs)
261 key_system_(
std::move(key_system)) {
262 for (
auto& config : configs) {
263 configs_.emplace_back(
264 MakeJsRef<MediaKeySystemConfiguration>(std::move(config)));
279 if (!implementation) {
280 VLOG(1) <<
"No implementation found for: " << key_system_;
287 for (
auto& candidate_config : configs_) {
295 if (GetSupportedConfiguration(implementation, *candidate_config,
296 &supported_config)) {
300 key_system_, supported_config, implementation));
304 LocalVar<JsValue> value(
ToJsValue(access));
305 promise_->ResolveWith(value);
ReturnVal< JsValue > ToJsValue(T &&source)
static std::shared_ptr< ImplementationFactory > GetImplementation(const std::string &key_system)
SearchRegistry & operator=(const SearchRegistry &)=delete
RefPtr< T > MakeJsRef(Args &&... args)
static JsError DOMException(ExceptionCode code)
SearchRegistry(Promise promise, std::string key_system, std::vector< MediaKeySystemConfiguration > configs)