Prevent missing corruption header because of floating point errors.
Sometimes the blurred value gets to be a little above 255 because of floating point errors. This prevents the header from being sent, losing 1 second of information. This can easily be prevented with the changes in this CL. Bug: webrtc:358039777 Change-Id: Ibad1c8f41272260e28fe58557c623e52a6af8294 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/376740 Reviewed-by: Björn Terelius <terelius@webrtc.org> Reviewed-by: Erik Språng <sprang@webrtc.org> Commit-Queue: Emil Vardar (xWF) <vardar@google.com> Cr-Commit-Position: refs/heads/main@{#43906}
This commit is contained in:
parent
5f90dc8afb
commit
ba0d9713ba
@ -103,6 +103,7 @@ rtc_library("halton_frame_sampler") {
|
||||
"../../api/video:video_frame",
|
||||
"../../rtc_base:checks",
|
||||
"../../rtc_base:logging",
|
||||
"../../rtc_base:safe_minmax",
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@ -20,6 +20,7 @@
|
||||
#include "api/video/video_frame_buffer.h"
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/logging.h"
|
||||
#include "rtc_base/numerics/safe_minmax.h"
|
||||
#include "video/corruption_detection/halton_sequence.h"
|
||||
|
||||
namespace webrtc {
|
||||
@ -134,7 +135,9 @@ double GetFilteredElement(int width,
|
||||
total_weight += weight;
|
||||
}
|
||||
}
|
||||
return element_sum / total_weight;
|
||||
|
||||
// Take the rounding errors into consideration.
|
||||
return rtc::SafeClamp(element_sum / total_weight, 0.0, 255.0);
|
||||
}
|
||||
|
||||
std::vector<FilteredSample> GetSampleValuesForFrame(
|
||||
|
||||
@ -145,6 +145,18 @@ TEST(GaussianFilteringTest, ShouldCrashWhenStdDevIsNegative) {
|
||||
_);
|
||||
}
|
||||
|
||||
TEST(GaussianFilteringTest, RoundingErrorsShouldNotHappen) {
|
||||
// These values should force a rounding error.
|
||||
constexpr int kWidth = 128;
|
||||
constexpr int kHeight = 128;
|
||||
constexpr double kStdDev = 40;
|
||||
const std::vector<uint8_t> data(kWidth * kHeight, 255);
|
||||
|
||||
EXPECT_THAT(GetFilteredElement(kWidth, kHeight, kHeight, data.data(),
|
||||
kWidth / 2, kHeight / 2, kStdDev),
|
||||
255);
|
||||
}
|
||||
|
||||
TEST(HaltonFrameSamplerTest, FrameIsNotSampledWhenTimestampsAreEqual) {
|
||||
HaltonFrameSampler halton_frame_sampler;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user