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> | |
8 #include <utility> | |
9 | |
7 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
8 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "content/renderer/media/media_stream_constraints_util_sets.h" | |
9 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" | 13 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" |
10 #include "third_party/WebKit/public/platform/WebString.h" | 14 #include "third_party/WebKit/public/platform/WebString.h" |
11 | 15 |
12 namespace content { | 16 namespace content { |
13 | 17 |
14 namespace { | 18 namespace { |
15 | 19 |
16 template <typename P, typename T> | 20 template <typename P, typename T> |
17 bool ScanConstraintsForExactValue(const blink::WebMediaConstraints& constraints, | 21 bool ScanConstraintsForExactValue(const blink::WebMediaConstraints& constraints, |
18 P picker, | 22 P picker, |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
84 if (the_field.hasExact()) { | 88 if (the_field.hasExact()) { |
85 *value = the_field.exact(); | 89 *value = the_field.exact(); |
86 return true; | 90 return true; |
87 } | 91 } |
88 } | 92 } |
89 return false; | 93 return false; |
90 } | 94 } |
91 | 95 |
92 } // namespace | 96 } // namespace |
93 | 97 |
98 VideoCaptureSettings::VideoCaptureSettings() : VideoCaptureSettings("") {} | |
99 | |
100 VideoCaptureSettings::VideoCaptureSettings(const char* failed_constraint_name) | |
101 : failed_constraint_name_(failed_constraint_name) {} | |
102 | |
103 VideoCaptureSettings::VideoCaptureSettings( | |
104 std::string device_id, | |
105 ::mojom::FacingMode facing_mode, | |
106 media::VideoCaptureParams capture_params, | |
107 base::Optional<bool> noise_reduction, | |
108 const VideoTrackAdapterSettings& track_adapter_settings, | |
109 double min_frame_rate) | |
110 : failed_constraint_name_(nullptr), | |
111 device_id_(std::move(device_id)), | |
112 facing_mode_(facing_mode), | |
113 capture_params_(capture_params), | |
114 noise_reduction_(noise_reduction), | |
115 track_adapter_settings_(track_adapter_settings), | |
116 min_frame_rate_(min_frame_rate) {} | |
hbos_chromium
2017/03/28 12:52:53
Should we DCHECK that the video capture params are
Guido Urdaneta
2017/03/28 18:35:43
We don't support upscaling. The source must provid
| |
117 | |
118 VideoCaptureSettings::VideoCaptureSettings(const VideoCaptureSettings& other) = | |
119 default; | |
120 VideoCaptureSettings::VideoCaptureSettings(VideoCaptureSettings&& other) = | |
121 default; | |
122 VideoCaptureSettings::~VideoCaptureSettings() = default; | |
123 VideoCaptureSettings& VideoCaptureSettings::operator=( | |
124 const VideoCaptureSettings& other) = default; | |
125 VideoCaptureSettings& VideoCaptureSettings::operator=( | |
126 VideoCaptureSettings&& other) = default; | |
127 | |
94 bool GetConstraintValueAsBoolean( | 128 bool GetConstraintValueAsBoolean( |
95 const blink::WebMediaConstraints& constraints, | 129 const blink::WebMediaConstraints& constraints, |
96 const blink::BooleanConstraint blink::WebMediaTrackConstraintSet::*picker, | 130 const blink::BooleanConstraint blink::WebMediaTrackConstraintSet::*picker, |
97 bool* value) { | 131 bool* value) { |
98 return ScanConstraintsForExactValue(constraints, picker, value); | 132 return ScanConstraintsForExactValue(constraints, picker, value); |
99 } | 133 } |
100 | 134 |
101 bool GetConstraintValueAsInteger( | 135 bool GetConstraintValueAsInteger( |
102 const blink::WebMediaConstraints& constraints, | 136 const blink::WebMediaConstraints& constraints, |
103 const blink::LongConstraint blink::WebMediaTrackConstraintSet::*picker, | 137 const blink::LongConstraint blink::WebMediaTrackConstraintSet::*picker, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
155 rtc::Optional<bool> ConstraintToOptional( | 189 rtc::Optional<bool> ConstraintToOptional( |
156 const blink::WebMediaConstraints& constraints, | 190 const blink::WebMediaConstraints& constraints, |
157 const blink::BooleanConstraint blink::WebMediaTrackConstraintSet::*picker) { | 191 const blink::BooleanConstraint blink::WebMediaTrackConstraintSet::*picker) { |
158 bool value; | 192 bool value; |
159 if (GetConstraintValueAsBoolean(constraints, picker, &value)) { | 193 if (GetConstraintValueAsBoolean(constraints, picker, &value)) { |
160 return rtc::Optional<bool>(value); | 194 return rtc::Optional<bool>(value); |
161 } | 195 } |
162 return rtc::Optional<bool>(); | 196 return rtc::Optional<bool>(); |
163 } | 197 } |
164 | 198 |
199 VideoTrackAdapterSettings SelectVideoTrackAdapterSettings( | |
200 const blink::WebMediaTrackConstraintSet& basic_constraint_set, | |
201 const ResolutionSet& resolution_set, | |
202 const NumericRangeSet<double>& frame_rate_set, | |
203 const media::VideoCaptureFormat& source_format) { | |
204 ResolutionSet::Point resolution = resolution_set.SelectClosestPointToIdeal( | |
205 basic_constraint_set, source_format.frame_size.height(), | |
206 source_format.frame_size.width()); | |
207 int track_max_height = static_cast<int>(std::round(resolution.height())); | |
208 int track_max_width = static_cast<int>(std::round(resolution.width())); | |
209 double track_min_aspect_ratio = | |
210 std::max(resolution_set.min_aspect_ratio(), | |
211 static_cast<double>(resolution_set.min_width()) / | |
212 static_cast<double>(resolution_set.max_height())); | |
213 double track_max_aspect_ratio = | |
214 std::min(resolution_set.max_aspect_ratio(), | |
215 static_cast<double>(resolution_set.max_width()) / | |
216 static_cast<double>(resolution_set.min_height())); | |
217 double track_max_frame_rate = frame_rate_set.Max(); | |
218 if (basic_constraint_set.frameRate.hasIdeal()) { | |
219 track_max_frame_rate = std::min( | |
220 track_max_frame_rate, | |
221 std::max(basic_constraint_set.frameRate.ideal(), frame_rate_set.Min())); | |
222 } | |
223 // VideoTrackAdapter uses a frame rate of 0.0 to disable frame-rate | |
224 // adjustment. | |
225 if (track_max_frame_rate >= source_format.frame_rate) | |
226 track_max_frame_rate = 0.0; | |
227 | |
228 return VideoTrackAdapterSettings( | |
229 track_max_width, track_max_height, track_min_aspect_ratio, | |
230 track_max_aspect_ratio, track_max_frame_rate); | |
231 } | |
232 | |
165 } // namespace content | 233 } // namespace content |
OLD | NEW |