Chromium Code Reviews| 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 #include <vector> |
| 10 | 10 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 31 // forwards decryptor calls to it. | 31 // forwards decryptor calls to it. |
| 32 // 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 |
| 33 // objects. Fix this when needed. | 33 // objects. Fix this when needed. |
| 34 class ProxyDecryptor : public media::Decryptor { | 34 class ProxyDecryptor : public media::Decryptor { |
| 35 public: | 35 public: |
| 36 ProxyDecryptor(media::DecryptorClient* decryptor_client, | 36 ProxyDecryptor(media::DecryptorClient* decryptor_client, |
| 37 WebKit::WebMediaPlayerClient* web_media_player_client, | 37 WebKit::WebMediaPlayerClient* web_media_player_client, |
| 38 WebKit::WebFrame* web_frame); | 38 WebKit::WebFrame* web_frame); |
| 39 virtual ~ProxyDecryptor(); | 39 virtual ~ProxyDecryptor(); |
| 40 | 40 |
| 41 void set_decryptor_for_testing(scoped_ptr<media::Decryptor> decryptor) { | |
| 42 decryptor_ = decryptor.Pass(); | |
| 43 } | |
| 44 | |
| 41 // media::Decryptor implementation. | 45 // media::Decryptor implementation. |
| 42 virtual void GenerateKeyRequest(const std::string& key_system, | 46 virtual void GenerateKeyRequest(const std::string& key_system, |
| 43 const uint8* init_data, | 47 const uint8* init_data, |
| 44 int init_data_length) OVERRIDE; | 48 int init_data_length) OVERRIDE; |
| 45 virtual void AddKey(const std::string& key_system, | 49 virtual void AddKey(const std::string& key_system, |
| 46 const uint8* key, | 50 const uint8* key, |
| 47 int key_length, | 51 int key_length, |
| 48 const uint8* init_data, | 52 const uint8* init_data, |
| 49 int init_data_length, | 53 int init_data_length, |
| 50 const std::string& session_id) OVERRIDE; | 54 const std::string& session_id) OVERRIDE; |
| 51 virtual void CancelKeyRequest(const std::string& key_system, | 55 virtual void CancelKeyRequest(const std::string& key_system, |
| 52 const std::string& session_id) OVERRIDE; | 56 const std::string& session_id) OVERRIDE; |
| 53 virtual void Decrypt(const scoped_refptr<media::DecoderBuffer>& encrypted, | 57 virtual void Decrypt(const scoped_refptr<media::DecoderBuffer>& encrypted, |
| 54 const DecryptCB& decrypt_cb) OVERRIDE; | 58 const DecryptCB& decrypt_cb) OVERRIDE; |
| 59 virtual void Stop() OVERRIDE; | |
| 55 | 60 |
| 56 private: | 61 private: |
| 57 scoped_ptr<media::Decryptor> CreatePpapiDecryptor( | 62 scoped_ptr<media::Decryptor> CreatePpapiDecryptor( |
| 58 const std::string& key_system); | 63 const std::string& key_system); |
| 59 scoped_ptr<media::Decryptor> CreateDecryptor(const std::string& key_system); | 64 scoped_ptr<media::Decryptor> CreateDecryptor(const std::string& key_system); |
| 60 | 65 |
| 61 // Helper function that makes sure decryptor_->Decrypt() runs on the | 66 // Helper function that makes sure decryptor_->Decrypt() runs on the |
| 62 // |message_loop|. | 67 // |message_loop|. |
| 63 void DecryptOnMessageLoop( | 68 void DecryptOnMessageLoop( |
| 64 const scoped_refptr<base::MessageLoopProxy>& message_loop_proxy, | 69 const scoped_refptr<base::MessageLoopProxy>& message_loop_proxy, |
| 65 const scoped_refptr<media::DecoderBuffer>& encrypted, | 70 const scoped_refptr<media::DecoderBuffer>& encrypted, |
| 66 const media::Decryptor::DecryptCB& decrypt_cb); | 71 const media::Decryptor::DecryptCB& decrypt_cb); |
| 67 | 72 |
| 68 // Callback used to pass into decryptor_->Decrypt(). | 73 // Callback used to pass into decryptor_->Decrypt(). |
| 69 void OnBufferDecrypted( | 74 void OnBufferDecrypted( |
| 70 const scoped_refptr<base::MessageLoopProxy>& message_loop_proxy, | 75 const scoped_refptr<base::MessageLoopProxy>& message_loop_proxy, |
| 71 const scoped_refptr<media::DecoderBuffer>& encrypted, | 76 const scoped_refptr<media::DecoderBuffer>& encrypted, |
| 72 const media::Decryptor::DecryptCB& decrypt_cb, | 77 const media::Decryptor::DecryptCB& decrypt_cb, |
| 73 media::Decryptor::DecryptStatus status, | 78 media::Decryptor::DecryptStatus status, |
| 74 const scoped_refptr<media::DecoderBuffer>& decrypted); | 79 const scoped_refptr<media::DecoderBuffer>& decrypted); |
| 75 | 80 |
| 76 media::DecryptorClient* client_; | 81 media::DecryptorClient* client_; |
| 77 | 82 |
| 78 // Needed to create the PpapiDecryptor. | 83 // Needed to create the PpapiDecryptor. |
| 79 WebKit::WebMediaPlayerClient* web_media_player_client_; | 84 WebKit::WebMediaPlayerClient* web_media_player_client_; |
| 80 WebKit::WebFrame* web_frame_; | 85 WebKit::WebFrame* web_frame_; |
| 81 | 86 |
| 82 // Protects the |decryptor_|. The Decryptor interface specifies that the | 87 // Protects the |decryptor_| and |pending_decrypt_closures_|. Note that |
| 83 // Decrypt() function will be called on the decoder thread and all other | 88 // |decryptor_| itself should be thread safe as per the Decryptor interface. |
| 84 // methods on the renderer thread. The |decryptor_| itself is thread safe | 89 base::Lock lock_; |
| 85 // when this rule is obeyed. This lock is solely to prevent the race condition | 90 scoped_ptr<media::Decryptor> decryptor_; |
| 86 // between setting the |decryptor_| in GenerateKeyRequest() and using it in | |
| 87 // Decrypt(). | |
| 88 base::Lock decryptor_lock_; | |
| 89 scoped_ptr<media::Decryptor> decryptor_; // Protected by the |lock_|. | |
| 90 | |
| 91 // Protects the |pending_decrypt_closures_|. | |
| 92 base::Lock pending_decrypt_closures_lock_; | |
| 93 std::vector<base::Closure> pending_decrypt_closures_; | 91 std::vector<base::Closure> pending_decrypt_closures_; |
| 92 bool is_shutting_down_; | |
|
scherkus (not reviewing)
2012/08/02 18:05:32
nit: use stopped_ instead
xhwang
2012/08/03 20:08:10
Done.
| |
| 94 | 93 |
| 95 DISALLOW_COPY_AND_ASSIGN(ProxyDecryptor); | 94 DISALLOW_COPY_AND_ASSIGN(ProxyDecryptor); |
| 96 }; | 95 }; |
| 97 | 96 |
| 98 } // namespace webkit_media | 97 } // namespace webkit_media |
| 99 | 98 |
| 100 #endif // WEBKIT_MEDIA_CRYPTO_PROXY_DECRYPTOR_H_ | 99 #endif // WEBKIT_MEDIA_CRYPTO_PROXY_DECRYPTOR_H_ |
| OLD | NEW |