AEC3: Rounding of estimated call skew

This CL fixes the rounding of the estimated average call skew. Before it
was rounded down (toward INT_MIN). Now it is rounded to the nearest integer.
This avoids unnecessary fluctuations of the estimated call skew (and
unnecessary resets).

Bug: webrtc:9283,chromium:888042
Change-Id: Id5b3c593f812f5f9fd3dcdafb7e388a6ef1ac153
Reviewed-on: https://webrtc-review.googlesource.com/77684
Commit-Queue: Gustaf Ullberg <gustaf@webrtc.org>
Reviewed-by: Per Åhgren <peah@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23338}
This commit is contained in:
Gustaf Ullberg
2018-05-22 08:59:29 +02:00
committed by Commit Bot
parent 5991ac9d22
commit 41c11e4cad
2 changed files with 36 additions and 3 deletions

View File

@ -38,9 +38,9 @@ rtc::Optional<int> SkewEstimator::GetSkewFromCapture() {
sufficient_skew_stored_ = true;
}
return sufficient_skew_stored_
? rtc::Optional<int>(skew_sum_ >> skew_history_size_log2_)
: rtc::nullopt;
const int bias = static_cast<int>(skew_history_.size()) >> 1;
const int average = (skew_sum_ + bias) >> skew_history_size_log2_;
return sufficient_skew_stored_ ? rtc::Optional<int>(average) : rtc::nullopt;
}
} // namespace webrtc

View File

@ -120,5 +120,38 @@ TEST(SkewEstimator, NullEstimate) {
EXPECT_FALSE(skew);
}
}
// Tests that the skew estimator properly rounds the average skew.
TEST(SkewEstimator, SkewRounding) {
constexpr int kNumSkewsLog2 = 4;
constexpr int kNumSkews = 1 << kNumSkewsLog2;
SkewEstimator estimator(kNumSkewsLog2);
rtc::Optional<int> skew;
for (int k = 0; k < kNumSkews; ++k) {
if (k == kNumSkews - 1) {
// Reverse call order once.
skew = estimator.GetSkewFromCapture();
estimator.LogRenderCall();
} else {
// Normal call order.
estimator.LogRenderCall();
skew = estimator.GetSkewFromCapture();
}
}
EXPECT_EQ(*skew, 0);
estimator.Reset();
for (int k = 0; k < kNumSkews; ++k) {
estimator.LogRenderCall();
estimator.LogRenderCall();
estimator.LogRenderCall();
estimator.GetSkewFromCapture();
estimator.GetSkewFromCapture();
skew = estimator.GetSkewFromCapture();
}
EXPECT_EQ(*skew, 1);
}
} // namespace aec3
} // namespace webrtc