video_capture_types_unittest.cc 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. #include "media/capture/video_capture_types.h"
  5. #include "testing/gtest/include/gtest/gtest.h"
  6. #include "ui/gfx/geometry/size.h"
  7. namespace media {
  8. namespace {
  9. using SuggestedConstraints = VideoCaptureParams::SuggestedConstraints;
  10. void ExpectEqualConstraints(const SuggestedConstraints& a,
  11. const SuggestedConstraints& b) {
  12. EXPECT_EQ(a.min_frame_size, b.min_frame_size);
  13. EXPECT_EQ(a.max_frame_size, b.max_frame_size);
  14. EXPECT_EQ(a.fixed_aspect_ratio, b.fixed_aspect_ratio);
  15. }
  16. } // namespace
  17. TEST(VideoCaptureTypesTest, SuggestsConstraints) {
  18. VideoCaptureParams params;
  19. // For empty/invalid VideoCaptureParams, results will be empty sizes.
  20. ExpectEqualConstraints(
  21. SuggestedConstraints({gfx::Size(), gfx::Size(), false}),
  22. params.SuggestConstraints());
  23. // Set an impractically small frame size, and confirm the same suggestion as
  24. // if the params were empty.
  25. params.requested_format.frame_size = gfx::Size(1, 1);
  26. ExpectEqualConstraints(
  27. SuggestedConstraints({gfx::Size(), gfx::Size(), false}),
  28. params.SuggestConstraints());
  29. // Test: Fixed 1080p resolution.
  30. params.requested_format.frame_size = gfx::Size(1920, 1080);
  31. params.resolution_change_policy = ResolutionChangePolicy::FIXED_RESOLUTION;
  32. ExpectEqualConstraints(SuggestedConstraints({gfx::Size(1920, 1080),
  33. gfx::Size(1920, 1080), false}),
  34. params.SuggestConstraints());
  35. // Test: Max 1080p resolution, fixed aspect ratio.
  36. params.requested_format.frame_size = gfx::Size(1920, 1080);
  37. params.resolution_change_policy = ResolutionChangePolicy::FIXED_ASPECT_RATIO;
  38. ExpectEqualConstraints(
  39. SuggestedConstraints({gfx::Size(320, 180), gfx::Size(1920, 1080), true}),
  40. params.SuggestConstraints());
  41. // Test: Max 1080p resolution, any aspect ratio.
  42. params.requested_format.frame_size = gfx::Size(1920, 1080);
  43. params.resolution_change_policy = ResolutionChangePolicy::ANY_WITHIN_LIMIT;
  44. ExpectEqualConstraints(
  45. SuggestedConstraints({gfx::Size(2, 2), gfx::Size(1920, 1080), false}),
  46. params.SuggestConstraints());
  47. // Test: Odd-valued resolution, fixed aspect ratio.
  48. params.requested_format.frame_size = gfx::Size(999, 777);
  49. params.resolution_change_policy = ResolutionChangePolicy::FIXED_ASPECT_RATIO;
  50. ExpectEqualConstraints(
  51. SuggestedConstraints({gfx::Size(232, 180), gfx::Size(998, 776), true}),
  52. params.SuggestConstraints());
  53. // Test: Max resolution less the hard-coded 180-line minimum, fixed aspect.
  54. params.requested_format.frame_size = gfx::Size(160, 90);
  55. params.resolution_change_policy = ResolutionChangePolicy::FIXED_ASPECT_RATIO;
  56. ExpectEqualConstraints(
  57. SuggestedConstraints({gfx::Size(160, 90), gfx::Size(160, 90), true}),
  58. params.SuggestConstraints());
  59. }
  60. } // namespace media