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_CDM_AES_DECRYPTOR_H_ | 5 #ifndef MEDIA_CDM_AES_DECRYPTOR_H_ |
6 #define MEDIA_CDM_AES_DECRYPTOR_H_ | 6 #define MEDIA_CDM_AES_DECRYPTOR_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <set> | 11 #include <set> |
12 #include <string> | 12 #include <string> |
13 #include <unordered_map> | 13 #include <unordered_map> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "base/macros.h" | 16 #include "base/macros.h" |
17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
18 #include "base/synchronization/lock.h" | 18 #include "base/synchronization/lock.h" |
19 #include "media/base/cdm_context.h" | 19 #include "media/base/cdm_context.h" |
| 20 #include "media/base/cdm_key_information.h" |
20 #include "media/base/content_decryption_module.h" | 21 #include "media/base/content_decryption_module.h" |
21 #include "media/base/decryptor.h" | 22 #include "media/base/decryptor.h" |
22 #include "media/base/media_export.h" | 23 #include "media/base/media_export.h" |
23 | 24 |
24 class GURL; | 25 class GURL; |
25 | 26 |
26 namespace crypto { | 27 namespace crypto { |
27 class SymmetricKey; | 28 class SymmetricKey; |
28 } | 29 } |
29 | 30 |
30 namespace media { | 31 namespace media { |
31 | 32 |
32 // Decrypts an AES encrypted buffer into an unencrypted buffer. The AES | 33 // Decrypts an AES encrypted buffer into an unencrypted buffer. The AES |
33 // encryption must be CTR with a key size of 128bits. | 34 // encryption must be CTR with a key size of 128bits. |
34 class MEDIA_EXPORT AesDecryptor : public ContentDecryptionModule, | 35 class MEDIA_EXPORT AesDecryptor : public ContentDecryptionModule, |
35 public CdmContext, | 36 public CdmContext, |
36 public Decryptor { | 37 public Decryptor { |
37 public: | 38 public: |
38 AesDecryptor(const GURL& security_origin, | 39 AesDecryptor(const GURL& security_origin, |
39 const SessionMessageCB& session_message_cb, | 40 const SessionMessageCB& session_message_cb, |
40 const SessionClosedCB& session_closed_cb, | 41 const SessionClosedCB& session_closed_cb, |
41 const SessionKeysChangeCB& session_keys_change_cb); | 42 const SessionKeysChangeCB& session_keys_change_cb, |
| 43 const SessionExpirationUpdateCB& session_expiration_update_cb); |
42 | 44 |
43 // ContentDecryptionModule implementation. | 45 // ContentDecryptionModule implementation. |
44 void SetServerCertificate(const std::vector<uint8_t>& certificate, | 46 void SetServerCertificate(const std::vector<uint8_t>& certificate, |
45 std::unique_ptr<SimpleCdmPromise> promise) override; | 47 std::unique_ptr<SimpleCdmPromise> promise) override; |
46 void CreateSessionAndGenerateRequest( | 48 void CreateSessionAndGenerateRequest( |
47 CdmSessionType session_type, | 49 CdmSessionType session_type, |
48 EmeInitDataType init_data_type, | 50 EmeInitDataType init_data_type, |
49 const std::vector<uint8_t>& init_data, | 51 const std::vector<uint8_t>& init_data, |
50 std::unique_ptr<NewSessionCdmPromise> promise) override; | 52 std::unique_ptr<NewSessionCdmPromise> promise) override; |
51 void LoadSession(CdmSessionType session_type, | 53 void LoadSession(CdmSessionType session_type, |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 // Gets a DecryptionKey associated with |key_id|. The AesDecryptor still owns | 130 // Gets a DecryptionKey associated with |key_id|. The AesDecryptor still owns |
129 // the key. Returns NULL if no key is associated with |key_id|. | 131 // the key. Returns NULL if no key is associated with |key_id|. |
130 DecryptionKey* GetKey_Locked(const std::string& key_id) const; | 132 DecryptionKey* GetKey_Locked(const std::string& key_id) const; |
131 | 133 |
132 // Determines if |key_id| is already specified for |session_id|. | 134 // Determines if |key_id| is already specified for |session_id|. |
133 bool HasKey(const std::string& session_id, const std::string& key_id); | 135 bool HasKey(const std::string& session_id, const std::string& key_id); |
134 | 136 |
135 // Deletes all keys associated with |session_id|. | 137 // Deletes all keys associated with |session_id|. |
136 void DeleteKeysForSession(const std::string& session_id); | 138 void DeleteKeysForSession(const std::string& session_id); |
137 | 139 |
| 140 CdmKeysInfo GenerateKeysInfoList(const std::string& session_id, |
| 141 CdmKeyInformation::KeyStatus status); |
| 142 |
138 // Callbacks for firing session events. | 143 // Callbacks for firing session events. |
139 SessionMessageCB session_message_cb_; | 144 SessionMessageCB session_message_cb_; |
140 SessionClosedCB session_closed_cb_; | 145 SessionClosedCB session_closed_cb_; |
141 SessionKeysChangeCB session_keys_change_cb_; | 146 SessionKeysChangeCB session_keys_change_cb_; |
| 147 SessionExpirationUpdateCB session_expiration_update_cb_; |
142 | 148 |
143 // Since only Decrypt() is called off the renderer thread, we only need to | 149 // Since only Decrypt() is called off the renderer thread, we only need to |
144 // protect |key_map_|, the only member variable that is shared between | 150 // protect |key_map_|, the only member variable that is shared between |
145 // Decrypt() and other methods. | 151 // Decrypt() and other methods. |
146 KeyIdToSessionKeysMap key_map_; // Protected by |key_map_lock_|. | 152 KeyIdToSessionKeysMap key_map_; // Protected by |key_map_lock_|. |
147 mutable base::Lock key_map_lock_; // Protects the |key_map_|. | 153 mutable base::Lock key_map_lock_; // Protects the |key_map_|. |
148 | 154 |
149 // Keeps track of current open sessions. | 155 // Keeps track of current open sessions. |
150 std::set<std::string> open_sessions_; | 156 std::set<std::string> open_sessions_; |
151 | 157 |
152 // Make session ID unique per renderer by making it static. Session | 158 // Make session ID unique per renderer by making it static. Session |
153 // IDs seen by the app will be "1", "2", etc. | 159 // IDs seen by the app will be "1", "2", etc. |
154 static uint32_t next_session_id_; | 160 static uint32_t next_session_id_; |
155 | 161 |
156 NewKeyCB new_audio_key_cb_; | 162 NewKeyCB new_audio_key_cb_; |
157 NewKeyCB new_video_key_cb_; | 163 NewKeyCB new_video_key_cb_; |
158 | 164 |
159 // Protect |new_audio_key_cb_| and |new_video_key_cb_| as they are set on the | 165 // Protect |new_audio_key_cb_| and |new_video_key_cb_| as they are set on the |
160 // main thread but called on the media thread. | 166 // main thread but called on the media thread. |
161 mutable base::Lock new_key_cb_lock_; | 167 mutable base::Lock new_key_cb_lock_; |
162 | 168 |
163 DISALLOW_COPY_AND_ASSIGN(AesDecryptor); | 169 DISALLOW_COPY_AND_ASSIGN(AesDecryptor); |
164 }; | 170 }; |
165 | 171 |
166 } // namespace media | 172 } // namespace media |
167 | 173 |
168 #endif // MEDIA_CDM_AES_DECRYPTOR_H_ | 174 #endif // MEDIA_CDM_AES_DECRYPTOR_H_ |
OLD | NEW |