Raw packet loss rate reported by RTP_RTCP module may vary too drastically over time. This CL is to add a filter to the value in VoE before lending it to audio coding module.

The filter is an exponential filter borrowed from video coding module.

The method is written in a new class called PacketLossProtector (not sure if the name is nice), which can be used in the future for more sophisticated logic.

BUG=
R=henrika@webrtc.org, stefan@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/20809004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@6709 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/webrtc/voice_engine/network_predictor_unittest.cc b/webrtc/voice_engine/network_predictor_unittest.cc
new file mode 100644
index 0000000..e399f68
--- /dev/null
+++ b/webrtc/voice_engine/network_predictor_unittest.cc
@@ -0,0 +1,43 @@
+/*
+ *  Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
+ *
+ *  Use of this source code is governed by a BSD-style license
+ *  that can be found in the LICENSE file in the root of the source
+ *  tree. An additional intellectual property rights grant can be found
+ *  in the file PATENTS.  All contributing project authors may
+ *  be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include <math.h>
+
+#include "testing/gtest/include/gtest/gtest.h"
+#include "webrtc/voice_engine/network_predictor.h"
+#include "webrtc/system_wrappers/interface/clock.h"
+
+namespace webrtc {
+namespace voe {
+
+class TestNetworkPredictor : public ::testing::Test {
+ protected:
+  TestNetworkPredictor()
+      : clock_(0),
+        network_predictor_(new NetworkPredictor(&clock_)) {}
+  SimulatedClock clock_;
+  scoped_ptr<NetworkPredictor> network_predictor_;
+};
+
+TEST_F(TestNetworkPredictor, TestPacketLossRateFilter) {
+  // Test initial packet loss rate estimate is 0.
+  EXPECT_EQ(0, network_predictor_->GetLossRate());
+  network_predictor_->UpdatePacketLossRate(32);
+  // First time, no filtering.
+  EXPECT_EQ(32, network_predictor_->GetLossRate());
+  clock_.AdvanceTimeMilliseconds(1000);
+  network_predictor_->UpdatePacketLossRate(40);
+  float exp = pow(0.9999f, 1000);
+  float value = 32.0f * exp + (1 - exp) * 40.0f;
+  EXPECT_EQ(static_cast<uint8_t>(value + 0.5f),
+            network_predictor_->GetLossRate());
+}
+}  // namespace voe
+}  // namespace webrtc