OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/renderer/media/media_stream_constraints_util_video_content.h" |
| 6 |
| 7 #include <cmath> |
| 8 #include <string> |
| 9 |
| 10 #include "content/renderer/media/media_stream_video_source.h" |
| 11 #include "content/renderer/media/mock_constraint_factory.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" |
| 14 |
| 15 namespace content { |
| 16 |
| 17 namespace { |
| 18 |
| 19 void CheckNonResolutionDefaults( |
| 20 const VideoContentCaptureSourceSelectionResult& result) { |
| 21 EXPECT_EQ(MediaStreamVideoSource::kDefaultFrameRate, result.FrameRate()); |
| 22 EXPECT_EQ(rtc::Optional<bool>(), result.noise_reduction()); |
| 23 EXPECT_EQ(std::string(), result.device_id()); |
| 24 } |
| 25 |
| 26 void CheckNonFrameRateDefaults( |
| 27 const VideoContentCaptureSourceSelectionResult& result) { |
| 28 EXPECT_EQ(MediaStreamVideoSource::kDefaultHeight, result.Height()); |
| 29 EXPECT_EQ(MediaStreamVideoSource::kDefaultWidth, result.Width()); |
| 30 EXPECT_EQ(rtc::Optional<bool>(), result.noise_reduction()); |
| 31 EXPECT_EQ(std::string(), result.device_id()); |
| 32 } |
| 33 |
| 34 } // namespace |
| 35 |
| 36 class MediaStreamConstraintsUtilVideoContentTest : public testing::Test { |
| 37 protected: |
| 38 VideoContentCaptureSourceSelectionResult SelectSettings() { |
| 39 blink::WebMediaConstraints constraints = |
| 40 constraint_factory_.CreateWebMediaConstraints(); |
| 41 return SelectVideoContentCaptureSourceSettings(constraints); |
| 42 } |
| 43 |
| 44 MockConstraintFactory constraint_factory_; |
| 45 }; |
| 46 |
| 47 // The Unconstrained test checks the default selection criteria. |
| 48 TEST_F(MediaStreamConstraintsUtilVideoContentTest, Unconstrained) { |
| 49 constraint_factory_.Reset(); |
| 50 auto result = SelectSettings(); |
| 51 |
| 52 // All settings should have default values. |
| 53 EXPECT_TRUE(result.HasValue()); |
| 54 EXPECT_EQ(MediaStreamVideoSource::kDefaultHeight, result.Height()); |
| 55 EXPECT_EQ(MediaStreamVideoSource::kDefaultWidth, result.Width()); |
| 56 CheckNonResolutionDefaults(result); |
| 57 } |
| 58 |
| 59 // The "Overconstrained" tests verify that failure of any single required |
| 60 // constraint results in failure to select a candidate. |
| 61 TEST_F(MediaStreamConstraintsUtilVideoContentTest, OverconstrainedOnHeight) { |
| 62 constraint_factory_.Reset(); |
| 63 constraint_factory_.basic().height.setExact(123467890); |
| 64 auto result = SelectSettings(); |
| 65 EXPECT_FALSE(result.HasValue()); |
| 66 EXPECT_EQ(constraint_factory_.basic().height.name(), |
| 67 result.failed_constraint_name()); |
| 68 |
| 69 constraint_factory_.Reset(); |
| 70 constraint_factory_.basic().height.setMin(123467890); |
| 71 result = SelectSettings(); |
| 72 EXPECT_FALSE(result.HasValue()); |
| 73 EXPECT_EQ(constraint_factory_.basic().height.name(), |
| 74 result.failed_constraint_name()); |
| 75 |
| 76 constraint_factory_.Reset(); |
| 77 constraint_factory_.basic().height.setMax(0); |
| 78 result = SelectSettings(); |
| 79 EXPECT_FALSE(result.HasValue()); |
| 80 EXPECT_EQ(constraint_factory_.basic().height.name(), |
| 81 result.failed_constraint_name()); |
| 82 } |
| 83 |
| 84 TEST_F(MediaStreamConstraintsUtilVideoContentTest, OverconstrainedOnWidth) { |
| 85 constraint_factory_.Reset(); |
| 86 constraint_factory_.basic().width.setExact(123467890); |
| 87 auto result = SelectSettings(); |
| 88 EXPECT_FALSE(result.HasValue()); |
| 89 EXPECT_EQ(constraint_factory_.basic().width.name(), |
| 90 result.failed_constraint_name()); |
| 91 |
| 92 constraint_factory_.Reset(); |
| 93 constraint_factory_.basic().width.setMin(123467890); |
| 94 result = SelectSettings(); |
| 95 EXPECT_FALSE(result.HasValue()); |
| 96 EXPECT_EQ(constraint_factory_.basic().width.name(), |
| 97 result.failed_constraint_name()); |
| 98 |
| 99 constraint_factory_.Reset(); |
| 100 constraint_factory_.basic().width.setMax(0); |
| 101 result = SelectSettings(); |
| 102 EXPECT_FALSE(result.HasValue()); |
| 103 EXPECT_EQ(constraint_factory_.basic().width.name(), |
| 104 result.failed_constraint_name()); |
| 105 } |
| 106 |
| 107 TEST_F(MediaStreamConstraintsUtilVideoContentTest, |
| 108 OverconstrainedOnAspectRatio) { |
| 109 constraint_factory_.Reset(); |
| 110 constraint_factory_.basic().aspectRatio.setExact(123467890); |
| 111 auto result = SelectSettings(); |
| 112 EXPECT_FALSE(result.HasValue()); |
| 113 EXPECT_EQ(constraint_factory_.basic().aspectRatio.name(), |
| 114 result.failed_constraint_name()); |
| 115 |
| 116 constraint_factory_.Reset(); |
| 117 constraint_factory_.basic().aspectRatio.setMin(123467890); |
| 118 result = SelectSettings(); |
| 119 EXPECT_FALSE(result.HasValue()); |
| 120 EXPECT_EQ(constraint_factory_.basic().aspectRatio.name(), |
| 121 result.failed_constraint_name()); |
| 122 |
| 123 constraint_factory_.Reset(); |
| 124 constraint_factory_.basic().aspectRatio.setMax(0.00001); |
| 125 result = SelectSettings(); |
| 126 EXPECT_FALSE(result.HasValue()); |
| 127 EXPECT_EQ(constraint_factory_.basic().aspectRatio.name(), |
| 128 result.failed_constraint_name()); |
| 129 } |
| 130 |
| 131 TEST_F(MediaStreamConstraintsUtilVideoContentTest, OverconstrainedOnFrameRate) { |
| 132 constraint_factory_.Reset(); |
| 133 constraint_factory_.basic().frameRate.setExact(123467890.0); |
| 134 auto result = SelectSettings(); |
| 135 EXPECT_FALSE(result.HasValue()); |
| 136 EXPECT_EQ(constraint_factory_.basic().frameRate.name(), |
| 137 result.failed_constraint_name()); |
| 138 |
| 139 constraint_factory_.Reset(); |
| 140 constraint_factory_.basic().frameRate.setMin(123467890.0); |
| 141 result = SelectSettings(); |
| 142 EXPECT_FALSE(result.HasValue()); |
| 143 EXPECT_EQ(constraint_factory_.basic().frameRate.name(), |
| 144 result.failed_constraint_name()); |
| 145 |
| 146 constraint_factory_.Reset(); |
| 147 constraint_factory_.basic().frameRate.setMax(0.0); |
| 148 result = SelectSettings(); |
| 149 EXPECT_FALSE(result.HasValue()); |
| 150 EXPECT_EQ(constraint_factory_.basic().frameRate.name(), |
| 151 result.failed_constraint_name()); |
| 152 } |
| 153 |
| 154 // The "Mandatory" and "Ideal" tests check that various selection criteria work |
| 155 // for each individual constraint in the basic constraint set. |
| 156 TEST_F(MediaStreamConstraintsUtilVideoContentTest, MandatoryDeviceID) { |
| 157 const std::string kDeviceID = "Some ID"; |
| 158 constraint_factory_.Reset(); |
| 159 constraint_factory_.basic().deviceId.setExact( |
| 160 blink::WebString::fromASCII(kDeviceID)); |
| 161 auto result = SelectSettings(); |
| 162 EXPECT_TRUE(result.HasValue()); |
| 163 EXPECT_EQ(kDeviceID, result.device_id()); |
| 164 // Other settings should have default values. |
| 165 EXPECT_EQ(MediaStreamVideoSource::kDefaultHeight, result.Height()); |
| 166 EXPECT_EQ(MediaStreamVideoSource::kDefaultWidth, result.Width()); |
| 167 EXPECT_EQ(MediaStreamVideoSource::kDefaultFrameRate, result.FrameRate()); |
| 168 EXPECT_EQ(rtc::Optional<bool>(), result.noise_reduction()); |
| 169 } |
| 170 |
| 171 TEST_F(MediaStreamConstraintsUtilVideoContentTest, IdealDeviceID) { |
| 172 const std::string kDeviceID = "Some ID"; |
| 173 const std::string kIdealID = "Ideal ID"; |
| 174 blink::WebVector<blink::WebString> device_ids(static_cast<size_t>(2)); |
| 175 device_ids[0] = blink::WebString::fromASCII(kDeviceID); |
| 176 device_ids[1] = blink::WebString::fromASCII(kIdealID); |
| 177 constraint_factory_.Reset(); |
| 178 constraint_factory_.basic().deviceId.setExact(device_ids); |
| 179 |
| 180 blink::WebVector<blink::WebString> ideal_id(static_cast<size_t>(1)); |
| 181 ideal_id[0] = blink::WebString::fromASCII(kIdealID); |
| 182 constraint_factory_.basic().deviceId.setIdeal(ideal_id); |
| 183 |
| 184 auto result = SelectSettings(); |
| 185 EXPECT_TRUE(result.HasValue()); |
| 186 EXPECT_EQ(kIdealID, result.device_id()); |
| 187 // Other settings should have default values. |
| 188 EXPECT_EQ(MediaStreamVideoSource::kDefaultHeight, result.Height()); |
| 189 EXPECT_EQ(MediaStreamVideoSource::kDefaultWidth, result.Width()); |
| 190 EXPECT_EQ(MediaStreamVideoSource::kDefaultFrameRate, result.FrameRate()); |
| 191 EXPECT_EQ(rtc::Optional<bool>(), result.noise_reduction()); |
| 192 } |
| 193 |
| 194 TEST_F(MediaStreamConstraintsUtilVideoContentTest, MandatoryNoiseReduction) { |
| 195 constraint_factory_.Reset(); |
| 196 const bool kNoiseReductionValues[] = {true, false}; |
| 197 for (auto noise_reduction : kNoiseReductionValues) { |
| 198 constraint_factory_.basic().googNoiseReduction.setExact(noise_reduction); |
| 199 auto result = SelectSettings(); |
| 200 EXPECT_TRUE(result.HasValue()); |
| 201 EXPECT_EQ(noise_reduction, result.noise_reduction()); |
| 202 // Other settings should have default values. |
| 203 EXPECT_EQ(MediaStreamVideoSource::kDefaultHeight, result.Height()); |
| 204 EXPECT_EQ(MediaStreamVideoSource::kDefaultWidth, result.Width()); |
| 205 EXPECT_EQ(MediaStreamVideoSource::kDefaultFrameRate, result.FrameRate()); |
| 206 EXPECT_EQ(std::string(), result.device_id()); |
| 207 } |
| 208 } |
| 209 |
| 210 TEST_F(MediaStreamConstraintsUtilVideoContentTest, IdealNoiseReduction) { |
| 211 constraint_factory_.Reset(); |
| 212 const bool kNoiseReductionValues[] = {true, false}; |
| 213 for (auto noise_reduction : kNoiseReductionValues) { |
| 214 constraint_factory_.basic().googNoiseReduction.setIdeal(noise_reduction); |
| 215 auto result = SelectSettings(); |
| 216 EXPECT_TRUE(result.HasValue()); |
| 217 EXPECT_EQ(noise_reduction, result.noise_reduction()); |
| 218 // Other settings should have default values. |
| 219 EXPECT_EQ(MediaStreamVideoSource::kDefaultHeight, result.Height()); |
| 220 EXPECT_EQ(MediaStreamVideoSource::kDefaultWidth, result.Width()); |
| 221 EXPECT_EQ(MediaStreamVideoSource::kDefaultFrameRate, result.FrameRate()); |
| 222 EXPECT_EQ(std::string(), result.device_id()); |
| 223 } |
| 224 } |
| 225 |
| 226 TEST_F(MediaStreamConstraintsUtilVideoContentTest, MandatoryExactHeight) { |
| 227 constraint_factory_.Reset(); |
| 228 const int kHeight = 1000; |
| 229 constraint_factory_.basic().height.setExact(kHeight); |
| 230 auto result = SelectSettings(); |
| 231 EXPECT_TRUE(result.HasValue()); |
| 232 EXPECT_EQ(kHeight, result.Height()); |
| 233 // The algorithm tries to preserve the default aspect ratio. |
| 234 EXPECT_EQ(std::round(kHeight * MediaStreamVideoSource::kDefaultAspectRatio), |
| 235 result.Width()); |
| 236 CheckNonResolutionDefaults(result); |
| 237 } |
| 238 |
| 239 TEST_F(MediaStreamConstraintsUtilVideoContentTest, MandatoryMinHeight) { |
| 240 constraint_factory_.Reset(); |
| 241 const int kHeight = 1000; |
| 242 constraint_factory_.basic().height.setMin(kHeight); |
| 243 auto result = SelectSettings(); |
| 244 EXPECT_TRUE(result.HasValue()); |
| 245 // kHeight is greater that the default, so expect kHeight. |
| 246 EXPECT_EQ(kHeight, result.Height()); |
| 247 EXPECT_EQ(std::round(kHeight * MediaStreamVideoSource::kDefaultAspectRatio), |
| 248 result.Width()); |
| 249 CheckNonResolutionDefaults(result); |
| 250 |
| 251 const int kSmallHeight = 100; |
| 252 constraint_factory_.basic().height.setMin(kSmallHeight); |
| 253 result = SelectSettings(); |
| 254 EXPECT_TRUE(result.HasValue()); |
| 255 // kSmallHeight is less that the default, so expect the default. |
| 256 EXPECT_EQ(MediaStreamVideoSource::kDefaultHeight, result.Height()); |
| 257 EXPECT_EQ(MediaStreamVideoSource::kDefaultWidth, result.Width()); |
| 258 CheckNonResolutionDefaults(result); |
| 259 } |
| 260 |
| 261 TEST_F(MediaStreamConstraintsUtilVideoContentTest, MandatoryMaxHeight) { |
| 262 constraint_factory_.Reset(); |
| 263 const int kHeight = 1000; |
| 264 constraint_factory_.basic().height.setMax(kHeight); |
| 265 auto result = SelectSettings(); |
| 266 EXPECT_TRUE(result.HasValue()); |
| 267 // kHeight is greater that the default, so expect the default. |
| 268 EXPECT_EQ(MediaStreamVideoSource::kDefaultHeight, result.Height()); |
| 269 EXPECT_EQ(MediaStreamVideoSource::kDefaultWidth, result.Width()); |
| 270 CheckNonResolutionDefaults(result); |
| 271 |
| 272 const int kSmallHeight = 100; |
| 273 constraint_factory_.basic().height.setMax(kSmallHeight); |
| 274 result = SelectSettings(); |
| 275 EXPECT_TRUE(result.HasValue()); |
| 276 // kSmallHeight is less that the default, so expect kSmallHeight. |
| 277 EXPECT_EQ(kSmallHeight, result.Height()); |
| 278 EXPECT_EQ( |
| 279 std::round(kSmallHeight * MediaStreamVideoSource::kDefaultAspectRatio), |
| 280 result.Width()); |
| 281 CheckNonResolutionDefaults(result); |
| 282 } |
| 283 |
| 284 TEST_F(MediaStreamConstraintsUtilVideoContentTest, MandatoryHeightRange) { |
| 285 constraint_factory_.Reset(); |
| 286 { |
| 287 const int kMinHeight = 300; |
| 288 const int kMaxHeight = 1000; |
| 289 constraint_factory_.basic().height.setMin(kMinHeight); |
| 290 constraint_factory_.basic().height.setMax(kMaxHeight); |
| 291 auto result = SelectSettings(); |
| 292 EXPECT_TRUE(result.HasValue()); |
| 293 // The range includes the default, so expect the default. |
| 294 EXPECT_EQ(MediaStreamVideoSource::kDefaultHeight, result.Height()); |
| 295 EXPECT_EQ(MediaStreamVideoSource::kDefaultWidth, result.Width()); |
| 296 CheckNonResolutionDefaults(result); |
| 297 } |
| 298 |
| 299 { |
| 300 const int kMinHeight = 900; |
| 301 const int kMaxHeight = 1000; |
| 302 constraint_factory_.basic().height.setMin(kMinHeight); |
| 303 constraint_factory_.basic().height.setMax(kMaxHeight); |
| 304 auto result = SelectSettings(); |
| 305 EXPECT_TRUE(result.HasValue()); |
| 306 // The whole range is greater than the default, so expect the range minimum. |
| 307 EXPECT_EQ(kMinHeight, result.Height()); |
| 308 EXPECT_EQ( |
| 309 std::round(kMinHeight * MediaStreamVideoSource::kDefaultAspectRatio), |
| 310 result.Width()); |
| 311 CheckNonResolutionDefaults(result); |
| 312 } |
| 313 |
| 314 { |
| 315 const int kMinHeight = 300; |
| 316 const int kMaxHeight = 400; |
| 317 constraint_factory_.basic().height.setMin(kMinHeight); |
| 318 constraint_factory_.basic().height.setMax(kMaxHeight); |
| 319 auto result = SelectSettings(); |
| 320 EXPECT_TRUE(result.HasValue()); |
| 321 // The whole range is less than the default, so expect the range maximum. |
| 322 EXPECT_EQ(kMaxHeight, result.Height()); |
| 323 EXPECT_EQ( |
| 324 std::round(kMaxHeight * MediaStreamVideoSource::kDefaultAspectRatio), |
| 325 result.Width()); |
| 326 CheckNonResolutionDefaults(result); |
| 327 } |
| 328 } |
| 329 |
| 330 TEST_F(MediaStreamConstraintsUtilVideoContentTest, IdealHeight) { |
| 331 // Unconstrained. |
| 332 { |
| 333 constraint_factory_.Reset(); |
| 334 const int kIdealHeight = 1000; |
| 335 constraint_factory_.basic().height.setIdeal(kIdealHeight); |
| 336 auto result = SelectSettings(); |
| 337 EXPECT_TRUE(result.HasValue()); |
| 338 EXPECT_EQ(kIdealHeight, result.Height()); |
| 339 // When ideal height is given, the algorithm returns a width that is closest |
| 340 // to height * kDefaultAspectRatio. |
| 341 EXPECT_EQ( |
| 342 std::round(kIdealHeight * MediaStreamVideoSource::kDefaultAspectRatio), |
| 343 result.Width()); |
| 344 CheckNonResolutionDefaults(result); |
| 345 } |
| 346 |
| 347 // Ideal greater than maximum. |
| 348 { |
| 349 constraint_factory_.Reset(); |
| 350 const int kIdealHeight = 1000; |
| 351 const int kMaxHeight = 800; |
| 352 constraint_factory_.basic().height.setIdeal(kIdealHeight); |
| 353 constraint_factory_.basic().height.setMax(kMaxHeight); |
| 354 auto result = SelectSettings(); |
| 355 EXPECT_TRUE(result.HasValue()); |
| 356 // Ideal height is greater than the maximum, expect maximum. |
| 357 EXPECT_EQ(kMaxHeight, result.Height()); |
| 358 // Expect closest to kMaxHeight * kDefaultAspectRatio. |
| 359 EXPECT_EQ( |
| 360 std::round(kMaxHeight * MediaStreamVideoSource::kDefaultAspectRatio), |
| 361 result.Width()); |
| 362 CheckNonResolutionDefaults(result); |
| 363 } |
| 364 |
| 365 // Ideal less than minimum. |
| 366 { |
| 367 constraint_factory_.Reset(); |
| 368 const int kIdealHeight = 1000; |
| 369 const int kMinHeight = 1200; |
| 370 constraint_factory_.basic().height.setIdeal(kIdealHeight); |
| 371 constraint_factory_.basic().height.setMin(kMinHeight); |
| 372 auto result = SelectSettings(); |
| 373 EXPECT_TRUE(result.HasValue()); |
| 374 // Ideal height is less than the minimum, expect minimum. |
| 375 EXPECT_EQ(kMinHeight, result.Height()); |
| 376 // Expect closest to kMinHeight * kDefaultAspectRatio. |
| 377 EXPECT_EQ( |
| 378 std::round(kMinHeight * MediaStreamVideoSource::kDefaultAspectRatio), |
| 379 result.Width()); |
| 380 CheckNonResolutionDefaults(result); |
| 381 } |
| 382 |
| 383 // Ideal intersects a box. |
| 384 { |
| 385 constraint_factory_.Reset(); |
| 386 constraint_factory_.basic().height.setMin(500); |
| 387 constraint_factory_.basic().height.setMax(1000); |
| 388 constraint_factory_.basic().width.setMin(100); |
| 389 constraint_factory_.basic().width.setMax(500); |
| 390 const int kIdealHeight = 750; |
| 391 constraint_factory_.basic().height.setIdeal(kIdealHeight); |
| 392 auto result = SelectSettings(); |
| 393 EXPECT_TRUE(result.HasValue()); |
| 394 // Ideal height is included in the bounding box. |
| 395 EXPECT_EQ(kIdealHeight, result.Height()); |
| 396 // Expect width closest to kIdealHeight * kDefaultAspectRatio, which is |
| 397 // outside the box. Closest is max width. |
| 398 EXPECT_EQ(constraint_factory_.basic().width.max(), result.Width()); |
| 399 CheckNonResolutionDefaults(result); |
| 400 |
| 401 constraint_factory_.basic().width.setMin(1200); |
| 402 constraint_factory_.basic().width.setMax(2000); |
| 403 result = SelectSettings(); |
| 404 EXPECT_TRUE(result.HasValue()); |
| 405 EXPECT_EQ(kIdealHeight, result.Height()); |
| 406 // kIdealHeight * kDefaultAspectRatio is outside the box. Closest is |
| 407 // min width. |
| 408 EXPECT_EQ(constraint_factory_.basic().width.min(), result.Width()); |
| 409 CheckNonResolutionDefaults(result); |
| 410 |
| 411 constraint_factory_.basic().width.setMin(100); |
| 412 constraint_factory_.basic().width.setMax(500); |
| 413 result = SelectSettings(); |
| 414 EXPECT_TRUE(result.HasValue()); |
| 415 EXPECT_EQ(kIdealHeight, result.Height()); |
| 416 // kIdealHeight * kDefaultAspectRatio is outside the box. Closest is |
| 417 // max width. |
| 418 EXPECT_EQ(constraint_factory_.basic().width.max(), result.Width()); |
| 419 CheckNonResolutionDefaults(result); |
| 420 } |
| 421 |
| 422 // Ideal outside the box, closest to the side coinciding with max height. |
| 423 { |
| 424 const int kMaxHeight = 1000; |
| 425 constraint_factory_.Reset(); |
| 426 constraint_factory_.basic().height.setMin(500); |
| 427 constraint_factory_.basic().height.setMax(kMaxHeight); |
| 428 constraint_factory_.basic().width.setMin(100); |
| 429 constraint_factory_.basic().width.setMax(500); |
| 430 constraint_factory_.basic().height.setIdeal(1200); |
| 431 auto result = SelectSettings(); |
| 432 EXPECT_TRUE(result.HasValue()); |
| 433 EXPECT_EQ(kMaxHeight, result.Height()); |
| 434 // Expect width closest to kMaxHeight * kDefaultAspectRatio, which is |
| 435 // outside the box. Closest it max width. |
| 436 EXPECT_EQ(constraint_factory_.basic().width.max(), result.Width()); |
| 437 CheckNonResolutionDefaults(result); |
| 438 |
| 439 constraint_factory_.basic().width.setMin(1500); |
| 440 constraint_factory_.basic().width.setMax(2000); |
| 441 result = SelectSettings(); |
| 442 EXPECT_TRUE(result.HasValue()); |
| 443 EXPECT_EQ(kMaxHeight, result.Height()); |
| 444 // kMaxHeight * kDefaultAspectRatio is outside the box. Closest is min |
| 445 // width. |
| 446 EXPECT_EQ(constraint_factory_.basic().width.min(), result.Width()); |
| 447 CheckNonResolutionDefaults(result); |
| 448 |
| 449 constraint_factory_.basic().width.setMin(100); |
| 450 result = SelectSettings(); |
| 451 EXPECT_TRUE(result.HasValue()); |
| 452 EXPECT_EQ(kMaxHeight, result.Height()); |
| 453 // kMaxHeight * kDefaultAspectRatio is within the width limits. |
| 454 EXPECT_EQ( |
| 455 std::round(kMaxHeight * MediaStreamVideoSource::kDefaultAspectRatio), |
| 456 result.Width()); |
| 457 CheckNonResolutionDefaults(result); |
| 458 } |
| 459 |
| 460 // Ideal outside the constrained set, closest to a single point. |
| 461 { |
| 462 constraint_factory_.Reset(); |
| 463 constraint_factory_.basic().height.setMin(500); |
| 464 constraint_factory_.basic().height.setMax(1000); |
| 465 constraint_factory_.basic().width.setMin(500); |
| 466 constraint_factory_.basic().width.setMax(1000); |
| 467 constraint_factory_.basic().aspectRatio.setMin(1.0); |
| 468 constraint_factory_.basic().height.setIdeal(1200); |
| 469 auto result = SelectSettings(); |
| 470 EXPECT_TRUE(result.HasValue()); |
| 471 // (max-height, max-width) is the single point closest to the ideal line. |
| 472 EXPECT_EQ(constraint_factory_.basic().height.max(), result.Height()); |
| 473 EXPECT_EQ(constraint_factory_.basic().width.max(), result.Width()); |
| 474 CheckNonResolutionDefaults(result); |
| 475 } |
| 476 } |
| 477 |
| 478 TEST_F(MediaStreamConstraintsUtilVideoContentTest, MandatoryExactWidth) { |
| 479 constraint_factory_.Reset(); |
| 480 const int kWidth = 1000; |
| 481 constraint_factory_.basic().width.setExact(kWidth); |
| 482 auto result = SelectSettings(); |
| 483 EXPECT_TRUE(result.HasValue()); |
| 484 EXPECT_EQ(kWidth, result.Width()); |
| 485 EXPECT_EQ(std::round(kWidth / MediaStreamVideoSource::kDefaultAspectRatio), |
| 486 result.Height()); |
| 487 CheckNonResolutionDefaults(result); |
| 488 } |
| 489 |
| 490 TEST_F(MediaStreamConstraintsUtilVideoContentTest, MandatoryMinWidth) { |
| 491 constraint_factory_.Reset(); |
| 492 const int kWidth = 1000; |
| 493 constraint_factory_.basic().width.setMin(kWidth); |
| 494 auto result = SelectSettings(); |
| 495 EXPECT_TRUE(result.HasValue()); |
| 496 // kWidth is greater that the default, so expect kWidth. |
| 497 EXPECT_EQ(kWidth, result.Width()); |
| 498 EXPECT_EQ(std::round(kWidth / MediaStreamVideoSource::kDefaultAspectRatio), |
| 499 result.Height()); |
| 500 CheckNonResolutionDefaults(result); |
| 501 |
| 502 const int kSmallWidth = 100; |
| 503 constraint_factory_.basic().width.setMin(kSmallWidth); |
| 504 result = SelectSettings(); |
| 505 EXPECT_TRUE(result.HasValue()); |
| 506 // kSmallWidth is less that the default, so expect the default. |
| 507 EXPECT_EQ(MediaStreamVideoSource::kDefaultWidth, result.Width()); |
| 508 EXPECT_EQ(MediaStreamVideoSource::kDefaultHeight, result.Height()); |
| 509 CheckNonResolutionDefaults(result); |
| 510 } |
| 511 |
| 512 TEST_F(MediaStreamConstraintsUtilVideoContentTest, MandatoryMaxWidth) { |
| 513 constraint_factory_.Reset(); |
| 514 const int kWidth = 1000; |
| 515 constraint_factory_.basic().width.setMax(kWidth); |
| 516 auto result = SelectSettings(); |
| 517 EXPECT_TRUE(result.HasValue()); |
| 518 // kWidth is greater that the default, so expect the default. |
| 519 EXPECT_EQ(MediaStreamVideoSource::kDefaultWidth, result.Width()); |
| 520 EXPECT_EQ(MediaStreamVideoSource::kDefaultHeight, result.Height()); |
| 521 CheckNonResolutionDefaults(result); |
| 522 |
| 523 const int kSmallWidth = 100; |
| 524 constraint_factory_.basic().width.setMax(kSmallWidth); |
| 525 result = SelectSettings(); |
| 526 EXPECT_TRUE(result.HasValue()); |
| 527 // kSmallWidth is less that the default, so expect kSmallWidth. |
| 528 EXPECT_EQ(kSmallWidth, result.Width()); |
| 529 EXPECT_EQ( |
| 530 std::round(kSmallWidth / MediaStreamVideoSource::kDefaultAspectRatio), |
| 531 result.Height()); |
| 532 CheckNonResolutionDefaults(result); |
| 533 } |
| 534 |
| 535 TEST_F(MediaStreamConstraintsUtilVideoContentTest, MandatoryWidthRange) { |
| 536 constraint_factory_.Reset(); |
| 537 { |
| 538 const int kMinWidth = 300; |
| 539 const int kMaxWidth = 1000; |
| 540 constraint_factory_.basic().width.setMin(kMinWidth); |
| 541 constraint_factory_.basic().width.setMax(kMaxWidth); |
| 542 auto result = SelectSettings(); |
| 543 EXPECT_TRUE(result.HasValue()); |
| 544 // The range includes the default, so expect the default. |
| 545 EXPECT_EQ(MediaStreamVideoSource::kDefaultWidth, result.Width()); |
| 546 EXPECT_EQ(MediaStreamVideoSource::kDefaultHeight, result.Height()); |
| 547 CheckNonResolutionDefaults(result); |
| 548 } |
| 549 |
| 550 { |
| 551 const int kMinWidth = 900; |
| 552 const int kMaxWidth = 1000; |
| 553 constraint_factory_.basic().width.setMin(kMinWidth); |
| 554 constraint_factory_.basic().width.setMax(kMaxWidth); |
| 555 auto result = SelectSettings(); |
| 556 EXPECT_TRUE(result.HasValue()); |
| 557 // The whole range is greater than the default, so expect the range minimum. |
| 558 EXPECT_EQ(kMinWidth, result.Width()); |
| 559 EXPECT_EQ( |
| 560 std::round(kMinWidth / MediaStreamVideoSource::kDefaultAspectRatio), |
| 561 result.Height()); |
| 562 CheckNonResolutionDefaults(result); |
| 563 } |
| 564 |
| 565 { |
| 566 const int kMinWidth = 300; |
| 567 const int kMaxWidth = 400; |
| 568 constraint_factory_.basic().width.setMin(kMinWidth); |
| 569 constraint_factory_.basic().width.setMax(kMaxWidth); |
| 570 auto result = SelectSettings(); |
| 571 EXPECT_TRUE(result.HasValue()); |
| 572 // The whole range is less than the default, so expect the range maximum. |
| 573 EXPECT_EQ(kMaxWidth, result.Width()); |
| 574 EXPECT_EQ( |
| 575 std::round(kMaxWidth / MediaStreamVideoSource::kDefaultAspectRatio), |
| 576 result.Height()); |
| 577 CheckNonResolutionDefaults(result); |
| 578 } |
| 579 } |
| 580 |
| 581 TEST_F(MediaStreamConstraintsUtilVideoContentTest, IdealWidth) { |
| 582 // Unconstrained |
| 583 { |
| 584 constraint_factory_.Reset(); |
| 585 const int kIdealWidth = 1000; |
| 586 constraint_factory_.basic().width.setIdeal(kIdealWidth); |
| 587 auto result = SelectSettings(); |
| 588 EXPECT_TRUE(result.HasValue()); |
| 589 EXPECT_EQ(kIdealWidth, result.Width()); |
| 590 // When ideal width is given, the algorithm returns a height that is closest |
| 591 // to width / kDefaultAspectRatio. |
| 592 EXPECT_EQ( |
| 593 std::round(kIdealWidth / MediaStreamVideoSource::kDefaultAspectRatio), |
| 594 result.Height()); |
| 595 CheckNonResolutionDefaults(result); |
| 596 } |
| 597 |
| 598 // Ideal greater than maximum. |
| 599 { |
| 600 constraint_factory_.Reset(); |
| 601 const int kIdealWidth = 1000; |
| 602 const int kMaxWidth = 800; |
| 603 constraint_factory_.basic().width.setIdeal(kIdealWidth); |
| 604 constraint_factory_.basic().width.setMax(kMaxWidth); |
| 605 auto result = SelectSettings(); |
| 606 EXPECT_TRUE(result.HasValue()); |
| 607 EXPECT_EQ(kMaxWidth, result.Width()); |
| 608 // Expect closest to kMaxWidth / kDefaultAspectRatio. |
| 609 EXPECT_EQ( |
| 610 std::round(kMaxWidth / MediaStreamVideoSource::kDefaultAspectRatio), |
| 611 result.Height()); |
| 612 CheckNonResolutionDefaults(result); |
| 613 } |
| 614 |
| 615 // Ideal less than minimum. |
| 616 { |
| 617 constraint_factory_.Reset(); |
| 618 const int kIdealWidth = 1000; |
| 619 const int kMinWidth = 1200; |
| 620 constraint_factory_.basic().width.setIdeal(kIdealWidth); |
| 621 constraint_factory_.basic().width.setMin(kMinWidth); |
| 622 auto result = SelectSettings(); |
| 623 EXPECT_TRUE(result.HasValue()); |
| 624 EXPECT_EQ(kMinWidth, result.Width()); |
| 625 // Expect closest to kMinWidth / kDefaultAspectRatio. |
| 626 EXPECT_EQ( |
| 627 std::round(kMinWidth / MediaStreamVideoSource::kDefaultAspectRatio), |
| 628 result.Height()); |
| 629 CheckNonResolutionDefaults(result); |
| 630 } |
| 631 |
| 632 // Ideal intersects a box. |
| 633 { |
| 634 constraint_factory_.Reset(); |
| 635 constraint_factory_.basic().width.setMin(500); |
| 636 constraint_factory_.basic().width.setMax(1000); |
| 637 constraint_factory_.basic().height.setMin(100); |
| 638 constraint_factory_.basic().height.setMax(500); |
| 639 const int kIdealWidth = 750; |
| 640 constraint_factory_.basic().width.setIdeal(kIdealWidth); |
| 641 auto result = SelectSettings(); |
| 642 EXPECT_TRUE(result.HasValue()); |
| 643 // Ideal width is included in the bounding box. |
| 644 EXPECT_EQ(kIdealWidth, result.Width()); |
| 645 // Expect height closest to kIdealWidth / kDefaultAspectRatio, which is |
| 646 // outside the box. Closest is max height. |
| 647 EXPECT_EQ(constraint_factory_.basic().height.max(), result.Height()); |
| 648 CheckNonResolutionDefaults(result); |
| 649 |
| 650 constraint_factory_.basic().height.setMin(1200); |
| 651 constraint_factory_.basic().height.setMax(2000); |
| 652 result = SelectSettings(); |
| 653 EXPECT_TRUE(result.HasValue()); |
| 654 EXPECT_EQ(kIdealWidth, result.Width()); |
| 655 // kIdealWidth / kDefaultAspectRatio outside the box. Closest is |
| 656 // min height. |
| 657 EXPECT_EQ(constraint_factory_.basic().height.min(), result.Height()); |
| 658 CheckNonResolutionDefaults(result); |
| 659 |
| 660 constraint_factory_.basic().height.setMin(100); |
| 661 constraint_factory_.basic().height.setMax(500); |
| 662 result = SelectSettings(); |
| 663 EXPECT_TRUE(result.HasValue()); |
| 664 EXPECT_EQ(kIdealWidth, result.Width()); |
| 665 // kIdealWidth / kDefaultAspectRatio is outside the box. Closest is max |
| 666 // height. |
| 667 EXPECT_EQ(constraint_factory_.basic().height.max(), result.Height()); |
| 668 CheckNonResolutionDefaults(result); |
| 669 } |
| 670 |
| 671 // Ideal outside the box, closest to the side coinciding with max width. |
| 672 { |
| 673 const int kMaxWidth = 1000; |
| 674 constraint_factory_.Reset(); |
| 675 constraint_factory_.basic().width.setMin(500); |
| 676 constraint_factory_.basic().width.setMax(kMaxWidth); |
| 677 constraint_factory_.basic().height.setMin(100); |
| 678 constraint_factory_.basic().height.setMax(500); |
| 679 constraint_factory_.basic().width.setIdeal(1200); |
| 680 auto result = SelectSettings(); |
| 681 EXPECT_TRUE(result.HasValue()); |
| 682 EXPECT_EQ(kMaxWidth, result.Width()); |
| 683 // kMaxWidth / kDefaultAspectRatio is outside the box. Closest is max |
| 684 // height. |
| 685 EXPECT_EQ(constraint_factory_.basic().height.max(), result.Height()); |
| 686 CheckNonResolutionDefaults(result); |
| 687 |
| 688 constraint_factory_.basic().height.setMin(1500); |
| 689 constraint_factory_.basic().height.setMax(2000); |
| 690 result = SelectSettings(); |
| 691 EXPECT_TRUE(result.HasValue()); |
| 692 EXPECT_EQ(kMaxWidth, result.Width()); |
| 693 // kMaxWidth / kDefaultAspectRatio is outside the box. Closest is |
| 694 // min height. |
| 695 EXPECT_EQ(constraint_factory_.basic().height.min(), result.Height()); |
| 696 CheckNonResolutionDefaults(result); |
| 697 |
| 698 constraint_factory_.basic().height.setMin(100); |
| 699 result = SelectSettings(); |
| 700 EXPECT_TRUE(result.HasValue()); |
| 701 EXPECT_EQ(kMaxWidth, result.Width()); |
| 702 // kMaxWidth / kDefaultAspectRatio is within the height limits. |
| 703 EXPECT_EQ( |
| 704 std::round(kMaxWidth / MediaStreamVideoSource::kDefaultAspectRatio), |
| 705 result.Height()); |
| 706 CheckNonResolutionDefaults(result); |
| 707 } |
| 708 |
| 709 // Ideal outside the constrained set, closest to a single point. |
| 710 { |
| 711 constraint_factory_.Reset(); |
| 712 constraint_factory_.basic().width.setMin(100); |
| 713 constraint_factory_.basic().width.setMax(500); |
| 714 constraint_factory_.basic().height.setMin(100); |
| 715 constraint_factory_.basic().height.setMax(500); |
| 716 constraint_factory_.basic().aspectRatio.setMax(1.0); |
| 717 constraint_factory_.basic().width.setIdeal(1200); |
| 718 auto result = SelectSettings(); |
| 719 EXPECT_TRUE(result.HasValue()); |
| 720 // (max-width, max-height) is the single point closest to the ideal line. |
| 721 EXPECT_EQ(constraint_factory_.basic().width.max(), result.Width()); |
| 722 EXPECT_EQ(constraint_factory_.basic().height.max(), result.Height()); |
| 723 CheckNonResolutionDefaults(result); |
| 724 } |
| 725 } |
| 726 |
| 727 TEST_F(MediaStreamConstraintsUtilVideoContentTest, MandatoryExactAspectRatio) { |
| 728 constraint_factory_.Reset(); |
| 729 const double kAspectRatio = 2.0; |
| 730 constraint_factory_.basic().aspectRatio.setExact(kAspectRatio); |
| 731 auto result = SelectSettings(); |
| 732 EXPECT_TRUE(result.HasValue()); |
| 733 // Given that the default aspect ratio cannot be preserved, the algorithm |
| 734 // tries to preserve, among the default height or width, the one that leads |
| 735 // to highest area. In this case, height is preserved. |
| 736 EXPECT_EQ(MediaStreamVideoSource::kDefaultHeight, result.Height()); |
| 737 EXPECT_EQ(std::round(MediaStreamVideoSource::kDefaultHeight * kAspectRatio), |
| 738 result.Width()); |
| 739 CheckNonResolutionDefaults(result); |
| 740 } |
| 741 |
| 742 TEST_F(MediaStreamConstraintsUtilVideoContentTest, MandatoryMinAspectRatio) { |
| 743 constraint_factory_.Reset(); |
| 744 const double kAspectRatio = 2.0; |
| 745 constraint_factory_.basic().aspectRatio.setMin(kAspectRatio); |
| 746 auto result = SelectSettings(); |
| 747 EXPECT_TRUE(result.HasValue()); |
| 748 // kAspectRatio is greater that the default, so expect kAspectRatio. |
| 749 EXPECT_EQ(MediaStreamVideoSource::kDefaultHeight, result.Height()); |
| 750 EXPECT_EQ(std::round(MediaStreamVideoSource::kDefaultHeight * kAspectRatio), |
| 751 result.Width()); |
| 752 CheckNonResolutionDefaults(result); |
| 753 |
| 754 const double kSmallAspectRatio = 0.5; |
| 755 constraint_factory_.basic().aspectRatio.setMin(kSmallAspectRatio); |
| 756 result = SelectSettings(); |
| 757 EXPECT_TRUE(result.HasValue()); |
| 758 // kSmallAspectRatio is less that the default, so expect the default. |
| 759 EXPECT_EQ(MediaStreamVideoSource::kDefaultHeight, result.Height()); |
| 760 EXPECT_EQ(MediaStreamVideoSource::kDefaultWidth, result.Width()); |
| 761 CheckNonResolutionDefaults(result); |
| 762 } |
| 763 |
| 764 TEST_F(MediaStreamConstraintsUtilVideoContentTest, MandatoryMaxAspectRatio) { |
| 765 constraint_factory_.Reset(); |
| 766 const double kAspectRatio = 2.0; |
| 767 constraint_factory_.basic().aspectRatio.setMax(kAspectRatio); |
| 768 auto result = SelectSettings(); |
| 769 EXPECT_TRUE(result.HasValue()); |
| 770 // kAspectRatio is greater that the default, so expect the default. |
| 771 EXPECT_EQ(MediaStreamVideoSource::kDefaultHeight, result.Height()); |
| 772 EXPECT_EQ(MediaStreamVideoSource::kDefaultWidth, result.Width()); |
| 773 CheckNonResolutionDefaults(result); |
| 774 |
| 775 const double kSmallAspectRatio = 0.5; |
| 776 constraint_factory_.basic().aspectRatio.setMax(kSmallAspectRatio); |
| 777 result = SelectSettings(); |
| 778 EXPECT_TRUE(result.HasValue()); |
| 779 // kSmallAspectRatio is less that the default, so expect kSmallAspectRatio. |
| 780 // Prefer to preserve default width since that leads to larger area than |
| 781 // preserving default height. |
| 782 EXPECT_EQ( |
| 783 std::round(MediaStreamVideoSource::kDefaultWidth / kSmallAspectRatio), |
| 784 result.Height()); |
| 785 EXPECT_EQ(MediaStreamVideoSource::kDefaultWidth, result.Width()); |
| 786 CheckNonResolutionDefaults(result); |
| 787 } |
| 788 |
| 789 TEST_F(MediaStreamConstraintsUtilVideoContentTest, MandatoryRangeAspectRatio) { |
| 790 constraint_factory_.Reset(); |
| 791 { |
| 792 const double kMinAspectRatio = 0.5; |
| 793 const double kMaxAspectRatio = 2.0; |
| 794 constraint_factory_.basic().aspectRatio.setMin(kMinAspectRatio); |
| 795 constraint_factory_.basic().aspectRatio.setMax(kMaxAspectRatio); |
| 796 auto result = SelectSettings(); |
| 797 EXPECT_TRUE(result.HasValue()); |
| 798 // Range includes default, so expect the default. |
| 799 EXPECT_EQ(MediaStreamVideoSource::kDefaultHeight, result.Height()); |
| 800 EXPECT_EQ(MediaStreamVideoSource::kDefaultWidth, result.Width()); |
| 801 CheckNonResolutionDefaults(result); |
| 802 } |
| 803 |
| 804 { |
| 805 const double kMinAspectRatio = 2.0; |
| 806 const double kMaxAspectRatio = 3.0; |
| 807 constraint_factory_.basic().aspectRatio.setMin(kMinAspectRatio); |
| 808 constraint_factory_.basic().aspectRatio.setMax(kMaxAspectRatio); |
| 809 auto result = SelectSettings(); |
| 810 EXPECT_TRUE(result.HasValue()); |
| 811 // The whole range is greater than the default. Expect the minimum. |
| 812 EXPECT_EQ(MediaStreamVideoSource::kDefaultHeight, result.Height()); |
| 813 EXPECT_EQ( |
| 814 std::round(MediaStreamVideoSource::kDefaultHeight * kMinAspectRatio), |
| 815 result.Width()); |
| 816 CheckNonResolutionDefaults(result); |
| 817 } |
| 818 |
| 819 { |
| 820 const double kMinAspectRatio = 0.5; |
| 821 const double kMaxAspectRatio = 1.0; |
| 822 constraint_factory_.basic().aspectRatio.setMin(kMinAspectRatio); |
| 823 constraint_factory_.basic().aspectRatio.setMax(kMaxAspectRatio); |
| 824 auto result = SelectSettings(); |
| 825 EXPECT_TRUE(result.HasValue()); |
| 826 // The whole range is less than the default. Expect the maximum. |
| 827 EXPECT_EQ( |
| 828 std::round(MediaStreamVideoSource::kDefaultWidth / kMaxAspectRatio), |
| 829 result.Height()); |
| 830 EXPECT_EQ(MediaStreamVideoSource::kDefaultWidth, result.Width()); |
| 831 CheckNonResolutionDefaults(result); |
| 832 } |
| 833 } |
| 834 |
| 835 TEST_F(MediaStreamConstraintsUtilVideoContentTest, IdealAspectRatio) { |
| 836 // Unconstrained. |
| 837 { |
| 838 constraint_factory_.Reset(); |
| 839 const double kIdealAspectRatio = 2.0; |
| 840 constraint_factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); |
| 841 auto result = SelectSettings(); |
| 842 EXPECT_TRUE(result.HasValue()); |
| 843 EXPECT_EQ(MediaStreamVideoSource::kDefaultHeight, result.Height()); |
| 844 EXPECT_EQ( |
| 845 std::round(MediaStreamVideoSource::kDefaultHeight * kIdealAspectRatio), |
| 846 result.Width()); |
| 847 CheckNonResolutionDefaults(result); |
| 848 } |
| 849 |
| 850 // Ideal greater than maximum. |
| 851 { |
| 852 constraint_factory_.Reset(); |
| 853 const double kIdealAspectRatio = 2.0; |
| 854 const double kMaxAspectRatio = 1.5; |
| 855 constraint_factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); |
| 856 constraint_factory_.basic().aspectRatio.setMax(kMaxAspectRatio); |
| 857 auto result = SelectSettings(); |
| 858 EXPECT_TRUE(result.HasValue()); |
| 859 // Ideal height is greater than the maximum, expect maximum. |
| 860 EXPECT_EQ(MediaStreamVideoSource::kDefaultHeight, result.Height()); |
| 861 EXPECT_EQ( |
| 862 std::round(MediaStreamVideoSource::kDefaultHeight * kMaxAspectRatio), |
| 863 result.Width()); |
| 864 CheckNonResolutionDefaults(result); |
| 865 } |
| 866 |
| 867 // Ideal less than minimum. |
| 868 { |
| 869 constraint_factory_.Reset(); |
| 870 const double kIdealAspectRatio = 1.0; |
| 871 const double kMinAspectRatio = 1.5; |
| 872 constraint_factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); |
| 873 constraint_factory_.basic().aspectRatio.setMin(kMinAspectRatio); |
| 874 auto result = SelectSettings(); |
| 875 EXPECT_TRUE(result.HasValue()); |
| 876 // Ideal height is greater than the maximum, expect maximum. |
| 877 EXPECT_EQ(MediaStreamVideoSource::kDefaultHeight, result.Height()); |
| 878 EXPECT_EQ( |
| 879 std::round(MediaStreamVideoSource::kDefaultHeight * kMinAspectRatio), |
| 880 result.Width()); |
| 881 CheckNonResolutionDefaults(result); |
| 882 } |
| 883 |
| 884 // Ideal intersects a box. |
| 885 { |
| 886 constraint_factory_.Reset(); |
| 887 constraint_factory_.basic().height.setMin(100); |
| 888 constraint_factory_.basic().height.setMax(500); |
| 889 constraint_factory_.basic().width.setMin(100); |
| 890 constraint_factory_.basic().width.setMax(500); |
| 891 const int kIdealAspectRatio = 2.0; |
| 892 constraint_factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); |
| 893 auto result = SelectSettings(); |
| 894 EXPECT_TRUE(result.HasValue()); |
| 895 // Ideal aspect-ratio is included in the bounding box, with the value |
| 896 // closest to a standard width or height being the cut with the maximum |
| 897 // width. |
| 898 EXPECT_EQ( |
| 899 std::round(constraint_factory_.basic().width.max() / kIdealAspectRatio), |
| 900 result.Height()); |
| 901 EXPECT_EQ(constraint_factory_.basic().width.max(), result.Width()); |
| 902 CheckNonResolutionDefaults(result); |
| 903 |
| 904 constraint_factory_.basic().height.setMin(1000); |
| 905 constraint_factory_.basic().height.setMax(5000); |
| 906 constraint_factory_.basic().width.setMin(1000); |
| 907 constraint_factory_.basic().width.setMax(5000); |
| 908 result = SelectSettings(); |
| 909 EXPECT_TRUE(result.HasValue()); |
| 910 // Ideal aspect-ratio is included in the bounding box, with the value |
| 911 // closest to a standard width or height and largest area being the cut with |
| 912 // the minimum height. |
| 913 EXPECT_EQ(constraint_factory_.basic().height.min(), result.Height()); |
| 914 EXPECT_EQ(std::round(constraint_factory_.basic().height.min() * |
| 915 kIdealAspectRatio), |
| 916 result.Width()); |
| 917 CheckNonResolutionDefaults(result); |
| 918 |
| 919 constraint_factory_.basic().height.setMin(250); |
| 920 constraint_factory_.basic().height.setMax(5000); |
| 921 constraint_factory_.basic().width.setMin(250); |
| 922 constraint_factory_.basic().width.setMax(5000); |
| 923 result = SelectSettings(); |
| 924 EXPECT_TRUE(result.HasValue()); |
| 925 // Ideal aspect-ratio and default width and height are included in the |
| 926 // bounding box. Preserving default height leads to larger area than |
| 927 // preserving default width. |
| 928 EXPECT_EQ(MediaStreamVideoSource::kDefaultHeight, result.Height()); |
| 929 EXPECT_EQ(MediaStreamVideoSource::kDefaultHeight * kIdealAspectRatio, |
| 930 result.Width()); |
| 931 CheckNonResolutionDefaults(result); |
| 932 } |
| 933 |
| 934 // Ideal outside the constrained area, closest to min or max aspect ratio. |
| 935 { |
| 936 const double kMinAspectRatio = 0.5; |
| 937 const double kMaxAspectRatio = 2.0; |
| 938 constraint_factory_.Reset(); |
| 939 constraint_factory_.basic().height.setMin(100); |
| 940 constraint_factory_.basic().height.setMax(500); |
| 941 constraint_factory_.basic().width.setMin(100); |
| 942 constraint_factory_.basic().width.setMax(500); |
| 943 constraint_factory_.basic().aspectRatio.setMin(kMinAspectRatio); |
| 944 constraint_factory_.basic().aspectRatio.setMax(kMaxAspectRatio); |
| 945 constraint_factory_.basic().aspectRatio.setIdeal(3.0); |
| 946 auto result = SelectSettings(); |
| 947 EXPECT_TRUE(result.HasValue()); |
| 948 // Ideal is closest to kMaxAspectRatio. |
| 949 EXPECT_EQ( |
| 950 std::round(constraint_factory_.basic().width.max() / kMaxAspectRatio), |
| 951 result.Height()); |
| 952 EXPECT_EQ(constraint_factory_.basic().width.max(), result.Width()); |
| 953 CheckNonResolutionDefaults(result); |
| 954 |
| 955 constraint_factory_.basic().aspectRatio.setIdeal(0.3); |
| 956 result = SelectSettings(); |
| 957 EXPECT_TRUE(result.HasValue()); |
| 958 // Ideal is closest to kMinAspectRatio. |
| 959 EXPECT_EQ(constraint_factory_.basic().height.max(), result.Height()); |
| 960 EXPECT_EQ( |
| 961 std::round(constraint_factory_.basic().height.max() * kMinAspectRatio), |
| 962 result.Width()); |
| 963 CheckNonResolutionDefaults(result); |
| 964 |
| 965 // Use a box that is bigger and further from the origin to force closeness |
| 966 // to a different default dimension. |
| 967 constraint_factory_.basic().height.setMin(1000); |
| 968 constraint_factory_.basic().height.setMax(5000); |
| 969 constraint_factory_.basic().width.setMin(1000); |
| 970 constraint_factory_.basic().width.setMax(5000); |
| 971 constraint_factory_.basic().aspectRatio.setIdeal(3.0); |
| 972 result = SelectSettings(); |
| 973 EXPECT_TRUE(result.HasValue()); |
| 974 // Ideal is closest to kMaxAspectRatio. |
| 975 EXPECT_EQ(constraint_factory_.basic().height.min(), result.Height()); |
| 976 EXPECT_EQ( |
| 977 std::round(constraint_factory_.basic().height.min() * kMaxAspectRatio), |
| 978 result.Width()); |
| 979 CheckNonResolutionDefaults(result); |
| 980 |
| 981 constraint_factory_.basic().aspectRatio.setIdeal(0.3); |
| 982 result = SelectSettings(); |
| 983 EXPECT_TRUE(result.HasValue()); |
| 984 // Ideal is closest to kMinAspectRatio. |
| 985 EXPECT_EQ( |
| 986 std::round(constraint_factory_.basic().width.min() / kMinAspectRatio), |
| 987 result.Height()); |
| 988 EXPECT_EQ(constraint_factory_.basic().width.min(), result.Width()); |
| 989 CheckNonResolutionDefaults(result); |
| 990 } |
| 991 |
| 992 // Ideal outside the constrained area, closest to a single point. |
| 993 { |
| 994 constraint_factory_.Reset(); |
| 995 constraint_factory_.basic().height.setMin(100); |
| 996 constraint_factory_.basic().height.setMax(500); |
| 997 constraint_factory_.basic().width.setMin(100); |
| 998 constraint_factory_.basic().width.setMax(500); |
| 999 constraint_factory_.basic().aspectRatio.setMin(1.0); |
| 1000 constraint_factory_.basic().aspectRatio.setIdeal(10.0); |
| 1001 auto result = SelectSettings(); |
| 1002 EXPECT_TRUE(result.HasValue()); |
| 1003 // Ideal is closest to the min height and max width. |
| 1004 EXPECT_EQ(constraint_factory_.basic().height.min(), result.Height()); |
| 1005 EXPECT_EQ(constraint_factory_.basic().width.max(), result.Width()); |
| 1006 CheckNonResolutionDefaults(result); |
| 1007 } |
| 1008 } |
| 1009 |
| 1010 TEST_F(MediaStreamConstraintsUtilVideoContentTest, MandatoryExactFrameRate) { |
| 1011 constraint_factory_.Reset(); |
| 1012 const int kFrameRate = 45.0; |
| 1013 constraint_factory_.basic().frameRate.setExact(kFrameRate); |
| 1014 auto result = SelectSettings(); |
| 1015 EXPECT_TRUE(result.HasValue()); |
| 1016 EXPECT_EQ(kFrameRate, result.FrameRate()); |
| 1017 CheckNonFrameRateDefaults(result); |
| 1018 } |
| 1019 |
| 1020 TEST_F(MediaStreamConstraintsUtilVideoContentTest, MandatoryMinFrameRate) { |
| 1021 constraint_factory_.Reset(); |
| 1022 const double kFrameRate = 45.0; |
| 1023 constraint_factory_.basic().frameRate.setMin(kFrameRate); |
| 1024 auto result = SelectSettings(); |
| 1025 EXPECT_TRUE(result.HasValue()); |
| 1026 // kFrameRate is greater that the default, so expect kFrameRate. |
| 1027 EXPECT_EQ(kFrameRate, result.FrameRate()); |
| 1028 CheckNonFrameRateDefaults(result); |
| 1029 |
| 1030 const double kSmallFrameRate = 5.0; |
| 1031 constraint_factory_.basic().frameRate.setMin(kSmallFrameRate); |
| 1032 result = SelectSettings(); |
| 1033 EXPECT_TRUE(result.HasValue()); |
| 1034 // kFrameRate is greater that the default, so expect kFrameRate. |
| 1035 EXPECT_EQ(MediaStreamVideoSource::kDefaultFrameRate, result.FrameRate()); |
| 1036 CheckNonFrameRateDefaults(result); |
| 1037 } |
| 1038 |
| 1039 TEST_F(MediaStreamConstraintsUtilVideoContentTest, MandatoryMaxFrameRate) { |
| 1040 constraint_factory_.Reset(); |
| 1041 const double kFrameRate = 45.0; |
| 1042 constraint_factory_.basic().frameRate.setMax(kFrameRate); |
| 1043 auto result = SelectSettings(); |
| 1044 EXPECT_TRUE(result.HasValue()); |
| 1045 // kFrameRate is greater that the default, so expect the default. |
| 1046 EXPECT_EQ(MediaStreamVideoSource::kDefaultFrameRate, result.FrameRate()); |
| 1047 CheckNonFrameRateDefaults(result); |
| 1048 |
| 1049 const double kSmallFrameRate = 5.0; |
| 1050 constraint_factory_.basic().frameRate.setMax(kSmallFrameRate); |
| 1051 result = SelectSettings(); |
| 1052 EXPECT_TRUE(result.HasValue()); |
| 1053 // kFrameRate is less that the default, so expect kFrameRate. |
| 1054 EXPECT_EQ(kSmallFrameRate, result.FrameRate()); |
| 1055 CheckNonFrameRateDefaults(result); |
| 1056 } |
| 1057 |
| 1058 TEST_F(MediaStreamConstraintsUtilVideoContentTest, MandatoryRangeFrameRate) { |
| 1059 constraint_factory_.Reset(); |
| 1060 { |
| 1061 const double kMinFrameRate = 15.0; |
| 1062 const double kMaxFrameRate = 45.0; |
| 1063 constraint_factory_.basic().frameRate.setMax(kMinFrameRate); |
| 1064 constraint_factory_.basic().frameRate.setMax(kMaxFrameRate); |
| 1065 auto result = SelectSettings(); |
| 1066 EXPECT_TRUE(result.HasValue()); |
| 1067 // The range includes the default, so expect the default. |
| 1068 EXPECT_EQ(MediaStreamVideoSource::kDefaultFrameRate, result.FrameRate()); |
| 1069 CheckNonFrameRateDefaults(result); |
| 1070 } |
| 1071 |
| 1072 { |
| 1073 const double kMinFrameRate = 45.0; |
| 1074 const double kMaxFrameRate = 55.0; |
| 1075 constraint_factory_.basic().frameRate.setMax(kMinFrameRate); |
| 1076 constraint_factory_.basic().frameRate.setMax(kMaxFrameRate); |
| 1077 auto result = SelectSettings(); |
| 1078 EXPECT_TRUE(result.HasValue()); |
| 1079 // The whole range is greater that the default, so expect the minimum. |
| 1080 EXPECT_EQ(MediaStreamVideoSource::kDefaultFrameRate, result.FrameRate()); |
| 1081 CheckNonFrameRateDefaults(result); |
| 1082 } |
| 1083 |
| 1084 { |
| 1085 const double kMinFrameRate = 10.0; |
| 1086 const double kMaxFrameRate = 15.0; |
| 1087 constraint_factory_.basic().frameRate.setMax(kMinFrameRate); |
| 1088 constraint_factory_.basic().frameRate.setMax(kMaxFrameRate); |
| 1089 auto result = SelectSettings(); |
| 1090 EXPECT_TRUE(result.HasValue()); |
| 1091 // The whole range is less that the default, so expect the maximum. |
| 1092 EXPECT_EQ(kMaxFrameRate, result.FrameRate()); |
| 1093 CheckNonFrameRateDefaults(result); |
| 1094 } |
| 1095 } |
| 1096 |
| 1097 TEST_F(MediaStreamConstraintsUtilVideoContentTest, IdealFrameRate) { |
| 1098 // Unconstrained. |
| 1099 { |
| 1100 constraint_factory_.Reset(); |
| 1101 const int kIdealFrameRate = 45.0; |
| 1102 constraint_factory_.basic().frameRate.setIdeal(kIdealFrameRate); |
| 1103 auto result = SelectSettings(); |
| 1104 EXPECT_TRUE(result.HasValue()); |
| 1105 EXPECT_EQ(kIdealFrameRate, result.FrameRate()); |
| 1106 CheckNonFrameRateDefaults(result); |
| 1107 } |
| 1108 |
| 1109 // Ideal greater than maximum. |
| 1110 { |
| 1111 constraint_factory_.Reset(); |
| 1112 const int kIdealFrameRate = 45.0; |
| 1113 const int kMaxFrameRate = 30.0; |
| 1114 constraint_factory_.basic().frameRate.setIdeal(kIdealFrameRate); |
| 1115 constraint_factory_.basic().frameRate.setMax(kMaxFrameRate); |
| 1116 auto result = SelectSettings(); |
| 1117 EXPECT_TRUE(result.HasValue()); |
| 1118 EXPECT_EQ(kMaxFrameRate, result.FrameRate()); |
| 1119 CheckNonFrameRateDefaults(result); |
| 1120 } |
| 1121 |
| 1122 // Ideal less than minimum. |
| 1123 { |
| 1124 constraint_factory_.Reset(); |
| 1125 const int kIdealFrameRate = 45.0; |
| 1126 const int kMinFrameRate = 50.0; |
| 1127 constraint_factory_.basic().frameRate.setIdeal(kIdealFrameRate); |
| 1128 constraint_factory_.basic().frameRate.setMin(kMinFrameRate); |
| 1129 auto result = SelectSettings(); |
| 1130 EXPECT_TRUE(result.HasValue()); |
| 1131 EXPECT_EQ(kMinFrameRate, result.FrameRate()); |
| 1132 CheckNonFrameRateDefaults(result); |
| 1133 } |
| 1134 |
| 1135 // Ideal within range. |
| 1136 { |
| 1137 constraint_factory_.Reset(); |
| 1138 const int kIdealFrameRate = 45.0; |
| 1139 const int kMinFrameRate = 35.0; |
| 1140 const int kMaxFrameRate = 50.0; |
| 1141 constraint_factory_.basic().frameRate.setIdeal(kIdealFrameRate); |
| 1142 constraint_factory_.basic().frameRate.setMin(kMinFrameRate); |
| 1143 constraint_factory_.basic().frameRate.setMax(kMaxFrameRate); |
| 1144 auto result = SelectSettings(); |
| 1145 EXPECT_TRUE(result.HasValue()); |
| 1146 EXPECT_EQ(kIdealFrameRate, result.FrameRate()); |
| 1147 CheckNonFrameRateDefaults(result); |
| 1148 } |
| 1149 } |
| 1150 |
| 1151 // The "Advanced" tests check selection criteria involving advanced constraint |
| 1152 // sets. |
| 1153 TEST_F(MediaStreamConstraintsUtilVideoContentTest, |
| 1154 AdvancedMinMaxResolutionFrameRate) { |
| 1155 constraint_factory_.Reset(); |
| 1156 blink::WebMediaTrackConstraintSet& advanced1 = |
| 1157 constraint_factory_.AddAdvanced(); |
| 1158 advanced1.width.setMin(2000000000); |
| 1159 advanced1.height.setMin(2000000000); |
| 1160 // The first advanced set cannot be satisfied and is therefore ignored in all |
| 1161 // calls to SelectSettings(). |
| 1162 // In this case, default settings must be selected. |
| 1163 auto result = SelectSettings(); |
| 1164 EXPECT_TRUE(result.HasValue()); |
| 1165 EXPECT_EQ(MediaStreamVideoSource::kDefaultHeight, result.Height()); |
| 1166 EXPECT_EQ(MediaStreamVideoSource::kDefaultWidth, result.Width()); |
| 1167 CheckNonResolutionDefaults(result); |
| 1168 |
| 1169 blink::WebMediaTrackConstraintSet& advanced2 = |
| 1170 constraint_factory_.AddAdvanced(); |
| 1171 advanced2.height.setMax(400); |
| 1172 advanced2.width.setMax(500); |
| 1173 advanced2.aspectRatio.setExact(5.0 / 4.0); |
| 1174 result = SelectSettings(); |
| 1175 EXPECT_TRUE(result.HasValue()); |
| 1176 EXPECT_EQ(400, result.Height()); |
| 1177 EXPECT_EQ(500, result.Width()); |
| 1178 CheckNonResolutionDefaults(result); |
| 1179 |
| 1180 blink::WebMediaTrackConstraintSet& advanced3 = |
| 1181 constraint_factory_.AddAdvanced(); |
| 1182 advanced3.frameRate.setMax(10.0); |
| 1183 result = SelectSettings(); |
| 1184 EXPECT_TRUE(result.HasValue()); |
| 1185 // The third advanced set is supported in addition to the previous set. |
| 1186 EXPECT_EQ(400, result.Height()); |
| 1187 EXPECT_EQ(500, result.Width()); |
| 1188 EXPECT_EQ(10.0, result.FrameRate()); |
| 1189 EXPECT_EQ(rtc::Optional<bool>(), result.noise_reduction()); |
| 1190 EXPECT_EQ(std::string(), result.device_id()); |
| 1191 |
| 1192 blink::WebMediaTrackConstraintSet& advanced4 = |
| 1193 constraint_factory_.AddAdvanced(); |
| 1194 advanced4.width.setExact(1000); |
| 1195 advanced4.height.setExact(1000); |
| 1196 result = SelectSettings(); |
| 1197 // The fourth advanced set cannot be supported in combination with the |
| 1198 // previous two sets, so it must be ignored. |
| 1199 EXPECT_TRUE(result.HasValue()); |
| 1200 EXPECT_EQ(400, result.Height()); |
| 1201 EXPECT_EQ(500, result.Width()); |
| 1202 EXPECT_EQ(10.0, result.FrameRate()); |
| 1203 EXPECT_EQ(rtc::Optional<bool>(), result.noise_reduction()); |
| 1204 EXPECT_EQ(std::string(), result.device_id()); |
| 1205 |
| 1206 constraint_factory_.basic().width.setIdeal(100); |
| 1207 constraint_factory_.basic().height.setIdeal(100); |
| 1208 result = SelectSettings(); |
| 1209 EXPECT_TRUE(result.HasValue()); |
| 1210 // The closest point to (100, 100) that satisfies all previous constraint |
| 1211 // sets is its projection on the aspect-ratio line 5.0/4.0. |
| 1212 // This is a point m*(4, 5) such that Dot((4,5), (100 - m(4,5))) == 0. |
| 1213 // This works out to be m = 900/41. |
| 1214 EXPECT_EQ(std::round(4.0 * 900.0 / 41.0), result.Height()); |
| 1215 EXPECT_EQ(std::round(5.0 * 900.0 / 41.0), result.Width()); |
| 1216 EXPECT_EQ(10.0, result.FrameRate()); |
| 1217 EXPECT_EQ(rtc::Optional<bool>(), result.noise_reduction()); |
| 1218 EXPECT_EQ(std::string(), result.device_id()); |
| 1219 |
| 1220 constraint_factory_.basic().width.setIdeal(2000); |
| 1221 constraint_factory_.basic().height.setIdeal(1500); |
| 1222 result = SelectSettings(); |
| 1223 EXPECT_TRUE(result.HasValue()); |
| 1224 // The projection of (2000,1500) on the aspect-ratio line 5.0/4.0 is beyond |
| 1225 // the maximum of (400, 500), so use the maximum allowed resolution. |
| 1226 EXPECT_TRUE(result.HasValue()); |
| 1227 EXPECT_EQ(400, result.Height()); |
| 1228 EXPECT_EQ(500, result.Width()); |
| 1229 EXPECT_EQ(10.0, result.FrameRate()); |
| 1230 EXPECT_EQ(rtc::Optional<bool>(), result.noise_reduction()); |
| 1231 EXPECT_EQ(std::string(), result.device_id()); |
| 1232 } |
| 1233 |
| 1234 TEST_F(MediaStreamConstraintsUtilVideoContentTest, AdvancedExactResolution) { |
| 1235 { |
| 1236 constraint_factory_.Reset(); |
| 1237 blink::WebMediaTrackConstraintSet& advanced1 = |
| 1238 constraint_factory_.AddAdvanced(); |
| 1239 advanced1.width.setExact(40000000); |
| 1240 advanced1.height.setExact(40000000); |
| 1241 blink::WebMediaTrackConstraintSet& advanced2 = |
| 1242 constraint_factory_.AddAdvanced(); |
| 1243 advanced2.width.setExact(300000000); |
| 1244 advanced2.height.setExact(300000000); |
| 1245 auto result = SelectSettings(); |
| 1246 // None of the constraint sets can be satisfied. Default resolution should |
| 1247 // be selected. |
| 1248 EXPECT_TRUE(result.HasValue()); |
| 1249 EXPECT_EQ(MediaStreamVideoSource::kDefaultHeight, result.Height()); |
| 1250 EXPECT_EQ(MediaStreamVideoSource::kDefaultWidth, result.Width()); |
| 1251 CheckNonResolutionDefaults(result); |
| 1252 |
| 1253 blink::WebMediaTrackConstraintSet& advanced3 = |
| 1254 constraint_factory_.AddAdvanced(); |
| 1255 advanced3.width.setExact(1920); |
| 1256 advanced3.height.setExact(1080); |
| 1257 result = SelectSettings(); |
| 1258 EXPECT_TRUE(result.HasValue()); |
| 1259 EXPECT_EQ(1920, result.Width()); |
| 1260 EXPECT_EQ(1080, result.Height()); |
| 1261 CheckNonResolutionDefaults(result); |
| 1262 |
| 1263 blink::WebMediaTrackConstraintSet& advanced4 = |
| 1264 constraint_factory_.AddAdvanced(); |
| 1265 advanced4.width.setExact(640); |
| 1266 advanced4.height.setExact(480); |
| 1267 result = SelectSettings(); |
| 1268 // The fourth constraint set contradicts the third set. The fourth set |
| 1269 // should be ignored. |
| 1270 EXPECT_TRUE(result.HasValue()); |
| 1271 EXPECT_EQ(1920, result.Width()); |
| 1272 EXPECT_EQ(1080, result.Height()); |
| 1273 CheckNonResolutionDefaults(result); |
| 1274 |
| 1275 constraint_factory_.basic().width.setIdeal(800); |
| 1276 constraint_factory_.basic().height.setIdeal(600); |
| 1277 result = SelectSettings(); |
| 1278 EXPECT_TRUE(result.HasValue()); |
| 1279 // The exact constraints has priority over ideal. |
| 1280 EXPECT_EQ(1920, result.Width()); |
| 1281 EXPECT_EQ(1080, result.Height()); |
| 1282 CheckNonResolutionDefaults(result); |
| 1283 } |
| 1284 } |
| 1285 |
| 1286 TEST_F(MediaStreamConstraintsUtilVideoContentTest, |
| 1287 AdvancedResolutionAndFrameRate) { |
| 1288 constraint_factory_.Reset(); |
| 1289 blink::WebMediaTrackConstraintSet& advanced1 = |
| 1290 constraint_factory_.AddAdvanced(); |
| 1291 advanced1.width.setExact(1920); |
| 1292 advanced1.height.setExact(1080); |
| 1293 blink::WebMediaTrackConstraintSet& advanced2 = |
| 1294 constraint_factory_.AddAdvanced(); |
| 1295 advanced2.frameRate.setExact(60.0); |
| 1296 auto result = SelectSettings(); |
| 1297 EXPECT_TRUE(result.HasValue()); |
| 1298 EXPECT_EQ(1920, result.Width()); |
| 1299 EXPECT_EQ(1080, result.Height()); |
| 1300 EXPECT_EQ(60.0, result.FrameRate()); |
| 1301 } |
| 1302 |
| 1303 TEST_F(MediaStreamConstraintsUtilVideoContentTest, AdvancedNoiseReduction) { |
| 1304 constraint_factory_.Reset(); |
| 1305 blink::WebMediaTrackConstraintSet& advanced1 = |
| 1306 constraint_factory_.AddAdvanced(); |
| 1307 advanced1.width.setMin(640); |
| 1308 advanced1.height.setMin(480); |
| 1309 blink::WebMediaTrackConstraintSet& advanced2 = |
| 1310 constraint_factory_.AddAdvanced(); |
| 1311 advanced2.width.setMin(1920); |
| 1312 advanced2.height.setMin(1080); |
| 1313 advanced2.googNoiseReduction.setExact(false); |
| 1314 auto result = SelectSettings(); |
| 1315 EXPECT_TRUE(result.HasValue()); |
| 1316 EXPECT_EQ(1920, result.Width()); |
| 1317 // Preserves default aspect ratio. |
| 1318 EXPECT_EQ(static_cast<int>(std::round( |
| 1319 result.Width() / MediaStreamVideoSource::kDefaultAspectRatio)), |
| 1320 result.Height()); |
| 1321 EXPECT_TRUE(result.noise_reduction() && !*result.noise_reduction()); |
| 1322 } |
| 1323 |
| 1324 // The "AdvancedContradictory" tests check that advanced constraint sets that |
| 1325 // contradict previous constraint sets are ignored. |
| 1326 TEST_F(MediaStreamConstraintsUtilVideoContentTest, |
| 1327 AdvancedContradictoryNoiseReduction) { |
| 1328 constraint_factory_.Reset(); |
| 1329 blink::WebMediaTrackConstraintSet& advanced1 = |
| 1330 constraint_factory_.AddAdvanced(); |
| 1331 advanced1.width.setExact(640); |
| 1332 advanced1.height.setExact(480); |
| 1333 advanced1.googNoiseReduction.setExact(true); |
| 1334 blink::WebMediaTrackConstraintSet& advanced2 = |
| 1335 constraint_factory_.AddAdvanced(); |
| 1336 advanced2.width.setExact(1920); |
| 1337 advanced2.height.setExact(1080); |
| 1338 advanced2.googNoiseReduction.setExact(false); |
| 1339 auto result = SelectSettings(); |
| 1340 EXPECT_TRUE(result.HasValue()); |
| 1341 EXPECT_EQ(640, result.Width()); |
| 1342 EXPECT_EQ(480, result.Height()); |
| 1343 EXPECT_TRUE(result.noise_reduction() && *result.noise_reduction()); |
| 1344 } |
| 1345 |
| 1346 TEST_F(MediaStreamConstraintsUtilVideoContentTest, |
| 1347 AdvancedContradictoryExactResolution) { |
| 1348 constraint_factory_.Reset(); |
| 1349 blink::WebMediaTrackConstraintSet& advanced1 = |
| 1350 constraint_factory_.AddAdvanced(); |
| 1351 advanced1.width.setExact(640); |
| 1352 advanced1.height.setExact(480); |
| 1353 blink::WebMediaTrackConstraintSet& advanced2 = |
| 1354 constraint_factory_.AddAdvanced(); |
| 1355 advanced2.width.setExact(1920); |
| 1356 advanced2.height.setExact(1080); |
| 1357 auto result = SelectSettings(); |
| 1358 EXPECT_TRUE(result.HasValue()); |
| 1359 EXPECT_EQ(640, result.Width()); |
| 1360 EXPECT_EQ(480, result.Height()); |
| 1361 // Resolution cannot be adjusted due to exact in the first advanced set. |
| 1362 CheckNonResolutionDefaults(result); |
| 1363 } |
| 1364 |
| 1365 TEST_F(MediaStreamConstraintsUtilVideoContentTest, |
| 1366 AdvancedContradictoryMaxMinResolutionFrameRate) { |
| 1367 constraint_factory_.Reset(); |
| 1368 blink::WebMediaTrackConstraintSet& advanced1 = |
| 1369 constraint_factory_.AddAdvanced(); |
| 1370 advanced1.width.setMax(640); |
| 1371 advanced1.height.setMax(480); |
| 1372 blink::WebMediaTrackConstraintSet& advanced2 = |
| 1373 constraint_factory_.AddAdvanced(); |
| 1374 advanced2.width.setMin(1920); |
| 1375 advanced2.height.setMin(1080); |
| 1376 advanced2.frameRate.setExact(60.0); |
| 1377 auto result = SelectSettings(); |
| 1378 EXPECT_TRUE(result.HasValue()); |
| 1379 EXPECT_EQ(640, result.Width()); |
| 1380 EXPECT_EQ(480, result.Height()); |
| 1381 // Resolution cannot exceed the requested resolution. |
| 1382 EXPECT_EQ(MediaStreamVideoSource::kDefaultFrameRate, result.FrameRate()); |
| 1383 } |
| 1384 |
| 1385 TEST_F(MediaStreamConstraintsUtilVideoContentTest, |
| 1386 AdvancedContradictoryMinMaxResolutionFrameRate) { |
| 1387 constraint_factory_.Reset(); |
| 1388 blink::WebMediaTrackConstraintSet& advanced1 = |
| 1389 constraint_factory_.AddAdvanced(); |
| 1390 advanced1.width.setMin(800); |
| 1391 advanced1.height.setMin(600); |
| 1392 blink::WebMediaTrackConstraintSet& advanced2 = |
| 1393 constraint_factory_.AddAdvanced(); |
| 1394 advanced2.width.setMax(640); |
| 1395 advanced2.height.setMax(480); |
| 1396 advanced2.frameRate.setExact(60.0); |
| 1397 auto result = SelectSettings(); |
| 1398 EXPECT_TRUE(result.HasValue()); |
| 1399 EXPECT_EQ(800, result.Width()); |
| 1400 EXPECT_EQ(600, result.Height()); |
| 1401 EXPECT_EQ(MediaStreamVideoSource::kDefaultFrameRate, result.FrameRate()); |
| 1402 } |
| 1403 |
| 1404 TEST_F(MediaStreamConstraintsUtilVideoContentTest, |
| 1405 AdvancedContradictoryExactAspectRatio) { |
| 1406 constraint_factory_.Reset(); |
| 1407 blink::WebMediaTrackConstraintSet& advanced1 = |
| 1408 constraint_factory_.AddAdvanced(); |
| 1409 advanced1.aspectRatio.setExact(10.0); |
| 1410 blink::WebMediaTrackConstraintSet& advanced2 = |
| 1411 constraint_factory_.AddAdvanced(); |
| 1412 advanced2.aspectRatio.setExact(3.0); |
| 1413 auto result = SelectSettings(); |
| 1414 EXPECT_TRUE(result.HasValue()); |
| 1415 EXPECT_EQ(std::round(MediaStreamVideoSource::kDefaultHeight * 10.0), |
| 1416 result.Width()); |
| 1417 EXPECT_EQ(MediaStreamVideoSource::kDefaultHeight, result.Height()); |
| 1418 CheckNonResolutionDefaults(result); |
| 1419 } |
| 1420 |
| 1421 TEST_F(MediaStreamConstraintsUtilVideoContentTest, |
| 1422 AdvancedContradictoryAspectRatioRange) { |
| 1423 constraint_factory_.Reset(); |
| 1424 blink::WebMediaTrackConstraintSet& advanced1 = |
| 1425 constraint_factory_.AddAdvanced(); |
| 1426 advanced1.aspectRatio.setMin(10.0); |
| 1427 blink::WebMediaTrackConstraintSet& advanced2 = |
| 1428 constraint_factory_.AddAdvanced(); |
| 1429 advanced2.aspectRatio.setMax(3.0); |
| 1430 auto result = SelectSettings(); |
| 1431 EXPECT_TRUE(result.HasValue()); |
| 1432 EXPECT_EQ(std::round(MediaStreamVideoSource::kDefaultHeight * 10.0), |
| 1433 result.Width()); |
| 1434 EXPECT_EQ(MediaStreamVideoSource::kDefaultHeight, result.Height()); |
| 1435 CheckNonResolutionDefaults(result); |
| 1436 } |
| 1437 |
| 1438 TEST_F(MediaStreamConstraintsUtilVideoContentTest, |
| 1439 AdvancedContradictoryExactFrameRate) { |
| 1440 constraint_factory_.Reset(); |
| 1441 blink::WebMediaTrackConstraintSet& advanced1 = |
| 1442 constraint_factory_.AddAdvanced(); |
| 1443 advanced1.frameRate.setExact(40.0); |
| 1444 blink::WebMediaTrackConstraintSet& advanced2 = |
| 1445 constraint_factory_.AddAdvanced(); |
| 1446 advanced2.frameRate.setExact(45.0); |
| 1447 auto result = SelectSettings(); |
| 1448 EXPECT_TRUE(result.HasValue()); |
| 1449 EXPECT_EQ(40.0, result.FrameRate()); |
| 1450 CheckNonFrameRateDefaults(result); |
| 1451 } |
| 1452 |
| 1453 TEST_F(MediaStreamConstraintsUtilVideoContentTest, |
| 1454 AdvancedContradictoryFrameRateRange) { |
| 1455 constraint_factory_.Reset(); |
| 1456 blink::WebMediaTrackConstraintSet& advanced1 = |
| 1457 constraint_factory_.AddAdvanced(); |
| 1458 advanced1.frameRate.setMin(40.0); |
| 1459 blink::WebMediaTrackConstraintSet& advanced2 = |
| 1460 constraint_factory_.AddAdvanced(); |
| 1461 advanced2.frameRate.setMax(35.0); |
| 1462 auto result = SelectSettings(); |
| 1463 EXPECT_TRUE(result.HasValue()); |
| 1464 EXPECT_LE(40.0, result.FrameRate()); |
| 1465 CheckNonFrameRateDefaults(result); |
| 1466 } |
| 1467 |
| 1468 TEST_F(MediaStreamConstraintsUtilVideoContentTest, |
| 1469 AdvancedContradictoryWidthFrameRate) { |
| 1470 constraint_factory_.Reset(); |
| 1471 blink::WebMediaTrackConstraintSet& advanced1 = |
| 1472 constraint_factory_.AddAdvanced(); |
| 1473 advanced1.width.setMax(1920); |
| 1474 blink::WebMediaTrackConstraintSet& advanced2 = |
| 1475 constraint_factory_.AddAdvanced(); |
| 1476 advanced2.width.setMin(2000); |
| 1477 advanced2.frameRate.setExact(10.0); |
| 1478 blink::WebMediaTrackConstraintSet& advanced3 = |
| 1479 constraint_factory_.AddAdvanced(); |
| 1480 advanced3.frameRate.setExact(90.0); |
| 1481 auto result = SelectSettings(); |
| 1482 EXPECT_TRUE(result.HasValue()); |
| 1483 EXPECT_EQ(MediaStreamVideoSource::kDefaultWidth, result.Width()); |
| 1484 EXPECT_EQ(MediaStreamVideoSource::kDefaultHeight, result.Height()); |
| 1485 EXPECT_EQ(90.0, result.FrameRate()); |
| 1486 } |
| 1487 |
| 1488 TEST_F(MediaStreamConstraintsUtilVideoContentTest, |
| 1489 AdvancedContradictoryHeightFrameRate) { |
| 1490 constraint_factory_.Reset(); |
| 1491 blink::WebMediaTrackConstraintSet& advanced1 = |
| 1492 constraint_factory_.AddAdvanced(); |
| 1493 advanced1.height.setMax(1080); |
| 1494 blink::WebMediaTrackConstraintSet& advanced2 = |
| 1495 constraint_factory_.AddAdvanced(); |
| 1496 advanced2.height.setMin(1500); |
| 1497 advanced2.frameRate.setExact(10.0); |
| 1498 blink::WebMediaTrackConstraintSet& advanced3 = |
| 1499 constraint_factory_.AddAdvanced(); |
| 1500 advanced3.frameRate.setExact(60.0); |
| 1501 auto result = SelectSettings(); |
| 1502 EXPECT_TRUE(result.HasValue()); |
| 1503 EXPECT_EQ(MediaStreamVideoSource::kDefaultWidth, result.Width()); |
| 1504 EXPECT_EQ(MediaStreamVideoSource::kDefaultHeight, result.Height()); |
| 1505 EXPECT_EQ(60.0, result.FrameRate()); |
| 1506 } |
| 1507 |
| 1508 TEST_F(MediaStreamConstraintsUtilVideoContentTest, AdvancedDeviceID) { |
| 1509 const std::string kDeviceID1 = "fake_device_1"; |
| 1510 const std::string kDeviceID2 = "fake_device_2"; |
| 1511 const std::string kDeviceID3 = "fake_device_3"; |
| 1512 const std::string kDeviceID4 = "fake_device_4"; |
| 1513 constraint_factory_.Reset(); |
| 1514 blink::WebMediaTrackConstraintSet& advanced1 = |
| 1515 constraint_factory_.AddAdvanced(); |
| 1516 blink::WebString id_vector1[] = {blink::WebString::fromASCII(kDeviceID1), |
| 1517 blink::WebString::fromASCII(kDeviceID2)}; |
| 1518 advanced1.deviceId.setExact( |
| 1519 blink::WebVector<blink::WebString>(id_vector1, arraysize(id_vector1))); |
| 1520 blink::WebString id_vector2[] = {blink::WebString::fromASCII(kDeviceID2), |
| 1521 blink::WebString::fromASCII(kDeviceID3)}; |
| 1522 blink::WebMediaTrackConstraintSet& advanced2 = |
| 1523 constraint_factory_.AddAdvanced(); |
| 1524 advanced2.deviceId.setExact( |
| 1525 blink::WebVector<blink::WebString>(id_vector2, arraysize(id_vector2))); |
| 1526 auto result = SelectSettings(); |
| 1527 EXPECT_TRUE(result.HasValue()); |
| 1528 // kDeviceID2 must be selected because it is the only one that satisfies both |
| 1529 // advanced sets. |
| 1530 EXPECT_EQ(kDeviceID2, result.device_id()); |
| 1531 } |
| 1532 |
| 1533 TEST_F(MediaStreamConstraintsUtilVideoContentTest, |
| 1534 AdvancedContradictoryDeviceID) { |
| 1535 const std::string kDeviceID1 = "fake_device_1"; |
| 1536 const std::string kDeviceID2 = "fake_device_2"; |
| 1537 const std::string kDeviceID3 = "fake_device_3"; |
| 1538 const std::string kDeviceID4 = "fake_device_4"; |
| 1539 constraint_factory_.Reset(); |
| 1540 blink::WebMediaTrackConstraintSet& advanced1 = |
| 1541 constraint_factory_.AddAdvanced(); |
| 1542 blink::WebString id_vector1[] = {blink::WebString::fromASCII(kDeviceID1), |
| 1543 blink::WebString::fromASCII(kDeviceID2)}; |
| 1544 advanced1.deviceId.setExact( |
| 1545 blink::WebVector<blink::WebString>(id_vector1, arraysize(id_vector1))); |
| 1546 blink::WebString id_vector2[] = {blink::WebString::fromASCII(kDeviceID3), |
| 1547 blink::WebString::fromASCII(kDeviceID4)}; |
| 1548 blink::WebMediaTrackConstraintSet& advanced2 = |
| 1549 constraint_factory_.AddAdvanced(); |
| 1550 advanced2.deviceId.setExact( |
| 1551 blink::WebVector<blink::WebString>(id_vector2, arraysize(id_vector2))); |
| 1552 auto result = SelectSettings(); |
| 1553 EXPECT_TRUE(result.HasValue()); |
| 1554 // The second advanced set must be ignored because it contradicts the first |
| 1555 // set. |
| 1556 EXPECT_EQ(std::string(kDeviceID1), result.device_id()); |
| 1557 } |
| 1558 |
| 1559 TEST_F(MediaStreamConstraintsUtilVideoContentTest, AdvancedIdealDeviceID) { |
| 1560 const std::string kDeviceID1 = "fake_device_1"; |
| 1561 const std::string kDeviceID2 = "fake_device_2"; |
| 1562 const std::string kDeviceID3 = "fake_device_3"; |
| 1563 constraint_factory_.Reset(); |
| 1564 blink::WebMediaTrackConstraintSet& advanced = |
| 1565 constraint_factory_.AddAdvanced(); |
| 1566 blink::WebString id_vector1[] = {blink::WebString::fromASCII(kDeviceID1), |
| 1567 blink::WebString::fromASCII(kDeviceID2)}; |
| 1568 advanced.deviceId.setExact( |
| 1569 blink::WebVector<blink::WebString>(id_vector1, arraysize(id_vector1))); |
| 1570 |
| 1571 blink::WebString id_vector2[] = {blink::WebString::fromASCII(kDeviceID2), |
| 1572 blink::WebString::fromASCII(kDeviceID3)}; |
| 1573 constraint_factory_.basic().deviceId.setIdeal( |
| 1574 blink::WebVector<blink::WebString>(id_vector2, arraysize(id_vector2))); |
| 1575 auto result = SelectSettings(); |
| 1576 EXPECT_TRUE(result.HasValue()); |
| 1577 // Should select kDeviceID2, which appears in ideal and satisfies the advanced |
| 1578 // set. |
| 1579 EXPECT_EQ(std::string(kDeviceID2), result.device_id()); |
| 1580 } |
| 1581 |
| 1582 TEST_F(MediaStreamConstraintsUtilVideoContentTest, ResolutionChangePolicy) { |
| 1583 { |
| 1584 constraint_factory_.Reset(); |
| 1585 auto result = SelectSettings(); |
| 1586 EXPECT_EQ(MediaStreamVideoSource::kDefaultWidth, result.Width()); |
| 1587 EXPECT_EQ(MediaStreamVideoSource::kDefaultHeight, result.Height()); |
| 1588 // Resolution can be adjusted. |
| 1589 EXPECT_EQ(media::RESOLUTION_POLICY_ANY_WITHIN_LIMIT, |
| 1590 result.ResolutionChangePolicy()); |
| 1591 } |
| 1592 { |
| 1593 constraint_factory_.Reset(); |
| 1594 constraint_factory_.basic().width.setIdeal(630); |
| 1595 constraint_factory_.basic().height.setIdeal(470); |
| 1596 auto result = SelectSettings(); |
| 1597 EXPECT_EQ(630, result.Width()); |
| 1598 EXPECT_EQ(470, result.Height()); |
| 1599 // Resolution can be adjusted because ideal was used to select the |
| 1600 // resolution. |
| 1601 EXPECT_EQ(media::RESOLUTION_POLICY_ANY_WITHIN_LIMIT, |
| 1602 result.ResolutionChangePolicy()); |
| 1603 } |
| 1604 { |
| 1605 constraint_factory_.Reset(); |
| 1606 constraint_factory_.basic().width.setExact(640); |
| 1607 constraint_factory_.basic().height.setExact(480); |
| 1608 auto result = SelectSettings(); |
| 1609 EXPECT_EQ(640, result.Width()); |
| 1610 EXPECT_EQ(480, result.Height()); |
| 1611 EXPECT_EQ(media::RESOLUTION_POLICY_FIXED_RESOLUTION, |
| 1612 result.ResolutionChangePolicy()); |
| 1613 } |
| 1614 { |
| 1615 constraint_factory_.Reset(); |
| 1616 constraint_factory_.basic().width.setExact(1000); |
| 1617 constraint_factory_.basic().height.setExact(500); |
| 1618 auto result = SelectSettings(); |
| 1619 EXPECT_EQ(1000, result.Width()); |
| 1620 EXPECT_EQ(500, result.Height()); |
| 1621 EXPECT_EQ(media::RESOLUTION_POLICY_FIXED_RESOLUTION, |
| 1622 result.ResolutionChangePolicy()); |
| 1623 } |
| 1624 { |
| 1625 constraint_factory_.Reset(); |
| 1626 constraint_factory_.basic().width.setExact(630); |
| 1627 constraint_factory_.basic().height.setExact(470); |
| 1628 auto result = SelectSettings(); |
| 1629 EXPECT_EQ(630, result.Width()); |
| 1630 EXPECT_EQ(470, result.Height()); |
| 1631 EXPECT_EQ(media::RESOLUTION_POLICY_FIXED_RESOLUTION, |
| 1632 result.ResolutionChangePolicy()); |
| 1633 } |
| 1634 { |
| 1635 constraint_factory_.Reset(); |
| 1636 constraint_factory_.basic().width.setIdeal(630); |
| 1637 constraint_factory_.basic().width.setMin(629); |
| 1638 constraint_factory_.basic().width.setMax(631); |
| 1639 constraint_factory_.basic().height.setIdeal(470); |
| 1640 constraint_factory_.basic().height.setMin(469); |
| 1641 auto result = SelectSettings(); |
| 1642 EXPECT_EQ(630, result.Width()); |
| 1643 EXPECT_EQ(470, result.Height()); |
| 1644 // Min/Max ranges prevent the resolution from being adjusted. |
| 1645 EXPECT_EQ(media::RESOLUTION_POLICY_FIXED_RESOLUTION, |
| 1646 result.ResolutionChangePolicy()); |
| 1647 } |
| 1648 { |
| 1649 constraint_factory_.Reset(); |
| 1650 constraint_factory_.basic().aspectRatio.setExact(1.32); |
| 1651 constraint_factory_.basic().height.setIdeal(480); |
| 1652 auto result = SelectSettings(); |
| 1653 EXPECT_EQ(std::round(480 * 1.32), result.Width()); |
| 1654 EXPECT_EQ(480, result.Height()); |
| 1655 // Exact aspect ratio prevents the resolution from being adjusted. |
| 1656 EXPECT_EQ(media::RESOLUTION_POLICY_FIXED_RESOLUTION, |
| 1657 result.ResolutionChangePolicy()); |
| 1658 } |
| 1659 } |
| 1660 |
| 1661 } // namespace content |
OLD | NEW |