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

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: 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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 size_t width = frame->size().width();
176 size_t height = frame->size().height(); 176 size_t height = frame->size().height();
Sergey Ulanov 2016/03/22 17:27:09 change these two to int then you wouldn't need the
nisse-chromium (ooo August 14) 2016/03/24 13:11:26 Done.
177 if (!yuv_frame_ || yuv_frame_->GetWidth() != width || 177 if (!yuv_frame_ || static_cast<size_t>(yuv_frame_->width()) != width ||
178 yuv_frame_->GetHeight() != height) { 178 static_cast<size_t>(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 // TODO(sergeyu): This will copy the buffer if it's being used. Optimize it by
perkj_chrome 2016/03/23 14:43:54 About this todo: Is the whole yuv_frame updated be
Sergey Ulanov 2016/03/23 23:46:43 The for loop below performs YUV conversion only fo
193 // keeping a queue of frames. 189 // keeping a queue of frames.
194 CHECK(yuv_frame_->MakeExclusive()); 190 if (!yuv_frame_->HasOneRef()) {
195 191 // Frame is still used, typically by the encoder. We have to make
Sergey Ulanov 2016/03/22 17:27:09 Please move this comment above the TODO or move th
nisse-chromium (ooo August 14) 2016/03/24 13:11:26 Done.
196 yuv_frame_->SetTimeStamp(base::TimeTicks::Now().ToInternalValue() * 192 // a copy before modifying it.
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 }
214 libyuv::ARGBToI420( 211 libyuv::ARGBToI420(
215 frame->data() + frame->stride() * top + 212 frame->data() + frame->stride() * top +
216 left * webrtc::DesktopFrame::kBytesPerPixel, 213 left * webrtc::DesktopFrame::kBytesPerPixel,
217 frame->stride(), 214 frame->stride(), yuv_frame_->MutableData(webrtc::kYPlane) +
218 yuv_frame_->GetYPlane() + yuv_frame_->GetYPitch() * top + left, 215 yuv_frame_->stride(webrtc::kYPlane) * top + left,
219 yuv_frame_->GetYPitch(), 216 yuv_frame_->stride(webrtc::kYPlane),
220 yuv_frame_->GetUPlane() + yuv_frame_->GetUPitch() * top / 2 + left / 2, 217 yuv_frame_->MutableData(webrtc::kUPlane) +
221 yuv_frame_->GetUPitch(), 218 yuv_frame_->stride(webrtc::kUPlane) * top / 2 + left / 2,
222 yuv_frame_->GetVPlane() + yuv_frame_->GetVPitch() * top / 2 + left / 2, 219 yuv_frame_->stride(webrtc::kUPlane),
223 yuv_frame_->GetVPitch(), width, height); 220 yuv_frame_->MutableData(webrtc::kVPlane) +
221 yuv_frame_->stride(webrtc::kVPlane) * top / 2 + left / 2,
222 yuv_frame_->stride(webrtc::kVPlane), width, height);
Sergey Ulanov 2016/03/22 17:27:09 nit: this ARGBToI420() call would be cleaner if yo
nisse-chromium (ooo August 14) 2016/03/24 13:11:26 Done.
224 } 223 }
225 224
226 SignalVideoFrame(this, yuv_frame_.get()); 225 scoped_ptr<cricket::VideoFrame> video_frame(new cricket::WebRtcVideoFrame(
226 yuv_frame_, base::TimeTicks::Now().ToInternalValue() *
Sergey Ulanov 2016/03/22 17:27:09 This is not a proper way to convert TimeTicks to m
nisse-chromium (ooo August 14) 2016/03/24 13:11:26 Done.
227 base::Time::kNanosecondsPerMicrosecond,
228 webrtc::kVideoRotation_0));
229
230 SignalVideoFrame(this, video_frame.get());
227 } 231 }
228 232
229 void WebrtcVideoCapturerAdapter::CaptureNextFrame() { 233 void WebrtcVideoCapturerAdapter::CaptureNextFrame() {
230 DCHECK(thread_checker_.CalledOnValidThread()); 234 DCHECK(thread_checker_.CalledOnValidThread());
231 235
232 if (capture_pending_) 236 if (capture_pending_)
233 return; 237 return;
234 capture_pending_ = true; 238 capture_pending_ = true;
235 desktop_capturer_->Capture(webrtc::DesktopRegion()); 239 desktop_capturer_->Capture(webrtc::DesktopRegion());
236 } 240 }
237 241
238 } // namespace protocol 242 } // namespace protocol
239 } // namespace remoting 243 } // 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