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

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

Powered by Google App Engine
This is Rietveld 408576698