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

Side by Side Diff: webkit/media/crypto/proxy_decryptor.h

Issue 10822026: Implement "Key Presence" step in "Encrypted Block Encounted" algorithm in EME. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add unit test. Created 8 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 WEBKIT_MEDIA_CRYPTO_PROXY_DECRYPTOR_H_ 5 #ifndef WEBKIT_MEDIA_CRYPTO_PROXY_DECRYPTOR_H_
6 #define WEBKIT_MEDIA_CRYPTO_PROXY_DECRYPTOR_H_ 6 #define WEBKIT_MEDIA_CRYPTO_PROXY_DECRYPTOR_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector>
9 10
10 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
11 #include "base/synchronization/lock.h" 12 #include "base/synchronization/lock.h"
12 #include "media/base/decryptor.h" 13 #include "media/base/decryptor.h"
13 14
15 namespace base {
16 class MessageLoopProxy;
17 }
18
14 namespace media { 19 namespace media {
15 class DecryptorClient; 20 class DecryptorClient;
16 } 21 }
17 22
18 namespace WebKit { 23 namespace WebKit {
19 class WebFrame; 24 class WebFrame;
20 class WebMediaPlayerClient; 25 class WebMediaPlayerClient;
21 } 26 }
22 27
23 namespace webkit_media { 28 namespace webkit_media {
24 29
25 // A decryptor proxy that creates a real decryptor object on demand and 30 // A decryptor proxy that creates a real decryptor object on demand and
26 // forwards decryptor calls to it. 31 // forwards decryptor calls to it.
27 // TODO(xhwang): Currently we don't support run-time switching among decryptor 32 // TODO(xhwang): Currently we don't support run-time switching among decryptor
28 // objects. Fix this when needed. 33 // objects. Fix this when needed.
29 class ProxyDecryptor : public media::Decryptor { 34 class ProxyDecryptor : public media::Decryptor {
30 public: 35 public:
31 ProxyDecryptor(media::DecryptorClient* decryptor_client, 36 ProxyDecryptor(media::DecryptorClient* decryptor_client,
32 WebKit::WebMediaPlayerClient* web_media_player_client, 37 WebKit::WebMediaPlayerClient* web_media_player_client,
33 WebKit::WebFrame* web_frame); 38 WebKit::WebFrame* web_frame);
34 virtual ~ProxyDecryptor(); 39 virtual ~ProxyDecryptor();
35 40
41 // This is only for testing purpose.
scherkus (not reviewing) 2012/07/28 23:07:19 instead of a comment + setter that looks like it's
xhwang 2012/07/30 19:58:10 Done.
42 void set_decryptor(scoped_ptr<media::Decryptor> decryptor) {
43 decryptor_ = decryptor.Pass();
44 }
45
36 // media::Decryptor implementation. 46 // media::Decryptor implementation.
37 virtual void GenerateKeyRequest(const std::string& key_system, 47 virtual void GenerateKeyRequest(const std::string& key_system,
38 const uint8* init_data, 48 const uint8* init_data,
39 int init_data_length) OVERRIDE; 49 int init_data_length) OVERRIDE;
40 virtual void AddKey(const std::string& key_system, 50 virtual void AddKey(const std::string& key_system,
41 const uint8* key, 51 const uint8* key,
42 int key_length, 52 int key_length,
43 const uint8* init_data, 53 const uint8* init_data,
44 int init_data_length, 54 int init_data_length,
45 const std::string& session_id) OVERRIDE; 55 const std::string& session_id) OVERRIDE;
46 virtual void CancelKeyRequest(const std::string& key_system, 56 virtual void CancelKeyRequest(const std::string& key_system,
47 const std::string& session_id) OVERRIDE; 57 const std::string& session_id) OVERRIDE;
48 virtual void Decrypt(const scoped_refptr<media::DecoderBuffer>& encrypted, 58 virtual void Decrypt(const scoped_refptr<media::DecoderBuffer>& encrypted,
49 const DecryptCB& decrypt_cb) OVERRIDE; 59 const DecryptCB& decrypt_cb) OVERRIDE;
50 60
51 private: 61 private:
52 scoped_ptr<media::Decryptor> CreatePpapiDecryptor( 62 scoped_ptr<media::Decryptor> CreatePpapiDecryptor(
53 const std::string& key_system); 63 const std::string& key_system);
54 scoped_ptr<media::Decryptor> CreateDecryptor(const std::string& key_system); 64 scoped_ptr<media::Decryptor> CreateDecryptor(const std::string& key_system);
55 65
66 // Helper function that makes sure decryptor_->Decrypt() runs on the
67 // |message_loop|.
68 void DecryptOnMessageLoop(
69 const scoped_refptr<base::MessageLoopProxy>& message_loop_proxy,
70 const scoped_refptr<media::DecoderBuffer>& encrypted,
71 const media::Decryptor::DecryptCB& decrypt_cb);
72
73 // Callback used to pass into decryptor_->Decrypt().
74 void OnBufferDecrypted(
75 const scoped_refptr<base::MessageLoopProxy>& message_loop_proxy,
76 const scoped_refptr<media::DecoderBuffer>& encrypted,
77 const media::Decryptor::DecryptCB& decrypt_cb,
78 media::Decryptor::DecryptStatus status,
79 const scoped_refptr<media::DecoderBuffer>& decrypted);
80
56 media::DecryptorClient* client_; 81 media::DecryptorClient* client_;
57 82
58 // Needed to create the PpapiDecryptor. 83 // Needed to create the PpapiDecryptor.
59 WebKit::WebMediaPlayerClient* web_media_player_client_; 84 WebKit::WebMediaPlayerClient* web_media_player_client_;
60 WebKit::WebFrame* web_frame_; 85 WebKit::WebFrame* web_frame_;
61 86
62 // Protects the |decryptor_|. The Decryptor interface specifies that the 87 // Protects the |decryptor_|. The Decryptor interface specifies that the
63 // Decrypt() function will be called on the decoder thread and all other 88 // Decrypt() function will be called on the decoder thread and all other
64 // methods on the renderer thread. The |decryptor_| itself is thread safe 89 // methods on the renderer thread. The |decryptor_| itself is thread safe
65 // when this rule is obeyed. This lock is solely to prevent the race condition 90 // when this rule is obeyed. This lock is solely to prevent the race condition
66 // between setting the |decryptor_| in GenerateKeyRequest() and using it in 91 // between setting the |decryptor_| in GenerateKeyRequest() and using it in
67 // Decrypt(). 92 // Decrypt().
68 base::Lock lock_; 93 base::Lock decryptor_lock_;
69 scoped_ptr<media::Decryptor> decryptor_; // Protected by the |lock_|. 94 scoped_ptr<media::Decryptor> decryptor_; // Protected by the |lock_|.
70 95
96 // Protects the |pending_decrypt_closures_|.
97 base::Lock pending_decrypt_closures_lock_;
scherkus (not reviewing) 2012/07/28 23:07:19 see my other comment -- we don't need this
xhwang 2012/07/30 19:58:10 Done.
98 std::vector<base::Closure> pending_decrypt_closures_;
99
71 DISALLOW_COPY_AND_ASSIGN(ProxyDecryptor); 100 DISALLOW_COPY_AND_ASSIGN(ProxyDecryptor);
72 }; 101 };
73 102
74 } // namespace webkit_media 103 } // namespace webkit_media
75 104
76 #endif // WEBKIT_MEDIA_CRYPTO_PROXY_DECRYPTOR_H_ 105 #endif // WEBKIT_MEDIA_CRYPTO_PROXY_DECRYPTOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698