samplefilt: drop last sample in SPF_DropSamples()

When SPF_DropSamples() is called, don't keep the last sample to be
retrieved by SPF_GetLastSample(). It should be kept only after
filtering.
This commit is contained in:
Miroslav Lichvar 2022-05-11 11:04:52 +02:00
parent 35220aac9d
commit e66f1df89d
2 changed files with 14 additions and 3 deletions

View file

@ -170,11 +170,21 @@ SPF_GetAvgSampleDispersion(SPF_Instance filter)
/* ================================================== */
void
SPF_DropSamples(SPF_Instance filter)
static void
drop_samples(SPF_Instance filter, int keep_last)
{
filter->index = -1;
filter->used = 0;
if (!keep_last)
filter->last = -1;
}
/* ================================================== */
void
SPF_DropSamples(SPF_Instance filter)
{
drop_samples(filter, 0);
}
/* ================================================== */
@ -405,7 +415,7 @@ SPF_GetFilteredSample(SPF_Instance filter, NTP_Sample *sample)
if (!combine_selected_samples(filter, n, sample))
return 0;
SPF_DropSamples(filter);
drop_samples(filter, 1);
return 1;
}

View file

@ -103,6 +103,7 @@ test_unit(void)
} else {
SPF_DropSamples(filter);
TEST_CHECK(filter->last < 0);
}
TEST_CHECK(SPF_GetNumberOfSamples(filter) == 0);