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 1226 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, AdvancedExactResolution) { |
hbos_chromium
2017/02/28 11:41:54
This name no longer matches what the test is doing
| |
1248 constraint_factory_.Reset(); | 1248 constraint_factory_.Reset(); |
1249 blink::WebMediaTrackConstraintSet& advanced1 = | 1249 blink::WebMediaTrackConstraintSet& advanced1 = |
1250 constraint_factory_.AddAdvanced(); | 1250 constraint_factory_.AddAdvanced(); |
1251 advanced1.width.setExact(4000); | 1251 advanced1.width.setMin(4000); |
1252 advanced1.height.setExact(4000); | 1252 advanced1.height.setMin(4000); |
1253 blink::WebMediaTrackConstraintSet& advanced2 = | 1253 blink::WebMediaTrackConstraintSet& advanced2 = |
1254 constraint_factory_.AddAdvanced(); | 1254 constraint_factory_.AddAdvanced(); |
1255 advanced2.width.setExact(3000); | 1255 advanced2.width.setMin(3000); |
1256 advanced2.height.setExact(3000); | 1256 advanced2.height.setMin(3000); |
1257 auto result = SelectSettings(); | 1257 auto result = SelectSettings(); |
1258 // No device supports the advanced constraint sets. | 1258 // No device supports the advanced constraint sets. |
1259 // Tie-breaker rule that applies is closeness to default settings. | 1259 // Tie-breaker rule that applies is closeness to default settings. |
hbos_chromium
2017/02/28 11:41:54
adv1 is superflous given adv2.
What about...?
adv
Guido Urdaneta
2017/02/28 16:44:00
Replaced with a test where each advanced set cause
| |
1260 EXPECT_EQ(default_device_->device_id, result.device_id); | 1260 EXPECT_EQ(default_device_->device_id, result.device_id); |
1261 EXPECT_EQ(*default_closest_format_, result.Format()); | 1261 EXPECT_EQ(*default_closest_format_, result.Format()); |
1262 | 1262 |
1263 blink::WebMediaTrackConstraintSet& advanced3 = | 1263 blink::WebMediaTrackConstraintSet& advanced3 = |
1264 constraint_factory_.AddAdvanced(); | 1264 constraint_factory_.AddAdvanced(); |
1265 advanced3.width.setExact(1920); | 1265 advanced3.width.setMin(1920); |
1266 advanced3.height.setExact(1080); | 1266 advanced3.height.setMin(1080); |
1267 result = SelectSettings(); | 1267 result = SelectSettings(); |
1268 EXPECT_TRUE(result.HasValue()); | 1268 EXPECT_TRUE(result.HasValue()); |
1269 // The high-res device natively supports the third advanced constraint set | 1269 // The high-res device natively supports the third advanced constraint set |
1270 // and should be selected. | 1270 // and should be selected. |
1271 // First tie-breaker rule that applies is support for advanced constraints | 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 | 1272 // that appear first. Second tie-breaker rule is custom distance to advanced |
1273 // constraint sets that appear first. | 1273 // constraint sets that appear first. |
1274 EXPECT_EQ(high_res_device_->device_id, result.device_id); | 1274 EXPECT_EQ(high_res_device_->device_id, result.device_id); |
1275 EXPECT_EQ(1920, result.Width()); | 1275 EXPECT_EQ(1920, result.Width()); |
1276 EXPECT_EQ(1080, result.Height()); | 1276 EXPECT_EQ(1080, result.Height()); |
1277 | 1277 |
1278 blink::WebMediaTrackConstraintSet& advanced4 = | 1278 blink::WebMediaTrackConstraintSet& advanced4 = |
1279 constraint_factory_.AddAdvanced(); | 1279 constraint_factory_.AddAdvanced(); |
1280 advanced4.width.setExact(640); | 1280 advanced4.width.setMin(640); |
1281 advanced4.height.setExact(480); | 1281 advanced4.height.setMin(480); |
1282 result = SelectSettings(); | 1282 result = SelectSettings(); |
1283 EXPECT_TRUE(result.HasValue()); | 1283 EXPECT_TRUE(result.HasValue()); |
1284 // First tie-breaker rule that applies is support for advanced constraints | 1284 // First tie-breaker rule that applies is support for advanced constraints |
1285 // that appear first, which leaves out configurations that only support the | 1285 // that appear first, which leaves out configurations that only support the |
1286 // fourth advanced constraint set in favor of configurations that support | 1286 // fourth advanced constraint set in favor of configurations that support |
1287 // the third set. | 1287 // the third set. |
1288 // Second tie-breaker rule is custom distance to advanced constraint sets | 1288 // Second tie-breaker rule is custom distance to advanced constraint sets |
1289 // that appear first. | 1289 // that appear first. |
1290 EXPECT_EQ(high_res_device_->device_id, result.device_id); | 1290 EXPECT_EQ(high_res_device_->device_id, result.device_id); |
1291 EXPECT_EQ(1920, result.Width()); | 1291 EXPECT_EQ(1920, result.Width()); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1334 EXPECT_EQ(high_res_device_->device_id, result.device_id); | 1334 EXPECT_EQ(high_res_device_->device_id, result.device_id); |
1335 EXPECT_EQ(1920, result.Width()); | 1335 EXPECT_EQ(1920, result.Width()); |
1336 EXPECT_EQ(1080, result.Height()); | 1336 EXPECT_EQ(1080, result.Height()); |
1337 EXPECT_EQ(60.0, result.FrameRate()); | 1337 EXPECT_EQ(60.0, result.FrameRate()); |
1338 } | 1338 } |
1339 | 1339 |
1340 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, AdvancedNoiseReduction) { | 1340 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, AdvancedNoiseReduction) { |
1341 constraint_factory_.Reset(); | 1341 constraint_factory_.Reset(); |
1342 blink::WebMediaTrackConstraintSet& advanced1 = | 1342 blink::WebMediaTrackConstraintSet& advanced1 = |
1343 constraint_factory_.AddAdvanced(); | 1343 constraint_factory_.AddAdvanced(); |
1344 advanced1.width.setExact(640); | 1344 advanced1.width.setMin(640); |
1345 advanced1.height.setExact(480); | 1345 advanced1.height.setMin(480); |
1346 blink::WebMediaTrackConstraintSet& advanced2 = | 1346 blink::WebMediaTrackConstraintSet& advanced2 = |
1347 constraint_factory_.AddAdvanced(); | 1347 constraint_factory_.AddAdvanced(); |
1348 advanced2.width.setExact(1920); | 1348 advanced2.width.setMin(1920); |
1349 advanced2.height.setExact(1080); | 1349 advanced2.height.setMin(1080); |
1350 advanced2.googNoiseReduction.setExact(false); | 1350 advanced2.googNoiseReduction.setExact(false); |
1351 auto result = SelectSettings(); | 1351 auto result = SelectSettings(); |
1352 EXPECT_TRUE(result.HasValue()); | 1352 EXPECT_TRUE(result.HasValue()); |
1353 EXPECT_EQ(high_res_device_->device_id, result.device_id); | 1353 EXPECT_EQ(high_res_device_->device_id, result.device_id); |
1354 EXPECT_EQ(1920, result.Width()); | 1354 EXPECT_LE(1920, result.Width()); |
1355 EXPECT_EQ(1080, result.Height()); | 1355 EXPECT_LE(1080, result.Height()); |
1356 EXPECT_TRUE(result.noise_reduction && !*result.noise_reduction); | 1356 EXPECT_TRUE(result.noise_reduction && !*result.noise_reduction); |
1357 } | 1357 } |
1358 | 1358 |
1359 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, | 1359 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, |
1360 AdvancedContradictoryNoiseReduction) { | 1360 AdvancedContradictoryNoiseReduction) { |
1361 { | 1361 { |
1362 constraint_factory_.Reset(); | 1362 constraint_factory_.Reset(); |
1363 blink::WebMediaTrackConstraintSet& advanced1 = | 1363 blink::WebMediaTrackConstraintSet& advanced1 = |
1364 constraint_factory_.AddAdvanced(); | 1364 constraint_factory_.AddAdvanced(); |
1365 advanced1.width.setMin(640); | 1365 advanced1.width.setMin(640); |
(...skipping 30 matching lines...) Expand all Loading... | |
1396 EXPECT_TRUE(result.HasValue()); | 1396 EXPECT_TRUE(result.HasValue()); |
1397 // Only the high-res device can satisfy the second advanced set. | 1397 // Only the high-res device can satisfy the second advanced set. |
1398 EXPECT_EQ(high_res_device_->device_id, result.device_id); | 1398 EXPECT_EQ(high_res_device_->device_id, result.device_id); |
1399 EXPECT_LE(1920, result.Width()); | 1399 EXPECT_LE(1920, result.Width()); |
1400 EXPECT_LE(1080, result.Height()); | 1400 EXPECT_LE(1080, result.Height()); |
1401 // Should select default noise reduction setting. | 1401 // Should select default noise reduction setting. |
1402 EXPECT_TRUE(!result.noise_reduction); | 1402 EXPECT_TRUE(!result.noise_reduction); |
1403 } | 1403 } |
1404 } | 1404 } |
1405 | 1405 |
1406 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, | |
1407 AdvancedContradictoryExactResolution) { | |
1408 constraint_factory_.Reset(); | |
1409 blink::WebMediaTrackConstraintSet& advanced1 = | |
1410 constraint_factory_.AddAdvanced(); | |
1411 advanced1.width.setExact(640); | |
1412 advanced1.height.setExact(480); | |
1413 blink::WebMediaTrackConstraintSet& advanced2 = | |
1414 constraint_factory_.AddAdvanced(); | |
1415 advanced2.width.setExact(1920); | |
1416 advanced2.height.setExact(1080); | |
1417 auto result = SelectSettings(); | |
1418 EXPECT_TRUE(result.HasValue()); | |
1419 // The second advanced set must be ignored because it contradicts the first | |
1420 // set. The low-res device is the one that best supports the requested | |
1421 // resolution. | |
1422 EXPECT_EQ(low_res_device_->device_id, result.device_id); | |
1423 EXPECT_EQ(640, result.Width()); | |
1424 EXPECT_EQ(480, result.Height()); | |
hbos_chromium
2017/02/28 11:41:54
These tests are all good, but we want if possible
Guido Urdaneta
2017/02/28 16:44:00
Added tests similar to the proposed ones with widt
| |
1425 } | |
1426 | |
1427 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, | |
1428 AdvancedContradictoryResolutionRange) { | |
1429 constraint_factory_.Reset(); | |
1430 blink::WebMediaTrackConstraintSet& advanced1 = | |
1431 constraint_factory_.AddAdvanced(); | |
1432 advanced1.width.setMax(640); | |
1433 advanced1.height.setMax(480); | |
1434 blink::WebMediaTrackConstraintSet& advanced2 = | |
1435 constraint_factory_.AddAdvanced(); | |
1436 advanced2.width.setMin(1920); | |
1437 advanced2.height.setMin(1080); | |
1438 auto result = SelectSettings(); | |
1439 EXPECT_TRUE(result.HasValue()); | |
1440 // The second advanced set must be ignored because it contradicts the first | |
1441 // set. | |
1442 EXPECT_EQ(default_device_->device_id, result.device_id); | |
1443 EXPECT_GE(640, result.Width()); | |
1444 EXPECT_GE(480, result.Height()); | |
1445 } | |
1446 | |
1447 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, | |
1448 AdvancedContradictoryExactAspectRatio) { | |
1449 constraint_factory_.Reset(); | |
1450 blink::WebMediaTrackConstraintSet& advanced1 = | |
1451 constraint_factory_.AddAdvanced(); | |
1452 advanced1.aspectRatio.setExact(2300.0); | |
1453 blink::WebMediaTrackConstraintSet& advanced2 = | |
1454 constraint_factory_.AddAdvanced(); | |
1455 advanced2.aspectRatio.setExact(3.0); | |
1456 auto result = SelectSettings(); | |
1457 EXPECT_TRUE(result.HasValue()); | |
1458 // The second advanced set must be ignored because it contradicts the first | |
1459 // set. Only the high-res device in the highest-resolution format supports the | |
1460 // requested aspect ratio. | |
1461 EXPECT_EQ(high_res_device_->device_id, result.device_id); | |
1462 EXPECT_EQ(*high_res_highest_format_, result.Format()); | |
1463 } | |
1464 | |
1465 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, | |
1466 AdvancedContradictoryAspectRatioRange) { | |
1467 constraint_factory_.Reset(); | |
1468 blink::WebMediaTrackConstraintSet& advanced1 = | |
1469 constraint_factory_.AddAdvanced(); | |
1470 advanced1.aspectRatio.setMin(2300.0); | |
1471 blink::WebMediaTrackConstraintSet& advanced2 = | |
1472 constraint_factory_.AddAdvanced(); | |
1473 advanced2.aspectRatio.setMax(3.0); | |
1474 auto result = SelectSettings(); | |
1475 EXPECT_TRUE(result.HasValue()); | |
1476 // The second advanced set must be ignored because it contradicts the first | |
1477 // set. Only the high-res device in the highest-resolution format supports the | |
1478 // requested aspect ratio. | |
1479 EXPECT_EQ(high_res_device_->device_id, result.device_id); | |
1480 EXPECT_EQ(*high_res_highest_format_, result.Format()); | |
1481 } | |
1482 | |
1483 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, | |
1484 AdvancedContradictoryExactFrameRate) { | |
1485 constraint_factory_.Reset(); | |
1486 blink::WebMediaTrackConstraintSet& advanced1 = | |
1487 constraint_factory_.AddAdvanced(); | |
1488 advanced1.frameRate.setExact(40.0); | |
1489 blink::WebMediaTrackConstraintSet& advanced2 = | |
1490 constraint_factory_.AddAdvanced(); | |
1491 advanced2.frameRate.setExact(45.0); | |
1492 auto result = SelectSettings(); | |
1493 EXPECT_TRUE(result.HasValue()); | |
1494 // The second advanced set must be ignored because it contradicts the first | |
1495 // set. | |
1496 EXPECT_EQ(40.0, result.FrameRate()); | |
1497 } | |
1498 | |
1499 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, | |
1500 AdvancedContradictoryFrameRateRange) { | |
1501 constraint_factory_.Reset(); | |
1502 blink::WebMediaTrackConstraintSet& advanced1 = | |
1503 constraint_factory_.AddAdvanced(); | |
1504 advanced1.frameRate.setMin(40.0); | |
1505 blink::WebMediaTrackConstraintSet& advanced2 = | |
1506 constraint_factory_.AddAdvanced(); | |
1507 advanced2.frameRate.setMax(35.0); | |
1508 auto result = SelectSettings(); | |
1509 EXPECT_TRUE(result.HasValue()); | |
1510 // The second advanced set must be ignored because it contradicts the first | |
1511 // set. | |
1512 EXPECT_LE(40.0, result.FrameRate()); | |
1513 } | |
1514 | |
1515 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, AdvancedDeviceID) { | |
1516 constraint_factory_.Reset(); | |
1517 blink::WebMediaTrackConstraintSet& advanced1 = | |
1518 constraint_factory_.AddAdvanced(); | |
1519 blink::WebString id_vector1[] = {blink::WebString::fromASCII(kDeviceID1), | |
1520 blink::WebString::fromASCII(kDeviceID2)}; | |
1521 advanced1.deviceId.setExact( | |
1522 blink::WebVector<blink::WebString>(id_vector1, arraysize(id_vector1))); | |
1523 blink::WebString id_vector2[] = {blink::WebString::fromASCII(kDeviceID2), | |
1524 blink::WebString::fromASCII(kDeviceID3)}; | |
1525 blink::WebMediaTrackConstraintSet& advanced2 = | |
1526 constraint_factory_.AddAdvanced(); | |
1527 advanced2.deviceId.setExact( | |
1528 blink::WebVector<blink::WebString>(id_vector2, arraysize(id_vector2))); | |
1529 auto result = SelectSettings(); | |
1530 EXPECT_TRUE(result.HasValue()); | |
1531 // kDeviceID2 must be selected because it is the only one that satisfies both | |
1532 // advanced sets. | |
1533 EXPECT_EQ(std::string(kDeviceID2), result.device_id); | |
1534 } | |
1535 | |
1536 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, | |
1537 AdvancedContradictoryDeviceID) { | |
1538 constraint_factory_.Reset(); | |
1539 blink::WebMediaTrackConstraintSet& advanced1 = | |
1540 constraint_factory_.AddAdvanced(); | |
1541 blink::WebString id_vector1[] = {blink::WebString::fromASCII(kDeviceID1), | |
1542 blink::WebString::fromASCII(kDeviceID2)}; | |
1543 advanced1.deviceId.setExact( | |
1544 blink::WebVector<blink::WebString>(id_vector1, arraysize(id_vector1))); | |
1545 blink::WebString id_vector2[] = {blink::WebString::fromASCII(kDeviceID3), | |
1546 blink::WebString::fromASCII(kDeviceID4)}; | |
1547 blink::WebMediaTrackConstraintSet& advanced2 = | |
1548 constraint_factory_.AddAdvanced(); | |
1549 advanced2.deviceId.setExact( | |
1550 blink::WebVector<blink::WebString>(id_vector2, arraysize(id_vector2))); | |
1551 auto result = SelectSettings(); | |
1552 EXPECT_TRUE(result.HasValue()); | |
1553 // The second advanced set must be ignored because it contradicts the first | |
1554 // set. | |
1555 EXPECT_EQ(std::string(kDeviceID1), result.device_id); | |
1556 } | |
1557 | |
1558 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, | |
1559 AdvancedContradictoryPowerLineFrequency) { | |
1560 { | |
1561 constraint_factory_.Reset(); | |
1562 blink::WebMediaTrackConstraintSet& advanced1 = | |
1563 constraint_factory_.AddAdvanced(); | |
1564 advanced1.width.setMin(640); | |
1565 advanced1.height.setMin(480); | |
1566 advanced1.googPowerLineFrequency.setExact(50); | |
1567 blink::WebMediaTrackConstraintSet& advanced2 = | |
1568 constraint_factory_.AddAdvanced(); | |
1569 advanced2.width.setMin(1920); | |
1570 advanced2.height.setMin(1080); | |
1571 advanced2.googPowerLineFrequency.setExact(60); | |
1572 auto result = SelectSettings(); | |
1573 EXPECT_TRUE(result.HasValue()); | |
1574 // The second advanced set cannot be satisfied because it contradicts the | |
1575 // first set. The default device supports the first set and should be | |
1576 // selected. | |
1577 EXPECT_EQ(default_device_->device_id, result.device_id); | |
1578 EXPECT_LE(640, result.Width()); | |
1579 EXPECT_LE(480, result.Height()); | |
1580 EXPECT_EQ(50, static_cast<int>(result.PowerLineFrequency())); | |
1581 } | |
1582 } | |
1583 | |
1406 // The "NoDevices" tests verify that the algorithm returns the expected result | 1584 // The "NoDevices" tests verify that the algorithm returns the expected result |
1407 // when there are no candidates to choose from. | 1585 // when there are no candidates to choose from. |
1408 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, NoDevicesNoConstraints) { | 1586 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, NoDevicesNoConstraints) { |
1409 constraint_factory_.Reset(); | 1587 constraint_factory_.Reset(); |
1410 VideoDeviceCaptureCapabilities capabilities; | 1588 VideoDeviceCaptureCapabilities capabilities; |
1411 auto result = SelectVideoDeviceCaptureSourceSettings( | 1589 auto result = SelectVideoDeviceCaptureSourceSettings( |
1412 capabilities, constraint_factory_.CreateWebMediaConstraints()); | 1590 capabilities, constraint_factory_.CreateWebMediaConstraints()); |
1413 EXPECT_FALSE(result.HasValue()); | 1591 EXPECT_FALSE(result.HasValue()); |
1414 EXPECT_TRUE(std::string(result.failed_constraint_name).empty()); | 1592 EXPECT_TRUE(std::string(result.failed_constraint_name).empty()); |
1415 } | 1593 } |
1416 | 1594 |
1417 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, NoDevicesWithConstraints) { | 1595 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, NoDevicesWithConstraints) { |
1418 constraint_factory_.Reset(); | 1596 constraint_factory_.Reset(); |
1419 constraint_factory_.basic().height.setExact(100); | 1597 constraint_factory_.basic().height.setExact(100); |
1420 VideoDeviceCaptureCapabilities capabilities; | 1598 VideoDeviceCaptureCapabilities capabilities; |
1421 auto result = SelectVideoDeviceCaptureSourceSettings( | 1599 auto result = SelectVideoDeviceCaptureSourceSettings( |
1422 capabilities, constraint_factory_.CreateWebMediaConstraints()); | 1600 capabilities, constraint_factory_.CreateWebMediaConstraints()); |
1423 EXPECT_FALSE(result.HasValue()); | 1601 EXPECT_FALSE(result.HasValue()); |
1424 EXPECT_TRUE(std::string(result.failed_constraint_name).empty()); | 1602 EXPECT_TRUE(std::string(result.failed_constraint_name).empty()); |
1425 } | 1603 } |
1426 | 1604 |
1427 } // namespace content | 1605 } // namespace content |
OLD | NEW |