| 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 DCHECK(encrypted_buffer->GetDataSize()) |
| 104 block_info->data_size = data_size; | 99 << "DecryptConfig is set on an empty buffer"; |
| 100 |
| 101 block_info->tracking_info.timestamp = |
| 102 encrypted_buffer->GetTimestamp().InMicroseconds(); |
| 103 block_info->data_size = encrypted_buffer->GetDataSize(); |
| 104 |
| 105 const media::DecryptConfig* decrypt_config = |
| 106 encrypted_buffer->GetDecryptConfig(); |
| 105 block_info->data_offset = decrypt_config->data_offset(); | 107 block_info->data_offset = decrypt_config->data_offset(); |
| 106 | 108 |
| 107 if (!CopyStringToArray(decrypt_config->key_id(), block_info->key_id) || | 109 if (!CopyStringToArray(decrypt_config->key_id(), block_info->key_id) || |
| 108 !CopyStringToArray(decrypt_config->iv(), block_info->iv)) | 110 !CopyStringToArray(decrypt_config->iv(), block_info->iv)) |
| 109 return false; | 111 return false; |
| 110 | 112 |
| 111 block_info->key_id_size = decrypt_config->key_id().size(); | 113 block_info->key_id_size = decrypt_config->key_id().size(); |
| 112 block_info->iv_size = decrypt_config->iv().size(); | 114 block_info->iv_size = decrypt_config->iv().size(); |
| 113 | 115 |
| 114 if (decrypt_config->subsamples().size() > arraysize(block_info->subsamples)) | 116 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( | 347 bool ContentDecryptorDelegate::Decrypt( |
| 346 media::Decryptor::StreamType stream_type, | 348 media::Decryptor::StreamType stream_type, |
| 347 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, | 349 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, |
| 348 const media::Decryptor::DecryptCB& decrypt_cb) { | 350 const media::Decryptor::DecryptCB& decrypt_cb) { |
| 349 DVLOG(3) << "Decrypt() - stream_type: " << stream_type; | 351 DVLOG(3) << "Decrypt() - stream_type: " << stream_type; |
| 350 // |{audio|video}_input_resource_| is not being used by the plugin | 352 // |{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 | 353 // now because there is only one pending audio/video decrypt request at any |
| 352 // time. This is enforced by the media pipeline. | 354 // time. This is enforced by the media pipeline. |
| 353 scoped_refptr<PPB_Buffer_Impl> encrypted_resource; | 355 scoped_refptr<PPB_Buffer_Impl> encrypted_resource; |
| 354 if (!MakeMediaBufferResource(stream_type, | 356 if (!MakeMediaBufferResource(stream_type, |
| 355 encrypted_buffer->GetData(), | 357 encrypted_buffer, |
| 356 encrypted_buffer->GetDataSize(), | |
| 357 &encrypted_resource) || | 358 &encrypted_resource) || |
| 358 !encrypted_resource) { | 359 !encrypted_resource) { |
| 359 return false; | 360 return false; |
| 360 } | 361 } |
| 361 ScopedPPResource pp_resource(encrypted_resource.get()); | 362 ScopedPPResource pp_resource(encrypted_resource.get()); |
| 362 | 363 |
| 363 const uint32_t request_id = next_decryption_request_id_++; | 364 const uint32_t request_id = next_decryption_request_id_++; |
| 364 DVLOG(2) << "Decrypt() - request_id " << request_id; | 365 DVLOG(2) << "Decrypt() - request_id " << request_id; |
| 365 | 366 |
| 366 PP_EncryptedBlockInfo block_info = {}; | 367 PP_EncryptedBlockInfo block_info = {}; |
| 367 DCHECK(encrypted_buffer->GetDecryptConfig()); | 368 DCHECK(encrypted_buffer->GetDecryptConfig()); |
| 368 if (!MakeEncryptedBlockInfo(encrypted_buffer->GetDataSize(), | 369 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; | 370 return false; |
| 374 } | 371 } |
| 375 | 372 |
| 376 // There is only one pending decrypt request at any time per stream. This is | 373 // There is only one pending decrypt request at any time per stream. This is |
| 377 // enforced by the media pipeline. | 374 // enforced by the media pipeline. |
| 378 switch (stream_type) { | 375 switch (stream_type) { |
| 379 case media::Decryptor::kAudio: | 376 case media::Decryptor::kAudio: |
| 380 DCHECK_EQ(pending_audio_decrypt_request_id_, 0u); | 377 DCHECK_EQ(pending_audio_decrypt_request_id_, 0u); |
| 381 DCHECK(pending_audio_decrypt_cb_.is_null()); | 378 DCHECK(pending_audio_decrypt_cb_.is_null()); |
| 382 pending_audio_decrypt_request_id_ = request_id; | 379 pending_audio_decrypt_request_id_ = request_id; |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 | 518 |
| 522 // TODO(tomfinegan): Add decoder reset request tracking. | 519 // TODO(tomfinegan): Add decoder reset request tracking. |
| 523 plugin_decryption_interface_->ResetDecoder( | 520 plugin_decryption_interface_->ResetDecoder( |
| 524 pp_instance_, MediaDecryptorStreamTypeToPpStreamType(stream_type), 0); | 521 pp_instance_, MediaDecryptorStreamTypeToPpStreamType(stream_type), 0); |
| 525 return true; | 522 return true; |
| 526 } | 523 } |
| 527 | 524 |
| 528 bool ContentDecryptorDelegate::DecryptAndDecodeAudio( | 525 bool ContentDecryptorDelegate::DecryptAndDecodeAudio( |
| 529 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, | 526 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, |
| 530 const media::Decryptor::AudioDecodeCB& audio_decode_cb) { | 527 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 | 528 // |audio_input_resource_| is not being used by the plugin now |
| 535 // because there is only one pending audio decode request at any time. | 529 // because there is only one pending audio decode request at any time. |
| 536 // This is enforced by the media pipeline. | 530 // This is enforced by the media pipeline. |
| 537 scoped_refptr<PPB_Buffer_Impl> encrypted_resource; | 531 scoped_refptr<PPB_Buffer_Impl> encrypted_resource; |
| 538 if (!MakeMediaBufferResource(media::Decryptor::kAudio, | 532 if (!MakeMediaBufferResource(media::Decryptor::kAudio, |
| 539 encrypted_buffer->GetData(), | 533 encrypted_buffer, |
| 540 encrypted_buffer->GetDataSize(), | |
| 541 &encrypted_resource)) { | 534 &encrypted_resource)) { |
| 542 return false; | 535 return false; |
| 543 } | 536 } |
| 544 ScopedPPResource pp_resource(encrypted_resource.get()); | |
| 545 | 537 |
| 546 // The resource should not be NULL for non-EOS buffer. | 538 // The resource should not be NULL for non-EOS buffer. |
| 547 if (!encrypted_buffer->IsEndOfStream() && !encrypted_resource) | 539 if (!encrypted_buffer->IsEndOfStream() && !encrypted_resource) |
| 548 return false; | 540 return false; |
| 549 | 541 |
| 550 const uint32_t request_id = next_decryption_request_id_++; | 542 const uint32_t request_id = next_decryption_request_id_++; |
| 551 DVLOG(2) << "DecryptAndDecodeAudio() - request_id " << request_id; | 543 DVLOG(2) << "DecryptAndDecodeAudio() - request_id " << request_id; |
| 552 | 544 |
| 553 PP_EncryptedBlockInfo block_info = {}; | 545 PP_EncryptedBlockInfo block_info = {}; |
| 554 if (!MakeEncryptedBlockInfo( | 546 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; | 547 return false; |
| 561 } | 548 } |
| 562 | 549 |
| 563 SetBufferToFreeInTrackingInfo(&block_info.tracking_info); | 550 SetBufferToFreeInTrackingInfo(&block_info.tracking_info); |
| 564 | 551 |
| 565 // There is only one pending audio decode request at any time. This is | 552 // 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 | 553 // 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 | 554 // reuse policy is not valid, and we may have race problems for the shared |
| 568 // buffer. | 555 // buffer. |
| 569 DCHECK_EQ(pending_audio_decode_request_id_, 0u); | 556 DCHECK_EQ(pending_audio_decode_request_id_, 0u); |
| 570 DCHECK(pending_audio_decode_cb_.is_null()); | 557 DCHECK(pending_audio_decode_cb_.is_null()); |
| 571 pending_audio_decode_request_id_ = request_id; | 558 pending_audio_decode_request_id_ = request_id; |
| 572 pending_audio_decode_cb_ = audio_decode_cb; | 559 pending_audio_decode_cb_ = audio_decode_cb; |
| 573 | 560 |
| 561 ScopedPPResource pp_resource(encrypted_resource.get()); |
| 574 plugin_decryption_interface_->DecryptAndDecode(pp_instance_, | 562 plugin_decryption_interface_->DecryptAndDecode(pp_instance_, |
| 575 PP_DECRYPTORSTREAMTYPE_AUDIO, | 563 PP_DECRYPTORSTREAMTYPE_AUDIO, |
| 576 pp_resource, | 564 pp_resource, |
| 577 &block_info); | 565 &block_info); |
| 578 return true; | 566 return true; |
| 579 } | 567 } |
| 580 | 568 |
| 581 bool ContentDecryptorDelegate::DecryptAndDecodeVideo( | 569 bool ContentDecryptorDelegate::DecryptAndDecodeVideo( |
| 582 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, | 570 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, |
| 583 const media::Decryptor::VideoDecodeCB& video_decode_cb) { | 571 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 | 572 // |video_input_resource_| is not being used by the plugin now |
| 588 // because there is only one pending video decode request at any time. | 573 // because there is only one pending video decode request at any time. |
| 589 // This is enforced by the media pipeline. | 574 // This is enforced by the media pipeline. |
| 590 scoped_refptr<PPB_Buffer_Impl> encrypted_resource; | 575 scoped_refptr<PPB_Buffer_Impl> encrypted_resource; |
| 591 if (!MakeMediaBufferResource(media::Decryptor::kVideo, | 576 if (!MakeMediaBufferResource(media::Decryptor::kVideo, |
| 592 encrypted_buffer->GetData(), | 577 encrypted_buffer, |
| 593 encrypted_buffer->GetDataSize(), | |
| 594 &encrypted_resource)) { | 578 &encrypted_resource)) { |
| 595 return false; | 579 return false; |
| 596 } | 580 } |
| 597 ScopedPPResource pp_resource(encrypted_resource.get()); | |
| 598 | 581 |
| 599 // The resource should not be 0 for non-EOS buffer. | 582 // The resource should not be 0 for non-EOS buffer. |
| 600 if (!encrypted_buffer->IsEndOfStream() && !encrypted_resource) | 583 if (!encrypted_buffer->IsEndOfStream() && !encrypted_resource) |
| 601 return false; | 584 return false; |
| 602 | 585 |
| 603 const uint32_t request_id = next_decryption_request_id_++; | 586 const uint32_t request_id = next_decryption_request_id_++; |
| 604 DVLOG(2) << "DecryptAndDecodeVideo() - request_id " << request_id; | 587 DVLOG(2) << "DecryptAndDecodeVideo() - request_id " << request_id; |
| 605 TRACE_EVENT_ASYNC_BEGIN0( | 588 TRACE_EVENT_ASYNC_BEGIN0( |
| 606 "eme", "ContentDecryptorDelegate::DecryptAndDecodeVideo", request_id); | 589 "eme", "ContentDecryptorDelegate::DecryptAndDecodeVideo", request_id); |
| 607 | 590 |
| 608 PP_EncryptedBlockInfo block_info = {}; | 591 PP_EncryptedBlockInfo block_info = {}; |
| 609 if (!MakeEncryptedBlockInfo( | 592 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; | 593 return false; |
| 616 } | 594 } |
| 617 | 595 |
| 618 SetBufferToFreeInTrackingInfo(&block_info.tracking_info); | 596 SetBufferToFreeInTrackingInfo(&block_info.tracking_info); |
| 619 | 597 |
| 620 // Only one pending video decode request at any time. This is enforced by the | 598 // Only one pending video decode request at any time. This is enforced by the |
| 621 // media pipeline. If this DCHECK is violated, our buffer | 599 // media pipeline. If this DCHECK is violated, our buffer |
| 622 // reuse policy is not valid, and we may have race problems for the shared | 600 // reuse policy is not valid, and we may have race problems for the shared |
| 623 // buffer. | 601 // buffer. |
| 624 DCHECK_EQ(pending_video_decode_request_id_, 0u); | 602 DCHECK_EQ(pending_video_decode_request_id_, 0u); |
| 625 DCHECK(pending_video_decode_cb_.is_null()); | 603 DCHECK(pending_video_decode_cb_.is_null()); |
| 626 pending_video_decode_request_id_ = request_id; | 604 pending_video_decode_request_id_ = request_id; |
| 627 pending_video_decode_cb_ = video_decode_cb; | 605 pending_video_decode_cb_ = video_decode_cb; |
| 628 | 606 |
| 629 // TODO(tomfinegan): Need to get stream type from media stack. | 607 // TODO(tomfinegan): Need to get stream type from media stack. |
| 608 ScopedPPResource pp_resource(encrypted_resource.get()); |
| 630 plugin_decryption_interface_->DecryptAndDecode(pp_instance_, | 609 plugin_decryption_interface_->DecryptAndDecode(pp_instance_, |
| 631 PP_DECRYPTORSTREAMTYPE_VIDEO, | 610 PP_DECRYPTORSTREAMTYPE_VIDEO, |
| 632 pp_resource, | 611 pp_resource, |
| 633 &block_info); | 612 &block_info); |
| 634 return true; | 613 return true; |
| 635 } | 614 } |
| 636 | 615 |
| 637 void ContentDecryptorDelegate::NeedKey(PP_Var key_system_var, | 616 void ContentDecryptorDelegate::NeedKey(PP_Var key_system_var, |
| 638 PP_Var session_id_var, | 617 PP_Var session_id_var, |
| 639 PP_Var init_data_var) { | 618 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( | 951 base::ResetAndReturn(&pending_video_decode_cb_).Run( |
| 973 media::Decryptor::kSuccess, NULL); | 952 media::Decryptor::kSuccess, NULL); |
| 974 break; | 953 break; |
| 975 default: | 954 default: |
| 976 NOTREACHED(); | 955 NOTREACHED(); |
| 977 } | 956 } |
| 978 } | 957 } |
| 979 | 958 |
| 980 bool ContentDecryptorDelegate::MakeMediaBufferResource( | 959 bool ContentDecryptorDelegate::MakeMediaBufferResource( |
| 981 media::Decryptor::StreamType stream_type, | 960 media::Decryptor::StreamType stream_type, |
| 982 const uint8* data, uint32_t size, | 961 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, |
| 983 scoped_refptr<PPB_Buffer_Impl>* resource) { | 962 scoped_refptr<PPB_Buffer_Impl>* resource) { |
| 984 TRACE_EVENT0("eme", "ContentDecryptorDelegate::MakeMediaBufferResource"); | 963 TRACE_EVENT0("eme", "ContentDecryptorDelegate::MakeMediaBufferResource"); |
| 985 | 964 |
| 986 DCHECK(resource); | 965 // End of stream buffers are represented as null resources. |
| 987 | 966 if (encrypted_buffer->IsEndOfStream()) { |
| 988 if (!data || !size) { | 967 *resource = NULL; |
| 989 DCHECK(!data && !size); | |
| 990 resource = NULL; | |
| 991 return true; | 968 return true; |
| 992 } | 969 } |
| 993 | 970 |
| 994 DCHECK(stream_type == media::Decryptor::kAudio || | 971 DCHECK(stream_type == media::Decryptor::kAudio || |
| 995 stream_type == media::Decryptor::kVideo); | 972 stream_type == media::Decryptor::kVideo); |
| 996 scoped_refptr<PPB_Buffer_Impl>& media_resource = | 973 scoped_refptr<PPB_Buffer_Impl>& media_resource = |
| 997 (stream_type == media::Decryptor::kAudio) ? audio_input_resource_ : | 974 (stream_type == media::Decryptor::kAudio) ? audio_input_resource_ : |
| 998 video_input_resource_; | 975 video_input_resource_; |
| 999 if (!media_resource || (media_resource->size() < size)) { | 976 |
| 977 const size_t data_size = static_cast<size_t>(encrypted_buffer->GetDataSize()); |
| 978 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 | 979 // Either the buffer hasn't been created yet, or we have one that isn't big |
| 1001 // enough to fit |size| bytes. | 980 // enough to fit |size| bytes. |
| 1002 | 981 |
| 1003 // Media resource size starts from |kMinimumMediaBufferSize| and grows | 982 // Media resource size starts from |kMinimumMediaBufferSize| and grows |
| 1004 // exponentially to avoid frequent re-allocation of PPB_Buffer_Impl, | 983 // exponentially to avoid frequent re-allocation of PPB_Buffer_Impl, |
| 1005 // which is usually expensive. Since input media buffers are compressed, | 984 // which is usually expensive. Since input media buffers are compressed, |
| 1006 // they are usually small (compared to outputs). The over-allocated memory | 985 // they are usually small (compared to outputs). The over-allocated memory |
| 1007 // should be negligible. | 986 // should be negligible. |
| 1008 const uint32_t kMinimumMediaBufferSize = 1024; | 987 const uint32_t kMinimumMediaBufferSize = 1024; |
| 1009 uint32_t media_resource_size = media_resource ? media_resource->size() : | 988 uint32_t media_resource_size = media_resource ? media_resource->size() : |
| 1010 kMinimumMediaBufferSize; | 989 kMinimumMediaBufferSize; |
| 1011 while (media_resource_size < size) | 990 while (media_resource_size < data_size) |
| 1012 media_resource_size *= 2; | 991 media_resource_size *= 2; |
| 1013 | 992 |
| 1014 DVLOG(2) << "Size of media buffer for " | 993 DVLOG(2) << "Size of media buffer for " |
| 1015 << ((stream_type == media::Decryptor::kAudio) ? "audio" : "video") | 994 << ((stream_type == media::Decryptor::kAudio) ? "audio" : "video") |
| 1016 << " stream bumped to " << media_resource_size | 995 << " stream bumped to " << media_resource_size |
| 1017 << " bytes to fit input."; | 996 << " bytes to fit input."; |
| 1018 media_resource = PPB_Buffer_Impl::CreateResource(pp_instance_, | 997 media_resource = PPB_Buffer_Impl::CreateResource(pp_instance_, |
| 1019 media_resource_size); | 998 media_resource_size); |
| 1020 if (!media_resource) | 999 if (!media_resource) |
| 1021 return false; | 1000 return false; |
| 1022 } | 1001 } |
| 1023 | 1002 |
| 1024 BufferAutoMapper mapper(media_resource); | 1003 BufferAutoMapper mapper(media_resource); |
| 1025 if (!mapper.data() || mapper.size() < static_cast<size_t>(size)) { | 1004 if (!mapper.data() || mapper.size() < data_size) { |
| 1026 media_resource = NULL; | 1005 media_resource = NULL; |
| 1027 return false; | 1006 return false; |
| 1028 } | 1007 } |
| 1029 memcpy(mapper.data(), data, size); | 1008 memcpy(mapper.data(), encrypted_buffer->GetData(), data_size); |
| 1030 | 1009 |
| 1031 *resource = media_resource; | 1010 *resource = media_resource; |
| 1032 return true; | 1011 return true; |
| 1033 } | 1012 } |
| 1034 | 1013 |
| 1035 void ContentDecryptorDelegate::FreeBuffer(uint32_t buffer_id) { | 1014 void ContentDecryptorDelegate::FreeBuffer(uint32_t buffer_id) { |
| 1036 if (buffer_id) | 1015 if (buffer_id) |
| 1037 free_buffers_.push(buffer_id); | 1016 free_buffers_.push(buffer_id); |
| 1038 } | 1017 } |
| 1039 | 1018 |
| 1040 void ContentDecryptorDelegate::SetBufferToFreeInTrackingInfo( | 1019 void ContentDecryptorDelegate::SetBufferToFreeInTrackingInfo( |
| 1041 PP_DecryptTrackingInfo* tracking_info) { | 1020 PP_DecryptTrackingInfo* tracking_info) { |
| 1042 DCHECK_EQ(tracking_info->buffer_id, 0u); | 1021 DCHECK_EQ(tracking_info->buffer_id, 0u); |
| 1043 | 1022 |
| 1044 if (free_buffers_.empty()) | 1023 if (free_buffers_.empty()) |
| 1045 return; | 1024 return; |
| 1046 | 1025 |
| 1047 tracking_info->buffer_id = free_buffers_.front(); | 1026 tracking_info->buffer_id = free_buffers_.front(); |
| 1048 free_buffers_.pop(); | 1027 free_buffers_.pop(); |
| 1049 } | 1028 } |
| 1050 | 1029 |
| 1051 } // namespace ppapi | 1030 } // namespace ppapi |
| 1052 } // namespace webkit | 1031 } // namespace webkit |
| OLD | NEW |