Chromium Code Reviews| 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 CONTENT_RENDERER_PEPPER_CONTENT_DECRYPTOR_DELEGATE_H_ | 5 #ifndef CONTENT_RENDERER_PEPPER_CONTENT_DECRYPTOR_DELEGATE_H_ |
| 6 #define CONTENT_RENDERER_PEPPER_CONTENT_DECRYPTOR_DELEGATE_H_ | 6 #define CONTENT_RENDERER_PEPPER_CONTENT_DECRYPTOR_DELEGATE_H_ |
| 7 | 7 |
| 8 #include <map> | |
| 8 #include <queue> | 9 #include <queue> |
| 9 #include <string> | 10 #include <string> |
| 10 | 11 |
| 11 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 12 #include "base/callback_helpers.h" | 13 #include "base/callback_helpers.h" |
| 13 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 14 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 16 #include "media/base/channel_layout.h" | 17 #include "media/base/channel_layout.h" |
| 17 #include "media/base/decryptor.h" | 18 #include "media/base/decryptor.h" |
| 18 #include "media/base/media_keys.h" | 19 #include "media/base/media_keys.h" |
| 20 #include "media/base/media_keys_session_promise.h" | |
| 19 #include "media/base/sample_format.h" | 21 #include "media/base/sample_format.h" |
| 20 #include "ppapi/c/private/pp_content_decryptor.h" | 22 #include "ppapi/c/private/pp_content_decryptor.h" |
| 21 #include "ppapi/c/private/ppp_content_decryptor_private.h" | 23 #include "ppapi/c/private/ppp_content_decryptor_private.h" |
| 22 #include "ui/gfx/size.h" | 24 #include "ui/gfx/size.h" |
| 23 | 25 |
| 24 namespace media { | 26 namespace media { |
| 25 class AudioDecoderConfig; | 27 class AudioDecoderConfig; |
| 26 class DecoderBuffer; | 28 class DecoderBuffer; |
| 27 class VideoDecoderConfig; | 29 class VideoDecoderConfig; |
| 28 } | 30 } |
| 29 | 31 |
| 30 namespace content { | 32 namespace content { |
| 31 | 33 |
| 32 class PPB_Buffer_Impl; | 34 class PPB_Buffer_Impl; |
| 33 | 35 |
| 34 class ContentDecryptorDelegate { | 36 class ContentDecryptorDelegate { |
| 35 public: | 37 public: |
| 36 // ContentDecryptorDelegate does not take ownership of | 38 // ContentDecryptorDelegate does not take ownership of |
| 37 // |plugin_decryption_interface|. Therefore |plugin_decryption_interface| | 39 // |plugin_decryption_interface|. Therefore |plugin_decryption_interface| |
| 38 // must outlive this object. | 40 // must outlive this object. |
| 39 ContentDecryptorDelegate( | 41 ContentDecryptorDelegate( |
| 40 PP_Instance pp_instance, | 42 PP_Instance pp_instance, |
| 41 const PPP_ContentDecryptor_Private* plugin_decryption_interface); | 43 const PPP_ContentDecryptor_Private* plugin_decryption_interface); |
| 42 ~ContentDecryptorDelegate(); | 44 ~ContentDecryptorDelegate(); |
| 43 | 45 |
| 44 // This object should not be accessed after |fatal_plugin_error_cb| is called. | 46 // This object should not be accessed after |fatal_plugin_error_cb| is called. |
| 45 void Initialize(const std::string& key_system, | 47 void Initialize(const std::string& key_system, |
| 46 const media::SessionCreatedCB& session_created_cb, | |
| 47 const media::SessionMessageCB& session_message_cb, | 48 const media::SessionMessageCB& session_message_cb, |
| 48 const media::SessionReadyCB& session_ready_cb, | 49 const media::SessionReadyCB& session_ready_cb, |
| 49 const media::SessionClosedCB& session_closed_cb, | 50 const media::SessionClosedCB& session_closed_cb, |
| 50 const media::SessionErrorCB& session_error_cb, | 51 const media::SessionErrorCB& session_error_cb, |
| 51 const base::Closure& fatal_plugin_error_cb); | 52 const base::Closure& fatal_plugin_error_cb); |
| 52 | 53 |
| 53 void InstanceCrashed(); | 54 void InstanceCrashed(); |
| 54 | 55 |
| 55 // Provides access to PPP_ContentDecryptor_Private. | 56 // Provides access to PPP_ContentDecryptor_Private. |
| 56 bool CreateSession(uint32 session_id, | 57 void CreateSession(const std::string& init_data_type, |
| 57 const std::string& content_type, | |
| 58 const uint8* init_data, | 58 const uint8* init_data, |
| 59 int init_data_length); | 59 int init_data_length, |
| 60 void LoadSession(uint32 session_id, const std::string& web_session_id); | 60 media::MediaKeys::SessionType session_type, |
| 61 bool UpdateSession(uint32 session_id, | 61 scoped_ptr<media::MediaKeysSessionPromise> promise); |
| 62 void LoadSession(const std::string& web_session_id, | |
| 63 scoped_ptr<media::MediaKeysSessionPromise> promise); | |
| 64 void UpdateSession(const std::string& web_session_id, | |
| 62 const uint8* response, | 65 const uint8* response, |
| 63 int response_length); | 66 int response_length, |
| 64 bool ReleaseSession(uint32 session_id); | 67 scoped_ptr<media::MediaKeysSessionPromise> promise); |
| 68 void ReleaseSession(const std::string& web_session_id, | |
| 69 scoped_ptr<media::MediaKeysSessionPromise> promise); | |
| 65 bool Decrypt(media::Decryptor::StreamType stream_type, | 70 bool Decrypt(media::Decryptor::StreamType stream_type, |
| 66 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, | 71 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, |
| 67 const media::Decryptor::DecryptCB& decrypt_cb); | 72 const media::Decryptor::DecryptCB& decrypt_cb); |
| 68 bool CancelDecrypt(media::Decryptor::StreamType stream_type); | 73 bool CancelDecrypt(media::Decryptor::StreamType stream_type); |
| 69 bool InitializeAudioDecoder( | 74 bool InitializeAudioDecoder( |
| 70 const media::AudioDecoderConfig& decoder_config, | 75 const media::AudioDecoderConfig& decoder_config, |
| 71 const media::Decryptor::DecoderInitCB& decoder_init_cb); | 76 const media::Decryptor::DecoderInitCB& decoder_init_cb); |
| 72 bool InitializeVideoDecoder( | 77 bool InitializeVideoDecoder( |
| 73 const media::VideoDecoderConfig& decoder_config, | 78 const media::VideoDecoderConfig& decoder_config, |
| 74 const media::Decryptor::DecoderInitCB& decoder_init_cb); | 79 const media::Decryptor::DecoderInitCB& decoder_init_cb); |
| 75 // TODO(tomfinegan): Add callback args for DeinitializeDecoder() and | 80 // TODO(tomfinegan): Add callback args for DeinitializeDecoder() and |
| 76 // ResetDecoder() | 81 // ResetDecoder() |
| 77 bool DeinitializeDecoder(media::Decryptor::StreamType stream_type); | 82 bool DeinitializeDecoder(media::Decryptor::StreamType stream_type); |
| 78 bool ResetDecoder(media::Decryptor::StreamType stream_type); | 83 bool ResetDecoder(media::Decryptor::StreamType stream_type); |
| 79 // Note: These methods can be used with unencrypted data. | 84 // Note: These methods can be used with unencrypted data. |
| 80 bool DecryptAndDecodeAudio( | 85 bool DecryptAndDecodeAudio( |
| 81 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, | 86 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, |
| 82 const media::Decryptor::AudioDecodeCB& audio_decode_cb); | 87 const media::Decryptor::AudioDecodeCB& audio_decode_cb); |
| 83 bool DecryptAndDecodeVideo( | 88 bool DecryptAndDecodeVideo( |
| 84 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, | 89 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, |
| 85 const media::Decryptor::VideoDecodeCB& video_decode_cb); | 90 const media::Decryptor::VideoDecodeCB& video_decode_cb); |
| 86 | 91 |
| 87 // PPB_ContentDecryptor_Private dispatching methods. | 92 // PPB_ContentDecryptor_Private dispatching methods. |
| 88 void OnSessionCreated(uint32 session_id, PP_Var web_session_id_var); | 93 void OnPromiseResolved(uint32 promise_id); |
| 89 void OnSessionMessage(uint32 session_id, | 94 void OnPromiseResolvedWithSession(uint32 promise_id, |
| 90 PP_Var message, | 95 PP_Var web_session_id_var); |
| 91 PP_Var destination_url); | 96 void OnPromiseRejected(uint32 promise_id, |
| 92 void OnSessionReady(uint32 session_id); | 97 PP_Var error_name_var, |
| 93 void OnSessionClosed(uint32 session_id); | 98 uint32 system_code, |
| 94 void OnSessionError(uint32 session_id, | 99 PP_Var error_description_var); |
| 95 int32_t media_error, | 100 void OnSessionMessage(PP_Var web_session_id_var, |
| 96 uint32_t system_code); | 101 PP_Var message_var, |
| 102 PP_Var destination_url_var); | |
| 103 void OnSessionReady(PP_Var web_session_id_var); | |
| 104 void OnSessionClosed(PP_Var web_session_id_var); | |
| 105 void OnSessionError(PP_Var web_session_id_var, | |
| 106 PP_Var error_name_var, | |
| 107 uint32 system_code, | |
| 108 PP_Var error_description_var); | |
| 97 void DeliverBlock(PP_Resource decrypted_block, | 109 void DeliverBlock(PP_Resource decrypted_block, |
| 98 const PP_DecryptedBlockInfo* block_info); | 110 const PP_DecryptedBlockInfo* block_info); |
| 99 void DecoderInitializeDone(PP_DecryptorStreamType decoder_type, | 111 void DecoderInitializeDone(PP_DecryptorStreamType decoder_type, |
| 100 uint32_t request_id, | 112 uint32_t request_id, |
| 101 PP_Bool success); | 113 PP_Bool success); |
| 102 void DecoderDeinitializeDone(PP_DecryptorStreamType decoder_type, | 114 void DecoderDeinitializeDone(PP_DecryptorStreamType decoder_type, |
| 103 uint32_t request_id); | 115 uint32_t request_id); |
| 104 void DecoderResetDone(PP_DecryptorStreamType decoder_type, | 116 void DecoderResetDone(PP_DecryptorStreamType decoder_type, |
| 105 uint32_t request_id); | 117 uint32_t request_id); |
| 106 void DeliverFrame(PP_Resource decrypted_frame, | 118 void DeliverFrame(PP_Resource decrypted_frame, |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 164 | 176 |
| 165 // Deserializes audio data stored in |audio_frames| into individual audio | 177 // Deserializes audio data stored in |audio_frames| into individual audio |
| 166 // buffers in |frames|. Returns true upon success. | 178 // buffers in |frames|. Returns true upon success. |
| 167 bool DeserializeAudioFrames(PP_Resource audio_frames, | 179 bool DeserializeAudioFrames(PP_Resource audio_frames, |
| 168 size_t data_size, | 180 size_t data_size, |
| 169 media::SampleFormat sample_format, | 181 media::SampleFormat sample_format, |
| 170 media::Decryptor::AudioBuffers* frames); | 182 media::Decryptor::AudioBuffers* frames); |
| 171 | 183 |
| 172 void SatisfyAllPendingCallbacksOnError(); | 184 void SatisfyAllPendingCallbacksOnError(); |
| 173 | 185 |
| 186 // Takes ownership of |promise| and returns an identifier to be passed via | |
| 187 // Pepper. | |
| 188 uint32_t SavePromise(scoped_ptr<media::MediaKeysSessionPromise> promise); | |
| 189 | |
| 190 // Find the promise for a specified |promise_id|. Caller is responsible to | |
| 191 // delete the MediaKeysSessionPromise once done with it. | |
| 192 scoped_ptr<media::MediaKeysSessionPromise> FindPromise(uint32_t promise_id); | |
|
xhwang
2014/05/05 20:46:42
"find" usually doesn't touch the container. Here w
jrummell
2014/05/08 23:37:45
Done.
| |
| 193 | |
| 174 const PP_Instance pp_instance_; | 194 const PP_Instance pp_instance_; |
| 175 const PPP_ContentDecryptor_Private* const plugin_decryption_interface_; | 195 const PPP_ContentDecryptor_Private* const plugin_decryption_interface_; |
| 176 | 196 |
| 177 // TODO(ddorwin): Remove after updating the Pepper API to not use key system. | 197 // TODO(ddorwin): Remove after updating the Pepper API to not use key system. |
| 178 std::string key_system_; | 198 std::string key_system_; |
| 179 | 199 |
| 180 // Callbacks for firing session events. | 200 // Callbacks for firing session events. |
| 181 media::SessionCreatedCB session_created_cb_; | |
| 182 media::SessionMessageCB session_message_cb_; | 201 media::SessionMessageCB session_message_cb_; |
| 183 media::SessionReadyCB session_ready_cb_; | 202 media::SessionReadyCB session_ready_cb_; |
| 184 media::SessionClosedCB session_closed_cb_; | 203 media::SessionClosedCB session_closed_cb_; |
| 185 media::SessionErrorCB session_error_cb_; | 204 media::SessionErrorCB session_error_cb_; |
| 186 | 205 |
| 187 // Callback to notify that unexpected error happened and |this| should not | 206 // Callback to notify that unexpected error happened and |this| should not |
| 188 // be used anymore. | 207 // be used anymore. |
| 189 base::Closure fatal_plugin_error_cb_; | 208 base::Closure fatal_plugin_error_cb_; |
| 190 | 209 |
| 191 gfx::Size natural_size_; | 210 gfx::Size natural_size_; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 207 scoped_refptr<PPB_Buffer_Impl> audio_input_resource_; | 226 scoped_refptr<PPB_Buffer_Impl> audio_input_resource_; |
| 208 scoped_refptr<PPB_Buffer_Impl> video_input_resource_; | 227 scoped_refptr<PPB_Buffer_Impl> video_input_resource_; |
| 209 | 228 |
| 210 std::queue<uint32_t> free_buffers_; | 229 std::queue<uint32_t> free_buffers_; |
| 211 | 230 |
| 212 // Keep track of audio parameters. | 231 // Keep track of audio parameters. |
| 213 int audio_samples_per_second_; | 232 int audio_samples_per_second_; |
| 214 int audio_channel_count_; | 233 int audio_channel_count_; |
| 215 media::ChannelLayout audio_channel_layout_; | 234 media::ChannelLayout audio_channel_layout_; |
| 216 | 235 |
| 236 // Keep track of outstanding promises. |promises_| has ownership of the | |
| 237 // promise. | |
| 238 uint32_t next_promise_id_; | |
| 239 std::map<uint32_t, media::MediaKeysSessionPromise*> promises_; | |
| 240 | |
| 217 base::WeakPtr<ContentDecryptorDelegate> weak_this_; | 241 base::WeakPtr<ContentDecryptorDelegate> weak_this_; |
| 218 base::WeakPtrFactory<ContentDecryptorDelegate> weak_ptr_factory_; | 242 base::WeakPtrFactory<ContentDecryptorDelegate> weak_ptr_factory_; |
| 219 | 243 |
| 220 DISALLOW_COPY_AND_ASSIGN(ContentDecryptorDelegate); | 244 DISALLOW_COPY_AND_ASSIGN(ContentDecryptorDelegate); |
| 221 }; | 245 }; |
| 222 | 246 |
| 223 } // namespace content | 247 } // namespace content |
| 224 | 248 |
| 225 #endif // CONTENT_RENDERER_PEPPER_CONTENT_DECRYPTOR_DELEGATE_H_ | 249 #endif // CONTENT_RENDERER_PEPPER_CONTENT_DECRYPTOR_DELEGATE_H_ |
| OLD | NEW |