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

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: Fixed to compile with latest webrtc. Created 4 years, 8 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
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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 return; 157 return;
158 158
159 scoped_ptr<webrtc::DesktopFrame> owned_frame(frame); 159 scoped_ptr<webrtc::DesktopFrame> owned_frame(frame);
160 160
161 // TODO(sergeyu): Currently the adapter keeps generating frames even when 161 // TODO(sergeyu): Currently the adapter keeps generating frames even when
162 // nothing is changing on the screen. This is necessary because the video 162 // nothing is changing on the screen. This is necessary because the video
163 // sender drops frames. Obviously this is a suboptimal. The sending code in 163 // sender drops frames. Obviously this is a suboptimal. The sending code in
164 // WebRTC needs to have some mechanism to notify when the bandwidth is 164 // WebRTC needs to have some mechanism to notify when the bandwidth is
165 // exceeded, so the capturer can adapt frame rate. 165 // exceeded, so the capturer can adapt frame rate.
166 166
167 size_t width = frame->size().width(); 167 int width = frame->size().width();
168 size_t height = frame->size().height(); 168 int height = frame->size().height();
169 if (!yuv_frame_ || yuv_frame_->GetWidth() != width || 169 if (!yuv_frame_ || yuv_frame_->width() != width ||
170 yuv_frame_->GetHeight() != height) { 170 yuv_frame_->height() != height) {
171 if (!size_callback_.is_null()) 171 if (!size_callback_.is_null())
172 size_callback_.Run(frame->size()); 172 size_callback_.Run(frame->size());
173 173
174 scoped_ptr<cricket::WebRtcVideoFrame> webrtc_frame( 174 yuv_frame_ = new rtc::RefCountedObject<webrtc::I420Buffer>(width, height);
175 new cricket::WebRtcVideoFrame());
176 webrtc_frame->InitToEmptyBuffer(width, height, 0);
177 yuv_frame_ = std::move(webrtc_frame);
178
179 // Set updated_region so the whole frame is converted to YUV below. 175 // Set updated_region so the whole frame is converted to YUV below.
180 frame->mutable_updated_region()->SetRect( 176 frame->mutable_updated_region()->SetRect(
181 webrtc::DesktopRect::MakeWH(width, height)); 177 webrtc::DesktopRect::MakeWH(width, height));
182 } 178 }
183 179
184 // TODO(sergeyu): This will copy the buffer if it's being used. Optimize it by 180 if (!yuv_frame_->HasOneRef()) {
185 // keeping a queue of frames. 181 // Frame is still used, typically by the encoder. We have to make
186 CHECK(yuv_frame_->MakeExclusive()); 182 // a copy before modifying it.
187 183 // TODO(sergeyu): This will copy the buffer if it's being used.
188 yuv_frame_->SetTimeStamp(base::TimeTicks::Now().ToInternalValue() * 184 // Optimize it by keeping a queue of frames.
189 base::Time::kNanosecondsPerMicrosecond); 185 yuv_frame_ = webrtc::I420Buffer::Copy(yuv_frame_);
186 }
190 187
191 for (webrtc::DesktopRegion::Iterator i(frame->updated_region()); !i.IsAtEnd(); 188 for (webrtc::DesktopRegion::Iterator i(frame->updated_region()); !i.IsAtEnd();
192 i.Advance()) { 189 i.Advance()) {
193 int left = i.rect().left(); 190 int left = i.rect().left();
194 int top = i.rect().top(); 191 int top = i.rect().top();
195 int width = i.rect().width(); 192 int width = i.rect().width();
196 int height = i.rect().height(); 193 int height = i.rect().height();
197 194
198 if (left % 2 == 1) { 195 if (left % 2 == 1) {
199 --left; 196 --left;
200 ++width; 197 ++width;
201 } 198 }
202 if (top % 2 == 1) { 199 if (top % 2 == 1) {
203 --top; 200 --top;
204 ++height; 201 ++height;
205 } 202 }
203
204 int y_stride = yuv_frame_->stride(webrtc::kYPlane);
205 int u_stride = yuv_frame_->stride(webrtc::kUPlane);
206 int v_stride = yuv_frame_->stride(webrtc::kVPlane);
206 libyuv::ARGBToI420( 207 libyuv::ARGBToI420(
207 frame->data() + frame->stride() * top + 208 frame->data() + frame->stride() * top +
208 left * webrtc::DesktopFrame::kBytesPerPixel, 209 left * webrtc::DesktopFrame::kBytesPerPixel,
209 frame->stride(), 210 frame->stride(),
210 yuv_frame_->GetYPlane() + yuv_frame_->GetYPitch() * top + left, 211 yuv_frame_->MutableData(webrtc::kYPlane) + y_stride * top + left,
211 yuv_frame_->GetYPitch(), 212 y_stride, yuv_frame_->MutableData(webrtc::kUPlane) +
212 yuv_frame_->GetUPlane() + yuv_frame_->GetUPitch() * top / 2 + left / 2, 213 u_stride * top / 2 + left / 2,
213 yuv_frame_->GetUPitch(), 214 u_stride, yuv_frame_->MutableData(webrtc::kVPlane) +
214 yuv_frame_->GetVPlane() + yuv_frame_->GetVPitch() * top / 2 + left / 2, 215 v_stride * top / 2 + left / 2,
215 yuv_frame_->GetVPitch(), width, height); 216 v_stride, width, height);
216 } 217 }
217 218
218 OnFrame(this, yuv_frame_.get()); 219 cricket::WebRtcVideoFrame video_frame(
220 yuv_frame_, (base::TimeTicks::Now() - base::TimeTicks()) /
221 base::TimeDelta::FromMicroseconds(1),
222 webrtc::kVideoRotation_0);
223
224 OnFrame(this, &video_frame);
219 } 225 }
220 226
221 void WebrtcVideoCapturerAdapter::CaptureNextFrame() { 227 void WebrtcVideoCapturerAdapter::CaptureNextFrame() {
222 DCHECK(thread_checker_.CalledOnValidThread()); 228 DCHECK(thread_checker_.CalledOnValidThread());
223 229
224 if (capture_pending_) 230 if (capture_pending_)
225 return; 231 return;
226 capture_pending_ = true; 232 capture_pending_ = true;
227 desktop_capturer_->Capture(webrtc::DesktopRegion()); 233 desktop_capturer_->Capture(webrtc::DesktopRegion());
228 } 234 }
229 235
230 } // namespace protocol 236 } // namespace protocol
231 } // namespace remoting 237 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698