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 class MessageLoop; |
| 16 |
14 namespace media { | 17 namespace media { |
15 class DecryptorClient; | 18 class DecryptorClient; |
16 } | 19 } |
17 | 20 |
18 namespace WebKit { | 21 namespace WebKit { |
19 class WebFrame; | 22 class WebFrame; |
20 class WebMediaPlayerClient; | 23 class WebMediaPlayerClient; |
21 } | 24 } |
22 | 25 |
23 namespace webkit_media { | 26 namespace webkit_media { |
(...skipping 22 matching lines...) Expand all Loading... |
46 virtual void CancelKeyRequest(const std::string& key_system, | 49 virtual void CancelKeyRequest(const std::string& key_system, |
47 const std::string& session_id) OVERRIDE; | 50 const std::string& session_id) OVERRIDE; |
48 virtual void Decrypt(const scoped_refptr<media::DecoderBuffer>& encrypted, | 51 virtual void Decrypt(const scoped_refptr<media::DecoderBuffer>& encrypted, |
49 const DecryptCB& decrypt_cb) OVERRIDE; | 52 const DecryptCB& decrypt_cb) OVERRIDE; |
50 | 53 |
51 private: | 54 private: |
52 scoped_ptr<media::Decryptor> CreatePpapiDecryptor( | 55 scoped_ptr<media::Decryptor> CreatePpapiDecryptor( |
53 const std::string& key_system); | 56 const std::string& key_system); |
54 scoped_ptr<media::Decryptor> CreateDecryptor(const std::string& key_system); | 57 scoped_ptr<media::Decryptor> CreateDecryptor(const std::string& key_system); |
55 | 58 |
| 59 // Helper function that makes sure decryptor_->Decrypt() runs on the |
| 60 // |message_loop|. |
| 61 void DecryptOnMessageLoop( |
| 62 MessageLoop* message_loop, |
| 63 const scoped_refptr<media::DecoderBuffer>& encrypted, |
| 64 const media::Decryptor::DecryptCB& decrypt_cb); |
| 65 |
| 66 // Callback used to pass into decryptor_->Decrypt(). |
| 67 void OnBufferDecrypted(MessageLoop* message_loop, |
| 68 const scoped_refptr<media::DecoderBuffer>& encrypted, |
| 69 const media::Decryptor::DecryptCB& decrypt_cb, |
| 70 media::Decryptor::DecryptStatus status, |
| 71 const scoped_refptr<media::DecoderBuffer>& decrypted); |
| 72 |
56 media::DecryptorClient* client_; | 73 media::DecryptorClient* client_; |
57 | 74 |
58 // Needed to create the PpapiDecryptor. | 75 // Needed to create the PpapiDecryptor. |
59 WebKit::WebMediaPlayerClient* web_media_player_client_; | 76 WebKit::WebMediaPlayerClient* web_media_player_client_; |
60 WebKit::WebFrame* web_frame_; | 77 WebKit::WebFrame* web_frame_; |
61 | 78 |
62 // Protects the |decryptor_|. The Decryptor interface specifies that the | 79 // Protects the |decryptor_|. The Decryptor interface specifies that the |
63 // Decrypt() function will be called on the decoder thread and all other | 80 // Decrypt() function will be called on the decoder thread and all other |
64 // methods on the renderer thread. The |decryptor_| itself is thread safe | 81 // 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 | 82 // 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 | 83 // between setting the |decryptor_| in GenerateKeyRequest() and using it in |
67 // Decrypt(). | 84 // Decrypt(). |
68 base::Lock lock_; | 85 base::Lock decryptor_lock_; |
69 scoped_ptr<media::Decryptor> decryptor_; // Protected by the |lock_|. | 86 scoped_ptr<media::Decryptor> decryptor_; // Protected by the |lock_|. |
70 | 87 |
| 88 // Protects the |pending_decrypt_closures_|. |
| 89 base::Lock pending_decrypt_closures_lock_; |
| 90 std::vector<base::Closure> pending_decrypt_closures_; |
| 91 |
71 DISALLOW_COPY_AND_ASSIGN(ProxyDecryptor); | 92 DISALLOW_COPY_AND_ASSIGN(ProxyDecryptor); |
72 }; | 93 }; |
73 | 94 |
74 } // namespace webkit_media | 95 } // namespace webkit_media |
75 | 96 |
76 #endif // WEBKIT_MEDIA_CRYPTO_PROXY_DECRYPTOR_H_ | 97 #endif // WEBKIT_MEDIA_CRYPTO_PROXY_DECRYPTOR_H_ |
OLD | NEW |