| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 // Unit tests for DelayPeakDetector class. | 11 // Unit tests for DelayPeakDetector class. |
| 12 | 12 |
| 13 #include "webrtc/modules/audio_coding/neteq/delay_peak_detector.h" | 13 #include "webrtc/modules/audio_coding/neteq/delay_peak_detector.h" |
| 14 | 14 |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 16 |
| 17 namespace webrtc { | 17 namespace webrtc { |
| 18 | 18 |
| 19 TEST(DelayPeakDetector, CreateAndDestroy) { | 19 TEST(DelayPeakDetector, CreateAndDestroy) { |
| 20 DelayPeakDetector* detector = new DelayPeakDetector(); | 20 TickTimer tick_timer; |
| 21 DelayPeakDetector* detector = new DelayPeakDetector(&tick_timer); |
| 21 EXPECT_FALSE(detector->peak_found()); | 22 EXPECT_FALSE(detector->peak_found()); |
| 22 delete detector; | 23 delete detector; |
| 23 } | 24 } |
| 24 | 25 |
| 25 TEST(DelayPeakDetector, EmptyHistory) { | 26 TEST(DelayPeakDetector, EmptyHistory) { |
| 26 DelayPeakDetector detector; | 27 TickTimer tick_timer; |
| 28 DelayPeakDetector detector(&tick_timer); |
| 27 EXPECT_EQ(-1, detector.MaxPeakHeight()); | 29 EXPECT_EQ(-1, detector.MaxPeakHeight()); |
| 28 EXPECT_EQ(-1, detector.MaxPeakPeriod()); | 30 EXPECT_EQ(0u, detector.MaxPeakPeriod()); |
| 29 } | 31 } |
| 30 | 32 |
| 31 // Inject a series of packet arrivals into the detector. Three of the packets | 33 // Inject a series of packet arrivals into the detector. Three of the packets |
| 32 // have suffered delays. After the third delay peak, peak-mode is expected to | 34 // have suffered delays. After the third delay peak, peak-mode is expected to |
| 33 // start. This should then continue until it is disengaged due to lack of peaks. | 35 // start. This should then continue until it is disengaged due to lack of peaks. |
| 34 TEST(DelayPeakDetector, TriggerPeakMode) { | 36 TEST(DelayPeakDetector, TriggerPeakMode) { |
| 35 DelayPeakDetector detector; | 37 TickTimer tick_timer; |
| 38 DelayPeakDetector detector(&tick_timer); |
| 36 const int kPacketSizeMs = 30; | 39 const int kPacketSizeMs = 30; |
| 37 detector.SetPacketAudioLength(kPacketSizeMs); | 40 detector.SetPacketAudioLength(kPacketSizeMs); |
| 38 | 41 |
| 39 // Load up normal arrival times; 0 ms, 30 ms, 60 ms, 90 ms, ... | 42 // Load up normal arrival times; 0 ms, 30 ms, 60 ms, 90 ms, ... |
| 40 const int kNumPackets = 1000; | 43 const int kNumPackets = 1000; |
| 41 int arrival_times_ms[kNumPackets]; | 44 int arrival_times_ms[kNumPackets]; |
| 42 for (int i = 0; i < kNumPackets; ++i) { | 45 for (int i = 0; i < kNumPackets; ++i) { |
| 43 arrival_times_ms[i] = i * kPacketSizeMs; | 46 arrival_times_ms[i] = i * kPacketSizeMs; |
| 44 } | 47 } |
| 45 | 48 |
| 46 // Delay three packets. | 49 // Delay three packets. |
| 47 const int kPeakDelayMs = 100; | 50 const int kPeakDelayMs = 100; |
| 48 // First delay peak. | 51 // First delay peak. |
| 49 arrival_times_ms[100] += kPeakDelayMs; | 52 arrival_times_ms[100] += kPeakDelayMs; |
| 50 // Second delay peak. | 53 // Second delay peak. |
| 51 arrival_times_ms[200] += kPeakDelayMs; | 54 arrival_times_ms[200] += kPeakDelayMs; |
| 52 // Third delay peak. Trigger peak-mode after this packet. | 55 // Third delay peak. Trigger peak-mode after this packet. |
| 53 arrival_times_ms[400] += kPeakDelayMs; | 56 arrival_times_ms[400] += kPeakDelayMs; |
| 54 // The second peak period is the longest, 200 packets. | 57 // The second peak period is the longest, 200 packets. |
| 55 const int kWorstPeakPeriod = 200 * kPacketSizeMs; | 58 const uint64_t kWorstPeakPeriod = 200 * kPacketSizeMs; |
| 56 int peak_mode_start_ms = arrival_times_ms[400]; | 59 int peak_mode_start_ms = arrival_times_ms[400]; |
| 57 // Expect to disengage after no peaks are observed for two period times. | 60 // Expect to disengage after no peaks are observed for two period times. |
| 58 int peak_mode_end_ms = peak_mode_start_ms + 2 * kWorstPeakPeriod; | 61 int peak_mode_end_ms = peak_mode_start_ms + 2 * kWorstPeakPeriod; |
| 59 | 62 |
| 60 // Load into detector. | 63 // Load into detector. |
| 61 int time = 0; | 64 int time = 0; |
| 62 int next = 1; // Start with the second packet to get a proper IAT. | 65 int next = 1; // Start with the second packet to get a proper IAT. |
| 63 while (next < kNumPackets) { | 66 while (next < kNumPackets) { |
| 64 while (next < kNumPackets && arrival_times_ms[next] <= time) { | 67 while (next < kNumPackets && arrival_times_ms[next] <= time) { |
| 65 int iat_packets = (arrival_times_ms[next] - arrival_times_ms[next - 1]) / | 68 int iat_packets = (arrival_times_ms[next] - arrival_times_ms[next - 1]) / |
| 66 kPacketSizeMs; | 69 kPacketSizeMs; |
| 67 const int kTargetBufferLevel = 1; // Define peaks to be iat > 2. | 70 const int kTargetBufferLevel = 1; // Define peaks to be iat > 2. |
| 68 if (time < peak_mode_start_ms || time > peak_mode_end_ms) { | 71 if (time < peak_mode_start_ms || time > peak_mode_end_ms) { |
| 69 EXPECT_FALSE(detector.Update(iat_packets, kTargetBufferLevel)); | 72 EXPECT_FALSE(detector.Update(iat_packets, kTargetBufferLevel)); |
| 70 } else { | 73 } else { |
| 71 EXPECT_TRUE(detector.Update(iat_packets, kTargetBufferLevel)); | 74 EXPECT_TRUE(detector.Update(iat_packets, kTargetBufferLevel)); |
| 72 EXPECT_EQ(kWorstPeakPeriod, detector.MaxPeakPeriod()); | 75 EXPECT_EQ(kWorstPeakPeriod, detector.MaxPeakPeriod()); |
| 73 EXPECT_EQ(kPeakDelayMs / kPacketSizeMs + 1, detector.MaxPeakHeight()); | 76 EXPECT_EQ(kPeakDelayMs / kPacketSizeMs + 1, detector.MaxPeakHeight()); |
| 74 } | 77 } |
| 75 ++next; | 78 ++next; |
| 76 } | 79 } |
| 77 detector.IncrementCounter(10); | 80 tick_timer.Increment(); |
| 78 time += 10; // Increase time 10 ms. | 81 time += 10; // Increase time 10 ms. |
| 79 } | 82 } |
| 80 } | 83 } |
| 81 | 84 |
| 82 // Same test as TriggerPeakMode, but with base target buffer level increased to | 85 // Same test as TriggerPeakMode, but with base target buffer level increased to |
| 83 // 2, in order to raise the bar for delay peaks to inter-arrival times > 4. | 86 // 2, in order to raise the bar for delay peaks to inter-arrival times > 4. |
| 84 // The delay pattern has peaks with delay = 3, thus should not trigger. | 87 // The delay pattern has peaks with delay = 3, thus should not trigger. |
| 85 TEST(DelayPeakDetector, DoNotTriggerPeakMode) { | 88 TEST(DelayPeakDetector, DoNotTriggerPeakMode) { |
| 86 DelayPeakDetector detector; | 89 TickTimer tick_timer; |
| 90 DelayPeakDetector detector(&tick_timer); |
| 87 const int kPacketSizeMs = 30; | 91 const int kPacketSizeMs = 30; |
| 88 detector.SetPacketAudioLength(kPacketSizeMs); | 92 detector.SetPacketAudioLength(kPacketSizeMs); |
| 89 | 93 |
| 90 // Load up normal arrival times; 0 ms, 30 ms, 60 ms, 90 ms, ... | 94 // Load up normal arrival times; 0 ms, 30 ms, 60 ms, 90 ms, ... |
| 91 const int kNumPackets = 1000; | 95 const int kNumPackets = 1000; |
| 92 int arrival_times_ms[kNumPackets]; | 96 int arrival_times_ms[kNumPackets]; |
| 93 for (int i = 0; i < kNumPackets; ++i) { | 97 for (int i = 0; i < kNumPackets; ++i) { |
| 94 arrival_times_ms[i] = i * kPacketSizeMs; | 98 arrival_times_ms[i] = i * kPacketSizeMs; |
| 95 } | 99 } |
| 96 | 100 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 107 int time = 0; | 111 int time = 0; |
| 108 int next = 1; // Start with the second packet to get a proper IAT. | 112 int next = 1; // Start with the second packet to get a proper IAT. |
| 109 while (next < kNumPackets) { | 113 while (next < kNumPackets) { |
| 110 while (next < kNumPackets && arrival_times_ms[next] <= time) { | 114 while (next < kNumPackets && arrival_times_ms[next] <= time) { |
| 111 int iat_packets = (arrival_times_ms[next] - arrival_times_ms[next - 1]) / | 115 int iat_packets = (arrival_times_ms[next] - arrival_times_ms[next - 1]) / |
| 112 kPacketSizeMs; | 116 kPacketSizeMs; |
| 113 const int kTargetBufferLevel = 2; // Define peaks to be iat > 4. | 117 const int kTargetBufferLevel = 2; // Define peaks to be iat > 4. |
| 114 EXPECT_FALSE(detector.Update(iat_packets, kTargetBufferLevel)); | 118 EXPECT_FALSE(detector.Update(iat_packets, kTargetBufferLevel)); |
| 115 ++next; | 119 ++next; |
| 116 } | 120 } |
| 117 detector.IncrementCounter(10); | 121 tick_timer.Increment(); |
| 118 time += 10; // Increase time 10 ms. | 122 time += 10; // Increase time 10 ms. |
| 119 } | 123 } |
| 120 } | 124 } |
| 121 } // namespace webrtc | 125 } // namespace webrtc |
| OLD | NEW |