OLD | NEW |
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 void set_decryptor_for_testing(scoped_ptr<media::Decryptor> decryptor) { |
| 42 decryptor_ = decryptor.Pass(); |
| 43 } |
| 44 |
36 // media::Decryptor implementation. | 45 // media::Decryptor implementation. |
37 virtual void GenerateKeyRequest(const std::string& key_system, | 46 virtual void GenerateKeyRequest(const std::string& key_system, |
38 const uint8* init_data, | 47 const uint8* init_data, |
39 int init_data_length) OVERRIDE; | 48 int init_data_length) OVERRIDE; |
40 virtual void AddKey(const std::string& key_system, | 49 virtual void AddKey(const std::string& key_system, |
41 const uint8* key, | 50 const uint8* key, |
42 int key_length, | 51 int key_length, |
43 const uint8* init_data, | 52 const uint8* init_data, |
44 int init_data_length, | 53 int init_data_length, |
45 const std::string& session_id) OVERRIDE; | 54 const std::string& session_id) OVERRIDE; |
46 virtual void CancelKeyRequest(const std::string& key_system, | 55 virtual void CancelKeyRequest(const std::string& key_system, |
47 const std::string& session_id) OVERRIDE; | 56 const std::string& session_id) OVERRIDE; |
48 virtual void Decrypt(const scoped_refptr<media::DecoderBuffer>& encrypted, | 57 virtual void Decrypt(const scoped_refptr<media::DecoderBuffer>& encrypted, |
49 const DecryptCB& decrypt_cb) OVERRIDE; | 58 const DecryptCB& decrypt_cb) OVERRIDE; |
| 59 virtual void Stop() 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_| and |pending_decrypt_closures_|. Note that |
63 // Decrypt() function will be called on the decoder thread and all other | 88 // |decryptor_| itself should be thread safe as per the Decryptor interface. |
64 // 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 | |
66 // between setting the |decryptor_| in GenerateKeyRequest() and using it in | |
67 // Decrypt(). | |
68 base::Lock lock_; | 89 base::Lock lock_; |
69 scoped_ptr<media::Decryptor> decryptor_; // Protected by the |lock_|. | 90 scoped_ptr<media::Decryptor> decryptor_; |
| 91 std::vector<base::Closure> pending_decrypt_closures_; |
| 92 bool stopped_; |
70 | 93 |
71 DISALLOW_COPY_AND_ASSIGN(ProxyDecryptor); | 94 DISALLOW_COPY_AND_ASSIGN(ProxyDecryptor); |
72 }; | 95 }; |
73 | 96 |
74 } // namespace webkit_media | 97 } // namespace webkit_media |
75 | 98 |
76 #endif // WEBKIT_MEDIA_CRYPTO_PROXY_DECRYPTOR_H_ | 99 #endif // WEBKIT_MEDIA_CRYPTO_PROXY_DECRYPTOR_H_ |
OLD | NEW |