Jakob Ivarsson | 74158ff | 2021-09-07 14:24:56 +0200 | [diff] [blame] | 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 "test/gtest.h" |
| 14 | |
| 15 | namespace webrtc { |
| 16 | |
| 17 | namespace { |
| 18 | |
| 19 | constexpr int kDefaultHistogramQuantile = 1020054733; // 0.95 in Q30. |
| 20 | constexpr int kForgetFactor = 32745; // 0.9993 in Q15. |
| 21 | |
| 22 | } // namespace |
| 23 | |
| 24 | TEST(UnderrunOptimizerTest, ResamplePacketDelays) { |
| 25 | TickTimer tick_timer; |
| 26 | constexpr int kResampleIntervalMs = 500; |
| 27 | UnderrunOptimizer underrun_optimizer(&tick_timer, kDefaultHistogramQuantile, |
| 28 | kForgetFactor, absl::nullopt, |
| 29 | kResampleIntervalMs); |
| 30 | |
| 31 | // The histogram should be updated once with the maximum delay observed for |
| 32 | // the following sequence of updates. |
| 33 | for (int i = 0; i < 500; i += 20) { |
| 34 | underrun_optimizer.Update(i); |
| 35 | EXPECT_FALSE(underrun_optimizer.GetOptimalDelayMs()); |
| 36 | } |
| 37 | tick_timer.Increment(kResampleIntervalMs / tick_timer.ms_per_tick() + 1); |
| 38 | underrun_optimizer.Update(0); |
| 39 | EXPECT_EQ(underrun_optimizer.GetOptimalDelayMs(), 500); |
| 40 | } |
| 41 | |
| 42 | } // namespace webrtc |