| 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 #include "content/renderer/media/crypto/ppapi_decryptor.h" | 5 #include "content/renderer/media/crypto/ppapi_decryptor.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 session_error_cb_(session_error_cb), | 66 session_error_cb_(session_error_cb), |
| 67 render_loop_proxy_(base::MessageLoopProxy::current()), | 67 render_loop_proxy_(base::MessageLoopProxy::current()), |
| 68 weak_ptr_factory_(this) { | 68 weak_ptr_factory_(this) { |
| 69 DCHECK(pepper_cdm_wrapper_.get()); | 69 DCHECK(pepper_cdm_wrapper_.get()); |
| 70 DCHECK(!session_created_cb_.is_null()); | 70 DCHECK(!session_created_cb_.is_null()); |
| 71 DCHECK(!session_message_cb_.is_null()); | 71 DCHECK(!session_message_cb_.is_null()); |
| 72 DCHECK(!session_ready_cb_.is_null()); | 72 DCHECK(!session_ready_cb_.is_null()); |
| 73 DCHECK(!session_closed_cb_.is_null()); | 73 DCHECK(!session_closed_cb_.is_null()); |
| 74 DCHECK(!session_error_cb_.is_null()); | 74 DCHECK(!session_error_cb_.is_null()); |
| 75 | 75 |
| 76 weak_this_ = weak_ptr_factory_.GetWeakPtr(); | 76 base::WeakPtr<PpapiDecryptor> weak_this = weak_ptr_factory_.GetWeakPtr(); |
| 77 | |
| 78 CdmDelegate()->Initialize( | 77 CdmDelegate()->Initialize( |
| 79 key_system, | 78 key_system, |
| 80 base::Bind(&PpapiDecryptor::OnSessionCreated, weak_this_), | 79 base::Bind(&PpapiDecryptor::OnSessionCreated, weak_this), |
| 81 base::Bind(&PpapiDecryptor::OnSessionMessage, weak_this_), | 80 base::Bind(&PpapiDecryptor::OnSessionMessage, weak_this), |
| 82 base::Bind(&PpapiDecryptor::OnSessionReady, weak_this_), | 81 base::Bind(&PpapiDecryptor::OnSessionReady, weak_this), |
| 83 base::Bind(&PpapiDecryptor::OnSessionClosed, weak_this_), | 82 base::Bind(&PpapiDecryptor::OnSessionClosed, weak_this), |
| 84 base::Bind(&PpapiDecryptor::OnSessionError, weak_this_), | 83 base::Bind(&PpapiDecryptor::OnSessionError, weak_this), |
| 85 base::Bind(&PpapiDecryptor::OnFatalPluginError, weak_this_)); | 84 base::Bind(&PpapiDecryptor::OnFatalPluginError, weak_this)); |
| 86 } | 85 } |
| 87 | 86 |
| 88 PpapiDecryptor::~PpapiDecryptor() { | 87 PpapiDecryptor::~PpapiDecryptor() { |
| 89 pepper_cdm_wrapper_.reset(); | 88 pepper_cdm_wrapper_.reset(); |
| 90 } | 89 } |
| 91 | 90 |
| 92 bool PpapiDecryptor::CreateSession(uint32 session_id, | 91 bool PpapiDecryptor::CreateSession(uint32 session_id, |
| 93 const std::string& content_type, | 92 const std::string& content_type, |
| 94 const uint8* init_data, | 93 const uint8* init_data, |
| 95 int init_data_length) { | 94 int init_data_length) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 } | 141 } |
| 143 } | 142 } |
| 144 | 143 |
| 145 media::Decryptor* PpapiDecryptor::GetDecryptor() { | 144 media::Decryptor* PpapiDecryptor::GetDecryptor() { |
| 146 return this; | 145 return this; |
| 147 } | 146 } |
| 148 | 147 |
| 149 void PpapiDecryptor::RegisterNewKeyCB(StreamType stream_type, | 148 void PpapiDecryptor::RegisterNewKeyCB(StreamType stream_type, |
| 150 const NewKeyCB& new_key_cb) { | 149 const NewKeyCB& new_key_cb) { |
| 151 if (!render_loop_proxy_->BelongsToCurrentThread()) { | 150 if (!render_loop_proxy_->BelongsToCurrentThread()) { |
| 152 render_loop_proxy_->PostTask(FROM_HERE, base::Bind( | 151 render_loop_proxy_->PostTask(FROM_HERE, |
| 153 &PpapiDecryptor::RegisterNewKeyCB, weak_this_, stream_type, | 152 base::Bind(&PpapiDecryptor::RegisterNewKeyCB, |
| 154 new_key_cb)); | 153 weak_ptr_factory_.GetWeakPtr(), |
| 154 stream_type, |
| 155 new_key_cb)); |
| 155 return; | 156 return; |
| 156 } | 157 } |
| 157 | 158 |
| 158 DVLOG(3) << __FUNCTION__ << " - stream_type: " << stream_type; | 159 DVLOG(3) << __FUNCTION__ << " - stream_type: " << stream_type; |
| 159 switch (stream_type) { | 160 switch (stream_type) { |
| 160 case kAudio: | 161 case kAudio: |
| 161 new_audio_key_cb_ = new_key_cb; | 162 new_audio_key_cb_ = new_key_cb; |
| 162 break; | 163 break; |
| 163 case kVideo: | 164 case kVideo: |
| 164 new_video_key_cb_ = new_key_cb; | 165 new_video_key_cb_ = new_key_cb; |
| 165 break; | 166 break; |
| 166 default: | 167 default: |
| 167 NOTREACHED(); | 168 NOTREACHED(); |
| 168 } | 169 } |
| 169 } | 170 } |
| 170 | 171 |
| 171 void PpapiDecryptor::Decrypt( | 172 void PpapiDecryptor::Decrypt( |
| 172 StreamType stream_type, | 173 StreamType stream_type, |
| 173 const scoped_refptr<media::DecoderBuffer>& encrypted, | 174 const scoped_refptr<media::DecoderBuffer>& encrypted, |
| 174 const DecryptCB& decrypt_cb) { | 175 const DecryptCB& decrypt_cb) { |
| 175 if (!render_loop_proxy_->BelongsToCurrentThread()) { | 176 if (!render_loop_proxy_->BelongsToCurrentThread()) { |
| 176 render_loop_proxy_->PostTask(FROM_HERE, base::Bind( | 177 render_loop_proxy_->PostTask(FROM_HERE, |
| 177 &PpapiDecryptor::Decrypt, weak_this_, | 178 base::Bind(&PpapiDecryptor::Decrypt, |
| 178 stream_type, encrypted, decrypt_cb)); | 179 weak_ptr_factory_.GetWeakPtr(), |
| 180 stream_type, |
| 181 encrypted, |
| 182 decrypt_cb)); |
| 179 return; | 183 return; |
| 180 } | 184 } |
| 181 | 185 |
| 182 DVLOG(3) << __FUNCTION__ << " - stream_type: " << stream_type; | 186 DVLOG(3) << __FUNCTION__ << " - stream_type: " << stream_type; |
| 183 if (!CdmDelegate() || | 187 if (!CdmDelegate() || |
| 184 !CdmDelegate()->Decrypt(stream_type, encrypted, decrypt_cb)) { | 188 !CdmDelegate()->Decrypt(stream_type, encrypted, decrypt_cb)) { |
| 185 decrypt_cb.Run(kError, NULL); | 189 decrypt_cb.Run(kError, NULL); |
| 186 } | 190 } |
| 187 } | 191 } |
| 188 | 192 |
| 189 void PpapiDecryptor::CancelDecrypt(StreamType stream_type) { | 193 void PpapiDecryptor::CancelDecrypt(StreamType stream_type) { |
| 190 if (!render_loop_proxy_->BelongsToCurrentThread()) { | 194 if (!render_loop_proxy_->BelongsToCurrentThread()) { |
| 191 render_loop_proxy_->PostTask(FROM_HERE, base::Bind( | 195 render_loop_proxy_->PostTask(FROM_HERE, |
| 192 &PpapiDecryptor::CancelDecrypt, weak_this_, stream_type)); | 196 base::Bind(&PpapiDecryptor::CancelDecrypt, |
| 197 weak_ptr_factory_.GetWeakPtr(), |
| 198 stream_type)); |
| 193 return; | 199 return; |
| 194 } | 200 } |
| 195 | 201 |
| 196 DVLOG(1) << __FUNCTION__ << " - stream_type: " << stream_type; | 202 DVLOG(1) << __FUNCTION__ << " - stream_type: " << stream_type; |
| 197 if (CdmDelegate()) | 203 if (CdmDelegate()) |
| 198 CdmDelegate()->CancelDecrypt(stream_type); | 204 CdmDelegate()->CancelDecrypt(stream_type); |
| 199 } | 205 } |
| 200 | 206 |
| 201 void PpapiDecryptor::InitializeAudioDecoder( | 207 void PpapiDecryptor::InitializeAudioDecoder( |
| 202 const media::AudioDecoderConfig& config, | 208 const media::AudioDecoderConfig& config, |
| 203 const DecoderInitCB& init_cb) { | 209 const DecoderInitCB& init_cb) { |
| 204 if (!render_loop_proxy_->BelongsToCurrentThread()) { | 210 if (!render_loop_proxy_->BelongsToCurrentThread()) { |
| 205 render_loop_proxy_->PostTask(FROM_HERE, base::Bind( | 211 render_loop_proxy_->PostTask( |
| 206 &PpapiDecryptor::InitializeAudioDecoder, weak_this_, config, init_cb)); | 212 FROM_HERE, |
| 213 base::Bind(&PpapiDecryptor::InitializeAudioDecoder, |
| 214 weak_ptr_factory_.GetWeakPtr(), |
| 215 config, |
| 216 init_cb)); |
| 207 return; | 217 return; |
| 208 } | 218 } |
| 209 | 219 |
| 210 DVLOG(2) << __FUNCTION__; | 220 DVLOG(2) << __FUNCTION__; |
| 211 DCHECK(config.is_encrypted()); | 221 DCHECK(config.is_encrypted()); |
| 212 DCHECK(config.IsValidConfig()); | 222 DCHECK(config.IsValidConfig()); |
| 213 | 223 |
| 214 audio_decoder_init_cb_ = init_cb; | 224 audio_decoder_init_cb_ = init_cb; |
| 215 if (!CdmDelegate() || | 225 if (!CdmDelegate() || !CdmDelegate()->InitializeAudioDecoder( |
| 216 !CdmDelegate()->InitializeAudioDecoder( | 226 config, |
| 217 config, | 227 base::Bind(&PpapiDecryptor::OnDecoderInitialized, |
| 218 base::Bind( | 228 weak_ptr_factory_.GetWeakPtr(), |
| 219 &PpapiDecryptor::OnDecoderInitialized, weak_this_, kAudio))) { | 229 kAudio))) { |
| 220 base::ResetAndReturn(&audio_decoder_init_cb_).Run(false); | 230 base::ResetAndReturn(&audio_decoder_init_cb_).Run(false); |
| 221 return; | 231 return; |
| 222 } | 232 } |
| 223 } | 233 } |
| 224 | 234 |
| 225 void PpapiDecryptor::InitializeVideoDecoder( | 235 void PpapiDecryptor::InitializeVideoDecoder( |
| 226 const media::VideoDecoderConfig& config, | 236 const media::VideoDecoderConfig& config, |
| 227 const DecoderInitCB& init_cb) { | 237 const DecoderInitCB& init_cb) { |
| 228 if (!render_loop_proxy_->BelongsToCurrentThread()) { | 238 if (!render_loop_proxy_->BelongsToCurrentThread()) { |
| 229 render_loop_proxy_->PostTask(FROM_HERE, base::Bind( | 239 render_loop_proxy_->PostTask( |
| 230 &PpapiDecryptor::InitializeVideoDecoder, weak_this_, config, init_cb)); | 240 FROM_HERE, |
| 241 base::Bind(&PpapiDecryptor::InitializeVideoDecoder, |
| 242 weak_ptr_factory_.GetWeakPtr(), |
| 243 config, |
| 244 init_cb)); |
| 231 return; | 245 return; |
| 232 } | 246 } |
| 233 | 247 |
| 234 DVLOG(2) << __FUNCTION__; | 248 DVLOG(2) << __FUNCTION__; |
| 235 DCHECK(config.is_encrypted()); | 249 DCHECK(config.is_encrypted()); |
| 236 DCHECK(config.IsValidConfig()); | 250 DCHECK(config.IsValidConfig()); |
| 237 | 251 |
| 238 video_decoder_init_cb_ = init_cb; | 252 video_decoder_init_cb_ = init_cb; |
| 239 if (!CdmDelegate() || | 253 if (!CdmDelegate() || !CdmDelegate()->InitializeVideoDecoder( |
| 240 !CdmDelegate()->InitializeVideoDecoder( | 254 config, |
| 241 config, | 255 base::Bind(&PpapiDecryptor::OnDecoderInitialized, |
| 242 base::Bind( | 256 weak_ptr_factory_.GetWeakPtr(), |
| 243 &PpapiDecryptor::OnDecoderInitialized, weak_this_, kVideo))) { | 257 kVideo))) { |
| 244 base::ResetAndReturn(&video_decoder_init_cb_).Run(false); | 258 base::ResetAndReturn(&video_decoder_init_cb_).Run(false); |
| 245 return; | 259 return; |
| 246 } | 260 } |
| 247 } | 261 } |
| 248 | 262 |
| 249 void PpapiDecryptor::DecryptAndDecodeAudio( | 263 void PpapiDecryptor::DecryptAndDecodeAudio( |
| 250 const scoped_refptr<media::DecoderBuffer>& encrypted, | 264 const scoped_refptr<media::DecoderBuffer>& encrypted, |
| 251 const AudioDecodeCB& audio_decode_cb) { | 265 const AudioDecodeCB& audio_decode_cb) { |
| 252 if (!render_loop_proxy_->BelongsToCurrentThread()) { | 266 if (!render_loop_proxy_->BelongsToCurrentThread()) { |
| 253 render_loop_proxy_->PostTask(FROM_HERE, base::Bind( | 267 render_loop_proxy_->PostTask( |
| 254 &PpapiDecryptor::DecryptAndDecodeAudio, weak_this_, | 268 FROM_HERE, |
| 255 encrypted, audio_decode_cb)); | 269 base::Bind(&PpapiDecryptor::DecryptAndDecodeAudio, |
| 270 weak_ptr_factory_.GetWeakPtr(), |
| 271 encrypted, |
| 272 audio_decode_cb)); |
| 256 return; | 273 return; |
| 257 } | 274 } |
| 258 | 275 |
| 259 DVLOG(3) << __FUNCTION__; | 276 DVLOG(3) << __FUNCTION__; |
| 260 if (!CdmDelegate() || | 277 if (!CdmDelegate() || |
| 261 !CdmDelegate()->DecryptAndDecodeAudio(encrypted, audio_decode_cb)) { | 278 !CdmDelegate()->DecryptAndDecodeAudio(encrypted, audio_decode_cb)) { |
| 262 audio_decode_cb.Run(kError, AudioBuffers()); | 279 audio_decode_cb.Run(kError, AudioBuffers()); |
| 263 } | 280 } |
| 264 } | 281 } |
| 265 | 282 |
| 266 void PpapiDecryptor::DecryptAndDecodeVideo( | 283 void PpapiDecryptor::DecryptAndDecodeVideo( |
| 267 const scoped_refptr<media::DecoderBuffer>& encrypted, | 284 const scoped_refptr<media::DecoderBuffer>& encrypted, |
| 268 const VideoDecodeCB& video_decode_cb) { | 285 const VideoDecodeCB& video_decode_cb) { |
| 269 if (!render_loop_proxy_->BelongsToCurrentThread()) { | 286 if (!render_loop_proxy_->BelongsToCurrentThread()) { |
| 270 render_loop_proxy_->PostTask(FROM_HERE, base::Bind( | 287 render_loop_proxy_->PostTask( |
| 271 &PpapiDecryptor::DecryptAndDecodeVideo, weak_this_, | 288 FROM_HERE, |
| 272 encrypted, video_decode_cb)); | 289 base::Bind(&PpapiDecryptor::DecryptAndDecodeVideo, |
| 290 weak_ptr_factory_.GetWeakPtr(), |
| 291 encrypted, |
| 292 video_decode_cb)); |
| 273 return; | 293 return; |
| 274 } | 294 } |
| 275 | 295 |
| 276 DVLOG(3) << __FUNCTION__; | 296 DVLOG(3) << __FUNCTION__; |
| 277 if (!CdmDelegate() || | 297 if (!CdmDelegate() || |
| 278 !CdmDelegate()->DecryptAndDecodeVideo(encrypted, video_decode_cb)) { | 298 !CdmDelegate()->DecryptAndDecodeVideo(encrypted, video_decode_cb)) { |
| 279 video_decode_cb.Run(kError, NULL); | 299 video_decode_cb.Run(kError, NULL); |
| 280 } | 300 } |
| 281 } | 301 } |
| 282 | 302 |
| 283 void PpapiDecryptor::ResetDecoder(StreamType stream_type) { | 303 void PpapiDecryptor::ResetDecoder(StreamType stream_type) { |
| 284 if (!render_loop_proxy_->BelongsToCurrentThread()) { | 304 if (!render_loop_proxy_->BelongsToCurrentThread()) { |
| 285 render_loop_proxy_->PostTask(FROM_HERE, base::Bind( | 305 render_loop_proxy_->PostTask(FROM_HERE, |
| 286 &PpapiDecryptor::ResetDecoder, weak_this_, stream_type)); | 306 base::Bind(&PpapiDecryptor::ResetDecoder, |
| 307 weak_ptr_factory_.GetWeakPtr(), |
| 308 stream_type)); |
| 287 return; | 309 return; |
| 288 } | 310 } |
| 289 | 311 |
| 290 DVLOG(2) << __FUNCTION__ << " - stream_type: " << stream_type; | 312 DVLOG(2) << __FUNCTION__ << " - stream_type: " << stream_type; |
| 291 if (CdmDelegate()) | 313 if (CdmDelegate()) |
| 292 CdmDelegate()->ResetDecoder(stream_type); | 314 CdmDelegate()->ResetDecoder(stream_type); |
| 293 } | 315 } |
| 294 | 316 |
| 295 void PpapiDecryptor::DeinitializeDecoder(StreamType stream_type) { | 317 void PpapiDecryptor::DeinitializeDecoder(StreamType stream_type) { |
| 296 if (!render_loop_proxy_->BelongsToCurrentThread()) { | 318 if (!render_loop_proxy_->BelongsToCurrentThread()) { |
| 297 render_loop_proxy_->PostTask(FROM_HERE, base::Bind( | 319 render_loop_proxy_->PostTask( |
| 298 &PpapiDecryptor::DeinitializeDecoder, weak_this_, stream_type)); | 320 FROM_HERE, |
| 321 base::Bind(&PpapiDecryptor::DeinitializeDecoder, |
| 322 weak_ptr_factory_.GetWeakPtr(), |
| 323 stream_type)); |
| 299 return; | 324 return; |
| 300 } | 325 } |
| 301 | 326 |
| 302 DVLOG(2) << __FUNCTION__ << " - stream_type: " << stream_type; | 327 DVLOG(2) << __FUNCTION__ << " - stream_type: " << stream_type; |
| 303 if (CdmDelegate()) | 328 if (CdmDelegate()) |
| 304 CdmDelegate()->DeinitializeDecoder(stream_type); | 329 CdmDelegate()->DeinitializeDecoder(stream_type); |
| 305 } | 330 } |
| 306 | 331 |
| 307 void PpapiDecryptor::ReportFailureToCallPlugin(uint32 session_id) { | 332 void PpapiDecryptor::ReportFailureToCallPlugin(uint32 session_id) { |
| 308 DCHECK(render_loop_proxy_->BelongsToCurrentThread()); | 333 DCHECK(render_loop_proxy_->BelongsToCurrentThread()); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 DCHECK(render_loop_proxy_->BelongsToCurrentThread()); | 399 DCHECK(render_loop_proxy_->BelongsToCurrentThread()); |
| 375 pepper_cdm_wrapper_.reset(); | 400 pepper_cdm_wrapper_.reset(); |
| 376 } | 401 } |
| 377 | 402 |
| 378 ContentDecryptorDelegate* PpapiDecryptor::CdmDelegate() { | 403 ContentDecryptorDelegate* PpapiDecryptor::CdmDelegate() { |
| 379 DCHECK(render_loop_proxy_->BelongsToCurrentThread()); | 404 DCHECK(render_loop_proxy_->BelongsToCurrentThread()); |
| 380 return (pepper_cdm_wrapper_) ? pepper_cdm_wrapper_->GetCdmDelegate() : NULL; | 405 return (pepper_cdm_wrapper_) ? pepper_cdm_wrapper_->GetCdmDelegate() : NULL; |
| 381 } | 406 } |
| 382 | 407 |
| 383 } // namespace content | 408 } // namespace content |
| OLD | NEW |