underrun_optimizer_unittest.cc (1521B)
1 /* 2 * Copyright (c) 2021 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 "modules/audio_coding/neteq/underrun_optimizer.h" 12 13 #include <optional> 14 15 #include "api/neteq/tick_timer.h" 16 #include "test/gtest.h" 17 18 namespace webrtc { 19 20 namespace { 21 22 constexpr int kDefaultHistogramQuantile = 1020054733; // 0.95 in Q30. 23 constexpr int kForgetFactor = 32745; // 0.9993 in Q15. 24 25 } // namespace 26 27 TEST(UnderrunOptimizerTest, ResamplePacketDelays) { 28 TickTimer tick_timer; 29 constexpr int kResampleIntervalMs = 500; 30 UnderrunOptimizer underrun_optimizer(&tick_timer, kDefaultHistogramQuantile, 31 kForgetFactor, std::nullopt, 32 kResampleIntervalMs); 33 34 // The histogram should be updated once with the maximum delay observed for 35 // the following sequence of updates. 36 for (int i = 0; i < 500; i += 20) { 37 underrun_optimizer.Update(i); 38 EXPECT_FALSE(underrun_optimizer.GetOptimalDelayMs()); 39 } 40 tick_timer.Increment(kResampleIntervalMs / tick_timer.ms_per_tick() + 1); 41 underrun_optimizer.Update(0); 42 EXPECT_EQ(underrun_optimizer.GetOptimalDelayMs(), 500); 43 } 44 45 } // namespace webrtc