| 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 CONTENT_RENDERER_MEDIA_CRYPTO_PPAPI_DECRYPTOR_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_CRYPTO_PPAPI_DECRYPTOR_H_ |
| 6 #define CONTENT_RENDERER_MEDIA_CRYPTO_PPAPI_DECRYPTOR_H_ | 6 #define CONTENT_RENDERER_MEDIA_CRYPTO_PPAPI_DECRYPTOR_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "content/renderer/media/crypto/pepper_cdm_wrapper.h" | 14 #include "content/renderer/media/crypto/pepper_cdm_wrapper.h" |
| 15 #include "media/base/decryptor.h" | 15 #include "media/base/decryptor.h" |
| 16 #include "media/base/media_keys.h" | 16 #include "media/base/media_keys.h" |
| 17 #include "media/base/media_keys_session_promise.h" |
| 17 #include "media/base/video_decoder_config.h" | 18 #include "media/base/video_decoder_config.h" |
| 18 | 19 |
| 19 class GURL; | 20 class GURL; |
| 20 | 21 |
| 21 namespace base { | 22 namespace base { |
| 22 class MessageLoopProxy; | 23 class MessageLoopProxy; |
| 23 } | 24 } |
| 24 | 25 |
| 25 namespace content { | 26 namespace content { |
| 26 class ContentDecryptorDelegate; | 27 class ContentDecryptorDelegate; |
| 27 class PepperPluginInstanceImpl; | 28 class PepperPluginInstanceImpl; |
| 28 | 29 |
| 29 // PpapiDecryptor implements media::MediaKeys and media::Decryptor and forwards | 30 // PpapiDecryptor implements media::MediaKeys and media::Decryptor and forwards |
| 30 // all calls to the PluginInstance. | 31 // all calls to the PluginInstance. |
| 31 // This class should always be created & destroyed on the main renderer thread. | 32 // This class should always be created & destroyed on the main renderer thread. |
| 32 class PpapiDecryptor : public media::MediaKeys, public media::Decryptor { | 33 class PpapiDecryptor : public media::MediaKeys, public media::Decryptor { |
| 33 public: | 34 public: |
| 34 static scoped_ptr<PpapiDecryptor> Create( | 35 static scoped_ptr<PpapiDecryptor> Create( |
| 35 const std::string& key_system, | 36 const std::string& key_system, |
| 36 const GURL& security_origin, | 37 const GURL& security_origin, |
| 37 const CreatePepperCdmCB& create_pepper_cdm_cb, | 38 const CreatePepperCdmCB& create_pepper_cdm_cb, |
| 38 const media::SessionCreatedCB& session_created_cb, | |
| 39 const media::SessionMessageCB& session_message_cb, | 39 const media::SessionMessageCB& session_message_cb, |
| 40 const media::SessionReadyCB& session_ready_cb, | 40 const media::SessionReadyCB& session_ready_cb, |
| 41 const media::SessionClosedCB& session_closed_cb, | 41 const media::SessionClosedCB& session_closed_cb, |
| 42 const media::SessionErrorCB& session_error_cb); | 42 const media::SessionErrorCB& session_error_cb); |
| 43 | 43 |
| 44 virtual ~PpapiDecryptor(); | 44 virtual ~PpapiDecryptor(); |
| 45 | 45 |
| 46 // media::MediaKeys implementation. | 46 // media::MediaKeys implementation. |
| 47 virtual bool CreateSession(uint32 session_id, | 47 virtual void CreateSession( |
| 48 const std::string& content_type, | 48 const std::string& init_data_type, |
| 49 const uint8* init_data, | 49 const uint8* init_data, |
| 50 int init_data_length) OVERRIDE; | 50 int init_data_length, |
| 51 virtual void LoadSession(uint32 session_id, | 51 SessionType session_type, |
| 52 const std::string& web_session_id) OVERRIDE; | 52 scoped_ptr<media::MediaKeysSessionPromise> promise) OVERRIDE; |
| 53 virtual void UpdateSession(uint32 session_id, | 53 virtual void LoadSession( |
| 54 const uint8* response, | 54 const std::string& web_session_id, |
| 55 int response_length) OVERRIDE; | 55 scoped_ptr<media::MediaKeysSessionPromise> promise) OVERRIDE; |
| 56 virtual void ReleaseSession(uint32 session_id) OVERRIDE; | 56 virtual void UpdateSession( |
| 57 const std::string& web_session_id, |
| 58 const uint8* response, |
| 59 int response_length, |
| 60 scoped_ptr<media::MediaKeysSessionPromise> promise) OVERRIDE; |
| 61 virtual void ReleaseSession( |
| 62 const std::string& web_session_id, |
| 63 scoped_ptr<media::MediaKeysSessionPromise> promise) OVERRIDE; |
| 57 virtual Decryptor* GetDecryptor() OVERRIDE; | 64 virtual Decryptor* GetDecryptor() OVERRIDE; |
| 58 | 65 |
| 59 // media::Decryptor implementation. | 66 // media::Decryptor implementation. |
| 60 virtual void RegisterNewKeyCB(StreamType stream_type, | 67 virtual void RegisterNewKeyCB(StreamType stream_type, |
| 61 const NewKeyCB& key_added_cb) OVERRIDE; | 68 const NewKeyCB& key_added_cb) OVERRIDE; |
| 62 virtual void Decrypt(StreamType stream_type, | 69 virtual void Decrypt(StreamType stream_type, |
| 63 const scoped_refptr<media::DecoderBuffer>& encrypted, | 70 const scoped_refptr<media::DecoderBuffer>& encrypted, |
| 64 const DecryptCB& decrypt_cb) OVERRIDE; | 71 const DecryptCB& decrypt_cb) OVERRIDE; |
| 65 virtual void CancelDecrypt(StreamType stream_type) OVERRIDE; | 72 virtual void CancelDecrypt(StreamType stream_type) OVERRIDE; |
| 66 virtual void InitializeAudioDecoder(const media::AudioDecoderConfig& config, | 73 virtual void InitializeAudioDecoder(const media::AudioDecoderConfig& config, |
| 67 const DecoderInitCB& init_cb) OVERRIDE; | 74 const DecoderInitCB& init_cb) OVERRIDE; |
| 68 virtual void InitializeVideoDecoder(const media::VideoDecoderConfig& config, | 75 virtual void InitializeVideoDecoder(const media::VideoDecoderConfig& config, |
| 69 const DecoderInitCB& init_cb) OVERRIDE; | 76 const DecoderInitCB& init_cb) OVERRIDE; |
| 70 virtual void DecryptAndDecodeAudio( | 77 virtual void DecryptAndDecodeAudio( |
| 71 const scoped_refptr<media::DecoderBuffer>& encrypted, | 78 const scoped_refptr<media::DecoderBuffer>& encrypted, |
| 72 const AudioDecodeCB& audio_decode_cb) OVERRIDE; | 79 const AudioDecodeCB& audio_decode_cb) OVERRIDE; |
| 73 virtual void DecryptAndDecodeVideo( | 80 virtual void DecryptAndDecodeVideo( |
| 74 const scoped_refptr<media::DecoderBuffer>& encrypted, | 81 const scoped_refptr<media::DecoderBuffer>& encrypted, |
| 75 const VideoDecodeCB& video_decode_cb) OVERRIDE; | 82 const VideoDecodeCB& video_decode_cb) OVERRIDE; |
| 76 virtual void ResetDecoder(StreamType stream_type) OVERRIDE; | 83 virtual void ResetDecoder(StreamType stream_type) OVERRIDE; |
| 77 virtual void DeinitializeDecoder(StreamType stream_type) OVERRIDE; | 84 virtual void DeinitializeDecoder(StreamType stream_type) OVERRIDE; |
| 78 | 85 |
| 79 private: | 86 private: |
| 80 PpapiDecryptor(const std::string& key_system, | 87 PpapiDecryptor(const std::string& key_system, |
| 81 scoped_ptr<PepperCdmWrapper> pepper_cdm_wrapper, | 88 scoped_ptr<PepperCdmWrapper> pepper_cdm_wrapper, |
| 82 const media::SessionCreatedCB& session_created_cb, | |
| 83 const media::SessionMessageCB& session_message_cb, | 89 const media::SessionMessageCB& session_message_cb, |
| 84 const media::SessionReadyCB& session_ready_cb, | 90 const media::SessionReadyCB& session_ready_cb, |
| 85 const media::SessionClosedCB& session_closed_cb, | 91 const media::SessionClosedCB& session_closed_cb, |
| 86 const media::SessionErrorCB& session_error_cb); | 92 const media::SessionErrorCB& session_error_cb); |
| 87 | 93 |
| 88 void ReportFailureToCallPlugin(uint32 session_id); | |
| 89 | |
| 90 void OnDecoderInitialized(StreamType stream_type, bool success); | 94 void OnDecoderInitialized(StreamType stream_type, bool success); |
| 91 | 95 |
| 92 // Callbacks for |plugin_cdm_delegate_| to fire session events. | 96 // Callbacks for |plugin_cdm_delegate_| to fire session events. |
| 93 void OnSessionCreated(uint32 session_id, const std::string& web_session_id); | 97 void OnSessionMessage(const std::string& web_session_id, |
| 94 void OnSessionMessage(uint32 session_id, | |
| 95 const std::vector<uint8>& message, | 98 const std::vector<uint8>& message, |
| 96 const std::string& destination_url); | 99 const std::string& destination_url); |
| 97 void OnSessionReady(uint32 session_id); | 100 void OnSessionReady(const std::string& web_session_id); |
| 98 void OnSessionClosed(uint32 session_id); | 101 void OnSessionClosed(const std::string& web_session_id); |
| 99 void OnSessionError(uint32 session_id, | 102 void OnSessionError(const std::string& web_session_id, |
| 100 media::MediaKeys::KeyError error_code, | 103 const std::string& error_name, |
| 101 uint32 system_code); | 104 uint32 system_code, |
| 105 const std::string& error_description); |
| 106 |
| 107 // On a successful Update() or SessionReady event, trigger playback to resume. |
| 108 void ResumePlayback(); |
| 102 | 109 |
| 103 // Callback to notify that a fatal error happened in |plugin_cdm_delegate_|. | 110 // Callback to notify that a fatal error happened in |plugin_cdm_delegate_|. |
| 104 // The error is terminal and |plugin_cdm_delegate_| should not be used after | 111 // The error is terminal and |plugin_cdm_delegate_| should not be used after |
| 105 // this call. | 112 // this call. |
| 106 void OnFatalPluginError(); | 113 void OnFatalPluginError(); |
| 107 | 114 |
| 108 ContentDecryptorDelegate* CdmDelegate(); | 115 ContentDecryptorDelegate* CdmDelegate(); |
| 109 | 116 |
| 110 // Hold a reference of the Pepper CDM wrapper to make sure the plugin lives | 117 // Hold a reference of the Pepper CDM wrapper to make sure the plugin lives |
| 111 // as long as needed. | 118 // as long as needed. |
| 112 scoped_ptr<PepperCdmWrapper> pepper_cdm_wrapper_; | 119 scoped_ptr<PepperCdmWrapper> pepper_cdm_wrapper_; |
| 113 | 120 |
| 114 // Callbacks for firing session events. | 121 // Callbacks for firing session events. |
| 115 media::SessionCreatedCB session_created_cb_; | |
| 116 media::SessionMessageCB session_message_cb_; | 122 media::SessionMessageCB session_message_cb_; |
| 117 media::SessionReadyCB session_ready_cb_; | 123 media::SessionReadyCB session_ready_cb_; |
| 118 media::SessionClosedCB session_closed_cb_; | 124 media::SessionClosedCB session_closed_cb_; |
| 119 media::SessionErrorCB session_error_cb_; | 125 media::SessionErrorCB session_error_cb_; |
| 120 | 126 |
| 121 scoped_refptr<base::MessageLoopProxy> render_loop_proxy_; | 127 scoped_refptr<base::MessageLoopProxy> render_loop_proxy_; |
| 122 | 128 |
| 123 DecoderInitCB audio_decoder_init_cb_; | 129 DecoderInitCB audio_decoder_init_cb_; |
| 124 DecoderInitCB video_decoder_init_cb_; | 130 DecoderInitCB video_decoder_init_cb_; |
| 125 NewKeyCB new_audio_key_cb_; | 131 NewKeyCB new_audio_key_cb_; |
| 126 NewKeyCB new_video_key_cb_; | 132 NewKeyCB new_video_key_cb_; |
| 127 | 133 |
| 128 // NOTE: Weak pointers must be invalidated before all other member variables. | 134 // NOTE: Weak pointers must be invalidated before all other member variables. |
| 129 base::WeakPtrFactory<PpapiDecryptor> weak_ptr_factory_; | 135 base::WeakPtrFactory<PpapiDecryptor> weak_ptr_factory_; |
| 130 | 136 |
| 131 DISALLOW_COPY_AND_ASSIGN(PpapiDecryptor); | 137 DISALLOW_COPY_AND_ASSIGN(PpapiDecryptor); |
| 132 }; | 138 }; |
| 133 | 139 |
| 134 } // namespace content | 140 } // namespace content |
| 135 | 141 |
| 136 #endif // CONTENT_RENDERER_MEDIA_CRYPTO_PPAPI_DECRYPTOR_H_ | 142 #endif // CONTENT_RENDERER_MEDIA_CRYPTO_PPAPI_DECRYPTOR_H_ |
| OLD | NEW |