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

Side by Side Diff: webkit/plugins/ppapi/ppapi_plugin_instance.cc

Issue 11091005: Update PluginInstance for decrypt-and-decode video. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: fix a bug in ppp_content_decryptor_private_proxy.cc Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "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/debug/trace_event.h" 9 #include "base/debug/trace_event.h"
9 #include "base/logging.h" 10 #include "base/logging.h"
10 #include "base/memory/linked_ptr.h" 11 #include "base/memory/linked_ptr.h"
11 #include "base/message_loop.h" 12 #include "base/message_loop.h"
12 #include "base/stl_util.h" 13 #include "base/stl_util.h"
13 #include "base/stringprintf.h" 14 #include "base/stringprintf.h"
14 #include "base/time.h" 15 #include "base/time.h"
15 #include "base/utf_offset_string_conversions.h" 16 #include "base/utf_offset_string_conversions.h"
16 #include "base/utf_string_conversions.h" 17 #include "base/utf_string_conversions.h"
18 // TODO(xhwang): Move media specific code out of this class.
17 #include "media/base/decoder_buffer.h" 19 #include "media/base/decoder_buffer.h"
18 #include "media/base/decryptor_client.h" 20 #include "media/base/decryptor_client.h"
19 #include "media/base/video_decoder_config.h" 21 #include "media/base/video_decoder_config.h"
20 #include "media/base/video_frame.h" 22 #include "media/base/video_frame.h"
23 #include "media/base/video_util.h"
21 #include "ppapi/c/dev/ppb_find_dev.h" 24 #include "ppapi/c/dev/ppb_find_dev.h"
22 #include "ppapi/c/dev/ppb_zoom_dev.h" 25 #include "ppapi/c/dev/ppb_zoom_dev.h"
23 #include "ppapi/c/dev/ppp_find_dev.h" 26 #include "ppapi/c/dev/ppp_find_dev.h"
24 #include "ppapi/c/dev/ppp_selection_dev.h" 27 #include "ppapi/c/dev/ppp_selection_dev.h"
25 #include "ppapi/c/dev/ppp_text_input_dev.h" 28 #include "ppapi/c/dev/ppp_text_input_dev.h"
26 #include "ppapi/c/dev/ppp_zoom_dev.h" 29 #include "ppapi/c/dev/ppp_zoom_dev.h"
27 #include "ppapi/c/pp_rect.h" 30 #include "ppapi/c/pp_rect.h"
28 #include "ppapi/c/ppb_audio_config.h" 31 #include "ppapi/c/ppb_audio_config.h"
29 #include "ppapi/c/ppb_core.h" 32 #include "ppapi/c/ppb_core.h"
30 #include "ppapi/c/ppb_gamepad.h" 33 #include "ppapi/c/ppb_gamepad.h"
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 template <uint32_t array_size> 340 template <uint32_t array_size>
338 bool CopyStringToArray(const std::string& str, uint8 (&array)[array_size]) { 341 bool CopyStringToArray(const std::string& str, uint8 (&array)[array_size]) {
339 if (array_size < str.size()) 342 if (array_size < str.size())
340 return false; 343 return false;
341 344
342 memcpy(array, str.data(), str.size()); 345 memcpy(array, str.data(), str.size());
343 return true; 346 return true;
344 } 347 }
345 348
346 // Fills the |block_info| with information from |decrypt_config|, |timestamp| 349 // Fills the |block_info| with information from |decrypt_config|, |timestamp|
347 // and |request_id|. 350 // and |request_id|. |decrypt_config| can be NULL if the block is not encrypted.
351 // This is useful for end-of-stream blocks.
348 // Returns true if |block_info| is successfully filled. Returns false 352 // Returns true if |block_info| is successfully filled. Returns false
349 // otherwise. 353 // otherwise.
350 bool MakeEncryptedBlockInfo( 354 bool MakeEncryptedBlockInfo(
351 const media::DecryptConfig& decrypt_config, 355 const media::DecryptConfig* decrypt_config,
352 int64_t timestamp, 356 int64_t timestamp,
353 uint32_t request_id, 357 uint32_t request_id,
354 PP_EncryptedBlockInfo* block_info) { 358 PP_EncryptedBlockInfo* block_info) {
355 DCHECK(block_info); 359 DCHECK(block_info);
356 360
357 // TODO(xhwang): Fix initialization of PP_EncryptedBlockInfo here and 361 // TODO(xhwang): Fix initialization of PP_EncryptedBlockInfo here and
358 // anywhere else. 362 // anywhere else.
359 memset(block_info, 0, sizeof(*block_info)); 363 memset(block_info, 0, sizeof(*block_info));
360 364
361 block_info->tracking_info.request_id = request_id; 365 block_info->tracking_info.request_id = request_id;
362 block_info->tracking_info.timestamp = timestamp; 366 block_info->tracking_info.timestamp = timestamp;
363 block_info->data_offset = decrypt_config.data_offset();
364 367
365 if (!CopyStringToArray(decrypt_config.key_id(), block_info->key_id) || 368 if (!decrypt_config)
366 !CopyStringToArray(decrypt_config.iv(), block_info->iv)) 369 return true;
370
371 block_info->data_offset = decrypt_config->data_offset();
372
373 if (!CopyStringToArray(decrypt_config->key_id(), block_info->key_id) ||
374 !CopyStringToArray(decrypt_config->iv(), block_info->iv))
367 return false; 375 return false;
368 376
369 block_info->key_id_size = decrypt_config.key_id().size(); 377 block_info->key_id_size = decrypt_config->key_id().size();
370 block_info->iv_size = decrypt_config.iv().size(); 378 block_info->iv_size = decrypt_config->iv().size();
371 379
372 if (decrypt_config.subsamples().size() > arraysize(block_info->subsamples)) 380 if (decrypt_config->subsamples().size() > arraysize(block_info->subsamples))
373 return false; 381 return false;
374 382
375 block_info->num_subsamples = decrypt_config.subsamples().size(); 383 block_info->num_subsamples = decrypt_config->subsamples().size();
376 for (uint32_t i = 0; i < block_info->num_subsamples; ++i) { 384 for (uint32_t i = 0; i < block_info->num_subsamples; ++i) {
377 block_info->subsamples[i].clear_bytes = 385 block_info->subsamples[i].clear_bytes =
378 decrypt_config.subsamples()[i].clear_bytes; 386 decrypt_config->subsamples()[i].clear_bytes;
379 block_info->subsamples[i].cipher_bytes = 387 block_info->subsamples[i].cipher_bytes =
380 decrypt_config.subsamples()[i].cypher_bytes; 388 decrypt_config->subsamples()[i].cypher_bytes;
381 } 389 }
382 390
383 return true; 391 return true;
384 } 392 }
385 393
386 PP_VideoCodec MediaVideoCodecToPpVideoCodec(media::VideoCodec codec) { 394 PP_VideoCodec MediaVideoCodecToPpVideoCodec(media::VideoCodec codec) {
387 if (codec == media::kCodecVP8) 395 if (codec == media::kCodecVP8)
388 return PP_VIDEOCODEC_VP8; 396 return PP_VIDEOCODEC_VP8;
389 397
390 return PP_VIDEOCODEC_UNKNOWN; 398 return PP_VIDEOCODEC_UNKNOWN;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 filtered_input_event_mask_(0), 484 filtered_input_event_mask_(0),
477 text_input_type_(kPluginDefaultTextInputType), 485 text_input_type_(kPluginDefaultTextInputType),
478 text_input_caret_(0, 0, 0, 0), 486 text_input_caret_(0, 0, 0, 0),
479 text_input_caret_bounds_(0, 0, 0, 0), 487 text_input_caret_bounds_(0, 0, 0, 0),
480 text_input_caret_set_(false), 488 text_input_caret_set_(false),
481 selection_caret_(0), 489 selection_caret_(0),
482 selection_anchor_(0), 490 selection_anchor_(0),
483 pending_user_gesture_(0.0), 491 pending_user_gesture_(0.0),
484 flash_impl_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 492 flash_impl_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
485 decryptor_client_(NULL), 493 decryptor_client_(NULL),
486 next_decryption_request_id_(1) { 494 next_decryption_request_id_(1),
495 pending_video_decoder_init_request_id_(0),
496 pending_video_decode_request_id_(0) {
487 pp_instance_ = HostGlobals::Get()->AddInstance(this); 497 pp_instance_ = HostGlobals::Get()->AddInstance(this);
488 498
489 memset(&current_print_settings_, 0, sizeof(current_print_settings_)); 499 memset(&current_print_settings_, 0, sizeof(current_print_settings_));
490 DCHECK(delegate); 500 DCHECK(delegate);
491 module_->InstanceCreated(this); 501 module_->InstanceCreated(this);
492 delegate_->InstanceCreated(this); 502 delegate_->InstanceCreated(this);
493 message_channel_.reset(new MessageChannel(this)); 503 message_channel_.reset(new MessageChannel(this));
494 504
495 view_data_.is_page_visible = delegate->IsPageVisible(); 505 view_data_.is_page_visible = delegate->IsPageVisible();
496 506
(...skipping 1052 matching lines...) Expand 10 before | Expand all | Expand 10 after
1549 return false; 1559 return false;
1550 1560
1551 ScopedPPResource encrypted_resource( 1561 ScopedPPResource encrypted_resource(
1552 ScopedPPResource::PassRef(), 1562 ScopedPPResource::PassRef(),
1553 MakeBufferResource(pp_instance(), 1563 MakeBufferResource(pp_instance(),
1554 encrypted_buffer->GetData(), 1564 encrypted_buffer->GetData(),
1555 encrypted_buffer->GetDataSize())); 1565 encrypted_buffer->GetDataSize()));
1556 if (!encrypted_resource.get()) 1566 if (!encrypted_resource.get())
1557 return false; 1567 return false;
1558 1568
1559 uint32_t request_id = next_decryption_request_id_++; 1569 const uint32_t request_id = next_decryption_request_id_++;
1560 DVLOG(2) << "Decrypt() - request_id " << request_id; 1570 DVLOG(2) << "Decrypt() - request_id " << request_id;
1561 1571
1562 PP_EncryptedBlockInfo block_info; 1572 PP_EncryptedBlockInfo block_info;
1563 DCHECK(encrypted_buffer->GetDecryptConfig()); 1573 DCHECK(encrypted_buffer->GetDecryptConfig());
1564 if (!MakeEncryptedBlockInfo(*encrypted_buffer->GetDecryptConfig(), 1574 if (!MakeEncryptedBlockInfo(encrypted_buffer->GetDecryptConfig(),
1565 encrypted_buffer->GetTimestamp().InMicroseconds(), 1575 encrypted_buffer->GetTimestamp().InMicroseconds(),
1566 request_id, 1576 request_id,
1567 &block_info)) { 1577 &block_info)) {
1568 return false; 1578 return false;
1569 } 1579 }
1570 1580
1571 DCHECK(!ContainsKey(pending_decryption_cbs_, request_id)); 1581 DCHECK(!ContainsKey(pending_decryption_cbs_, request_id));
1572 pending_decryption_cbs_.insert(std::make_pair(request_id, decrypt_cb)); 1582 pending_decryption_cbs_.insert(std::make_pair(request_id, decrypt_cb));
1573 1583
1574 plugin_decryption_interface_->Decrypt(pp_instance(), 1584 plugin_decryption_interface_->Decrypt(pp_instance(),
1575 encrypted_resource, 1585 encrypted_resource,
1576 &block_info); 1586 &block_info);
1577 return true; 1587 return true;
1578 } 1588 }
1579 1589
1580 bool PluginInstance::InitializeVideoDecoder( 1590 bool PluginInstance::InitializeVideoDecoder(
1581 const media::VideoDecoderConfig& decoder_config, 1591 const media::VideoDecoderConfig& decoder_config,
1582 const media::Decryptor::DecryptCB& decrypt_cb) { 1592 const media::Decryptor::DecoderInitCB& init_cb) {
1583 PP_VideoDecoderConfig pp_decoder_config; 1593 PP_VideoDecoderConfig pp_decoder_config;
1584 pp_decoder_config.codec = 1594 pp_decoder_config.codec =
1585 MediaVideoCodecToPpVideoCodec(decoder_config.codec()); 1595 MediaVideoCodecToPpVideoCodec(decoder_config.codec());
1586 pp_decoder_config.profile = 1596 pp_decoder_config.profile =
1587 MediaVideoCodecProfileToPpVideoCodecProfile(decoder_config.profile()); 1597 MediaVideoCodecProfileToPpVideoCodecProfile(decoder_config.profile());
1588 pp_decoder_config.format = 1598 pp_decoder_config.format =
1589 MediaVideoFormatToPpDecryptedFrameFormat(decoder_config.format()); 1599 MediaVideoFormatToPpDecryptedFrameFormat(decoder_config.format());
1590 pp_decoder_config.width = decoder_config.coded_size().width(); 1600 pp_decoder_config.width = decoder_config.coded_size().width();
1591 pp_decoder_config.height = decoder_config.coded_size().height(); 1601 pp_decoder_config.height = decoder_config.coded_size().height();
1592 pp_decoder_config.request_id = next_decryption_request_id_++; 1602 pp_decoder_config.request_id = next_decryption_request_id_++;
1593 1603
1594 // TODO(xhwang): Use individual variables for decoder init request tracking.
1595 DCHECK(!ContainsKey(pending_decryption_cbs_, pp_decoder_config.request_id));
1596 pending_decryption_cbs_.insert(std::make_pair(pp_decoder_config.request_id,
1597 decrypt_cb));
1598
1599 ScopedPPResource extra_data_resource( 1604 ScopedPPResource extra_data_resource(
1600 ScopedPPResource::PassRef(), 1605 ScopedPPResource::PassRef(),
1601 MakeBufferResource(pp_instance(), 1606 MakeBufferResource(pp_instance(),
1602 decoder_config.extra_data(), 1607 decoder_config.extra_data(),
1603 decoder_config.extra_data_size())); 1608 decoder_config.extra_data_size()));
1604 1609
1610 DCHECK_EQ(pending_video_decoder_init_request_id_, 0u);
1611 DCHECK(pending_video_decoder_init_cb_.is_null());
1612 pending_video_decoder_init_request_id_ = pp_decoder_config.request_id;
1613 pending_video_decoder_init_cb_ = init_cb;
1614
1605 plugin_decryption_interface_->InitializeVideoDecoder(pp_instance(), 1615 plugin_decryption_interface_->InitializeVideoDecoder(pp_instance(),
1606 &pp_decoder_config, 1616 &pp_decoder_config,
1607 extra_data_resource); 1617 extra_data_resource);
1608 return true; 1618 return true;
1609 } 1619 }
1610 1620
1611 bool PluginInstance::DeinitializeDecoder() { 1621 bool PluginInstance::DeinitializeDecoder() {
1612 if (!LoadContentDecryptorInterface()) 1622 if (!LoadContentDecryptorInterface())
1613 return false; 1623 return false;
1614 1624
(...skipping 13 matching lines...) Expand all
1628 // TODO(tomfinegan): Add decoder reset request tracking, and get 1638 // TODO(tomfinegan): Add decoder reset request tracking, and get
1629 // stream type from media stack. 1639 // stream type from media stack.
1630 plugin_decryption_interface_->ResetDecoder(pp_instance(), 1640 plugin_decryption_interface_->ResetDecoder(pp_instance(),
1631 PP_DECRYPTORSTREAMTYPE_VIDEO, 1641 PP_DECRYPTORSTREAMTYPE_VIDEO,
1632 0); 1642 0);
1633 return true; 1643 return true;
1634 } 1644 }
1635 1645
1636 bool PluginInstance::DecryptAndDecode( 1646 bool PluginInstance::DecryptAndDecode(
1637 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, 1647 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer,
1638 const media::Decryptor::DecryptCB& decrypt_cb) { 1648 const media::Decryptor::VideoDecodeCB& video_decode_cb) {
1639 if (!LoadContentDecryptorInterface()) 1649 if (!LoadContentDecryptorInterface())
1640 return false; 1650 return false;
1641 1651
1642 ScopedPPResource encrypted_resource(MakeBufferResource( 1652 // If |encrypted_buffer| is end-of-stream buffer, GetData() and GetDataSize()
1643 pp_instance(), 1653 // return NULL and 0 respectively. In that case, we'll just create a 0
1644 encrypted_buffer->GetData(), 1654 // resource.
1645 encrypted_buffer->GetDataSize())); 1655 ScopedPPResource encrypted_resource(
1646 if (!encrypted_resource.get()) 1656 ScopedPPResource::PassRef(),
1657 MakeBufferResource(pp_instance(),
1658 encrypted_buffer->GetData(),
1659 encrypted_buffer->GetDataSize()));
1660 if (!encrypted_buffer->IsEndOfStream() && !encrypted_resource.get())
1647 return false; 1661 return false;
1648 1662
1649 const uint32_t request_id = next_decryption_request_id_++; 1663 const uint32_t request_id = next_decryption_request_id_++;
1664 DVLOG(2) << "DecryptAndDecode() - request_id " << request_id;
1650 1665
1651 PP_EncryptedBlockInfo block_info; 1666 PP_EncryptedBlockInfo block_info;
1652 DCHECK(encrypted_buffer->GetDecryptConfig()); 1667 if (!MakeEncryptedBlockInfo(
1653 if (!MakeEncryptedBlockInfo(*encrypted_buffer->GetDecryptConfig(), 1668 encrypted_buffer->GetDecryptConfig(),
1654 encrypted_buffer->GetTimestamp().InMicroseconds(), 1669 encrypted_buffer->GetTimestamp().InMicroseconds(),
1655 request_id, 1670 request_id,
1656 &block_info)) { 1671 &block_info)) {
1657 return false; 1672 return false;
1658 } 1673 }
1659 1674
1660 DCHECK(!ContainsKey(pending_decryption_cbs_, request_id)); 1675 // Only one pending video decode request at any time. This is enforced by the
1661 pending_decryption_cbs_.insert(std::make_pair(request_id, decrypt_cb)); 1676 // media pipeline.
1677 DCHECK_EQ(pending_video_decode_request_id_, 0u);
1678 DCHECK(pending_video_decode_cb_.is_null());
1679 pending_video_decode_request_id_ = request_id;
1680 pending_video_decode_cb_ = video_decode_cb;
1662 1681
1663 // TODO(tomfinegan): Need to get stream type from media stack. 1682 // TODO(tomfinegan): Need to get stream type from media stack.
1664 plugin_decryption_interface_->DecryptAndDecode(pp_instance(), 1683 plugin_decryption_interface_->DecryptAndDecode(pp_instance(),
1665 PP_DECRYPTORSTREAMTYPE_VIDEO, 1684 PP_DECRYPTORSTREAMTYPE_VIDEO,
1666 encrypted_resource, 1685 encrypted_resource,
1667 &block_info); 1686 &block_info);
1668 return true; 1687 return true;
1669 } 1688 }
1670 1689
1671 bool PluginInstance::FlashIsFullscreenOrPending() { 1690 bool PluginInstance::FlashIsFullscreenOrPending() {
(...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after
2357 decryptor_client_->KeyError( 2376 decryptor_client_->KeyError(
2358 key_system_string->value(), 2377 key_system_string->value(),
2359 session_id_string->value(), 2378 session_id_string->value(),
2360 static_cast<media::Decryptor::KeyError>(media_error), 2379 static_cast<media::Decryptor::KeyError>(media_error),
2361 system_code); 2380 system_code);
2362 } 2381 }
2363 2382
2364 void PluginInstance::DecoderInitialized(PP_Instance instance, 2383 void PluginInstance::DecoderInitialized(PP_Instance instance,
2365 PP_Bool success, 2384 PP_Bool success,
2366 uint32_t request_id) { 2385 uint32_t request_id) {
2367 // TODO(xhwang): Use individual variables for decoder init request tracking. 2386 // If the request ID is not valid or does not match what's saved, do nothing.
2368 DecryptionCBMap::iterator found = pending_decryption_cbs_.find(request_id); 2387 if (request_id == 0 || request_id != pending_video_decoder_init_request_id_)
2369 if (found == pending_decryption_cbs_.end())
2370 return; 2388 return;
2371 media::Decryptor::DecryptCB decrypt_cb = found->second;
2372 pending_decryption_cbs_.erase(found);
2373 2389
2374 media::Decryptor::Status status = 2390 DCHECK(!pending_video_decoder_init_cb_.is_null());
2375 success == PP_TRUE ? media::Decryptor::kSuccess : 2391 pending_video_decoder_init_request_id_ = 0;
2376 media::Decryptor::kError; 2392 base::ResetAndReturn(&pending_video_decoder_init_cb_).Run(PP_ToBool(success));
2377 decrypt_cb.Run(status, NULL);
2378 } 2393 }
2379 2394
2380 void PluginInstance::DecoderDeinitializeDone( 2395 void PluginInstance::DecoderDeinitializeDone(
2381 PP_Instance instance, 2396 PP_Instance instance,
2382 PP_DecryptorStreamType decoder_type, 2397 PP_DecryptorStreamType decoder_type,
2383 uint32_t request_id) { 2398 uint32_t request_id) {
2384 // TODO(tomfinegan): Add decoder stop completion handling. 2399 // TODO(tomfinegan): Add decoder stop completion handling.
2385 } 2400 }
2386 2401
2387 void PluginInstance::DecoderResetDone(PP_Instance instance, 2402 void PluginInstance::DecoderResetDone(PP_Instance instance,
(...skipping 12 matching lines...) Expand all
2400 block_info->tracking_info.request_id); 2415 block_info->tracking_info.request_id);
2401 if (found == pending_decryption_cbs_.end()) 2416 if (found == pending_decryption_cbs_.end())
2402 return; 2417 return;
2403 media::Decryptor::DecryptCB decrypt_cb = found->second; 2418 media::Decryptor::DecryptCB decrypt_cb = found->second;
2404 pending_decryption_cbs_.erase(found); 2419 pending_decryption_cbs_.erase(found);
2405 2420
2406 if (block_info->result == PP_DECRYPTRESULT_DECRYPT_NOKEY) { 2421 if (block_info->result == PP_DECRYPTRESULT_DECRYPT_NOKEY) {
2407 decrypt_cb.Run(media::Decryptor::kNoKey, NULL); 2422 decrypt_cb.Run(media::Decryptor::kNoKey, NULL);
2408 return; 2423 return;
2409 } 2424 }
2425
2410 if (block_info->result != PP_DECRYPTRESULT_SUCCESS) { 2426 if (block_info->result != PP_DECRYPTRESULT_SUCCESS) {
2411 decrypt_cb.Run(media::Decryptor::kError, NULL); 2427 decrypt_cb.Run(media::Decryptor::kError, NULL);
2412 return; 2428 return;
2413 } 2429 }
2414 2430
2415 EnterResourceNoLock<PPB_Buffer_API> enter(decrypted_block, true); 2431 EnterResourceNoLock<PPB_Buffer_API> enter(decrypted_block, true);
2416 if (!enter.succeeded()) { 2432 if (!enter.succeeded()) {
2417 decrypt_cb.Run(media::Decryptor::kError, NULL); 2433 decrypt_cb.Run(media::Decryptor::kError, NULL);
2418 return; 2434 return;
2419 } 2435 }
2420 BufferAutoMapper mapper(enter.object()); 2436 BufferAutoMapper mapper(enter.object());
2421 if (!mapper.data() || !mapper.size()) { 2437 if (!mapper.data() || !mapper.size()) {
2422 decrypt_cb.Run(media::Decryptor::kError, NULL); 2438 decrypt_cb.Run(media::Decryptor::kError, NULL);
2423 return; 2439 return;
2424 } 2440 }
2425 2441
2426 // TODO(tomfinegan): Find a way to take ownership of the shared memory 2442 // TODO(tomfinegan): Find a way to take ownership of the shared memory
2427 // managed by the PPB_Buffer_Dev, and avoid the extra copy. 2443 // managed by the PPB_Buffer_Dev, and avoid the extra copy.
2428 scoped_refptr<media::DecoderBuffer> decrypted_buffer( 2444 scoped_refptr<media::DecoderBuffer> decrypted_buffer(
2429 media::DecoderBuffer::CopyFrom( 2445 media::DecoderBuffer::CopyFrom(
2430 reinterpret_cast<const uint8*>(mapper.data()), mapper.size())); 2446 static_cast<uint8*>(mapper.data()), mapper.size()));
2431 decrypted_buffer->SetTimestamp(base::TimeDelta::FromMicroseconds( 2447 decrypted_buffer->SetTimestamp(base::TimeDelta::FromMicroseconds(
2432 block_info->tracking_info.timestamp)); 2448 block_info->tracking_info.timestamp));
2433 decrypt_cb.Run(media::Decryptor::kSuccess, decrypted_buffer); 2449 decrypt_cb.Run(media::Decryptor::kSuccess, decrypted_buffer);
2434 } 2450 }
2435 2451
2436 void PluginInstance::DeliverFrame(PP_Instance instance, 2452 void PluginInstance::DeliverFrame(PP_Instance instance,
2437 PP_Resource decrypted_frame, 2453 PP_Resource decrypted_frame,
2438 const PP_DecryptedFrameInfo* frame_info) { 2454 const PP_DecryptedFrameInfo* frame_info) {
2439 DVLOG(2) << "DeliverFrame() - request_id: " 2455 DVLOG(2) << "DeliverFrame() - request_id: "
2440 << frame_info->tracking_info.request_id; 2456 << frame_info->tracking_info.request_id;
2441 // TODO(tomfinegan): To be implemented after completion of v0.1 of the 2457 DCHECK(frame_info);
2442 // EME/CDM work. 2458
2459 // If the request ID is not valid or does not match what's saved, do nothing.
2460 if (frame_info->tracking_info.request_id == 0 ||
2461 frame_info->tracking_info.request_id !=
2462 pending_video_decode_request_id_) {
2463 DCHECK(pending_video_decode_cb_.is_null());
2464 return;
2465 }
2466
2467 DCHECK(!pending_video_decode_cb_.is_null());
2468 pending_video_decode_request_id_ = 0;
2469 media::Decryptor::VideoDecodeCB video_decode_cb =
2470 base::ResetAndReturn(&pending_video_decode_cb_);
2471
2472 if (frame_info->result == PP_DECRYPTRESULT_DECRYPT_NOKEY) {
2473 video_decode_cb.Run(media::Decryptor::kNoKey, NULL);
2474 return;
2475 }
2476
2477 if (frame_info->result != PP_DECRYPTRESULT_SUCCESS) {
2478 video_decode_cb.Run(media::Decryptor::kError, NULL);
2479 return;
2480 }
2481
2482 if (frame_info->format == PP_DECRYPTEDFRAMEFORMAT_EMPTY) {
2483 video_decode_cb.Run(media::Decryptor::kSuccess,
2484 media::VideoFrame::CreateEmptyFrame());
2485 return;
2486 }
2487
2488 EnterResourceNoLock<PPB_Buffer_API> enter(decrypted_frame, true);
2489 if (!enter.succeeded()) {
2490 video_decode_cb.Run(media::Decryptor::kError, NULL);
2491 return;
2492 }
2493 BufferAutoMapper mapper(enter.object());
2494 if (!mapper.data() || !mapper.size()) {
2495 video_decode_cb.Run(media::Decryptor::kError, NULL);
2496 return;
2497 }
2498
2499 const uint8* frame_data = static_cast<uint8*>(mapper.data());
2500 gfx::Size frame_size(frame_info->width, frame_info->height);
2501
2502 DCHECK(frame_info->format == PP_DECRYPTEDFRAMEFORMAT_YV12);
2503 const media::VideoFrame::Format format = media::VideoFrame::YV12;
2504
2505 // TODO(tomfinegan): Find a way to take ownership of the shared memory
2506 // managed by the PPB_Buffer_Dev, and avoid the extra copy.
2507 scoped_refptr<media::VideoFrame> decoded_frame(
2508 media::VideoFrame::CreateFrame(
2509 format, frame_size, frame_size,
2510 base::TimeDelta::FromMicroseconds(
2511 frame_info->tracking_info.timestamp)));
2512
2513 media::CopyYPlane(
2514 frame_data + frame_info->plane_offsets[PP_DECRYPTEDFRAMEPLANES_Y],
2515 frame_info->strides[PP_DECRYPTEDFRAMEPLANES_Y],
2516 frame_info->height,
2517 decoded_frame.get());
2518
2519 media::CopyUPlane(
2520 frame_data + frame_info->plane_offsets[PP_DECRYPTEDFRAMEPLANES_U],
2521 frame_info->strides[PP_DECRYPTEDFRAMEPLANES_U],
2522 frame_info->height,
2523 decoded_frame.get());
2524
2525 media::CopyVPlane(
2526 frame_data + frame_info->plane_offsets[PP_DECRYPTEDFRAMEPLANES_V],
2527 frame_info->strides[PP_DECRYPTEDFRAMEPLANES_V],
2528 frame_info->height,
2529 decoded_frame.get());
2530
2531 video_decode_cb.Run(media::Decryptor::kSuccess, decoded_frame);
2443 } 2532 }
2444 2533
2445 void PluginInstance::DeliverSamples(PP_Instance instance, 2534 void PluginInstance::DeliverSamples(PP_Instance instance,
2446 PP_Resource decrypted_samples, 2535 PP_Resource decrypted_samples,
2447 const PP_DecryptedBlockInfo* block_info) { 2536 const PP_DecryptedBlockInfo* block_info) {
2448 DVLOG(2) << "DeliverSamples() - request_id: " 2537 DVLOG(2) << "DeliverSamples() - request_id: "
2449 << block_info->tracking_info.request_id; 2538 << block_info->tracking_info.request_id;
2450 // TODO(tomfinegan): To be implemented after completion of v0.1 of the 2539 // TODO(tomfinegan): To be implemented after completion of v0.1 of the
2451 // EME/CDM work. 2540 // EME/CDM work.
2452 } 2541 }
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
2831 screen_size_for_fullscreen_ = gfx::Size(); 2920 screen_size_for_fullscreen_ = gfx::Size();
2832 WebElement element = container_->element(); 2921 WebElement element = container_->element();
2833 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); 2922 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_);
2834 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); 2923 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_);
2835 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); 2924 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_);
2836 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); 2925 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_);
2837 } 2926 }
2838 2927
2839 } // namespace ppapi 2928 } // namespace ppapi
2840 } // namespace webkit 2929 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698