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> |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 long native_width_; | 167 long native_width_; |
168 long min_width_; | 168 long min_width_; |
169 long max_width_; | 169 long max_width_; |
170 double native_frame_rate_; | 170 double native_frame_rate_; |
171 double min_frame_rate_; | 171 double min_frame_rate_; |
172 double max_frame_rate_; | 172 double max_frame_rate_; |
173 }; | 173 }; |
174 | 174 |
175 VideoDeviceCaptureSourceSelectionResult ResultFromSettings( | 175 VideoDeviceCaptureSourceSelectionResult ResultFromSettings( |
176 const VideoDeviceCaptureSourceSettings& settings) { | 176 const VideoDeviceCaptureSourceSettings& settings) { |
177 VideoDeviceCaptureSourceSelectionResult result; | 177 media::VideoCaptureParams capture_params; |
178 result.capture_params.power_line_frequency = settings.power_line_frequency(); | 178 capture_params.requested_format = settings.format(); |
179 result.capture_params.requested_format = settings.format(); | 179 capture_params.power_line_frequency = settings.power_line_frequency(); |
180 result.device_id = settings.device_id(); | |
181 result.facing_mode = settings.facing_mode(); | |
182 result.noise_reduction = settings.noise_reduction(); | |
183 result.failed_constraint_name = nullptr; | |
184 | 180 |
185 return result; | 181 return VideoDeviceCaptureSourceSelectionResult( |
| 182 settings.device_id(), settings.facing_mode(), capture_params, |
| 183 settings.noise_reduction()); |
186 } | 184 } |
187 | 185 |
188 // Generic distance function between two numeric values. Based on the fitness | 186 // Generic distance function between two numeric values. Based on the fitness |
189 // distance function described in | 187 // distance function described in |
190 // https://w3c.github.io/mediacapture-main/#dfn-fitness-distance | 188 // https://w3c.github.io/mediacapture-main/#dfn-fitness-distance |
191 double Distance(double value1, double value2) { | 189 double Distance(double value1, double value2) { |
192 if (std::fabs(value1 - value2) <= blink::DoubleConstraint::kConstraintEpsilon) | 190 if (std::fabs(value1 - value2) <= blink::DoubleConstraint::kConstraintEpsilon) |
193 return 0.0; | 191 return 0.0; |
194 | 192 |
195 return std::fabs(value1 - value2) / | 193 return std::fabs(value1 - value2) / |
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
741 : blink::WebString::fromASCII(kVideoKindColor); | 739 : blink::WebString::fromASCII(kVideoKindColor); |
742 } | 740 } |
743 | 741 |
744 VideoDeviceCaptureCapabilities::VideoDeviceCaptureCapabilities() = default; | 742 VideoDeviceCaptureCapabilities::VideoDeviceCaptureCapabilities() = default; |
745 VideoDeviceCaptureCapabilities::VideoDeviceCaptureCapabilities( | 743 VideoDeviceCaptureCapabilities::VideoDeviceCaptureCapabilities( |
746 VideoDeviceCaptureCapabilities&& other) = default; | 744 VideoDeviceCaptureCapabilities&& other) = default; |
747 VideoDeviceCaptureCapabilities::~VideoDeviceCaptureCapabilities() = default; | 745 VideoDeviceCaptureCapabilities::~VideoDeviceCaptureCapabilities() = default; |
748 VideoDeviceCaptureCapabilities& VideoDeviceCaptureCapabilities::operator=( | 746 VideoDeviceCaptureCapabilities& VideoDeviceCaptureCapabilities::operator=( |
749 VideoDeviceCaptureCapabilities&& other) = default; | 747 VideoDeviceCaptureCapabilities&& other) = default; |
750 | 748 |
751 const char kDefaultFailedConstraintName[] = ""; | 749 VideoDeviceCaptureSourceSelectionResult:: |
| 750 VideoDeviceCaptureSourceSelectionResult() |
| 751 : VideoDeviceCaptureSourceSelectionResult("") {} |
752 | 752 |
753 VideoDeviceCaptureSourceSelectionResult:: | 753 VideoDeviceCaptureSourceSelectionResult:: |
754 VideoDeviceCaptureSourceSelectionResult() | 754 VideoDeviceCaptureSourceSelectionResult(const char* failed_constraint_name) |
755 : failed_constraint_name(kDefaultFailedConstraintName), | 755 : failed_constraint_name_(failed_constraint_name) {} |
756 facing_mode(::mojom::FacingMode::NONE) {} | 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 |
757 VideoDeviceCaptureSourceSelectionResult:: | 769 VideoDeviceCaptureSourceSelectionResult:: |
758 VideoDeviceCaptureSourceSelectionResult( | 770 VideoDeviceCaptureSourceSelectionResult( |
759 const VideoDeviceCaptureSourceSelectionResult& other) = default; | 771 const VideoDeviceCaptureSourceSelectionResult& other) = default; |
760 VideoDeviceCaptureSourceSelectionResult:: | 772 VideoDeviceCaptureSourceSelectionResult:: |
761 VideoDeviceCaptureSourceSelectionResult( | 773 VideoDeviceCaptureSourceSelectionResult( |
762 VideoDeviceCaptureSourceSelectionResult&& other) = default; | 774 VideoDeviceCaptureSourceSelectionResult&& other) = default; |
763 VideoDeviceCaptureSourceSelectionResult:: | 775 VideoDeviceCaptureSourceSelectionResult:: |
764 ~VideoDeviceCaptureSourceSelectionResult() = default; | 776 ~VideoDeviceCaptureSourceSelectionResult() = default; |
765 VideoDeviceCaptureSourceSelectionResult& | 777 VideoDeviceCaptureSourceSelectionResult& |
766 VideoDeviceCaptureSourceSelectionResult::operator=( | 778 VideoDeviceCaptureSourceSelectionResult::operator=( |
(...skipping 19 matching lines...) Expand all Loading... |
786 // ideal values of the basic constraint set using native values for | 798 // ideal values of the basic constraint set using native values for |
787 // settings that can support a range of values. | 799 // settings that can support a range of values. |
788 // e) A custom distance value based on how close the candidate is to default | 800 // e) A custom distance value based on how close the candidate is to default |
789 // settings. | 801 // settings. |
790 // Parts (a) and (b) are according to spec. Parts (c) to (e) are | 802 // Parts (a) and (b) are according to spec. Parts (c) to (e) are |
791 // implementation specific and used to break ties. | 803 // implementation specific and used to break ties. |
792 DistanceVector best_distance(2 * constraints.advanced().size() + 3 + | 804 DistanceVector best_distance(2 * constraints.advanced().size() + 3 + |
793 kNumDefaultDistanceEntries); | 805 kNumDefaultDistanceEntries); |
794 std::fill(best_distance.begin(), best_distance.end(), HUGE_VAL); | 806 std::fill(best_distance.begin(), best_distance.end(), HUGE_VAL); |
795 VideoDeviceCaptureSourceSelectionResult result; | 807 VideoDeviceCaptureSourceSelectionResult result; |
796 const char* failed_constraint_name = result.failed_constraint_name; | 808 const char* failed_constraint_name = result.failed_constraint_name(); |
797 | 809 |
798 for (auto& device : capabilities.device_capabilities) { | 810 for (auto& device : capabilities.device_capabilities) { |
799 double basic_device_distance = | 811 double basic_device_distance = |
800 DeviceSourceDistance(device->device_id, device->facing_mode, | 812 DeviceSourceDistance(device->device_id, device->facing_mode, |
801 constraints.basic(), &failed_constraint_name); | 813 constraints.basic(), &failed_constraint_name); |
802 if (!std::isfinite(basic_device_distance)) | 814 if (!std::isfinite(basic_device_distance)) |
803 continue; | 815 continue; |
804 | 816 |
805 for (auto& format : device->formats) { | 817 for (auto& format : device->formats) { |
806 ConstrainedFormat constrained_format(format); | 818 ConstrainedFormat constrained_format(format); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
877 if (candidate_distance_vector < best_distance) { | 889 if (candidate_distance_vector < best_distance) { |
878 best_distance = candidate_distance_vector; | 890 best_distance = candidate_distance_vector; |
879 result = ResultFromSettings(candidate); | 891 result = ResultFromSettings(candidate); |
880 } | 892 } |
881 } | 893 } |
882 } | 894 } |
883 } | 895 } |
884 } | 896 } |
885 | 897 |
886 if (!result.HasValue()) | 898 if (!result.HasValue()) |
887 result.failed_constraint_name = failed_constraint_name; | 899 return VideoDeviceCaptureSourceSelectionResult(failed_constraint_name); |
888 | 900 |
889 return result; | 901 return result; |
890 } | 902 } |
891 | 903 |
892 } // namespace content | 904 } // namespace content |
OLD | NEW |