Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(198)

Side by Side Diff: content/renderer/media/media_stream_constraints_util_video_device_unittest.cc

Issue 2719153002: Patch constraints algorithm for device video-capture sources. (Closed)
Patch Set: improve comments based on hta's suggestions, fix bug and modify test to catch that bug. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/renderer/media/media_stream_constraints_util_video_device.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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. This first advanced constraint
1254 constraint_factory_.AddAdvanced(); 1255 // set is therefore ignored in all calls to SelectSettings().
1255 advanced2.width.setExact(3000); 1256 // Tie-breaker rule that applies is closeness to default settings.
1256 advanced2.height.setExact(3000);
1257 auto result = SelectSettings(); 1257 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); 1258 EXPECT_EQ(default_device_->device_id, result.device_id);
1261 EXPECT_EQ(*default_closest_format_, result.Format()); 1259 EXPECT_EQ(*default_closest_format_, result.Format());
1262 1260
1261 blink::WebMediaTrackConstraintSet& advanced2 =
1262 constraint_factory_.AddAdvanced();
1263 advanced2.width.setMin(320);
1264 advanced2.height.setMin(240);
1265 advanced2.width.setMax(640);
1266 advanced2.height.setMax(480);
1267 result = SelectSettings();
1268 // The device that best supports this advanced set is the low-res device,
1269 // which natively supports the maximum resolution.
1270 EXPECT_EQ(low_res_device_->device_id, result.device_id);
1271 EXPECT_EQ(640, result.Width());
1272 EXPECT_EQ(480, result.Height());
1273
1263 blink::WebMediaTrackConstraintSet& advanced3 = 1274 blink::WebMediaTrackConstraintSet& advanced3 =
1264 constraint_factory_.AddAdvanced(); 1275 constraint_factory_.AddAdvanced();
1265 advanced3.width.setExact(1920); 1276 advanced3.frameRate.setMax(10.0);
1266 advanced3.height.setExact(1080);
1267 result = SelectSettings(); 1277 result = SelectSettings();
1268 EXPECT_TRUE(result.HasValue()); 1278 EXPECT_TRUE(result.HasValue());
1269 // The high-res device natively supports the third advanced constraint set 1279 // The high-res device natively supports the third advanced set in addition
1270 // and should be selected. 1280 // to the previous set and should be 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); 1281 EXPECT_EQ(high_res_device_->device_id, result.device_id);
1275 EXPECT_EQ(1920, result.Width()); 1282 EXPECT_EQ(640, result.Width());
1276 EXPECT_EQ(1080, result.Height()); 1283 EXPECT_EQ(480, result.Height());
1277 1284
1278 blink::WebMediaTrackConstraintSet& advanced4 = 1285 blink::WebMediaTrackConstraintSet& advanced4 =
1279 constraint_factory_.AddAdvanced(); 1286 constraint_factory_.AddAdvanced();
1280 advanced4.width.setExact(640); 1287 advanced4.width.setMax(1000);
1281 advanced4.height.setExact(480); 1288 advanced4.height.setMax(1000);
1289 result = SelectSettings();
1290 // Even though the default device supports the resolution in the fourth
1291 // advanced natively, having better support for the previous sets has
1292 // precedence, so the high-res device is selected.
1293 EXPECT_TRUE(result.HasValue());
1294 EXPECT_EQ(high_res_device_->device_id, result.device_id);
1295 EXPECT_EQ(640, result.Width());
1296 EXPECT_EQ(480, result.Height());
1297
1298 constraint_factory_.basic().width.setIdeal(100);
1299 constraint_factory_.basic().height.setIdeal(100);
1282 result = SelectSettings(); 1300 result = SelectSettings();
1283 EXPECT_TRUE(result.HasValue()); 1301 EXPECT_TRUE(result.HasValue());
1284 // First tie-breaker rule that applies is support for advanced constraints 1302 // 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 1303 // better at supporting the ideal value.
1286 // fourth advanced constraint set in favor of configurations that support 1304 // It beats 320x240@30Hz because the penalty for the native frame rate takes
1287 // the third set. 1305 // precedence over the native fitness distance.
1288 // Second tie-breaker rule is custom distance to advanced constraint sets 1306 // Both support standard fitness distance equally, since 600x400 can be
1289 // that appear first. 1307 // cropped to 320x240.
1290 EXPECT_EQ(high_res_device_->device_id, result.device_id); 1308 EXPECT_EQ(high_res_device_->device_id, result.device_id);
1291 EXPECT_EQ(1920, result.Width()); 1309 EXPECT_EQ(600, result.Width());
1292 EXPECT_EQ(1080, result.Height()); 1310 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 1311
1304 constraint_factory_.basic().width.setIdeal(2000); 1312 constraint_factory_.basic().width.setIdeal(2000);
1305 constraint_factory_.basic().height.setIdeal(1500); 1313 constraint_factory_.basic().height.setIdeal(1500);
1306 result = SelectSettings(); 1314 result = SelectSettings();
1307 EXPECT_TRUE(result.HasValue()); 1315 EXPECT_TRUE(result.HasValue());
1308 // The closest configuration to the ideal resolution is the high-res device 1316 // The high-res device at 640x480@10Hz is closer to the large ideal
1309 // at the highest resolution. 1317 // resolution.
1310 EXPECT_EQ(high_res_device_->device_id, result.device_id); 1318 EXPECT_EQ(high_res_device_->device_id, result.device_id);
1311 EXPECT_EQ(*high_res_highest_format_, result.Format()); 1319 EXPECT_EQ(640, result.Width());
1320 EXPECT_EQ(480, result.Height());
1312 } 1321 }
1313 1322
1314 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, 1323 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest,
1315 AdvancedResolutionAndFrameRate) { 1324 AdvancedResolutionAndFrameRate) {
1316 constraint_factory_.Reset(); 1325 constraint_factory_.Reset();
1317 blink::WebMediaTrackConstraintSet& advanced1 = 1326 blink::WebMediaTrackConstraintSet& advanced1 =
1318 constraint_factory_.AddAdvanced(); 1327 constraint_factory_.AddAdvanced();
1319 advanced1.width.setExact(1920); 1328 advanced1.width.setExact(1920);
1320 advanced1.height.setExact(1080); 1329 advanced1.height.setExact(1080);
1321 blink::WebMediaTrackConstraintSet& advanced2 = 1330 blink::WebMediaTrackConstraintSet& advanced2 =
(...skipping 12 matching lines...) Expand all
1334 EXPECT_EQ(high_res_device_->device_id, result.device_id); 1343 EXPECT_EQ(high_res_device_->device_id, result.device_id);
1335 EXPECT_EQ(1920, result.Width()); 1344 EXPECT_EQ(1920, result.Width());
1336 EXPECT_EQ(1080, result.Height()); 1345 EXPECT_EQ(1080, result.Height());
1337 EXPECT_EQ(60.0, result.FrameRate()); 1346 EXPECT_EQ(60.0, result.FrameRate());
1338 } 1347 }
1339 1348
1340 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, AdvancedNoiseReduction) { 1349 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, AdvancedNoiseReduction) {
1341 constraint_factory_.Reset(); 1350 constraint_factory_.Reset();
1342 blink::WebMediaTrackConstraintSet& advanced1 = 1351 blink::WebMediaTrackConstraintSet& advanced1 =
1343 constraint_factory_.AddAdvanced(); 1352 constraint_factory_.AddAdvanced();
1344 advanced1.width.setExact(640); 1353 advanced1.width.setMin(640);
1345 advanced1.height.setExact(480); 1354 advanced1.height.setMin(480);
1346 blink::WebMediaTrackConstraintSet& advanced2 = 1355 blink::WebMediaTrackConstraintSet& advanced2 =
1347 constraint_factory_.AddAdvanced(); 1356 constraint_factory_.AddAdvanced();
1348 advanced2.width.setExact(1920); 1357 advanced2.width.setMin(1920);
1349 advanced2.height.setExact(1080); 1358 advanced2.height.setMin(1080);
1350 advanced2.googNoiseReduction.setExact(false); 1359 advanced2.googNoiseReduction.setExact(false);
1351 auto result = SelectSettings(); 1360 auto result = SelectSettings();
1352 EXPECT_TRUE(result.HasValue()); 1361 EXPECT_TRUE(result.HasValue());
1353 EXPECT_EQ(high_res_device_->device_id, result.device_id); 1362 EXPECT_EQ(high_res_device_->device_id, result.device_id);
1354 EXPECT_EQ(1920, result.Width()); 1363 EXPECT_LE(1920, result.Width());
1355 EXPECT_EQ(1080, result.Height()); 1364 EXPECT_LE(1080, result.Height());
1356 EXPECT_TRUE(result.noise_reduction && !*result.noise_reduction); 1365 EXPECT_TRUE(result.noise_reduction && !*result.noise_reduction);
1357 } 1366 }
1358 1367
1359 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, 1368 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest,
1360 AdvancedContradictoryNoiseReduction) { 1369 AdvancedContradictoryNoiseReduction) {
1361 { 1370 {
1362 constraint_factory_.Reset(); 1371 constraint_factory_.Reset();
1363 blink::WebMediaTrackConstraintSet& advanced1 = 1372 blink::WebMediaTrackConstraintSet& advanced1 =
1364 constraint_factory_.AddAdvanced(); 1373 constraint_factory_.AddAdvanced();
1365 advanced1.width.setMin(640); 1374 advanced1.width.setMin(640);
(...skipping 30 matching lines...) Expand all
1396 EXPECT_TRUE(result.HasValue()); 1405 EXPECT_TRUE(result.HasValue());
1397 // Only the high-res device can satisfy the second advanced set. 1406 // Only the high-res device can satisfy the second advanced set.
1398 EXPECT_EQ(high_res_device_->device_id, result.device_id); 1407 EXPECT_EQ(high_res_device_->device_id, result.device_id);
1399 EXPECT_LE(1920, result.Width()); 1408 EXPECT_LE(1920, result.Width());
1400 EXPECT_LE(1080, result.Height()); 1409 EXPECT_LE(1080, result.Height());
1401 // Should select default noise reduction setting. 1410 // Should select default noise reduction setting.
1402 EXPECT_TRUE(!result.noise_reduction); 1411 EXPECT_TRUE(!result.noise_reduction);
1403 } 1412 }
1404 } 1413 }
1405 1414
1415 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest,
1416 AdvancedContradictoryExactResolution) {
1417 constraint_factory_.Reset();
1418 blink::WebMediaTrackConstraintSet& advanced1 =
1419 constraint_factory_.AddAdvanced();
1420 advanced1.width.setExact(640);
1421 advanced1.height.setExact(480);
1422 blink::WebMediaTrackConstraintSet& advanced2 =
1423 constraint_factory_.AddAdvanced();
1424 advanced2.width.setExact(1920);
1425 advanced2.height.setExact(1080);
1426 auto result = SelectSettings();
1427 EXPECT_TRUE(result.HasValue());
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
1430 // resolution.
1431 EXPECT_EQ(low_res_device_->device_id, result.device_id);
1432 EXPECT_EQ(640, result.Width());
1433 EXPECT_EQ(480, result.Height());
1434 }
1435
1436 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest,
1437 AdvancedContradictoryMaxMinResolutionFrameRate) {
1438 constraint_factory_.Reset();
1439 blink::WebMediaTrackConstraintSet& advanced1 =
1440 constraint_factory_.AddAdvanced();
1441 advanced1.width.setMax(640);
1442 advanced1.height.setMax(480);
1443 blink::WebMediaTrackConstraintSet& advanced2 =
1444 constraint_factory_.AddAdvanced();
1445 advanced2.width.setMin(1920);
1446 advanced2.height.setMin(1080);
1447 advanced2.frameRate.setExact(60.0);
1448 auto result = SelectSettings();
1449 EXPECT_TRUE(result.HasValue());
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.
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.
1454 EXPECT_EQ(default_device_->device_id, result.device_id);
1455 EXPECT_EQ(200, result.Width());
1456 EXPECT_EQ(200, result.Height());
1457 EXPECT_EQ(40, result.FrameRate());
1458 }
1459
1460 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest,
1461 AdvancedContradictoryMinMaxResolutionFrameRate) {
1462 constraint_factory_.Reset();
1463 blink::WebMediaTrackConstraintSet& advanced1 =
1464 constraint_factory_.AddAdvanced();
1465 advanced1.width.setMin(800);
1466 advanced1.height.setMin(600);
1467 blink::WebMediaTrackConstraintSet& advanced2 =
1468 constraint_factory_.AddAdvanced();
1469 advanced2.width.setMax(640);
1470 advanced2.height.setMax(480);
1471 advanced2.frameRate.setExact(60.0);
1472 auto result = SelectSettings();
1473 EXPECT_TRUE(result.HasValue());
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.
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.
1478 EXPECT_EQ(default_device_->device_id, result.device_id);
1479 EXPECT_EQ(1000, result.Width());
1480 EXPECT_EQ(1000, result.Height());
1481 EXPECT_EQ(20, result.FrameRate());
1482 }
1483
1484 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest,
1485 AdvancedContradictoryExactAspectRatio) {
1486 constraint_factory_.Reset();
1487 blink::WebMediaTrackConstraintSet& advanced1 =
1488 constraint_factory_.AddAdvanced();
1489 advanced1.aspectRatio.setExact(2300.0);
1490 blink::WebMediaTrackConstraintSet& advanced2 =
1491 constraint_factory_.AddAdvanced();
1492 advanced2.aspectRatio.setExact(3.0);
1493 auto result = SelectSettings();
1494 EXPECT_TRUE(result.HasValue());
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
1497 // requested aspect ratio.
1498 EXPECT_EQ(high_res_device_->device_id, result.device_id);
1499 EXPECT_EQ(*high_res_highest_format_, result.Format());
1500 }
1501
1502 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest,
1503 AdvancedContradictoryAspectRatioRange) {
1504 constraint_factory_.Reset();
1505 blink::WebMediaTrackConstraintSet& advanced1 =
1506 constraint_factory_.AddAdvanced();
1507 advanced1.aspectRatio.setMin(2300.0);
1508 blink::WebMediaTrackConstraintSet& advanced2 =
1509 constraint_factory_.AddAdvanced();
1510 advanced2.aspectRatio.setMax(3.0);
1511 auto result = SelectSettings();
1512 EXPECT_TRUE(result.HasValue());
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
1515 // requested aspect ratio.
1516 EXPECT_EQ(high_res_device_->device_id, result.device_id);
1517 EXPECT_EQ(*high_res_highest_format_, result.Format());
1518 }
1519
1520 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest,
1521 AdvancedContradictoryExactFrameRate) {
1522 constraint_factory_.Reset();
1523 blink::WebMediaTrackConstraintSet& advanced1 =
1524 constraint_factory_.AddAdvanced();
1525 advanced1.frameRate.setExact(40.0);
1526 blink::WebMediaTrackConstraintSet& advanced2 =
1527 constraint_factory_.AddAdvanced();
1528 advanced2.frameRate.setExact(45.0);
1529 auto result = SelectSettings();
1530 EXPECT_TRUE(result.HasValue());
1531 // The second advanced set must be ignored because it contradicts the first
1532 // set.
1533 EXPECT_EQ(40.0, result.FrameRate());
1534 }
1535
1536 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest,
1537 AdvancedContradictoryFrameRateRange) {
1538 constraint_factory_.Reset();
1539 blink::WebMediaTrackConstraintSet& advanced1 =
1540 constraint_factory_.AddAdvanced();
1541 advanced1.frameRate.setMin(40.0);
1542 blink::WebMediaTrackConstraintSet& advanced2 =
1543 constraint_factory_.AddAdvanced();
1544 advanced2.frameRate.setMax(35.0);
1545 auto result = SelectSettings();
1546 EXPECT_TRUE(result.HasValue());
1547 // The second advanced set must be ignored because it contradicts the first
1548 // set.
1549 EXPECT_LE(40.0, result.FrameRate());
1550 }
1551
1552 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest,
1553 AdvancedContradictoryWidthFrameRate) {
1554 constraint_factory_.Reset();
1555 blink::WebMediaTrackConstraintSet& advanced1 =
1556 constraint_factory_.AddAdvanced();
1557 advanced1.width.setMax(1920);
1558 blink::WebMediaTrackConstraintSet& advanced2 =
1559 constraint_factory_.AddAdvanced();
1560 advanced2.width.setMin(2000);
1561 advanced2.frameRate.setExact(10.0);
1562 blink::WebMediaTrackConstraintSet& advanced3 =
1563 constraint_factory_.AddAdvanced();
1564 advanced3.frameRate.setExact(30.0);
1565 auto result = SelectSettings();
1566 EXPECT_TRUE(result.HasValue());
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
1569 // both at the same time. Thus, low-res device must be preferred.
1570 EXPECT_EQ(low_res_device_->device_id, result.device_id);
1571 EXPECT_EQ(30.0, result.FrameRate());
1572 EXPECT_GE(1920, result.Width());
1573 }
1574
1575 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest,
1576 AdvancedContradictoryHeightFrameRate) {
1577 constraint_factory_.Reset();
1578 blink::WebMediaTrackConstraintSet& advanced1 =
1579 constraint_factory_.AddAdvanced();
1580 advanced1.height.setMax(1080);
1581 blink::WebMediaTrackConstraintSet& advanced2 =
1582 constraint_factory_.AddAdvanced();
1583 advanced2.height.setMin(1500);
1584 advanced2.frameRate.setExact(10.0);
1585 blink::WebMediaTrackConstraintSet& advanced3 =
1586 constraint_factory_.AddAdvanced();
1587 advanced3.frameRate.setExact(60.0);
1588 auto result = SelectSettings();
1589 EXPECT_TRUE(result.HasValue());
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,
1592 // but not both at the same time. Thus, the format closest to default that
1593 // satisfies sets 1 and 3 must be chosen.
1594 EXPECT_EQ(high_res_device_->device_id, result.device_id);
1595 EXPECT_EQ(60.0, result.FrameRate());
1596 EXPECT_GE(1080, result.Height());
1597 }
1598
1599 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, AdvancedDeviceID) {
1600 constraint_factory_.Reset();
1601 blink::WebMediaTrackConstraintSet& advanced1 =
1602 constraint_factory_.AddAdvanced();
1603 blink::WebString id_vector1[] = {blink::WebString::fromASCII(kDeviceID1),
1604 blink::WebString::fromASCII(kDeviceID2)};
1605 advanced1.deviceId.setExact(
1606 blink::WebVector<blink::WebString>(id_vector1, arraysize(id_vector1)));
1607 blink::WebString id_vector2[] = {blink::WebString::fromASCII(kDeviceID2),
1608 blink::WebString::fromASCII(kDeviceID3)};
1609 blink::WebMediaTrackConstraintSet& advanced2 =
1610 constraint_factory_.AddAdvanced();
1611 advanced2.deviceId.setExact(
1612 blink::WebVector<blink::WebString>(id_vector2, arraysize(id_vector2)));
1613 auto result = SelectSettings();
1614 EXPECT_TRUE(result.HasValue());
1615 // kDeviceID2 must be selected because it is the only one that satisfies both
1616 // advanced sets.
1617 EXPECT_EQ(std::string(kDeviceID2), result.device_id);
1618 }
1619
1620 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest,
1621 AdvancedContradictoryDeviceID) {
1622 constraint_factory_.Reset();
1623 blink::WebMediaTrackConstraintSet& advanced1 =
1624 constraint_factory_.AddAdvanced();
1625 blink::WebString id_vector1[] = {blink::WebString::fromASCII(kDeviceID1),
1626 blink::WebString::fromASCII(kDeviceID2)};
1627 advanced1.deviceId.setExact(
1628 blink::WebVector<blink::WebString>(id_vector1, arraysize(id_vector1)));
1629 blink::WebString id_vector2[] = {blink::WebString::fromASCII(kDeviceID3),
1630 blink::WebString::fromASCII(kDeviceID4)};
1631 blink::WebMediaTrackConstraintSet& advanced2 =
1632 constraint_factory_.AddAdvanced();
1633 advanced2.deviceId.setExact(
1634 blink::WebVector<blink::WebString>(id_vector2, arraysize(id_vector2)));
1635 auto result = SelectSettings();
1636 EXPECT_TRUE(result.HasValue());
1637 // The second advanced set must be ignored because it contradicts the first
1638 // set.
1639 EXPECT_EQ(std::string(kDeviceID1), result.device_id);
1640 }
1641
1642 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest,
1643 AdvancedContradictoryPowerLineFrequency) {
1644 {
1645 constraint_factory_.Reset();
1646 blink::WebMediaTrackConstraintSet& advanced1 =
1647 constraint_factory_.AddAdvanced();
1648 advanced1.width.setMin(640);
1649 advanced1.height.setMin(480);
1650 advanced1.googPowerLineFrequency.setExact(50);
1651 blink::WebMediaTrackConstraintSet& advanced2 =
1652 constraint_factory_.AddAdvanced();
1653 advanced2.width.setMin(1920);
1654 advanced2.height.setMin(1080);
1655 advanced2.googPowerLineFrequency.setExact(60);
1656 auto result = SelectSettings();
1657 EXPECT_TRUE(result.HasValue());
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
1660 // selected.
1661 EXPECT_EQ(default_device_->device_id, result.device_id);
1662 EXPECT_LE(640, result.Width());
1663 EXPECT_LE(480, result.Height());
1664 EXPECT_EQ(50, static_cast<int>(result.PowerLineFrequency()));
1665 }
1666 }
1667
1406 // The "NoDevices" tests verify that the algorithm returns the expected result 1668 // The "NoDevices" tests verify that the algorithm returns the expected result
1407 // when there are no candidates to choose from. 1669 // when there are no candidates to choose from.
1408 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, NoDevicesNoConstraints) { 1670 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, NoDevicesNoConstraints) {
1409 constraint_factory_.Reset(); 1671 constraint_factory_.Reset();
1410 VideoDeviceCaptureCapabilities capabilities; 1672 VideoDeviceCaptureCapabilities capabilities;
1411 auto result = SelectVideoDeviceCaptureSourceSettings( 1673 auto result = SelectVideoDeviceCaptureSourceSettings(
1412 capabilities, constraint_factory_.CreateWebMediaConstraints()); 1674 capabilities, constraint_factory_.CreateWebMediaConstraints());
1413 EXPECT_FALSE(result.HasValue()); 1675 EXPECT_FALSE(result.HasValue());
1414 EXPECT_TRUE(std::string(result.failed_constraint_name).empty()); 1676 EXPECT_TRUE(std::string(result.failed_constraint_name).empty());
1415 } 1677 }
1416 1678
1417 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, NoDevicesWithConstraints) { 1679 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, NoDevicesWithConstraints) {
1418 constraint_factory_.Reset(); 1680 constraint_factory_.Reset();
1419 constraint_factory_.basic().height.setExact(100); 1681 constraint_factory_.basic().height.setExact(100);
1420 VideoDeviceCaptureCapabilities capabilities; 1682 VideoDeviceCaptureCapabilities capabilities;
1421 auto result = SelectVideoDeviceCaptureSourceSettings( 1683 auto result = SelectVideoDeviceCaptureSourceSettings(
1422 capabilities, constraint_factory_.CreateWebMediaConstraints()); 1684 capabilities, constraint_factory_.CreateWebMediaConstraints());
1423 EXPECT_FALSE(result.HasValue()); 1685 EXPECT_FALSE(result.HasValue());
1424 EXPECT_TRUE(std::string(result.failed_constraint_name).empty()); 1686 EXPECT_TRUE(std::string(result.failed_constraint_name).empty());
1425 } 1687 }
1426 1688
1427 } // namespace content 1689 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/media_stream_constraints_util_video_device.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698