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_source.h" | 5 #include "content/renderer/media/media_stream_constraints_util_video_device.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/optional.h" | 10 #include "base/optional.h" |
11 #include "content/renderer/media/media_stream_video_source.h" | 11 #include "content/renderer/media/media_stream_video_source.h" |
12 #include "content/renderer/media/mock_constraint_factory.h" | 12 #include "content/renderer/media/mock_constraint_factory.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" | 14 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" |
15 | 15 |
16 namespace content { | 16 namespace content { |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 const char kDeviceID1[] = "fake_device_1"; | 20 const char kDeviceID1[] = "fake_device_1"; |
21 const char kDeviceID2[] = "fake_device_2"; | 21 const char kDeviceID2[] = "fake_device_2"; |
22 const char kDeviceID3[] = "fake_device_3"; | 22 const char kDeviceID3[] = "fake_device_3"; |
23 const char kDeviceID4[] = "fake_device_4"; | 23 const char kDeviceID4[] = "fake_device_4"; |
24 } | 24 } |
25 | 25 |
26 class MediaStreamConstraintsUtilVideoSourceTest : public testing::Test { | 26 class MediaStreamConstraintsUtilVideoDeviceTest : public testing::Test { |
27 public: | 27 public: |
28 void SetUp() override { | 28 void SetUp() override { |
29 // Default device. It is default because it is the first in the enumeration. | 29 // Default device. It is default because it is the first in the enumeration. |
30 ::mojom::VideoInputDeviceCapabilitiesPtr device = | 30 ::mojom::VideoInputDeviceCapabilitiesPtr device = |
31 ::mojom::VideoInputDeviceCapabilities::New(); | 31 ::mojom::VideoInputDeviceCapabilities::New(); |
32 device->device_id = kDeviceID1; | 32 device->device_id = kDeviceID1; |
33 device->facing_mode = ::mojom::FacingMode::NONE; | 33 device->facing_mode = ::mojom::FacingMode::NONE; |
34 device->formats = { | 34 device->formats = { |
35 media::VideoCaptureFormat(gfx::Size(200, 200), 40.0f, | 35 media::VideoCaptureFormat(gfx::Size(200, 200), 40.0f, |
36 media::PIXEL_FORMAT_I420), | 36 media::PIXEL_FORMAT_I420), |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 default_device_ = capabilities_.device_capabilities[0].get(); | 103 default_device_ = capabilities_.device_capabilities[0].get(); |
104 low_res_device_ = capabilities_.device_capabilities[1].get(); | 104 low_res_device_ = capabilities_.device_capabilities[1].get(); |
105 high_res_device_ = capabilities_.device_capabilities[2].get(); | 105 high_res_device_ = capabilities_.device_capabilities[2].get(); |
106 default_closest_format_ = &default_device_->formats[1]; | 106 default_closest_format_ = &default_device_->formats[1]; |
107 low_res_closest_format_ = &low_res_device_->formats[2]; | 107 low_res_closest_format_ = &low_res_device_->formats[2]; |
108 high_res_closest_format_ = &high_res_device_->formats[2]; | 108 high_res_closest_format_ = &high_res_device_->formats[2]; |
109 high_res_highest_format_ = &high_res_device_->formats[5]; | 109 high_res_highest_format_ = &high_res_device_->formats[5]; |
110 } | 110 } |
111 | 111 |
112 protected: | 112 protected: |
113 VideoCaptureSourceSelectionResult SelectSettings() { | 113 VideoDeviceCaptureSourceSelectionResult SelectSettings() { |
114 blink::WebMediaConstraints constraints = | 114 blink::WebMediaConstraints constraints = |
115 constraint_factory_.CreateWebMediaConstraints(); | 115 constraint_factory_.CreateWebMediaConstraints(); |
116 return SelectVideoCaptureSourceSettings(capabilities_, constraints); | 116 return SelectVideoDeviceCaptureSourceSettings(capabilities_, constraints); |
117 } | 117 } |
118 | 118 |
119 VideoCaptureCapabilities capabilities_; | 119 VideoDeviceCaptureCapabilities capabilities_; |
120 const mojom::VideoInputDeviceCapabilities* default_device_; | 120 const mojom::VideoInputDeviceCapabilities* default_device_; |
121 const mojom::VideoInputDeviceCapabilities* low_res_device_; | 121 const mojom::VideoInputDeviceCapabilities* low_res_device_; |
122 const mojom::VideoInputDeviceCapabilities* high_res_device_; | 122 const mojom::VideoInputDeviceCapabilities* high_res_device_; |
123 // Closest formats to the default settings. | 123 // Closest formats to the default settings. |
124 const media::VideoCaptureFormat* default_closest_format_; | 124 const media::VideoCaptureFormat* default_closest_format_; |
125 const media::VideoCaptureFormat* low_res_closest_format_; | 125 const media::VideoCaptureFormat* low_res_closest_format_; |
126 const media::VideoCaptureFormat* high_res_closest_format_; | 126 const media::VideoCaptureFormat* high_res_closest_format_; |
127 const media::VideoCaptureFormat* high_res_highest_format_; | 127 const media::VideoCaptureFormat* high_res_highest_format_; |
128 | 128 |
129 MockConstraintFactory constraint_factory_; | 129 MockConstraintFactory constraint_factory_; |
130 }; | 130 }; |
131 | 131 |
132 // The Unconstrained test checks the default selection criteria. | 132 // The Unconstrained test checks the default selection criteria. |
133 TEST_F(MediaStreamConstraintsUtilVideoSourceTest, Unconstrained) { | 133 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, Unconstrained) { |
134 constraint_factory_.Reset(); | 134 constraint_factory_.Reset(); |
135 auto result = SelectSettings(); | 135 auto result = SelectSettings(); |
136 EXPECT_TRUE(result.has_value()); | 136 EXPECT_TRUE(result.HasValue()); |
137 // Should select the default device with closest-to-default settings. | 137 // Should select the default device with closest-to-default settings. |
138 EXPECT_EQ(default_device_->device_id, result.settings.device_id()); | 138 EXPECT_EQ(default_device_->device_id, result.device_id); |
139 EXPECT_EQ(default_device_->facing_mode, result.settings.facing_mode()); | 139 EXPECT_EQ(default_device_->facing_mode, result.facing_mode); |
140 EXPECT_EQ(*default_closest_format_, result.settings.format()); | 140 EXPECT_EQ(*default_closest_format_, result.Format()); |
141 } | 141 } |
142 | 142 |
143 // The "Overconstrained" tests verify that failure of any single required | 143 // The "Overconstrained" tests verify that failure of any single required |
144 // constraint results in failure to select a candidate. | 144 // constraint results in failure to select a candidate. |
145 TEST_F(MediaStreamConstraintsUtilVideoSourceTest, OverconstrainedOnDeviceID) { | 145 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, OverconstrainedOnDeviceID) { |
146 constraint_factory_.Reset(); | 146 constraint_factory_.Reset(); |
147 constraint_factory_.basic().deviceId.setExact( | 147 constraint_factory_.basic().deviceId.setExact( |
148 blink::WebString::fromASCII("NONEXISTING")); | 148 blink::WebString::fromASCII("NONEXISTING")); |
149 auto result = SelectSettings(); | 149 auto result = SelectSettings(); |
150 EXPECT_FALSE(result.has_value()); | 150 EXPECT_FALSE(result.HasValue()); |
151 EXPECT_EQ(constraint_factory_.basic().deviceId.name(), | 151 EXPECT_EQ(constraint_factory_.basic().deviceId.name(), |
152 result.failed_constraint_name); | 152 result.failed_constraint_name); |
153 } | 153 } |
154 | 154 |
155 TEST_F(MediaStreamConstraintsUtilVideoSourceTest, OverconstrainedOnFacingMode) { | 155 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, OverconstrainedOnFacingMode) { |
156 constraint_factory_.Reset(); | 156 constraint_factory_.Reset(); |
157 // No device in |capabilities_| has facing mode equal to LEFT. | 157 // No device in |capabilities_| has facing mode equal to LEFT. |
158 constraint_factory_.basic().facingMode.setExact( | 158 constraint_factory_.basic().facingMode.setExact( |
159 blink::WebString::fromASCII("left")); | 159 blink::WebString::fromASCII("left")); |
160 auto result = SelectSettings(); | 160 auto result = SelectSettings(); |
161 EXPECT_FALSE(result.has_value()); | 161 EXPECT_FALSE(result.HasValue()); |
162 EXPECT_EQ(constraint_factory_.basic().facingMode.name(), | 162 EXPECT_EQ(constraint_factory_.basic().facingMode.name(), |
163 result.failed_constraint_name); | 163 result.failed_constraint_name); |
164 } | 164 } |
165 | 165 |
166 TEST_F(MediaStreamConstraintsUtilVideoSourceTest, OverconstrainedOnVideoKind) { | 166 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, OverconstrainedOnVideoKind) { |
167 constraint_factory_.Reset(); | 167 constraint_factory_.Reset(); |
168 // No device in |capabilities_| has video kind infrared. | 168 // No device in |capabilities_| has video kind infrared. |
169 constraint_factory_.basic().videoKind.setExact( | 169 constraint_factory_.basic().videoKind.setExact( |
170 blink::WebString::fromASCII("infrared")); | 170 blink::WebString::fromASCII("infrared")); |
171 auto result = SelectSettings(); | 171 auto result = SelectSettings(); |
172 EXPECT_FALSE(result.has_value()); | 172 EXPECT_FALSE(result.HasValue()); |
173 EXPECT_EQ(constraint_factory_.basic().videoKind.name(), | 173 EXPECT_EQ(constraint_factory_.basic().videoKind.name(), |
174 result.failed_constraint_name); | 174 result.failed_constraint_name); |
175 } | 175 } |
176 | 176 |
177 TEST_F(MediaStreamConstraintsUtilVideoSourceTest, OverconstrainedOnHeight) { | 177 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, OverconstrainedOnHeight) { |
178 constraint_factory_.Reset(); | 178 constraint_factory_.Reset(); |
179 constraint_factory_.basic().height.setExact(123467890); | 179 constraint_factory_.basic().height.setExact(123467890); |
180 auto result = SelectSettings(); | 180 auto result = SelectSettings(); |
181 EXPECT_FALSE(result.has_value()); | 181 EXPECT_FALSE(result.HasValue()); |
182 EXPECT_EQ(constraint_factory_.basic().height.name(), | 182 EXPECT_EQ(constraint_factory_.basic().height.name(), |
183 result.failed_constraint_name); | 183 result.failed_constraint_name); |
184 | 184 |
185 constraint_factory_.Reset(); | 185 constraint_factory_.Reset(); |
186 constraint_factory_.basic().height.setMin(123467890); | 186 constraint_factory_.basic().height.setMin(123467890); |
187 result = SelectSettings(); | 187 result = SelectSettings(); |
188 EXPECT_FALSE(result.has_value()); | 188 EXPECT_FALSE(result.HasValue()); |
189 EXPECT_EQ(constraint_factory_.basic().height.name(), | 189 EXPECT_EQ(constraint_factory_.basic().height.name(), |
190 result.failed_constraint_name); | 190 result.failed_constraint_name); |
191 | 191 |
192 constraint_factory_.Reset(); | 192 constraint_factory_.Reset(); |
193 constraint_factory_.basic().height.setMax(0); | 193 constraint_factory_.basic().height.setMax(0); |
194 result = SelectSettings(); | 194 result = SelectSettings(); |
195 EXPECT_FALSE(result.has_value()); | 195 EXPECT_FALSE(result.HasValue()); |
196 EXPECT_EQ(constraint_factory_.basic().height.name(), | 196 EXPECT_EQ(constraint_factory_.basic().height.name(), |
197 result.failed_constraint_name); | 197 result.failed_constraint_name); |
198 } | 198 } |
199 | 199 |
200 TEST_F(MediaStreamConstraintsUtilVideoSourceTest, OverconstrainedOnWidth) { | 200 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, OverconstrainedOnWidth) { |
201 constraint_factory_.Reset(); | 201 constraint_factory_.Reset(); |
202 constraint_factory_.basic().width.setExact(123467890); | 202 constraint_factory_.basic().width.setExact(123467890); |
203 auto result = SelectSettings(); | 203 auto result = SelectSettings(); |
204 EXPECT_FALSE(result.has_value()); | 204 EXPECT_FALSE(result.HasValue()); |
205 EXPECT_EQ(constraint_factory_.basic().width.name(), | 205 EXPECT_EQ(constraint_factory_.basic().width.name(), |
206 result.failed_constraint_name); | 206 result.failed_constraint_name); |
207 | 207 |
208 constraint_factory_.Reset(); | 208 constraint_factory_.Reset(); |
209 constraint_factory_.basic().width.setMin(123467890); | 209 constraint_factory_.basic().width.setMin(123467890); |
210 result = SelectSettings(); | 210 result = SelectSettings(); |
211 EXPECT_FALSE(result.has_value()); | 211 EXPECT_FALSE(result.HasValue()); |
212 EXPECT_EQ(constraint_factory_.basic().width.name(), | 212 EXPECT_EQ(constraint_factory_.basic().width.name(), |
213 result.failed_constraint_name); | 213 result.failed_constraint_name); |
214 | 214 |
215 constraint_factory_.Reset(); | 215 constraint_factory_.Reset(); |
216 constraint_factory_.basic().width.setMax(0); | 216 constraint_factory_.basic().width.setMax(0); |
217 result = SelectSettings(); | 217 result = SelectSettings(); |
218 EXPECT_FALSE(result.has_value()); | 218 EXPECT_FALSE(result.HasValue()); |
219 EXPECT_EQ(constraint_factory_.basic().width.name(), | 219 EXPECT_EQ(constraint_factory_.basic().width.name(), |
220 result.failed_constraint_name); | 220 result.failed_constraint_name); |
221 } | 221 } |
222 | 222 |
223 TEST_F(MediaStreamConstraintsUtilVideoSourceTest, | 223 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, |
224 OverconstrainedOnAspectRatio) { | 224 OverconstrainedOnAspectRatio) { |
225 constraint_factory_.Reset(); | 225 constraint_factory_.Reset(); |
226 constraint_factory_.basic().aspectRatio.setExact(123467890.0); | 226 constraint_factory_.basic().aspectRatio.setExact(123467890.0); |
227 auto result = SelectSettings(); | 227 auto result = SelectSettings(); |
228 EXPECT_FALSE(result.has_value()); | 228 EXPECT_FALSE(result.HasValue()); |
229 EXPECT_EQ(constraint_factory_.basic().aspectRatio.name(), | 229 EXPECT_EQ(constraint_factory_.basic().aspectRatio.name(), |
230 result.failed_constraint_name); | 230 result.failed_constraint_name); |
231 | 231 |
232 constraint_factory_.Reset(); | 232 constraint_factory_.Reset(); |
233 constraint_factory_.basic().aspectRatio.setMin(123467890.0); | 233 constraint_factory_.basic().aspectRatio.setMin(123467890.0); |
234 result = SelectSettings(); | 234 result = SelectSettings(); |
235 EXPECT_FALSE(result.has_value()); | 235 EXPECT_FALSE(result.HasValue()); |
236 EXPECT_EQ(constraint_factory_.basic().aspectRatio.name(), | 236 EXPECT_EQ(constraint_factory_.basic().aspectRatio.name(), |
237 result.failed_constraint_name); | 237 result.failed_constraint_name); |
238 | 238 |
239 constraint_factory_.Reset(); | 239 constraint_factory_.Reset(); |
240 // This value is lower than the minimum supported by sources. | 240 // This value is lower than the minimum supported by sources. |
241 double kLowAspectRatio = 0.01; | 241 double kLowAspectRatio = 0.01; |
242 constraint_factory_.basic().aspectRatio.setMax(kLowAspectRatio); | 242 constraint_factory_.basic().aspectRatio.setMax(kLowAspectRatio); |
243 result = SelectSettings(); | 243 result = SelectSettings(); |
244 EXPECT_FALSE(result.has_value()); | 244 EXPECT_FALSE(result.HasValue()); |
245 EXPECT_EQ(constraint_factory_.basic().aspectRatio.name(), | 245 EXPECT_EQ(constraint_factory_.basic().aspectRatio.name(), |
246 result.failed_constraint_name); | 246 result.failed_constraint_name); |
247 } | 247 } |
248 | 248 |
249 TEST_F(MediaStreamConstraintsUtilVideoSourceTest, OverconstrainedOnFrameRate) { | 249 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, OverconstrainedOnFrameRate) { |
250 constraint_factory_.Reset(); | 250 constraint_factory_.Reset(); |
251 constraint_factory_.basic().frameRate.setExact(123467890.0); | 251 constraint_factory_.basic().frameRate.setExact(123467890.0); |
252 auto result = SelectSettings(); | 252 auto result = SelectSettings(); |
253 EXPECT_FALSE(result.has_value()); | 253 EXPECT_FALSE(result.HasValue()); |
254 EXPECT_EQ(constraint_factory_.basic().frameRate.name(), | 254 EXPECT_EQ(constraint_factory_.basic().frameRate.name(), |
255 result.failed_constraint_name); | 255 result.failed_constraint_name); |
256 | 256 |
257 constraint_factory_.Reset(); | 257 constraint_factory_.Reset(); |
258 constraint_factory_.basic().frameRate.setMin(123467890.0); | 258 constraint_factory_.basic().frameRate.setMin(123467890.0); |
259 result = SelectSettings(); | 259 result = SelectSettings(); |
260 EXPECT_FALSE(result.has_value()); | 260 EXPECT_FALSE(result.HasValue()); |
261 EXPECT_EQ(constraint_factory_.basic().frameRate.name(), | 261 EXPECT_EQ(constraint_factory_.basic().frameRate.name(), |
262 result.failed_constraint_name); | 262 result.failed_constraint_name); |
263 | 263 |
264 constraint_factory_.Reset(); | 264 constraint_factory_.Reset(); |
265 constraint_factory_.basic().frameRate.setMax(0.0); | 265 constraint_factory_.basic().frameRate.setMax(0.0); |
266 result = SelectSettings(); | 266 result = SelectSettings(); |
267 EXPECT_FALSE(result.has_value()); | 267 EXPECT_FALSE(result.HasValue()); |
268 EXPECT_EQ(constraint_factory_.basic().frameRate.name(), | 268 EXPECT_EQ(constraint_factory_.basic().frameRate.name(), |
269 result.failed_constraint_name); | 269 result.failed_constraint_name); |
270 } | 270 } |
271 | 271 |
272 TEST_F(MediaStreamConstraintsUtilVideoSourceTest, | 272 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, |
273 OverconstrainedOnPowerLineFrequency) { | 273 OverconstrainedOnPowerLineFrequency) { |
274 constraint_factory_.Reset(); | 274 constraint_factory_.Reset(); |
275 constraint_factory_.basic().googPowerLineFrequency.setExact(123467890); | 275 constraint_factory_.basic().googPowerLineFrequency.setExact(123467890); |
276 auto result = SelectSettings(); | 276 auto result = SelectSettings(); |
277 EXPECT_FALSE(result.has_value()); | 277 EXPECT_FALSE(result.HasValue()); |
278 EXPECT_EQ(constraint_factory_.basic().googPowerLineFrequency.name(), | 278 EXPECT_EQ(constraint_factory_.basic().googPowerLineFrequency.name(), |
279 result.failed_constraint_name); | 279 result.failed_constraint_name); |
280 | 280 |
281 constraint_factory_.Reset(); | 281 constraint_factory_.Reset(); |
282 constraint_factory_.basic().googPowerLineFrequency.setMin(123467890); | 282 constraint_factory_.basic().googPowerLineFrequency.setMin(123467890); |
283 result = SelectSettings(); | 283 result = SelectSettings(); |
284 EXPECT_FALSE(result.has_value()); | 284 EXPECT_FALSE(result.HasValue()); |
285 EXPECT_EQ(constraint_factory_.basic().googPowerLineFrequency.name(), | 285 EXPECT_EQ(constraint_factory_.basic().googPowerLineFrequency.name(), |
286 result.failed_constraint_name); | 286 result.failed_constraint_name); |
287 | 287 |
288 constraint_factory_.Reset(); | 288 constraint_factory_.Reset(); |
289 constraint_factory_.basic().googPowerLineFrequency.setMax(-1); | 289 constraint_factory_.basic().googPowerLineFrequency.setMax(-1); |
290 result = SelectSettings(); | 290 result = SelectSettings(); |
291 EXPECT_FALSE(result.has_value()); | 291 EXPECT_FALSE(result.HasValue()); |
292 EXPECT_EQ(constraint_factory_.basic().googPowerLineFrequency.name(), | 292 EXPECT_EQ(constraint_factory_.basic().googPowerLineFrequency.name(), |
293 result.failed_constraint_name); | 293 result.failed_constraint_name); |
294 } | 294 } |
295 | 295 |
296 // The "Mandatory" and "Ideal" tests check that various selection criteria work | 296 // The "Mandatory" and "Ideal" tests check that various selection criteria work |
297 // for each individual constraint in the basic constraint set. | 297 // for each individual constraint in the basic constraint set. |
298 TEST_F(MediaStreamConstraintsUtilVideoSourceTest, MandatoryDeviceID) { | 298 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryDeviceID) { |
299 constraint_factory_.Reset(); | 299 constraint_factory_.Reset(); |
300 constraint_factory_.basic().deviceId.setExact( | 300 constraint_factory_.basic().deviceId.setExact( |
301 blink::WebString::fromASCII(default_device_->device_id)); | 301 blink::WebString::fromASCII(default_device_->device_id)); |
302 auto result = SelectSettings(); | 302 auto result = SelectSettings(); |
303 EXPECT_TRUE(result.has_value()); | 303 EXPECT_TRUE(result.HasValue()); |
304 EXPECT_EQ(default_device_->device_id, result.settings.device_id()); | 304 EXPECT_EQ(default_device_->device_id, result.device_id); |
305 EXPECT_EQ(*default_closest_format_, result.settings.format()); | 305 EXPECT_EQ(*default_closest_format_, result.Format()); |
306 EXPECT_EQ(media::PowerLineFrequency::FREQUENCY_DEFAULT, | 306 EXPECT_EQ(media::PowerLineFrequency::FREQUENCY_DEFAULT, |
307 result.settings.power_line_frequency()); | 307 result.PowerLineFrequency()); |
308 | 308 |
309 constraint_factory_.basic().deviceId.setExact( | 309 constraint_factory_.basic().deviceId.setExact( |
310 blink::WebString::fromASCII(low_res_device_->device_id)); | 310 blink::WebString::fromASCII(low_res_device_->device_id)); |
311 result = SelectSettings(); | 311 result = SelectSettings(); |
312 EXPECT_EQ(low_res_device_->device_id, result.settings.device_id()); | 312 EXPECT_EQ(low_res_device_->device_id, result.device_id); |
313 EXPECT_EQ(*low_res_closest_format_, result.settings.format()); | 313 EXPECT_EQ(*low_res_closest_format_, result.Format()); |
314 EXPECT_EQ(media::PowerLineFrequency::FREQUENCY_DEFAULT, | 314 EXPECT_EQ(media::PowerLineFrequency::FREQUENCY_DEFAULT, |
315 result.settings.power_line_frequency()); | 315 result.PowerLineFrequency()); |
316 | 316 |
317 constraint_factory_.basic().deviceId.setExact( | 317 constraint_factory_.basic().deviceId.setExact( |
318 blink::WebString::fromASCII(high_res_device_->device_id)); | 318 blink::WebString::fromASCII(high_res_device_->device_id)); |
319 result = SelectSettings(); | 319 result = SelectSettings(); |
320 EXPECT_EQ(high_res_device_->device_id, result.settings.device_id()); | 320 EXPECT_EQ(high_res_device_->device_id, result.device_id); |
321 EXPECT_EQ(*high_res_closest_format_, result.settings.format()); | 321 EXPECT_EQ(*high_res_closest_format_, result.Format()); |
322 EXPECT_EQ(media::PowerLineFrequency::FREQUENCY_DEFAULT, | 322 EXPECT_EQ(media::PowerLineFrequency::FREQUENCY_DEFAULT, |
323 result.settings.power_line_frequency()); | 323 result.PowerLineFrequency()); |
324 } | 324 } |
325 | 325 |
326 TEST_F(MediaStreamConstraintsUtilVideoSourceTest, MandatoryFacingMode) { | 326 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryFacingMode) { |
327 constraint_factory_.Reset(); | 327 constraint_factory_.Reset(); |
328 constraint_factory_.basic().facingMode.setExact( | 328 constraint_factory_.basic().facingMode.setExact( |
329 blink::WebString::fromASCII("environment")); | 329 blink::WebString::fromASCII("environment")); |
330 auto result = SelectSettings(); | 330 auto result = SelectSettings(); |
331 EXPECT_TRUE(result.has_value()); | 331 EXPECT_TRUE(result.HasValue()); |
332 EXPECT_EQ(::mojom::FacingMode::ENVIRONMENT, result.settings.facing_mode()); | 332 EXPECT_EQ(::mojom::FacingMode::ENVIRONMENT, result.facing_mode); |
333 // Only the low-res device supports environment facing mode. Should select | 333 // Only the low-res device supports environment facing mode. Should select |
334 // default settings for everything else. | 334 // default settings for everything else. |
335 EXPECT_EQ(low_res_device_->device_id, result.settings.device_id()); | 335 EXPECT_EQ(low_res_device_->device_id, result.device_id); |
336 EXPECT_EQ(*low_res_closest_format_, result.settings.format()); | 336 EXPECT_EQ(*low_res_closest_format_, result.Format()); |
337 EXPECT_EQ(media::PowerLineFrequency::FREQUENCY_DEFAULT, | 337 EXPECT_EQ(media::PowerLineFrequency::FREQUENCY_DEFAULT, |
338 result.settings.power_line_frequency()); | 338 result.PowerLineFrequency()); |
339 | 339 |
340 constraint_factory_.basic().facingMode.setExact( | 340 constraint_factory_.basic().facingMode.setExact( |
341 blink::WebString::fromASCII("user")); | 341 blink::WebString::fromASCII("user")); |
342 result = SelectSettings(); | 342 result = SelectSettings(); |
343 EXPECT_TRUE(result.has_value()); | 343 EXPECT_TRUE(result.HasValue()); |
344 EXPECT_EQ(::mojom::FacingMode::USER, result.settings.facing_mode()); | 344 EXPECT_EQ(::mojom::FacingMode::USER, result.facing_mode); |
345 // Only the high-res device supports user facing mode. Should select default | 345 // Only the high-res device supports user facing mode. Should select default |
346 // settings for everything else. | 346 // settings for everything else. |
347 EXPECT_EQ(high_res_device_->device_id, result.settings.device_id()); | 347 EXPECT_EQ(high_res_device_->device_id, result.device_id); |
348 EXPECT_EQ(*high_res_closest_format_, result.settings.format()); | 348 EXPECT_EQ(*high_res_closest_format_, result.Format()); |
349 EXPECT_EQ(media::PowerLineFrequency::FREQUENCY_DEFAULT, | 349 EXPECT_EQ(media::PowerLineFrequency::FREQUENCY_DEFAULT, |
350 result.settings.power_line_frequency()); | 350 result.PowerLineFrequency()); |
351 } | 351 } |
352 | 352 |
353 TEST_F(MediaStreamConstraintsUtilVideoSourceTest, MandatoryVideoKind) { | 353 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryVideoKind) { |
354 constraint_factory_.Reset(); | 354 constraint_factory_.Reset(); |
355 constraint_factory_.basic().videoKind.setExact( | 355 constraint_factory_.basic().videoKind.setExact( |
356 blink::WebString::fromASCII("depth")); | 356 blink::WebString::fromASCII("depth")); |
357 auto result = SelectSettings(); | 357 auto result = SelectSettings(); |
358 EXPECT_TRUE(result.has_value()); | 358 EXPECT_TRUE(result.HasValue()); |
359 EXPECT_EQ(kDeviceID4, result.settings.device_id()); | 359 EXPECT_EQ(kDeviceID4, result.device_id); |
360 EXPECT_EQ(media::PIXEL_FORMAT_Y16, result.settings.format().pixel_format); | 360 EXPECT_EQ(media::PIXEL_FORMAT_Y16, result.Format().pixel_format); |
361 | 361 |
362 constraint_factory_.basic().videoKind.setExact( | 362 constraint_factory_.basic().videoKind.setExact( |
363 blink::WebString::fromASCII("color")); | 363 blink::WebString::fromASCII("color")); |
364 result = SelectSettings(); | 364 result = SelectSettings(); |
365 EXPECT_TRUE(result.has_value()); | 365 EXPECT_TRUE(result.HasValue()); |
366 EXPECT_EQ(default_device_->device_id, result.settings.device_id()); | 366 EXPECT_EQ(default_device_->device_id, result.device_id); |
367 } | 367 } |
368 | 368 |
369 TEST_F(MediaStreamConstraintsUtilVideoSourceTest, MandatoryPowerLineFrequency) { | 369 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryPowerLineFrequency) { |
370 constraint_factory_.Reset(); | 370 constraint_factory_.Reset(); |
371 const media::PowerLineFrequency kPowerLineFrequencies[] = { | 371 const media::PowerLineFrequency kPowerLineFrequencies[] = { |
372 media::PowerLineFrequency::FREQUENCY_50HZ, | 372 media::PowerLineFrequency::FREQUENCY_50HZ, |
373 media::PowerLineFrequency::FREQUENCY_60HZ}; | 373 media::PowerLineFrequency::FREQUENCY_60HZ}; |
374 for (auto power_line_frequency : kPowerLineFrequencies) { | 374 for (auto power_line_frequency : kPowerLineFrequencies) { |
375 constraint_factory_.basic().googPowerLineFrequency.setExact( | 375 constraint_factory_.basic().googPowerLineFrequency.setExact( |
376 static_cast<long>(power_line_frequency)); | 376 static_cast<long>(power_line_frequency)); |
377 auto result = SelectSettings(); | 377 auto result = SelectSettings(); |
378 EXPECT_TRUE(result.has_value()); | 378 EXPECT_TRUE(result.HasValue()); |
379 EXPECT_EQ(power_line_frequency, result.settings.power_line_frequency()); | 379 EXPECT_EQ(power_line_frequency, result.PowerLineFrequency()); |
380 // The default device and settings closest to the default should be | 380 // The default device and settings closest to the default should be |
381 // selected. | 381 // selected. |
382 EXPECT_EQ(default_device_->device_id, result.settings.device_id()); | 382 EXPECT_EQ(default_device_->device_id, result.device_id); |
383 EXPECT_EQ(default_device_->facing_mode, result.settings.facing_mode()); | 383 EXPECT_EQ(default_device_->facing_mode, result.facing_mode); |
384 EXPECT_EQ(*default_closest_format_, result.settings.format()); | 384 EXPECT_EQ(*default_closest_format_, result.Format()); |
385 } | 385 } |
386 } | 386 } |
387 | 387 |
388 TEST_F(MediaStreamConstraintsUtilVideoSourceTest, MandatoryExactHeight) { | 388 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryExactHeight) { |
389 constraint_factory_.Reset(); | 389 constraint_factory_.Reset(); |
390 const int kHeight = MediaStreamVideoSource::kDefaultHeight; | 390 const int kHeight = MediaStreamVideoSource::kDefaultHeight; |
391 constraint_factory_.basic().height.setExact(kHeight); | 391 constraint_factory_.basic().height.setExact(kHeight); |
392 auto result = SelectSettings(); | 392 auto result = SelectSettings(); |
393 EXPECT_TRUE(result.has_value()); | 393 EXPECT_TRUE(result.HasValue()); |
394 // All devices in |capabilities_| support the requested height. The algorithm | 394 // All devices in |capabilities_| support the requested height. The algorithm |
395 // should prefer the first device that supports the requested height natively, | 395 // should prefer the first device that supports the requested height natively, |
396 // which is the low-res device. | 396 // which is the low-res device. |
397 EXPECT_EQ(low_res_device_->device_id, result.settings.device_id()); | 397 EXPECT_EQ(low_res_device_->device_id, result.device_id); |
398 EXPECT_EQ(kHeight, result.settings.GetHeight()); | 398 EXPECT_EQ(kHeight, result.Height()); |
399 | 399 |
400 const int kLargeHeight = 1500; | 400 const int kLargeHeight = 1500; |
401 constraint_factory_.basic().height.setExact(kLargeHeight); | 401 constraint_factory_.basic().height.setExact(kLargeHeight); |
402 result = SelectSettings(); | 402 result = SelectSettings(); |
403 EXPECT_TRUE(result.has_value()); | 403 EXPECT_TRUE(result.HasValue()); |
404 // Only the high-res device at the highest resolution supports the requested | 404 // Only the high-res device at the highest resolution supports the requested |
405 // height, even if not natively. | 405 // height, even if not natively. |
406 EXPECT_EQ(high_res_device_->device_id, result.settings.device_id()); | 406 EXPECT_EQ(high_res_device_->device_id, result.device_id); |
407 EXPECT_EQ(*high_res_highest_format_, result.settings.format()); | 407 EXPECT_EQ(*high_res_highest_format_, result.Format()); |
408 } | 408 } |
409 | 409 |
410 TEST_F(MediaStreamConstraintsUtilVideoSourceTest, MandatoryMinHeight) { | 410 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryMinHeight) { |
411 constraint_factory_.Reset(); | 411 constraint_factory_.Reset(); |
412 const int kHeight = MediaStreamVideoSource::kDefaultHeight; | 412 const int kHeight = MediaStreamVideoSource::kDefaultHeight; |
413 constraint_factory_.basic().height.setMin(kHeight); | 413 constraint_factory_.basic().height.setMin(kHeight); |
414 auto result = SelectSettings(); | 414 auto result = SelectSettings(); |
415 EXPECT_TRUE(result.has_value()); | 415 EXPECT_TRUE(result.HasValue()); |
416 // All devices in |capabilities_| support the requested height range. The | 416 // All devices in |capabilities_| support the requested height range. The |
417 // algorithm should prefer the default device. | 417 // algorithm should prefer the default device. |
418 EXPECT_EQ(default_device_->device_id, result.settings.device_id()); | 418 EXPECT_EQ(default_device_->device_id, result.device_id); |
419 EXPECT_LE(kHeight, result.settings.GetHeight()); | 419 EXPECT_LE(kHeight, result.Height()); |
420 | 420 |
421 const int kLargeHeight = 1500; | 421 const int kLargeHeight = 1500; |
422 constraint_factory_.basic().height.setMin(kLargeHeight); | 422 constraint_factory_.basic().height.setMin(kLargeHeight); |
423 result = SelectSettings(); | 423 result = SelectSettings(); |
424 EXPECT_TRUE(result.has_value()); | 424 EXPECT_TRUE(result.HasValue()); |
425 // Only the high-res device at the highest resolution supports the requested | 425 // Only the high-res device at the highest resolution supports the requested |
426 // height range. | 426 // height range. |
427 EXPECT_EQ(high_res_device_->device_id, result.settings.device_id()); | 427 EXPECT_EQ(high_res_device_->device_id, result.device_id); |
428 EXPECT_EQ(*high_res_highest_format_, result.settings.format()); | 428 EXPECT_EQ(*high_res_highest_format_, result.Format()); |
429 } | 429 } |
430 | 430 |
431 TEST_F(MediaStreamConstraintsUtilVideoSourceTest, MandatoryMaxHeight) { | 431 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryMaxHeight) { |
432 constraint_factory_.Reset(); | 432 constraint_factory_.Reset(); |
433 const int kLowHeight = 20; | 433 const int kLowHeight = 20; |
434 constraint_factory_.basic().height.setMax(kLowHeight); | 434 constraint_factory_.basic().height.setMax(kLowHeight); |
435 auto result = SelectSettings(); | 435 auto result = SelectSettings(); |
436 EXPECT_TRUE(result.has_value()); | 436 EXPECT_TRUE(result.HasValue()); |
437 // All devices in |capabilities_| support the requested height range. The | 437 // All devices in |capabilities_| support the requested height range. The |
438 // algorithm should prefer the settings that natively exceed the requested | 438 // algorithm should prefer the settings that natively exceed the requested |
439 // maximum by the lowest amount. In this case it is the low-res device. | 439 // maximum by the lowest amount. In this case it is the low-res device. |
440 EXPECT_EQ(low_res_device_->device_id, result.settings.device_id()); | 440 EXPECT_EQ(low_res_device_->device_id, result.device_id); |
441 EXPECT_EQ(low_res_device_->formats[0], result.settings.format()); | 441 EXPECT_EQ(low_res_device_->formats[0], result.Format()); |
442 } | 442 } |
443 | 443 |
444 TEST_F(MediaStreamConstraintsUtilVideoSourceTest, MandatoryHeightRange) { | 444 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryHeightRange) { |
445 constraint_factory_.Reset(); | 445 constraint_factory_.Reset(); |
446 { | 446 { |
447 const int kMinHeight = 480; | 447 const int kMinHeight = 480; |
448 const int kMaxHeight = 720; | 448 const int kMaxHeight = 720; |
449 constraint_factory_.basic().height.setMin(kMinHeight); | 449 constraint_factory_.basic().height.setMin(kMinHeight); |
450 constraint_factory_.basic().height.setMax(kMaxHeight); | 450 constraint_factory_.basic().height.setMax(kMaxHeight); |
451 auto result = SelectSettings(); | 451 auto result = SelectSettings(); |
452 EXPECT_TRUE(result.has_value()); | 452 EXPECT_TRUE(result.HasValue()); |
453 EXPECT_GE(result.settings.GetHeight(), kMinHeight); | 453 EXPECT_GE(result.Height(), kMinHeight); |
454 EXPECT_LE(result.settings.GetHeight(), kMaxHeight); | 454 EXPECT_LE(result.Height(), kMaxHeight); |
455 // All devices in |capabilities_| support the constraint range. The | 455 // All devices in |capabilities_| support the constraint range. The |
456 // algorithm should prefer the default device since it has at least one | 456 // algorithm should prefer the default device since it has at least one |
457 // native format (the closest-to-default format) included in the requested | 457 // native format (the closest-to-default format) included in the requested |
458 // range. | 458 // range. |
459 EXPECT_EQ(default_device_->device_id, result.settings.device_id()); | 459 EXPECT_EQ(default_device_->device_id, result.device_id); |
460 EXPECT_EQ(*default_closest_format_, result.settings.format()); | 460 EXPECT_EQ(*default_closest_format_, result.Format()); |
461 } | 461 } |
462 | 462 |
463 { | 463 { |
464 const int kMinHeight = 550; | 464 const int kMinHeight = 550; |
465 const int kMaxHeight = 650; | 465 const int kMaxHeight = 650; |
466 constraint_factory_.basic().height.setMin(kMinHeight); | 466 constraint_factory_.basic().height.setMin(kMinHeight); |
467 constraint_factory_.basic().height.setMax(kMaxHeight); | 467 constraint_factory_.basic().height.setMax(kMaxHeight); |
468 auto result = SelectSettings(); | 468 auto result = SelectSettings(); |
469 EXPECT_TRUE(result.has_value()); | 469 EXPECT_TRUE(result.HasValue()); |
470 EXPECT_GE(result.settings.GetHeight(), kMinHeight); | 470 EXPECT_GE(result.Height(), kMinHeight); |
471 EXPECT_LE(result.settings.GetHeight(), kMaxHeight); | 471 EXPECT_LE(result.Height(), kMaxHeight); |
472 // In this case, the algorithm should prefer the low-res device since it is | 472 // In this case, the algorithm should prefer the low-res device since it is |
473 // the first device with a native format (800x600) included in the requested | 473 // the first device with a native format (800x600) included in the requested |
474 // range. | 474 // range. |
475 EXPECT_EQ(low_res_device_->device_id, result.settings.device_id()); | 475 EXPECT_EQ(low_res_device_->device_id, result.device_id); |
476 EXPECT_EQ(800, result.settings.GetWidth()); | 476 EXPECT_EQ(800, result.Width()); |
477 EXPECT_EQ(600, result.settings.GetHeight()); | 477 EXPECT_EQ(600, result.Height()); |
478 } | 478 } |
479 | 479 |
480 { | 480 { |
481 const int kMinHeight = 700; | 481 const int kMinHeight = 700; |
482 const int kMaxHeight = 800; | 482 const int kMaxHeight = 800; |
483 constraint_factory_.basic().height.setMin(kMinHeight); | 483 constraint_factory_.basic().height.setMin(kMinHeight); |
484 constraint_factory_.basic().height.setMax(kMaxHeight); | 484 constraint_factory_.basic().height.setMax(kMaxHeight); |
485 auto result = SelectSettings(); | 485 auto result = SelectSettings(); |
486 EXPECT_TRUE(result.has_value()); | 486 EXPECT_TRUE(result.HasValue()); |
487 EXPECT_GE(result.settings.GetHeight(), kMinHeight); | 487 EXPECT_GE(result.Height(), kMinHeight); |
488 EXPECT_LE(result.settings.GetHeight(), kMaxHeight); | 488 EXPECT_LE(result.Height(), kMaxHeight); |
489 // In this case, the algorithm should prefer the high-res device since it is | 489 // In this case, the algorithm should prefer the high-res device since it is |
490 // the only device with a native format (1280x720) included in the requested | 490 // the only device with a native format (1280x720) included in the requested |
491 // range. | 491 // range. |
492 EXPECT_EQ(high_res_device_->device_id, result.settings.device_id()); | 492 EXPECT_EQ(high_res_device_->device_id, result.device_id); |
493 EXPECT_EQ(1280, result.settings.GetWidth()); | 493 EXPECT_EQ(1280, result.Width()); |
494 EXPECT_EQ(720, result.settings.GetHeight()); | 494 EXPECT_EQ(720, result.Height()); |
495 } | 495 } |
496 } | 496 } |
497 | 497 |
498 TEST_F(MediaStreamConstraintsUtilVideoSourceTest, IdealHeight) { | 498 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, IdealHeight) { |
499 constraint_factory_.Reset(); | 499 constraint_factory_.Reset(); |
500 { | 500 { |
501 const int kIdealHeight = 480; | 501 const int kIdealHeight = 480; |
502 constraint_factory_.basic().height.setIdeal(kIdealHeight); | 502 constraint_factory_.basic().height.setIdeal(kIdealHeight); |
503 auto result = SelectSettings(); | 503 auto result = SelectSettings(); |
504 EXPECT_TRUE(result.has_value()); | 504 EXPECT_TRUE(result.HasValue()); |
505 // The algorithm should select the first device that supports the ideal | 505 // The algorithm should select the first device that supports the ideal |
506 // height natively. | 506 // height natively. |
507 EXPECT_EQ(low_res_device_->device_id, result.settings.device_id()); | 507 EXPECT_EQ(low_res_device_->device_id, result.device_id); |
508 EXPECT_EQ(kIdealHeight, result.settings.GetHeight()); | 508 EXPECT_EQ(kIdealHeight, result.Height()); |
509 } | 509 } |
510 | 510 |
511 { | 511 { |
512 const int kIdealHeight = 481; | 512 const int kIdealHeight = 481; |
513 constraint_factory_.basic().height.setIdeal(kIdealHeight); | 513 constraint_factory_.basic().height.setIdeal(kIdealHeight); |
514 auto result = SelectSettings(); | 514 auto result = SelectSettings(); |
515 EXPECT_TRUE(result.has_value()); | 515 EXPECT_TRUE(result.HasValue()); |
516 // In this case, the default device is selected because it can satisfy the | 516 // In this case, the default device is selected because it can satisfy the |
517 // ideal at a lower cost than the other devices (500 vs 600 or 720). | 517 // ideal at a lower cost than the other devices (500 vs 600 or 720). |
518 // Note that a native resolution of 480 is further from the ideal than | 518 // Note that a native resolution of 480 is further from the ideal than |
519 // 500 cropped to 480. | 519 // 500 cropped to 480. |
520 EXPECT_EQ(default_device_->device_id, result.settings.device_id()); | 520 EXPECT_EQ(default_device_->device_id, result.device_id); |
521 EXPECT_EQ(*default_closest_format_, result.settings.format()); | 521 EXPECT_EQ(*default_closest_format_, result.Format()); |
522 } | 522 } |
523 | 523 |
524 { | 524 { |
525 const int kIdealHeight = 1079; | 525 const int kIdealHeight = 1079; |
526 constraint_factory_.basic().height.setIdeal(kIdealHeight); | 526 constraint_factory_.basic().height.setIdeal(kIdealHeight); |
527 auto result = SelectSettings(); | 527 auto result = SelectSettings(); |
528 EXPECT_TRUE(result.has_value()); | 528 EXPECT_TRUE(result.HasValue()); |
529 // In this case, the high-res device has two configurations that satisfy | 529 // In this case, the high-res device has two configurations that satisfy |
530 // the ideal value (1920x1080 and 2304x1536). Select the one with shortest | 530 // the ideal value (1920x1080 and 2304x1536). Select the one with shortest |
531 // native distance to the ideal value (1920x1080). | 531 // native distance to the ideal value (1920x1080). |
532 EXPECT_EQ(high_res_device_->device_id, result.settings.device_id()); | 532 EXPECT_EQ(high_res_device_->device_id, result.device_id); |
533 EXPECT_EQ(1920, result.settings.GetWidth()); | 533 EXPECT_EQ(1920, result.Width()); |
534 EXPECT_EQ(1080, result.settings.GetHeight()); | 534 EXPECT_EQ(1080, result.Height()); |
535 } | 535 } |
536 | 536 |
537 { | 537 { |
538 const int kIdealHeight = 1200; | 538 const int kIdealHeight = 1200; |
539 constraint_factory_.basic().height.setIdeal(kIdealHeight); | 539 constraint_factory_.basic().height.setIdeal(kIdealHeight); |
540 auto result = SelectSettings(); | 540 auto result = SelectSettings(); |
541 EXPECT_TRUE(result.has_value()); | 541 EXPECT_TRUE(result.HasValue()); |
542 // The algorithm must the select the only device that can satisfy the ideal, | 542 // The algorithm must the select the only device that can satisfy the ideal, |
543 // which is the high-res device at the highest resolution. | 543 // which is the high-res device at the highest resolution. |
544 EXPECT_EQ(high_res_device_->device_id, result.settings.device_id()); | 544 EXPECT_EQ(high_res_device_->device_id, result.device_id); |
545 EXPECT_EQ(*high_res_highest_format_, result.settings.format()); | 545 EXPECT_EQ(*high_res_highest_format_, result.Format()); |
546 } | 546 } |
547 } | 547 } |
548 | 548 |
549 TEST_F(MediaStreamConstraintsUtilVideoSourceTest, MandatoryExactWidth) { | 549 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryExactWidth) { |
550 constraint_factory_.Reset(); | 550 constraint_factory_.Reset(); |
551 const int kWidth = 640; | 551 const int kWidth = 640; |
552 constraint_factory_.basic().width.setExact(kWidth); | 552 constraint_factory_.basic().width.setExact(kWidth); |
553 auto result = SelectSettings(); | 553 auto result = SelectSettings(); |
554 EXPECT_TRUE(result.has_value()); | 554 EXPECT_TRUE(result.HasValue()); |
555 // All devices in |capabilities_| support the requested width. The algorithm | 555 // All devices in |capabilities_| support the requested width. The algorithm |
556 // should prefer the first device that supports the requested width natively, | 556 // should prefer the first device that supports the requested width natively, |
557 // which is the low-res device. | 557 // which is the low-res device. |
558 EXPECT_EQ(low_res_device_->device_id, result.settings.device_id()); | 558 EXPECT_EQ(low_res_device_->device_id, result.device_id); |
559 EXPECT_EQ(kWidth, result.settings.GetWidth()); | 559 EXPECT_EQ(kWidth, result.Width()); |
560 | 560 |
561 const int kLargeWidth = 2000; | 561 const int kLargeWidth = 2000; |
562 constraint_factory_.basic().width.setExact(kLargeWidth); | 562 constraint_factory_.basic().width.setExact(kLargeWidth); |
563 result = SelectSettings(); | 563 result = SelectSettings(); |
564 EXPECT_TRUE(result.has_value()); | 564 EXPECT_TRUE(result.HasValue()); |
565 EXPECT_LE(kLargeWidth, result.settings.GetWidth()); | 565 EXPECT_LE(kLargeWidth, result.Width()); |
566 // Only the high-res device at the highest resolution supports the requested | 566 // Only the high-res device at the highest resolution supports the requested |
567 // width, even if not natively. | 567 // width, even if not natively. |
568 EXPECT_EQ(high_res_device_->device_id, result.settings.device_id()); | 568 EXPECT_EQ(high_res_device_->device_id, result.device_id); |
569 EXPECT_EQ(*high_res_highest_format_, result.settings.format()); | 569 EXPECT_EQ(*high_res_highest_format_, result.Format()); |
570 } | 570 } |
571 | 571 |
572 TEST_F(MediaStreamConstraintsUtilVideoSourceTest, MandatoryMinWidth) { | 572 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryMinWidth) { |
573 constraint_factory_.Reset(); | 573 constraint_factory_.Reset(); |
574 const int kWidth = 640; | 574 const int kWidth = 640; |
575 constraint_factory_.basic().width.setMin(kWidth); | 575 constraint_factory_.basic().width.setMin(kWidth); |
576 auto result = SelectSettings(); | 576 auto result = SelectSettings(); |
577 EXPECT_TRUE(result.has_value()); | 577 EXPECT_TRUE(result.HasValue()); |
578 // All devices in |capabilities_| support the requested width range. The | 578 // All devices in |capabilities_| support the requested width range. The |
579 // algorithm should prefer the default device at 1000x1000, which is the | 579 // algorithm should prefer the default device at 1000x1000, which is the |
580 // first configuration that satisfies the minimum width. | 580 // first configuration that satisfies the minimum width. |
581 EXPECT_EQ(default_device_->device_id, result.settings.device_id()); | 581 EXPECT_EQ(default_device_->device_id, result.device_id); |
582 EXPECT_LE(kWidth, result.settings.GetWidth()); | 582 EXPECT_LE(kWidth, result.Width()); |
583 EXPECT_EQ(1000, result.settings.GetWidth()); | 583 EXPECT_EQ(1000, result.Width()); |
584 EXPECT_EQ(1000, result.settings.GetHeight()); | 584 EXPECT_EQ(1000, result.Height()); |
585 | 585 |
586 const int kLargeWidth = 2000; | 586 const int kLargeWidth = 2000; |
587 constraint_factory_.basic().width.setMin(kLargeWidth); | 587 constraint_factory_.basic().width.setMin(kLargeWidth); |
588 result = SelectSettings(); | 588 result = SelectSettings(); |
589 EXPECT_TRUE(result.has_value()); | 589 EXPECT_TRUE(result.HasValue()); |
590 // Only the high-res device at the highest resolution supports the requested | 590 // Only the high-res device at the highest resolution supports the requested |
591 // minimum width. | 591 // minimum width. |
592 EXPECT_EQ(high_res_device_->device_id, result.settings.device_id()); | 592 EXPECT_EQ(high_res_device_->device_id, result.device_id); |
593 EXPECT_LE(kLargeWidth, result.settings.GetWidth()); | 593 EXPECT_LE(kLargeWidth, result.Width()); |
594 EXPECT_EQ(*high_res_highest_format_, result.settings.format()); | 594 EXPECT_EQ(*high_res_highest_format_, result.Format()); |
595 } | 595 } |
596 | 596 |
597 TEST_F(MediaStreamConstraintsUtilVideoSourceTest, MandatoryMaxWidth) { | 597 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryMaxWidth) { |
598 constraint_factory_.Reset(); | 598 constraint_factory_.Reset(); |
599 const int kLowWidth = 30; | 599 const int kLowWidth = 30; |
600 constraint_factory_.basic().width.setMax(kLowWidth); | 600 constraint_factory_.basic().width.setMax(kLowWidth); |
601 auto result = SelectSettings(); | 601 auto result = SelectSettings(); |
602 EXPECT_TRUE(result.has_value()); | 602 EXPECT_TRUE(result.HasValue()); |
603 // All devices in |capabilities_| support the requested width range. The | 603 // All devices in |capabilities_| support the requested width range. The |
604 // algorithm should prefer the settings that natively exceed the requested | 604 // algorithm should prefer the settings that natively exceed the requested |
605 // maximum by the lowest amount. In this case it is the low-res device at its | 605 // maximum by the lowest amount. In this case it is the low-res device at its |
606 // lowest resolution. | 606 // lowest resolution. |
607 EXPECT_EQ(low_res_device_->device_id, result.settings.device_id()); | 607 EXPECT_EQ(low_res_device_->device_id, result.device_id); |
608 EXPECT_EQ(low_res_device_->formats[0], result.settings.format()); | 608 EXPECT_EQ(low_res_device_->formats[0], result.Format()); |
609 } | 609 } |
610 | 610 |
611 TEST_F(MediaStreamConstraintsUtilVideoSourceTest, MandatoryWidthRange) { | 611 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryWidthRange) { |
612 constraint_factory_.Reset(); | 612 constraint_factory_.Reset(); |
613 { | 613 { |
614 const int kMinWidth = 640; | 614 const int kMinWidth = 640; |
615 const int kMaxWidth = 1280; | 615 const int kMaxWidth = 1280; |
616 constraint_factory_.basic().width.setMin(kMinWidth); | 616 constraint_factory_.basic().width.setMin(kMinWidth); |
617 constraint_factory_.basic().width.setMax(kMaxWidth); | 617 constraint_factory_.basic().width.setMax(kMaxWidth); |
618 auto result = SelectSettings(); | 618 auto result = SelectSettings(); |
619 EXPECT_TRUE(result.has_value()); | 619 EXPECT_TRUE(result.HasValue()); |
620 EXPECT_GE(result.settings.GetWidth(), kMinWidth); | 620 EXPECT_GE(result.Width(), kMinWidth); |
621 EXPECT_LE(result.settings.GetWidth(), kMaxWidth); | 621 EXPECT_LE(result.Width(), kMaxWidth); |
622 // All devices in |capabilities_| support the constraint range. The | 622 // All devices in |capabilities_| support the constraint range. The |
623 // algorithm should prefer the default device since it has at least one | 623 // algorithm should prefer the default device since it has at least one |
624 // native format (1000x1000) included in the requested range. | 624 // native format (1000x1000) included in the requested range. |
625 EXPECT_EQ(default_device_->device_id, result.settings.device_id()); | 625 EXPECT_EQ(default_device_->device_id, result.device_id); |
626 EXPECT_EQ(1000, result.settings.GetWidth()); | 626 EXPECT_EQ(1000, result.Width()); |
627 EXPECT_EQ(1000, result.settings.GetHeight()); | 627 EXPECT_EQ(1000, result.Height()); |
628 } | 628 } |
629 | 629 |
630 { | 630 { |
631 const int kMinWidth = 750; | 631 const int kMinWidth = 750; |
632 const int kMaxWidth = 850; | 632 const int kMaxWidth = 850; |
633 constraint_factory_.basic().width.setMin(kMinWidth); | 633 constraint_factory_.basic().width.setMin(kMinWidth); |
634 constraint_factory_.basic().width.setMax(kMaxWidth); | 634 constraint_factory_.basic().width.setMax(kMaxWidth); |
635 auto result = SelectSettings(); | 635 auto result = SelectSettings(); |
636 EXPECT_TRUE(result.has_value()); | 636 EXPECT_TRUE(result.HasValue()); |
637 EXPECT_GE(result.settings.GetWidth(), kMinWidth); | 637 EXPECT_GE(result.Width(), kMinWidth); |
638 EXPECT_LE(result.settings.GetWidth(), kMaxWidth); | 638 EXPECT_LE(result.Width(), kMaxWidth); |
639 // In this case, the algorithm should prefer the low-res device since it is | 639 // In this case, the algorithm should prefer the low-res device since it is |
640 // the first device with a native format (800x600) included in the requested | 640 // the first device with a native format (800x600) included in the requested |
641 // range. | 641 // range. |
642 EXPECT_EQ(low_res_device_->device_id, result.settings.device_id()); | 642 EXPECT_EQ(low_res_device_->device_id, result.device_id); |
643 EXPECT_EQ(800, result.settings.GetWidth()); | 643 EXPECT_EQ(800, result.Width()); |
644 EXPECT_EQ(600, result.settings.GetHeight()); | 644 EXPECT_EQ(600, result.Height()); |
645 } | 645 } |
646 | 646 |
647 { | 647 { |
648 const int kMinWidth = 1900; | 648 const int kMinWidth = 1900; |
649 const int kMaxWidth = 2000; | 649 const int kMaxWidth = 2000; |
650 constraint_factory_.basic().width.setMin(kMinWidth); | 650 constraint_factory_.basic().width.setMin(kMinWidth); |
651 constraint_factory_.basic().width.setMax(kMaxWidth); | 651 constraint_factory_.basic().width.setMax(kMaxWidth); |
652 auto result = SelectSettings(); | 652 auto result = SelectSettings(); |
653 EXPECT_TRUE(result.has_value()); | 653 EXPECT_TRUE(result.HasValue()); |
654 EXPECT_GE(result.settings.GetWidth(), kMinWidth); | 654 EXPECT_GE(result.Width(), kMinWidth); |
655 EXPECT_LE(result.settings.GetWidth(), kMaxWidth); | 655 EXPECT_LE(result.Width(), kMaxWidth); |
656 // In this case, the algorithm should prefer the high-res device since it is | 656 // In this case, the algorithm should prefer the high-res device since it is |
657 // the only device with a native format (1920x1080) included in the | 657 // the only device with a native format (1920x1080) included in the |
658 // requested range. | 658 // requested range. |
659 EXPECT_EQ(high_res_device_->device_id, result.settings.device_id()); | 659 EXPECT_EQ(high_res_device_->device_id, result.device_id); |
660 EXPECT_EQ(1920, result.settings.GetWidth()); | 660 EXPECT_EQ(1920, result.Width()); |
661 EXPECT_EQ(1080, result.settings.GetHeight()); | 661 EXPECT_EQ(1080, result.Height()); |
662 } | 662 } |
663 } | 663 } |
664 | 664 |
665 TEST_F(MediaStreamConstraintsUtilVideoSourceTest, IdealWidth) { | 665 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, IdealWidth) { |
666 constraint_factory_.Reset(); | 666 constraint_factory_.Reset(); |
667 { | 667 { |
668 const int kIdealWidth = 320; | 668 const int kIdealWidth = 320; |
669 constraint_factory_.basic().width.setIdeal(kIdealWidth); | 669 constraint_factory_.basic().width.setIdeal(kIdealWidth); |
670 auto result = SelectSettings(); | 670 auto result = SelectSettings(); |
671 EXPECT_TRUE(result.has_value()); | 671 EXPECT_TRUE(result.HasValue()); |
672 // The algorithm should select the first device that supports the ideal | 672 // The algorithm should select the first device that supports the ideal |
673 // width natively, which is the low-res device at 320x240. | 673 // width natively, which is the low-res device at 320x240. |
674 EXPECT_EQ(low_res_device_->device_id, result.settings.device_id()); | 674 EXPECT_EQ(low_res_device_->device_id, result.device_id); |
675 EXPECT_EQ(kIdealWidth, result.settings.GetWidth()); | 675 EXPECT_EQ(kIdealWidth, result.Width()); |
676 } | 676 } |
677 | 677 |
678 { | 678 { |
679 const int kIdealWidth = 321; | 679 const int kIdealWidth = 321; |
680 constraint_factory_.basic().width.setIdeal(kIdealWidth); | 680 constraint_factory_.basic().width.setIdeal(kIdealWidth); |
681 auto result = SelectSettings(); | 681 auto result = SelectSettings(); |
682 EXPECT_TRUE(result.has_value()); | 682 EXPECT_TRUE(result.HasValue()); |
683 // In this case, the default device is selected because it can satisfy the | 683 // In this case, the default device is selected because it can satisfy the |
684 // ideal at a lower cost than the other devices (500 vs 640). | 684 // ideal at a lower cost than the other devices (500 vs 640). |
685 // Note that a native resolution of 320 is further from the ideal value of | 685 // Note that a native resolution of 320 is further from the ideal value of |
686 // 321 than 500 cropped to 321. | 686 // 321 than 500 cropped to 321. |
687 EXPECT_EQ(default_device_->device_id, result.settings.device_id()); | 687 EXPECT_EQ(default_device_->device_id, result.device_id); |
688 EXPECT_EQ(*default_closest_format_, result.settings.format()); | 688 EXPECT_EQ(*default_closest_format_, result.Format()); |
689 } | 689 } |
690 | 690 |
691 { | 691 { |
692 const int kIdealWidth = 2000; | 692 const int kIdealWidth = 2000; |
693 constraint_factory_.basic().width.setIdeal(kIdealWidth); | 693 constraint_factory_.basic().width.setIdeal(kIdealWidth); |
694 auto result = SelectSettings(); | 694 auto result = SelectSettings(); |
695 EXPECT_TRUE(result.has_value()); | 695 EXPECT_TRUE(result.HasValue()); |
696 // The algorithm must the select the only device that can satisfy the ideal. | 696 // The algorithm must the select the only device that can satisfy the ideal. |
697 EXPECT_EQ(high_res_device_->device_id, result.settings.device_id()); | 697 EXPECT_EQ(high_res_device_->device_id, result.device_id); |
698 EXPECT_EQ(*high_res_highest_format_, result.settings.format()); | 698 EXPECT_EQ(*high_res_highest_format_, result.Format()); |
699 } | 699 } |
700 | 700 |
701 { | 701 { |
702 const int kIdealWidth = 3000; | 702 const int kIdealWidth = 3000; |
703 constraint_factory_.basic().width.setIdeal(kIdealWidth); | 703 constraint_factory_.basic().width.setIdeal(kIdealWidth); |
704 auto result = SelectSettings(); | 704 auto result = SelectSettings(); |
705 EXPECT_TRUE(result.has_value()); | 705 EXPECT_TRUE(result.HasValue()); |
706 // The algorithm must the select the device and setting with less distance | 706 // The algorithm must the select the device and setting with less distance |
707 // to the ideal. | 707 // to the ideal. |
708 EXPECT_EQ(high_res_device_->device_id, result.settings.device_id()); | 708 EXPECT_EQ(high_res_device_->device_id, result.device_id); |
709 EXPECT_EQ(*high_res_highest_format_, result.settings.format()); | 709 EXPECT_EQ(*high_res_highest_format_, result.Format()); |
710 } | 710 } |
711 } | 711 } |
712 | 712 |
713 TEST_F(MediaStreamConstraintsUtilVideoSourceTest, MandatoryExactFrameRate) { | 713 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryExactFrameRate) { |
714 constraint_factory_.Reset(); | 714 constraint_factory_.Reset(); |
715 const double kFrameRate = MediaStreamVideoSource::kDefaultFrameRate; | 715 const double kFrameRate = MediaStreamVideoSource::kDefaultFrameRate; |
716 constraint_factory_.basic().frameRate.setExact(kFrameRate); | 716 constraint_factory_.basic().frameRate.setExact(kFrameRate); |
717 auto result = SelectSettings(); | 717 auto result = SelectSettings(); |
718 EXPECT_TRUE(result.has_value()); | 718 EXPECT_TRUE(result.HasValue()); |
719 // All devices in |capabilities_| support the requested frame rate. The | 719 // All devices in |capabilities_| support the requested frame rate. The |
720 // algorithm should prefer the first device that supports the requested frame | 720 // algorithm should prefer the first device that supports the requested frame |
721 // rate natively, which is the low-res device at 640x480x30Hz. | 721 // rate natively, which is the low-res device at 640x480x30Hz. |
722 EXPECT_EQ(low_res_device_->device_id, result.settings.device_id()); | 722 EXPECT_EQ(low_res_device_->device_id, result.device_id); |
723 EXPECT_EQ(kFrameRate, result.settings.GetFrameRate()); | 723 EXPECT_EQ(kFrameRate, result.FrameRate()); |
724 EXPECT_EQ(640, result.settings.GetWidth()); | 724 EXPECT_EQ(640, result.Width()); |
725 EXPECT_EQ(480, result.settings.GetHeight()); | 725 EXPECT_EQ(480, result.Height()); |
726 | 726 |
727 const double kLargeFrameRate = 50; | 727 const double kLargeFrameRate = 50; |
728 constraint_factory_.basic().frameRate.setExact(kLargeFrameRate); | 728 constraint_factory_.basic().frameRate.setExact(kLargeFrameRate); |
729 result = SelectSettings(); | 729 result = SelectSettings(); |
730 EXPECT_TRUE(result.has_value()); | 730 EXPECT_TRUE(result.HasValue()); |
731 // Only the high-res device supports the requested frame rate, even if not | 731 // Only the high-res device supports the requested frame rate, even if not |
732 // natively. The least expensive configuration that supports the requested | 732 // natively. The least expensive configuration that supports the requested |
733 // frame rate is 1280x720x60Hz. | 733 // frame rate is 1280x720x60Hz. |
734 EXPECT_EQ(high_res_device_->device_id, result.settings.device_id()); | 734 EXPECT_EQ(high_res_device_->device_id, result.device_id); |
735 EXPECT_EQ(60.0, result.settings.GetFrameRate()); | 735 EXPECT_EQ(60.0, result.FrameRate()); |
736 EXPECT_EQ(1280, result.settings.GetWidth()); | 736 EXPECT_EQ(1280, result.Width()); |
737 EXPECT_EQ(720, result.settings.GetHeight()); | 737 EXPECT_EQ(720, result.Height()); |
738 } | 738 } |
739 | 739 |
740 TEST_F(MediaStreamConstraintsUtilVideoSourceTest, MandatoryMinFrameRate) { | 740 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryMinFrameRate) { |
741 constraint_factory_.Reset(); | 741 constraint_factory_.Reset(); |
742 const double kFrameRate = MediaStreamVideoSource::kDefaultFrameRate; | 742 const double kFrameRate = MediaStreamVideoSource::kDefaultFrameRate; |
743 constraint_factory_.basic().frameRate.setMin(kFrameRate); | 743 constraint_factory_.basic().frameRate.setMin(kFrameRate); |
744 auto result = SelectSettings(); | 744 auto result = SelectSettings(); |
745 EXPECT_TRUE(result.has_value()); | 745 EXPECT_TRUE(result.HasValue()); |
746 // All devices in |capabilities_| support the requested frame-rate range. The | 746 // All devices in |capabilities_| support the requested frame-rate range. The |
747 // algorithm should prefer the default device. | 747 // algorithm should prefer the default device. |
748 EXPECT_EQ(default_device_->device_id, result.settings.device_id()); | 748 EXPECT_EQ(default_device_->device_id, result.device_id); |
749 // The format closest to the default satisfies the constraint. | 749 // The format closest to the default satisfies the constraint. |
750 EXPECT_EQ(*default_closest_format_, result.settings.format()); | 750 EXPECT_EQ(*default_closest_format_, result.Format()); |
751 | 751 |
752 const double kLargeFrameRate = 50; | 752 const double kLargeFrameRate = 50; |
753 constraint_factory_.basic().frameRate.setMin(kLargeFrameRate); | 753 constraint_factory_.basic().frameRate.setMin(kLargeFrameRate); |
754 result = SelectSettings(); | 754 result = SelectSettings(); |
755 EXPECT_TRUE(result.has_value()); | 755 EXPECT_TRUE(result.HasValue()); |
756 // Only the high-res device supports the requested frame-rate range. | 756 // Only the high-res device supports the requested frame-rate range. |
757 // The least expensive configuration is 1280x720x60Hz. | 757 // The least expensive configuration is 1280x720x60Hz. |
758 EXPECT_EQ(high_res_device_->device_id, result.settings.device_id()); | 758 EXPECT_EQ(high_res_device_->device_id, result.device_id); |
759 EXPECT_LE(kLargeFrameRate, result.settings.GetFrameRate()); | 759 EXPECT_LE(kLargeFrameRate, result.FrameRate()); |
760 EXPECT_EQ(1280, result.settings.GetWidth()); | 760 EXPECT_EQ(1280, result.Width()); |
761 EXPECT_EQ(720, result.settings.GetHeight()); | 761 EXPECT_EQ(720, result.Height()); |
762 } | 762 } |
763 | 763 |
764 TEST_F(MediaStreamConstraintsUtilVideoSourceTest, MandatoryMaxFrameRate) { | 764 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryMaxFrameRate) { |
765 constraint_factory_.Reset(); | 765 constraint_factory_.Reset(); |
766 const double kLowFrameRate = 10; | 766 const double kLowFrameRate = 10; |
767 constraint_factory_.basic().frameRate.setMax(kLowFrameRate); | 767 constraint_factory_.basic().frameRate.setMax(kLowFrameRate); |
768 auto result = SelectSettings(); | 768 auto result = SelectSettings(); |
769 EXPECT_TRUE(result.has_value()); | 769 EXPECT_TRUE(result.HasValue()); |
770 // All devices in |capabilities_| support the requested frame-rate range. The | 770 // All devices in |capabilities_| support the requested frame-rate range. The |
771 // algorithm should prefer the settings that natively exceed the requested | 771 // algorithm should prefer the settings that natively exceed the requested |
772 // maximum by the lowest amount. In this case it is the high-res device with | 772 // maximum by the lowest amount. In this case it is the high-res device with |
773 // default resolution . | 773 // default resolution . |
774 EXPECT_EQ(high_res_device_->device_id, result.settings.device_id()); | 774 EXPECT_EQ(high_res_device_->device_id, result.device_id); |
775 EXPECT_EQ(kLowFrameRate, result.settings.GetFrameRate()); | 775 EXPECT_EQ(kLowFrameRate, result.FrameRate()); |
776 EXPECT_EQ(MediaStreamVideoSource::kDefaultHeight, | 776 EXPECT_EQ(MediaStreamVideoSource::kDefaultHeight, result.Height()); |
777 result.settings.GetHeight()); | 777 EXPECT_EQ(MediaStreamVideoSource::kDefaultWidth, result.Width()); |
778 EXPECT_EQ(MediaStreamVideoSource::kDefaultWidth, result.settings.GetWidth()); | |
779 } | 778 } |
780 | 779 |
781 TEST_F(MediaStreamConstraintsUtilVideoSourceTest, MandatoryFrameRateRange) { | 780 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryFrameRateRange) { |
782 constraint_factory_.Reset(); | 781 constraint_factory_.Reset(); |
783 { | 782 { |
784 const double kMinFrameRate = 10; | 783 const double kMinFrameRate = 10; |
785 const double kMaxFrameRate = 40; | 784 const double kMaxFrameRate = 40; |
786 constraint_factory_.basic().frameRate.setMin(kMinFrameRate); | 785 constraint_factory_.basic().frameRate.setMin(kMinFrameRate); |
787 constraint_factory_.basic().frameRate.setMax(kMaxFrameRate); | 786 constraint_factory_.basic().frameRate.setMax(kMaxFrameRate); |
788 auto result = SelectSettings(); | 787 auto result = SelectSettings(); |
789 EXPECT_TRUE(result.has_value()); | 788 EXPECT_TRUE(result.HasValue()); |
790 EXPECT_LE(kMinFrameRate, result.settings.GetFrameRate()); | 789 EXPECT_LE(kMinFrameRate, result.FrameRate()); |
791 EXPECT_GE(kMaxFrameRate, result.settings.GetFrameRate()); | 790 EXPECT_GE(kMaxFrameRate, result.FrameRate()); |
792 // All devices in |capabilities_| support the constraint range. The | 791 // All devices in |capabilities_| support the constraint range. The |
793 // algorithm should prefer the default device since its closest-to-default | 792 // algorithm should prefer the default device since its closest-to-default |
794 // format has a frame rate included in the requested range. | 793 // format has a frame rate included in the requested range. |
795 EXPECT_EQ(default_device_->device_id, result.settings.device_id()); | 794 EXPECT_EQ(default_device_->device_id, result.device_id); |
796 EXPECT_EQ(*default_closest_format_, result.settings.format()); | 795 EXPECT_EQ(*default_closest_format_, result.Format()); |
797 } | 796 } |
798 | 797 |
799 { | 798 { |
800 const double kMinFrameRate = 25; | 799 const double kMinFrameRate = 25; |
801 const double kMaxFrameRate = 35; | 800 const double kMaxFrameRate = 35; |
802 constraint_factory_.basic().frameRate.setMin(kMinFrameRate); | 801 constraint_factory_.basic().frameRate.setMin(kMinFrameRate); |
803 constraint_factory_.basic().frameRate.setMax(kMaxFrameRate); | 802 constraint_factory_.basic().frameRate.setMax(kMaxFrameRate); |
804 auto result = SelectSettings(); | 803 auto result = SelectSettings(); |
805 EXPECT_TRUE(result.has_value()); | 804 EXPECT_TRUE(result.HasValue()); |
806 EXPECT_GE(result.settings.GetFrameRate(), kMinFrameRate); | 805 EXPECT_GE(result.FrameRate(), kMinFrameRate); |
807 EXPECT_LE(result.settings.GetFrameRate(), kMaxFrameRate); | 806 EXPECT_LE(result.FrameRate(), kMaxFrameRate); |
808 // In this case, the algorithm should prefer the low-res device since it is | 807 // In this case, the algorithm should prefer the low-res device since it is |
809 // the first device with a native frame rate included in the requested | 808 // the first device with a native frame rate included in the requested |
810 // range. The default resolution should be preferred as secondary criterion. | 809 // range. The default resolution should be preferred as secondary criterion. |
811 EXPECT_EQ(low_res_device_->device_id, result.settings.device_id()); | 810 EXPECT_EQ(low_res_device_->device_id, result.device_id); |
812 EXPECT_EQ(*low_res_closest_format_, result.settings.format()); | 811 EXPECT_EQ(*low_res_closest_format_, result.Format()); |
813 } | 812 } |
814 | 813 |
815 { | 814 { |
816 const double kMinFrameRate = 50; | 815 const double kMinFrameRate = 50; |
817 const double kMaxFrameRate = 70; | 816 const double kMaxFrameRate = 70; |
818 constraint_factory_.basic().frameRate.setMin(kMinFrameRate); | 817 constraint_factory_.basic().frameRate.setMin(kMinFrameRate); |
819 constraint_factory_.basic().frameRate.setMax(kMaxFrameRate); | 818 constraint_factory_.basic().frameRate.setMax(kMaxFrameRate); |
820 auto result = SelectSettings(); | 819 auto result = SelectSettings(); |
821 EXPECT_TRUE(result.has_value()); | 820 EXPECT_TRUE(result.HasValue()); |
822 EXPECT_GE(result.settings.GetFrameRate(), kMinFrameRate); | 821 EXPECT_GE(result.FrameRate(), kMinFrameRate); |
823 EXPECT_LE(result.settings.GetFrameRate(), kMaxFrameRate); | 822 EXPECT_LE(result.FrameRate(), kMaxFrameRate); |
824 // In this case, the algorithm should prefer the high-res device since it is | 823 // In this case, the algorithm should prefer the high-res device since it is |
825 // the only device with a native format included in the requested range. | 824 // the only device with a native format included in the requested range. |
826 // The 1280x720 resolution should be selected due to closeness to default | 825 // The 1280x720 resolution should be selected due to closeness to default |
827 // settings, which is the second tie-breaker criterion that applies. | 826 // settings, which is the second tie-breaker criterion that applies. |
828 EXPECT_EQ(high_res_device_->device_id, result.settings.device_id()); | 827 EXPECT_EQ(high_res_device_->device_id, result.device_id); |
829 EXPECT_EQ(1280, result.settings.GetWidth()); | 828 EXPECT_EQ(1280, result.Width()); |
830 EXPECT_EQ(720, result.settings.GetHeight()); | 829 EXPECT_EQ(720, result.Height()); |
831 } | 830 } |
832 } | 831 } |
833 | 832 |
834 TEST_F(MediaStreamConstraintsUtilVideoSourceTest, IdealFrameRate) { | 833 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, IdealFrameRate) { |
835 constraint_factory_.Reset(); | 834 constraint_factory_.Reset(); |
836 { | 835 { |
837 const double kIdealFrameRate = MediaStreamVideoSource::kDefaultFrameRate; | 836 const double kIdealFrameRate = MediaStreamVideoSource::kDefaultFrameRate; |
838 constraint_factory_.basic().frameRate.setIdeal(kIdealFrameRate); | 837 constraint_factory_.basic().frameRate.setIdeal(kIdealFrameRate); |
839 auto result = SelectSettings(); | 838 auto result = SelectSettings(); |
840 EXPECT_TRUE(result.has_value()); | 839 EXPECT_TRUE(result.HasValue()); |
841 // The algorithm should select the first configuration that supports the | 840 // The algorithm should select the first configuration that supports the |
842 // ideal frame rate natively, which is the low-res device. Default | 841 // ideal frame rate natively, which is the low-res device. Default |
843 // resolution should be selected as secondary criterion. | 842 // resolution should be selected as secondary criterion. |
844 EXPECT_EQ(low_res_device_->device_id, result.settings.device_id()); | 843 EXPECT_EQ(low_res_device_->device_id, result.device_id); |
845 EXPECT_EQ(*low_res_closest_format_, result.settings.format()); | 844 EXPECT_EQ(*low_res_closest_format_, result.Format()); |
846 } | 845 } |
847 | 846 |
848 { | 847 { |
849 const double kIdealFrameRate = 31; | 848 const double kIdealFrameRate = 31; |
850 constraint_factory_.basic().frameRate.setIdeal(kIdealFrameRate); | 849 constraint_factory_.basic().frameRate.setIdeal(kIdealFrameRate); |
851 auto result = SelectSettings(); | 850 auto result = SelectSettings(); |
852 EXPECT_TRUE(result.has_value()); | 851 EXPECT_TRUE(result.HasValue()); |
853 // In this case, the default device is selected because it can satisfy the | 852 // In this case, the default device is selected because it can satisfy the |
854 // ideal at a lower cost than the other devices (40 vs 60). | 853 // ideal at a lower cost than the other devices (40 vs 60). |
855 // Note that a native frame rate of 30 is further from the ideal than | 854 // Note that a native frame rate of 30 is further from the ideal than |
856 // 31 adjusted to 30. | 855 // 31 adjusted to 30. |
857 EXPECT_EQ(default_device_->device_id, result.settings.device_id()); | 856 EXPECT_EQ(default_device_->device_id, result.device_id); |
858 EXPECT_EQ(*default_closest_format_, result.settings.format()); | 857 EXPECT_EQ(*default_closest_format_, result.Format()); |
859 } | 858 } |
860 | 859 |
861 { | 860 { |
862 const double kIdealFrameRate = 55; | 861 const double kIdealFrameRate = 55; |
863 constraint_factory_.basic().frameRate.setIdeal(kIdealFrameRate); | 862 constraint_factory_.basic().frameRate.setIdeal(kIdealFrameRate); |
864 auto result = SelectSettings(); | 863 auto result = SelectSettings(); |
865 EXPECT_TRUE(result.has_value()); | 864 EXPECT_TRUE(result.HasValue()); |
866 // The high-res device format 1280x720x60.0 must be selected because its | 865 // The high-res device format 1280x720x60.0 must be selected because its |
867 // frame rate can satisfy the ideal frame rate and has resolution closest | 866 // frame rate can satisfy the ideal frame rate and has resolution closest |
868 // to the default. | 867 // to the default. |
869 EXPECT_EQ(high_res_device_->device_id, result.settings.device_id()); | 868 EXPECT_EQ(high_res_device_->device_id, result.device_id); |
870 EXPECT_EQ(1280, result.settings.GetWidth()); | 869 EXPECT_EQ(1280, result.Width()); |
871 EXPECT_EQ(720, result.settings.GetHeight()); | 870 EXPECT_EQ(720, result.Height()); |
872 EXPECT_EQ(60, result.settings.GetFrameRate()); | 871 EXPECT_EQ(60, result.FrameRate()); |
873 } | 872 } |
874 | 873 |
875 { | 874 { |
876 const double kIdealFrameRate = 100; | 875 const double kIdealFrameRate = 100; |
877 constraint_factory_.basic().frameRate.setIdeal(kIdealFrameRate); | 876 constraint_factory_.basic().frameRate.setIdeal(kIdealFrameRate); |
878 auto result = SelectSettings(); | 877 auto result = SelectSettings(); |
879 EXPECT_TRUE(result.has_value()); | 878 EXPECT_TRUE(result.HasValue()); |
880 // The algorithm must select settings with frame rate closest to the ideal. | 879 // The algorithm must select settings with frame rate closest to the ideal. |
881 // The high-res device format 1280x720x60.0 must be selected because its | 880 // The high-res device format 1280x720x60.0 must be selected because its |
882 // frame rate it closest to the ideal value and it has resolution closest to | 881 // frame rate it closest to the ideal value and it has resolution closest to |
883 // the default. | 882 // the default. |
884 EXPECT_EQ(high_res_device_->device_id, result.settings.device_id()); | 883 EXPECT_EQ(high_res_device_->device_id, result.device_id); |
885 EXPECT_EQ(1280, result.settings.GetWidth()); | 884 EXPECT_EQ(1280, result.Width()); |
886 EXPECT_EQ(720, result.settings.GetHeight()); | 885 EXPECT_EQ(720, result.Height()); |
887 EXPECT_EQ(60, result.settings.GetFrameRate()); | 886 EXPECT_EQ(60, result.FrameRate()); |
888 } | 887 } |
889 } | 888 } |
890 | 889 |
891 TEST_F(MediaStreamConstraintsUtilVideoSourceTest, MandatoryExactAspectRatio) { | 890 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryExactAspectRatio) { |
892 constraint_factory_.Reset(); | 891 constraint_factory_.Reset(); |
893 const double kAspectRatio = 4.0 / 3.0; | 892 const double kAspectRatio = 4.0 / 3.0; |
894 constraint_factory_.basic().aspectRatio.setExact(kAspectRatio); | 893 constraint_factory_.basic().aspectRatio.setExact(kAspectRatio); |
895 auto result = SelectSettings(); | 894 auto result = SelectSettings(); |
896 EXPECT_TRUE(result.has_value()); | 895 EXPECT_TRUE(result.HasValue()); |
897 double min_width = 1.0; | 896 double min_width = 1.0; |
898 double max_width = result.settings.GetWidth(); | 897 double max_width = result.Width(); |
899 double min_height = 1.0; | 898 double min_height = 1.0; |
900 double max_height = result.settings.GetHeight(); | 899 double max_height = result.Height(); |
901 double min_aspect_ratio = min_width / max_height; | 900 double min_aspect_ratio = min_width / max_height; |
902 double max_aspect_ratio = max_width / min_height; | 901 double max_aspect_ratio = max_width / min_height; |
903 // The requested aspect ratio must be within the supported range. | 902 // The requested aspect ratio must be within the supported range. |
904 EXPECT_GE(kAspectRatio, min_aspect_ratio); | 903 EXPECT_GE(kAspectRatio, min_aspect_ratio); |
905 EXPECT_LE(kAspectRatio, max_aspect_ratio); | 904 EXPECT_LE(kAspectRatio, max_aspect_ratio); |
906 // All devices in |capabilities_| support the requested aspect ratio. | 905 // All devices in |capabilities_| support the requested aspect ratio. |
907 // The algorithm should prefer the first device that supports the requested | 906 // The algorithm should prefer the first device that supports the requested |
908 // aspect ratio. | 907 // aspect ratio. |
909 EXPECT_EQ(default_device_->device_id, result.settings.device_id()); | 908 EXPECT_EQ(default_device_->device_id, result.device_id); |
910 EXPECT_EQ(*default_closest_format_, result.settings.format()); | 909 EXPECT_EQ(*default_closest_format_, result.Format()); |
911 | 910 |
912 const long kMinWidth = 500; | 911 const int kMinWidth = 500; |
913 const long kMaxWidth = 1000; | 912 const int kMaxWidth = 1000; |
914 const long kMaxHeight = 500; | 913 const int kMaxHeight = 500; |
915 constraint_factory_.basic().height.setMax(kMaxHeight); | 914 constraint_factory_.basic().height.setMax(kMaxHeight); |
916 constraint_factory_.basic().width.setMin(kMinWidth); | 915 constraint_factory_.basic().width.setMin(kMinWidth); |
917 constraint_factory_.basic().width.setMax(kMaxWidth); | 916 constraint_factory_.basic().width.setMax(kMaxWidth); |
918 constraint_factory_.basic().aspectRatio.setExact(kAspectRatio); | 917 constraint_factory_.basic().aspectRatio.setExact(kAspectRatio); |
919 result = SelectSettings(); | 918 result = SelectSettings(); |
920 EXPECT_TRUE(result.has_value()); | 919 EXPECT_TRUE(result.HasValue()); |
921 min_width = std::max(1L, kMinWidth); | 920 min_width = std::max(1, kMinWidth); |
922 max_width = std::min(result.settings.GetWidth(), kMaxWidth); | 921 max_width = std::min(result.Width(), kMaxWidth); |
923 min_height = 1.0; | 922 min_height = 1.0; |
924 max_height = std::min(result.settings.GetHeight(), kMaxHeight); | 923 max_height = std::min(result.Height(), kMaxHeight); |
925 min_aspect_ratio = min_width / max_height; | 924 min_aspect_ratio = min_width / max_height; |
926 max_aspect_ratio = max_width / min_height; | 925 max_aspect_ratio = max_width / min_height; |
927 // The requested aspect ratio must be within the supported range. | 926 // The requested aspect ratio must be within the supported range. |
928 EXPECT_GE(kAspectRatio, min_aspect_ratio); | 927 EXPECT_GE(kAspectRatio, min_aspect_ratio); |
929 EXPECT_LE(kAspectRatio, max_aspect_ratio); | 928 EXPECT_LE(kAspectRatio, max_aspect_ratio); |
930 // The default device can support the requested aspect ratio with the default | 929 // The default device can support the requested aspect ratio with the default |
931 // settings (500x500) using cropping. | 930 // settings (500x500) using cropping. |
932 EXPECT_EQ(default_device_->device_id, result.settings.device_id()); | 931 EXPECT_EQ(default_device_->device_id, result.device_id); |
933 EXPECT_EQ(*default_closest_format_, result.settings.format()); | 932 EXPECT_EQ(*default_closest_format_, result.Format()); |
934 | 933 |
935 const long kMinHeight = 480; | 934 const int kMinHeight = 480; |
936 constraint_factory_.basic().height.setMin(kMinHeight); | 935 constraint_factory_.basic().height.setMin(kMinHeight); |
937 constraint_factory_.basic().height.setMax(kMaxHeight); | 936 constraint_factory_.basic().height.setMax(kMaxHeight); |
938 constraint_factory_.basic().width.setMin(kMinWidth); | 937 constraint_factory_.basic().width.setMin(kMinWidth); |
939 constraint_factory_.basic().width.setMax(kMaxWidth); | 938 constraint_factory_.basic().width.setMax(kMaxWidth); |
940 constraint_factory_.basic().aspectRatio.setExact(kAspectRatio); | 939 constraint_factory_.basic().aspectRatio.setExact(kAspectRatio); |
941 result = SelectSettings(); | 940 result = SelectSettings(); |
942 EXPECT_TRUE(result.has_value()); | 941 EXPECT_TRUE(result.HasValue()); |
943 min_width = std::max(1L, kMinWidth); | 942 min_width = std::max(1, kMinWidth); |
944 max_width = std::min(result.settings.GetWidth(), kMaxWidth); | 943 max_width = std::min(result.Width(), kMaxWidth); |
945 min_height = std::max(1L, kMinHeight); | 944 min_height = std::max(1, kMinHeight); |
946 max_height = std::min(result.settings.GetHeight(), kMaxHeight); | 945 max_height = std::min(result.Height(), kMaxHeight); |
947 min_aspect_ratio = min_width / max_height; | 946 min_aspect_ratio = min_width / max_height; |
948 max_aspect_ratio = max_width / min_height; | 947 max_aspect_ratio = max_width / min_height; |
949 // The requested aspect ratio must be within the supported range. | 948 // The requested aspect ratio must be within the supported range. |
950 EXPECT_GE(kAspectRatio, min_aspect_ratio); | 949 EXPECT_GE(kAspectRatio, min_aspect_ratio); |
951 EXPECT_LE(kAspectRatio, max_aspect_ratio); | 950 EXPECT_LE(kAspectRatio, max_aspect_ratio); |
952 // Given resolution constraints, the default device with closest-to-default | 951 // Given resolution constraints, the default device with closest-to-default |
953 // settings cannot satisfy the required aspect ratio. | 952 // settings cannot satisfy the required aspect ratio. |
954 // The first device that can do it is the low-res device with a native | 953 // The first device that can do it is the low-res device with a native |
955 // resolution of 640x480. Higher resolutions for the default device are more | 954 // resolution of 640x480. Higher resolutions for the default device are more |
956 // penalized by the constraints than the default native resolution of the | 955 // penalized by the constraints than the default native resolution of the |
957 // low-res device. | 956 // low-res device. |
958 EXPECT_EQ(low_res_device_->device_id, result.settings.device_id()); | 957 EXPECT_EQ(low_res_device_->device_id, result.device_id); |
959 EXPECT_EQ(*low_res_closest_format_, result.settings.format()); | 958 EXPECT_EQ(*low_res_closest_format_, result.Format()); |
960 } | 959 } |
961 | 960 |
962 TEST_F(MediaStreamConstraintsUtilVideoSourceTest, MandatoryMinAspectRatio) { | 961 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryMinAspectRatio) { |
963 constraint_factory_.Reset(); | 962 constraint_factory_.Reset(); |
964 const double kAspectRatio = 4.0 / 3.0; | 963 const double kAspectRatio = 4.0 / 3.0; |
965 constraint_factory_.basic().aspectRatio.setMin(kAspectRatio); | 964 constraint_factory_.basic().aspectRatio.setMin(kAspectRatio); |
966 auto result = SelectSettings(); | 965 auto result = SelectSettings(); |
967 EXPECT_TRUE(result.has_value()); | 966 EXPECT_TRUE(result.HasValue()); |
968 double max_width = result.settings.GetWidth(); | 967 double max_width = result.Width(); |
969 double min_height = 1.0; | 968 double min_height = 1.0; |
970 double max_aspect_ratio = max_width / min_height; | 969 double max_aspect_ratio = max_width / min_height; |
971 // Minimum constraint aspect ratio must be less than or equal to the maximum | 970 // Minimum constraint aspect ratio must be less than or equal to the maximum |
972 // supported by the source. | 971 // supported by the source. |
973 EXPECT_LE(kAspectRatio, max_aspect_ratio); | 972 EXPECT_LE(kAspectRatio, max_aspect_ratio); |
974 // All devices in |capabilities_| support the requested aspect-ratio range. | 973 // All devices in |capabilities_| support the requested aspect-ratio range. |
975 // The algorithm should prefer the first device that supports the requested | 974 // The algorithm should prefer the first device that supports the requested |
976 // aspect-ratio range, which in this case is the default device. | 975 // aspect-ratio range, which in this case is the default device. |
977 EXPECT_EQ(default_device_->device_id, result.settings.device_id()); | 976 EXPECT_EQ(default_device_->device_id, result.device_id); |
978 EXPECT_EQ(*default_closest_format_, result.settings.format()); | 977 EXPECT_EQ(*default_closest_format_, result.Format()); |
979 | 978 |
980 const long kMinWidth = 500; | 979 const int kMinWidth = 500; |
981 const long kMaxWidth = 1000; | 980 const int kMaxWidth = 1000; |
982 const long kMinHeight = 480; | 981 const int kMinHeight = 480; |
983 const long kMaxHeight = 500; | 982 const int kMaxHeight = 500; |
984 constraint_factory_.basic().width.setMin(kMinWidth); | 983 constraint_factory_.basic().width.setMin(kMinWidth); |
985 constraint_factory_.basic().width.setMax(kMaxWidth); | 984 constraint_factory_.basic().width.setMax(kMaxWidth); |
986 constraint_factory_.basic().height.setMin(kMinHeight); | 985 constraint_factory_.basic().height.setMin(kMinHeight); |
987 constraint_factory_.basic().height.setMax(kMaxHeight); | 986 constraint_factory_.basic().height.setMax(kMaxHeight); |
988 constraint_factory_.basic().aspectRatio.setMin(kAspectRatio); | 987 constraint_factory_.basic().aspectRatio.setMin(kAspectRatio); |
989 result = SelectSettings(); | 988 result = SelectSettings(); |
990 EXPECT_TRUE(result.has_value()); | 989 EXPECT_TRUE(result.HasValue()); |
991 max_width = std::min(result.settings.GetWidth(), kMaxWidth); | 990 max_width = std::min(result.Width(), kMaxWidth); |
992 min_height = std::max(1L, kMinHeight); | 991 min_height = std::max(1, kMinHeight); |
993 max_aspect_ratio = max_width / min_height; | 992 max_aspect_ratio = max_width / min_height; |
994 // Minimum constraint aspect ratio must be less than or equal to the minimum | 993 // Minimum constraint aspect ratio must be less than or equal to the minimum |
995 // supported by the source. | 994 // supported by the source. |
996 EXPECT_LE(kAspectRatio, max_aspect_ratio); | 995 EXPECT_LE(kAspectRatio, max_aspect_ratio); |
997 // Given resolution constraints, the default device with closest-to-default | 996 // Given resolution constraints, the default device with closest-to-default |
998 // settings cannot satisfy the required minimum aspect ratio (maximum would | 997 // settings cannot satisfy the required minimum aspect ratio (maximum would |
999 // be 500/480). The first device that can is the low-res device with a native | 998 // be 500/480). The first device that can is the low-res device with a native |
1000 // resolution of 640x480. | 999 // resolution of 640x480. |
1001 // Higher resolutions for the default device are more penalized by the | 1000 // Higher resolutions for the default device are more penalized by the |
1002 // constraints than the default native resolution of the low-res device. | 1001 // constraints than the default native resolution of the low-res device. |
1003 EXPECT_EQ(low_res_device_->device_id, result.settings.device_id()); | 1002 EXPECT_EQ(low_res_device_->device_id, result.device_id); |
1004 EXPECT_EQ(*low_res_closest_format_, result.settings.format()); | 1003 EXPECT_EQ(*low_res_closest_format_, result.Format()); |
1005 } | 1004 } |
1006 | 1005 |
1007 TEST_F(MediaStreamConstraintsUtilVideoSourceTest, MandatoryMaxAspectRatio) { | 1006 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryMaxAspectRatio) { |
1008 constraint_factory_.Reset(); | 1007 constraint_factory_.Reset(); |
1009 const double kAspectRatio = 0.5; | 1008 const double kAspectRatio = 0.5; |
1010 constraint_factory_.basic().aspectRatio.setMax(kAspectRatio); | 1009 constraint_factory_.basic().aspectRatio.setMax(kAspectRatio); |
1011 auto result = SelectSettings(); | 1010 auto result = SelectSettings(); |
1012 EXPECT_TRUE(result.has_value()); | 1011 EXPECT_TRUE(result.HasValue()); |
1013 double min_width = 1.0; | 1012 double min_width = 1.0; |
1014 double max_height = result.settings.GetHeight(); | 1013 double max_height = result.Height(); |
1015 double min_aspect_ratio = min_width / max_height; | 1014 double min_aspect_ratio = min_width / max_height; |
1016 // Minimum constraint aspect ratio must be less than or equal to the maximum | 1015 // Minimum constraint aspect ratio must be less than or equal to the maximum |
1017 // supported by the source. | 1016 // supported by the source. |
1018 EXPECT_GE(kAspectRatio, min_aspect_ratio); | 1017 EXPECT_GE(kAspectRatio, min_aspect_ratio); |
1019 // All devices in |capabilities_| support the requested aspect-ratio range. | 1018 // All devices in |capabilities_| support the requested aspect-ratio range. |
1020 // The algorithm should prefer the first device that supports the requested | 1019 // The algorithm should prefer the first device that supports the requested |
1021 // aspect-ratio range, which in this case is the default device. | 1020 // aspect-ratio range, which in this case is the default device. |
1022 EXPECT_EQ(default_device_->device_id, result.settings.device_id()); | 1021 EXPECT_EQ(default_device_->device_id, result.device_id); |
1023 EXPECT_EQ(*default_closest_format_, result.settings.format()); | 1022 EXPECT_EQ(*default_closest_format_, result.Format()); |
1024 | 1023 |
1025 const long kExactWidth = 360; | 1024 const int kExactWidth = 360; |
1026 const long kMinHeight = 360; | 1025 const int kMinHeight = 360; |
1027 const long kMaxHeight = 720; | 1026 const int kMaxHeight = 720; |
1028 constraint_factory_.basic().width.setExact(kExactWidth); | 1027 constraint_factory_.basic().width.setExact(kExactWidth); |
1029 constraint_factory_.basic().height.setMin(kMinHeight); | 1028 constraint_factory_.basic().height.setMin(kMinHeight); |
1030 constraint_factory_.basic().height.setMax(kMaxHeight); | 1029 constraint_factory_.basic().height.setMax(kMaxHeight); |
1031 constraint_factory_.basic().aspectRatio.setMax(kAspectRatio); | 1030 constraint_factory_.basic().aspectRatio.setMax(kAspectRatio); |
1032 result = SelectSettings(); | 1031 result = SelectSettings(); |
1033 EXPECT_TRUE(result.has_value()); | 1032 EXPECT_TRUE(result.HasValue()); |
1034 min_width = std::max(1L, kExactWidth); | 1033 min_width = std::max(1, kExactWidth); |
1035 max_height = std::min(result.settings.GetHeight(), kMaxHeight); | 1034 max_height = std::min(result.Height(), kMaxHeight); |
1036 min_aspect_ratio = min_width / max_height; | 1035 min_aspect_ratio = min_width / max_height; |
1037 // Minimum constraint aspect ratio must be less than or equal to the minimum | 1036 // Minimum constraint aspect ratio must be less than or equal to the minimum |
1038 // supported by the source. | 1037 // supported by the source. |
1039 EXPECT_GE(kAspectRatio, min_aspect_ratio); | 1038 EXPECT_GE(kAspectRatio, min_aspect_ratio); |
1040 // Given resolution constraints, the default device with closest-to-default | 1039 // Given resolution constraints, the default device with closest-to-default |
1041 // settings cannot satisfy the required maximum aspect ratio (maximum would | 1040 // settings cannot satisfy the required maximum aspect ratio (maximum would |
1042 // be 360/500). | 1041 // be 360/500). |
1043 // The high-res device with a native resolution of 1280x720 can support | 1042 // The high-res device with a native resolution of 1280x720 can support |
1044 // 360x720 with cropping with less penalty than the default device at | 1043 // 360x720 with cropping with less penalty than the default device at |
1045 // 1000x1000. | 1044 // 1000x1000. |
1046 EXPECT_EQ(high_res_device_->device_id, result.settings.device_id()); | 1045 EXPECT_EQ(high_res_device_->device_id, result.device_id); |
1047 EXPECT_EQ(1280, result.settings.GetWidth()); | 1046 EXPECT_EQ(1280, result.Width()); |
1048 EXPECT_EQ(720, result.settings.GetHeight()); | 1047 EXPECT_EQ(720, result.Height()); |
1049 } | 1048 } |
1050 | 1049 |
1051 TEST_F(MediaStreamConstraintsUtilVideoSourceTest, MandatoryAspectRatioRange) { | 1050 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryAspectRatioRange) { |
1052 constraint_factory_.Reset(); | 1051 constraint_factory_.Reset(); |
1053 { | 1052 { |
1054 const double kMinAspectRatio = 0.5; | 1053 const double kMinAspectRatio = 0.5; |
1055 const double kMaxAspectRatio = 1.0; | 1054 const double kMaxAspectRatio = 1.0; |
1056 | 1055 |
1057 constraint_factory_.basic().aspectRatio.setMin(kMinAspectRatio); | 1056 constraint_factory_.basic().aspectRatio.setMin(kMinAspectRatio); |
1058 constraint_factory_.basic().aspectRatio.setMax(kMaxAspectRatio); | 1057 constraint_factory_.basic().aspectRatio.setMax(kMaxAspectRatio); |
1059 auto result = SelectSettings(); | 1058 auto result = SelectSettings(); |
1060 EXPECT_TRUE(result.has_value()); | 1059 EXPECT_TRUE(result.HasValue()); |
1061 double min_width = 1.0; | 1060 double min_width = 1.0; |
1062 double max_width = result.settings.GetWidth(); | 1061 double max_width = result.Width(); |
1063 double min_height = 1.0; | 1062 double min_height = 1.0; |
1064 double max_height = result.settings.GetHeight(); | 1063 double max_height = result.Height(); |
1065 double min_aspect_ratio = min_width / max_height; | 1064 double min_aspect_ratio = min_width / max_height; |
1066 double max_aspect_ratio = max_width / min_height; | 1065 double max_aspect_ratio = max_width / min_height; |
1067 // Constraint aspect-ratio range must have nonempty intersection with | 1066 // Constraint aspect-ratio range must have nonempty intersection with |
1068 // supported range. | 1067 // supported range. |
1069 EXPECT_LE(kMinAspectRatio, max_aspect_ratio); | 1068 EXPECT_LE(kMinAspectRatio, max_aspect_ratio); |
1070 EXPECT_GE(kMaxAspectRatio, min_aspect_ratio); | 1069 EXPECT_GE(kMaxAspectRatio, min_aspect_ratio); |
1071 // All devices in |capabilities_| support the requested aspect-ratio range. | 1070 // All devices in |capabilities_| support the requested aspect-ratio range. |
1072 // The algorithm should prefer the first device that supports the requested | 1071 // The algorithm should prefer the first device that supports the requested |
1073 // aspect-ratio range, which in this case is the default device. | 1072 // aspect-ratio range, which in this case is the default device. |
1074 EXPECT_EQ(default_device_->device_id, result.settings.device_id()); | 1073 EXPECT_EQ(default_device_->device_id, result.device_id); |
1075 EXPECT_EQ(*default_closest_format_, result.settings.format()); | 1074 EXPECT_EQ(*default_closest_format_, result.Format()); |
1076 } | 1075 } |
1077 | 1076 |
1078 { | 1077 { |
1079 const double kMinAspectRatio = 3.0; | 1078 const double kMinAspectRatio = 3.0; |
1080 const double kMaxAspectRatio = 4.0; | 1079 const double kMaxAspectRatio = 4.0; |
1081 | 1080 |
1082 const long kExactHeight = 600; | 1081 const long kExactHeight = 600; |
1083 constraint_factory_.Reset(); | 1082 constraint_factory_.Reset(); |
1084 constraint_factory_.basic().height.setMin(kExactHeight); | 1083 constraint_factory_.basic().height.setMin(kExactHeight); |
1085 constraint_factory_.basic().aspectRatio.setMin(kMinAspectRatio); | 1084 constraint_factory_.basic().aspectRatio.setMin(kMinAspectRatio); |
1086 constraint_factory_.basic().aspectRatio.setMax(kMaxAspectRatio); | 1085 constraint_factory_.basic().aspectRatio.setMax(kMaxAspectRatio); |
1087 auto result = SelectSettings(); | 1086 auto result = SelectSettings(); |
1088 EXPECT_TRUE(result.has_value()); | 1087 EXPECT_TRUE(result.HasValue()); |
1089 double min_width = 1.0; | 1088 double min_width = 1.0; |
1090 double max_width = result.settings.GetWidth(); | 1089 double max_width = result.Width(); |
1091 double min_height = 1.0; | 1090 double min_height = 1.0; |
1092 double max_height = result.settings.GetHeight(); | 1091 double max_height = result.Height(); |
1093 double min_aspect_ratio = min_width / max_height; | 1092 double min_aspect_ratio = min_width / max_height; |
1094 double max_aspect_ratio = max_width / min_height; | 1093 double max_aspect_ratio = max_width / min_height; |
1095 // Constraint aspect-ratio range must have nonempty intersection with | 1094 // Constraint aspect-ratio range must have nonempty intersection with |
1096 // supported range. | 1095 // supported range. |
1097 EXPECT_LE(kMinAspectRatio, max_aspect_ratio); | 1096 EXPECT_LE(kMinAspectRatio, max_aspect_ratio); |
1098 EXPECT_GE(kMaxAspectRatio, min_aspect_ratio); | 1097 EXPECT_GE(kMaxAspectRatio, min_aspect_ratio); |
1099 // The only device that supports the resolution and aspect ratio constraint | 1098 // The only device that supports the resolution and aspect ratio constraint |
1100 // is the high-res device. The 1920x1080 is the least expensive format. | 1099 // is the high-res device. The 1920x1080 is the least expensive format. |
1101 EXPECT_EQ(high_res_device_->device_id, result.settings.device_id()); | 1100 EXPECT_EQ(high_res_device_->device_id, result.device_id); |
1102 EXPECT_EQ(1920, result.settings.GetWidth()); | 1101 EXPECT_EQ(1920, result.Width()); |
1103 EXPECT_EQ(1080, result.settings.GetHeight()); | 1102 EXPECT_EQ(1080, result.Height()); |
1104 } | 1103 } |
1105 } | 1104 } |
1106 | 1105 |
1107 TEST_F(MediaStreamConstraintsUtilVideoSourceTest, IdealAspectRatio) { | 1106 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, IdealAspectRatio) { |
1108 constraint_factory_.Reset(); | 1107 constraint_factory_.Reset(); |
1109 { | 1108 { |
1110 const double kIdealAspectRatio = 0.5; | 1109 const double kIdealAspectRatio = 0.5; |
1111 constraint_factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); | 1110 constraint_factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); |
1112 auto result = SelectSettings(); | 1111 auto result = SelectSettings(); |
1113 EXPECT_TRUE(result.has_value()); | 1112 EXPECT_TRUE(result.HasValue()); |
1114 double min_width = 1.0; | 1113 double min_width = 1.0; |
1115 double max_width = result.settings.GetWidth(); | 1114 double max_width = result.Width(); |
1116 double min_height = 1.0; | 1115 double min_height = 1.0; |
1117 double max_height = result.settings.GetHeight(); | 1116 double max_height = result.Height(); |
1118 double min_aspect_ratio = min_width / max_height; | 1117 double min_aspect_ratio = min_width / max_height; |
1119 double max_aspect_ratio = max_width / min_height; | 1118 double max_aspect_ratio = max_width / min_height; |
1120 // All devices in |capabilities_| support the ideal aspect-ratio. | 1119 // All devices in |capabilities_| support the ideal aspect-ratio. |
1121 // The algorithm should prefer the default device with closest-to-default | 1120 // The algorithm should prefer the default device with closest-to-default |
1122 // settings. | 1121 // settings. |
1123 EXPECT_LE(kIdealAspectRatio, max_aspect_ratio); | 1122 EXPECT_LE(kIdealAspectRatio, max_aspect_ratio); |
1124 EXPECT_GE(kIdealAspectRatio, min_aspect_ratio); | 1123 EXPECT_GE(kIdealAspectRatio, min_aspect_ratio); |
1125 EXPECT_EQ(default_device_->device_id, result.settings.device_id()); | 1124 EXPECT_EQ(default_device_->device_id, result.device_id); |
1126 EXPECT_EQ(*default_closest_format_, result.settings.format()); | 1125 EXPECT_EQ(*default_closest_format_, result.Format()); |
1127 } | 1126 } |
1128 | 1127 |
1129 { | 1128 { |
1130 const double kIdealAspectRatio = 1500.0; | 1129 const double kIdealAspectRatio = 1500.0; |
1131 constraint_factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); | 1130 constraint_factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); |
1132 auto result = SelectSettings(); | 1131 auto result = SelectSettings(); |
1133 EXPECT_TRUE(result.has_value()); | 1132 EXPECT_TRUE(result.HasValue()); |
1134 // The only device that supports the ideal aspect ratio is the high-res | 1133 // The only device that supports the ideal aspect ratio is the high-res |
1135 // device. The least expensive way to support it with the 1920x1080 format | 1134 // device. The least expensive way to support it with the 1920x1080 format |
1136 // cropped to 1500x1. | 1135 // cropped to 1500x1. |
1137 EXPECT_EQ(high_res_device_->device_id, result.settings.device_id()); | 1136 EXPECT_EQ(high_res_device_->device_id, result.device_id); |
1138 EXPECT_EQ(1920, result.settings.GetWidth()); | 1137 EXPECT_EQ(1920, result.Width()); |
1139 EXPECT_EQ(1080, result.settings.GetHeight()); | 1138 EXPECT_EQ(1080, result.Height()); |
1140 } | 1139 } |
1141 | 1140 |
1142 { | 1141 { |
1143 const double kIdealAspectRatio = 2000.0; | 1142 const double kIdealAspectRatio = 2000.0; |
1144 constraint_factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); | 1143 constraint_factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); |
1145 auto result = SelectSettings(); | 1144 auto result = SelectSettings(); |
1146 EXPECT_TRUE(result.has_value()); | 1145 EXPECT_TRUE(result.HasValue()); |
1147 // The only device that supports the ideal aspect ratio is the high-res | 1146 // The only device that supports the ideal aspect ratio is the high-res |
1148 // device with its highest resolution, cropped to 2000x1. | 1147 // device with its highest resolution, cropped to 2000x1. |
1149 EXPECT_EQ(high_res_device_->device_id, result.settings.device_id()); | 1148 EXPECT_EQ(high_res_device_->device_id, result.device_id); |
1150 EXPECT_EQ(*high_res_highest_format_, result.settings.format()); | 1149 EXPECT_EQ(*high_res_highest_format_, result.Format()); |
1151 } | 1150 } |
1152 | 1151 |
1153 { | 1152 { |
1154 const double kIdealAspectRatio = 4000.0; | 1153 const double kIdealAspectRatio = 4000.0; |
1155 constraint_factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); | 1154 constraint_factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); |
1156 auto result = SelectSettings(); | 1155 auto result = SelectSettings(); |
1157 EXPECT_TRUE(result.has_value()); | 1156 EXPECT_TRUE(result.HasValue()); |
1158 // The configuration closest to the ideal aspect ratio is is the high-res | 1157 // The configuration closest to the ideal aspect ratio is is the high-res |
1159 // device with its highest resolution, cropped to 2304x1. | 1158 // device with its highest resolution, cropped to 2304x1. |
1160 EXPECT_EQ(high_res_device_->device_id, result.settings.device_id()); | 1159 EXPECT_EQ(high_res_device_->device_id, result.device_id); |
1161 EXPECT_EQ(*high_res_highest_format_, result.settings.format()); | 1160 EXPECT_EQ(*high_res_highest_format_, result.Format()); |
1162 } | 1161 } |
1163 | 1162 |
1164 { | 1163 { |
1165 const double kIdealAspectRatio = 2.0; | 1164 const double kIdealAspectRatio = 2.0; |
1166 constraint_factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); | 1165 constraint_factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); |
1167 constraint_factory_.basic().height.setExact(400); | 1166 constraint_factory_.basic().height.setExact(400); |
1168 auto result = SelectSettings(); | 1167 auto result = SelectSettings(); |
1169 EXPECT_TRUE(result.has_value()); | 1168 EXPECT_TRUE(result.HasValue()); |
1170 // The first device to support the ideal aspect ratio and the resolution | 1169 // The first device to support the ideal aspect ratio and the resolution |
1171 // constraint is the low-res device. The 800x600 format cropped to 800x400 | 1170 // constraint is the low-res device. The 800x600 format cropped to 800x400 |
1172 // is the lest expensive way to achieve it. | 1171 // is the lest expensive way to achieve it. |
1173 EXPECT_EQ(low_res_device_->device_id, result.settings.device_id()); | 1172 EXPECT_EQ(low_res_device_->device_id, result.device_id); |
1174 EXPECT_EQ(800, result.settings.GetWidth()); | 1173 EXPECT_EQ(800, result.Width()); |
1175 EXPECT_EQ(600, result.settings.GetHeight()); | 1174 EXPECT_EQ(600, result.Height()); |
1176 } | 1175 } |
1177 | 1176 |
1178 { | 1177 { |
1179 const double kIdealAspectRatio = 3.0; | 1178 const double kIdealAspectRatio = 3.0; |
1180 constraint_factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); | 1179 constraint_factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); |
1181 constraint_factory_.basic().height.setExact(400); | 1180 constraint_factory_.basic().height.setExact(400); |
1182 auto result = SelectSettings(); | 1181 auto result = SelectSettings(); |
1183 EXPECT_TRUE(result.has_value()); | 1182 EXPECT_TRUE(result.HasValue()); |
1184 // The only device that supports the ideal aspect ratio and the resolution | 1183 // The only device that supports the ideal aspect ratio and the resolution |
1185 // constraint is the high-res device. The 1280x720 cropped to 1200x400 is | 1184 // constraint is the high-res device. The 1280x720 cropped to 1200x400 is |
1186 // the lest expensive way to achieve it. | 1185 // the lest expensive way to achieve it. |
1187 EXPECT_EQ(high_res_device_->device_id, result.settings.device_id()); | 1186 EXPECT_EQ(high_res_device_->device_id, result.device_id); |
1188 EXPECT_EQ(1280, result.settings.GetWidth()); | 1187 EXPECT_EQ(1280, result.Width()); |
1189 EXPECT_EQ(720, result.settings.GetHeight()); | 1188 EXPECT_EQ(720, result.Height()); |
1190 } | 1189 } |
1191 } | 1190 } |
1192 | 1191 |
1193 // The "Advanced" tests check selection criteria involving advanced constraint | 1192 // The "Advanced" tests check selection criteria involving advanced constraint |
1194 // sets. | 1193 // sets. |
1195 TEST_F(MediaStreamConstraintsUtilVideoSourceTest, AdvancedExactResolution) { | 1194 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, AdvancedExactResolution) { |
1196 { | 1195 { |
1197 constraint_factory_.Reset(); | 1196 constraint_factory_.Reset(); |
1198 blink::WebMediaTrackConstraintSet& advanced1 = | 1197 blink::WebMediaTrackConstraintSet& advanced1 = |
1199 constraint_factory_.AddAdvanced(); | 1198 constraint_factory_.AddAdvanced(); |
1200 advanced1.width.setExact(4000); | 1199 advanced1.width.setExact(4000); |
1201 advanced1.height.setExact(4000); | 1200 advanced1.height.setExact(4000); |
1202 blink::WebMediaTrackConstraintSet& advanced2 = | 1201 blink::WebMediaTrackConstraintSet& advanced2 = |
1203 constraint_factory_.AddAdvanced(); | 1202 constraint_factory_.AddAdvanced(); |
1204 advanced2.width.setExact(3000); | 1203 advanced2.width.setExact(3000); |
1205 advanced2.height.setExact(3000); | 1204 advanced2.height.setExact(3000); |
1206 auto result = SelectSettings(); | 1205 auto result = SelectSettings(); |
1207 // No device supports the advanced constraint sets. | 1206 // No device supports the advanced constraint sets. |
1208 // Tie-breaker rule that applies is closeness to default settings. | 1207 // Tie-breaker rule that applies is closeness to default settings. |
1209 EXPECT_EQ(default_device_->device_id, result.settings.device_id()); | 1208 EXPECT_EQ(default_device_->device_id, result.device_id); |
1210 EXPECT_EQ(*default_closest_format_, result.settings.format()); | 1209 EXPECT_EQ(*default_closest_format_, result.Format()); |
1211 | 1210 |
1212 blink::WebMediaTrackConstraintSet& advanced3 = | 1211 blink::WebMediaTrackConstraintSet& advanced3 = |
1213 constraint_factory_.AddAdvanced(); | 1212 constraint_factory_.AddAdvanced(); |
1214 advanced3.width.setExact(1920); | 1213 advanced3.width.setExact(1920); |
1215 advanced3.height.setExact(1080); | 1214 advanced3.height.setExact(1080); |
1216 result = SelectSettings(); | 1215 result = SelectSettings(); |
1217 EXPECT_TRUE(result.has_value()); | 1216 EXPECT_TRUE(result.HasValue()); |
1218 // The high-res device natively supports the third advanced constraint set | 1217 // The high-res device natively supports the third advanced constraint set |
1219 // and should be selected. | 1218 // and should be selected. |
1220 // First tie-breaker rule that applies is support for advanced constraints | 1219 // First tie-breaker rule that applies is support for advanced constraints |
1221 // that appear first. Second tie-breaker rule is custom distance to advanced | 1220 // that appear first. Second tie-breaker rule is custom distance to advanced |
1222 // constraint sets that appear first. | 1221 // constraint sets that appear first. |
1223 EXPECT_EQ(high_res_device_->device_id, result.settings.device_id()); | 1222 EXPECT_EQ(high_res_device_->device_id, result.device_id); |
1224 EXPECT_EQ(1920, result.settings.GetWidth()); | 1223 EXPECT_EQ(1920, result.Width()); |
1225 EXPECT_EQ(1080, result.settings.GetHeight()); | 1224 EXPECT_EQ(1080, result.Height()); |
1226 | 1225 |
1227 blink::WebMediaTrackConstraintSet& advanced4 = | 1226 blink::WebMediaTrackConstraintSet& advanced4 = |
1228 constraint_factory_.AddAdvanced(); | 1227 constraint_factory_.AddAdvanced(); |
1229 advanced4.width.setExact(640); | 1228 advanced4.width.setExact(640); |
1230 advanced4.height.setExact(480); | 1229 advanced4.height.setExact(480); |
1231 result = SelectSettings(); | 1230 result = SelectSettings(); |
1232 EXPECT_TRUE(result.has_value()); | 1231 EXPECT_TRUE(result.HasValue()); |
1233 // First tie-breaker rule that applies is support for advanced constraints | 1232 // First tie-breaker rule that applies is support for advanced constraints |
1234 // that appear first, which leaves out configurations that only support the | 1233 // that appear first, which leaves out configurations that only support the |
1235 // fourth advanced constraint set in favor of configurations that support | 1234 // fourth advanced constraint set in favor of configurations that support |
1236 // the third set. | 1235 // the third set. |
1237 // Second tie-breaker rule is custom distance to advanced constraint sets | 1236 // Second tie-breaker rule is custom distance to advanced constraint sets |
1238 // that appear first. | 1237 // that appear first. |
1239 EXPECT_EQ(high_res_device_->device_id, result.settings.device_id()); | 1238 EXPECT_EQ(high_res_device_->device_id, result.device_id); |
1240 EXPECT_EQ(1920, result.settings.GetWidth()); | 1239 EXPECT_EQ(1920, result.Width()); |
1241 EXPECT_EQ(1080, result.settings.GetHeight()); | 1240 EXPECT_EQ(1080, result.Height()); |
1242 | 1241 |
1243 constraint_factory_.basic().width.setIdeal(800); | 1242 constraint_factory_.basic().width.setIdeal(800); |
1244 constraint_factory_.basic().height.setIdeal(600); | 1243 constraint_factory_.basic().height.setIdeal(600); |
1245 result = SelectSettings(); | 1244 result = SelectSettings(); |
1246 EXPECT_TRUE(result.has_value()); | 1245 EXPECT_TRUE(result.HasValue()); |
1247 // The ideal value is supported by the same configuration, so nothing | 1246 // The ideal value is supported by the same configuration, so nothing |
1248 // changes. | 1247 // changes. |
1249 EXPECT_EQ(high_res_device_->device_id, result.settings.device_id()); | 1248 EXPECT_EQ(high_res_device_->device_id, result.device_id); |
1250 EXPECT_EQ(1920, result.settings.GetWidth()); | 1249 EXPECT_EQ(1920, result.Width()); |
1251 EXPECT_EQ(1080, result.settings.GetHeight()); | 1250 EXPECT_EQ(1080, result.Height()); |
1252 | 1251 |
1253 constraint_factory_.basic().width.setIdeal(2000); | 1252 constraint_factory_.basic().width.setIdeal(2000); |
1254 constraint_factory_.basic().height.setIdeal(1500); | 1253 constraint_factory_.basic().height.setIdeal(1500); |
1255 result = SelectSettings(); | 1254 result = SelectSettings(); |
1256 EXPECT_TRUE(result.has_value()); | 1255 EXPECT_TRUE(result.HasValue()); |
1257 // The closest configuration to the ideal resolution is the high-res device | 1256 // The closest configuration to the ideal resolution is the high-res device |
1258 // at the highest resolution. | 1257 // at the highest resolution. |
1259 EXPECT_EQ(high_res_device_->device_id, result.settings.device_id()); | 1258 EXPECT_EQ(high_res_device_->device_id, result.device_id); |
1260 EXPECT_EQ(*high_res_highest_format_, result.settings.format()); | 1259 EXPECT_EQ(*high_res_highest_format_, result.Format()); |
1261 } | 1260 } |
1262 } | 1261 } |
1263 | 1262 |
1264 TEST_F(MediaStreamConstraintsUtilVideoSourceTest, | 1263 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, |
1265 AdvancedResolutionAndFrameRate) { | 1264 AdvancedResolutionAndFrameRate) { |
1266 { | 1265 { |
1267 constraint_factory_.Reset(); | 1266 constraint_factory_.Reset(); |
1268 blink::WebMediaTrackConstraintSet& advanced1 = | 1267 blink::WebMediaTrackConstraintSet& advanced1 = |
1269 constraint_factory_.AddAdvanced(); | 1268 constraint_factory_.AddAdvanced(); |
1270 advanced1.width.setExact(1920); | 1269 advanced1.width.setExact(1920); |
1271 advanced1.height.setExact(1080); | 1270 advanced1.height.setExact(1080); |
1272 blink::WebMediaTrackConstraintSet& advanced2 = | 1271 blink::WebMediaTrackConstraintSet& advanced2 = |
1273 constraint_factory_.AddAdvanced(); | 1272 constraint_factory_.AddAdvanced(); |
1274 advanced2.frameRate.setExact(60.0); | 1273 advanced2.frameRate.setExact(60.0); |
1275 blink::WebMediaTrackConstraintSet& advanced3 = | 1274 blink::WebMediaTrackConstraintSet& advanced3 = |
1276 constraint_factory_.AddAdvanced(); | 1275 constraint_factory_.AddAdvanced(); |
1277 advanced3.width.setExact(2304); | 1276 advanced3.width.setExact(2304); |
1278 advanced3.height.setExact(1536); | 1277 advanced3.height.setExact(1536); |
1279 auto result = SelectSettings(); | 1278 auto result = SelectSettings(); |
1280 EXPECT_TRUE(result.has_value()); | 1279 EXPECT_TRUE(result.HasValue()); |
1281 // The high-res device is the only one that satisfies the first advanced | 1280 // The high-res device is the only one that satisfies the first advanced |
1282 // set. 2304x1536x10.0 satisfies sets 1 and 3, while 1920x1080x60.0 | 1281 // set. 2304x1536x10.0 satisfies sets 1 and 3, while 1920x1080x60.0 |
1283 // satisfies sets 1, and 2. The latter must be selected, regardless of | 1282 // satisfies sets 1, and 2. The latter must be selected, regardless of |
1284 // any other criteria. | 1283 // any other criteria. |
1285 EXPECT_EQ(high_res_device_->device_id, result.settings.device_id()); | 1284 EXPECT_EQ(high_res_device_->device_id, result.device_id); |
1286 EXPECT_EQ(1920, result.settings.GetWidth()); | 1285 EXPECT_EQ(1920, result.Width()); |
1287 EXPECT_EQ(1080, result.settings.GetHeight()); | 1286 EXPECT_EQ(1080, result.Height()); |
1288 EXPECT_EQ(60.0, result.settings.GetFrameRate()); | 1287 EXPECT_EQ(60.0, result.FrameRate()); |
1289 } | 1288 } |
1290 } | 1289 } |
1291 | 1290 |
1292 // The "NoDevices" tests verify that the algorithm returns the expected result | 1291 // The "NoDevices" tests verify that the algorithm returns the expected result |
1293 // when there are no candidates to choose from. | 1292 // when there are no candidates to choose from. |
1294 TEST_F(MediaStreamConstraintsUtilVideoSourceTest, NoDevicesNoConstraints) { | 1293 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, NoDevicesNoConstraints) { |
1295 constraint_factory_.Reset(); | 1294 constraint_factory_.Reset(); |
1296 VideoCaptureCapabilities capabilities; | 1295 VideoDeviceCaptureCapabilities capabilities; |
1297 auto result = SelectVideoCaptureSourceSettings( | 1296 auto result = SelectVideoDeviceCaptureSourceSettings( |
1298 capabilities, constraint_factory_.CreateWebMediaConstraints()); | 1297 capabilities, constraint_factory_.CreateWebMediaConstraints()); |
1299 EXPECT_FALSE(result.has_value()); | 1298 EXPECT_FALSE(result.HasValue()); |
1300 EXPECT_TRUE(std::string(result.failed_constraint_name).empty()); | 1299 EXPECT_TRUE(std::string(result.failed_constraint_name).empty()); |
1301 } | 1300 } |
1302 | 1301 |
1303 TEST_F(MediaStreamConstraintsUtilVideoSourceTest, NoDevicesWithConstraints) { | 1302 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, NoDevicesWithConstraints) { |
1304 constraint_factory_.Reset(); | 1303 constraint_factory_.Reset(); |
1305 constraint_factory_.basic().height.setExact(100); | 1304 constraint_factory_.basic().height.setExact(100); |
1306 VideoCaptureCapabilities capabilities; | 1305 VideoDeviceCaptureCapabilities capabilities; |
1307 auto result = SelectVideoCaptureSourceSettings( | 1306 auto result = SelectVideoDeviceCaptureSourceSettings( |
1308 capabilities, constraint_factory_.CreateWebMediaConstraints()); | 1307 capabilities, constraint_factory_.CreateWebMediaConstraints()); |
1309 EXPECT_FALSE(result.has_value()); | 1308 EXPECT_FALSE(result.HasValue()); |
1310 EXPECT_TRUE(std::string(result.failed_constraint_name).empty()); | 1309 EXPECT_TRUE(std::string(result.failed_constraint_name).empty()); |
1311 } | 1310 } |
1312 | 1311 |
1313 } // namespace content | 1312 } // namespace content |
OLD | NEW |