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(audio_frames); | |
402 DCHECK(frames); | |
403 EnterResourceNoLock<PPB_Buffer_API> enter(audio_frames, true); | |
404 if (!enter.succeeded()) | |
405 return false; | |
406 | |
407 BufferAutoMapper mapper(enter.object()); | |
408 if (!mapper.data() || !mapper.size()) | |
409 return false; | |
410 | |
411 const uint8* cur = static_cast<uint8*>(mapper.data()); | |
412 int bytes_left = mapper.size(); | |
413 | |
414 do { | |
415 int64 timestamp = 0; | |
416 int64 frame_size = -1; | |
417 const int header_size = sizeof(timestamp) + sizeof(frame_size); | |
ddorwin
2012/10/22 17:47:11
kHeaderSize
xhwang
2012/10/23 01:53:12
Done.
| |
418 | |
419 if (bytes_left < header_size) | |
420 return false; | |
421 | |
422 timestamp = *(reinterpret_cast<const int64*>(cur)); | |
423 cur += sizeof(timestamp); | |
424 bytes_left -= sizeof(timestamp); | |
425 | |
426 frame_size = *(reinterpret_cast<const int64*>(cur)); | |
427 cur += sizeof(frame_size); | |
428 bytes_left -= sizeof(bytes_left); | |
ddorwin
2012/10/22 17:47:11
sizeof(frame_size)
xhwang
2012/10/23 01:53:12
Done.
| |
429 | |
430 if (frame_size < 0 || bytes_left < frame_size) | |
431 return false; | |
432 | |
433 scoped_refptr<media::DataBuffer> frame(new media::DataBuffer(frame_size)); | |
434 if (frame_size > 0) { | |
435 memcpy(frame->GetWritableData(), cur, frame_size); | |
436 frame->SetTimestamp(base::TimeDelta::FromMicroseconds(timestamp)); | |
437 cur += frame_size; | |
438 bytes_left -= frame_size; | |
439 } | |
440 frames->push_back(frame); | |
441 } while (bytes_left > 0); | |
442 | |
443 return true; | |
444 } | |
445 | |
395 PP_AudioCodec MediaAudioCodecToPpAudioCodec(media::AudioCodec codec) { | 446 PP_AudioCodec MediaAudioCodecToPpAudioCodec(media::AudioCodec codec) { |
396 if (codec == media::kCodecVorbis) | 447 if (codec == media::kCodecVorbis) |
397 return PP_AUDIOCODEC_VORBIS; | 448 return PP_AUDIOCODEC_VORBIS; |
398 | 449 |
399 return PP_AUDIOCODEC_UNKNOWN; | 450 return PP_AUDIOCODEC_UNKNOWN; |
400 } | 451 } |
401 | 452 |
402 PP_VideoCodec MediaVideoCodecToPpVideoCodec(media::VideoCodec codec) { | 453 PP_VideoCodec MediaVideoCodecToPpVideoCodec(media::VideoCodec codec) { |
403 if (codec == media::kCodecVP8) | 454 if (codec == media::kCodecVP8) |
404 return PP_VIDEOCODEC_VP8; | 455 return PP_VIDEOCODEC_VP8; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
493 text_input_type_(kPluginDefaultTextInputType), | 544 text_input_type_(kPluginDefaultTextInputType), |
494 text_input_caret_(0, 0, 0, 0), | 545 text_input_caret_(0, 0, 0, 0), |
495 text_input_caret_bounds_(0, 0, 0, 0), | 546 text_input_caret_bounds_(0, 0, 0, 0), |
496 text_input_caret_set_(false), | 547 text_input_caret_set_(false), |
497 selection_caret_(0), | 548 selection_caret_(0), |
498 selection_anchor_(0), | 549 selection_anchor_(0), |
499 pending_user_gesture_(0.0), | 550 pending_user_gesture_(0.0), |
500 flash_impl_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 551 flash_impl_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
501 decryptor_client_(NULL), | 552 decryptor_client_(NULL), |
502 next_decryption_request_id_(1), | 553 next_decryption_request_id_(1), |
554 pending_audio_decrypt_request_id_(0), | |
555 pending_video_decrypt_request_id_(0), | |
503 pending_audio_decoder_init_request_id_(0), | 556 pending_audio_decoder_init_request_id_(0), |
504 pending_video_decoder_init_request_id_(0), | 557 pending_video_decoder_init_request_id_(0), |
558 pending_audio_decode_request_id_(0), | |
505 pending_video_decode_request_id_(0) { | 559 pending_video_decode_request_id_(0) { |
506 pp_instance_ = HostGlobals::Get()->AddInstance(this); | 560 pp_instance_ = HostGlobals::Get()->AddInstance(this); |
507 | 561 |
508 memset(¤t_print_settings_, 0, sizeof(current_print_settings_)); | 562 memset(¤t_print_settings_, 0, sizeof(current_print_settings_)); |
509 DCHECK(delegate); | 563 DCHECK(delegate); |
510 module_->InstanceCreated(this); | 564 module_->InstanceCreated(this); |
511 delegate_->InstanceCreated(this); | 565 delegate_->InstanceCreated(this); |
512 message_channel_.reset(new MessageChannel(this)); | 566 message_channel_.reset(new MessageChannel(this)); |
513 | 567 |
514 view_data_.is_page_visible = delegate->IsPageVisible(); | 568 view_data_.is_page_visible = delegate->IsPageVisible(); |
(...skipping 986 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1501 PP_PrivatePageTransformType transform_type = | 1555 PP_PrivatePageTransformType transform_type = |
1502 type == WebPlugin::RotationType90Clockwise ? | 1556 type == WebPlugin::RotationType90Clockwise ? |
1503 PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CW : | 1557 PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CW : |
1504 PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CCW; | 1558 PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CCW; |
1505 plugin_pdf_interface_->Transform(pp_instance(), transform_type); | 1559 plugin_pdf_interface_->Transform(pp_instance(), transform_type); |
1506 // NOTE: plugin instance may have been deleted. | 1560 // NOTE: plugin instance may have been deleted. |
1507 } | 1561 } |
1508 | 1562 |
1509 void PluginInstance::set_decrypt_client( | 1563 void PluginInstance::set_decrypt_client( |
1510 media::DecryptorClient* decryptor_client) { | 1564 media::DecryptorClient* decryptor_client) { |
1511 DCHECK(decryptor_client); | |
1512 decryptor_client_ = decryptor_client; | 1565 decryptor_client_ = decryptor_client; |
1513 } | 1566 } |
1514 | 1567 |
1515 bool PluginInstance::GenerateKeyRequest(const std::string& key_system, | 1568 bool PluginInstance::GenerateKeyRequest(const std::string& key_system, |
1516 const std::string& init_data) { | 1569 const std::string& init_data) { |
1517 if (!LoadContentDecryptorInterface()) | 1570 if (!LoadContentDecryptorInterface()) |
1518 return false; | 1571 return false; |
1519 if (key_system.empty()) | 1572 if (key_system.empty()) |
1520 return false; | 1573 return false; |
1521 | 1574 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1553 | 1606 |
1554 bool PluginInstance::CancelKeyRequest(const std::string& session_id) { | 1607 bool PluginInstance::CancelKeyRequest(const std::string& session_id) { |
1555 if (!LoadContentDecryptorInterface()) | 1608 if (!LoadContentDecryptorInterface()) |
1556 return false; | 1609 return false; |
1557 plugin_decryption_interface_->CancelKeyRequest( | 1610 plugin_decryption_interface_->CancelKeyRequest( |
1558 pp_instance(), | 1611 pp_instance(), |
1559 StringVar::StringToPPVar(session_id)); | 1612 StringVar::StringToPPVar(session_id)); |
1560 return true; | 1613 return true; |
1561 } | 1614 } |
1562 | 1615 |
1616 // TODO(xhwang): Remove duplication of code in Decrypt(), | |
1617 // DecryptAndDecodeAudio() and DecryptAndDecodeVideo(). | |
1563 bool PluginInstance::Decrypt( | 1618 bool PluginInstance::Decrypt( |
1619 media::Decryptor::StreamType stream_type, | |
1564 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, | 1620 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, |
1565 const media::Decryptor::DecryptCB& decrypt_cb) { | 1621 const media::Decryptor::DecryptCB& decrypt_cb) { |
1566 DVLOG(3) << "Decrypt()"; | 1622 DVLOG(3) << "Decrypt() - stream_type: " << stream_type; |
1567 if (!LoadContentDecryptorInterface()) | 1623 if (!LoadContentDecryptorInterface()) |
1568 return false; | 1624 return false; |
1569 | 1625 |
1570 ScopedPPResource encrypted_resource( | 1626 ScopedPPResource encrypted_resource( |
1571 ScopedPPResource::PassRef(), | 1627 ScopedPPResource::PassRef(), |
1572 MakeBufferResource(pp_instance(), | 1628 MakeBufferResource(pp_instance(), |
1573 encrypted_buffer->GetData(), | 1629 encrypted_buffer->GetData(), |
1574 encrypted_buffer->GetDataSize())); | 1630 encrypted_buffer->GetDataSize())); |
1575 if (!encrypted_resource.get()) | 1631 if (!encrypted_resource.get()) |
1576 return false; | 1632 return false; |
1577 | 1633 |
1578 const uint32_t request_id = next_decryption_request_id_++; | 1634 const uint32_t request_id = next_decryption_request_id_++; |
1579 DVLOG(2) << "Decrypt() - request_id " << request_id; | 1635 DVLOG(2) << "Decrypt() - request_id " << request_id; |
1580 | 1636 |
1581 PP_EncryptedBlockInfo block_info; | 1637 PP_EncryptedBlockInfo block_info; |
1582 DCHECK(encrypted_buffer->GetDecryptConfig()); | 1638 DCHECK(encrypted_buffer->GetDecryptConfig()); |
1583 if (!MakeEncryptedBlockInfo(encrypted_buffer->GetDecryptConfig(), | 1639 if (!MakeEncryptedBlockInfo(encrypted_buffer->GetDecryptConfig(), |
1584 encrypted_buffer->GetTimestamp().InMicroseconds(), | 1640 encrypted_buffer->GetTimestamp().InMicroseconds(), |
1585 request_id, | 1641 request_id, |
1586 &block_info)) { | 1642 &block_info)) { |
1587 return false; | 1643 return false; |
1588 } | 1644 } |
1589 | 1645 |
1590 DCHECK(!ContainsKey(pending_decryption_cbs_, request_id)); | 1646 // There is only one pending decrypt request at any time per stream. This is |
1591 pending_decryption_cbs_.insert(std::make_pair(request_id, decrypt_cb)); | 1647 // enforced by the media pipeline. |
1648 switch (stream_type) { | |
1649 case media::Decryptor::kAudio: | |
1650 DCHECK_EQ(pending_audio_decrypt_request_id_, 0u); | |
1651 DCHECK(pending_audio_decrypt_cb_.is_null()); | |
1652 pending_audio_decrypt_request_id_ = request_id; | |
1653 pending_audio_decrypt_cb_ = decrypt_cb; | |
1654 break; | |
1655 case media::Decryptor::kVideo: | |
1656 DCHECK_EQ(pending_video_decrypt_request_id_, 0u); | |
1657 DCHECK(pending_video_decrypt_cb_.is_null()); | |
1658 pending_video_decrypt_request_id_ = request_id; | |
1659 pending_video_decrypt_cb_ = decrypt_cb; | |
1660 break; | |
1661 default: | |
1662 NOTREACHED(); | |
1663 return false; | |
1664 } | |
1592 | 1665 |
1593 plugin_decryption_interface_->Decrypt(pp_instance(), | 1666 plugin_decryption_interface_->Decrypt(pp_instance(), |
1594 encrypted_resource, | 1667 encrypted_resource, |
1595 &block_info); | 1668 &block_info); |
1596 return true; | 1669 return true; |
1597 } | 1670 } |
1598 | 1671 |
1672 bool PluginInstance::CancelDecrypt(media::Decryptor::StreamType stream_type) { | |
1673 DVLOG(3) << "CancelDecrypt() - stream_type: " << stream_type; | |
1674 | |
1675 media::Decryptor::DecryptCB decrypt_cb; | |
1676 switch (stream_type) { | |
1677 case media::Decryptor::kAudio: | |
1678 pending_audio_decrypt_request_id_ = 0; | |
1679 decrypt_cb = base::ResetAndReturn(&pending_audio_decrypt_cb_); | |
1680 break; | |
1681 case media::Decryptor::kVideo: | |
1682 pending_video_decrypt_request_id_ = 0; | |
1683 decrypt_cb = base::ResetAndReturn(&pending_video_decrypt_cb_); | |
1684 break; | |
1685 default: | |
1686 NOTREACHED(); | |
1687 return false; | |
1688 } | |
1689 | |
1690 if (!decrypt_cb.is_null()) | |
1691 decrypt_cb.Run(media::Decryptor::kSuccess, NULL); | |
1692 | |
1693 return true; | |
1694 } | |
1695 | |
1599 bool PluginInstance::InitializeAudioDecoder( | 1696 bool PluginInstance::InitializeAudioDecoder( |
1600 const media::AudioDecoderConfig& decoder_config, | 1697 const media::AudioDecoderConfig& decoder_config, |
1601 const media::Decryptor::DecoderInitCB& init_cb) { | 1698 const media::Decryptor::DecoderInitCB& init_cb) { |
1602 PP_AudioDecoderConfig pp_decoder_config; | 1699 PP_AudioDecoderConfig pp_decoder_config; |
1603 pp_decoder_config.channel_count = | 1700 pp_decoder_config.channel_count = |
1604 media::ChannelLayoutToChannelCount(decoder_config.channel_layout()); | 1701 media::ChannelLayoutToChannelCount(decoder_config.channel_layout()); |
1605 pp_decoder_config.bits_per_channel = decoder_config.bits_per_channel(); | 1702 pp_decoder_config.bits_per_channel = decoder_config.bits_per_channel(); |
1606 pp_decoder_config.samples_per_second = decoder_config.samples_per_second(); | 1703 pp_decoder_config.samples_per_second = decoder_config.samples_per_second(); |
1607 pp_decoder_config.request_id = next_decryption_request_id_++; | 1704 pp_decoder_config.request_id = next_decryption_request_id_++; |
1608 | 1705 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1647 DCHECK(pending_video_decoder_init_cb_.is_null()); | 1744 DCHECK(pending_video_decoder_init_cb_.is_null()); |
1648 pending_video_decoder_init_request_id_ = pp_decoder_config.request_id; | 1745 pending_video_decoder_init_request_id_ = pp_decoder_config.request_id; |
1649 pending_video_decoder_init_cb_ = init_cb; | 1746 pending_video_decoder_init_cb_ = init_cb; |
1650 | 1747 |
1651 plugin_decryption_interface_->InitializeVideoDecoder(pp_instance(), | 1748 plugin_decryption_interface_->InitializeVideoDecoder(pp_instance(), |
1652 &pp_decoder_config, | 1749 &pp_decoder_config, |
1653 extra_data_resource); | 1750 extra_data_resource); |
1654 return true; | 1751 return true; |
1655 } | 1752 } |
1656 | 1753 |
1657 bool PluginInstance::DeinitializeDecoder() { | 1754 void PluginInstance::CancelDecode(media::Decryptor::StreamType stream_type) { |
1755 switch (stream_type) { | |
1756 case media::Decryptor::kAudio: | |
1757 pending_audio_decode_request_id_ = 0; | |
1758 if (!pending_audio_decode_cb_.is_null()) | |
1759 base::ResetAndReturn(&pending_audio_decode_cb_).Run( | |
1760 media::Decryptor::kSuccess, media::Decryptor::AudioBuffers()); | |
1761 break; | |
1762 case media::Decryptor::kVideo: | |
1763 pending_video_decode_request_id_ = 0; | |
1764 if (!pending_video_decode_cb_.is_null()) | |
1765 base::ResetAndReturn(&pending_video_decode_cb_).Run( | |
1766 media::Decryptor::kSuccess, NULL); | |
1767 break; | |
1768 default: | |
1769 NOTREACHED(); | |
1770 } | |
1771 } | |
1772 | |
1773 bool PluginInstance::DeinitializeDecoder( | |
1774 media::Decryptor::StreamType stream_type) { | |
1658 if (!LoadContentDecryptorInterface()) | 1775 if (!LoadContentDecryptorInterface()) |
1659 return false; | 1776 return false; |
1660 | 1777 |
1778 CancelDecode(stream_type); | |
1779 | |
1661 // TODO(tomfinegan): Add decoder deinitialize request tracking, and get | 1780 // TODO(tomfinegan): Add decoder deinitialize request tracking, and get |
1662 // stream type from media stack. | 1781 // stream type from media stack. |
1663 plugin_decryption_interface_->DeinitializeDecoder( | 1782 plugin_decryption_interface_->DeinitializeDecoder( |
1664 pp_instance(), | 1783 pp_instance(), |
1665 PP_DECRYPTORSTREAMTYPE_VIDEO, | 1784 PP_DECRYPTORSTREAMTYPE_VIDEO, |
1666 0); | 1785 0); |
1667 return true; | 1786 return true; |
1668 } | 1787 } |
1669 | 1788 |
1670 bool PluginInstance::ResetDecoder() { | 1789 bool PluginInstance::ResetDecoder(media::Decryptor::StreamType stream_type) { |
1671 if (!LoadContentDecryptorInterface()) | 1790 if (!LoadContentDecryptorInterface()) |
1672 return false; | 1791 return false; |
1673 | 1792 |
1793 CancelDecode(stream_type); | |
1794 | |
1674 // TODO(tomfinegan): Add decoder reset request tracking, and get | 1795 // TODO(tomfinegan): Add decoder reset request tracking, and get |
1675 // stream type from media stack. | 1796 // stream type from media stack. |
1676 plugin_decryption_interface_->ResetDecoder(pp_instance(), | 1797 plugin_decryption_interface_->ResetDecoder(pp_instance(), |
1677 PP_DECRYPTORSTREAMTYPE_VIDEO, | 1798 PP_DECRYPTORSTREAMTYPE_VIDEO, |
1678 0); | 1799 0); |
1679 return true; | 1800 return true; |
1680 } | 1801 } |
1681 | 1802 |
1682 bool PluginInstance::DecryptAndDecode( | 1803 bool PluginInstance::DecryptAndDecodeAudio( |
1804 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, | |
1805 const media::Decryptor::AudioDecodeCB& audio_decode_cb) { | |
1806 if (!LoadContentDecryptorInterface()) | |
1807 return false; | |
1808 | |
1809 // If |encrypted_buffer| is end-of-stream buffer, GetData() and GetDataSize() | |
1810 // return NULL and 0 respectively. In that case, we'll just create a 0 | |
1811 // resource. | |
1812 ScopedPPResource encrypted_resource( | |
1813 ScopedPPResource::PassRef(), | |
1814 MakeBufferResource(pp_instance(), | |
1815 encrypted_buffer->GetData(), | |
1816 encrypted_buffer->GetDataSize())); | |
1817 if (!encrypted_buffer->IsEndOfStream() && !encrypted_resource.get()) | |
1818 return false; | |
1819 | |
1820 const uint32_t request_id = next_decryption_request_id_++; | |
1821 DVLOG(2) << "DecryptAndDecodeAudio() - request_id " << request_id; | |
1822 | |
1823 PP_EncryptedBlockInfo block_info; | |
1824 if (!MakeEncryptedBlockInfo( | |
1825 encrypted_buffer->GetDecryptConfig(), | |
1826 encrypted_buffer->GetTimestamp().InMicroseconds(), | |
1827 request_id, | |
1828 &block_info)) { | |
1829 return false; | |
1830 } | |
1831 | |
1832 // There is only one pending audio decode request at any time. This is | |
1833 // enforced by the media pipeline. | |
1834 DCHECK_EQ(pending_audio_decode_request_id_, 0u); | |
1835 DCHECK(pending_audio_decode_cb_.is_null()); | |
1836 pending_audio_decode_request_id_ = request_id; | |
1837 pending_audio_decode_cb_ = audio_decode_cb; | |
1838 | |
1839 plugin_decryption_interface_->DecryptAndDecode(pp_instance(), | |
1840 PP_DECRYPTORSTREAMTYPE_AUDIO, | |
1841 encrypted_resource, | |
1842 &block_info); | |
1843 return true; | |
1844 } | |
1845 | |
1846 bool PluginInstance::DecryptAndDecodeVideo( | |
1683 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, | 1847 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, |
1684 const media::Decryptor::VideoDecodeCB& video_decode_cb) { | 1848 const media::Decryptor::VideoDecodeCB& video_decode_cb) { |
1685 if (!LoadContentDecryptorInterface()) | 1849 if (!LoadContentDecryptorInterface()) |
1686 return false; | 1850 return false; |
1687 | 1851 |
1688 // If |encrypted_buffer| is end-of-stream buffer, GetData() and GetDataSize() | 1852 // If |encrypted_buffer| is end-of-stream buffer, GetData() and GetDataSize() |
1689 // return NULL and 0 respectively. In that case, we'll just create a 0 | 1853 // return NULL and 0 respectively. In that case, we'll just create a 0 |
1690 // resource. | 1854 // resource. |
1691 ScopedPPResource encrypted_resource( | 1855 ScopedPPResource encrypted_resource( |
1692 ScopedPPResource::PassRef(), | 1856 ScopedPPResource::PassRef(), |
1693 MakeBufferResource(pp_instance(), | 1857 MakeBufferResource(pp_instance(), |
1694 encrypted_buffer->GetData(), | 1858 encrypted_buffer->GetData(), |
1695 encrypted_buffer->GetDataSize())); | 1859 encrypted_buffer->GetDataSize())); |
1696 if (!encrypted_buffer->IsEndOfStream() && !encrypted_resource.get()) | 1860 if (!encrypted_buffer->IsEndOfStream() && !encrypted_resource.get()) |
1697 return false; | 1861 return false; |
1698 | 1862 |
1699 const uint32_t request_id = next_decryption_request_id_++; | 1863 const uint32_t request_id = next_decryption_request_id_++; |
1700 DVLOG(2) << "DecryptAndDecode() - request_id " << request_id; | 1864 DVLOG(2) << "DecryptAndDecodeVideo() - request_id " << request_id; |
1701 | 1865 |
1702 PP_EncryptedBlockInfo block_info; | 1866 PP_EncryptedBlockInfo block_info; |
1703 if (!MakeEncryptedBlockInfo( | 1867 if (!MakeEncryptedBlockInfo( |
1704 encrypted_buffer->GetDecryptConfig(), | 1868 encrypted_buffer->GetDecryptConfig(), |
1705 encrypted_buffer->GetTimestamp().InMicroseconds(), | 1869 encrypted_buffer->GetTimestamp().InMicroseconds(), |
1706 request_id, | 1870 request_id, |
1707 &block_info)) { | 1871 &block_info)) { |
1708 return false; | 1872 return false; |
1709 } | 1873 } |
1710 | 1874 |
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2341 void PluginInstance::NeedKey(PP_Instance instance, | 2505 void PluginInstance::NeedKey(PP_Instance instance, |
2342 PP_Var key_system_var, | 2506 PP_Var key_system_var, |
2343 PP_Var session_id_var, | 2507 PP_Var session_id_var, |
2344 PP_Var init_data_var) { | 2508 PP_Var init_data_var) { |
2345 // TODO(tomfinegan): send the data to media stack. | 2509 // TODO(tomfinegan): send the data to media stack. |
2346 } | 2510 } |
2347 | 2511 |
2348 void PluginInstance::KeyAdded(PP_Instance instance, | 2512 void PluginInstance::KeyAdded(PP_Instance instance, |
2349 PP_Var key_system_var, | 2513 PP_Var key_system_var, |
2350 PP_Var session_id_var) { | 2514 PP_Var session_id_var) { |
2515 if (!decryptor_client_) | |
2516 return; | |
2517 | |
2351 StringVar* key_system_string = StringVar::FromPPVar(key_system_var); | 2518 StringVar* key_system_string = StringVar::FromPPVar(key_system_var); |
2352 StringVar* session_id_string = StringVar::FromPPVar(session_id_var); | 2519 StringVar* session_id_string = StringVar::FromPPVar(session_id_var); |
2353 if (!key_system_string || !session_id_string) { | 2520 if (!key_system_string || !session_id_string) { |
2354 decryptor_client_->KeyError("", "", media::Decryptor::kUnknownError, 0); | 2521 decryptor_client_->KeyError("", "", media::Decryptor::kUnknownError, 0); |
2355 return; | 2522 return; |
2356 } | 2523 } |
2357 | 2524 |
2358 DCHECK(decryptor_client_); | |
2359 decryptor_client_->KeyAdded(key_system_string->value(), | 2525 decryptor_client_->KeyAdded(key_system_string->value(), |
2360 session_id_string->value()); | 2526 session_id_string->value()); |
2361 } | 2527 } |
2362 | 2528 |
2363 void PluginInstance::KeyMessage(PP_Instance instance, | 2529 void PluginInstance::KeyMessage(PP_Instance instance, |
2364 PP_Var key_system_var, | 2530 PP_Var key_system_var, |
2365 PP_Var session_id_var, | 2531 PP_Var session_id_var, |
2366 PP_Resource message_resource, | 2532 PP_Resource message_resource, |
2367 PP_Var default_url_var) { | 2533 PP_Var default_url_var) { |
2534 if (!decryptor_client_) | |
2535 return; | |
2536 | |
2368 StringVar* key_system_string = StringVar::FromPPVar(key_system_var); | 2537 StringVar* key_system_string = StringVar::FromPPVar(key_system_var); |
2369 StringVar* session_id_string = StringVar::FromPPVar(session_id_var); | 2538 StringVar* session_id_string = StringVar::FromPPVar(session_id_var); |
2370 StringVar* default_url_string = StringVar::FromPPVar(default_url_var); | 2539 StringVar* default_url_string = StringVar::FromPPVar(default_url_var); |
2371 | 2540 |
2372 if (!key_system_string || !session_id_string || !default_url_string) { | 2541 if (!key_system_string || !session_id_string || !default_url_string) { |
2373 decryptor_client_->KeyError("", "", media::Decryptor::kUnknownError, 0); | 2542 decryptor_client_->KeyError("", "", media::Decryptor::kUnknownError, 0); |
2374 return; | 2543 return; |
2375 } | 2544 } |
2376 | 2545 |
2377 EnterResourceNoLock<PPB_Buffer_API> enter(message_resource, true); | 2546 EnterResourceNoLock<PPB_Buffer_API> enter(message_resource, true); |
2378 if (!enter.succeeded()) { | 2547 if (!enter.succeeded()) { |
2379 decryptor_client_->KeyError(key_system_string->value(), | 2548 decryptor_client_->KeyError(key_system_string->value(), |
2380 session_id_string->value(), | 2549 session_id_string->value(), |
2381 media::Decryptor::kUnknownError, | 2550 media::Decryptor::kUnknownError, |
2382 0); | 2551 0); |
2383 return; | 2552 return; |
2384 } | 2553 } |
2385 | 2554 |
2386 BufferAutoMapper mapper(enter.object()); | 2555 BufferAutoMapper mapper(enter.object()); |
2387 scoped_array<uint8> message_array(new uint8[mapper.size()]); | 2556 scoped_array<uint8> message_array(new uint8[mapper.size()]); |
2388 if (mapper.data() && mapper.size()) | 2557 if (mapper.data() && mapper.size()) |
2389 memcpy(message_array.get(), mapper.data(), mapper.size()); | 2558 memcpy(message_array.get(), mapper.data(), mapper.size()); |
2390 | 2559 |
2391 DCHECK(decryptor_client_); | |
2392 decryptor_client_->KeyMessage(key_system_string->value(), | 2560 decryptor_client_->KeyMessage(key_system_string->value(), |
2393 session_id_string->value(), | 2561 session_id_string->value(), |
2394 message_array.Pass(), | 2562 message_array.Pass(), |
2395 mapper.size(), | 2563 mapper.size(), |
2396 default_url_string->value()); | 2564 default_url_string->value()); |
2397 } | 2565 } |
2398 | 2566 |
2399 void PluginInstance::KeyError(PP_Instance instance, | 2567 void PluginInstance::KeyError(PP_Instance instance, |
2400 PP_Var key_system_var, | 2568 PP_Var key_system_var, |
2401 PP_Var session_id_var, | 2569 PP_Var session_id_var, |
2402 int32_t media_error, | 2570 int32_t media_error, |
2403 int32_t system_code) { | 2571 int32_t system_code) { |
2572 if (!decryptor_client_) | |
2573 return; | |
2574 | |
2404 StringVar* key_system_string = StringVar::FromPPVar(key_system_var); | 2575 StringVar* key_system_string = StringVar::FromPPVar(key_system_var); |
2405 StringVar* session_id_string = StringVar::FromPPVar(session_id_var); | 2576 StringVar* session_id_string = StringVar::FromPPVar(session_id_var); |
2406 if (!key_system_string || !session_id_string) { | 2577 if (!key_system_string || !session_id_string) { |
2407 decryptor_client_->KeyError("", "", media::Decryptor::kUnknownError, 0); | 2578 decryptor_client_->KeyError("", "", media::Decryptor::kUnknownError, 0); |
2408 return; | 2579 return; |
2409 } | 2580 } |
2410 | 2581 |
2411 DCHECK(decryptor_client_); | |
2412 decryptor_client_->KeyError( | 2582 decryptor_client_->KeyError( |
2413 key_system_string->value(), | 2583 key_system_string->value(), |
2414 session_id_string->value(), | 2584 session_id_string->value(), |
2415 static_cast<media::Decryptor::KeyError>(media_error), | 2585 static_cast<media::Decryptor::KeyError>(media_error), |
2416 system_code); | 2586 system_code); |
2417 } | 2587 } |
2418 | 2588 |
2419 void PluginInstance::DecoderInitializeDone(PP_Instance instance, | 2589 void PluginInstance::DecoderInitializeDone(PP_Instance instance, |
2420 PP_DecryptorStreamType decoder_type, | 2590 PP_DecryptorStreamType decoder_type, |
2421 uint32_t request_id, | 2591 uint32_t request_id, |
(...skipping 30 matching lines...) Expand all Loading... | |
2452 | 2622 |
2453 void PluginInstance::DecoderResetDone(PP_Instance instance, | 2623 void PluginInstance::DecoderResetDone(PP_Instance instance, |
2454 PP_DecryptorStreamType decoder_type, | 2624 PP_DecryptorStreamType decoder_type, |
2455 uint32_t request_id) { | 2625 uint32_t request_id) { |
2456 // TODO(tomfinegan): Add decoder reset completion handling. | 2626 // TODO(tomfinegan): Add decoder reset completion handling. |
2457 } | 2627 } |
2458 | 2628 |
2459 void PluginInstance::DeliverBlock(PP_Instance instance, | 2629 void PluginInstance::DeliverBlock(PP_Instance instance, |
2460 PP_Resource decrypted_block, | 2630 PP_Resource decrypted_block, |
2461 const PP_DecryptedBlockInfo* block_info) { | 2631 const PP_DecryptedBlockInfo* block_info) { |
2462 DVLOG(2) << "DeliverBlock() - request_id: " | |
2463 << block_info->tracking_info.request_id; | |
2464 DCHECK(block_info); | 2632 DCHECK(block_info); |
2465 DecryptionCBMap::iterator found = pending_decryption_cbs_.find( | 2633 const uint32_t request_id = block_info->tracking_info.request_id; |
2466 block_info->tracking_info.request_id); | 2634 DVLOG(2) << "DeliverBlock() - request_id: " << request_id; |
2467 if (found == pending_decryption_cbs_.end()) | 2635 |
2636 // If the request ID is not valid or does not match what's saved, do nothing. | |
2637 if (request_id == 0) { | |
2638 DVLOG(1) << "DeliverBlock() - invalid request_id " << request_id; | |
2468 return; | 2639 return; |
2469 media::Decryptor::DecryptCB decrypt_cb = found->second; | 2640 } |
2470 pending_decryption_cbs_.erase(found); | 2641 |
2642 media::Decryptor::DecryptCB decrypt_cb; | |
2643 if (request_id == pending_audio_decrypt_request_id_) { | |
2644 DCHECK(!pending_audio_decrypt_cb_.is_null()); | |
2645 pending_audio_decrypt_request_id_ = 0; | |
2646 decrypt_cb = base::ResetAndReturn(&pending_audio_decrypt_cb_); | |
2647 } else if (request_id == pending_video_decrypt_request_id_) { | |
2648 DCHECK(!pending_video_decrypt_cb_.is_null()); | |
2649 pending_video_decrypt_request_id_ = 0; | |
2650 decrypt_cb = base::ResetAndReturn(&pending_video_decrypt_cb_); | |
2651 } else { | |
2652 DVLOG(1) << "DeliverBlock() - request_id " << request_id << " not found"; | |
2653 return; | |
2654 } | |
2471 | 2655 |
2472 if (block_info->result == PP_DECRYPTRESULT_DECRYPT_NOKEY) { | 2656 if (block_info->result == PP_DECRYPTRESULT_DECRYPT_NOKEY) { |
2473 decrypt_cb.Run(media::Decryptor::kNoKey, NULL); | 2657 decrypt_cb.Run(media::Decryptor::kNoKey, NULL); |
2474 return; | 2658 return; |
2475 } | 2659 } |
2476 | 2660 |
2477 if (block_info->result != PP_DECRYPTRESULT_SUCCESS) { | 2661 if (block_info->result != PP_DECRYPTRESULT_SUCCESS) { |
2478 decrypt_cb.Run(media::Decryptor::kError, NULL); | 2662 decrypt_cb.Run(media::Decryptor::kError, NULL); |
2479 return; | 2663 return; |
2480 } | 2664 } |
(...skipping 15 matching lines...) Expand all Loading... | |
2496 media::DecoderBuffer::CopyFrom( | 2680 media::DecoderBuffer::CopyFrom( |
2497 static_cast<uint8*>(mapper.data()), mapper.size())); | 2681 static_cast<uint8*>(mapper.data()), mapper.size())); |
2498 decrypted_buffer->SetTimestamp(base::TimeDelta::FromMicroseconds( | 2682 decrypted_buffer->SetTimestamp(base::TimeDelta::FromMicroseconds( |
2499 block_info->tracking_info.timestamp)); | 2683 block_info->tracking_info.timestamp)); |
2500 decrypt_cb.Run(media::Decryptor::kSuccess, decrypted_buffer); | 2684 decrypt_cb.Run(media::Decryptor::kSuccess, decrypted_buffer); |
2501 } | 2685 } |
2502 | 2686 |
2503 void PluginInstance::DeliverFrame(PP_Instance instance, | 2687 void PluginInstance::DeliverFrame(PP_Instance instance, |
2504 PP_Resource decrypted_frame, | 2688 PP_Resource decrypted_frame, |
2505 const PP_DecryptedFrameInfo* frame_info) { | 2689 const PP_DecryptedFrameInfo* frame_info) { |
2506 DVLOG(2) << "DeliverFrame() - request_id: " | |
2507 << frame_info->tracking_info.request_id; | |
2508 DCHECK(frame_info); | 2690 DCHECK(frame_info); |
2691 const uint32_t request_id = frame_info->tracking_info.request_id; | |
2692 DVLOG(2) << "DeliverFrame() - request_id: " << request_id; | |
2509 | 2693 |
2510 // If the request ID is not valid or does not match what's saved, do nothing. | 2694 // If the request ID is not valid or does not match what's saved, do nothing. |
2511 if (frame_info->tracking_info.request_id == 0 || | 2695 if (request_id == 0 || request_id != pending_video_decode_request_id_) { |
2512 frame_info->tracking_info.request_id != | 2696 DVLOG(1) << "DeliverFrame() - request_id " << request_id << " not found"; |
2513 pending_video_decode_request_id_) { | |
2514 DCHECK(pending_video_decode_cb_.is_null()); | 2697 DCHECK(pending_video_decode_cb_.is_null()); |
2515 return; | 2698 return; |
2516 } | 2699 } |
2517 | 2700 |
2518 DCHECK(!pending_video_decode_cb_.is_null()); | 2701 DCHECK(!pending_video_decode_cb_.is_null()); |
2519 pending_video_decode_request_id_ = 0; | 2702 pending_video_decode_request_id_ = 0; |
2520 media::Decryptor::VideoDecodeCB video_decode_cb = | 2703 media::Decryptor::VideoDecodeCB video_decode_cb = |
2521 base::ResetAndReturn(&pending_video_decode_cb_); | 2704 base::ResetAndReturn(&pending_video_decode_cb_); |
2522 | 2705 |
2523 if (frame_info->result == PP_DECRYPTRESULT_DECRYPT_NOKEY) { | 2706 if (frame_info->result == PP_DECRYPTRESULT_DECRYPT_NOKEY) { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2578 frame_info->strides[PP_DECRYPTEDFRAMEPLANES_V], | 2761 frame_info->strides[PP_DECRYPTEDFRAMEPLANES_V], |
2579 frame_info->height, | 2762 frame_info->height, |
2580 decoded_frame.get()); | 2763 decoded_frame.get()); |
2581 | 2764 |
2582 video_decode_cb.Run(media::Decryptor::kSuccess, decoded_frame); | 2765 video_decode_cb.Run(media::Decryptor::kSuccess, decoded_frame); |
2583 } | 2766 } |
2584 | 2767 |
2585 void PluginInstance::DeliverSamples(PP_Instance instance, | 2768 void PluginInstance::DeliverSamples(PP_Instance instance, |
2586 PP_Resource audio_frames, | 2769 PP_Resource audio_frames, |
2587 const PP_DecryptedBlockInfo* block_info) { | 2770 const PP_DecryptedBlockInfo* block_info) { |
2588 DVLOG(2) << "DeliverSamples() - request_id: " | 2771 DCHECK(block_info); |
2589 << block_info->tracking_info.request_id; | 2772 const uint32_t request_id = block_info->tracking_info.request_id; |
2590 // TODO(tomfinegan): To be implemented after completion of v0.1 of the | 2773 DVLOG(2) << "DeliverSamples() - request_id: " << request_id; |
2591 // EME/CDM work. | 2774 |
2775 // If the request ID is not valid or does not match what's saved, do nothing. | |
2776 if (request_id == 0 || request_id != pending_audio_decode_request_id_) { | |
2777 DVLOG(1) << "DeliverSamples() - request_id " << request_id << " not found"; | |
2778 DCHECK(pending_audio_decode_cb_.is_null()); | |
2779 return; | |
2780 } | |
2781 | |
2782 DCHECK(!pending_audio_decode_cb_.is_null()); | |
2783 pending_audio_decode_request_id_ = 0; | |
2784 media::Decryptor::AudioDecodeCB audio_decode_cb = | |
2785 base::ResetAndReturn(&pending_audio_decode_cb_); | |
2786 | |
2787 const media::Decryptor::AudioBuffers empty_frames; | |
2788 | |
2789 if (block_info->result == PP_DECRYPTRESULT_DECRYPT_NOKEY) { | |
2790 audio_decode_cb.Run(media::Decryptor::kNoKey, empty_frames); | |
2791 return; | |
2792 } | |
2793 | |
2794 if (block_info->result != PP_DECRYPTRESULT_SUCCESS) { | |
2795 audio_decode_cb.Run(media::Decryptor::kError, empty_frames); | |
2796 return; | |
2797 } | |
2798 | |
2799 if (audio_frames == 0) { // End-of-stream frame. | |
2800 audio_decode_cb.Run(media::Decryptor::kSuccess, empty_frames); | |
2801 return; | |
2802 } | |
2803 | |
2804 media::Decryptor::AudioBuffers audio_frame_list; | |
2805 if (!DeserializeAudioFrames(audio_frames, &audio_frame_list)) { | |
2806 audio_decode_cb.Run(media::Decryptor::kError, empty_frames); | |
2807 return; | |
2808 } | |
2809 | |
2810 audio_decode_cb.Run(media::Decryptor::kSuccess, audio_frame_list); | |
2592 } | 2811 } |
2593 | 2812 |
2594 void PluginInstance::NumberOfFindResultsChanged(PP_Instance instance, | 2813 void PluginInstance::NumberOfFindResultsChanged(PP_Instance instance, |
2595 int32_t total, | 2814 int32_t total, |
2596 PP_Bool final_result) { | 2815 PP_Bool final_result) { |
2597 DCHECK_NE(find_identifier_, -1); | 2816 DCHECK_NE(find_identifier_, -1); |
2598 delegate_->NumberOfFindResultsChanged(find_identifier_, total, | 2817 delegate_->NumberOfFindResultsChanged(find_identifier_, total, |
2599 PP_ToBool(final_result)); | 2818 PP_ToBool(final_result)); |
2600 } | 2819 } |
2601 | 2820 |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2971 screen_size_for_fullscreen_ = gfx::Size(); | 3190 screen_size_for_fullscreen_ = gfx::Size(); |
2972 WebElement element = container_->element(); | 3191 WebElement element = container_->element(); |
2973 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); | 3192 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); |
2974 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); | 3193 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); |
2975 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); | 3194 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); |
2976 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); | 3195 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); |
2977 } | 3196 } |
2978 | 3197 |
2979 } // namespace ppapi | 3198 } // namespace ppapi |
2980 } // namespace webkit | 3199 } // namespace webkit |
OLD | NEW |