Shaka Player Embedded
media_keys.h
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 
15 #ifndef SHAKA_EMBEDDED_JS_EME_MEDIA_KEYS_H_
16 #define SHAKA_EMBEDDED_JS_EME_MEDIA_KEYS_H_
17 
18 #include <memory>
19 #include <mutex>
20 #include <string>
21 #include <unordered_map>
22 #include <vector>
23 
27 #include "shaka/optional.h"
28 
29 #include "src/core/member.h"
30 #include "src/core/ref_ptr.h"
37 #include "src/mapping/promise.h"
38 
39 namespace shaka {
40 namespace js {
41 namespace eme {
42 
43 class MediaKeySession;
44 
45 class MediaKeys : public BackingObject {
46  DECLARE_TYPE_INFO(MediaKeys);
47 
48  public:
49  MediaKeys(std::shared_ptr<ImplementationFactory> factory,
50  const std::string& key_system,
51  const MediaKeySystemConfiguration& config);
52 
53  void Trace(memory::HeapTracer* tracer) const override;
54 
55  bool valid() const;
56 
58  optional<MediaKeySessionType> session_type);
60 
61  RefPtr<MediaKeySession> GetSession(const std::string& session_id);
63  return implementation_.get();
64  }
65 
66  const std::string key_system;
67 
68  private:
69  mutable std::mutex mutex_;
70  // TODO: These should be weak pointers.
71  std::vector<Member<MediaKeySession>> sessions_;
73  std::shared_ptr<ImplementationFactory> factory_;
74  std::shared_ptr<Implementation> implementation_;
75 };
76 
77 class MediaKeysFactory : public BackingObjectFactory<MediaKeys> {
78  public:
80 };
81 
82 } // namespace eme
83 } // namespace js
84 } // namespace shaka
85 
86 #endif // SHAKA_EMBEDDED_JS_EME_MEDIA_KEYS_H_
virtual BackingObjectFactoryBase * factory() const =0
Promise SetServerCertificate(ByteBuffer cert)
Definition: media_keys.cc:74
void Trace(memory::HeapTracer *tracer) const override
Definition: media_keys.cc:47
Implementation * GetCdm() const
Definition: media_keys.h:62
MediaKeys(std::shared_ptr< ImplementationFactory > factory, const std::string &key_system, const MediaKeySystemConfiguration &config)
Definition: media_keys.cc:25
RefPtr< MediaKeySession > GetSession(const std::string &session_id)
Definition: media_keys.cc:81
ExceptionOr< RefPtr< MediaKeySession > > CreateSession(optional< MediaKeySessionType > session_type)
Definition: media_keys.cc:58
const std::string key_system
Definition: media_keys.h:66