Fixes a linear interpolation bad access
Bug: webrtc:353425611 Change-Id: I9c38428d2463d9d76047ad5be84ed57cba9ebb72 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/367981 Commit-Queue: Harald Alvestrand <hta@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Reviewed-by: Erik Språng <sprang@webrtc.org> Cr-Commit-Position: refs/heads/main@{#43408}
This commit is contained in:
parent
9ab2ac126d
commit
1dcf202ffe
1
AUTHORS
1
AUTHORS
@ -56,6 +56,7 @@ Frederik Riedel, Frogg GmbH <frederik.riedel@frogg.io>
|
|||||||
Gao Chun <gaochun.dev@gmail.com>
|
Gao Chun <gaochun.dev@gmail.com>
|
||||||
Giji Gangadharan <giji.g@samsung.com>
|
Giji Gangadharan <giji.g@samsung.com>
|
||||||
Graham Yoakum <gyoakum@skobalt.com>
|
Graham Yoakum <gyoakum@skobalt.com>
|
||||||
|
Guillaume Petit <guillaume.petit@shadow.tech>
|
||||||
Gustavo Garcia <gustavogb@gmail.com>
|
Gustavo Garcia <gustavogb@gmail.com>
|
||||||
Hans Knoechel <hans@hans-knoechel.de>
|
Hans Knoechel <hans@hans-knoechel.de>
|
||||||
Helmut Januschka <helmut@januschka.com>
|
Helmut Januschka <helmut@januschka.com>
|
||||||
|
|||||||
@ -144,6 +144,12 @@ EncoderInfoSettings::GetSinglecastBitrateLimitForResolutionWhenQpIsUntrusted(
|
|||||||
return bitrate_limits[interpolation_index];
|
return bitrate_limits[interpolation_index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 0 means our resolution is smaller than the smallest resolution in the list,
|
||||||
|
// we will select smallest data as the return result.
|
||||||
|
if (interpolation_index == 0) {
|
||||||
|
return *bitrate_limits.begin();
|
||||||
|
}
|
||||||
|
|
||||||
// No matching resolution, do a linear interpolate.
|
// No matching resolution, do a linear interpolate.
|
||||||
int lower_pixel_count =
|
int lower_pixel_count =
|
||||||
bitrate_limits[interpolation_index - 1].frame_size_pixels;
|
bitrate_limits[interpolation_index - 1].frame_size_pixels;
|
||||||
|
|||||||
@ -103,4 +103,49 @@ TEST(EncoderSettingsTest, CommonSettingsUsedIfEncoderNameUnspecified) {
|
|||||||
EXPECT_EQ(3u, vp9_settings.requested_resolution_alignment());
|
EXPECT_EQ(3u, vp9_settings.requested_resolution_alignment());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(GetSinglecastBitrateLimitForResolutionWhenQpIsUntrustedTests,
|
||||||
|
LinearInterpolationUnderflow) {
|
||||||
|
std::optional<int> frame_size_pixels = 480 * 360;
|
||||||
|
std::vector<VideoEncoder::ResolutionBitrateLimits> resolution_bitrate_limits(
|
||||||
|
{{1280 * 720, 1500000, 30000, 2500000},
|
||||||
|
{1920 * 1080, 2500000, 30000, 4000000}});
|
||||||
|
|
||||||
|
const auto resolutionBitrateLimit = EncoderInfoSettings::
|
||||||
|
GetSinglecastBitrateLimitForResolutionWhenQpIsUntrusted(
|
||||||
|
frame_size_pixels, resolution_bitrate_limits);
|
||||||
|
EXPECT_TRUE(resolutionBitrateLimit.has_value());
|
||||||
|
EXPECT_EQ(resolutionBitrateLimit.value(), resolution_bitrate_limits.front());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(GetSinglecastBitrateLimitForResolutionWhenQpIsUntrustedTests,
|
||||||
|
LinearInterpolationOverflow) {
|
||||||
|
std::optional<int> frame_size_pixels = 4096 * 2160;
|
||||||
|
std::vector<VideoEncoder::ResolutionBitrateLimits> resolution_bitrate_limits(
|
||||||
|
{{1280 * 720, 1500000, 30000, 2500000},
|
||||||
|
{1920 * 1080, 2500000, 30000, 4000000}});
|
||||||
|
|
||||||
|
const auto resolutionBitrateLimit = EncoderInfoSettings::
|
||||||
|
GetSinglecastBitrateLimitForResolutionWhenQpIsUntrusted(
|
||||||
|
frame_size_pixels, resolution_bitrate_limits);
|
||||||
|
EXPECT_TRUE(resolutionBitrateLimit.has_value());
|
||||||
|
EXPECT_EQ(resolutionBitrateLimit.value(), resolution_bitrate_limits.back());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(GetSinglecastBitrateLimitForResolutionWhenQpIsUntrustedTests,
|
||||||
|
LinearInterpolationExactMatch) {
|
||||||
|
std::optional<int> frame_size_pixels = 1920 * 1080;
|
||||||
|
VideoEncoder::ResolutionBitrateLimits expected_match{1920 * 1080, 2500000,
|
||||||
|
30000, 4000000};
|
||||||
|
std::vector<VideoEncoder::ResolutionBitrateLimits> resolution_bitrate_limits(
|
||||||
|
{{1280 * 720, 1500000, 30000, 2500000},
|
||||||
|
expected_match,
|
||||||
|
{4096 * 2160, 4000000, 30000, 8000000}});
|
||||||
|
|
||||||
|
const auto resolutionBitrateLimit = EncoderInfoSettings::
|
||||||
|
GetSinglecastBitrateLimitForResolutionWhenQpIsUntrusted(
|
||||||
|
frame_size_pixels, resolution_bitrate_limits);
|
||||||
|
EXPECT_TRUE(resolutionBitrateLimit.has_value());
|
||||||
|
EXPECT_EQ(resolutionBitrateLimit.value(), expected_match);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user