Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: media/cdm/aes_decryptor.h

Issue 265993002: Add Promises for EME (Chromium side) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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);
xhwang 2014/05/23 06:01:23 explicit
jrummell 2014/05/29 00:54:40 Done.
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<NewSessionCdmPromise> promise) OVERRIDE;
44 virtual void UpdateSession(uint32 session_id, 39 virtual void LoadSession(const std::string& web_session_id,
40 scoped_ptr<NewSessionCdmPromise> promise) OVERRIDE;
41 virtual void UpdateSession(const std::string& web_session_id,
45 const uint8* response, 42 const uint8* response,
46 int response_length) OVERRIDE; 43 int response_length,
47 virtual void ReleaseSession(uint32 session_id) OVERRIDE; 44 scoped_ptr<SimpleCdmPromise> promise) OVERRIDE;
45 virtual void ReleaseSession(const std::string& web_session_id,
46 scoped_ptr<SimpleCdmPromise> promise) OVERRIDE;
48 virtual Decryptor* GetDecryptor() OVERRIDE; 47 virtual Decryptor* GetDecryptor() OVERRIDE;
49 48
50 // Decryptor implementation. 49 // Decryptor implementation.
51 virtual void RegisterNewKeyCB(StreamType stream_type, 50 virtual void RegisterNewKeyCB(StreamType stream_type,
52 const NewKeyCB& key_added_cb) OVERRIDE; 51 const NewKeyCB& key_added_cb) OVERRIDE;
53 virtual void Decrypt(StreamType stream_type, 52 virtual void Decrypt(StreamType stream_type,
54 const scoped_refptr<DecoderBuffer>& encrypted, 53 const scoped_refptr<DecoderBuffer>& encrypted,
55 const DecryptCB& decrypt_cb) OVERRIDE; 54 const DecryptCB& decrypt_cb) OVERRIDE;
56 virtual void CancelDecrypt(StreamType stream_type) OVERRIDE; 55 virtual void CancelDecrypt(StreamType stream_type) OVERRIDE;
57 virtual void InitializeAudioDecoder(const AudioDecoderConfig& config, 56 virtual void InitializeAudioDecoder(const AudioDecoderConfig& config,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 // optimized so that Decrypt() has fast access, at the cost of slow deletion 95 // optimized so that Decrypt() has fast access, at the cost of slow deletion
97 // of keys when a session is released. 96 // of keys when a session is released.
98 class SessionIdDecryptionKeyMap; 97 class SessionIdDecryptionKeyMap;
99 98
100 // Key ID <-> SessionIdDecryptionKeyMap map. 99 // Key ID <-> SessionIdDecryptionKeyMap map.
101 typedef base::ScopedPtrHashMap<std::string, SessionIdDecryptionKeyMap> 100 typedef base::ScopedPtrHashMap<std::string, SessionIdDecryptionKeyMap>
102 KeyIdToSessionKeysMap; 101 KeyIdToSessionKeysMap;
103 102
104 // Creates a DecryptionKey using |key_string| and associates it with |key_id|. 103 // Creates a DecryptionKey using |key_string| and associates it with |key_id|.
105 // Returns true if successful. 104 // Returns true if successful.
106 bool AddDecryptionKey(const uint32 session_id, 105 bool AddDecryptionKey(const std::string& web_session_id,
107 const std::string& key_id, 106 const std::string& key_id,
108 const std::string& key_string); 107 const std::string& key_string);
109 108
110 // Gets a DecryptionKey associated with |key_id|. The AesDecryptor still owns 109 // Gets a DecryptionKey associated with |key_id|. The AesDecryptor still owns
111 // the key. Returns NULL if no key is associated with |key_id|. 110 // the key. Returns NULL if no key is associated with |key_id|.
112 DecryptionKey* GetKey(const std::string& key_id) const; 111 DecryptionKey* GetKey(const std::string& key_id) const;
113 112
114 // Deletes all keys associated with |session_id|. 113 // Deletes all keys associated with |web_session_id|.
115 void DeleteKeysForSession(const uint32 session_id); 114 void DeleteKeysForSession(const std::string& web_session_id);
116 115
117 // Callbacks for firing session events. 116 // Callbacks for firing session events.
118 SessionCreatedCB session_created_cb_;
119 SessionMessageCB session_message_cb_; 117 SessionMessageCB session_message_cb_;
120 SessionReadyCB session_ready_cb_;
121 SessionClosedCB session_closed_cb_;
122 SessionErrorCB session_error_cb_;
123 118
124 // Since only Decrypt() is called off the renderer thread, we only need to 119 // 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 120 // protect |key_map_|, the only member variable that is shared between
126 // Decrypt() and other methods. 121 // Decrypt() and other methods.
127 KeyIdToSessionKeysMap key_map_; // Protected by |key_map_lock_|. 122 KeyIdToSessionKeysMap key_map_; // Protected by |key_map_lock_|.
128 mutable base::Lock key_map_lock_; // Protects the |key_map_|. 123 mutable base::Lock key_map_lock_; // Protects the |key_map_|.
129 124
130 // Keeps track of current valid session IDs. 125 // Keeps track of current valid sessions.
131 std::set<uint32> valid_sessions_; 126 std::set<std::string> valid_sessions_;
132 127
133 // Make web session ID unique per renderer by making it static. Web session 128 // Make web session ID unique per renderer by making it static. Web session
134 // IDs seen by the app will be "1", "2", etc. 129 // IDs seen by the app will be "1", "2", etc.
135 static uint32 next_web_session_id_; 130 static uint32 next_web_session_id_;
136 131
137 NewKeyCB new_audio_key_cb_; 132 NewKeyCB new_audio_key_cb_;
138 NewKeyCB new_video_key_cb_; 133 NewKeyCB new_video_key_cb_;
139 134
140 // Protect |new_audio_key_cb_| and |new_video_key_cb_| as they are set on the 135 // 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. 136 // main thread but called on the media thread.
142 mutable base::Lock new_key_cb_lock_; 137 mutable base::Lock new_key_cb_lock_;
143 138
144 DISALLOW_COPY_AND_ASSIGN(AesDecryptor); 139 DISALLOW_COPY_AND_ASSIGN(AesDecryptor);
145 }; 140 };
146 141
147 } // namespace media 142 } // namespace media
148 143
149 #endif // MEDIA_CRYPTO_AES_DECRYPTOR_H_ 144 #endif // MEDIA_CRYPTO_AES_DECRYPTOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698