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

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

Issue 2922013002: Update constraints processing for video content capture. (Closed)
Patch Set: Rebase Created 3 years, 6 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 | « content/renderer/media/media_stream_video_track.cc ('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 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> 7 #include <algorithm>
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 10
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 261
262 MediaStreamVideoWebRtcSink::MediaStreamVideoWebRtcSink( 262 MediaStreamVideoWebRtcSink::MediaStreamVideoWebRtcSink(
263 const blink::WebMediaStreamTrack& track, 263 const blink::WebMediaStreamTrack& track,
264 PeerConnectionDependencyFactory* factory) 264 PeerConnectionDependencyFactory* factory)
265 : weak_factory_(this) { 265 : weak_factory_(this) {
266 MediaStreamVideoTrack* video_track = 266 MediaStreamVideoTrack* video_track =
267 MediaStreamVideoTrack::GetVideoTrack(track); 267 MediaStreamVideoTrack::GetVideoTrack(track);
268 DCHECK(video_track); 268 DCHECK(video_track);
269 rtc::Optional<bool> needs_denoising; 269 rtc::Optional<bool> needs_denoising;
270 bool is_screencast = false; 270 bool is_screencast = false;
271 double min_frame_rate = 0.0; 271 base::Optional<double> min_frame_rate;
272 double max_frame_rate = 0.0; 272 base::Optional<double> max_frame_rate;
273 273
274 if (IsOldVideoConstraints()) { 274 if (IsOldVideoConstraints()) {
275 const blink::WebMediaConstraints& constraints = video_track->constraints(); 275 const blink::WebMediaConstraints& constraints = video_track->constraints();
276 276
277 // Check for presence of mediaStreamSource constraint. The value is ignored. 277 // Check for presence of mediaStreamSource constraint. The value is ignored.
278 std::string value; 278 std::string value;
279 is_screencast = GetConstraintValueAsString( 279 is_screencast = GetConstraintValueAsString(
280 constraints, &blink::WebMediaTrackConstraintSet::media_stream_source, 280 constraints, &blink::WebMediaTrackConstraintSet::media_stream_source,
281 &value); 281 &value);
282 282
283 // Extract denoising preference, if no value is set this currently falls 283 // Extract denoising preference, if no value is set this currently falls
284 // back to a codec-specific default inside webrtc, hence the tri-state of 284 // back to a codec-specific default inside webrtc, hence the tri-state of
285 // {on, off unset}. 285 // {on, off unset}.
286 // TODO(pbos): Add tests that make sure that googNoiseReduction has properly 286 // TODO(pbos): Add tests that make sure that googNoiseReduction has properly
287 // propagated from getUserMedia down to a VideoTrackSource. 287 // propagated from getUserMedia down to a VideoTrackSource.
288 bool denoising_value; 288 bool denoising_value;
289 if (GetConstraintValueAsBoolean( 289 if (GetConstraintValueAsBoolean(
290 constraints, 290 constraints,
291 &blink::WebMediaTrackConstraintSet::goog_noise_reduction, 291 &blink::WebMediaTrackConstraintSet::goog_noise_reduction,
292 &denoising_value)) { 292 &denoising_value)) {
293 needs_denoising = rtc::Optional<bool>(denoising_value); 293 needs_denoising = rtc::Optional<bool>(denoising_value);
294 } 294 }
295 GetConstraintMinAsDouble(constraints, 295 double frame_rate_value;
296 &blink::WebMediaTrackConstraintSet::frame_rate, 296 if (GetConstraintMinAsDouble(constraints,
297 &min_frame_rate); 297 &blink::WebMediaTrackConstraintSet::frame_rate,
298 GetConstraintMaxAsDouble(constraints, 298 &frame_rate_value) &&
299 &blink::WebMediaTrackConstraintSet::frame_rate, 299 frame_rate_value >= 0.0) {
300 &max_frame_rate); 300 min_frame_rate = frame_rate_value;
301 }
302 if (GetConstraintMaxAsDouble(constraints,
303 &blink::WebMediaTrackConstraintSet::frame_rate,
304 &frame_rate_value) &&
305 frame_rate_value >= 0.0) {
306 max_frame_rate = frame_rate_value;
307 }
301 } else { 308 } else {
302 needs_denoising = ToRtcOptional(video_track->noise_reduction()); 309 needs_denoising = ToRtcOptional(video_track->noise_reduction());
303 is_screencast = video_track->is_screencast(); 310 is_screencast = video_track->is_screencast();
304 min_frame_rate = video_track->min_frame_rate(); 311 min_frame_rate = video_track->min_frame_rate();
305 max_frame_rate = video_track->adapter_settings().max_frame_rate; 312 max_frame_rate = video_track->max_frame_rate();
306 } 313 }
307 314
308 // Enable automatic frame refreshes for the screen capture sources, which will 315 // Enable automatic frame refreshes for the screen capture sources, which will
309 // stop producing frames whenever screen content is not changing. Check the 316 // stop producing frames whenever screen content is not changing. Check the
310 // frameRate constraint to determine the rate of refreshes. If a minimum 317 // frameRate constraint to determine the rate of refreshes. If a minimum
311 // frameRate is provided, use that. Otherwise, use the maximum frameRate if it 318 // frameRate is provided, use that. Otherwise, use the maximum frameRate if it
312 // happens to be less than the default. 319 // happens to be less than the default.
313 base::TimeDelta refresh_interval = base::TimeDelta::FromMicroseconds(0); 320 base::TimeDelta refresh_interval = base::TimeDelta::FromMicroseconds(0);
314 if (is_screencast) { 321 if (is_screencast) {
315 // Start with the default refresh interval, and refine based on constraints. 322 // Start with the default refresh interval, and refine based on constraints.
316 refresh_interval = 323 refresh_interval =
317 base::TimeDelta::FromMicroseconds(kDefaultRefreshIntervalMicros); 324 base::TimeDelta::FromMicroseconds(kDefaultRefreshIntervalMicros);
318 if (min_frame_rate > 0.0) { 325 if (min_frame_rate.has_value()) {
319 refresh_interval = 326 refresh_interval =
320 base::TimeDelta::FromMicroseconds(base::saturated_cast<int64_t>( 327 base::TimeDelta::FromMicroseconds(base::saturated_cast<int64_t>(
321 base::Time::kMicrosecondsPerSecond / min_frame_rate)); 328 base::Time::kMicrosecondsPerSecond / *min_frame_rate));
322 } 329 }
323 if (max_frame_rate > 0.0) { 330 if (max_frame_rate.has_value()) {
324 const base::TimeDelta alternate_refresh_interval = 331 const base::TimeDelta alternate_refresh_interval =
325 base::TimeDelta::FromMicroseconds(base::saturated_cast<int64_t>( 332 base::TimeDelta::FromMicroseconds(base::saturated_cast<int64_t>(
326 base::Time::kMicrosecondsPerSecond / max_frame_rate)); 333 base::Time::kMicrosecondsPerSecond / *max_frame_rate));
327 refresh_interval = std::max(refresh_interval, alternate_refresh_interval); 334 refresh_interval = std::max(refresh_interval, alternate_refresh_interval);
328 } 335 }
329 if (refresh_interval.InMicroseconds() < kLowerBoundRefreshIntervalMicros) { 336 if (refresh_interval.InMicroseconds() < kLowerBoundRefreshIntervalMicros) {
330 refresh_interval = 337 refresh_interval =
331 base::TimeDelta::FromMicroseconds(kLowerBoundRefreshIntervalMicros); 338 base::TimeDelta::FromMicroseconds(kLowerBoundRefreshIntervalMicros);
332 } 339 }
333 } 340 }
334 341
335 // TODO(pbos): Consolidate WebRtcVideoCapturerAdapter into WebRtcVideoSource 342 // TODO(pbos): Consolidate WebRtcVideoCapturerAdapter into WebRtcVideoSource
336 // by removing the need for and dependency on a cricket::VideoCapturer. 343 // by removing the need for and dependency on a cricket::VideoCapturer.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 DCHECK(thread_checker_.CalledOnValidThread()); 398 DCHECK(thread_checker_.CalledOnValidThread());
392 content::RequestRefreshFrameFromVideoTrack(connected_track()); 399 content::RequestRefreshFrameFromVideoTrack(connected_track());
393 } 400 }
394 401
395 rtc::Optional<bool> MediaStreamVideoWebRtcSink::SourceNeedsDenoisingForTesting() 402 rtc::Optional<bool> MediaStreamVideoWebRtcSink::SourceNeedsDenoisingForTesting()
396 const { 403 const {
397 return video_source_->needs_denoising(); 404 return video_source_->needs_denoising();
398 } 405 }
399 406
400 } // namespace content 407 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/media_stream_video_track.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698