Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "webkit/plugins/ppapi/content_decryptor_delegate.h" | 5 #include "webkit/plugins/ppapi/content_decryptor_delegate.h" |
| 6 | 6 |
| 7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
| 8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
| 9 #include "base/message_loop_proxy.h" | 9 #include "base/message_loop_proxy.h" |
| 10 #include "media/base/audio_decoder_config.h" | 10 #include "media/base/audio_decoder_config.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 // |array_size| is smaller than the |str| length. | 71 // |array_size| is smaller than the |str| length. |
| 72 template <uint32_t array_size> | 72 template <uint32_t array_size> |
| 73 bool CopyStringToArray(const std::string& str, uint8 (&array)[array_size]) { | 73 bool CopyStringToArray(const std::string& str, uint8 (&array)[array_size]) { |
| 74 if (array_size < str.size()) | 74 if (array_size < str.size()) |
| 75 return false; | 75 return false; |
| 76 | 76 |
| 77 memcpy(array, str.data(), str.size()); | 77 memcpy(array, str.data(), str.size()); |
| 78 return true; | 78 return true; |
| 79 } | 79 } |
| 80 | 80 |
| 81 // Fills the |block_info| with information from |decrypt_config|, |timestamp| | 81 // Fills the |block_info| with information from |encrypted_buffer|. |
| 82 // and |request_id|. |decrypt_config| can be NULL if the block is not encrypted. | 82 // |
| 83 // This is useful for end-of-stream blocks. | |
| 84 // Returns true if |block_info| is successfully filled. Returns false | 83 // Returns true if |block_info| is successfully filled. Returns false |
| 85 // otherwise. | 84 // otherwise. |
| 86 bool MakeEncryptedBlockInfo(int data_size, | 85 static bool MakeEncryptedBlockInfo( |
| 87 const media::DecryptConfig* decrypt_config, | 86 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, |
| 88 int64_t timestamp, | 87 uint32_t request_id, |
| 89 uint32_t request_id, | 88 PP_EncryptedBlockInfo* block_info) { |
| 90 PP_EncryptedBlockInfo* block_info) { | |
| 91 DCHECK(block_info); | |
| 92 | |
| 93 // TODO(xhwang): Fix initialization of PP_EncryptedBlockInfo here and | 89 // TODO(xhwang): Fix initialization of PP_EncryptedBlockInfo here and |
| 94 // anywhere else. | 90 // anywhere else. |
| 95 memset(block_info, 0, sizeof(*block_info)); | 91 memset(block_info, 0, sizeof(*block_info)); |
| 92 block_info->tracking_info.request_id = request_id; | |
| 96 | 93 |
| 97 block_info->tracking_info.request_id = request_id; | 94 // EOS buffers need a request ID and nothing more. |
| 98 block_info->tracking_info.timestamp = timestamp; | 95 if (encrypted_buffer->IsEndOfStream()) |
| 99 | |
| 100 if (!decrypt_config) | |
| 101 return true; | 96 return true; |
| 102 | 97 |
| 103 DCHECK(data_size) << "DecryptConfig is set on an empty buffer"; | 98 block_info->tracking_info.timestamp = |
|
xhwang
2013/01/28 16:35:20
can we keep this DCHECK so that we won't miss 0-by
scherkus (not reviewing)
2013/01/28 18:28:37
Done.
| |
| 104 block_info->data_size = data_size; | 99 encrypted_buffer->GetTimestamp().InMicroseconds(); |
| 100 block_info->data_size = encrypted_buffer->GetDataSize(); | |
| 101 | |
| 102 const media::DecryptConfig* decrypt_config = | |
| 103 encrypted_buffer->GetDecryptConfig(); | |
| 105 block_info->data_offset = decrypt_config->data_offset(); | 104 block_info->data_offset = decrypt_config->data_offset(); |
| 106 | 105 |
| 107 if (!CopyStringToArray(decrypt_config->key_id(), block_info->key_id) || | 106 if (!CopyStringToArray(decrypt_config->key_id(), block_info->key_id) || |
| 108 !CopyStringToArray(decrypt_config->iv(), block_info->iv)) | 107 !CopyStringToArray(decrypt_config->iv(), block_info->iv)) |
| 109 return false; | 108 return false; |
| 110 | 109 |
| 111 block_info->key_id_size = decrypt_config->key_id().size(); | 110 block_info->key_id_size = decrypt_config->key_id().size(); |
| 112 block_info->iv_size = decrypt_config->iv().size(); | 111 block_info->iv_size = decrypt_config->iv().size(); |
| 113 | 112 |
| 114 if (decrypt_config->subsamples().size() > arraysize(block_info->subsamples)) | 113 if (decrypt_config->subsamples().size() > arraysize(block_info->subsamples)) |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 345 bool ContentDecryptorDelegate::Decrypt( | 344 bool ContentDecryptorDelegate::Decrypt( |
| 346 media::Decryptor::StreamType stream_type, | 345 media::Decryptor::StreamType stream_type, |
| 347 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, | 346 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, |
| 348 const media::Decryptor::DecryptCB& decrypt_cb) { | 347 const media::Decryptor::DecryptCB& decrypt_cb) { |
| 349 DVLOG(3) << "Decrypt() - stream_type: " << stream_type; | 348 DVLOG(3) << "Decrypt() - stream_type: " << stream_type; |
| 350 // |{audio|video}_input_resource_| is not being used by the plugin | 349 // |{audio|video}_input_resource_| is not being used by the plugin |
| 351 // now because there is only one pending audio/video decrypt request at any | 350 // now because there is only one pending audio/video decrypt request at any |
| 352 // time. This is enforced by the media pipeline. | 351 // time. This is enforced by the media pipeline. |
| 353 scoped_refptr<PPB_Buffer_Impl> encrypted_resource; | 352 scoped_refptr<PPB_Buffer_Impl> encrypted_resource; |
| 354 if (!MakeMediaBufferResource(stream_type, | 353 if (!MakeMediaBufferResource(stream_type, |
| 355 encrypted_buffer->GetData(), | 354 encrypted_buffer, |
| 356 encrypted_buffer->GetDataSize(), | |
| 357 &encrypted_resource) || | 355 &encrypted_resource) || |
| 358 !encrypted_resource) { | 356 !encrypted_resource) { |
| 359 return false; | 357 return false; |
| 360 } | 358 } |
| 361 ScopedPPResource pp_resource(encrypted_resource.get()); | 359 ScopedPPResource pp_resource(encrypted_resource.get()); |
| 362 | 360 |
| 363 const uint32_t request_id = next_decryption_request_id_++; | 361 const uint32_t request_id = next_decryption_request_id_++; |
| 364 DVLOG(2) << "Decrypt() - request_id " << request_id; | 362 DVLOG(2) << "Decrypt() - request_id " << request_id; |
| 365 | 363 |
| 366 PP_EncryptedBlockInfo block_info = {}; | 364 PP_EncryptedBlockInfo block_info = {}; |
| 367 DCHECK(encrypted_buffer->GetDecryptConfig()); | 365 DCHECK(encrypted_buffer->GetDecryptConfig()); |
| 368 if (!MakeEncryptedBlockInfo(encrypted_buffer->GetDataSize(), | 366 if (!MakeEncryptedBlockInfo(encrypted_buffer, request_id, &block_info)) { |
| 369 encrypted_buffer->GetDecryptConfig(), | |
| 370 encrypted_buffer->GetTimestamp().InMicroseconds(), | |
| 371 request_id, | |
| 372 &block_info)) { | |
| 373 return false; | 367 return false; |
| 374 } | 368 } |
| 375 | 369 |
| 376 // There is only one pending decrypt request at any time per stream. This is | 370 // There is only one pending decrypt request at any time per stream. This is |
| 377 // enforced by the media pipeline. | 371 // enforced by the media pipeline. |
| 378 switch (stream_type) { | 372 switch (stream_type) { |
| 379 case media::Decryptor::kAudio: | 373 case media::Decryptor::kAudio: |
| 380 DCHECK_EQ(pending_audio_decrypt_request_id_, 0u); | 374 DCHECK_EQ(pending_audio_decrypt_request_id_, 0u); |
| 381 DCHECK(pending_audio_decrypt_cb_.is_null()); | 375 DCHECK(pending_audio_decrypt_cb_.is_null()); |
| 382 pending_audio_decrypt_request_id_ = request_id; | 376 pending_audio_decrypt_request_id_ = request_id; |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 521 | 515 |
| 522 // TODO(tomfinegan): Add decoder reset request tracking. | 516 // TODO(tomfinegan): Add decoder reset request tracking. |
| 523 plugin_decryption_interface_->ResetDecoder( | 517 plugin_decryption_interface_->ResetDecoder( |
| 524 pp_instance_, MediaDecryptorStreamTypeToPpStreamType(stream_type), 0); | 518 pp_instance_, MediaDecryptorStreamTypeToPpStreamType(stream_type), 0); |
| 525 return true; | 519 return true; |
| 526 } | 520 } |
| 527 | 521 |
| 528 bool ContentDecryptorDelegate::DecryptAndDecodeAudio( | 522 bool ContentDecryptorDelegate::DecryptAndDecodeAudio( |
| 529 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, | 523 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, |
| 530 const media::Decryptor::AudioDecodeCB& audio_decode_cb) { | 524 const media::Decryptor::AudioDecodeCB& audio_decode_cb) { |
| 531 // If |encrypted_buffer| is end-of-stream buffer, GetData() and GetDataSize() | |
| 532 // return NULL and 0 respectively. In that case, we'll just create a NULL | |
| 533 // resource. | |
| 534 // |audio_input_resource_| is not being used by the plugin now | 525 // |audio_input_resource_| is not being used by the plugin now |
| 535 // because there is only one pending audio decode request at any time. | 526 // because there is only one pending audio decode request at any time. |
| 536 // This is enforced by the media pipeline. | 527 // This is enforced by the media pipeline. |
| 537 scoped_refptr<PPB_Buffer_Impl> encrypted_resource; | 528 scoped_refptr<PPB_Buffer_Impl> encrypted_resource; |
| 538 if (!MakeMediaBufferResource(media::Decryptor::kAudio, | 529 if (!MakeMediaBufferResource(media::Decryptor::kAudio, |
| 539 encrypted_buffer->GetData(), | 530 encrypted_buffer, |
| 540 encrypted_buffer->GetDataSize(), | |
| 541 &encrypted_resource)) { | 531 &encrypted_resource)) { |
| 542 return false; | 532 return false; |
| 543 } | 533 } |
| 544 ScopedPPResource pp_resource(encrypted_resource.get()); | |
| 545 | 534 |
| 546 // The resource should not be NULL for non-EOS buffer. | 535 // The resource should not be NULL for non-EOS buffer. |
| 547 if (!encrypted_buffer->IsEndOfStream() && !encrypted_resource) | 536 if (!encrypted_buffer->IsEndOfStream() && !encrypted_resource) |
| 548 return false; | 537 return false; |
| 549 | 538 |
| 550 const uint32_t request_id = next_decryption_request_id_++; | 539 const uint32_t request_id = next_decryption_request_id_++; |
| 551 DVLOG(2) << "DecryptAndDecodeAudio() - request_id " << request_id; | 540 DVLOG(2) << "DecryptAndDecodeAudio() - request_id " << request_id; |
| 552 | 541 |
| 553 PP_EncryptedBlockInfo block_info = {}; | 542 PP_EncryptedBlockInfo block_info = {}; |
| 554 if (!MakeEncryptedBlockInfo( | 543 if (!MakeEncryptedBlockInfo(encrypted_buffer, request_id, &block_info)) { |
| 555 encrypted_buffer->GetDataSize(), | |
| 556 encrypted_buffer->GetDecryptConfig(), | |
| 557 encrypted_buffer->GetTimestamp().InMicroseconds(), | |
| 558 request_id, | |
| 559 &block_info)) { | |
| 560 return false; | 544 return false; |
| 561 } | 545 } |
| 562 | 546 |
| 563 SetBufferToFreeInTrackingInfo(&block_info.tracking_info); | 547 SetBufferToFreeInTrackingInfo(&block_info.tracking_info); |
| 564 | 548 |
| 565 // There is only one pending audio decode request at any time. This is | 549 // There is only one pending audio decode request at any time. This is |
| 566 // enforced by the media pipeline. If this DCHECK is violated, our buffer | 550 // enforced by the media pipeline. If this DCHECK is violated, our buffer |
| 567 // reuse policy is not valid, and we may have race problems for the shared | 551 // reuse policy is not valid, and we may have race problems for the shared |
| 568 // buffer. | 552 // buffer. |
| 569 DCHECK_EQ(pending_audio_decode_request_id_, 0u); | 553 DCHECK_EQ(pending_audio_decode_request_id_, 0u); |
| 570 DCHECK(pending_audio_decode_cb_.is_null()); | 554 DCHECK(pending_audio_decode_cb_.is_null()); |
| 571 pending_audio_decode_request_id_ = request_id; | 555 pending_audio_decode_request_id_ = request_id; |
| 572 pending_audio_decode_cb_ = audio_decode_cb; | 556 pending_audio_decode_cb_ = audio_decode_cb; |
| 573 | 557 |
| 558 ScopedPPResource pp_resource(encrypted_resource.get()); | |
| 574 plugin_decryption_interface_->DecryptAndDecode(pp_instance_, | 559 plugin_decryption_interface_->DecryptAndDecode(pp_instance_, |
| 575 PP_DECRYPTORSTREAMTYPE_AUDIO, | 560 PP_DECRYPTORSTREAMTYPE_AUDIO, |
| 576 pp_resource, | 561 pp_resource, |
| 577 &block_info); | 562 &block_info); |
| 578 return true; | 563 return true; |
| 579 } | 564 } |
| 580 | 565 |
| 581 bool ContentDecryptorDelegate::DecryptAndDecodeVideo( | 566 bool ContentDecryptorDelegate::DecryptAndDecodeVideo( |
| 582 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, | 567 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, |
| 583 const media::Decryptor::VideoDecodeCB& video_decode_cb) { | 568 const media::Decryptor::VideoDecodeCB& video_decode_cb) { |
| 584 // If |encrypted_buffer| is end-of-stream buffer, GetData() and GetDataSize() | |
| 585 // return NULL and 0 respectively. In that case, we'll just get a NULL | |
| 586 // resource. | |
| 587 // |video_input_resource_| is not being used by the plugin now | 569 // |video_input_resource_| is not being used by the plugin now |
| 588 // because there is only one pending video decode request at any time. | 570 // because there is only one pending video decode request at any time. |
| 589 // This is enforced by the media pipeline. | 571 // This is enforced by the media pipeline. |
| 590 scoped_refptr<PPB_Buffer_Impl> encrypted_resource; | 572 scoped_refptr<PPB_Buffer_Impl> encrypted_resource; |
| 591 if (!MakeMediaBufferResource(media::Decryptor::kVideo, | 573 if (!MakeMediaBufferResource(media::Decryptor::kVideo, |
| 592 encrypted_buffer->GetData(), | 574 encrypted_buffer, |
| 593 encrypted_buffer->GetDataSize(), | |
| 594 &encrypted_resource)) { | 575 &encrypted_resource)) { |
| 595 return false; | 576 return false; |
| 596 } | 577 } |
| 597 ScopedPPResource pp_resource(encrypted_resource.get()); | |
| 598 | 578 |
| 599 // The resource should not be 0 for non-EOS buffer. | 579 // The resource should not be 0 for non-EOS buffer. |
| 600 if (!encrypted_buffer->IsEndOfStream() && !encrypted_resource) | 580 if (!encrypted_buffer->IsEndOfStream() && !encrypted_resource) |
| 601 return false; | 581 return false; |
| 602 | 582 |
| 603 const uint32_t request_id = next_decryption_request_id_++; | 583 const uint32_t request_id = next_decryption_request_id_++; |
| 604 DVLOG(2) << "DecryptAndDecodeVideo() - request_id " << request_id; | 584 DVLOG(2) << "DecryptAndDecodeVideo() - request_id " << request_id; |
| 605 TRACE_EVENT_ASYNC_BEGIN0( | 585 TRACE_EVENT_ASYNC_BEGIN0( |
| 606 "eme", "ContentDecryptorDelegate::DecryptAndDecodeVideo", request_id); | 586 "eme", "ContentDecryptorDelegate::DecryptAndDecodeVideo", request_id); |
| 607 | 587 |
| 608 PP_EncryptedBlockInfo block_info = {}; | 588 PP_EncryptedBlockInfo block_info = {}; |
| 609 if (!MakeEncryptedBlockInfo( | 589 if (!MakeEncryptedBlockInfo(encrypted_buffer, request_id, &block_info)) { |
| 610 encrypted_buffer->GetDataSize(), | |
| 611 encrypted_buffer->GetDecryptConfig(), | |
| 612 encrypted_buffer->GetTimestamp().InMicroseconds(), | |
| 613 request_id, | |
| 614 &block_info)) { | |
| 615 return false; | 590 return false; |
| 616 } | 591 } |
| 617 | 592 |
| 618 SetBufferToFreeInTrackingInfo(&block_info.tracking_info); | 593 SetBufferToFreeInTrackingInfo(&block_info.tracking_info); |
| 619 | 594 |
| 620 // Only one pending video decode request at any time. This is enforced by the | 595 // Only one pending video decode request at any time. This is enforced by the |
| 621 // media pipeline. If this DCHECK is violated, our buffer | 596 // media pipeline. If this DCHECK is violated, our buffer |
| 622 // reuse policy is not valid, and we may have race problems for the shared | 597 // reuse policy is not valid, and we may have race problems for the shared |
| 623 // buffer. | 598 // buffer. |
| 624 DCHECK_EQ(pending_video_decode_request_id_, 0u); | 599 DCHECK_EQ(pending_video_decode_request_id_, 0u); |
| 625 DCHECK(pending_video_decode_cb_.is_null()); | 600 DCHECK(pending_video_decode_cb_.is_null()); |
| 626 pending_video_decode_request_id_ = request_id; | 601 pending_video_decode_request_id_ = request_id; |
| 627 pending_video_decode_cb_ = video_decode_cb; | 602 pending_video_decode_cb_ = video_decode_cb; |
| 628 | 603 |
| 629 // TODO(tomfinegan): Need to get stream type from media stack. | 604 // TODO(tomfinegan): Need to get stream type from media stack. |
| 605 ScopedPPResource pp_resource(encrypted_resource.get()); | |
| 630 plugin_decryption_interface_->DecryptAndDecode(pp_instance_, | 606 plugin_decryption_interface_->DecryptAndDecode(pp_instance_, |
| 631 PP_DECRYPTORSTREAMTYPE_VIDEO, | 607 PP_DECRYPTORSTREAMTYPE_VIDEO, |
| 632 pp_resource, | 608 pp_resource, |
| 633 &block_info); | 609 &block_info); |
| 634 return true; | 610 return true; |
| 635 } | 611 } |
| 636 | 612 |
| 637 void ContentDecryptorDelegate::NeedKey(PP_Var key_system_var, | 613 void ContentDecryptorDelegate::NeedKey(PP_Var key_system_var, |
| 638 PP_Var session_id_var, | 614 PP_Var session_id_var, |
| 639 PP_Var init_data_var) { | 615 PP_Var init_data_var) { |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 972 base::ResetAndReturn(&pending_video_decode_cb_).Run( | 948 base::ResetAndReturn(&pending_video_decode_cb_).Run( |
| 973 media::Decryptor::kSuccess, NULL); | 949 media::Decryptor::kSuccess, NULL); |
| 974 break; | 950 break; |
| 975 default: | 951 default: |
| 976 NOTREACHED(); | 952 NOTREACHED(); |
| 977 } | 953 } |
| 978 } | 954 } |
| 979 | 955 |
| 980 bool ContentDecryptorDelegate::MakeMediaBufferResource( | 956 bool ContentDecryptorDelegate::MakeMediaBufferResource( |
| 981 media::Decryptor::StreamType stream_type, | 957 media::Decryptor::StreamType stream_type, |
| 982 const uint8* data, uint32_t size, | 958 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, |
| 983 scoped_refptr<PPB_Buffer_Impl>* resource) { | 959 scoped_refptr<PPB_Buffer_Impl>* resource) { |
| 984 TRACE_EVENT0("eme", "ContentDecryptorDelegate::MakeMediaBufferResource"); | 960 TRACE_EVENT0("eme", "ContentDecryptorDelegate::MakeMediaBufferResource"); |
| 985 | 961 |
| 986 DCHECK(resource); | 962 // End of stream buffers are represented as null resources. |
| 987 | 963 if (encrypted_buffer->IsEndOfStream()) { |
| 988 if (!data || !size) { | 964 *resource = NULL; |
|
xhwang
2013/01/28 16:35:20
looks like you found a bug! thanks!
scherkus (not reviewing)
2013/01/28 18:28:37
:)
| |
| 989 DCHECK(!data && !size); | |
| 990 resource = NULL; | |
| 991 return true; | 965 return true; |
| 992 } | 966 } |
| 993 | 967 |
| 968 const size_t data_size = static_cast<size_t>(encrypted_buffer->GetDataSize()); | |
|
xhwang
2013/01/28 16:35:20
move this down to 972 or 975?
scherkus (not reviewing)
2013/01/28 18:28:37
Done.
| |
| 969 | |
| 994 DCHECK(stream_type == media::Decryptor::kAudio || | 970 DCHECK(stream_type == media::Decryptor::kAudio || |
| 995 stream_type == media::Decryptor::kVideo); | 971 stream_type == media::Decryptor::kVideo); |
| 996 scoped_refptr<PPB_Buffer_Impl>& media_resource = | 972 scoped_refptr<PPB_Buffer_Impl>& media_resource = |
| 997 (stream_type == media::Decryptor::kAudio) ? audio_input_resource_ : | 973 (stream_type == media::Decryptor::kAudio) ? audio_input_resource_ : |
| 998 video_input_resource_; | 974 video_input_resource_; |
| 999 if (!media_resource || (media_resource->size() < size)) { | 975 if (!media_resource || media_resource->size() < data_size) { |
| 1000 // Either the buffer hasn't been created yet, or we have one that isn't big | 976 // Either the buffer hasn't been created yet, or we have one that isn't big |
| 1001 // enough to fit |size| bytes. | 977 // enough to fit |size| bytes. |
| 1002 | 978 |
| 1003 // Media resource size starts from |kMinimumMediaBufferSize| and grows | 979 // Media resource size starts from |kMinimumMediaBufferSize| and grows |
| 1004 // exponentially to avoid frequent re-allocation of PPB_Buffer_Impl, | 980 // exponentially to avoid frequent re-allocation of PPB_Buffer_Impl, |
| 1005 // which is usually expensive. Since input media buffers are compressed, | 981 // which is usually expensive. Since input media buffers are compressed, |
| 1006 // they are usually small (compared to outputs). The over-allocated memory | 982 // they are usually small (compared to outputs). The over-allocated memory |
| 1007 // should be negligible. | 983 // should be negligible. |
| 1008 const uint32_t kMinimumMediaBufferSize = 1024; | 984 const uint32_t kMinimumMediaBufferSize = 1024; |
| 1009 uint32_t media_resource_size = media_resource ? media_resource->size() : | 985 uint32_t media_resource_size = media_resource ? media_resource->size() : |
| 1010 kMinimumMediaBufferSize; | 986 kMinimumMediaBufferSize; |
| 1011 while (media_resource_size < size) | 987 while (media_resource_size < data_size) |
| 1012 media_resource_size *= 2; | 988 media_resource_size *= 2; |
| 1013 | 989 |
| 1014 DVLOG(2) << "Size of media buffer for " | 990 DVLOG(2) << "Size of media buffer for " |
| 1015 << ((stream_type == media::Decryptor::kAudio) ? "audio" : "video") | 991 << ((stream_type == media::Decryptor::kAudio) ? "audio" : "video") |
| 1016 << " stream bumped to " << media_resource_size | 992 << " stream bumped to " << media_resource_size |
| 1017 << " bytes to fit input."; | 993 << " bytes to fit input."; |
| 1018 media_resource = PPB_Buffer_Impl::CreateResource(pp_instance_, | 994 media_resource = PPB_Buffer_Impl::CreateResource(pp_instance_, |
| 1019 media_resource_size); | 995 media_resource_size); |
| 1020 if (!media_resource) | 996 if (!media_resource) |
| 1021 return false; | 997 return false; |
| 1022 } | 998 } |
| 1023 | 999 |
| 1024 BufferAutoMapper mapper(media_resource); | 1000 BufferAutoMapper mapper(media_resource); |
| 1025 if (!mapper.data() || mapper.size() < static_cast<size_t>(size)) { | 1001 if (!mapper.data() || mapper.size() < data_size) { |
| 1026 media_resource = NULL; | 1002 media_resource = NULL; |
| 1027 return false; | 1003 return false; |
| 1028 } | 1004 } |
| 1029 memcpy(mapper.data(), data, size); | 1005 memcpy(mapper.data(), encrypted_buffer->GetData(), data_size); |
| 1030 | 1006 |
| 1031 *resource = media_resource; | 1007 *resource = media_resource; |
| 1032 return true; | 1008 return true; |
| 1033 } | 1009 } |
| 1034 | 1010 |
| 1035 void ContentDecryptorDelegate::FreeBuffer(uint32_t buffer_id) { | 1011 void ContentDecryptorDelegate::FreeBuffer(uint32_t buffer_id) { |
| 1036 if (buffer_id) | 1012 if (buffer_id) |
| 1037 free_buffers_.push(buffer_id); | 1013 free_buffers_.push(buffer_id); |
| 1038 } | 1014 } |
| 1039 | 1015 |
| 1040 void ContentDecryptorDelegate::SetBufferToFreeInTrackingInfo( | 1016 void ContentDecryptorDelegate::SetBufferToFreeInTrackingInfo( |
| 1041 PP_DecryptTrackingInfo* tracking_info) { | 1017 PP_DecryptTrackingInfo* tracking_info) { |
| 1042 DCHECK_EQ(tracking_info->buffer_id, 0u); | 1018 DCHECK_EQ(tracking_info->buffer_id, 0u); |
| 1043 | 1019 |
| 1044 if (free_buffers_.empty()) | 1020 if (free_buffers_.empty()) |
| 1045 return; | 1021 return; |
| 1046 | 1022 |
| 1047 tracking_info->buffer_id = free_buffers_.front(); | 1023 tracking_info->buffer_id = free_buffers_.front(); |
| 1048 free_buffers_.pop(); | 1024 free_buffers_.pop(); |
| 1049 } | 1025 } |
| 1050 | 1026 |
| 1051 } // namespace ppapi | 1027 } // namespace ppapi |
| 1052 } // namespace webkit | 1028 } // namespace webkit |
| OLD | NEW |