| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 DCHECK(resource); | 47 DCHECK(resource); |
| 48 | 48 |
| 49 if (!data || !size) { | 49 if (!data || !size) { |
| 50 DCHECK(!data && !size); | 50 DCHECK(!data && !size); |
| 51 resource = NULL; | 51 resource = NULL; |
| 52 return true; | 52 return true; |
| 53 } | 53 } |
| 54 | 54 |
| 55 scoped_refptr<PPB_Buffer_Impl> buffer( | 55 scoped_refptr<PPB_Buffer_Impl> buffer( |
| 56 PPB_Buffer_Impl::CreateResource(instance, size)); | 56 PPB_Buffer_Impl::CreateResource(instance, size)); |
| 57 if (!buffer) | 57 if (!buffer.get()) |
| 58 return false; | 58 return false; |
| 59 | 59 |
| 60 BufferAutoMapper mapper(buffer.get()); | 60 BufferAutoMapper mapper(buffer.get()); |
| 61 if (!mapper.data() || mapper.size() < size) | 61 if (!mapper.data() || mapper.size() < size) |
| 62 return false; | 62 return false; |
| 63 memcpy(mapper.data(), data, size); | 63 memcpy(mapper.data(), data, size); |
| 64 | 64 |
| 65 *resource = buffer; | 65 *resource = buffer; |
| 66 return true; | 66 return true; |
| 67 } | 67 } |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 // DecryptAndDecodeAudio() and DecryptAndDecodeVideo(). | 346 // DecryptAndDecodeAudio() and DecryptAndDecodeVideo(). |
| 347 bool ContentDecryptorDelegate::Decrypt( | 347 bool ContentDecryptorDelegate::Decrypt( |
| 348 media::Decryptor::StreamType stream_type, | 348 media::Decryptor::StreamType stream_type, |
| 349 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, | 349 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, |
| 350 const media::Decryptor::DecryptCB& decrypt_cb) { | 350 const media::Decryptor::DecryptCB& decrypt_cb) { |
| 351 DVLOG(3) << "Decrypt() - stream_type: " << stream_type; | 351 DVLOG(3) << "Decrypt() - stream_type: " << stream_type; |
| 352 // |{audio|video}_input_resource_| is not being used by the plugin | 352 // |{audio|video}_input_resource_| is not being used by the plugin |
| 353 // 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 |
| 354 // time. This is enforced by the media pipeline. | 354 // time. This is enforced by the media pipeline. |
| 355 scoped_refptr<PPB_Buffer_Impl> encrypted_resource; | 355 scoped_refptr<PPB_Buffer_Impl> encrypted_resource; |
| 356 if (!MakeMediaBufferResource(stream_type, | 356 if (!MakeMediaBufferResource( |
| 357 encrypted_buffer, | 357 stream_type, encrypted_buffer, &encrypted_resource) || |
| 358 &encrypted_resource) || | 358 !encrypted_resource.get()) { |
| 359 !encrypted_resource) { | |
| 360 return false; | 359 return false; |
| 361 } | 360 } |
| 362 ScopedPPResource pp_resource(encrypted_resource.get()); | 361 ScopedPPResource pp_resource(encrypted_resource.get()); |
| 363 | 362 |
| 364 const uint32_t request_id = next_decryption_request_id_++; | 363 const uint32_t request_id = next_decryption_request_id_++; |
| 365 DVLOG(2) << "Decrypt() - request_id " << request_id; | 364 DVLOG(2) << "Decrypt() - request_id " << request_id; |
| 366 | 365 |
| 367 PP_EncryptedBlockInfo block_info = {}; | 366 PP_EncryptedBlockInfo block_info = {}; |
| 368 DCHECK(encrypted_buffer->GetDecryptConfig()); | 367 DCHECK(encrypted_buffer->GetDecryptConfig()); |
| 369 if (!MakeEncryptedBlockInfo(encrypted_buffer, request_id, &block_info)) { | 368 if (!MakeEncryptedBlockInfo(encrypted_buffer, request_id, &block_info)) { |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 // because there is only one pending audio decode request at any time. | 528 // because there is only one pending audio decode request at any time. |
| 530 // This is enforced by the media pipeline. | 529 // This is enforced by the media pipeline. |
| 531 scoped_refptr<PPB_Buffer_Impl> encrypted_resource; | 530 scoped_refptr<PPB_Buffer_Impl> encrypted_resource; |
| 532 if (!MakeMediaBufferResource(media::Decryptor::kAudio, | 531 if (!MakeMediaBufferResource(media::Decryptor::kAudio, |
| 533 encrypted_buffer, | 532 encrypted_buffer, |
| 534 &encrypted_resource)) { | 533 &encrypted_resource)) { |
| 535 return false; | 534 return false; |
| 536 } | 535 } |
| 537 | 536 |
| 538 // The resource should not be NULL for non-EOS buffer. | 537 // The resource should not be NULL for non-EOS buffer. |
| 539 if (!encrypted_buffer->IsEndOfStream() && !encrypted_resource) | 538 if (!encrypted_buffer->IsEndOfStream() && !encrypted_resource.get()) |
| 540 return false; | 539 return false; |
| 541 | 540 |
| 542 const uint32_t request_id = next_decryption_request_id_++; | 541 const uint32_t request_id = next_decryption_request_id_++; |
| 543 DVLOG(2) << "DecryptAndDecodeAudio() - request_id " << request_id; | 542 DVLOG(2) << "DecryptAndDecodeAudio() - request_id " << request_id; |
| 544 | 543 |
| 545 PP_EncryptedBlockInfo block_info = {}; | 544 PP_EncryptedBlockInfo block_info = {}; |
| 546 if (!MakeEncryptedBlockInfo(encrypted_buffer, request_id, &block_info)) { | 545 if (!MakeEncryptedBlockInfo(encrypted_buffer, request_id, &block_info)) { |
| 547 return false; | 546 return false; |
| 548 } | 547 } |
| 549 | 548 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 573 // because there is only one pending video decode request at any time. | 572 // because there is only one pending video decode request at any time. |
| 574 // This is enforced by the media pipeline. | 573 // This is enforced by the media pipeline. |
| 575 scoped_refptr<PPB_Buffer_Impl> encrypted_resource; | 574 scoped_refptr<PPB_Buffer_Impl> encrypted_resource; |
| 576 if (!MakeMediaBufferResource(media::Decryptor::kVideo, | 575 if (!MakeMediaBufferResource(media::Decryptor::kVideo, |
| 577 encrypted_buffer, | 576 encrypted_buffer, |
| 578 &encrypted_resource)) { | 577 &encrypted_resource)) { |
| 579 return false; | 578 return false; |
| 580 } | 579 } |
| 581 | 580 |
| 582 // The resource should not be 0 for non-EOS buffer. | 581 // The resource should not be 0 for non-EOS buffer. |
| 583 if (!encrypted_buffer->IsEndOfStream() && !encrypted_resource) | 582 if (!encrypted_buffer->IsEndOfStream() && !encrypted_resource.get()) |
| 584 return false; | 583 return false; |
| 585 | 584 |
| 586 const uint32_t request_id = next_decryption_request_id_++; | 585 const uint32_t request_id = next_decryption_request_id_++; |
| 587 DVLOG(2) << "DecryptAndDecodeVideo() - request_id " << request_id; | 586 DVLOG(2) << "DecryptAndDecodeVideo() - request_id " << request_id; |
| 588 TRACE_EVENT_ASYNC_BEGIN0( | 587 TRACE_EVENT_ASYNC_BEGIN0( |
| 589 "eme", "ContentDecryptorDelegate::DecryptAndDecodeVideo", request_id); | 588 "eme", "ContentDecryptorDelegate::DecryptAndDecodeVideo", request_id); |
| 590 | 589 |
| 591 PP_EncryptedBlockInfo block_info = {}; | 590 PP_EncryptedBlockInfo block_info = {}; |
| 592 if (!MakeEncryptedBlockInfo(encrypted_buffer, request_id, &block_info)) { | 591 if (!MakeEncryptedBlockInfo(encrypted_buffer, request_id, &block_info)) { |
| 593 return false; | 592 return false; |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 971 return true; | 970 return true; |
| 972 } | 971 } |
| 973 | 972 |
| 974 DCHECK(stream_type == media::Decryptor::kAudio || | 973 DCHECK(stream_type == media::Decryptor::kAudio || |
| 975 stream_type == media::Decryptor::kVideo); | 974 stream_type == media::Decryptor::kVideo); |
| 976 scoped_refptr<PPB_Buffer_Impl>& media_resource = | 975 scoped_refptr<PPB_Buffer_Impl>& media_resource = |
| 977 (stream_type == media::Decryptor::kAudio) ? audio_input_resource_ : | 976 (stream_type == media::Decryptor::kAudio) ? audio_input_resource_ : |
| 978 video_input_resource_; | 977 video_input_resource_; |
| 979 | 978 |
| 980 const size_t data_size = static_cast<size_t>(encrypted_buffer->GetDataSize()); | 979 const size_t data_size = static_cast<size_t>(encrypted_buffer->GetDataSize()); |
| 981 if (!media_resource || media_resource->size() < data_size) { | 980 if (!media_resource.get() || media_resource->size() < data_size) { |
| 982 // Either the buffer hasn't been created yet, or we have one that isn't big | 981 // Either the buffer hasn't been created yet, or we have one that isn't big |
| 983 // enough to fit |size| bytes. | 982 // enough to fit |size| bytes. |
| 984 | 983 |
| 985 // Media resource size starts from |kMinimumMediaBufferSize| and grows | 984 // Media resource size starts from |kMinimumMediaBufferSize| and grows |
| 986 // exponentially to avoid frequent re-allocation of PPB_Buffer_Impl, | 985 // exponentially to avoid frequent re-allocation of PPB_Buffer_Impl, |
| 987 // which is usually expensive. Since input media buffers are compressed, | 986 // which is usually expensive. Since input media buffers are compressed, |
| 988 // they are usually small (compared to outputs). The over-allocated memory | 987 // they are usually small (compared to outputs). The over-allocated memory |
| 989 // should be negligible. | 988 // should be negligible. |
| 990 const uint32_t kMinimumMediaBufferSize = 1024; | 989 const uint32_t kMinimumMediaBufferSize = 1024; |
| 991 uint32_t media_resource_size = media_resource ? media_resource->size() : | 990 uint32_t media_resource_size = |
| 992 kMinimumMediaBufferSize; | 991 media_resource.get() ? media_resource->size() : kMinimumMediaBufferSize; |
| 993 while (media_resource_size < data_size) | 992 while (media_resource_size < data_size) |
| 994 media_resource_size *= 2; | 993 media_resource_size *= 2; |
| 995 | 994 |
| 996 DVLOG(2) << "Size of media buffer for " | 995 DVLOG(2) << "Size of media buffer for " |
| 997 << ((stream_type == media::Decryptor::kAudio) ? "audio" : "video") | 996 << ((stream_type == media::Decryptor::kAudio) ? "audio" : "video") |
| 998 << " stream bumped to " << media_resource_size | 997 << " stream bumped to " << media_resource_size |
| 999 << " bytes to fit input."; | 998 << " bytes to fit input."; |
| 1000 media_resource = PPB_Buffer_Impl::CreateResource(pp_instance_, | 999 media_resource = PPB_Buffer_Impl::CreateResource(pp_instance_, |
| 1001 media_resource_size); | 1000 media_resource_size); |
| 1002 if (!media_resource) | 1001 if (!media_resource.get()) |
| 1003 return false; | 1002 return false; |
| 1004 } | 1003 } |
| 1005 | 1004 |
| 1006 BufferAutoMapper mapper(media_resource); | 1005 BufferAutoMapper mapper(media_resource.get()); |
| 1007 if (!mapper.data() || mapper.size() < data_size) { | 1006 if (!mapper.data() || mapper.size() < data_size) { |
| 1008 media_resource = NULL; | 1007 media_resource = NULL; |
| 1009 return false; | 1008 return false; |
| 1010 } | 1009 } |
| 1011 memcpy(mapper.data(), encrypted_buffer->GetData(), data_size); | 1010 memcpy(mapper.data(), encrypted_buffer->GetData(), data_size); |
| 1012 | 1011 |
| 1013 *resource = media_resource; | 1012 *resource = media_resource; |
| 1014 return true; | 1013 return true; |
| 1015 } | 1014 } |
| 1016 | 1015 |
| 1017 void ContentDecryptorDelegate::FreeBuffer(uint32_t buffer_id) { | 1016 void ContentDecryptorDelegate::FreeBuffer(uint32_t buffer_id) { |
| 1018 if (buffer_id) | 1017 if (buffer_id) |
| 1019 free_buffers_.push(buffer_id); | 1018 free_buffers_.push(buffer_id); |
| 1020 } | 1019 } |
| 1021 | 1020 |
| 1022 void ContentDecryptorDelegate::SetBufferToFreeInTrackingInfo( | 1021 void ContentDecryptorDelegate::SetBufferToFreeInTrackingInfo( |
| 1023 PP_DecryptTrackingInfo* tracking_info) { | 1022 PP_DecryptTrackingInfo* tracking_info) { |
| 1024 DCHECK_EQ(tracking_info->buffer_id, 0u); | 1023 DCHECK_EQ(tracking_info->buffer_id, 0u); |
| 1025 | 1024 |
| 1026 if (free_buffers_.empty()) | 1025 if (free_buffers_.empty()) |
| 1027 return; | 1026 return; |
| 1028 | 1027 |
| 1029 tracking_info->buffer_id = free_buffers_.front(); | 1028 tracking_info->buffer_id = free_buffers_.front(); |
| 1030 free_buffers_.pop(); | 1029 free_buffers_.pop(); |
| 1031 } | 1030 } |
| 1032 | 1031 |
| 1033 } // namespace ppapi | 1032 } // namespace ppapi |
| 1034 } // namespace webkit | 1033 } // namespace webkit |
| OLD | NEW |