Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / webrtc / voice_engine / network_predictor.cc
1 /*
2  *  Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
3  *
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.
9  */
10
11 #include "webrtc/voice_engine/network_predictor.h"
12
13 namespace webrtc {
14 namespace voe {
15
16 NetworkPredictor::NetworkPredictor(Clock* clock)
17     : clock_(clock),
18       last_loss_rate_update_time_ms_(clock_->TimeInMilliseconds()),
19       loss_rate_filter_(new rtc::ExpFilter(0.9999f)) {
20 }
21
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;
29 }
30
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);
35 }
36 }  // namespace voe
37 }  // namespace webrtc