| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/renderer/media/rtc_video_decoder.h" | 5 #include "content/renderer/media/rtc_video_decoder.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
| 11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "base/safe_numerics.h" | 12 #include "base/safe_numerics.h" |
| 13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 14 #include "base/task_runner_util.h" | 14 #include "base/task_runner_util.h" |
| 15 #include "content/child/child_thread.h" | 15 #include "content/child/child_thread.h" |
| 16 #include "content/renderer/media/native_handle_impl.h" | 16 #include "content/renderer/media/native_handle_impl.h" |
| 17 #include "gpu/command_buffer/common/mailbox_holder.h" |
| 17 #include "media/base/bind_to_loop.h" | 18 #include "media/base/bind_to_loop.h" |
| 18 #include "media/filters/gpu_video_accelerator_factories.h" | 19 #include "media/filters/gpu_video_accelerator_factories.h" |
| 19 #include "third_party/webrtc/common_video/interface/texture_video_frame.h" | 20 #include "third_party/webrtc/common_video/interface/texture_video_frame.h" |
| 20 #include "third_party/webrtc/system_wrappers/interface/ref_count.h" | 21 #include "third_party/webrtc/system_wrappers/interface/ref_count.h" |
| 21 | 22 |
| 22 namespace content { | 23 namespace content { |
| 23 | 24 |
| 24 const int32 RTCVideoDecoder::ID_LAST = 0x3FFFFFFF; | 25 const int32 RTCVideoDecoder::ID_LAST = 0x3FFFFFFF; |
| 25 const int32 RTCVideoDecoder::ID_HALF = 0x20000000; | 26 const int32 RTCVideoDecoder::ID_HALF = 0x20000000; |
| 26 const int32 RTCVideoDecoder::ID_INVALID = -1; | 27 const int32 RTCVideoDecoder::ID_INVALID = -1; |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 uint32_t width, | 414 uint32_t width, |
| 414 uint32_t height, | 415 uint32_t height, |
| 415 size_t size) { | 416 size_t size) { |
| 416 gfx::Rect visible_rect(width, height); | 417 gfx::Rect visible_rect(width, height); |
| 417 gfx::Size natural_size(width, height); | 418 gfx::Size natural_size(width, height); |
| 418 DCHECK(decoder_texture_target_); | 419 DCHECK(decoder_texture_target_); |
| 419 // Convert timestamp from 90KHz to ms. | 420 // Convert timestamp from 90KHz to ms. |
| 420 base::TimeDelta timestamp_ms = base::TimeDelta::FromInternalValue( | 421 base::TimeDelta timestamp_ms = base::TimeDelta::FromInternalValue( |
| 421 base::checked_numeric_cast<uint64_t>(timestamp) * 1000 / 90); | 422 base::checked_numeric_cast<uint64_t>(timestamp) * 1000 / 90); |
| 422 return media::VideoFrame::WrapNativeTexture( | 423 return media::VideoFrame::WrapNativeTexture( |
| 423 make_scoped_ptr(new media::VideoFrame::MailboxHolder( | 424 make_scoped_ptr(new gpu::MailboxHolder( |
| 424 pb.texture_mailbox(), | 425 pb.texture_mailbox(), decoder_texture_target_, 0)), |
| 425 0, // sync_point | 426 media::BindToCurrentLoop(base::Bind(&RTCVideoDecoder::ReusePictureBuffer, |
| 426 media::BindToCurrentLoop( | 427 weak_this_, |
| 427 base::Bind(&RTCVideoDecoder::ReusePictureBuffer, | 428 picture.picture_buffer_id())), |
| 428 weak_this_, | |
| 429 picture.picture_buffer_id())))), | |
| 430 decoder_texture_target_, | |
| 431 pb.size(), | 429 pb.size(), |
| 432 visible_rect, | 430 visible_rect, |
| 433 natural_size, | 431 natural_size, |
| 434 timestamp_ms, | 432 timestamp_ms, |
| 435 base::Bind(&media::GpuVideoAcceleratorFactories::ReadPixels, | 433 base::Bind(&media::GpuVideoAcceleratorFactories::ReadPixels, |
| 436 factories_, | 434 factories_, |
| 437 pb.texture_id(), | 435 pb.texture_id(), |
| 438 natural_size), | 436 natural_size)); |
| 439 base::Closure()); | |
| 440 } | 437 } |
| 441 | 438 |
| 442 void RTCVideoDecoder::NotifyEndOfBitstreamBuffer(int32 id) { | 439 void RTCVideoDecoder::NotifyEndOfBitstreamBuffer(int32 id) { |
| 443 DVLOG(3) << "NotifyEndOfBitstreamBuffer. id=" << id; | 440 DVLOG(3) << "NotifyEndOfBitstreamBuffer. id=" << id; |
| 444 DCHECK(vda_task_runner_->BelongsToCurrentThread()); | 441 DCHECK(vda_task_runner_->BelongsToCurrentThread()); |
| 445 | 442 |
| 446 std::map<int32, SHMBuffer*>::iterator it = | 443 std::map<int32, SHMBuffer*>::iterator it = |
| 447 bitstream_buffers_in_decoder_.find(id); | 444 bitstream_buffers_in_decoder_.find(id); |
| 448 if (it == bitstream_buffers_in_decoder_.end()) { | 445 if (it == bitstream_buffers_in_decoder_.end()) { |
| 449 NotifyError(media::VideoDecodeAccelerator::PLATFORM_FAILURE); | 446 NotifyError(media::VideoDecodeAccelerator::PLATFORM_FAILURE); |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 633 } | 630 } |
| 634 } | 631 } |
| 635 | 632 |
| 636 void RTCVideoDecoder::ResetInternal() { | 633 void RTCVideoDecoder::ResetInternal() { |
| 637 DCHECK(vda_task_runner_->BelongsToCurrentThread()); | 634 DCHECK(vda_task_runner_->BelongsToCurrentThread()); |
| 638 DVLOG(2) << "ResetInternal"; | 635 DVLOG(2) << "ResetInternal"; |
| 639 if (vda_) | 636 if (vda_) |
| 640 vda_->Reset(); | 637 vda_->Reset(); |
| 641 } | 638 } |
| 642 | 639 |
| 643 void RTCVideoDecoder::ReusePictureBuffer(int64 picture_buffer_id, | 640 void RTCVideoDecoder::ReusePictureBuffer( |
| 644 uint32 sync_point) { | 641 int64 picture_buffer_id, |
| 642 const gpu::MailboxHolder* mailbox_holder) { |
| 645 DCHECK(vda_task_runner_->BelongsToCurrentThread()); | 643 DCHECK(vda_task_runner_->BelongsToCurrentThread()); |
| 646 DVLOG(3) << "ReusePictureBuffer. id=" << picture_buffer_id; | 644 DVLOG(3) << "ReusePictureBuffer. id=" << picture_buffer_id; |
| 647 | 645 |
| 648 if (!vda_) | 646 if (!vda_) |
| 649 return; | 647 return; |
| 650 | 648 |
| 651 CHECK(!picture_buffers_at_display_.empty()); | 649 CHECK(!picture_buffers_at_display_.empty()); |
| 652 | 650 |
| 653 size_t num_erased = picture_buffers_at_display_.erase(picture_buffer_id); | 651 size_t num_erased = picture_buffers_at_display_.erase(picture_buffer_id); |
| 654 DCHECK(num_erased); | 652 DCHECK(num_erased); |
| 655 | 653 |
| 656 std::map<int32, media::PictureBuffer>::iterator it = | 654 std::map<int32, media::PictureBuffer>::iterator it = |
| 657 assigned_picture_buffers_.find(picture_buffer_id); | 655 assigned_picture_buffers_.find(picture_buffer_id); |
| 658 | 656 |
| 659 if (it == assigned_picture_buffers_.end()) { | 657 if (it == assigned_picture_buffers_.end()) { |
| 660 // This picture was dismissed while in display, so we postponed deletion. | 658 // This picture was dismissed while in display, so we postponed deletion. |
| 661 it = dismissed_picture_buffers_.find(picture_buffer_id); | 659 it = dismissed_picture_buffers_.find(picture_buffer_id); |
| 662 DCHECK(it != dismissed_picture_buffers_.end()); | 660 DCHECK(it != dismissed_picture_buffers_.end()); |
| 663 factories_->DeleteTexture(it->second.texture_id()); | 661 factories_->DeleteTexture(it->second.texture_id()); |
| 664 dismissed_picture_buffers_.erase(it); | 662 dismissed_picture_buffers_.erase(it); |
| 665 return; | 663 return; |
| 666 } | 664 } |
| 667 | 665 |
| 668 factories_->WaitSyncPoint(sync_point); | 666 factories_->WaitSyncPoint(mailbox_holder->sync_point); |
| 669 | 667 |
| 670 vda_->ReusePictureBuffer(picture_buffer_id); | 668 vda_->ReusePictureBuffer(picture_buffer_id); |
| 671 } | 669 } |
| 672 | 670 |
| 673 void RTCVideoDecoder::DestroyTextures() { | 671 void RTCVideoDecoder::DestroyTextures() { |
| 674 DCHECK(vda_task_runner_->BelongsToCurrentThread()); | 672 DCHECK(vda_task_runner_->BelongsToCurrentThread()); |
| 675 std::map<int32, media::PictureBuffer>::iterator it; | 673 std::map<int32, media::PictureBuffer>::iterator it; |
| 676 | 674 |
| 677 for (it = assigned_picture_buffers_.begin(); | 675 for (it = assigned_picture_buffers_.begin(); |
| 678 it != assigned_picture_buffers_.end(); | 676 it != assigned_picture_buffers_.end(); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 778 | 776 |
| 779 int32_t RTCVideoDecoder::RecordInitDecodeUMA(int32_t status) { | 777 int32_t RTCVideoDecoder::RecordInitDecodeUMA(int32_t status) { |
| 780 // Logging boolean is enough to know if HW decoding has been used. Also, | 778 // Logging boolean is enough to know if HW decoding has been used. Also, |
| 781 // InitDecode is less likely to return an error so enum is not used here. | 779 // InitDecode is less likely to return an error so enum is not used here. |
| 782 bool sample = (status == WEBRTC_VIDEO_CODEC_OK) ? true : false; | 780 bool sample = (status == WEBRTC_VIDEO_CODEC_OK) ? true : false; |
| 783 UMA_HISTOGRAM_BOOLEAN("Media.RTCVideoDecoderInitDecodeSuccess", sample); | 781 UMA_HISTOGRAM_BOOLEAN("Media.RTCVideoDecoderInitDecodeSuccess", sample); |
| 784 return status; | 782 return status; |
| 785 } | 783 } |
| 786 | 784 |
| 787 } // namespace content | 785 } // namespace content |
| OLD | NEW |