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 "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 5 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/memory/linked_ptr.h" | 11 #include "base/memory/linked_ptr.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
14 #include "base/stringprintf.h" | 14 #include "base/stringprintf.h" |
15 #include "base/time.h" | 15 #include "base/time.h" |
16 #include "base/utf_offset_string_conversions.h" | 16 #include "base/utf_offset_string_conversions.h" |
17 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
18 // TODO(xhwang): Move media specific code out of this class. | 18 // TODO(xhwang): Move media specific code out of this class. |
19 #include "media/base/audio_decoder_config.h" | 19 #include "media/base/audio_decoder_config.h" |
20 #include "media/base/channel_layout.h" | |
21 #include "media/base/data_buffer.h" | |
20 #include "media/base/decoder_buffer.h" | 22 #include "media/base/decoder_buffer.h" |
21 #include "media/base/decryptor_client.h" | 23 #include "media/base/decryptor_client.h" |
22 #include "media/base/video_decoder_config.h" | 24 #include "media/base/video_decoder_config.h" |
23 #include "media/base/video_frame.h" | 25 #include "media/base/video_frame.h" |
24 #include "media/base/video_util.h" | 26 #include "media/base/video_util.h" |
25 #include "ppapi/c/dev/ppb_find_dev.h" | 27 #include "ppapi/c/dev/ppb_find_dev.h" |
26 #include "ppapi/c/dev/ppb_zoom_dev.h" | 28 #include "ppapi/c/dev/ppb_zoom_dev.h" |
27 #include "ppapi/c/dev/ppp_find_dev.h" | 29 #include "ppapi/c/dev/ppp_find_dev.h" |
28 #include "ppapi/c/dev/ppp_selection_dev.h" | 30 #include "ppapi/c/dev/ppp_selection_dev.h" |
29 #include "ppapi/c/dev/ppp_text_input_dev.h" | 31 #include "ppapi/c/dev/ppp_text_input_dev.h" |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
385 for (uint32_t i = 0; i < block_info->num_subsamples; ++i) { | 387 for (uint32_t i = 0; i < block_info->num_subsamples; ++i) { |
386 block_info->subsamples[i].clear_bytes = | 388 block_info->subsamples[i].clear_bytes = |
387 decrypt_config->subsamples()[i].clear_bytes; | 389 decrypt_config->subsamples()[i].clear_bytes; |
388 block_info->subsamples[i].cipher_bytes = | 390 block_info->subsamples[i].cipher_bytes = |
389 decrypt_config->subsamples()[i].cypher_bytes; | 391 decrypt_config->subsamples()[i].cypher_bytes; |
390 } | 392 } |
391 | 393 |
392 return true; | 394 return true; |
393 } | 395 } |
394 | 396 |
397 // Deserializes audio data stored in |audio_frames| into individual audio | |
398 // buffers in |frames|. Returns true upon success. | |
399 bool DeserializeAudioFrames(PP_Resource audio_frames, | |
400 media::Decryptor::AudioBuffers* frames) { | |
401 DCHECK(frames); | |
402 EnterResourceNoLock<PPB_Buffer_API> enter(audio_frames, true); | |
403 if (!enter.succeeded()) | |
404 return false; | |
405 | |
406 BufferAutoMapper mapper(enter.object()); | |
407 if (!mapper.data() || !mapper.size()) | |
408 return false; | |
409 | |
410 const uint8* cur = static_cast<uint8*>(mapper.data()); | |
411 int bytes_left = mapper.size(); | |
412 | |
413 do { | |
414 int64 timestamp = 0; | |
415 int64 frame_size = -1; | |
416 const int kHeaderSize = sizeof(timestamp) + sizeof(frame_size); | |
417 | |
418 if (bytes_left < kHeaderSize) | |
419 return false; | |
420 | |
421 timestamp = *(reinterpret_cast<const int64*>(cur)); | |
viettrungluu
2012/10/24 16:59:20
You should probably use bit_cast (see basictypes.h
xhwang
2012/10/24 18:57:14
It seems bit_cast only works on casting two types
| |
422 cur += sizeof(timestamp); | |
423 bytes_left -= sizeof(timestamp); | |
424 | |
425 frame_size = *(reinterpret_cast<const int64*>(cur)); | |
viettrungluu
2012/10/24 16:59:20
"
xhwang
2012/10/24 18:57:14
ditto
| |
426 cur += sizeof(frame_size); | |
427 bytes_left -= sizeof(frame_size); | |
428 | |
429 if (frame_size < 0 || bytes_left < frame_size) | |
430 return false; | |
431 | |
432 scoped_refptr<media::DataBuffer> frame(new media::DataBuffer(frame_size)); | |
433 if (frame_size > 0) { | |
434 memcpy(frame->GetWritableData(), cur, frame_size); | |
435 frame->SetTimestamp(base::TimeDelta::FromMicroseconds(timestamp)); | |
viettrungluu
2012/10/24 16:59:20
You don't set the timestamp if frame_size == 0 (ev
xhwang
2012/10/24 18:57:14
It's okay not to set timestamp to an empty frame.
| |
436 cur += frame_size; | |
437 bytes_left -= frame_size; | |
438 } | |
439 frames->push_back(frame); | |
440 } while (bytes_left > 0); | |
441 | |
442 return true; | |
443 } | |
444 | |
395 PP_AudioCodec MediaAudioCodecToPpAudioCodec(media::AudioCodec codec) { | 445 PP_AudioCodec MediaAudioCodecToPpAudioCodec(media::AudioCodec codec) { |
396 switch (codec) { | 446 switch (codec) { |
397 case media::kCodecVorbis: | 447 case media::kCodecVorbis: |
398 return PP_AUDIOCODEC_VORBIS; | 448 return PP_AUDIOCODEC_VORBIS; |
399 default: | 449 default: |
400 return PP_AUDIOCODEC_UNKNOWN; | 450 return PP_AUDIOCODEC_UNKNOWN; |
401 } | 451 } |
402 } | 452 } |
403 | 453 |
404 PP_VideoCodec MediaVideoCodecToPpVideoCodec(media::VideoCodec codec) { | 454 PP_VideoCodec MediaVideoCodecToPpVideoCodec(media::VideoCodec codec) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
444 case PP_DECRYPTRESULT_DECRYPT_ERROR: | 494 case PP_DECRYPTRESULT_DECRYPT_ERROR: |
445 return media::Decryptor::kError; | 495 return media::Decryptor::kError; |
446 case PP_DECRYPTRESULT_DECODE_ERROR: | 496 case PP_DECRYPTRESULT_DECODE_ERROR: |
447 return media::Decryptor::kError; | 497 return media::Decryptor::kError; |
448 default: | 498 default: |
449 NOTREACHED(); | 499 NOTREACHED(); |
450 return media::Decryptor::kError; | 500 return media::Decryptor::kError; |
451 } | 501 } |
452 } | 502 } |
453 | 503 |
504 PP_DecryptorStreamType MediaDecryptorStreamTypeToPpStreamType( | |
505 media::Decryptor::StreamType stream_type) { | |
506 switch (stream_type) { | |
507 case media::Decryptor::kAudio: | |
508 return PP_DECRYPTORSTREAMTYPE_AUDIO; | |
509 case media::Decryptor::kVideo: | |
510 return PP_DECRYPTORSTREAMTYPE_VIDEO; | |
511 default: | |
512 NOTREACHED(); | |
513 return PP_DECRYPTORSTREAMTYPE_VIDEO; | |
514 } | |
515 } | |
516 | |
454 } // namespace | 517 } // namespace |
455 | 518 |
456 // static | 519 // static |
457 PluginInstance* PluginInstance::Create(PluginDelegate* delegate, | 520 PluginInstance* PluginInstance::Create(PluginDelegate* delegate, |
458 PluginModule* module) { | 521 PluginModule* module) { |
459 base::Callback<const void*(const char*)> get_plugin_interface_func = | 522 base::Callback<const void*(const char*)> get_plugin_interface_func = |
460 base::Bind(&PluginModule::GetPluginInterface, module); | 523 base::Bind(&PluginModule::GetPluginInterface, module); |
461 PPP_Instance_Combined* ppp_instance_combined = | 524 PPP_Instance_Combined* ppp_instance_combined = |
462 PPP_Instance_Combined::Create(get_plugin_interface_func); | 525 PPP_Instance_Combined::Create(get_plugin_interface_func); |
463 if (!ppp_instance_combined) | 526 if (!ppp_instance_combined) |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
518 text_input_type_(kPluginDefaultTextInputType), | 581 text_input_type_(kPluginDefaultTextInputType), |
519 text_input_caret_(0, 0, 0, 0), | 582 text_input_caret_(0, 0, 0, 0), |
520 text_input_caret_bounds_(0, 0, 0, 0), | 583 text_input_caret_bounds_(0, 0, 0, 0), |
521 text_input_caret_set_(false), | 584 text_input_caret_set_(false), |
522 selection_caret_(0), | 585 selection_caret_(0), |
523 selection_anchor_(0), | 586 selection_anchor_(0), |
524 pending_user_gesture_(0.0), | 587 pending_user_gesture_(0.0), |
525 flash_impl_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 588 flash_impl_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
526 decryptor_client_(NULL), | 589 decryptor_client_(NULL), |
527 next_decryption_request_id_(1), | 590 next_decryption_request_id_(1), |
591 pending_audio_decrypt_request_id_(0), | |
592 pending_video_decrypt_request_id_(0), | |
528 pending_audio_decoder_init_request_id_(0), | 593 pending_audio_decoder_init_request_id_(0), |
529 pending_video_decoder_init_request_id_(0), | 594 pending_video_decoder_init_request_id_(0), |
595 pending_audio_decode_request_id_(0), | |
530 pending_video_decode_request_id_(0) { | 596 pending_video_decode_request_id_(0) { |
531 pp_instance_ = HostGlobals::Get()->AddInstance(this); | 597 pp_instance_ = HostGlobals::Get()->AddInstance(this); |
532 | 598 |
533 memset(¤t_print_settings_, 0, sizeof(current_print_settings_)); | 599 memset(¤t_print_settings_, 0, sizeof(current_print_settings_)); |
534 DCHECK(delegate); | 600 DCHECK(delegate); |
535 module_->InstanceCreated(this); | 601 module_->InstanceCreated(this); |
536 delegate_->InstanceCreated(this); | 602 delegate_->InstanceCreated(this); |
537 message_channel_.reset(new MessageChannel(this)); | 603 message_channel_.reset(new MessageChannel(this)); |
538 | 604 |
539 view_data_.is_page_visible = delegate->IsPageVisible(); | 605 view_data_.is_page_visible = delegate->IsPageVisible(); |
(...skipping 989 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1529 PP_PrivatePageTransformType transform_type = | 1595 PP_PrivatePageTransformType transform_type = |
1530 type == WebPlugin::RotationType90Clockwise ? | 1596 type == WebPlugin::RotationType90Clockwise ? |
1531 PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CW : | 1597 PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CW : |
1532 PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CCW; | 1598 PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CCW; |
1533 plugin_pdf_interface_->Transform(pp_instance(), transform_type); | 1599 plugin_pdf_interface_->Transform(pp_instance(), transform_type); |
1534 // NOTE: plugin instance may have been deleted. | 1600 // NOTE: plugin instance may have been deleted. |
1535 } | 1601 } |
1536 | 1602 |
1537 void PluginInstance::set_decrypt_client( | 1603 void PluginInstance::set_decrypt_client( |
1538 media::DecryptorClient* decryptor_client) { | 1604 media::DecryptorClient* decryptor_client) { |
1539 DCHECK(decryptor_client); | |
1540 decryptor_client_ = decryptor_client; | 1605 decryptor_client_ = decryptor_client; |
1541 } | 1606 } |
1542 | 1607 |
1543 bool PluginInstance::GenerateKeyRequest(const std::string& key_system, | 1608 bool PluginInstance::GenerateKeyRequest(const std::string& key_system, |
1544 const std::string& init_data) { | 1609 const std::string& init_data) { |
1545 if (!LoadContentDecryptorInterface()) | 1610 if (!LoadContentDecryptorInterface()) |
1546 return false; | 1611 return false; |
1547 if (key_system.empty()) | 1612 if (key_system.empty()) |
1548 return false; | 1613 return false; |
1549 | 1614 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1581 | 1646 |
1582 bool PluginInstance::CancelKeyRequest(const std::string& session_id) { | 1647 bool PluginInstance::CancelKeyRequest(const std::string& session_id) { |
1583 if (!LoadContentDecryptorInterface()) | 1648 if (!LoadContentDecryptorInterface()) |
1584 return false; | 1649 return false; |
1585 plugin_decryption_interface_->CancelKeyRequest( | 1650 plugin_decryption_interface_->CancelKeyRequest( |
1586 pp_instance(), | 1651 pp_instance(), |
1587 StringVar::StringToPPVar(session_id)); | 1652 StringVar::StringToPPVar(session_id)); |
1588 return true; | 1653 return true; |
1589 } | 1654 } |
1590 | 1655 |
1656 // TODO(xhwang): Remove duplication of code in Decrypt(), | |
1657 // DecryptAndDecodeAudio() and DecryptAndDecodeVideo(). | |
1591 bool PluginInstance::Decrypt( | 1658 bool PluginInstance::Decrypt( |
1659 media::Decryptor::StreamType stream_type, | |
1592 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, | 1660 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, |
1593 const media::Decryptor::DecryptCB& decrypt_cb) { | 1661 const media::Decryptor::DecryptCB& decrypt_cb) { |
1594 DVLOG(3) << "Decrypt()"; | 1662 DVLOG(3) << "Decrypt() - stream_type: " << stream_type; |
1595 if (!LoadContentDecryptorInterface()) | 1663 if (!LoadContentDecryptorInterface()) |
1596 return false; | 1664 return false; |
1597 | 1665 |
1598 ScopedPPResource encrypted_resource( | 1666 ScopedPPResource encrypted_resource( |
1599 ScopedPPResource::PassRef(), | 1667 ScopedPPResource::PassRef(), |
1600 MakeBufferResource(pp_instance(), | 1668 MakeBufferResource(pp_instance(), |
1601 encrypted_buffer->GetData(), | 1669 encrypted_buffer->GetData(), |
1602 encrypted_buffer->GetDataSize())); | 1670 encrypted_buffer->GetDataSize())); |
1603 if (!encrypted_resource.get()) | 1671 if (!encrypted_resource.get()) |
1604 return false; | 1672 return false; |
1605 | 1673 |
1606 const uint32_t request_id = next_decryption_request_id_++; | 1674 const uint32_t request_id = next_decryption_request_id_++; |
1607 DVLOG(2) << "Decrypt() - request_id " << request_id; | 1675 DVLOG(2) << "Decrypt() - request_id " << request_id; |
1608 | 1676 |
1609 PP_EncryptedBlockInfo block_info; | 1677 PP_EncryptedBlockInfo block_info; |
1610 DCHECK(encrypted_buffer->GetDecryptConfig()); | 1678 DCHECK(encrypted_buffer->GetDecryptConfig()); |
1611 if (!MakeEncryptedBlockInfo(encrypted_buffer->GetDecryptConfig(), | 1679 if (!MakeEncryptedBlockInfo(encrypted_buffer->GetDecryptConfig(), |
1612 encrypted_buffer->GetTimestamp().InMicroseconds(), | 1680 encrypted_buffer->GetTimestamp().InMicroseconds(), |
1613 request_id, | 1681 request_id, |
1614 &block_info)) { | 1682 &block_info)) { |
1615 return false; | 1683 return false; |
1616 } | 1684 } |
1617 | 1685 |
1618 DCHECK(!ContainsKey(pending_decryption_cbs_, request_id)); | 1686 // There is only one pending decrypt request at any time per stream. This is |
1619 pending_decryption_cbs_.insert(std::make_pair(request_id, decrypt_cb)); | 1687 // enforced by the media pipeline. |
1688 switch (stream_type) { | |
1689 case media::Decryptor::kAudio: | |
1690 DCHECK_EQ(pending_audio_decrypt_request_id_, 0u); | |
1691 DCHECK(pending_audio_decrypt_cb_.is_null()); | |
1692 pending_audio_decrypt_request_id_ = request_id; | |
1693 pending_audio_decrypt_cb_ = decrypt_cb; | |
1694 break; | |
1695 case media::Decryptor::kVideo: | |
1696 DCHECK_EQ(pending_video_decrypt_request_id_, 0u); | |
1697 DCHECK(pending_video_decrypt_cb_.is_null()); | |
1698 pending_video_decrypt_request_id_ = request_id; | |
1699 pending_video_decrypt_cb_ = decrypt_cb; | |
1700 break; | |
1701 default: | |
1702 NOTREACHED(); | |
1703 return false; | |
1704 } | |
1620 | 1705 |
1621 plugin_decryption_interface_->Decrypt(pp_instance(), | 1706 plugin_decryption_interface_->Decrypt(pp_instance(), |
1622 encrypted_resource, | 1707 encrypted_resource, |
1623 &block_info); | 1708 &block_info); |
1624 return true; | 1709 return true; |
1625 } | 1710 } |
1626 | 1711 |
1712 bool PluginInstance::CancelDecrypt(media::Decryptor::StreamType stream_type) { | |
1713 DVLOG(3) << "CancelDecrypt() - stream_type: " << stream_type; | |
1714 | |
1715 media::Decryptor::DecryptCB decrypt_cb; | |
1716 switch (stream_type) { | |
1717 case media::Decryptor::kAudio: | |
1718 pending_audio_decrypt_request_id_ = 0; | |
1719 decrypt_cb = base::ResetAndReturn(&pending_audio_decrypt_cb_); | |
1720 break; | |
1721 case media::Decryptor::kVideo: | |
1722 pending_video_decrypt_request_id_ = 0; | |
1723 decrypt_cb = base::ResetAndReturn(&pending_video_decrypt_cb_); | |
1724 break; | |
1725 default: | |
1726 NOTREACHED(); | |
1727 return false; | |
1728 } | |
1729 | |
1730 if (!decrypt_cb.is_null()) | |
1731 decrypt_cb.Run(media::Decryptor::kSuccess, NULL); | |
1732 | |
1733 return true; | |
1734 } | |
1735 | |
1627 bool PluginInstance::InitializeAudioDecoder( | 1736 bool PluginInstance::InitializeAudioDecoder( |
1628 const media::AudioDecoderConfig& decoder_config, | 1737 const media::AudioDecoderConfig& decoder_config, |
1629 const media::Decryptor::DecoderInitCB& init_cb) { | 1738 const media::Decryptor::DecoderInitCB& init_cb) { |
1630 PP_AudioDecoderConfig pp_decoder_config; | 1739 PP_AudioDecoderConfig pp_decoder_config; |
1631 pp_decoder_config.codec = | 1740 pp_decoder_config.codec = |
1632 MediaAudioCodecToPpAudioCodec(decoder_config.codec()); | 1741 MediaAudioCodecToPpAudioCodec(decoder_config.codec()); |
1633 pp_decoder_config.channel_count = | 1742 pp_decoder_config.channel_count = |
1634 media::ChannelLayoutToChannelCount(decoder_config.channel_layout()); | 1743 media::ChannelLayoutToChannelCount(decoder_config.channel_layout()); |
1635 pp_decoder_config.bits_per_channel = decoder_config.bits_per_channel(); | 1744 pp_decoder_config.bits_per_channel = decoder_config.bits_per_channel(); |
1636 pp_decoder_config.samples_per_second = decoder_config.samples_per_second(); | 1745 pp_decoder_config.samples_per_second = decoder_config.samples_per_second(); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1677 DCHECK(pending_video_decoder_init_cb_.is_null()); | 1786 DCHECK(pending_video_decoder_init_cb_.is_null()); |
1678 pending_video_decoder_init_request_id_ = pp_decoder_config.request_id; | 1787 pending_video_decoder_init_request_id_ = pp_decoder_config.request_id; |
1679 pending_video_decoder_init_cb_ = init_cb; | 1788 pending_video_decoder_init_cb_ = init_cb; |
1680 | 1789 |
1681 plugin_decryption_interface_->InitializeVideoDecoder(pp_instance(), | 1790 plugin_decryption_interface_->InitializeVideoDecoder(pp_instance(), |
1682 &pp_decoder_config, | 1791 &pp_decoder_config, |
1683 extra_data_resource); | 1792 extra_data_resource); |
1684 return true; | 1793 return true; |
1685 } | 1794 } |
1686 | 1795 |
1687 bool PluginInstance::DeinitializeDecoder() { | 1796 void PluginInstance::CancelDecode(media::Decryptor::StreamType stream_type) { |
1797 switch (stream_type) { | |
viettrungluu
2012/10/24 16:59:20
It'd be nice (in the future) to figure out a way t
xhwang
2012/10/24 18:57:14
Added TODO.
| |
1798 case media::Decryptor::kAudio: | |
1799 pending_audio_decode_request_id_ = 0; | |
1800 if (!pending_audio_decode_cb_.is_null()) | |
1801 base::ResetAndReturn(&pending_audio_decode_cb_).Run( | |
1802 media::Decryptor::kSuccess, media::Decryptor::AudioBuffers()); | |
1803 break; | |
1804 case media::Decryptor::kVideo: | |
1805 pending_video_decode_request_id_ = 0; | |
1806 if (!pending_video_decode_cb_.is_null()) | |
1807 base::ResetAndReturn(&pending_video_decode_cb_).Run( | |
1808 media::Decryptor::kSuccess, NULL); | |
1809 break; | |
1810 default: | |
1811 NOTREACHED(); | |
1812 } | |
1813 } | |
1814 | |
1815 bool PluginInstance::DeinitializeDecoder( | |
1816 media::Decryptor::StreamType stream_type) { | |
1688 if (!LoadContentDecryptorInterface()) | 1817 if (!LoadContentDecryptorInterface()) |
1689 return false; | 1818 return false; |
1690 | 1819 |
1820 CancelDecode(stream_type); | |
1821 | |
1691 // TODO(tomfinegan): Add decoder deinitialize request tracking, and get | 1822 // TODO(tomfinegan): Add decoder deinitialize request tracking, and get |
1692 // stream type from media stack. | 1823 // stream type from media stack. |
1693 plugin_decryption_interface_->DeinitializeDecoder( | 1824 plugin_decryption_interface_->DeinitializeDecoder( |
1694 pp_instance(), | 1825 pp_instance(), MediaDecryptorStreamTypeToPpStreamType(stream_type), 0); |
1695 PP_DECRYPTORSTREAMTYPE_VIDEO, | |
1696 0); | |
1697 return true; | 1826 return true; |
1698 } | 1827 } |
1699 | 1828 |
1700 bool PluginInstance::ResetDecoder() { | 1829 bool PluginInstance::ResetDecoder(media::Decryptor::StreamType stream_type) { |
1701 if (!LoadContentDecryptorInterface()) | 1830 if (!LoadContentDecryptorInterface()) |
1702 return false; | 1831 return false; |
1703 | 1832 |
1704 // TODO(tomfinegan): Add decoder reset request tracking, and get | 1833 CancelDecode(stream_type); |
1705 // stream type from media stack. | 1834 |
1706 plugin_decryption_interface_->ResetDecoder(pp_instance(), | 1835 // TODO(tomfinegan): Add decoder reset request tracking. |
1707 PP_DECRYPTORSTREAMTYPE_VIDEO, | 1836 plugin_decryption_interface_->ResetDecoder( |
1708 0); | 1837 pp_instance(), MediaDecryptorStreamTypeToPpStreamType(stream_type), 0); |
1709 return true; | 1838 return true; |
1710 } | 1839 } |
1711 | 1840 |
1712 bool PluginInstance::DecryptAndDecode( | 1841 bool PluginInstance::DecryptAndDecodeAudio( |
1842 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, | |
1843 const media::Decryptor::AudioDecodeCB& audio_decode_cb) { | |
1844 if (!LoadContentDecryptorInterface()) | |
1845 return false; | |
1846 | |
1847 // If |encrypted_buffer| is end-of-stream buffer, GetData() and GetDataSize() | |
1848 // return NULL and 0 respectively. In that case, we'll just create a 0 | |
1849 // resource. | |
1850 ScopedPPResource encrypted_resource( | |
1851 ScopedPPResource::PassRef(), | |
1852 MakeBufferResource(pp_instance(), | |
1853 encrypted_buffer->GetData(), | |
1854 encrypted_buffer->GetDataSize())); | |
1855 if (!encrypted_buffer->IsEndOfStream() && !encrypted_resource.get()) | |
1856 return false; | |
1857 | |
1858 const uint32_t request_id = next_decryption_request_id_++; | |
1859 DVLOG(2) << "DecryptAndDecodeAudio() - request_id " << request_id; | |
1860 | |
1861 PP_EncryptedBlockInfo block_info; | |
1862 if (!MakeEncryptedBlockInfo( | |
1863 encrypted_buffer->GetDecryptConfig(), | |
1864 encrypted_buffer->GetTimestamp().InMicroseconds(), | |
1865 request_id, | |
1866 &block_info)) { | |
1867 return false; | |
1868 } | |
1869 | |
1870 // There is only one pending audio decode request at any time. This is | |
1871 // enforced by the media pipeline. | |
1872 DCHECK_EQ(pending_audio_decode_request_id_, 0u); | |
1873 DCHECK(pending_audio_decode_cb_.is_null()); | |
1874 pending_audio_decode_request_id_ = request_id; | |
1875 pending_audio_decode_cb_ = audio_decode_cb; | |
1876 | |
1877 plugin_decryption_interface_->DecryptAndDecode(pp_instance(), | |
1878 PP_DECRYPTORSTREAMTYPE_AUDIO, | |
1879 encrypted_resource, | |
1880 &block_info); | |
1881 return true; | |
1882 } | |
1883 | |
1884 bool PluginInstance::DecryptAndDecodeVideo( | |
1713 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, | 1885 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, |
1714 const media::Decryptor::VideoDecodeCB& video_decode_cb) { | 1886 const media::Decryptor::VideoDecodeCB& video_decode_cb) { |
1715 if (!LoadContentDecryptorInterface()) | 1887 if (!LoadContentDecryptorInterface()) |
1716 return false; | 1888 return false; |
1717 | 1889 |
1718 // If |encrypted_buffer| is end-of-stream buffer, GetData() and GetDataSize() | 1890 // If |encrypted_buffer| is end-of-stream buffer, GetData() and GetDataSize() |
1719 // return NULL and 0 respectively. In that case, we'll just create a 0 | 1891 // return NULL and 0 respectively. In that case, we'll just create a 0 |
1720 // resource. | 1892 // resource. |
1721 ScopedPPResource encrypted_resource( | 1893 ScopedPPResource encrypted_resource( |
1722 ScopedPPResource::PassRef(), | 1894 ScopedPPResource::PassRef(), |
1723 MakeBufferResource(pp_instance(), | 1895 MakeBufferResource(pp_instance(), |
1724 encrypted_buffer->GetData(), | 1896 encrypted_buffer->GetData(), |
1725 encrypted_buffer->GetDataSize())); | 1897 encrypted_buffer->GetDataSize())); |
1726 if (!encrypted_buffer->IsEndOfStream() && !encrypted_resource.get()) | 1898 if (!encrypted_buffer->IsEndOfStream() && !encrypted_resource.get()) |
1727 return false; | 1899 return false; |
1728 | 1900 |
1729 const uint32_t request_id = next_decryption_request_id_++; | 1901 const uint32_t request_id = next_decryption_request_id_++; |
1730 DVLOG(2) << "DecryptAndDecode() - request_id " << request_id; | 1902 DVLOG(2) << "DecryptAndDecodeVideo() - request_id " << request_id; |
1731 | 1903 |
1732 PP_EncryptedBlockInfo block_info; | 1904 PP_EncryptedBlockInfo block_info; |
1733 if (!MakeEncryptedBlockInfo( | 1905 if (!MakeEncryptedBlockInfo( |
1734 encrypted_buffer->GetDecryptConfig(), | 1906 encrypted_buffer->GetDecryptConfig(), |
1735 encrypted_buffer->GetTimestamp().InMicroseconds(), | 1907 encrypted_buffer->GetTimestamp().InMicroseconds(), |
1736 request_id, | 1908 request_id, |
1737 &block_info)) { | 1909 &block_info)) { |
1738 return false; | 1910 return false; |
1739 } | 1911 } |
1740 | 1912 |
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2371 void PluginInstance::NeedKey(PP_Instance instance, | 2543 void PluginInstance::NeedKey(PP_Instance instance, |
2372 PP_Var key_system_var, | 2544 PP_Var key_system_var, |
2373 PP_Var session_id_var, | 2545 PP_Var session_id_var, |
2374 PP_Var init_data_var) { | 2546 PP_Var init_data_var) { |
2375 // TODO(tomfinegan): send the data to media stack. | 2547 // TODO(tomfinegan): send the data to media stack. |
2376 } | 2548 } |
2377 | 2549 |
2378 void PluginInstance::KeyAdded(PP_Instance instance, | 2550 void PluginInstance::KeyAdded(PP_Instance instance, |
2379 PP_Var key_system_var, | 2551 PP_Var key_system_var, |
2380 PP_Var session_id_var) { | 2552 PP_Var session_id_var) { |
2553 if (!decryptor_client_) | |
2554 return; | |
2555 | |
2381 StringVar* key_system_string = StringVar::FromPPVar(key_system_var); | 2556 StringVar* key_system_string = StringVar::FromPPVar(key_system_var); |
2382 StringVar* session_id_string = StringVar::FromPPVar(session_id_var); | 2557 StringVar* session_id_string = StringVar::FromPPVar(session_id_var); |
2383 if (!key_system_string || !session_id_string) { | 2558 if (!key_system_string || !session_id_string) { |
2384 decryptor_client_->KeyError("", "", media::Decryptor::kUnknownError, 0); | 2559 decryptor_client_->KeyError("", "", media::Decryptor::kUnknownError, 0); |
2385 return; | 2560 return; |
2386 } | 2561 } |
2387 | 2562 |
2388 DCHECK(decryptor_client_); | |
2389 decryptor_client_->KeyAdded(key_system_string->value(), | 2563 decryptor_client_->KeyAdded(key_system_string->value(), |
2390 session_id_string->value()); | 2564 session_id_string->value()); |
2391 } | 2565 } |
2392 | 2566 |
2393 void PluginInstance::KeyMessage(PP_Instance instance, | 2567 void PluginInstance::KeyMessage(PP_Instance instance, |
2394 PP_Var key_system_var, | 2568 PP_Var key_system_var, |
2395 PP_Var session_id_var, | 2569 PP_Var session_id_var, |
2396 PP_Resource message_resource, | 2570 PP_Resource message_resource, |
2397 PP_Var default_url_var) { | 2571 PP_Var default_url_var) { |
2572 if (!decryptor_client_) | |
2573 return; | |
2574 | |
2398 StringVar* key_system_string = StringVar::FromPPVar(key_system_var); | 2575 StringVar* key_system_string = StringVar::FromPPVar(key_system_var); |
2399 StringVar* session_id_string = StringVar::FromPPVar(session_id_var); | 2576 StringVar* session_id_string = StringVar::FromPPVar(session_id_var); |
2400 StringVar* default_url_string = StringVar::FromPPVar(default_url_var); | 2577 StringVar* default_url_string = StringVar::FromPPVar(default_url_var); |
2401 | 2578 |
2402 if (!key_system_string || !session_id_string || !default_url_string) { | 2579 if (!key_system_string || !session_id_string || !default_url_string) { |
2403 decryptor_client_->KeyError("", "", media::Decryptor::kUnknownError, 0); | 2580 decryptor_client_->KeyError("", "", media::Decryptor::kUnknownError, 0); |
2404 return; | 2581 return; |
2405 } | 2582 } |
2406 | 2583 |
2407 EnterResourceNoLock<PPB_Buffer_API> enter(message_resource, true); | 2584 EnterResourceNoLock<PPB_Buffer_API> enter(message_resource, true); |
2408 if (!enter.succeeded()) { | 2585 if (!enter.succeeded()) { |
2409 decryptor_client_->KeyError(key_system_string->value(), | 2586 decryptor_client_->KeyError(key_system_string->value(), |
2410 session_id_string->value(), | 2587 session_id_string->value(), |
2411 media::Decryptor::kUnknownError, | 2588 media::Decryptor::kUnknownError, |
2412 0); | 2589 0); |
2413 return; | 2590 return; |
2414 } | 2591 } |
2415 | 2592 |
2416 BufferAutoMapper mapper(enter.object()); | 2593 BufferAutoMapper mapper(enter.object()); |
2417 scoped_array<uint8> message_array(new uint8[mapper.size()]); | 2594 scoped_array<uint8> message_array(new uint8[mapper.size()]); |
2418 if (mapper.data() && mapper.size()) | 2595 if (mapper.data() && mapper.size()) |
2419 memcpy(message_array.get(), mapper.data(), mapper.size()); | 2596 memcpy(message_array.get(), mapper.data(), mapper.size()); |
2420 | 2597 |
2421 DCHECK(decryptor_client_); | |
2422 decryptor_client_->KeyMessage(key_system_string->value(), | 2598 decryptor_client_->KeyMessage(key_system_string->value(), |
2423 session_id_string->value(), | 2599 session_id_string->value(), |
2424 message_array.Pass(), | 2600 message_array.Pass(), |
2425 mapper.size(), | 2601 mapper.size(), |
2426 default_url_string->value()); | 2602 default_url_string->value()); |
2427 } | 2603 } |
2428 | 2604 |
2429 void PluginInstance::KeyError(PP_Instance instance, | 2605 void PluginInstance::KeyError(PP_Instance instance, |
2430 PP_Var key_system_var, | 2606 PP_Var key_system_var, |
2431 PP_Var session_id_var, | 2607 PP_Var session_id_var, |
2432 int32_t media_error, | 2608 int32_t media_error, |
2433 int32_t system_code) { | 2609 int32_t system_code) { |
2610 if (!decryptor_client_) | |
2611 return; | |
2612 | |
2434 StringVar* key_system_string = StringVar::FromPPVar(key_system_var); | 2613 StringVar* key_system_string = StringVar::FromPPVar(key_system_var); |
2435 StringVar* session_id_string = StringVar::FromPPVar(session_id_var); | 2614 StringVar* session_id_string = StringVar::FromPPVar(session_id_var); |
2436 if (!key_system_string || !session_id_string) { | 2615 if (!key_system_string || !session_id_string) { |
2437 decryptor_client_->KeyError("", "", media::Decryptor::kUnknownError, 0); | 2616 decryptor_client_->KeyError("", "", media::Decryptor::kUnknownError, 0); |
2438 return; | 2617 return; |
2439 } | 2618 } |
2440 | 2619 |
2441 DCHECK(decryptor_client_); | |
2442 decryptor_client_->KeyError( | 2620 decryptor_client_->KeyError( |
2443 key_system_string->value(), | 2621 key_system_string->value(), |
2444 session_id_string->value(), | 2622 session_id_string->value(), |
2445 static_cast<media::Decryptor::KeyError>(media_error), | 2623 static_cast<media::Decryptor::KeyError>(media_error), |
2446 system_code); | 2624 system_code); |
2447 } | 2625 } |
2448 | 2626 |
2449 void PluginInstance::DecoderInitializeDone(PP_Instance instance, | 2627 void PluginInstance::DecoderInitializeDone(PP_Instance instance, |
2450 PP_DecryptorStreamType decoder_type, | 2628 PP_DecryptorStreamType decoder_type, |
2451 uint32_t request_id, | 2629 uint32_t request_id, |
(...skipping 30 matching lines...) Expand all Loading... | |
2482 | 2660 |
2483 void PluginInstance::DecoderResetDone(PP_Instance instance, | 2661 void PluginInstance::DecoderResetDone(PP_Instance instance, |
2484 PP_DecryptorStreamType decoder_type, | 2662 PP_DecryptorStreamType decoder_type, |
2485 uint32_t request_id) { | 2663 uint32_t request_id) { |
2486 // TODO(tomfinegan): Add decoder reset completion handling. | 2664 // TODO(tomfinegan): Add decoder reset completion handling. |
2487 } | 2665 } |
2488 | 2666 |
2489 void PluginInstance::DeliverBlock(PP_Instance instance, | 2667 void PluginInstance::DeliverBlock(PP_Instance instance, |
2490 PP_Resource decrypted_block, | 2668 PP_Resource decrypted_block, |
2491 const PP_DecryptedBlockInfo* block_info) { | 2669 const PP_DecryptedBlockInfo* block_info) { |
2492 DVLOG(2) << "DeliverBlock() - request_id: " | |
2493 << block_info->tracking_info.request_id; | |
2494 DCHECK(block_info); | 2670 DCHECK(block_info); |
2495 DecryptionCBMap::iterator found = pending_decryption_cbs_.find( | 2671 const uint32_t request_id = block_info->tracking_info.request_id; |
2496 block_info->tracking_info.request_id); | 2672 DVLOG(2) << "DeliverBlock() - request_id: " << request_id; |
2497 if (found == pending_decryption_cbs_.end()) | 2673 |
2674 // If the request ID is not valid or does not match what's saved, do nothing. | |
2675 if (request_id == 0) { | |
2676 DVLOG(1) << "DeliverBlock() - invalid request_id " << request_id; | |
2498 return; | 2677 return; |
2499 media::Decryptor::DecryptCB decrypt_cb = found->second; | 2678 } |
2500 pending_decryption_cbs_.erase(found); | 2679 |
2680 media::Decryptor::DecryptCB decrypt_cb; | |
2681 if (request_id == pending_audio_decrypt_request_id_) { | |
2682 DCHECK(!pending_audio_decrypt_cb_.is_null()); | |
2683 pending_audio_decrypt_request_id_ = 0; | |
2684 decrypt_cb = base::ResetAndReturn(&pending_audio_decrypt_cb_); | |
2685 } else if (request_id == pending_video_decrypt_request_id_) { | |
2686 DCHECK(!pending_video_decrypt_cb_.is_null()); | |
2687 pending_video_decrypt_request_id_ = 0; | |
2688 decrypt_cb = base::ResetAndReturn(&pending_video_decrypt_cb_); | |
2689 } else { | |
2690 DVLOG(1) << "DeliverBlock() - request_id " << request_id << " not found"; | |
2691 return; | |
2692 } | |
2501 | 2693 |
2502 media::Decryptor::Status status = | 2694 media::Decryptor::Status status = |
2503 PpDecryptResultToMediaDecryptorStatus(block_info->result); | 2695 PpDecryptResultToMediaDecryptorStatus(block_info->result); |
2504 if (status != media::Decryptor::kSuccess) { | 2696 if (status != media::Decryptor::kSuccess) { |
2505 decrypt_cb.Run(status, NULL); | 2697 decrypt_cb.Run(status, NULL); |
2506 return; | 2698 return; |
2507 } | 2699 } |
2508 | 2700 |
2509 EnterResourceNoLock<PPB_Buffer_API> enter(decrypted_block, true); | 2701 EnterResourceNoLock<PPB_Buffer_API> enter(decrypted_block, true); |
2510 if (!enter.succeeded()) { | 2702 if (!enter.succeeded()) { |
(...skipping 12 matching lines...) Expand all Loading... | |
2523 media::DecoderBuffer::CopyFrom( | 2715 media::DecoderBuffer::CopyFrom( |
2524 static_cast<uint8*>(mapper.data()), mapper.size())); | 2716 static_cast<uint8*>(mapper.data()), mapper.size())); |
2525 decrypted_buffer->SetTimestamp(base::TimeDelta::FromMicroseconds( | 2717 decrypted_buffer->SetTimestamp(base::TimeDelta::FromMicroseconds( |
2526 block_info->tracking_info.timestamp)); | 2718 block_info->tracking_info.timestamp)); |
2527 decrypt_cb.Run(media::Decryptor::kSuccess, decrypted_buffer); | 2719 decrypt_cb.Run(media::Decryptor::kSuccess, decrypted_buffer); |
2528 } | 2720 } |
2529 | 2721 |
2530 void PluginInstance::DeliverFrame(PP_Instance instance, | 2722 void PluginInstance::DeliverFrame(PP_Instance instance, |
2531 PP_Resource decrypted_frame, | 2723 PP_Resource decrypted_frame, |
2532 const PP_DecryptedFrameInfo* frame_info) { | 2724 const PP_DecryptedFrameInfo* frame_info) { |
2533 DVLOG(2) << "DeliverFrame() - request_id: " | |
2534 << frame_info->tracking_info.request_id; | |
2535 DCHECK(frame_info); | 2725 DCHECK(frame_info); |
2726 const uint32_t request_id = frame_info->tracking_info.request_id; | |
2727 DVLOG(2) << "DeliverFrame() - request_id: " << request_id; | |
2536 | 2728 |
2537 // If the request ID is not valid or does not match what's saved, do nothing. | 2729 // If the request ID is not valid or does not match what's saved, do nothing. |
2538 if (frame_info->tracking_info.request_id == 0 || | 2730 if (request_id == 0 || request_id != pending_video_decode_request_id_) { |
2539 frame_info->tracking_info.request_id != | 2731 DVLOG(1) << "DeliverFrame() - request_id " << request_id << " not found"; |
2540 pending_video_decode_request_id_) { | |
2541 DCHECK(pending_video_decode_cb_.is_null()); | 2732 DCHECK(pending_video_decode_cb_.is_null()); |
2542 return; | 2733 return; |
2543 } | 2734 } |
2544 | 2735 |
2545 DCHECK(!pending_video_decode_cb_.is_null()); | 2736 DCHECK(!pending_video_decode_cb_.is_null()); |
2546 pending_video_decode_request_id_ = 0; | 2737 pending_video_decode_request_id_ = 0; |
2547 media::Decryptor::VideoDecodeCB video_decode_cb = | 2738 media::Decryptor::VideoDecodeCB video_decode_cb = |
2548 base::ResetAndReturn(&pending_video_decode_cb_); | 2739 base::ResetAndReturn(&pending_video_decode_cb_); |
2549 | 2740 |
2550 media::Decryptor::Status status = | 2741 media::Decryptor::Status status = |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2596 frame_info->strides[PP_DECRYPTEDFRAMEPLANES_V], | 2787 frame_info->strides[PP_DECRYPTEDFRAMEPLANES_V], |
2597 frame_info->height, | 2788 frame_info->height, |
2598 decoded_frame.get()); | 2789 decoded_frame.get()); |
2599 | 2790 |
2600 video_decode_cb.Run(media::Decryptor::kSuccess, decoded_frame); | 2791 video_decode_cb.Run(media::Decryptor::kSuccess, decoded_frame); |
2601 } | 2792 } |
2602 | 2793 |
2603 void PluginInstance::DeliverSamples(PP_Instance instance, | 2794 void PluginInstance::DeliverSamples(PP_Instance instance, |
2604 PP_Resource audio_frames, | 2795 PP_Resource audio_frames, |
2605 const PP_DecryptedBlockInfo* block_info) { | 2796 const PP_DecryptedBlockInfo* block_info) { |
2606 DVLOG(2) << "DeliverSamples() - request_id: " | 2797 DCHECK(block_info); |
2607 << block_info->tracking_info.request_id; | 2798 const uint32_t request_id = block_info->tracking_info.request_id; |
2608 // TODO(tomfinegan): To be implemented after completion of v0.1 of the | 2799 DVLOG(2) << "DeliverSamples() - request_id: " << request_id; |
2609 // EME/CDM work. | 2800 |
2801 // If the request ID is not valid or does not match what's saved, do nothing. | |
2802 if (request_id == 0 || request_id != pending_audio_decode_request_id_) { | |
2803 DVLOG(1) << "DeliverSamples() - request_id " << request_id << " not found"; | |
2804 DCHECK(pending_audio_decode_cb_.is_null()); | |
2805 return; | |
2806 } | |
2807 | |
2808 DCHECK(!pending_audio_decode_cb_.is_null()); | |
2809 pending_audio_decode_request_id_ = 0; | |
2810 media::Decryptor::AudioDecodeCB audio_decode_cb = | |
2811 base::ResetAndReturn(&pending_audio_decode_cb_); | |
2812 | |
2813 const media::Decryptor::AudioBuffers empty_frames; | |
2814 | |
2815 media::Decryptor::Status status = | |
2816 PpDecryptResultToMediaDecryptorStatus(block_info->result); | |
2817 if (status != media::Decryptor::kSuccess) { | |
2818 audio_decode_cb.Run(status, empty_frames); | |
2819 return; | |
2820 } | |
2821 | |
2822 media::Decryptor::AudioBuffers audio_frame_list; | |
2823 if (!DeserializeAudioFrames(audio_frames, &audio_frame_list)) { | |
2824 NOTREACHED() << "CDM did not serialize the buffer correctly."; | |
2825 audio_decode_cb.Run(media::Decryptor::kError, empty_frames); | |
2826 return; | |
2827 } | |
2828 | |
2829 audio_decode_cb.Run(media::Decryptor::kSuccess, audio_frame_list); | |
2610 } | 2830 } |
2611 | 2831 |
2612 void PluginInstance::NumberOfFindResultsChanged(PP_Instance instance, | 2832 void PluginInstance::NumberOfFindResultsChanged(PP_Instance instance, |
2613 int32_t total, | 2833 int32_t total, |
2614 PP_Bool final_result) { | 2834 PP_Bool final_result) { |
2615 DCHECK_NE(find_identifier_, -1); | 2835 DCHECK_NE(find_identifier_, -1); |
2616 delegate_->NumberOfFindResultsChanged(find_identifier_, total, | 2836 delegate_->NumberOfFindResultsChanged(find_identifier_, total, |
2617 PP_ToBool(final_result)); | 2837 PP_ToBool(final_result)); |
2618 } | 2838 } |
2619 | 2839 |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2989 screen_size_for_fullscreen_ = gfx::Size(); | 3209 screen_size_for_fullscreen_ = gfx::Size(); |
2990 WebElement element = container_->element(); | 3210 WebElement element = container_->element(); |
2991 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); | 3211 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); |
2992 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); | 3212 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); |
2993 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); | 3213 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); |
2994 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); | 3214 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); |
2995 } | 3215 } |
2996 | 3216 |
2997 } // namespace ppapi | 3217 } // namespace ppapi |
2998 } // namespace webkit | 3218 } // namespace webkit |
OLD | NEW |