Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(632)

Unified Diff: webrtc/base/rate_statistics_unittest.cc

Issue 1908893003: Improve the behavior when the BWE times out and when we have too little data to determine the incom… (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/base/rate_statistics_unittest.cc
diff --git a/webrtc/base/rate_statistics_unittest.cc b/webrtc/base/rate_statistics_unittest.cc
index 0270253d5e2f919a99f7c627a467c5d86aaad94d..dba6a989ca2d39285a5f7fd5a7dd38ce9859fb92 100644
--- a/webrtc/base/rate_statistics_unittest.cc
+++ b/webrtc/base/rate_statistics_unittest.cc
@@ -8,6 +8,8 @@
* be found in the AUTHORS file in the root of the source tree.
*/
+#include <algorithm>
+
#include "testing/gtest/include/gtest/gtest.h"
#include "webrtc/base/rate_statistics.h"
@@ -26,8 +28,9 @@ TEST_F(RateStatisticsTest, TestStrictMode) {
// Should be initialized to 0.
EXPECT_EQ(0u, stats_.Rate(now_ms));
stats_.Update(1500, now_ms);
- // Expecting 24 kbps given a 500 ms window with one 1500 bytes packet.
- EXPECT_EQ(24000u, stats_.Rate(now_ms));
+ // Expecting 1200 kbps since the window is initially kept small and grows as
+ // we have more data.
+ EXPECT_EQ(12000000u, stats_.Rate(now_ms));
stats_.Reset();
// Expecting 0 after init.
EXPECT_EQ(0u, stats_.Rate(now_ms));
@@ -38,7 +41,7 @@ TEST_F(RateStatisticsTest, TestStrictMode) {
// Approximately 1200 kbps expected. Not exact since when packets
// are removed we will jump 10 ms to the next packet.
if (now_ms > 0 && now_ms % 500 == 0) {
- EXPECT_NEAR(1200000u, stats_.Rate(now_ms), 24000u);
+ EXPECT_NEAR(1200000u, stats_.Rate(now_ms), 22000u);
}
now_ms += 1;
}
@@ -54,25 +57,26 @@ TEST_F(RateStatisticsTest, IncreasingThenDecreasingBitrate) {
// Expecting 0 after init.
uint32_t bitrate = stats_.Rate(now_ms);
EXPECT_EQ(0u, bitrate);
+ uint32_t kExpectedBitrate = 8000000;
perkj_webrtc 2016/04/22 05:24:58 nit: const uint32_t
// 1000 bytes per millisecond until plateau is reached.
+ int prev_error = kExpectedBitrate;
while (++now_ms < 10000) {
stats_.Update(1000, now_ms);
- uint32_t new_bitrate = stats_.Rate(now_ms);
- if (new_bitrate != bitrate) {
- // New bitrate must be higher than previous one.
- EXPECT_GT(new_bitrate, bitrate);
- } else {
- // Plateau reached, 8000 kbps expected.
- EXPECT_NEAR(8000000u, bitrate, 80000u);
- break;
- }
- bitrate = new_bitrate;
+ bitrate = stats_.Rate(now_ms);
+ int error = kExpectedBitrate - bitrate;
+ error = std::abs(error);
+ // Expect the estimation error to decrease as the window is extended.
+ EXPECT_LE(error, prev_error + 1);
+ prev_error = error;
}
+ // Window filled, expect to be close to 8000000.
+ EXPECT_EQ(8000000u, bitrate);
+
// 1000 bytes per millisecond until 10-second mark, 8000 kbps expected.
while (++now_ms < 10000) {
stats_.Update(1000, now_ms);
bitrate = stats_.Rate(now_ms);
- EXPECT_NEAR(8000000u, bitrate, 80000u);
+ EXPECT_EQ(8000000u, bitrate);
}
// Zero bytes per millisecond until 0 is reached.
while (++now_ms < 20000) {
@@ -94,4 +98,33 @@ TEST_F(RateStatisticsTest, IncreasingThenDecreasingBitrate) {
EXPECT_EQ(0u, stats_.Rate(now_ms));
}
}
+
+TEST_F(RateStatisticsTest, ResetAfterSilence) {
+ int64_t now_ms = 0;
+ stats_.Reset();
+ // Expecting 0 after init.
+ uint32_t bitrate = stats_.Rate(now_ms);
+ EXPECT_EQ(0u, bitrate);
+ uint32_t kExpectedBitrate = 8000000;
perkj_webrtc 2016/04/22 05:24:58 dito
+ // 1000 bytes per millisecond until the window has been filled.
+ int prev_error = kExpectedBitrate;
+ while (++now_ms < 10000) {
+ stats_.Update(1000, now_ms);
+ bitrate = stats_.Rate(now_ms);
+ int error = kExpectedBitrate - bitrate;
+ error = std::abs(error);
+ // Expect the estimation error to decrease as the window is extended.
+ EXPECT_LE(error, prev_error + 1);
+ prev_error = error;
+ }
+ // Window filled, expect to be close to 8000000.
+ EXPECT_EQ(8000000u, bitrate);
+
+ now_ms += 501;
sprang_webrtc 2016/04/22 10:36:58 Can we add a named constant for the 500ms window?
+ EXPECT_EQ(0u, stats_.Rate(now_ms));
+ stats_.Update(1000, now_ms);
+ // We expect one sample of 1000 bytes, and that the bitrate is measured over
+ // 2 milliseconds, i.e., 8 * 1000 / 0.002 =
+ EXPECT_EQ(8000000u, stats_.Rate(now_ms));
+}
} // namespace

Powered by Google App Engine
This is Rietveld 408576698