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

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

Issue 2790823002: Spec compliant video constraints for getUserMedia behind flag. (Closed)
Patch Set: rebase Created 3 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 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/media_stream_video_webrtc_sink.h" 5 #include "content/renderer/media/webrtc/media_stream_video_webrtc_sink.h"
6 6
7 #include <algorithm>
8 #include <memory>
9 #include <string>
10
11 #include "base/feature_list.h"
7 #include "base/location.h" 12 #include "base/location.h"
8 #include "base/numerics/safe_conversions.h" 13 #include "base/numerics/safe_conversions.h"
9 #include "base/single_thread_task_runner.h" 14 #include "base/single_thread_task_runner.h"
10 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
11 #include "base/synchronization/lock.h" 16 #include "base/synchronization/lock.h"
12 #include "base/threading/thread_task_runner_handle.h" 17 #include "base/threading/thread_task_runner_handle.h"
13 #include "base/timer/timer.h" 18 #include "base/timer/timer.h"
14 #include "content/common/media/media_stream_options.h" 19 #include "content/common/media/media_stream_options.h"
20 #include "content/public/common/content_features.h"
15 #include "content/public/renderer/media_stream_utils.h" 21 #include "content/public/renderer/media_stream_utils.h"
16 #include "content/renderer/media/media_stream_constraints_util.h" 22 #include "content/renderer/media/media_stream_constraints_util.h"
17 #include "content/renderer/media/media_stream_video_track.h" 23 #include "content/renderer/media/media_stream_video_track.h"
18 #include "content/renderer/media/webrtc/peer_connection_dependency_factory.h" 24 #include "content/renderer/media/webrtc/peer_connection_dependency_factory.h"
19 #include "media/base/limits.h" 25 #include "media/base/limits.h"
20 #include "third_party/webrtc/api/videosourceproxy.h" 26 #include "third_party/webrtc/api/videosourceproxy.h"
21 #include "third_party/webrtc/api/videotracksource.h" 27 #include "third_party/webrtc/api/videotracksource.h"
22 28
23 namespace content { 29 namespace content {
24 30
31 namespace {
32
33 rtc::Optional<bool> ToRtcOptional(const base::Optional<bool>& value) {
34 return value ? rtc::Optional<bool>(*value) : rtc::Optional<bool>();
35 }
36
37 } // namespace
38
25 class MediaStreamVideoWebRtcSink::WebRtcVideoSource 39 class MediaStreamVideoWebRtcSink::WebRtcVideoSource
26 : public webrtc::VideoTrackSource { 40 : public webrtc::VideoTrackSource {
27 public: 41 public:
28 WebRtcVideoSource(WebRtcVideoCapturerAdapter* capture_adapter, 42 WebRtcVideoSource(WebRtcVideoCapturerAdapter* capture_adapter,
29 bool is_screencast, 43 bool is_screencast,
30 rtc::Optional<bool> needs_denoising) 44 rtc::Optional<bool> needs_denoising)
31 : VideoTrackSource(capture_adapter, false), 45 : VideoTrackSource(capture_adapter, false),
32 capture_adapter_(capture_adapter), 46 capture_adapter_(capture_adapter),
33 is_screencast_(is_screencast), 47 is_screencast_(is_screencast),
34 needs_denoising_(needs_denoising) {} 48 needs_denoising_(needs_denoising) {}
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 DCHECK(libjingle_worker_thread_->BelongsToCurrentThread()); 256 DCHECK(libjingle_worker_thread_->BelongsToCurrentThread());
243 base::AutoLock auto_lock(capture_adapter_stop_lock_); 257 base::AutoLock auto_lock(capture_adapter_stop_lock_);
244 if (capture_adapter_) 258 if (capture_adapter_)
245 capture_adapter_->OnFrameCaptured(frame); 259 capture_adapter_->OnFrameCaptured(frame);
246 } 260 }
247 261
248 MediaStreamVideoWebRtcSink::MediaStreamVideoWebRtcSink( 262 MediaStreamVideoWebRtcSink::MediaStreamVideoWebRtcSink(
249 const blink::WebMediaStreamTrack& track, 263 const blink::WebMediaStreamTrack& track,
250 PeerConnectionDependencyFactory* factory) 264 PeerConnectionDependencyFactory* factory)
251 : weak_factory_(this) { 265 : weak_factory_(this) {
252 DCHECK(MediaStreamVideoTrack::GetVideoTrack(track)); 266 MediaStreamVideoTrack* video_track =
253 const blink::WebMediaConstraints& constraints = 267 MediaStreamVideoTrack::GetVideoTrack(track);
254 MediaStreamVideoTrack::GetVideoTrack(track)->constraints(); 268 DCHECK(video_track);
269 rtc::Optional<bool> needs_denoising;
270 bool is_screencast = false;
271 double min_frame_rate = 0.0;
272 double max_frame_rate = 0.0;
255 273
256 // Check for presence of mediaStreamSource constraint. The value is ignored. 274 if (IsOldVideoConstraints()) {
257 std::string value; 275 const blink::WebMediaConstraints& constraints = video_track->constraints();
258 bool is_screencast = GetConstraintValueAsString(
259 constraints, &blink::WebMediaTrackConstraintSet::mediaStreamSource,
260 &value);
261 276
262 // Extract denoising preference, if no value is set this currently falls back 277 // Check for presence of mediaStreamSource constraint. The value is ignored.
263 // to a codec-specific default inside webrtc, hence the tri-state of {on, off 278 std::string value;
264 // unset}. 279 is_screencast = GetConstraintValueAsString(
265 // TODO(pbos): Add tests that make sure that googNoiseReduction has properly 280 constraints, &blink::WebMediaTrackConstraintSet::mediaStreamSource,
266 // propagated from getUserMedia down to a VideoTrackSource. 281 &value);
267 rtc::Optional<bool> needs_denoising; 282
268 bool denoising_value; 283 // Extract denoising preference, if no value is set this currently falls
269 if (GetConstraintValueAsBoolean( 284 // back to a codec-specific default inside webrtc, hence the tri-state of
270 constraints, &blink::WebMediaTrackConstraintSet::googNoiseReduction, 285 // {on, off unset}.
271 &denoising_value)) { 286 // TODO(pbos): Add tests that make sure that googNoiseReduction has properly
272 needs_denoising = rtc::Optional<bool>(denoising_value); 287 // propagated from getUserMedia down to a VideoTrackSource.
288 bool denoising_value;
289 if (GetConstraintValueAsBoolean(
290 constraints, &blink::WebMediaTrackConstraintSet::googNoiseReduction,
291 &denoising_value)) {
292 needs_denoising = rtc::Optional<bool>(denoising_value);
293 }
294 GetConstraintMinAsDouble(constraints,
295 &blink::WebMediaTrackConstraintSet::frameRate,
296 &min_frame_rate);
297 GetConstraintMaxAsDouble(constraints,
298 &blink::WebMediaTrackConstraintSet::frameRate,
299 &max_frame_rate);
300 } else {
301 needs_denoising = ToRtcOptional(video_track->noise_reduction());
302 is_screencast = video_track->is_screencast();
303 min_frame_rate = video_track->min_frame_rate();
304 max_frame_rate = video_track->adapter_settings().max_frame_rate;
273 } 305 }
274 306
275 // Enable automatic frame refreshes for the screen capture sources, which will 307 // Enable automatic frame refreshes for the screen capture sources, which will
276 // stop producing frames whenever screen content is not changing. Check the 308 // stop producing frames whenever screen content is not changing. Check the
277 // frameRate constraint to determine the rate of refreshes. If a minimum 309 // frameRate constraint to determine the rate of refreshes. If a minimum
278 // frameRate is provided, use that. Otherwise, use the maximum frameRate if it 310 // frameRate is provided, use that. Otherwise, use the maximum frameRate if it
279 // happens to be less than the default. 311 // happens to be less than the default.
280 base::TimeDelta refresh_interval = base::TimeDelta::FromMicroseconds(0); 312 base::TimeDelta refresh_interval = base::TimeDelta::FromMicroseconds(0);
281 if (is_screencast) { 313 if (is_screencast) {
282 // Start with the default refresh interval, and refine based on constraints. 314 // Start with the default refresh interval, and refine based on constraints.
283 refresh_interval = 315 refresh_interval =
284 base::TimeDelta::FromMicroseconds(kDefaultRefreshIntervalMicros); 316 base::TimeDelta::FromMicroseconds(kDefaultRefreshIntervalMicros);
285 double value = 0.0; 317 if (min_frame_rate > 0.0) {
286 if (GetConstraintMinAsDouble(
287 constraints, &blink::WebMediaTrackConstraintSet::frameRate,
288 &value) &&
289 value > 0.0) {
290 refresh_interval = 318 refresh_interval =
291 base::TimeDelta::FromMicroseconds(base::saturated_cast<int64_t>( 319 base::TimeDelta::FromMicroseconds(base::saturated_cast<int64_t>(
292 base::Time::kMicrosecondsPerSecond / value)); 320 base::Time::kMicrosecondsPerSecond / min_frame_rate));
293 } 321 }
294 if (GetConstraintMaxAsDouble( 322 if (max_frame_rate > 0.0) {
295 constraints, &blink::WebMediaTrackConstraintSet::frameRate,
296 &value) &&
297 value > 0.0) {
298 const base::TimeDelta alternate_refresh_interval = 323 const base::TimeDelta alternate_refresh_interval =
299 base::TimeDelta::FromMicroseconds(base::saturated_cast<int64_t>( 324 base::TimeDelta::FromMicroseconds(base::saturated_cast<int64_t>(
300 base::Time::kMicrosecondsPerSecond / value)); 325 base::Time::kMicrosecondsPerSecond / max_frame_rate));
301 refresh_interval = std::max(refresh_interval, alternate_refresh_interval); 326 refresh_interval = std::max(refresh_interval, alternate_refresh_interval);
302 } 327 }
303 if (refresh_interval.InMicroseconds() < kLowerBoundRefreshIntervalMicros) { 328 if (refresh_interval.InMicroseconds() < kLowerBoundRefreshIntervalMicros) {
304 refresh_interval = 329 refresh_interval =
305 base::TimeDelta::FromMicroseconds(kLowerBoundRefreshIntervalMicros); 330 base::TimeDelta::FromMicroseconds(kLowerBoundRefreshIntervalMicros);
306 } 331 }
307 } 332 }
308 333
309 // TODO(pbos): Consolidate WebRtcVideoCapturerAdapter into WebRtcVideoSource 334 // TODO(pbos): Consolidate WebRtcVideoCapturerAdapter into WebRtcVideoSource
310 // by removing the need for and dependency on a cricket::VideoCapturer. 335 // by removing the need for and dependency on a cricket::VideoCapturer.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 DCHECK(thread_checker_.CalledOnValidThread()); 390 DCHECK(thread_checker_.CalledOnValidThread());
366 content::RequestRefreshFrameFromVideoTrack(connected_track()); 391 content::RequestRefreshFrameFromVideoTrack(connected_track());
367 } 392 }
368 393
369 rtc::Optional<bool> MediaStreamVideoWebRtcSink::SourceNeedsDenoisingForTesting() 394 rtc::Optional<bool> MediaStreamVideoWebRtcSink::SourceNeedsDenoisingForTesting()
370 const { 395 const {
371 return video_source_->needs_denoising(); 396 return video_source_->needs_denoising();
372 } 397 }
373 398
374 } // namespace content 399 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698