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_CRYPTO_AES_DECRYPTOR_H_ | 5 #ifndef MEDIA_CRYPTO_AES_DECRYPTOR_H_ |
6 #define MEDIA_CRYPTO_AES_DECRYPTOR_H_ | 6 #define MEDIA_CRYPTO_AES_DECRYPTOR_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/containers/scoped_ptr_hash_map.h" | 12 #include "base/containers/scoped_ptr_hash_map.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/synchronization/lock.h" | 15 #include "base/synchronization/lock.h" |
16 #include "media/base/decryptor.h" | 16 #include "media/base/decryptor.h" |
17 #include "media/base/media_export.h" | 17 #include "media/base/media_export.h" |
18 #include "media/base/media_keys.h" | 18 #include "media/base/media_keys.h" |
19 | 19 |
20 namespace crypto { | 20 namespace crypto { |
21 class SymmetricKey; | 21 class SymmetricKey; |
22 } | 22 } |
23 | 23 |
24 namespace media { | 24 namespace media { |
25 | 25 |
26 // Decrypts an AES encrypted buffer into an unencrypted buffer. The AES | 26 // Decrypts an AES encrypted buffer into an unencrypted buffer. The AES |
27 // encryption must be CTR with a key size of 128bits. | 27 // encryption must be CTR with a key size of 128bits. |
28 class MEDIA_EXPORT AesDecryptor : public MediaKeys, public Decryptor { | 28 class MEDIA_EXPORT AesDecryptor : public MediaKeys, public Decryptor { |
29 public: | 29 public: |
30 AesDecryptor(const SessionCreatedCB& session_created_cb, | 30 AesDecryptor(const SessionMessageCB& session_message_cb); |
31 const SessionMessageCB& session_message_cb, | |
32 const SessionReadyCB& session_ready_cb, | |
33 const SessionClosedCB& session_closed_cb, | |
34 const SessionErrorCB& session_error_cb); | |
35 virtual ~AesDecryptor(); | 31 virtual ~AesDecryptor(); |
36 | 32 |
37 // MediaKeys implementation. | 33 // MediaKeys implementation. |
38 virtual bool CreateSession(uint32 session_id, | 34 virtual void CreateSession(const std::string& init_data_type, |
39 const std::string& content_type, | |
40 const uint8* init_data, | 35 const uint8* init_data, |
41 int init_data_length) OVERRIDE; | 36 int init_data_length, |
42 virtual void LoadSession(uint32 session_id, | 37 SessionType session_type, |
43 const std::string& web_session_id) OVERRIDE; | 38 scoped_ptr<CdmNewSessionPromise> promise) OVERRIDE; |
44 virtual void UpdateSession(uint32 session_id, | 39 virtual void LoadSession(const std::string& web_session_id, |
45 const uint8* response, | 40 scoped_ptr<CdmNewSessionPromise> promise) OVERRIDE; |
46 int response_length) OVERRIDE; | 41 virtual void UpdateSession( |
47 virtual void ReleaseSession(uint32 session_id) OVERRIDE; | 42 const std::string& web_session_id, |
| 43 const uint8* response, |
| 44 int response_length, |
| 45 scoped_ptr<CdmChangeSessionPromise> promise) OVERRIDE; |
| 46 virtual void ReleaseSession( |
| 47 const std::string& web_session_id, |
| 48 scoped_ptr<CdmChangeSessionPromise> promise) OVERRIDE; |
48 virtual Decryptor* GetDecryptor() OVERRIDE; | 49 virtual Decryptor* GetDecryptor() OVERRIDE; |
49 | 50 |
50 // Decryptor implementation. | 51 // Decryptor implementation. |
51 virtual void RegisterNewKeyCB(StreamType stream_type, | 52 virtual void RegisterNewKeyCB(StreamType stream_type, |
52 const NewKeyCB& key_added_cb) OVERRIDE; | 53 const NewKeyCB& key_added_cb) OVERRIDE; |
53 virtual void Decrypt(StreamType stream_type, | 54 virtual void Decrypt(StreamType stream_type, |
54 const scoped_refptr<DecoderBuffer>& encrypted, | 55 const scoped_refptr<DecoderBuffer>& encrypted, |
55 const DecryptCB& decrypt_cb) OVERRIDE; | 56 const DecryptCB& decrypt_cb) OVERRIDE; |
56 virtual void CancelDecrypt(StreamType stream_type) OVERRIDE; | 57 virtual void CancelDecrypt(StreamType stream_type) OVERRIDE; |
57 virtual void InitializeAudioDecoder(const AudioDecoderConfig& config, | 58 virtual void InitializeAudioDecoder(const AudioDecoderConfig& config, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 // optimized so that Decrypt() has fast access, at the cost of slow deletion | 97 // optimized so that Decrypt() has fast access, at the cost of slow deletion |
97 // of keys when a session is released. | 98 // of keys when a session is released. |
98 class SessionIdDecryptionKeyMap; | 99 class SessionIdDecryptionKeyMap; |
99 | 100 |
100 // Key ID <-> SessionIdDecryptionKeyMap map. | 101 // Key ID <-> SessionIdDecryptionKeyMap map. |
101 typedef base::ScopedPtrHashMap<std::string, SessionIdDecryptionKeyMap> | 102 typedef base::ScopedPtrHashMap<std::string, SessionIdDecryptionKeyMap> |
102 KeyIdToSessionKeysMap; | 103 KeyIdToSessionKeysMap; |
103 | 104 |
104 // Creates a DecryptionKey using |key_string| and associates it with |key_id|. | 105 // Creates a DecryptionKey using |key_string| and associates it with |key_id|. |
105 // Returns true if successful. | 106 // Returns true if successful. |
106 bool AddDecryptionKey(const uint32 session_id, | 107 bool AddDecryptionKey(const std::string& web_session_id, |
107 const std::string& key_id, | 108 const std::string& key_id, |
108 const std::string& key_string); | 109 const std::string& key_string); |
109 | 110 |
110 // Gets a DecryptionKey associated with |key_id|. The AesDecryptor still owns | 111 // Gets a DecryptionKey associated with |key_id|. The AesDecryptor still owns |
111 // the key. Returns NULL if no key is associated with |key_id|. | 112 // the key. Returns NULL if no key is associated with |key_id|. |
112 DecryptionKey* GetKey(const std::string& key_id) const; | 113 DecryptionKey* GetKey(const std::string& key_id) const; |
113 | 114 |
114 // Deletes all keys associated with |session_id|. | 115 // Deletes all keys associated with |web_session_id|. |
115 void DeleteKeysForSession(const uint32 session_id); | 116 void DeleteKeysForSession(const std::string& web_session_id); |
116 | 117 |
117 // Callbacks for firing session events. | 118 // Callbacks for firing session events. |
118 SessionCreatedCB session_created_cb_; | |
119 SessionMessageCB session_message_cb_; | 119 SessionMessageCB session_message_cb_; |
120 SessionReadyCB session_ready_cb_; | |
121 SessionClosedCB session_closed_cb_; | |
122 SessionErrorCB session_error_cb_; | |
123 | 120 |
124 // Since only Decrypt() is called off the renderer thread, we only need to | 121 // Since only Decrypt() is called off the renderer thread, we only need to |
125 // protect |key_map_|, the only member variable that is shared between | 122 // protect |key_map_|, the only member variable that is shared between |
126 // Decrypt() and other methods. | 123 // Decrypt() and other methods. |
127 KeyIdToSessionKeysMap key_map_; // Protected by |key_map_lock_|. | 124 KeyIdToSessionKeysMap key_map_; // Protected by |key_map_lock_|. |
128 mutable base::Lock key_map_lock_; // Protects the |key_map_|. | 125 mutable base::Lock key_map_lock_; // Protects the |key_map_|. |
129 | 126 |
130 // Keeps track of current valid session IDs. | 127 // Keeps track of current valid sessions. |
131 std::set<uint32> valid_sessions_; | 128 std::set<std::string> valid_sessions_; |
132 | 129 |
133 // Make web session ID unique per renderer by making it static. Web session | 130 // Make web session ID unique per renderer by making it static. Web session |
134 // IDs seen by the app will be "1", "2", etc. | 131 // IDs seen by the app will be "1", "2", etc. |
135 static uint32 next_web_session_id_; | 132 static uint32 next_web_session_id_; |
136 | 133 |
137 NewKeyCB new_audio_key_cb_; | 134 NewKeyCB new_audio_key_cb_; |
138 NewKeyCB new_video_key_cb_; | 135 NewKeyCB new_video_key_cb_; |
139 | 136 |
140 // Protect |new_audio_key_cb_| and |new_video_key_cb_| as they are set on the | 137 // Protect |new_audio_key_cb_| and |new_video_key_cb_| as they are set on the |
141 // main thread but called on the media thread. | 138 // main thread but called on the media thread. |
142 mutable base::Lock new_key_cb_lock_; | 139 mutable base::Lock new_key_cb_lock_; |
143 | 140 |
144 DISALLOW_COPY_AND_ASSIGN(AesDecryptor); | 141 DISALLOW_COPY_AND_ASSIGN(AesDecryptor); |
145 }; | 142 }; |
146 | 143 |
147 } // namespace media | 144 } // namespace media |
148 | 145 |
149 #endif // MEDIA_CRYPTO_AES_DECRYPTOR_H_ | 146 #endif // MEDIA_CRYPTO_AES_DECRYPTOR_H_ |
OLD | NEW |