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_MEDIA_KEYS_H_ |
6 #define MEDIA_BASE_MEDIA_KEYS_H_ | 6 #define MEDIA_BASE_MEDIA_KEYS_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/memory/ref_counted.h" |
13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
14 #include "base/memory/scoped_vector.h" | 15 #include "base/memory/scoped_vector.h" |
15 #include "media/base/eme_constants.h" | 16 #include "media/base/eme_constants.h" |
16 #include "media/base/media_export.h" | 17 #include "media/base/media_export.h" |
17 #include "url/gurl.h" | 18 #include "url/gurl.h" |
18 | 19 |
19 namespace base { | 20 namespace base { |
20 class Time; | 21 class Time; |
21 } | 22 } |
22 | 23 |
23 namespace media { | 24 namespace media { |
24 | 25 |
25 class CdmContext; | 26 class CdmContext; |
26 struct CdmKeyInformation; | 27 struct CdmKeyInformation; |
| 28 struct MediaKeysTraits; |
27 | 29 |
28 template <typename... T> | 30 template <typename... T> |
29 class CdmPromiseTemplate; | 31 class CdmPromiseTemplate; |
30 | 32 |
31 typedef CdmPromiseTemplate<std::string> NewSessionCdmPromise; | 33 typedef CdmPromiseTemplate<std::string> NewSessionCdmPromise; |
32 typedef CdmPromiseTemplate<> SimpleCdmPromise; | 34 typedef CdmPromiseTemplate<> SimpleCdmPromise; |
33 typedef ScopedVector<CdmKeyInformation> CdmKeysInfo; | 35 typedef ScopedVector<CdmKeyInformation> CdmKeysInfo; |
34 | 36 |
35 // Performs media key operations. | 37 // An interface that represents the Content Decryption Module (CDM) in the |
| 38 // Encrypted Media Extensions (EME) spec in Chromium. |
| 39 // See http://w3c.github.io/encrypted-media/#cdm |
36 // | 40 // |
37 // All key operations are called on the renderer thread. Therefore, these calls | 41 // * Ownership |
38 // should be fast and nonblocking; key events should be fired asynchronously. | 42 // |
39 class MEDIA_EXPORT MediaKeys{ | 43 // This class is ref-counted. However, a ref-count should only be held by: |
| 44 // - The owner of the CDM. This is usually some class in the EME stack, e.g. |
| 45 // CdmSessionAdapter in the render process, or MojoCdmService in a non-render |
| 46 // process. |
| 47 // - The media player that uses the CDM, to prevent the CDM from being |
| 48 // destructed while still being used by the media player. |
| 49 // |
| 50 // When binding class methods into callbacks, prefer WeakPtr to using |this| |
| 51 // directly to avoid having a ref-count held by the callback. |
| 52 // |
| 53 // * Thread Safety |
| 54 // |
| 55 // Most CDM operations happen on one thread. However, it is not uncommon that |
| 56 // the media player lives on a different thread and may call into the CDM from |
| 57 // that thread. For example, if the CDM supports a Decryptor interface, the |
| 58 // Decryptor methods could be called on a different thread. The CDM |
| 59 // implementation should make sure it's thread safe for these situations. |
| 60 // |
| 61 // TODO(xhwang): Rename MediaKeys to ContentDecryptionModule. See |
| 62 // http://crbug.com/309237 |
| 63 |
| 64 class MEDIA_EXPORT MediaKeys |
| 65 : public base::RefCountedThreadSafe<MediaKeys, MediaKeysTraits> { |
40 public: | 66 public: |
41 // Reported to UMA, so never reuse a value! | 67 // Reported to UMA, so never reuse a value! |
42 // Must be kept in sync with blink::WebMediaPlayerClient::MediaKeyErrorCode | 68 // Must be kept in sync with blink::WebMediaPlayerClient::MediaKeyErrorCode |
43 // (enforced in webmediaplayer_impl.cc). | 69 // (enforced in webmediaplayer_impl.cc). |
44 // TODO(jrummell): Can this be moved to proxy_decryptor as it should only be | 70 // TODO(jrummell): Can this be moved to proxy_decryptor as it should only be |
45 // used by the prefixed EME code? | 71 // used by the prefixed EME code? |
46 enum KeyError { | 72 enum KeyError { |
47 kUnknownError = 1, | 73 kUnknownError = 1, |
48 kClientError, | 74 kClientError, |
49 // The commented v0.1b values below have never been used. | 75 // The commented v0.1b values below have never been used. |
(...skipping 29 matching lines...) Expand all Loading... |
79 // Type of message being sent to the application. | 105 // Type of message being sent to the application. |
80 // Must be consistent with the values specified in the spec: | 106 // Must be consistent with the values specified in the spec: |
81 // https://w3c.github.io/encrypted-media/#idl-def-MediaKeyMessageType | 107 // https://w3c.github.io/encrypted-media/#idl-def-MediaKeyMessageType |
82 enum MessageType { | 108 enum MessageType { |
83 LICENSE_REQUEST, | 109 LICENSE_REQUEST, |
84 LICENSE_RENEWAL, | 110 LICENSE_RENEWAL, |
85 LICENSE_RELEASE, | 111 LICENSE_RELEASE, |
86 MESSAGE_TYPE_MAX = LICENSE_RELEASE | 112 MESSAGE_TYPE_MAX = LICENSE_RELEASE |
87 }; | 113 }; |
88 | 114 |
89 virtual ~MediaKeys(); | |
90 | |
91 // Provides a server certificate to be used to encrypt messages to the | 115 // Provides a server certificate to be used to encrypt messages to the |
92 // license server. | 116 // license server. |
93 virtual void SetServerCertificate(const std::vector<uint8_t>& certificate, | 117 virtual void SetServerCertificate(const std::vector<uint8_t>& certificate, |
94 scoped_ptr<SimpleCdmPromise> promise) = 0; | 118 scoped_ptr<SimpleCdmPromise> promise) = 0; |
95 | 119 |
96 // Creates a session with |session_type|. Then generates a request with the | 120 // Creates a session with |session_type|. Then generates a request with the |
97 // |init_data_type| and |init_data|. | 121 // |init_data_type| and |init_data|. |
98 // Note: | 122 // Note: |
99 // 1. The session ID will be provided when the |promise| is resolved. | 123 // 1. The session ID will be provided when the |promise| is resolved. |
100 // 2. The generated request should be returned through a SessionMessageCB, | 124 // 2. The generated request should be returned through a SessionMessageCB, |
(...skipping 29 matching lines...) Expand all Loading... |
130 // Removes stored session data associated with the session specified by | 154 // Removes stored session data associated with the session specified by |
131 // |session_id|. | 155 // |session_id|. |
132 virtual void RemoveSession(const std::string& session_id, | 156 virtual void RemoveSession(const std::string& session_id, |
133 scoped_ptr<SimpleCdmPromise> promise) = 0; | 157 scoped_ptr<SimpleCdmPromise> promise) = 0; |
134 | 158 |
135 // Returns the CdmContext associated with |this|, which must NOT be null. | 159 // Returns the CdmContext associated with |this|, which must NOT be null. |
136 // Usually the CdmContext is owned by |this|. Caller needs to make sure it is | 160 // Usually the CdmContext is owned by |this|. Caller needs to make sure it is |
137 // not used after |this| is destructed. | 161 // not used after |this| is destructed. |
138 virtual CdmContext* GetCdmContext() = 0; | 162 virtual CdmContext* GetCdmContext() = 0; |
139 | 163 |
| 164 // Deletes |this| on the correct thread. By default |this| is deleted |
| 165 // immediately. Override this method if |this| needs to be deleted on a |
| 166 // specific thread. |
| 167 virtual void DeleteOnCorrectThread() const; |
| 168 |
140 protected: | 169 protected: |
| 170 friend class base::RefCountedThreadSafe<MediaKeys, MediaKeysTraits>; |
| 171 |
141 MediaKeys(); | 172 MediaKeys(); |
| 173 virtual ~MediaKeys(); |
142 | 174 |
143 private: | 175 private: |
144 DISALLOW_COPY_AND_ASSIGN(MediaKeys); | 176 DISALLOW_COPY_AND_ASSIGN(MediaKeys); |
145 }; | 177 }; |
146 | 178 |
147 // Key event callbacks. See the spec for details: | 179 struct MEDIA_EXPORT MediaKeysTraits { |
148 // https://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/encrypted-
media.html#event-summary | 180 // Destroys |media_keys| on the correct thread. |
| 181 static void Destruct(const MediaKeys* media_keys); |
| 182 }; |
149 | 183 |
| 184 // CDM session event callbacks. |
| 185 |
| 186 // Called when the CDM needs to queue a message event to the session object. |
| 187 // See http://w3c.github.io/encrypted-media/#dom-evt-message |
150 typedef base::Callback<void(const std::string& session_id, | 188 typedef base::Callback<void(const std::string& session_id, |
151 MediaKeys::MessageType message_type, | 189 MediaKeys::MessageType message_type, |
152 const std::vector<uint8_t>& message, | 190 const std::vector<uint8_t>& message, |
153 const GURL& legacy_destination_url)> | 191 const GURL& legacy_destination_url)> |
154 SessionMessageCB; | 192 SessionMessageCB; |
155 | 193 |
156 // Called when the session specified by |session_id| is closed. Note that the | 194 // Called when the session specified by |session_id| is closed. Note that the |
157 // CDM may close a session at any point, such as in response to a CloseSession() | 195 // CDM may close a session at any point, such as in response to a CloseSession() |
158 // call, when the session is no longer needed, or when system resources are | 196 // call, when the session is no longer needed, or when system resources are |
159 // lost. See for details: http://w3c.github.io/encrypted-media/#session-close | 197 // lost. See http://w3c.github.io/encrypted-media/#session-close |
160 typedef base::Callback<void(const std::string& session_id)> SessionClosedCB; | 198 typedef base::Callback<void(const std::string& session_id)> SessionClosedCB; |
161 | 199 |
| 200 // TODO(xhwang): Remove after prefixed EME support is removed. See |
| 201 // http://crbug.com/249976 |
162 typedef base::Callback<void(const std::string& session_id, | 202 typedef base::Callback<void(const std::string& session_id, |
163 MediaKeys::Exception exception, | 203 MediaKeys::Exception exception, |
164 uint32_t system_code, | 204 uint32_t system_code, |
165 const std::string& error_message)> | 205 const std::string& error_message)> |
166 LegacySessionErrorCB; | 206 LegacySessionErrorCB; |
167 | 207 |
| 208 // Called when there has been a change in the keys in the session or their |
| 209 // status. See http://w3c.github.io/encrypted-media/#dom-evt-keystatuseschange |
168 typedef base::Callback<void(const std::string& session_id, | 210 typedef base::Callback<void(const std::string& session_id, |
169 bool has_additional_usable_key, | 211 bool has_additional_usable_key, |
170 CdmKeysInfo keys_info)> SessionKeysChangeCB; | 212 CdmKeysInfo keys_info)> SessionKeysChangeCB; |
171 | 213 |
| 214 // Called when the CDM changes the expiration time of a session. |
| 215 // See http://w3c.github.io/encrypted-media/#update-expiration |
172 typedef base::Callback<void(const std::string& session_id, | 216 typedef base::Callback<void(const std::string& session_id, |
173 const base::Time& new_expiry_time)> | 217 const base::Time& new_expiry_time)> |
174 SessionExpirationUpdateCB; | 218 SessionExpirationUpdateCB; |
175 | 219 |
176 } // namespace media | 220 } // namespace media |
177 | 221 |
178 #endif // MEDIA_BASE_MEDIA_KEYS_H_ | 222 #endif // MEDIA_BASE_MEDIA_KEYS_H_ |
OLD | NEW |