| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_RENDERER_MEDIA_CRYPTO_PPAPI_DECRYPTOR_H_ | 5 #ifndef WEBKIT_RENDERER_MEDIA_CRYPTO_PPAPI_DECRYPTOR_H_ |
| 6 #define WEBKIT_RENDERER_MEDIA_CRYPTO_PPAPI_DECRYPTOR_H_ | 6 #define WEBKIT_RENDERER_MEDIA_CRYPTO_PPAPI_DECRYPTOR_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 } | 24 } |
| 25 } | 25 } |
| 26 | 26 |
| 27 namespace webkit_media { | 27 namespace webkit_media { |
| 28 | 28 |
| 29 // PpapiDecryptor implements media::Decryptor and forwards all calls to the | 29 // PpapiDecryptor implements media::Decryptor and forwards all calls to the |
| 30 // PluginInstance. | 30 // PluginInstance. |
| 31 // This class should always be created & destroyed on the main renderer thread. | 31 // This class should always be created & destroyed on the main renderer thread. |
| 32 class PpapiDecryptor : public media::MediaKeys, public media::Decryptor { | 32 class PpapiDecryptor : public media::MediaKeys, public media::Decryptor { |
| 33 public: | 33 public: |
| 34 PpapiDecryptor( | 34 static scoped_ptr<webkit_media::PpapiDecryptor> Create( |
| 35 // TODO(ddorwin): Remove after updating the delegate. |
| 36 const std::string& key_system, |
| 35 const scoped_refptr<webkit::ppapi::PluginInstance>& plugin_instance, | 37 const scoped_refptr<webkit::ppapi::PluginInstance>& plugin_instance, |
| 36 const media::KeyAddedCB& key_added_cb, | 38 const media::KeyAddedCB& key_added_cb, |
| 37 const media::KeyErrorCB& key_error_cb, | 39 const media::KeyErrorCB& key_error_cb, |
| 38 const media::KeyMessageCB& key_message_cb, | 40 const media::KeyMessageCB& key_message_cb, |
| 39 const media::NeedKeyCB& need_key_cb, | 41 const media::NeedKeyCB& need_key_cb, |
| 40 const base::Closure& destroy_plugin_cb); | 42 const base::Closure& destroy_plugin_cb); |
| 43 |
| 41 virtual ~PpapiDecryptor(); | 44 virtual ~PpapiDecryptor(); |
| 42 | 45 |
| 43 // media::MediaKeys implementation. | 46 // media::MediaKeys implementation. |
| 44 virtual bool GenerateKeyRequest(const std::string& key_system, | 47 virtual bool GenerateKeyRequest(const std::string& type, |
| 45 const std::string& type, | |
| 46 const uint8* init_data, | 48 const uint8* init_data, |
| 47 int init_data_length) OVERRIDE; | 49 int init_data_length) OVERRIDE; |
| 48 virtual void AddKey(const std::string& key_system, | 50 virtual void AddKey(const uint8* key, int key_length, |
| 49 const uint8* key, int key_length, | |
| 50 const uint8* init_data, int init_data_length, | 51 const uint8* init_data, int init_data_length, |
| 51 const std::string& session_id) OVERRIDE; | 52 const std::string& session_id) OVERRIDE; |
| 52 virtual void CancelKeyRequest(const std::string& key_system, | 53 virtual void CancelKeyRequest(const std::string& session_id) OVERRIDE; |
| 53 const std::string& session_id) OVERRIDE; | |
| 54 | 54 |
| 55 // media::Decryptor implementation. | 55 // media::Decryptor implementation. |
| 56 virtual media::MediaKeys* GetMediaKeys() OVERRIDE; | 56 virtual media::MediaKeys* GetMediaKeys() OVERRIDE; |
| 57 virtual void RegisterNewKeyCB(StreamType stream_type, | 57 virtual void RegisterNewKeyCB(StreamType stream_type, |
| 58 const NewKeyCB& key_added_cb) OVERRIDE; | 58 const NewKeyCB& key_added_cb) OVERRIDE; |
| 59 virtual void Decrypt(StreamType stream_type, | 59 virtual void Decrypt(StreamType stream_type, |
| 60 const scoped_refptr<media::DecoderBuffer>& encrypted, | 60 const scoped_refptr<media::DecoderBuffer>& encrypted, |
| 61 const DecryptCB& decrypt_cb) OVERRIDE; | 61 const DecryptCB& decrypt_cb) OVERRIDE; |
| 62 virtual void CancelDecrypt(StreamType stream_type) OVERRIDE; | 62 virtual void CancelDecrypt(StreamType stream_type) OVERRIDE; |
| 63 virtual void InitializeAudioDecoder(const media::AudioDecoderConfig& config, | 63 virtual void InitializeAudioDecoder(const media::AudioDecoderConfig& config, |
| 64 const DecoderInitCB& init_cb) OVERRIDE; | 64 const DecoderInitCB& init_cb) OVERRIDE; |
| 65 virtual void InitializeVideoDecoder(const media::VideoDecoderConfig& config, | 65 virtual void InitializeVideoDecoder(const media::VideoDecoderConfig& config, |
| 66 const DecoderInitCB& init_cb) OVERRIDE; | 66 const DecoderInitCB& init_cb) OVERRIDE; |
| 67 virtual void DecryptAndDecodeAudio( | 67 virtual void DecryptAndDecodeAudio( |
| 68 const scoped_refptr<media::DecoderBuffer>& encrypted, | 68 const scoped_refptr<media::DecoderBuffer>& encrypted, |
| 69 const AudioDecodeCB& audio_decode_cb) OVERRIDE; | 69 const AudioDecodeCB& audio_decode_cb) OVERRIDE; |
| 70 virtual void DecryptAndDecodeVideo( | 70 virtual void DecryptAndDecodeVideo( |
| 71 const scoped_refptr<media::DecoderBuffer>& encrypted, | 71 const scoped_refptr<media::DecoderBuffer>& encrypted, |
| 72 const VideoDecodeCB& video_decode_cb) OVERRIDE; | 72 const VideoDecodeCB& video_decode_cb) OVERRIDE; |
| 73 virtual void ResetDecoder(StreamType stream_type) OVERRIDE; | 73 virtual void ResetDecoder(StreamType stream_type) OVERRIDE; |
| 74 virtual void DeinitializeDecoder(StreamType stream_type) OVERRIDE; | 74 virtual void DeinitializeDecoder(StreamType stream_type) OVERRIDE; |
| 75 | 75 |
| 76 private: | 76 private: |
| 77 void ReportFailureToCallPlugin(const std::string& key_system, | 77 PpapiDecryptor( |
| 78 const std::string& session_id); | 78 const scoped_refptr<webkit::ppapi::PluginInstance>& plugin_instance, |
| 79 webkit::ppapi::ContentDecryptorDelegate* plugin_cdm_delegate, |
| 80 const media::KeyAddedCB& key_added_cb, |
| 81 const media::KeyErrorCB& key_error_cb, |
| 82 const media::KeyMessageCB& key_message_cb, |
| 83 const media::NeedKeyCB& need_key_cb, |
| 84 const base::Closure& destroy_plugin_cb); |
| 85 |
| 86 void ReportFailureToCallPlugin(const std::string& session_id); |
| 79 | 87 |
| 80 void OnDecoderInitialized(StreamType stream_type, bool success); | 88 void OnDecoderInitialized(StreamType stream_type, bool success); |
| 81 | 89 |
| 82 // Callbacks for |plugin_cdm_delegate_| to fire key events. | 90 // Callbacks for |plugin_cdm_delegate_| to fire key events. |
| 83 void KeyAdded(const std::string& key_system, const std::string& session_id); | 91 void KeyAdded(const std::string& session_id); |
| 84 void KeyError(const std::string& key_system, | 92 void KeyError(const std::string& session_id, |
| 85 const std::string& session_id, | |
| 86 media::MediaKeys::KeyError error_code, | 93 media::MediaKeys::KeyError error_code, |
| 87 int system_code); | 94 int system_code); |
| 88 void KeyMessage(const std::string& key_system, | 95 void KeyMessage(const std::string& session_id, |
| 89 const std::string& session_id, | |
| 90 const std::string& message, | 96 const std::string& message, |
| 91 const std::string& default_url); | 97 const std::string& default_url); |
| 92 void NeedKey(const std::string& key_system, | 98 void NeedKey(const std::string& session_id, |
| 93 const std::string& session_id, | |
| 94 const std::string& type, | 99 const std::string& type, |
| 95 scoped_ptr<uint8[]> init_data, int init_data_size); | 100 scoped_ptr<uint8[]> init_data, int init_data_size); |
| 96 | 101 |
| 97 // Hold a reference of the plugin instance to make sure the plugin outlives | 102 // Hold a reference of the plugin instance to make sure the plugin outlives |
| 98 // the |plugin_cdm_delegate_|. This is needed because |plugin_cdm_delegate_| | 103 // the |plugin_cdm_delegate_|. This is needed because |plugin_cdm_delegate_| |
| 99 // is owned by the |plugin_instance_|. | 104 // is owned by the |plugin_instance_|. |
| 100 scoped_refptr<webkit::ppapi::PluginInstance> plugin_instance_; | 105 scoped_refptr<webkit::ppapi::PluginInstance> plugin_instance_; |
| 101 | 106 |
| 107 webkit::ppapi::ContentDecryptorDelegate* plugin_cdm_delegate_; |
| 108 |
| 102 // Callbacks for firing key events. | 109 // Callbacks for firing key events. |
| 103 media::KeyAddedCB key_added_cb_; | 110 media::KeyAddedCB key_added_cb_; |
| 104 media::KeyErrorCB key_error_cb_; | 111 media::KeyErrorCB key_error_cb_; |
| 105 media::KeyMessageCB key_message_cb_; | 112 media::KeyMessageCB key_message_cb_; |
| 106 media::NeedKeyCB need_key_cb_; | 113 media::NeedKeyCB need_key_cb_; |
| 107 | 114 |
| 108 // Called to destroy the helper plugin when this class no longer needs it. | 115 // Called to destroy the helper plugin when this class no longer needs it. |
| 109 base::Closure destroy_plugin_cb_; | 116 base::Closure destroy_plugin_cb_; |
| 110 | 117 |
| 111 webkit::ppapi::ContentDecryptorDelegate* plugin_cdm_delegate_; | |
| 112 | |
| 113 scoped_refptr<base::MessageLoopProxy> render_loop_proxy_; | 118 scoped_refptr<base::MessageLoopProxy> render_loop_proxy_; |
| 114 | 119 |
| 115 DecoderInitCB audio_decoder_init_cb_; | 120 DecoderInitCB audio_decoder_init_cb_; |
| 116 DecoderInitCB video_decoder_init_cb_; | 121 DecoderInitCB video_decoder_init_cb_; |
| 117 NewKeyCB new_audio_key_cb_; | 122 NewKeyCB new_audio_key_cb_; |
| 118 NewKeyCB new_video_key_cb_; | 123 NewKeyCB new_video_key_cb_; |
| 119 | 124 |
| 120 base::WeakPtrFactory<PpapiDecryptor> weak_ptr_factory_; | 125 base::WeakPtrFactory<PpapiDecryptor> weak_ptr_factory_; |
| 121 base::WeakPtr<PpapiDecryptor> weak_this_; | 126 base::WeakPtr<PpapiDecryptor> weak_this_; |
| 122 | 127 |
| 123 DISALLOW_COPY_AND_ASSIGN(PpapiDecryptor); | 128 DISALLOW_COPY_AND_ASSIGN(PpapiDecryptor); |
| 124 }; | 129 }; |
| 125 | 130 |
| 126 } // namespace webkit_media | 131 } // namespace webkit_media |
| 127 | 132 |
| 128 #endif // WEBKIT_RENDERER_MEDIA_CRYPTO_PPAPI_DECRYPTOR_H_ | 133 #endif // WEBKIT_RENDERER_MEDIA_CRYPTO_PPAPI_DECRYPTOR_H_ |
| OLD | NEW |