Number of samples need to be more than 0 when calculating corruption score.
Bug: webrtc:358039777 Change-Id: I28597185731ba3d9485103f7c24813f2bdd7110a Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/363120 Reviewed-by: Fanny Linderborg <linderborg@webrtc.org> Reviewed-by: Åsa Persson <asapersson@webrtc.org> Commit-Queue: Emil Vardar (xWF) <vardar@google.com> Cr-Commit-Position: refs/heads/main@{#43075}
This commit is contained in:
parent
37458ce40a
commit
965f134b2b
@ -43,13 +43,6 @@ double CorruptionClassifier::CalculateCorruptionProbablility(
|
|||||||
rtc::ArrayView<const FilteredSample> filtered_compressed_samples,
|
rtc::ArrayView<const FilteredSample> filtered_compressed_samples,
|
||||||
int luma_threshold,
|
int luma_threshold,
|
||||||
int chroma_threshold) const {
|
int chroma_threshold) const {
|
||||||
RTC_DCHECK_GT(luma_threshold, 0) << "Luma threshold must be positive.";
|
|
||||||
RTC_DCHECK_GT(chroma_threshold, 0) << "Chroma threshold must be positive.";
|
|
||||||
RTC_DCHECK_EQ(filtered_original_samples.size(),
|
|
||||||
filtered_compressed_samples.size())
|
|
||||||
<< "The original and compressed frame have a different amount of "
|
|
||||||
"filtered samples.";
|
|
||||||
|
|
||||||
double loss = GetScore(filtered_original_samples, filtered_compressed_samples,
|
double loss = GetScore(filtered_original_samples, filtered_compressed_samples,
|
||||||
luma_threshold, chroma_threshold);
|
luma_threshold, chroma_threshold);
|
||||||
|
|
||||||
@ -78,8 +71,13 @@ double CorruptionClassifier::GetScore(
|
|||||||
rtc::ArrayView<const FilteredSample> filtered_compressed_samples,
|
rtc::ArrayView<const FilteredSample> filtered_compressed_samples,
|
||||||
int luma_threshold,
|
int luma_threshold,
|
||||||
int chroma_threshold) const {
|
int chroma_threshold) const {
|
||||||
|
RTC_DCHECK_GE(luma_threshold, 0);
|
||||||
|
RTC_DCHECK_GE(chroma_threshold, 0);
|
||||||
RTC_CHECK_EQ(filtered_original_samples.size(),
|
RTC_CHECK_EQ(filtered_original_samples.size(),
|
||||||
filtered_compressed_samples.size());
|
filtered_compressed_samples.size())
|
||||||
|
<< "The original and compressed frame have different amounts of "
|
||||||
|
"filtered samples.";
|
||||||
|
RTC_CHECK_GT(filtered_original_samples.size(), 0);
|
||||||
const int num_samples = filtered_original_samples.size();
|
const int num_samples = filtered_original_samples.size();
|
||||||
double sum = 0.0;
|
double sum = 0.0;
|
||||||
for (int i = 0; i < num_samples; ++i) {
|
for (int i = 0; i < num_samples; ++i) {
|
||||||
|
|||||||
@ -20,6 +20,10 @@ namespace webrtc {
|
|||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
using ::testing::DoubleNear;
|
using ::testing::DoubleNear;
|
||||||
|
#if GTEST_HAS_DEATH_TEST
|
||||||
|
using ::testing::_;
|
||||||
|
using ::testing::HasSubstr;
|
||||||
|
#endif // GTEST_HAS_DEATH_TEST
|
||||||
|
|
||||||
constexpr int kLumaThreshold = 3;
|
constexpr int kLumaThreshold = 3;
|
||||||
constexpr int kChromaThreshold = 2;
|
constexpr int kChromaThreshold = 2;
|
||||||
@ -56,6 +60,27 @@ std::vector<FilteredSample> GetCompressedSampleValues(
|
|||||||
.plane = ImagePlane::kChroma}};
|
.plane = ImagePlane::kChroma}};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if GTEST_HAS_DEATH_TEST
|
||||||
|
TEST(CorruptionClassifierTest, EmptySamplesShouldResultInDeath) {
|
||||||
|
CorruptionClassifier corruption_classifier(kScaleFactor);
|
||||||
|
EXPECT_DEATH(corruption_classifier.CalculateCorruptionProbablility(
|
||||||
|
{}, {}, kLumaThreshold, kChromaThreshold),
|
||||||
|
_);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(CorruptionClassifierTest, DifferentAmountOfSamplesShouldResultInDeath) {
|
||||||
|
CorruptionClassifier corruption_classifier(kScaleFactor);
|
||||||
|
const std::vector<FilteredSample> filtered_compressed_samples = {
|
||||||
|
{.value = 1.0, .plane = ImagePlane::kLuma}};
|
||||||
|
|
||||||
|
EXPECT_DEATH(corruption_classifier.CalculateCorruptionProbablility(
|
||||||
|
kFilteredOriginalSampleValues, filtered_compressed_samples,
|
||||||
|
kLumaThreshold, kChromaThreshold),
|
||||||
|
HasSubstr("The original and compressed frame have different "
|
||||||
|
"amounts of filtered samples."));
|
||||||
|
}
|
||||||
|
#endif // GTEST_HAS_DEATH_TEST
|
||||||
|
|
||||||
TEST(CorruptionClassifierTest,
|
TEST(CorruptionClassifierTest,
|
||||||
SameSampleValuesShouldResultInNoCorruptionScalarConfig) {
|
SameSampleValuesShouldResultInNoCorruptionScalarConfig) {
|
||||||
float kIncreaseValue = 0.0;
|
float kIncreaseValue = 0.0;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user