Compute the scale factor in int_64.

This avoid overflow when handling large input sizes, e.g.2016x1512, or 2592x1944.

Bug: webrtc:15030
Change-Id: I97d5fa163ce0fac4c47f21826656819e652efafe
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300240
Commit-Queue: Ying Wang <yinwa@webrtc.org>
Reviewed-by: Erik Språng <sprang@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#39774}
This commit is contained in:
Ying Wang 2023-04-04 15:56:24 +08:00 committed by Rashad Sookram
parent 3f6d0b3834
commit 5afc53d06b
2 changed files with 13 additions and 1 deletions

View file

@ -12,6 +12,7 @@
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdlib>
#include <limits>
#include <utility>
@ -39,7 +40,8 @@ struct Fraction {
// Determines number of output pixels if both width and height of an input of
// `input_pixels` pixels is scaled with the fraction numerator / denominator.
int scale_pixel_count(int input_pixels) {
return (numerator * numerator * input_pixels) / (denominator * denominator);
return (numerator * numerator * static_cast<int64_t>(input_pixels))
/ (denominator * denominator);
}
};

View file

@ -839,6 +839,16 @@ TEST_P(VideoAdapterTest, RequestAspectRatio) {
EXPECT_EQ(360, cropped_height_);
EXPECT_EQ(640, out_width_);
EXPECT_EQ(360, out_height_);
adapter_.OnOutputFormatRequest(std::make_pair(1280, 720), 1280 * 720 - 1,
absl::nullopt);
EXPECT_TRUE(adapter_.AdaptFrameResolution(2592, 1944, 0, &cropped_width_,
&cropped_height_, &out_width_,
&out_height_));
EXPECT_EQ(2592, cropped_width_);
EXPECT_EQ(1458, cropped_height_);
EXPECT_EQ(1152, out_width_);
EXPECT_EQ(648, out_height_);
}
TEST_P(VideoAdapterTest, RequestAspectRatioWithDifferentOrientation) {