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 #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/numerics/safe_conversions.h" | 10 #include "base/numerics/safe_conversions.h" |
| 11 #include "content/renderer/pepper/ppb_buffer_impl.h" | 11 #include "content/renderer/pepper/ppb_buffer_impl.h" |
| 12 #include "media/base/audio_buffer.h" | 12 #include "media/base/audio_buffer.h" |
| 13 #include "media/base/audio_decoder_config.h" | 13 #include "media/base/audio_decoder_config.h" |
| 14 #include "media/base/bind_to_current_loop.h" | 14 #include "media/base/bind_to_current_loop.h" |
| 15 #include "media/base/cdm_promise.h" | |
| 15 #include "media/base/channel_layout.h" | 16 #include "media/base/channel_layout.h" |
| 16 #include "media/base/data_buffer.h" | 17 #include "media/base/data_buffer.h" |
| 17 #include "media/base/decoder_buffer.h" | 18 #include "media/base/decoder_buffer.h" |
| 18 #include "media/base/decrypt_config.h" | 19 #include "media/base/decrypt_config.h" |
| 19 #include "media/base/video_decoder_config.h" | 20 #include "media/base/video_decoder_config.h" |
| 20 #include "media/base/video_frame.h" | 21 #include "media/base/video_frame.h" |
| 21 #include "media/base/video_util.h" | 22 #include "media/base/video_util.h" |
| 22 #include "ppapi/shared_impl/scoped_pp_resource.h" | 23 #include "ppapi/shared_impl/scoped_pp_resource.h" |
| 23 #include "ppapi/shared_impl/var.h" | 24 #include "ppapi/shared_impl/var.h" |
| 24 #include "ppapi/shared_impl/var_tracker.h" | 25 #include "ppapi/shared_impl/var_tracker.h" |
| 25 #include "ppapi/thunk/enter.h" | 26 #include "ppapi/thunk/enter.h" |
| 26 #include "ppapi/thunk/ppb_buffer_api.h" | 27 #include "ppapi/thunk/ppb_buffer_api.h" |
| 27 #include "ui/gfx/rect.h" | 28 #include "ui/gfx/rect.h" |
| 28 | 29 |
| 29 using media::Decryptor; | 30 using media::Decryptor; |
|
xhwang
2014/05/23 06:01:23
nit: using media::*Promise and media::MediaKeys he
jrummell
2014/05/29 00:54:40
Looks like it's done sometimes and not others. Cha
| |
| 30 using ppapi::ArrayBufferVar; | 31 using ppapi::ArrayBufferVar; |
| 31 using ppapi::PpapiGlobals; | 32 using ppapi::PpapiGlobals; |
| 32 using ppapi::ScopedPPResource; | 33 using ppapi::ScopedPPResource; |
| 33 using ppapi::StringVar; | 34 using ppapi::StringVar; |
| 34 using ppapi::thunk::EnterResourceNoLock; | 35 using ppapi::thunk::EnterResourceNoLock; |
| 35 using ppapi::thunk::PPB_Buffer_API; | 36 using ppapi::thunk::PPB_Buffer_API; |
| 36 | 37 |
| 37 namespace content { | 38 namespace content { |
| 38 | 39 |
| 39 namespace { | 40 namespace { |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 238 case PP_DECRYPTEDSAMPLEFORMAT_PLANAR_S16: | 239 case PP_DECRYPTEDSAMPLEFORMAT_PLANAR_S16: |
| 239 return media::kSampleFormatPlanarS16; | 240 return media::kSampleFormatPlanarS16; |
| 240 case PP_DECRYPTEDSAMPLEFORMAT_PLANAR_F32: | 241 case PP_DECRYPTEDSAMPLEFORMAT_PLANAR_F32: |
| 241 return media::kSampleFormatPlanarF32; | 242 return media::kSampleFormatPlanarF32; |
| 242 default: | 243 default: |
| 243 NOTREACHED(); | 244 NOTREACHED(); |
| 244 return media::kUnknownSampleFormat; | 245 return media::kUnknownSampleFormat; |
| 245 } | 246 } |
| 246 } | 247 } |
| 247 | 248 |
| 249 PP_SessionType MediaSessionTypeToPpSessionType( | |
| 250 media::MediaKeys::SessionType session_type) { | |
| 251 switch (session_type) { | |
| 252 case media::MediaKeys::SESSION_TYPE_TEMPORARY: | |
| 253 return PP_SESSIONTYPE_TEMPORARY; | |
| 254 case media::MediaKeys::SESSION_TYPE_PERSISTENT: | |
| 255 return PP_SESSIONTYPE_PERSISTENT; | |
| 256 default: | |
| 257 NOTREACHED(); | |
| 258 return PP_SESSIONTYPE_TEMPORARY; | |
| 259 } | |
| 260 } | |
| 261 | |
| 262 media::MediaKeys::Exception PpExceptionTypeToMediaException( | |
| 263 PP_ExceptionCode exception_code) { | |
| 264 switch (exception_code) { | |
| 265 case PP_EXCEPTIONCODE_NOMODIFICATIONALLOWEDERROR: | |
| 266 return media::MediaKeys::EXCEPTION_NO_MODIFICATION_ALLOWED_ERROR; | |
| 267 case PP_EXCEPTIONCODE_NOTFOUNDERROR: | |
| 268 return media::MediaKeys::EXCEPTION_NOT_FOUND_ERROR; | |
| 269 case PP_EXCEPTIONCODE_NOTSUPPORTEDERROR: | |
| 270 return media::MediaKeys::EXCEPTION_NOT_SUPPORTED_ERROR; | |
| 271 case PP_EXCEPTIONCODE_INVALIDSTATEERROR: | |
| 272 return media::MediaKeys::EXCEPTION_INVALID_STATE_ERROR; | |
| 273 case PP_EXCEPTIONCODE_INVALIDMODIFICATIONERROR: | |
| 274 return media::MediaKeys::EXCEPTION_INVALID_MODIFICATION_ERROR; | |
| 275 case PP_EXCEPTIONCODE_INVALIDACCESSERROR: | |
| 276 return media::MediaKeys::EXCEPTION_INVALID_ACCESS_ERROR; | |
| 277 case PP_EXCEPTIONCODE_SECURITYERROR: | |
| 278 return media::MediaKeys::EXCEPTION_SECURITY_ERROR; | |
| 279 case PP_EXCEPTIONCODE_ABORTERROR: | |
| 280 return media::MediaKeys::EXCEPTION_ABORT_ERROR; | |
| 281 case PP_EXCEPTIONCODE_QUOTAEXCEEDEDERROR: | |
| 282 return media::MediaKeys::EXCEPTION_QUOTA_EXCEEDED_ERROR; | |
| 283 case PP_EXCEPTIONCODE_TIMEOUTERROR: | |
| 284 return media::MediaKeys::EXCEPTION_TIMEOUT_ERROR; | |
| 285 case PP_EXCEPTIONCODE_UNKNOWNERROR: | |
| 286 return media::MediaKeys::EXCEPTION_UNKNOWN_ERROR; | |
| 287 case PP_EXCEPTIONCODE_DATAERROR: | |
| 288 return media::MediaKeys::EXCEPTION_DATA_ERROR; | |
| 289 case PP_EXCEPTIONCODE_VERSIONERROR: | |
| 290 return media::MediaKeys::EXCEPTION_VERSION_ERROR; | |
| 291 case PP_EXCEPTIONCODE_NOTREADABLEERROR: | |
| 292 return media::MediaKeys::EXCEPTION_NOT_READABLE_ERROR; | |
| 293 case PP_EXCEPTIONCODE_OPERATIONERROR: | |
| 294 return media::MediaKeys::EXCEPTION_OPERATION_ERROR; | |
| 295 case PP_EXCEPTIONCODE_CLIENTERROR: | |
| 296 return media::MediaKeys::EXCEPTION_CLIENT_ERROR; | |
| 297 case PP_EXCEPTIONCODE_OUTPUTERROR: | |
| 298 return media::MediaKeys::EXCEPTION_OUTPUT_ERROR; | |
| 299 default: | |
| 300 NOTREACHED(); | |
| 301 return media::MediaKeys::EXCEPTION_UNKNOWN_ERROR; | |
| 302 } | |
| 303 } | |
| 304 | |
| 248 } // namespace | 305 } // namespace |
| 249 | 306 |
| 250 ContentDecryptorDelegate::ContentDecryptorDelegate( | 307 ContentDecryptorDelegate::ContentDecryptorDelegate( |
| 251 PP_Instance pp_instance, | 308 PP_Instance pp_instance, |
| 252 const PPP_ContentDecryptor_Private* plugin_decryption_interface) | 309 const PPP_ContentDecryptor_Private* plugin_decryption_interface) |
| 253 : pp_instance_(pp_instance), | 310 : pp_instance_(pp_instance), |
| 254 plugin_decryption_interface_(plugin_decryption_interface), | 311 plugin_decryption_interface_(plugin_decryption_interface), |
| 255 next_decryption_request_id_(1), | 312 next_decryption_request_id_(1), |
| 256 audio_samples_per_second_(0), | 313 audio_samples_per_second_(0), |
| 257 audio_channel_count_(0), | 314 audio_channel_count_(0), |
| 258 audio_channel_layout_(media::CHANNEL_LAYOUT_NONE), | 315 audio_channel_layout_(media::CHANNEL_LAYOUT_NONE), |
| 316 next_promise_id_(0), | |
| 259 weak_ptr_factory_(this) { | 317 weak_ptr_factory_(this) { |
| 260 weak_this_ = weak_ptr_factory_.GetWeakPtr(); | 318 weak_this_ = weak_ptr_factory_.GetWeakPtr(); |
| 261 } | 319 } |
| 262 | 320 |
| 263 ContentDecryptorDelegate::~ContentDecryptorDelegate() { | 321 ContentDecryptorDelegate::~ContentDecryptorDelegate() { |
| 264 SatisfyAllPendingCallbacksOnError(); | 322 SatisfyAllPendingCallbacksOnError(); |
| 265 } | 323 } |
| 266 | 324 |
| 267 void ContentDecryptorDelegate::Initialize( | 325 void ContentDecryptorDelegate::Initialize( |
| 268 const std::string& key_system, | 326 const std::string& key_system, |
| 269 const media::SessionCreatedCB& session_created_cb, | |
| 270 const media::SessionMessageCB& session_message_cb, | 327 const media::SessionMessageCB& session_message_cb, |
| 271 const media::SessionReadyCB& session_ready_cb, | 328 const media::SessionReadyCB& session_ready_cb, |
| 272 const media::SessionClosedCB& session_closed_cb, | 329 const media::SessionClosedCB& session_closed_cb, |
| 273 const media::SessionErrorCB& session_error_cb, | 330 const media::SessionErrorCB& session_error_cb, |
| 274 const base::Closure& fatal_plugin_error_cb) { | 331 const base::Closure& fatal_plugin_error_cb) { |
| 275 DCHECK(!key_system.empty()); | 332 DCHECK(!key_system.empty()); |
| 276 DCHECK(key_system_.empty()); | 333 DCHECK(key_system_.empty()); |
| 277 key_system_ = key_system; | 334 key_system_ = key_system; |
| 278 | 335 |
| 279 session_created_cb_ = session_created_cb; | |
| 280 session_message_cb_ = session_message_cb; | 336 session_message_cb_ = session_message_cb; |
| 281 session_ready_cb_ = session_ready_cb; | 337 session_ready_cb_ = session_ready_cb; |
| 282 session_closed_cb_ = session_closed_cb; | 338 session_closed_cb_ = session_closed_cb; |
| 283 session_error_cb_ = session_error_cb; | 339 session_error_cb_ = session_error_cb; |
| 284 fatal_plugin_error_cb_ = fatal_plugin_error_cb; | 340 fatal_plugin_error_cb_ = fatal_plugin_error_cb; |
| 285 | 341 |
| 286 plugin_decryption_interface_->Initialize( | 342 plugin_decryption_interface_->Initialize( |
| 287 pp_instance_, StringVar::StringToPPVar(key_system_)); | 343 pp_instance_, StringVar::StringToPPVar(key_system_)); |
| 288 } | 344 } |
| 289 | 345 |
| 290 void ContentDecryptorDelegate::InstanceCrashed() { | 346 void ContentDecryptorDelegate::InstanceCrashed() { |
| 291 fatal_plugin_error_cb_.Run(); | 347 fatal_plugin_error_cb_.Run(); |
| 292 SatisfyAllPendingCallbacksOnError(); | 348 SatisfyAllPendingCallbacksOnError(); |
| 293 } | 349 } |
| 294 | 350 |
| 295 bool ContentDecryptorDelegate::CreateSession(uint32 session_id, | 351 void ContentDecryptorDelegate::CreateSession( |
| 296 const std::string& content_type, | 352 const std::string& init_data_type, |
| 297 const uint8* init_data, | 353 const uint8* init_data, |
| 298 int init_data_length) { | 354 int init_data_length, |
| 355 media::MediaKeys::SessionType session_type, | |
| 356 scoped_ptr<media::NewSessionCdmPromise> promise) { | |
| 357 uint32_t promise_id = SaveNewSessionPromise(promise.Pass()); | |
| 299 PP_Var init_data_array = | 358 PP_Var init_data_array = |
| 300 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar( | 359 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar( |
| 301 init_data_length, init_data); | 360 init_data_length, init_data); |
| 302 | |
| 303 plugin_decryption_interface_->CreateSession( | 361 plugin_decryption_interface_->CreateSession( |
| 304 pp_instance_, | 362 pp_instance_, |
| 305 session_id, | 363 promise_id, |
| 306 StringVar::StringToPPVar(content_type), | 364 StringVar::StringToPPVar(init_data_type), |
| 307 init_data_array); | 365 init_data_array, |
| 308 return true; | 366 MediaSessionTypeToPpSessionType(session_type)); |
| 309 } | 367 } |
| 310 | 368 |
| 311 void ContentDecryptorDelegate::LoadSession(uint32 session_id, | 369 void ContentDecryptorDelegate::LoadSession( |
| 312 const std::string& web_session_id) { | 370 const std::string& web_session_id, |
| 371 scoped_ptr<media::NewSessionCdmPromise> promise) { | |
| 372 uint32_t promise_id = SaveNewSessionPromise(promise.Pass()); | |
| 313 plugin_decryption_interface_->LoadSession( | 373 plugin_decryption_interface_->LoadSession( |
| 314 pp_instance_, session_id, StringVar::StringToPPVar(web_session_id)); | 374 pp_instance_, promise_id, StringVar::StringToPPVar(web_session_id)); |
| 315 } | 375 } |
| 316 | 376 |
| 317 bool ContentDecryptorDelegate::UpdateSession(uint32 session_id, | 377 void ContentDecryptorDelegate::UpdateSession( |
| 318 const uint8* response, | 378 const std::string& web_session_id, |
| 319 int response_length) { | 379 const uint8* response, |
| 380 int response_length, | |
| 381 scoped_ptr<media::SimpleCdmPromise> promise) { | |
| 382 uint32_t promise_id = SaveSimplePromise(promise.Pass()); | |
| 320 PP_Var response_array = | 383 PP_Var response_array = |
| 321 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar( | 384 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar( |
| 322 response_length, response); | 385 response_length, response); |
| 323 plugin_decryption_interface_->UpdateSession( | 386 plugin_decryption_interface_->UpdateSession( |
| 324 pp_instance_, session_id, response_array); | 387 pp_instance_, |
| 325 return true; | 388 promise_id, |
| 389 StringVar::StringToPPVar(web_session_id), | |
| 390 response_array); | |
| 326 } | 391 } |
| 327 | 392 |
| 328 bool ContentDecryptorDelegate::ReleaseSession(uint32 session_id) { | 393 void ContentDecryptorDelegate::ReleaseSession( |
| 329 plugin_decryption_interface_->ReleaseSession(pp_instance_, session_id); | 394 const std::string& web_session_id, |
| 330 return true; | 395 scoped_ptr<media::SimpleCdmPromise> promise) { |
| 396 uint32_t promise_id = SaveSimplePromise(promise.Pass()); | |
| 397 plugin_decryption_interface_->ReleaseSession( | |
| 398 pp_instance_, promise_id, StringVar::StringToPPVar(web_session_id)); | |
| 331 } | 399 } |
| 332 | 400 |
| 333 // TODO(xhwang): Remove duplication of code in Decrypt(), | 401 // TODO(xhwang): Remove duplication of code in Decrypt(), |
| 334 // DecryptAndDecodeAudio() and DecryptAndDecodeVideo(). | 402 // DecryptAndDecodeAudio() and DecryptAndDecodeVideo(). |
| 335 bool ContentDecryptorDelegate::Decrypt( | 403 bool ContentDecryptorDelegate::Decrypt( |
| 336 Decryptor::StreamType stream_type, | 404 Decryptor::StreamType stream_type, |
| 337 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, | 405 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, |
| 338 const Decryptor::DecryptCB& decrypt_cb) { | 406 const Decryptor::DecryptCB& decrypt_cb) { |
| 339 DVLOG(3) << "Decrypt() - stream_type: " << stream_type; | 407 DVLOG(3) << "Decrypt() - stream_type: " << stream_type; |
| 340 | 408 |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 566 // buffer. | 634 // buffer. |
| 567 video_decode_cb_.Set(request_id, video_decode_cb); | 635 video_decode_cb_.Set(request_id, video_decode_cb); |
| 568 | 636 |
| 569 // TODO(tomfinegan): Need to get stream type from media stack. | 637 // TODO(tomfinegan): Need to get stream type from media stack. |
| 570 ScopedPPResource pp_resource(encrypted_resource.get()); | 638 ScopedPPResource pp_resource(encrypted_resource.get()); |
| 571 plugin_decryption_interface_->DecryptAndDecode( | 639 plugin_decryption_interface_->DecryptAndDecode( |
| 572 pp_instance_, PP_DECRYPTORSTREAMTYPE_VIDEO, pp_resource, &block_info); | 640 pp_instance_, PP_DECRYPTORSTREAMTYPE_VIDEO, pp_resource, &block_info); |
| 573 return true; | 641 return true; |
| 574 } | 642 } |
| 575 | 643 |
| 576 void ContentDecryptorDelegate::OnSessionCreated(uint32 session_id, | 644 void ContentDecryptorDelegate::OnPromiseResolved(uint32 promise_id) { |
| 577 PP_Var web_session_id_var) { | 645 scoped_ptr<media::SimpleCdmPromise> promise = TakeSimplePromise(promise_id); |
| 578 if (session_created_cb_.is_null()) | 646 promise->resolve(); |
|
xhwang
2014/05/23 06:01:23
Is the CdmWrapper making sure the |promise_id| ret
jrummell
2014/05/29 00:54:40
Done.
| |
| 579 return; | |
| 580 | |
| 581 StringVar* session_id_string = StringVar::FromPPVar(web_session_id_var); | |
| 582 | |
| 583 if (!session_id_string) { | |
| 584 OnSessionError(session_id, media::MediaKeys::kUnknownError, 0); | |
| 585 return; | |
| 586 } | |
| 587 | |
| 588 session_created_cb_.Run(session_id, session_id_string->value()); | |
| 589 } | 647 } |
| 590 | 648 |
| 591 void ContentDecryptorDelegate::OnSessionMessage(uint32 session_id, | 649 void ContentDecryptorDelegate::OnPromiseResolvedWithSession( |
| 650 uint32 promise_id, | |
| 651 PP_Var web_session_id_var) { | |
| 652 scoped_ptr<media::NewSessionCdmPromise> promise = | |
| 653 TakeNewSessionPromise(promise_id); | |
| 654 | |
| 655 StringVar* web_session_id = StringVar::FromPPVar(web_session_id_var); | |
| 656 DCHECK(web_session_id); | |
| 657 | |
| 658 promise->resolve(web_session_id->value()); | |
| 659 } | |
| 660 | |
| 661 void ContentDecryptorDelegate::OnPromiseRejected( | |
| 662 uint32 promise_id, | |
| 663 PP_ExceptionCode exception_code, | |
| 664 uint32 system_code, | |
| 665 PP_Var error_description_var) { | |
| 666 StringVar* error_description = StringVar::FromPPVar(error_description_var); | |
| 667 DCHECK(error_description); | |
| 668 | |
| 669 scoped_ptr<media::NewSessionCdmPromise> promise = | |
| 670 TakeNewSessionPromise(promise_id); | |
| 671 if (promise) { | |
| 672 promise->reject(PpExceptionTypeToMediaException(exception_code), | |
| 673 system_code, | |
| 674 error_description->value()); | |
|
xhwang
2014/05/23 06:01:23
nit: return early here so that you don't need the
jrummell
2014/05/29 00:54:40
Done.
| |
| 675 } else { | |
| 676 scoped_ptr<media::SimpleCdmPromise> promise = TakeSimplePromise(promise_id); | |
| 677 promise->reject(PpExceptionTypeToMediaException(exception_code), | |
| 678 system_code, | |
| 679 error_description->value()); | |
| 680 } | |
| 681 } | |
| 682 | |
| 683 void ContentDecryptorDelegate::OnSessionMessage(PP_Var web_session_id_var, | |
| 592 PP_Var message_var, | 684 PP_Var message_var, |
| 593 PP_Var default_url_var) { | 685 PP_Var destination_url_var) { |
| 594 if (session_message_cb_.is_null()) | 686 if (session_message_cb_.is_null()) |
| 595 return; | 687 return; |
| 596 | 688 |
| 689 StringVar* web_session_id = StringVar::FromPPVar(web_session_id_var); | |
| 690 DCHECK(web_session_id); | |
| 691 | |
| 597 ArrayBufferVar* message_array_buffer = ArrayBufferVar::FromPPVar(message_var); | 692 ArrayBufferVar* message_array_buffer = ArrayBufferVar::FromPPVar(message_var); |
| 598 | |
| 599 std::vector<uint8> message; | 693 std::vector<uint8> message; |
| 600 if (message_array_buffer) { | 694 if (message_array_buffer) { |
| 601 const uint8* data = static_cast<const uint8*>(message_array_buffer->Map()); | 695 const uint8* data = static_cast<const uint8*>(message_array_buffer->Map()); |
| 602 message.assign(data, data + message_array_buffer->ByteLength()); | 696 message.assign(data, data + message_array_buffer->ByteLength()); |
| 603 } | 697 } |
| 604 | 698 |
| 605 StringVar* default_url_string = StringVar::FromPPVar(default_url_var); | 699 StringVar* destination_url_string = StringVar::FromPPVar(destination_url_var); |
| 700 DCHECK(destination_url_string); | |
| 606 | 701 |
| 607 if (!default_url_string) { | 702 session_message_cb_.Run( |
| 608 OnSessionError(session_id, media::MediaKeys::kUnknownError, 0); | 703 web_session_id->value(), message, destination_url_string->value()); |
| 609 return; | |
| 610 } | |
| 611 | |
| 612 session_message_cb_.Run(session_id, message, default_url_string->value()); | |
| 613 } | 704 } |
| 614 | 705 |
| 615 void ContentDecryptorDelegate::OnSessionReady(uint32 session_id) { | 706 void ContentDecryptorDelegate::OnSessionReady(PP_Var web_session_id_var) { |
| 616 if (session_ready_cb_.is_null()) | 707 if (session_ready_cb_.is_null()) |
| 617 return; | 708 return; |
| 618 | 709 |
| 619 session_ready_cb_.Run(session_id); | 710 StringVar* web_session_id = StringVar::FromPPVar(web_session_id_var); |
| 711 DCHECK(web_session_id); | |
| 712 | |
| 713 session_ready_cb_.Run(web_session_id->value()); | |
| 620 } | 714 } |
| 621 | 715 |
| 622 void ContentDecryptorDelegate::OnSessionClosed(uint32 session_id) { | 716 void ContentDecryptorDelegate::OnSessionClosed(PP_Var web_session_id_var) { |
| 623 if (session_closed_cb_.is_null()) | 717 if (session_closed_cb_.is_null()) |
| 624 return; | 718 return; |
| 625 | 719 |
| 626 session_closed_cb_.Run(session_id); | 720 StringVar* web_session_id = StringVar::FromPPVar(web_session_id_var); |
| 721 DCHECK(web_session_id); | |
| 722 | |
| 723 session_closed_cb_.Run(web_session_id->value()); | |
| 627 } | 724 } |
| 628 | 725 |
| 629 void ContentDecryptorDelegate::OnSessionError(uint32 session_id, | 726 void ContentDecryptorDelegate::OnSessionError(PP_Var web_session_id_var, |
| 630 int32_t media_error, | 727 PP_ExceptionCode exception_code, |
| 631 uint32_t system_code) { | 728 uint32 system_code, |
| 729 PP_Var error_description_var) { | |
| 632 if (session_error_cb_.is_null()) | 730 if (session_error_cb_.is_null()) |
| 633 return; | 731 return; |
| 634 | 732 |
| 635 session_error_cb_.Run(session_id, | 733 StringVar* web_session_id = StringVar::FromPPVar(web_session_id_var); |
| 636 static_cast<media::MediaKeys::KeyError>(media_error), | 734 DCHECK(web_session_id); |
| 637 system_code); | 735 |
| 736 StringVar* error_description = StringVar::FromPPVar(error_description_var); | |
| 737 DCHECK(error_description); | |
| 738 | |
| 739 session_error_cb_.Run(web_session_id->value(), | |
| 740 PpExceptionTypeToMediaException(exception_code), | |
| 741 system_code, | |
| 742 error_description->value()); | |
| 638 } | 743 } |
| 639 | 744 |
| 640 void ContentDecryptorDelegate::DecoderInitializeDone( | 745 void ContentDecryptorDelegate::DecoderInitializeDone( |
| 641 PP_DecryptorStreamType decoder_type, | 746 PP_DecryptorStreamType decoder_type, |
| 642 uint32_t request_id, | 747 uint32_t request_id, |
| 643 PP_Bool success) { | 748 PP_Bool success) { |
| 644 if (decoder_type == PP_DECRYPTORSTREAMTYPE_AUDIO) { | 749 if (decoder_type == PP_DECRYPTORSTREAMTYPE_AUDIO) { |
| 645 // If the request ID is not valid or does not match what's saved, do | 750 // If the request ID is not valid or does not match what's saved, do |
| 646 // nothing. | 751 // nothing. |
| 647 if (request_id == 0 || !audio_decoder_init_cb_.Matches(request_id)) | 752 if (request_id == 0 || !audio_decoder_init_cb_.Matches(request_id)) |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1053 video_decrypt_cb_.ResetAndReturn().Run(media::Decryptor::kError, NULL); | 1158 video_decrypt_cb_.ResetAndReturn().Run(media::Decryptor::kError, NULL); |
| 1054 | 1159 |
| 1055 if (!audio_decode_cb_.is_null()) { | 1160 if (!audio_decode_cb_.is_null()) { |
| 1056 const media::Decryptor::AudioBuffers empty_frames; | 1161 const media::Decryptor::AudioBuffers empty_frames; |
| 1057 audio_decode_cb_.ResetAndReturn().Run(media::Decryptor::kError, | 1162 audio_decode_cb_.ResetAndReturn().Run(media::Decryptor::kError, |
| 1058 empty_frames); | 1163 empty_frames); |
| 1059 } | 1164 } |
| 1060 | 1165 |
| 1061 if (!video_decode_cb_.is_null()) | 1166 if (!video_decode_cb_.is_null()) |
| 1062 video_decode_cb_.ResetAndReturn().Run(media::Decryptor::kError, NULL); | 1167 video_decode_cb_.ResetAndReturn().Run(media::Decryptor::kError, NULL); |
| 1168 | |
| 1169 // TODO(jrummell): Reject all outstanding promises. Currently some tests | |
| 1170 // (ECKEncryptedMediaTest.CDMExpectedCrash and CDMCrashDuringDecode) | |
| 1171 // trigger a crash in the CDM, and don't handle the response to the pending | |
| 1172 // request. Once blink:: uses promises, this will be required. | |
| 1173 } | |
| 1174 | |
| 1175 uint32_t ContentDecryptorDelegate::SaveSimplePromise( | |
| 1176 scoped_ptr<media::SimpleCdmPromise> promise) { | |
| 1177 uint32_t promise_id = ++next_promise_id_; | |
| 1178 simple_promises_.insert(std::make_pair(promise_id, promise.release())); | |
| 1179 return promise_id; | |
| 1180 } | |
| 1181 | |
| 1182 scoped_ptr<media::SimpleCdmPromise> ContentDecryptorDelegate::TakeSimplePromise( | |
| 1183 uint32_t promise_id) { | |
| 1184 std::map<uint32_t, media::SimpleCdmPromise*>::iterator it = | |
| 1185 simple_promises_.find(promise_id); | |
| 1186 if (it == simple_promises_.end()) | |
| 1187 return scoped_ptr<media::SimpleCdmPromise>(); | |
| 1188 scoped_ptr<media::SimpleCdmPromise> result(it->second); | |
| 1189 simple_promises_.erase(it); | |
| 1190 return result.Pass(); | |
| 1191 } | |
| 1192 | |
| 1193 uint32_t ContentDecryptorDelegate::SaveNewSessionPromise( | |
| 1194 scoped_ptr<media::NewSessionCdmPromise> promise) { | |
| 1195 uint32_t promise_id = ++next_promise_id_; | |
| 1196 new_session_promises_.insert(std::make_pair(promise_id, promise.release())); | |
| 1197 return promise_id; | |
| 1198 } | |
| 1199 | |
| 1200 scoped_ptr<media::NewSessionCdmPromise> | |
| 1201 ContentDecryptorDelegate::TakeNewSessionPromise(uint32_t promise_id) { | |
| 1202 std::map<uint32_t, media::NewSessionCdmPromise*>::iterator it = | |
| 1203 new_session_promises_.find(promise_id); | |
| 1204 if (it == new_session_promises_.end()) | |
| 1205 return scoped_ptr<media::NewSessionCdmPromise>(); | |
| 1206 scoped_ptr<media::NewSessionCdmPromise> result(it->second); | |
| 1207 new_session_promises_.erase(it); | |
| 1208 return result.Pass(); | |
|
xhwang
2014/05/23 06:01:23
There are some duplication here:
1, 2 maps instead
jrummell
2014/05/29 00:54:40
Done.
| |
| 1063 } | 1209 } |
| 1064 | 1210 |
| 1065 } // namespace content | 1211 } // namespace content |
| OLD | NEW |