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

Side by Side Diff: content/renderer/media/webrtc/webrtc_video_capturer_adapter.cc

Issue 2585313002: Propagate MediaStreamTrack video content hints. (Closed)
Patch Set: add tests + fix compile Created 4 years 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/webrtc/webrtc_video_capturer_adapter.h" 5 #include "content/renderer/media/webrtc/webrtc_video_capturer_adapter.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/aligned_memory.h" 8 #include "base/memory/aligned_memory.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/synchronization/waitable_event.h" 10 #include "base/synchronization/waitable_event.h"
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 (*new_frame)->visible_rect().width(), 136 (*new_frame)->visible_rect().width(),
137 (*new_frame)->visible_rect().height(), libyuv::kRotate0, 137 (*new_frame)->visible_rect().height(), libyuv::kRotate0,
138 source_pixel_format); 138 source_pixel_format);
139 } 139 }
140 140
141 const scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; 141 const scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_;
142 scoped_refptr<ContextProviderCommandBuffer> provider_; 142 scoped_refptr<ContextProviderCommandBuffer> provider_;
143 std::unique_ptr<media::SkCanvasVideoRenderer> canvas_video_renderer_; 143 std::unique_ptr<media::SkCanvasVideoRenderer> canvas_video_renderer_;
144 }; 144 };
145 145
146 WebRtcVideoCapturerAdapter::WebRtcVideoCapturerAdapter(bool is_screencast) 146 WebRtcVideoCapturerAdapter::WebRtcVideoCapturerAdapter(
147 bool is_screencast,
148 blink::WebMediaStreamTrack::ContentHintType content_hint)
147 : texture_copier_(new WebRtcVideoCapturerAdapter::TextureFrameCopier()), 149 : texture_copier_(new WebRtcVideoCapturerAdapter::TextureFrameCopier()),
148 is_screencast_(is_screencast), 150 is_screencast_(is_screencast),
151 content_hint_(content_hint),
149 running_(false) { 152 running_(false) {
150 thread_checker_.DetachFromThread(); 153 thread_checker_.DetachFromThread();
151 } 154 }
152 155
153 WebRtcVideoCapturerAdapter::~WebRtcVideoCapturerAdapter() { 156 WebRtcVideoCapturerAdapter::~WebRtcVideoCapturerAdapter() {
154 DVLOG(3) << __func__; 157 DVLOG(3) << __func__;
155 } 158 }
156 159
157 void WebRtcVideoCapturerAdapter::OnFrameCaptured( 160 void WebRtcVideoCapturerAdapter::OnFrameCaptured(
158 const scoped_refptr<media::VideoFrame>& input_frame) { 161 const scoped_refptr<media::VideoFrame>& input_frame) {
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 bool WebRtcVideoCapturerAdapter::GetPreferredFourccs( 296 bool WebRtcVideoCapturerAdapter::GetPreferredFourccs(
294 std::vector<uint32_t>* fourccs) { 297 std::vector<uint32_t>* fourccs) {
295 DCHECK(thread_checker_.CalledOnValidThread()); 298 DCHECK(thread_checker_.CalledOnValidThread());
296 if (!fourccs) 299 if (!fourccs)
297 return false; 300 return false;
298 DCHECK(fourccs->empty()); 301 DCHECK(fourccs->empty());
299 fourccs->push_back(cricket::FOURCC_I420); 302 fourccs->push_back(cricket::FOURCC_I420);
300 return true; 303 return true;
301 } 304 }
302 305
306 void WebRtcVideoCapturerAdapter::SetContentHint(
307 blink::WebMediaStreamTrack::ContentHintType content_hint) {
308 DCHECK(thread_checker_.CalledOnValidThread());
309 content_hint_ = content_hint;
310 }
311
303 bool WebRtcVideoCapturerAdapter::IsScreencast() const { 312 bool WebRtcVideoCapturerAdapter::IsScreencast() const {
304 return is_screencast_; 313 return !ShouldAdaptResolution();
314 }
315
316 bool WebRtcVideoCapturerAdapter::ShouldAdaptResolution() const {
317 DCHECK(thread_checker_.CalledOnValidThread());
318 if (content_hint_ ==
319 blink::WebMediaStreamTrack::ContentHintType::VideoFluid) {
320 return true;
321 } else if (content_hint_ ==
mcasas 2016/12/19 19:32:05 nit: no need for else{} after if(){ return }
pbos 2016/12/19 19:42:09 Done.
322 blink::WebMediaStreamTrack::ContentHintType::VideoDetailed) {
323 return false;
324 }
325 // Screencast does not adapt by default.
326 return !is_screencast_;
305 } 327 }
306 328
307 bool WebRtcVideoCapturerAdapter::GetBestCaptureFormat( 329 bool WebRtcVideoCapturerAdapter::GetBestCaptureFormat(
308 const cricket::VideoFormat& desired, 330 const cricket::VideoFormat& desired,
309 cricket::VideoFormat* best_format) { 331 cricket::VideoFormat* best_format) {
310 DCHECK(thread_checker_.CalledOnValidThread()); 332 DCHECK(thread_checker_.CalledOnValidThread());
311 DVLOG(3) << __func__ << " desired: " << desired.ToString(); 333 DVLOG(3) << __func__ << " desired: " << desired.ToString();
312 334
313 // Capability enumeration is done in MediaStreamVideoSource. The adapter can 335 // Capability enumeration is done in MediaStreamVideoSource. The adapter can
314 // just use what is provided. 336 // just use what is provided.
315 // Use the desired format as the best format. 337 // Use the desired format as the best format.
316 best_format->width = desired.width; 338 best_format->width = desired.width;
317 best_format->height = desired.height; 339 best_format->height = desired.height;
318 best_format->fourcc = cricket::FOURCC_I420; 340 best_format->fourcc = cricket::FOURCC_I420;
319 best_format->interval = desired.interval; 341 best_format->interval = desired.interval;
320 return true; 342 return true;
321 } 343 }
322 344
323 } // namespace content 345 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698