OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/media/capture/web_contents_video_capture_device.h" | 5 #include "content/browser/media/capture/web_contents_video_capture_device.h" |
6 | 6 |
7 #include "base/bind_helpers.h" | 7 #include "base/bind_helpers.h" |
8 #include "base/debug/debugger.h" | 8 #include "base/debug/debugger.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "base/test/test_timeouts.h" | 10 #include "base/test/test_timeouts.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 #include "media/base/video_frame.h" | 30 #include "media/base/video_frame.h" |
31 #include "media/base/video_util.h" | 31 #include "media/base/video_util.h" |
32 #include "media/base/yuv_convert.h" | 32 #include "media/base/yuv_convert.h" |
33 #include "skia/ext/platform_canvas.h" | 33 #include "skia/ext/platform_canvas.h" |
34 #include "testing/gmock/include/gmock/gmock.h" | 34 #include "testing/gmock/include/gmock/gmock.h" |
35 #include "testing/gtest/include/gtest/gtest.h" | 35 #include "testing/gtest/include/gtest/gtest.h" |
36 #include "third_party/skia/include/core/SkColor.h" | 36 #include "third_party/skia/include/core/SkColor.h" |
37 #include "ui/base/layout.h" | 37 #include "ui/base/layout.h" |
38 #include "ui/gfx/display.h" | 38 #include "ui/gfx/display.h" |
39 #include "ui/gfx/geometry/dip_util.h" | 39 #include "ui/gfx/geometry/dip_util.h" |
| 40 #include "ui/gfx/geometry/size_conversions.h" |
40 #include "ui/gfx/screen.h" | 41 #include "ui/gfx/screen.h" |
41 #include "ui/gfx/test/test_screen.h" | 42 #include "ui/gfx/test/test_screen.h" |
42 | 43 |
43 namespace content { | 44 namespace content { |
44 namespace { | 45 namespace { |
45 | 46 |
46 const int kTestWidth = 320; | 47 const int kTestWidth = 320; |
47 const int kTestHeight = 240; | 48 const int kTestHeight = 240; |
48 const int kTestFramesPerSecond = 20; | 49 const int kTestFramesPerSecond = 20; |
49 const float kTestDeviceScaleFactor = 2.0f; | 50 const float kTestDeviceScaleFactor = 2.0f; |
(...skipping 969 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1019 arbitrary_source_size)); | 1020 arbitrary_source_size)); |
1020 SimulateDrawEvent(); | 1021 SimulateDrawEvent(); |
1021 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColorAndFrameSize( | 1022 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColorAndFrameSize( |
1022 SK_ColorBLACK, gfx::Size(kTestWidth, | 1023 SK_ColorBLACK, gfx::Size(kTestWidth, |
1023 kTestWidth * arbitrary_source_size.height() / | 1024 kTestWidth * arbitrary_source_size.height() / |
1024 arbitrary_source_size.width()))); | 1025 arbitrary_source_size.width()))); |
1025 | 1026 |
1026 device()->StopAndDeAllocate(); | 1027 device()->StopAndDeAllocate(); |
1027 } | 1028 } |
1028 | 1029 |
| 1030 TEST_F(WebContentsVideoCaptureDeviceTest, |
| 1031 ComputesStandardResolutionsForPreferredSize) { |
| 1032 // Helper function to run the same testing procedure for multiple combinations |
| 1033 // of |policy|, |standard_size| and |oddball_size|. |
| 1034 const auto RunTestForPreferredSize = |
| 1035 [=](media::ResolutionChangePolicy policy, |
| 1036 const gfx::Size& oddball_size, |
| 1037 const gfx::Size& standard_size) { |
| 1038 SCOPED_TRACE(::testing::Message() |
| 1039 << "policy=" << policy |
| 1040 << ", oddball_size=" << oddball_size.ToString() |
| 1041 << ", standard_size=" << standard_size.ToString()); |
| 1042 |
| 1043 // Compute the expected preferred size. For the fixed-resolution use case, |
| 1044 // the |oddball_size| is always the expected size; whereas for the |
| 1045 // variable-resolution cases, the |standard_size| is the expected size. |
| 1046 // Also, adjust to account for the device scale factor. |
| 1047 gfx::Size capture_preferred_size = gfx::ToFlooredSize(gfx::ScaleSize( |
| 1048 policy == media::RESOLUTION_POLICY_FIXED_RESOLUTION ? |
| 1049 oddball_size : standard_size, |
| 1050 1.0f / GetDeviceScaleFactor())); |
| 1051 ASSERT_NE(capture_preferred_size, web_contents()->GetPreferredSize()); |
| 1052 |
| 1053 // Start the WebContentsVideoCaptureDevice. |
| 1054 media::VideoCaptureParams capture_params; |
| 1055 capture_params.requested_format.frame_size = oddball_size; |
| 1056 capture_params.requested_format.frame_rate = kTestFramesPerSecond; |
| 1057 capture_params.requested_format.pixel_format = |
| 1058 media::VIDEO_CAPTURE_PIXEL_FORMAT_I420; |
| 1059 capture_params.resolution_change_policy = policy; |
| 1060 StubClientObserver unused_observer; |
| 1061 device()->AllocateAndStart(capture_params, unused_observer.PassClient()); |
| 1062 base::RunLoop().RunUntilIdle(); |
| 1063 |
| 1064 // Check that the preferred size of the WebContents matches the one provided |
| 1065 // by WebContentsVideoCaptureDevice. |
| 1066 EXPECT_EQ(capture_preferred_size, web_contents()->GetPreferredSize()); |
| 1067 |
| 1068 // Stop the WebContentsVideoCaptureDevice. |
| 1069 device()->StopAndDeAllocate(); |
| 1070 base::RunLoop().RunUntilIdle(); |
| 1071 }; |
| 1072 |
| 1073 const media::ResolutionChangePolicy policies[3] = { |
| 1074 media::RESOLUTION_POLICY_FIXED_RESOLUTION, |
| 1075 media::RESOLUTION_POLICY_FIXED_ASPECT_RATIO, |
| 1076 media::RESOLUTION_POLICY_ANY_WITHIN_LIMIT, |
| 1077 }; |
| 1078 |
| 1079 for (size_t i = 0; i < arraysize(policies); ++i) { |
| 1080 // A 16:9 standard resolution should be set as the preferred size when the |
| 1081 // source size is almost or exactly 16:9. |
| 1082 for (int delta_w = 0; delta_w <= +5; ++delta_w) { |
| 1083 for (int delta_h = 0; delta_h <= +5; ++delta_h) { |
| 1084 RunTestForPreferredSize(policies[i], |
| 1085 gfx::Size(1280 + delta_w, 720 + delta_h), |
| 1086 gfx::Size(1280, 720)); |
| 1087 } |
| 1088 } |
| 1089 for (int delta_w = -5; delta_w <= +5; ++delta_w) { |
| 1090 for (int delta_h = -5; delta_h <= +5; ++delta_h) { |
| 1091 RunTestForPreferredSize(policies[i], |
| 1092 gfx::Size(1365 + delta_w, 768 + delta_h), |
| 1093 gfx::Size(1280, 720)); |
| 1094 } |
| 1095 } |
| 1096 |
| 1097 // A 4:3 standard resolution should be set as the preferred size when the |
| 1098 // source size is almost or exactly 4:3. |
| 1099 for (int delta_w = 0; delta_w <= +5; ++delta_w) { |
| 1100 for (int delta_h = 0; delta_h <= +5; ++delta_h) { |
| 1101 RunTestForPreferredSize(policies[i], |
| 1102 gfx::Size(640 + delta_w, 480 + delta_h), |
| 1103 gfx::Size(640, 480)); |
| 1104 } |
| 1105 } |
| 1106 for (int delta_w = -5; delta_w <= +5; ++delta_w) { |
| 1107 for (int delta_h = -5; delta_h <= +5; ++delta_h) { |
| 1108 RunTestForPreferredSize(policies[i], |
| 1109 gfx::Size(800 + delta_w, 600 + delta_h), |
| 1110 gfx::Size(768, 576)); |
| 1111 } |
| 1112 } |
| 1113 |
| 1114 // When the source size is not a common video aspect ratio, there is no |
| 1115 // adjustment made. |
| 1116 RunTestForPreferredSize( |
| 1117 policies[i], gfx::Size(1000, 1000), gfx::Size(1000, 1000)); |
| 1118 RunTestForPreferredSize( |
| 1119 policies[i], gfx::Size(1600, 1000), gfx::Size(1600, 1000)); |
| 1120 RunTestForPreferredSize( |
| 1121 policies[i], gfx::Size(837, 999), gfx::Size(837, 999)); |
| 1122 } |
| 1123 } |
| 1124 |
1029 } // namespace | 1125 } // namespace |
1030 } // namespace content | 1126 } // namespace content |
OLD | NEW |