Fix issue where video scaling gets stuck at low resolution
This CL fixes issue 7211 as well as adding a test that would have
caught the issue.
BUG=webrtc:7211,webrtc:6850,b/35471214
R=sprang@webrtc.org
TBR=kthelgason, sprang
Review-Url: https://codereview.webrtc.org/2713683002 .
Cr-Commit-Position: refs/heads/master@{#16778}
diff --git a/webrtc/media/base/videoadapter.cc b/webrtc/media/base/videoadapter.cc
index 660df8a..589be63 100644
--- a/webrtc/media/base/videoadapter.cc
+++ b/webrtc/media/base/videoadapter.cc
@@ -60,7 +60,7 @@
// The minimum (absolute) difference between the number of output pixels and
// the target pixel count.
int min_pixel_diff = std::numeric_limits<int>::max();
- if (input_pixels < max_pixels) {
+ if (input_pixels <= max_pixels) {
// Start condition for 1/1 case, if it is less than max.
min_pixel_diff = std::abs(input_pixels - target_pixels);
}
diff --git a/webrtc/media/base/videoadapter_unittest.cc b/webrtc/media/base/videoadapter_unittest.cc
index 0bfb6c6..6ec90d8 100644
--- a/webrtc/media/base/videoadapter_unittest.cc
+++ b/webrtc/media/base/videoadapter_unittest.cc
@@ -1016,4 +1016,17 @@
&out_width_, &out_height_));
}
+// Test that we will adapt to max given a target pixel count close to max.
+TEST_F(VideoAdapterTest, TestAdaptToMax) {
+ adapter_.OnOutputFormatRequest(VideoFormat(640, 360, 0, FOURCC_I420));
+ adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 - 1) /* target */,
+ rtc::Optional<int>());
+
+ EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 360, 0, &cropped_width_,
+ &cropped_height_, &out_width_,
+ &out_height_));
+ EXPECT_EQ(640, out_width_);
+ EXPECT_EQ(360, out_height_);
+}
+
} // namespace cricket