Added experiment to improve handling of frame length changes in NetEq.
The field trial effects two things: after a frame length change the IAT
histogram is scaled to prevent an immediate change in target buffer
level. Also, the peak history in the delay peak detector is cleared,
because the size of the peaks is stored in number of packets (which
will be incorrect after a frame length change).
Bug: webrtc:8381
Change-Id: I214b990f6e5959b655b6542884a7f75da181a0d8
Reviewed-on: https://webrtc-review.googlesource.com/8101
Reviewed-by: Henrik Lundin <henrik.lundin@webrtc.org>
Commit-Queue: Ivo Creusen <ivoc@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#20284}
diff --git a/modules/audio_coding/neteq/delay_manager_unittest.cc b/modules/audio_coding/neteq/delay_manager_unittest.cc
index 6bdbc38..6dad4db 100644
--- a/modules/audio_coding/neteq/delay_manager_unittest.cc
+++ b/modules/audio_coding/neteq/delay_manager_unittest.cc
@@ -335,4 +335,80 @@
EXPECT_FALSE(dm_->SetMaximumDelay(60));
}
+// Test if the histogram is stretched correctly if the packet size is decreased.
+TEST(DelayManagerIATScalingTest, StretchTest) {
+ using IATVector = DelayManager::IATVector;
+ // Test a straightforward 60ms to 20ms change.
+ IATVector iat = {12, 0, 0, 0, 0, 0};
+ IATVector expected_result = {4, 4, 4, 0, 0, 0};
+ IATVector stretched_iat = DelayManager::ScaleHistogram(iat, 60, 20);
+ EXPECT_EQ(stretched_iat, expected_result);
+
+ // Test an example where the last bin in the stretched histogram should
+ // contain the sum of the elements that don't fit into the new histogram.
+ iat = {18, 15, 12, 9, 6, 3, 0};
+ expected_result = {6, 6, 6, 5, 5, 5, 30};
+ stretched_iat = DelayManager::ScaleHistogram(iat, 60, 20);
+ EXPECT_EQ(stretched_iat, expected_result);
+
+ // Test a 120ms to 60ms change.
+ iat = {18, 16, 14, 4, 0};
+ expected_result = {9, 9, 8, 8, 18};
+ stretched_iat = DelayManager::ScaleHistogram(iat, 120, 60);
+ EXPECT_EQ(stretched_iat, expected_result);
+
+ // Test a 120ms to 20ms change.
+ iat = {19, 12, 0, 0, 0, 0, 0, 0};
+ expected_result = {3, 3, 3, 3, 3, 3, 2, 11};
+ stretched_iat = DelayManager::ScaleHistogram(iat, 120, 20);
+ EXPECT_EQ(stretched_iat, expected_result);
+
+ // Test a 70ms to 40ms change.
+ iat = {13, 7, 5, 3, 1, 5, 12, 11, 3, 0, 0, 0};
+ expected_result = {7, 5, 5, 3, 3, 2, 2, 1, 2, 2, 6, 22};
+ stretched_iat = DelayManager::ScaleHistogram(iat, 70, 40);
+ EXPECT_EQ(stretched_iat, expected_result);
+
+ // Test a 30ms to 20ms change.
+ iat = {13, 7, 5, 3, 1, 5, 12, 11, 3, 0, 0, 0};
+ expected_result = {8, 6, 6, 3, 2, 2, 1, 3, 3, 8, 7, 11};
+ stretched_iat = DelayManager::ScaleHistogram(iat, 30, 20);
+ EXPECT_EQ(stretched_iat, expected_result);
+}
+
+// Test if the histogram is compressed correctly if the packet size is
+// increased.
+TEST(DelayManagerIATScalingTest, CompressionTest) {
+ using IATVector = DelayManager::IATVector;
+ // Test a 20 to 60 ms change.
+ IATVector iat = {12, 11, 10, 3, 2, 1};
+ IATVector expected_result = {33, 6, 0, 0, 0, 0};
+ IATVector compressed_iat = DelayManager::ScaleHistogram(iat, 20, 60);
+ EXPECT_EQ(compressed_iat, expected_result);
+
+ // Test a 60ms to 120ms change.
+ iat = {18, 16, 14, 4, 1};
+ expected_result = {34, 18, 1, 0, 0};
+ compressed_iat = DelayManager::ScaleHistogram(iat, 60, 120);
+ EXPECT_EQ(compressed_iat, expected_result);
+
+ // Test a 20ms to 120ms change.
+ iat = {18, 12, 5, 4, 4, 3, 5, 1};
+ expected_result = {46, 6, 0, 0, 0, 0, 0, 0};
+ compressed_iat = DelayManager::ScaleHistogram(iat, 20, 120);
+ EXPECT_EQ(compressed_iat, expected_result);
+
+ // Test a 70ms to 80ms change.
+ iat = {13, 7, 5, 3, 1, 5, 12, 11, 3};
+ expected_result = {11, 8, 6, 2, 5, 12, 13, 3, 0};
+ compressed_iat = DelayManager::ScaleHistogram(iat, 70, 80);
+ EXPECT_EQ(compressed_iat, expected_result);
+
+ // Test a 50ms to 110ms change.
+ iat = {13, 7, 5, 3, 1, 5, 12, 11, 3};
+ expected_result = {18, 8, 16, 16, 2, 0, 0, 0, 0};
+ compressed_iat = DelayManager::ScaleHistogram(iat, 50, 110);
+ EXPECT_EQ(compressed_iat, expected_result);
+}
+
} // namespace webrtc