blob: e399f6820f83ab7e6b43cce687820146a04fed4a [file] [log] [blame]
minyue@webrtc.org74aaf292014-07-16 21:28:261/*
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 <math.h>
12
13#include "testing/gtest/include/gtest/gtest.h"
14#include "webrtc/voice_engine/network_predictor.h"
15#include "webrtc/system_wrappers/interface/clock.h"
16
17namespace webrtc {
18namespace voe {
19
20class TestNetworkPredictor : public ::testing::Test {
21 protected:
22 TestNetworkPredictor()
23 : clock_(0),
24 network_predictor_(new NetworkPredictor(&clock_)) {}
25 SimulatedClock clock_;
26 scoped_ptr<NetworkPredictor> network_predictor_;
27};
28
29TEST_F(TestNetworkPredictor, TestPacketLossRateFilter) {
30 // Test initial packet loss rate estimate is 0.
31 EXPECT_EQ(0, network_predictor_->GetLossRate());
32 network_predictor_->UpdatePacketLossRate(32);
33 // First time, no filtering.
34 EXPECT_EQ(32, network_predictor_->GetLossRate());
35 clock_.AdvanceTimeMilliseconds(1000);
36 network_predictor_->UpdatePacketLossRate(40);
37 float exp = pow(0.9999f, 1000);
38 float value = 32.0f * exp + (1 - exp) * 40.0f;
39 EXPECT_EQ(static_cast<uint8_t>(value + 0.5f),
40 network_predictor_->GetLossRate());
41}
42} // namespace voe
43} // namespace webrtc