OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/media/media_stream_constraints_util_video_device.h" | 5 #include "content/renderer/media/media_stream_constraints_util_video_device.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/optional.h" | 10 #include "base/optional.h" |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 | 133 |
134 MockConstraintFactory constraint_factory_; | 134 MockConstraintFactory constraint_factory_; |
135 }; | 135 }; |
136 | 136 |
137 // The Unconstrained test checks the default selection criteria. | 137 // The Unconstrained test checks the default selection criteria. |
138 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, Unconstrained) { | 138 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, Unconstrained) { |
139 constraint_factory_.Reset(); | 139 constraint_factory_.Reset(); |
140 auto result = SelectSettings(); | 140 auto result = SelectSettings(); |
141 EXPECT_TRUE(result.HasValue()); | 141 EXPECT_TRUE(result.HasValue()); |
142 // Should select the default device with closest-to-default settings. | 142 // Should select the default device with closest-to-default settings. |
143 EXPECT_EQ(default_device_->device_id, result.device_id); | 143 EXPECT_EQ(default_device_->device_id, result.device_id()); |
144 EXPECT_EQ(default_device_->facing_mode, result.facing_mode); | 144 EXPECT_EQ(default_device_->facing_mode, result.facing_mode()); |
145 EXPECT_EQ(*default_closest_format_, result.Format()); | 145 EXPECT_EQ(*default_closest_format_, result.Format()); |
146 // Should select default settings for other constraints. | 146 // Should select default settings for other constraints. |
147 EXPECT_EQ(media::PowerLineFrequency::FREQUENCY_DEFAULT, | 147 EXPECT_EQ(media::PowerLineFrequency::FREQUENCY_DEFAULT, |
148 result.PowerLineFrequency()); | 148 result.PowerLineFrequency()); |
149 EXPECT_EQ(rtc::Optional<bool>(), result.noise_reduction); | 149 EXPECT_EQ(rtc::Optional<bool>(), result.noise_reduction()); |
150 } | 150 } |
151 | 151 |
152 // The "Overconstrained" tests verify that failure of any single required | 152 // The "Overconstrained" tests verify that failure of any single required |
153 // constraint results in failure to select a candidate. | 153 // constraint results in failure to select a candidate. |
154 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, OverconstrainedOnDeviceID) { | 154 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, OverconstrainedOnDeviceID) { |
155 constraint_factory_.Reset(); | 155 constraint_factory_.Reset(); |
156 constraint_factory_.basic().deviceId.setExact( | 156 constraint_factory_.basic().deviceId.setExact( |
157 blink::WebString::fromASCII("NONEXISTING")); | 157 blink::WebString::fromASCII("NONEXISTING")); |
158 auto result = SelectSettings(); | 158 auto result = SelectSettings(); |
159 EXPECT_FALSE(result.HasValue()); | 159 EXPECT_FALSE(result.HasValue()); |
160 EXPECT_EQ(constraint_factory_.basic().deviceId.name(), | 160 EXPECT_EQ(constraint_factory_.basic().deviceId.name(), |
161 result.failed_constraint_name); | 161 result.failed_constraint_name()); |
162 } | 162 } |
163 | 163 |
164 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, OverconstrainedOnFacingMode) { | 164 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, OverconstrainedOnFacingMode) { |
165 constraint_factory_.Reset(); | 165 constraint_factory_.Reset(); |
166 // No device in |capabilities_| has facing mode equal to LEFT. | 166 // No device in |capabilities_| has facing mode equal to LEFT. |
167 constraint_factory_.basic().facingMode.setExact( | 167 constraint_factory_.basic().facingMode.setExact( |
168 blink::WebString::fromASCII("left")); | 168 blink::WebString::fromASCII("left")); |
169 auto result = SelectSettings(); | 169 auto result = SelectSettings(); |
170 EXPECT_FALSE(result.HasValue()); | 170 EXPECT_FALSE(result.HasValue()); |
171 EXPECT_EQ(constraint_factory_.basic().facingMode.name(), | 171 EXPECT_EQ(constraint_factory_.basic().facingMode.name(), |
172 result.failed_constraint_name); | 172 result.failed_constraint_name()); |
173 } | 173 } |
174 | 174 |
175 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, OverconstrainedOnVideoKind) { | 175 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, OverconstrainedOnVideoKind) { |
176 constraint_factory_.Reset(); | 176 constraint_factory_.Reset(); |
177 // No device in |capabilities_| has video kind infrared. | 177 // No device in |capabilities_| has video kind infrared. |
178 constraint_factory_.basic().videoKind.setExact( | 178 constraint_factory_.basic().videoKind.setExact( |
179 blink::WebString::fromASCII("infrared")); | 179 blink::WebString::fromASCII("infrared")); |
180 auto result = SelectSettings(); | 180 auto result = SelectSettings(); |
181 EXPECT_FALSE(result.HasValue()); | 181 EXPECT_FALSE(result.HasValue()); |
182 EXPECT_EQ(constraint_factory_.basic().videoKind.name(), | 182 EXPECT_EQ(constraint_factory_.basic().videoKind.name(), |
183 result.failed_constraint_name); | 183 result.failed_constraint_name()); |
184 } | 184 } |
185 | 185 |
186 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, OverconstrainedOnHeight) { | 186 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, OverconstrainedOnHeight) { |
187 constraint_factory_.Reset(); | 187 constraint_factory_.Reset(); |
188 constraint_factory_.basic().height.setExact(123467890); | 188 constraint_factory_.basic().height.setExact(123467890); |
189 auto result = SelectSettings(); | 189 auto result = SelectSettings(); |
190 EXPECT_FALSE(result.HasValue()); | 190 EXPECT_FALSE(result.HasValue()); |
191 EXPECT_EQ(constraint_factory_.basic().height.name(), | 191 EXPECT_EQ(constraint_factory_.basic().height.name(), |
192 result.failed_constraint_name); | 192 result.failed_constraint_name()); |
193 | 193 |
194 constraint_factory_.Reset(); | 194 constraint_factory_.Reset(); |
195 constraint_factory_.basic().height.setMin(123467890); | 195 constraint_factory_.basic().height.setMin(123467890); |
196 result = SelectSettings(); | 196 result = SelectSettings(); |
197 EXPECT_FALSE(result.HasValue()); | 197 EXPECT_FALSE(result.HasValue()); |
198 EXPECT_EQ(constraint_factory_.basic().height.name(), | 198 EXPECT_EQ(constraint_factory_.basic().height.name(), |
199 result.failed_constraint_name); | 199 result.failed_constraint_name()); |
200 | 200 |
201 constraint_factory_.Reset(); | 201 constraint_factory_.Reset(); |
202 constraint_factory_.basic().height.setMax(0); | 202 constraint_factory_.basic().height.setMax(0); |
203 result = SelectSettings(); | 203 result = SelectSettings(); |
204 EXPECT_FALSE(result.HasValue()); | 204 EXPECT_FALSE(result.HasValue()); |
205 EXPECT_EQ(constraint_factory_.basic().height.name(), | 205 EXPECT_EQ(constraint_factory_.basic().height.name(), |
206 result.failed_constraint_name); | 206 result.failed_constraint_name()); |
207 } | 207 } |
208 | 208 |
209 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, OverconstrainedOnWidth) { | 209 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, OverconstrainedOnWidth) { |
210 constraint_factory_.Reset(); | 210 constraint_factory_.Reset(); |
211 constraint_factory_.basic().width.setExact(123467890); | 211 constraint_factory_.basic().width.setExact(123467890); |
212 auto result = SelectSettings(); | 212 auto result = SelectSettings(); |
213 EXPECT_FALSE(result.HasValue()); | 213 EXPECT_FALSE(result.HasValue()); |
214 EXPECT_EQ(constraint_factory_.basic().width.name(), | 214 EXPECT_EQ(constraint_factory_.basic().width.name(), |
215 result.failed_constraint_name); | 215 result.failed_constraint_name()); |
216 | 216 |
217 constraint_factory_.Reset(); | 217 constraint_factory_.Reset(); |
218 constraint_factory_.basic().width.setMin(123467890); | 218 constraint_factory_.basic().width.setMin(123467890); |
219 result = SelectSettings(); | 219 result = SelectSettings(); |
220 EXPECT_FALSE(result.HasValue()); | 220 EXPECT_FALSE(result.HasValue()); |
221 EXPECT_EQ(constraint_factory_.basic().width.name(), | 221 EXPECT_EQ(constraint_factory_.basic().width.name(), |
222 result.failed_constraint_name); | 222 result.failed_constraint_name()); |
223 | 223 |
224 constraint_factory_.Reset(); | 224 constraint_factory_.Reset(); |
225 constraint_factory_.basic().width.setMax(0); | 225 constraint_factory_.basic().width.setMax(0); |
226 result = SelectSettings(); | 226 result = SelectSettings(); |
227 EXPECT_FALSE(result.HasValue()); | 227 EXPECT_FALSE(result.HasValue()); |
228 EXPECT_EQ(constraint_factory_.basic().width.name(), | 228 EXPECT_EQ(constraint_factory_.basic().width.name(), |
229 result.failed_constraint_name); | 229 result.failed_constraint_name()); |
230 } | 230 } |
231 | 231 |
232 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, | 232 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, |
233 OverconstrainedOnAspectRatio) { | 233 OverconstrainedOnAspectRatio) { |
234 constraint_factory_.Reset(); | 234 constraint_factory_.Reset(); |
235 constraint_factory_.basic().aspectRatio.setExact(123467890.0); | 235 constraint_factory_.basic().aspectRatio.setExact(123467890.0); |
236 auto result = SelectSettings(); | 236 auto result = SelectSettings(); |
237 EXPECT_FALSE(result.HasValue()); | 237 EXPECT_FALSE(result.HasValue()); |
238 EXPECT_EQ(constraint_factory_.basic().aspectRatio.name(), | 238 EXPECT_EQ(constraint_factory_.basic().aspectRatio.name(), |
239 result.failed_constraint_name); | 239 result.failed_constraint_name()); |
240 | 240 |
241 constraint_factory_.Reset(); | 241 constraint_factory_.Reset(); |
242 constraint_factory_.basic().aspectRatio.setMin(123467890.0); | 242 constraint_factory_.basic().aspectRatio.setMin(123467890.0); |
243 result = SelectSettings(); | 243 result = SelectSettings(); |
244 EXPECT_FALSE(result.HasValue()); | 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 constraint_factory_.Reset(); | 248 constraint_factory_.Reset(); |
249 // This value is lower than the minimum supported by sources. | 249 // This value is lower than the minimum supported by sources. |
250 double kLowAspectRatio = 0.01; | 250 double kLowAspectRatio = 0.01; |
251 constraint_factory_.basic().aspectRatio.setMax(kLowAspectRatio); | 251 constraint_factory_.basic().aspectRatio.setMax(kLowAspectRatio); |
252 result = SelectSettings(); | 252 result = SelectSettings(); |
253 EXPECT_FALSE(result.HasValue()); | 253 EXPECT_FALSE(result.HasValue()); |
254 EXPECT_EQ(constraint_factory_.basic().aspectRatio.name(), | 254 EXPECT_EQ(constraint_factory_.basic().aspectRatio.name(), |
255 result.failed_constraint_name); | 255 result.failed_constraint_name()); |
256 } | 256 } |
257 | 257 |
258 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, OverconstrainedOnFrameRate) { | 258 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, OverconstrainedOnFrameRate) { |
259 constraint_factory_.Reset(); | 259 constraint_factory_.Reset(); |
260 constraint_factory_.basic().frameRate.setExact(123467890.0); | 260 constraint_factory_.basic().frameRate.setExact(123467890.0); |
261 auto result = SelectSettings(); | 261 auto result = SelectSettings(); |
262 EXPECT_FALSE(result.HasValue()); | 262 EXPECT_FALSE(result.HasValue()); |
263 EXPECT_EQ(constraint_factory_.basic().frameRate.name(), | 263 EXPECT_EQ(constraint_factory_.basic().frameRate.name(), |
264 result.failed_constraint_name); | 264 result.failed_constraint_name()); |
265 | 265 |
266 constraint_factory_.Reset(); | 266 constraint_factory_.Reset(); |
267 constraint_factory_.basic().frameRate.setMin(123467890.0); | 267 constraint_factory_.basic().frameRate.setMin(123467890.0); |
268 result = SelectSettings(); | 268 result = SelectSettings(); |
269 EXPECT_FALSE(result.HasValue()); | 269 EXPECT_FALSE(result.HasValue()); |
270 EXPECT_EQ(constraint_factory_.basic().frameRate.name(), | 270 EXPECT_EQ(constraint_factory_.basic().frameRate.name(), |
271 result.failed_constraint_name); | 271 result.failed_constraint_name()); |
272 | 272 |
273 constraint_factory_.Reset(); | 273 constraint_factory_.Reset(); |
274 constraint_factory_.basic().frameRate.setMax(0.0); | 274 constraint_factory_.basic().frameRate.setMax(0.0); |
275 result = SelectSettings(); | 275 result = SelectSettings(); |
276 EXPECT_FALSE(result.HasValue()); | 276 EXPECT_FALSE(result.HasValue()); |
277 EXPECT_EQ(constraint_factory_.basic().frameRate.name(), | 277 EXPECT_EQ(constraint_factory_.basic().frameRate.name(), |
278 result.failed_constraint_name); | 278 result.failed_constraint_name()); |
279 } | 279 } |
280 | 280 |
281 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, | 281 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, |
282 OverconstrainedOnPowerLineFrequency) { | 282 OverconstrainedOnPowerLineFrequency) { |
283 constraint_factory_.Reset(); | 283 constraint_factory_.Reset(); |
284 constraint_factory_.basic().googPowerLineFrequency.setExact(123467890); | 284 constraint_factory_.basic().googPowerLineFrequency.setExact(123467890); |
285 auto result = SelectSettings(); | 285 auto result = SelectSettings(); |
286 EXPECT_FALSE(result.HasValue()); | 286 EXPECT_FALSE(result.HasValue()); |
287 EXPECT_EQ(constraint_factory_.basic().googPowerLineFrequency.name(), | 287 EXPECT_EQ(constraint_factory_.basic().googPowerLineFrequency.name(), |
288 result.failed_constraint_name); | 288 result.failed_constraint_name()); |
289 | 289 |
290 constraint_factory_.Reset(); | 290 constraint_factory_.Reset(); |
291 constraint_factory_.basic().googPowerLineFrequency.setMin(123467890); | 291 constraint_factory_.basic().googPowerLineFrequency.setMin(123467890); |
292 result = SelectSettings(); | 292 result = SelectSettings(); |
293 EXPECT_FALSE(result.HasValue()); | 293 EXPECT_FALSE(result.HasValue()); |
294 EXPECT_EQ(constraint_factory_.basic().googPowerLineFrequency.name(), | 294 EXPECT_EQ(constraint_factory_.basic().googPowerLineFrequency.name(), |
295 result.failed_constraint_name); | 295 result.failed_constraint_name()); |
296 | 296 |
297 constraint_factory_.Reset(); | 297 constraint_factory_.Reset(); |
298 constraint_factory_.basic().googPowerLineFrequency.setMax(-1); | 298 constraint_factory_.basic().googPowerLineFrequency.setMax(-1); |
299 result = SelectSettings(); | 299 result = SelectSettings(); |
300 EXPECT_FALSE(result.HasValue()); | 300 EXPECT_FALSE(result.HasValue()); |
301 EXPECT_EQ(constraint_factory_.basic().googPowerLineFrequency.name(), | 301 EXPECT_EQ(constraint_factory_.basic().googPowerLineFrequency.name(), |
302 result.failed_constraint_name); | 302 result.failed_constraint_name()); |
303 } | 303 } |
304 | 304 |
305 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, | 305 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, |
306 OverconstrainedOnNoiseReduction) { | 306 OverconstrainedOnNoiseReduction) { |
307 // Simulate a system that does not support noise reduction. | 307 // Simulate a system that does not support noise reduction. |
308 // Manually adding device capabilities because VideoDeviceCaptureCapabilities | 308 // Manually adding device capabilities because VideoDeviceCaptureCapabilities |
309 // is move only. | 309 // is move only. |
310 VideoDeviceCaptureCapabilities capabilities; | 310 VideoDeviceCaptureCapabilities capabilities; |
311 ::mojom::VideoInputDeviceCapabilitiesPtr device = | 311 ::mojom::VideoInputDeviceCapabilitiesPtr device = |
312 ::mojom::VideoInputDeviceCapabilities::New(); | 312 ::mojom::VideoInputDeviceCapabilities::New(); |
313 device->device_id = kDeviceID1; | 313 device->device_id = kDeviceID1; |
314 device->facing_mode = ::mojom::FacingMode::NONE; | 314 device->facing_mode = ::mojom::FacingMode::NONE; |
315 device->formats = { | 315 device->formats = { |
316 media::VideoCaptureFormat(gfx::Size(200, 200), 40.0f, | 316 media::VideoCaptureFormat(gfx::Size(200, 200), 40.0f, |
317 media::PIXEL_FORMAT_I420), | 317 media::PIXEL_FORMAT_I420), |
318 }; | 318 }; |
319 capabilities.device_capabilities.push_back(std::move(device)); | 319 capabilities.device_capabilities.push_back(std::move(device)); |
320 capabilities.power_line_capabilities = capabilities_.power_line_capabilities; | 320 capabilities.power_line_capabilities = capabilities_.power_line_capabilities; |
321 capabilities.noise_reduction_capabilities = {rtc::Optional<bool>(false)}; | 321 capabilities.noise_reduction_capabilities = {rtc::Optional<bool>(false)}; |
322 | 322 |
323 constraint_factory_.Reset(); | 323 constraint_factory_.Reset(); |
324 constraint_factory_.basic().googNoiseReduction.setExact(true); | 324 constraint_factory_.basic().googNoiseReduction.setExact(true); |
325 auto constraints = constraint_factory_.CreateWebMediaConstraints(); | 325 auto constraints = constraint_factory_.CreateWebMediaConstraints(); |
326 auto result = | 326 auto result = |
327 SelectVideoDeviceCaptureSourceSettings(capabilities, constraints); | 327 SelectVideoDeviceCaptureSourceSettings(capabilities, constraints); |
328 EXPECT_FALSE(result.HasValue()); | 328 EXPECT_FALSE(result.HasValue()); |
329 EXPECT_EQ(constraint_factory_.basic().googNoiseReduction.name(), | 329 EXPECT_EQ(constraint_factory_.basic().googNoiseReduction.name(), |
330 result.failed_constraint_name); | 330 result.failed_constraint_name()); |
331 } | 331 } |
332 | 332 |
333 // The "Mandatory" and "Ideal" tests check that various selection criteria work | 333 // The "Mandatory" and "Ideal" tests check that various selection criteria work |
334 // for each individual constraint in the basic constraint set. | 334 // for each individual constraint in the basic constraint set. |
335 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryDeviceID) { | 335 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryDeviceID) { |
336 constraint_factory_.Reset(); | 336 constraint_factory_.Reset(); |
337 constraint_factory_.basic().deviceId.setExact( | 337 constraint_factory_.basic().deviceId.setExact( |
338 blink::WebString::fromASCII(default_device_->device_id)); | 338 blink::WebString::fromASCII(default_device_->device_id)); |
339 auto result = SelectSettings(); | 339 auto result = SelectSettings(); |
340 EXPECT_TRUE(result.HasValue()); | 340 EXPECT_TRUE(result.HasValue()); |
341 EXPECT_EQ(default_device_->device_id, result.device_id); | 341 EXPECT_EQ(default_device_->device_id, result.device_id()); |
342 EXPECT_EQ(*default_closest_format_, result.Format()); | 342 EXPECT_EQ(*default_closest_format_, result.Format()); |
343 EXPECT_EQ(media::PowerLineFrequency::FREQUENCY_DEFAULT, | 343 EXPECT_EQ(media::PowerLineFrequency::FREQUENCY_DEFAULT, |
344 result.PowerLineFrequency()); | 344 result.PowerLineFrequency()); |
345 | 345 |
346 constraint_factory_.basic().deviceId.setExact( | 346 constraint_factory_.basic().deviceId.setExact( |
347 blink::WebString::fromASCII(low_res_device_->device_id)); | 347 blink::WebString::fromASCII(low_res_device_->device_id)); |
348 result = SelectSettings(); | 348 result = SelectSettings(); |
349 EXPECT_EQ(low_res_device_->device_id, result.device_id); | 349 EXPECT_EQ(low_res_device_->device_id, result.device_id()); |
350 EXPECT_EQ(*low_res_closest_format_, result.Format()); | 350 EXPECT_EQ(*low_res_closest_format_, result.Format()); |
351 EXPECT_EQ(media::PowerLineFrequency::FREQUENCY_DEFAULT, | 351 EXPECT_EQ(media::PowerLineFrequency::FREQUENCY_DEFAULT, |
352 result.PowerLineFrequency()); | 352 result.PowerLineFrequency()); |
353 | 353 |
354 constraint_factory_.basic().deviceId.setExact( | 354 constraint_factory_.basic().deviceId.setExact( |
355 blink::WebString::fromASCII(high_res_device_->device_id)); | 355 blink::WebString::fromASCII(high_res_device_->device_id)); |
356 result = SelectSettings(); | 356 result = SelectSettings(); |
357 EXPECT_EQ(high_res_device_->device_id, result.device_id); | 357 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
358 EXPECT_EQ(*high_res_closest_format_, result.Format()); | 358 EXPECT_EQ(*high_res_closest_format_, result.Format()); |
359 EXPECT_EQ(media::PowerLineFrequency::FREQUENCY_DEFAULT, | 359 EXPECT_EQ(media::PowerLineFrequency::FREQUENCY_DEFAULT, |
360 result.PowerLineFrequency()); | 360 result.PowerLineFrequency()); |
361 } | 361 } |
362 | 362 |
363 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryFacingMode) { | 363 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryFacingMode) { |
364 constraint_factory_.Reset(); | 364 constraint_factory_.Reset(); |
365 constraint_factory_.basic().facingMode.setExact( | 365 constraint_factory_.basic().facingMode.setExact( |
366 blink::WebString::fromASCII("environment")); | 366 blink::WebString::fromASCII("environment")); |
367 auto result = SelectSettings(); | 367 auto result = SelectSettings(); |
368 EXPECT_TRUE(result.HasValue()); | 368 EXPECT_TRUE(result.HasValue()); |
369 EXPECT_EQ(::mojom::FacingMode::ENVIRONMENT, result.facing_mode); | 369 EXPECT_EQ(::mojom::FacingMode::ENVIRONMENT, result.facing_mode()); |
370 // Only the low-res device supports environment facing mode. Should select | 370 // Only the low-res device supports environment facing mode. Should select |
371 // default settings for everything else. | 371 // default settings for everything else. |
372 EXPECT_EQ(low_res_device_->device_id, result.device_id); | 372 EXPECT_EQ(low_res_device_->device_id, result.device_id()); |
373 EXPECT_EQ(*low_res_closest_format_, result.Format()); | 373 EXPECT_EQ(*low_res_closest_format_, result.Format()); |
374 EXPECT_EQ(media::PowerLineFrequency::FREQUENCY_DEFAULT, | 374 EXPECT_EQ(media::PowerLineFrequency::FREQUENCY_DEFAULT, |
375 result.PowerLineFrequency()); | 375 result.PowerLineFrequency()); |
376 | 376 |
377 constraint_factory_.basic().facingMode.setExact( | 377 constraint_factory_.basic().facingMode.setExact( |
378 blink::WebString::fromASCII("user")); | 378 blink::WebString::fromASCII("user")); |
379 result = SelectSettings(); | 379 result = SelectSettings(); |
380 EXPECT_TRUE(result.HasValue()); | 380 EXPECT_TRUE(result.HasValue()); |
381 EXPECT_EQ(::mojom::FacingMode::USER, result.facing_mode); | 381 EXPECT_EQ(::mojom::FacingMode::USER, result.facing_mode()); |
382 // Only the high-res device supports user facing mode. Should select default | 382 // Only the high-res device supports user facing mode. Should select default |
383 // settings for everything else. | 383 // settings for everything else. |
384 EXPECT_EQ(high_res_device_->device_id, result.device_id); | 384 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
385 EXPECT_EQ(*high_res_closest_format_, result.Format()); | 385 EXPECT_EQ(*high_res_closest_format_, result.Format()); |
386 EXPECT_EQ(media::PowerLineFrequency::FREQUENCY_DEFAULT, | 386 EXPECT_EQ(media::PowerLineFrequency::FREQUENCY_DEFAULT, |
387 result.PowerLineFrequency()); | 387 result.PowerLineFrequency()); |
388 } | 388 } |
389 | 389 |
390 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryVideoKind) { | 390 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryVideoKind) { |
391 constraint_factory_.Reset(); | 391 constraint_factory_.Reset(); |
392 constraint_factory_.basic().videoKind.setExact( | 392 constraint_factory_.basic().videoKind.setExact( |
393 blink::WebString::fromASCII("depth")); | 393 blink::WebString::fromASCII("depth")); |
394 auto result = SelectSettings(); | 394 auto result = SelectSettings(); |
395 EXPECT_TRUE(result.HasValue()); | 395 EXPECT_TRUE(result.HasValue()); |
396 EXPECT_EQ(kDeviceID4, result.device_id); | 396 EXPECT_EQ(kDeviceID4, result.device_id()); |
397 EXPECT_EQ(media::PIXEL_FORMAT_Y16, result.Format().pixel_format); | 397 EXPECT_EQ(media::PIXEL_FORMAT_Y16, result.Format().pixel_format); |
398 | 398 |
399 constraint_factory_.basic().videoKind.setExact( | 399 constraint_factory_.basic().videoKind.setExact( |
400 blink::WebString::fromASCII("color")); | 400 blink::WebString::fromASCII("color")); |
401 result = SelectSettings(); | 401 result = SelectSettings(); |
402 EXPECT_TRUE(result.HasValue()); | 402 EXPECT_TRUE(result.HasValue()); |
403 EXPECT_EQ(default_device_->device_id, result.device_id); | 403 EXPECT_EQ(default_device_->device_id, result.device_id()); |
404 } | 404 } |
405 | 405 |
406 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryPowerLineFrequency) { | 406 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryPowerLineFrequency) { |
407 constraint_factory_.Reset(); | 407 constraint_factory_.Reset(); |
408 const media::PowerLineFrequency kPowerLineFrequencies[] = { | 408 const media::PowerLineFrequency kPowerLineFrequencies[] = { |
409 media::PowerLineFrequency::FREQUENCY_50HZ, | 409 media::PowerLineFrequency::FREQUENCY_50HZ, |
410 media::PowerLineFrequency::FREQUENCY_60HZ}; | 410 media::PowerLineFrequency::FREQUENCY_60HZ}; |
411 for (auto power_line_frequency : kPowerLineFrequencies) { | 411 for (auto power_line_frequency : kPowerLineFrequencies) { |
412 constraint_factory_.basic().googPowerLineFrequency.setExact( | 412 constraint_factory_.basic().googPowerLineFrequency.setExact( |
413 static_cast<long>(power_line_frequency)); | 413 static_cast<long>(power_line_frequency)); |
414 auto result = SelectSettings(); | 414 auto result = SelectSettings(); |
415 EXPECT_TRUE(result.HasValue()); | 415 EXPECT_TRUE(result.HasValue()); |
416 EXPECT_EQ(power_line_frequency, result.PowerLineFrequency()); | 416 EXPECT_EQ(power_line_frequency, result.PowerLineFrequency()); |
417 // The default device and settings closest to the default should be | 417 // The default device and settings closest to the default should be |
418 // selected. | 418 // selected. |
419 EXPECT_EQ(default_device_->device_id, result.device_id); | 419 EXPECT_EQ(default_device_->device_id, result.device_id()); |
420 EXPECT_EQ(default_device_->facing_mode, result.facing_mode); | 420 EXPECT_EQ(default_device_->facing_mode, result.facing_mode()); |
421 EXPECT_EQ(*default_closest_format_, result.Format()); | 421 EXPECT_EQ(*default_closest_format_, result.Format()); |
422 } | 422 } |
423 } | 423 } |
424 | 424 |
425 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryNoiseReduction) { | 425 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryNoiseReduction) { |
426 constraint_factory_.Reset(); | 426 constraint_factory_.Reset(); |
427 const bool kNoiseReductionValues[] = {true, false}; | 427 const bool kNoiseReductionValues[] = {true, false}; |
428 for (auto noise_reduction : kNoiseReductionValues) { | 428 for (auto noise_reduction : kNoiseReductionValues) { |
429 constraint_factory_.basic().googNoiseReduction.setExact(noise_reduction); | 429 constraint_factory_.basic().googNoiseReduction.setExact(noise_reduction); |
430 auto result = SelectSettings(); | 430 auto result = SelectSettings(); |
431 EXPECT_TRUE(result.HasValue()); | 431 EXPECT_TRUE(result.HasValue()); |
432 EXPECT_EQ(noise_reduction, result.noise_reduction); | 432 EXPECT_EQ(noise_reduction, result.noise_reduction()); |
433 // The default device and settings closest to the default should be | 433 // The default device and settings closest to the default should be |
434 // selected. | 434 // selected. |
435 EXPECT_EQ(default_device_->device_id, result.device_id); | 435 EXPECT_EQ(default_device_->device_id, result.device_id()); |
436 EXPECT_EQ(default_device_->facing_mode, result.facing_mode); | 436 EXPECT_EQ(default_device_->facing_mode, result.facing_mode()); |
437 EXPECT_EQ(*default_closest_format_, result.Format()); | 437 EXPECT_EQ(*default_closest_format_, result.Format()); |
438 } | 438 } |
439 } | 439 } |
440 | 440 |
441 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryExactHeight) { | 441 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryExactHeight) { |
442 constraint_factory_.Reset(); | 442 constraint_factory_.Reset(); |
443 const int kHeight = MediaStreamVideoSource::kDefaultHeight; | 443 const int kHeight = MediaStreamVideoSource::kDefaultHeight; |
444 constraint_factory_.basic().height.setExact(kHeight); | 444 constraint_factory_.basic().height.setExact(kHeight); |
445 auto result = SelectSettings(); | 445 auto result = SelectSettings(); |
446 EXPECT_TRUE(result.HasValue()); | 446 EXPECT_TRUE(result.HasValue()); |
447 // All devices in |capabilities_| support the requested height. The algorithm | 447 // All devices in |capabilities_| support the requested height. The algorithm |
448 // should prefer the first device that supports the requested height natively, | 448 // should prefer the first device that supports the requested height natively, |
449 // which is the low-res device. | 449 // which is the low-res device. |
450 EXPECT_EQ(low_res_device_->device_id, result.device_id); | 450 EXPECT_EQ(low_res_device_->device_id, result.device_id()); |
451 EXPECT_EQ(kHeight, result.Height()); | 451 EXPECT_EQ(kHeight, result.Height()); |
452 | 452 |
453 const int kLargeHeight = 1500; | 453 const int kLargeHeight = 1500; |
454 constraint_factory_.basic().height.setExact(kLargeHeight); | 454 constraint_factory_.basic().height.setExact(kLargeHeight); |
455 result = SelectSettings(); | 455 result = SelectSettings(); |
456 EXPECT_TRUE(result.HasValue()); | 456 EXPECT_TRUE(result.HasValue()); |
457 // Only the high-res device at the highest resolution supports the requested | 457 // Only the high-res device at the highest resolution supports the requested |
458 // height, even if not natively. | 458 // height, even if not natively. |
459 EXPECT_EQ(high_res_device_->device_id, result.device_id); | 459 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
460 EXPECT_EQ(*high_res_highest_format_, result.Format()); | 460 EXPECT_EQ(*high_res_highest_format_, result.Format()); |
461 } | 461 } |
462 | 462 |
463 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryMinHeight) { | 463 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryMinHeight) { |
464 constraint_factory_.Reset(); | 464 constraint_factory_.Reset(); |
465 const int kHeight = MediaStreamVideoSource::kDefaultHeight; | 465 const int kHeight = MediaStreamVideoSource::kDefaultHeight; |
466 constraint_factory_.basic().height.setMin(kHeight); | 466 constraint_factory_.basic().height.setMin(kHeight); |
467 auto result = SelectSettings(); | 467 auto result = SelectSettings(); |
468 EXPECT_TRUE(result.HasValue()); | 468 EXPECT_TRUE(result.HasValue()); |
469 // All devices in |capabilities_| support the requested height range. The | 469 // All devices in |capabilities_| support the requested height range. The |
470 // algorithm should prefer the default device. | 470 // algorithm should prefer the default device. |
471 EXPECT_EQ(default_device_->device_id, result.device_id); | 471 EXPECT_EQ(default_device_->device_id, result.device_id()); |
472 EXPECT_LE(kHeight, result.Height()); | 472 EXPECT_LE(kHeight, result.Height()); |
473 | 473 |
474 const int kLargeHeight = 1500; | 474 const int kLargeHeight = 1500; |
475 constraint_factory_.basic().height.setMin(kLargeHeight); | 475 constraint_factory_.basic().height.setMin(kLargeHeight); |
476 result = SelectSettings(); | 476 result = SelectSettings(); |
477 EXPECT_TRUE(result.HasValue()); | 477 EXPECT_TRUE(result.HasValue()); |
478 // Only the high-res device at the highest resolution supports the requested | 478 // Only the high-res device at the highest resolution supports the requested |
479 // height range. | 479 // height range. |
480 EXPECT_EQ(high_res_device_->device_id, result.device_id); | 480 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
481 EXPECT_EQ(*high_res_highest_format_, result.Format()); | 481 EXPECT_EQ(*high_res_highest_format_, result.Format()); |
482 } | 482 } |
483 | 483 |
484 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryMaxHeight) { | 484 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryMaxHeight) { |
485 constraint_factory_.Reset(); | 485 constraint_factory_.Reset(); |
486 const int kLowHeight = 20; | 486 const int kLowHeight = 20; |
487 constraint_factory_.basic().height.setMax(kLowHeight); | 487 constraint_factory_.basic().height.setMax(kLowHeight); |
488 auto result = SelectSettings(); | 488 auto result = SelectSettings(); |
489 EXPECT_TRUE(result.HasValue()); | 489 EXPECT_TRUE(result.HasValue()); |
490 // All devices in |capabilities_| support the requested height range. The | 490 // All devices in |capabilities_| support the requested height range. The |
491 // algorithm should prefer the settings that natively exceed the requested | 491 // algorithm should prefer the settings that natively exceed the requested |
492 // maximum by the lowest amount. In this case it is the low-res device. | 492 // maximum by the lowest amount. In this case it is the low-res device. |
493 EXPECT_EQ(low_res_device_->device_id, result.device_id); | 493 EXPECT_EQ(low_res_device_->device_id, result.device_id()); |
494 EXPECT_EQ(low_res_device_->formats[0], result.Format()); | 494 EXPECT_EQ(low_res_device_->formats[0], result.Format()); |
495 } | 495 } |
496 | 496 |
497 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryHeightRange) { | 497 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryHeightRange) { |
498 constraint_factory_.Reset(); | 498 constraint_factory_.Reset(); |
499 { | 499 { |
500 const int kMinHeight = 480; | 500 const int kMinHeight = 480; |
501 const int kMaxHeight = 720; | 501 const int kMaxHeight = 720; |
502 constraint_factory_.basic().height.setMin(kMinHeight); | 502 constraint_factory_.basic().height.setMin(kMinHeight); |
503 constraint_factory_.basic().height.setMax(kMaxHeight); | 503 constraint_factory_.basic().height.setMax(kMaxHeight); |
504 auto result = SelectSettings(); | 504 auto result = SelectSettings(); |
505 EXPECT_TRUE(result.HasValue()); | 505 EXPECT_TRUE(result.HasValue()); |
506 EXPECT_GE(result.Height(), kMinHeight); | 506 EXPECT_GE(result.Height(), kMinHeight); |
507 EXPECT_LE(result.Height(), kMaxHeight); | 507 EXPECT_LE(result.Height(), kMaxHeight); |
508 // All devices in |capabilities_| support the constraint range. The | 508 // All devices in |capabilities_| support the constraint range. The |
509 // algorithm should prefer the default device since it has at least one | 509 // algorithm should prefer the default device since it has at least one |
510 // native format (the closest-to-default format) included in the requested | 510 // native format (the closest-to-default format) included in the requested |
511 // range. | 511 // range. |
512 EXPECT_EQ(default_device_->device_id, result.device_id); | 512 EXPECT_EQ(default_device_->device_id, result.device_id()); |
513 EXPECT_EQ(*default_closest_format_, result.Format()); | 513 EXPECT_EQ(*default_closest_format_, result.Format()); |
514 } | 514 } |
515 | 515 |
516 { | 516 { |
517 const int kMinHeight = 550; | 517 const int kMinHeight = 550; |
518 const int kMaxHeight = 650; | 518 const int kMaxHeight = 650; |
519 constraint_factory_.basic().height.setMin(kMinHeight); | 519 constraint_factory_.basic().height.setMin(kMinHeight); |
520 constraint_factory_.basic().height.setMax(kMaxHeight); | 520 constraint_factory_.basic().height.setMax(kMaxHeight); |
521 auto result = SelectSettings(); | 521 auto result = SelectSettings(); |
522 EXPECT_TRUE(result.HasValue()); | 522 EXPECT_TRUE(result.HasValue()); |
523 EXPECT_GE(result.Height(), kMinHeight); | 523 EXPECT_GE(result.Height(), kMinHeight); |
524 EXPECT_LE(result.Height(), kMaxHeight); | 524 EXPECT_LE(result.Height(), kMaxHeight); |
525 // In this case, the algorithm should prefer the low-res device since it is | 525 // In this case, the algorithm should prefer the low-res device since it is |
526 // the first device with a native format (800x600) included in the requested | 526 // the first device with a native format (800x600) included in the requested |
527 // range. | 527 // range. |
528 EXPECT_EQ(low_res_device_->device_id, result.device_id); | 528 EXPECT_EQ(low_res_device_->device_id, result.device_id()); |
529 EXPECT_EQ(800, result.Width()); | 529 EXPECT_EQ(800, result.Width()); |
530 EXPECT_EQ(600, result.Height()); | 530 EXPECT_EQ(600, result.Height()); |
531 } | 531 } |
532 | 532 |
533 { | 533 { |
534 const int kMinHeight = 700; | 534 const int kMinHeight = 700; |
535 const int kMaxHeight = 800; | 535 const int kMaxHeight = 800; |
536 constraint_factory_.basic().height.setMin(kMinHeight); | 536 constraint_factory_.basic().height.setMin(kMinHeight); |
537 constraint_factory_.basic().height.setMax(kMaxHeight); | 537 constraint_factory_.basic().height.setMax(kMaxHeight); |
538 auto result = SelectSettings(); | 538 auto result = SelectSettings(); |
539 EXPECT_TRUE(result.HasValue()); | 539 EXPECT_TRUE(result.HasValue()); |
540 EXPECT_GE(result.Height(), kMinHeight); | 540 EXPECT_GE(result.Height(), kMinHeight); |
541 EXPECT_LE(result.Height(), kMaxHeight); | 541 EXPECT_LE(result.Height(), kMaxHeight); |
542 // In this case, the algorithm should prefer the high-res device since it is | 542 // In this case, the algorithm should prefer the high-res device since it is |
543 // the only device with a native format (1280x720) included in the requested | 543 // the only device with a native format (1280x720) included in the requested |
544 // range. | 544 // range. |
545 EXPECT_EQ(high_res_device_->device_id, result.device_id); | 545 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
546 EXPECT_EQ(1280, result.Width()); | 546 EXPECT_EQ(1280, result.Width()); |
547 EXPECT_EQ(720, result.Height()); | 547 EXPECT_EQ(720, result.Height()); |
548 } | 548 } |
549 } | 549 } |
550 | 550 |
551 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, IdealHeight) { | 551 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, IdealHeight) { |
552 constraint_factory_.Reset(); | 552 constraint_factory_.Reset(); |
553 { | 553 { |
554 const int kIdealHeight = 480; | 554 const int kIdealHeight = 480; |
555 constraint_factory_.basic().height.setIdeal(kIdealHeight); | 555 constraint_factory_.basic().height.setIdeal(kIdealHeight); |
556 auto result = SelectSettings(); | 556 auto result = SelectSettings(); |
557 EXPECT_TRUE(result.HasValue()); | 557 EXPECT_TRUE(result.HasValue()); |
558 // The algorithm should select the first device that supports the ideal | 558 // The algorithm should select the first device that supports the ideal |
559 // height natively. | 559 // height natively. |
560 EXPECT_EQ(low_res_device_->device_id, result.device_id); | 560 EXPECT_EQ(low_res_device_->device_id, result.device_id()); |
561 EXPECT_EQ(kIdealHeight, result.Height()); | 561 EXPECT_EQ(kIdealHeight, result.Height()); |
562 } | 562 } |
563 | 563 |
564 { | 564 { |
565 const int kIdealHeight = 481; | 565 const int kIdealHeight = 481; |
566 constraint_factory_.basic().height.setIdeal(kIdealHeight); | 566 constraint_factory_.basic().height.setIdeal(kIdealHeight); |
567 auto result = SelectSettings(); | 567 auto result = SelectSettings(); |
568 EXPECT_TRUE(result.HasValue()); | 568 EXPECT_TRUE(result.HasValue()); |
569 // In this case, the default device is selected because it can satisfy the | 569 // In this case, the default device is selected because it can satisfy the |
570 // ideal at a lower cost than the other devices (500 vs 600 or 720). | 570 // ideal at a lower cost than the other devices (500 vs 600 or 720). |
571 // Note that a native resolution of 480 is further from the ideal than | 571 // Note that a native resolution of 480 is further from the ideal than |
572 // 500 cropped to 480. | 572 // 500 cropped to 480. |
573 EXPECT_EQ(default_device_->device_id, result.device_id); | 573 EXPECT_EQ(default_device_->device_id, result.device_id()); |
574 EXPECT_EQ(*default_closest_format_, result.Format()); | 574 EXPECT_EQ(*default_closest_format_, result.Format()); |
575 } | 575 } |
576 | 576 |
577 { | 577 { |
578 const int kIdealHeight = 1079; | 578 const int kIdealHeight = 1079; |
579 constraint_factory_.basic().height.setIdeal(kIdealHeight); | 579 constraint_factory_.basic().height.setIdeal(kIdealHeight); |
580 auto result = SelectSettings(); | 580 auto result = SelectSettings(); |
581 EXPECT_TRUE(result.HasValue()); | 581 EXPECT_TRUE(result.HasValue()); |
582 // In this case, the high-res device has two configurations that satisfy | 582 // In this case, the high-res device has two configurations that satisfy |
583 // the ideal value (1920x1080 and 2304x1536). Select the one with shortest | 583 // the ideal value (1920x1080 and 2304x1536). Select the one with shortest |
584 // native distance to the ideal value (1920x1080). | 584 // native distance to the ideal value (1920x1080). |
585 EXPECT_EQ(high_res_device_->device_id, result.device_id); | 585 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
586 EXPECT_EQ(1920, result.Width()); | 586 EXPECT_EQ(1920, result.Width()); |
587 EXPECT_EQ(1080, result.Height()); | 587 EXPECT_EQ(1080, result.Height()); |
588 } | 588 } |
589 | 589 |
590 { | 590 { |
591 const int kIdealHeight = 1200; | 591 const int kIdealHeight = 1200; |
592 constraint_factory_.basic().height.setIdeal(kIdealHeight); | 592 constraint_factory_.basic().height.setIdeal(kIdealHeight); |
593 auto result = SelectSettings(); | 593 auto result = SelectSettings(); |
594 EXPECT_TRUE(result.HasValue()); | 594 EXPECT_TRUE(result.HasValue()); |
595 // The algorithm must the select the only device that can satisfy the ideal, | 595 // The algorithm must the select the only device that can satisfy the ideal, |
596 // which is the high-res device at the highest resolution. | 596 // which is the high-res device at the highest resolution. |
597 EXPECT_EQ(high_res_device_->device_id, result.device_id); | 597 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
598 EXPECT_EQ(*high_res_highest_format_, result.Format()); | 598 EXPECT_EQ(*high_res_highest_format_, result.Format()); |
599 } | 599 } |
600 } | 600 } |
601 | 601 |
602 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryExactWidth) { | 602 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryExactWidth) { |
603 constraint_factory_.Reset(); | 603 constraint_factory_.Reset(); |
604 const int kWidth = 640; | 604 const int kWidth = 640; |
605 constraint_factory_.basic().width.setExact(kWidth); | 605 constraint_factory_.basic().width.setExact(kWidth); |
606 auto result = SelectSettings(); | 606 auto result = SelectSettings(); |
607 EXPECT_TRUE(result.HasValue()); | 607 EXPECT_TRUE(result.HasValue()); |
608 // All devices in |capabilities_| support the requested width. The algorithm | 608 // All devices in |capabilities_| support the requested width. The algorithm |
609 // should prefer the first device that supports the requested width natively, | 609 // should prefer the first device that supports the requested width natively, |
610 // which is the low-res device. | 610 // which is the low-res device. |
611 EXPECT_EQ(low_res_device_->device_id, result.device_id); | 611 EXPECT_EQ(low_res_device_->device_id, result.device_id()); |
612 EXPECT_EQ(kWidth, result.Width()); | 612 EXPECT_EQ(kWidth, result.Width()); |
613 | 613 |
614 const int kLargeWidth = 2000; | 614 const int kLargeWidth = 2000; |
615 constraint_factory_.basic().width.setExact(kLargeWidth); | 615 constraint_factory_.basic().width.setExact(kLargeWidth); |
616 result = SelectSettings(); | 616 result = SelectSettings(); |
617 EXPECT_TRUE(result.HasValue()); | 617 EXPECT_TRUE(result.HasValue()); |
618 EXPECT_LE(kLargeWidth, result.Width()); | 618 EXPECT_LE(kLargeWidth, result.Width()); |
619 // Only the high-res device at the highest resolution supports the requested | 619 // Only the high-res device at the highest resolution supports the requested |
620 // width, even if not natively. | 620 // width, even if not natively. |
621 EXPECT_EQ(high_res_device_->device_id, result.device_id); | 621 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
622 EXPECT_EQ(*high_res_highest_format_, result.Format()); | 622 EXPECT_EQ(*high_res_highest_format_, result.Format()); |
623 } | 623 } |
624 | 624 |
625 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryMinWidth) { | 625 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryMinWidth) { |
626 constraint_factory_.Reset(); | 626 constraint_factory_.Reset(); |
627 const int kWidth = 640; | 627 const int kWidth = 640; |
628 constraint_factory_.basic().width.setMin(kWidth); | 628 constraint_factory_.basic().width.setMin(kWidth); |
629 auto result = SelectSettings(); | 629 auto result = SelectSettings(); |
630 EXPECT_TRUE(result.HasValue()); | 630 EXPECT_TRUE(result.HasValue()); |
631 // All devices in |capabilities_| support the requested width range. The | 631 // All devices in |capabilities_| support the requested width range. The |
632 // algorithm should prefer the default device at 1000x1000, which is the | 632 // algorithm should prefer the default device at 1000x1000, which is the |
633 // first configuration that satisfies the minimum width. | 633 // first configuration that satisfies the minimum width. |
634 EXPECT_EQ(default_device_->device_id, result.device_id); | 634 EXPECT_EQ(default_device_->device_id, result.device_id()); |
635 EXPECT_LE(kWidth, result.Width()); | 635 EXPECT_LE(kWidth, result.Width()); |
636 EXPECT_EQ(1000, result.Width()); | 636 EXPECT_EQ(1000, result.Width()); |
637 EXPECT_EQ(1000, result.Height()); | 637 EXPECT_EQ(1000, result.Height()); |
638 | 638 |
639 const int kLargeWidth = 2000; | 639 const int kLargeWidth = 2000; |
640 constraint_factory_.basic().width.setMin(kLargeWidth); | 640 constraint_factory_.basic().width.setMin(kLargeWidth); |
641 result = SelectSettings(); | 641 result = SelectSettings(); |
642 EXPECT_TRUE(result.HasValue()); | 642 EXPECT_TRUE(result.HasValue()); |
643 // Only the high-res device at the highest resolution supports the requested | 643 // Only the high-res device at the highest resolution supports the requested |
644 // minimum width. | 644 // minimum width. |
645 EXPECT_EQ(high_res_device_->device_id, result.device_id); | 645 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
646 EXPECT_LE(kLargeWidth, result.Width()); | 646 EXPECT_LE(kLargeWidth, result.Width()); |
647 EXPECT_EQ(*high_res_highest_format_, result.Format()); | 647 EXPECT_EQ(*high_res_highest_format_, result.Format()); |
648 } | 648 } |
649 | 649 |
650 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryMaxWidth) { | 650 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryMaxWidth) { |
651 constraint_factory_.Reset(); | 651 constraint_factory_.Reset(); |
652 const int kLowWidth = 30; | 652 const int kLowWidth = 30; |
653 constraint_factory_.basic().width.setMax(kLowWidth); | 653 constraint_factory_.basic().width.setMax(kLowWidth); |
654 auto result = SelectSettings(); | 654 auto result = SelectSettings(); |
655 EXPECT_TRUE(result.HasValue()); | 655 EXPECT_TRUE(result.HasValue()); |
656 // All devices in |capabilities_| support the requested width range. The | 656 // All devices in |capabilities_| support the requested width range. The |
657 // algorithm should prefer the settings that natively exceed the requested | 657 // algorithm should prefer the settings that natively exceed the requested |
658 // maximum by the lowest amount. In this case it is the low-res device at its | 658 // maximum by the lowest amount. In this case it is the low-res device at its |
659 // lowest resolution. | 659 // lowest resolution. |
660 EXPECT_EQ(low_res_device_->device_id, result.device_id); | 660 EXPECT_EQ(low_res_device_->device_id, result.device_id()); |
661 EXPECT_EQ(low_res_device_->formats[0], result.Format()); | 661 EXPECT_EQ(low_res_device_->formats[0], result.Format()); |
662 } | 662 } |
663 | 663 |
664 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryWidthRange) { | 664 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryWidthRange) { |
665 constraint_factory_.Reset(); | 665 constraint_factory_.Reset(); |
666 { | 666 { |
667 const int kMinWidth = 640; | 667 const int kMinWidth = 640; |
668 const int kMaxWidth = 1280; | 668 const int kMaxWidth = 1280; |
669 constraint_factory_.basic().width.setMin(kMinWidth); | 669 constraint_factory_.basic().width.setMin(kMinWidth); |
670 constraint_factory_.basic().width.setMax(kMaxWidth); | 670 constraint_factory_.basic().width.setMax(kMaxWidth); |
671 auto result = SelectSettings(); | 671 auto result = SelectSettings(); |
672 EXPECT_TRUE(result.HasValue()); | 672 EXPECT_TRUE(result.HasValue()); |
673 EXPECT_GE(result.Width(), kMinWidth); | 673 EXPECT_GE(result.Width(), kMinWidth); |
674 EXPECT_LE(result.Width(), kMaxWidth); | 674 EXPECT_LE(result.Width(), kMaxWidth); |
675 // All devices in |capabilities_| support the constraint range. The | 675 // All devices in |capabilities_| support the constraint range. The |
676 // algorithm should prefer the default device since it has at least one | 676 // algorithm should prefer the default device since it has at least one |
677 // native format (1000x1000) included in the requested range. | 677 // native format (1000x1000) included in the requested range. |
678 EXPECT_EQ(default_device_->device_id, result.device_id); | 678 EXPECT_EQ(default_device_->device_id, result.device_id()); |
679 EXPECT_EQ(1000, result.Width()); | 679 EXPECT_EQ(1000, result.Width()); |
680 EXPECT_EQ(1000, result.Height()); | 680 EXPECT_EQ(1000, result.Height()); |
681 } | 681 } |
682 | 682 |
683 { | 683 { |
684 const int kMinWidth = 750; | 684 const int kMinWidth = 750; |
685 const int kMaxWidth = 850; | 685 const int kMaxWidth = 850; |
686 constraint_factory_.basic().width.setMin(kMinWidth); | 686 constraint_factory_.basic().width.setMin(kMinWidth); |
687 constraint_factory_.basic().width.setMax(kMaxWidth); | 687 constraint_factory_.basic().width.setMax(kMaxWidth); |
688 auto result = SelectSettings(); | 688 auto result = SelectSettings(); |
689 EXPECT_TRUE(result.HasValue()); | 689 EXPECT_TRUE(result.HasValue()); |
690 EXPECT_GE(result.Width(), kMinWidth); | 690 EXPECT_GE(result.Width(), kMinWidth); |
691 EXPECT_LE(result.Width(), kMaxWidth); | 691 EXPECT_LE(result.Width(), kMaxWidth); |
692 // In this case, the algorithm should prefer the low-res device since it is | 692 // In this case, the algorithm should prefer the low-res device since it is |
693 // the first device with a native format (800x600) included in the requested | 693 // the first device with a native format (800x600) included in the requested |
694 // range. | 694 // range. |
695 EXPECT_EQ(low_res_device_->device_id, result.device_id); | 695 EXPECT_EQ(low_res_device_->device_id, result.device_id()); |
696 EXPECT_EQ(800, result.Width()); | 696 EXPECT_EQ(800, result.Width()); |
697 EXPECT_EQ(600, result.Height()); | 697 EXPECT_EQ(600, result.Height()); |
698 } | 698 } |
699 | 699 |
700 { | 700 { |
701 const int kMinWidth = 1900; | 701 const int kMinWidth = 1900; |
702 const int kMaxWidth = 2000; | 702 const int kMaxWidth = 2000; |
703 constraint_factory_.basic().width.setMin(kMinWidth); | 703 constraint_factory_.basic().width.setMin(kMinWidth); |
704 constraint_factory_.basic().width.setMax(kMaxWidth); | 704 constraint_factory_.basic().width.setMax(kMaxWidth); |
705 auto result = SelectSettings(); | 705 auto result = SelectSettings(); |
706 EXPECT_TRUE(result.HasValue()); | 706 EXPECT_TRUE(result.HasValue()); |
707 EXPECT_GE(result.Width(), kMinWidth); | 707 EXPECT_GE(result.Width(), kMinWidth); |
708 EXPECT_LE(result.Width(), kMaxWidth); | 708 EXPECT_LE(result.Width(), kMaxWidth); |
709 // In this case, the algorithm should prefer the high-res device since it is | 709 // In this case, the algorithm should prefer the high-res device since it is |
710 // the only device with a native format (1920x1080) included in the | 710 // the only device with a native format (1920x1080) included in the |
711 // requested range. | 711 // requested range. |
712 EXPECT_EQ(high_res_device_->device_id, result.device_id); | 712 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
713 EXPECT_EQ(1920, result.Width()); | 713 EXPECT_EQ(1920, result.Width()); |
714 EXPECT_EQ(1080, result.Height()); | 714 EXPECT_EQ(1080, result.Height()); |
715 } | 715 } |
716 } | 716 } |
717 | 717 |
718 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, IdealWidth) { | 718 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, IdealWidth) { |
719 constraint_factory_.Reset(); | 719 constraint_factory_.Reset(); |
720 { | 720 { |
721 const int kIdealWidth = 320; | 721 const int kIdealWidth = 320; |
722 constraint_factory_.basic().width.setIdeal(kIdealWidth); | 722 constraint_factory_.basic().width.setIdeal(kIdealWidth); |
723 auto result = SelectSettings(); | 723 auto result = SelectSettings(); |
724 EXPECT_TRUE(result.HasValue()); | 724 EXPECT_TRUE(result.HasValue()); |
725 // The algorithm should select the first device that supports the ideal | 725 // The algorithm should select the first device that supports the ideal |
726 // width natively, which is the low-res device at 320x240. | 726 // width natively, which is the low-res device at 320x240. |
727 EXPECT_EQ(low_res_device_->device_id, result.device_id); | 727 EXPECT_EQ(low_res_device_->device_id, result.device_id()); |
728 EXPECT_EQ(kIdealWidth, result.Width()); | 728 EXPECT_EQ(kIdealWidth, result.Width()); |
729 } | 729 } |
730 | 730 |
731 { | 731 { |
732 const int kIdealWidth = 321; | 732 const int kIdealWidth = 321; |
733 constraint_factory_.basic().width.setIdeal(kIdealWidth); | 733 constraint_factory_.basic().width.setIdeal(kIdealWidth); |
734 auto result = SelectSettings(); | 734 auto result = SelectSettings(); |
735 EXPECT_TRUE(result.HasValue()); | 735 EXPECT_TRUE(result.HasValue()); |
736 // In this case, the default device is selected because it can satisfy the | 736 // In this case, the default device is selected because it can satisfy the |
737 // ideal at a lower cost than the other devices (500 vs 640). | 737 // ideal at a lower cost than the other devices (500 vs 640). |
738 // Note that a native resolution of 320 is further from the ideal value of | 738 // Note that a native resolution of 320 is further from the ideal value of |
739 // 321 than 500 cropped to 321. | 739 // 321 than 500 cropped to 321. |
740 EXPECT_EQ(default_device_->device_id, result.device_id); | 740 EXPECT_EQ(default_device_->device_id, result.device_id()); |
741 EXPECT_EQ(*default_closest_format_, result.Format()); | 741 EXPECT_EQ(*default_closest_format_, result.Format()); |
742 } | 742 } |
743 | 743 |
744 { | 744 { |
745 const int kIdealWidth = 2000; | 745 const int kIdealWidth = 2000; |
746 constraint_factory_.basic().width.setIdeal(kIdealWidth); | 746 constraint_factory_.basic().width.setIdeal(kIdealWidth); |
747 auto result = SelectSettings(); | 747 auto result = SelectSettings(); |
748 EXPECT_TRUE(result.HasValue()); | 748 EXPECT_TRUE(result.HasValue()); |
749 // The algorithm must the select the only device that can satisfy the ideal. | 749 // The algorithm must the select the only device that can satisfy the ideal. |
750 EXPECT_EQ(high_res_device_->device_id, result.device_id); | 750 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
751 EXPECT_EQ(*high_res_highest_format_, result.Format()); | 751 EXPECT_EQ(*high_res_highest_format_, result.Format()); |
752 } | 752 } |
753 | 753 |
754 { | 754 { |
755 const int kIdealWidth = 3000; | 755 const int kIdealWidth = 3000; |
756 constraint_factory_.basic().width.setIdeal(kIdealWidth); | 756 constraint_factory_.basic().width.setIdeal(kIdealWidth); |
757 auto result = SelectSettings(); | 757 auto result = SelectSettings(); |
758 EXPECT_TRUE(result.HasValue()); | 758 EXPECT_TRUE(result.HasValue()); |
759 // The algorithm must the select the device and setting with less distance | 759 // The algorithm must the select the device and setting with less distance |
760 // to the ideal. | 760 // to the ideal. |
761 EXPECT_EQ(high_res_device_->device_id, result.device_id); | 761 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
762 EXPECT_EQ(*high_res_highest_format_, result.Format()); | 762 EXPECT_EQ(*high_res_highest_format_, result.Format()); |
763 } | 763 } |
764 } | 764 } |
765 | 765 |
766 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryExactFrameRate) { | 766 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryExactFrameRate) { |
767 constraint_factory_.Reset(); | 767 constraint_factory_.Reset(); |
768 const double kFrameRate = MediaStreamVideoSource::kDefaultFrameRate; | 768 const double kFrameRate = MediaStreamVideoSource::kDefaultFrameRate; |
769 constraint_factory_.basic().frameRate.setExact(kFrameRate); | 769 constraint_factory_.basic().frameRate.setExact(kFrameRate); |
770 auto result = SelectSettings(); | 770 auto result = SelectSettings(); |
771 EXPECT_TRUE(result.HasValue()); | 771 EXPECT_TRUE(result.HasValue()); |
772 // All devices in |capabilities_| support the requested frame rate. The | 772 // All devices in |capabilities_| support the requested frame rate. The |
773 // algorithm should prefer the first device that supports the requested frame | 773 // algorithm should prefer the first device that supports the requested frame |
774 // rate natively, which is the low-res device at 640x480x30Hz. | 774 // rate natively, which is the low-res device at 640x480x30Hz. |
775 EXPECT_EQ(low_res_device_->device_id, result.device_id); | 775 EXPECT_EQ(low_res_device_->device_id, result.device_id()); |
776 EXPECT_EQ(kFrameRate, result.FrameRate()); | 776 EXPECT_EQ(kFrameRate, result.FrameRate()); |
777 EXPECT_EQ(640, result.Width()); | 777 EXPECT_EQ(640, result.Width()); |
778 EXPECT_EQ(480, result.Height()); | 778 EXPECT_EQ(480, result.Height()); |
779 | 779 |
780 const double kLargeFrameRate = 50; | 780 const double kLargeFrameRate = 50; |
781 constraint_factory_.basic().frameRate.setExact(kLargeFrameRate); | 781 constraint_factory_.basic().frameRate.setExact(kLargeFrameRate); |
782 result = SelectSettings(); | 782 result = SelectSettings(); |
783 EXPECT_TRUE(result.HasValue()); | 783 EXPECT_TRUE(result.HasValue()); |
784 // Only the high-res device supports the requested frame rate, even if not | 784 // Only the high-res device supports the requested frame rate, even if not |
785 // natively. The least expensive configuration that supports the requested | 785 // natively. The least expensive configuration that supports the requested |
786 // frame rate is 1280x720x60Hz. | 786 // frame rate is 1280x720x60Hz. |
787 EXPECT_EQ(high_res_device_->device_id, result.device_id); | 787 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
788 EXPECT_EQ(60.0, result.FrameRate()); | 788 EXPECT_EQ(60.0, result.FrameRate()); |
789 EXPECT_EQ(1280, result.Width()); | 789 EXPECT_EQ(1280, result.Width()); |
790 EXPECT_EQ(720, result.Height()); | 790 EXPECT_EQ(720, result.Height()); |
791 } | 791 } |
792 | 792 |
793 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryMinFrameRate) { | 793 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryMinFrameRate) { |
794 constraint_factory_.Reset(); | 794 constraint_factory_.Reset(); |
795 const double kFrameRate = MediaStreamVideoSource::kDefaultFrameRate; | 795 const double kFrameRate = MediaStreamVideoSource::kDefaultFrameRate; |
796 constraint_factory_.basic().frameRate.setMin(kFrameRate); | 796 constraint_factory_.basic().frameRate.setMin(kFrameRate); |
797 auto result = SelectSettings(); | 797 auto result = SelectSettings(); |
798 EXPECT_TRUE(result.HasValue()); | 798 EXPECT_TRUE(result.HasValue()); |
799 // All devices in |capabilities_| support the requested frame-rate range. The | 799 // All devices in |capabilities_| support the requested frame-rate range. The |
800 // algorithm should prefer the default device. | 800 // algorithm should prefer the default device. |
801 EXPECT_EQ(default_device_->device_id, result.device_id); | 801 EXPECT_EQ(default_device_->device_id, result.device_id()); |
802 // The format closest to the default satisfies the constraint. | 802 // The format closest to the default satisfies the constraint. |
803 EXPECT_EQ(*default_closest_format_, result.Format()); | 803 EXPECT_EQ(*default_closest_format_, result.Format()); |
804 | 804 |
805 const double kLargeFrameRate = 50; | 805 const double kLargeFrameRate = 50; |
806 constraint_factory_.basic().frameRate.setMin(kLargeFrameRate); | 806 constraint_factory_.basic().frameRate.setMin(kLargeFrameRate); |
807 result = SelectSettings(); | 807 result = SelectSettings(); |
808 EXPECT_TRUE(result.HasValue()); | 808 EXPECT_TRUE(result.HasValue()); |
809 // Only the high-res device supports the requested frame-rate range. | 809 // Only the high-res device supports the requested frame-rate range. |
810 // The least expensive configuration is 1280x720x60Hz. | 810 // The least expensive configuration is 1280x720x60Hz. |
811 EXPECT_EQ(high_res_device_->device_id, result.device_id); | 811 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
812 EXPECT_LE(kLargeFrameRate, result.FrameRate()); | 812 EXPECT_LE(kLargeFrameRate, result.FrameRate()); |
813 EXPECT_EQ(1280, result.Width()); | 813 EXPECT_EQ(1280, result.Width()); |
814 EXPECT_EQ(720, result.Height()); | 814 EXPECT_EQ(720, result.Height()); |
815 } | 815 } |
816 | 816 |
817 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryMaxFrameRate) { | 817 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryMaxFrameRate) { |
818 constraint_factory_.Reset(); | 818 constraint_factory_.Reset(); |
819 const double kLowFrameRate = 10; | 819 const double kLowFrameRate = 10; |
820 constraint_factory_.basic().frameRate.setMax(kLowFrameRate); | 820 constraint_factory_.basic().frameRate.setMax(kLowFrameRate); |
821 auto result = SelectSettings(); | 821 auto result = SelectSettings(); |
822 EXPECT_TRUE(result.HasValue()); | 822 EXPECT_TRUE(result.HasValue()); |
823 // All devices in |capabilities_| support the requested frame-rate range. The | 823 // All devices in |capabilities_| support the requested frame-rate range. The |
824 // algorithm should prefer the settings that natively exceed the requested | 824 // algorithm should prefer the settings that natively exceed the requested |
825 // maximum by the lowest amount. In this case it is the high-res device with | 825 // maximum by the lowest amount. In this case it is the high-res device with |
826 // default resolution . | 826 // default resolution . |
827 EXPECT_EQ(high_res_device_->device_id, result.device_id); | 827 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
828 EXPECT_EQ(kLowFrameRate, result.FrameRate()); | 828 EXPECT_EQ(kLowFrameRate, result.FrameRate()); |
829 EXPECT_EQ(MediaStreamVideoSource::kDefaultHeight, result.Height()); | 829 EXPECT_EQ(MediaStreamVideoSource::kDefaultHeight, result.Height()); |
830 EXPECT_EQ(MediaStreamVideoSource::kDefaultWidth, result.Width()); | 830 EXPECT_EQ(MediaStreamVideoSource::kDefaultWidth, result.Width()); |
831 } | 831 } |
832 | 832 |
833 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryFrameRateRange) { | 833 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryFrameRateRange) { |
834 constraint_factory_.Reset(); | 834 constraint_factory_.Reset(); |
835 { | 835 { |
836 const double kMinFrameRate = 10; | 836 const double kMinFrameRate = 10; |
837 const double kMaxFrameRate = 40; | 837 const double kMaxFrameRate = 40; |
838 constraint_factory_.basic().frameRate.setMin(kMinFrameRate); | 838 constraint_factory_.basic().frameRate.setMin(kMinFrameRate); |
839 constraint_factory_.basic().frameRate.setMax(kMaxFrameRate); | 839 constraint_factory_.basic().frameRate.setMax(kMaxFrameRate); |
840 auto result = SelectSettings(); | 840 auto result = SelectSettings(); |
841 EXPECT_TRUE(result.HasValue()); | 841 EXPECT_TRUE(result.HasValue()); |
842 EXPECT_LE(kMinFrameRate, result.FrameRate()); | 842 EXPECT_LE(kMinFrameRate, result.FrameRate()); |
843 EXPECT_GE(kMaxFrameRate, result.FrameRate()); | 843 EXPECT_GE(kMaxFrameRate, result.FrameRate()); |
844 // All devices in |capabilities_| support the constraint range. The | 844 // All devices in |capabilities_| support the constraint range. The |
845 // algorithm should prefer the default device since its closest-to-default | 845 // algorithm should prefer the default device since its closest-to-default |
846 // format has a frame rate included in the requested range. | 846 // format has a frame rate included in the requested range. |
847 EXPECT_EQ(default_device_->device_id, result.device_id); | 847 EXPECT_EQ(default_device_->device_id, result.device_id()); |
848 EXPECT_EQ(*default_closest_format_, result.Format()); | 848 EXPECT_EQ(*default_closest_format_, result.Format()); |
849 } | 849 } |
850 | 850 |
851 { | 851 { |
852 const double kMinFrameRate = 25; | 852 const double kMinFrameRate = 25; |
853 const double kMaxFrameRate = 35; | 853 const double kMaxFrameRate = 35; |
854 constraint_factory_.basic().frameRate.setMin(kMinFrameRate); | 854 constraint_factory_.basic().frameRate.setMin(kMinFrameRate); |
855 constraint_factory_.basic().frameRate.setMax(kMaxFrameRate); | 855 constraint_factory_.basic().frameRate.setMax(kMaxFrameRate); |
856 auto result = SelectSettings(); | 856 auto result = SelectSettings(); |
857 EXPECT_TRUE(result.HasValue()); | 857 EXPECT_TRUE(result.HasValue()); |
858 EXPECT_GE(result.FrameRate(), kMinFrameRate); | 858 EXPECT_GE(result.FrameRate(), kMinFrameRate); |
859 EXPECT_LE(result.FrameRate(), kMaxFrameRate); | 859 EXPECT_LE(result.FrameRate(), kMaxFrameRate); |
860 // In this case, the algorithm should prefer the low-res device since it is | 860 // In this case, the algorithm should prefer the low-res device since it is |
861 // the first device with a native frame rate included in the requested | 861 // the first device with a native frame rate included in the requested |
862 // range. The default resolution should be preferred as secondary criterion. | 862 // range. The default resolution should be preferred as secondary criterion. |
863 EXPECT_EQ(low_res_device_->device_id, result.device_id); | 863 EXPECT_EQ(low_res_device_->device_id, result.device_id()); |
864 EXPECT_EQ(*low_res_closest_format_, result.Format()); | 864 EXPECT_EQ(*low_res_closest_format_, result.Format()); |
865 } | 865 } |
866 | 866 |
867 { | 867 { |
868 const double kMinFrameRate = 50; | 868 const double kMinFrameRate = 50; |
869 const double kMaxFrameRate = 70; | 869 const double kMaxFrameRate = 70; |
870 constraint_factory_.basic().frameRate.setMin(kMinFrameRate); | 870 constraint_factory_.basic().frameRate.setMin(kMinFrameRate); |
871 constraint_factory_.basic().frameRate.setMax(kMaxFrameRate); | 871 constraint_factory_.basic().frameRate.setMax(kMaxFrameRate); |
872 auto result = SelectSettings(); | 872 auto result = SelectSettings(); |
873 EXPECT_TRUE(result.HasValue()); | 873 EXPECT_TRUE(result.HasValue()); |
874 EXPECT_GE(result.FrameRate(), kMinFrameRate); | 874 EXPECT_GE(result.FrameRate(), kMinFrameRate); |
875 EXPECT_LE(result.FrameRate(), kMaxFrameRate); | 875 EXPECT_LE(result.FrameRate(), kMaxFrameRate); |
876 // In this case, the algorithm should prefer the high-res device since it is | 876 // In this case, the algorithm should prefer the high-res device since it is |
877 // the only device with a native format included in the requested range. | 877 // the only device with a native format included in the requested range. |
878 // The 1280x720 resolution should be selected due to closeness to default | 878 // The 1280x720 resolution should be selected due to closeness to default |
879 // settings, which is the second tie-breaker criterion that applies. | 879 // settings, which is the second tie-breaker criterion that applies. |
880 EXPECT_EQ(high_res_device_->device_id, result.device_id); | 880 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
881 EXPECT_EQ(1280, result.Width()); | 881 EXPECT_EQ(1280, result.Width()); |
882 EXPECT_EQ(720, result.Height()); | 882 EXPECT_EQ(720, result.Height()); |
883 } | 883 } |
884 } | 884 } |
885 | 885 |
886 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, IdealFrameRate) { | 886 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, IdealFrameRate) { |
887 constraint_factory_.Reset(); | 887 constraint_factory_.Reset(); |
888 { | 888 { |
889 const double kIdealFrameRate = MediaStreamVideoSource::kDefaultFrameRate; | 889 const double kIdealFrameRate = MediaStreamVideoSource::kDefaultFrameRate; |
890 constraint_factory_.basic().frameRate.setIdeal(kIdealFrameRate); | 890 constraint_factory_.basic().frameRate.setIdeal(kIdealFrameRate); |
891 auto result = SelectSettings(); | 891 auto result = SelectSettings(); |
892 EXPECT_TRUE(result.HasValue()); | 892 EXPECT_TRUE(result.HasValue()); |
893 // The algorithm should select the first configuration that supports the | 893 // The algorithm should select the first configuration that supports the |
894 // ideal frame rate natively, which is the low-res device. Default | 894 // ideal frame rate natively, which is the low-res device. Default |
895 // resolution should be selected as secondary criterion. | 895 // resolution should be selected as secondary criterion. |
896 EXPECT_EQ(low_res_device_->device_id, result.device_id); | 896 EXPECT_EQ(low_res_device_->device_id, result.device_id()); |
897 EXPECT_EQ(*low_res_closest_format_, result.Format()); | 897 EXPECT_EQ(*low_res_closest_format_, result.Format()); |
898 } | 898 } |
899 | 899 |
900 { | 900 { |
901 const double kIdealFrameRate = 31; | 901 const double kIdealFrameRate = 31; |
902 constraint_factory_.basic().frameRate.setIdeal(kIdealFrameRate); | 902 constraint_factory_.basic().frameRate.setIdeal(kIdealFrameRate); |
903 auto result = SelectSettings(); | 903 auto result = SelectSettings(); |
904 EXPECT_TRUE(result.HasValue()); | 904 EXPECT_TRUE(result.HasValue()); |
905 // In this case, the default device is selected because it can satisfy the | 905 // In this case, the default device is selected because it can satisfy the |
906 // ideal at a lower cost than the other devices (40 vs 60). | 906 // ideal at a lower cost than the other devices (40 vs 60). |
907 // Note that a native frame rate of 30 is further from the ideal than | 907 // Note that a native frame rate of 30 is further from the ideal than |
908 // 31 adjusted to 30. | 908 // 31 adjusted to 30. |
909 EXPECT_EQ(default_device_->device_id, result.device_id); | 909 EXPECT_EQ(default_device_->device_id, result.device_id()); |
910 EXPECT_EQ(*default_closest_format_, result.Format()); | 910 EXPECT_EQ(*default_closest_format_, result.Format()); |
911 } | 911 } |
912 | 912 |
913 { | 913 { |
914 const double kIdealFrameRate = 55; | 914 const double kIdealFrameRate = 55; |
915 constraint_factory_.basic().frameRate.setIdeal(kIdealFrameRate); | 915 constraint_factory_.basic().frameRate.setIdeal(kIdealFrameRate); |
916 auto result = SelectSettings(); | 916 auto result = SelectSettings(); |
917 EXPECT_TRUE(result.HasValue()); | 917 EXPECT_TRUE(result.HasValue()); |
918 // The high-res device format 1280x720x60.0 must be selected because its | 918 // The high-res device format 1280x720x60.0 must be selected because its |
919 // frame rate can satisfy the ideal frame rate and has resolution closest | 919 // frame rate can satisfy the ideal frame rate and has resolution closest |
920 // to the default. | 920 // to the default. |
921 EXPECT_EQ(high_res_device_->device_id, result.device_id); | 921 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
922 EXPECT_EQ(1280, result.Width()); | 922 EXPECT_EQ(1280, result.Width()); |
923 EXPECT_EQ(720, result.Height()); | 923 EXPECT_EQ(720, result.Height()); |
924 EXPECT_EQ(60, result.FrameRate()); | 924 EXPECT_EQ(60, result.FrameRate()); |
925 } | 925 } |
926 | 926 |
927 { | 927 { |
928 const double kIdealFrameRate = 100; | 928 const double kIdealFrameRate = 100; |
929 constraint_factory_.basic().frameRate.setIdeal(kIdealFrameRate); | 929 constraint_factory_.basic().frameRate.setIdeal(kIdealFrameRate); |
930 auto result = SelectSettings(); | 930 auto result = SelectSettings(); |
931 EXPECT_TRUE(result.HasValue()); | 931 EXPECT_TRUE(result.HasValue()); |
932 // The algorithm must select settings with frame rate closest to the ideal. | 932 // The algorithm must select settings with frame rate closest to the ideal. |
933 // The high-res device format 1280x720x60.0 must be selected because its | 933 // The high-res device format 1280x720x60.0 must be selected because its |
934 // frame rate it closest to the ideal value and it has resolution closest to | 934 // frame rate it closest to the ideal value and it has resolution closest to |
935 // the default. | 935 // the default. |
936 EXPECT_EQ(high_res_device_->device_id, result.device_id); | 936 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
937 EXPECT_EQ(1280, result.Width()); | 937 EXPECT_EQ(1280, result.Width()); |
938 EXPECT_EQ(720, result.Height()); | 938 EXPECT_EQ(720, result.Height()); |
939 EXPECT_EQ(60, result.FrameRate()); | 939 EXPECT_EQ(60, result.FrameRate()); |
940 } | 940 } |
941 } | 941 } |
942 | 942 |
943 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryExactAspectRatio) { | 943 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryExactAspectRatio) { |
944 constraint_factory_.Reset(); | 944 constraint_factory_.Reset(); |
945 const double kAspectRatio = 4.0 / 3.0; | 945 const double kAspectRatio = 4.0 / 3.0; |
946 constraint_factory_.basic().aspectRatio.setExact(kAspectRatio); | 946 constraint_factory_.basic().aspectRatio.setExact(kAspectRatio); |
947 auto result = SelectSettings(); | 947 auto result = SelectSettings(); |
948 EXPECT_TRUE(result.HasValue()); | 948 EXPECT_TRUE(result.HasValue()); |
949 double min_width = 1.0; | 949 double min_width = 1.0; |
950 double max_width = result.Width(); | 950 double max_width = result.Width(); |
951 double min_height = 1.0; | 951 double min_height = 1.0; |
952 double max_height = result.Height(); | 952 double max_height = result.Height(); |
953 double min_aspect_ratio = min_width / max_height; | 953 double min_aspect_ratio = min_width / max_height; |
954 double max_aspect_ratio = max_width / min_height; | 954 double max_aspect_ratio = max_width / min_height; |
955 // The requested aspect ratio must be within the supported range. | 955 // The requested aspect ratio must be within the supported range. |
956 EXPECT_GE(kAspectRatio, min_aspect_ratio); | 956 EXPECT_GE(kAspectRatio, min_aspect_ratio); |
957 EXPECT_LE(kAspectRatio, max_aspect_ratio); | 957 EXPECT_LE(kAspectRatio, max_aspect_ratio); |
958 // All devices in |capabilities_| support the requested aspect ratio. | 958 // All devices in |capabilities_| support the requested aspect ratio. |
959 // The algorithm should prefer the first device that supports the requested | 959 // The algorithm should prefer the first device that supports the requested |
960 // aspect ratio. | 960 // aspect ratio. |
961 EXPECT_EQ(default_device_->device_id, result.device_id); | 961 EXPECT_EQ(default_device_->device_id, result.device_id()); |
962 EXPECT_EQ(*default_closest_format_, result.Format()); | 962 EXPECT_EQ(*default_closest_format_, result.Format()); |
963 | 963 |
964 const int kMinWidth = 500; | 964 const int kMinWidth = 500; |
965 const int kMaxWidth = 1000; | 965 const int kMaxWidth = 1000; |
966 const int kMaxHeight = 500; | 966 const int kMaxHeight = 500; |
967 constraint_factory_.basic().height.setMax(kMaxHeight); | 967 constraint_factory_.basic().height.setMax(kMaxHeight); |
968 constraint_factory_.basic().width.setMin(kMinWidth); | 968 constraint_factory_.basic().width.setMin(kMinWidth); |
969 constraint_factory_.basic().width.setMax(kMaxWidth); | 969 constraint_factory_.basic().width.setMax(kMaxWidth); |
970 constraint_factory_.basic().aspectRatio.setExact(kAspectRatio); | 970 constraint_factory_.basic().aspectRatio.setExact(kAspectRatio); |
971 result = SelectSettings(); | 971 result = SelectSettings(); |
972 EXPECT_TRUE(result.HasValue()); | 972 EXPECT_TRUE(result.HasValue()); |
973 min_width = std::max(1, kMinWidth); | 973 min_width = std::max(1, kMinWidth); |
974 max_width = std::min(result.Width(), kMaxWidth); | 974 max_width = std::min(result.Width(), kMaxWidth); |
975 min_height = 1.0; | 975 min_height = 1.0; |
976 max_height = std::min(result.Height(), kMaxHeight); | 976 max_height = std::min(result.Height(), kMaxHeight); |
977 min_aspect_ratio = min_width / max_height; | 977 min_aspect_ratio = min_width / max_height; |
978 max_aspect_ratio = max_width / min_height; | 978 max_aspect_ratio = max_width / min_height; |
979 // The requested aspect ratio must be within the supported range. | 979 // The requested aspect ratio must be within the supported range. |
980 EXPECT_GE(kAspectRatio, min_aspect_ratio); | 980 EXPECT_GE(kAspectRatio, min_aspect_ratio); |
981 EXPECT_LE(kAspectRatio, max_aspect_ratio); | 981 EXPECT_LE(kAspectRatio, max_aspect_ratio); |
982 // The default device can support the requested aspect ratio with the default | 982 // The default device can support the requested aspect ratio with the default |
983 // settings (500x500) using cropping. | 983 // settings (500x500) using cropping. |
984 EXPECT_EQ(default_device_->device_id, result.device_id); | 984 EXPECT_EQ(default_device_->device_id, result.device_id()); |
985 EXPECT_EQ(*default_closest_format_, result.Format()); | 985 EXPECT_EQ(*default_closest_format_, result.Format()); |
986 | 986 |
987 const int kMinHeight = 480; | 987 const int kMinHeight = 480; |
988 constraint_factory_.basic().height.setMin(kMinHeight); | 988 constraint_factory_.basic().height.setMin(kMinHeight); |
989 constraint_factory_.basic().height.setMax(kMaxHeight); | 989 constraint_factory_.basic().height.setMax(kMaxHeight); |
990 constraint_factory_.basic().width.setMin(kMinWidth); | 990 constraint_factory_.basic().width.setMin(kMinWidth); |
991 constraint_factory_.basic().width.setMax(kMaxWidth); | 991 constraint_factory_.basic().width.setMax(kMaxWidth); |
992 constraint_factory_.basic().aspectRatio.setExact(kAspectRatio); | 992 constraint_factory_.basic().aspectRatio.setExact(kAspectRatio); |
993 result = SelectSettings(); | 993 result = SelectSettings(); |
994 EXPECT_TRUE(result.HasValue()); | 994 EXPECT_TRUE(result.HasValue()); |
995 min_width = std::max(1, kMinWidth); | 995 min_width = std::max(1, kMinWidth); |
996 max_width = std::min(result.Width(), kMaxWidth); | 996 max_width = std::min(result.Width(), kMaxWidth); |
997 min_height = std::max(1, kMinHeight); | 997 min_height = std::max(1, kMinHeight); |
998 max_height = std::min(result.Height(), kMaxHeight); | 998 max_height = std::min(result.Height(), kMaxHeight); |
999 min_aspect_ratio = min_width / max_height; | 999 min_aspect_ratio = min_width / max_height; |
1000 max_aspect_ratio = max_width / min_height; | 1000 max_aspect_ratio = max_width / min_height; |
1001 // The requested aspect ratio must be within the supported range. | 1001 // The requested aspect ratio must be within the supported range. |
1002 EXPECT_GE(kAspectRatio, min_aspect_ratio); | 1002 EXPECT_GE(kAspectRatio, min_aspect_ratio); |
1003 EXPECT_LE(kAspectRatio, max_aspect_ratio); | 1003 EXPECT_LE(kAspectRatio, max_aspect_ratio); |
1004 // Given resolution constraints, the default device with closest-to-default | 1004 // Given resolution constraints, the default device with closest-to-default |
1005 // settings cannot satisfy the required aspect ratio. | 1005 // settings cannot satisfy the required aspect ratio. |
1006 // The first device that can do it is the low-res device with a native | 1006 // The first device that can do it is the low-res device with a native |
1007 // resolution of 640x480. Higher resolutions for the default device are more | 1007 // resolution of 640x480. Higher resolutions for the default device are more |
1008 // penalized by the constraints than the default native resolution of the | 1008 // penalized by the constraints than the default native resolution of the |
1009 // low-res device. | 1009 // low-res device. |
1010 EXPECT_EQ(low_res_device_->device_id, result.device_id); | 1010 EXPECT_EQ(low_res_device_->device_id, result.device_id()); |
1011 EXPECT_EQ(*low_res_closest_format_, result.Format()); | 1011 EXPECT_EQ(*low_res_closest_format_, result.Format()); |
1012 } | 1012 } |
1013 | 1013 |
1014 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryMinAspectRatio) { | 1014 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryMinAspectRatio) { |
1015 constraint_factory_.Reset(); | 1015 constraint_factory_.Reset(); |
1016 const double kAspectRatio = 4.0 / 3.0; | 1016 const double kAspectRatio = 4.0 / 3.0; |
1017 constraint_factory_.basic().aspectRatio.setMin(kAspectRatio); | 1017 constraint_factory_.basic().aspectRatio.setMin(kAspectRatio); |
1018 auto result = SelectSettings(); | 1018 auto result = SelectSettings(); |
1019 EXPECT_TRUE(result.HasValue()); | 1019 EXPECT_TRUE(result.HasValue()); |
1020 double max_width = result.Width(); | 1020 double max_width = result.Width(); |
1021 double min_height = 1.0; | 1021 double min_height = 1.0; |
1022 double max_aspect_ratio = max_width / min_height; | 1022 double max_aspect_ratio = max_width / min_height; |
1023 // Minimum constraint aspect ratio must be less than or equal to the maximum | 1023 // Minimum constraint aspect ratio must be less than or equal to the maximum |
1024 // supported by the source. | 1024 // supported by the source. |
1025 EXPECT_LE(kAspectRatio, max_aspect_ratio); | 1025 EXPECT_LE(kAspectRatio, max_aspect_ratio); |
1026 // All devices in |capabilities_| support the requested aspect-ratio range. | 1026 // All devices in |capabilities_| support the requested aspect-ratio range. |
1027 // The algorithm should prefer the first device that supports the requested | 1027 // The algorithm should prefer the first device that supports the requested |
1028 // aspect-ratio range, which in this case is the default device. | 1028 // aspect-ratio range, which in this case is the default device. |
1029 EXPECT_EQ(default_device_->device_id, result.device_id); | 1029 EXPECT_EQ(default_device_->device_id, result.device_id()); |
1030 EXPECT_EQ(*default_closest_format_, result.Format()); | 1030 EXPECT_EQ(*default_closest_format_, result.Format()); |
1031 | 1031 |
1032 const int kMinWidth = 500; | 1032 const int kMinWidth = 500; |
1033 const int kMaxWidth = 1000; | 1033 const int kMaxWidth = 1000; |
1034 const int kMinHeight = 480; | 1034 const int kMinHeight = 480; |
1035 const int kMaxHeight = 500; | 1035 const int kMaxHeight = 500; |
1036 constraint_factory_.basic().width.setMin(kMinWidth); | 1036 constraint_factory_.basic().width.setMin(kMinWidth); |
1037 constraint_factory_.basic().width.setMax(kMaxWidth); | 1037 constraint_factory_.basic().width.setMax(kMaxWidth); |
1038 constraint_factory_.basic().height.setMin(kMinHeight); | 1038 constraint_factory_.basic().height.setMin(kMinHeight); |
1039 constraint_factory_.basic().height.setMax(kMaxHeight); | 1039 constraint_factory_.basic().height.setMax(kMaxHeight); |
1040 constraint_factory_.basic().aspectRatio.setMin(kAspectRatio); | 1040 constraint_factory_.basic().aspectRatio.setMin(kAspectRatio); |
1041 result = SelectSettings(); | 1041 result = SelectSettings(); |
1042 EXPECT_TRUE(result.HasValue()); | 1042 EXPECT_TRUE(result.HasValue()); |
1043 max_width = std::min(result.Width(), kMaxWidth); | 1043 max_width = std::min(result.Width(), kMaxWidth); |
1044 min_height = std::max(1, kMinHeight); | 1044 min_height = std::max(1, kMinHeight); |
1045 max_aspect_ratio = max_width / min_height; | 1045 max_aspect_ratio = max_width / min_height; |
1046 // Minimum constraint aspect ratio must be less than or equal to the minimum | 1046 // Minimum constraint aspect ratio must be less than or equal to the minimum |
1047 // supported by the source. | 1047 // supported by the source. |
1048 EXPECT_LE(kAspectRatio, max_aspect_ratio); | 1048 EXPECT_LE(kAspectRatio, max_aspect_ratio); |
1049 // Given resolution constraints, the default device with closest-to-default | 1049 // Given resolution constraints, the default device with closest-to-default |
1050 // settings cannot satisfy the required minimum aspect ratio (maximum would | 1050 // settings cannot satisfy the required minimum aspect ratio (maximum would |
1051 // be 500/480). The first device that can is the low-res device with a native | 1051 // be 500/480). The first device that can is the low-res device with a native |
1052 // resolution of 640x480. | 1052 // resolution of 640x480. |
1053 // Higher resolutions for the default device are more penalized by the | 1053 // Higher resolutions for the default device are more penalized by the |
1054 // constraints than the default native resolution of the low-res device. | 1054 // constraints than the default native resolution of the low-res device. |
1055 EXPECT_EQ(low_res_device_->device_id, result.device_id); | 1055 EXPECT_EQ(low_res_device_->device_id, result.device_id()); |
1056 EXPECT_EQ(*low_res_closest_format_, result.Format()); | 1056 EXPECT_EQ(*low_res_closest_format_, result.Format()); |
1057 } | 1057 } |
1058 | 1058 |
1059 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryMaxAspectRatio) { | 1059 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryMaxAspectRatio) { |
1060 constraint_factory_.Reset(); | 1060 constraint_factory_.Reset(); |
1061 const double kAspectRatio = 0.5; | 1061 const double kAspectRatio = 0.5; |
1062 constraint_factory_.basic().aspectRatio.setMax(kAspectRatio); | 1062 constraint_factory_.basic().aspectRatio.setMax(kAspectRatio); |
1063 auto result = SelectSettings(); | 1063 auto result = SelectSettings(); |
1064 EXPECT_TRUE(result.HasValue()); | 1064 EXPECT_TRUE(result.HasValue()); |
1065 double min_width = 1.0; | 1065 double min_width = 1.0; |
1066 double max_height = result.Height(); | 1066 double max_height = result.Height(); |
1067 double min_aspect_ratio = min_width / max_height; | 1067 double min_aspect_ratio = min_width / max_height; |
1068 // Minimum constraint aspect ratio must be less than or equal to the maximum | 1068 // Minimum constraint aspect ratio must be less than or equal to the maximum |
1069 // supported by the source. | 1069 // supported by the source. |
1070 EXPECT_GE(kAspectRatio, min_aspect_ratio); | 1070 EXPECT_GE(kAspectRatio, min_aspect_ratio); |
1071 // All devices in |capabilities_| support the requested aspect-ratio range. | 1071 // All devices in |capabilities_| support the requested aspect-ratio range. |
1072 // The algorithm should prefer the first device that supports the requested | 1072 // The algorithm should prefer the first device that supports the requested |
1073 // aspect-ratio range, which in this case is the default device. | 1073 // aspect-ratio range, which in this case is the default device. |
1074 EXPECT_EQ(default_device_->device_id, result.device_id); | 1074 EXPECT_EQ(default_device_->device_id, result.device_id()); |
1075 EXPECT_EQ(*default_closest_format_, result.Format()); | 1075 EXPECT_EQ(*default_closest_format_, result.Format()); |
1076 | 1076 |
1077 const int kExactWidth = 360; | 1077 const int kExactWidth = 360; |
1078 const int kMinHeight = 360; | 1078 const int kMinHeight = 360; |
1079 const int kMaxHeight = 720; | 1079 const int kMaxHeight = 720; |
1080 constraint_factory_.basic().width.setExact(kExactWidth); | 1080 constraint_factory_.basic().width.setExact(kExactWidth); |
1081 constraint_factory_.basic().height.setMin(kMinHeight); | 1081 constraint_factory_.basic().height.setMin(kMinHeight); |
1082 constraint_factory_.basic().height.setMax(kMaxHeight); | 1082 constraint_factory_.basic().height.setMax(kMaxHeight); |
1083 constraint_factory_.basic().aspectRatio.setMax(kAspectRatio); | 1083 constraint_factory_.basic().aspectRatio.setMax(kAspectRatio); |
1084 result = SelectSettings(); | 1084 result = SelectSettings(); |
1085 EXPECT_TRUE(result.HasValue()); | 1085 EXPECT_TRUE(result.HasValue()); |
1086 min_width = std::max(1, kExactWidth); | 1086 min_width = std::max(1, kExactWidth); |
1087 max_height = std::min(result.Height(), kMaxHeight); | 1087 max_height = std::min(result.Height(), kMaxHeight); |
1088 min_aspect_ratio = min_width / max_height; | 1088 min_aspect_ratio = min_width / max_height; |
1089 // Minimum constraint aspect ratio must be less than or equal to the minimum | 1089 // Minimum constraint aspect ratio must be less than or equal to the minimum |
1090 // supported by the source. | 1090 // supported by the source. |
1091 EXPECT_GE(kAspectRatio, min_aspect_ratio); | 1091 EXPECT_GE(kAspectRatio, min_aspect_ratio); |
1092 // Given resolution constraints, the default device with closest-to-default | 1092 // Given resolution constraints, the default device with closest-to-default |
1093 // settings cannot satisfy the required maximum aspect ratio (maximum would | 1093 // settings cannot satisfy the required maximum aspect ratio (maximum would |
1094 // be 360/500). | 1094 // be 360/500). |
1095 // The high-res device with a native resolution of 1280x720 can support | 1095 // The high-res device with a native resolution of 1280x720 can support |
1096 // 360x720 with cropping with less penalty than the default device at | 1096 // 360x720 with cropping with less penalty than the default device at |
1097 // 1000x1000. | 1097 // 1000x1000. |
1098 EXPECT_EQ(high_res_device_->device_id, result.device_id); | 1098 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
1099 EXPECT_EQ(1280, result.Width()); | 1099 EXPECT_EQ(1280, result.Width()); |
1100 EXPECT_EQ(720, result.Height()); | 1100 EXPECT_EQ(720, result.Height()); |
1101 } | 1101 } |
1102 | 1102 |
1103 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryAspectRatioRange) { | 1103 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryAspectRatioRange) { |
1104 constraint_factory_.Reset(); | 1104 constraint_factory_.Reset(); |
1105 { | 1105 { |
1106 const double kMinAspectRatio = 0.5; | 1106 const double kMinAspectRatio = 0.5; |
1107 const double kMaxAspectRatio = 1.0; | 1107 const double kMaxAspectRatio = 1.0; |
1108 | 1108 |
1109 constraint_factory_.basic().aspectRatio.setMin(kMinAspectRatio); | 1109 constraint_factory_.basic().aspectRatio.setMin(kMinAspectRatio); |
1110 constraint_factory_.basic().aspectRatio.setMax(kMaxAspectRatio); | 1110 constraint_factory_.basic().aspectRatio.setMax(kMaxAspectRatio); |
1111 auto result = SelectSettings(); | 1111 auto result = SelectSettings(); |
1112 EXPECT_TRUE(result.HasValue()); | 1112 EXPECT_TRUE(result.HasValue()); |
1113 double min_width = 1.0; | 1113 double min_width = 1.0; |
1114 double max_width = result.Width(); | 1114 double max_width = result.Width(); |
1115 double min_height = 1.0; | 1115 double min_height = 1.0; |
1116 double max_height = result.Height(); | 1116 double max_height = result.Height(); |
1117 double min_aspect_ratio = min_width / max_height; | 1117 double min_aspect_ratio = min_width / max_height; |
1118 double max_aspect_ratio = max_width / min_height; | 1118 double max_aspect_ratio = max_width / min_height; |
1119 // Constraint aspect-ratio range must have nonempty intersection with | 1119 // Constraint aspect-ratio range must have nonempty intersection with |
1120 // supported range. | 1120 // supported range. |
1121 EXPECT_LE(kMinAspectRatio, max_aspect_ratio); | 1121 EXPECT_LE(kMinAspectRatio, max_aspect_ratio); |
1122 EXPECT_GE(kMaxAspectRatio, min_aspect_ratio); | 1122 EXPECT_GE(kMaxAspectRatio, min_aspect_ratio); |
1123 // All devices in |capabilities_| support the requested aspect-ratio range. | 1123 // All devices in |capabilities_| support the requested aspect-ratio range. |
1124 // The algorithm should prefer the first device that supports the requested | 1124 // The algorithm should prefer the first device that supports the requested |
1125 // aspect-ratio range, which in this case is the default device. | 1125 // aspect-ratio range, which in this case is the default device. |
1126 EXPECT_EQ(default_device_->device_id, result.device_id); | 1126 EXPECT_EQ(default_device_->device_id, result.device_id()); |
1127 EXPECT_EQ(*default_closest_format_, result.Format()); | 1127 EXPECT_EQ(*default_closest_format_, result.Format()); |
1128 } | 1128 } |
1129 | 1129 |
1130 { | 1130 { |
1131 const double kMinAspectRatio = 3.0; | 1131 const double kMinAspectRatio = 3.0; |
1132 const double kMaxAspectRatio = 4.0; | 1132 const double kMaxAspectRatio = 4.0; |
1133 | 1133 |
1134 const long kExactHeight = 600; | 1134 const long kExactHeight = 600; |
1135 constraint_factory_.Reset(); | 1135 constraint_factory_.Reset(); |
1136 constraint_factory_.basic().height.setMin(kExactHeight); | 1136 constraint_factory_.basic().height.setMin(kExactHeight); |
1137 constraint_factory_.basic().aspectRatio.setMin(kMinAspectRatio); | 1137 constraint_factory_.basic().aspectRatio.setMin(kMinAspectRatio); |
1138 constraint_factory_.basic().aspectRatio.setMax(kMaxAspectRatio); | 1138 constraint_factory_.basic().aspectRatio.setMax(kMaxAspectRatio); |
1139 auto result = SelectSettings(); | 1139 auto result = SelectSettings(); |
1140 EXPECT_TRUE(result.HasValue()); | 1140 EXPECT_TRUE(result.HasValue()); |
1141 double min_width = 1.0; | 1141 double min_width = 1.0; |
1142 double max_width = result.Width(); | 1142 double max_width = result.Width(); |
1143 double min_height = 1.0; | 1143 double min_height = 1.0; |
1144 double max_height = result.Height(); | 1144 double max_height = result.Height(); |
1145 double min_aspect_ratio = min_width / max_height; | 1145 double min_aspect_ratio = min_width / max_height; |
1146 double max_aspect_ratio = max_width / min_height; | 1146 double max_aspect_ratio = max_width / min_height; |
1147 // Constraint aspect-ratio range must have nonempty intersection with | 1147 // Constraint aspect-ratio range must have nonempty intersection with |
1148 // supported range. | 1148 // supported range. |
1149 EXPECT_LE(kMinAspectRatio, max_aspect_ratio); | 1149 EXPECT_LE(kMinAspectRatio, max_aspect_ratio); |
1150 EXPECT_GE(kMaxAspectRatio, min_aspect_ratio); | 1150 EXPECT_GE(kMaxAspectRatio, min_aspect_ratio); |
1151 // The only device that supports the resolution and aspect ratio constraint | 1151 // The only device that supports the resolution and aspect ratio constraint |
1152 // is the high-res device. The 1920x1080 is the least expensive format. | 1152 // is the high-res device. The 1920x1080 is the least expensive format. |
1153 EXPECT_EQ(high_res_device_->device_id, result.device_id); | 1153 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
1154 EXPECT_EQ(1920, result.Width()); | 1154 EXPECT_EQ(1920, result.Width()); |
1155 EXPECT_EQ(1080, result.Height()); | 1155 EXPECT_EQ(1080, result.Height()); |
1156 } | 1156 } |
1157 } | 1157 } |
1158 | 1158 |
1159 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, IdealAspectRatio) { | 1159 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, IdealAspectRatio) { |
1160 constraint_factory_.Reset(); | 1160 constraint_factory_.Reset(); |
1161 { | 1161 { |
1162 const double kIdealAspectRatio = 0.5; | 1162 const double kIdealAspectRatio = 0.5; |
1163 constraint_factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); | 1163 constraint_factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); |
1164 auto result = SelectSettings(); | 1164 auto result = SelectSettings(); |
1165 EXPECT_TRUE(result.HasValue()); | 1165 EXPECT_TRUE(result.HasValue()); |
1166 double min_width = 1.0; | 1166 double min_width = 1.0; |
1167 double max_width = result.Width(); | 1167 double max_width = result.Width(); |
1168 double min_height = 1.0; | 1168 double min_height = 1.0; |
1169 double max_height = result.Height(); | 1169 double max_height = result.Height(); |
1170 double min_aspect_ratio = min_width / max_height; | 1170 double min_aspect_ratio = min_width / max_height; |
1171 double max_aspect_ratio = max_width / min_height; | 1171 double max_aspect_ratio = max_width / min_height; |
1172 // All devices in |capabilities_| support the ideal aspect-ratio. | 1172 // All devices in |capabilities_| support the ideal aspect-ratio. |
1173 // The algorithm should prefer the default device with closest-to-default | 1173 // The algorithm should prefer the default device with closest-to-default |
1174 // settings. | 1174 // settings. |
1175 EXPECT_LE(kIdealAspectRatio, max_aspect_ratio); | 1175 EXPECT_LE(kIdealAspectRatio, max_aspect_ratio); |
1176 EXPECT_GE(kIdealAspectRatio, min_aspect_ratio); | 1176 EXPECT_GE(kIdealAspectRatio, min_aspect_ratio); |
1177 EXPECT_EQ(default_device_->device_id, result.device_id); | 1177 EXPECT_EQ(default_device_->device_id, result.device_id()); |
1178 EXPECT_EQ(*default_closest_format_, result.Format()); | 1178 EXPECT_EQ(*default_closest_format_, result.Format()); |
1179 } | 1179 } |
1180 | 1180 |
1181 { | 1181 { |
1182 const double kIdealAspectRatio = 1500.0; | 1182 const double kIdealAspectRatio = 1500.0; |
1183 constraint_factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); | 1183 constraint_factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); |
1184 auto result = SelectSettings(); | 1184 auto result = SelectSettings(); |
1185 EXPECT_TRUE(result.HasValue()); | 1185 EXPECT_TRUE(result.HasValue()); |
1186 // The only device that supports the ideal aspect ratio is the high-res | 1186 // The only device that supports the ideal aspect ratio is the high-res |
1187 // device. The least expensive way to support it with the 1920x1080 format | 1187 // device. The least expensive way to support it with the 1920x1080 format |
1188 // cropped to 1500x1. | 1188 // cropped to 1500x1. |
1189 EXPECT_EQ(high_res_device_->device_id, result.device_id); | 1189 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
1190 EXPECT_EQ(1920, result.Width()); | 1190 EXPECT_EQ(1920, result.Width()); |
1191 EXPECT_EQ(1080, result.Height()); | 1191 EXPECT_EQ(1080, result.Height()); |
1192 } | 1192 } |
1193 | 1193 |
1194 { | 1194 { |
1195 const double kIdealAspectRatio = 2000.0; | 1195 const double kIdealAspectRatio = 2000.0; |
1196 constraint_factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); | 1196 constraint_factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); |
1197 auto result = SelectSettings(); | 1197 auto result = SelectSettings(); |
1198 EXPECT_TRUE(result.HasValue()); | 1198 EXPECT_TRUE(result.HasValue()); |
1199 // The only device that supports the ideal aspect ratio is the high-res | 1199 // The only device that supports the ideal aspect ratio is the high-res |
1200 // device with its highest resolution, cropped to 2000x1. | 1200 // device with its highest resolution, cropped to 2000x1. |
1201 EXPECT_EQ(high_res_device_->device_id, result.device_id); | 1201 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
1202 EXPECT_EQ(*high_res_highest_format_, result.Format()); | 1202 EXPECT_EQ(*high_res_highest_format_, result.Format()); |
1203 } | 1203 } |
1204 | 1204 |
1205 { | 1205 { |
1206 const double kIdealAspectRatio = 4000.0; | 1206 const double kIdealAspectRatio = 4000.0; |
1207 constraint_factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); | 1207 constraint_factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); |
1208 auto result = SelectSettings(); | 1208 auto result = SelectSettings(); |
1209 EXPECT_TRUE(result.HasValue()); | 1209 EXPECT_TRUE(result.HasValue()); |
1210 // The configuration closest to the ideal aspect ratio is is the high-res | 1210 // The configuration closest to the ideal aspect ratio is is the high-res |
1211 // device with its highest resolution, cropped to 2304x1. | 1211 // device with its highest resolution, cropped to 2304x1. |
1212 EXPECT_EQ(high_res_device_->device_id, result.device_id); | 1212 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
1213 EXPECT_EQ(*high_res_highest_format_, result.Format()); | 1213 EXPECT_EQ(*high_res_highest_format_, result.Format()); |
1214 } | 1214 } |
1215 | 1215 |
1216 { | 1216 { |
1217 const double kIdealAspectRatio = 2.0; | 1217 const double kIdealAspectRatio = 2.0; |
1218 constraint_factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); | 1218 constraint_factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); |
1219 constraint_factory_.basic().height.setExact(400); | 1219 constraint_factory_.basic().height.setExact(400); |
1220 auto result = SelectSettings(); | 1220 auto result = SelectSettings(); |
1221 EXPECT_TRUE(result.HasValue()); | 1221 EXPECT_TRUE(result.HasValue()); |
1222 // The first device to support the ideal aspect ratio and the resolution | 1222 // The first device to support the ideal aspect ratio and the resolution |
1223 // constraint is the low-res device. The 800x600 format cropped to 800x400 | 1223 // constraint is the low-res device. The 800x600 format cropped to 800x400 |
1224 // is the lest expensive way to achieve it. | 1224 // is the lest expensive way to achieve it. |
1225 EXPECT_EQ(low_res_device_->device_id, result.device_id); | 1225 EXPECT_EQ(low_res_device_->device_id, result.device_id()); |
1226 EXPECT_EQ(800, result.Width()); | 1226 EXPECT_EQ(800, result.Width()); |
1227 EXPECT_EQ(600, result.Height()); | 1227 EXPECT_EQ(600, result.Height()); |
1228 } | 1228 } |
1229 | 1229 |
1230 { | 1230 { |
1231 const double kIdealAspectRatio = 3.0; | 1231 const double kIdealAspectRatio = 3.0; |
1232 constraint_factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); | 1232 constraint_factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); |
1233 constraint_factory_.basic().height.setExact(400); | 1233 constraint_factory_.basic().height.setExact(400); |
1234 auto result = SelectSettings(); | 1234 auto result = SelectSettings(); |
1235 EXPECT_TRUE(result.HasValue()); | 1235 EXPECT_TRUE(result.HasValue()); |
1236 // The only device that supports the ideal aspect ratio and the resolution | 1236 // The only device that supports the ideal aspect ratio and the resolution |
1237 // constraint is the high-res device. The 1280x720 cropped to 1200x400 is | 1237 // constraint is the high-res device. The 1280x720 cropped to 1200x400 is |
1238 // the lest expensive way to achieve it. | 1238 // the lest expensive way to achieve it. |
1239 EXPECT_EQ(high_res_device_->device_id, result.device_id); | 1239 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
1240 EXPECT_EQ(1280, result.Width()); | 1240 EXPECT_EQ(1280, result.Width()); |
1241 EXPECT_EQ(720, result.Height()); | 1241 EXPECT_EQ(720, result.Height()); |
1242 } | 1242 } |
1243 } | 1243 } |
1244 | 1244 |
1245 // The "Advanced" tests check selection criteria involving advanced constraint | 1245 // The "Advanced" tests check selection criteria involving advanced constraint |
1246 // sets. | 1246 // sets. |
1247 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, | 1247 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, |
1248 AdvancedMinMaxResolutionFrameRate) { | 1248 AdvancedMinMaxResolutionFrameRate) { |
1249 constraint_factory_.Reset(); | 1249 constraint_factory_.Reset(); |
1250 blink::WebMediaTrackConstraintSet& advanced1 = | 1250 blink::WebMediaTrackConstraintSet& advanced1 = |
1251 constraint_factory_.AddAdvanced(); | 1251 constraint_factory_.AddAdvanced(); |
1252 advanced1.width.setMin(4000); | 1252 advanced1.width.setMin(4000); |
1253 advanced1.height.setMin(4000); | 1253 advanced1.height.setMin(4000); |
1254 // No device supports the first advanced set. This first advanced constraint | 1254 // No device supports the first advanced set. This first advanced constraint |
1255 // set is therefore ignored in all calls to SelectSettings(). | 1255 // set is therefore ignored in all calls to SelectSettings(). |
1256 // Tie-breaker rule that applies is closeness to default settings. | 1256 // Tie-breaker rule that applies is closeness to default settings. |
1257 auto result = SelectSettings(); | 1257 auto result = SelectSettings(); |
1258 EXPECT_EQ(default_device_->device_id, result.device_id); | 1258 EXPECT_EQ(default_device_->device_id, result.device_id()); |
1259 EXPECT_EQ(*default_closest_format_, result.Format()); | 1259 EXPECT_EQ(*default_closest_format_, result.Format()); |
1260 | 1260 |
1261 blink::WebMediaTrackConstraintSet& advanced2 = | 1261 blink::WebMediaTrackConstraintSet& advanced2 = |
1262 constraint_factory_.AddAdvanced(); | 1262 constraint_factory_.AddAdvanced(); |
1263 advanced2.width.setMin(320); | 1263 advanced2.width.setMin(320); |
1264 advanced2.height.setMin(240); | 1264 advanced2.height.setMin(240); |
1265 advanced2.width.setMax(640); | 1265 advanced2.width.setMax(640); |
1266 advanced2.height.setMax(480); | 1266 advanced2.height.setMax(480); |
1267 result = SelectSettings(); | 1267 result = SelectSettings(); |
1268 // The device that best supports this advanced set is the low-res device, | 1268 // The device that best supports this advanced set is the low-res device, |
1269 // which natively supports the maximum resolution. | 1269 // which natively supports the maximum resolution. |
1270 EXPECT_EQ(low_res_device_->device_id, result.device_id); | 1270 EXPECT_EQ(low_res_device_->device_id, result.device_id()); |
1271 EXPECT_EQ(640, result.Width()); | 1271 EXPECT_EQ(640, result.Width()); |
1272 EXPECT_EQ(480, result.Height()); | 1272 EXPECT_EQ(480, result.Height()); |
1273 | 1273 |
1274 blink::WebMediaTrackConstraintSet& advanced3 = | 1274 blink::WebMediaTrackConstraintSet& advanced3 = |
1275 constraint_factory_.AddAdvanced(); | 1275 constraint_factory_.AddAdvanced(); |
1276 advanced3.frameRate.setMax(10.0); | 1276 advanced3.frameRate.setMax(10.0); |
1277 result = SelectSettings(); | 1277 result = SelectSettings(); |
1278 EXPECT_TRUE(result.HasValue()); | 1278 EXPECT_TRUE(result.HasValue()); |
1279 // The high-res device natively supports the third advanced set in addition | 1279 // The high-res device natively supports the third advanced set in addition |
1280 // to the previous set and should be selected. | 1280 // to the previous set and should be selected. |
1281 EXPECT_EQ(high_res_device_->device_id, result.device_id); | 1281 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
1282 EXPECT_EQ(640, result.Width()); | 1282 EXPECT_EQ(640, result.Width()); |
1283 EXPECT_EQ(480, result.Height()); | 1283 EXPECT_EQ(480, result.Height()); |
1284 | 1284 |
1285 blink::WebMediaTrackConstraintSet& advanced4 = | 1285 blink::WebMediaTrackConstraintSet& advanced4 = |
1286 constraint_factory_.AddAdvanced(); | 1286 constraint_factory_.AddAdvanced(); |
1287 advanced4.width.setMax(1000); | 1287 advanced4.width.setMax(1000); |
1288 advanced4.height.setMax(1000); | 1288 advanced4.height.setMax(1000); |
1289 result = SelectSettings(); | 1289 result = SelectSettings(); |
1290 // Even though the default device supports the resolution in the fourth | 1290 // Even though the default device supports the resolution in the fourth |
1291 // advanced natively, having better support for the previous sets has | 1291 // advanced natively, having better support for the previous sets has |
1292 // precedence, so the high-res device is selected. | 1292 // precedence, so the high-res device is selected. |
1293 EXPECT_TRUE(result.HasValue()); | 1293 EXPECT_TRUE(result.HasValue()); |
1294 EXPECT_EQ(high_res_device_->device_id, result.device_id); | 1294 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
1295 EXPECT_EQ(640, result.Width()); | 1295 EXPECT_EQ(640, result.Width()); |
1296 EXPECT_EQ(480, result.Height()); | 1296 EXPECT_EQ(480, result.Height()); |
1297 | 1297 |
1298 constraint_factory_.basic().width.setIdeal(100); | 1298 constraint_factory_.basic().width.setIdeal(100); |
1299 constraint_factory_.basic().height.setIdeal(100); | 1299 constraint_factory_.basic().height.setIdeal(100); |
1300 result = SelectSettings(); | 1300 result = SelectSettings(); |
1301 EXPECT_TRUE(result.HasValue()); | 1301 EXPECT_TRUE(result.HasValue()); |
1302 // The high-res device at 600x400@10Hz supports all advanced sets and is | 1302 // The high-res device at 600x400@10Hz supports all advanced sets and is |
1303 // better at supporting the ideal value. | 1303 // better at supporting the ideal value. |
1304 // It beats 320x240@30Hz because the penalty for the native frame rate takes | 1304 // It beats 320x240@30Hz because the penalty for the native frame rate takes |
1305 // precedence over the native fitness distance. | 1305 // precedence over the native fitness distance. |
1306 // Both support standard fitness distance equally, since 600x400 can be | 1306 // Both support standard fitness distance equally, since 600x400 can be |
1307 // cropped to 320x240. | 1307 // cropped to 320x240. |
1308 EXPECT_EQ(high_res_device_->device_id, result.device_id); | 1308 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
1309 EXPECT_EQ(600, result.Width()); | 1309 EXPECT_EQ(600, result.Width()); |
1310 EXPECT_EQ(400, result.Height()); | 1310 EXPECT_EQ(400, result.Height()); |
1311 | 1311 |
1312 constraint_factory_.basic().width.setIdeal(2000); | 1312 constraint_factory_.basic().width.setIdeal(2000); |
1313 constraint_factory_.basic().height.setIdeal(1500); | 1313 constraint_factory_.basic().height.setIdeal(1500); |
1314 result = SelectSettings(); | 1314 result = SelectSettings(); |
1315 EXPECT_TRUE(result.HasValue()); | 1315 EXPECT_TRUE(result.HasValue()); |
1316 // The high-res device at 640x480@10Hz is closer to the large ideal | 1316 // The high-res device at 640x480@10Hz is closer to the large ideal |
1317 // resolution. | 1317 // resolution. |
1318 EXPECT_EQ(high_res_device_->device_id, result.device_id); | 1318 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
1319 EXPECT_EQ(640, result.Width()); | 1319 EXPECT_EQ(640, result.Width()); |
1320 EXPECT_EQ(480, result.Height()); | 1320 EXPECT_EQ(480, result.Height()); |
1321 } | 1321 } |
1322 | 1322 |
1323 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, | 1323 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, |
1324 AdvancedResolutionAndFrameRate) { | 1324 AdvancedResolutionAndFrameRate) { |
1325 constraint_factory_.Reset(); | 1325 constraint_factory_.Reset(); |
1326 blink::WebMediaTrackConstraintSet& advanced1 = | 1326 blink::WebMediaTrackConstraintSet& advanced1 = |
1327 constraint_factory_.AddAdvanced(); | 1327 constraint_factory_.AddAdvanced(); |
1328 advanced1.width.setExact(1920); | 1328 advanced1.width.setExact(1920); |
1329 advanced1.height.setExact(1080); | 1329 advanced1.height.setExact(1080); |
1330 blink::WebMediaTrackConstraintSet& advanced2 = | 1330 blink::WebMediaTrackConstraintSet& advanced2 = |
1331 constraint_factory_.AddAdvanced(); | 1331 constraint_factory_.AddAdvanced(); |
1332 advanced2.frameRate.setExact(60.0); | 1332 advanced2.frameRate.setExact(60.0); |
1333 blink::WebMediaTrackConstraintSet& advanced3 = | 1333 blink::WebMediaTrackConstraintSet& advanced3 = |
1334 constraint_factory_.AddAdvanced(); | 1334 constraint_factory_.AddAdvanced(); |
1335 advanced3.width.setExact(2304); | 1335 advanced3.width.setExact(2304); |
1336 advanced3.height.setExact(1536); | 1336 advanced3.height.setExact(1536); |
1337 auto result = SelectSettings(); | 1337 auto result = SelectSettings(); |
1338 EXPECT_TRUE(result.HasValue()); | 1338 EXPECT_TRUE(result.HasValue()); |
1339 // The high-res device is the only one that satisfies the first advanced | 1339 // The high-res device is the only one that satisfies the first advanced |
1340 // set. 2304x1536x10.0 satisfies sets 1 and 3, while 1920x1080x60.0 | 1340 // set. 2304x1536x10.0 satisfies sets 1 and 3, while 1920x1080x60.0 |
1341 // satisfies sets 1, and 2. The latter must be selected, regardless of | 1341 // satisfies sets 1, and 2. The latter must be selected, regardless of |
1342 // any other criteria. | 1342 // any other criteria. |
1343 EXPECT_EQ(high_res_device_->device_id, result.device_id); | 1343 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
1344 EXPECT_EQ(1920, result.Width()); | 1344 EXPECT_EQ(1920, result.Width()); |
1345 EXPECT_EQ(1080, result.Height()); | 1345 EXPECT_EQ(1080, result.Height()); |
1346 EXPECT_EQ(60.0, result.FrameRate()); | 1346 EXPECT_EQ(60.0, result.FrameRate()); |
1347 } | 1347 } |
1348 | 1348 |
1349 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, AdvancedNoiseReduction) { | 1349 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, AdvancedNoiseReduction) { |
1350 constraint_factory_.Reset(); | 1350 constraint_factory_.Reset(); |
1351 blink::WebMediaTrackConstraintSet& advanced1 = | 1351 blink::WebMediaTrackConstraintSet& advanced1 = |
1352 constraint_factory_.AddAdvanced(); | 1352 constraint_factory_.AddAdvanced(); |
1353 advanced1.width.setMin(640); | 1353 advanced1.width.setMin(640); |
1354 advanced1.height.setMin(480); | 1354 advanced1.height.setMin(480); |
1355 blink::WebMediaTrackConstraintSet& advanced2 = | 1355 blink::WebMediaTrackConstraintSet& advanced2 = |
1356 constraint_factory_.AddAdvanced(); | 1356 constraint_factory_.AddAdvanced(); |
1357 advanced2.width.setMin(1920); | 1357 advanced2.width.setMin(1920); |
1358 advanced2.height.setMin(1080); | 1358 advanced2.height.setMin(1080); |
1359 advanced2.googNoiseReduction.setExact(false); | 1359 advanced2.googNoiseReduction.setExact(false); |
1360 auto result = SelectSettings(); | 1360 auto result = SelectSettings(); |
1361 EXPECT_TRUE(result.HasValue()); | 1361 EXPECT_TRUE(result.HasValue()); |
1362 EXPECT_EQ(high_res_device_->device_id, result.device_id); | 1362 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
1363 EXPECT_LE(1920, result.Width()); | 1363 EXPECT_LE(1920, result.Width()); |
1364 EXPECT_LE(1080, result.Height()); | 1364 EXPECT_LE(1080, result.Height()); |
1365 EXPECT_TRUE(result.noise_reduction && !*result.noise_reduction); | 1365 EXPECT_TRUE(result.noise_reduction() && !*result.noise_reduction()); |
1366 } | 1366 } |
1367 | 1367 |
1368 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, | 1368 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, |
1369 AdvancedContradictoryNoiseReduction) { | 1369 AdvancedContradictoryNoiseReduction) { |
1370 { | 1370 { |
1371 constraint_factory_.Reset(); | 1371 constraint_factory_.Reset(); |
1372 blink::WebMediaTrackConstraintSet& advanced1 = | 1372 blink::WebMediaTrackConstraintSet& advanced1 = |
1373 constraint_factory_.AddAdvanced(); | 1373 constraint_factory_.AddAdvanced(); |
1374 advanced1.width.setMin(640); | 1374 advanced1.width.setMin(640); |
1375 advanced1.height.setMin(480); | 1375 advanced1.height.setMin(480); |
1376 advanced1.googNoiseReduction.setExact(true); | 1376 advanced1.googNoiseReduction.setExact(true); |
1377 blink::WebMediaTrackConstraintSet& advanced2 = | 1377 blink::WebMediaTrackConstraintSet& advanced2 = |
1378 constraint_factory_.AddAdvanced(); | 1378 constraint_factory_.AddAdvanced(); |
1379 advanced2.width.setMin(1920); | 1379 advanced2.width.setMin(1920); |
1380 advanced2.height.setMin(1080); | 1380 advanced2.height.setMin(1080); |
1381 advanced2.googNoiseReduction.setExact(false); | 1381 advanced2.googNoiseReduction.setExact(false); |
1382 auto result = SelectSettings(); | 1382 auto result = SelectSettings(); |
1383 EXPECT_TRUE(result.HasValue()); | 1383 EXPECT_TRUE(result.HasValue()); |
1384 // The second advanced set cannot be satisfied because it contradicts the | 1384 // The second advanced set cannot be satisfied because it contradicts the |
1385 // first set. The default device supports the first set and should be | 1385 // first set. The default device supports the first set and should be |
1386 // selected. | 1386 // selected. |
1387 EXPECT_EQ(default_device_->device_id, result.device_id); | 1387 EXPECT_EQ(default_device_->device_id, result.device_id()); |
1388 EXPECT_LE(640, result.Width()); | 1388 EXPECT_LE(640, result.Width()); |
1389 EXPECT_LE(480, result.Height()); | 1389 EXPECT_LE(480, result.Height()); |
1390 EXPECT_TRUE(result.noise_reduction && *result.noise_reduction); | 1390 EXPECT_TRUE(result.noise_reduction() && *result.noise_reduction()); |
1391 } | 1391 } |
1392 | 1392 |
1393 // Same test without noise reduction | 1393 // Same test without noise reduction |
1394 { | 1394 { |
1395 constraint_factory_.Reset(); | 1395 constraint_factory_.Reset(); |
1396 blink::WebMediaTrackConstraintSet& advanced1 = | 1396 blink::WebMediaTrackConstraintSet& advanced1 = |
1397 constraint_factory_.AddAdvanced(); | 1397 constraint_factory_.AddAdvanced(); |
1398 advanced1.width.setMin(640); | 1398 advanced1.width.setMin(640); |
1399 advanced1.height.setMin(480); | 1399 advanced1.height.setMin(480); |
1400 blink::WebMediaTrackConstraintSet& advanced2 = | 1400 blink::WebMediaTrackConstraintSet& advanced2 = |
1401 constraint_factory_.AddAdvanced(); | 1401 constraint_factory_.AddAdvanced(); |
1402 advanced2.width.setMin(1920); | 1402 advanced2.width.setMin(1920); |
1403 advanced2.height.setMin(1080); | 1403 advanced2.height.setMin(1080); |
1404 auto result = SelectSettings(); | 1404 auto result = SelectSettings(); |
1405 EXPECT_TRUE(result.HasValue()); | 1405 EXPECT_TRUE(result.HasValue()); |
1406 // Only the high-res device can satisfy the second advanced set. | 1406 // Only the high-res device can satisfy the second advanced set. |
1407 EXPECT_EQ(high_res_device_->device_id, result.device_id); | 1407 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
1408 EXPECT_LE(1920, result.Width()); | 1408 EXPECT_LE(1920, result.Width()); |
1409 EXPECT_LE(1080, result.Height()); | 1409 EXPECT_LE(1080, result.Height()); |
1410 // Should select default noise reduction setting. | 1410 // Should select default noise reduction setting. |
1411 EXPECT_TRUE(!result.noise_reduction); | 1411 EXPECT_TRUE(!result.noise_reduction()); |
1412 } | 1412 } |
1413 } | 1413 } |
1414 | 1414 |
1415 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, | 1415 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, |
1416 AdvancedContradictoryExactResolution) { | 1416 AdvancedContradictoryExactResolution) { |
1417 constraint_factory_.Reset(); | 1417 constraint_factory_.Reset(); |
1418 blink::WebMediaTrackConstraintSet& advanced1 = | 1418 blink::WebMediaTrackConstraintSet& advanced1 = |
1419 constraint_factory_.AddAdvanced(); | 1419 constraint_factory_.AddAdvanced(); |
1420 advanced1.width.setExact(640); | 1420 advanced1.width.setExact(640); |
1421 advanced1.height.setExact(480); | 1421 advanced1.height.setExact(480); |
1422 blink::WebMediaTrackConstraintSet& advanced2 = | 1422 blink::WebMediaTrackConstraintSet& advanced2 = |
1423 constraint_factory_.AddAdvanced(); | 1423 constraint_factory_.AddAdvanced(); |
1424 advanced2.width.setExact(1920); | 1424 advanced2.width.setExact(1920); |
1425 advanced2.height.setExact(1080); | 1425 advanced2.height.setExact(1080); |
1426 auto result = SelectSettings(); | 1426 auto result = SelectSettings(); |
1427 EXPECT_TRUE(result.HasValue()); | 1427 EXPECT_TRUE(result.HasValue()); |
1428 // The second advanced set must be ignored because it contradicts the first | 1428 // The second advanced set must be ignored because it contradicts the first |
1429 // set. The low-res device is the one that best supports the requested | 1429 // set. The low-res device is the one that best supports the requested |
1430 // resolution. | 1430 // resolution. |
1431 EXPECT_EQ(low_res_device_->device_id, result.device_id); | 1431 EXPECT_EQ(low_res_device_->device_id, result.device_id()); |
1432 EXPECT_EQ(640, result.Width()); | 1432 EXPECT_EQ(640, result.Width()); |
1433 EXPECT_EQ(480, result.Height()); | 1433 EXPECT_EQ(480, result.Height()); |
1434 } | 1434 } |
1435 | 1435 |
1436 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, | 1436 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, |
1437 AdvancedContradictoryMaxMinResolutionFrameRate) { | 1437 AdvancedContradictoryMaxMinResolutionFrameRate) { |
1438 constraint_factory_.Reset(); | 1438 constraint_factory_.Reset(); |
1439 blink::WebMediaTrackConstraintSet& advanced1 = | 1439 blink::WebMediaTrackConstraintSet& advanced1 = |
1440 constraint_factory_.AddAdvanced(); | 1440 constraint_factory_.AddAdvanced(); |
1441 advanced1.width.setMax(640); | 1441 advanced1.width.setMax(640); |
1442 advanced1.height.setMax(480); | 1442 advanced1.height.setMax(480); |
1443 blink::WebMediaTrackConstraintSet& advanced2 = | 1443 blink::WebMediaTrackConstraintSet& advanced2 = |
1444 constraint_factory_.AddAdvanced(); | 1444 constraint_factory_.AddAdvanced(); |
1445 advanced2.width.setMin(1920); | 1445 advanced2.width.setMin(1920); |
1446 advanced2.height.setMin(1080); | 1446 advanced2.height.setMin(1080); |
1447 advanced2.frameRate.setExact(60.0); | 1447 advanced2.frameRate.setExact(60.0); |
1448 auto result = SelectSettings(); | 1448 auto result = SelectSettings(); |
1449 EXPECT_TRUE(result.HasValue()); | 1449 EXPECT_TRUE(result.HasValue()); |
1450 // The second advanced set must be ignored because it contradicts the first | 1450 // The second advanced set must be ignored because it contradicts the first |
1451 // set. The default device with the 200x200@40Hz format should be selected. | 1451 // set. The default device with the 200x200@40Hz format should be selected. |
1452 // That format satisfies the first advanced set as well as any other, so the | 1452 // That format satisfies the first advanced set as well as any other, so the |
1453 // tie breaker rule that applies is default device ID. | 1453 // tie breaker rule that applies is default device ID. |
1454 EXPECT_EQ(default_device_->device_id, result.device_id); | 1454 EXPECT_EQ(default_device_->device_id, result.device_id()); |
1455 EXPECT_EQ(200, result.Width()); | 1455 EXPECT_EQ(200, result.Width()); |
1456 EXPECT_EQ(200, result.Height()); | 1456 EXPECT_EQ(200, result.Height()); |
1457 EXPECT_EQ(40, result.FrameRate()); | 1457 EXPECT_EQ(40, result.FrameRate()); |
1458 } | 1458 } |
1459 | 1459 |
1460 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, | 1460 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, |
1461 AdvancedContradictoryMinMaxResolutionFrameRate) { | 1461 AdvancedContradictoryMinMaxResolutionFrameRate) { |
1462 constraint_factory_.Reset(); | 1462 constraint_factory_.Reset(); |
1463 blink::WebMediaTrackConstraintSet& advanced1 = | 1463 blink::WebMediaTrackConstraintSet& advanced1 = |
1464 constraint_factory_.AddAdvanced(); | 1464 constraint_factory_.AddAdvanced(); |
1465 advanced1.width.setMin(800); | 1465 advanced1.width.setMin(800); |
1466 advanced1.height.setMin(600); | 1466 advanced1.height.setMin(600); |
1467 blink::WebMediaTrackConstraintSet& advanced2 = | 1467 blink::WebMediaTrackConstraintSet& advanced2 = |
1468 constraint_factory_.AddAdvanced(); | 1468 constraint_factory_.AddAdvanced(); |
1469 advanced2.width.setMax(640); | 1469 advanced2.width.setMax(640); |
1470 advanced2.height.setMax(480); | 1470 advanced2.height.setMax(480); |
1471 advanced2.frameRate.setExact(60.0); | 1471 advanced2.frameRate.setExact(60.0); |
1472 auto result = SelectSettings(); | 1472 auto result = SelectSettings(); |
1473 EXPECT_TRUE(result.HasValue()); | 1473 EXPECT_TRUE(result.HasValue()); |
1474 // The second advanced set must be ignored because it contradicts the first | 1474 // The second advanced set must be ignored because it contradicts the first |
1475 // set. The default device with the 1000x1000@20Hz format should be selected. | 1475 // set. The default device with the 1000x1000@20Hz format should be selected. |
1476 // That format satisfies the first advanced set as well as any other, so the | 1476 // That format satisfies the first advanced set as well as any other, so the |
1477 // tie breaker rule that applies is default device ID. | 1477 // tie breaker rule that applies is default device ID. |
1478 EXPECT_EQ(default_device_->device_id, result.device_id); | 1478 EXPECT_EQ(default_device_->device_id, result.device_id()); |
1479 EXPECT_EQ(1000, result.Width()); | 1479 EXPECT_EQ(1000, result.Width()); |
1480 EXPECT_EQ(1000, result.Height()); | 1480 EXPECT_EQ(1000, result.Height()); |
1481 EXPECT_EQ(20, result.FrameRate()); | 1481 EXPECT_EQ(20, result.FrameRate()); |
1482 } | 1482 } |
1483 | 1483 |
1484 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, | 1484 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, |
1485 AdvancedContradictoryExactAspectRatio) { | 1485 AdvancedContradictoryExactAspectRatio) { |
1486 constraint_factory_.Reset(); | 1486 constraint_factory_.Reset(); |
1487 blink::WebMediaTrackConstraintSet& advanced1 = | 1487 blink::WebMediaTrackConstraintSet& advanced1 = |
1488 constraint_factory_.AddAdvanced(); | 1488 constraint_factory_.AddAdvanced(); |
1489 advanced1.aspectRatio.setExact(2300.0); | 1489 advanced1.aspectRatio.setExact(2300.0); |
1490 blink::WebMediaTrackConstraintSet& advanced2 = | 1490 blink::WebMediaTrackConstraintSet& advanced2 = |
1491 constraint_factory_.AddAdvanced(); | 1491 constraint_factory_.AddAdvanced(); |
1492 advanced2.aspectRatio.setExact(3.0); | 1492 advanced2.aspectRatio.setExact(3.0); |
1493 auto result = SelectSettings(); | 1493 auto result = SelectSettings(); |
1494 EXPECT_TRUE(result.HasValue()); | 1494 EXPECT_TRUE(result.HasValue()); |
1495 // The second advanced set must be ignored because it contradicts the first | 1495 // The second advanced set must be ignored because it contradicts the first |
1496 // set. Only the high-res device in the highest-resolution format supports the | 1496 // set. Only the high-res device in the highest-resolution format supports the |
1497 // requested aspect ratio. | 1497 // requested aspect ratio. |
1498 EXPECT_EQ(high_res_device_->device_id, result.device_id); | 1498 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
1499 EXPECT_EQ(*high_res_highest_format_, result.Format()); | 1499 EXPECT_EQ(*high_res_highest_format_, result.Format()); |
1500 } | 1500 } |
1501 | 1501 |
1502 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, | 1502 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, |
1503 AdvancedContradictoryAspectRatioRange) { | 1503 AdvancedContradictoryAspectRatioRange) { |
1504 constraint_factory_.Reset(); | 1504 constraint_factory_.Reset(); |
1505 blink::WebMediaTrackConstraintSet& advanced1 = | 1505 blink::WebMediaTrackConstraintSet& advanced1 = |
1506 constraint_factory_.AddAdvanced(); | 1506 constraint_factory_.AddAdvanced(); |
1507 advanced1.aspectRatio.setMin(2300.0); | 1507 advanced1.aspectRatio.setMin(2300.0); |
1508 blink::WebMediaTrackConstraintSet& advanced2 = | 1508 blink::WebMediaTrackConstraintSet& advanced2 = |
1509 constraint_factory_.AddAdvanced(); | 1509 constraint_factory_.AddAdvanced(); |
1510 advanced2.aspectRatio.setMax(3.0); | 1510 advanced2.aspectRatio.setMax(3.0); |
1511 auto result = SelectSettings(); | 1511 auto result = SelectSettings(); |
1512 EXPECT_TRUE(result.HasValue()); | 1512 EXPECT_TRUE(result.HasValue()); |
1513 // The second advanced set must be ignored because it contradicts the first | 1513 // The second advanced set must be ignored because it contradicts the first |
1514 // set. Only the high-res device in the highest-resolution format supports the | 1514 // set. Only the high-res device in the highest-resolution format supports the |
1515 // requested aspect ratio. | 1515 // requested aspect ratio. |
1516 EXPECT_EQ(high_res_device_->device_id, result.device_id); | 1516 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
1517 EXPECT_EQ(*high_res_highest_format_, result.Format()); | 1517 EXPECT_EQ(*high_res_highest_format_, result.Format()); |
1518 } | 1518 } |
1519 | 1519 |
1520 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, | 1520 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, |
1521 AdvancedContradictoryExactFrameRate) { | 1521 AdvancedContradictoryExactFrameRate) { |
1522 constraint_factory_.Reset(); | 1522 constraint_factory_.Reset(); |
1523 blink::WebMediaTrackConstraintSet& advanced1 = | 1523 blink::WebMediaTrackConstraintSet& advanced1 = |
1524 constraint_factory_.AddAdvanced(); | 1524 constraint_factory_.AddAdvanced(); |
1525 advanced1.frameRate.setExact(40.0); | 1525 advanced1.frameRate.setExact(40.0); |
1526 blink::WebMediaTrackConstraintSet& advanced2 = | 1526 blink::WebMediaTrackConstraintSet& advanced2 = |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1560 advanced2.width.setMin(2000); | 1560 advanced2.width.setMin(2000); |
1561 advanced2.frameRate.setExact(10.0); | 1561 advanced2.frameRate.setExact(10.0); |
1562 blink::WebMediaTrackConstraintSet& advanced3 = | 1562 blink::WebMediaTrackConstraintSet& advanced3 = |
1563 constraint_factory_.AddAdvanced(); | 1563 constraint_factory_.AddAdvanced(); |
1564 advanced3.frameRate.setExact(30.0); | 1564 advanced3.frameRate.setExact(30.0); |
1565 auto result = SelectSettings(); | 1565 auto result = SelectSettings(); |
1566 EXPECT_TRUE(result.HasValue()); | 1566 EXPECT_TRUE(result.HasValue()); |
1567 // The low-res device at 320x240@30Hz satisfies advanced sets 1 and 3. | 1567 // The low-res device at 320x240@30Hz satisfies advanced sets 1 and 3. |
1568 // The high-res device at 2304x1536@10.0f can satisfy sets 1 and 2, but not | 1568 // The high-res device at 2304x1536@10.0f can satisfy sets 1 and 2, but not |
1569 // both at the same time. Thus, low-res device must be preferred. | 1569 // both at the same time. Thus, low-res device must be preferred. |
1570 EXPECT_EQ(low_res_device_->device_id, result.device_id); | 1570 EXPECT_EQ(low_res_device_->device_id, result.device_id()); |
1571 EXPECT_EQ(30.0, result.FrameRate()); | 1571 EXPECT_EQ(30.0, result.FrameRate()); |
1572 EXPECT_GE(1920, result.Width()); | 1572 EXPECT_GE(1920, result.Width()); |
1573 } | 1573 } |
1574 | 1574 |
1575 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, | 1575 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, |
1576 AdvancedContradictoryHeightFrameRate) { | 1576 AdvancedContradictoryHeightFrameRate) { |
1577 constraint_factory_.Reset(); | 1577 constraint_factory_.Reset(); |
1578 blink::WebMediaTrackConstraintSet& advanced1 = | 1578 blink::WebMediaTrackConstraintSet& advanced1 = |
1579 constraint_factory_.AddAdvanced(); | 1579 constraint_factory_.AddAdvanced(); |
1580 advanced1.height.setMax(1080); | 1580 advanced1.height.setMax(1080); |
1581 blink::WebMediaTrackConstraintSet& advanced2 = | 1581 blink::WebMediaTrackConstraintSet& advanced2 = |
1582 constraint_factory_.AddAdvanced(); | 1582 constraint_factory_.AddAdvanced(); |
1583 advanced2.height.setMin(1500); | 1583 advanced2.height.setMin(1500); |
1584 advanced2.frameRate.setExact(10.0); | 1584 advanced2.frameRate.setExact(10.0); |
1585 blink::WebMediaTrackConstraintSet& advanced3 = | 1585 blink::WebMediaTrackConstraintSet& advanced3 = |
1586 constraint_factory_.AddAdvanced(); | 1586 constraint_factory_.AddAdvanced(); |
1587 advanced3.frameRate.setExact(60.0); | 1587 advanced3.frameRate.setExact(60.0); |
1588 auto result = SelectSettings(); | 1588 auto result = SelectSettings(); |
1589 EXPECT_TRUE(result.HasValue()); | 1589 EXPECT_TRUE(result.HasValue()); |
1590 // The high-res device at 1280x768@60Hz and 1920x1080@60Hz satisfies advanced | 1590 // The high-res device at 1280x768@60Hz and 1920x1080@60Hz satisfies advanced |
1591 // sets 1 and 3. The same device at 2304x1536@10.0f can satisfy sets 1 and 2, | 1591 // sets 1 and 3. The same device at 2304x1536@10.0f can satisfy sets 1 and 2, |
1592 // but not both at the same time. Thus, the format closest to default that | 1592 // but not both at the same time. Thus, the format closest to default that |
1593 // satisfies sets 1 and 3 must be chosen. | 1593 // satisfies sets 1 and 3 must be chosen. |
1594 EXPECT_EQ(high_res_device_->device_id, result.device_id); | 1594 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
1595 EXPECT_EQ(60.0, result.FrameRate()); | 1595 EXPECT_EQ(60.0, result.FrameRate()); |
1596 EXPECT_GE(1080, result.Height()); | 1596 EXPECT_GE(1080, result.Height()); |
1597 } | 1597 } |
1598 | 1598 |
1599 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, AdvancedDeviceID) { | 1599 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, AdvancedDeviceID) { |
1600 constraint_factory_.Reset(); | 1600 constraint_factory_.Reset(); |
1601 blink::WebMediaTrackConstraintSet& advanced1 = | 1601 blink::WebMediaTrackConstraintSet& advanced1 = |
1602 constraint_factory_.AddAdvanced(); | 1602 constraint_factory_.AddAdvanced(); |
1603 blink::WebString id_vector1[] = {blink::WebString::fromASCII(kDeviceID1), | 1603 blink::WebString id_vector1[] = {blink::WebString::fromASCII(kDeviceID1), |
1604 blink::WebString::fromASCII(kDeviceID2)}; | 1604 blink::WebString::fromASCII(kDeviceID2)}; |
1605 advanced1.deviceId.setExact( | 1605 advanced1.deviceId.setExact( |
1606 blink::WebVector<blink::WebString>(id_vector1, arraysize(id_vector1))); | 1606 blink::WebVector<blink::WebString>(id_vector1, arraysize(id_vector1))); |
1607 blink::WebString id_vector2[] = {blink::WebString::fromASCII(kDeviceID2), | 1607 blink::WebString id_vector2[] = {blink::WebString::fromASCII(kDeviceID2), |
1608 blink::WebString::fromASCII(kDeviceID3)}; | 1608 blink::WebString::fromASCII(kDeviceID3)}; |
1609 blink::WebMediaTrackConstraintSet& advanced2 = | 1609 blink::WebMediaTrackConstraintSet& advanced2 = |
1610 constraint_factory_.AddAdvanced(); | 1610 constraint_factory_.AddAdvanced(); |
1611 advanced2.deviceId.setExact( | 1611 advanced2.deviceId.setExact( |
1612 blink::WebVector<blink::WebString>(id_vector2, arraysize(id_vector2))); | 1612 blink::WebVector<blink::WebString>(id_vector2, arraysize(id_vector2))); |
1613 auto result = SelectSettings(); | 1613 auto result = SelectSettings(); |
1614 EXPECT_TRUE(result.HasValue()); | 1614 EXPECT_TRUE(result.HasValue()); |
1615 // kDeviceID2 must be selected because it is the only one that satisfies both | 1615 // kDeviceID2 must be selected because it is the only one that satisfies both |
1616 // advanced sets. | 1616 // advanced sets. |
1617 EXPECT_EQ(std::string(kDeviceID2), result.device_id); | 1617 EXPECT_EQ(std::string(kDeviceID2), result.device_id()); |
1618 } | 1618 } |
1619 | 1619 |
1620 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, | 1620 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, |
1621 AdvancedContradictoryDeviceID) { | 1621 AdvancedContradictoryDeviceID) { |
1622 constraint_factory_.Reset(); | 1622 constraint_factory_.Reset(); |
1623 blink::WebMediaTrackConstraintSet& advanced1 = | 1623 blink::WebMediaTrackConstraintSet& advanced1 = |
1624 constraint_factory_.AddAdvanced(); | 1624 constraint_factory_.AddAdvanced(); |
1625 blink::WebString id_vector1[] = {blink::WebString::fromASCII(kDeviceID1), | 1625 blink::WebString id_vector1[] = {blink::WebString::fromASCII(kDeviceID1), |
1626 blink::WebString::fromASCII(kDeviceID2)}; | 1626 blink::WebString::fromASCII(kDeviceID2)}; |
1627 advanced1.deviceId.setExact( | 1627 advanced1.deviceId.setExact( |
1628 blink::WebVector<blink::WebString>(id_vector1, arraysize(id_vector1))); | 1628 blink::WebVector<blink::WebString>(id_vector1, arraysize(id_vector1))); |
1629 blink::WebString id_vector2[] = {blink::WebString::fromASCII(kDeviceID3), | 1629 blink::WebString id_vector2[] = {blink::WebString::fromASCII(kDeviceID3), |
1630 blink::WebString::fromASCII(kDeviceID4)}; | 1630 blink::WebString::fromASCII(kDeviceID4)}; |
1631 blink::WebMediaTrackConstraintSet& advanced2 = | 1631 blink::WebMediaTrackConstraintSet& advanced2 = |
1632 constraint_factory_.AddAdvanced(); | 1632 constraint_factory_.AddAdvanced(); |
1633 advanced2.deviceId.setExact( | 1633 advanced2.deviceId.setExact( |
1634 blink::WebVector<blink::WebString>(id_vector2, arraysize(id_vector2))); | 1634 blink::WebVector<blink::WebString>(id_vector2, arraysize(id_vector2))); |
1635 auto result = SelectSettings(); | 1635 auto result = SelectSettings(); |
1636 EXPECT_TRUE(result.HasValue()); | 1636 EXPECT_TRUE(result.HasValue()); |
1637 // The second advanced set must be ignored because it contradicts the first | 1637 // The second advanced set must be ignored because it contradicts the first |
1638 // set. | 1638 // set. |
1639 EXPECT_EQ(std::string(kDeviceID1), result.device_id); | 1639 EXPECT_EQ(std::string(kDeviceID1), result.device_id()); |
1640 } | 1640 } |
1641 | 1641 |
1642 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, | 1642 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, |
1643 AdvancedContradictoryPowerLineFrequency) { | 1643 AdvancedContradictoryPowerLineFrequency) { |
1644 { | 1644 { |
1645 constraint_factory_.Reset(); | 1645 constraint_factory_.Reset(); |
1646 blink::WebMediaTrackConstraintSet& advanced1 = | 1646 blink::WebMediaTrackConstraintSet& advanced1 = |
1647 constraint_factory_.AddAdvanced(); | 1647 constraint_factory_.AddAdvanced(); |
1648 advanced1.width.setMin(640); | 1648 advanced1.width.setMin(640); |
1649 advanced1.height.setMin(480); | 1649 advanced1.height.setMin(480); |
1650 advanced1.googPowerLineFrequency.setExact(50); | 1650 advanced1.googPowerLineFrequency.setExact(50); |
1651 blink::WebMediaTrackConstraintSet& advanced2 = | 1651 blink::WebMediaTrackConstraintSet& advanced2 = |
1652 constraint_factory_.AddAdvanced(); | 1652 constraint_factory_.AddAdvanced(); |
1653 advanced2.width.setMin(1920); | 1653 advanced2.width.setMin(1920); |
1654 advanced2.height.setMin(1080); | 1654 advanced2.height.setMin(1080); |
1655 advanced2.googPowerLineFrequency.setExact(60); | 1655 advanced2.googPowerLineFrequency.setExact(60); |
1656 auto result = SelectSettings(); | 1656 auto result = SelectSettings(); |
1657 EXPECT_TRUE(result.HasValue()); | 1657 EXPECT_TRUE(result.HasValue()); |
1658 // The second advanced set cannot be satisfied because it contradicts the | 1658 // The second advanced set cannot be satisfied because it contradicts the |
1659 // first set. The default device supports the first set and should be | 1659 // first set. The default device supports the first set and should be |
1660 // selected. | 1660 // selected. |
1661 EXPECT_EQ(default_device_->device_id, result.device_id); | 1661 EXPECT_EQ(default_device_->device_id, result.device_id()); |
1662 EXPECT_LE(640, result.Width()); | 1662 EXPECT_LE(640, result.Width()); |
1663 EXPECT_LE(480, result.Height()); | 1663 EXPECT_LE(480, result.Height()); |
1664 EXPECT_EQ(50, static_cast<int>(result.PowerLineFrequency())); | 1664 EXPECT_EQ(50, static_cast<int>(result.PowerLineFrequency())); |
1665 } | 1665 } |
1666 } | 1666 } |
1667 | 1667 |
1668 // The "NoDevices" tests verify that the algorithm returns the expected result | 1668 // The "NoDevices" tests verify that the algorithm returns the expected result |
1669 // when there are no candidates to choose from. | 1669 // when there are no candidates to choose from. |
1670 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, NoDevicesNoConstraints) { | 1670 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, NoDevicesNoConstraints) { |
1671 constraint_factory_.Reset(); | 1671 constraint_factory_.Reset(); |
1672 VideoDeviceCaptureCapabilities capabilities; | 1672 VideoDeviceCaptureCapabilities capabilities; |
1673 auto result = SelectVideoDeviceCaptureSourceSettings( | 1673 auto result = SelectVideoDeviceCaptureSourceSettings( |
1674 capabilities, constraint_factory_.CreateWebMediaConstraints()); | 1674 capabilities, constraint_factory_.CreateWebMediaConstraints()); |
1675 EXPECT_FALSE(result.HasValue()); | 1675 EXPECT_FALSE(result.HasValue()); |
1676 EXPECT_TRUE(std::string(result.failed_constraint_name).empty()); | 1676 EXPECT_TRUE(std::string(result.failed_constraint_name()).empty()); |
1677 } | 1677 } |
1678 | 1678 |
1679 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, NoDevicesWithConstraints) { | 1679 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, NoDevicesWithConstraints) { |
1680 constraint_factory_.Reset(); | 1680 constraint_factory_.Reset(); |
1681 constraint_factory_.basic().height.setExact(100); | 1681 constraint_factory_.basic().height.setExact(100); |
1682 VideoDeviceCaptureCapabilities capabilities; | 1682 VideoDeviceCaptureCapabilities capabilities; |
1683 auto result = SelectVideoDeviceCaptureSourceSettings( | 1683 auto result = SelectVideoDeviceCaptureSourceSettings( |
1684 capabilities, constraint_factory_.CreateWebMediaConstraints()); | 1684 capabilities, constraint_factory_.CreateWebMediaConstraints()); |
1685 EXPECT_FALSE(result.HasValue()); | 1685 EXPECT_FALSE(result.HasValue()); |
1686 EXPECT_TRUE(std::string(result.failed_constraint_name).empty()); | 1686 EXPECT_TRUE(std::string(result.failed_constraint_name()).empty()); |
1687 } | 1687 } |
1688 | 1688 |
1689 } // namespace content | 1689 } // namespace content |
OLD | NEW |