Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1013)

Side by Side Diff: content/renderer/pepper/content_decryptor_delegate.cc

Issue 116443009: Handle plugin instance crash in ContentDecryptorDelegate. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #include "content/renderer/pepper/content_decryptor_delegate.h" 5 #include "content/renderer/pepper/content_decryptor_delegate.h"
6 6
7 #include "base/callback_helpers.h" 7 #include "base/callback_helpers.h"
8 #include "base/debug/trace_event.h" 8 #include "base/debug/trace_event.h"
9 #include "base/message_loop/message_loop_proxy.h" 9 #include "base/message_loop/message_loop_proxy.h"
10 #include "base/safe_numerics.h" 10 #include "base/safe_numerics.h"
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 plugin_decryption_interface_(plugin_decryption_interface), 248 plugin_decryption_interface_(plugin_decryption_interface),
249 next_decryption_request_id_(1), 249 next_decryption_request_id_(1),
250 pending_audio_decrypt_request_id_(0), 250 pending_audio_decrypt_request_id_(0),
251 pending_video_decrypt_request_id_(0), 251 pending_video_decrypt_request_id_(0),
252 pending_audio_decoder_init_request_id_(0), 252 pending_audio_decoder_init_request_id_(0),
253 pending_video_decoder_init_request_id_(0), 253 pending_video_decoder_init_request_id_(0),
254 pending_audio_decode_request_id_(0), 254 pending_audio_decode_request_id_(0),
255 pending_video_decode_request_id_(0), 255 pending_video_decode_request_id_(0),
256 audio_samples_per_second_(0), 256 audio_samples_per_second_(0),
257 audio_channel_count_(0), 257 audio_channel_count_(0),
258 weak_ptr_factory_(this) { 258 weak_ptr_factory_(this),
259 is_instance_crashed_(false) {
259 weak_this_ = weak_ptr_factory_.GetWeakPtr(); 260 weak_this_ = weak_ptr_factory_.GetWeakPtr();
260 } 261 }
261 262
262 ContentDecryptorDelegate::~ContentDecryptorDelegate() { 263 ContentDecryptorDelegate::~ContentDecryptorDelegate() {
263 } 264 }
264 265
265 void ContentDecryptorDelegate::Initialize(const std::string& key_system) { 266 void ContentDecryptorDelegate::Initialize(const std::string& key_system) {
266 DCHECK(!key_system.empty()); 267 DCHECK(!key_system.empty());
267 DCHECK(key_system_.empty()); 268 DCHECK(key_system_.empty());
268 key_system_ = key_system; 269 key_system_ = key_system;
269 270
270 plugin_decryption_interface_->Initialize( 271 plugin_decryption_interface_->Initialize(
271 pp_instance_, 272 pp_instance_,
272 StringVar::StringToPPVar(key_system_)); 273 StringVar::StringToPPVar(key_system_));
273 } 274 }
274 275
275 void ContentDecryptorDelegate::SetSessionEventCallbacks( 276 void ContentDecryptorDelegate::SetSessionEventCallbacks(
276 const media::SessionCreatedCB& session_created_cb, 277 const media::SessionCreatedCB& session_created_cb,
277 const media::SessionMessageCB& session_message_cb, 278 const media::SessionMessageCB& session_message_cb,
278 const media::SessionReadyCB& session_ready_cb, 279 const media::SessionReadyCB& session_ready_cb,
279 const media::SessionClosedCB& session_closed_cb, 280 const media::SessionClosedCB& session_closed_cb,
280 const media::SessionErrorCB& session_error_cb) { 281 const media::SessionErrorCB& session_error_cb) {
281 session_created_cb_ = session_created_cb; 282 session_created_cb_ = session_created_cb;
282 session_message_cb_ = session_message_cb; 283 session_message_cb_ = session_message_cb;
283 session_ready_cb_ = session_ready_cb; 284 session_ready_cb_ = session_ready_cb;
284 session_closed_cb_ = session_closed_cb; 285 session_closed_cb_ = session_closed_cb;
285 session_error_cb_ = session_error_cb; 286 session_error_cb_ = session_error_cb;
286 } 287 }
287 288
289 void ContentDecryptorDelegate::InstanceCrashed() {
290 if (!pending_audio_decoder_init_cb_.is_null()) {
291 pending_audio_decoder_init_request_id_ = 0;
292 base::ResetAndReturn(&pending_audio_decoder_init_cb_).Run(false);
293 }
294
295 if (!pending_video_decoder_init_cb_.is_null()) {
296 pending_video_decoder_init_request_id_ = 0;
297 base::ResetAndReturn(&pending_video_decoder_init_cb_).Run(false);
298 }
299
300 if (!pending_audio_decrypt_cb_.is_null()) {
301 audio_input_resource_ = NULL;
302 pending_audio_decrypt_request_id_ = 0;
303 base::ResetAndReturn(&pending_audio_decrypt_cb_)
304 .Run(media::Decryptor::kError, NULL);
305 }
306
307 if (!pending_video_decrypt_cb_.is_null()) {
308 video_input_resource_ = NULL;
309 pending_video_decrypt_request_id_ = 0;
310 base::ResetAndReturn(&pending_video_decrypt_cb_)
311 .Run(media::Decryptor::kError, NULL);
312 }
313
314 if (!pending_audio_decode_cb_.is_null()) {
315 audio_input_resource_ = NULL;
316 pending_audio_decode_request_id_ = 0;
317 const media::Decryptor::AudioBuffers empty_frames;
318 base::ResetAndReturn(&pending_audio_decode_cb_)
319 .Run(media::Decryptor::kError, empty_frames);
320 }
321
322 if (!pending_video_decode_cb_.is_null()) {
323 video_input_resource_ = NULL;
324 pending_video_decode_request_id_ = 0;
325 base::ResetAndReturn(&pending_video_decode_cb_)
326 .Run(media::Decryptor::kError, NULL);
327 }
328
329 is_instance_crashed_ = true;
330 }
xhwang 2013/12/28 01:00:28 We have too many duplicate code about reqeust_id a
331
288 bool ContentDecryptorDelegate::CreateSession(uint32 session_id, 332 bool ContentDecryptorDelegate::CreateSession(uint32 session_id,
289 const std::string& type, 333 const std::string& type,
290 const uint8* init_data, 334 const uint8* init_data,
291 int init_data_length) { 335 int init_data_length) {
336 if (is_instance_crashed_)
337 return false;
338
292 PP_Var init_data_array = 339 PP_Var init_data_array =
293 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar( 340 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar(
294 init_data_length, init_data); 341 init_data_length, init_data);
295 342
296 plugin_decryption_interface_->CreateSession(pp_instance_, 343 plugin_decryption_interface_->CreateSession(pp_instance_,
297 session_id, 344 session_id,
298 StringVar::StringToPPVar(type), 345 StringVar::StringToPPVar(type),
299 init_data_array); 346 init_data_array);
300 return true; 347 return true;
301 } 348 }
302 349
303 bool ContentDecryptorDelegate::UpdateSession(uint32 session_id, 350 bool ContentDecryptorDelegate::UpdateSession(uint32 session_id,
304 const uint8* response, 351 const uint8* response,
305 int response_length) { 352 int response_length) {
353 if (is_instance_crashed_)
354 return false;
355
306 PP_Var response_array = 356 PP_Var response_array =
307 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar( 357 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar(
308 response_length, response); 358 response_length, response);
309 plugin_decryption_interface_->UpdateSession( 359 plugin_decryption_interface_->UpdateSession(
310 pp_instance_, session_id, response_array); 360 pp_instance_, session_id, response_array);
311 return true; 361 return true;
312 } 362 }
313 363
314 bool ContentDecryptorDelegate::ReleaseSession(uint32 session_id) { 364 bool ContentDecryptorDelegate::ReleaseSession(uint32 session_id) {
365 if (is_instance_crashed_)
366 return false;
367
315 plugin_decryption_interface_->ReleaseSession(pp_instance_, session_id); 368 plugin_decryption_interface_->ReleaseSession(pp_instance_, session_id);
316 return true; 369 return true;
317 } 370 }
318 371
319 // TODO(xhwang): Remove duplication of code in Decrypt(), 372 // TODO(xhwang): Remove duplication of code in Decrypt(),
320 // DecryptAndDecodeAudio() and DecryptAndDecodeVideo(). 373 // DecryptAndDecodeAudio() and DecryptAndDecodeVideo().
321 bool ContentDecryptorDelegate::Decrypt( 374 bool ContentDecryptorDelegate::Decrypt(
322 media::Decryptor::StreamType stream_type, 375 media::Decryptor::StreamType stream_type,
323 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, 376 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer,
324 const media::Decryptor::DecryptCB& decrypt_cb) { 377 const media::Decryptor::DecryptCB& decrypt_cb) {
325 DVLOG(3) << "Decrypt() - stream_type: " << stream_type; 378 DVLOG(3) << "Decrypt() - stream_type: " << stream_type;
379
380 if (is_instance_crashed_)
381 return false;
382
326 // |{audio|video}_input_resource_| is not being used by the plugin 383 // |{audio|video}_input_resource_| is not being used by the plugin
327 // now because there is only one pending audio/video decrypt request at any 384 // now because there is only one pending audio/video decrypt request at any
328 // time. This is enforced by the media pipeline. 385 // time. This is enforced by the media pipeline.
329 scoped_refptr<PPB_Buffer_Impl> encrypted_resource; 386 scoped_refptr<PPB_Buffer_Impl> encrypted_resource;
330 if (!MakeMediaBufferResource( 387 if (!MakeMediaBufferResource(
331 stream_type, encrypted_buffer, &encrypted_resource) || 388 stream_type, encrypted_buffer, &encrypted_resource) ||
332 !encrypted_resource.get()) { 389 !encrypted_resource.get()) {
333 return false; 390 return false;
334 } 391 }
335 ScopedPPResource pp_resource(encrypted_resource.get()); 392 ScopedPPResource pp_resource(encrypted_resource.get());
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 plugin_decryption_interface_->Decrypt(pp_instance_, 425 plugin_decryption_interface_->Decrypt(pp_instance_,
369 pp_resource, 426 pp_resource,
370 &block_info); 427 &block_info);
371 return true; 428 return true;
372 } 429 }
373 430
374 bool ContentDecryptorDelegate::CancelDecrypt( 431 bool ContentDecryptorDelegate::CancelDecrypt(
375 media::Decryptor::StreamType stream_type) { 432 media::Decryptor::StreamType stream_type) {
376 DVLOG(3) << "CancelDecrypt() - stream_type: " << stream_type; 433 DVLOG(3) << "CancelDecrypt() - stream_type: " << stream_type;
377 434
435 if (is_instance_crashed_)
436 return false;
437
378 media::Decryptor::DecryptCB decrypt_cb; 438 media::Decryptor::DecryptCB decrypt_cb;
379 switch (stream_type) { 439 switch (stream_type) {
380 case media::Decryptor::kAudio: 440 case media::Decryptor::kAudio:
381 // Release the shared memory as it can still be in use by the plugin. 441 // Release the shared memory as it can still be in use by the plugin.
382 // The next Decrypt() call will need to allocate a new shared memory 442 // The next Decrypt() call will need to allocate a new shared memory
383 // buffer. 443 // buffer.
384 audio_input_resource_ = NULL; 444 audio_input_resource_ = NULL;
385 pending_audio_decrypt_request_id_ = 0; 445 pending_audio_decrypt_request_id_ = 0;
386 decrypt_cb = base::ResetAndReturn(&pending_audio_decrypt_cb_); 446 decrypt_cb = base::ResetAndReturn(&pending_audio_decrypt_cb_);
387 break; 447 break;
(...skipping 12 matching lines...) Expand all
400 460
401 if (!decrypt_cb.is_null()) 461 if (!decrypt_cb.is_null())
402 decrypt_cb.Run(media::Decryptor::kSuccess, NULL); 462 decrypt_cb.Run(media::Decryptor::kSuccess, NULL);
403 463
404 return true; 464 return true;
405 } 465 }
406 466
407 bool ContentDecryptorDelegate::InitializeAudioDecoder( 467 bool ContentDecryptorDelegate::InitializeAudioDecoder(
408 const media::AudioDecoderConfig& decoder_config, 468 const media::AudioDecoderConfig& decoder_config,
409 const media::Decryptor::DecoderInitCB& init_cb) { 469 const media::Decryptor::DecoderInitCB& init_cb) {
470 if (is_instance_crashed_)
471 return false;
472
410 PP_AudioDecoderConfig pp_decoder_config; 473 PP_AudioDecoderConfig pp_decoder_config;
411 pp_decoder_config.codec = 474 pp_decoder_config.codec =
412 MediaAudioCodecToPpAudioCodec(decoder_config.codec()); 475 MediaAudioCodecToPpAudioCodec(decoder_config.codec());
413 pp_decoder_config.channel_count = 476 pp_decoder_config.channel_count =
414 media::ChannelLayoutToChannelCount(decoder_config.channel_layout()); 477 media::ChannelLayoutToChannelCount(decoder_config.channel_layout());
415 pp_decoder_config.bits_per_channel = decoder_config.bits_per_channel(); 478 pp_decoder_config.bits_per_channel = decoder_config.bits_per_channel();
416 pp_decoder_config.samples_per_second = decoder_config.samples_per_second(); 479 pp_decoder_config.samples_per_second = decoder_config.samples_per_second();
417 pp_decoder_config.request_id = next_decryption_request_id_++; 480 pp_decoder_config.request_id = next_decryption_request_id_++;
418 481
419 audio_samples_per_second_ = pp_decoder_config.samples_per_second; 482 audio_samples_per_second_ = pp_decoder_config.samples_per_second;
(...skipping 15 matching lines...) Expand all
435 498
436 plugin_decryption_interface_->InitializeAudioDecoder(pp_instance_, 499 plugin_decryption_interface_->InitializeAudioDecoder(pp_instance_,
437 &pp_decoder_config, 500 &pp_decoder_config,
438 pp_resource); 501 pp_resource);
439 return true; 502 return true;
440 } 503 }
441 504
442 bool ContentDecryptorDelegate::InitializeVideoDecoder( 505 bool ContentDecryptorDelegate::InitializeVideoDecoder(
443 const media::VideoDecoderConfig& decoder_config, 506 const media::VideoDecoderConfig& decoder_config,
444 const media::Decryptor::DecoderInitCB& init_cb) { 507 const media::Decryptor::DecoderInitCB& init_cb) {
508 if (is_instance_crashed_)
509 return false;
510
445 PP_VideoDecoderConfig pp_decoder_config; 511 PP_VideoDecoderConfig pp_decoder_config;
446 pp_decoder_config.codec = 512 pp_decoder_config.codec =
447 MediaVideoCodecToPpVideoCodec(decoder_config.codec()); 513 MediaVideoCodecToPpVideoCodec(decoder_config.codec());
448 pp_decoder_config.profile = 514 pp_decoder_config.profile =
449 MediaVideoCodecProfileToPpVideoCodecProfile(decoder_config.profile()); 515 MediaVideoCodecProfileToPpVideoCodecProfile(decoder_config.profile());
450 pp_decoder_config.format = 516 pp_decoder_config.format =
451 MediaVideoFormatToPpDecryptedFrameFormat(decoder_config.format()); 517 MediaVideoFormatToPpDecryptedFrameFormat(decoder_config.format());
452 pp_decoder_config.width = decoder_config.coded_size().width(); 518 pp_decoder_config.width = decoder_config.coded_size().width();
453 pp_decoder_config.height = decoder_config.coded_size().height(); 519 pp_decoder_config.height = decoder_config.coded_size().height();
454 pp_decoder_config.request_id = next_decryption_request_id_++; 520 pp_decoder_config.request_id = next_decryption_request_id_++;
(...skipping 15 matching lines...) Expand all
470 natural_size_ = decoder_config.natural_size(); 536 natural_size_ = decoder_config.natural_size();
471 537
472 plugin_decryption_interface_->InitializeVideoDecoder(pp_instance_, 538 plugin_decryption_interface_->InitializeVideoDecoder(pp_instance_,
473 &pp_decoder_config, 539 &pp_decoder_config,
474 pp_resource); 540 pp_resource);
475 return true; 541 return true;
476 } 542 }
477 543
478 bool ContentDecryptorDelegate::DeinitializeDecoder( 544 bool ContentDecryptorDelegate::DeinitializeDecoder(
479 media::Decryptor::StreamType stream_type) { 545 media::Decryptor::StreamType stream_type) {
546 if (is_instance_crashed_)
547 return false;
548
480 CancelDecode(stream_type); 549 CancelDecode(stream_type);
481 550
482 natural_size_ = gfx::Size(); 551 natural_size_ = gfx::Size();
483 552
484 // TODO(tomfinegan): Add decoder deinitialize request tracking, and get 553 // TODO(tomfinegan): Add decoder deinitialize request tracking, and get
485 // stream type from media stack. 554 // stream type from media stack.
486 plugin_decryption_interface_->DeinitializeDecoder( 555 plugin_decryption_interface_->DeinitializeDecoder(
487 pp_instance_, MediaDecryptorStreamTypeToPpStreamType(stream_type), 0); 556 pp_instance_, MediaDecryptorStreamTypeToPpStreamType(stream_type), 0);
488 return true; 557 return true;
489 } 558 }
490 559
491 bool ContentDecryptorDelegate::ResetDecoder( 560 bool ContentDecryptorDelegate::ResetDecoder(
492 media::Decryptor::StreamType stream_type) { 561 media::Decryptor::StreamType stream_type) {
562 if (is_instance_crashed_)
563 return false;
564
493 CancelDecode(stream_type); 565 CancelDecode(stream_type);
494 566
495 // TODO(tomfinegan): Add decoder reset request tracking. 567 // TODO(tomfinegan): Add decoder reset request tracking.
496 plugin_decryption_interface_->ResetDecoder( 568 plugin_decryption_interface_->ResetDecoder(
497 pp_instance_, MediaDecryptorStreamTypeToPpStreamType(stream_type), 0); 569 pp_instance_, MediaDecryptorStreamTypeToPpStreamType(stream_type), 0);
498 return true; 570 return true;
499 } 571 }
500 572
501 bool ContentDecryptorDelegate::DecryptAndDecodeAudio( 573 bool ContentDecryptorDelegate::DecryptAndDecodeAudio(
502 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, 574 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer,
503 const media::Decryptor::AudioDecodeCB& audio_decode_cb) { 575 const media::Decryptor::AudioDecodeCB& audio_decode_cb) {
576 if (is_instance_crashed_)
577 return false;
578
504 // |audio_input_resource_| is not being used by the plugin now 579 // |audio_input_resource_| is not being used by the plugin now
505 // because there is only one pending audio decode request at any time. 580 // because there is only one pending audio decode request at any time.
506 // This is enforced by the media pipeline. 581 // This is enforced by the media pipeline.
507 scoped_refptr<PPB_Buffer_Impl> encrypted_resource; 582 scoped_refptr<PPB_Buffer_Impl> encrypted_resource;
508 if (!MakeMediaBufferResource(media::Decryptor::kAudio, 583 if (!MakeMediaBufferResource(media::Decryptor::kAudio,
509 encrypted_buffer, 584 encrypted_buffer,
510 &encrypted_resource)) { 585 &encrypted_resource)) {
511 return false; 586 return false;
512 } 587 }
513 588
(...skipping 24 matching lines...) Expand all
538 plugin_decryption_interface_->DecryptAndDecode(pp_instance_, 613 plugin_decryption_interface_->DecryptAndDecode(pp_instance_,
539 PP_DECRYPTORSTREAMTYPE_AUDIO, 614 PP_DECRYPTORSTREAMTYPE_AUDIO,
540 pp_resource, 615 pp_resource,
541 &block_info); 616 &block_info);
542 return true; 617 return true;
543 } 618 }
544 619
545 bool ContentDecryptorDelegate::DecryptAndDecodeVideo( 620 bool ContentDecryptorDelegate::DecryptAndDecodeVideo(
546 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, 621 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer,
547 const media::Decryptor::VideoDecodeCB& video_decode_cb) { 622 const media::Decryptor::VideoDecodeCB& video_decode_cb) {
623 if (is_instance_crashed_)
624 return false;
625
548 // |video_input_resource_| is not being used by the plugin now 626 // |video_input_resource_| is not being used by the plugin now
549 // because there is only one pending video decode request at any time. 627 // because there is only one pending video decode request at any time.
550 // This is enforced by the media pipeline. 628 // This is enforced by the media pipeline.
551 scoped_refptr<PPB_Buffer_Impl> encrypted_resource; 629 scoped_refptr<PPB_Buffer_Impl> encrypted_resource;
552 if (!MakeMediaBufferResource(media::Decryptor::kVideo, 630 if (!MakeMediaBufferResource(media::Decryptor::kVideo,
553 encrypted_buffer, 631 encrypted_buffer,
554 &encrypted_resource)) { 632 &encrypted_resource)) {
555 return false; 633 return false;
556 } 634 }
557 635
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after
1068 frames->push_back(frame); 1146 frames->push_back(frame);
1069 1147
1070 cur += frame_size; 1148 cur += frame_size;
1071 bytes_left -= frame_size; 1149 bytes_left -= frame_size;
1072 } while (bytes_left > 0); 1150 } while (bytes_left > 0);
1073 1151
1074 return true; 1152 return true;
1075 } 1153 }
1076 1154
1077 } // namespace content 1155 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698