diff --git a/video/corruption_detection/halton_frame_sampler.cc b/video/corruption_detection/halton_frame_sampler.cc index ea11217d9a..cd88310a10 100644 --- a/video/corruption_detection/halton_frame_sampler.cc +++ b/video/corruption_detection/halton_frame_sampler.cc @@ -173,6 +173,13 @@ std::vector GetSampleValuesForFrame( << std_dev_gaussian_blur << ".\n"; return {}; } + if (scaled_width > i420_frame_buffer->width() || + scaled_height > i420_frame_buffer->height()) { + RTC_LOG(LS_WARNING) + << "Upscaling causes corruption. Therefore, only down-scaling is " + "permissible."; + return {}; + } // Scale the frame to the desired resolution: // 1. Create a new buffer with the desired resolution. diff --git a/video/corruption_detection/halton_frame_sampler_unittest.cc b/video/corruption_detection/halton_frame_sampler_unittest.cc index 747884b9b5..3475c67bf4 100644 --- a/video/corruption_detection/halton_frame_sampler_unittest.cc +++ b/video/corruption_detection/halton_frame_sampler_unittest.cc @@ -157,6 +157,7 @@ TEST(HaltonFrameSamplerTest, FrameIsNotSampledWhenTimestampsAreEqual) { /*is_key_frame=*/false, /*rtp_timestamp=*/0, /*num_samples=*/1), _); } + #endif // GTEST_HAS_DEATH_TEST TEST(HaltonFrameSamplerGaussianFilteringTest, @@ -236,6 +237,18 @@ TEST(HaltonFrameSamplerGaussianFilteringTest, IsEmpty()); } +TEST(HaltonFrameSamplerGaussianFilteringTest, + ShouldReturnEmptyListWhenUpscaling) { + const scoped_refptr kDefaultI420Buffer = + MakeDefaultI420FrameBuffer(); + + EXPECT_THAT(GetSampleValuesForFrame(kDefaultI420Buffer, + MakeDefaultSampleCoordinates(), + /*scaled_width=*/8, /*scaled_height=*/8, + kDefaultStdDevGaussianBlur), + IsEmpty()); +} + TEST(HaltonFrameSamplerGaussianFilteringTest, ShouldReturnGivenValueWhenStdDevZero) { // 4x4 i420 frame data. @@ -337,8 +350,8 @@ TEST(HaltonFrameSamplerGaussianFilteringTest, {.row = 0.8, .column = 0.4}}; // With scaling. - const int kScaledWidth = 10; - const int kScaledHeight = 10; + const int kScaledWidth = 2; + const int kScaledHeight = 2; // No filtering. const double kStdDevGaussianBlur = 0.02; @@ -346,13 +359,13 @@ TEST(HaltonFrameSamplerGaussianFilteringTest, EXPECT_THAT( GetSampleValuesForFrame(kI420Buffer, kSampleCoordinates, kScaledWidth, kScaledHeight, kStdDevGaussianBlur), - ElementsAre(AllOf(Field(&FilteredSample::value, DoubleEq(96.0)), + ElementsAre(AllOf(Field(&FilteredSample::value, DoubleEq(131.0)), Field(&FilteredSample::plane, ImagePlane::kChroma)), - AllOf(Field(&FilteredSample::value, DoubleEq(30.0)), + AllOf(Field(&FilteredSample::value, DoubleEq(35.0)), Field(&FilteredSample::plane, ImagePlane::kChroma)), - AllOf(Field(&FilteredSample::value, DoubleEq(66.0)), + AllOf(Field(&FilteredSample::value, DoubleEq(131.0)), Field(&FilteredSample::plane, ImagePlane::kChroma)), - AllOf(Field(&FilteredSample::value, DoubleNear(127.0, 1.0)), + AllOf(Field(&FilteredSample::value, DoubleEq(98.0)), Field(&FilteredSample::plane, ImagePlane::kLuma)))); }