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 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/synchronization/lock.h" | 11 #include "base/synchronization/lock.h" |
12 #include "media/base/decryptor.h" | 12 #include "media/base/decryptor.h" |
13 | 13 |
14 namespace media { | 14 namespace media { |
15 class DecryptorClient; | 15 class DecryptorClient; |
16 } | 16 } |
17 | 17 |
| 18 namespace WebKit { |
| 19 class WebFrame; |
| 20 class WebMediaPlayerClient; |
| 21 } |
| 22 |
18 namespace webkit_media { | 23 namespace webkit_media { |
19 | 24 |
20 // A decryptor proxy that creates a real decryptor object on demand and | 25 // A decryptor proxy that creates a real decryptor object on demand and |
21 // forwards decryptor calls to it. | 26 // forwards decryptor calls to it. |
22 // TODO(xhwang): Currently we don't support run-time switching among decryptor | 27 // TODO(xhwang): Currently we don't support run-time switching among decryptor |
23 // objects. Fix this when needed. | 28 // objects. Fix this when needed. |
24 class ProxyDecryptor : public media::Decryptor { | 29 class ProxyDecryptor : public media::Decryptor { |
25 public: | 30 public: |
26 explicit ProxyDecryptor(media::DecryptorClient* client); | 31 ProxyDecryptor(media::DecryptorClient* decryptor_client, |
| 32 WebKit::WebMediaPlayerClient* web_media_player_client, |
| 33 WebKit::WebFrame* web_frame); |
27 virtual ~ProxyDecryptor(); | 34 virtual ~ProxyDecryptor(); |
28 | 35 |
29 // media::Decryptor implementation. | 36 // media::Decryptor implementation. |
30 virtual void GenerateKeyRequest(const std::string& key_system, | 37 virtual void GenerateKeyRequest(const std::string& key_system, |
31 const uint8* init_data, | 38 const uint8* init_data, |
32 int init_data_length) OVERRIDE; | 39 int init_data_length) OVERRIDE; |
33 virtual void AddKey(const std::string& key_system, | 40 virtual void AddKey(const std::string& key_system, |
34 const uint8* key, | 41 const uint8* key, |
35 int key_length, | 42 int key_length, |
36 const uint8* init_data, | 43 const uint8* init_data, |
37 int init_data_length, | 44 int init_data_length, |
38 const std::string& session_id) OVERRIDE; | 45 const std::string& session_id) OVERRIDE; |
39 virtual void CancelKeyRequest(const std::string& key_system, | 46 virtual void CancelKeyRequest(const std::string& key_system, |
40 const std::string& session_id) OVERRIDE; | 47 const std::string& session_id) OVERRIDE; |
41 virtual void Decrypt(const scoped_refptr<media::DecoderBuffer>& encrypted, | 48 virtual void Decrypt(const scoped_refptr<media::DecoderBuffer>& encrypted, |
42 const DecryptCB& decrypt_cb) OVERRIDE; | 49 const DecryptCB& decrypt_cb) OVERRIDE; |
43 | 50 |
44 private: | 51 private: |
45 media::DecryptorClient* const client_; | 52 scoped_ptr<media::Decryptor> CreatePpapiDecryptor( |
| 53 const std::string& key_system); |
| 54 scoped_ptr<media::Decryptor> CreateDecryptor(const std::string& key_system); |
| 55 |
| 56 media::DecryptorClient* client_; |
| 57 |
| 58 // Needed to create the PpapiDecryptor. |
| 59 WebKit::WebMediaPlayerClient* web_media_player_client_; |
| 60 WebKit::WebFrame* web_frame_; |
| 61 |
46 // Protects the |decryptor_|. The Decryptor interface specifies that the | 62 // Protects the |decryptor_|. The Decryptor interface specifies that the |
47 // Decrypt() function will be called on the decoder thread and all other | 63 // Decrypt() function will be called on the decoder thread and all other |
48 // methods on the renderer thread. The |decryptor_| itself is thread safe | 64 // methods on the renderer thread. The |decryptor_| itself is thread safe |
49 // when this rule is obeyed. This lock is solely to prevent the race condition | 65 // when this rule is obeyed. This lock is solely to prevent the race condition |
50 // between setting the |decryptor_| in GenerateKeyRequest() and using it in | 66 // between setting the |decryptor_| in GenerateKeyRequest() and using it in |
51 // Decrypt(). | 67 // Decrypt(). |
52 base::Lock lock_; | 68 base::Lock lock_; |
53 scoped_ptr<media::Decryptor> decryptor_; // Protected by the |lock_|. | 69 scoped_ptr<media::Decryptor> decryptor_; // Protected by the |lock_|. |
54 | 70 |
55 DISALLOW_COPY_AND_ASSIGN(ProxyDecryptor); | 71 DISALLOW_COPY_AND_ASSIGN(ProxyDecryptor); |
56 }; | 72 }; |
57 | 73 |
58 } // namespace webkit_media | 74 } // namespace webkit_media |
59 | 75 |
60 #endif // WEBKIT_MEDIA_CRYPTO_PROXY_DECRYPTOR_H_ | 76 #endif // WEBKIT_MEDIA_CRYPTO_PROXY_DECRYPTOR_H_ |
OLD | NEW |