2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
11 #include "webrtc/voice_engine/network_predictor.h"
16 NetworkPredictor::NetworkPredictor(Clock* clock)
18 last_loss_rate_update_time_ms_(clock_->TimeInMilliseconds()),
19 loss_rate_filter_(new rtc::ExpFilter(0.9999f)) {
22 void NetworkPredictor::UpdatePacketLossRate(uint8_t loss_rate) {
23 int64_t now_ms = clock_->TimeInMilliseconds();
24 // Update the recursive average filter.
25 loss_rate_filter_->Apply(
26 static_cast<float>(now_ms - last_loss_rate_update_time_ms_),
27 static_cast<float>(loss_rate));
28 last_loss_rate_update_time_ms_ = now_ms;
31 uint8_t NetworkPredictor::GetLossRate() {
32 float value = loss_rate_filter_->filtered();
33 return (value == rtc::ExpFilter::kValueUndefined) ? 0 :
34 static_cast<uint8_t>(value + 0.5);