OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MEDIA_BASE_MEDIA_KEYS_H_ | 5 #ifndef MEDIA_BASE_CONTENT_DECRYPTION_MODULE_H_ |
6 #define MEDIA_BASE_MEDIA_KEYS_H_ | 6 #define MEDIA_BASE_CONTENT_DECRYPTION_MODULE_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/callback.h" | 14 #include "base/callback.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
17 #include "base/memory/scoped_vector.h" | 17 #include "base/memory/scoped_vector.h" |
18 #include "media/base/eme_constants.h" | 18 #include "media/base/eme_constants.h" |
19 #include "media/base/media_export.h" | 19 #include "media/base/media_export.h" |
20 #include "url/gurl.h" | 20 #include "url/gurl.h" |
21 | 21 |
22 namespace base { | 22 namespace base { |
23 class Time; | 23 class Time; |
24 } | 24 } |
25 | 25 |
26 namespace media { | 26 namespace media { |
27 | 27 |
28 class CdmContext; | 28 class CdmContext; |
29 struct CdmKeyInformation; | 29 struct CdmKeyInformation; |
30 struct MediaKeysTraits; | 30 struct ContentDecryptionModuleTraits; |
31 | 31 |
32 template <typename... T> | 32 template <typename... T> |
33 class CdmPromiseTemplate; | 33 class CdmPromiseTemplate; |
34 | 34 |
35 typedef CdmPromiseTemplate<std::string> NewSessionCdmPromise; | 35 typedef CdmPromiseTemplate<std::string> NewSessionCdmPromise; |
36 typedef CdmPromiseTemplate<> SimpleCdmPromise; | 36 typedef CdmPromiseTemplate<> SimpleCdmPromise; |
37 typedef ScopedVector<CdmKeyInformation> CdmKeysInfo; | 37 typedef ScopedVector<CdmKeyInformation> CdmKeysInfo; |
38 | 38 |
39 // An interface that represents the Content Decryption Module (CDM) in the | 39 // An interface that represents the Content Decryption Module (CDM) in the |
40 // Encrypted Media Extensions (EME) spec in Chromium. | 40 // Encrypted Media Extensions (EME) spec in Chromium. |
(...skipping 11 matching lines...) Expand all Loading... |
52 // When binding class methods into callbacks, prefer WeakPtr to using |this| | 52 // When binding class methods into callbacks, prefer WeakPtr to using |this| |
53 // directly to avoid having a ref-count held by the callback. | 53 // directly to avoid having a ref-count held by the callback. |
54 // | 54 // |
55 // * Thread Safety | 55 // * Thread Safety |
56 // | 56 // |
57 // Most CDM operations happen on one thread. However, it is not uncommon that | 57 // Most CDM operations happen on one thread. However, it is not uncommon that |
58 // the media player lives on a different thread and may call into the CDM from | 58 // the media player lives on a different thread and may call into the CDM from |
59 // that thread. For example, if the CDM supports a Decryptor interface, the | 59 // that thread. For example, if the CDM supports a Decryptor interface, the |
60 // Decryptor methods could be called on a different thread. The CDM | 60 // Decryptor methods could be called on a different thread. The CDM |
61 // implementation should make sure it's thread safe for these situations. | 61 // implementation should make sure it's thread safe for these situations. |
62 // | |
63 // TODO(xhwang): Rename MediaKeys to ContentDecryptionModule. See | |
64 // http://crbug.com/309237 | |
65 | 62 |
66 class MEDIA_EXPORT MediaKeys | 63 class MEDIA_EXPORT ContentDecryptionModule |
67 : public base::RefCountedThreadSafe<MediaKeys, MediaKeysTraits> { | 64 : public base::RefCountedThreadSafe<ContentDecryptionModule, |
| 65 ContentDecryptionModuleTraits> { |
68 public: | 66 public: |
69 // Type of license required when creating/loading a session. | 67 // Type of license required when creating/loading a session. |
70 // Must be consistent with the values specified in the spec: | 68 // Must be consistent with the values specified in the spec: |
71 // https://w3c.github.io/encrypted-media/#idl-def-MediaKeySessionType | 69 // https://w3c.github.io/encrypted-media/#idl-def-MediaKeySessionType |
72 enum SessionType { | 70 enum SessionType { |
73 TEMPORARY_SESSION, | 71 TEMPORARY_SESSION, |
74 PERSISTENT_LICENSE_SESSION, | 72 PERSISTENT_LICENSE_SESSION, |
75 PERSISTENT_RELEASE_MESSAGE_SESSION, | 73 PERSISTENT_RELEASE_MESSAGE_SESSION, |
76 SESSION_TYPE_MAX = PERSISTENT_RELEASE_MESSAGE_SESSION | 74 SESSION_TYPE_MAX = PERSISTENT_RELEASE_MESSAGE_SESSION |
77 }; | 75 }; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 // TODO(xhwang): Convert all SetCdm() implementations to use CdmContext so | 142 // TODO(xhwang): Convert all SetCdm() implementations to use CdmContext so |
145 // that this function should never return nullptr. | 143 // that this function should never return nullptr. |
146 virtual CdmContext* GetCdmContext(); | 144 virtual CdmContext* GetCdmContext(); |
147 | 145 |
148 // Deletes |this| on the correct thread. By default |this| is deleted | 146 // Deletes |this| on the correct thread. By default |this| is deleted |
149 // immediately. Override this method if |this| needs to be deleted on a | 147 // immediately. Override this method if |this| needs to be deleted on a |
150 // specific thread. | 148 // specific thread. |
151 virtual void DeleteOnCorrectThread() const; | 149 virtual void DeleteOnCorrectThread() const; |
152 | 150 |
153 protected: | 151 protected: |
154 friend class base::RefCountedThreadSafe<MediaKeys, MediaKeysTraits>; | 152 friend class base::RefCountedThreadSafe<ContentDecryptionModule, |
| 153 ContentDecryptionModuleTraits>; |
155 | 154 |
156 MediaKeys(); | 155 ContentDecryptionModule(); |
157 virtual ~MediaKeys(); | 156 virtual ~ContentDecryptionModule(); |
158 | 157 |
159 private: | 158 private: |
160 DISALLOW_COPY_AND_ASSIGN(MediaKeys); | 159 DISALLOW_COPY_AND_ASSIGN(ContentDecryptionModule); |
161 }; | 160 }; |
162 | 161 |
163 struct MEDIA_EXPORT MediaKeysTraits { | 162 struct MEDIA_EXPORT ContentDecryptionModuleTraits { |
164 // Destroys |media_keys| on the correct thread. | 163 // Destroys |cdm| on the correct thread. |
165 static void Destruct(const MediaKeys* media_keys); | 164 static void Destruct(const ContentDecryptionModule* cdm); |
166 }; | 165 }; |
167 | 166 |
168 // CDM session event callbacks. | 167 // CDM session event callbacks. |
169 | 168 |
170 // Called when the CDM needs to queue a message event to the session object. | 169 // Called when the CDM needs to queue a message event to the session object. |
171 // See http://w3c.github.io/encrypted-media/#dom-evt-message | 170 // See http://w3c.github.io/encrypted-media/#dom-evt-message |
172 typedef base::Callback<void(const std::string& session_id, | 171 typedef base::Callback<void(const std::string& session_id, |
173 MediaKeys::MessageType message_type, | 172 ContentDecryptionModule::MessageType message_type, |
174 const std::vector<uint8_t>& message)> | 173 const std::vector<uint8_t>& message)> |
175 SessionMessageCB; | 174 SessionMessageCB; |
176 | 175 |
177 // Called when the session specified by |session_id| is closed. Note that the | 176 // Called when the session specified by |session_id| is closed. Note that the |
178 // CDM may close a session at any point, such as in response to a CloseSession() | 177 // CDM may close a session at any point, such as in response to a CloseSession() |
179 // call, when the session is no longer needed, or when system resources are | 178 // call, when the session is no longer needed, or when system resources are |
180 // lost. See http://w3c.github.io/encrypted-media/#session-close | 179 // lost. See http://w3c.github.io/encrypted-media/#session-close |
181 typedef base::Callback<void(const std::string& session_id)> SessionClosedCB; | 180 typedef base::Callback<void(const std::string& session_id)> SessionClosedCB; |
182 | 181 |
183 // Called when there has been a change in the keys in the session or their | 182 // Called when there has been a change in the keys in the session or their |
184 // status. See http://w3c.github.io/encrypted-media/#dom-evt-keystatuseschange | 183 // status. See http://w3c.github.io/encrypted-media/#dom-evt-keystatuseschange |
185 typedef base::Callback<void(const std::string& session_id, | 184 typedef base::Callback<void(const std::string& session_id, |
186 bool has_additional_usable_key, | 185 bool has_additional_usable_key, |
187 CdmKeysInfo keys_info)> SessionKeysChangeCB; | 186 CdmKeysInfo keys_info)> |
| 187 SessionKeysChangeCB; |
188 | 188 |
189 // Called when the CDM changes the expiration time of a session. | 189 // Called when the CDM changes the expiration time of a session. |
190 // See http://w3c.github.io/encrypted-media/#update-expiration | 190 // See http://w3c.github.io/encrypted-media/#update-expiration |
191 typedef base::Callback<void(const std::string& session_id, | 191 typedef base::Callback<void(const std::string& session_id, |
192 base::Time new_expiry_time)> | 192 base::Time new_expiry_time)> |
193 SessionExpirationUpdateCB; | 193 SessionExpirationUpdateCB; |
194 | 194 |
195 } // namespace media | 195 } // namespace media |
196 | 196 |
197 #endif // MEDIA_BASE_MEDIA_KEYS_H_ | 197 #endif // MEDIA_BASE_CONTENT_DECRYPTION_MODULE_H_ |
OLD | NEW |