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

Side by Side Diff: content/renderer/media/media_stream_constraints_util_video_content.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
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/media_stream_constraints_util_video_content.h" 5 #include "content/renderer/media/media_stream_constraints_util_video_content.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 return BoolSet({constraint.Exact()}); 71 return BoolSet({constraint.Exact()});
72 } 72 }
73 73
74 using DoubleRangeSet = NumericRangeSet<double>; 74 using DoubleRangeSet = NumericRangeSet<double>;
75 75
76 class VideoContentCaptureCandidates { 76 class VideoContentCaptureCandidates {
77 public: 77 public:
78 VideoContentCaptureCandidates() 78 VideoContentCaptureCandidates()
79 : has_explicit_max_height_(false), 79 : has_explicit_max_height_(false),
80 has_explicit_max_width_(false), 80 has_explicit_max_width_(false),
81 has_explicit_min_frame_rate_(false),
81 has_explicit_max_frame_rate_(false), 82 has_explicit_max_frame_rate_(false),
82 device_id_set_(StringSet::UniversalSet()), 83 device_id_set_(StringSet::UniversalSet()),
83 noise_reduction_set_(BoolSet::UniversalSet()) {} 84 noise_reduction_set_(BoolSet::UniversalSet()) {}
84 explicit VideoContentCaptureCandidates( 85 explicit VideoContentCaptureCandidates(
85 const blink::WebMediaTrackConstraintSet& constraint_set) 86 const blink::WebMediaTrackConstraintSet& constraint_set)
86 : resolution_set_(ResolutionSet::FromConstraintSet(constraint_set)), 87 : resolution_set_(ResolutionSet::FromConstraintSet(constraint_set)),
87 has_explicit_max_height_(ConstraintHasMax(constraint_set.height) && 88 has_explicit_max_height_(ConstraintHasMax(constraint_set.height) &&
88 ConstraintMax(constraint_set.height) <= 89 ConstraintMax(constraint_set.height) <=
89 kMaxScreenCastDimension), 90 kMaxScreenCastDimension),
90 has_explicit_max_width_(ConstraintHasMax(constraint_set.width) && 91 has_explicit_max_width_(ConstraintHasMax(constraint_set.width) &&
91 ConstraintMax(constraint_set.width) <= 92 ConstraintMax(constraint_set.width) <=
92 kMaxScreenCastDimension), 93 kMaxScreenCastDimension),
93 frame_rate_set_( 94 frame_rate_set_(
94 DoubleRangeSet::FromConstraint(constraint_set.frame_rate)), 95 DoubleRangeSet::FromConstraint(constraint_set.frame_rate)),
96 has_explicit_min_frame_rate_(
97 ConstraintHasMin(constraint_set.frame_rate) &&
98 ConstraintMin(constraint_set.frame_rate) >= 0.0),
95 has_explicit_max_frame_rate_( 99 has_explicit_max_frame_rate_(
96 ConstraintHasMax(constraint_set.frame_rate) && 100 ConstraintHasMax(constraint_set.frame_rate) &&
97 ConstraintMax(constraint_set.frame_rate) <= 101 ConstraintMax(constraint_set.frame_rate) <=
98 kMaxScreenCastFrameRate), 102 kMaxScreenCastFrameRate),
99 device_id_set_(StringSetFromConstraint(constraint_set.device_id)), 103 device_id_set_(StringSetFromConstraint(constraint_set.device_id)),
100 noise_reduction_set_( 104 noise_reduction_set_(
101 BoolSetFromConstraint(constraint_set.goog_noise_reduction)) {} 105 BoolSetFromConstraint(constraint_set.goog_noise_reduction)) {}
102 106
103 VideoContentCaptureCandidates(VideoContentCaptureCandidates&& other) = 107 VideoContentCaptureCandidates(VideoContentCaptureCandidates&& other) =
104 default; 108 default;
105 VideoContentCaptureCandidates& operator=( 109 VideoContentCaptureCandidates& operator=(
106 VideoContentCaptureCandidates&& other) = default; 110 VideoContentCaptureCandidates&& other) = default;
107 111
108 bool IsEmpty() const { 112 bool IsEmpty() const {
109 return resolution_set_.IsEmpty() || frame_rate_set_.IsEmpty() || 113 return resolution_set_.IsEmpty() || frame_rate_set_.IsEmpty() ||
110 device_id_set_.IsEmpty() || noise_reduction_set_.IsEmpty(); 114 device_id_set_.IsEmpty() || noise_reduction_set_.IsEmpty();
111 } 115 }
112 116
113 VideoContentCaptureCandidates Intersection( 117 VideoContentCaptureCandidates Intersection(
114 const VideoContentCaptureCandidates& other) { 118 const VideoContentCaptureCandidates& other) {
115 VideoContentCaptureCandidates intersection; 119 VideoContentCaptureCandidates intersection;
116 intersection.resolution_set_ = 120 intersection.resolution_set_ =
117 resolution_set_.Intersection(other.resolution_set_); 121 resolution_set_.Intersection(other.resolution_set_);
118 intersection.has_explicit_max_height_ = 122 intersection.has_explicit_max_height_ =
119 has_explicit_max_height_ || other.has_explicit_max_height_; 123 has_explicit_max_height_ || other.has_explicit_max_height_;
120 intersection.has_explicit_max_width_ = 124 intersection.has_explicit_max_width_ =
121 has_explicit_max_width_ || other.has_explicit_max_width_; 125 has_explicit_max_width_ || other.has_explicit_max_width_;
122 intersection.frame_rate_set_ = 126 intersection.frame_rate_set_ =
123 frame_rate_set_.Intersection(other.frame_rate_set_); 127 frame_rate_set_.Intersection(other.frame_rate_set_);
128 intersection.has_explicit_min_frame_rate_ =
129 has_explicit_min_frame_rate_ || other.has_explicit_min_frame_rate_;
124 intersection.has_explicit_max_frame_rate_ = 130 intersection.has_explicit_max_frame_rate_ =
125 has_explicit_max_frame_rate_ || other.has_explicit_max_frame_rate_; 131 has_explicit_max_frame_rate_ || other.has_explicit_max_frame_rate_;
126 intersection.device_id_set_ = 132 intersection.device_id_set_ =
127 device_id_set_.Intersection(other.device_id_set_); 133 device_id_set_.Intersection(other.device_id_set_);
128 intersection.noise_reduction_set_ = 134 intersection.noise_reduction_set_ =
129 noise_reduction_set_.Intersection(other.noise_reduction_set_); 135 noise_reduction_set_.Intersection(other.noise_reduction_set_);
130 return intersection; 136 return intersection;
131 } 137 }
132 138
133 const ResolutionSet& resolution_set() const { return resolution_set_; } 139 const ResolutionSet& resolution_set() const { return resolution_set_; }
134 bool has_explicit_max_height() const { return has_explicit_max_height_; } 140 bool has_explicit_max_height() const { return has_explicit_max_height_; }
135 bool has_explicit_max_width() const { return has_explicit_max_width_; } 141 bool has_explicit_max_width() const { return has_explicit_max_width_; }
136 const DoubleRangeSet& frame_rate_set() const { return frame_rate_set_; } 142 const DoubleRangeSet& frame_rate_set() const { return frame_rate_set_; }
143 bool has_explicit_min_frame_rate() const {
144 return has_explicit_min_frame_rate_;
145 }
137 bool has_explicit_max_frame_rate() const { 146 bool has_explicit_max_frame_rate() const {
138 return has_explicit_max_frame_rate_; 147 return has_explicit_max_frame_rate_;
139 } 148 }
140 const StringSet& device_id_set() const { return device_id_set_; } 149 const StringSet& device_id_set() const { return device_id_set_; }
141 const BoolSet& noise_reduction_set() const { return noise_reduction_set_; } 150 const BoolSet& noise_reduction_set() const { return noise_reduction_set_; }
142 void set_resolution_set(const ResolutionSet& set) { resolution_set_ = set; } 151 void set_resolution_set(const ResolutionSet& set) { resolution_set_ = set; }
143 void set_frame_rate_set(const DoubleRangeSet& set) { frame_rate_set_ = set; } 152 void set_frame_rate_set(const DoubleRangeSet& set) { frame_rate_set_ = set; }
144 153
145 private: 154 private:
146 ResolutionSet resolution_set_; 155 ResolutionSet resolution_set_;
147 bool has_explicit_max_height_; 156 bool has_explicit_max_height_;
148 bool has_explicit_max_width_; 157 bool has_explicit_max_width_;
149 DoubleRangeSet frame_rate_set_; 158 DoubleRangeSet frame_rate_set_;
159 bool has_explicit_min_frame_rate_;
150 bool has_explicit_max_frame_rate_; 160 bool has_explicit_max_frame_rate_;
151 StringSet device_id_set_; 161 StringSet device_id_set_;
152 BoolSet noise_reduction_set_; 162 BoolSet noise_reduction_set_;
153 }; 163 };
154 164
155 ResolutionSet ScreenCastResolutionCapabilities() { 165 ResolutionSet ScreenCastResolutionCapabilities() {
156 return ResolutionSet(kMinScreenCastDimension, kMaxScreenCastDimension, 166 return ResolutionSet(kMinScreenCastDimension, kMaxScreenCastDimension,
157 kMinScreenCastDimension, kMaxScreenCastDimension, 167 kMinScreenCastDimension, kMaxScreenCastDimension,
158 kMinScreenCastAspectRatio, kMaxScreenCastAspectRatio); 168 kMinScreenCastAspectRatio, kMaxScreenCastAspectRatio);
159 } 169 }
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 candidates.noise_reduction_set(), basic_constraint_set); 353 candidates.noise_reduction_set(), basic_constraint_set);
344 354
345 // Using false because the resolution policy for content capture can produce 355 // Using false because the resolution policy for content capture can produce
346 // frames in various sizes. 356 // frames in various sizes.
347 bool expect_source_native_size = false; 357 bool expect_source_native_size = false;
348 auto track_adapter_settings = SelectVideoTrackAdapterSettings( 358 auto track_adapter_settings = SelectVideoTrackAdapterSettings(
349 basic_constraint_set, candidates.resolution_set(), 359 basic_constraint_set, candidates.resolution_set(),
350 candidates.frame_rate_set(), capture_params.requested_format, 360 candidates.frame_rate_set(), capture_params.requested_format,
351 expect_source_native_size); 361 expect_source_native_size);
352 362
363 base::Optional<double> min_frame_rate;
364 if (candidates.has_explicit_min_frame_rate())
365 min_frame_rate = candidates.frame_rate_set().Min();
366
367 base::Optional<double> max_frame_rate;
368 if (candidates.has_explicit_max_frame_rate())
369 max_frame_rate = candidates.frame_rate_set().Max();
370
353 return VideoCaptureSettings(std::move(device_id), capture_params, 371 return VideoCaptureSettings(std::move(device_id), capture_params,
354 noise_reduction, track_adapter_settings, 372 noise_reduction, track_adapter_settings,
355 candidates.frame_rate_set().Min()); 373 min_frame_rate, max_frame_rate);
356 } 374 }
357 375
358 VideoCaptureSettings UnsatisfiedConstraintsResult( 376 VideoCaptureSettings UnsatisfiedConstraintsResult(
359 const VideoContentCaptureCandidates& candidates, 377 const VideoContentCaptureCandidates& candidates,
360 const blink::WebMediaTrackConstraintSet& constraint_set) { 378 const blink::WebMediaTrackConstraintSet& constraint_set) {
361 DCHECK(candidates.IsEmpty()); 379 DCHECK(candidates.IsEmpty());
362 if (candidates.resolution_set().IsHeightEmpty()) { 380 if (candidates.resolution_set().IsHeightEmpty()) {
363 return VideoCaptureSettings(constraint_set.height.GetName()); 381 return VideoCaptureSettings(constraint_set.height.GetName());
364 } else if (candidates.resolution_set().IsWidthEmpty()) { 382 } else if (candidates.resolution_set().IsWidthEmpty()) {
365 return VideoCaptureSettings(constraint_set.width.GetName()); 383 return VideoCaptureSettings(constraint_set.width.GetName());
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 if (!intersection.IsEmpty()) 417 if (!intersection.IsEmpty())
400 candidates = std::move(intersection); 418 candidates = std::move(intersection);
401 } 419 }
402 420
403 DCHECK(!candidates.IsEmpty()); 421 DCHECK(!candidates.IsEmpty());
404 return SelectResultFromCandidates(candidates, constraints.Basic(), 422 return SelectResultFromCandidates(candidates, constraints.Basic(),
405 stream_source); 423 stream_source);
406 } 424 }
407 425
408 } // namespace content 426 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698