Shaka Player Embedded
implementation_helper_impl.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 <vector>
18 
21 #include "src/js/eme/media_keys.h"
22 #include "src/js/events/event.h"
24 #include "src/js/js_error.h"
25 #include "src/util/crypto.h"
26 #include "src/util/file_system.h"
27 #include "src/util/utils.h"
28 
29 namespace shaka {
30 namespace js {
31 namespace eme {
32 
34  const std::string& key_system, MediaKeys* media_keys)
35  : mutex_("ImplementationHelper"),
36  key_system_(key_system),
37  media_keys_(media_keys) {}
38 
40 
41 
43  std::unique_lock<Mutex> lock(mutex_);
44  const std::vector<uint8_t> hash = util::HashData(
45  reinterpret_cast<const uint8_t*>(key_system_.data()), key_system_.size());
46  const std::string dir = util::ToHexString(hash.data(), hash.size());
48  JsManagerImpl::Instance()->GetPathForDynamicFile("eme"), dir);
49 }
50 
51 void ImplementationHelperImpl::OnMessage(const std::string& session_id,
52  MediaKeyMessageType message_type,
53  const uint8_t* data,
54  size_t data_size) const {
55  std::unique_lock<Mutex> lock(mutex_);
56  RefPtr<MediaKeySession> session = media_keys_->GetSession(session_id);
57  if (session) {
58  session->ScheduleEvent<events::MediaKeyMessageEvent>(
59  EventType::Message, message_type, ByteBuffer(data, data_size));
60  }
61 }
62 
64  const std::string& session_id) const {
65  std::unique_lock<Mutex> lock(mutex_);
66  RefPtr<MediaKeySession> session = media_keys_->GetSession(session_id);
67  if (session) {
68  session->ScheduleEvent<events::Event>(EventType::KeyStatusesChange);
69  }
70 }
71 
72 } // namespace eme
73 } // namespace js
74 } // namespace shaka
void OnKeyStatusChange(const std::string &session_id) const override
std::string ToHexString(const uint8_t *data, size_t data_size)
Definition: utils.cc:97
void OnMessage(const std::string &session_id, MediaKeyMessageType message_type, const uint8_t *data, size_t data_size) const override
static std::string PathJoin(const std::string &a, const std::string &b)
RefPtr< MediaKeySession > GetSession(const std::string &session_id)
Definition: media_keys.cc:81
std::vector< uint8_t > HashData(const uint8_t *data, size_t size)
ImplementationHelperImpl(const std::string &key_system, MediaKeys *media_keys)