OLD | NEW |
| (Empty) |
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 uint8_t NetworkPredictor::GetLossRate() { | |
23 float value = loss_rate_filter_->filtered(); | |
24 return (value == rtc::ExpFilter::kValueUndefined) ? 0 : | |
25 static_cast<uint8_t>(value + 0.5); | |
26 } | |
27 | |
28 void NetworkPredictor::UpdatePacketLossRate(uint8_t loss_rate) { | |
29 int64_t now_ms = clock_->TimeInMilliseconds(); | |
30 // Update the recursive average filter. | |
31 loss_rate_filter_->Apply( | |
32 static_cast<float>(now_ms - last_loss_rate_update_time_ms_), | |
33 static_cast<float>(loss_rate)); | |
34 last_loss_rate_update_time_ms_ = now_ms; | |
35 } | |
36 | |
37 } // namespace voe | |
38 } // namespace webrtc | |
OLD | NEW |