Chromium Code Reviews| 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 60 media::VideoCaptureFormat(gfx::Size(800, 600), 20.0f, | 60 media::VideoCaptureFormat(gfx::Size(800, 600), 20.0f, |
| 61 media::PIXEL_FORMAT_I420), | 61 media::PIXEL_FORMAT_I420), |
| 62 }; | 62 }; |
| 63 capabilities_.device_capabilities.push_back(std::move(device)); | 63 capabilities_.device_capabilities.push_back(std::move(device)); |
| 64 | 64 |
| 65 // A high-resolution device. | 65 // A high-resolution device. |
| 66 device = ::mojom::VideoInputDeviceCapabilities::New(); | 66 device = ::mojom::VideoInputDeviceCapabilities::New(); |
| 67 device->device_id = kDeviceID3; | 67 device->device_id = kDeviceID3; |
| 68 device->facing_mode = ::mojom::FacingMode::USER; | 68 device->facing_mode = ::mojom::FacingMode::USER; |
| 69 device->formats = { | 69 device->formats = { |
| 70 media::VideoCaptureFormat(gfx::Size(320, 240), 10.0f, | 70 media::VideoCaptureFormat(gfx::Size(600, 400), 10.0f, |
| 71 media::PIXEL_FORMAT_I420), | 71 media::PIXEL_FORMAT_I420), |
| 72 media::VideoCaptureFormat(gfx::Size(640, 480), 10.0f, | 72 media::VideoCaptureFormat(gfx::Size(640, 480), 10.0f, |
| 73 media::PIXEL_FORMAT_I420), | 73 media::PIXEL_FORMAT_I420), |
| 74 // This format has defaults for all settings | 74 // This format has defaults for all settings |
| 75 media::VideoCaptureFormat( | 75 media::VideoCaptureFormat( |
| 76 gfx::Size(MediaStreamVideoSource::kDefaultWidth, | 76 gfx::Size(MediaStreamVideoSource::kDefaultWidth, |
| 77 MediaStreamVideoSource::kDefaultHeight), | 77 MediaStreamVideoSource::kDefaultHeight), |
| 78 MediaStreamVideoSource::kDefaultFrameRate, | 78 MediaStreamVideoSource::kDefaultFrameRate, |
| 79 media::PIXEL_FORMAT_I420), | 79 media::PIXEL_FORMAT_I420), |
| 80 media::VideoCaptureFormat(gfx::Size(1280, 720), 60.0f, | 80 media::VideoCaptureFormat(gfx::Size(1280, 720), 60.0f, |
| (...skipping 1156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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, AdvancedExactResolution) { | 1247 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, |
| 1248 AdvancedMinMaxResolutionFrameRate) { | |
| 1248 constraint_factory_.Reset(); | 1249 constraint_factory_.Reset(); |
| 1249 blink::WebMediaTrackConstraintSet& advanced1 = | 1250 blink::WebMediaTrackConstraintSet& advanced1 = |
| 1250 constraint_factory_.AddAdvanced(); | 1251 constraint_factory_.AddAdvanced(); |
| 1251 advanced1.width.setExact(4000); | 1252 advanced1.width.setMin(4000); |
| 1252 advanced1.height.setExact(4000); | 1253 advanced1.height.setMin(4000); |
| 1253 blink::WebMediaTrackConstraintSet& advanced2 = | 1254 // No device supports the first advanced set. |
|
hta - Chromium
2017/02/28 19:32:21
Add a comment: This first advanced constraint is t
Guido Urdaneta
2017/03/01 11:32:42
Done.
| |
| 1254 constraint_factory_.AddAdvanced(); | 1255 // Tie-breaker rule that applies is closeness to default settings. |
| 1255 advanced2.width.setExact(3000); | |
| 1256 advanced2.height.setExact(3000); | |
| 1257 auto result = SelectSettings(); | 1256 auto result = SelectSettings(); |
| 1258 // No device supports the advanced constraint sets. | |
| 1259 // Tie-breaker rule that applies is closeness to default settings. | |
| 1260 EXPECT_EQ(default_device_->device_id, result.device_id); | 1257 EXPECT_EQ(default_device_->device_id, result.device_id); |
| 1261 EXPECT_EQ(*default_closest_format_, result.Format()); | 1258 EXPECT_EQ(*default_closest_format_, result.Format()); |
| 1262 | 1259 |
| 1260 blink::WebMediaTrackConstraintSet& advanced2 = | |
| 1261 constraint_factory_.AddAdvanced(); | |
| 1262 advanced2.width.setMin(320); | |
| 1263 advanced2.height.setMin(240); | |
| 1264 advanced2.width.setMax(640); | |
| 1265 advanced2.height.setMax(480); | |
| 1266 result = SelectSettings(); | |
| 1267 // The device that best supports this advanced set is the low-res device, | |
| 1268 // which natively supports the maximum resolution. | |
| 1269 EXPECT_EQ(low_res_device_->device_id, result.device_id); | |
| 1270 EXPECT_EQ(640, result.Width()); | |
| 1271 EXPECT_EQ(480, result.Height()); | |
| 1272 | |
| 1263 blink::WebMediaTrackConstraintSet& advanced3 = | 1273 blink::WebMediaTrackConstraintSet& advanced3 = |
| 1264 constraint_factory_.AddAdvanced(); | 1274 constraint_factory_.AddAdvanced(); |
| 1265 advanced3.width.setExact(1920); | 1275 advanced3.frameRate.setMax(10.0); |
| 1266 advanced3.height.setExact(1080); | |
| 1267 result = SelectSettings(); | 1276 result = SelectSettings(); |
| 1268 EXPECT_TRUE(result.HasValue()); | 1277 EXPECT_TRUE(result.HasValue()); |
| 1269 // The high-res device natively supports the third advanced constraint set | 1278 // The high-res device natively supports the third advanced set and should be |
| 1270 // and should be selected. | 1279 // selected. |
| 1271 // First tie-breaker rule that applies is support for advanced constraints | |
| 1272 // that appear first. Second tie-breaker rule is custom distance to advanced | |
| 1273 // constraint sets that appear first. | |
| 1274 EXPECT_EQ(high_res_device_->device_id, result.device_id); | 1280 EXPECT_EQ(high_res_device_->device_id, result.device_id); |
| 1275 EXPECT_EQ(1920, result.Width()); | 1281 EXPECT_EQ(640, result.Width()); |
| 1276 EXPECT_EQ(1080, result.Height()); | 1282 EXPECT_EQ(480, result.Height()); |
| 1277 | 1283 |
| 1278 blink::WebMediaTrackConstraintSet& advanced4 = | 1284 blink::WebMediaTrackConstraintSet& advanced4 = |
| 1279 constraint_factory_.AddAdvanced(); | 1285 constraint_factory_.AddAdvanced(); |
| 1280 advanced4.width.setExact(640); | 1286 advanced4.width.setMax(1000); |
| 1281 advanced4.height.setExact(480); | 1287 advanced4.height.setMax(1000); |
| 1288 result = SelectSettings(); | |
| 1289 // Even though the default device supports the resolution in the fourth | |
| 1290 // advanced natively, having better support for the previous sets has | |
| 1291 // precedence. | |
| 1292 EXPECT_TRUE(result.HasValue()); | |
| 1293 EXPECT_EQ(high_res_device_->device_id, result.device_id); | |
| 1294 EXPECT_EQ(640, result.Width()); | |
| 1295 EXPECT_EQ(480, result.Height()); | |
| 1296 | |
| 1297 constraint_factory_.basic().width.setIdeal(100); | |
| 1298 constraint_factory_.basic().height.setIdeal(100); | |
| 1282 result = SelectSettings(); | 1299 result = SelectSettings(); |
| 1283 EXPECT_TRUE(result.HasValue()); | 1300 EXPECT_TRUE(result.HasValue()); |
| 1284 // First tie-breaker rule that applies is support for advanced constraints | 1301 // The high-res device at 600x400@10Hz supports all advanced sets and is |
| 1285 // that appear first, which leaves out configurations that only support the | 1302 // better at supporting the ideal value. |
| 1286 // fourth advanced constraint set in favor of configurations that support | 1303 // It beats 320x240@30Hz because the penalty for the frame rate takes |
| 1287 // the third set. | 1304 // precedence over the native fitness distance. |
| 1288 // Second tie-breaker rule is custom distance to advanced constraint sets | 1305 // Both support standard fitness distance equally, since 600x400 can be |
| 1289 // that appear first. | 1306 // cropped to 320x240. |
| 1290 EXPECT_EQ(high_res_device_->device_id, result.device_id); | 1307 EXPECT_EQ(high_res_device_->device_id, result.device_id); |
| 1291 EXPECT_EQ(1920, result.Width()); | 1308 EXPECT_EQ(600, result.Width()); |
| 1292 EXPECT_EQ(1080, result.Height()); | 1309 EXPECT_EQ(400, result.Height()); |
| 1293 | |
| 1294 constraint_factory_.basic().width.setIdeal(800); | |
| 1295 constraint_factory_.basic().height.setIdeal(600); | |
| 1296 result = SelectSettings(); | |
| 1297 EXPECT_TRUE(result.HasValue()); | |
| 1298 // The ideal value is supported by the same configuration, so nothing | |
| 1299 // changes. | |
| 1300 EXPECT_EQ(high_res_device_->device_id, result.device_id); | |
| 1301 EXPECT_EQ(1920, result.Width()); | |
| 1302 EXPECT_EQ(1080, result.Height()); | |
| 1303 | 1310 |
| 1304 constraint_factory_.basic().width.setIdeal(2000); | 1311 constraint_factory_.basic().width.setIdeal(2000); |
| 1305 constraint_factory_.basic().height.setIdeal(1500); | 1312 constraint_factory_.basic().height.setIdeal(1500); |
| 1306 result = SelectSettings(); | 1313 result = SelectSettings(); |
| 1307 EXPECT_TRUE(result.HasValue()); | 1314 EXPECT_TRUE(result.HasValue()); |
| 1308 // The closest configuration to the ideal resolution is the high-res device | 1315 // The high-res device at 640x480@10Hz is closer to the large ideal |
| 1309 // at the highest resolution. | 1316 // resolution. |
| 1310 EXPECT_EQ(high_res_device_->device_id, result.device_id); | 1317 EXPECT_EQ(high_res_device_->device_id, result.device_id); |
| 1311 EXPECT_EQ(*high_res_highest_format_, result.Format()); | 1318 EXPECT_EQ(640, result.Width()); |
| 1319 EXPECT_EQ(480, result.Height()); | |
| 1312 } | 1320 } |
| 1313 | 1321 |
| 1314 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, | 1322 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, |
| 1315 AdvancedResolutionAndFrameRate) { | 1323 AdvancedResolutionAndFrameRate) { |
| 1316 constraint_factory_.Reset(); | 1324 constraint_factory_.Reset(); |
| 1317 blink::WebMediaTrackConstraintSet& advanced1 = | 1325 blink::WebMediaTrackConstraintSet& advanced1 = |
| 1318 constraint_factory_.AddAdvanced(); | 1326 constraint_factory_.AddAdvanced(); |
| 1319 advanced1.width.setExact(1920); | 1327 advanced1.width.setExact(1920); |
| 1320 advanced1.height.setExact(1080); | 1328 advanced1.height.setExact(1080); |
| 1321 blink::WebMediaTrackConstraintSet& advanced2 = | 1329 blink::WebMediaTrackConstraintSet& advanced2 = |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 1334 EXPECT_EQ(high_res_device_->device_id, result.device_id); | 1342 EXPECT_EQ(high_res_device_->device_id, result.device_id); |
| 1335 EXPECT_EQ(1920, result.Width()); | 1343 EXPECT_EQ(1920, result.Width()); |
| 1336 EXPECT_EQ(1080, result.Height()); | 1344 EXPECT_EQ(1080, result.Height()); |
| 1337 EXPECT_EQ(60.0, result.FrameRate()); | 1345 EXPECT_EQ(60.0, result.FrameRate()); |
| 1338 } | 1346 } |
| 1339 | 1347 |
| 1340 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, AdvancedNoiseReduction) { | 1348 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, AdvancedNoiseReduction) { |
| 1341 constraint_factory_.Reset(); | 1349 constraint_factory_.Reset(); |
| 1342 blink::WebMediaTrackConstraintSet& advanced1 = | 1350 blink::WebMediaTrackConstraintSet& advanced1 = |
| 1343 constraint_factory_.AddAdvanced(); | 1351 constraint_factory_.AddAdvanced(); |
| 1344 advanced1.width.setExact(640); | 1352 advanced1.width.setMin(640); |
| 1345 advanced1.height.setExact(480); | 1353 advanced1.height.setMin(480); |
| 1346 blink::WebMediaTrackConstraintSet& advanced2 = | 1354 blink::WebMediaTrackConstraintSet& advanced2 = |
| 1347 constraint_factory_.AddAdvanced(); | 1355 constraint_factory_.AddAdvanced(); |
| 1348 advanced2.width.setExact(1920); | 1356 advanced2.width.setMin(1920); |
| 1349 advanced2.height.setExact(1080); | 1357 advanced2.height.setMin(1080); |
| 1350 advanced2.googNoiseReduction.setExact(false); | 1358 advanced2.googNoiseReduction.setExact(false); |
| 1351 auto result = SelectSettings(); | 1359 auto result = SelectSettings(); |
| 1352 EXPECT_TRUE(result.HasValue()); | 1360 EXPECT_TRUE(result.HasValue()); |
| 1353 EXPECT_EQ(high_res_device_->device_id, result.device_id); | 1361 EXPECT_EQ(high_res_device_->device_id, result.device_id); |
| 1354 EXPECT_EQ(1920, result.Width()); | 1362 EXPECT_LE(1920, result.Width()); |
| 1355 EXPECT_EQ(1080, result.Height()); | 1363 EXPECT_LE(1080, result.Height()); |
| 1356 EXPECT_TRUE(result.noise_reduction && !*result.noise_reduction); | 1364 EXPECT_TRUE(result.noise_reduction && !*result.noise_reduction); |
| 1357 } | 1365 } |
| 1358 | 1366 |
| 1359 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, | 1367 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, |
| 1360 AdvancedContradictoryNoiseReduction) { | 1368 AdvancedContradictoryNoiseReduction) { |
| 1361 { | 1369 { |
| 1362 constraint_factory_.Reset(); | 1370 constraint_factory_.Reset(); |
| 1363 blink::WebMediaTrackConstraintSet& advanced1 = | 1371 blink::WebMediaTrackConstraintSet& advanced1 = |
| 1364 constraint_factory_.AddAdvanced(); | 1372 constraint_factory_.AddAdvanced(); |
| 1365 advanced1.width.setMin(640); | 1373 advanced1.width.setMin(640); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 1396 EXPECT_TRUE(result.HasValue()); | 1404 EXPECT_TRUE(result.HasValue()); |
| 1397 // Only the high-res device can satisfy the second advanced set. | 1405 // Only the high-res device can satisfy the second advanced set. |
| 1398 EXPECT_EQ(high_res_device_->device_id, result.device_id); | 1406 EXPECT_EQ(high_res_device_->device_id, result.device_id); |
| 1399 EXPECT_LE(1920, result.Width()); | 1407 EXPECT_LE(1920, result.Width()); |
| 1400 EXPECT_LE(1080, result.Height()); | 1408 EXPECT_LE(1080, result.Height()); |
| 1401 // Should select default noise reduction setting. | 1409 // Should select default noise reduction setting. |
| 1402 EXPECT_TRUE(!result.noise_reduction); | 1410 EXPECT_TRUE(!result.noise_reduction); |
| 1403 } | 1411 } |
| 1404 } | 1412 } |
| 1405 | 1413 |
| 1414 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, | |
| 1415 AdvancedContradictoryExactResolution) { | |
| 1416 constraint_factory_.Reset(); | |
| 1417 blink::WebMediaTrackConstraintSet& advanced1 = | |
| 1418 constraint_factory_.AddAdvanced(); | |
| 1419 advanced1.width.setExact(640); | |
| 1420 advanced1.height.setExact(480); | |
| 1421 blink::WebMediaTrackConstraintSet& advanced2 = | |
| 1422 constraint_factory_.AddAdvanced(); | |
| 1423 advanced2.width.setExact(1920); | |
| 1424 advanced2.height.setExact(1080); | |
| 1425 auto result = SelectSettings(); | |
| 1426 EXPECT_TRUE(result.HasValue()); | |
| 1427 // The second advanced set must be ignored because it contradicts the first | |
| 1428 // set. The low-res device is the one that best supports the requested | |
| 1429 // resolution. | |
| 1430 EXPECT_EQ(low_res_device_->device_id, result.device_id); | |
| 1431 EXPECT_EQ(640, result.Width()); | |
| 1432 EXPECT_EQ(480, result.Height()); | |
| 1433 } | |
| 1434 | |
| 1435 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, | |
| 1436 AdvancedContradictoryResolutionRange) { | |
| 1437 constraint_factory_.Reset(); | |
| 1438 blink::WebMediaTrackConstraintSet& advanced1 = | |
| 1439 constraint_factory_.AddAdvanced(); | |
| 1440 advanced1.width.setMax(640); | |
| 1441 advanced1.height.setMax(480); | |
| 1442 blink::WebMediaTrackConstraintSet& advanced2 = | |
| 1443 constraint_factory_.AddAdvanced(); | |
| 1444 advanced2.width.setMin(1920); | |
| 1445 advanced2.height.setMin(1080); | |
| 1446 auto result = SelectSettings(); | |
| 1447 EXPECT_TRUE(result.HasValue()); | |
| 1448 // The second advanced set must be ignored because it contradicts the first | |
| 1449 // set. | |
| 1450 EXPECT_EQ(default_device_->device_id, result.device_id); | |
| 1451 EXPECT_GE(640, result.Width()); | |
| 1452 EXPECT_GE(480, result.Height()); | |
| 1453 } | |
| 1454 | |
| 1455 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, | |
| 1456 AdvancedContradictoryExactAspectRatio) { | |
| 1457 constraint_factory_.Reset(); | |
| 1458 blink::WebMediaTrackConstraintSet& advanced1 = | |
| 1459 constraint_factory_.AddAdvanced(); | |
| 1460 advanced1.aspectRatio.setExact(2300.0); | |
| 1461 blink::WebMediaTrackConstraintSet& advanced2 = | |
| 1462 constraint_factory_.AddAdvanced(); | |
| 1463 advanced2.aspectRatio.setExact(3.0); | |
| 1464 auto result = SelectSettings(); | |
| 1465 EXPECT_TRUE(result.HasValue()); | |
| 1466 // The second advanced set must be ignored because it contradicts the first | |
| 1467 // set. Only the high-res device in the highest-resolution format supports the | |
| 1468 // requested aspect ratio. | |
| 1469 EXPECT_EQ(high_res_device_->device_id, result.device_id); | |
| 1470 EXPECT_EQ(*high_res_highest_format_, result.Format()); | |
| 1471 } | |
| 1472 | |
| 1473 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, | |
| 1474 AdvancedContradictoryAspectRatioRange) { | |
| 1475 constraint_factory_.Reset(); | |
| 1476 blink::WebMediaTrackConstraintSet& advanced1 = | |
| 1477 constraint_factory_.AddAdvanced(); | |
| 1478 advanced1.aspectRatio.setMin(2300.0); | |
| 1479 blink::WebMediaTrackConstraintSet& advanced2 = | |
| 1480 constraint_factory_.AddAdvanced(); | |
| 1481 advanced2.aspectRatio.setMax(3.0); | |
| 1482 auto result = SelectSettings(); | |
| 1483 EXPECT_TRUE(result.HasValue()); | |
| 1484 // The second advanced set must be ignored because it contradicts the first | |
| 1485 // set. Only the high-res device in the highest-resolution format supports the | |
| 1486 // requested aspect ratio. | |
| 1487 EXPECT_EQ(high_res_device_->device_id, result.device_id); | |
| 1488 EXPECT_EQ(*high_res_highest_format_, result.Format()); | |
| 1489 } | |
| 1490 | |
| 1491 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, | |
| 1492 AdvancedContradictoryExactFrameRate) { | |
| 1493 constraint_factory_.Reset(); | |
| 1494 blink::WebMediaTrackConstraintSet& advanced1 = | |
| 1495 constraint_factory_.AddAdvanced(); | |
| 1496 advanced1.frameRate.setExact(40.0); | |
| 1497 blink::WebMediaTrackConstraintSet& advanced2 = | |
| 1498 constraint_factory_.AddAdvanced(); | |
| 1499 advanced2.frameRate.setExact(45.0); | |
| 1500 auto result = SelectSettings(); | |
| 1501 EXPECT_TRUE(result.HasValue()); | |
| 1502 // The second advanced set must be ignored because it contradicts the first | |
| 1503 // set. | |
| 1504 EXPECT_EQ(40.0, result.FrameRate()); | |
| 1505 } | |
| 1506 | |
| 1507 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, | |
| 1508 AdvancedContradictoryFrameRateRange) { | |
| 1509 constraint_factory_.Reset(); | |
| 1510 blink::WebMediaTrackConstraintSet& advanced1 = | |
| 1511 constraint_factory_.AddAdvanced(); | |
| 1512 advanced1.frameRate.setMin(40.0); | |
| 1513 blink::WebMediaTrackConstraintSet& advanced2 = | |
| 1514 constraint_factory_.AddAdvanced(); | |
| 1515 advanced2.frameRate.setMax(35.0); | |
| 1516 auto result = SelectSettings(); | |
| 1517 EXPECT_TRUE(result.HasValue()); | |
| 1518 // The second advanced set must be ignored because it contradicts the first | |
| 1519 // set. | |
| 1520 EXPECT_LE(40.0, result.FrameRate()); | |
| 1521 } | |
| 1522 | |
| 1523 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, | |
| 1524 AdvancedContradictoryWidthFrameRate) { | |
| 1525 constraint_factory_.Reset(); | |
| 1526 blink::WebMediaTrackConstraintSet& advanced1 = | |
| 1527 constraint_factory_.AddAdvanced(); | |
| 1528 advanced1.width.setMax(1920); | |
| 1529 blink::WebMediaTrackConstraintSet& advanced2 = | |
| 1530 constraint_factory_.AddAdvanced(); | |
| 1531 advanced2.width.setMin(2000); | |
| 1532 advanced2.frameRate.setExact(10.0); | |
| 1533 blink::WebMediaTrackConstraintSet& advanced3 = | |
| 1534 constraint_factory_.AddAdvanced(); | |
| 1535 advanced3.frameRate.setExact(30.0); | |
| 1536 auto result = SelectSettings(); | |
| 1537 EXPECT_TRUE(result.HasValue()); | |
| 1538 // The low-res device at 320x240@30Hz satisfies advanced sets 1 and 3. | |
| 1539 // The high-res device at 2304x1536@10.0f can satisfy sets 1 and 2, but not | |
| 1540 // both at the same time. Thus, low-res device must be preferred. | |
| 1541 EXPECT_EQ(low_res_device_->device_id, result.device_id); | |
| 1542 EXPECT_EQ(30.0, result.FrameRate()); | |
| 1543 EXPECT_GE(1920, result.Width()); | |
| 1544 } | |
| 1545 | |
| 1546 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, | |
| 1547 AdvancedContradictoryHeightFrameRate) { | |
| 1548 constraint_factory_.Reset(); | |
| 1549 blink::WebMediaTrackConstraintSet& advanced1 = | |
| 1550 constraint_factory_.AddAdvanced(); | |
| 1551 advanced1.height.setMax(1080); | |
| 1552 blink::WebMediaTrackConstraintSet& advanced2 = | |
| 1553 constraint_factory_.AddAdvanced(); | |
| 1554 advanced2.height.setMin(1500); | |
| 1555 advanced2.frameRate.setExact(10.0); | |
| 1556 blink::WebMediaTrackConstraintSet& advanced3 = | |
| 1557 constraint_factory_.AddAdvanced(); | |
| 1558 advanced3.frameRate.setExact(60.0); | |
| 1559 auto result = SelectSettings(); | |
| 1560 EXPECT_TRUE(result.HasValue()); | |
| 1561 // The high-res device at 1280x768@60Hz and 1920x1080@60Hz satisfies advanced | |
| 1562 // sets 1 and 3. The same device at 2304x1536@10.0f can satisfy sets 1 and 2, | |
| 1563 // but not both at the same time. Thus, the format closest to default that | |
| 1564 // satisfies sets 1 and 3 must be chosen. | |
| 1565 EXPECT_EQ(high_res_device_->device_id, result.device_id); | |
| 1566 EXPECT_EQ(60.0, result.FrameRate()); | |
| 1567 EXPECT_GE(1080, result.Height()); | |
| 1568 } | |
| 1569 | |
| 1570 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, AdvancedDeviceID) { | |
| 1571 constraint_factory_.Reset(); | |
| 1572 blink::WebMediaTrackConstraintSet& advanced1 = | |
| 1573 constraint_factory_.AddAdvanced(); | |
| 1574 blink::WebString id_vector1[] = {blink::WebString::fromASCII(kDeviceID1), | |
| 1575 blink::WebString::fromASCII(kDeviceID2)}; | |
| 1576 advanced1.deviceId.setExact( | |
| 1577 blink::WebVector<blink::WebString>(id_vector1, arraysize(id_vector1))); | |
| 1578 blink::WebString id_vector2[] = {blink::WebString::fromASCII(kDeviceID2), | |
| 1579 blink::WebString::fromASCII(kDeviceID3)}; | |
| 1580 blink::WebMediaTrackConstraintSet& advanced2 = | |
| 1581 constraint_factory_.AddAdvanced(); | |
| 1582 advanced2.deviceId.setExact( | |
| 1583 blink::WebVector<blink::WebString>(id_vector2, arraysize(id_vector2))); | |
| 1584 auto result = SelectSettings(); | |
| 1585 EXPECT_TRUE(result.HasValue()); | |
| 1586 // kDeviceID2 must be selected because it is the only one that satisfies both | |
| 1587 // advanced sets. | |
| 1588 EXPECT_EQ(std::string(kDeviceID2), result.device_id); | |
| 1589 } | |
| 1590 | |
| 1591 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, | |
| 1592 AdvancedContradictoryDeviceID) { | |
| 1593 constraint_factory_.Reset(); | |
| 1594 blink::WebMediaTrackConstraintSet& advanced1 = | |
| 1595 constraint_factory_.AddAdvanced(); | |
| 1596 blink::WebString id_vector1[] = {blink::WebString::fromASCII(kDeviceID1), | |
| 1597 blink::WebString::fromASCII(kDeviceID2)}; | |
| 1598 advanced1.deviceId.setExact( | |
| 1599 blink::WebVector<blink::WebString>(id_vector1, arraysize(id_vector1))); | |
| 1600 blink::WebString id_vector2[] = {blink::WebString::fromASCII(kDeviceID3), | |
| 1601 blink::WebString::fromASCII(kDeviceID4)}; | |
| 1602 blink::WebMediaTrackConstraintSet& advanced2 = | |
| 1603 constraint_factory_.AddAdvanced(); | |
| 1604 advanced2.deviceId.setExact( | |
| 1605 blink::WebVector<blink::WebString>(id_vector2, arraysize(id_vector2))); | |
| 1606 auto result = SelectSettings(); | |
| 1607 EXPECT_TRUE(result.HasValue()); | |
| 1608 // The second advanced set must be ignored because it contradicts the first | |
| 1609 // set. | |
| 1610 EXPECT_EQ(std::string(kDeviceID1), result.device_id); | |
| 1611 } | |
| 1612 | |
| 1613 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, | |
| 1614 AdvancedContradictoryPowerLineFrequency) { | |
| 1615 { | |
| 1616 constraint_factory_.Reset(); | |
| 1617 blink::WebMediaTrackConstraintSet& advanced1 = | |
| 1618 constraint_factory_.AddAdvanced(); | |
| 1619 advanced1.width.setMin(640); | |
| 1620 advanced1.height.setMin(480); | |
| 1621 advanced1.googPowerLineFrequency.setExact(50); | |
| 1622 blink::WebMediaTrackConstraintSet& advanced2 = | |
| 1623 constraint_factory_.AddAdvanced(); | |
| 1624 advanced2.width.setMin(1920); | |
| 1625 advanced2.height.setMin(1080); | |
| 1626 advanced2.googPowerLineFrequency.setExact(60); | |
| 1627 auto result = SelectSettings(); | |
| 1628 EXPECT_TRUE(result.HasValue()); | |
| 1629 // The second advanced set cannot be satisfied because it contradicts the | |
| 1630 // first set. The default device supports the first set and should be | |
| 1631 // selected. | |
| 1632 EXPECT_EQ(default_device_->device_id, result.device_id); | |
| 1633 EXPECT_LE(640, result.Width()); | |
| 1634 EXPECT_LE(480, result.Height()); | |
| 1635 EXPECT_EQ(50, static_cast<int>(result.PowerLineFrequency())); | |
| 1636 } | |
| 1637 } | |
| 1638 | |
| 1406 // The "NoDevices" tests verify that the algorithm returns the expected result | 1639 // The "NoDevices" tests verify that the algorithm returns the expected result |
| 1407 // when there are no candidates to choose from. | 1640 // when there are no candidates to choose from. |
| 1408 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, NoDevicesNoConstraints) { | 1641 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, NoDevicesNoConstraints) { |
| 1409 constraint_factory_.Reset(); | 1642 constraint_factory_.Reset(); |
| 1410 VideoDeviceCaptureCapabilities capabilities; | 1643 VideoDeviceCaptureCapabilities capabilities; |
| 1411 auto result = SelectVideoDeviceCaptureSourceSettings( | 1644 auto result = SelectVideoDeviceCaptureSourceSettings( |
| 1412 capabilities, constraint_factory_.CreateWebMediaConstraints()); | 1645 capabilities, constraint_factory_.CreateWebMediaConstraints()); |
| 1413 EXPECT_FALSE(result.HasValue()); | 1646 EXPECT_FALSE(result.HasValue()); |
| 1414 EXPECT_TRUE(std::string(result.failed_constraint_name).empty()); | 1647 EXPECT_TRUE(std::string(result.failed_constraint_name).empty()); |
| 1415 } | 1648 } |
| 1416 | 1649 |
| 1417 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, NoDevicesWithConstraints) { | 1650 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, NoDevicesWithConstraints) { |
| 1418 constraint_factory_.Reset(); | 1651 constraint_factory_.Reset(); |
| 1419 constraint_factory_.basic().height.setExact(100); | 1652 constraint_factory_.basic().height.setExact(100); |
| 1420 VideoDeviceCaptureCapabilities capabilities; | 1653 VideoDeviceCaptureCapabilities capabilities; |
| 1421 auto result = SelectVideoDeviceCaptureSourceSettings( | 1654 auto result = SelectVideoDeviceCaptureSourceSettings( |
| 1422 capabilities, constraint_factory_.CreateWebMediaConstraints()); | 1655 capabilities, constraint_factory_.CreateWebMediaConstraints()); |
| 1423 EXPECT_FALSE(result.HasValue()); | 1656 EXPECT_FALSE(result.HasValue()); |
| 1424 EXPECT_TRUE(std::string(result.failed_constraint_name).empty()); | 1657 EXPECT_TRUE(std::string(result.failed_constraint_name).empty()); |
| 1425 } | 1658 } |
| 1426 | 1659 |
| 1427 } // namespace content | 1660 } // namespace content |
| OLD | NEW |