OLD | NEW |
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/media_stream_constraints_util.h" | 5 #include "content/renderer/media/media_stream_constraints_util.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 } | 97 } |
98 } | 98 } |
99 return false; | 99 return false; |
100 } | 100 } |
101 | 101 |
102 } // namespace | 102 } // namespace |
103 | 103 |
104 VideoCaptureSettings::VideoCaptureSettings() : VideoCaptureSettings("") {} | 104 VideoCaptureSettings::VideoCaptureSettings() : VideoCaptureSettings("") {} |
105 | 105 |
106 VideoCaptureSettings::VideoCaptureSettings(const char* failed_constraint_name) | 106 VideoCaptureSettings::VideoCaptureSettings(const char* failed_constraint_name) |
107 : failed_constraint_name_(failed_constraint_name) {} | 107 : failed_constraint_name_(failed_constraint_name) { |
| 108 DCHECK(failed_constraint_name_); |
| 109 } |
108 | 110 |
109 VideoCaptureSettings::VideoCaptureSettings( | 111 VideoCaptureSettings::VideoCaptureSettings( |
110 std::string device_id, | 112 std::string device_id, |
111 media::VideoCaptureParams capture_params, | 113 media::VideoCaptureParams capture_params, |
112 base::Optional<bool> noise_reduction, | 114 base::Optional<bool> noise_reduction, |
113 const VideoTrackAdapterSettings& track_adapter_settings, | 115 const VideoTrackAdapterSettings& track_adapter_settings, |
114 base::Optional<double> min_frame_rate, | 116 base::Optional<double> min_frame_rate, |
115 base::Optional<double> max_frame_rate) | 117 base::Optional<double> max_frame_rate) |
116 : failed_constraint_name_(nullptr), | 118 : failed_constraint_name_(nullptr), |
117 device_id_(std::move(device_id)), | 119 device_id_(std::move(device_id)), |
(...skipping 15 matching lines...) Expand all Loading... |
133 VideoCaptureSettings::VideoCaptureSettings(const VideoCaptureSettings& other) = | 135 VideoCaptureSettings::VideoCaptureSettings(const VideoCaptureSettings& other) = |
134 default; | 136 default; |
135 VideoCaptureSettings::VideoCaptureSettings(VideoCaptureSettings&& other) = | 137 VideoCaptureSettings::VideoCaptureSettings(VideoCaptureSettings&& other) = |
136 default; | 138 default; |
137 VideoCaptureSettings::~VideoCaptureSettings() = default; | 139 VideoCaptureSettings::~VideoCaptureSettings() = default; |
138 VideoCaptureSettings& VideoCaptureSettings::operator=( | 140 VideoCaptureSettings& VideoCaptureSettings::operator=( |
139 const VideoCaptureSettings& other) = default; | 141 const VideoCaptureSettings& other) = default; |
140 VideoCaptureSettings& VideoCaptureSettings::operator=( | 142 VideoCaptureSettings& VideoCaptureSettings::operator=( |
141 VideoCaptureSettings&& other) = default; | 143 VideoCaptureSettings&& other) = default; |
142 | 144 |
| 145 AudioCaptureSettings::AudioCaptureSettings() : AudioCaptureSettings("") {} |
| 146 |
| 147 AudioCaptureSettings::AudioCaptureSettings(const char* failed_constraint_name) |
| 148 : failed_constraint_name_(failed_constraint_name) { |
| 149 DCHECK(failed_constraint_name_); |
| 150 } |
| 151 |
| 152 AudioCaptureSettings::AudioCaptureSettings( |
| 153 std::string device_id, |
| 154 const media::AudioParameters& audio_parameters, |
| 155 bool enable_hotword, |
| 156 bool disable_local_echo, |
| 157 bool enable_automatic_output_device_selection, |
| 158 const AudioProcessingProperties& audio_processing_properties) |
| 159 : failed_constraint_name_(nullptr), |
| 160 device_id_(std::move(device_id)), |
| 161 audio_parameters_(audio_parameters), |
| 162 hotword_enabled_(enable_hotword), |
| 163 disable_local_echo_(disable_local_echo), |
| 164 render_to_associated_sink_(enable_automatic_output_device_selection), |
| 165 audio_processing_properties_(audio_processing_properties) {} |
| 166 |
| 167 AudioCaptureSettings::AudioCaptureSettings(const AudioCaptureSettings& other) = |
| 168 default; |
| 169 AudioCaptureSettings& AudioCaptureSettings::operator=( |
| 170 const AudioCaptureSettings& other) = default; |
| 171 AudioCaptureSettings::AudioCaptureSettings(AudioCaptureSettings&& other) = |
| 172 default; |
| 173 AudioCaptureSettings& AudioCaptureSettings::operator=( |
| 174 AudioCaptureSettings&& other) = default; |
| 175 |
143 bool GetConstraintValueAsBoolean( | 176 bool GetConstraintValueAsBoolean( |
144 const blink::WebMediaConstraints& constraints, | 177 const blink::WebMediaConstraints& constraints, |
145 const blink::BooleanConstraint blink::WebMediaTrackConstraintSet::*picker, | 178 const blink::BooleanConstraint blink::WebMediaTrackConstraintSet::*picker, |
146 bool* value) { | 179 bool* value) { |
147 return ScanConstraintsForExactValue(constraints, picker, value); | 180 return ScanConstraintsForExactValue(constraints, picker, value); |
148 } | 181 } |
149 | 182 |
150 bool GetConstraintValueAsInteger( | 183 bool GetConstraintValueAsInteger( |
151 const blink::WebMediaConstraints& constraints, | 184 const blink::WebMediaConstraints& constraints, |
152 const blink::LongConstraint blink::WebMediaTrackConstraintSet::*picker, | 185 const blink::LongConstraint blink::WebMediaTrackConstraintSet::*picker, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 rtc::Optional<bool> ConstraintToOptional( | 237 rtc::Optional<bool> ConstraintToOptional( |
205 const blink::WebMediaConstraints& constraints, | 238 const blink::WebMediaConstraints& constraints, |
206 const blink::BooleanConstraint blink::WebMediaTrackConstraintSet::*picker) { | 239 const blink::BooleanConstraint blink::WebMediaTrackConstraintSet::*picker) { |
207 bool value; | 240 bool value; |
208 if (GetConstraintValueAsBoolean(constraints, picker, &value)) { | 241 if (GetConstraintValueAsBoolean(constraints, picker, &value)) { |
209 return rtc::Optional<bool>(value); | 242 return rtc::Optional<bool>(value); |
210 } | 243 } |
211 return rtc::Optional<bool>(); | 244 return rtc::Optional<bool>(); |
212 } | 245 } |
213 | 246 |
| 247 std::string GetMediaStreamSource( |
| 248 const blink::WebMediaConstraints& constraints) { |
| 249 std::string source; |
| 250 if (constraints.Basic().media_stream_source.HasIdeal() && |
| 251 constraints.Basic().media_stream_source.Exact().size() > 0) { |
| 252 source = constraints.Basic().media_stream_source.Ideal()[0].Utf8(); |
| 253 } |
| 254 if (constraints.Basic().media_stream_source.HasExact() && |
| 255 constraints.Basic().media_stream_source.Exact().size() > 0) { |
| 256 source = constraints.Basic().media_stream_source.Exact()[0].Utf8(); |
| 257 } |
| 258 |
| 259 return source; |
| 260 } |
| 261 |
| 262 bool IsDeviceCapture(const blink::WebMediaConstraints& constraints) { |
| 263 return GetMediaStreamSource(constraints).empty(); |
| 264 } |
| 265 |
214 VideoTrackAdapterSettings SelectVideoTrackAdapterSettings( | 266 VideoTrackAdapterSettings SelectVideoTrackAdapterSettings( |
215 const blink::WebMediaTrackConstraintSet& basic_constraint_set, | 267 const blink::WebMediaTrackConstraintSet& basic_constraint_set, |
216 const ResolutionSet& resolution_set, | 268 const ResolutionSet& resolution_set, |
217 const NumericRangeSet<double>& frame_rate_set, | 269 const NumericRangeSet<double>& frame_rate_set, |
218 const media::VideoCaptureFormat& source_format, | 270 const media::VideoCaptureFormat& source_format, |
219 bool expect_source_native_size) { | 271 bool expect_source_native_size) { |
220 ResolutionSet::Point resolution = resolution_set.SelectClosestPointToIdeal( | 272 ResolutionSet::Point resolution = resolution_set.SelectClosestPointToIdeal( |
221 basic_constraint_set, source_format.frame_size.height(), | 273 basic_constraint_set, source_format.frame_size.height(), |
222 source_format.frame_size.width()); | 274 source_format.frame_size.width()); |
223 int track_max_height = static_cast<int>(std::round(resolution.height())); | 275 int track_max_height = static_cast<int>(std::round(resolution.height())); |
(...skipping 19 matching lines...) Expand all Loading... |
243 | 295 |
244 base::Optional<gfx::Size> expected_native_size; | 296 base::Optional<gfx::Size> expected_native_size; |
245 if (expect_source_native_size) | 297 if (expect_source_native_size) |
246 expected_native_size = source_format.frame_size; | 298 expected_native_size = source_format.frame_size; |
247 | 299 |
248 return VideoTrackAdapterSettings( | 300 return VideoTrackAdapterSettings( |
249 track_max_width, track_max_height, track_min_aspect_ratio, | 301 track_max_width, track_max_height, track_min_aspect_ratio, |
250 track_max_aspect_ratio, track_max_frame_rate, expected_native_size); | 302 track_max_aspect_ratio, track_max_frame_rate, expected_native_size); |
251 } | 303 } |
252 | 304 |
| 305 double NumericConstraintFitnessDistance(double value1, double value2) { |
| 306 if (std::fabs(value1 - value2) <= blink::DoubleConstraint::kConstraintEpsilon) |
| 307 return 0.0; |
| 308 |
| 309 return std::fabs(value1 - value2) / |
| 310 std::max(std::fabs(value1), std::fabs(value2)); |
| 311 } |
| 312 |
| 313 double StringConstraintFitnessDistance( |
| 314 const blink::WebString& value, |
| 315 const blink::StringConstraint& constraint) { |
| 316 if (!constraint.HasIdeal()) |
| 317 return 0.0; |
| 318 |
| 319 for (auto& ideal_value : constraint.Ideal()) { |
| 320 if (value == ideal_value) |
| 321 return 0.0; |
| 322 } |
| 323 |
| 324 return 1.0; |
| 325 } |
| 326 |
253 } // namespace content | 327 } // namespace content |
OLD | NEW |