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

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

Issue 2777703002: Introduce SelectSettings algorithm for MediaStream video tracks. (Closed)
Patch Set: static asserts Created 3 years, 8 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <string> 5 #include <string>
6 6
7 #include "content/renderer/media/media_stream_audio_processor_options.h" 7 #include "content/renderer/media/media_stream_audio_processor_options.h"
8 #include "content/renderer/media/media_stream_constraints_util.h" 8 #include "content/renderer/media/media_stream_constraints_util.h"
9 #include "content/renderer/media/media_stream_video_source.h" 9 #include "content/renderer/media/media_stream_constraints_util_sets.h"
10 #include "content/renderer/media/mock_constraint_factory.h" 10 #include "content/renderer/media/mock_constraint_factory.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 12
13 namespace {
14
15 const int kSourceHeight = 1000;
16 const int kSourceWidth = 1500;
17 constexpr double kSourceAspectRatio =
18 static_cast<double>(kSourceWidth) / static_cast<double>(kSourceHeight);
19 constexpr double kSourceFrameRate = 100.0;
20
21 media::VideoCaptureFormat SourceFormat() {
22 return media::VideoCaptureFormat(gfx::Size(kSourceWidth, kSourceHeight),
23 kSourceFrameRate, media::PIXEL_FORMAT_I420);
24 }
25
26 } // namespace
27
13 namespace content { 28 namespace content {
14 29
15 class MediaStreamConstraintsUtilTest : public testing::Test { 30 class MediaStreamConstraintsUtilTest : public testing::Test {
31 protected:
32 using DoubleRangeSet = NumericRangeSet<double>;
16 }; 33 };
17 34
18 TEST_F(MediaStreamConstraintsUtilTest, BooleanConstraints) { 35 TEST_F(MediaStreamConstraintsUtilTest, BooleanConstraints) {
19 static const std::string kValueTrue = "true"; 36 static const std::string kValueTrue = "true";
20 static const std::string kValueFalse = "false"; 37 static const std::string kValueFalse = "false";
21 38
22 MockConstraintFactory constraint_factory; 39 MockConstraintFactory constraint_factory;
23 // Mandatory constraints. 40 // Mandatory constraints.
24 constraint_factory.basic().echoCancellation.setExact(true); 41 constraint_factory.basic().echoCancellation.setExact(true);
25 constraint_factory.basic().googEchoCancellation.setExact(false); 42 constraint_factory.basic().googEchoCancellation.setExact(false);
(...skipping 30 matching lines...) Expand all
56 constraint_factory.basic().echoCancellation.setExact(true); 73 constraint_factory.basic().echoCancellation.setExact(true);
57 constraints = constraint_factory.CreateWebMediaConstraints(); 74 constraints = constraint_factory.CreateWebMediaConstraints();
58 EXPECT_TRUE(GetConstraintValueAsBoolean( 75 EXPECT_TRUE(GetConstraintValueAsBoolean(
59 constraints, &blink::WebMediaTrackConstraintSet::echoCancellation, 76 constraints, &blink::WebMediaTrackConstraintSet::echoCancellation,
60 &value_true)); 77 &value_true));
61 EXPECT_TRUE(value_true); 78 EXPECT_TRUE(value_true);
62 } 79 }
63 80
64 TEST_F(MediaStreamConstraintsUtilTest, DoubleConstraints) { 81 TEST_F(MediaStreamConstraintsUtilTest, DoubleConstraints) {
65 MockConstraintFactory constraint_factory; 82 MockConstraintFactory constraint_factory;
66 const double test_value= 0.01f; 83 const double test_value = 0.01f;
67 84
68 constraint_factory.basic().aspectRatio.setExact(test_value); 85 constraint_factory.basic().aspectRatio.setExact(test_value);
69 blink::WebMediaConstraints constraints = 86 blink::WebMediaConstraints constraints =
70 constraint_factory.CreateWebMediaConstraints(); 87 constraint_factory.CreateWebMediaConstraints();
71 88
72 double value; 89 double value;
73 EXPECT_FALSE(GetConstraintValueAsDouble( 90 EXPECT_FALSE(GetConstraintValueAsDouble(
74 constraints, &blink::WebMediaTrackConstraintSet::frameRate, &value)); 91 constraints, &blink::WebMediaTrackConstraintSet::frameRate, &value));
75 EXPECT_TRUE(GetConstraintValueAsDouble( 92 EXPECT_TRUE(GetConstraintValueAsDouble(
76 constraints, &blink::WebMediaTrackConstraintSet::aspectRatio, &value)); 93 constraints, &blink::WebMediaTrackConstraintSet::aspectRatio, &value));
(...skipping 15 matching lines...) Expand all
92 109
93 // An exact value should also be reflected as min and max. 110 // An exact value should also be reflected as min and max.
94 EXPECT_TRUE(GetConstraintMaxAsInteger( 111 EXPECT_TRUE(GetConstraintMaxAsInteger(
95 constraints, &blink::WebMediaTrackConstraintSet::width, &value)); 112 constraints, &blink::WebMediaTrackConstraintSet::width, &value));
96 EXPECT_EQ(test_value, value); 113 EXPECT_EQ(test_value, value);
97 EXPECT_TRUE(GetConstraintMinAsInteger( 114 EXPECT_TRUE(GetConstraintMinAsInteger(
98 constraints, &blink::WebMediaTrackConstraintSet::width, &value)); 115 constraints, &blink::WebMediaTrackConstraintSet::width, &value));
99 EXPECT_EQ(test_value, value); 116 EXPECT_EQ(test_value, value);
100 } 117 }
101 118
119 TEST_F(MediaStreamConstraintsUtilTest, VideoTrackAdapterSettingsUnconstrained) {
120 ResolutionSet resolution_set;
121 DoubleRangeSet frame_rate_set;
122
123 // No ideal values.
124 {
125 MockConstraintFactory constraint_factory;
126 auto result = SelectVideoTrackAdapterSettings(
127 constraint_factory.CreateWebMediaConstraints().basic(), resolution_set,
128 frame_rate_set, SourceFormat());
129 EXPECT_EQ(kSourceHeight, result.max_height);
130 EXPECT_EQ(kSourceWidth, result.max_width);
131 EXPECT_EQ(0.0, result.min_aspect_ratio);
132 EXPECT_EQ(HUGE_VAL, result.max_aspect_ratio);
133 EXPECT_EQ(0.0, result.max_frame_rate);
134 }
135
136 // Ideal height.
137 {
138 const int kIdealHeight = 400;
139 MockConstraintFactory constraint_factory;
140 constraint_factory.basic().height.setIdeal(kIdealHeight);
141 auto result = SelectVideoTrackAdapterSettings(
142 constraint_factory.CreateWebMediaConstraints().basic(), resolution_set,
143 frame_rate_set, SourceFormat());
144 EXPECT_EQ(kIdealHeight, result.max_height);
145 EXPECT_EQ(std::round(kIdealHeight * kSourceAspectRatio), result.max_width);
146 EXPECT_EQ(0.0, result.min_aspect_ratio);
147 EXPECT_EQ(HUGE_VAL, result.max_aspect_ratio);
148 EXPECT_EQ(0.0, result.max_frame_rate);
149 }
150
151 // Ideal width.
152 {
153 const int kIdealWidth = 400;
154 MockConstraintFactory constraint_factory;
155 constraint_factory.basic().width.setIdeal(kIdealWidth);
156 auto result = SelectVideoTrackAdapterSettings(
157 constraint_factory.CreateWebMediaConstraints().basic(), resolution_set,
158 frame_rate_set, SourceFormat());
159 EXPECT_EQ(std::round(kIdealWidth / kSourceAspectRatio), result.max_height);
160 EXPECT_EQ(kIdealWidth, result.max_width);
161 EXPECT_EQ(0.0, result.min_aspect_ratio);
162 EXPECT_EQ(HUGE_VAL, result.max_aspect_ratio);
163 EXPECT_EQ(0.0, result.max_frame_rate);
164 }
165
166 // Ideal aspect ratio.
167 {
168 const double kIdealAspectRatio = 2.0;
169 MockConstraintFactory constraint_factory;
170 constraint_factory.basic().aspectRatio.setIdeal(kIdealAspectRatio);
171 auto result = SelectVideoTrackAdapterSettings(
172 constraint_factory.CreateWebMediaConstraints().basic(), resolution_set,
173 frame_rate_set, SourceFormat());
174 EXPECT_EQ(kSourceHeight, result.max_height);
175 EXPECT_EQ(std::round(kSourceHeight * kIdealAspectRatio), result.max_width);
176 EXPECT_EQ(0.0, result.min_aspect_ratio);
177 EXPECT_EQ(HUGE_VAL, result.max_aspect_ratio);
178 EXPECT_EQ(0.0, result.max_frame_rate);
179 }
180
181 // Ideal frame rate.
182 {
183 const double kIdealFrameRate = 33;
184 MockConstraintFactory constraint_factory;
185 constraint_factory.basic().frameRate.setIdeal(kIdealFrameRate);
186 auto result = SelectVideoTrackAdapterSettings(
187 constraint_factory.CreateWebMediaConstraints().basic(), resolution_set,
188 frame_rate_set, SourceFormat());
189 EXPECT_EQ(kSourceHeight, result.max_height);
190 EXPECT_EQ(kSourceWidth, result.max_width);
191 EXPECT_EQ(0.0, result.min_aspect_ratio);
192 EXPECT_EQ(HUGE_VAL, result.max_aspect_ratio);
193 EXPECT_EQ(kIdealFrameRate, result.max_frame_rate);
194 }
195
196 // All ideals supplied.
197 {
198 const int kIdealHeight = 400;
199 const int kIdealWidth = 600;
200 const int kIdealAspectRatio = 2.0;
201 const double kIdealFrameRate = 33;
202 MockConstraintFactory constraint_factory;
203 constraint_factory.basic().height.setIdeal(kIdealHeight);
204 constraint_factory.basic().width.setIdeal(kIdealWidth);
205 // Ideal aspect ratio is ignored if ideal width and height are supplied.
206 constraint_factory.basic().aspectRatio.setIdeal(kIdealAspectRatio);
207 constraint_factory.basic().frameRate.setIdeal(kIdealFrameRate);
208 auto result = SelectVideoTrackAdapterSettings(
209 constraint_factory.CreateWebMediaConstraints().basic(), resolution_set,
210 frame_rate_set, SourceFormat());
211 EXPECT_EQ(kIdealHeight, result.max_height);
212 EXPECT_EQ(kIdealWidth, result.max_width);
213 EXPECT_EQ(0.0, result.min_aspect_ratio);
214 EXPECT_EQ(HUGE_VAL, result.max_aspect_ratio);
215 EXPECT_EQ(kIdealFrameRate, result.max_frame_rate);
216 }
217 }
218
219 TEST_F(MediaStreamConstraintsUtilTest, VideoTrackAdapterSettingsConstrained) {
220 const int kMinHeight = 500;
221 const int kMaxHeight = 1200;
222 const int kMinWidth = 1000;
223 const int kMaxWidth = 2000;
224 constexpr double kMinAspectRatio = 1.0;
225 constexpr double kMaxAspectRatio = 2.0;
226 constexpr double kMinFrameRate = 20.0;
227 constexpr double kMaxFrameRate = 44.0;
228 ResolutionSet resolution_set(kMinHeight, kMaxHeight, kMinWidth, kMaxWidth,
229 kMinAspectRatio, kMaxAspectRatio);
230 DoubleRangeSet frame_rate_set(kMinFrameRate, kMaxFrameRate);
231
232 // No ideal values.
233 {
234 MockConstraintFactory constraint_factory;
235 auto result = SelectVideoTrackAdapterSettings(
236 constraint_factory.CreateWebMediaConstraints().basic(), resolution_set,
237 frame_rate_set, SourceFormat());
238 EXPECT_EQ(kSourceHeight, result.max_height);
239 EXPECT_EQ(kSourceWidth, result.max_width);
240 EXPECT_EQ(kMinAspectRatio, result.min_aspect_ratio);
241 EXPECT_EQ(kMaxAspectRatio, result.max_aspect_ratio);
242 EXPECT_EQ(kMaxFrameRate, result.max_frame_rate);
243 }
244
245 // Ideal height < min.
246 {
247 const int kIdealHeight = 400;
248 static_assert(kIdealHeight < kMinHeight,
249 "kIdealHeight must be less than kMinHeight");
250 MockConstraintFactory constraint_factory;
251 constraint_factory.basic().height.setIdeal(kIdealHeight);
252 auto result = SelectVideoTrackAdapterSettings(
253 constraint_factory.CreateWebMediaConstraints().basic(), resolution_set,
254 frame_rate_set, SourceFormat());
255 EXPECT_EQ(kMinHeight, result.max_height);
256 // kMinWidth > kMinHeight * kNativeAspectRatio
257 EXPECT_EQ(kMinWidth, result.max_width);
258 EXPECT_EQ(kMinAspectRatio, result.min_aspect_ratio);
259 EXPECT_EQ(kMaxAspectRatio, result.max_aspect_ratio);
260 EXPECT_EQ(kMaxFrameRate, result.max_frame_rate);
261 }
262
263 // min < Ideal height < max.
264 {
265 const int kIdealHeight = 1100;
266 static_assert(kIdealHeight > kMinHeight,
267 "kIdealHeight must be greater than kMinHeight");
268 static_assert(kIdealHeight < kMaxHeight,
269 "kIdealHeight must be less than kMaxHeight");
270 MockConstraintFactory constraint_factory;
271 constraint_factory.basic().height.setIdeal(kIdealHeight);
272 auto result = SelectVideoTrackAdapterSettings(
273 constraint_factory.CreateWebMediaConstraints().basic(), resolution_set,
274 frame_rate_set, SourceFormat());
275 EXPECT_EQ(kIdealHeight, result.max_height);
276 EXPECT_EQ(std::round(kIdealHeight * kSourceAspectRatio), result.max_width);
277 EXPECT_EQ(kMinAspectRatio, result.min_aspect_ratio);
278 EXPECT_EQ(kMaxAspectRatio, result.max_aspect_ratio);
279 EXPECT_EQ(kMaxFrameRate, result.max_frame_rate);
280 }
281
282 // Ideal height > max.
283 {
284 const int kIdealHeight = 2000;
285 static_assert(kIdealHeight > kMaxHeight,
286 "kIdealHeight must be greater than kMaxHeight");
287 MockConstraintFactory constraint_factory;
288 constraint_factory.basic().height.setIdeal(kIdealHeight);
289 auto result = SelectVideoTrackAdapterSettings(
290 constraint_factory.CreateWebMediaConstraints().basic(), resolution_set,
291 frame_rate_set, SourceFormat());
292 EXPECT_EQ(kMaxHeight, result.max_height);
293 EXPECT_EQ(std::round(kMaxHeight * kSourceAspectRatio), result.max_width);
294 EXPECT_EQ(kMinAspectRatio, result.min_aspect_ratio);
295 EXPECT_EQ(kMaxAspectRatio, result.max_aspect_ratio);
296 EXPECT_EQ(kMaxFrameRate, result.max_frame_rate);
297 }
298
299 // Ideal width < min.
300 {
301 const int kIdealWidth = 800;
302 static_assert(kIdealWidth < kMinWidth,
303 "kIdealWidth must be less than kMinWidth");
304 MockConstraintFactory constraint_factory;
305 constraint_factory.basic().width.setIdeal(kIdealWidth);
306 auto result = SelectVideoTrackAdapterSettings(
307 constraint_factory.CreateWebMediaConstraints().basic(), resolution_set,
308 frame_rate_set, SourceFormat());
309 EXPECT_EQ(std::round(kMinWidth / kSourceAspectRatio), result.max_height);
310 EXPECT_EQ(kMinWidth, result.max_width);
311 EXPECT_EQ(kMinAspectRatio, result.min_aspect_ratio);
312 EXPECT_EQ(kMaxAspectRatio, result.max_aspect_ratio);
313 EXPECT_EQ(kMaxFrameRate, result.max_frame_rate);
314 }
315
316 // min < Ideal width < max.
317 {
318 const int kIdealWidth = 1800;
319 static_assert(kIdealWidth > kMinWidth,
320 "kIdealWidth must be greater than kMinWidth");
321 static_assert(kIdealWidth < kMaxWidth,
322 "kIdealWidth must be less than kMaxWidth");
323 MockConstraintFactory constraint_factory;
324 constraint_factory.basic().width.setIdeal(kIdealWidth);
325 auto result = SelectVideoTrackAdapterSettings(
326 constraint_factory.CreateWebMediaConstraints().basic(), resolution_set,
327 frame_rate_set, SourceFormat());
328 EXPECT_EQ(std::round(kIdealWidth / kSourceAspectRatio), result.max_height);
329 EXPECT_EQ(kIdealWidth, result.max_width);
330 EXPECT_EQ(kMinAspectRatio, result.min_aspect_ratio);
331 EXPECT_EQ(kMaxAspectRatio, result.max_aspect_ratio);
332 EXPECT_EQ(kMaxFrameRate, result.max_frame_rate);
333 }
334
335 // Ideal width > max.
336 {
337 const int kIdealWidth = 3000;
338 static_assert(kIdealWidth > kMaxWidth,
339 "kIdealWidth must be greater than kMaxWidth");
340 MockConstraintFactory constraint_factory;
341 constraint_factory.basic().width.setIdeal(kIdealWidth);
342 auto result = SelectVideoTrackAdapterSettings(
343 constraint_factory.CreateWebMediaConstraints().basic(), resolution_set,
344 frame_rate_set, SourceFormat());
345 // kMaxHeight < kMaxWidth / kNativeAspectRatio
346 EXPECT_EQ(kMaxHeight, result.max_height);
347 EXPECT_EQ(kMaxWidth, result.max_width);
348 EXPECT_EQ(kMinAspectRatio, result.min_aspect_ratio);
349 EXPECT_EQ(kMaxAspectRatio, result.max_aspect_ratio);
350 EXPECT_EQ(kMaxFrameRate, result.max_frame_rate);
351 }
352
353 // Ideal aspect ratio < min.
354 {
355 constexpr double kIdealAspectRatio = 0.5;
356 static_assert(kIdealAspectRatio < kMinAspectRatio,
357 "kIdealAspectRatio must be less than kMinAspectRatio");
358 MockConstraintFactory constraint_factory;
359 constraint_factory.basic().aspectRatio.setIdeal(kIdealAspectRatio);
360 auto result = SelectVideoTrackAdapterSettings(
361 constraint_factory.CreateWebMediaConstraints().basic(), resolution_set,
362 frame_rate_set, SourceFormat());
363 // Desired point is (kNativeWidth/kMinAspectRatio, kNativeWidth), but it
364 // is outside the size constraints. Closest to that while maintaining the
365 // same aspect ratio is (kMaxHeight, kMaxHeight * kMinAspectRatio).
366 EXPECT_EQ(kMaxHeight, result.max_height);
367 EXPECT_EQ(std::round(kMaxHeight * kMinAspectRatio), result.max_width);
368 EXPECT_EQ(kMinAspectRatio, result.min_aspect_ratio);
369 EXPECT_EQ(kMaxAspectRatio, result.max_aspect_ratio);
370 EXPECT_EQ(kMaxFrameRate, result.max_frame_rate);
371 }
372
373 // min < Ideal aspect ratio < max.
374 {
375 constexpr double kIdealAspectRatio = 1.25;
376 static_assert(kIdealAspectRatio > kMinAspectRatio,
377 "kIdealAspectRatio must be greater than kMinAspectRatio");
378 static_assert(kIdealAspectRatio < kMaxAspectRatio,
379 "kIdealAspectRatio must be less than kMaxAspectRatio");
380 MockConstraintFactory constraint_factory;
381 constraint_factory.basic().aspectRatio.setIdeal(kIdealAspectRatio);
382 auto result = SelectVideoTrackAdapterSettings(
383 constraint_factory.CreateWebMediaConstraints().basic(), resolution_set,
384 frame_rate_set, SourceFormat());
385 EXPECT_EQ(std::round(kSourceWidth / kIdealAspectRatio), result.max_height);
386 EXPECT_EQ(kSourceWidth, result.max_width);
387 EXPECT_EQ(kMinAspectRatio, result.min_aspect_ratio);
388 EXPECT_EQ(kMaxAspectRatio, result.max_aspect_ratio);
389 EXPECT_EQ(kMaxFrameRate, result.max_frame_rate);
390 }
391
392 // Ideal aspect ratio > max.
393 {
394 constexpr double kIdealAspectRatio = 3.0;
395 static_assert(kIdealAspectRatio > kMaxAspectRatio,
396 "kIdealAspectRatio must be greater than kMaxAspectRatio");
397 MockConstraintFactory constraint_factory;
398 constraint_factory.basic().aspectRatio.setIdeal(kIdealAspectRatio);
399 auto result = SelectVideoTrackAdapterSettings(
400 constraint_factory.CreateWebMediaConstraints().basic(), resolution_set,
401 frame_rate_set, SourceFormat());
402 EXPECT_EQ(kSourceHeight, result.max_height);
403 EXPECT_EQ(std::round(kSourceHeight * kMaxAspectRatio), result.max_width);
404 EXPECT_EQ(kMinAspectRatio, result.min_aspect_ratio);
405 EXPECT_EQ(kMaxAspectRatio, result.max_aspect_ratio);
406 EXPECT_EQ(kMaxFrameRate, result.max_frame_rate);
407 }
408
409 // Ideal frame rate < min.
410 {
411 constexpr double kIdealFrameRate = 3.0;
412 static_assert(kIdealFrameRate < kMinFrameRate,
413 "kIdealFrameRate must be less than kMinFrameRate");
414 MockConstraintFactory constraint_factory;
415 constraint_factory.basic().frameRate.setIdeal(kIdealFrameRate);
416 auto result = SelectVideoTrackAdapterSettings(
417 constraint_factory.CreateWebMediaConstraints().basic(), resolution_set,
418 frame_rate_set, SourceFormat());
419 EXPECT_EQ(kSourceHeight, result.max_height);
420 EXPECT_EQ(kSourceWidth, result.max_width);
421 EXPECT_EQ(kMinAspectRatio, result.min_aspect_ratio);
422 EXPECT_EQ(kMaxAspectRatio, result.max_aspect_ratio);
423 EXPECT_EQ(kMinFrameRate, result.max_frame_rate);
424 }
425
426 // min < Ideal frame rate < max.
427 {
428 constexpr double kIdealFrameRate = 31.0;
429 static_assert(kIdealFrameRate > kMinFrameRate,
430 "kIdealFrameRate must be greater than kMinFrameRate");
431 static_assert(kIdealFrameRate < kMaxFrameRate,
432 "kIdealFrameRate must be less than kMaxFrameRate");
433 MockConstraintFactory constraint_factory;
434 constraint_factory.basic().frameRate.setIdeal(kIdealFrameRate);
435 auto result = SelectVideoTrackAdapterSettings(
436 constraint_factory.CreateWebMediaConstraints().basic(), resolution_set,
437 frame_rate_set, SourceFormat());
438 EXPECT_EQ(kSourceHeight, result.max_height);
439 EXPECT_EQ(kSourceWidth, result.max_width);
440 EXPECT_EQ(kMinAspectRatio, result.min_aspect_ratio);
441 EXPECT_EQ(kMaxAspectRatio, result.max_aspect_ratio);
442 EXPECT_EQ(kIdealFrameRate, result.max_frame_rate);
443 }
444
445 // Ideal frame rate > max.
446 {
447 constexpr double kIdealFrameRate = 1000.0;
448 static_assert(kIdealFrameRate > kMaxFrameRate,
449 "kIdealFrameRate must be greater than kMaxFrameRate");
450 MockConstraintFactory constraint_factory;
451 constraint_factory.basic().frameRate.setIdeal(kIdealFrameRate);
452 auto result = SelectVideoTrackAdapterSettings(
453 constraint_factory.CreateWebMediaConstraints().basic(), resolution_set,
454 frame_rate_set, SourceFormat());
455 EXPECT_EQ(kSourceHeight, result.max_height);
456 EXPECT_EQ(kSourceWidth, result.max_width);
457 EXPECT_EQ(kMinAspectRatio, result.min_aspect_ratio);
458 EXPECT_EQ(kMaxAspectRatio, result.max_aspect_ratio);
459 EXPECT_EQ(kMaxFrameRate, result.max_frame_rate);
460 }
461
462 // Ideal values inside constraints.
463 {
464 const int kIdealHeight = 900;
465 const int kIdealWidth = 1600;
466 constexpr double kIdealFrameRate = 35.0;
467 static_assert(kIdealHeight > kMinHeight,
468 "kMinHeight must be greater than kMinHeight");
469 static_assert(kIdealHeight < kMaxHeight,
470 "kMinHeight must be less than kMaxHeight");
471 static_assert(kIdealWidth > kMinWidth,
472 "kIdealWidth must be greater than kMinWidth");
473 static_assert(kIdealWidth < kMaxWidth,
474 "kIdealWidth must be less than kMaxHeight");
475 static_assert(kIdealFrameRate > kMinFrameRate,
476 "kIdealFrameRate must be greater than kMinFrameRate");
477 static_assert(kIdealFrameRate < kMaxFrameRate,
478 "kIdealFrameRate must be less than kMaxFrameRate");
479 MockConstraintFactory constraint_factory;
480 constraint_factory.basic().height.setIdeal(kIdealHeight);
481 constraint_factory.basic().width.setIdeal(kIdealWidth);
482 constraint_factory.basic().frameRate.setIdeal(kIdealFrameRate);
483 auto result = SelectVideoTrackAdapterSettings(
484 constraint_factory.CreateWebMediaConstraints().basic(), resolution_set,
485 frame_rate_set, SourceFormat());
486 EXPECT_EQ(kIdealHeight, result.max_height);
487 EXPECT_EQ(kIdealWidth, result.max_width);
488 EXPECT_EQ(kMinAspectRatio, result.min_aspect_ratio);
489 EXPECT_EQ(kMaxAspectRatio, result.max_aspect_ratio);
490 EXPECT_EQ(kIdealFrameRate, result.max_frame_rate);
491 }
492
493 // Ideal values outside constraints.
494 {
495 const int kIdealHeight = 2900;
496 const int kIdealWidth = 3600;
497 constexpr double kIdealFrameRate = 350.0;
498 static_assert(kIdealHeight > kMaxHeight,
499 "kMinHeight must be greater than kMaxHeight");
500 static_assert(kIdealWidth > kMaxWidth,
501 "kIdealWidth must be greater than kMaxHeight");
502 static_assert(kIdealFrameRate > kMaxFrameRate,
503 "kIdealFrameRate must be greater than kMaxFrameRate");
504 MockConstraintFactory constraint_factory;
505 constraint_factory.basic().height.setIdeal(kIdealHeight);
506 constraint_factory.basic().width.setIdeal(kIdealWidth);
507 constraint_factory.basic().frameRate.setIdeal(kIdealFrameRate);
508 auto result = SelectVideoTrackAdapterSettings(
509 constraint_factory.CreateWebMediaConstraints().basic(), resolution_set,
510 frame_rate_set, SourceFormat());
511 EXPECT_EQ(kMaxHeight, result.max_height);
512 EXPECT_EQ(kMaxWidth, result.max_width);
513 EXPECT_EQ(kMinAspectRatio, result.min_aspect_ratio);
514 EXPECT_EQ(kMaxAspectRatio, result.max_aspect_ratio);
515 EXPECT_EQ(kMaxFrameRate, result.max_frame_rate);
516 }
517
518 // Source frame rate.
519 {
520 DoubleRangeSet frame_rate_set(kMinFrameRate, kSourceFrameRate);
521 MockConstraintFactory constraint_factory;
522 auto result = SelectVideoTrackAdapterSettings(
523 constraint_factory.CreateWebMediaConstraints().basic(), resolution_set,
524 frame_rate_set, SourceFormat());
525 EXPECT_EQ(kSourceHeight, result.max_height);
526 EXPECT_EQ(kSourceWidth, result.max_width);
527 EXPECT_EQ(kMinAspectRatio, result.min_aspect_ratio);
528 EXPECT_EQ(kMaxAspectRatio, result.max_aspect_ratio);
529 // No frame-rate adjustment because the track will use the same frame rate
530 // as the source.
531 EXPECT_EQ(0.0, result.max_frame_rate);
532 }
533
534 // High frame rate.
535 {
536 constexpr double kHighFrameRate = 400.0; // Greater than source.
537 DoubleRangeSet frame_rate_set(kMinFrameRate, kHighFrameRate);
538 static_assert(kHighFrameRate > kSourceFrameRate,
539 "kIdealFrameRate must be greater than kSourceFrameRate");
540 MockConstraintFactory constraint_factory;
541 auto result = SelectVideoTrackAdapterSettings(
542 constraint_factory.CreateWebMediaConstraints().basic(), resolution_set,
543 frame_rate_set, SourceFormat());
544 EXPECT_EQ(kSourceHeight, result.max_height);
545 EXPECT_EQ(kSourceWidth, result.max_width);
546 EXPECT_EQ(kMinAspectRatio, result.min_aspect_ratio);
547 EXPECT_EQ(kMaxAspectRatio, result.max_aspect_ratio);
548 // No frame-rate adjustment because the track will use a frame rate that is
549 // greater than the source's.
550 EXPECT_EQ(0.0, result.max_frame_rate);
551 }
552 }
553
102 } // namespace content 554 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698