| 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 #include "webkit/media/crypto/key_systems.h" |
| 13 | 14 |
| 14 namespace media { | 15 namespace media { |
| 15 class DecryptorClient; | 16 class DecryptorClient; |
| 16 } | 17 } |
| 17 | 18 |
| 18 namespace webkit_media { | 19 namespace webkit_media { |
| 19 | 20 |
| 20 // A decryptor proxy that creates a real decryptor object on demand and | 21 // A decryptor proxy that creates a real decryptor object on demand and |
| 21 // forwards decryptor calls to it. | 22 // forwards decryptor calls to it. |
| 22 // TODO(xhwang): Currently we don't support run-time switching among decryptor | 23 // TODO(xhwang): Currently we don't support run-time switching among decryptor |
| 23 // objects. Fix this when needed. | 24 // objects. Fix this when needed. |
| 24 class ProxyDecryptor : public media::Decryptor { | 25 class ProxyDecryptor : public media::Decryptor { |
| 25 public: | 26 public: |
| 26 explicit ProxyDecryptor(media::DecryptorClient* client); | 27 explicit ProxyDecryptor(media::DecryptorClient* client, |
| 28 const CreatePluginCB& create_plugin_cb); |
| 27 virtual ~ProxyDecryptor(); | 29 virtual ~ProxyDecryptor(); |
| 28 | 30 |
| 29 // media::Decryptor implementation. | 31 // media::Decryptor implementation. |
| 30 virtual void GenerateKeyRequest(const std::string& key_system, | 32 virtual void GenerateKeyRequest(const std::string& key_system, |
| 31 const uint8* init_data, | 33 const uint8* init_data, |
| 32 int init_data_length) OVERRIDE; | 34 int init_data_length) OVERRIDE; |
| 33 virtual void AddKey(const std::string& key_system, | 35 virtual void AddKey(const std::string& key_system, |
| 34 const uint8* key, | 36 const uint8* key, |
| 35 int key_length, | 37 int key_length, |
| 36 const uint8* init_data, | 38 const uint8* init_data, |
| 37 int init_data_length, | 39 int init_data_length, |
| 38 const std::string& session_id) OVERRIDE; | 40 const std::string& session_id) OVERRIDE; |
| 39 virtual void CancelKeyRequest(const std::string& key_system, | 41 virtual void CancelKeyRequest(const std::string& key_system, |
| 40 const std::string& session_id) OVERRIDE; | 42 const std::string& session_id) OVERRIDE; |
| 41 virtual void Decrypt(const scoped_refptr<media::DecoderBuffer>& encrypted, | 43 virtual void Decrypt(const scoped_refptr<media::DecoderBuffer>& encrypted, |
| 42 const DecryptCB& decrypt_cb) OVERRIDE; | 44 const DecryptCB& decrypt_cb) OVERRIDE; |
| 43 | 45 |
| 44 private: | 46 private: |
| 45 media::DecryptorClient* const client_; | 47 media::DecryptorClient* const client_; |
| 48 CreatePluginCB create_plugin_cb_; |
| 46 // Protects the |decryptor_|. The Decryptor interface specifies that the | 49 // Protects the |decryptor_|. The Decryptor interface specifies that the |
| 47 // Decrypt() function will be called on the decoder thread and all other | 50 // Decrypt() function will be called on the decoder thread and all other |
| 48 // methods on the renderer thread. The |decryptor_| itself is thread safe | 51 // 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 | 52 // 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 | 53 // between setting the |decryptor_| in GenerateKeyRequest() and using it in |
| 51 // Decrypt(). | 54 // Decrypt(). |
| 52 base::Lock lock_; | 55 base::Lock lock_; |
| 53 scoped_ptr<media::Decryptor> decryptor_; // Protected by the |lock_|. | 56 scoped_ptr<media::Decryptor> decryptor_; // Protected by the |lock_|. |
| 54 | 57 |
| 55 DISALLOW_COPY_AND_ASSIGN(ProxyDecryptor); | 58 DISALLOW_COPY_AND_ASSIGN(ProxyDecryptor); |
| 56 }; | 59 }; |
| 57 | 60 |
| 58 } // namespace webkit_media | 61 } // namespace webkit_media |
| 59 | 62 |
| 60 #endif // WEBKIT_MEDIA_CRYPTO_PROXY_DECRYPTOR_H_ | 63 #endif // WEBKIT_MEDIA_CRYPTO_PROXY_DECRYPTOR_H_ |
| OLD | NEW |