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" |
11 #include "content/renderer/media/media_stream_video_source.h" | 11 #include "content/renderer/media/media_stream_video_source.h" |
12 #include "content/renderer/media/mock_constraint_factory.h" | 12 #include "content/renderer/media/mock_constraint_factory.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" | 14 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" |
15 | 15 |
16 namespace content { | 16 namespace content { |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 const char kDeviceID1[] = "fake_device_1"; | 20 const char kDeviceID1[] = "fake_device_1"; |
21 const char kDeviceID2[] = "fake_device_2"; | 21 const char kDeviceID2[] = "fake_device_2"; |
22 const char kDeviceID3[] = "fake_device_3"; | 22 const char kDeviceID3[] = "fake_device_3"; |
23 const char kDeviceID4[] = "fake_device_4"; | 23 const char kDeviceID4[] = "fake_device_4"; |
| 24 |
| 25 void CheckTrackAdapterSettingsEqualsResolution( |
| 26 const VideoCaptureSettings& settings) { |
| 27 EXPECT_EQ(settings.Format().frame_size.width(), |
| 28 settings.track_adapter_settings().max_width); |
| 29 EXPECT_EQ(settings.Format().frame_size.height(), |
| 30 settings.track_adapter_settings().max_height); |
| 31 EXPECT_EQ(1.0 / settings.Format().frame_size.height(), |
| 32 settings.track_adapter_settings().min_aspect_ratio); |
| 33 EXPECT_EQ(settings.Format().frame_size.width(), |
| 34 settings.track_adapter_settings().max_aspect_ratio); |
24 } | 35 } |
25 | 36 |
| 37 void CheckTrackAdapterSettingsEqualsFrameRate( |
| 38 const VideoCaptureSettings& settings, |
| 39 double value = 0.0) { |
| 40 if (value >= settings.FrameRate()) |
| 41 value = 0.0; |
| 42 EXPECT_EQ(value, settings.track_adapter_settings().max_frame_rate); |
| 43 } |
| 44 |
| 45 void CheckTrackAdapterSettingsEqualsFormat( |
| 46 const VideoCaptureSettings& settings) { |
| 47 CheckTrackAdapterSettingsEqualsResolution(settings); |
| 48 CheckTrackAdapterSettingsEqualsFrameRate(settings); |
| 49 } |
| 50 |
| 51 double AspectRatio(const media::VideoCaptureFormat& format) { |
| 52 return static_cast<double>(format.frame_size.width()) / |
| 53 static_cast<double>(format.frame_size.height()); |
| 54 } |
| 55 |
| 56 } // namespace |
| 57 |
26 class MediaStreamConstraintsUtilVideoDeviceTest : public testing::Test { | 58 class MediaStreamConstraintsUtilVideoDeviceTest : public testing::Test { |
27 public: | 59 public: |
28 void SetUp() override { | 60 void SetUp() override { |
29 // Default device. It is default because it is the first in the enumeration. | 61 // Default device. It is default because it is the first in the enumeration. |
30 ::mojom::VideoInputDeviceCapabilitiesPtr device = | 62 ::mojom::VideoInputDeviceCapabilitiesPtr device = |
31 ::mojom::VideoInputDeviceCapabilities::New(); | 63 ::mojom::VideoInputDeviceCapabilities::New(); |
32 device->device_id = kDeviceID1; | 64 device->device_id = kDeviceID1; |
33 device->facing_mode = ::mojom::FacingMode::NONE; | 65 device->facing_mode = ::mojom::FacingMode::NONE; |
34 device->formats = { | 66 device->formats = { |
35 media::VideoCaptureFormat(gfx::Size(200, 200), 40.0f, | 67 media::VideoCaptureFormat(gfx::Size(200, 200), 40.0f, |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 media::PIXEL_FORMAT_Y16)}; | 126 media::PIXEL_FORMAT_Y16)}; |
95 capabilities_.device_capabilities.push_back(std::move(device)); | 127 capabilities_.device_capabilities.push_back(std::move(device)); |
96 | 128 |
97 capabilities_.power_line_capabilities = { | 129 capabilities_.power_line_capabilities = { |
98 media::PowerLineFrequency::FREQUENCY_DEFAULT, | 130 media::PowerLineFrequency::FREQUENCY_DEFAULT, |
99 media::PowerLineFrequency::FREQUENCY_50HZ, | 131 media::PowerLineFrequency::FREQUENCY_50HZ, |
100 media::PowerLineFrequency::FREQUENCY_60HZ, | 132 media::PowerLineFrequency::FREQUENCY_60HZ, |
101 }; | 133 }; |
102 | 134 |
103 capabilities_.noise_reduction_capabilities = { | 135 capabilities_.noise_reduction_capabilities = { |
104 rtc::Optional<bool>(), rtc::Optional<bool>(true), | 136 base::Optional<bool>(), base::Optional<bool>(true), |
105 rtc::Optional<bool>(false), | 137 base::Optional<bool>(false), |
106 }; | 138 }; |
107 | 139 |
108 default_device_ = capabilities_.device_capabilities[0].get(); | 140 default_device_ = capabilities_.device_capabilities[0].get(); |
109 low_res_device_ = capabilities_.device_capabilities[1].get(); | 141 low_res_device_ = capabilities_.device_capabilities[1].get(); |
110 high_res_device_ = capabilities_.device_capabilities[2].get(); | 142 high_res_device_ = capabilities_.device_capabilities[2].get(); |
111 default_closest_format_ = &default_device_->formats[1]; | 143 default_closest_format_ = &default_device_->formats[1]; |
112 low_res_closest_format_ = &low_res_device_->formats[2]; | 144 low_res_closest_format_ = &low_res_device_->formats[2]; |
113 high_res_closest_format_ = &high_res_device_->formats[2]; | 145 high_res_closest_format_ = &high_res_device_->formats[2]; |
114 high_res_highest_format_ = &high_res_device_->formats[5]; | 146 high_res_highest_format_ = &high_res_device_->formats[5]; |
115 } | 147 } |
116 | 148 |
117 protected: | 149 protected: |
118 VideoDeviceCaptureSourceSelectionResult SelectSettings() { | 150 VideoCaptureSettings SelectSettings() { |
119 blink::WebMediaConstraints constraints = | 151 blink::WebMediaConstraints constraints = |
120 constraint_factory_.CreateWebMediaConstraints(); | 152 constraint_factory_.CreateWebMediaConstraints(); |
121 return SelectVideoDeviceCaptureSourceSettings(capabilities_, constraints); | 153 return SelectSettingsVideoDeviceCapture(capabilities_, constraints); |
122 } | 154 } |
123 | 155 |
124 VideoDeviceCaptureCapabilities capabilities_; | 156 VideoDeviceCaptureCapabilities capabilities_; |
125 const mojom::VideoInputDeviceCapabilities* default_device_; | 157 const mojom::VideoInputDeviceCapabilities* default_device_; |
126 const mojom::VideoInputDeviceCapabilities* low_res_device_; | 158 const mojom::VideoInputDeviceCapabilities* low_res_device_; |
127 const mojom::VideoInputDeviceCapabilities* high_res_device_; | 159 const mojom::VideoInputDeviceCapabilities* high_res_device_; |
128 // Closest formats to the default settings. | 160 // Closest formats to the default settings. |
129 const media::VideoCaptureFormat* default_closest_format_; | 161 const media::VideoCaptureFormat* default_closest_format_; |
130 const media::VideoCaptureFormat* low_res_closest_format_; | 162 const media::VideoCaptureFormat* low_res_closest_format_; |
131 const media::VideoCaptureFormat* high_res_closest_format_; | 163 const media::VideoCaptureFormat* high_res_closest_format_; |
132 const media::VideoCaptureFormat* high_res_highest_format_; | 164 const media::VideoCaptureFormat* high_res_highest_format_; |
133 | 165 |
134 MockConstraintFactory constraint_factory_; | 166 MockConstraintFactory constraint_factory_; |
135 }; | 167 }; |
136 | 168 |
137 // The Unconstrained test checks the default selection criteria. | 169 // The Unconstrained test checks the default selection criteria. |
138 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, Unconstrained) { | 170 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, Unconstrained) { |
139 constraint_factory_.Reset(); | 171 constraint_factory_.Reset(); |
140 auto result = SelectSettings(); | 172 auto result = SelectSettings(); |
141 EXPECT_TRUE(result.HasValue()); | 173 EXPECT_TRUE(result.HasValue()); |
142 // Should select the default device with closest-to-default settings. | 174 // Should select the default device with closest-to-default settings. |
143 EXPECT_EQ(default_device_->device_id, result.device_id()); | 175 EXPECT_EQ(default_device_->device_id, result.device_id()); |
144 EXPECT_EQ(default_device_->facing_mode, result.facing_mode()); | |
145 EXPECT_EQ(*default_closest_format_, result.Format()); | 176 EXPECT_EQ(*default_closest_format_, result.Format()); |
146 // Should select default settings for other constraints. | 177 // Should select default settings for other constraints. |
147 EXPECT_EQ(media::PowerLineFrequency::FREQUENCY_DEFAULT, | 178 EXPECT_EQ(media::PowerLineFrequency::FREQUENCY_DEFAULT, |
148 result.PowerLineFrequency()); | 179 result.PowerLineFrequency()); |
149 EXPECT_EQ(rtc::Optional<bool>(), result.noise_reduction()); | 180 EXPECT_EQ(base::Optional<bool>(), result.noise_reduction()); |
150 } | 181 } |
151 | 182 |
152 // The "Overconstrained" tests verify that failure of any single required | 183 // The "Overconstrained" tests verify that failure of any single required |
153 // constraint results in failure to select a candidate. | 184 // constraint results in failure to select a candidate. |
154 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, OverconstrainedOnDeviceID) { | 185 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, OverconstrainedOnDeviceID) { |
155 constraint_factory_.Reset(); | 186 constraint_factory_.Reset(); |
156 constraint_factory_.basic().deviceId.setExact( | 187 constraint_factory_.basic().deviceId.setExact( |
157 blink::WebString::fromASCII("NONEXISTING")); | 188 blink::WebString::fromASCII("NONEXISTING")); |
158 auto result = SelectSettings(); | 189 auto result = SelectSettings(); |
159 EXPECT_FALSE(result.HasValue()); | 190 EXPECT_FALSE(result.HasValue()); |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 ::mojom::VideoInputDeviceCapabilitiesPtr device = | 342 ::mojom::VideoInputDeviceCapabilitiesPtr device = |
312 ::mojom::VideoInputDeviceCapabilities::New(); | 343 ::mojom::VideoInputDeviceCapabilities::New(); |
313 device->device_id = kDeviceID1; | 344 device->device_id = kDeviceID1; |
314 device->facing_mode = ::mojom::FacingMode::NONE; | 345 device->facing_mode = ::mojom::FacingMode::NONE; |
315 device->formats = { | 346 device->formats = { |
316 media::VideoCaptureFormat(gfx::Size(200, 200), 40.0f, | 347 media::VideoCaptureFormat(gfx::Size(200, 200), 40.0f, |
317 media::PIXEL_FORMAT_I420), | 348 media::PIXEL_FORMAT_I420), |
318 }; | 349 }; |
319 capabilities.device_capabilities.push_back(std::move(device)); | 350 capabilities.device_capabilities.push_back(std::move(device)); |
320 capabilities.power_line_capabilities = capabilities_.power_line_capabilities; | 351 capabilities.power_line_capabilities = capabilities_.power_line_capabilities; |
321 capabilities.noise_reduction_capabilities = {rtc::Optional<bool>(false)}; | 352 capabilities.noise_reduction_capabilities = {base::Optional<bool>(false)}; |
322 | 353 |
323 constraint_factory_.Reset(); | 354 constraint_factory_.Reset(); |
324 constraint_factory_.basic().googNoiseReduction.setExact(true); | 355 constraint_factory_.basic().googNoiseReduction.setExact(true); |
325 auto constraints = constraint_factory_.CreateWebMediaConstraints(); | 356 auto constraints = constraint_factory_.CreateWebMediaConstraints(); |
326 auto result = | 357 auto result = SelectSettingsVideoDeviceCapture(capabilities, constraints); |
327 SelectVideoDeviceCaptureSourceSettings(capabilities, constraints); | |
328 EXPECT_FALSE(result.HasValue()); | 358 EXPECT_FALSE(result.HasValue()); |
329 EXPECT_EQ(constraint_factory_.basic().googNoiseReduction.name(), | 359 EXPECT_EQ(constraint_factory_.basic().googNoiseReduction.name(), |
330 result.failed_constraint_name()); | 360 result.failed_constraint_name()); |
331 } | 361 } |
332 | 362 |
333 // The "Mandatory" and "Ideal" tests check that various selection criteria work | 363 // The "Mandatory" and "Ideal" tests check that various selection criteria work |
334 // for each individual constraint in the basic constraint set. | 364 // for each individual constraint in the basic constraint set. |
335 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryDeviceID) { | 365 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryDeviceID) { |
336 constraint_factory_.Reset(); | 366 constraint_factory_.Reset(); |
337 constraint_factory_.basic().deviceId.setExact( | 367 constraint_factory_.basic().deviceId.setExact( |
338 blink::WebString::fromASCII(default_device_->device_id)); | 368 blink::WebString::fromASCII(default_device_->device_id)); |
339 auto result = SelectSettings(); | 369 auto result = SelectSettings(); |
340 EXPECT_TRUE(result.HasValue()); | 370 EXPECT_TRUE(result.HasValue()); |
341 EXPECT_EQ(default_device_->device_id, result.device_id()); | 371 EXPECT_EQ(default_device_->device_id, result.device_id()); |
342 EXPECT_EQ(*default_closest_format_, result.Format()); | 372 EXPECT_EQ(*default_closest_format_, result.Format()); |
343 EXPECT_EQ(media::PowerLineFrequency::FREQUENCY_DEFAULT, | 373 EXPECT_EQ(media::PowerLineFrequency::FREQUENCY_DEFAULT, |
344 result.PowerLineFrequency()); | 374 result.PowerLineFrequency()); |
| 375 CheckTrackAdapterSettingsEqualsFormat(result); |
345 | 376 |
346 constraint_factory_.basic().deviceId.setExact( | 377 constraint_factory_.basic().deviceId.setExact( |
347 blink::WebString::fromASCII(low_res_device_->device_id)); | 378 blink::WebString::fromASCII(low_res_device_->device_id)); |
348 result = SelectSettings(); | 379 result = SelectSettings(); |
349 EXPECT_EQ(low_res_device_->device_id, result.device_id()); | 380 EXPECT_EQ(low_res_device_->device_id, result.device_id()); |
350 EXPECT_EQ(*low_res_closest_format_, result.Format()); | 381 EXPECT_EQ(*low_res_closest_format_, result.Format()); |
351 EXPECT_EQ(media::PowerLineFrequency::FREQUENCY_DEFAULT, | 382 EXPECT_EQ(media::PowerLineFrequency::FREQUENCY_DEFAULT, |
352 result.PowerLineFrequency()); | 383 result.PowerLineFrequency()); |
| 384 CheckTrackAdapterSettingsEqualsFormat(result); |
353 | 385 |
354 constraint_factory_.basic().deviceId.setExact( | 386 constraint_factory_.basic().deviceId.setExact( |
355 blink::WebString::fromASCII(high_res_device_->device_id)); | 387 blink::WebString::fromASCII(high_res_device_->device_id)); |
356 result = SelectSettings(); | 388 result = SelectSettings(); |
357 EXPECT_EQ(high_res_device_->device_id, result.device_id()); | 389 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
358 EXPECT_EQ(*high_res_closest_format_, result.Format()); | 390 EXPECT_EQ(*high_res_closest_format_, result.Format()); |
359 EXPECT_EQ(media::PowerLineFrequency::FREQUENCY_DEFAULT, | 391 EXPECT_EQ(media::PowerLineFrequency::FREQUENCY_DEFAULT, |
360 result.PowerLineFrequency()); | 392 result.PowerLineFrequency()); |
| 393 CheckTrackAdapterSettingsEqualsFormat(result); |
361 } | 394 } |
362 | 395 |
363 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryFacingMode) { | 396 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryFacingMode) { |
364 constraint_factory_.Reset(); | 397 constraint_factory_.Reset(); |
365 constraint_factory_.basic().facingMode.setExact( | 398 constraint_factory_.basic().facingMode.setExact( |
366 blink::WebString::fromASCII("environment")); | 399 blink::WebString::fromASCII("environment")); |
367 auto result = SelectSettings(); | 400 auto result = SelectSettings(); |
368 EXPECT_TRUE(result.HasValue()); | 401 EXPECT_TRUE(result.HasValue()); |
369 EXPECT_EQ(::mojom::FacingMode::ENVIRONMENT, result.facing_mode()); | |
370 // Only the low-res device supports environment facing mode. Should select | 402 // Only the low-res device supports environment facing mode. Should select |
371 // default settings for everything else. | 403 // default settings for everything else. |
372 EXPECT_EQ(low_res_device_->device_id, result.device_id()); | 404 EXPECT_EQ(low_res_device_->device_id, result.device_id()); |
| 405 EXPECT_EQ(::mojom::FacingMode::ENVIRONMENT, low_res_device_->facing_mode); |
373 EXPECT_EQ(*low_res_closest_format_, result.Format()); | 406 EXPECT_EQ(*low_res_closest_format_, result.Format()); |
374 EXPECT_EQ(media::PowerLineFrequency::FREQUENCY_DEFAULT, | 407 EXPECT_EQ(media::PowerLineFrequency::FREQUENCY_DEFAULT, |
375 result.PowerLineFrequency()); | 408 result.PowerLineFrequency()); |
| 409 CheckTrackAdapterSettingsEqualsFormat(result); |
376 | 410 |
377 constraint_factory_.basic().facingMode.setExact( | 411 constraint_factory_.basic().facingMode.setExact( |
378 blink::WebString::fromASCII("user")); | 412 blink::WebString::fromASCII("user")); |
379 result = SelectSettings(); | 413 result = SelectSettings(); |
380 EXPECT_TRUE(result.HasValue()); | 414 EXPECT_TRUE(result.HasValue()); |
381 EXPECT_EQ(::mojom::FacingMode::USER, result.facing_mode()); | |
382 // Only the high-res device supports user facing mode. Should select default | 415 // Only the high-res device supports user facing mode. Should select default |
383 // settings for everything else. | 416 // settings for everything else. |
384 EXPECT_EQ(high_res_device_->device_id, result.device_id()); | 417 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
| 418 EXPECT_EQ(::mojom::FacingMode::USER, high_res_device_->facing_mode); |
385 EXPECT_EQ(*high_res_closest_format_, result.Format()); | 419 EXPECT_EQ(*high_res_closest_format_, result.Format()); |
386 EXPECT_EQ(media::PowerLineFrequency::FREQUENCY_DEFAULT, | 420 EXPECT_EQ(media::PowerLineFrequency::FREQUENCY_DEFAULT, |
387 result.PowerLineFrequency()); | 421 result.PowerLineFrequency()); |
| 422 CheckTrackAdapterSettingsEqualsFormat(result); |
388 } | 423 } |
389 | 424 |
390 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryVideoKind) { | 425 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryVideoKind) { |
391 constraint_factory_.Reset(); | 426 constraint_factory_.Reset(); |
392 constraint_factory_.basic().videoKind.setExact( | 427 constraint_factory_.basic().videoKind.setExact( |
393 blink::WebString::fromASCII("depth")); | 428 blink::WebString::fromASCII("depth")); |
394 auto result = SelectSettings(); | 429 auto result = SelectSettings(); |
395 EXPECT_TRUE(result.HasValue()); | 430 EXPECT_TRUE(result.HasValue()); |
396 EXPECT_EQ(kDeviceID4, result.device_id()); | 431 EXPECT_EQ(kDeviceID4, result.device_id()); |
397 EXPECT_EQ(media::PIXEL_FORMAT_Y16, result.Format().pixel_format); | 432 EXPECT_EQ(media::PIXEL_FORMAT_Y16, result.Format().pixel_format); |
| 433 CheckTrackAdapterSettingsEqualsFormat(result); |
398 | 434 |
399 constraint_factory_.basic().videoKind.setExact( | 435 constraint_factory_.basic().videoKind.setExact( |
400 blink::WebString::fromASCII("color")); | 436 blink::WebString::fromASCII("color")); |
401 result = SelectSettings(); | 437 result = SelectSettings(); |
402 EXPECT_TRUE(result.HasValue()); | 438 EXPECT_TRUE(result.HasValue()); |
403 EXPECT_EQ(default_device_->device_id, result.device_id()); | 439 EXPECT_EQ(default_device_->device_id, result.device_id()); |
| 440 CheckTrackAdapterSettingsEqualsFormat(result); |
404 } | 441 } |
405 | 442 |
406 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryPowerLineFrequency) { | 443 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryPowerLineFrequency) { |
407 constraint_factory_.Reset(); | 444 constraint_factory_.Reset(); |
408 const media::PowerLineFrequency kPowerLineFrequencies[] = { | 445 const media::PowerLineFrequency kPowerLineFrequencies[] = { |
409 media::PowerLineFrequency::FREQUENCY_50HZ, | 446 media::PowerLineFrequency::FREQUENCY_50HZ, |
410 media::PowerLineFrequency::FREQUENCY_60HZ}; | 447 media::PowerLineFrequency::FREQUENCY_60HZ}; |
411 for (auto power_line_frequency : kPowerLineFrequencies) { | 448 for (auto power_line_frequency : kPowerLineFrequencies) { |
412 constraint_factory_.basic().googPowerLineFrequency.setExact( | 449 constraint_factory_.basic().googPowerLineFrequency.setExact( |
413 static_cast<long>(power_line_frequency)); | 450 static_cast<long>(power_line_frequency)); |
414 auto result = SelectSettings(); | 451 auto result = SelectSettings(); |
415 EXPECT_TRUE(result.HasValue()); | 452 EXPECT_TRUE(result.HasValue()); |
416 EXPECT_EQ(power_line_frequency, result.PowerLineFrequency()); | 453 EXPECT_EQ(power_line_frequency, result.PowerLineFrequency()); |
417 // The default device and settings closest to the default should be | 454 // The default device and settings closest to the default should be |
418 // selected. | 455 // selected. |
419 EXPECT_EQ(default_device_->device_id, result.device_id()); | 456 EXPECT_EQ(default_device_->device_id, result.device_id()); |
420 EXPECT_EQ(default_device_->facing_mode, result.facing_mode()); | |
421 EXPECT_EQ(*default_closest_format_, result.Format()); | 457 EXPECT_EQ(*default_closest_format_, result.Format()); |
| 458 CheckTrackAdapterSettingsEqualsFormat(result); |
422 } | 459 } |
423 } | 460 } |
424 | 461 |
425 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryNoiseReduction) { | 462 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryNoiseReduction) { |
426 constraint_factory_.Reset(); | 463 constraint_factory_.Reset(); |
427 const bool kNoiseReductionValues[] = {true, false}; | 464 const bool kNoiseReductionValues[] = {true, false}; |
428 for (auto noise_reduction : kNoiseReductionValues) { | 465 for (auto noise_reduction : kNoiseReductionValues) { |
429 constraint_factory_.basic().googNoiseReduction.setExact(noise_reduction); | 466 constraint_factory_.basic().googNoiseReduction.setExact(noise_reduction); |
430 auto result = SelectSettings(); | 467 auto result = SelectSettings(); |
431 EXPECT_TRUE(result.HasValue()); | 468 EXPECT_TRUE(result.HasValue()); |
432 EXPECT_EQ(noise_reduction, result.noise_reduction()); | 469 EXPECT_EQ(noise_reduction, result.noise_reduction()); |
433 // The default device and settings closest to the default should be | 470 // The default device and settings closest to the default should be |
434 // selected. | 471 // selected. |
435 EXPECT_EQ(default_device_->device_id, result.device_id()); | 472 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()); | 473 EXPECT_EQ(*default_closest_format_, result.Format()); |
| 474 CheckTrackAdapterSettingsEqualsFormat(result); |
438 } | 475 } |
439 } | 476 } |
440 | 477 |
441 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryExactHeight) { | 478 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryExactHeight) { |
442 constraint_factory_.Reset(); | 479 constraint_factory_.Reset(); |
443 const int kHeight = MediaStreamVideoSource::kDefaultHeight; | 480 const int kHeight = MediaStreamVideoSource::kDefaultHeight; |
444 constraint_factory_.basic().height.setExact(kHeight); | 481 constraint_factory_.basic().height.setExact(kHeight); |
445 auto result = SelectSettings(); | 482 auto result = SelectSettings(); |
446 EXPECT_TRUE(result.HasValue()); | 483 EXPECT_TRUE(result.HasValue()); |
447 // All devices in |capabilities_| support the requested height. The algorithm | 484 // All devices in |capabilities_| support the requested height. The algorithm |
448 // should prefer the first device that supports the requested height natively, | 485 // should prefer the first device that supports the requested height natively, |
449 // which is the low-res device. | 486 // which is the low-res device. |
450 EXPECT_EQ(low_res_device_->device_id, result.device_id()); | 487 EXPECT_EQ(low_res_device_->device_id, result.device_id()); |
451 EXPECT_EQ(kHeight, result.Height()); | 488 EXPECT_EQ(kHeight, result.Height()); |
| 489 EXPECT_EQ(kHeight, result.track_adapter_settings().max_height); |
452 | 490 |
453 const int kLargeHeight = 1500; | 491 const int kLargeHeight = 1500; |
454 constraint_factory_.basic().height.setExact(kLargeHeight); | 492 constraint_factory_.basic().height.setExact(kLargeHeight); |
455 result = SelectSettings(); | 493 result = SelectSettings(); |
456 EXPECT_TRUE(result.HasValue()); | 494 EXPECT_TRUE(result.HasValue()); |
457 // Only the high-res device at the highest resolution supports the requested | 495 // Only the high-res device at the highest resolution supports the requested |
458 // height, even if not natively. | 496 // height, even if not natively. |
459 EXPECT_EQ(high_res_device_->device_id, result.device_id()); | 497 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
460 EXPECT_EQ(*high_res_highest_format_, result.Format()); | 498 EXPECT_EQ(*high_res_highest_format_, result.Format()); |
| 499 EXPECT_EQ(kLargeHeight, result.track_adapter_settings().max_height); |
| 500 EXPECT_EQ(std::round(kLargeHeight * AspectRatio(*high_res_highest_format_)), |
| 501 result.track_adapter_settings().max_width); |
461 } | 502 } |
462 | 503 |
463 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryMinHeight) { | 504 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryMinHeight) { |
464 constraint_factory_.Reset(); | 505 constraint_factory_.Reset(); |
465 const int kHeight = MediaStreamVideoSource::kDefaultHeight; | 506 const int kHeight = MediaStreamVideoSource::kDefaultHeight; |
466 constraint_factory_.basic().height.setMin(kHeight); | 507 constraint_factory_.basic().height.setMin(kHeight); |
467 auto result = SelectSettings(); | 508 auto result = SelectSettings(); |
468 EXPECT_TRUE(result.HasValue()); | 509 EXPECT_TRUE(result.HasValue()); |
469 // All devices in |capabilities_| support the requested height range. The | 510 // All devices in |capabilities_| support the requested height range. The |
470 // algorithm should prefer the default device. | 511 // algorithm should prefer the default device. |
471 EXPECT_EQ(default_device_->device_id, result.device_id()); | 512 EXPECT_EQ(default_device_->device_id, result.device_id()); |
472 EXPECT_LE(kHeight, result.Height()); | 513 EXPECT_LE(kHeight, result.Height()); |
| 514 EXPECT_EQ(result.Height(), result.track_adapter_settings().max_height); |
| 515 EXPECT_EQ(result.Width(), result.track_adapter_settings().max_width); |
| 516 EXPECT_EQ(static_cast<double>(result.Width()) / kHeight, |
| 517 result.track_adapter_settings().max_aspect_ratio); |
| 518 EXPECT_EQ(1.0 / result.Height(), |
| 519 result.track_adapter_settings().min_aspect_ratio); |
| 520 CheckTrackAdapterSettingsEqualsFrameRate(result); |
473 | 521 |
474 const int kLargeHeight = 1500; | 522 const int kLargeHeight = 1500; |
475 constraint_factory_.basic().height.setMin(kLargeHeight); | 523 constraint_factory_.basic().height.setMin(kLargeHeight); |
476 result = SelectSettings(); | 524 result = SelectSettings(); |
477 EXPECT_TRUE(result.HasValue()); | 525 EXPECT_TRUE(result.HasValue()); |
478 // Only the high-res device at the highest resolution supports the requested | 526 // Only the high-res device at the highest resolution supports the requested |
479 // height range. | 527 // height range. |
480 EXPECT_EQ(high_res_device_->device_id, result.device_id()); | 528 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
481 EXPECT_EQ(*high_res_highest_format_, result.Format()); | 529 EXPECT_EQ(*high_res_highest_format_, result.Format()); |
| 530 EXPECT_LE(kHeight, result.Height()); |
| 531 EXPECT_EQ(result.Height(), result.track_adapter_settings().max_height); |
| 532 EXPECT_EQ(result.Width(), result.track_adapter_settings().max_width); |
| 533 EXPECT_EQ(static_cast<double>(result.Width()) / kLargeHeight, |
| 534 result.track_adapter_settings().max_aspect_ratio); |
| 535 EXPECT_EQ(1.0 / result.Height(), |
| 536 result.track_adapter_settings().min_aspect_ratio); |
| 537 CheckTrackAdapterSettingsEqualsFrameRate(result); |
482 } | 538 } |
483 | 539 |
484 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryMaxHeight) { | 540 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryMaxHeight) { |
485 constraint_factory_.Reset(); | 541 constraint_factory_.Reset(); |
486 const int kLowHeight = 20; | 542 const int kLowHeight = 20; |
487 constraint_factory_.basic().height.setMax(kLowHeight); | 543 constraint_factory_.basic().height.setMax(kLowHeight); |
488 auto result = SelectSettings(); | 544 auto result = SelectSettings(); |
489 EXPECT_TRUE(result.HasValue()); | 545 EXPECT_TRUE(result.HasValue()); |
490 // All devices in |capabilities_| support the requested height range. The | 546 // All devices in |capabilities_| support the requested height range. The |
491 // algorithm should prefer the settings that natively exceed the requested | 547 // algorithm should prefer the settings that natively exceed the requested |
492 // maximum by the lowest amount. In this case it is the low-res device. | 548 // maximum by the lowest amount. In this case it is the low-res device. |
493 EXPECT_EQ(low_res_device_->device_id, result.device_id()); | 549 EXPECT_EQ(low_res_device_->device_id, result.device_id()); |
494 EXPECT_EQ(low_res_device_->formats[0], result.Format()); | 550 EXPECT_EQ(low_res_device_->formats[0], result.Format()); |
| 551 EXPECT_EQ(kLowHeight, result.track_adapter_settings().max_height); |
| 552 EXPECT_EQ(std::round(kLowHeight * AspectRatio(result.Format())), |
| 553 result.track_adapter_settings().max_width); |
| 554 EXPECT_EQ(static_cast<double>(result.Width()), |
| 555 result.track_adapter_settings().max_aspect_ratio); |
| 556 EXPECT_EQ(1.0 / kLowHeight, result.track_adapter_settings().min_aspect_ratio); |
| 557 CheckTrackAdapterSettingsEqualsFrameRate(result); |
495 } | 558 } |
496 | 559 |
497 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryHeightRange) { | 560 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryHeightRange) { |
498 constraint_factory_.Reset(); | 561 constraint_factory_.Reset(); |
499 { | 562 { |
500 const int kMinHeight = 480; | 563 const int kMinHeight = 480; |
501 const int kMaxHeight = 720; | 564 const int kMaxHeight = 720; |
502 constraint_factory_.basic().height.setMin(kMinHeight); | 565 constraint_factory_.basic().height.setMin(kMinHeight); |
503 constraint_factory_.basic().height.setMax(kMaxHeight); | 566 constraint_factory_.basic().height.setMax(kMaxHeight); |
504 auto result = SelectSettings(); | 567 auto result = SelectSettings(); |
505 EXPECT_TRUE(result.HasValue()); | 568 EXPECT_TRUE(result.HasValue()); |
506 EXPECT_GE(result.Height(), kMinHeight); | 569 EXPECT_GE(result.Height(), kMinHeight); |
507 EXPECT_LE(result.Height(), kMaxHeight); | 570 EXPECT_LE(result.Height(), kMaxHeight); |
508 // All devices in |capabilities_| support the constraint range. The | 571 // All devices in |capabilities_| support the constraint range. The |
509 // algorithm should prefer the default device since it has at least one | 572 // algorithm should prefer the default device since it has at least one |
510 // native format (the closest-to-default format) included in the requested | 573 // native format (the closest-to-default format) included in the requested |
511 // range. | 574 // range. |
512 EXPECT_EQ(default_device_->device_id, result.device_id()); | 575 EXPECT_EQ(default_device_->device_id, result.device_id()); |
513 EXPECT_EQ(*default_closest_format_, result.Format()); | 576 EXPECT_EQ(*default_closest_format_, result.Format()); |
| 577 EXPECT_EQ(result.Height(), result.track_adapter_settings().max_height); |
| 578 EXPECT_EQ(result.Width(), result.track_adapter_settings().max_width); |
| 579 EXPECT_EQ(static_cast<double>(result.Width()) / kMinHeight, |
| 580 result.track_adapter_settings().max_aspect_ratio); |
| 581 EXPECT_EQ(1.0 / result.Height(), |
| 582 result.track_adapter_settings().min_aspect_ratio); |
| 583 CheckTrackAdapterSettingsEqualsFrameRate(result); |
514 } | 584 } |
515 | 585 |
516 { | 586 { |
517 const int kMinHeight = 550; | 587 const int kMinHeight = 550; |
518 const int kMaxHeight = 650; | 588 const int kMaxHeight = 650; |
519 constraint_factory_.basic().height.setMin(kMinHeight); | 589 constraint_factory_.basic().height.setMin(kMinHeight); |
520 constraint_factory_.basic().height.setMax(kMaxHeight); | 590 constraint_factory_.basic().height.setMax(kMaxHeight); |
521 auto result = SelectSettings(); | 591 auto result = SelectSettings(); |
522 EXPECT_TRUE(result.HasValue()); | 592 EXPECT_TRUE(result.HasValue()); |
523 EXPECT_GE(result.Height(), kMinHeight); | 593 EXPECT_GE(result.Height(), kMinHeight); |
524 EXPECT_LE(result.Height(), kMaxHeight); | 594 EXPECT_LE(result.Height(), kMaxHeight); |
525 // In this case, the algorithm should prefer the low-res device since it is | 595 // In this case, the algorithm should prefer the low-res device since it is |
526 // the first device with a native format (800x600) included in the requested | 596 // the first device with a native format (800x600) included in the requested |
527 // range. | 597 // range. |
528 EXPECT_EQ(low_res_device_->device_id, result.device_id()); | 598 EXPECT_EQ(low_res_device_->device_id, result.device_id()); |
529 EXPECT_EQ(800, result.Width()); | 599 EXPECT_EQ(800, result.Width()); |
530 EXPECT_EQ(600, result.Height()); | 600 EXPECT_EQ(600, result.Height()); |
| 601 EXPECT_EQ(result.Height(), result.track_adapter_settings().max_height); |
| 602 EXPECT_EQ(result.Width(), result.track_adapter_settings().max_width); |
| 603 EXPECT_EQ(static_cast<double>(result.Width()) / kMinHeight, |
| 604 result.track_adapter_settings().max_aspect_ratio); |
| 605 EXPECT_EQ(1.0 / result.Height(), |
| 606 result.track_adapter_settings().min_aspect_ratio); |
| 607 CheckTrackAdapterSettingsEqualsFrameRate(result); |
531 } | 608 } |
532 | 609 |
533 { | 610 { |
534 const int kMinHeight = 700; | 611 const int kMinHeight = 700; |
535 const int kMaxHeight = 800; | 612 const int kMaxHeight = 800; |
536 constraint_factory_.basic().height.setMin(kMinHeight); | 613 constraint_factory_.basic().height.setMin(kMinHeight); |
537 constraint_factory_.basic().height.setMax(kMaxHeight); | 614 constraint_factory_.basic().height.setMax(kMaxHeight); |
538 auto result = SelectSettings(); | 615 auto result = SelectSettings(); |
539 EXPECT_TRUE(result.HasValue()); | 616 EXPECT_TRUE(result.HasValue()); |
540 EXPECT_GE(result.Height(), kMinHeight); | 617 EXPECT_GE(result.Height(), kMinHeight); |
541 EXPECT_LE(result.Height(), kMaxHeight); | 618 EXPECT_LE(result.Height(), kMaxHeight); |
542 // In this case, the algorithm should prefer the high-res device since it is | 619 // In this case, the algorithm should prefer the high-res device since it is |
543 // the only device with a native format (1280x720) included in the requested | 620 // the only device with a native format (1280x720) included in the requested |
544 // range. | 621 // range. |
545 EXPECT_EQ(high_res_device_->device_id, result.device_id()); | 622 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
546 EXPECT_EQ(1280, result.Width()); | 623 EXPECT_EQ(1280, result.Width()); |
547 EXPECT_EQ(720, result.Height()); | 624 EXPECT_EQ(720, result.Height()); |
| 625 EXPECT_EQ(result.Height(), result.track_adapter_settings().max_height); |
| 626 EXPECT_EQ(result.Width(), result.track_adapter_settings().max_width); |
| 627 EXPECT_EQ(static_cast<double>(result.Width()) / kMinHeight, |
| 628 result.track_adapter_settings().max_aspect_ratio); |
| 629 EXPECT_EQ(1.0 / result.Height(), |
| 630 result.track_adapter_settings().min_aspect_ratio); |
| 631 CheckTrackAdapterSettingsEqualsFrameRate(result); |
548 } | 632 } |
549 } | 633 } |
550 | 634 |
551 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, IdealHeight) { | 635 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, IdealHeight) { |
552 constraint_factory_.Reset(); | 636 constraint_factory_.Reset(); |
553 { | 637 { |
554 const int kIdealHeight = 480; | 638 const int kIdealHeight = 480; |
555 constraint_factory_.basic().height.setIdeal(kIdealHeight); | 639 constraint_factory_.basic().height.setIdeal(kIdealHeight); |
556 auto result = SelectSettings(); | 640 auto result = SelectSettings(); |
557 EXPECT_TRUE(result.HasValue()); | 641 EXPECT_TRUE(result.HasValue()); |
558 // The algorithm should select the first device that supports the ideal | 642 // The algorithm should select the first device that supports the ideal |
559 // height natively. | 643 // height natively. |
560 EXPECT_EQ(low_res_device_->device_id, result.device_id()); | 644 EXPECT_EQ(low_res_device_->device_id, result.device_id()); |
561 EXPECT_EQ(kIdealHeight, result.Height()); | 645 EXPECT_EQ(kIdealHeight, result.Height()); |
| 646 CheckTrackAdapterSettingsEqualsFormat(result); |
562 } | 647 } |
563 | 648 |
564 { | 649 { |
565 const int kIdealHeight = 481; | 650 const int kIdealHeight = 481; |
566 constraint_factory_.basic().height.setIdeal(kIdealHeight); | 651 constraint_factory_.basic().height.setIdeal(kIdealHeight); |
567 auto result = SelectSettings(); | 652 auto result = SelectSettings(); |
568 EXPECT_TRUE(result.HasValue()); | 653 EXPECT_TRUE(result.HasValue()); |
569 // In this case, the default device is selected because it can satisfy the | 654 // In this case, the default device is selected because it can satisfy the |
570 // ideal at a lower cost than the other devices (500 vs 600 or 720). | 655 // ideal at a lower cost than the other devices (500 vs 600 or 720). |
571 // Note that a native resolution of 480 is further from the ideal than | 656 // Note that a native resolution of 480 is further from the ideal than |
572 // 500 cropped to 480. | 657 // 500 cropped to 480. |
573 EXPECT_EQ(default_device_->device_id, result.device_id()); | 658 EXPECT_EQ(default_device_->device_id, result.device_id()); |
574 EXPECT_EQ(*default_closest_format_, result.Format()); | 659 EXPECT_EQ(*default_closest_format_, result.Format()); |
| 660 // The track is cropped to the ideal height, maintaining the source aspect |
| 661 // ratio. |
| 662 EXPECT_EQ(kIdealHeight, result.track_adapter_settings().max_height); |
| 663 EXPECT_EQ(std::round(kIdealHeight * AspectRatio(result.Format())), |
| 664 result.track_adapter_settings().max_width); |
| 665 EXPECT_EQ(result.Width(), result.track_adapter_settings().max_aspect_ratio); |
| 666 EXPECT_EQ(1.0 / result.Height(), |
| 667 result.track_adapter_settings().min_aspect_ratio); |
| 668 CheckTrackAdapterSettingsEqualsFrameRate(result); |
575 } | 669 } |
576 | 670 |
577 { | 671 { |
578 const int kIdealHeight = 1079; | 672 const int kIdealHeight = 1079; |
579 constraint_factory_.basic().height.setIdeal(kIdealHeight); | 673 constraint_factory_.basic().height.setIdeal(kIdealHeight); |
580 auto result = SelectSettings(); | 674 auto result = SelectSettings(); |
581 EXPECT_TRUE(result.HasValue()); | 675 EXPECT_TRUE(result.HasValue()); |
582 // In this case, the high-res device has two configurations that satisfy | 676 // In this case, the high-res device has two configurations that satisfy |
583 // the ideal value (1920x1080 and 2304x1536). Select the one with shortest | 677 // the ideal value (1920x1080 and 2304x1536). Select the one with shortest |
584 // native distance to the ideal value (1920x1080). | 678 // native distance to the ideal value (1920x1080). |
585 EXPECT_EQ(high_res_device_->device_id, result.device_id()); | 679 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
586 EXPECT_EQ(1920, result.Width()); | 680 EXPECT_EQ(1920, result.Width()); |
587 EXPECT_EQ(1080, result.Height()); | 681 EXPECT_EQ(1080, result.Height()); |
| 682 EXPECT_EQ(kIdealHeight, result.track_adapter_settings().max_height); |
| 683 EXPECT_EQ(std::round(kIdealHeight * AspectRatio(result.Format())), |
| 684 result.track_adapter_settings().max_width); |
| 685 EXPECT_EQ(result.Width(), result.track_adapter_settings().max_aspect_ratio); |
| 686 EXPECT_EQ(1.0 / result.Height(), |
| 687 result.track_adapter_settings().min_aspect_ratio); |
| 688 CheckTrackAdapterSettingsEqualsFrameRate(result); |
588 } | 689 } |
589 | 690 |
590 { | 691 { |
591 const int kIdealHeight = 1200; | 692 const int kIdealHeight = 1200; |
592 constraint_factory_.basic().height.setIdeal(kIdealHeight); | 693 constraint_factory_.basic().height.setIdeal(kIdealHeight); |
593 auto result = SelectSettings(); | 694 auto result = SelectSettings(); |
594 EXPECT_TRUE(result.HasValue()); | 695 EXPECT_TRUE(result.HasValue()); |
595 // The algorithm must the select the only device that can satisfy the ideal, | 696 // The algorithm must the select the only device that can satisfy the ideal, |
596 // which is the high-res device at the highest resolution. | 697 // which is the high-res device at the highest resolution. |
597 EXPECT_EQ(high_res_device_->device_id, result.device_id()); | 698 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
598 EXPECT_EQ(*high_res_highest_format_, result.Format()); | 699 EXPECT_EQ(*high_res_highest_format_, result.Format()); |
| 700 EXPECT_EQ(kIdealHeight, result.track_adapter_settings().max_height); |
| 701 EXPECT_EQ(std::round(kIdealHeight * AspectRatio(result.Format())), |
| 702 result.track_adapter_settings().max_width); |
| 703 EXPECT_EQ(result.Width(), result.track_adapter_settings().max_aspect_ratio); |
| 704 EXPECT_EQ(1.0 / result.Height(), |
| 705 result.track_adapter_settings().min_aspect_ratio); |
| 706 CheckTrackAdapterSettingsEqualsFrameRate(result); |
599 } | 707 } |
600 } | 708 } |
601 | 709 |
602 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryExactWidth) { | 710 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryExactWidth) { |
603 constraint_factory_.Reset(); | 711 constraint_factory_.Reset(); |
604 const int kWidth = 640; | 712 const int kWidth = 640; |
605 constraint_factory_.basic().width.setExact(kWidth); | 713 constraint_factory_.basic().width.setExact(kWidth); |
606 auto result = SelectSettings(); | 714 auto result = SelectSettings(); |
607 EXPECT_TRUE(result.HasValue()); | 715 EXPECT_TRUE(result.HasValue()); |
608 // All devices in |capabilities_| support the requested width. The algorithm | 716 // All devices in |capabilities_| support the requested width. The algorithm |
609 // should prefer the first device that supports the requested width natively, | 717 // should prefer the first device that supports the requested width natively, |
610 // which is the low-res device. | 718 // which is the low-res device. |
611 EXPECT_EQ(low_res_device_->device_id, result.device_id()); | 719 EXPECT_EQ(low_res_device_->device_id, result.device_id()); |
612 EXPECT_EQ(kWidth, result.Width()); | 720 EXPECT_EQ(kWidth, result.Width()); |
| 721 EXPECT_EQ(std::round(kWidth / AspectRatio(result.Format())), |
| 722 result.track_adapter_settings().max_height); |
| 723 EXPECT_EQ(kWidth, result.track_adapter_settings().max_width); |
| 724 EXPECT_EQ(kWidth, result.track_adapter_settings().max_aspect_ratio); |
| 725 EXPECT_EQ(static_cast<double>(kWidth) / result.Height(), |
| 726 result.track_adapter_settings().min_aspect_ratio); |
| 727 CheckTrackAdapterSettingsEqualsFrameRate(result); |
613 | 728 |
614 const int kLargeWidth = 2000; | 729 const int kLargeWidth = 2000; |
615 constraint_factory_.basic().width.setExact(kLargeWidth); | 730 constraint_factory_.basic().width.setExact(kLargeWidth); |
616 result = SelectSettings(); | 731 result = SelectSettings(); |
617 EXPECT_TRUE(result.HasValue()); | 732 EXPECT_TRUE(result.HasValue()); |
618 EXPECT_LE(kLargeWidth, result.Width()); | 733 EXPECT_LE(kLargeWidth, result.Width()); |
619 // Only the high-res device at the highest resolution supports the requested | 734 // Only the high-res device at the highest resolution supports the requested |
620 // width, even if not natively. | 735 // width, even if not natively. |
621 EXPECT_EQ(high_res_device_->device_id, result.device_id()); | 736 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
622 EXPECT_EQ(*high_res_highest_format_, result.Format()); | 737 EXPECT_EQ(*high_res_highest_format_, result.Format()); |
| 738 EXPECT_EQ(std::round(kLargeWidth / AspectRatio(result.Format())), |
| 739 result.track_adapter_settings().max_height); |
| 740 EXPECT_EQ(kLargeWidth, result.track_adapter_settings().max_width); |
| 741 EXPECT_EQ(kLargeWidth, result.track_adapter_settings().max_aspect_ratio); |
| 742 EXPECT_EQ(static_cast<double>(kLargeWidth) / result.Height(), |
| 743 result.track_adapter_settings().min_aspect_ratio); |
| 744 CheckTrackAdapterSettingsEqualsFrameRate(result); |
623 } | 745 } |
624 | 746 |
625 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryMinWidth) { | 747 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryMinWidth) { |
626 constraint_factory_.Reset(); | 748 constraint_factory_.Reset(); |
627 const int kWidth = 640; | 749 const int kWidth = 640; |
628 constraint_factory_.basic().width.setMin(kWidth); | 750 constraint_factory_.basic().width.setMin(kWidth); |
629 auto result = SelectSettings(); | 751 auto result = SelectSettings(); |
630 EXPECT_TRUE(result.HasValue()); | 752 EXPECT_TRUE(result.HasValue()); |
631 // All devices in |capabilities_| support the requested width range. The | 753 // All devices in |capabilities_| support the requested width range. The |
632 // algorithm should prefer the default device at 1000x1000, which is the | 754 // algorithm should prefer the default device at 1000x1000, which is the |
633 // first configuration that satisfies the minimum width. | 755 // first configuration that satisfies the minimum width. |
634 EXPECT_EQ(default_device_->device_id, result.device_id()); | 756 EXPECT_EQ(default_device_->device_id, result.device_id()); |
635 EXPECT_LE(kWidth, result.Width()); | 757 EXPECT_LE(kWidth, result.Width()); |
636 EXPECT_EQ(1000, result.Width()); | 758 EXPECT_EQ(1000, result.Width()); |
637 EXPECT_EQ(1000, result.Height()); | 759 EXPECT_EQ(1000, result.Height()); |
| 760 EXPECT_EQ(result.Height(), result.track_adapter_settings().max_height); |
| 761 EXPECT_EQ(result.Width(), result.track_adapter_settings().max_width); |
| 762 EXPECT_EQ(result.Width(), result.track_adapter_settings().max_aspect_ratio); |
| 763 EXPECT_EQ(static_cast<double>(kWidth) / result.Height(), |
| 764 result.track_adapter_settings().min_aspect_ratio); |
| 765 CheckTrackAdapterSettingsEqualsFrameRate(result); |
638 | 766 |
639 const int kLargeWidth = 2000; | 767 const int kLargeWidth = 2000; |
640 constraint_factory_.basic().width.setMin(kLargeWidth); | 768 constraint_factory_.basic().width.setMin(kLargeWidth); |
641 result = SelectSettings(); | 769 result = SelectSettings(); |
642 EXPECT_TRUE(result.HasValue()); | 770 EXPECT_TRUE(result.HasValue()); |
643 // Only the high-res device at the highest resolution supports the requested | 771 // Only the high-res device at the highest resolution supports the requested |
644 // minimum width. | 772 // minimum width. |
645 EXPECT_EQ(high_res_device_->device_id, result.device_id()); | 773 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
646 EXPECT_LE(kLargeWidth, result.Width()); | 774 EXPECT_LE(kLargeWidth, result.Width()); |
647 EXPECT_EQ(*high_res_highest_format_, result.Format()); | 775 EXPECT_EQ(*high_res_highest_format_, result.Format()); |
| 776 EXPECT_EQ(result.Height(), result.track_adapter_settings().max_height); |
| 777 EXPECT_EQ(result.Width(), result.track_adapter_settings().max_width); |
| 778 EXPECT_EQ(result.Width(), result.track_adapter_settings().max_aspect_ratio); |
| 779 EXPECT_EQ(static_cast<double>(kLargeWidth) / result.Height(), |
| 780 result.track_adapter_settings().min_aspect_ratio); |
| 781 CheckTrackAdapterSettingsEqualsFrameRate(result); |
648 } | 782 } |
649 | 783 |
650 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryMaxWidth) { | 784 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryMaxWidth) { |
651 constraint_factory_.Reset(); | 785 constraint_factory_.Reset(); |
652 const int kLowWidth = 30; | 786 const int kLowWidth = 30; |
653 constraint_factory_.basic().width.setMax(kLowWidth); | 787 constraint_factory_.basic().width.setMax(kLowWidth); |
654 auto result = SelectSettings(); | 788 auto result = SelectSettings(); |
655 EXPECT_TRUE(result.HasValue()); | 789 EXPECT_TRUE(result.HasValue()); |
656 // All devices in |capabilities_| support the requested width range. The | 790 // All devices in |capabilities_| support the requested width range. The |
657 // algorithm should prefer the settings that natively exceed the requested | 791 // algorithm should prefer the settings that natively exceed the requested |
658 // maximum by the lowest amount. In this case it is the low-res device at its | 792 // maximum by the lowest amount. In this case it is the low-res device at its |
659 // lowest resolution. | 793 // lowest resolution. |
660 EXPECT_EQ(low_res_device_->device_id, result.device_id()); | 794 EXPECT_EQ(low_res_device_->device_id, result.device_id()); |
661 EXPECT_EQ(low_res_device_->formats[0], result.Format()); | 795 EXPECT_EQ(low_res_device_->formats[0], result.Format()); |
| 796 // The track is cropped to kLowWidth and keeps the source aspect ratio. |
| 797 EXPECT_EQ(std::round(kLowWidth / AspectRatio(result.Format())), |
| 798 result.track_adapter_settings().max_height); |
| 799 EXPECT_EQ(kLowWidth, result.track_adapter_settings().max_width); |
| 800 EXPECT_EQ(kLowWidth, result.track_adapter_settings().max_aspect_ratio); |
| 801 EXPECT_EQ(1.0 / result.Height(), |
| 802 result.track_adapter_settings().min_aspect_ratio); |
| 803 CheckTrackAdapterSettingsEqualsFrameRate(result); |
662 } | 804 } |
663 | 805 |
664 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryWidthRange) { | 806 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryWidthRange) { |
665 constraint_factory_.Reset(); | 807 constraint_factory_.Reset(); |
666 { | 808 { |
667 const int kMinWidth = 640; | 809 const int kMinWidth = 640; |
668 const int kMaxWidth = 1280; | 810 const int kMaxWidth = 1280; |
669 constraint_factory_.basic().width.setMin(kMinWidth); | 811 constraint_factory_.basic().width.setMin(kMinWidth); |
670 constraint_factory_.basic().width.setMax(kMaxWidth); | 812 constraint_factory_.basic().width.setMax(kMaxWidth); |
671 auto result = SelectSettings(); | 813 auto result = SelectSettings(); |
672 EXPECT_TRUE(result.HasValue()); | 814 EXPECT_TRUE(result.HasValue()); |
673 EXPECT_GE(result.Width(), kMinWidth); | 815 EXPECT_GE(result.Width(), kMinWidth); |
674 EXPECT_LE(result.Width(), kMaxWidth); | 816 EXPECT_LE(result.Width(), kMaxWidth); |
675 // All devices in |capabilities_| support the constraint range. The | 817 // All devices in |capabilities_| support the constraint range. The |
676 // algorithm should prefer the default device since it has at least one | 818 // algorithm should prefer the default device since it has at least one |
677 // native format (1000x1000) included in the requested range. | 819 // native format (1000x1000) included in the requested range. |
678 EXPECT_EQ(default_device_->device_id, result.device_id()); | 820 EXPECT_EQ(default_device_->device_id, result.device_id()); |
679 EXPECT_EQ(1000, result.Width()); | 821 EXPECT_EQ(1000, result.Width()); |
680 EXPECT_EQ(1000, result.Height()); | 822 EXPECT_EQ(1000, result.Height()); |
| 823 EXPECT_EQ(result.Height(), result.track_adapter_settings().max_height); |
| 824 EXPECT_EQ(result.Width(), result.track_adapter_settings().max_width); |
| 825 EXPECT_EQ(result.Width(), result.track_adapter_settings().max_aspect_ratio); |
| 826 EXPECT_EQ(static_cast<double>(kMinWidth) / result.Height(), |
| 827 result.track_adapter_settings().min_aspect_ratio); |
| 828 CheckTrackAdapterSettingsEqualsFrameRate(result); |
681 } | 829 } |
682 | 830 |
683 { | 831 { |
684 const int kMinWidth = 750; | 832 const int kMinWidth = 750; |
685 const int kMaxWidth = 850; | 833 const int kMaxWidth = 850; |
686 constraint_factory_.basic().width.setMin(kMinWidth); | 834 constraint_factory_.basic().width.setMin(kMinWidth); |
687 constraint_factory_.basic().width.setMax(kMaxWidth); | 835 constraint_factory_.basic().width.setMax(kMaxWidth); |
688 auto result = SelectSettings(); | 836 auto result = SelectSettings(); |
689 EXPECT_TRUE(result.HasValue()); | 837 EXPECT_TRUE(result.HasValue()); |
690 EXPECT_GE(result.Width(), kMinWidth); | 838 EXPECT_GE(result.Width(), kMinWidth); |
691 EXPECT_LE(result.Width(), kMaxWidth); | 839 EXPECT_LE(result.Width(), kMaxWidth); |
692 // In this case, the algorithm should prefer the low-res device since it is | 840 // In this case, the algorithm should prefer the low-res device since it is |
693 // the first device with a native format (800x600) included in the requested | 841 // the first device with a native format (800x600) included in the requested |
694 // range. | 842 // range. |
695 EXPECT_EQ(low_res_device_->device_id, result.device_id()); | 843 EXPECT_EQ(low_res_device_->device_id, result.device_id()); |
696 EXPECT_EQ(800, result.Width()); | 844 EXPECT_EQ(800, result.Width()); |
697 EXPECT_EQ(600, result.Height()); | 845 EXPECT_EQ(600, result.Height()); |
| 846 EXPECT_EQ(result.Height(), result.track_adapter_settings().max_height); |
| 847 EXPECT_EQ(result.Width(), result.track_adapter_settings().max_width); |
| 848 EXPECT_EQ(result.Width(), result.track_adapter_settings().max_aspect_ratio); |
| 849 EXPECT_EQ(static_cast<double>(kMinWidth) / result.Height(), |
| 850 result.track_adapter_settings().min_aspect_ratio); |
| 851 CheckTrackAdapterSettingsEqualsFrameRate(result); |
698 } | 852 } |
699 | 853 |
700 { | 854 { |
701 const int kMinWidth = 1900; | 855 const int kMinWidth = 1900; |
702 const int kMaxWidth = 2000; | 856 const int kMaxWidth = 2000; |
703 constraint_factory_.basic().width.setMin(kMinWidth); | 857 constraint_factory_.basic().width.setMin(kMinWidth); |
704 constraint_factory_.basic().width.setMax(kMaxWidth); | 858 constraint_factory_.basic().width.setMax(kMaxWidth); |
705 auto result = SelectSettings(); | 859 auto result = SelectSettings(); |
706 EXPECT_TRUE(result.HasValue()); | 860 EXPECT_TRUE(result.HasValue()); |
707 EXPECT_GE(result.Width(), kMinWidth); | 861 EXPECT_GE(result.Width(), kMinWidth); |
708 EXPECT_LE(result.Width(), kMaxWidth); | 862 EXPECT_LE(result.Width(), kMaxWidth); |
709 // In this case, the algorithm should prefer the high-res device since it is | 863 // In this case, the algorithm should prefer the high-res device since it is |
710 // the only device with a native format (1920x1080) included in the | 864 // the only device with a native format (1920x1080) included in the |
711 // requested range. | 865 // requested range. |
712 EXPECT_EQ(high_res_device_->device_id, result.device_id()); | 866 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
713 EXPECT_EQ(1920, result.Width()); | 867 EXPECT_EQ(1920, result.Width()); |
714 EXPECT_EQ(1080, result.Height()); | 868 EXPECT_EQ(1080, result.Height()); |
| 869 EXPECT_EQ(result.Height(), result.track_adapter_settings().max_height); |
| 870 EXPECT_EQ(result.Width(), result.track_adapter_settings().max_width); |
| 871 EXPECT_EQ(result.Width(), result.track_adapter_settings().max_aspect_ratio); |
| 872 EXPECT_EQ(static_cast<double>(kMinWidth) / result.Height(), |
| 873 result.track_adapter_settings().min_aspect_ratio); |
| 874 CheckTrackAdapterSettingsEqualsFrameRate(result); |
715 } | 875 } |
716 } | 876 } |
717 | 877 |
718 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, IdealWidth) { | 878 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, IdealWidth) { |
719 constraint_factory_.Reset(); | 879 constraint_factory_.Reset(); |
720 { | 880 { |
721 const int kIdealWidth = 320; | 881 const int kIdealWidth = 320; |
722 constraint_factory_.basic().width.setIdeal(kIdealWidth); | 882 constraint_factory_.basic().width.setIdeal(kIdealWidth); |
723 auto result = SelectSettings(); | 883 auto result = SelectSettings(); |
724 EXPECT_TRUE(result.HasValue()); | 884 EXPECT_TRUE(result.HasValue()); |
725 // The algorithm should select the first device that supports the ideal | 885 // The algorithm should select the first device that supports the ideal |
726 // width natively, which is the low-res device at 320x240. | 886 // width natively, which is the low-res device at 320x240. |
727 EXPECT_EQ(low_res_device_->device_id, result.device_id()); | 887 EXPECT_EQ(low_res_device_->device_id, result.device_id()); |
728 EXPECT_EQ(kIdealWidth, result.Width()); | 888 EXPECT_EQ(kIdealWidth, result.Width()); |
| 889 EXPECT_EQ(std::round(kIdealWidth / AspectRatio(result.Format())), |
| 890 result.track_adapter_settings().max_height); |
| 891 EXPECT_EQ(kIdealWidth, result.track_adapter_settings().max_width); |
| 892 EXPECT_EQ(kIdealWidth, result.track_adapter_settings().max_aspect_ratio); |
| 893 EXPECT_EQ(1.0 / result.Height(), |
| 894 result.track_adapter_settings().min_aspect_ratio); |
| 895 CheckTrackAdapterSettingsEqualsFrameRate(result); |
729 } | 896 } |
730 | 897 |
731 { | 898 { |
732 const int kIdealWidth = 321; | 899 const int kIdealWidth = 321; |
733 constraint_factory_.basic().width.setIdeal(kIdealWidth); | 900 constraint_factory_.basic().width.setIdeal(kIdealWidth); |
734 auto result = SelectSettings(); | 901 auto result = SelectSettings(); |
735 EXPECT_TRUE(result.HasValue()); | 902 EXPECT_TRUE(result.HasValue()); |
736 // In this case, the default device is selected because it can satisfy the | 903 // In this case, the default device is selected because it can satisfy the |
737 // ideal at a lower cost than the other devices (500 vs 640). | 904 // ideal at a lower cost than the other devices (500 vs 640). |
738 // Note that a native resolution of 320 is further from the ideal value of | 905 // Note that a native resolution of 320 is further from the ideal value of |
739 // 321 than 500 cropped to 321. | 906 // 321 than 500 cropped to 321. |
740 EXPECT_EQ(default_device_->device_id, result.device_id()); | 907 EXPECT_EQ(default_device_->device_id, result.device_id()); |
741 EXPECT_EQ(*default_closest_format_, result.Format()); | 908 EXPECT_EQ(*default_closest_format_, result.Format()); |
| 909 // The track is cropped to kIdealWidth and keeps the source aspect ratio. |
| 910 EXPECT_EQ(std::round(kIdealWidth / AspectRatio(result.Format())), |
| 911 result.track_adapter_settings().max_height); |
| 912 EXPECT_EQ(kIdealWidth, result.track_adapter_settings().max_width); |
| 913 EXPECT_EQ(result.Width(), result.track_adapter_settings().max_aspect_ratio); |
| 914 EXPECT_EQ(1.0 / result.Height(), |
| 915 result.track_adapter_settings().min_aspect_ratio); |
| 916 CheckTrackAdapterSettingsEqualsFrameRate(result); |
742 } | 917 } |
743 | 918 |
744 { | 919 { |
745 const int kIdealWidth = 2000; | 920 const int kIdealWidth = 2000; |
746 constraint_factory_.basic().width.setIdeal(kIdealWidth); | 921 constraint_factory_.basic().width.setIdeal(kIdealWidth); |
747 auto result = SelectSettings(); | 922 auto result = SelectSettings(); |
748 EXPECT_TRUE(result.HasValue()); | 923 EXPECT_TRUE(result.HasValue()); |
749 // The algorithm must the select the only device that can satisfy the ideal. | 924 // The algorithm must the select the only device that can satisfy the ideal. |
750 EXPECT_EQ(high_res_device_->device_id, result.device_id()); | 925 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
751 EXPECT_EQ(*high_res_highest_format_, result.Format()); | 926 EXPECT_EQ(*high_res_highest_format_, result.Format()); |
| 927 // The track is cropped to kIdealWidth and keeps the source aspect ratio. |
| 928 EXPECT_EQ(std::round(kIdealWidth / AspectRatio(result.Format())), |
| 929 result.track_adapter_settings().max_height); |
| 930 EXPECT_EQ(kIdealWidth, result.track_adapter_settings().max_width); |
| 931 EXPECT_EQ(result.Width(), result.track_adapter_settings().max_aspect_ratio); |
| 932 EXPECT_EQ(1.0 / result.Height(), |
| 933 result.track_adapter_settings().min_aspect_ratio); |
| 934 CheckTrackAdapterSettingsEqualsFrameRate(result); |
752 } | 935 } |
753 | 936 |
754 { | 937 { |
755 const int kIdealWidth = 3000; | 938 const int kIdealWidth = 3000; |
756 constraint_factory_.basic().width.setIdeal(kIdealWidth); | 939 constraint_factory_.basic().width.setIdeal(kIdealWidth); |
757 auto result = SelectSettings(); | 940 auto result = SelectSettings(); |
758 EXPECT_TRUE(result.HasValue()); | 941 EXPECT_TRUE(result.HasValue()); |
759 // The algorithm must the select the device and setting with less distance | 942 // The algorithm must the select the device and setting with less distance |
760 // to the ideal. | 943 // to the ideal. |
761 EXPECT_EQ(high_res_device_->device_id, result.device_id()); | 944 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
762 EXPECT_EQ(*high_res_highest_format_, result.Format()); | 945 EXPECT_EQ(*high_res_highest_format_, result.Format()); |
| 946 CheckTrackAdapterSettingsEqualsFormat(result); |
763 } | 947 } |
764 } | 948 } |
765 | 949 |
766 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryExactFrameRate) { | 950 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryExactFrameRate) { |
767 constraint_factory_.Reset(); | 951 constraint_factory_.Reset(); |
768 const double kFrameRate = MediaStreamVideoSource::kDefaultFrameRate; | 952 const double kFrameRate = MediaStreamVideoSource::kDefaultFrameRate; |
769 constraint_factory_.basic().frameRate.setExact(kFrameRate); | 953 constraint_factory_.basic().frameRate.setExact(kFrameRate); |
770 auto result = SelectSettings(); | 954 auto result = SelectSettings(); |
771 EXPECT_TRUE(result.HasValue()); | 955 EXPECT_TRUE(result.HasValue()); |
772 // All devices in |capabilities_| support the requested frame rate. The | 956 // All devices in |capabilities_| support the requested frame rate. The |
773 // algorithm should prefer the first device that supports the requested frame | 957 // algorithm should prefer the first device that supports the requested frame |
774 // rate natively, which is the low-res device at 640x480x30Hz. | 958 // rate natively, which is the low-res device at 640x480x30Hz. |
775 EXPECT_EQ(low_res_device_->device_id, result.device_id()); | 959 EXPECT_EQ(low_res_device_->device_id, result.device_id()); |
776 EXPECT_EQ(kFrameRate, result.FrameRate()); | 960 EXPECT_EQ(kFrameRate, result.FrameRate()); |
777 EXPECT_EQ(640, result.Width()); | 961 EXPECT_EQ(640, result.Width()); |
778 EXPECT_EQ(480, result.Height()); | 962 EXPECT_EQ(480, result.Height()); |
| 963 CheckTrackAdapterSettingsEqualsResolution(result); |
| 964 CheckTrackAdapterSettingsEqualsFrameRate(result, kFrameRate); |
779 | 965 |
780 const double kLargeFrameRate = 50; | 966 const double kLargeFrameRate = 50; |
781 constraint_factory_.basic().frameRate.setExact(kLargeFrameRate); | 967 constraint_factory_.basic().frameRate.setExact(kLargeFrameRate); |
782 result = SelectSettings(); | 968 result = SelectSettings(); |
783 EXPECT_TRUE(result.HasValue()); | 969 EXPECT_TRUE(result.HasValue()); |
784 // Only the high-res device supports the requested frame rate, even if not | 970 // Only the high-res device supports the requested frame rate, even if not |
785 // natively. The least expensive configuration that supports the requested | 971 // natively. The least expensive configuration that supports the requested |
786 // frame rate is 1280x720x60Hz. | 972 // frame rate is 1280x720x60Hz. |
787 EXPECT_EQ(high_res_device_->device_id, result.device_id()); | 973 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
788 EXPECT_EQ(60.0, result.FrameRate()); | 974 EXPECT_EQ(60.0, result.FrameRate()); |
789 EXPECT_EQ(1280, result.Width()); | 975 EXPECT_EQ(1280, result.Width()); |
790 EXPECT_EQ(720, result.Height()); | 976 EXPECT_EQ(720, result.Height()); |
| 977 CheckTrackAdapterSettingsEqualsResolution(result); |
| 978 CheckTrackAdapterSettingsEqualsFrameRate(result, kLargeFrameRate); |
791 } | 979 } |
792 | 980 |
793 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryMinFrameRate) { | 981 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryMinFrameRate) { |
794 constraint_factory_.Reset(); | 982 constraint_factory_.Reset(); |
795 const double kFrameRate = MediaStreamVideoSource::kDefaultFrameRate; | 983 const double kFrameRate = MediaStreamVideoSource::kDefaultFrameRate; |
796 constraint_factory_.basic().frameRate.setMin(kFrameRate); | 984 constraint_factory_.basic().frameRate.setMin(kFrameRate); |
797 auto result = SelectSettings(); | 985 auto result = SelectSettings(); |
798 EXPECT_TRUE(result.HasValue()); | 986 EXPECT_TRUE(result.HasValue()); |
799 // All devices in |capabilities_| support the requested frame-rate range. The | 987 // All devices in |capabilities_| support the requested frame-rate range. The |
800 // algorithm should prefer the default device. | 988 // algorithm should prefer the default device. |
801 EXPECT_EQ(default_device_->device_id, result.device_id()); | 989 EXPECT_EQ(default_device_->device_id, result.device_id()); |
802 // The format closest to the default satisfies the constraint. | 990 // The format closest to the default satisfies the constraint. |
803 EXPECT_EQ(*default_closest_format_, result.Format()); | 991 EXPECT_EQ(*default_closest_format_, result.Format()); |
| 992 CheckTrackAdapterSettingsEqualsFormat(result); |
804 | 993 |
805 const double kLargeFrameRate = 50; | 994 const double kLargeFrameRate = 50; |
806 constraint_factory_.basic().frameRate.setMin(kLargeFrameRate); | 995 constraint_factory_.basic().frameRate.setMin(kLargeFrameRate); |
807 result = SelectSettings(); | 996 result = SelectSettings(); |
808 EXPECT_TRUE(result.HasValue()); | 997 EXPECT_TRUE(result.HasValue()); |
809 // Only the high-res device supports the requested frame-rate range. | 998 // Only the high-res device supports the requested frame-rate range. |
810 // The least expensive configuration is 1280x720x60Hz. | 999 // The least expensive configuration is 1280x720x60Hz. |
811 EXPECT_EQ(high_res_device_->device_id, result.device_id()); | 1000 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
812 EXPECT_LE(kLargeFrameRate, result.FrameRate()); | 1001 EXPECT_LE(kLargeFrameRate, result.FrameRate()); |
813 EXPECT_EQ(1280, result.Width()); | 1002 EXPECT_EQ(1280, result.Width()); |
814 EXPECT_EQ(720, result.Height()); | 1003 EXPECT_EQ(720, result.Height()); |
| 1004 CheckTrackAdapterSettingsEqualsFormat(result); |
815 } | 1005 } |
816 | 1006 |
817 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryMaxFrameRate) { | 1007 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryMaxFrameRate) { |
818 constraint_factory_.Reset(); | 1008 constraint_factory_.Reset(); |
819 const double kLowFrameRate = 10; | 1009 const double kLowFrameRate = 10; |
820 constraint_factory_.basic().frameRate.setMax(kLowFrameRate); | 1010 constraint_factory_.basic().frameRate.setMax(kLowFrameRate); |
821 auto result = SelectSettings(); | 1011 auto result = SelectSettings(); |
822 EXPECT_TRUE(result.HasValue()); | 1012 EXPECT_TRUE(result.HasValue()); |
823 // All devices in |capabilities_| support the requested frame-rate range. The | 1013 // All devices in |capabilities_| support the requested frame-rate range. The |
824 // algorithm should prefer the settings that natively exceed the requested | 1014 // algorithm should prefer the settings that natively exceed the requested |
825 // maximum by the lowest amount. In this case it is the high-res device with | 1015 // maximum by the lowest amount. In this case it is the high-res device with |
826 // default resolution . | 1016 // default resolution . |
827 EXPECT_EQ(high_res_device_->device_id, result.device_id()); | 1017 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
828 EXPECT_EQ(kLowFrameRate, result.FrameRate()); | 1018 EXPECT_EQ(kLowFrameRate, result.FrameRate()); |
829 EXPECT_EQ(MediaStreamVideoSource::kDefaultHeight, result.Height()); | 1019 EXPECT_EQ(MediaStreamVideoSource::kDefaultHeight, result.Height()); |
830 EXPECT_EQ(MediaStreamVideoSource::kDefaultWidth, result.Width()); | 1020 EXPECT_EQ(MediaStreamVideoSource::kDefaultWidth, result.Width()); |
| 1021 CheckTrackAdapterSettingsEqualsResolution(result); |
| 1022 CheckTrackAdapterSettingsEqualsFrameRate(result, kLowFrameRate); |
831 } | 1023 } |
832 | 1024 |
833 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryFrameRateRange) { | 1025 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryFrameRateRange) { |
834 constraint_factory_.Reset(); | 1026 constraint_factory_.Reset(); |
835 { | 1027 { |
836 const double kMinFrameRate = 10; | 1028 const double kMinFrameRate = 10; |
837 const double kMaxFrameRate = 40; | 1029 const double kMaxFrameRate = 40; |
838 constraint_factory_.basic().frameRate.setMin(kMinFrameRate); | 1030 constraint_factory_.basic().frameRate.setMin(kMinFrameRate); |
839 constraint_factory_.basic().frameRate.setMax(kMaxFrameRate); | 1031 constraint_factory_.basic().frameRate.setMax(kMaxFrameRate); |
840 auto result = SelectSettings(); | 1032 auto result = SelectSettings(); |
841 EXPECT_TRUE(result.HasValue()); | 1033 EXPECT_TRUE(result.HasValue()); |
842 EXPECT_LE(kMinFrameRate, result.FrameRate()); | 1034 EXPECT_LE(kMinFrameRate, result.FrameRate()); |
843 EXPECT_GE(kMaxFrameRate, result.FrameRate()); | 1035 EXPECT_GE(kMaxFrameRate, result.FrameRate()); |
844 // All devices in |capabilities_| support the constraint range. The | 1036 // All devices in |capabilities_| support the constraint range. The |
845 // algorithm should prefer the default device since its closest-to-default | 1037 // algorithm should prefer the default device since its closest-to-default |
846 // format has a frame rate included in the requested range. | 1038 // format has a frame rate included in the requested range. |
847 EXPECT_EQ(default_device_->device_id, result.device_id()); | 1039 EXPECT_EQ(default_device_->device_id, result.device_id()); |
848 EXPECT_EQ(*default_closest_format_, result.Format()); | 1040 EXPECT_EQ(*default_closest_format_, result.Format()); |
| 1041 CheckTrackAdapterSettingsEqualsFormat(result); |
849 } | 1042 } |
850 | 1043 |
851 { | 1044 { |
852 const double kMinFrameRate = 25; | 1045 const double kMinFrameRate = 25; |
853 const double kMaxFrameRate = 35; | 1046 const double kMaxFrameRate = 35; |
854 constraint_factory_.basic().frameRate.setMin(kMinFrameRate); | 1047 constraint_factory_.basic().frameRate.setMin(kMinFrameRate); |
855 constraint_factory_.basic().frameRate.setMax(kMaxFrameRate); | 1048 constraint_factory_.basic().frameRate.setMax(kMaxFrameRate); |
856 auto result = SelectSettings(); | 1049 auto result = SelectSettings(); |
857 EXPECT_TRUE(result.HasValue()); | 1050 EXPECT_TRUE(result.HasValue()); |
858 EXPECT_GE(result.FrameRate(), kMinFrameRate); | 1051 EXPECT_GE(result.FrameRate(), kMinFrameRate); |
859 EXPECT_LE(result.FrameRate(), kMaxFrameRate); | 1052 EXPECT_LE(result.FrameRate(), kMaxFrameRate); |
860 // In this case, the algorithm should prefer the low-res device since it is | 1053 // In this case, the algorithm should prefer the low-res device since it is |
861 // the first device with a native frame rate included in the requested | 1054 // the first device with a native frame rate included in the requested |
862 // range. The default resolution should be preferred as secondary criterion. | 1055 // range. The default resolution should be preferred as secondary criterion. |
863 EXPECT_EQ(low_res_device_->device_id, result.device_id()); | 1056 EXPECT_EQ(low_res_device_->device_id, result.device_id()); |
864 EXPECT_EQ(*low_res_closest_format_, result.Format()); | 1057 EXPECT_EQ(*low_res_closest_format_, result.Format()); |
| 1058 CheckTrackAdapterSettingsEqualsFormat(result); |
865 } | 1059 } |
866 | 1060 |
867 { | 1061 { |
868 const double kMinFrameRate = 50; | 1062 const double kMinFrameRate = 50; |
869 const double kMaxFrameRate = 70; | 1063 const double kMaxFrameRate = 70; |
870 constraint_factory_.basic().frameRate.setMin(kMinFrameRate); | 1064 constraint_factory_.basic().frameRate.setMin(kMinFrameRate); |
871 constraint_factory_.basic().frameRate.setMax(kMaxFrameRate); | 1065 constraint_factory_.basic().frameRate.setMax(kMaxFrameRate); |
872 auto result = SelectSettings(); | 1066 auto result = SelectSettings(); |
873 EXPECT_TRUE(result.HasValue()); | 1067 EXPECT_TRUE(result.HasValue()); |
874 EXPECT_GE(result.FrameRate(), kMinFrameRate); | 1068 EXPECT_GE(result.FrameRate(), kMinFrameRate); |
875 EXPECT_LE(result.FrameRate(), kMaxFrameRate); | 1069 EXPECT_LE(result.FrameRate(), kMaxFrameRate); |
876 // In this case, the algorithm should prefer the high-res device since it is | 1070 // In this case, the algorithm should prefer the high-res device since it is |
877 // the only device with a native format included in the requested range. | 1071 // the only device with a native format included in the requested range. |
878 // The 1280x720 resolution should be selected due to closeness to default | 1072 // The 1280x720 resolution should be selected due to closeness to default |
879 // settings, which is the second tie-breaker criterion that applies. | 1073 // settings, which is the second tie-breaker criterion that applies. |
880 EXPECT_EQ(high_res_device_->device_id, result.device_id()); | 1074 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
881 EXPECT_EQ(1280, result.Width()); | 1075 EXPECT_EQ(1280, result.Width()); |
882 EXPECT_EQ(720, result.Height()); | 1076 EXPECT_EQ(720, result.Height()); |
| 1077 CheckTrackAdapterSettingsEqualsFormat(result); |
883 } | 1078 } |
884 } | 1079 } |
885 | 1080 |
886 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, IdealFrameRate) { | 1081 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, IdealFrameRate) { |
887 constraint_factory_.Reset(); | 1082 constraint_factory_.Reset(); |
888 { | 1083 { |
889 const double kIdealFrameRate = MediaStreamVideoSource::kDefaultFrameRate; | 1084 const double kIdealFrameRate = MediaStreamVideoSource::kDefaultFrameRate; |
890 constraint_factory_.basic().frameRate.setIdeal(kIdealFrameRate); | 1085 constraint_factory_.basic().frameRate.setIdeal(kIdealFrameRate); |
891 auto result = SelectSettings(); | 1086 auto result = SelectSettings(); |
892 EXPECT_TRUE(result.HasValue()); | 1087 EXPECT_TRUE(result.HasValue()); |
893 // The algorithm should select the first configuration that supports the | 1088 // The algorithm should select the first configuration that supports the |
894 // ideal frame rate natively, which is the low-res device. Default | 1089 // ideal frame rate natively, which is the low-res device. Default |
895 // resolution should be selected as secondary criterion. | 1090 // resolution should be selected as secondary criterion. |
896 EXPECT_EQ(low_res_device_->device_id, result.device_id()); | 1091 EXPECT_EQ(low_res_device_->device_id, result.device_id()); |
897 EXPECT_EQ(*low_res_closest_format_, result.Format()); | 1092 EXPECT_EQ(*low_res_closest_format_, result.Format()); |
| 1093 CheckTrackAdapterSettingsEqualsResolution(result); |
| 1094 CheckTrackAdapterSettingsEqualsFrameRate(result, kIdealFrameRate); |
898 } | 1095 } |
899 | 1096 |
900 { | 1097 { |
901 const double kIdealFrameRate = 31; | 1098 const double kIdealFrameRate = 31; |
902 constraint_factory_.basic().frameRate.setIdeal(kIdealFrameRate); | 1099 constraint_factory_.basic().frameRate.setIdeal(kIdealFrameRate); |
903 auto result = SelectSettings(); | 1100 auto result = SelectSettings(); |
904 EXPECT_TRUE(result.HasValue()); | 1101 EXPECT_TRUE(result.HasValue()); |
905 // In this case, the default device is selected because it can satisfy the | 1102 // In this case, the default device is selected because it can satisfy the |
906 // ideal at a lower cost than the other devices (40 vs 60). | 1103 // ideal at a lower cost than the other devices (40 vs 60). |
907 // Note that a native frame rate of 30 is further from the ideal than | 1104 // Note that a native frame rate of 30 is further from the ideal than |
908 // 31 adjusted to 30. | 1105 // 31 adjusted to 30. |
909 EXPECT_EQ(default_device_->device_id, result.device_id()); | 1106 EXPECT_EQ(default_device_->device_id, result.device_id()); |
910 EXPECT_EQ(*default_closest_format_, result.Format()); | 1107 EXPECT_EQ(*default_closest_format_, result.Format()); |
| 1108 CheckTrackAdapterSettingsEqualsResolution(result); |
| 1109 CheckTrackAdapterSettingsEqualsFrameRate(result, kIdealFrameRate); |
911 } | 1110 } |
912 | 1111 |
913 { | 1112 { |
914 const double kIdealFrameRate = 55; | 1113 const double kIdealFrameRate = 55; |
915 constraint_factory_.basic().frameRate.setIdeal(kIdealFrameRate); | 1114 constraint_factory_.basic().frameRate.setIdeal(kIdealFrameRate); |
916 auto result = SelectSettings(); | 1115 auto result = SelectSettings(); |
917 EXPECT_TRUE(result.HasValue()); | 1116 EXPECT_TRUE(result.HasValue()); |
918 // The high-res device format 1280x720x60.0 must be selected because its | 1117 // The high-res device format 1280x720x60.0 must be selected because its |
919 // frame rate can satisfy the ideal frame rate and has resolution closest | 1118 // frame rate can satisfy the ideal frame rate and has resolution closest |
920 // to the default. | 1119 // to the default. |
921 EXPECT_EQ(high_res_device_->device_id, result.device_id()); | 1120 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
922 EXPECT_EQ(1280, result.Width()); | 1121 EXPECT_EQ(1280, result.Width()); |
923 EXPECT_EQ(720, result.Height()); | 1122 EXPECT_EQ(720, result.Height()); |
924 EXPECT_EQ(60, result.FrameRate()); | 1123 EXPECT_EQ(60, result.FrameRate()); |
| 1124 CheckTrackAdapterSettingsEqualsResolution(result); |
| 1125 CheckTrackAdapterSettingsEqualsFrameRate(result, kIdealFrameRate); |
925 } | 1126 } |
926 | 1127 |
927 { | 1128 { |
928 const double kIdealFrameRate = 100; | 1129 const double kIdealFrameRate = 100; |
929 constraint_factory_.basic().frameRate.setIdeal(kIdealFrameRate); | 1130 constraint_factory_.basic().frameRate.setIdeal(kIdealFrameRate); |
930 auto result = SelectSettings(); | 1131 auto result = SelectSettings(); |
931 EXPECT_TRUE(result.HasValue()); | 1132 EXPECT_TRUE(result.HasValue()); |
932 // The algorithm must select settings with frame rate closest to the ideal. | 1133 // The algorithm must select settings with frame rate closest to the ideal. |
933 // The high-res device format 1280x720x60.0 must be selected because its | 1134 // The high-res device format 1280x720x60.0 must be selected because its |
934 // frame rate it closest to the ideal value and it has resolution closest to | 1135 // frame rate it closest to the ideal value and it has resolution closest to |
935 // the default. | 1136 // the default. |
936 EXPECT_EQ(high_res_device_->device_id, result.device_id()); | 1137 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
937 EXPECT_EQ(1280, result.Width()); | 1138 EXPECT_EQ(1280, result.Width()); |
938 EXPECT_EQ(720, result.Height()); | 1139 EXPECT_EQ(720, result.Height()); |
939 EXPECT_EQ(60, result.FrameRate()); | 1140 EXPECT_EQ(60, result.FrameRate()); |
| 1141 CheckTrackAdapterSettingsEqualsFormat(result); |
940 } | 1142 } |
941 } | 1143 } |
942 | 1144 |
943 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryExactAspectRatio) { | 1145 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryExactAspectRatio) { |
944 constraint_factory_.Reset(); | 1146 constraint_factory_.Reset(); |
945 const double kAspectRatio = 4.0 / 3.0; | 1147 const double kAspectRatio = 4.0 / 3.0; |
946 constraint_factory_.basic().aspectRatio.setExact(kAspectRatio); | 1148 constraint_factory_.basic().aspectRatio.setExact(kAspectRatio); |
947 auto result = SelectSettings(); | 1149 auto result = SelectSettings(); |
948 EXPECT_TRUE(result.HasValue()); | 1150 EXPECT_TRUE(result.HasValue()); |
949 double min_width = 1.0; | 1151 double min_width = 1.0; |
950 double max_width = result.Width(); | 1152 double max_width = result.Width(); |
951 double min_height = 1.0; | 1153 double min_height = 1.0; |
952 double max_height = result.Height(); | 1154 double max_height = result.Height(); |
953 double min_aspect_ratio = min_width / max_height; | 1155 double min_aspect_ratio = min_width / max_height; |
954 double max_aspect_ratio = max_width / min_height; | 1156 double max_aspect_ratio = max_width / min_height; |
955 // The requested aspect ratio must be within the supported range. | 1157 // The requested aspect ratio must be within the supported range. |
956 EXPECT_GE(kAspectRatio, min_aspect_ratio); | 1158 EXPECT_GE(kAspectRatio, min_aspect_ratio); |
957 EXPECT_LE(kAspectRatio, max_aspect_ratio); | 1159 EXPECT_LE(kAspectRatio, max_aspect_ratio); |
958 // All devices in |capabilities_| support the requested aspect ratio. | 1160 // All devices in |capabilities_| support the requested aspect ratio. |
959 // The algorithm should prefer the first device that supports the requested | 1161 // The algorithm should prefer the first device that supports the requested |
960 // aspect ratio. | 1162 // aspect ratio. |
961 EXPECT_EQ(default_device_->device_id, result.device_id()); | 1163 EXPECT_EQ(default_device_->device_id, result.device_id()); |
962 EXPECT_EQ(*default_closest_format_, result.Format()); | 1164 EXPECT_EQ(*default_closest_format_, result.Format()); |
| 1165 EXPECT_EQ(std::round(result.Width() / kAspectRatio), |
| 1166 result.track_adapter_settings().max_height); |
| 1167 EXPECT_EQ(result.Width(), result.track_adapter_settings().max_width); |
| 1168 EXPECT_EQ(kAspectRatio, result.track_adapter_settings().min_aspect_ratio); |
| 1169 EXPECT_EQ(kAspectRatio, result.track_adapter_settings().max_aspect_ratio); |
| 1170 CheckTrackAdapterSettingsEqualsFrameRate(result); |
963 | 1171 |
964 const int kMinWidth = 500; | 1172 const int kMinWidth = 500; |
965 const int kMaxWidth = 1000; | 1173 const int kMaxWidth = 1000; |
966 const int kMaxHeight = 500; | 1174 const int kMaxHeight = 500; |
967 constraint_factory_.basic().height.setMax(kMaxHeight); | 1175 constraint_factory_.basic().height.setMax(kMaxHeight); |
968 constraint_factory_.basic().width.setMin(kMinWidth); | 1176 constraint_factory_.basic().width.setMin(kMinWidth); |
969 constraint_factory_.basic().width.setMax(kMaxWidth); | 1177 constraint_factory_.basic().width.setMax(kMaxWidth); |
970 constraint_factory_.basic().aspectRatio.setExact(kAspectRatio); | 1178 constraint_factory_.basic().aspectRatio.setExact(kAspectRatio); |
971 result = SelectSettings(); | 1179 result = SelectSettings(); |
972 EXPECT_TRUE(result.HasValue()); | 1180 EXPECT_TRUE(result.HasValue()); |
973 min_width = std::max(1, kMinWidth); | 1181 min_width = std::max(1, kMinWidth); |
974 max_width = std::min(result.Width(), kMaxWidth); | 1182 max_width = std::min(result.Width(), kMaxWidth); |
975 min_height = 1.0; | 1183 min_height = 1.0; |
976 max_height = std::min(result.Height(), kMaxHeight); | 1184 max_height = std::min(result.Height(), kMaxHeight); |
977 min_aspect_ratio = min_width / max_height; | 1185 min_aspect_ratio = min_width / max_height; |
978 max_aspect_ratio = max_width / min_height; | 1186 max_aspect_ratio = max_width / min_height; |
979 // The requested aspect ratio must be within the supported range. | 1187 // The requested aspect ratio must be within the supported range. |
980 EXPECT_GE(kAspectRatio, min_aspect_ratio); | 1188 EXPECT_GE(kAspectRatio, min_aspect_ratio); |
981 EXPECT_LE(kAspectRatio, max_aspect_ratio); | 1189 EXPECT_LE(kAspectRatio, max_aspect_ratio); |
982 // The default device can support the requested aspect ratio with the default | 1190 // The default device can support the requested aspect ratio with the default |
983 // settings (500x500) using cropping. | 1191 // settings (500x500) using cropping. |
984 EXPECT_EQ(default_device_->device_id, result.device_id()); | 1192 EXPECT_EQ(default_device_->device_id, result.device_id()); |
985 EXPECT_EQ(*default_closest_format_, result.Format()); | 1193 EXPECT_EQ(*default_closest_format_, result.Format()); |
| 1194 EXPECT_EQ(std::round(result.Width() / kAspectRatio), |
| 1195 result.track_adapter_settings().max_height); |
| 1196 EXPECT_EQ(result.Width(), result.track_adapter_settings().max_width); |
| 1197 EXPECT_EQ(kAspectRatio, result.track_adapter_settings().min_aspect_ratio); |
| 1198 EXPECT_EQ(kAspectRatio, result.track_adapter_settings().max_aspect_ratio); |
| 1199 CheckTrackAdapterSettingsEqualsFrameRate(result); |
986 | 1200 |
987 const int kMinHeight = 480; | 1201 const int kMinHeight = 480; |
988 constraint_factory_.basic().height.setMin(kMinHeight); | 1202 constraint_factory_.basic().height.setMin(kMinHeight); |
989 constraint_factory_.basic().height.setMax(kMaxHeight); | 1203 constraint_factory_.basic().height.setMax(kMaxHeight); |
990 constraint_factory_.basic().width.setMin(kMinWidth); | 1204 constraint_factory_.basic().width.setMin(kMinWidth); |
991 constraint_factory_.basic().width.setMax(kMaxWidth); | 1205 constraint_factory_.basic().width.setMax(kMaxWidth); |
992 constraint_factory_.basic().aspectRatio.setExact(kAspectRatio); | 1206 constraint_factory_.basic().aspectRatio.setExact(kAspectRatio); |
993 result = SelectSettings(); | 1207 result = SelectSettings(); |
994 EXPECT_TRUE(result.HasValue()); | 1208 EXPECT_TRUE(result.HasValue()); |
995 min_width = std::max(1, kMinWidth); | 1209 min_width = std::max(1, kMinWidth); |
996 max_width = std::min(result.Width(), kMaxWidth); | 1210 max_width = std::min(result.Width(), kMaxWidth); |
997 min_height = std::max(1, kMinHeight); | 1211 min_height = std::max(1, kMinHeight); |
998 max_height = std::min(result.Height(), kMaxHeight); | 1212 max_height = std::min(result.Height(), kMaxHeight); |
999 min_aspect_ratio = min_width / max_height; | 1213 min_aspect_ratio = min_width / max_height; |
1000 max_aspect_ratio = max_width / min_height; | 1214 max_aspect_ratio = max_width / min_height; |
1001 // The requested aspect ratio must be within the supported range. | 1215 // The requested aspect ratio must be within the supported range. |
1002 EXPECT_GE(kAspectRatio, min_aspect_ratio); | 1216 EXPECT_GE(kAspectRatio, min_aspect_ratio); |
1003 EXPECT_LE(kAspectRatio, max_aspect_ratio); | 1217 EXPECT_LE(kAspectRatio, max_aspect_ratio); |
1004 // Given resolution constraints, the default device with closest-to-default | 1218 // Given resolution constraints, the default device with closest-to-default |
1005 // settings cannot satisfy the required aspect ratio. | 1219 // settings cannot satisfy the required aspect ratio. |
1006 // The first device that can do it is the low-res device with a native | 1220 // The first device that can do it is the low-res device with a native |
1007 // resolution of 640x480. Higher resolutions for the default device are more | 1221 // resolution of 640x480. Higher resolutions for the default device are more |
1008 // penalized by the constraints than the default native resolution of the | 1222 // penalized by the constraints than the default native resolution of the |
1009 // low-res device. | 1223 // low-res device. |
1010 EXPECT_EQ(low_res_device_->device_id, result.device_id()); | 1224 EXPECT_EQ(low_res_device_->device_id, result.device_id()); |
1011 EXPECT_EQ(*low_res_closest_format_, result.Format()); | 1225 EXPECT_EQ(*low_res_closest_format_, result.Format()); |
| 1226 EXPECT_EQ(std::round(result.Width() / kAspectRatio), |
| 1227 result.track_adapter_settings().max_height); |
| 1228 EXPECT_EQ(result.Width(), result.track_adapter_settings().max_width); |
| 1229 EXPECT_EQ(kAspectRatio, result.track_adapter_settings().min_aspect_ratio); |
| 1230 EXPECT_EQ(kAspectRatio, result.track_adapter_settings().max_aspect_ratio); |
| 1231 CheckTrackAdapterSettingsEqualsFrameRate(result); |
1012 } | 1232 } |
1013 | 1233 |
1014 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryMinAspectRatio) { | 1234 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryMinAspectRatio) { |
1015 constraint_factory_.Reset(); | 1235 constraint_factory_.Reset(); |
1016 const double kAspectRatio = 4.0 / 3.0; | 1236 const double kAspectRatio = 4.0 / 3.0; |
1017 constraint_factory_.basic().aspectRatio.setMin(kAspectRatio); | 1237 constraint_factory_.basic().aspectRatio.setMin(kAspectRatio); |
1018 auto result = SelectSettings(); | 1238 auto result = SelectSettings(); |
1019 EXPECT_TRUE(result.HasValue()); | 1239 EXPECT_TRUE(result.HasValue()); |
1020 double max_width = result.Width(); | 1240 double max_width = result.Width(); |
1021 double min_height = 1.0; | 1241 double min_height = 1.0; |
1022 double max_aspect_ratio = max_width / min_height; | 1242 double max_aspect_ratio = max_width / min_height; |
1023 // Minimum constraint aspect ratio must be less than or equal to the maximum | 1243 // Minimum constraint aspect ratio must be less than or equal to the maximum |
1024 // supported by the source. | 1244 // supported by the source. |
1025 EXPECT_LE(kAspectRatio, max_aspect_ratio); | 1245 EXPECT_LE(kAspectRatio, max_aspect_ratio); |
1026 // All devices in |capabilities_| support the requested aspect-ratio range. | 1246 // All devices in |capabilities_| support the requested aspect-ratio range. |
1027 // The algorithm should prefer the first device that supports the requested | 1247 // The algorithm should prefer the first device that supports the requested |
1028 // aspect-ratio range, which in this case is the default device. | 1248 // aspect-ratio range, which in this case is the default device. |
1029 EXPECT_EQ(default_device_->device_id, result.device_id()); | 1249 EXPECT_EQ(default_device_->device_id, result.device_id()); |
1030 EXPECT_EQ(*default_closest_format_, result.Format()); | 1250 EXPECT_EQ(*default_closest_format_, result.Format()); |
| 1251 // Adjust the track resolution to use the minimum aspect ratio, which is |
| 1252 // greater than the source's aspect ratio. |
| 1253 EXPECT_EQ(std::round(result.Width() / kAspectRatio), |
| 1254 result.track_adapter_settings().max_height); |
| 1255 EXPECT_EQ(result.Width(), result.track_adapter_settings().max_width); |
| 1256 EXPECT_EQ(kAspectRatio, result.track_adapter_settings().min_aspect_ratio); |
| 1257 EXPECT_EQ(result.Width(), result.track_adapter_settings().max_aspect_ratio); |
| 1258 CheckTrackAdapterSettingsEqualsFrameRate(result); |
1031 | 1259 |
1032 const int kMinWidth = 500; | 1260 const int kMinWidth = 500; |
1033 const int kMaxWidth = 1000; | 1261 const int kMaxWidth = 1000; |
1034 const int kMinHeight = 480; | 1262 const int kMinHeight = 480; |
1035 const int kMaxHeight = 500; | 1263 const int kMaxHeight = 500; |
1036 constraint_factory_.basic().width.setMin(kMinWidth); | 1264 constraint_factory_.basic().width.setMin(kMinWidth); |
1037 constraint_factory_.basic().width.setMax(kMaxWidth); | 1265 constraint_factory_.basic().width.setMax(kMaxWidth); |
1038 constraint_factory_.basic().height.setMin(kMinHeight); | 1266 constraint_factory_.basic().height.setMin(kMinHeight); |
1039 constraint_factory_.basic().height.setMax(kMaxHeight); | 1267 constraint_factory_.basic().height.setMax(kMaxHeight); |
1040 constraint_factory_.basic().aspectRatio.setMin(kAspectRatio); | 1268 constraint_factory_.basic().aspectRatio.setMin(kAspectRatio); |
1041 result = SelectSettings(); | 1269 result = SelectSettings(); |
1042 EXPECT_TRUE(result.HasValue()); | 1270 EXPECT_TRUE(result.HasValue()); |
1043 max_width = std::min(result.Width(), kMaxWidth); | 1271 max_width = std::min(result.Width(), kMaxWidth); |
1044 min_height = std::max(1, kMinHeight); | 1272 min_height = std::max(1, kMinHeight); |
1045 max_aspect_ratio = max_width / min_height; | 1273 max_aspect_ratio = max_width / min_height; |
1046 // Minimum constraint aspect ratio must be less than or equal to the minimum | 1274 // Minimum constraint aspect ratio must be less than or equal to the minimum |
1047 // supported by the source. | 1275 // supported by the source. |
1048 EXPECT_LE(kAspectRatio, max_aspect_ratio); | 1276 EXPECT_LE(kAspectRatio, max_aspect_ratio); |
1049 // Given resolution constraints, the default device with closest-to-default | 1277 // Given resolution constraints, the default device with closest-to-default |
1050 // settings cannot satisfy the required minimum aspect ratio (maximum would | 1278 // settings cannot satisfy the required minimum aspect ratio (maximum would |
1051 // be 500/480). The first device that can is the low-res device with a native | 1279 // be 500/480). The first device that can is the low-res device with a native |
1052 // resolution of 640x480. | 1280 // resolution of 640x480. |
1053 // Higher resolutions for the default device are more penalized by the | 1281 // Higher resolutions for the default device are more penalized by the |
1054 // constraints than the default native resolution of the low-res device. | 1282 // constraints than the default native resolution of the low-res device. |
1055 EXPECT_EQ(low_res_device_->device_id, result.device_id()); | 1283 EXPECT_EQ(low_res_device_->device_id, result.device_id()); |
1056 EXPECT_EQ(*low_res_closest_format_, result.Format()); | 1284 EXPECT_EQ(*low_res_closest_format_, result.Format()); |
| 1285 // The source's native aspect ratio equals the minimum aspect ratio. |
| 1286 EXPECT_EQ(result.Height(), result.track_adapter_settings().max_height); |
| 1287 EXPECT_EQ(result.Width(), result.track_adapter_settings().max_width); |
| 1288 EXPECT_EQ(kAspectRatio, result.track_adapter_settings().min_aspect_ratio); |
| 1289 EXPECT_EQ(max_aspect_ratio, result.track_adapter_settings().max_aspect_ratio); |
| 1290 CheckTrackAdapterSettingsEqualsFrameRate(result); |
1057 } | 1291 } |
1058 | 1292 |
1059 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryMaxAspectRatio) { | 1293 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryMaxAspectRatio) { |
1060 constraint_factory_.Reset(); | 1294 constraint_factory_.Reset(); |
1061 const double kAspectRatio = 0.5; | 1295 const double kAspectRatio = 0.5; |
1062 constraint_factory_.basic().aspectRatio.setMax(kAspectRatio); | 1296 constraint_factory_.basic().aspectRatio.setMax(kAspectRatio); |
1063 auto result = SelectSettings(); | 1297 auto result = SelectSettings(); |
1064 EXPECT_TRUE(result.HasValue()); | 1298 EXPECT_TRUE(result.HasValue()); |
1065 double min_width = 1.0; | 1299 double min_width = 1.0; |
1066 double max_height = result.Height(); | 1300 double max_height = result.Height(); |
1067 double min_aspect_ratio = min_width / max_height; | 1301 double min_aspect_ratio = min_width / max_height; |
1068 // Minimum constraint aspect ratio must be less than or equal to the maximum | 1302 // Minimum constraint aspect ratio must be less than or equal to the maximum |
1069 // supported by the source. | 1303 // supported by the source. |
1070 EXPECT_GE(kAspectRatio, min_aspect_ratio); | 1304 EXPECT_GE(kAspectRatio, min_aspect_ratio); |
1071 // All devices in |capabilities_| support the requested aspect-ratio range. | 1305 // All devices in |capabilities_| support the requested aspect-ratio range. |
1072 // The algorithm should prefer the first device that supports the requested | 1306 // The algorithm should prefer the first device that supports the requested |
1073 // aspect-ratio range, which in this case is the default device. | 1307 // aspect-ratio range, which in this case is the default device. |
1074 EXPECT_EQ(default_device_->device_id, result.device_id()); | 1308 EXPECT_EQ(default_device_->device_id, result.device_id()); |
1075 EXPECT_EQ(*default_closest_format_, result.Format()); | 1309 EXPECT_EQ(*default_closest_format_, result.Format()); |
| 1310 // The track's aspect ratio is adjusted to the maximum, which is lower than |
| 1311 // the source's native aspect ratio. |
| 1312 EXPECT_EQ(result.Height(), result.track_adapter_settings().max_height); |
| 1313 EXPECT_EQ(std::round(result.Height() * kAspectRatio), |
| 1314 result.track_adapter_settings().max_width); |
| 1315 EXPECT_EQ(min_aspect_ratio, result.track_adapter_settings().min_aspect_ratio); |
| 1316 EXPECT_EQ(kAspectRatio, result.track_adapter_settings().max_aspect_ratio); |
| 1317 CheckTrackAdapterSettingsEqualsFrameRate(result); |
1076 | 1318 |
1077 const int kExactWidth = 360; | 1319 const int kExactWidth = 360; |
1078 const int kMinHeight = 360; | 1320 const int kMinHeight = 360; |
1079 const int kMaxHeight = 720; | 1321 const int kMaxHeight = 720; |
1080 constraint_factory_.basic().width.setExact(kExactWidth); | 1322 constraint_factory_.basic().width.setExact(kExactWidth); |
1081 constraint_factory_.basic().height.setMin(kMinHeight); | 1323 constraint_factory_.basic().height.setMin(kMinHeight); |
1082 constraint_factory_.basic().height.setMax(kMaxHeight); | 1324 constraint_factory_.basic().height.setMax(kMaxHeight); |
1083 constraint_factory_.basic().aspectRatio.setMax(kAspectRatio); | 1325 constraint_factory_.basic().aspectRatio.setMax(kAspectRatio); |
1084 result = SelectSettings(); | 1326 result = SelectSettings(); |
1085 EXPECT_TRUE(result.HasValue()); | 1327 EXPECT_TRUE(result.HasValue()); |
1086 min_width = std::max(1, kExactWidth); | 1328 min_width = std::max(1, kExactWidth); |
1087 max_height = std::min(result.Height(), kMaxHeight); | 1329 max_height = std::min(result.Height(), kMaxHeight); |
1088 min_aspect_ratio = min_width / max_height; | 1330 min_aspect_ratio = min_width / max_height; |
1089 // Minimum constraint aspect ratio must be less than or equal to the minimum | 1331 // Minimum constraint aspect ratio must be less than or equal to the minimum |
1090 // supported by the source. | 1332 // supported by the source. |
1091 EXPECT_GE(kAspectRatio, min_aspect_ratio); | 1333 EXPECT_GE(kAspectRatio, min_aspect_ratio); |
1092 // Given resolution constraints, the default device with closest-to-default | 1334 // Given resolution constraints, the default device with closest-to-default |
1093 // settings cannot satisfy the required maximum aspect ratio (maximum would | 1335 // settings cannot satisfy the required maximum aspect ratio (maximum would |
1094 // be 360/500). | 1336 // be 360/500). |
1095 // The high-res device with a native resolution of 1280x720 can support | 1337 // The high-res device with a native resolution of 1280x720 can support |
1096 // 360x720 with cropping with less penalty than the default device at | 1338 // 360x720 with cropping with less penalty than the default device at |
1097 // 1000x1000. | 1339 // 1000x1000. |
1098 EXPECT_EQ(high_res_device_->device_id, result.device_id()); | 1340 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
1099 EXPECT_EQ(1280, result.Width()); | 1341 EXPECT_EQ(1280, result.Width()); |
1100 EXPECT_EQ(720, result.Height()); | 1342 EXPECT_EQ(720, result.Height()); |
| 1343 // The track's aspect ratio is adjusted to the maximum, which is lower than |
| 1344 // the source's native aspect ratio. |
| 1345 EXPECT_EQ(result.Height(), result.track_adapter_settings().max_height); |
| 1346 EXPECT_EQ(std::round(result.Height() * kAspectRatio), |
| 1347 result.track_adapter_settings().max_width); |
| 1348 EXPECT_EQ(min_aspect_ratio, result.track_adapter_settings().min_aspect_ratio); |
| 1349 EXPECT_EQ(kAspectRatio, result.track_adapter_settings().max_aspect_ratio); |
| 1350 CheckTrackAdapterSettingsEqualsFrameRate(result); |
1101 } | 1351 } |
1102 | 1352 |
1103 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryAspectRatioRange) { | 1353 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, MandatoryAspectRatioRange) { |
1104 constraint_factory_.Reset(); | 1354 constraint_factory_.Reset(); |
1105 { | 1355 { |
1106 const double kMinAspectRatio = 0.5; | 1356 const double kMinAspectRatio = 0.5; |
1107 const double kMaxAspectRatio = 1.0; | 1357 const double kMaxAspectRatio = 1.0; |
1108 | 1358 |
1109 constraint_factory_.basic().aspectRatio.setMin(kMinAspectRatio); | 1359 constraint_factory_.basic().aspectRatio.setMin(kMinAspectRatio); |
1110 constraint_factory_.basic().aspectRatio.setMax(kMaxAspectRatio); | 1360 constraint_factory_.basic().aspectRatio.setMax(kMaxAspectRatio); |
1111 auto result = SelectSettings(); | 1361 auto result = SelectSettings(); |
1112 EXPECT_TRUE(result.HasValue()); | 1362 EXPECT_TRUE(result.HasValue()); |
1113 double min_width = 1.0; | 1363 double min_width = 1.0; |
1114 double max_width = result.Width(); | 1364 double max_width = result.Width(); |
1115 double min_height = 1.0; | 1365 double min_height = 1.0; |
1116 double max_height = result.Height(); | 1366 double max_height = result.Height(); |
1117 double min_aspect_ratio = min_width / max_height; | 1367 double min_aspect_ratio = min_width / max_height; |
1118 double max_aspect_ratio = max_width / min_height; | 1368 double max_aspect_ratio = max_width / min_height; |
1119 // Constraint aspect-ratio range must have nonempty intersection with | 1369 // Constraint aspect-ratio range must have nonempty intersection with |
1120 // supported range. | 1370 // supported range. |
1121 EXPECT_LE(kMinAspectRatio, max_aspect_ratio); | 1371 EXPECT_LE(kMinAspectRatio, max_aspect_ratio); |
1122 EXPECT_GE(kMaxAspectRatio, min_aspect_ratio); | 1372 EXPECT_GE(kMaxAspectRatio, min_aspect_ratio); |
1123 // All devices in |capabilities_| support the requested aspect-ratio range. | 1373 // All devices in |capabilities_| support the requested aspect-ratio range. |
1124 // The algorithm should prefer the first device that supports the requested | 1374 // The algorithm should prefer the first device that supports the requested |
1125 // aspect-ratio range, which in this case is the default device. | 1375 // aspect-ratio range, which in this case is the default device. |
1126 EXPECT_EQ(default_device_->device_id, result.device_id()); | 1376 EXPECT_EQ(default_device_->device_id, result.device_id()); |
1127 EXPECT_EQ(*default_closest_format_, result.Format()); | 1377 EXPECT_EQ(*default_closest_format_, result.Format()); |
| 1378 // The source's aspect ratio matches the maximum aspect ratio. No adjustment |
| 1379 // is required. |
| 1380 EXPECT_EQ(result.Height(), result.track_adapter_settings().max_height); |
| 1381 EXPECT_EQ(result.Width(), result.track_adapter_settings().max_width); |
| 1382 EXPECT_EQ(kMinAspectRatio, |
| 1383 result.track_adapter_settings().min_aspect_ratio); |
| 1384 EXPECT_EQ(kMaxAspectRatio, |
| 1385 result.track_adapter_settings().max_aspect_ratio); |
| 1386 CheckTrackAdapterSettingsEqualsFrameRate(result); |
1128 } | 1387 } |
1129 | 1388 |
1130 { | 1389 { |
1131 const double kMinAspectRatio = 3.0; | 1390 const double kMinAspectRatio = 3.0; |
1132 const double kMaxAspectRatio = 4.0; | 1391 const double kMaxAspectRatio = 4.0; |
1133 | 1392 |
1134 const long kExactHeight = 600; | 1393 const long kMinHeight = 600; |
1135 constraint_factory_.Reset(); | 1394 constraint_factory_.Reset(); |
1136 constraint_factory_.basic().height.setMin(kExactHeight); | 1395 constraint_factory_.basic().height.setMin(kMinHeight); |
1137 constraint_factory_.basic().aspectRatio.setMin(kMinAspectRatio); | 1396 constraint_factory_.basic().aspectRatio.setMin(kMinAspectRatio); |
1138 constraint_factory_.basic().aspectRatio.setMax(kMaxAspectRatio); | 1397 constraint_factory_.basic().aspectRatio.setMax(kMaxAspectRatio); |
1139 auto result = SelectSettings(); | 1398 auto result = SelectSettings(); |
1140 EXPECT_TRUE(result.HasValue()); | 1399 EXPECT_TRUE(result.HasValue()); |
1141 double min_width = 1.0; | 1400 double min_width = 1.0; |
1142 double max_width = result.Width(); | 1401 double max_width = result.Width(); |
1143 double min_height = 1.0; | 1402 double min_height = 1.0; |
1144 double max_height = result.Height(); | 1403 double max_height = result.Height(); |
1145 double min_aspect_ratio = min_width / max_height; | 1404 double min_aspect_ratio = min_width / max_height; |
1146 double max_aspect_ratio = max_width / min_height; | 1405 double max_aspect_ratio = max_width / min_height; |
1147 // Constraint aspect-ratio range must have nonempty intersection with | 1406 // Constraint aspect-ratio range must have nonempty intersection with |
1148 // supported range. | 1407 // supported range. |
1149 EXPECT_LE(kMinAspectRatio, max_aspect_ratio); | 1408 EXPECT_LE(kMinAspectRatio, max_aspect_ratio); |
1150 EXPECT_GE(kMaxAspectRatio, min_aspect_ratio); | 1409 EXPECT_GE(kMaxAspectRatio, min_aspect_ratio); |
1151 // The only device that supports the resolution and aspect ratio constraint | 1410 // The only device that supports the resolution and aspect ratio constraint |
1152 // is the high-res device. The 1920x1080 is the least expensive format. | 1411 // is the high-res device. The 1920x1080 is the least expensive format. |
1153 EXPECT_EQ(high_res_device_->device_id, result.device_id()); | 1412 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
1154 EXPECT_EQ(1920, result.Width()); | 1413 EXPECT_EQ(1920, result.Width()); |
1155 EXPECT_EQ(1080, result.Height()); | 1414 EXPECT_EQ(1080, result.Height()); |
| 1415 // The track is cropped to support the minimum aspect ratio. |
| 1416 EXPECT_EQ(std::round(result.Width() / kMinAspectRatio), |
| 1417 result.track_adapter_settings().max_height); |
| 1418 EXPECT_EQ(result.Width(), result.track_adapter_settings().max_width); |
| 1419 EXPECT_EQ(kMinAspectRatio, |
| 1420 result.track_adapter_settings().min_aspect_ratio); |
| 1421 EXPECT_EQ(static_cast<double>(result.Width()) / kMinHeight, |
| 1422 result.track_adapter_settings().max_aspect_ratio); |
| 1423 CheckTrackAdapterSettingsEqualsFrameRate(result); |
1156 } | 1424 } |
1157 } | 1425 } |
1158 | 1426 |
1159 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, IdealAspectRatio) { | 1427 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, IdealAspectRatio) { |
1160 constraint_factory_.Reset(); | 1428 constraint_factory_.Reset(); |
1161 { | 1429 { |
1162 const double kIdealAspectRatio = 0.5; | 1430 const double kIdealAspectRatio = 0.5; |
1163 constraint_factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); | 1431 constraint_factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); |
1164 auto result = SelectSettings(); | 1432 auto result = SelectSettings(); |
1165 EXPECT_TRUE(result.HasValue()); | 1433 EXPECT_TRUE(result.HasValue()); |
1166 double min_width = 1.0; | 1434 double min_width = 1.0; |
1167 double max_width = result.Width(); | 1435 double max_width = result.Width(); |
1168 double min_height = 1.0; | 1436 double min_height = 1.0; |
1169 double max_height = result.Height(); | 1437 double max_height = result.Height(); |
1170 double min_aspect_ratio = min_width / max_height; | 1438 double min_aspect_ratio = min_width / max_height; |
1171 double max_aspect_ratio = max_width / min_height; | 1439 double max_aspect_ratio = max_width / min_height; |
1172 // All devices in |capabilities_| support the ideal aspect-ratio. | 1440 // All devices in |capabilities_| support the ideal aspect-ratio. |
1173 // The algorithm should prefer the default device with closest-to-default | 1441 // The algorithm should prefer the default device with closest-to-default |
1174 // settings. | 1442 // settings. |
1175 EXPECT_LE(kIdealAspectRatio, max_aspect_ratio); | 1443 EXPECT_LE(kIdealAspectRatio, max_aspect_ratio); |
1176 EXPECT_GE(kIdealAspectRatio, min_aspect_ratio); | 1444 EXPECT_GE(kIdealAspectRatio, min_aspect_ratio); |
1177 EXPECT_EQ(default_device_->device_id, result.device_id()); | 1445 EXPECT_EQ(default_device_->device_id, result.device_id()); |
1178 EXPECT_EQ(*default_closest_format_, result.Format()); | 1446 EXPECT_EQ(*default_closest_format_, result.Format()); |
| 1447 // The track is cropped to support the ideal aspect ratio. |
| 1448 EXPECT_EQ(result.Height(), result.track_adapter_settings().max_height); |
| 1449 EXPECT_EQ(std::round(result.Height() * kIdealAspectRatio), |
| 1450 result.track_adapter_settings().max_width); |
| 1451 EXPECT_EQ(min_aspect_ratio, |
| 1452 result.track_adapter_settings().min_aspect_ratio); |
| 1453 EXPECT_EQ(max_aspect_ratio, |
| 1454 result.track_adapter_settings().max_aspect_ratio); |
| 1455 CheckTrackAdapterSettingsEqualsFrameRate(result); |
1179 } | 1456 } |
1180 | 1457 |
1181 { | 1458 { |
1182 const double kIdealAspectRatio = 1500.0; | 1459 const double kIdealAspectRatio = 1500.0; |
1183 constraint_factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); | 1460 constraint_factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); |
1184 auto result = SelectSettings(); | 1461 auto result = SelectSettings(); |
1185 EXPECT_TRUE(result.HasValue()); | 1462 EXPECT_TRUE(result.HasValue()); |
1186 // The only device that supports the ideal aspect ratio is the high-res | 1463 // The only device that supports the ideal aspect ratio is the high-res |
1187 // device. The least expensive way to support it with the 1920x1080 format | 1464 // device. |
1188 // cropped to 1500x1. | |
1189 EXPECT_EQ(high_res_device_->device_id, result.device_id()); | 1465 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
1190 EXPECT_EQ(1920, result.Width()); | 1466 EXPECT_EQ(1920, result.Width()); |
1191 EXPECT_EQ(1080, result.Height()); | 1467 EXPECT_EQ(1080, result.Height()); |
| 1468 // The most exact way to support the ideal aspect ratio would be to crop to |
| 1469 // 1500x1. However, the algorithm tries to crop to 1920x1.28 and rounds. |
| 1470 // In this case, the effect of rounding is noticeable because of the |
| 1471 // resulting low value for height. For more typical resolution values, |
| 1472 // the at-most 1-pixel error caused by rounding is not an issue. |
| 1473 EXPECT_EQ(std::round(result.Width() / kIdealAspectRatio), |
| 1474 result.track_adapter_settings().max_height); |
| 1475 EXPECT_EQ(result.Width(), result.track_adapter_settings().max_width); |
| 1476 EXPECT_EQ(1.0 / result.Height(), |
| 1477 result.track_adapter_settings().min_aspect_ratio); |
| 1478 EXPECT_EQ(result.Width(), result.track_adapter_settings().max_aspect_ratio); |
| 1479 CheckTrackAdapterSettingsEqualsFrameRate(result); |
1192 } | 1480 } |
1193 | 1481 |
1194 { | 1482 { |
1195 const double kIdealAspectRatio = 2000.0; | 1483 const double kIdealAspectRatio = 2000.0; |
1196 constraint_factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); | 1484 constraint_factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); |
1197 auto result = SelectSettings(); | 1485 auto result = SelectSettings(); |
1198 EXPECT_TRUE(result.HasValue()); | 1486 EXPECT_TRUE(result.HasValue()); |
1199 // The only device that supports the ideal aspect ratio is the high-res | 1487 // The only device that supports the ideal aspect ratio is the high-res |
1200 // device with its highest resolution, cropped to 2000x1. | 1488 // device with its highest resolution. |
1201 EXPECT_EQ(high_res_device_->device_id, result.device_id()); | 1489 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
1202 EXPECT_EQ(*high_res_highest_format_, result.Format()); | 1490 EXPECT_EQ(*high_res_highest_format_, result.Format()); |
| 1491 EXPECT_EQ(std::round(result.Width() / kIdealAspectRatio), |
| 1492 result.track_adapter_settings().max_height); |
| 1493 EXPECT_EQ(result.Width(), result.track_adapter_settings().max_width); |
| 1494 EXPECT_EQ(1.0 / result.Height(), |
| 1495 result.track_adapter_settings().min_aspect_ratio); |
| 1496 EXPECT_EQ(result.Width(), result.track_adapter_settings().max_aspect_ratio); |
| 1497 CheckTrackAdapterSettingsEqualsFrameRate(result); |
1203 } | 1498 } |
1204 | 1499 |
1205 { | 1500 { |
1206 const double kIdealAspectRatio = 4000.0; | 1501 const double kIdealAspectRatio = 4000.0; |
1207 constraint_factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); | 1502 constraint_factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); |
1208 auto result = SelectSettings(); | 1503 auto result = SelectSettings(); |
1209 EXPECT_TRUE(result.HasValue()); | 1504 EXPECT_TRUE(result.HasValue()); |
1210 // The configuration closest to the ideal aspect ratio is is the high-res | 1505 // The configuration closest to the ideal aspect ratio is is the high-res |
1211 // device with its highest resolution, cropped to 2304x1. | 1506 // device with its highest resolution, cropped to 2304x1. |
1212 EXPECT_EQ(high_res_device_->device_id, result.device_id()); | 1507 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
1213 EXPECT_EQ(*high_res_highest_format_, result.Format()); | 1508 EXPECT_EQ(*high_res_highest_format_, result.Format()); |
| 1509 // In this case there is no rounding error. |
| 1510 EXPECT_EQ(1, result.track_adapter_settings().max_height); |
| 1511 EXPECT_EQ(result.Width(), result.track_adapter_settings().max_width); |
| 1512 EXPECT_EQ(1.0 / result.Height(), |
| 1513 result.track_adapter_settings().min_aspect_ratio); |
| 1514 EXPECT_EQ(result.Width(), result.track_adapter_settings().max_aspect_ratio); |
| 1515 CheckTrackAdapterSettingsEqualsFrameRate(result); |
1214 } | 1516 } |
1215 | 1517 |
1216 { | 1518 { |
1217 const double kIdealAspectRatio = 2.0; | 1519 const double kIdealAspectRatio = 2.0; |
| 1520 const int kExactHeight = 400; |
1218 constraint_factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); | 1521 constraint_factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); |
1219 constraint_factory_.basic().height.setExact(400); | 1522 constraint_factory_.basic().height.setExact(kExactHeight); |
1220 auto result = SelectSettings(); | 1523 auto result = SelectSettings(); |
1221 EXPECT_TRUE(result.HasValue()); | 1524 EXPECT_TRUE(result.HasValue()); |
1222 // The first device to support the ideal aspect ratio and the resolution | 1525 // The first device to support the ideal aspect ratio and the resolution |
1223 // constraint is the low-res device. The 800x600 format cropped to 800x400 | 1526 // constraint is the low-res device. The 800x600 format cropped to 800x400 |
1224 // is the lest expensive way to achieve it. | 1527 // is the lest expensive way to achieve it. |
1225 EXPECT_EQ(low_res_device_->device_id, result.device_id()); | 1528 EXPECT_EQ(low_res_device_->device_id, result.device_id()); |
1226 EXPECT_EQ(800, result.Width()); | 1529 EXPECT_EQ(800, result.Width()); |
1227 EXPECT_EQ(600, result.Height()); | 1530 EXPECT_EQ(600, result.Height()); |
| 1531 EXPECT_EQ(kExactHeight, result.track_adapter_settings().max_height); |
| 1532 EXPECT_EQ(kExactHeight * kIdealAspectRatio, |
| 1533 result.track_adapter_settings().max_width); |
| 1534 EXPECT_EQ(1.0 / kExactHeight, |
| 1535 result.track_adapter_settings().min_aspect_ratio); |
| 1536 EXPECT_EQ(static_cast<double>(result.Width()) / kExactHeight, |
| 1537 result.track_adapter_settings().max_aspect_ratio); |
| 1538 CheckTrackAdapterSettingsEqualsFrameRate(result); |
1228 } | 1539 } |
1229 | 1540 |
1230 { | 1541 { |
1231 const double kIdealAspectRatio = 3.0; | 1542 const double kIdealAspectRatio = 3.0; |
| 1543 const int kExactHeight = 400; |
1232 constraint_factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); | 1544 constraint_factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); |
1233 constraint_factory_.basic().height.setExact(400); | 1545 constraint_factory_.basic().height.setExact(kExactHeight); |
1234 auto result = SelectSettings(); | 1546 auto result = SelectSettings(); |
1235 EXPECT_TRUE(result.HasValue()); | 1547 EXPECT_TRUE(result.HasValue()); |
1236 // The only device that supports the ideal aspect ratio and the resolution | 1548 // The only device that supports the ideal aspect ratio and the resolution |
1237 // constraint is the high-res device. The 1280x720 cropped to 1200x400 is | 1549 // constraint is the high-res device. The 1280x720 cropped to 1200x400 is |
1238 // the lest expensive way to achieve it. | 1550 // the lest expensive way to achieve it. |
1239 EXPECT_EQ(high_res_device_->device_id, result.device_id()); | 1551 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
1240 EXPECT_EQ(1280, result.Width()); | 1552 EXPECT_EQ(1280, result.Width()); |
1241 EXPECT_EQ(720, result.Height()); | 1553 EXPECT_EQ(720, result.Height()); |
| 1554 EXPECT_EQ(kExactHeight, result.track_adapter_settings().max_height); |
| 1555 EXPECT_EQ(kExactHeight * kIdealAspectRatio, |
| 1556 result.track_adapter_settings().max_width); |
| 1557 EXPECT_EQ(1.0 / kExactHeight, |
| 1558 result.track_adapter_settings().min_aspect_ratio); |
| 1559 EXPECT_EQ(static_cast<double>(result.Width()) / kExactHeight, |
| 1560 result.track_adapter_settings().max_aspect_ratio); |
| 1561 CheckTrackAdapterSettingsEqualsFrameRate(result); |
1242 } | 1562 } |
1243 } | 1563 } |
1244 | 1564 |
1245 // The "Advanced" tests check selection criteria involving advanced constraint | 1565 // The "Advanced" tests check selection criteria involving advanced constraint |
1246 // sets. | 1566 // sets. |
1247 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, | 1567 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, |
1248 AdvancedMinMaxResolutionFrameRate) { | 1568 AdvancedMinMaxResolutionFrameRate) { |
1249 constraint_factory_.Reset(); | 1569 constraint_factory_.Reset(); |
1250 blink::WebMediaTrackConstraintSet& advanced1 = | 1570 blink::WebMediaTrackConstraintSet& advanced1 = |
1251 constraint_factory_.AddAdvanced(); | 1571 constraint_factory_.AddAdvanced(); |
1252 advanced1.width.setMin(4000); | 1572 advanced1.width.setMin(4000); |
1253 advanced1.height.setMin(4000); | 1573 advanced1.height.setMin(4000); |
1254 // No device supports the first advanced set. This first advanced constraint | 1574 // No device supports the first advanced set. This first advanced constraint |
1255 // set is therefore ignored in all calls to SelectSettings(). | 1575 // set is therefore ignored in all calls to SelectSettings(). |
1256 // Tie-breaker rule that applies is closeness to default settings. | 1576 // Tie-breaker rule that applies is closeness to default settings. |
1257 auto result = SelectSettings(); | 1577 auto result = SelectSettings(); |
1258 EXPECT_EQ(default_device_->device_id, result.device_id()); | 1578 EXPECT_EQ(default_device_->device_id, result.device_id()); |
1259 EXPECT_EQ(*default_closest_format_, result.Format()); | 1579 EXPECT_EQ(*default_closest_format_, result.Format()); |
| 1580 CheckTrackAdapterSettingsEqualsFormat(result); |
1260 | 1581 |
1261 blink::WebMediaTrackConstraintSet& advanced2 = | 1582 blink::WebMediaTrackConstraintSet& advanced2 = |
1262 constraint_factory_.AddAdvanced(); | 1583 constraint_factory_.AddAdvanced(); |
1263 advanced2.width.setMin(320); | 1584 advanced2.width.setMin(320); |
1264 advanced2.height.setMin(240); | 1585 advanced2.height.setMin(240); |
1265 advanced2.width.setMax(640); | 1586 advanced2.width.setMax(640); |
1266 advanced2.height.setMax(480); | 1587 advanced2.height.setMax(480); |
1267 result = SelectSettings(); | 1588 result = SelectSettings(); |
1268 // The device that best supports this advanced set is the low-res device, | 1589 // The device that best supports this advanced set is the low-res device, |
1269 // which natively supports the maximum resolution. | 1590 // which natively supports the maximum resolution. |
1270 EXPECT_EQ(low_res_device_->device_id, result.device_id()); | 1591 EXPECT_EQ(low_res_device_->device_id, result.device_id()); |
1271 EXPECT_EQ(640, result.Width()); | 1592 EXPECT_EQ(640, result.Width()); |
1272 EXPECT_EQ(480, result.Height()); | 1593 EXPECT_EQ(480, result.Height()); |
| 1594 EXPECT_EQ(result.Height(), result.track_adapter_settings().max_height); |
| 1595 EXPECT_EQ(result.Width(), result.track_adapter_settings().max_width); |
| 1596 EXPECT_EQ(320.0 / 480.0, result.track_adapter_settings().min_aspect_ratio); |
| 1597 EXPECT_EQ(640.0 / 240.0, result.track_adapter_settings().max_aspect_ratio); |
| 1598 CheckTrackAdapterSettingsEqualsFrameRate(result); |
1273 | 1599 |
1274 blink::WebMediaTrackConstraintSet& advanced3 = | 1600 blink::WebMediaTrackConstraintSet& advanced3 = |
1275 constraint_factory_.AddAdvanced(); | 1601 constraint_factory_.AddAdvanced(); |
1276 advanced3.frameRate.setMax(10.0); | 1602 advanced3.frameRate.setMax(10.0); |
1277 result = SelectSettings(); | 1603 result = SelectSettings(); |
1278 EXPECT_TRUE(result.HasValue()); | 1604 EXPECT_TRUE(result.HasValue()); |
1279 // The high-res device natively supports the third advanced set in addition | 1605 // The high-res device natively supports the third advanced set in addition |
1280 // to the previous set and should be selected. | 1606 // to the previous set and should be selected. |
1281 EXPECT_EQ(high_res_device_->device_id, result.device_id()); | 1607 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
1282 EXPECT_EQ(640, result.Width()); | 1608 EXPECT_EQ(640, result.Width()); |
1283 EXPECT_EQ(480, result.Height()); | 1609 EXPECT_EQ(480, result.Height()); |
| 1610 EXPECT_EQ(result.Height(), result.track_adapter_settings().max_height); |
| 1611 EXPECT_EQ(result.Width(), result.track_adapter_settings().max_width); |
| 1612 EXPECT_EQ(320.0 / 480.0, result.track_adapter_settings().min_aspect_ratio); |
| 1613 EXPECT_EQ(640.0 / 240.0, result.track_adapter_settings().max_aspect_ratio); |
| 1614 CheckTrackAdapterSettingsEqualsFrameRate(result, 10.0); |
1284 | 1615 |
1285 blink::WebMediaTrackConstraintSet& advanced4 = | 1616 blink::WebMediaTrackConstraintSet& advanced4 = |
1286 constraint_factory_.AddAdvanced(); | 1617 constraint_factory_.AddAdvanced(); |
1287 advanced4.width.setMax(1000); | 1618 advanced4.width.setMax(1000); |
1288 advanced4.height.setMax(1000); | 1619 advanced4.height.setMax(1000); |
1289 result = SelectSettings(); | 1620 result = SelectSettings(); |
1290 // Even though the default device supports the resolution in the fourth | 1621 // Even though the default device supports the resolution in the fourth |
1291 // advanced natively, having better support for the previous sets has | 1622 // advanced natively, having better support for the previous sets has |
1292 // precedence, so the high-res device is selected. | 1623 // precedence, so the high-res device is selected. |
1293 EXPECT_TRUE(result.HasValue()); | 1624 EXPECT_TRUE(result.HasValue()); |
1294 EXPECT_EQ(high_res_device_->device_id, result.device_id()); | 1625 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
1295 EXPECT_EQ(640, result.Width()); | 1626 EXPECT_EQ(640, result.Width()); |
1296 EXPECT_EQ(480, result.Height()); | 1627 EXPECT_EQ(480, result.Height()); |
| 1628 EXPECT_EQ(result.Height(), result.track_adapter_settings().max_height); |
| 1629 EXPECT_EQ(result.Width(), result.track_adapter_settings().max_width); |
| 1630 EXPECT_EQ(320.0 / 480.0, result.track_adapter_settings().min_aspect_ratio); |
| 1631 EXPECT_EQ(640.0 / 240.0, result.track_adapter_settings().max_aspect_ratio); |
| 1632 CheckTrackAdapterSettingsEqualsFrameRate(result, 10.0); |
1297 | 1633 |
1298 constraint_factory_.basic().width.setIdeal(100); | 1634 constraint_factory_.basic().width.setIdeal(100); |
1299 constraint_factory_.basic().height.setIdeal(100); | 1635 constraint_factory_.basic().height.setIdeal(100); |
1300 result = SelectSettings(); | 1636 result = SelectSettings(); |
1301 EXPECT_TRUE(result.HasValue()); | 1637 EXPECT_TRUE(result.HasValue()); |
1302 // The high-res device at 600x400@10Hz supports all advanced sets and is | 1638 // The high-res device at 600x400@10Hz supports all advanced sets and is |
1303 // better at supporting the ideal value. | 1639 // better at supporting the ideal value. |
1304 // It beats 320x240@30Hz because the penalty for the native frame rate takes | 1640 // It beats 320x240@30Hz because the penalty for the native frame rate takes |
1305 // precedence over the native fitness distance. | 1641 // precedence over the native fitness distance. |
1306 // Both support standard fitness distance equally, since 600x400 can be | 1642 // Both support standard fitness distance equally, since 600x400 can be |
1307 // cropped to 320x240. | 1643 // cropped to 320x240. |
1308 EXPECT_EQ(high_res_device_->device_id, result.device_id()); | 1644 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
1309 EXPECT_EQ(600, result.Width()); | 1645 EXPECT_EQ(600, result.Width()); |
1310 EXPECT_EQ(400, result.Height()); | 1646 EXPECT_EQ(400, result.Height()); |
| 1647 EXPECT_EQ(320, result.track_adapter_settings().max_width); |
| 1648 EXPECT_EQ(240, result.track_adapter_settings().max_height); |
| 1649 EXPECT_EQ(320.0 / 400.0, result.track_adapter_settings().min_aspect_ratio); |
| 1650 EXPECT_EQ(600.0 / 240.0, result.track_adapter_settings().max_aspect_ratio); |
| 1651 CheckTrackAdapterSettingsEqualsFrameRate(result, 10.0); |
1311 | 1652 |
1312 constraint_factory_.basic().width.setIdeal(2000); | 1653 constraint_factory_.basic().width.setIdeal(2000); |
1313 constraint_factory_.basic().height.setIdeal(1500); | 1654 constraint_factory_.basic().height.setIdeal(1500); |
1314 result = SelectSettings(); | 1655 result = SelectSettings(); |
1315 EXPECT_TRUE(result.HasValue()); | 1656 EXPECT_TRUE(result.HasValue()); |
1316 // The high-res device at 640x480@10Hz is closer to the large ideal | 1657 // The high-res device at 640x480@10Hz is closer to the large ideal |
1317 // resolution. | 1658 // resolution. |
1318 EXPECT_EQ(high_res_device_->device_id, result.device_id()); | 1659 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
1319 EXPECT_EQ(640, result.Width()); | 1660 EXPECT_EQ(640, result.Width()); |
1320 EXPECT_EQ(480, result.Height()); | 1661 EXPECT_EQ(480, result.Height()); |
| 1662 EXPECT_EQ(640, result.track_adapter_settings().max_width); |
| 1663 EXPECT_EQ(480, result.track_adapter_settings().max_height); |
| 1664 EXPECT_EQ(320.0 / 480.0, result.track_adapter_settings().min_aspect_ratio); |
| 1665 EXPECT_EQ(640.0 / 240.0, result.track_adapter_settings().max_aspect_ratio); |
| 1666 CheckTrackAdapterSettingsEqualsFrameRate(result, 10.0); |
1321 } | 1667 } |
1322 | 1668 |
1323 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, | 1669 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, |
1324 AdvancedResolutionAndFrameRate) { | 1670 AdvancedResolutionAndFrameRate) { |
1325 constraint_factory_.Reset(); | 1671 constraint_factory_.Reset(); |
1326 blink::WebMediaTrackConstraintSet& advanced1 = | 1672 blink::WebMediaTrackConstraintSet& advanced1 = |
1327 constraint_factory_.AddAdvanced(); | 1673 constraint_factory_.AddAdvanced(); |
1328 advanced1.width.setExact(1920); | 1674 advanced1.width.setExact(1920); |
1329 advanced1.height.setExact(1080); | 1675 advanced1.height.setExact(1080); |
1330 blink::WebMediaTrackConstraintSet& advanced2 = | 1676 blink::WebMediaTrackConstraintSet& advanced2 = |
1331 constraint_factory_.AddAdvanced(); | 1677 constraint_factory_.AddAdvanced(); |
1332 advanced2.frameRate.setExact(60.0); | 1678 advanced2.frameRate.setExact(60.0); |
1333 blink::WebMediaTrackConstraintSet& advanced3 = | 1679 blink::WebMediaTrackConstraintSet& advanced3 = |
1334 constraint_factory_.AddAdvanced(); | 1680 constraint_factory_.AddAdvanced(); |
1335 advanced3.width.setExact(2304); | 1681 advanced3.width.setExact(2304); |
1336 advanced3.height.setExact(1536); | 1682 advanced3.height.setExact(1536); |
1337 auto result = SelectSettings(); | 1683 auto result = SelectSettings(); |
1338 EXPECT_TRUE(result.HasValue()); | 1684 EXPECT_TRUE(result.HasValue()); |
1339 // The high-res device is the only one that satisfies the first advanced | 1685 // The high-res device is the only one that satisfies the first advanced |
1340 // set. 2304x1536x10.0 satisfies sets 1 and 3, while 1920x1080x60.0 | 1686 // set. 2304x1536x10.0 satisfies sets 1 and 3, while 1920x1080x60.0 |
1341 // satisfies sets 1, and 2. The latter must be selected, regardless of | 1687 // satisfies sets 1, and 2. The latter must be selected, regardless of |
1342 // any other criteria. | 1688 // any other criteria. |
1343 EXPECT_EQ(high_res_device_->device_id, result.device_id()); | 1689 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
1344 EXPECT_EQ(1920, result.Width()); | 1690 EXPECT_EQ(1920, result.Width()); |
1345 EXPECT_EQ(1080, result.Height()); | 1691 EXPECT_EQ(1080, result.Height()); |
1346 EXPECT_EQ(60.0, result.FrameRate()); | 1692 EXPECT_EQ(60.0, result.FrameRate()); |
| 1693 EXPECT_EQ(1920, result.track_adapter_settings().max_width); |
| 1694 EXPECT_EQ(1080, result.track_adapter_settings().max_height); |
| 1695 EXPECT_EQ(1920.0 / 1080.0, result.track_adapter_settings().min_aspect_ratio); |
| 1696 EXPECT_EQ(1920.0 / 1080.0, result.track_adapter_settings().max_aspect_ratio); |
| 1697 CheckTrackAdapterSettingsEqualsFrameRate(result, 60.0); |
1347 } | 1698 } |
1348 | 1699 |
1349 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, AdvancedNoiseReduction) { | 1700 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, AdvancedNoiseReduction) { |
1350 constraint_factory_.Reset(); | 1701 constraint_factory_.Reset(); |
1351 blink::WebMediaTrackConstraintSet& advanced1 = | 1702 blink::WebMediaTrackConstraintSet& advanced1 = |
1352 constraint_factory_.AddAdvanced(); | 1703 constraint_factory_.AddAdvanced(); |
1353 advanced1.width.setMin(640); | 1704 advanced1.width.setMin(640); |
1354 advanced1.height.setMin(480); | 1705 advanced1.height.setMin(480); |
1355 blink::WebMediaTrackConstraintSet& advanced2 = | 1706 blink::WebMediaTrackConstraintSet& advanced2 = |
1356 constraint_factory_.AddAdvanced(); | 1707 constraint_factory_.AddAdvanced(); |
1357 advanced2.width.setMin(1920); | 1708 advanced2.width.setMin(1920); |
1358 advanced2.height.setMin(1080); | 1709 advanced2.height.setMin(1080); |
1359 advanced2.googNoiseReduction.setExact(false); | 1710 advanced2.googNoiseReduction.setExact(false); |
1360 auto result = SelectSettings(); | 1711 auto result = SelectSettings(); |
1361 EXPECT_TRUE(result.HasValue()); | 1712 EXPECT_TRUE(result.HasValue()); |
1362 EXPECT_EQ(high_res_device_->device_id, result.device_id()); | 1713 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
1363 EXPECT_LE(1920, result.Width()); | 1714 EXPECT_LE(1920, result.Width()); |
1364 EXPECT_LE(1080, result.Height()); | 1715 EXPECT_LE(1080, result.Height()); |
1365 EXPECT_TRUE(result.noise_reduction() && !*result.noise_reduction()); | 1716 EXPECT_TRUE(result.noise_reduction() && !*result.noise_reduction()); |
| 1717 EXPECT_EQ(result.Width(), result.track_adapter_settings().max_width); |
| 1718 EXPECT_EQ(result.Height(), result.track_adapter_settings().max_height); |
| 1719 EXPECT_EQ(1920.0 / result.Height(), |
| 1720 result.track_adapter_settings().min_aspect_ratio); |
| 1721 EXPECT_EQ(result.Width() / 1080.0, |
| 1722 result.track_adapter_settings().max_aspect_ratio); |
| 1723 CheckTrackAdapterSettingsEqualsFrameRate(result); |
1366 } | 1724 } |
1367 | 1725 |
1368 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, | 1726 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, |
1369 AdvancedContradictoryNoiseReduction) { | 1727 AdvancedContradictoryNoiseReduction) { |
1370 { | 1728 { |
1371 constraint_factory_.Reset(); | 1729 constraint_factory_.Reset(); |
1372 blink::WebMediaTrackConstraintSet& advanced1 = | 1730 blink::WebMediaTrackConstraintSet& advanced1 = |
1373 constraint_factory_.AddAdvanced(); | 1731 constraint_factory_.AddAdvanced(); |
1374 advanced1.width.setMin(640); | 1732 advanced1.width.setMin(640); |
1375 advanced1.height.setMin(480); | 1733 advanced1.height.setMin(480); |
1376 advanced1.googNoiseReduction.setExact(true); | 1734 advanced1.googNoiseReduction.setExact(true); |
1377 blink::WebMediaTrackConstraintSet& advanced2 = | 1735 blink::WebMediaTrackConstraintSet& advanced2 = |
1378 constraint_factory_.AddAdvanced(); | 1736 constraint_factory_.AddAdvanced(); |
1379 advanced2.width.setMin(1920); | 1737 advanced2.width.setMin(1920); |
1380 advanced2.height.setMin(1080); | 1738 advanced2.height.setMin(1080); |
1381 advanced2.googNoiseReduction.setExact(false); | 1739 advanced2.googNoiseReduction.setExact(false); |
1382 auto result = SelectSettings(); | 1740 auto result = SelectSettings(); |
1383 EXPECT_TRUE(result.HasValue()); | 1741 EXPECT_TRUE(result.HasValue()); |
1384 // The second advanced set cannot be satisfied because it contradicts the | 1742 // The second advanced set cannot be satisfied because it contradicts the |
1385 // first set. The default device supports the first set and should be | 1743 // first set. The default device supports the first set and should be |
1386 // selected. | 1744 // selected. |
1387 EXPECT_EQ(default_device_->device_id, result.device_id()); | 1745 EXPECT_EQ(default_device_->device_id, result.device_id()); |
1388 EXPECT_LE(640, result.Width()); | 1746 EXPECT_LE(640, result.Width()); |
1389 EXPECT_LE(480, result.Height()); | 1747 EXPECT_LE(480, result.Height()); |
1390 EXPECT_TRUE(result.noise_reduction() && *result.noise_reduction()); | 1748 EXPECT_TRUE(result.noise_reduction() && *result.noise_reduction()); |
| 1749 EXPECT_EQ(result.Width(), result.track_adapter_settings().max_width); |
| 1750 EXPECT_EQ(result.Height(), result.track_adapter_settings().max_height); |
| 1751 EXPECT_EQ(640.0 / result.Height(), |
| 1752 result.track_adapter_settings().min_aspect_ratio); |
| 1753 EXPECT_EQ(result.Width() / 480.0, |
| 1754 result.track_adapter_settings().max_aspect_ratio); |
| 1755 CheckTrackAdapterSettingsEqualsFrameRate(result); |
1391 } | 1756 } |
1392 | 1757 |
1393 // Same test without noise reduction | 1758 // Same test without noise reduction |
1394 { | 1759 { |
1395 constraint_factory_.Reset(); | 1760 constraint_factory_.Reset(); |
1396 blink::WebMediaTrackConstraintSet& advanced1 = | 1761 blink::WebMediaTrackConstraintSet& advanced1 = |
1397 constraint_factory_.AddAdvanced(); | 1762 constraint_factory_.AddAdvanced(); |
1398 advanced1.width.setMin(640); | 1763 advanced1.width.setMin(640); |
1399 advanced1.height.setMin(480); | 1764 advanced1.height.setMin(480); |
1400 blink::WebMediaTrackConstraintSet& advanced2 = | 1765 blink::WebMediaTrackConstraintSet& advanced2 = |
1401 constraint_factory_.AddAdvanced(); | 1766 constraint_factory_.AddAdvanced(); |
1402 advanced2.width.setMin(1920); | 1767 advanced2.width.setMin(1920); |
1403 advanced2.height.setMin(1080); | 1768 advanced2.height.setMin(1080); |
1404 auto result = SelectSettings(); | 1769 auto result = SelectSettings(); |
1405 EXPECT_TRUE(result.HasValue()); | 1770 EXPECT_TRUE(result.HasValue()); |
1406 // Only the high-res device can satisfy the second advanced set. | 1771 // Only the high-res device can satisfy the second advanced set. |
1407 EXPECT_EQ(high_res_device_->device_id, result.device_id()); | 1772 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
1408 EXPECT_LE(1920, result.Width()); | 1773 EXPECT_LE(1920, result.Width()); |
1409 EXPECT_LE(1080, result.Height()); | 1774 EXPECT_LE(1080, result.Height()); |
1410 // Should select default noise reduction setting. | 1775 // Should select default noise reduction setting. |
1411 EXPECT_TRUE(!result.noise_reduction()); | 1776 EXPECT_TRUE(!result.noise_reduction()); |
| 1777 EXPECT_EQ(result.Width(), result.track_adapter_settings().max_width); |
| 1778 EXPECT_EQ(result.Height(), result.track_adapter_settings().max_height); |
| 1779 EXPECT_EQ(1920.0 / result.Height(), |
| 1780 result.track_adapter_settings().min_aspect_ratio); |
| 1781 EXPECT_EQ(result.Width() / 1080.0, |
| 1782 result.track_adapter_settings().max_aspect_ratio); |
| 1783 CheckTrackAdapterSettingsEqualsFrameRate(result); |
1412 } | 1784 } |
1413 } | 1785 } |
1414 | 1786 |
1415 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, | 1787 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, |
1416 AdvancedContradictoryExactResolution) { | 1788 AdvancedContradictoryExactResolution) { |
1417 constraint_factory_.Reset(); | 1789 constraint_factory_.Reset(); |
1418 blink::WebMediaTrackConstraintSet& advanced1 = | 1790 blink::WebMediaTrackConstraintSet& advanced1 = |
1419 constraint_factory_.AddAdvanced(); | 1791 constraint_factory_.AddAdvanced(); |
1420 advanced1.width.setExact(640); | 1792 advanced1.width.setExact(640); |
1421 advanced1.height.setExact(480); | 1793 advanced1.height.setExact(480); |
1422 blink::WebMediaTrackConstraintSet& advanced2 = | 1794 blink::WebMediaTrackConstraintSet& advanced2 = |
1423 constraint_factory_.AddAdvanced(); | 1795 constraint_factory_.AddAdvanced(); |
1424 advanced2.width.setExact(1920); | 1796 advanced2.width.setExact(1920); |
1425 advanced2.height.setExact(1080); | 1797 advanced2.height.setExact(1080); |
1426 auto result = SelectSettings(); | 1798 auto result = SelectSettings(); |
1427 EXPECT_TRUE(result.HasValue()); | 1799 EXPECT_TRUE(result.HasValue()); |
1428 // The second advanced set must be ignored because it contradicts the first | 1800 // 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 | 1801 // set. The low-res device is the one that best supports the requested |
1430 // resolution. | 1802 // resolution. |
1431 EXPECT_EQ(low_res_device_->device_id, result.device_id()); | 1803 EXPECT_EQ(low_res_device_->device_id, result.device_id()); |
1432 EXPECT_EQ(640, result.Width()); | 1804 EXPECT_EQ(640, result.Width()); |
1433 EXPECT_EQ(480, result.Height()); | 1805 EXPECT_EQ(480, result.Height()); |
| 1806 EXPECT_EQ(result.Width(), result.track_adapter_settings().max_width); |
| 1807 EXPECT_EQ(result.Height(), result.track_adapter_settings().max_height); |
| 1808 EXPECT_EQ(640.0 / 480.0, result.track_adapter_settings().min_aspect_ratio); |
| 1809 EXPECT_EQ(640.0 / 480.0, result.track_adapter_settings().max_aspect_ratio); |
| 1810 CheckTrackAdapterSettingsEqualsFrameRate(result); |
1434 } | 1811 } |
1435 | 1812 |
1436 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, | 1813 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, |
1437 AdvancedContradictoryMaxMinResolutionFrameRate) { | 1814 AdvancedContradictoryMaxMinResolutionFrameRate) { |
1438 constraint_factory_.Reset(); | 1815 constraint_factory_.Reset(); |
1439 blink::WebMediaTrackConstraintSet& advanced1 = | 1816 blink::WebMediaTrackConstraintSet& advanced1 = |
1440 constraint_factory_.AddAdvanced(); | 1817 constraint_factory_.AddAdvanced(); |
1441 advanced1.width.setMax(640); | 1818 advanced1.width.setMax(640); |
1442 advanced1.height.setMax(480); | 1819 advanced1.height.setMax(480); |
1443 blink::WebMediaTrackConstraintSet& advanced2 = | 1820 blink::WebMediaTrackConstraintSet& advanced2 = |
1444 constraint_factory_.AddAdvanced(); | 1821 constraint_factory_.AddAdvanced(); |
1445 advanced2.width.setMin(1920); | 1822 advanced2.width.setMin(1920); |
1446 advanced2.height.setMin(1080); | 1823 advanced2.height.setMin(1080); |
1447 advanced2.frameRate.setExact(60.0); | 1824 advanced2.frameRate.setExact(60.0); |
1448 auto result = SelectSettings(); | 1825 auto result = SelectSettings(); |
1449 EXPECT_TRUE(result.HasValue()); | 1826 EXPECT_TRUE(result.HasValue()); |
1450 // The second advanced set must be ignored because it contradicts the first | 1827 // 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. | 1828 // 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 | 1829 // That format satisfies the first advanced set as well as any other, so the |
1453 // tie breaker rule that applies is default device ID. | 1830 // tie breaker rule that applies is default device ID. |
1454 EXPECT_EQ(default_device_->device_id, result.device_id()); | 1831 EXPECT_EQ(default_device_->device_id, result.device_id()); |
1455 EXPECT_EQ(200, result.Width()); | 1832 EXPECT_EQ(200, result.Width()); |
1456 EXPECT_EQ(200, result.Height()); | 1833 EXPECT_EQ(200, result.Height()); |
1457 EXPECT_EQ(40, result.FrameRate()); | 1834 EXPECT_EQ(40, result.FrameRate()); |
| 1835 EXPECT_EQ(result.Width(), result.track_adapter_settings().max_width); |
| 1836 EXPECT_EQ(result.Height(), result.track_adapter_settings().max_height); |
| 1837 EXPECT_EQ(1.0 / result.Height(), |
| 1838 result.track_adapter_settings().min_aspect_ratio); |
| 1839 EXPECT_EQ(result.Width(), result.track_adapter_settings().max_aspect_ratio); |
| 1840 CheckTrackAdapterSettingsEqualsFrameRate(result); |
1458 } | 1841 } |
1459 | 1842 |
1460 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, | 1843 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, |
1461 AdvancedContradictoryMinMaxResolutionFrameRate) { | 1844 AdvancedContradictoryMinMaxResolutionFrameRate) { |
1462 constraint_factory_.Reset(); | 1845 constraint_factory_.Reset(); |
1463 blink::WebMediaTrackConstraintSet& advanced1 = | 1846 blink::WebMediaTrackConstraintSet& advanced1 = |
1464 constraint_factory_.AddAdvanced(); | 1847 constraint_factory_.AddAdvanced(); |
1465 advanced1.width.setMin(800); | 1848 advanced1.width.setMin(800); |
1466 advanced1.height.setMin(600); | 1849 advanced1.height.setMin(600); |
1467 blink::WebMediaTrackConstraintSet& advanced2 = | 1850 blink::WebMediaTrackConstraintSet& advanced2 = |
1468 constraint_factory_.AddAdvanced(); | 1851 constraint_factory_.AddAdvanced(); |
1469 advanced2.width.setMax(640); | 1852 advanced2.width.setMax(640); |
1470 advanced2.height.setMax(480); | 1853 advanced2.height.setMax(480); |
1471 advanced2.frameRate.setExact(60.0); | 1854 advanced2.frameRate.setExact(60.0); |
1472 auto result = SelectSettings(); | 1855 auto result = SelectSettings(); |
1473 EXPECT_TRUE(result.HasValue()); | 1856 EXPECT_TRUE(result.HasValue()); |
1474 // The second advanced set must be ignored because it contradicts the first | 1857 // 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. | 1858 // 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 | 1859 // That format satisfies the first advanced set as well as any other, so the |
1477 // tie breaker rule that applies is default device ID. | 1860 // tie breaker rule that applies is default device ID. |
1478 EXPECT_EQ(default_device_->device_id, result.device_id()); | 1861 EXPECT_EQ(default_device_->device_id, result.device_id()); |
1479 EXPECT_EQ(1000, result.Width()); | 1862 EXPECT_EQ(1000, result.Width()); |
1480 EXPECT_EQ(1000, result.Height()); | 1863 EXPECT_EQ(1000, result.Height()); |
1481 EXPECT_EQ(20, result.FrameRate()); | 1864 EXPECT_EQ(20, result.FrameRate()); |
| 1865 EXPECT_EQ(result.Width(), result.track_adapter_settings().max_width); |
| 1866 EXPECT_EQ(result.Height(), result.track_adapter_settings().max_height); |
| 1867 EXPECT_EQ(800.0 / result.Height(), |
| 1868 result.track_adapter_settings().min_aspect_ratio); |
| 1869 EXPECT_EQ(result.Width() / 600.0, |
| 1870 result.track_adapter_settings().max_aspect_ratio); |
| 1871 CheckTrackAdapterSettingsEqualsFrameRate(result); |
1482 } | 1872 } |
1483 | 1873 |
1484 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, | 1874 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, |
1485 AdvancedContradictoryExactAspectRatio) { | 1875 AdvancedContradictoryExactAspectRatio) { |
1486 constraint_factory_.Reset(); | 1876 constraint_factory_.Reset(); |
1487 blink::WebMediaTrackConstraintSet& advanced1 = | 1877 blink::WebMediaTrackConstraintSet& advanced1 = |
1488 constraint_factory_.AddAdvanced(); | 1878 constraint_factory_.AddAdvanced(); |
1489 advanced1.aspectRatio.setExact(2300.0); | 1879 advanced1.aspectRatio.setExact(2300.0); |
1490 blink::WebMediaTrackConstraintSet& advanced2 = | 1880 blink::WebMediaTrackConstraintSet& advanced2 = |
1491 constraint_factory_.AddAdvanced(); | 1881 constraint_factory_.AddAdvanced(); |
1492 advanced2.aspectRatio.setExact(3.0); | 1882 advanced2.aspectRatio.setExact(3.0); |
1493 auto result = SelectSettings(); | 1883 auto result = SelectSettings(); |
1494 EXPECT_TRUE(result.HasValue()); | 1884 EXPECT_TRUE(result.HasValue()); |
1495 // The second advanced set must be ignored because it contradicts the first | 1885 // 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 | 1886 // set. Only the high-res device in the highest-resolution format supports the |
1497 // requested aspect ratio. | 1887 // requested aspect ratio. |
1498 EXPECT_EQ(high_res_device_->device_id, result.device_id()); | 1888 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
1499 EXPECT_EQ(*high_res_highest_format_, result.Format()); | 1889 EXPECT_EQ(*high_res_highest_format_, result.Format()); |
| 1890 // The track is cropped to support the exact aspect ratio. |
| 1891 EXPECT_EQ(result.Width(), result.track_adapter_settings().max_width); |
| 1892 EXPECT_EQ(std::round(result.Height() / 2300.0), |
| 1893 result.track_adapter_settings().max_height); |
| 1894 EXPECT_EQ(2300.0, result.track_adapter_settings().min_aspect_ratio); |
| 1895 EXPECT_EQ(2300.0, result.track_adapter_settings().max_aspect_ratio); |
| 1896 CheckTrackAdapterSettingsEqualsFrameRate(result); |
1500 } | 1897 } |
1501 | 1898 |
1502 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, | 1899 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, |
1503 AdvancedContradictoryAspectRatioRange) { | 1900 AdvancedContradictoryAspectRatioRange) { |
1504 constraint_factory_.Reset(); | 1901 constraint_factory_.Reset(); |
1505 blink::WebMediaTrackConstraintSet& advanced1 = | 1902 blink::WebMediaTrackConstraintSet& advanced1 = |
1506 constraint_factory_.AddAdvanced(); | 1903 constraint_factory_.AddAdvanced(); |
1507 advanced1.aspectRatio.setMin(2300.0); | 1904 advanced1.aspectRatio.setMin(2300.0); |
1508 blink::WebMediaTrackConstraintSet& advanced2 = | 1905 blink::WebMediaTrackConstraintSet& advanced2 = |
1509 constraint_factory_.AddAdvanced(); | 1906 constraint_factory_.AddAdvanced(); |
1510 advanced2.aspectRatio.setMax(3.0); | 1907 advanced2.aspectRatio.setMax(3.0); |
1511 auto result = SelectSettings(); | 1908 auto result = SelectSettings(); |
1512 EXPECT_TRUE(result.HasValue()); | 1909 EXPECT_TRUE(result.HasValue()); |
1513 // The second advanced set must be ignored because it contradicts the first | 1910 // 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 | 1911 // set. Only the high-res device in the highest-resolution format supports the |
1515 // requested aspect ratio. | 1912 // requested aspect ratio. |
1516 EXPECT_EQ(high_res_device_->device_id, result.device_id()); | 1913 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
1517 EXPECT_EQ(*high_res_highest_format_, result.Format()); | 1914 EXPECT_EQ(*high_res_highest_format_, result.Format()); |
| 1915 // The track is cropped to support the min aspect ratio. |
| 1916 EXPECT_EQ(result.Width(), result.track_adapter_settings().max_width); |
| 1917 EXPECT_EQ(std::round(result.Height() / 2300.0), |
| 1918 result.track_adapter_settings().max_height); |
| 1919 EXPECT_EQ(2300.0, result.track_adapter_settings().min_aspect_ratio); |
| 1920 EXPECT_EQ(result.Width(), result.track_adapter_settings().max_aspect_ratio); |
| 1921 CheckTrackAdapterSettingsEqualsFrameRate(result); |
1518 } | 1922 } |
1519 | 1923 |
1520 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, | 1924 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, |
1521 AdvancedContradictoryExactFrameRate) { | 1925 AdvancedContradictoryExactFrameRate) { |
1522 constraint_factory_.Reset(); | 1926 constraint_factory_.Reset(); |
1523 blink::WebMediaTrackConstraintSet& advanced1 = | 1927 blink::WebMediaTrackConstraintSet& advanced1 = |
1524 constraint_factory_.AddAdvanced(); | 1928 constraint_factory_.AddAdvanced(); |
1525 advanced1.frameRate.setExact(40.0); | 1929 advanced1.frameRate.setExact(40.0); |
1526 blink::WebMediaTrackConstraintSet& advanced2 = | 1930 blink::WebMediaTrackConstraintSet& advanced2 = |
1527 constraint_factory_.AddAdvanced(); | 1931 constraint_factory_.AddAdvanced(); |
1528 advanced2.frameRate.setExact(45.0); | 1932 advanced2.frameRate.setExact(45.0); |
1529 auto result = SelectSettings(); | 1933 auto result = SelectSettings(); |
1530 EXPECT_TRUE(result.HasValue()); | 1934 EXPECT_TRUE(result.HasValue()); |
1531 // The second advanced set must be ignored because it contradicts the first | 1935 // The second advanced set must be ignored because it contradicts the first |
1532 // set. | 1936 // set. |
1533 EXPECT_EQ(40.0, result.FrameRate()); | 1937 EXPECT_EQ(40.0, result.FrameRate()); |
| 1938 CheckTrackAdapterSettingsEqualsResolution(result); |
| 1939 CheckTrackAdapterSettingsEqualsFrameRate(result); |
1534 } | 1940 } |
1535 | 1941 |
1536 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, | 1942 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, |
1537 AdvancedContradictoryFrameRateRange) { | 1943 AdvancedContradictoryFrameRateRange) { |
1538 constraint_factory_.Reset(); | 1944 constraint_factory_.Reset(); |
1539 blink::WebMediaTrackConstraintSet& advanced1 = | 1945 blink::WebMediaTrackConstraintSet& advanced1 = |
1540 constraint_factory_.AddAdvanced(); | 1946 constraint_factory_.AddAdvanced(); |
1541 advanced1.frameRate.setMin(40.0); | 1947 advanced1.frameRate.setMin(40.0); |
1542 blink::WebMediaTrackConstraintSet& advanced2 = | 1948 blink::WebMediaTrackConstraintSet& advanced2 = |
1543 constraint_factory_.AddAdvanced(); | 1949 constraint_factory_.AddAdvanced(); |
1544 advanced2.frameRate.setMax(35.0); | 1950 advanced2.frameRate.setMax(35.0); |
1545 auto result = SelectSettings(); | 1951 auto result = SelectSettings(); |
1546 EXPECT_TRUE(result.HasValue()); | 1952 EXPECT_TRUE(result.HasValue()); |
1547 // The second advanced set must be ignored because it contradicts the first | 1953 // The second advanced set must be ignored because it contradicts the first |
1548 // set. | 1954 // set. |
1549 EXPECT_LE(40.0, result.FrameRate()); | 1955 EXPECT_LE(40.0, result.FrameRate()); |
| 1956 CheckTrackAdapterSettingsEqualsResolution(result); |
| 1957 CheckTrackAdapterSettingsEqualsFrameRate(result); |
1550 } | 1958 } |
1551 | 1959 |
1552 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, | 1960 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, |
1553 AdvancedContradictoryWidthFrameRate) { | 1961 AdvancedContradictoryWidthFrameRate) { |
1554 constraint_factory_.Reset(); | 1962 constraint_factory_.Reset(); |
1555 blink::WebMediaTrackConstraintSet& advanced1 = | 1963 blink::WebMediaTrackConstraintSet& advanced1 = |
1556 constraint_factory_.AddAdvanced(); | 1964 constraint_factory_.AddAdvanced(); |
1557 advanced1.width.setMax(1920); | 1965 advanced1.width.setMax(1920); |
1558 blink::WebMediaTrackConstraintSet& advanced2 = | 1966 blink::WebMediaTrackConstraintSet& advanced2 = |
1559 constraint_factory_.AddAdvanced(); | 1967 constraint_factory_.AddAdvanced(); |
1560 advanced2.width.setMin(2000); | 1968 advanced2.width.setMin(2000); |
1561 advanced2.frameRate.setExact(10.0); | 1969 advanced2.frameRate.setExact(10.0); |
1562 blink::WebMediaTrackConstraintSet& advanced3 = | 1970 blink::WebMediaTrackConstraintSet& advanced3 = |
1563 constraint_factory_.AddAdvanced(); | 1971 constraint_factory_.AddAdvanced(); |
1564 advanced3.frameRate.setExact(30.0); | 1972 advanced3.frameRate.setExact(30.0); |
1565 auto result = SelectSettings(); | 1973 auto result = SelectSettings(); |
1566 EXPECT_TRUE(result.HasValue()); | 1974 EXPECT_TRUE(result.HasValue()); |
1567 // The low-res device at 320x240@30Hz satisfies advanced sets 1 and 3. | 1975 // 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 | 1976 // 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. | 1977 // both at the same time. Thus, low-res device must be preferred. |
1570 EXPECT_EQ(low_res_device_->device_id, result.device_id()); | 1978 EXPECT_EQ(low_res_device_->device_id, result.device_id()); |
1571 EXPECT_EQ(30.0, result.FrameRate()); | 1979 EXPECT_EQ(30.0, result.FrameRate()); |
1572 EXPECT_GE(1920, result.Width()); | 1980 EXPECT_GE(1920, result.Width()); |
| 1981 CheckTrackAdapterSettingsEqualsFormat(result); |
1573 } | 1982 } |
1574 | 1983 |
1575 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, | 1984 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, |
1576 AdvancedContradictoryHeightFrameRate) { | 1985 AdvancedContradictoryHeightFrameRate) { |
1577 constraint_factory_.Reset(); | 1986 constraint_factory_.Reset(); |
1578 blink::WebMediaTrackConstraintSet& advanced1 = | 1987 blink::WebMediaTrackConstraintSet& advanced1 = |
1579 constraint_factory_.AddAdvanced(); | 1988 constraint_factory_.AddAdvanced(); |
1580 advanced1.height.setMax(1080); | 1989 advanced1.height.setMax(1080); |
1581 blink::WebMediaTrackConstraintSet& advanced2 = | 1990 blink::WebMediaTrackConstraintSet& advanced2 = |
1582 constraint_factory_.AddAdvanced(); | 1991 constraint_factory_.AddAdvanced(); |
1583 advanced2.height.setMin(1500); | 1992 advanced2.height.setMin(1500); |
1584 advanced2.frameRate.setExact(10.0); | 1993 advanced2.frameRate.setExact(10.0); |
1585 blink::WebMediaTrackConstraintSet& advanced3 = | 1994 blink::WebMediaTrackConstraintSet& advanced3 = |
1586 constraint_factory_.AddAdvanced(); | 1995 constraint_factory_.AddAdvanced(); |
1587 advanced3.frameRate.setExact(60.0); | 1996 advanced3.frameRate.setExact(60.0); |
1588 auto result = SelectSettings(); | 1997 auto result = SelectSettings(); |
1589 EXPECT_TRUE(result.HasValue()); | 1998 EXPECT_TRUE(result.HasValue()); |
1590 // The high-res device at 1280x768@60Hz and 1920x1080@60Hz satisfies advanced | 1999 // 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, | 2000 // 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 | 2001 // but not both at the same time. Thus, the format closest to default that |
1593 // satisfies sets 1 and 3 must be chosen. | 2002 // satisfies sets 1 and 3 must be chosen. |
1594 EXPECT_EQ(high_res_device_->device_id, result.device_id()); | 2003 EXPECT_EQ(high_res_device_->device_id, result.device_id()); |
1595 EXPECT_EQ(60.0, result.FrameRate()); | 2004 EXPECT_EQ(60.0, result.FrameRate()); |
1596 EXPECT_GE(1080, result.Height()); | 2005 EXPECT_GE(1080, result.Height()); |
| 2006 CheckTrackAdapterSettingsEqualsFormat(result); |
1597 } | 2007 } |
1598 | 2008 |
1599 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, AdvancedDeviceID) { | 2009 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, AdvancedDeviceID) { |
1600 constraint_factory_.Reset(); | 2010 constraint_factory_.Reset(); |
1601 blink::WebMediaTrackConstraintSet& advanced1 = | 2011 blink::WebMediaTrackConstraintSet& advanced1 = |
1602 constraint_factory_.AddAdvanced(); | 2012 constraint_factory_.AddAdvanced(); |
1603 blink::WebString id_vector1[] = {blink::WebString::fromASCII(kDeviceID1), | 2013 blink::WebString id_vector1[] = {blink::WebString::fromASCII(kDeviceID1), |
1604 blink::WebString::fromASCII(kDeviceID2)}; | 2014 blink::WebString::fromASCII(kDeviceID2)}; |
1605 advanced1.deviceId.setExact( | 2015 advanced1.deviceId.setExact( |
1606 blink::WebVector<blink::WebString>(id_vector1, arraysize(id_vector1))); | 2016 blink::WebVector<blink::WebString>(id_vector1, arraysize(id_vector1))); |
1607 blink::WebString id_vector2[] = {blink::WebString::fromASCII(kDeviceID2), | 2017 blink::WebString id_vector2[] = {blink::WebString::fromASCII(kDeviceID2), |
1608 blink::WebString::fromASCII(kDeviceID3)}; | 2018 blink::WebString::fromASCII(kDeviceID3)}; |
1609 blink::WebMediaTrackConstraintSet& advanced2 = | 2019 blink::WebMediaTrackConstraintSet& advanced2 = |
1610 constraint_factory_.AddAdvanced(); | 2020 constraint_factory_.AddAdvanced(); |
1611 advanced2.deviceId.setExact( | 2021 advanced2.deviceId.setExact( |
1612 blink::WebVector<blink::WebString>(id_vector2, arraysize(id_vector2))); | 2022 blink::WebVector<blink::WebString>(id_vector2, arraysize(id_vector2))); |
1613 auto result = SelectSettings(); | 2023 auto result = SelectSettings(); |
1614 EXPECT_TRUE(result.HasValue()); | 2024 EXPECT_TRUE(result.HasValue()); |
1615 // kDeviceID2 must be selected because it is the only one that satisfies both | 2025 // kDeviceID2 must be selected because it is the only one that satisfies both |
1616 // advanced sets. | 2026 // advanced sets. |
1617 EXPECT_EQ(std::string(kDeviceID2), result.device_id()); | 2027 EXPECT_EQ(std::string(kDeviceID2), result.device_id()); |
| 2028 CheckTrackAdapterSettingsEqualsFormat(result); |
1618 } | 2029 } |
1619 | 2030 |
1620 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, | 2031 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, |
1621 AdvancedContradictoryDeviceID) { | 2032 AdvancedContradictoryDeviceID) { |
1622 constraint_factory_.Reset(); | 2033 constraint_factory_.Reset(); |
1623 blink::WebMediaTrackConstraintSet& advanced1 = | 2034 blink::WebMediaTrackConstraintSet& advanced1 = |
1624 constraint_factory_.AddAdvanced(); | 2035 constraint_factory_.AddAdvanced(); |
1625 blink::WebString id_vector1[] = {blink::WebString::fromASCII(kDeviceID1), | 2036 blink::WebString id_vector1[] = {blink::WebString::fromASCII(kDeviceID1), |
1626 blink::WebString::fromASCII(kDeviceID2)}; | 2037 blink::WebString::fromASCII(kDeviceID2)}; |
1627 advanced1.deviceId.setExact( | 2038 advanced1.deviceId.setExact( |
1628 blink::WebVector<blink::WebString>(id_vector1, arraysize(id_vector1))); | 2039 blink::WebVector<blink::WebString>(id_vector1, arraysize(id_vector1))); |
1629 blink::WebString id_vector2[] = {blink::WebString::fromASCII(kDeviceID3), | 2040 blink::WebString id_vector2[] = {blink::WebString::fromASCII(kDeviceID3), |
1630 blink::WebString::fromASCII(kDeviceID4)}; | 2041 blink::WebString::fromASCII(kDeviceID4)}; |
1631 blink::WebMediaTrackConstraintSet& advanced2 = | 2042 blink::WebMediaTrackConstraintSet& advanced2 = |
1632 constraint_factory_.AddAdvanced(); | 2043 constraint_factory_.AddAdvanced(); |
1633 advanced2.deviceId.setExact( | 2044 advanced2.deviceId.setExact( |
1634 blink::WebVector<blink::WebString>(id_vector2, arraysize(id_vector2))); | 2045 blink::WebVector<blink::WebString>(id_vector2, arraysize(id_vector2))); |
1635 auto result = SelectSettings(); | 2046 auto result = SelectSettings(); |
1636 EXPECT_TRUE(result.HasValue()); | 2047 EXPECT_TRUE(result.HasValue()); |
1637 // The second advanced set must be ignored because it contradicts the first | 2048 // The second advanced set must be ignored because it contradicts the first |
1638 // set. | 2049 // set. |
1639 EXPECT_EQ(std::string(kDeviceID1), result.device_id()); | 2050 EXPECT_EQ(std::string(kDeviceID1), result.device_id()); |
| 2051 CheckTrackAdapterSettingsEqualsFormat(result); |
1640 } | 2052 } |
1641 | 2053 |
1642 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, | 2054 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, |
1643 AdvancedContradictoryPowerLineFrequency) { | 2055 AdvancedContradictoryPowerLineFrequency) { |
1644 { | 2056 { |
1645 constraint_factory_.Reset(); | 2057 constraint_factory_.Reset(); |
1646 blink::WebMediaTrackConstraintSet& advanced1 = | 2058 blink::WebMediaTrackConstraintSet& advanced1 = |
1647 constraint_factory_.AddAdvanced(); | 2059 constraint_factory_.AddAdvanced(); |
1648 advanced1.width.setMin(640); | 2060 advanced1.width.setMin(640); |
1649 advanced1.height.setMin(480); | 2061 advanced1.height.setMin(480); |
1650 advanced1.googPowerLineFrequency.setExact(50); | 2062 advanced1.googPowerLineFrequency.setExact(50); |
1651 blink::WebMediaTrackConstraintSet& advanced2 = | 2063 blink::WebMediaTrackConstraintSet& advanced2 = |
1652 constraint_factory_.AddAdvanced(); | 2064 constraint_factory_.AddAdvanced(); |
1653 advanced2.width.setMin(1920); | 2065 advanced2.width.setMin(1920); |
1654 advanced2.height.setMin(1080); | 2066 advanced2.height.setMin(1080); |
1655 advanced2.googPowerLineFrequency.setExact(60); | 2067 advanced2.googPowerLineFrequency.setExact(60); |
1656 auto result = SelectSettings(); | 2068 auto result = SelectSettings(); |
1657 EXPECT_TRUE(result.HasValue()); | 2069 EXPECT_TRUE(result.HasValue()); |
1658 // The second advanced set cannot be satisfied because it contradicts the | 2070 // The second advanced set cannot be satisfied because it contradicts the |
1659 // first set. The default device supports the first set and should be | 2071 // first set. The default device supports the first set and should be |
1660 // selected. | 2072 // selected. |
1661 EXPECT_EQ(default_device_->device_id, result.device_id()); | 2073 EXPECT_EQ(default_device_->device_id, result.device_id()); |
1662 EXPECT_LE(640, result.Width()); | 2074 EXPECT_LE(640, result.Width()); |
1663 EXPECT_LE(480, result.Height()); | 2075 EXPECT_LE(480, result.Height()); |
1664 EXPECT_EQ(50, static_cast<int>(result.PowerLineFrequency())); | 2076 EXPECT_EQ(50, static_cast<int>(result.PowerLineFrequency())); |
| 2077 EXPECT_EQ(result.Width(), result.track_adapter_settings().max_width); |
| 2078 EXPECT_EQ(result.Height(), result.track_adapter_settings().max_height); |
| 2079 EXPECT_EQ(640.0 / result.Height(), |
| 2080 result.track_adapter_settings().min_aspect_ratio); |
| 2081 EXPECT_EQ(result.Width() / 480.0, |
| 2082 result.track_adapter_settings().max_aspect_ratio); |
| 2083 CheckTrackAdapterSettingsEqualsFrameRate(result); |
1665 } | 2084 } |
1666 } | 2085 } |
1667 | 2086 |
1668 // The "NoDevices" tests verify that the algorithm returns the expected result | 2087 // The "NoDevices" tests verify that the algorithm returns the expected result |
1669 // when there are no candidates to choose from. | 2088 // when there are no candidates to choose from. |
1670 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, NoDevicesNoConstraints) { | 2089 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, NoDevicesNoConstraints) { |
1671 constraint_factory_.Reset(); | 2090 constraint_factory_.Reset(); |
1672 VideoDeviceCaptureCapabilities capabilities; | 2091 VideoDeviceCaptureCapabilities capabilities; |
1673 auto result = SelectVideoDeviceCaptureSourceSettings( | 2092 auto result = SelectSettingsVideoDeviceCapture( |
1674 capabilities, constraint_factory_.CreateWebMediaConstraints()); | 2093 capabilities, constraint_factory_.CreateWebMediaConstraints()); |
1675 EXPECT_FALSE(result.HasValue()); | 2094 EXPECT_FALSE(result.HasValue()); |
1676 EXPECT_TRUE(std::string(result.failed_constraint_name()).empty()); | 2095 EXPECT_TRUE(std::string(result.failed_constraint_name()).empty()); |
1677 } | 2096 } |
1678 | 2097 |
1679 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, NoDevicesWithConstraints) { | 2098 TEST_F(MediaStreamConstraintsUtilVideoDeviceTest, NoDevicesWithConstraints) { |
1680 constraint_factory_.Reset(); | 2099 constraint_factory_.Reset(); |
1681 constraint_factory_.basic().height.setExact(100); | 2100 constraint_factory_.basic().height.setExact(100); |
1682 VideoDeviceCaptureCapabilities capabilities; | 2101 VideoDeviceCaptureCapabilities capabilities; |
1683 auto result = SelectVideoDeviceCaptureSourceSettings( | 2102 auto result = SelectSettingsVideoDeviceCapture( |
1684 capabilities, constraint_factory_.CreateWebMediaConstraints()); | 2103 capabilities, constraint_factory_.CreateWebMediaConstraints()); |
1685 EXPECT_FALSE(result.HasValue()); | 2104 EXPECT_FALSE(result.HasValue()); |
1686 EXPECT_TRUE(std::string(result.failed_constraint_name()).empty()); | 2105 EXPECT_TRUE(std::string(result.failed_constraint_name()).empty()); |
1687 } | 2106 } |
1688 | 2107 |
1689 } // namespace content | 2108 } // namespace content |
OLD | NEW |