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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « remoting/protocol/webrtc_video_capturer_adapter.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "remoting/protocol/webrtc_video_capturer_adapter.h" 5 #include "remoting/protocol/webrtc_video_capturer_adapter.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "third_party/libyuv/include/libyuv/convert.h" 9 #include "third_party/libyuv/include/libyuv/convert.h"
10 #include "third_party/webrtc/media/engine/webrtcvideoframe.h" 10 #include "third_party/webrtc/media/engine/webrtcvideoframe.h"
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 return; 165 return;
166 166
167 scoped_ptr<webrtc::DesktopFrame> owned_frame(frame); 167 scoped_ptr<webrtc::DesktopFrame> owned_frame(frame);
168 168
169 // TODO(sergeyu): Currently the adapter keeps generating frames even when 169 // TODO(sergeyu): Currently the adapter keeps generating frames even when
170 // nothing is changing on the screen. This is necessary because the video 170 // nothing is changing on the screen. This is necessary because the video
171 // sender drops frames. Obviously this is a suboptimal. The sending code in 171 // sender drops frames. Obviously this is a suboptimal. The sending code in
172 // WebRTC needs to have some mechanism to notify when the bandwidth is 172 // WebRTC needs to have some mechanism to notify when the bandwidth is
173 // exceeded, so the capturer can adapt frame rate. 173 // exceeded, so the capturer can adapt frame rate.
174 174
175 size_t width = frame->size().width(); 175 int width = frame->size().width();
176 size_t height = frame->size().height(); 176 int height = frame->size().height();
177 if (!yuv_frame_ || yuv_frame_->GetWidth() != width || 177 if (!yuv_frame_ ||
178 yuv_frame_->GetHeight() != height) { 178 yuv_frame_->width() != width || yuv_frame_->height() != height) {
179 if (!size_callback_.is_null()) 179 if (!size_callback_.is_null())
180 size_callback_.Run(frame->size()); 180 size_callback_.Run(frame->size());
181 181
182 scoped_ptr<cricket::WebRtcVideoFrame> webrtc_frame( 182 yuv_frame_ = new rtc::RefCountedObject<webrtc::I420Buffer>(width, height);
183 new cricket::WebRtcVideoFrame());
184 webrtc_frame->InitToEmptyBuffer(width, height, 0);
185 yuv_frame_ = std::move(webrtc_frame);
186
187 // Set updated_region so the whole frame is converted to YUV below. 183 // Set updated_region so the whole frame is converted to YUV below.
188 frame->mutable_updated_region()->SetRect( 184 frame->mutable_updated_region()->SetRect(
189 webrtc::DesktopRect::MakeWH(width, height)); 185 webrtc::DesktopRect::MakeWH(width, height));
190 } 186 }
191 187
192 // TODO(sergeyu): This will copy the buffer if it's being used. Optimize it by 188 if (!yuv_frame_->HasOneRef()) {
193 // keeping a queue of frames. 189 // Frame is still used, typically by the encoder. We have to make
194 CHECK(yuv_frame_->MakeExclusive()); 190 // a copy before modifying it.
195 191 // TODO(sergeyu): This will copy the buffer if it's being used.
196 yuv_frame_->SetTimeStamp(base::TimeTicks::Now().ToInternalValue() * 192 // Optimize it by keeping a queue of frames.
197 base::Time::kNanosecondsPerMicrosecond); 193 yuv_frame_ = yuv_frame_->Copy();
194 }
198 195
199 for (webrtc::DesktopRegion::Iterator i(frame->updated_region()); !i.IsAtEnd(); 196 for (webrtc::DesktopRegion::Iterator i(frame->updated_region()); !i.IsAtEnd();
200 i.Advance()) { 197 i.Advance()) {
201 int left = i.rect().left(); 198 int left = i.rect().left();
202 int top = i.rect().top(); 199 int top = i.rect().top();
203 int width = i.rect().width(); 200 int width = i.rect().width();
204 int height = i.rect().height(); 201 int height = i.rect().height();
205 202
206 if (left % 2 == 1) { 203 if (left % 2 == 1) {
207 --left; 204 --left;
208 ++width; 205 ++width;
209 } 206 }
210 if (top % 2 == 1) { 207 if (top % 2 == 1) {
211 --top; 208 --top;
212 ++height; 209 ++height;
213 } 210 }
211
212 int y_stride = yuv_frame_->stride(webrtc::kYPlane);
213 int u_stride = yuv_frame_->stride(webrtc::kUPlane);
214 int v_stride = yuv_frame_->stride(webrtc::kVPlane);
214 libyuv::ARGBToI420( 215 libyuv::ARGBToI420(
215 frame->data() + frame->stride() * top + 216 frame->data() + frame->stride() * top +
216 left * webrtc::DesktopFrame::kBytesPerPixel, 217 left * webrtc::DesktopFrame::kBytesPerPixel,
217 frame->stride(), 218 frame->stride(),
218 yuv_frame_->GetYPlane() + yuv_frame_->GetYPitch() * top + left, 219 yuv_frame_->MutableData(webrtc::kYPlane) +
219 yuv_frame_->GetYPitch(), 220 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.
220 yuv_frame_->GetUPlane() + yuv_frame_->GetUPitch() * top / 2 + left / 2, 221 y_stride,
221 yuv_frame_->GetUPitch(), 222 yuv_frame_->MutableData(webrtc::kUPlane) +
222 yuv_frame_->GetVPlane() + yuv_frame_->GetVPitch() * top / 2 + left / 2, 223 u_stride * top / 2 + left / 2,
223 yuv_frame_->GetVPitch(), width, height); 224 u_stride,
225 yuv_frame_->MutableData(webrtc::kVPlane) +
226 v_stride * top / 2 + left / 2,
227 v_stride,
228 width, height);
224 } 229 }
225 230
226 SignalVideoFrame(this, yuv_frame_.get()); 231 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.
232 yuv_frame_,
233 (base::TimeTicks::Now() - base::TimeTicks()) /
234 base::TimeDelta::FromMicroseconds(1),
235 webrtc::kVideoRotation_0));
236
237 SignalVideoFrame(this, video_frame.get());
227 } 238 }
228 239
229 void WebrtcVideoCapturerAdapter::CaptureNextFrame() { 240 void WebrtcVideoCapturerAdapter::CaptureNextFrame() {
230 DCHECK(thread_checker_.CalledOnValidThread()); 241 DCHECK(thread_checker_.CalledOnValidThread());
231 242
232 if (capture_pending_) 243 if (capture_pending_)
233 return; 244 return;
234 capture_pending_ = true; 245 capture_pending_ = true;
235 desktop_capturer_->Capture(webrtc::DesktopRegion()); 246 desktop_capturer_->Capture(webrtc::DesktopRegion());
236 } 247 }
237 248
238 } // namespace protocol 249 } // namespace protocol
239 } // namespace remoting 250 } // namespace remoting
OLDNEW
« 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