Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(186)

Unified Diff: webrtc/common_audio/smoothing_filter.cc

Issue 2546493002: Update smoothed bitrate. (Closed)
Patch Set: Fix thread safety problem and changed smoothing filter. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/common_audio/smoothing_filter.h ('k') | webrtc/common_audio/smoothing_filter_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/common_audio/smoothing_filter.cc
diff --git a/webrtc/common_audio/smoothing_filter.cc b/webrtc/common_audio/smoothing_filter.cc
index ff79ab8799e9de332ff324152e97c43947837e6a..f3dafaf3f1a6b52acc11ff0fdcc64cd1afc8a1b8 100644
--- a/webrtc/common_audio/smoothing_filter.cc
+++ b/webrtc/common_audio/smoothing_filter.cc
@@ -50,13 +50,19 @@ void SmoothingFilterImpl::AddSample(float sample) {
// float alpha = pow(base, last_update_time_ms_ - now_ms);
// filtered_ = alpha * filtered_ + (1 - alpha) * sample;
filter_.Apply(static_cast<float>(last_sample_time_ms_ - now_ms), sample);
+ last_sample_ = sample;
last_sample_time_ms_ = now_ms;
}
rtc::Optional<float> SmoothingFilterImpl::GetAverage() const {
float value = filter_.filtered();
- return value == rtc::ExpFilter::kValueUndefined ? rtc::Optional<float>()
- : rtc::Optional<float>(value);
+ if (value == rtc::ExpFilter::kValueUndefined)
+ return rtc::Optional<float>();
+ int64_t now_ms = clock_->TimeInMilliseconds();
+ return rtc::Optional<float>(
minyue-webrtc 2016/12/01 11:32:50 I like the idea of making the query of average tim
+ value -
+ (value - last_sample_) *
+ (1 - exp((last_sample_time_ms_ - now_ms) / time_constant_ms_)));
}
void SmoothingFilterImpl::SetTimeConstantMs(int time_constant_ms) {
« no previous file with comments | « webrtc/common_audio/smoothing_filter.h ('k') | webrtc/common_audio/smoothing_filter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698