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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 device->formats = {media::VideoCaptureFormat(gfx::Size(640, 480), 30.0f, | 93 device->formats = {media::VideoCaptureFormat(gfx::Size(640, 480), 30.0f, |
| 94 media::PIXEL_FORMAT_Y16)}; | 94 media::PIXEL_FORMAT_Y16)}; |
| 95 capabilities_.device_capabilities.push_back(std::move(device)); | 95 capabilities_.device_capabilities.push_back(std::move(device)); |
| 96 | 96 |
| 97 capabilities_.power_line_capabilities = { | 97 capabilities_.power_line_capabilities = { |
| 98 media::PowerLineFrequency::FREQUENCY_DEFAULT, | 98 media::PowerLineFrequency::FREQUENCY_DEFAULT, |
| 99 media::PowerLineFrequency::FREQUENCY_50HZ, | 99 media::PowerLineFrequency::FREQUENCY_50HZ, |
| 100 media::PowerLineFrequency::FREQUENCY_60HZ, | 100 media::PowerLineFrequency::FREQUENCY_60HZ, |
| 101 }; | 101 }; |
| 102 | 102 |
| 103 capabilities_.noise_reduction_capabilities = { | |
| 104 rtc::Optional<bool>(), rtc::Optional<bool>(true), | |
| 105 rtc::Optional<bool>(false), | |
| 106 }; | |
| 107 | |
| 103 default_device_ = capabilities_.device_capabilities[0].get(); | 108 default_device_ = capabilities_.device_capabilities[0].get(); |
| 104 low_res_device_ = capabilities_.device_capabilities[1].get(); | 109 low_res_device_ = capabilities_.device_capabilities[1].get(); |
| 105 high_res_device_ = capabilities_.device_capabilities[2].get(); | 110 high_res_device_ = capabilities_.device_capabilities[2].get(); |
| 106 default_closest_format_ = &default_device_->formats[1]; | 111 default_closest_format_ = &default_device_->formats[1]; |
| 107 low_res_closest_format_ = &low_res_device_->formats[2]; | 112 low_res_closest_format_ = &low_res_device_->formats[2]; |
| 108 high_res_closest_format_ = &high_res_device_->formats[2]; | 113 high_res_closest_format_ = &high_res_device_->formats[2]; |
| 109 high_res_highest_format_ = &high_res_device_->formats[5]; | 114 high_res_highest_format_ = &high_res_device_->formats[5]; |
| 110 } | 115 } |
| 111 | 116 |
| 112 protected: | 117 protected: |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 131 | 136 |
| 132 // The Unconstrained test checks the default selection criteria. | 137 // The Unconstrained test checks the default selection criteria. |
| 133 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, Unconstrained) { | 138 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, Unconstrained) { |
| 134 constraint_factory_.Reset(); | 139 constraint_factory_.Reset(); |
| 135 auto result = SelectSettings(); | 140 auto result = SelectSettings(); |
| 136 EXPECT_TRUE(result.HasValue()); | 141 EXPECT_TRUE(result.HasValue()); |
| 137 // Should select the default device with closest-to-default settings. | 142 // Should select the default device with closest-to-default settings. |
| 138 EXPECT_EQ(default_device_->device_id, result.device_id); | 143 EXPECT_EQ(default_device_->device_id, result.device_id); |
| 139 EXPECT_EQ(default_device_->facing_mode, result.facing_mode); | 144 EXPECT_EQ(default_device_->facing_mode, result.facing_mode); |
| 140 EXPECT_EQ(*default_closest_format_, result.Format()); | 145 EXPECT_EQ(*default_closest_format_, result.Format()); |
| 146 // Should select default settings for other constraints. | |
| 147 EXPECT_EQ(media::PowerLineFrequency::FREQUENCY_DEFAULT, | |
| 148 result.PowerLineFrequency()); | |
| 149 EXPECT_EQ(rtc::Optional<bool>(), result.noise_reduction); | |
| 141 } | 150 } |
| 142 | 151 |
| 143 // The "Overconstrained" tests verify that failure of any single required | 152 // The "Overconstrained" tests verify that failure of any single required |
| 144 // constraint results in failure to select a candidate. | 153 // constraint results in failure to select a candidate. |
| 145 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, OverconstrainedOnDeviceID) { | 154 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, OverconstrainedOnDeviceID) { |
| 146 constraint_factory_.Reset(); | 155 constraint_factory_.Reset(); |
| 147 constraint_factory_.basic().deviceId.setExact( | 156 constraint_factory_.basic().deviceId.setExact( |
| 148 blink::WebString::fromASCII("NONEXISTING")); | 157 blink::WebString::fromASCII("NONEXISTING")); |
| 149 auto result = SelectSettings(); | 158 auto result = SelectSettings(); |
| 150 EXPECT_FALSE(result.HasValue()); | 159 EXPECT_FALSE(result.HasValue()); |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 286 result.failed_constraint_name); | 295 result.failed_constraint_name); |
| 287 | 296 |
| 288 constraint_factory_.Reset(); | 297 constraint_factory_.Reset(); |
| 289 constraint_factory_.basic().googPowerLineFrequency.setMax(-1); | 298 constraint_factory_.basic().googPowerLineFrequency.setMax(-1); |
| 290 result = SelectSettings(); | 299 result = SelectSettings(); |
| 291 EXPECT_FALSE(result.HasValue()); | 300 EXPECT_FALSE(result.HasValue()); |
| 292 EXPECT_EQ(constraint_factory_.basic().googPowerLineFrequency.name(), | 301 EXPECT_EQ(constraint_factory_.basic().googPowerLineFrequency.name(), |
| 293 result.failed_constraint_name); | 302 result.failed_constraint_name); |
| 294 } | 303 } |
| 295 | 304 |
| 305 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, | |
| 306 OverconstrainedOnNoiseReduction) { | |
| 307 // Simulate a system that does not support noise reduction. | |
| 308 // Manually adding device capabilities because VideoDeviceCaptureCapabilities | |
| 309 // is move only. | |
| 310 VideoDeviceCaptureCapabilities capabilities; | |
| 311 ::mojom::VideoInputDeviceCapabilitiesPtr device = | |
| 312 ::mojom::VideoInputDeviceCapabilities::New(); | |
| 313 device->device_id = kDeviceID1; | |
| 314 device->facing_mode = ::mojom::FacingMode::NONE; | |
| 315 device->formats = { | |
| 316 media::VideoCaptureFormat(gfx::Size(200, 200), 40.0f, | |
| 317 media::PIXEL_FORMAT_I420), | |
| 318 }; | |
| 319 capabilities.device_capabilities.push_back(std::move(device)); | |
| 320 capabilities.power_line_capabilities = capabilities_.power_line_capabilities; | |
| 321 capabilities.noise_reduction_capabilities = {rtc::Optional<bool>(false)}; | |
| 322 | |
| 323 constraint_factory_.Reset(); | |
| 324 constraint_factory_.basic().googNoiseReduction.setExact(true); | |
| 325 auto constraints = constraint_factory_.CreateWebMediaConstraints(); | |
| 326 auto result = | |
| 327 SelectVideoDeviceCaptureSourceSettings(capabilities, constraints); | |
| 328 EXPECT_FALSE(result.HasValue()); | |
| 329 EXPECT_EQ(constraint_factory_.basic().googNoiseReduction.name(), | |
| 330 result.failed_constraint_name); | |
| 331 } | |
| 332 | |
| 296 // The "Mandatory" and "Ideal" tests check that various selection criteria work | 333 // The "Mandatory" and "Ideal" tests check that various selection criteria work |
| 297 // for each individual constraint in the basic constraint set. | 334 // for each individual constraint in the basic constraint set. |
| 298 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryDeviceID) { | 335 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryDeviceID) { |
| 299 constraint_factory_.Reset(); | 336 constraint_factory_.Reset(); |
| 300 constraint_factory_.basic().deviceId.setExact( | 337 constraint_factory_.basic().deviceId.setExact( |
| 301 blink::WebString::fromASCII(default_device_->device_id)); | 338 blink::WebString::fromASCII(default_device_->device_id)); |
| 302 auto result = SelectSettings(); | 339 auto result = SelectSettings(); |
| 303 EXPECT_TRUE(result.HasValue()); | 340 EXPECT_TRUE(result.HasValue()); |
| 304 EXPECT_EQ(default_device_->device_id, result.device_id); | 341 EXPECT_EQ(default_device_->device_id, result.device_id); |
| 305 EXPECT_EQ(*default_closest_format_, result.Format()); | 342 EXPECT_EQ(*default_closest_format_, result.Format()); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 378 EXPECT_TRUE(result.HasValue()); | 415 EXPECT_TRUE(result.HasValue()); |
| 379 EXPECT_EQ(power_line_frequency, result.PowerLineFrequency()); | 416 EXPECT_EQ(power_line_frequency, result.PowerLineFrequency()); |
| 380 // The default device and settings closest to the default should be | 417 // The default device and settings closest to the default should be |
| 381 // selected. | 418 // selected. |
| 382 EXPECT_EQ(default_device_->device_id, result.device_id); | 419 EXPECT_EQ(default_device_->device_id, result.device_id); |
| 383 EXPECT_EQ(default_device_->facing_mode, result.facing_mode); | 420 EXPECT_EQ(default_device_->facing_mode, result.facing_mode); |
| 384 EXPECT_EQ(*default_closest_format_, result.Format()); | 421 EXPECT_EQ(*default_closest_format_, result.Format()); |
| 385 } | 422 } |
| 386 } | 423 } |
| 387 | 424 |
| 425 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryNoiseReduction) { | |
| 426 constraint_factory_.Reset(); | |
| 427 const bool kNoiseReductionValues[] = {true, false}; | |
| 428 for (auto noise_reduction : kNoiseReductionValues) { | |
| 429 constraint_factory_.basic().googNoiseReduction.setExact(noise_reduction); | |
| 430 auto result = SelectSettings(); | |
| 431 EXPECT_TRUE(result.HasValue()); | |
| 432 EXPECT_EQ(noise_reduction, result.noise_reduction); | |
| 433 // The default device and settings closest to the default should be | |
| 434 // selected. | |
| 435 EXPECT_EQ(default_device_->device_id, result.device_id); | |
| 436 EXPECT_EQ(default_device_->facing_mode, result.facing_mode); | |
| 437 EXPECT_EQ(*default_closest_format_, result.Format()); | |
| 438 } | |
| 439 } | |
| 440 | |
| 388 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryExactHeight) { | 441 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryExactHeight) { |
| 389 constraint_factory_.Reset(); | 442 constraint_factory_.Reset(); |
| 390 const int kHeight = MediaStreamVideoSource::kDefaultHeight; | 443 const int kHeight = MediaStreamVideoSource::kDefaultHeight; |
| 391 constraint_factory_.basic().height.setExact(kHeight); | 444 constraint_factory_.basic().height.setExact(kHeight); |
| 392 auto result = SelectSettings(); | 445 auto result = SelectSettings(); |
| 393 EXPECT_TRUE(result.HasValue()); | 446 EXPECT_TRUE(result.HasValue()); |
| 394 // All devices in |capabilities_| support the requested height. The algorithm | 447 // All devices in |capabilities_| support the requested height. The algorithm |
| 395 // should prefer the first device that supports the requested height natively, | 448 // should prefer the first device that supports the requested height natively, |
| 396 // which is the low-res device. | 449 // which is the low-res device. |
| 397 EXPECT_EQ(low_res_device_->device_id, result.device_id); | 450 EXPECT_EQ(low_res_device_->device_id, result.device_id); |
| (...skipping 883 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1281 // set. 2304x1536x10.0 satisfies sets 1 and 3, while 1920x1080x60.0 | 1334 // set. 2304x1536x10.0 satisfies sets 1 and 3, while 1920x1080x60.0 |
| 1282 // satisfies sets 1, and 2. The latter must be selected, regardless of | 1335 // satisfies sets 1, and 2. The latter must be selected, regardless of |
| 1283 // any other criteria. | 1336 // any other criteria. |
| 1284 EXPECT_EQ(high_res_device_->device_id, result.device_id); | 1337 EXPECT_EQ(high_res_device_->device_id, result.device_id); |
| 1285 EXPECT_EQ(1920, result.Width()); | 1338 EXPECT_EQ(1920, result.Width()); |
| 1286 EXPECT_EQ(1080, result.Height()); | 1339 EXPECT_EQ(1080, result.Height()); |
| 1287 EXPECT_EQ(60.0, result.FrameRate()); | 1340 EXPECT_EQ(60.0, result.FrameRate()); |
| 1288 } | 1341 } |
| 1289 } | 1342 } |
| 1290 | 1343 |
| 1344 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, AdvancedNoiseReduction) { | |
| 1345 { | |
| 1346 constraint_factory_.Reset(); | |
| 1347 blink::WebMediaTrackConstraintSet& advanced1 = | |
| 1348 constraint_factory_.AddAdvanced(); | |
| 1349 advanced1.width.setExact(640); | |
| 1350 advanced1.height.setExact(480); | |
| 1351 blink::WebMediaTrackConstraintSet& advanced2 = | |
| 1352 constraint_factory_.AddAdvanced(); | |
| 1353 advanced2.width.setExact(1920); | |
| 1354 advanced2.height.setExact(1080); | |
| 1355 advanced2.googNoiseReduction.setExact(false); | |
| 1356 auto result = SelectSettings(); | |
| 1357 EXPECT_TRUE(result.HasValue()); | |
| 1358 EXPECT_EQ(high_res_device_->device_id, result.device_id); | |
| 1359 EXPECT_EQ(1920, result.Width()); | |
| 1360 EXPECT_EQ(1080, result.Height()); | |
| 1361 EXPECT_TRUE(result.noise_reduction && !*result.noise_reduction); | |
| 1362 } | |
| 1363 } | |
| 1364 | |
| 1365 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, | |
| 1366 AdvancedContradictoryNoiseReduction) { | |
| 1367 { | |
| 1368 constraint_factory_.Reset(); | |
| 1369 blink::WebMediaTrackConstraintSet& advanced1 = | |
| 1370 constraint_factory_.AddAdvanced(); | |
| 1371 advanced1.width.setExact(640); | |
| 1372 advanced1.height.setExact(480); | |
| 1373 advanced1.googNoiseReduction.setExact(true); | |
| 1374 blink::WebMediaTrackConstraintSet& advanced2 = | |
| 1375 constraint_factory_.AddAdvanced(); | |
| 1376 advanced2.width.setExact(1920); | |
| 1377 advanced2.height.setExact(1080); | |
| 1378 advanced2.googNoiseReduction.setExact(false); | |
| 1379 auto result = SelectSettings(); | |
| 1380 EXPECT_TRUE(result.HasValue()); | |
| 1381 // The second advanced set cannot be satisfied because it contradicts the | |
| 1382 // first set. The low-res device should be selected in that case. | |
|
hbos_chromium
2017/02/27 11:57:07
With Exacts a device will satisfy the first OR the
Guido Urdaneta
2017/02/27 17:14:21
Done.
| |
| 1383 EXPECT_EQ(low_res_device_->device_id, result.device_id); | |
| 1384 EXPECT_EQ(640, result.Width()); | |
| 1385 EXPECT_EQ(480, result.Height()); | |
| 1386 EXPECT_TRUE(result.noise_reduction && *result.noise_reduction); | |
| 1387 } | |
| 1388 } | |
| 1389 | |
| 1291 // The "NoDevices" tests verify that the algorithm returns the expected result | 1390 // The "NoDevices" tests verify that the algorithm returns the expected result |
| 1292 // when there are no candidates to choose from. | 1391 // when there are no candidates to choose from. |
| 1293 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, NoDevicesNoConstraints) { | 1392 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, NoDevicesNoConstraints) { |
| 1294 constraint_factory_.Reset(); | 1393 constraint_factory_.Reset(); |
| 1295 VideoDeviceCaptureCapabilities capabilities; | 1394 VideoDeviceCaptureCapabilities capabilities; |
| 1296 auto result = SelectVideoDeviceCaptureSourceSettings( | 1395 auto result = SelectVideoDeviceCaptureSourceSettings( |
| 1297 capabilities, constraint_factory_.CreateWebMediaConstraints()); | 1396 capabilities, constraint_factory_.CreateWebMediaConstraints()); |
| 1298 EXPECT_FALSE(result.HasValue()); | 1397 EXPECT_FALSE(result.HasValue()); |
| 1299 EXPECT_TRUE(std::string(result.failed_constraint_name).empty()); | 1398 EXPECT_TRUE(std::string(result.failed_constraint_name).empty()); |
| 1300 } | 1399 } |
| 1301 | 1400 |
| 1302 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, NoDevicesWithConstraints) { | 1401 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, NoDevicesWithConstraints) { |
| 1303 constraint_factory_.Reset(); | 1402 constraint_factory_.Reset(); |
| 1304 constraint_factory_.basic().height.setExact(100); | 1403 constraint_factory_.basic().height.setExact(100); |
| 1305 VideoDeviceCaptureCapabilities capabilities; | 1404 VideoDeviceCaptureCapabilities capabilities; |
| 1306 auto result = SelectVideoDeviceCaptureSourceSettings( | 1405 auto result = SelectVideoDeviceCaptureSourceSettings( |
| 1307 capabilities, constraint_factory_.CreateWebMediaConstraints()); | 1406 capabilities, constraint_factory_.CreateWebMediaConstraints()); |
| 1308 EXPECT_FALSE(result.HasValue()); | 1407 EXPECT_FALSE(result.HasValue()); |
| 1309 EXPECT_TRUE(std::string(result.failed_constraint_name).empty()); | 1408 EXPECT_TRUE(std::string(result.failed_constraint_name).empty()); |
| 1310 } | 1409 } |
| 1311 | 1410 |
| 1312 } // namespace content | 1411 } // namespace content |
| OLD | NEW |