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

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

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

Powered by Google App Engine
This is Rietveld 408576698