Chromium Code Reviews| 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/gpu/rtc_video_encoder.h" | 5 #include "content/renderer/media/gpu/rtc_video_encoder.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include <deque> | 9 #include <deque> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 613 ->getMediaVideoFrame(); | 613 ->getMediaVideoFrame(); |
| 614 requires_copy = RequiresSizeChange(frame) || | 614 requires_copy = RequiresSizeChange(frame) || |
| 615 frame->storage_type() != media::VideoFrame::STORAGE_SHMEM; | 615 frame->storage_type() != media::VideoFrame::STORAGE_SHMEM; |
| 616 } else { | 616 } else { |
| 617 requires_copy = true; | 617 requires_copy = true; |
| 618 } | 618 } |
| 619 | 619 |
| 620 if (requires_copy) { | 620 if (requires_copy) { |
| 621 const base::TimeDelta timestamp = | 621 const base::TimeDelta timestamp = |
| 622 frame ? frame->timestamp() | 622 frame ? frame->timestamp() |
| 623 : base::TimeDelta::FromMilliseconds(next_frame->ntp_time_ms()); | 623 : base::TimeDelta::FromMilliseconds(next_frame->ntp_time_ms()); |
|
emircan
2017/06/12 20:06:16
We were hitting DCHECK before because next_frame->
magjed_chromium
2017/06/12 20:28:13
Can we land this CL to fix the immediate issues an
nisse-chromium (ooo August 14)
2017/06/13 08:06:44
I don't quite understand the context here, but in
| |
| 624 base::SharedMemory* input_buffer = input_buffers_[index].get(); | 624 base::SharedMemory* input_buffer = input_buffers_[index].get(); |
| 625 frame = media::VideoFrame::WrapExternalSharedMemory( | 625 frame = media::VideoFrame::WrapExternalSharedMemory( |
| 626 media::PIXEL_FORMAT_I420, input_frame_coded_size_, | 626 media::PIXEL_FORMAT_I420, input_frame_coded_size_, |
| 627 gfx::Rect(input_visible_size_), input_visible_size_, | 627 gfx::Rect(input_visible_size_), input_visible_size_, |
| 628 reinterpret_cast<uint8_t*>(input_buffer->memory()), | 628 reinterpret_cast<uint8_t*>(input_buffer->memory()), |
| 629 input_buffer->mapped_size(), input_buffer->handle(), 0, timestamp); | 629 input_buffer->mapped_size(), input_buffer->handle(), 0, timestamp); |
| 630 if (!frame.get()) { | 630 if (!frame.get()) { |
| 631 LogAndNotifyError(FROM_HERE, "failed to create frame", | 631 LogAndNotifyError(FROM_HERE, "failed to create frame", |
| 632 media::VideoEncodeAccelerator::kPlatformFailureError); | 632 media::VideoEncodeAccelerator::kPlatformFailureError); |
| 633 return; | 633 return; |
| 634 } | 634 } |
| 635 | 635 |
| 636 // Do a strided copy and scale (if necessary) the input frame to match | 636 // Do a strided copy and scale (if necessary) the input frame to match |
| 637 // the input requirements for the encoder. | 637 // the input requirements for the encoder. |
| 638 // TODO(sheu): Support zero-copy from WebRTC. http://crbug.com/269312 | 638 // TODO(sheu): Support zero-copy from WebRTC. http://crbug.com/269312 |
| 639 // TODO(magjed): Downscale with kFilterBox in an image pyramid instead. | 639 // TODO(magjed): Downscale with kFilterBox in an image pyramid instead. |
| 640 if (libyuv::I420Scale(next_frame->video_frame_buffer()->DataY(), | 640 rtc::scoped_refptr<webrtc::I420BufferInterface> i420_buffer = |
|
nisse-chromium (ooo August 14)
2017/06/13 08:06:44
Do we intend to change ToI420 to a const method? I
| |
| 641 next_frame->video_frame_buffer()->StrideY(), | 641 next_frame->video_frame_buffer()->ToI420(); |
| 642 next_frame->video_frame_buffer()->DataU(), | 642 if (libyuv::I420Scale(i420_buffer->DataY(), i420_buffer->StrideY(), |
| 643 next_frame->video_frame_buffer()->StrideU(), | 643 i420_buffer->DataU(), i420_buffer->StrideU(), |
| 644 next_frame->video_frame_buffer()->DataV(), | 644 i420_buffer->DataV(), i420_buffer->StrideV(), |
| 645 next_frame->video_frame_buffer()->StrideV(), | |
| 646 next_frame->width(), next_frame->height(), | 645 next_frame->width(), next_frame->height(), |
| 647 frame->visible_data(media::VideoFrame::kYPlane), | 646 frame->visible_data(media::VideoFrame::kYPlane), |
| 648 frame->stride(media::VideoFrame::kYPlane), | 647 frame->stride(media::VideoFrame::kYPlane), |
| 649 frame->visible_data(media::VideoFrame::kUPlane), | 648 frame->visible_data(media::VideoFrame::kUPlane), |
| 650 frame->stride(media::VideoFrame::kUPlane), | 649 frame->stride(media::VideoFrame::kUPlane), |
| 651 frame->visible_data(media::VideoFrame::kVPlane), | 650 frame->visible_data(media::VideoFrame::kVPlane), |
| 652 frame->stride(media::VideoFrame::kVPlane), | 651 frame->stride(media::VideoFrame::kVPlane), |
| 653 frame->visible_rect().width(), | 652 frame->visible_rect().width(), |
| 654 frame->visible_rect().height(), | 653 frame->visible_rect().height(), libyuv::kFilterBox)) { |
| 655 libyuv::kFilterBox)) { | |
| 656 LogAndNotifyError(FROM_HERE, "Failed to copy buffer", | 654 LogAndNotifyError(FROM_HERE, "Failed to copy buffer", |
| 657 media::VideoEncodeAccelerator::kPlatformFailureError); | 655 media::VideoEncodeAccelerator::kPlatformFailureError); |
| 658 return; | 656 return; |
| 659 } | 657 } |
| 660 } | 658 } |
| 661 frame->AddDestructionObserver(media::BindToCurrentLoop( | 659 frame->AddDestructionObserver(media::BindToCurrentLoop( |
| 662 base::Bind(&RTCVideoEncoder::Impl::EncodeFrameFinished, this, index))); | 660 base::Bind(&RTCVideoEncoder::Impl::EncodeFrameFinished, this, index))); |
| 663 if (!failed_timestamp_match_) { | 661 if (!failed_timestamp_match_) { |
| 664 DCHECK(std::find_if(pending_timestamps_.begin(), pending_timestamps_.end(), | 662 DCHECK(std::find_if(pending_timestamps_.begin(), pending_timestamps_.end(), |
| 665 [&frame](const RTCTimestamps& entry) { | 663 [&frame](const RTCTimestamps& entry) { |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 926 | 924 |
| 927 gpu_task_runner_->PostTask( | 925 gpu_task_runner_->PostTask( |
| 928 FROM_HERE, | 926 FROM_HERE, |
| 929 base::Bind(&RTCVideoEncoder::Impl::RequestEncodingParametersChange, | 927 base::Bind(&RTCVideoEncoder::Impl::RequestEncodingParametersChange, |
| 930 impl_, | 928 impl_, |
| 931 new_bit_rate, | 929 new_bit_rate, |
| 932 frame_rate)); | 930 frame_rate)); |
| 933 return WEBRTC_VIDEO_CODEC_OK; | 931 return WEBRTC_VIDEO_CODEC_OK; |
| 934 } | 932 } |
| 935 | 933 |
| 934 bool RTCVideoEncoder::SupportsNativeHandle() const { | |
| 935 return true; | |
| 936 } | |
| 937 | |
| 936 void RTCVideoEncoder::RecordInitEncodeUMA( | 938 void RTCVideoEncoder::RecordInitEncodeUMA( |
| 937 int32_t init_retval, media::VideoCodecProfile profile) { | 939 int32_t init_retval, media::VideoCodecProfile profile) { |
| 938 UMA_HISTOGRAM_BOOLEAN("Media.RTCVideoEncoderInitEncodeSuccess", | 940 UMA_HISTOGRAM_BOOLEAN("Media.RTCVideoEncoderInitEncodeSuccess", |
| 939 init_retval == WEBRTC_VIDEO_CODEC_OK); | 941 init_retval == WEBRTC_VIDEO_CODEC_OK); |
| 940 if (init_retval == WEBRTC_VIDEO_CODEC_OK) { | 942 if (init_retval == WEBRTC_VIDEO_CODEC_OK) { |
| 941 UMA_HISTOGRAM_ENUMERATION("Media.RTCVideoEncoderProfile", | 943 UMA_HISTOGRAM_ENUMERATION("Media.RTCVideoEncoderProfile", |
| 942 profile, | 944 profile, |
| 943 media::VIDEO_CODEC_PROFILE_MAX + 1); | 945 media::VIDEO_CODEC_PROFILE_MAX + 1); |
| 944 } | 946 } |
| 945 } | 947 } |
| 946 | 948 |
| 947 } // namespace content | 949 } // namespace content |
| OLD | NEW |