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 // Creates a result with the given values. |device_id| is moved to an internal | |
758 // field. | |
759 VideoDeviceCaptureSourceSelectionResult:: | |
760 VideoDeviceCaptureSourceSelectionResult( | |
761 const std::string& device_id, | |
hbos_chromium
2017/03/15 07:54:27
|device_id| is passed as a const& and isn't moved,
Guido Urdaneta
2017/03/15 19:16:47
Done.
| |
762 ::mojom::FacingMode facing_mode, | |
763 media::VideoCaptureParams capture_params, | |
764 rtc::Optional<bool> noise_reduction) | |
765 : failed_constraint_name_(nullptr), | |
766 device_id_(device_id), | |
767 facing_mode_(facing_mode), | |
768 capture_params_(capture_params), | |
769 noise_reduction_(noise_reduction) {} | |
770 | |
757 VideoDeviceCaptureSourceSelectionResult:: | 771 VideoDeviceCaptureSourceSelectionResult:: |
758 VideoDeviceCaptureSourceSelectionResult( | 772 VideoDeviceCaptureSourceSelectionResult( |
759 const VideoDeviceCaptureSourceSelectionResult& other) = default; | 773 const VideoDeviceCaptureSourceSelectionResult& other) = default; |
760 VideoDeviceCaptureSourceSelectionResult:: | 774 VideoDeviceCaptureSourceSelectionResult:: |
761 VideoDeviceCaptureSourceSelectionResult( | 775 VideoDeviceCaptureSourceSelectionResult( |
762 VideoDeviceCaptureSourceSelectionResult&& other) = default; | 776 VideoDeviceCaptureSourceSelectionResult&& other) = default; |
763 VideoDeviceCaptureSourceSelectionResult:: | 777 VideoDeviceCaptureSourceSelectionResult:: |
764 ~VideoDeviceCaptureSourceSelectionResult() = default; | 778 ~VideoDeviceCaptureSourceSelectionResult() = default; |
765 VideoDeviceCaptureSourceSelectionResult& | 779 VideoDeviceCaptureSourceSelectionResult& |
766 VideoDeviceCaptureSourceSelectionResult::operator=( | 780 VideoDeviceCaptureSourceSelectionResult::operator=( |
(...skipping 19 matching lines...) Expand all Loading... | |
786 // ideal values of the basic constraint set using native values for | 800 // ideal values of the basic constraint set using native values for |
787 // settings that can support a range of values. | 801 // settings that can support a range of values. |
788 // e) A custom distance value based on how close the candidate is to default | 802 // e) A custom distance value based on how close the candidate is to default |
789 // settings. | 803 // settings. |
790 // Parts (a) and (b) are according to spec. Parts (c) to (e) are | 804 // Parts (a) and (b) are according to spec. Parts (c) to (e) are |
791 // implementation specific and used to break ties. | 805 // implementation specific and used to break ties. |
792 DistanceVector best_distance(2 * constraints.advanced().size() + 3 + | 806 DistanceVector best_distance(2 * constraints.advanced().size() + 3 + |
793 kNumDefaultDistanceEntries); | 807 kNumDefaultDistanceEntries); |
794 std::fill(best_distance.begin(), best_distance.end(), HUGE_VAL); | 808 std::fill(best_distance.begin(), best_distance.end(), HUGE_VAL); |
795 VideoDeviceCaptureSourceSelectionResult result; | 809 VideoDeviceCaptureSourceSelectionResult result; |
796 const char* failed_constraint_name = result.failed_constraint_name; | 810 const char* failed_constraint_name = result.failed_constraint_name(); |
797 | 811 |
798 for (auto& device : capabilities.device_capabilities) { | 812 for (auto& device : capabilities.device_capabilities) { |
799 double basic_device_distance = | 813 double basic_device_distance = |
800 DeviceSourceDistance(device->device_id, device->facing_mode, | 814 DeviceSourceDistance(device->device_id, device->facing_mode, |
801 constraints.basic(), &failed_constraint_name); | 815 constraints.basic(), &failed_constraint_name); |
802 if (!std::isfinite(basic_device_distance)) | 816 if (!std::isfinite(basic_device_distance)) |
803 continue; | 817 continue; |
804 | 818 |
805 for (auto& format : device->formats) { | 819 for (auto& format : device->formats) { |
806 ConstrainedFormat constrained_format(format); | 820 ConstrainedFormat constrained_format(format); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
877 if (candidate_distance_vector < best_distance) { | 891 if (candidate_distance_vector < best_distance) { |
878 best_distance = candidate_distance_vector; | 892 best_distance = candidate_distance_vector; |
879 result = ResultFromSettings(candidate); | 893 result = ResultFromSettings(candidate); |
880 } | 894 } |
881 } | 895 } |
882 } | 896 } |
883 } | 897 } |
884 } | 898 } |
885 | 899 |
886 if (!result.HasValue()) | 900 if (!result.HasValue()) |
887 result.failed_constraint_name = failed_constraint_name; | 901 return VideoDeviceCaptureSourceSelectionResult(failed_constraint_name); |
888 | 902 |
889 return result; | 903 return result; |
890 } | 904 } |
891 | 905 |
892 } // namespace content | 906 } // namespace content |
OLD | NEW |