Shaka Player Embedded
media_key_system_access.cc
Go to the documentation of this file.
1 // Copyright 2017 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
16 
17 #include <utility>
18 
19 #include "src/js/eme/media_keys.h"
20 #include "src/js/js_error.h"
21 
22 namespace shaka {
23 namespace js {
24 namespace eme {
25 
27  const std::string& key_system, MediaKeySystemConfiguration config,
28  std::shared_ptr<ImplementationFactory> factory)
29  : key_system(key_system), config_(std::move(config)), factory_(factory) {}
30 
31 // \cond Doxygen_Skip
32 MediaKeySystemAccess::~MediaKeySystemAccess() {}
33 // \endcond Doxygen_Skip
34 
36  return config_;
37 }
38 
40  RefPtr<MediaKeys> media_keys = new MediaKeys(factory_, key_system, config_);
41  if (!media_keys->valid()) {
42  return Promise::Rejected(
43  JsError::DOMException(UnknownError, "Unable to create CDM instance."));
44  }
45 
46  LocalVar<JsValue> value(media_keys->JsThis());
47  return Promise::Resolved(value);
48 }
49 
50 
52  AddMemberFunction("getConfiguration",
54  AddMemberFunction("createMediaKeys", &MediaKeySystemAccess::CreateMediaKeys);
55 
56  AddReadOnlyProperty("keySystem", &MediaKeySystemAccess::key_system);
57 }
58 
59 } // namespace eme
60 } // namespace js
61 } // namespace shaka
static Promise Rejected(const js::JsError &error)
Definition: promise.h:77
MediaKeySystemConfiguration GetConfiguration() const
static JsError DOMException(ExceptionCode code)
Definition: js_error.cc:115
static Promise Resolved()
Definition: promise.h:64
MediaKeySystemAccess(const std::string &key_system, MediaKeySystemConfiguration config, std::shared_ptr< ImplementationFactory > factory)