Chromium Code Reviews| OLD | NEW |
|---|---|
| 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_device.h" | 5 #include "content/renderer/media/media_stream_constraints_util_video_device.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <utility> | 10 #include <utility> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "content/renderer/media/media_stream_constraints_util.h" | 13 #include "content/renderer/media/media_stream_constraints_util.h" |
| 14 #include "content/renderer/media/media_stream_constraints_util_sets.h" | |
| 14 #include "content/renderer/media/media_stream_video_source.h" | 15 #include "content/renderer/media/media_stream_video_source.h" |
| 15 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" | 16 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" |
| 16 #include "third_party/WebKit/public/platform/WebString.h" | 17 #include "third_party/WebKit/public/platform/WebString.h" |
| 17 | 18 |
| 18 namespace content { | 19 namespace content { |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 // Number of default settings to be used as final tie-breaking criteria for | 23 // Number of default settings to be used as final tie-breaking criteria for |
| 23 // settings that are equally good at satisfying constraints: | 24 // settings that are equally good at satisfying constraints: |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 43 return blink::WebString::fromASCII("environment"); | 44 return blink::WebString::fromASCII("environment"); |
| 44 case ::mojom::FacingMode::LEFT: | 45 case ::mojom::FacingMode::LEFT: |
| 45 return blink::WebString::fromASCII("left"); | 46 return blink::WebString::fromASCII("left"); |
| 46 case ::mojom::FacingMode::RIGHT: | 47 case ::mojom::FacingMode::RIGHT: |
| 47 return blink::WebString::fromASCII("right"); | 48 return blink::WebString::fromASCII("right"); |
| 48 default: | 49 default: |
| 49 return blink::WebString::fromASCII(""); | 50 return blink::WebString::fromASCII(""); |
| 50 } | 51 } |
| 51 } | 52 } |
| 52 | 53 |
| 53 struct VideoDeviceCaptureSourceSettings { | 54 struct Candidate { |
| 54 public: | 55 public: |
| 55 VideoDeviceCaptureSourceSettings( | 56 Candidate(const std::string& device_id, |
| 56 const std::string& device_id, | 57 const media::VideoCaptureFormat& format, |
| 57 const media::VideoCaptureFormat& format, | 58 ::mojom::FacingMode facing_mode, |
| 58 ::mojom::FacingMode facing_mode, | 59 media::PowerLineFrequency power_line_frequency, |
| 59 media::PowerLineFrequency power_line_frequency, | 60 const base::Optional<bool>& noise_reduction) |
| 60 const rtc::Optional<bool>& noise_reduction) | |
| 61 : device_id_(device_id), | 61 : device_id_(device_id), |
| 62 format_(format), | 62 format_(format), |
| 63 facing_mode_(facing_mode), | 63 facing_mode_(facing_mode), |
| 64 power_line_frequency_(power_line_frequency), | 64 power_line_frequency_(power_line_frequency), |
| 65 noise_reduction_(noise_reduction) {} | 65 noise_reduction_(noise_reduction) {} |
| 66 | 66 |
| 67 VideoDeviceCaptureSourceSettings( | |
| 68 const VideoDeviceCaptureSourceSettings& other) = default; | |
| 69 VideoDeviceCaptureSourceSettings& operator=( | |
| 70 const VideoDeviceCaptureSourceSettings& other) = default; | |
| 71 VideoDeviceCaptureSourceSettings(VideoDeviceCaptureSourceSettings&& other) = | |
| 72 default; | |
| 73 VideoDeviceCaptureSourceSettings& operator=( | |
| 74 VideoDeviceCaptureSourceSettings&& other) = default; | |
| 75 ~VideoDeviceCaptureSourceSettings() = default; | |
| 76 | |
| 77 // These accessor-like methods transform types to what Blink constraint | 67 // These accessor-like methods transform types to what Blink constraint |
| 78 // classes expect. | 68 // classes expect. |
| 79 blink::WebString GetFacingMode() const { return ToWebString(facing_mode_); } | 69 blink::WebString GetFacingMode() const { return ToWebString(facing_mode_); } |
| 80 long GetPowerLineFrequency() const { | 70 long GetPowerLineFrequency() const { |
| 81 return static_cast<long>(power_line_frequency_); | 71 return static_cast<long>(power_line_frequency_); |
| 82 } | 72 } |
| 83 blink::WebString GetDeviceId() const { | 73 blink::WebString GetDeviceId() const { |
| 84 return blink::WebString::fromASCII(device_id_.data()); | 74 return blink::WebString::fromASCII(device_id_.data()); |
| 85 } | 75 } |
| 86 blink::WebString GetVideoKind() const { | 76 blink::WebString GetVideoKind() const { |
| 87 return GetVideoKindForFormat(format_); | 77 return GetVideoKindForFormat(format_); |
| 88 } | 78 } |
| 89 | 79 |
| 90 // Accessors. | 80 // Accessors. |
| 91 const media::VideoCaptureFormat& format() const { return format_; } | 81 const media::VideoCaptureFormat& format() const { return format_; } |
| 92 const std::string& device_id() const { return device_id_; } | 82 const std::string& device_id() const { return device_id_; } |
| 93 ::mojom::FacingMode facing_mode() const { return facing_mode_; } | 83 ::mojom::FacingMode facing_mode() const { return facing_mode_; } |
| 94 media::PowerLineFrequency power_line_frequency() const { | 84 media::PowerLineFrequency power_line_frequency() const { |
| 95 return power_line_frequency_; | 85 return power_line_frequency_; |
| 96 } | 86 } |
| 97 const rtc::Optional<bool>& noise_reduction() const { | 87 const base::Optional<bool>& noise_reduction() const { |
| 98 return noise_reduction_; | 88 return noise_reduction_; |
| 99 } | 89 } |
| 100 | 90 |
| 101 private: | 91 private: |
| 102 std::string device_id_; | 92 std::string device_id_; |
| 103 media::VideoCaptureFormat format_; | 93 media::VideoCaptureFormat format_; |
| 104 ::mojom::FacingMode facing_mode_; | 94 ::mojom::FacingMode facing_mode_; |
| 105 media::PowerLineFrequency power_line_frequency_; | 95 media::PowerLineFrequency power_line_frequency_; |
| 106 rtc::Optional<bool> noise_reduction_; | 96 base::Optional<bool> noise_reduction_; |
| 107 }; | 97 }; |
| 108 | 98 |
| 109 // The ConstrainedFormat class keeps track of the effect of constraint sets on | 99 // The ConstrainedFormat class keeps track of the effect of constraint sets on |
| 110 // the range of values supported by a video-capture format while iterating over | 100 // the range of values supported by a video-capture format while iterating over |
| 111 // the constraint sets. | 101 // the constraint sets. |
| 112 // For example, suppose a device supports a width of 1024. Then, in principle, | 102 // For example, suppose a device supports a width of 1024. Then, in principle, |
| 113 // it can support any width below 1024 using cropping. | 103 // it can support any width below 1024 using cropping. |
| 114 // Suppose the first advanced constraint set requests a maximum width of 640, | 104 // Suppose the first advanced constraint set requests a maximum width of 640, |
| 115 // and the second advanced constraint set requests a minimum of 800. | 105 // and the second advanced constraint set requests a minimum of 800. |
| 116 // Separately, the camera supports both advanced sets. However, if the first | 106 // Separately, the camera supports both advanced sets. However, if the first |
| 117 // set is supported, the second set can no longer be supported because width can | 107 // set is supported, the second set can no longer be supported because width can |
| 118 // no longer exceed 640. The ConstrainedFormat class keeps track of this. | 108 // no longer exceed 640. The ConstrainedFormat class keeps track of this. |
| 119 class ConstrainedFormat { | 109 class ConstrainedFormat { |
| 120 public: | 110 public: |
| 121 explicit ConstrainedFormat(const media::VideoCaptureFormat& format) | 111 explicit ConstrainedFormat(const media::VideoCaptureFormat& format) |
| 122 : native_height_(format.frame_size.height()), | 112 : native_height_(format.frame_size.height()), |
| 123 min_height_(1), | |
| 124 max_height_(format.frame_size.height()), | |
| 125 native_width_(format.frame_size.width()), | 113 native_width_(format.frame_size.width()), |
| 126 min_width_(1), | |
| 127 max_width_(format.frame_size.width()), | |
| 128 native_frame_rate_(format.frame_rate), | 114 native_frame_rate_(format.frame_rate), |
| 129 min_frame_rate_(1), | 115 constrained_resolution_(1, |
| 130 max_frame_rate_(format.frame_rate) {} | 116 format.frame_size.height(), |
| 117 1, | |
| 118 format.frame_size.width(), | |
| 119 0.0, | |
| 120 HUGE_VAL), | |
| 121 constrained_frame_rate_(1, format.frame_rate) {} | |
| 131 | 122 |
| 132 long native_height() const { return native_height_; } | 123 long native_height() const { return native_height_; } |
| 133 long min_height() const { return min_height_; } | |
| 134 long max_height() const { return max_height_; } | |
| 135 long native_width() const { return native_width_; } | 124 long native_width() const { return native_width_; } |
| 136 long min_width() const { return min_width_; } | 125 double native_frame_rate() const { return native_frame_rate_; } |
| 137 long max_width() const { return max_width_; } | 126 const ResolutionSet& constrained_resolution() const { |
| 138 long native_frame_rate() const { return native_frame_rate_; } | 127 return constrained_resolution_; |
| 139 long min_frame_rate() const { return min_frame_rate_; } | 128 } |
| 140 long max_frame_rate() const { return max_frame_rate_; } | 129 const NumericRangeSet<double>& constrained_frame_rate() const { |
| 130 return constrained_frame_rate_; | |
| 131 } | |
| 141 | 132 |
| 142 void ApplyConstraintSet( | 133 long MinHeight() const { return constrained_resolution_.min_height(); } |
| 134 long MaxHeight() const { return constrained_resolution_.max_height(); } | |
| 135 long MinWidth() const { return constrained_resolution_.min_width(); } | |
| 136 long MaxWidth() const { return constrained_resolution_.max_width(); } | |
| 137 double MinAspectRatio() const { | |
| 138 return constrained_resolution_.min_aspect_ratio(); | |
| 139 } | |
| 140 double MaxAspectRatio() const { | |
| 141 return constrained_resolution_.max_aspect_ratio(); | |
| 142 } | |
| 143 double MinFrameRate() const { return constrained_frame_rate_.Min(); } | |
| 144 double MaxFrameRate() const { return constrained_frame_rate_.Max(); } | |
| 145 | |
| 146 // Returns true if the application of |constraint_set| is successful and | |
| 147 // results in a nonempty set. Returns true otherwise. | |
| 148 bool ApplyConstraintSet( | |
| 143 const blink::WebMediaTrackConstraintSet& constraint_set) { | 149 const blink::WebMediaTrackConstraintSet& constraint_set) { |
| 144 if (ConstraintHasMin(constraint_set.width)) | 150 constrained_resolution_ = constrained_resolution_.Intersection( |
| 145 min_width_ = std::max(min_width_, ConstraintMin(constraint_set.width)); | 151 ResolutionSet::FromConstraintSet(constraint_set)); |
| 146 if (ConstraintHasMax(constraint_set.width)) | 152 constrained_frame_rate_ = constrained_frame_rate_.Intersection( |
| 147 max_width_ = std::min(max_width_, ConstraintMax(constraint_set.width)); | 153 NumericRangeSet<double>::FromConstraint(constraint_set.frameRate)); |
| 148 | 154 DCHECK(!constrained_resolution_.IsEmpty()); |
| 149 if (ConstraintHasMin(constraint_set.height)) | 155 DCHECK(!constrained_frame_rate_.IsEmpty()); |
| 150 min_height_ = std::max(min_height_, ConstraintMin(constraint_set.height)); | 156 return true; |
| 151 if (ConstraintHasMax(constraint_set.height)) | |
| 152 max_height_ = std::min(max_height_, ConstraintMax(constraint_set.height)); | |
| 153 | |
| 154 if (ConstraintHasMin(constraint_set.frameRate)) | |
| 155 min_frame_rate_ = | |
| 156 std::max(min_frame_rate_, ConstraintMin(constraint_set.frameRate)); | |
| 157 if (ConstraintHasMax(constraint_set.frameRate)) | |
| 158 max_frame_rate_ = | |
| 159 std::min(max_frame_rate_, ConstraintMax(constraint_set.frameRate)); | |
| 160 } | 157 } |
| 161 | 158 |
| 162 private: | 159 private: |
| 163 // Using long for compatibility with Blink constraint classes. | 160 // Using long for compatibility with Blink constraint classes. |
| 164 long native_height_; | 161 long native_height_; |
| 165 long min_height_; | |
| 166 long max_height_; | |
| 167 long native_width_; | 162 long native_width_; |
| 168 long min_width_; | |
| 169 long max_width_; | |
| 170 double native_frame_rate_; | 163 double native_frame_rate_; |
| 171 double min_frame_rate_; | 164 ResolutionSet constrained_resolution_; |
| 172 double max_frame_rate_; | 165 NumericRangeSet<double> constrained_frame_rate_; |
| 173 }; | 166 }; |
| 174 | 167 |
| 175 VideoDeviceCaptureSourceSelectionResult ResultFromSettings( | 168 VideoCaptureSettings ComputeVideoDeviceCaptureSettings( |
| 176 const VideoDeviceCaptureSourceSettings& settings) { | 169 const Candidate& settings, |
| 170 const ConstrainedFormat& constrained_format, | |
| 171 const blink::WebMediaTrackConstraintSet& basic_constraint_set) { | |
| 177 media::VideoCaptureParams capture_params; | 172 media::VideoCaptureParams capture_params; |
| 178 capture_params.requested_format = settings.format(); | 173 capture_params.requested_format = settings.format(); |
| 179 capture_params.power_line_frequency = settings.power_line_frequency(); | 174 capture_params.power_line_frequency = settings.power_line_frequency(); |
| 175 auto track_adapter_settings = SelectVideoTrackAdapterSettings( | |
| 176 basic_constraint_set, constrained_format.constrained_resolution(), | |
| 177 constrained_format.constrained_frame_rate(), | |
| 178 capture_params.requested_format); | |
| 179 // constrained_format.native_height(), constrained_format.native_width(), | |
| 180 // constrained_format.native_frame_rate()); | |
|
hbos_chromium
2017/03/28 12:52:53
Remove the commented-out lines.
Guido Urdaneta
2017/03/28 18:35:43
Done.
| |
| 180 | 181 |
| 181 return VideoDeviceCaptureSourceSelectionResult( | 182 return VideoCaptureSettings( |
| 182 settings.device_id(), settings.facing_mode(), capture_params, | 183 settings.device_id(), settings.facing_mode(), capture_params, |
| 183 settings.noise_reduction()); | 184 settings.noise_reduction(), track_adapter_settings, |
| 185 constrained_format.constrained_frame_rate().Min()); | |
| 184 } | 186 } |
| 185 | 187 |
| 186 // Generic distance function between two numeric values. Based on the fitness | 188 // Generic distance function between two numeric values. Based on the fitness |
| 187 // distance function described in | 189 // distance function described in |
| 188 // https://w3c.github.io/mediacapture-main/#dfn-fitness-distance | 190 // https://w3c.github.io/mediacapture-main/#dfn-fitness-distance |
| 189 double Distance(double value1, double value2) { | 191 double Distance(double value1, double value2) { |
| 190 if (std::fabs(value1 - value2) <= blink::DoubleConstraint::kConstraintEpsilon) | 192 if (std::fabs(value1 - value2) <= blink::DoubleConstraint::kConstraintEpsilon) |
| 191 return 0.0; | 193 return 0.0; |
| 192 | 194 |
| 193 return std::fabs(value1 - value2) / | 195 return std::fabs(value1 - value2) / |
| 194 std::max(std::fabs(value1), std::fabs(value2)); | 196 std::max(std::fabs(value1), std::fabs(value2)); |
| 195 } | 197 } |
| 196 | 198 |
| 197 // Returns a pair with the minimum and maximum aspect ratios supported by the | 199 // Returns a pair with the minimum and maximum aspect ratios supported by the |
| 198 // candidate format |constrained_format|, subject to given width and height | 200 // candidate format |constrained_format|, subject to given width and height |
| 199 // constraints. | 201 // constraints. |
| 200 void GetSourceAspectRatioRange(const ConstrainedFormat& constrained_format, | 202 void GetSourceAspectRatioRange(const ConstrainedFormat& constrained_format, |
| 201 const blink::LongConstraint& height_constraint, | 203 const blink::LongConstraint& height_constraint, |
| 202 const blink::LongConstraint& width_constraint, | 204 const blink::LongConstraint& width_constraint, |
| 203 double* min_source_aspect_ratio, | 205 double* min_source_aspect_ratio, |
| 204 double* max_source_aspect_ratio) { | 206 double* max_source_aspect_ratio) { |
| 205 long min_height = constrained_format.min_height(); | 207 long min_height = constrained_format.MinHeight(); |
| 206 if (ConstraintHasMin(height_constraint)) | 208 if (ConstraintHasMin(height_constraint)) |
| 207 min_height = std::max(min_height, ConstraintMin(height_constraint)); | 209 min_height = std::max(min_height, ConstraintMin(height_constraint)); |
| 208 | 210 |
| 209 long max_height = constrained_format.max_height(); | 211 long max_height = constrained_format.MaxHeight(); |
| 210 if (ConstraintHasMax(height_constraint)) | 212 if (ConstraintHasMax(height_constraint)) |
| 211 max_height = std::min(max_height, ConstraintMax(height_constraint)); | 213 max_height = std::min(max_height, ConstraintMax(height_constraint)); |
| 212 | 214 |
| 213 long min_width = constrained_format.min_width(); | 215 long min_width = constrained_format.MinWidth(); |
| 214 if (ConstraintHasMin(width_constraint)) | 216 if (ConstraintHasMin(width_constraint)) |
| 215 min_width = std::max(min_width, ConstraintMin(width_constraint)); | 217 min_width = std::max(min_width, ConstraintMin(width_constraint)); |
| 216 | 218 |
| 217 long max_width = constrained_format.max_width(); | 219 long max_width = constrained_format.MaxWidth(); |
| 218 if (ConstraintHasMax(width_constraint)) | 220 if (ConstraintHasMax(width_constraint)) |
| 219 max_width = std::min(max_width, ConstraintMax(width_constraint)); | 221 max_width = std::min(max_width, ConstraintMax(width_constraint)); |
| 220 | 222 |
| 221 *min_source_aspect_ratio = | 223 *min_source_aspect_ratio = std::max( |
| 224 constrained_format.MinAspectRatio(), | |
| 222 std::max(static_cast<double>(min_width) / static_cast<double>(max_height), | 225 std::max(static_cast<double>(min_width) / static_cast<double>(max_height), |
| 223 kMinSourceAspectRatio); | 226 kMinSourceAspectRatio)); |
| 224 *max_source_aspect_ratio = | 227 *max_source_aspect_ratio = std::min( |
| 228 constrained_format.MaxAspectRatio(), | |
| 225 std::max(static_cast<double>(max_width) / static_cast<double>(min_height), | 229 std::max(static_cast<double>(max_width) / static_cast<double>(min_height), |
| 226 kMinSourceAspectRatio); | 230 kMinSourceAspectRatio)); |
| 227 } | 231 } |
| 228 | 232 |
| 229 // Returns a custom distance between a string and a string constraint. | 233 // Returns a custom distance between a string and a string constraint. |
| 230 // Returns 0 if |value| satisfies |constraint|. HUGE_VAL otherwise. | 234 // Returns 0 if |value| satisfies |constraint|. HUGE_VAL otherwise. |
| 231 double StringConstraintSourceDistance(const blink::WebString& value, | 235 double StringConstraintSourceDistance(const blink::WebString& value, |
| 232 const blink::StringConstraint& constraint, | 236 const blink::StringConstraint& constraint, |
| 233 const char** failed_constraint_name) { | 237 const char** failed_constraint_name) { |
| 234 if (constraint.matches(value)) | 238 if (constraint.matches(value)) |
| 235 return 0.0; | 239 return 0.0; |
| 236 | 240 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 294 double FrameRateConstraintSourceDistance( | 298 double FrameRateConstraintSourceDistance( |
| 295 const ConstrainedFormat& constrained_format, | 299 const ConstrainedFormat& constrained_format, |
| 296 const blink::DoubleConstraint& constraint, | 300 const blink::DoubleConstraint& constraint, |
| 297 const char** failed_constraint_name) { | 301 const char** failed_constraint_name) { |
| 298 bool constraint_has_min = ConstraintHasMin(constraint); | 302 bool constraint_has_min = ConstraintHasMin(constraint); |
| 299 double constraint_min = constraint_has_min ? ConstraintMin(constraint) : -1.0; | 303 double constraint_min = constraint_has_min ? ConstraintMin(constraint) : -1.0; |
| 300 bool constraint_has_max = ConstraintHasMax(constraint); | 304 bool constraint_has_max = ConstraintHasMax(constraint); |
| 301 double constraint_max = constraint_has_max ? ConstraintMax(constraint) : -1.0; | 305 double constraint_max = constraint_has_max ? ConstraintMax(constraint) : -1.0; |
| 302 | 306 |
| 303 if ((constraint_has_max && | 307 if ((constraint_has_max && |
| 304 constrained_format.min_frame_rate() > | 308 constrained_format.MinFrameRate() > |
| 305 constraint_max + blink::DoubleConstraint::kConstraintEpsilon) || | 309 constraint_max + blink::DoubleConstraint::kConstraintEpsilon) || |
| 306 (constraint_has_min && | 310 (constraint_has_min && |
| 307 constrained_format.max_frame_rate() < | 311 constrained_format.MaxFrameRate() < |
| 308 constraint_min - blink::DoubleConstraint::kConstraintEpsilon)) { | 312 constraint_min - blink::DoubleConstraint::kConstraintEpsilon)) { |
| 309 if (failed_constraint_name) | 313 if (failed_constraint_name) |
| 310 *failed_constraint_name = constraint.name(); | 314 *failed_constraint_name = constraint.name(); |
| 311 return HUGE_VAL; | 315 return HUGE_VAL; |
| 312 } | 316 } |
| 313 | 317 |
| 314 // Compute the cost using the native rate. | 318 // Compute the cost using the native rate. |
| 315 if (constraint_has_max && | 319 if (constraint_has_max && |
| 316 constrained_format.native_frame_rate() > constraint_max) | 320 constrained_format.native_frame_rate() > constraint_max) |
| 317 return Distance(constrained_format.native_frame_rate(), constraint_max); | 321 return Distance(constrained_format.native_frame_rate(), constraint_max); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 394 | 398 |
| 395 return 0.0; | 399 return 0.0; |
| 396 } | 400 } |
| 397 | 401 |
| 398 // Returns a custom distance function suitable for the googNoiseReduction | 402 // Returns a custom distance function suitable for the googNoiseReduction |
| 399 // constraint, given a |constraint| and a candidate value |value|. | 403 // constraint, given a |constraint| and a candidate value |value|. |
| 400 // The distance is HUGE_VAL if |candidate_value| cannot satisfy |constraint|. | 404 // The distance is HUGE_VAL if |candidate_value| cannot satisfy |constraint|. |
| 401 // Otherwise, the distance is zero. | 405 // Otherwise, the distance is zero. |
| 402 double NoiseReductionConstraintSourceDistance( | 406 double NoiseReductionConstraintSourceDistance( |
| 403 const blink::BooleanConstraint& constraint, | 407 const blink::BooleanConstraint& constraint, |
| 404 const rtc::Optional<bool>& value, | 408 const base::Optional<bool>& value, |
| 405 const char** failed_constraint_name) { | 409 const char** failed_constraint_name) { |
| 406 if (!constraint.hasExact()) | 410 if (!constraint.hasExact()) |
| 407 return 0.0; | 411 return 0.0; |
| 408 | 412 |
| 409 if (value && *value == constraint.exact()) | 413 if (value && *value == constraint.exact()) |
| 410 return 0.0; | 414 return 0.0; |
| 411 | 415 |
| 412 if (failed_constraint_name) | 416 if (failed_constraint_name) |
| 413 *failed_constraint_name = constraint.name(); | 417 *failed_constraint_name = constraint.name(); |
| 414 return HUGE_VAL; | 418 return HUGE_VAL; |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 435 // |constraint_set| cannot be satisfied together with previous constraint sets, | 439 // |constraint_set| cannot be satisfied together with previous constraint sets, |
| 436 // but will not influence the numeric value returned if it is not infinite. | 440 // but will not influence the numeric value returned if it is not infinite. |
| 437 // Formats with lower distance satisfy |constraint_set| with lower resource | 441 // Formats with lower distance satisfy |constraint_set| with lower resource |
| 438 // usage. | 442 // usage. |
| 439 double FormatSourceDistance( | 443 double FormatSourceDistance( |
| 440 const media::VideoCaptureFormat& format, | 444 const media::VideoCaptureFormat& format, |
| 441 const ConstrainedFormat& constrained_format, | 445 const ConstrainedFormat& constrained_format, |
| 442 const blink::WebMediaTrackConstraintSet& constraint_set, | 446 const blink::WebMediaTrackConstraintSet& constraint_set, |
| 443 const char** failed_constraint_name) { | 447 const char** failed_constraint_name) { |
| 444 return ResolutionConstraintSourceDistance( | 448 return ResolutionConstraintSourceDistance( |
| 445 constrained_format.native_height(), | 449 constrained_format.native_height(), constrained_format.MinHeight(), |
| 446 constrained_format.min_height(), constrained_format.max_height(), | 450 constrained_format.MaxHeight(), constraint_set.height, |
| 447 constraint_set.height, failed_constraint_name) + | 451 failed_constraint_name) + |
| 448 ResolutionConstraintSourceDistance( | 452 ResolutionConstraintSourceDistance( |
| 449 constrained_format.native_width(), constrained_format.min_width(), | 453 constrained_format.native_width(), constrained_format.MinWidth(), |
| 450 constrained_format.max_width(), constraint_set.width, | 454 constrained_format.MaxWidth(), constraint_set.width, |
| 451 failed_constraint_name) + | 455 failed_constraint_name) + |
| 452 AspectRatioConstraintSourceDistance( | 456 AspectRatioConstraintSourceDistance( |
| 453 constrained_format, constraint_set.height, constraint_set.width, | 457 constrained_format, constraint_set.height, constraint_set.width, |
| 454 constraint_set.aspectRatio, failed_constraint_name) + | 458 constraint_set.aspectRatio, failed_constraint_name) + |
| 455 FrameRateConstraintSourceDistance(constrained_format, | 459 FrameRateConstraintSourceDistance(constrained_format, |
| 456 constraint_set.frameRate, | 460 constraint_set.frameRate, |
| 457 failed_constraint_name) + | 461 failed_constraint_name) + |
| 458 StringConstraintSourceDistance(GetVideoKindForFormat(format), | 462 StringConstraintSourceDistance(GetVideoKindForFormat(format), |
| 459 constraint_set.videoKind, | 463 constraint_set.videoKind, |
| 460 failed_constraint_name); | 464 failed_constraint_name); |
| 461 } | 465 } |
| 462 | 466 |
| 463 // Returns a custom distance between |constraint_set| and |candidate|, given | 467 // Returns a custom distance between |constraint_set| and |candidate|, given |
| 464 // that the configuration is already constrained by |constrained_format|. | 468 // that the configuration is already constrained by |constrained_format|. |
| 465 // |constrained_format| may cause the distance to be infinite if | 469 // |constrained_format| may cause the distance to be infinite if |
| 466 // |constraint_set| cannot be satisfied together with previous constraint sets, | 470 // |constraint_set| cannot be satisfied together with previous constraint sets, |
| 467 // but will not influence the numeric value returned if it is not infinite. | 471 // but will not influence the numeric value returned if it is not infinite. |
| 468 // Candidates with lower distance satisfy |constraint_set| with lower resource | 472 // Candidates with lower distance satisfy |constraint_set| with lower resource |
| 469 // usage. | 473 // usage. |
| 470 double CandidateSourceDistance( | 474 double CandidateSourceDistance( |
| 471 const VideoDeviceCaptureSourceSettings& candidate, | 475 const Candidate& candidate, |
| 472 const ConstrainedFormat& constrained_format, | 476 const ConstrainedFormat& constrained_format, |
| 473 const blink::WebMediaTrackConstraintSet& constraint_set, | 477 const blink::WebMediaTrackConstraintSet& constraint_set, |
| 474 const char** failed_constraint_name) { | 478 const char** failed_constraint_name) { |
| 475 return DeviceSourceDistance(candidate.device_id(), candidate.facing_mode(), | 479 return DeviceSourceDistance(candidate.device_id(), candidate.facing_mode(), |
| 476 constraint_set, failed_constraint_name) + | 480 constraint_set, failed_constraint_name) + |
| 477 FormatSourceDistance(candidate.format(), constrained_format, | 481 FormatSourceDistance(candidate.format(), constrained_format, |
| 478 constraint_set, failed_constraint_name) + | 482 constraint_set, failed_constraint_name) + |
| 479 PowerLineFrequencyConstraintSourceDistance( | 483 PowerLineFrequencyConstraintSourceDistance( |
| 480 constraint_set.googPowerLineFrequency, | 484 constraint_set.googPowerLineFrequency, |
| 481 candidate.power_line_frequency(), failed_constraint_name) + | 485 candidate.power_line_frequency(), failed_constraint_name) + |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 606 if (value == constraint.ideal()) | 610 if (value == constraint.ideal()) |
| 607 return 0.0; | 611 return 0.0; |
| 608 | 612 |
| 609 return 1.0; | 613 return 1.0; |
| 610 } | 614 } |
| 611 | 615 |
| 612 // Returns the fitness distance between |value| and |constraint| for the | 616 // Returns the fitness distance between |value| and |constraint| for the |
| 613 // googNoiseReduction constraint. | 617 // googNoiseReduction constraint. |
| 614 // Based on https://w3c.github.io/mediacapture-main/#dfn-fitness-distance. | 618 // Based on https://w3c.github.io/mediacapture-main/#dfn-fitness-distance. |
| 615 double NoiseReductionConstraintFitnessDistance( | 619 double NoiseReductionConstraintFitnessDistance( |
| 616 const rtc::Optional<bool>& value, | 620 const base::Optional<bool>& value, |
| 617 const blink::BooleanConstraint& constraint) { | 621 const blink::BooleanConstraint& constraint) { |
| 618 if (!constraint.hasIdeal()) | 622 if (!constraint.hasIdeal()) |
| 619 return 0.0; | 623 return 0.0; |
| 620 | 624 |
| 621 if (value && value == constraint.ideal()) | 625 if (value && value == constraint.ideal()) |
| 622 return 0.0; | 626 return 0.0; |
| 623 | 627 |
| 624 return 1.0; | 628 return 1.0; |
| 625 } | 629 } |
| 626 | 630 |
| 627 // Returns the fitness distance between |constraint_set| and |candidate| given | 631 // Returns the fitness distance between |constraint_set| and |candidate| given |
| 628 // that the configuration is already constrained by |constrained_format|. | 632 // that the configuration is already constrained by |constrained_format|. |
| 629 // Based on https://w3c.github.io/mediacapture-main/#dfn-fitness-distance. | 633 // Based on https://w3c.github.io/mediacapture-main/#dfn-fitness-distance. |
| 630 double CandidateFitnessDistance( | 634 double CandidateFitnessDistance( |
| 631 const VideoDeviceCaptureSourceSettings& candidate, | 635 const Candidate& candidate, |
| 632 const ConstrainedFormat& constrained_format, | 636 const ConstrainedFormat& constrained_format, |
| 633 const blink::WebMediaTrackConstraintSet& constraint_set) { | 637 const blink::WebMediaTrackConstraintSet& constraint_set) { |
| 634 DCHECK(std::isfinite(CandidateSourceDistance(candidate, constrained_format, | 638 DCHECK(std::isfinite(CandidateSourceDistance(candidate, constrained_format, |
| 635 constraint_set, nullptr))); | 639 constraint_set, nullptr))); |
| 636 double fitness = 0.0; | 640 double fitness = 0.0; |
| 637 fitness += AspectRatioConstraintFitnessDistance( | 641 fitness += AspectRatioConstraintFitnessDistance( |
| 638 constrained_format, constraint_set.height, constraint_set.width, | 642 constrained_format, constraint_set.height, constraint_set.width, |
| 639 constraint_set.aspectRatio); | 643 constraint_set.aspectRatio); |
| 640 fitness += StringConstraintFitnessDistance(candidate.GetDeviceId(), | 644 fitness += StringConstraintFitnessDistance(candidate.GetDeviceId(), |
| 641 constraint_set.deviceId); | 645 constraint_set.deviceId); |
| 642 fitness += StringConstraintFitnessDistance(candidate.GetFacingMode(), | 646 fitness += StringConstraintFitnessDistance(candidate.GetFacingMode(), |
| 643 constraint_set.facingMode); | 647 constraint_set.facingMode); |
| 644 fitness += StringConstraintFitnessDistance(candidate.GetVideoKind(), | 648 fitness += StringConstraintFitnessDistance(candidate.GetVideoKind(), |
| 645 constraint_set.videoKind); | 649 constraint_set.videoKind); |
| 646 fitness += PowerLineFrequencyConstraintFitnessDistance( | 650 fitness += PowerLineFrequencyConstraintFitnessDistance( |
| 647 candidate.GetPowerLineFrequency(), constraint_set.googPowerLineFrequency); | 651 candidate.GetPowerLineFrequency(), constraint_set.googPowerLineFrequency); |
| 648 fitness += NoiseReductionConstraintFitnessDistance( | 652 fitness += NoiseReductionConstraintFitnessDistance( |
| 649 candidate.noise_reduction(), constraint_set.googNoiseReduction); | 653 candidate.noise_reduction(), constraint_set.googNoiseReduction); |
| 650 // No need to pass minimum value to compute fitness for range-based | 654 // No need to pass minimum value to compute fitness for range-based |
| 651 // constraints because all candidates start out with the same minimum and are | 655 // constraints because all candidates start out with the same minimum and are |
| 652 // subject to the same constraints. | 656 // subject to the same constraints. |
| 653 fitness += ResolutionConstraintFitnessDistance( | 657 fitness += ResolutionConstraintFitnessDistance(constrained_format.MaxHeight(), |
| 654 constrained_format.max_height(), constraint_set.height); | 658 constraint_set.height); |
| 655 fitness += ResolutionConstraintFitnessDistance(constrained_format.max_width(), | 659 fitness += ResolutionConstraintFitnessDistance(constrained_format.MaxWidth(), |
| 656 constraint_set.width); | 660 constraint_set.width); |
| 657 fitness += FrameRateConstraintFitnessDistance( | 661 fitness += FrameRateConstraintFitnessDistance( |
| 658 constrained_format.max_frame_rate(), constraint_set.frameRate); | 662 constrained_format.MaxFrameRate(), constraint_set.frameRate); |
| 659 | 663 |
| 660 return fitness; | 664 return fitness; |
| 661 } | 665 } |
| 662 | 666 |
| 663 // Returns the native fitness distance between a candidate format and a | 667 // Returns the native fitness distance between a candidate format and a |
| 664 // constraint set. The returned value is the sum of the fitness distances for | 668 // constraint set. The returned value is the sum of the fitness distances for |
| 665 // the native values of settings that support a range of values (i.e., width, | 669 // the native values of settings that support a range of values (i.e., width, |
| 666 // height and frame rate). | 670 // height and frame rate). |
| 667 // Based on https://w3c.github.io/mediacapture-main/#dfn-fitness-distance. | 671 // Based on https://w3c.github.io/mediacapture-main/#dfn-fitness-distance. |
| 668 double CandidateNativeFitnessDistance( | 672 double CandidateNativeFitnessDistance( |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 680 } | 684 } |
| 681 | 685 |
| 682 using DistanceVector = std::vector<double>; | 686 using DistanceVector = std::vector<double>; |
| 683 | 687 |
| 684 // This function appends additional entries to |distance_vector| based on | 688 // This function appends additional entries to |distance_vector| based on |
| 685 // custom distance metrics between |candidate| and some default settings. | 689 // custom distance metrics between |candidate| and some default settings. |
| 686 // These entries are to be used as the final tie breaker for candidates that | 690 // These entries are to be used as the final tie breaker for candidates that |
| 687 // are equally good according to the spec and the custom distance functions | 691 // are equally good according to the spec and the custom distance functions |
| 688 // between candidates and constraints. | 692 // between candidates and constraints. |
| 689 void AppendDistanceFromDefault( | 693 void AppendDistanceFromDefault( |
| 690 const VideoDeviceCaptureSourceSettings& candidate, | 694 const Candidate& candidate, |
| 691 const VideoDeviceCaptureCapabilities& capabilities, | 695 const VideoDeviceCaptureCapabilities& capabilities, |
| 692 DistanceVector* distance_vector) { | 696 DistanceVector* distance_vector) { |
| 693 // Favor IDs that appear first in the enumeration. | 697 // Favor IDs that appear first in the enumeration. |
| 694 for (size_t i = 0; i < capabilities.device_capabilities.size(); ++i) { | 698 for (size_t i = 0; i < capabilities.device_capabilities.size(); ++i) { |
| 695 if (candidate.device_id() == | 699 if (candidate.device_id() == |
| 696 capabilities.device_capabilities[i]->device_id) { | 700 capabilities.device_capabilities[i]->device_id) { |
| 697 distance_vector->push_back(i); | 701 distance_vector->push_back(i); |
| 698 break; | 702 break; |
| 699 } | 703 } |
| 700 } | 704 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 739 : blink::WebString::fromASCII(kVideoKindColor); | 743 : blink::WebString::fromASCII(kVideoKindColor); |
| 740 } | 744 } |
| 741 | 745 |
| 742 VideoDeviceCaptureCapabilities::VideoDeviceCaptureCapabilities() = default; | 746 VideoDeviceCaptureCapabilities::VideoDeviceCaptureCapabilities() = default; |
| 743 VideoDeviceCaptureCapabilities::VideoDeviceCaptureCapabilities( | 747 VideoDeviceCaptureCapabilities::VideoDeviceCaptureCapabilities( |
| 744 VideoDeviceCaptureCapabilities&& other) = default; | 748 VideoDeviceCaptureCapabilities&& other) = default; |
| 745 VideoDeviceCaptureCapabilities::~VideoDeviceCaptureCapabilities() = default; | 749 VideoDeviceCaptureCapabilities::~VideoDeviceCaptureCapabilities() = default; |
| 746 VideoDeviceCaptureCapabilities& VideoDeviceCaptureCapabilities::operator=( | 750 VideoDeviceCaptureCapabilities& VideoDeviceCaptureCapabilities::operator=( |
| 747 VideoDeviceCaptureCapabilities&& other) = default; | 751 VideoDeviceCaptureCapabilities&& other) = default; |
| 748 | 752 |
| 749 VideoDeviceCaptureSourceSelectionResult:: | 753 VideoCaptureSettings SelectSettingsVideoDeviceCapture( |
| 750 VideoDeviceCaptureSourceSelectionResult() | |
| 751 : VideoDeviceCaptureSourceSelectionResult("") {} | |
| 752 | |
| 753 VideoDeviceCaptureSourceSelectionResult:: | |
| 754 VideoDeviceCaptureSourceSelectionResult(const char* failed_constraint_name) | |
| 755 : failed_constraint_name_(failed_constraint_name) {} | |
| 756 | |
| 757 VideoDeviceCaptureSourceSelectionResult:: | |
| 758 VideoDeviceCaptureSourceSelectionResult( | |
| 759 const std::string& device_id, | |
| 760 ::mojom::FacingMode facing_mode, | |
| 761 media::VideoCaptureParams capture_params, | |
| 762 rtc::Optional<bool> noise_reduction) | |
| 763 : failed_constraint_name_(nullptr), | |
| 764 device_id_(device_id), | |
| 765 facing_mode_(facing_mode), | |
| 766 capture_params_(capture_params), | |
| 767 noise_reduction_(noise_reduction) {} | |
| 768 | |
| 769 VideoDeviceCaptureSourceSelectionResult:: | |
| 770 VideoDeviceCaptureSourceSelectionResult( | |
| 771 const VideoDeviceCaptureSourceSelectionResult& other) = default; | |
| 772 VideoDeviceCaptureSourceSelectionResult:: | |
| 773 VideoDeviceCaptureSourceSelectionResult( | |
| 774 VideoDeviceCaptureSourceSelectionResult&& other) = default; | |
| 775 VideoDeviceCaptureSourceSelectionResult:: | |
| 776 ~VideoDeviceCaptureSourceSelectionResult() = default; | |
| 777 VideoDeviceCaptureSourceSelectionResult& | |
| 778 VideoDeviceCaptureSourceSelectionResult::operator=( | |
| 779 const VideoDeviceCaptureSourceSelectionResult& other) = default; | |
| 780 VideoDeviceCaptureSourceSelectionResult& | |
| 781 VideoDeviceCaptureSourceSelectionResult::operator=( | |
| 782 VideoDeviceCaptureSourceSelectionResult&& other) = default; | |
| 783 | |
| 784 VideoDeviceCaptureSourceSelectionResult SelectVideoDeviceCaptureSourceSettings( | |
| 785 const VideoDeviceCaptureCapabilities& capabilities, | 754 const VideoDeviceCaptureCapabilities& capabilities, |
| 786 const blink::WebMediaConstraints& constraints) { | 755 const blink::WebMediaConstraints& constraints) { |
| 787 // This function works only if infinity is defined for the double type. | 756 // This function works only if infinity is defined for the double type. |
| 788 DCHECK(std::numeric_limits<double>::has_infinity); | 757 DCHECK(std::numeric_limits<double>::has_infinity); |
| 789 | 758 |
| 790 // A distance vector contains: | 759 // A distance vector contains: |
| 791 // a) For each advanced constraint set, a 0/1 value indicating if the | 760 // a) For each advanced constraint set, a 0/1 value indicating if the |
| 792 // candidate satisfies the corresponding constraint set. | 761 // candidate satisfies the corresponding constraint set. |
| 793 // b) Fitness distance for the candidate based on support for the ideal values | 762 // b) Fitness distance for the candidate based on support for the ideal values |
| 794 // of the basic constraint set. | 763 // of the basic constraint set. |
| 795 // c) A custom distance value based on how "well" a candidate satisfies each | 764 // c) A custom distance value based on how "well" a candidate satisfies each |
| 796 // constraint set, including basic and advanced sets. | 765 // constraint set, including basic and advanced sets. |
| 797 // d) Native fitness distance for the candidate based on support for the | 766 // d) Native fitness distance for the candidate based on support for the |
| 798 // ideal values of the basic constraint set using native values for | 767 // ideal values of the basic constraint set using native values for |
| 799 // settings that can support a range of values. | 768 // settings that can support a range of values. |
| 800 // e) A custom distance value based on how close the candidate is to default | 769 // e) A custom distance value based on how close the candidate is to default |
| 801 // settings. | 770 // settings. |
| 802 // Parts (a) and (b) are according to spec. Parts (c) to (e) are | 771 // Parts (a) and (b) are according to spec. Parts (c) to (e) are |
| 803 // implementation specific and used to break ties. | 772 // implementation specific and used to break ties. |
| 804 DistanceVector best_distance(2 * constraints.advanced().size() + 3 + | 773 DistanceVector best_distance(2 * constraints.advanced().size() + 3 + |
| 805 kNumDefaultDistanceEntries); | 774 kNumDefaultDistanceEntries); |
| 806 std::fill(best_distance.begin(), best_distance.end(), HUGE_VAL); | 775 std::fill(best_distance.begin(), best_distance.end(), HUGE_VAL); |
| 807 VideoDeviceCaptureSourceSelectionResult result; | 776 VideoCaptureSettings result; |
| 808 const char* failed_constraint_name = result.failed_constraint_name(); | 777 const char* failed_constraint_name = result.failed_constraint_name(); |
| 809 | 778 |
| 810 for (auto& device : capabilities.device_capabilities) { | 779 for (auto& device : capabilities.device_capabilities) { |
| 811 double basic_device_distance = | 780 double basic_device_distance = |
| 812 DeviceSourceDistance(device->device_id, device->facing_mode, | 781 DeviceSourceDistance(device->device_id, device->facing_mode, |
| 813 constraints.basic(), &failed_constraint_name); | 782 constraints.basic(), &failed_constraint_name); |
| 814 if (!std::isfinite(basic_device_distance)) | 783 if (!std::isfinite(basic_device_distance)) |
| 815 continue; | 784 continue; |
| 816 | 785 |
| 817 for (auto& format : device->formats) { | 786 for (auto& format : device->formats) { |
| 818 ConstrainedFormat constrained_format(format); | 787 ConstrainedFormat constrained_format(format); |
| 819 double basic_format_distance = | 788 double basic_format_distance = |
| 820 FormatSourceDistance(format, constrained_format, constraints.basic(), | 789 FormatSourceDistance(format, constrained_format, constraints.basic(), |
| 821 &failed_constraint_name); | 790 &failed_constraint_name); |
| 822 if (!std::isfinite(basic_format_distance)) | 791 if (!std::isfinite(basic_format_distance)) |
| 823 continue; | 792 continue; |
| 824 constrained_format.ApplyConstraintSet(constraints.basic()); | 793 constrained_format.ApplyConstraintSet(constraints.basic()); |
| 794 DCHECK(!constrained_format.constrained_resolution().IsEmpty()); | |
| 795 DCHECK(!constrained_format.constrained_frame_rate().IsEmpty()); | |
|
hbos_chromium
2017/03/28 12:52:53
(IsEmpty not possible due to isfinite checks, righ
Guido Urdaneta
2017/03/28 18:35:43
That's right.
| |
| 825 | 796 |
| 826 for (auto& power_line_frequency : capabilities.power_line_capabilities) { | 797 for (auto& power_line_frequency : capabilities.power_line_capabilities) { |
| 827 double basic_power_line_frequency_distance = | 798 double basic_power_line_frequency_distance = |
| 828 PowerLineFrequencyConstraintSourceDistance( | 799 PowerLineFrequencyConstraintSourceDistance( |
| 829 constraints.basic().googPowerLineFrequency, | 800 constraints.basic().googPowerLineFrequency, |
| 830 power_line_frequency, &failed_constraint_name); | 801 power_line_frequency, &failed_constraint_name); |
| 831 if (!std::isfinite(basic_power_line_frequency_distance)) | 802 if (!std::isfinite(basic_power_line_frequency_distance)) |
| 832 continue; | 803 continue; |
| 833 | 804 |
| 834 for (auto& noise_reduction : | 805 for (auto& noise_reduction : |
| 835 capabilities.noise_reduction_capabilities) { | 806 capabilities.noise_reduction_capabilities) { |
| 836 double basic_noise_reduction_distance = | 807 double basic_noise_reduction_distance = |
| 837 NoiseReductionConstraintSourceDistance( | 808 NoiseReductionConstraintSourceDistance( |
| 838 constraints.basic().googNoiseReduction, noise_reduction, | 809 constraints.basic().googNoiseReduction, noise_reduction, |
| 839 &failed_constraint_name); | 810 &failed_constraint_name); |
| 840 if (!std::isfinite(basic_noise_reduction_distance)) | 811 if (!std::isfinite(basic_noise_reduction_distance)) |
| 841 continue; | 812 continue; |
| 842 | 813 |
| 843 // The candidate satisfies the basic constraint set. | 814 // The candidate satisfies the basic constraint set. |
| 844 double candidate_basic_custom_distance = | 815 double candidate_basic_custom_distance = |
| 845 basic_device_distance + basic_format_distance + | 816 basic_device_distance + basic_format_distance + |
| 846 basic_power_line_frequency_distance + | 817 basic_power_line_frequency_distance + |
| 847 basic_noise_reduction_distance; | 818 basic_noise_reduction_distance; |
| 848 DCHECK(std::isfinite(candidate_basic_custom_distance)); | 819 DCHECK(std::isfinite(candidate_basic_custom_distance)); |
| 849 | 820 |
| 850 // Temporary vector to save custom distances for advanced constraints. | 821 // Temporary vector to save custom distances for advanced constraints. |
| 851 // Custom distances must be added to the candidate distance vector | 822 // Custom distances must be added to the candidate distance vector |
| 852 // after all the spec-mandated values. | 823 // after all the spec-mandated values. |
| 853 DistanceVector advanced_custom_distance_vector; | 824 DistanceVector advanced_custom_distance_vector; |
| 854 VideoDeviceCaptureSourceSettings candidate( | 825 Candidate candidate(device->device_id, format, device->facing_mode, |
| 855 device->device_id, format, device->facing_mode, | 826 power_line_frequency, noise_reduction); |
| 856 power_line_frequency, noise_reduction); | |
| 857 DistanceVector candidate_distance_vector; | 827 DistanceVector candidate_distance_vector; |
| 858 // First criteria for valid candidates is satisfaction of advanced | 828 // First criteria for valid candidates is satisfaction of advanced |
| 859 // constraint sets. | 829 // constraint sets. |
| 860 for (const auto& advanced_set : constraints.advanced()) { | 830 for (const auto& advanced_set : constraints.advanced()) { |
| 861 double custom_distance = CandidateSourceDistance( | 831 double custom_distance = CandidateSourceDistance( |
| 862 candidate, constrained_format, advanced_set, nullptr); | 832 candidate, constrained_format, advanced_set, nullptr); |
| 863 advanced_custom_distance_vector.push_back(custom_distance); | 833 advanced_custom_distance_vector.push_back(custom_distance); |
| 864 double spec_distance = std::isfinite(custom_distance) ? 0 : 1; | 834 double spec_distance = std::isfinite(custom_distance) ? 0 : 1; |
| 865 candidate_distance_vector.push_back(spec_distance); | 835 candidate_distance_vector.push_back(spec_distance); |
| 866 if (std::isfinite(custom_distance)) | 836 if (std::isfinite(custom_distance)) |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 881 candidate_distance_vector.push_back(CandidateNativeFitnessDistance( | 851 candidate_distance_vector.push_back(CandidateNativeFitnessDistance( |
| 882 constrained_format, constraints.basic())); | 852 constrained_format, constraints.basic())); |
| 883 | 853 |
| 884 // Final criteria are custom distances to default settings. | 854 // Final criteria are custom distances to default settings. |
| 885 AppendDistanceFromDefault(candidate, capabilities, | 855 AppendDistanceFromDefault(candidate, capabilities, |
| 886 &candidate_distance_vector); | 856 &candidate_distance_vector); |
| 887 | 857 |
| 888 DCHECK_EQ(best_distance.size(), candidate_distance_vector.size()); | 858 DCHECK_EQ(best_distance.size(), candidate_distance_vector.size()); |
| 889 if (candidate_distance_vector < best_distance) { | 859 if (candidate_distance_vector < best_distance) { |
| 890 best_distance = candidate_distance_vector; | 860 best_distance = candidate_distance_vector; |
| 891 result = ResultFromSettings(candidate); | 861 result = ComputeVideoDeviceCaptureSettings( |
| 862 candidate, constrained_format, constraints.basic()); | |
| 892 } | 863 } |
| 893 } | 864 } |
| 894 } | 865 } |
| 895 } | 866 } |
| 896 } | 867 } |
| 897 | 868 |
| 898 if (!result.HasValue()) | 869 if (!result.HasValue()) |
| 899 return VideoDeviceCaptureSourceSelectionResult(failed_constraint_name); | 870 return VideoCaptureSettings(failed_constraint_name); |
| 900 | 871 |
| 901 return result; | 872 return result; |
| 902 } | 873 } |
| 903 | 874 |
| 904 } // namespace content | 875 } // namespace content |
| OLD | NEW |