buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 1 | /* |
kjellander | 1afca73 | 2016-02-07 20:46:45 -0800 | [diff] [blame] | 2 | * Copyright (c) 2010 The WebRTC project authors. All Rights Reserved. |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 3 | * |
kjellander | 1afca73 | 2016-02-07 20:46:45 -0800 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 11 | #include "media/base/video_adapter.h" |
| 12 | |
Steve Anton | e78bcb9 | 2017-10-31 09:53:08 -0700 | [diff] [blame] | 13 | #include <limits> |
kwiberg | bfefb03 | 2016-05-01 14:53:46 -0700 | [diff] [blame] | 14 | #include <memory> |
Åsa Persson | 3f7e0ed | 2019-10-18 15:03:13 +0200 | [diff] [blame] | 15 | #include <string> |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 16 | #include <utility> |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 17 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 18 | #include "api/video/video_frame.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 19 | #include "media/base/fake_frame_source.h" |
Åsa Persson | 3f7e0ed | 2019-10-18 15:03:13 +0200 | [diff] [blame] | 20 | #include "rtc_base/arraysize.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 21 | #include "rtc_base/time_utils.h" |
Åsa Persson | 3f7e0ed | 2019-10-18 15:03:13 +0200 | [diff] [blame] | 22 | #include "test/field_trial.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 23 | #include "test/gtest.h" |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 24 | |
| 25 | namespace cricket { |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 26 | namespace { |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 27 | const int kWidth = 1280; |
| 28 | const int kHeight = 720; |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 29 | const int kDefaultFps = 30; |
| 30 | } // namespace |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 31 | |
Mirko Bonadei | 6a489f2 | 2019-04-09 15:11:12 +0200 | [diff] [blame] | 32 | class VideoAdapterTest : public ::testing::Test, |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 33 | public ::testing::WithParamInterface<bool> { |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 34 | public: |
Åsa Persson | 3f7e0ed | 2019-10-18 15:03:13 +0200 | [diff] [blame] | 35 | VideoAdapterTest() : VideoAdapterTest("") {} |
| 36 | explicit VideoAdapterTest(const std::string& field_trials) |
| 37 | : override_field_trials_(field_trials), |
| 38 | frame_source_(std::make_unique<FakeFrameSource>( |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 39 | kWidth, |
| 40 | kHeight, |
| 41 | VideoFormat::FpsToInterval(kDefaultFps) / |
| 42 | rtc::kNumNanosecsPerMicrosec)), |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 43 | adapter_wrapper_(std::make_unique<VideoAdapterWrapper>(&adapter_)), |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 44 | use_new_format_request_(GetParam()) {} |
pbos@webrtc.org | 75c3ec1 | 2014-08-27 18:16:13 +0000 | [diff] [blame] | 45 | |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 46 | protected: |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 47 | // Wrap a VideoAdapter and collect stats. |
| 48 | class VideoAdapterWrapper { |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 49 | public: |
pbos@webrtc.org | c9b3f77 | 2014-08-26 12:33:18 +0000 | [diff] [blame] | 50 | struct Stats { |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 51 | int captured_frames = 0; |
| 52 | int dropped_frames = 0; |
| 53 | bool last_adapt_was_no_op = false; |
pbos@webrtc.org | c9b3f77 | 2014-08-26 12:33:18 +0000 | [diff] [blame] | 54 | |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 55 | int cropped_width = 0; |
| 56 | int cropped_height = 0; |
| 57 | int out_width = 0; |
| 58 | int out_height = 0; |
pbos@webrtc.org | c9b3f77 | 2014-08-26 12:33:18 +0000 | [diff] [blame] | 59 | }; |
| 60 | |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 61 | explicit VideoAdapterWrapper(VideoAdapter* adapter) |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 62 | : video_adapter_(adapter) {} |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 63 | |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 64 | void AdaptFrame(const webrtc::VideoFrame& frame) { |
nisse | f5297a0 | 2016-09-30 01:34:27 -0700 | [diff] [blame] | 65 | const int in_width = frame.width(); |
| 66 | const int in_height = frame.height(); |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 67 | int cropped_width; |
| 68 | int cropped_height; |
| 69 | int out_width; |
| 70 | int out_height; |
nisse | f5297a0 | 2016-09-30 01:34:27 -0700 | [diff] [blame] | 71 | if (video_adapter_->AdaptFrameResolution( |
| 72 | in_width, in_height, |
| 73 | frame.timestamp_us() * rtc::kNumNanosecsPerMicrosec, |
| 74 | &cropped_width, &cropped_height, &out_width, &out_height)) { |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 75 | stats_.cropped_width = cropped_width; |
| 76 | stats_.cropped_height = cropped_height; |
| 77 | stats_.out_width = out_width; |
| 78 | stats_.out_height = out_height; |
| 79 | stats_.last_adapt_was_no_op = |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 80 | (in_width == cropped_width && in_height == cropped_height && |
| 81 | in_width == out_width && in_height == out_height); |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 82 | } else { |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 83 | ++stats_.dropped_frames; |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 84 | } |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 85 | ++stats_.captured_frames; |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 86 | } |
| 87 | |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 88 | Stats GetStats() const { return stats_; } |
pbos@webrtc.org | c9b3f77 | 2014-08-26 12:33:18 +0000 | [diff] [blame] | 89 | |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 90 | private: |
| 91 | VideoAdapter* video_adapter_; |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 92 | Stats stats_; |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 93 | }; |
| 94 | |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 95 | void VerifyAdaptedResolution(const VideoAdapterWrapper::Stats& stats, |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 96 | int cropped_width, |
| 97 | int cropped_height, |
| 98 | int out_width, |
| 99 | int out_height) { |
| 100 | EXPECT_EQ(cropped_width, stats.cropped_width); |
| 101 | EXPECT_EQ(cropped_height, stats.cropped_height); |
| 102 | EXPECT_EQ(out_width, stats.out_width); |
| 103 | EXPECT_EQ(out_height, stats.out_height); |
pbos@webrtc.org | c9b3f77 | 2014-08-26 12:33:18 +0000 | [diff] [blame] | 104 | } |
| 105 | |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 106 | void OnOutputFormatRequest(int width, |
| 107 | int height, |
| 108 | const absl::optional<int>& fps) { |
| 109 | if (use_new_format_request_) { |
| 110 | absl::optional<std::pair<int, int>> target_aspect_ratio = |
| 111 | std::make_pair(width, height); |
| 112 | absl::optional<int> max_pixel_count = width * height; |
| 113 | absl::optional<int> max_fps = fps; |
| 114 | adapter_.OnOutputFormatRequest(target_aspect_ratio, max_pixel_count, |
| 115 | max_fps); |
| 116 | return; |
| 117 | } |
| 118 | adapter_.OnOutputFormatRequest( |
| 119 | VideoFormat(width, height, fps ? VideoFormat::FpsToInterval(*fps) : 0, |
| 120 | cricket::FOURCC_I420)); |
| 121 | } |
| 122 | |
Åsa Persson | 3f7e0ed | 2019-10-18 15:03:13 +0200 | [diff] [blame] | 123 | webrtc::test::ScopedFieldTrials override_field_trials_; |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 124 | const std::unique_ptr<FakeFrameSource> frame_source_; |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 125 | VideoAdapter adapter_; |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 126 | int cropped_width_; |
| 127 | int cropped_height_; |
| 128 | int out_width_; |
| 129 | int out_height_; |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 130 | const std::unique_ptr<VideoAdapterWrapper> adapter_wrapper_; |
| 131 | const bool use_new_format_request_; |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 132 | }; |
| 133 | |
Åsa Persson | 3f7e0ed | 2019-10-18 15:03:13 +0200 | [diff] [blame] | 134 | class VideoAdapterTestVariableStartScale : public VideoAdapterTest { |
| 135 | public: |
| 136 | VideoAdapterTestVariableStartScale() |
| 137 | : VideoAdapterTest("WebRTC-Video-VariableStartScaleFactor/Enabled/") {} |
| 138 | }; |
| 139 | |
Mirko Bonadei | c84f661 | 2019-01-31 12:20:57 +0100 | [diff] [blame] | 140 | INSTANTIATE_TEST_SUITE_P(OnOutputFormatRequests, |
| 141 | VideoAdapterTest, |
| 142 | ::testing::Values(true, false)); |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 143 | |
Åsa Persson | 3f7e0ed | 2019-10-18 15:03:13 +0200 | [diff] [blame] | 144 | INSTANTIATE_TEST_SUITE_P(OnOutputFormatRequests, |
| 145 | VideoAdapterTestVariableStartScale, |
| 146 | ::testing::Values(true, false)); |
| 147 | |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 148 | // Do not adapt the frame rate or the resolution. Expect no frame drop, no |
| 149 | // cropping, and no resolution change. |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 150 | TEST_P(VideoAdapterTest, AdaptNothing) { |
Magnus Jedvert | 0184057 | 2015-04-10 11:18:39 +0200 | [diff] [blame] | 151 | for (int i = 0; i < 10; ++i) |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 152 | adapter_wrapper_->AdaptFrame(frame_source_->GetFrame()); |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 153 | |
| 154 | // Verify no frame drop and no resolution change. |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 155 | VideoAdapterWrapper::Stats stats = adapter_wrapper_->GetStats(); |
pbos@webrtc.org | c9b3f77 | 2014-08-26 12:33:18 +0000 | [diff] [blame] | 156 | EXPECT_GE(stats.captured_frames, 10); |
| 157 | EXPECT_EQ(0, stats.dropped_frames); |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 158 | VerifyAdaptedResolution(stats, kWidth, kHeight, kWidth, kHeight); |
pbos@webrtc.org | c9b3f77 | 2014-08-26 12:33:18 +0000 | [diff] [blame] | 159 | EXPECT_TRUE(stats.last_adapt_was_no_op); |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 160 | } |
| 161 | |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 162 | TEST_P(VideoAdapterTest, AdaptZeroInterval) { |
| 163 | OnOutputFormatRequest(kWidth, kHeight, absl::nullopt); |
| 164 | for (int i = 0; i < 40; ++i) |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 165 | adapter_wrapper_->AdaptFrame(frame_source_->GetFrame()); |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 166 | |
| 167 | // Verify no crash and that frames aren't dropped. |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 168 | VideoAdapterWrapper::Stats stats = adapter_wrapper_->GetStats(); |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 169 | EXPECT_GE(stats.captured_frames, 40); |
pbos@webrtc.org | c9b3f77 | 2014-08-26 12:33:18 +0000 | [diff] [blame] | 170 | EXPECT_EQ(0, stats.dropped_frames); |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 171 | VerifyAdaptedResolution(stats, kWidth, kHeight, kWidth, kHeight); |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | // Adapt the frame rate to be half of the capture rate at the beginning. Expect |
| 175 | // the number of dropped frames to be half of the number the captured frames. |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 176 | TEST_P(VideoAdapterTest, AdaptFramerateToHalf) { |
| 177 | OnOutputFormatRequest(kWidth, kHeight, kDefaultFps / 2); |
magjed | 604abe0 | 2016-05-19 06:05:40 -0700 | [diff] [blame] | 178 | |
| 179 | // Capture 10 frames and verify that every other frame is dropped. The first |
| 180 | // frame should not be dropped. |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 181 | adapter_wrapper_->AdaptFrame(frame_source_->GetFrame()); |
| 182 | EXPECT_GE(adapter_wrapper_->GetStats().captured_frames, 1); |
| 183 | EXPECT_EQ(0, adapter_wrapper_->GetStats().dropped_frames); |
magjed | 604abe0 | 2016-05-19 06:05:40 -0700 | [diff] [blame] | 184 | |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 185 | adapter_wrapper_->AdaptFrame(frame_source_->GetFrame()); |
| 186 | EXPECT_GE(adapter_wrapper_->GetStats().captured_frames, 2); |
| 187 | EXPECT_EQ(1, adapter_wrapper_->GetStats().dropped_frames); |
magjed | 604abe0 | 2016-05-19 06:05:40 -0700 | [diff] [blame] | 188 | |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 189 | adapter_wrapper_->AdaptFrame(frame_source_->GetFrame()); |
| 190 | EXPECT_GE(adapter_wrapper_->GetStats().captured_frames, 3); |
| 191 | EXPECT_EQ(1, adapter_wrapper_->GetStats().dropped_frames); |
magjed | 604abe0 | 2016-05-19 06:05:40 -0700 | [diff] [blame] | 192 | |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 193 | adapter_wrapper_->AdaptFrame(frame_source_->GetFrame()); |
| 194 | EXPECT_GE(adapter_wrapper_->GetStats().captured_frames, 4); |
| 195 | EXPECT_EQ(2, adapter_wrapper_->GetStats().dropped_frames); |
magjed | 604abe0 | 2016-05-19 06:05:40 -0700 | [diff] [blame] | 196 | |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 197 | adapter_wrapper_->AdaptFrame(frame_source_->GetFrame()); |
| 198 | EXPECT_GE(adapter_wrapper_->GetStats().captured_frames, 5); |
| 199 | EXPECT_EQ(2, adapter_wrapper_->GetStats().dropped_frames); |
magjed | 604abe0 | 2016-05-19 06:05:40 -0700 | [diff] [blame] | 200 | |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 201 | adapter_wrapper_->AdaptFrame(frame_source_->GetFrame()); |
| 202 | EXPECT_GE(adapter_wrapper_->GetStats().captured_frames, 6); |
| 203 | EXPECT_EQ(3, adapter_wrapper_->GetStats().dropped_frames); |
magjed | 604abe0 | 2016-05-19 06:05:40 -0700 | [diff] [blame] | 204 | |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 205 | adapter_wrapper_->AdaptFrame(frame_source_->GetFrame()); |
| 206 | EXPECT_GE(adapter_wrapper_->GetStats().captured_frames, 7); |
| 207 | EXPECT_EQ(3, adapter_wrapper_->GetStats().dropped_frames); |
magjed | 604abe0 | 2016-05-19 06:05:40 -0700 | [diff] [blame] | 208 | |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 209 | adapter_wrapper_->AdaptFrame(frame_source_->GetFrame()); |
| 210 | EXPECT_GE(adapter_wrapper_->GetStats().captured_frames, 8); |
| 211 | EXPECT_EQ(4, adapter_wrapper_->GetStats().dropped_frames); |
magjed | 604abe0 | 2016-05-19 06:05:40 -0700 | [diff] [blame] | 212 | |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 213 | adapter_wrapper_->AdaptFrame(frame_source_->GetFrame()); |
| 214 | EXPECT_GE(adapter_wrapper_->GetStats().captured_frames, 9); |
| 215 | EXPECT_EQ(4, adapter_wrapper_->GetStats().dropped_frames); |
magjed | 604abe0 | 2016-05-19 06:05:40 -0700 | [diff] [blame] | 216 | |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 217 | adapter_wrapper_->AdaptFrame(frame_source_->GetFrame()); |
| 218 | EXPECT_GE(adapter_wrapper_->GetStats().captured_frames, 10); |
| 219 | EXPECT_EQ(5, adapter_wrapper_->GetStats().dropped_frames); |
magjed | 604abe0 | 2016-05-19 06:05:40 -0700 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | // Adapt the frame rate to be two thirds of the capture rate at the beginning. |
| 223 | // Expect the number of dropped frames to be one thirds of the number the |
| 224 | // captured frames. |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 225 | TEST_P(VideoAdapterTest, AdaptFramerateToTwoThirds) { |
| 226 | OnOutputFormatRequest(kWidth, kHeight, kDefaultFps * 2 / 3); |
magjed | 604abe0 | 2016-05-19 06:05:40 -0700 | [diff] [blame] | 227 | |
| 228 | // Capture 10 frames and verify that every third frame is dropped. The first |
| 229 | // frame should not be dropped. |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 230 | adapter_wrapper_->AdaptFrame(frame_source_->GetFrame()); |
| 231 | EXPECT_GE(adapter_wrapper_->GetStats().captured_frames, 1); |
| 232 | EXPECT_EQ(0, adapter_wrapper_->GetStats().dropped_frames); |
magjed | 604abe0 | 2016-05-19 06:05:40 -0700 | [diff] [blame] | 233 | |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 234 | adapter_wrapper_->AdaptFrame(frame_source_->GetFrame()); |
| 235 | EXPECT_GE(adapter_wrapper_->GetStats().captured_frames, 2); |
| 236 | EXPECT_EQ(0, adapter_wrapper_->GetStats().dropped_frames); |
magjed | 604abe0 | 2016-05-19 06:05:40 -0700 | [diff] [blame] | 237 | |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 238 | adapter_wrapper_->AdaptFrame(frame_source_->GetFrame()); |
| 239 | EXPECT_GE(adapter_wrapper_->GetStats().captured_frames, 3); |
| 240 | EXPECT_EQ(1, adapter_wrapper_->GetStats().dropped_frames); |
magjed | 604abe0 | 2016-05-19 06:05:40 -0700 | [diff] [blame] | 241 | |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 242 | adapter_wrapper_->AdaptFrame(frame_source_->GetFrame()); |
| 243 | EXPECT_GE(adapter_wrapper_->GetStats().captured_frames, 4); |
| 244 | EXPECT_EQ(1, adapter_wrapper_->GetStats().dropped_frames); |
magjed | 604abe0 | 2016-05-19 06:05:40 -0700 | [diff] [blame] | 245 | |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 246 | adapter_wrapper_->AdaptFrame(frame_source_->GetFrame()); |
| 247 | EXPECT_GE(adapter_wrapper_->GetStats().captured_frames, 5); |
| 248 | EXPECT_EQ(1, adapter_wrapper_->GetStats().dropped_frames); |
magjed | 604abe0 | 2016-05-19 06:05:40 -0700 | [diff] [blame] | 249 | |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 250 | adapter_wrapper_->AdaptFrame(frame_source_->GetFrame()); |
| 251 | EXPECT_GE(adapter_wrapper_->GetStats().captured_frames, 6); |
| 252 | EXPECT_EQ(2, adapter_wrapper_->GetStats().dropped_frames); |
magjed | 604abe0 | 2016-05-19 06:05:40 -0700 | [diff] [blame] | 253 | |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 254 | adapter_wrapper_->AdaptFrame(frame_source_->GetFrame()); |
| 255 | EXPECT_GE(adapter_wrapper_->GetStats().captured_frames, 7); |
| 256 | EXPECT_EQ(2, adapter_wrapper_->GetStats().dropped_frames); |
magjed | 604abe0 | 2016-05-19 06:05:40 -0700 | [diff] [blame] | 257 | |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 258 | adapter_wrapper_->AdaptFrame(frame_source_->GetFrame()); |
| 259 | EXPECT_GE(adapter_wrapper_->GetStats().captured_frames, 8); |
| 260 | EXPECT_EQ(2, adapter_wrapper_->GetStats().dropped_frames); |
magjed | 604abe0 | 2016-05-19 06:05:40 -0700 | [diff] [blame] | 261 | |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 262 | adapter_wrapper_->AdaptFrame(frame_source_->GetFrame()); |
| 263 | EXPECT_GE(adapter_wrapper_->GetStats().captured_frames, 9); |
| 264 | EXPECT_EQ(3, adapter_wrapper_->GetStats().dropped_frames); |
magjed | 604abe0 | 2016-05-19 06:05:40 -0700 | [diff] [blame] | 265 | |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 266 | adapter_wrapper_->AdaptFrame(frame_source_->GetFrame()); |
| 267 | EXPECT_GE(adapter_wrapper_->GetStats().captured_frames, 10); |
| 268 | EXPECT_EQ(3, adapter_wrapper_->GetStats().dropped_frames); |
magjed | 604abe0 | 2016-05-19 06:05:40 -0700 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | // Request frame rate twice as high as captured frame rate. Expect no frame |
| 272 | // drop. |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 273 | TEST_P(VideoAdapterTest, AdaptFramerateHighLimit) { |
| 274 | OnOutputFormatRequest(kWidth, kHeight, kDefaultFps * 2); |
| 275 | |
Magnus Jedvert | 0184057 | 2015-04-10 11:18:39 +0200 | [diff] [blame] | 276 | for (int i = 0; i < 10; ++i) |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 277 | adapter_wrapper_->AdaptFrame(frame_source_->GetFrame()); |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 278 | |
magjed | 604abe0 | 2016-05-19 06:05:40 -0700 | [diff] [blame] | 279 | // Verify no frame drop. |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 280 | EXPECT_EQ(0, adapter_wrapper_->GetStats().dropped_frames); |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 281 | } |
| 282 | |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 283 | // Adapt the frame rate to be half of the capture rate. No resolution limit set. |
| 284 | // Expect the number of dropped frames to be half of the number the captured |
| 285 | // frames. |
| 286 | TEST_P(VideoAdapterTest, AdaptFramerateToHalfWithNoPixelLimit) { |
| 287 | adapter_.OnOutputFormatRequest(absl::nullopt, absl::nullopt, kDefaultFps / 2); |
| 288 | |
| 289 | // Capture 10 frames and verify that every other frame is dropped. The first |
| 290 | // frame should not be dropped. |
| 291 | int expected_dropped_frames = 0; |
| 292 | for (int i = 0; i < 10; ++i) { |
| 293 | adapter_wrapper_->AdaptFrame(frame_source_->GetFrame()); |
| 294 | EXPECT_GE(adapter_wrapper_->GetStats().captured_frames, i + 1); |
| 295 | if (i % 2 == 1) |
| 296 | ++expected_dropped_frames; |
| 297 | EXPECT_EQ(expected_dropped_frames, |
| 298 | adapter_wrapper_->GetStats().dropped_frames); |
| 299 | VerifyAdaptedResolution(adapter_wrapper_->GetStats(), kWidth, kHeight, |
| 300 | kWidth, kHeight); |
| 301 | } |
| 302 | } |
| 303 | |
magjed | 604abe0 | 2016-05-19 06:05:40 -0700 | [diff] [blame] | 304 | // After the first timestamp, add a big offset to the timestamps. Expect that |
| 305 | // the adapter is conservative and resets to the new offset and does not drop |
| 306 | // any frame. |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 307 | TEST_P(VideoAdapterTest, AdaptFramerateTimestampOffset) { |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 308 | const int64_t capture_interval = VideoFormat::FpsToInterval(kDefaultFps); |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 309 | OnOutputFormatRequest(640, 480, kDefaultFps); |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 310 | |
magjed | 604abe0 | 2016-05-19 06:05:40 -0700 | [diff] [blame] | 311 | const int64_t first_timestamp = 0; |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 312 | adapter_.AdaptFrameResolution(640, 480, first_timestamp, &cropped_width_, |
| 313 | &cropped_height_, &out_width_, &out_height_); |
magjed | 604abe0 | 2016-05-19 06:05:40 -0700 | [diff] [blame] | 314 | EXPECT_GT(out_width_, 0); |
| 315 | EXPECT_GT(out_height_, 0); |
| 316 | |
| 317 | const int64_t big_offset = -987654321LL * 1000; |
| 318 | const int64_t second_timestamp = big_offset; |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 319 | adapter_.AdaptFrameResolution(640, 480, second_timestamp, &cropped_width_, |
| 320 | &cropped_height_, &out_width_, &out_height_); |
magjed | 604abe0 | 2016-05-19 06:05:40 -0700 | [diff] [blame] | 321 | EXPECT_GT(out_width_, 0); |
| 322 | EXPECT_GT(out_height_, 0); |
| 323 | |
| 324 | const int64_t third_timestamp = big_offset + capture_interval; |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 325 | adapter_.AdaptFrameResolution(640, 480, third_timestamp, &cropped_width_, |
| 326 | &cropped_height_, &out_width_, &out_height_); |
magjed | 604abe0 | 2016-05-19 06:05:40 -0700 | [diff] [blame] | 327 | EXPECT_GT(out_width_, 0); |
| 328 | EXPECT_GT(out_height_, 0); |
| 329 | } |
| 330 | |
| 331 | // Request 30 fps and send 30 fps with jitter. Expect that no frame is dropped. |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 332 | TEST_P(VideoAdapterTest, AdaptFramerateTimestampJitter) { |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 333 | const int64_t capture_interval = VideoFormat::FpsToInterval(kDefaultFps); |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 334 | OnOutputFormatRequest(640, 480, kDefaultFps); |
magjed | 604abe0 | 2016-05-19 06:05:40 -0700 | [diff] [blame] | 335 | |
| 336 | adapter_.AdaptFrameResolution(640, 480, capture_interval * 0 / 10, |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 337 | &cropped_width_, &cropped_height_, &out_width_, |
| 338 | &out_height_); |
magjed | 604abe0 | 2016-05-19 06:05:40 -0700 | [diff] [blame] | 339 | EXPECT_GT(out_width_, 0); |
| 340 | EXPECT_GT(out_height_, 0); |
| 341 | |
| 342 | adapter_.AdaptFrameResolution(640, 480, capture_interval * 10 / 10 - 1, |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 343 | &cropped_width_, &cropped_height_, &out_width_, |
| 344 | &out_height_); |
magjed | 604abe0 | 2016-05-19 06:05:40 -0700 | [diff] [blame] | 345 | EXPECT_GT(out_width_, 0); |
| 346 | EXPECT_GT(out_height_, 0); |
| 347 | |
| 348 | adapter_.AdaptFrameResolution(640, 480, capture_interval * 25 / 10, |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 349 | &cropped_width_, &cropped_height_, &out_width_, |
| 350 | &out_height_); |
magjed | 604abe0 | 2016-05-19 06:05:40 -0700 | [diff] [blame] | 351 | EXPECT_GT(out_width_, 0); |
| 352 | EXPECT_GT(out_height_, 0); |
| 353 | |
| 354 | adapter_.AdaptFrameResolution(640, 480, capture_interval * 30 / 10, |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 355 | &cropped_width_, &cropped_height_, &out_width_, |
| 356 | &out_height_); |
magjed | 604abe0 | 2016-05-19 06:05:40 -0700 | [diff] [blame] | 357 | EXPECT_GT(out_width_, 0); |
| 358 | EXPECT_GT(out_height_, 0); |
| 359 | |
| 360 | adapter_.AdaptFrameResolution(640, 480, capture_interval * 35 / 10, |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 361 | &cropped_width_, &cropped_height_, &out_width_, |
| 362 | &out_height_); |
magjed | 604abe0 | 2016-05-19 06:05:40 -0700 | [diff] [blame] | 363 | EXPECT_GT(out_width_, 0); |
| 364 | EXPECT_GT(out_height_, 0); |
| 365 | |
| 366 | adapter_.AdaptFrameResolution(640, 480, capture_interval * 50 / 10, |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 367 | &cropped_width_, &cropped_height_, &out_width_, |
| 368 | &out_height_); |
magjed | 604abe0 | 2016-05-19 06:05:40 -0700 | [diff] [blame] | 369 | EXPECT_GT(out_width_, 0); |
| 370 | EXPECT_GT(out_height_, 0); |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | // Adapt the frame rate to be half of the capture rate after capturing no less |
| 374 | // than 10 frames. Expect no frame dropped before adaptation and frame dropped |
| 375 | // after adaptation. |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 376 | TEST_P(VideoAdapterTest, AdaptFramerateOntheFly) { |
| 377 | OnOutputFormatRequest(kWidth, kHeight, kDefaultFps); |
Magnus Jedvert | 0184057 | 2015-04-10 11:18:39 +0200 | [diff] [blame] | 378 | for (int i = 0; i < 10; ++i) |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 379 | adapter_wrapper_->AdaptFrame(frame_source_->GetFrame()); |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 380 | |
| 381 | // Verify no frame drop before adaptation. |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 382 | EXPECT_EQ(0, adapter_wrapper_->GetStats().dropped_frames); |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 383 | |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 384 | // Adapt the frame rate. |
| 385 | OnOutputFormatRequest(kWidth, kHeight, kDefaultFps / 2); |
Magnus Jedvert | 0184057 | 2015-04-10 11:18:39 +0200 | [diff] [blame] | 386 | for (int i = 0; i < 20; ++i) |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 387 | adapter_wrapper_->AdaptFrame(frame_source_->GetFrame()); |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 388 | |
| 389 | // Verify frame drop after adaptation. |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 390 | EXPECT_GT(adapter_wrapper_->GetStats().dropped_frames, 0); |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 391 | } |
| 392 | |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 393 | // Do not adapt the frame rate or the resolution. Expect no frame drop, no |
| 394 | // cropping, and no resolution change. |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 395 | TEST_P(VideoAdapterTest, AdaptFramerateRequestMax) { |
Danil Chapovalov | 00c7183 | 2018-06-15 15:58:38 +0200 | [diff] [blame] | 396 | adapter_.OnResolutionFramerateRequest(absl::nullopt, |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 397 | std::numeric_limits<int>::max(), |
| 398 | std::numeric_limits<int>::max()); |
| 399 | |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 400 | for (int i = 0; i < 10; ++i) |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 401 | adapter_wrapper_->AdaptFrame(frame_source_->GetFrame()); |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 402 | |
| 403 | // Verify no frame drop and no resolution change. |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 404 | VideoAdapterWrapper::Stats stats = adapter_wrapper_->GetStats(); |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 405 | EXPECT_GE(stats.captured_frames, 10); |
| 406 | EXPECT_EQ(0, stats.dropped_frames); |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 407 | VerifyAdaptedResolution(stats, kWidth, kHeight, kWidth, kHeight); |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 408 | EXPECT_TRUE(stats.last_adapt_was_no_op); |
| 409 | } |
| 410 | |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 411 | TEST_P(VideoAdapterTest, AdaptFramerateRequestZero) { |
Danil Chapovalov | 00c7183 | 2018-06-15 15:58:38 +0200 | [diff] [blame] | 412 | adapter_.OnResolutionFramerateRequest(absl::nullopt, |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 413 | std::numeric_limits<int>::max(), 0); |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 414 | for (int i = 0; i < 10; ++i) |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 415 | adapter_wrapper_->AdaptFrame(frame_source_->GetFrame()); |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 416 | |
| 417 | // Verify no crash and that frames aren't dropped. |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 418 | VideoAdapterWrapper::Stats stats = adapter_wrapper_->GetStats(); |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 419 | EXPECT_GE(stats.captured_frames, 10); |
| 420 | EXPECT_EQ(10, stats.dropped_frames); |
| 421 | } |
| 422 | |
| 423 | // Adapt the frame rate to be half of the capture rate at the beginning. Expect |
| 424 | // the number of dropped frames to be half of the number the captured frames. |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 425 | TEST_P(VideoAdapterTest, AdaptFramerateRequestHalf) { |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 426 | adapter_.OnResolutionFramerateRequest( |
Danil Chapovalov | 00c7183 | 2018-06-15 15:58:38 +0200 | [diff] [blame] | 427 | absl::nullopt, std::numeric_limits<int>::max(), kDefaultFps / 2); |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 428 | for (int i = 0; i < 10; ++i) |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 429 | adapter_wrapper_->AdaptFrame(frame_source_->GetFrame()); |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 430 | |
| 431 | // Verify no crash and that frames aren't dropped. |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 432 | VideoAdapterWrapper::Stats stats = adapter_wrapper_->GetStats(); |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 433 | EXPECT_GE(stats.captured_frames, 10); |
| 434 | EXPECT_EQ(5, stats.dropped_frames); |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 435 | VerifyAdaptedResolution(stats, kWidth, kHeight, kWidth, kHeight); |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 436 | } |
| 437 | |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 438 | // Set a very high output pixel resolution. Expect no cropping or resolution |
| 439 | // change. |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 440 | TEST_P(VideoAdapterTest, AdaptFrameResolutionHighLimit) { |
| 441 | OnOutputFormatRequest(kWidth * 10, kHeight * 10, kDefaultFps); |
| 442 | EXPECT_TRUE(adapter_.AdaptFrameResolution(kWidth, kHeight, 0, &cropped_width_, |
| 443 | &cropped_height_, &out_width_, |
| 444 | &out_height_)); |
| 445 | EXPECT_EQ(kWidth, cropped_width_); |
| 446 | EXPECT_EQ(kHeight, cropped_height_); |
| 447 | EXPECT_EQ(kWidth, out_width_); |
| 448 | EXPECT_EQ(kHeight, out_height_); |
magjed@webrtc.org | f58b455 | 2014-11-19 18:09:14 +0000 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | // Adapt the frame resolution to be the same as capture resolution. Expect no |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 452 | // cropping or resolution change. |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 453 | TEST_P(VideoAdapterTest, AdaptFrameResolutionIdentical) { |
| 454 | OnOutputFormatRequest(kWidth, kHeight, kDefaultFps); |
| 455 | EXPECT_TRUE(adapter_.AdaptFrameResolution(kWidth, kHeight, 0, &cropped_width_, |
| 456 | &cropped_height_, &out_width_, |
| 457 | &out_height_)); |
| 458 | EXPECT_EQ(kWidth, cropped_width_); |
| 459 | EXPECT_EQ(kHeight, cropped_height_); |
| 460 | EXPECT_EQ(kWidth, out_width_); |
| 461 | EXPECT_EQ(kHeight, out_height_); |
magjed@webrtc.org | f58b455 | 2014-11-19 18:09:14 +0000 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | // Adapt the frame resolution to be a quarter of the capture resolution. Expect |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 465 | // no cropping, but a resolution change. |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 466 | TEST_P(VideoAdapterTest, AdaptFrameResolutionQuarter) { |
| 467 | OnOutputFormatRequest(kWidth / 2, kHeight / 2, kDefaultFps); |
| 468 | EXPECT_TRUE(adapter_.AdaptFrameResolution(kWidth, kHeight, 0, &cropped_width_, |
| 469 | &cropped_height_, &out_width_, |
| 470 | &out_height_)); |
| 471 | EXPECT_EQ(kWidth, cropped_width_); |
| 472 | EXPECT_EQ(kHeight, cropped_height_); |
| 473 | EXPECT_EQ(kWidth / 2, out_width_); |
| 474 | EXPECT_EQ(kHeight / 2, out_height_); |
magjed@webrtc.org | f58b455 | 2014-11-19 18:09:14 +0000 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | // Adapt the pixel resolution to 0. Expect frame drop. |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 478 | TEST_P(VideoAdapterTest, AdaptFrameResolutionDrop) { |
| 479 | OnOutputFormatRequest(kWidth * 0, kHeight * 0, kDefaultFps); |
| 480 | EXPECT_FALSE(adapter_.AdaptFrameResolution(kWidth, kHeight, 0, |
| 481 | &cropped_width_, &cropped_height_, |
| 482 | &out_width_, &out_height_)); |
magjed@webrtc.org | f58b455 | 2014-11-19 18:09:14 +0000 | [diff] [blame] | 483 | } |
| 484 | |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 485 | // Adapt the frame resolution to be a quarter of the capture resolution at the |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 486 | // beginning. Expect no cropping but a resolution change. |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 487 | TEST_P(VideoAdapterTest, AdaptResolution) { |
| 488 | OnOutputFormatRequest(kWidth / 2, kHeight / 2, kDefaultFps); |
Magnus Jedvert | 0184057 | 2015-04-10 11:18:39 +0200 | [diff] [blame] | 489 | for (int i = 0; i < 10; ++i) |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 490 | adapter_wrapper_->AdaptFrame(frame_source_->GetFrame()); |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 491 | |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 492 | // Verify no frame drop, no cropping, and resolution change. |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 493 | VideoAdapterWrapper::Stats stats = adapter_wrapper_->GetStats(); |
pbos@webrtc.org | c9b3f77 | 2014-08-26 12:33:18 +0000 | [diff] [blame] | 494 | EXPECT_EQ(0, stats.dropped_frames); |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 495 | VerifyAdaptedResolution(stats, kWidth, kHeight, kWidth / 2, kHeight / 2); |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 496 | } |
| 497 | |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 498 | // Adapt the frame resolution to be a quarter of the capture resolution after |
| 499 | // capturing no less than 10 frames. Expect no resolution change before |
| 500 | // adaptation and resolution change after adaptation. |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 501 | TEST_P(VideoAdapterTest, AdaptResolutionOnTheFly) { |
| 502 | OnOutputFormatRequest(kWidth, kHeight, kDefaultFps); |
Magnus Jedvert | 0184057 | 2015-04-10 11:18:39 +0200 | [diff] [blame] | 503 | for (int i = 0; i < 10; ++i) |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 504 | adapter_wrapper_->AdaptFrame(frame_source_->GetFrame()); |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 505 | |
| 506 | // Verify no resolution change before adaptation. |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 507 | VerifyAdaptedResolution(adapter_wrapper_->GetStats(), kWidth, kHeight, kWidth, |
| 508 | kHeight); |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 509 | |
| 510 | // Adapt the frame resolution. |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 511 | OnOutputFormatRequest(kWidth / 2, kHeight / 2, kDefaultFps); |
Magnus Jedvert | 0184057 | 2015-04-10 11:18:39 +0200 | [diff] [blame] | 512 | for (int i = 0; i < 10; ++i) |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 513 | adapter_wrapper_->AdaptFrame(frame_source_->GetFrame()); |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 514 | |
| 515 | // Verify resolution change after adaptation. |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 516 | VerifyAdaptedResolution(adapter_wrapper_->GetStats(), kWidth, kHeight, |
| 517 | kWidth / 2, kHeight / 2); |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 518 | } |
| 519 | |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 520 | // Drop all frames for resolution 0x0. |
| 521 | TEST_P(VideoAdapterTest, DropAllFrames) { |
| 522 | OnOutputFormatRequest(kWidth * 0, kHeight * 0, kDefaultFps); |
Magnus Jedvert | 0184057 | 2015-04-10 11:18:39 +0200 | [diff] [blame] | 523 | for (int i = 0; i < 10; ++i) |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 524 | adapter_wrapper_->AdaptFrame(frame_source_->GetFrame()); |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 525 | |
| 526 | // Verify all frames are dropped. |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 527 | VideoAdapterWrapper::Stats stats = adapter_wrapper_->GetStats(); |
pbos@webrtc.org | c9b3f77 | 2014-08-26 12:33:18 +0000 | [diff] [blame] | 528 | EXPECT_GE(stats.captured_frames, 10); |
| 529 | EXPECT_EQ(stats.captured_frames, stats.dropped_frames); |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 530 | } |
| 531 | |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 532 | TEST_P(VideoAdapterTest, TestOnOutputFormatRequest) { |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 533 | EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 400, 0, &cropped_width_, |
| 534 | &cropped_height_, &out_width_, |
| 535 | &out_height_)); |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 536 | EXPECT_EQ(640, cropped_width_); |
| 537 | EXPECT_EQ(400, cropped_height_); |
| 538 | EXPECT_EQ(640, out_width_); |
| 539 | EXPECT_EQ(400, out_height_); |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 540 | |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 541 | // Format request 640x400. |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 542 | OnOutputFormatRequest(640, 400, absl::nullopt); |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 543 | EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 400, 0, &cropped_width_, |
| 544 | &cropped_height_, &out_width_, |
| 545 | &out_height_)); |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 546 | EXPECT_EQ(640, cropped_width_); |
| 547 | EXPECT_EQ(400, cropped_height_); |
| 548 | EXPECT_EQ(640, out_width_); |
| 549 | EXPECT_EQ(400, out_height_); |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 550 | |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 551 | // Request 1280x720, higher than input, but aspect 16:9. Expect cropping but |
| 552 | // no scaling. |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 553 | OnOutputFormatRequest(1280, 720, absl::nullopt); |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 554 | EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 400, 0, &cropped_width_, |
| 555 | &cropped_height_, &out_width_, |
| 556 | &out_height_)); |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 557 | EXPECT_EQ(640, cropped_width_); |
| 558 | EXPECT_EQ(360, cropped_height_); |
| 559 | EXPECT_EQ(640, out_width_); |
| 560 | EXPECT_EQ(360, out_height_); |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 561 | |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 562 | // Request 0x0. |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 563 | OnOutputFormatRequest(0, 0, absl::nullopt); |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 564 | EXPECT_FALSE(adapter_.AdaptFrameResolution(640, 400, 0, &cropped_width_, |
| 565 | &cropped_height_, &out_width_, |
| 566 | &out_height_)); |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 567 | |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 568 | // Request 320x200. Expect scaling, but no cropping. |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 569 | OnOutputFormatRequest(320, 200, absl::nullopt); |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 570 | EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 400, 0, &cropped_width_, |
| 571 | &cropped_height_, &out_width_, |
| 572 | &out_height_)); |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 573 | EXPECT_EQ(640, cropped_width_); |
| 574 | EXPECT_EQ(400, cropped_height_); |
| 575 | EXPECT_EQ(320, out_width_); |
| 576 | EXPECT_EQ(200, out_height_); |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 577 | |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 578 | // Request resolution close to 2/3 scale. Expect adapt down. Scaling to 2/3 |
| 579 | // is not optimized and not allowed, therefore 1/2 scaling will be used |
| 580 | // instead. |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 581 | OnOutputFormatRequest(424, 265, absl::nullopt); |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 582 | EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 400, 0, &cropped_width_, |
| 583 | &cropped_height_, &out_width_, |
| 584 | &out_height_)); |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 585 | EXPECT_EQ(640, cropped_width_); |
| 586 | EXPECT_EQ(400, cropped_height_); |
| 587 | EXPECT_EQ(320, out_width_); |
| 588 | EXPECT_EQ(200, out_height_); |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 589 | |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 590 | // Request resolution of 3 / 8. Expect adapt down. |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 591 | OnOutputFormatRequest(640 * 3 / 8, 400 * 3 / 8, absl::nullopt); |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 592 | EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 400, 0, &cropped_width_, |
| 593 | &cropped_height_, &out_width_, |
| 594 | &out_height_)); |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 595 | EXPECT_EQ(640, cropped_width_); |
| 596 | EXPECT_EQ(400, cropped_height_); |
| 597 | EXPECT_EQ(640 * 3 / 8, out_width_); |
| 598 | EXPECT_EQ(400 * 3 / 8, out_height_); |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 599 | |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 600 | // Switch back up. Expect adapt. |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 601 | OnOutputFormatRequest(320, 200, absl::nullopt); |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 602 | EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 400, 0, &cropped_width_, |
| 603 | &cropped_height_, &out_width_, |
| 604 | &out_height_)); |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 605 | EXPECT_EQ(640, cropped_width_); |
| 606 | EXPECT_EQ(400, cropped_height_); |
| 607 | EXPECT_EQ(320, out_width_); |
| 608 | EXPECT_EQ(200, out_height_); |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 609 | |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 610 | // Format request 480x300. |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 611 | OnOutputFormatRequest(480, 300, absl::nullopt); |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 612 | EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 400, 0, &cropped_width_, |
| 613 | &cropped_height_, &out_width_, |
| 614 | &out_height_)); |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 615 | EXPECT_EQ(640, cropped_width_); |
| 616 | EXPECT_EQ(400, cropped_height_); |
| 617 | EXPECT_EQ(480, out_width_); |
| 618 | EXPECT_EQ(300, out_height_); |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 619 | } |
| 620 | |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 621 | TEST_P(VideoAdapterTest, TestViewRequestPlusCameraSwitch) { |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 622 | // Start at HD. |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 623 | EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, &cropped_width_, |
| 624 | &cropped_height_, &out_width_, |
| 625 | &out_height_)); |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 626 | EXPECT_EQ(1280, cropped_width_); |
| 627 | EXPECT_EQ(720, cropped_height_); |
| 628 | EXPECT_EQ(1280, out_width_); |
| 629 | EXPECT_EQ(720, out_height_); |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 630 | |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 631 | // Format request for VGA. |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 632 | OnOutputFormatRequest(640, 360, absl::nullopt); |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 633 | EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, &cropped_width_, |
| 634 | &cropped_height_, &out_width_, |
| 635 | &out_height_)); |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 636 | EXPECT_EQ(1280, cropped_width_); |
| 637 | EXPECT_EQ(720, cropped_height_); |
| 638 | EXPECT_EQ(640, out_width_); |
| 639 | EXPECT_EQ(360, out_height_); |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 640 | |
| 641 | // Now, the camera reopens at VGA. |
| 642 | // Both the frame and the output format should be 640x360. |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 643 | EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 360, 0, &cropped_width_, |
| 644 | &cropped_height_, &out_width_, |
| 645 | &out_height_)); |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 646 | EXPECT_EQ(640, cropped_width_); |
| 647 | EXPECT_EQ(360, cropped_height_); |
| 648 | EXPECT_EQ(640, out_width_); |
| 649 | EXPECT_EQ(360, out_height_); |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 650 | |
| 651 | // And another view request comes in for 640x360, which should have no |
| 652 | // real impact. |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 653 | OnOutputFormatRequest(640, 360, absl::nullopt); |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 654 | EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 360, 0, &cropped_width_, |
| 655 | &cropped_height_, &out_width_, |
| 656 | &out_height_)); |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 657 | EXPECT_EQ(640, cropped_width_); |
| 658 | EXPECT_EQ(360, cropped_height_); |
| 659 | EXPECT_EQ(640, out_width_); |
| 660 | EXPECT_EQ(360, out_height_); |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 661 | } |
| 662 | |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 663 | TEST_P(VideoAdapterTest, TestVgaWidth) { |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 664 | // Reqeuested Output format is 640x360. |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 665 | OnOutputFormatRequest(640, 360, absl::nullopt); |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 666 | |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 667 | EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0, &cropped_width_, |
| 668 | &cropped_height_, &out_width_, |
| 669 | &out_height_)); |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 670 | // Expect cropping. |
| 671 | EXPECT_EQ(640, cropped_width_); |
| 672 | EXPECT_EQ(360, cropped_height_); |
| 673 | EXPECT_EQ(640, out_width_); |
| 674 | EXPECT_EQ(360, out_height_); |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 675 | |
| 676 | // But if frames come in at 640x360, we shouldn't adapt them down. |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 677 | EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 360, 0, &cropped_width_, |
| 678 | &cropped_height_, &out_width_, |
| 679 | &out_height_)); |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 680 | EXPECT_EQ(640, cropped_width_); |
| 681 | EXPECT_EQ(360, cropped_height_); |
| 682 | EXPECT_EQ(640, out_width_); |
| 683 | EXPECT_EQ(360, out_height_); |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 684 | |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 685 | EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0, &cropped_width_, |
| 686 | &cropped_height_, &out_width_, |
| 687 | &out_height_)); |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 688 | EXPECT_EQ(640, cropped_width_); |
| 689 | EXPECT_EQ(360, cropped_height_); |
| 690 | EXPECT_EQ(640, out_width_); |
| 691 | EXPECT_EQ(360, out_height_); |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 692 | } |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 693 | |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 694 | TEST_P(VideoAdapterTest, TestOnResolutionRequestInSmallSteps) { |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 695 | EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, &cropped_width_, |
| 696 | &cropped_height_, &out_width_, |
| 697 | &out_height_)); |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 698 | EXPECT_EQ(1280, cropped_width_); |
| 699 | EXPECT_EQ(720, cropped_height_); |
| 700 | EXPECT_EQ(1280, out_width_); |
| 701 | EXPECT_EQ(720, out_height_); |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 702 | |
| 703 | // Adapt down one step. |
Danil Chapovalov | 00c7183 | 2018-06-15 15:58:38 +0200 | [diff] [blame] | 704 | adapter_.OnResolutionFramerateRequest(absl::nullopt, 1280 * 720 - 1, |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 705 | std::numeric_limits<int>::max()); |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 706 | EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, &cropped_width_, |
| 707 | &cropped_height_, &out_width_, |
| 708 | &out_height_)); |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 709 | EXPECT_EQ(1280, cropped_width_); |
| 710 | EXPECT_EQ(720, cropped_height_); |
| 711 | EXPECT_EQ(960, out_width_); |
| 712 | EXPECT_EQ(540, out_height_); |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 713 | |
| 714 | // Adapt down one step more. |
Danil Chapovalov | 00c7183 | 2018-06-15 15:58:38 +0200 | [diff] [blame] | 715 | adapter_.OnResolutionFramerateRequest(absl::nullopt, 960 * 540 - 1, |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 716 | std::numeric_limits<int>::max()); |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 717 | EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, &cropped_width_, |
| 718 | &cropped_height_, &out_width_, |
| 719 | &out_height_)); |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 720 | EXPECT_EQ(1280, cropped_width_); |
| 721 | EXPECT_EQ(720, cropped_height_); |
| 722 | EXPECT_EQ(640, out_width_); |
| 723 | EXPECT_EQ(360, out_height_); |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 724 | |
| 725 | // Adapt down one step more. |
Danil Chapovalov | 00c7183 | 2018-06-15 15:58:38 +0200 | [diff] [blame] | 726 | adapter_.OnResolutionFramerateRequest(absl::nullopt, 640 * 360 - 1, |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 727 | std::numeric_limits<int>::max()); |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 728 | EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, &cropped_width_, |
| 729 | &cropped_height_, &out_width_, |
| 730 | &out_height_)); |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 731 | EXPECT_EQ(1280, cropped_width_); |
| 732 | EXPECT_EQ(720, cropped_height_); |
| 733 | EXPECT_EQ(480, out_width_); |
| 734 | EXPECT_EQ(270, out_height_); |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 735 | |
| 736 | // Adapt up one step. |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 737 | adapter_.OnResolutionFramerateRequest(640 * 360, 960 * 540, |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 738 | std::numeric_limits<int>::max()); |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 739 | EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, &cropped_width_, |
| 740 | &cropped_height_, &out_width_, |
| 741 | &out_height_)); |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 742 | EXPECT_EQ(1280, cropped_width_); |
| 743 | EXPECT_EQ(720, cropped_height_); |
| 744 | EXPECT_EQ(640, out_width_); |
| 745 | EXPECT_EQ(360, out_height_); |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 746 | |
| 747 | // Adapt up one step more. |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 748 | adapter_.OnResolutionFramerateRequest(960 * 540, 1280 * 720, |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 749 | std::numeric_limits<int>::max()); |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 750 | EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, &cropped_width_, |
| 751 | &cropped_height_, &out_width_, |
| 752 | &out_height_)); |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 753 | EXPECT_EQ(1280, cropped_width_); |
| 754 | EXPECT_EQ(720, cropped_height_); |
| 755 | EXPECT_EQ(960, out_width_); |
| 756 | EXPECT_EQ(540, out_height_); |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 757 | |
| 758 | // Adapt up one step more. |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 759 | adapter_.OnResolutionFramerateRequest(1280 * 720, 1920 * 1080, |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 760 | std::numeric_limits<int>::max()); |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 761 | EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, &cropped_width_, |
| 762 | &cropped_height_, &out_width_, |
| 763 | &out_height_)); |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 764 | EXPECT_EQ(1280, cropped_width_); |
| 765 | EXPECT_EQ(720, cropped_height_); |
| 766 | EXPECT_EQ(1280, out_width_); |
| 767 | EXPECT_EQ(720, out_height_); |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 768 | } |
| 769 | |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 770 | TEST_P(VideoAdapterTest, TestOnResolutionRequestMaxZero) { |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 771 | EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, &cropped_width_, |
| 772 | &cropped_height_, &out_width_, |
| 773 | &out_height_)); |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 774 | EXPECT_EQ(1280, cropped_width_); |
| 775 | EXPECT_EQ(720, cropped_height_); |
| 776 | EXPECT_EQ(1280, out_width_); |
| 777 | EXPECT_EQ(720, out_height_); |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 778 | |
Danil Chapovalov | 00c7183 | 2018-06-15 15:58:38 +0200 | [diff] [blame] | 779 | adapter_.OnResolutionFramerateRequest(absl::nullopt, 0, |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 780 | std::numeric_limits<int>::max()); |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 781 | EXPECT_FALSE(adapter_.AdaptFrameResolution(1280, 720, 0, &cropped_width_, |
| 782 | &cropped_height_, &out_width_, |
| 783 | &out_height_)); |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 784 | } |
| 785 | |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 786 | TEST_P(VideoAdapterTest, TestOnResolutionRequestInLargeSteps) { |
sprang | 84a3759 | 2017-02-10 07:04:27 -0800 | [diff] [blame] | 787 | // Large step down. |
Danil Chapovalov | 00c7183 | 2018-06-15 15:58:38 +0200 | [diff] [blame] | 788 | adapter_.OnResolutionFramerateRequest(absl::nullopt, 640 * 360 - 1, |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 789 | std::numeric_limits<int>::max()); |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 790 | EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, &cropped_width_, |
| 791 | &cropped_height_, &out_width_, |
| 792 | &out_height_)); |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 793 | EXPECT_EQ(1280, cropped_width_); |
| 794 | EXPECT_EQ(720, cropped_height_); |
| 795 | EXPECT_EQ(480, out_width_); |
| 796 | EXPECT_EQ(270, out_height_); |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 797 | |
sprang | 84a3759 | 2017-02-10 07:04:27 -0800 | [diff] [blame] | 798 | // Large step up. |
Oskar Sundbom | 7880758 | 2017-11-16 11:09:55 +0100 | [diff] [blame] | 799 | adapter_.OnResolutionFramerateRequest(1280 * 720, 1920 * 1080, |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 800 | std::numeric_limits<int>::max()); |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 801 | EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, &cropped_width_, |
| 802 | &cropped_height_, &out_width_, |
| 803 | &out_height_)); |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 804 | EXPECT_EQ(1280, cropped_width_); |
| 805 | EXPECT_EQ(720, cropped_height_); |
| 806 | EXPECT_EQ(1280, out_width_); |
| 807 | EXPECT_EQ(720, out_height_); |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 808 | } |
| 809 | |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 810 | TEST_P(VideoAdapterTest, TestOnOutputFormatRequestCapsMaxResolution) { |
Danil Chapovalov | 00c7183 | 2018-06-15 15:58:38 +0200 | [diff] [blame] | 811 | adapter_.OnResolutionFramerateRequest(absl::nullopt, 640 * 360 - 1, |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 812 | std::numeric_limits<int>::max()); |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 813 | EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, &cropped_width_, |
| 814 | &cropped_height_, &out_width_, |
| 815 | &out_height_)); |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 816 | EXPECT_EQ(1280, cropped_width_); |
| 817 | EXPECT_EQ(720, cropped_height_); |
| 818 | EXPECT_EQ(480, out_width_); |
| 819 | EXPECT_EQ(270, out_height_); |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 820 | |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 821 | OnOutputFormatRequest(640, 360, absl::nullopt); |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 822 | EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, &cropped_width_, |
| 823 | &cropped_height_, &out_width_, |
| 824 | &out_height_)); |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 825 | EXPECT_EQ(1280, cropped_width_); |
| 826 | EXPECT_EQ(720, cropped_height_); |
| 827 | EXPECT_EQ(480, out_width_); |
| 828 | EXPECT_EQ(270, out_height_); |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 829 | |
Danil Chapovalov | 00c7183 | 2018-06-15 15:58:38 +0200 | [diff] [blame] | 830 | adapter_.OnResolutionFramerateRequest(absl::nullopt, 960 * 720, |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 831 | std::numeric_limits<int>::max()); |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 832 | EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, &cropped_width_, |
| 833 | &cropped_height_, &out_width_, |
| 834 | &out_height_)); |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 835 | EXPECT_EQ(1280, cropped_width_); |
| 836 | EXPECT_EQ(720, cropped_height_); |
| 837 | EXPECT_EQ(640, out_width_); |
| 838 | EXPECT_EQ(360, out_height_); |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 839 | } |
| 840 | |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 841 | TEST_P(VideoAdapterTest, TestOnResolutionRequestReset) { |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 842 | EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, &cropped_width_, |
| 843 | &cropped_height_, &out_width_, |
| 844 | &out_height_)); |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 845 | EXPECT_EQ(1280, cropped_width_); |
| 846 | EXPECT_EQ(720, cropped_height_); |
| 847 | EXPECT_EQ(1280, out_width_); |
| 848 | EXPECT_EQ(720, out_height_); |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 849 | |
Danil Chapovalov | 00c7183 | 2018-06-15 15:58:38 +0200 | [diff] [blame] | 850 | adapter_.OnResolutionFramerateRequest(absl::nullopt, 640 * 360 - 1, |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 851 | std::numeric_limits<int>::max()); |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 852 | EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, &cropped_width_, |
| 853 | &cropped_height_, &out_width_, |
| 854 | &out_height_)); |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 855 | EXPECT_EQ(1280, cropped_width_); |
| 856 | EXPECT_EQ(720, cropped_height_); |
| 857 | EXPECT_EQ(480, out_width_); |
| 858 | EXPECT_EQ(270, out_height_); |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 859 | |
Danil Chapovalov | 00c7183 | 2018-06-15 15:58:38 +0200 | [diff] [blame] | 860 | adapter_.OnResolutionFramerateRequest(absl::nullopt, |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 861 | std::numeric_limits<int>::max(), |
| 862 | std::numeric_limits<int>::max()); |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 863 | EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, &cropped_width_, |
| 864 | &cropped_height_, &out_width_, |
| 865 | &out_height_)); |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 866 | EXPECT_EQ(1280, cropped_width_); |
| 867 | EXPECT_EQ(720, cropped_height_); |
| 868 | EXPECT_EQ(1280, out_width_); |
| 869 | EXPECT_EQ(720, out_height_); |
| 870 | } |
| 871 | |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 872 | TEST_P(VideoAdapterTest, TestOnOutputFormatRequestResolutionReset) { |
| 873 | EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, &cropped_width_, |
| 874 | &cropped_height_, &out_width_, |
| 875 | &out_height_)); |
| 876 | EXPECT_EQ(1280, cropped_width_); |
| 877 | EXPECT_EQ(720, cropped_height_); |
| 878 | EXPECT_EQ(1280, out_width_); |
| 879 | EXPECT_EQ(720, out_height_); |
| 880 | |
| 881 | adapter_.OnOutputFormatRequest(absl::nullopt, 640 * 360 - 1, absl::nullopt); |
| 882 | EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, &cropped_width_, |
| 883 | &cropped_height_, &out_width_, |
| 884 | &out_height_)); |
| 885 | EXPECT_EQ(1280, cropped_width_); |
| 886 | EXPECT_EQ(720, cropped_height_); |
| 887 | EXPECT_EQ(480, out_width_); |
| 888 | EXPECT_EQ(270, out_height_); |
| 889 | |
| 890 | adapter_.OnOutputFormatRequest(absl::nullopt, absl::nullopt, absl::nullopt); |
| 891 | EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, &cropped_width_, |
| 892 | &cropped_height_, &out_width_, |
| 893 | &out_height_)); |
| 894 | EXPECT_EQ(1280, cropped_width_); |
| 895 | EXPECT_EQ(720, cropped_height_); |
| 896 | EXPECT_EQ(1280, out_width_); |
| 897 | EXPECT_EQ(720, out_height_); |
| 898 | } |
| 899 | |
| 900 | TEST_P(VideoAdapterTest, TestOnOutputFormatRequestFpsReset) { |
| 901 | OnOutputFormatRequest(kWidth, kHeight, kDefaultFps / 2); |
| 902 | for (int i = 0; i < 10; ++i) |
| 903 | adapter_wrapper_->AdaptFrame(frame_source_->GetFrame()); |
| 904 | |
| 905 | // Verify frame drop. |
| 906 | const int dropped_frames = adapter_wrapper_->GetStats().dropped_frames; |
| 907 | EXPECT_GT(dropped_frames, 0); |
| 908 | |
| 909 | // Reset frame rate. |
| 910 | OnOutputFormatRequest(kWidth, kHeight, absl::nullopt); |
| 911 | for (int i = 0; i < 20; ++i) |
| 912 | adapter_wrapper_->AdaptFrame(frame_source_->GetFrame()); |
| 913 | |
| 914 | // Verify no frame drop after reset. |
| 915 | EXPECT_EQ(dropped_frames, adapter_wrapper_->GetStats().dropped_frames); |
| 916 | } |
| 917 | |
| 918 | TEST_P(VideoAdapterTest, RequestAspectRatio) { |
| 919 | // Request aspect ratio 320/180 (16:9), smaller than input, but no resolution |
| 920 | // limit. Expect cropping but no scaling. |
| 921 | adapter_.OnOutputFormatRequest(std::make_pair(320, 180), absl::nullopt, |
| 922 | absl::nullopt); |
| 923 | EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 400, 0, &cropped_width_, |
| 924 | &cropped_height_, &out_width_, |
| 925 | &out_height_)); |
| 926 | EXPECT_EQ(640, cropped_width_); |
| 927 | EXPECT_EQ(360, cropped_height_); |
| 928 | EXPECT_EQ(640, out_width_); |
| 929 | EXPECT_EQ(360, out_height_); |
| 930 | } |
| 931 | |
| 932 | TEST_P(VideoAdapterTest, RequestAspectRatioWithDifferentOrientation) { |
| 933 | // Request 720x1280, higher than input, but aspect 16:9. Orientation should |
| 934 | // not matter, expect cropping but no scaling. |
| 935 | OnOutputFormatRequest(720, 1280, absl::nullopt); |
| 936 | EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 400, 0, &cropped_width_, |
| 937 | &cropped_height_, &out_width_, |
| 938 | &out_height_)); |
| 939 | EXPECT_EQ(640, cropped_width_); |
| 940 | EXPECT_EQ(360, cropped_height_); |
| 941 | EXPECT_EQ(640, out_width_); |
| 942 | EXPECT_EQ(360, out_height_); |
| 943 | } |
| 944 | |
| 945 | TEST_P(VideoAdapterTest, InvalidAspectRatioIgnored) { |
| 946 | // Request aspect ratio 320/0. Expect no cropping. |
| 947 | adapter_.OnOutputFormatRequest(std::make_pair(320, 0), absl::nullopt, |
| 948 | absl::nullopt); |
| 949 | EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 400, 0, &cropped_width_, |
| 950 | &cropped_height_, &out_width_, |
| 951 | &out_height_)); |
| 952 | EXPECT_EQ(640, cropped_width_); |
| 953 | EXPECT_EQ(400, cropped_height_); |
| 954 | EXPECT_EQ(640, out_width_); |
| 955 | EXPECT_EQ(400, out_height_); |
| 956 | } |
| 957 | |
| 958 | TEST_P(VideoAdapterTest, TestCroppingWithResolutionRequest) { |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 959 | // Ask for 640x360 (16:9 aspect). |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 960 | OnOutputFormatRequest(640, 360, absl::nullopt); |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 961 | // Send 640x480 (4:3 aspect). |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 962 | EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0, &cropped_width_, |
| 963 | &cropped_height_, &out_width_, |
| 964 | &out_height_)); |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 965 | // Expect cropping to 16:9 format and no scaling. |
| 966 | EXPECT_EQ(640, cropped_width_); |
| 967 | EXPECT_EQ(360, cropped_height_); |
| 968 | EXPECT_EQ(640, out_width_); |
| 969 | EXPECT_EQ(360, out_height_); |
| 970 | |
| 971 | // Adapt down one step. |
Danil Chapovalov | 00c7183 | 2018-06-15 15:58:38 +0200 | [diff] [blame] | 972 | adapter_.OnResolutionFramerateRequest(absl::nullopt, 640 * 360 - 1, |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 973 | std::numeric_limits<int>::max()); |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 974 | // Expect cropping to 16:9 format and 3/4 scaling. |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 975 | EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0, &cropped_width_, |
| 976 | &cropped_height_, &out_width_, |
| 977 | &out_height_)); |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 978 | EXPECT_EQ(640, cropped_width_); |
| 979 | EXPECT_EQ(360, cropped_height_); |
| 980 | EXPECT_EQ(480, out_width_); |
| 981 | EXPECT_EQ(270, out_height_); |
| 982 | |
| 983 | // Adapt down one step more. |
Danil Chapovalov | 00c7183 | 2018-06-15 15:58:38 +0200 | [diff] [blame] | 984 | adapter_.OnResolutionFramerateRequest(absl::nullopt, 480 * 270 - 1, |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 985 | std::numeric_limits<int>::max()); |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 986 | // Expect cropping to 16:9 format and 1/2 scaling. |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 987 | EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0, &cropped_width_, |
| 988 | &cropped_height_, &out_width_, |
| 989 | &out_height_)); |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 990 | EXPECT_EQ(640, cropped_width_); |
| 991 | EXPECT_EQ(360, cropped_height_); |
| 992 | EXPECT_EQ(320, out_width_); |
| 993 | EXPECT_EQ(180, out_height_); |
| 994 | |
| 995 | // Adapt up one step. |
Oskar Sundbom | 7880758 | 2017-11-16 11:09:55 +0100 | [diff] [blame] | 996 | adapter_.OnResolutionFramerateRequest(480 * 270, 640 * 360, |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 997 | std::numeric_limits<int>::max()); |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 998 | // Expect cropping to 16:9 format and 3/4 scaling. |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 999 | EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0, &cropped_width_, |
| 1000 | &cropped_height_, &out_width_, |
| 1001 | &out_height_)); |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 1002 | EXPECT_EQ(640, cropped_width_); |
| 1003 | EXPECT_EQ(360, cropped_height_); |
| 1004 | EXPECT_EQ(480, out_width_); |
| 1005 | EXPECT_EQ(270, out_height_); |
| 1006 | |
| 1007 | // Adapt up one step more. |
Oskar Sundbom | 7880758 | 2017-11-16 11:09:55 +0100 | [diff] [blame] | 1008 | adapter_.OnResolutionFramerateRequest(640 * 360, 960 * 540, |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 1009 | std::numeric_limits<int>::max()); |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 1010 | // Expect cropping to 16:9 format and no scaling. |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 1011 | EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0, &cropped_width_, |
| 1012 | &cropped_height_, &out_width_, |
| 1013 | &out_height_)); |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 1014 | EXPECT_EQ(640, cropped_width_); |
| 1015 | EXPECT_EQ(360, cropped_height_); |
| 1016 | EXPECT_EQ(640, out_width_); |
| 1017 | EXPECT_EQ(360, out_height_); |
| 1018 | |
| 1019 | // Try to adapt up one step more. |
Oskar Sundbom | 7880758 | 2017-11-16 11:09:55 +0100 | [diff] [blame] | 1020 | adapter_.OnResolutionFramerateRequest(960 * 540, 1280 * 720, |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 1021 | std::numeric_limits<int>::max()); |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 1022 | // Expect cropping to 16:9 format and no scaling. |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 1023 | EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0, &cropped_width_, |
| 1024 | &cropped_height_, &out_width_, |
| 1025 | &out_height_)); |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 1026 | EXPECT_EQ(640, cropped_width_); |
| 1027 | EXPECT_EQ(360, cropped_height_); |
| 1028 | EXPECT_EQ(640, out_width_); |
| 1029 | EXPECT_EQ(360, out_height_); |
| 1030 | } |
| 1031 | |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 1032 | TEST_P(VideoAdapterTest, TestCroppingOddResolution) { |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 1033 | // Ask for 640x360 (16:9 aspect), with 3/16 scaling. |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 1034 | OnOutputFormatRequest(640, 360, absl::nullopt); |
Danil Chapovalov | 00c7183 | 2018-06-15 15:58:38 +0200 | [diff] [blame] | 1035 | adapter_.OnResolutionFramerateRequest(absl::nullopt, |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 1036 | 640 * 360 * 3 / 16 * 3 / 16, |
| 1037 | std::numeric_limits<int>::max()); |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 1038 | |
| 1039 | // Send 640x480 (4:3 aspect). |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 1040 | EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0, &cropped_width_, |
| 1041 | &cropped_height_, &out_width_, |
| 1042 | &out_height_)); |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 1043 | |
| 1044 | // Instead of getting the exact aspect ratio with cropped resolution 640x360, |
| 1045 | // the resolution should be adjusted to get a perfect scale factor instead. |
| 1046 | EXPECT_EQ(640, cropped_width_); |
| 1047 | EXPECT_EQ(368, cropped_height_); |
| 1048 | EXPECT_EQ(120, out_width_); |
| 1049 | EXPECT_EQ(69, out_height_); |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 1050 | } |
| 1051 | |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 1052 | TEST_P(VideoAdapterTest, TestAdaptToVerySmallResolution) { |
kthelgason | c847417 | 2016-12-08 08:04:51 -0800 | [diff] [blame] | 1053 | // Ask for 1920x1080 (16:9 aspect), with 1/16 scaling. |
| 1054 | const int w = 1920; |
| 1055 | const int h = 1080; |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 1056 | OnOutputFormatRequest(w, h, absl::nullopt); |
Danil Chapovalov | 00c7183 | 2018-06-15 15:58:38 +0200 | [diff] [blame] | 1057 | adapter_.OnResolutionFramerateRequest(absl::nullopt, w * h * 1 / 16 * 1 / 16, |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 1058 | std::numeric_limits<int>::max()); |
kthelgason | c847417 | 2016-12-08 08:04:51 -0800 | [diff] [blame] | 1059 | |
| 1060 | // Send 1920x1080 (16:9 aspect). |
| 1061 | EXPECT_TRUE(adapter_.AdaptFrameResolution( |
| 1062 | w, h, 0, &cropped_width_, &cropped_height_, &out_width_, &out_height_)); |
| 1063 | |
| 1064 | // Instead of getting the exact aspect ratio with cropped resolution 1920x1080 |
| 1065 | // the resolution should be adjusted to get a perfect scale factor instead. |
| 1066 | EXPECT_EQ(1920, cropped_width_); |
| 1067 | EXPECT_EQ(1072, cropped_height_); |
| 1068 | EXPECT_EQ(120, out_width_); |
| 1069 | EXPECT_EQ(67, out_height_); |
| 1070 | |
| 1071 | // Adapt back up one step to 3/32. |
Oskar Sundbom | 7880758 | 2017-11-16 11:09:55 +0100 | [diff] [blame] | 1072 | adapter_.OnResolutionFramerateRequest(w * h * 3 / 32 * 3 / 32, |
| 1073 | w * h * 1 / 8 * 1 / 8, |
| 1074 | std::numeric_limits<int>::max()); |
kthelgason | c847417 | 2016-12-08 08:04:51 -0800 | [diff] [blame] | 1075 | |
| 1076 | // Send 1920x1080 (16:9 aspect). |
| 1077 | EXPECT_TRUE(adapter_.AdaptFrameResolution( |
| 1078 | w, h, 0, &cropped_width_, &cropped_height_, &out_width_, &out_height_)); |
| 1079 | |
| 1080 | EXPECT_EQ(180, out_width_); |
| 1081 | EXPECT_EQ(99, out_height_); |
| 1082 | } |
| 1083 | |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 1084 | TEST_P(VideoAdapterTest, AdaptFrameResolutionDropWithResolutionRequest) { |
| 1085 | OnOutputFormatRequest(0, 0, kDefaultFps); |
| 1086 | EXPECT_FALSE(adapter_.AdaptFrameResolution(kWidth, kHeight, 0, |
| 1087 | &cropped_width_, &cropped_height_, |
| 1088 | &out_width_, &out_height_)); |
kthelgason | c847417 | 2016-12-08 08:04:51 -0800 | [diff] [blame] | 1089 | |
Oskar Sundbom | 7880758 | 2017-11-16 11:09:55 +0100 | [diff] [blame] | 1090 | adapter_.OnResolutionFramerateRequest(960 * 540, |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 1091 | std::numeric_limits<int>::max(), |
| 1092 | std::numeric_limits<int>::max()); |
kthelgason | c847417 | 2016-12-08 08:04:51 -0800 | [diff] [blame] | 1093 | |
| 1094 | // Still expect all frames to be dropped |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 1095 | EXPECT_FALSE(adapter_.AdaptFrameResolution(kWidth, kHeight, 0, |
| 1096 | &cropped_width_, &cropped_height_, |
| 1097 | &out_width_, &out_height_)); |
kthelgason | c847417 | 2016-12-08 08:04:51 -0800 | [diff] [blame] | 1098 | |
Danil Chapovalov | 00c7183 | 2018-06-15 15:58:38 +0200 | [diff] [blame] | 1099 | adapter_.OnResolutionFramerateRequest(absl::nullopt, 640 * 480 - 1, |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 1100 | std::numeric_limits<int>::max()); |
kthelgason | c847417 | 2016-12-08 08:04:51 -0800 | [diff] [blame] | 1101 | |
| 1102 | // Still expect all frames to be dropped |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 1103 | EXPECT_FALSE(adapter_.AdaptFrameResolution(kWidth, kHeight, 0, |
| 1104 | &cropped_width_, &cropped_height_, |
| 1105 | &out_width_, &out_height_)); |
kthelgason | c847417 | 2016-12-08 08:04:51 -0800 | [diff] [blame] | 1106 | } |
| 1107 | |
Magnus Jedvert | 6d230d7 | 2017-02-22 18:30:27 +0100 | [diff] [blame] | 1108 | // Test that we will adapt to max given a target pixel count close to max. |
Åsa Persson | 2e4419e | 2018-09-06 15:02:55 +0200 | [diff] [blame] | 1109 | TEST_P(VideoAdapterTest, TestAdaptToMax) { |
| 1110 | OnOutputFormatRequest(640, 360, kDefaultFps); |
Oskar Sundbom | 7880758 | 2017-11-16 11:09:55 +0100 | [diff] [blame] | 1111 | adapter_.OnResolutionFramerateRequest(640 * 360 - 1 /* target */, |
| 1112 | std::numeric_limits<int>::max(), |
| 1113 | std::numeric_limits<int>::max()); |
Magnus Jedvert | 6d230d7 | 2017-02-22 18:30:27 +0100 | [diff] [blame] | 1114 | |
| 1115 | EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 360, 0, &cropped_width_, |
| 1116 | &cropped_height_, &out_width_, |
| 1117 | &out_height_)); |
| 1118 | EXPECT_EQ(640, out_width_); |
| 1119 | EXPECT_EQ(360, out_height_); |
| 1120 | } |
Magnus Jedvert | 06aa209 | 2018-10-26 14:00:18 +0200 | [diff] [blame] | 1121 | |
| 1122 | // Test adjusting to 16:9 in landscape, and 9:16 in portrait. |
| 1123 | TEST(VideoAdapterTestMultipleOrientation, TestNormal) { |
| 1124 | VideoAdapter video_adapter; |
| 1125 | video_adapter.OnOutputFormatRequest(std::make_pair(640, 360), 640 * 360, |
| 1126 | std::make_pair(360, 640), 360 * 640, 30); |
| 1127 | |
| 1128 | int cropped_width; |
| 1129 | int cropped_height; |
| 1130 | int out_width; |
| 1131 | int out_height; |
| 1132 | EXPECT_TRUE(video_adapter.AdaptFrameResolution( |
| 1133 | /* in_width= */ 640, /* in_height= */ 480, /* in_timestamp_ns= */ 0, |
| 1134 | &cropped_width, &cropped_height, &out_width, &out_height)); |
| 1135 | EXPECT_EQ(640, cropped_width); |
| 1136 | EXPECT_EQ(360, cropped_height); |
| 1137 | EXPECT_EQ(640, out_width); |
| 1138 | EXPECT_EQ(360, out_height); |
| 1139 | |
| 1140 | EXPECT_TRUE(video_adapter.AdaptFrameResolution( |
| 1141 | /* in_width= */ 480, /* in_height= */ 640, |
| 1142 | /* in_timestamp_ns= */ rtc::kNumNanosecsPerSec / 30, &cropped_width, |
| 1143 | &cropped_height, &out_width, &out_height)); |
| 1144 | EXPECT_EQ(360, cropped_width); |
| 1145 | EXPECT_EQ(640, cropped_height); |
| 1146 | EXPECT_EQ(360, out_width); |
| 1147 | EXPECT_EQ(640, out_height); |
| 1148 | } |
| 1149 | |
| 1150 | // Force output to be 9:16, even for landscape input. |
| 1151 | TEST(VideoAdapterTestMultipleOrientation, TestForcePortrait) { |
| 1152 | VideoAdapter video_adapter; |
| 1153 | video_adapter.OnOutputFormatRequest(std::make_pair(360, 640), 640 * 360, |
| 1154 | std::make_pair(360, 640), 360 * 640, 30); |
| 1155 | |
| 1156 | int cropped_width; |
| 1157 | int cropped_height; |
| 1158 | int out_width; |
| 1159 | int out_height; |
| 1160 | EXPECT_TRUE(video_adapter.AdaptFrameResolution( |
| 1161 | /* in_width= */ 640, /* in_height= */ 480, /* in_timestamp_ns= */ 0, |
| 1162 | &cropped_width, &cropped_height, &out_width, &out_height)); |
| 1163 | EXPECT_EQ(270, cropped_width); |
| 1164 | EXPECT_EQ(480, cropped_height); |
| 1165 | EXPECT_EQ(270, out_width); |
| 1166 | EXPECT_EQ(480, out_height); |
| 1167 | |
| 1168 | EXPECT_TRUE(video_adapter.AdaptFrameResolution( |
| 1169 | /* in_width= */ 480, /* in_height= */ 640, |
| 1170 | /* in_timestamp_ns= */ rtc::kNumNanosecsPerSec / 30, &cropped_width, |
| 1171 | &cropped_height, &out_width, &out_height)); |
| 1172 | EXPECT_EQ(360, cropped_width); |
| 1173 | EXPECT_EQ(640, cropped_height); |
| 1174 | EXPECT_EQ(360, out_width); |
| 1175 | EXPECT_EQ(640, out_height); |
| 1176 | } |
| 1177 | |
Åsa Persson | 3f7e0ed | 2019-10-18 15:03:13 +0200 | [diff] [blame] | 1178 | TEST_P(VideoAdapterTest, AdaptResolutionInSteps) { |
| 1179 | const int kWidth = 1280; |
| 1180 | const int kHeight = 720; |
| 1181 | OnOutputFormatRequest(kWidth, kHeight, absl::nullopt); // 16:9 aspect. |
| 1182 | |
| 1183 | // Scale factors: 3/4, 2/3, 3/4, 2/3, ... |
| 1184 | // Scale : 3/4, 1/2, 3/8, 1/4, 3/16, 1/8. |
| 1185 | const int kExpectedWidths[] = {960, 640, 480, 320, 240, 160}; |
| 1186 | const int kExpectedHeights[] = {540, 360, 270, 180, 135, 90}; |
| 1187 | |
| 1188 | int request_width = kWidth; |
| 1189 | int request_height = kHeight; |
| 1190 | |
| 1191 | for (size_t i = 0; i < arraysize(kExpectedWidths); ++i) { |
| 1192 | // Adapt down one step. |
| 1193 | adapter_.OnResolutionFramerateRequest(absl::nullopt, |
| 1194 | request_width * request_height - 1, |
| 1195 | std::numeric_limits<int>::max()); |
| 1196 | EXPECT_TRUE(adapter_.AdaptFrameResolution(kWidth, kHeight, 0, |
| 1197 | &cropped_width_, &cropped_height_, |
| 1198 | &out_width_, &out_height_)); |
| 1199 | EXPECT_EQ(kExpectedWidths[i], out_width_); |
| 1200 | EXPECT_EQ(kExpectedHeights[i], out_height_); |
| 1201 | request_width = out_width_; |
| 1202 | request_height = out_height_; |
| 1203 | } |
| 1204 | } |
| 1205 | |
| 1206 | // Scale factors are 3/4, 2/3, 3/4, 2/3, ... (see test above). |
| 1207 | // In VideoAdapterTestVariableStartScale, first scale factor depends on |
| 1208 | // resolution. May start with: |
| 1209 | // - 2/3 (if width/height multiple of 3) or |
| 1210 | // - 2/3, 2/3 (if width/height multiple of 9). |
| 1211 | TEST_P(VideoAdapterTestVariableStartScale, AdaptResolutionInStepsFirst3_4) { |
| 1212 | const int kWidth = 1280; |
| 1213 | const int kHeight = 720; |
| 1214 | OnOutputFormatRequest(kWidth, kHeight, absl::nullopt); // 16:9 aspect. |
| 1215 | |
| 1216 | // Scale factors: 3/4, 2/3, 3/4, 2/3, ... |
| 1217 | // Scale : 3/4, 1/2, 3/8, 1/4, 3/16, 1/8. |
| 1218 | const int kExpectedWidths[] = {960, 640, 480, 320, 240, 160}; |
| 1219 | const int kExpectedHeights[] = {540, 360, 270, 180, 135, 90}; |
| 1220 | |
| 1221 | int request_width = kWidth; |
| 1222 | int request_height = kHeight; |
| 1223 | |
| 1224 | for (size_t i = 0; i < arraysize(kExpectedWidths); ++i) { |
| 1225 | // Adapt down one step. |
| 1226 | adapter_.OnResolutionFramerateRequest(absl::nullopt, |
| 1227 | request_width * request_height - 1, |
| 1228 | std::numeric_limits<int>::max()); |
| 1229 | EXPECT_TRUE(adapter_.AdaptFrameResolution(kWidth, kHeight, 0, |
| 1230 | &cropped_width_, &cropped_height_, |
| 1231 | &out_width_, &out_height_)); |
| 1232 | EXPECT_EQ(kExpectedWidths[i], out_width_); |
| 1233 | EXPECT_EQ(kExpectedHeights[i], out_height_); |
| 1234 | request_width = out_width_; |
| 1235 | request_height = out_height_; |
| 1236 | } |
| 1237 | } |
| 1238 | |
| 1239 | TEST_P(VideoAdapterTestVariableStartScale, AdaptResolutionInStepsFirst2_3) { |
| 1240 | const int kWidth = 1920; |
| 1241 | const int kHeight = 1080; |
| 1242 | OnOutputFormatRequest(kWidth, kHeight, absl::nullopt); // 16:9 aspect. |
| 1243 | |
| 1244 | // Scale factors: 2/3, 3/4, 2/3, 3/4, ... |
| 1245 | // Scale: 2/3, 1/2, 1/3, 1/4, 1/6, 1/8, 1/12. |
| 1246 | const int kExpectedWidths[] = {1280, 960, 640, 480, 320, 240, 160}; |
| 1247 | const int kExpectedHeights[] = {720, 540, 360, 270, 180, 135, 90}; |
| 1248 | |
| 1249 | int request_width = kWidth; |
| 1250 | int request_height = kHeight; |
| 1251 | |
| 1252 | for (size_t i = 0; i < arraysize(kExpectedWidths); ++i) { |
| 1253 | // Adapt down one step. |
| 1254 | adapter_.OnResolutionFramerateRequest(absl::nullopt, |
| 1255 | request_width * request_height - 1, |
| 1256 | std::numeric_limits<int>::max()); |
| 1257 | EXPECT_TRUE(adapter_.AdaptFrameResolution(kWidth, kHeight, 0, |
| 1258 | &cropped_width_, &cropped_height_, |
| 1259 | &out_width_, &out_height_)); |
| 1260 | EXPECT_EQ(kExpectedWidths[i], out_width_); |
| 1261 | EXPECT_EQ(kExpectedHeights[i], out_height_); |
| 1262 | request_width = out_width_; |
| 1263 | request_height = out_height_; |
| 1264 | } |
| 1265 | } |
| 1266 | |
| 1267 | TEST_P(VideoAdapterTestVariableStartScale, AdaptResolutionInStepsFirst2x2_3) { |
| 1268 | const int kWidth = 1440; |
| 1269 | const int kHeight = 1080; |
| 1270 | OnOutputFormatRequest(kWidth, kHeight, absl::nullopt); // 4:3 aspect. |
| 1271 | |
| 1272 | // Scale factors: 2/3, 2/3, 3/4, 2/3, 3/4, ... |
| 1273 | // Scale : 2/3, 4/9, 1/3, 2/9, 1/6, 1/9, 1/12, 1/18, 1/24, 1/36. |
| 1274 | const int kExpectedWidths[] = {960, 640, 480, 320, 240, 160, 120, 80, 60, 40}; |
| 1275 | const int kExpectedHeights[] = {720, 480, 360, 240, 180, 120, 90, 60, 45, 30}; |
| 1276 | |
| 1277 | int request_width = kWidth; |
| 1278 | int request_height = kHeight; |
| 1279 | |
| 1280 | for (size_t i = 0; i < arraysize(kExpectedWidths); ++i) { |
| 1281 | // Adapt down one step. |
| 1282 | adapter_.OnResolutionFramerateRequest(absl::nullopt, |
| 1283 | request_width * request_height - 1, |
| 1284 | std::numeric_limits<int>::max()); |
| 1285 | EXPECT_TRUE(adapter_.AdaptFrameResolution(kWidth, kHeight, 0, |
| 1286 | &cropped_width_, &cropped_height_, |
| 1287 | &out_width_, &out_height_)); |
| 1288 | EXPECT_EQ(kExpectedWidths[i], out_width_); |
| 1289 | EXPECT_EQ(kExpectedHeights[i], out_height_); |
| 1290 | request_width = out_width_; |
| 1291 | request_height = out_height_; |
| 1292 | } |
| 1293 | } |
| 1294 | |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 1295 | } // namespace cricket |