Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(736)

Unified Diff: remoting/protocol/webrtc_video_capturer_adapter.cc

Issue 1821153003: Avoid using MakeExclusive, which is going to be deleted in webrtc. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Sergey's comments. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/protocol/webrtc_video_capturer_adapter.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/protocol/webrtc_video_capturer_adapter.cc
diff --git a/remoting/protocol/webrtc_video_capturer_adapter.cc b/remoting/protocol/webrtc_video_capturer_adapter.cc
index c0aeea1a193fe1cca5953777784155ef47c3e01c..e276dd2b7171f01260368f93374dd8ccd17d506b 100644
--- a/remoting/protocol/webrtc_video_capturer_adapter.cc
+++ b/remoting/protocol/webrtc_video_capturer_adapter.cc
@@ -172,29 +172,26 @@ void WebrtcVideoCapturerAdapter::OnCaptureCompleted(
// WebRTC needs to have some mechanism to notify when the bandwidth is
// exceeded, so the capturer can adapt frame rate.
- size_t width = frame->size().width();
- size_t height = frame->size().height();
- if (!yuv_frame_ || yuv_frame_->GetWidth() != width ||
- yuv_frame_->GetHeight() != height) {
+ int width = frame->size().width();
+ int height = frame->size().height();
+ if (!yuv_frame_ ||
+ yuv_frame_->width() != width || yuv_frame_->height() != height) {
if (!size_callback_.is_null())
size_callback_.Run(frame->size());
- scoped_ptr<cricket::WebRtcVideoFrame> webrtc_frame(
- new cricket::WebRtcVideoFrame());
- webrtc_frame->InitToEmptyBuffer(width, height, 0);
- yuv_frame_ = std::move(webrtc_frame);
-
+ yuv_frame_ = new rtc::RefCountedObject<webrtc::I420Buffer>(width, height);
// Set updated_region so the whole frame is converted to YUV below.
frame->mutable_updated_region()->SetRect(
webrtc::DesktopRect::MakeWH(width, height));
}
- // TODO(sergeyu): This will copy the buffer if it's being used. Optimize it by
- // keeping a queue of frames.
- CHECK(yuv_frame_->MakeExclusive());
-
- yuv_frame_->SetTimeStamp(base::TimeTicks::Now().ToInternalValue() *
- base::Time::kNanosecondsPerMicrosecond);
+ if (!yuv_frame_->HasOneRef()) {
+ // Frame is still used, typically by the encoder. We have to make
+ // a copy before modifying it.
+ // TODO(sergeyu): This will copy the buffer if it's being used.
+ // Optimize it by keeping a queue of frames.
+ yuv_frame_ = yuv_frame_->Copy();
+ }
for (webrtc::DesktopRegion::Iterator i(frame->updated_region()); !i.IsAtEnd();
i.Advance()) {
@@ -211,19 +208,33 @@ void WebrtcVideoCapturerAdapter::OnCaptureCompleted(
--top;
++height;
}
+
+ int y_stride = yuv_frame_->stride(webrtc::kYPlane);
+ int u_stride = yuv_frame_->stride(webrtc::kUPlane);
+ int v_stride = yuv_frame_->stride(webrtc::kVPlane);
libyuv::ARGBToI420(
frame->data() + frame->stride() * top +
left * webrtc::DesktopFrame::kBytesPerPixel,
frame->stride(),
- yuv_frame_->GetYPlane() + yuv_frame_->GetYPitch() * top + left,
- yuv_frame_->GetYPitch(),
- yuv_frame_->GetUPlane() + yuv_frame_->GetUPitch() * top / 2 + left / 2,
- yuv_frame_->GetUPitch(),
- yuv_frame_->GetVPlane() + yuv_frame_->GetVPitch() * top / 2 + left / 2,
- yuv_frame_->GetVPitch(), width, height);
+ yuv_frame_->MutableData(webrtc::kYPlane) +
+ y_stride * top + left,
Sergey Ulanov 2016/03/24 18:15:19 Please run clang-format for this change (git cl fo
nisse-chromium (ooo August 14) 2016/03/30 13:15:50 Done.
+ y_stride,
+ yuv_frame_->MutableData(webrtc::kUPlane) +
+ u_stride * top / 2 + left / 2,
+ u_stride,
+ yuv_frame_->MutableData(webrtc::kVPlane) +
+ v_stride * top / 2 + left / 2,
+ v_stride,
+ width, height);
}
- SignalVideoFrame(this, yuv_frame_.get());
+ scoped_ptr<cricket::VideoFrame> video_frame(new cricket::WebRtcVideoFrame(
Sergey Ulanov 2016/03/24 18:15:19 nit: the frame can be allocated on the stack inste
nisse-chromium (ooo August 14) 2016/03/30 13:15:50 Done.
+ yuv_frame_,
+ (base::TimeTicks::Now() - base::TimeTicks()) /
+ base::TimeDelta::FromMicroseconds(1),
+ webrtc::kVideoRotation_0));
+
+ SignalVideoFrame(this, video_frame.get());
}
void WebrtcVideoCapturerAdapter::CaptureNextFrame() {
« no previous file with comments | « remoting/protocol/webrtc_video_capturer_adapter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698