henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2011 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 | |
Ivo Creusen | 3ce44a3 | 2019-10-31 14:38:11 +0100 | [diff] [blame] | 11 | #include "api/neteq/neteq.h" |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 12 | |
pbos@webrtc.org | 3ecc162 | 2014-03-07 15:23:34 +0000 | [diff] [blame] | 13 | #include <math.h> |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 14 | #include <stdlib.h> |
| 15 | #include <string.h> // memset |
| 16 | |
turaj@webrtc.org | 8d1cdaa | 2014-04-11 18:47:55 +0000 | [diff] [blame] | 17 | #include <algorithm> |
kwiberg | 2d0c332 | 2016-02-14 09:28:33 -0800 | [diff] [blame] | 18 | #include <memory> |
turaj@webrtc.org | 78b41a0 | 2013-11-22 20:27:07 +0000 | [diff] [blame] | 19 | #include <set> |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 20 | #include <string> |
| 21 | #include <vector> |
| 22 | |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 23 | #include "absl/flags/flag.h" |
Fredrik Solenberg | bbf21a3 | 2018-04-12 22:44:09 +0200 | [diff] [blame] | 24 | #include "api/audio/audio_frame.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 25 | #include "api/audio_codecs/builtin_audio_decoder_factory.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 26 | #include "modules/audio_coding/codecs/pcm16b/pcm16b.h" |
Yves Gerey | 3a65f39 | 2019-11-11 18:05:42 +0100 | [diff] [blame] | 27 | #include "modules/audio_coding/neteq/test/neteq_decoding_test.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 28 | #include "modules/audio_coding/neteq/tools/audio_loop.h" |
Henrik Lundin | 7687ad5 | 2018-07-02 10:14:46 +0200 | [diff] [blame] | 29 | #include "modules/audio_coding/neteq/tools/neteq_packet_source_input.h" |
| 30 | #include "modules/audio_coding/neteq/tools/neteq_test.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 31 | #include "modules/include/module_common_types_public.h" |
Niels Möller | 53382cb | 2018-11-27 14:05:08 +0100 | [diff] [blame] | 32 | #include "modules/rtp_rtcp/include/rtcp_statistics.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 33 | #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 34 | #include "rtc_base/ignore_wundef.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 35 | #include "rtc_base/message_digest.h" |
Karl Wiberg | e40468b | 2017-11-22 10:42:26 +0100 | [diff] [blame] | 36 | #include "rtc_base/numerics/safe_conversions.h" |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame] | 37 | #include "rtc_base/strings/string_builder.h" |
Niels Möller | a12c42a | 2018-07-25 16:05:48 +0200 | [diff] [blame] | 38 | #include "rtc_base/system/arch.h" |
Henrik Lundin | e9619f8 | 2017-11-27 14:05:27 +0100 | [diff] [blame] | 39 | #include "test/field_trial.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 40 | #include "test/gtest.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 41 | #include "test/testsupport/file_utils.h" |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 42 | |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 43 | ABSL_FLAG(bool, gen_ref, false, "Generate reference files."); |
turaj@webrtc.org | a6101d7 | 2013-10-01 22:01:09 +0000 | [diff] [blame] | 44 | |
kwiberg | 5adaf73 | 2016-10-04 09:33:27 -0700 | [diff] [blame] | 45 | namespace webrtc { |
| 46 | |
Ivo Creusen | f1053ba | 2022-01-31 12:50:29 +0100 | [diff] [blame] | 47 | #if defined(WEBRTC_LINUX) && defined(WEBRTC_ARCH_X86_64) && \ |
| 48 | defined(WEBRTC_NETEQ_UNITTEST_BITEXACT) && \ |
| 49 | (defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX)) && \ |
| 50 | defined(WEBRTC_CODEC_ILBC) |
minyue | 5f026d0 | 2015-12-16 07:36:04 -0800 | [diff] [blame] | 51 | #define MAYBE_TestBitExactness TestBitExactness |
kwiberg | 98ab3a4 | 2015-09-30 21:54:21 -0700 | [diff] [blame] | 52 | #else |
minyue | 5f026d0 | 2015-12-16 07:36:04 -0800 | [diff] [blame] | 53 | #define MAYBE_TestBitExactness DISABLED_TestBitExactness |
kwiberg | 98ab3a4 | 2015-09-30 21:54:21 -0700 | [diff] [blame] | 54 | #endif |
minyue | 5f026d0 | 2015-12-16 07:36:04 -0800 | [diff] [blame] | 55 | TEST_F(NetEqDecodingTest, MAYBE_TestBitExactness) { |
minyue | 49c454e | 2016-01-08 11:30:14 -0800 | [diff] [blame] | 56 | const std::string input_rtp_file = |
| 57 | webrtc::test::ResourcePath("audio_coding/neteq_universal_new", "rtp"); |
henrik.lundin@webrtc.org | 4e4b098 | 2014-08-11 14:48:49 +0000 | [diff] [blame] | 58 | |
Jakob Ivarsson | fa68ac0 | 2021-11-09 12:58:45 +0100 | [diff] [blame] | 59 | const std::string output_checksum = |
Jakob Ivarsson | 01ab7d5 | 2022-05-25 21:06:14 +0200 | [diff] [blame] | 60 | "dee7a10ab92526876a70a85bc48a4906901af3df"; |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 61 | |
Jakob Ivarsson | fa68ac0 | 2021-11-09 12:58:45 +0100 | [diff] [blame] | 62 | const std::string network_stats_checksum = |
Jakob Ivarsson | 01ab7d5 | 2022-05-25 21:06:14 +0200 | [diff] [blame] | 63 | "911dbf5fd97f48d25b8f0967286eb73c9d6f6158"; |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 64 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 65 | DecodeAndCompare(input_rtp_file, output_checksum, network_stats_checksum, |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 66 | absl::GetFlag(FLAGS_gen_ref)); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 67 | } |
| 68 | |
Ivo Creusen | f1053ba | 2022-01-31 12:50:29 +0100 | [diff] [blame] | 69 | #if defined(WEBRTC_LINUX) && defined(WEBRTC_ARCH_X86_64) && \ |
| 70 | defined(WEBRTC_NETEQ_UNITTEST_BITEXACT) && defined(WEBRTC_CODEC_OPUS) |
minyue | 93c08b7 | 2015-12-22 09:57:41 -0800 | [diff] [blame] | 71 | #define MAYBE_TestOpusBitExactness TestOpusBitExactness |
| 72 | #else |
| 73 | #define MAYBE_TestOpusBitExactness DISABLED_TestOpusBitExactness |
| 74 | #endif |
Ivo Creusen | f1053ba | 2022-01-31 12:50:29 +0100 | [diff] [blame] | 75 | TEST_F(NetEqDecodingTest, MAYBE_TestOpusBitExactness) { |
minyue | 93c08b7 | 2015-12-22 09:57:41 -0800 | [diff] [blame] | 76 | const std::string input_rtp_file = |
| 77 | webrtc::test::ResourcePath("audio_coding/neteq_opus", "rtp"); |
minyue | 93c08b7 | 2015-12-22 09:57:41 -0800 | [diff] [blame] | 78 | |
Ivo Creusen | f1053ba | 2022-01-31 12:50:29 +0100 | [diff] [blame] | 79 | // The checksum depends on SSE being enabled, the second part is the non-SSE |
| 80 | // checksum. |
| 81 | const std::string output_checksum = |
landrey | 6f24817 | 2022-07-27 14:19:30 +0000 | [diff] [blame] | 82 | "fec6827bb9ee0b21770bbbb4a3a6f8823bf537dc|" |
Jakob Ivarsson | ca101e6 | 2022-04-04 21:42:55 +0200 | [diff] [blame] | 83 | "c5eb0a8fcf7e8255a40f821cb815e1096619efeb"; |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 84 | |
Yves Gerey | 75e2290 | 2019-09-06 03:07:55 +0200 | [diff] [blame] | 85 | const std::string network_stats_checksum = |
landrey | 5505bb1 | 2022-07-27 21:03:05 +0000 | [diff] [blame^] | 86 | "3d043e47e5f4bb81d37e7bce8c44bf802965c853|" |
landrey | 6f24817 | 2022-07-27 14:19:30 +0000 | [diff] [blame] | 87 | "076662525572dba753b11578330bd491923f7f5e"; |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 88 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 89 | DecodeAndCompare(input_rtp_file, output_checksum, network_stats_checksum, |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 90 | absl::GetFlag(FLAGS_gen_ref)); |
minyue | 93c08b7 | 2015-12-22 09:57:41 -0800 | [diff] [blame] | 91 | } |
| 92 | |
Ivo Creusen | f1053ba | 2022-01-31 12:50:29 +0100 | [diff] [blame] | 93 | #if defined(WEBRTC_LINUX) && defined(WEBRTC_ARCH_X86_64) && \ |
| 94 | defined(WEBRTC_NETEQ_UNITTEST_BITEXACT) && defined(WEBRTC_CODEC_OPUS) |
| 95 | #define MAYBE_TestOpusDtxBitExactness TestOpusDtxBitExactness |
| 96 | #else |
| 97 | #define MAYBE_TestOpusDtxBitExactness DISABLED_TestOpusDtxBitExactness |
| 98 | #endif |
| 99 | TEST_F(NetEqDecodingTest, MAYBE_TestOpusDtxBitExactness) { |
Henrik Lundin | e9619f8 | 2017-11-27 14:05:27 +0100 | [diff] [blame] | 100 | const std::string input_rtp_file = |
| 101 | webrtc::test::ResourcePath("audio_coding/neteq_opus_dtx", "rtp"); |
| 102 | |
Ivo Creusen | f1053ba | 2022-01-31 12:50:29 +0100 | [diff] [blame] | 103 | // The checksum depends on SSE being enabled, the second part is the non-SSE |
| 104 | // checksum. |
| 105 | const std::string output_checksum = |
landrey | 6f24817 | 2022-07-27 14:19:30 +0000 | [diff] [blame] | 106 | "b3c4899eab5378ef5e54f2302948872149f6ad5e|" |
Ivo Creusen | f1053ba | 2022-01-31 12:50:29 +0100 | [diff] [blame] | 107 | "e97e32a77355e7ce46a2dc2f43bf1c2805530fcb"; |
Henrik Lundin | e9619f8 | 2017-11-27 14:05:27 +0100 | [diff] [blame] | 108 | |
| 109 | const std::string network_stats_checksum = |
Ivo Creusen | f1053ba | 2022-01-31 12:50:29 +0100 | [diff] [blame] | 110 | "dc8447b9fee1a21fd5d1f4045d62b982a3fb0215"; |
Henrik Lundin | e9619f8 | 2017-11-27 14:05:27 +0100 | [diff] [blame] | 111 | |
Henrik Lundin | e9619f8 | 2017-11-27 14:05:27 +0100 | [diff] [blame] | 112 | DecodeAndCompare(input_rtp_file, output_checksum, network_stats_checksum, |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 113 | absl::GetFlag(FLAGS_gen_ref)); |
Henrik Lundin | e9619f8 | 2017-11-27 14:05:27 +0100 | [diff] [blame] | 114 | } |
| 115 | |
henrik.lundin@webrtc.org | 7cbc4f9 | 2014-10-07 06:37:39 +0000 | [diff] [blame] | 116 | // Use fax mode to avoid time-scaling. This is to simplify the testing of |
| 117 | // packet waiting times in the packet buffer. |
| 118 | class NetEqDecodingTestFaxMode : public NetEqDecodingTest { |
| 119 | protected: |
| 120 | NetEqDecodingTestFaxMode() : NetEqDecodingTest() { |
Henrik Lundin | 7687ad5 | 2018-07-02 10:14:46 +0200 | [diff] [blame] | 121 | config_.for_test_no_time_stretching = true; |
henrik.lundin@webrtc.org | 7cbc4f9 | 2014-10-07 06:37:39 +0000 | [diff] [blame] | 122 | } |
Gustaf Ullberg | b0a0207 | 2017-10-02 12:00:34 +0200 | [diff] [blame] | 123 | void TestJitterBufferDelay(bool apply_packet_loss); |
henrik.lundin@webrtc.org | 7cbc4f9 | 2014-10-07 06:37:39 +0000 | [diff] [blame] | 124 | }; |
| 125 | |
| 126 | TEST_F(NetEqDecodingTestFaxMode, TestFrameWaitingTimeStatistics) { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 127 | // Insert 30 dummy packets at once. Each packet contains 10 ms 16 kHz audio. |
| 128 | size_t num_frames = 30; |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 129 | const size_t kSamples = 10 * 16; |
| 130 | const size_t kPayloadBytes = kSamples * 2; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 131 | for (size_t i = 0; i < num_frames; ++i) { |
kwiberg | ee2bac2 | 2015-11-11 10:34:00 -0800 | [diff] [blame] | 132 | const uint8_t payload[kPayloadBytes] = {0}; |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 133 | RTPHeader rtp_info; |
Mirko Bonadei | a811027 | 2017-10-18 14:22:50 +0200 | [diff] [blame] | 134 | rtp_info.sequenceNumber = rtc::checked_cast<uint16_t>(i); |
| 135 | rtp_info.timestamp = rtc::checked_cast<uint32_t>(i * kSamples); |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 136 | rtp_info.ssrc = 0x1234; // Just an arbitrary SSRC. |
| 137 | rtp_info.payloadType = 94; // PCM16b WB codec. |
| 138 | rtp_info.markerBit = 0; |
Karl Wiberg | 45eb135 | 2019-10-10 14:23:00 +0200 | [diff] [blame] | 139 | ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload)); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 140 | } |
| 141 | // Pull out all data. |
| 142 | for (size_t i = 0; i < num_frames; ++i) { |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 143 | bool muted; |
| 144 | ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 145 | ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 146 | } |
| 147 | |
Henrik Lundin | 1bb8cf8 | 2015-08-25 13:08:04 +0200 | [diff] [blame] | 148 | NetEqNetworkStatistics stats; |
| 149 | EXPECT_EQ(0, neteq_->NetworkStatistics(&stats)); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 150 | // Since all frames are dumped into NetEQ at once, but pulled out with 10 ms |
| 151 | // spacing (per definition), we expect the delay to increase with 10 ms for |
Henrik Lundin | 1bb8cf8 | 2015-08-25 13:08:04 +0200 | [diff] [blame] | 152 | // each packet. Thus, we are calculating the statistics for a series from 10 |
| 153 | // to 300, in steps of 10 ms. |
| 154 | EXPECT_EQ(155, stats.mean_waiting_time_ms); |
| 155 | EXPECT_EQ(155, stats.median_waiting_time_ms); |
| 156 | EXPECT_EQ(10, stats.min_waiting_time_ms); |
| 157 | EXPECT_EQ(300, stats.max_waiting_time_ms); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 158 | |
| 159 | // Check statistics again and make sure it's been reset. |
Henrik Lundin | 1bb8cf8 | 2015-08-25 13:08:04 +0200 | [diff] [blame] | 160 | EXPECT_EQ(0, neteq_->NetworkStatistics(&stats)); |
| 161 | EXPECT_EQ(-1, stats.mean_waiting_time_ms); |
| 162 | EXPECT_EQ(-1, stats.median_waiting_time_ms); |
| 163 | EXPECT_EQ(-1, stats.min_waiting_time_ms); |
| 164 | EXPECT_EQ(-1, stats.max_waiting_time_ms); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 165 | } |
| 166 | |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 167 | |
henrik.lundin@webrtc.org | b4e80e0 | 2014-05-15 07:14:00 +0000 | [diff] [blame] | 168 | TEST_F(NetEqDecodingTest, LongCngWithNegativeClockDrift) { |
henrik.lundin@webrtc.org | fcfc6a9 | 2014-02-13 11:42:28 +0000 | [diff] [blame] | 169 | // Apply a clock drift of -25 ms / s (sender faster than receiver). |
| 170 | const double kDriftFactor = 1000.0 / (1000.0 + 25.0); |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 171 | const double kNetworkFreezeTimeMs = 0.0; |
| 172 | const bool kGetAudioDuringFreezeRecovery = false; |
| 173 | const int kDelayToleranceMs = 20; |
| 174 | const int kMaxTimeToSpeechMs = 100; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 175 | LongCngWithClockDrift(kDriftFactor, kNetworkFreezeTimeMs, |
| 176 | kGetAudioDuringFreezeRecovery, kDelayToleranceMs, |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 177 | kMaxTimeToSpeechMs); |
henrik.lundin@webrtc.org | fcfc6a9 | 2014-02-13 11:42:28 +0000 | [diff] [blame] | 178 | } |
| 179 | |
henrik.lundin@webrtc.org | b4e80e0 | 2014-05-15 07:14:00 +0000 | [diff] [blame] | 180 | TEST_F(NetEqDecodingTest, LongCngWithPositiveClockDrift) { |
henrik.lundin@webrtc.org | fcfc6a9 | 2014-02-13 11:42:28 +0000 | [diff] [blame] | 181 | // Apply a clock drift of +25 ms / s (sender slower than receiver). |
| 182 | const double kDriftFactor = 1000.0 / (1000.0 - 25.0); |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 183 | const double kNetworkFreezeTimeMs = 0.0; |
| 184 | const bool kGetAudioDuringFreezeRecovery = false; |
Jakob Ivarsson | 507f434 | 2019-09-03 13:04:41 +0200 | [diff] [blame] | 185 | const int kDelayToleranceMs = 40; |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 186 | const int kMaxTimeToSpeechMs = 100; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 187 | LongCngWithClockDrift(kDriftFactor, kNetworkFreezeTimeMs, |
| 188 | kGetAudioDuringFreezeRecovery, kDelayToleranceMs, |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 189 | kMaxTimeToSpeechMs); |
| 190 | } |
| 191 | |
henrik.lundin@webrtc.org | b4e80e0 | 2014-05-15 07:14:00 +0000 | [diff] [blame] | 192 | TEST_F(NetEqDecodingTest, LongCngWithNegativeClockDriftNetworkFreeze) { |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 193 | // Apply a clock drift of -25 ms / s (sender faster than receiver). |
| 194 | const double kDriftFactor = 1000.0 / (1000.0 + 25.0); |
| 195 | const double kNetworkFreezeTimeMs = 5000.0; |
| 196 | const bool kGetAudioDuringFreezeRecovery = false; |
Jakob Ivarsson | a36c591 | 2019-06-27 10:12:02 +0200 | [diff] [blame] | 197 | const int kDelayToleranceMs = 60; |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 198 | const int kMaxTimeToSpeechMs = 200; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 199 | LongCngWithClockDrift(kDriftFactor, kNetworkFreezeTimeMs, |
| 200 | kGetAudioDuringFreezeRecovery, kDelayToleranceMs, |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 201 | kMaxTimeToSpeechMs); |
| 202 | } |
| 203 | |
henrik.lundin@webrtc.org | b4e80e0 | 2014-05-15 07:14:00 +0000 | [diff] [blame] | 204 | TEST_F(NetEqDecodingTest, LongCngWithPositiveClockDriftNetworkFreeze) { |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 205 | // Apply a clock drift of +25 ms / s (sender slower than receiver). |
| 206 | const double kDriftFactor = 1000.0 / (1000.0 - 25.0); |
| 207 | const double kNetworkFreezeTimeMs = 5000.0; |
| 208 | const bool kGetAudioDuringFreezeRecovery = false; |
Jakob Ivarsson | 507f434 | 2019-09-03 13:04:41 +0200 | [diff] [blame] | 209 | const int kDelayToleranceMs = 40; |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 210 | const int kMaxTimeToSpeechMs = 100; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 211 | LongCngWithClockDrift(kDriftFactor, kNetworkFreezeTimeMs, |
| 212 | kGetAudioDuringFreezeRecovery, kDelayToleranceMs, |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 213 | kMaxTimeToSpeechMs); |
| 214 | } |
| 215 | |
henrik.lundin@webrtc.org | b4e80e0 | 2014-05-15 07:14:00 +0000 | [diff] [blame] | 216 | TEST_F(NetEqDecodingTest, LongCngWithPositiveClockDriftNetworkFreezeExtraPull) { |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 217 | // Apply a clock drift of +25 ms / s (sender slower than receiver). |
| 218 | const double kDriftFactor = 1000.0 / (1000.0 - 25.0); |
| 219 | const double kNetworkFreezeTimeMs = 5000.0; |
| 220 | const bool kGetAudioDuringFreezeRecovery = true; |
Jakob Ivarsson | 507f434 | 2019-09-03 13:04:41 +0200 | [diff] [blame] | 221 | const int kDelayToleranceMs = 40; |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 222 | const int kMaxTimeToSpeechMs = 100; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 223 | LongCngWithClockDrift(kDriftFactor, kNetworkFreezeTimeMs, |
| 224 | kGetAudioDuringFreezeRecovery, kDelayToleranceMs, |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 225 | kMaxTimeToSpeechMs); |
| 226 | } |
| 227 | |
henrik.lundin@webrtc.org | b4e80e0 | 2014-05-15 07:14:00 +0000 | [diff] [blame] | 228 | TEST_F(NetEqDecodingTest, LongCngWithoutClockDrift) { |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 229 | const double kDriftFactor = 1.0; // No drift. |
| 230 | const double kNetworkFreezeTimeMs = 0.0; |
| 231 | const bool kGetAudioDuringFreezeRecovery = false; |
| 232 | const int kDelayToleranceMs = 10; |
| 233 | const int kMaxTimeToSpeechMs = 50; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 234 | LongCngWithClockDrift(kDriftFactor, kNetworkFreezeTimeMs, |
| 235 | kGetAudioDuringFreezeRecovery, kDelayToleranceMs, |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 236 | kMaxTimeToSpeechMs); |
henrik.lundin@webrtc.org | fcfc6a9 | 2014-02-13 11:42:28 +0000 | [diff] [blame] | 237 | } |
| 238 | |
henrik.lundin@webrtc.org | b4e80e0 | 2014-05-15 07:14:00 +0000 | [diff] [blame] | 239 | TEST_F(NetEqDecodingTest, UnknownPayloadType) { |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 240 | const size_t kPayloadBytes = 100; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 241 | uint8_t payload[kPayloadBytes] = {0}; |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 242 | RTPHeader rtp_info; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 243 | PopulateRtpInfo(0, 0, &rtp_info); |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 244 | rtp_info.payloadType = 1; // Not registered as a decoder. |
Karl Wiberg | 45eb135 | 2019-10-10 14:23:00 +0200 | [diff] [blame] | 245 | EXPECT_EQ(NetEq::kFail, neteq_->InsertPacket(rtp_info, payload)); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 246 | } |
| 247 | |
Peter Boström | e2976c8 | 2016-01-04 22:44:05 +0100 | [diff] [blame] | 248 | #if defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX) |
ivoc | 72c08ed | 2016-01-20 07:26:24 -0800 | [diff] [blame] | 249 | #define MAYBE_DecoderError DecoderError |
| 250 | #else |
| 251 | #define MAYBE_DecoderError DISABLED_DecoderError |
| 252 | #endif |
| 253 | |
Peter Boström | e2976c8 | 2016-01-04 22:44:05 +0100 | [diff] [blame] | 254 | TEST_F(NetEqDecodingTest, MAYBE_DecoderError) { |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 255 | const size_t kPayloadBytes = 100; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 256 | uint8_t payload[kPayloadBytes] = {0}; |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 257 | RTPHeader rtp_info; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 258 | PopulateRtpInfo(0, 0, &rtp_info); |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 259 | rtp_info.payloadType = 103; // iSAC, but the payload is invalid. |
Karl Wiberg | 45eb135 | 2019-10-10 14:23:00 +0200 | [diff] [blame] | 260 | EXPECT_EQ(0, neteq_->InsertPacket(rtp_info, payload)); |
Artem Titov | d00ce74 | 2021-07-28 20:00:17 +0200 | [diff] [blame] | 261 | // Set all of `out_data_` to 1, and verify that it was set to 0 by the call |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 262 | // to GetAudio. |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 263 | int16_t* out_frame_data = out_frame_.mutable_data(); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 264 | for (size_t i = 0; i < AudioFrame::kMaxDataSizeSamples; ++i) { |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 265 | out_frame_data[i] = 1; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 266 | } |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 267 | bool muted; |
| 268 | EXPECT_EQ(NetEq::kFail, neteq_->GetAudio(&out_frame_, &muted)); |
| 269 | ASSERT_FALSE(muted); |
ivoc | 72c08ed | 2016-01-20 07:26:24 -0800 | [diff] [blame] | 270 | |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 271 | // Verify that the first 160 samples are set to 0. |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 272 | static const int kExpectedOutputLength = 160; // 10 ms at 16 kHz sample rate. |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 273 | const int16_t* const_out_frame_data = out_frame_.data(); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 274 | for (int i = 0; i < kExpectedOutputLength; ++i) { |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame] | 275 | rtc::StringBuilder ss; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 276 | ss << "i = " << i; |
| 277 | SCOPED_TRACE(ss.str()); // Print out the parameter values on failure. |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 278 | EXPECT_EQ(0, const_out_frame_data[i]); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 279 | } |
| 280 | } |
| 281 | |
henrik.lundin@webrtc.org | b4e80e0 | 2014-05-15 07:14:00 +0000 | [diff] [blame] | 282 | TEST_F(NetEqDecodingTest, GetAudioBeforeInsertPacket) { |
Artem Titov | d00ce74 | 2021-07-28 20:00:17 +0200 | [diff] [blame] | 283 | // Set all of `out_data_` to 1, and verify that it was set to 0 by the call |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 284 | // to GetAudio. |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 285 | int16_t* out_frame_data = out_frame_.mutable_data(); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 286 | for (size_t i = 0; i < AudioFrame::kMaxDataSizeSamples; ++i) { |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 287 | out_frame_data[i] = 1; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 288 | } |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 289 | bool muted; |
| 290 | EXPECT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); |
| 291 | ASSERT_FALSE(muted); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 292 | // Verify that the first block of samples is set to 0. |
| 293 | static const int kExpectedOutputLength = |
| 294 | kInitSampleRateHz / 100; // 10 ms at initial sample rate. |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 295 | const int16_t* const_out_frame_data = out_frame_.data(); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 296 | for (int i = 0; i < kExpectedOutputLength; ++i) { |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame] | 297 | rtc::StringBuilder ss; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 298 | ss << "i = " << i; |
| 299 | SCOPED_TRACE(ss.str()); // Print out the parameter values on failure. |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 300 | EXPECT_EQ(0, const_out_frame_data[i]); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 301 | } |
henrik.lundin | d89814b | 2015-11-23 06:49:25 -0800 | [diff] [blame] | 302 | // Verify that the sample rate did not change from the initial configuration. |
| 303 | EXPECT_EQ(config_.sample_rate_hz, neteq_->last_output_sample_rate_hz()); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 304 | } |
turaj@webrtc.org | ff43c85 | 2013-09-25 00:07:27 +0000 | [diff] [blame] | 305 | |
henrik.lundin@webrtc.org | 9b8102c | 2014-08-21 08:27:44 +0000 | [diff] [blame] | 306 | class NetEqBgnTest : public NetEqDecodingTest { |
henrik.lundin@webrtc.org | ea25784 | 2014-08-07 12:27:37 +0000 | [diff] [blame] | 307 | protected: |
henrik.lundin@webrtc.org | 9b8102c | 2014-08-21 08:27:44 +0000 | [diff] [blame] | 308 | void CheckBgn(int sampling_rate_hz) { |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 309 | size_t expected_samples_per_channel = 0; |
henrik.lundin@webrtc.org | ea25784 | 2014-08-07 12:27:37 +0000 | [diff] [blame] | 310 | uint8_t payload_type = 0xFF; // Invalid. |
| 311 | if (sampling_rate_hz == 8000) { |
| 312 | expected_samples_per_channel = kBlockSize8kHz; |
| 313 | payload_type = 93; // PCM 16, 8 kHz. |
| 314 | } else if (sampling_rate_hz == 16000) { |
| 315 | expected_samples_per_channel = kBlockSize16kHz; |
| 316 | payload_type = 94; // PCM 16, 16 kHZ. |
| 317 | } else if (sampling_rate_hz == 32000) { |
| 318 | expected_samples_per_channel = kBlockSize32kHz; |
| 319 | payload_type = 95; // PCM 16, 32 kHz. |
| 320 | } else { |
| 321 | ASSERT_TRUE(false); // Unsupported test case. |
| 322 | } |
turaj@webrtc.org | ff43c85 | 2013-09-25 00:07:27 +0000 | [diff] [blame] | 323 | |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 324 | AudioFrame output; |
henrik.lundin@webrtc.org | 9b8102c | 2014-08-21 08:27:44 +0000 | [diff] [blame] | 325 | test::AudioLoop input; |
| 326 | // We are using the same 32 kHz input file for all tests, regardless of |
Artem Titov | d00ce74 | 2021-07-28 20:00:17 +0200 | [diff] [blame] | 327 | // `sampling_rate_hz`. The output may sound weird, but the test is still |
henrik.lundin@webrtc.org | 9b8102c | 2014-08-21 08:27:44 +0000 | [diff] [blame] | 328 | // valid. |
| 329 | ASSERT_TRUE(input.Init( |
| 330 | webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm"), |
| 331 | 10 * sampling_rate_hz, // Max 10 seconds loop length. |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 332 | expected_samples_per_channel)); |
henrik.lundin@webrtc.org | ea25784 | 2014-08-07 12:27:37 +0000 | [diff] [blame] | 333 | |
| 334 | // Payload of 10 ms of PCM16 32 kHz. |
| 335 | uint8_t payload[kBlockSize32kHz * sizeof(int16_t)]; |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 336 | RTPHeader rtp_info; |
henrik.lundin@webrtc.org | ea25784 | 2014-08-07 12:27:37 +0000 | [diff] [blame] | 337 | PopulateRtpInfo(0, 0, &rtp_info); |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 338 | rtp_info.payloadType = payload_type; |
henrik.lundin@webrtc.org | ea25784 | 2014-08-07 12:27:37 +0000 | [diff] [blame] | 339 | |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 340 | bool muted; |
henrik.lundin@webrtc.org | ea25784 | 2014-08-07 12:27:37 +0000 | [diff] [blame] | 341 | for (int n = 0; n < 10; ++n) { // Insert few packets and get audio. |
kwiberg | 288886b | 2015-11-06 01:21:35 -0800 | [diff] [blame] | 342 | auto block = input.GetNextBlock(); |
| 343 | ASSERT_EQ(expected_samples_per_channel, block.size()); |
| 344 | size_t enc_len_bytes = |
| 345 | WebRtcPcm16b_Encode(block.data(), block.size(), payload); |
henrik.lundin@webrtc.org | 9b8102c | 2014-08-21 08:27:44 +0000 | [diff] [blame] | 346 | ASSERT_EQ(enc_len_bytes, expected_samples_per_channel * 2); |
| 347 | |
Karl Wiberg | 45eb135 | 2019-10-10 14:23:00 +0200 | [diff] [blame] | 348 | ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, rtc::ArrayView<const uint8_t>( |
| 349 | payload, enc_len_bytes))); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 350 | output.Reset(); |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 351 | ASSERT_EQ(0, neteq_->GetAudio(&output, &muted)); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 352 | ASSERT_EQ(1u, output.num_channels_); |
| 353 | ASSERT_EQ(expected_samples_per_channel, output.samples_per_channel_); |
henrik.lundin | 55480f5 | 2016-03-08 02:37:57 -0800 | [diff] [blame] | 354 | ASSERT_EQ(AudioFrame::kNormalSpeech, output.speech_type_); |
henrik.lundin@webrtc.org | ea25784 | 2014-08-07 12:27:37 +0000 | [diff] [blame] | 355 | |
| 356 | // Next packet. |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 357 | rtp_info.timestamp += |
| 358 | rtc::checked_cast<uint32_t>(expected_samples_per_channel); |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 359 | rtp_info.sequenceNumber++; |
henrik.lundin@webrtc.org | ea25784 | 2014-08-07 12:27:37 +0000 | [diff] [blame] | 360 | } |
| 361 | |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 362 | output.Reset(); |
henrik.lundin@webrtc.org | ea25784 | 2014-08-07 12:27:37 +0000 | [diff] [blame] | 363 | |
| 364 | // Get audio without inserting packets, expecting PLC and PLC-to-CNG. Pull |
| 365 | // one frame without checking speech-type. This is the first frame pulled |
| 366 | // without inserting any packet, and might not be labeled as PLC. |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 367 | ASSERT_EQ(0, neteq_->GetAudio(&output, &muted)); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 368 | ASSERT_EQ(1u, output.num_channels_); |
| 369 | ASSERT_EQ(expected_samples_per_channel, output.samples_per_channel_); |
henrik.lundin@webrtc.org | ea25784 | 2014-08-07 12:27:37 +0000 | [diff] [blame] | 370 | |
| 371 | // To be able to test the fading of background noise we need at lease to |
| 372 | // pull 611 frames. |
| 373 | const int kFadingThreshold = 611; |
| 374 | |
| 375 | // Test several CNG-to-PLC packet for the expected behavior. The number 20 |
| 376 | // is arbitrary, but sufficiently large to test enough number of frames. |
| 377 | const int kNumPlcToCngTestFrames = 20; |
| 378 | bool plc_to_cng = false; |
| 379 | for (int n = 0; n < kFadingThreshold + kNumPlcToCngTestFrames; ++n) { |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 380 | output.Reset(); |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 381 | // Set to non-zero. |
| 382 | memset(output.mutable_data(), 1, AudioFrame::kMaxDataSizeBytes); |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 383 | ASSERT_EQ(0, neteq_->GetAudio(&output, &muted)); |
| 384 | ASSERT_FALSE(muted); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 385 | ASSERT_EQ(1u, output.num_channels_); |
| 386 | ASSERT_EQ(expected_samples_per_channel, output.samples_per_channel_); |
henrik.lundin | 55480f5 | 2016-03-08 02:37:57 -0800 | [diff] [blame] | 387 | if (output.speech_type_ == AudioFrame::kPLCCNG) { |
henrik.lundin@webrtc.org | ea25784 | 2014-08-07 12:27:37 +0000 | [diff] [blame] | 388 | plc_to_cng = true; |
| 389 | double sum_squared = 0; |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 390 | const int16_t* output_data = output.data(); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 391 | for (size_t k = 0; |
| 392 | k < output.num_channels_ * output.samples_per_channel_; ++k) |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 393 | sum_squared += output_data[k] * output_data[k]; |
Henrik Lundin | 6719017 | 2018-04-20 15:34:48 +0200 | [diff] [blame] | 394 | EXPECT_EQ(0, sum_squared); |
henrik.lundin@webrtc.org | ea25784 | 2014-08-07 12:27:37 +0000 | [diff] [blame] | 395 | } else { |
henrik.lundin | 55480f5 | 2016-03-08 02:37:57 -0800 | [diff] [blame] | 396 | EXPECT_EQ(AudioFrame::kPLC, output.speech_type_); |
henrik.lundin@webrtc.org | ea25784 | 2014-08-07 12:27:37 +0000 | [diff] [blame] | 397 | } |
| 398 | } |
| 399 | EXPECT_TRUE(plc_to_cng); // Just to be sure that PLC-to-CNG has occurred. |
| 400 | } |
| 401 | }; |
| 402 | |
Henrik Lundin | 6719017 | 2018-04-20 15:34:48 +0200 | [diff] [blame] | 403 | TEST_F(NetEqBgnTest, RunTest) { |
henrik.lundin@webrtc.org | 9b8102c | 2014-08-21 08:27:44 +0000 | [diff] [blame] | 404 | CheckBgn(8000); |
| 405 | CheckBgn(16000); |
| 406 | CheckBgn(32000); |
| 407 | } |
henrik.lundin@webrtc.org | ea25784 | 2014-08-07 12:27:37 +0000 | [diff] [blame] | 408 | |
turaj@webrtc.org | 78b41a0 | 2013-11-22 20:27:07 +0000 | [diff] [blame] | 409 | TEST_F(NetEqDecodingTest, SequenceNumberWrap) { |
| 410 | // Start with a sequence number that will soon wrap. |
| 411 | std::set<uint16_t> drop_seq_numbers; // Don't drop any packets. |
| 412 | WrapTest(0xFFFF - 10, 0, drop_seq_numbers, true, false); |
| 413 | } |
| 414 | |
| 415 | TEST_F(NetEqDecodingTest, SequenceNumberWrapAndDrop) { |
| 416 | // Start with a sequence number that will soon wrap. |
| 417 | std::set<uint16_t> drop_seq_numbers; |
| 418 | drop_seq_numbers.insert(0xFFFF); |
| 419 | drop_seq_numbers.insert(0x0); |
| 420 | WrapTest(0xFFFF - 10, 0, drop_seq_numbers, true, false); |
| 421 | } |
| 422 | |
| 423 | TEST_F(NetEqDecodingTest, TimestampWrap) { |
| 424 | // Start with a timestamp that will soon wrap. |
| 425 | std::set<uint16_t> drop_seq_numbers; |
| 426 | WrapTest(0, 0xFFFFFFFF - 3000, drop_seq_numbers, false, true); |
| 427 | } |
| 428 | |
| 429 | TEST_F(NetEqDecodingTest, TimestampAndSequenceNumberWrap) { |
| 430 | // Start with a timestamp and a sequence number that will wrap at the same |
| 431 | // time. |
| 432 | std::set<uint16_t> drop_seq_numbers; |
| 433 | WrapTest(0xFFFF - 10, 0xFFFFFFFF - 5000, drop_seq_numbers, true, true); |
| 434 | } |
| 435 | |
Yves Gerey | 3a65f39 | 2019-11-11 18:05:42 +0100 | [diff] [blame] | 436 | TEST_F(NetEqDecodingTest, DiscardDuplicateCng) { |
henrik.lundin@webrtc.org | ca8cb95 | 2014-03-12 10:26:52 +0000 | [diff] [blame] | 437 | uint16_t seq_no = 0; |
| 438 | uint32_t timestamp = 0; |
| 439 | const int kFrameSizeMs = 10; |
| 440 | const int kSampleRateKhz = 16; |
| 441 | const int kSamples = kFrameSizeMs * kSampleRateKhz; |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 442 | const size_t kPayloadBytes = kSamples * 2; |
henrik.lundin@webrtc.org | ca8cb95 | 2014-03-12 10:26:52 +0000 | [diff] [blame] | 443 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 444 | const int algorithmic_delay_samples = |
| 445 | std::max(algorithmic_delay_ms_ * kSampleRateKhz, 5 * kSampleRateKhz / 8); |
henrik.lundin@webrtc.org | c93437e | 2014-12-01 11:42:42 +0000 | [diff] [blame] | 446 | // Insert three speech packets. Three are needed to get the frame length |
henrik.lundin@webrtc.org | ca8cb95 | 2014-03-12 10:26:52 +0000 | [diff] [blame] | 447 | // correct. |
henrik.lundin@webrtc.org | ca8cb95 | 2014-03-12 10:26:52 +0000 | [diff] [blame] | 448 | uint8_t payload[kPayloadBytes] = {0}; |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 449 | RTPHeader rtp_info; |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 450 | bool muted; |
henrik.lundin@webrtc.org | ca8cb95 | 2014-03-12 10:26:52 +0000 | [diff] [blame] | 451 | for (int i = 0; i < 3; ++i) { |
| 452 | PopulateRtpInfo(seq_no, timestamp, &rtp_info); |
Karl Wiberg | 45eb135 | 2019-10-10 14:23:00 +0200 | [diff] [blame] | 453 | ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload)); |
henrik.lundin@webrtc.org | ca8cb95 | 2014-03-12 10:26:52 +0000 | [diff] [blame] | 454 | ++seq_no; |
| 455 | timestamp += kSamples; |
| 456 | |
| 457 | // Pull audio once. |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 458 | ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 459 | ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); |
henrik.lundin@webrtc.org | ca8cb95 | 2014-03-12 10:26:52 +0000 | [diff] [blame] | 460 | } |
| 461 | // Verify speech output. |
henrik.lundin | 55480f5 | 2016-03-08 02:37:57 -0800 | [diff] [blame] | 462 | EXPECT_EQ(AudioFrame::kNormalSpeech, out_frame_.speech_type_); |
henrik.lundin@webrtc.org | ca8cb95 | 2014-03-12 10:26:52 +0000 | [diff] [blame] | 463 | |
| 464 | // Insert same CNG packet twice. |
| 465 | const int kCngPeriodMs = 100; |
| 466 | const int kCngPeriodSamples = kCngPeriodMs * kSampleRateKhz; |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 467 | size_t payload_len; |
henrik.lundin@webrtc.org | ca8cb95 | 2014-03-12 10:26:52 +0000 | [diff] [blame] | 468 | PopulateCng(seq_no, timestamp, &rtp_info, payload, &payload_len); |
| 469 | // This is the first time this CNG packet is inserted. |
Karl Wiberg | 45eb135 | 2019-10-10 14:23:00 +0200 | [diff] [blame] | 470 | ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, rtc::ArrayView<const uint8_t>( |
| 471 | payload, payload_len))); |
henrik.lundin@webrtc.org | ca8cb95 | 2014-03-12 10:26:52 +0000 | [diff] [blame] | 472 | |
| 473 | // Pull audio once and make sure CNG is played. |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 474 | ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 475 | ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); |
henrik.lundin | 55480f5 | 2016-03-08 02:37:57 -0800 | [diff] [blame] | 476 | EXPECT_EQ(AudioFrame::kCNG, out_frame_.speech_type_); |
henrik.lundin | 114c1b3 | 2017-04-26 07:47:32 -0700 | [diff] [blame] | 477 | EXPECT_FALSE( |
| 478 | neteq_->GetPlayoutTimestamp()); // Returns empty value during CNG. |
henrik.lundin | 0d96ab7 | 2016-04-06 12:28:26 -0700 | [diff] [blame] | 479 | EXPECT_EQ(timestamp - algorithmic_delay_samples, |
| 480 | out_frame_.timestamp_ + out_frame_.samples_per_channel_); |
henrik.lundin@webrtc.org | ca8cb95 | 2014-03-12 10:26:52 +0000 | [diff] [blame] | 481 | |
| 482 | // Insert the same CNG packet again. Note that at this point it is old, since |
| 483 | // we have already decoded the first copy of it. |
Karl Wiberg | 45eb135 | 2019-10-10 14:23:00 +0200 | [diff] [blame] | 484 | ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, rtc::ArrayView<const uint8_t>( |
| 485 | payload, payload_len))); |
henrik.lundin@webrtc.org | ca8cb95 | 2014-03-12 10:26:52 +0000 | [diff] [blame] | 486 | |
Artem Titov | d00ce74 | 2021-07-28 20:00:17 +0200 | [diff] [blame] | 487 | // Pull audio until we have played `kCngPeriodMs` of CNG. Start at 10 ms since |
henrik.lundin@webrtc.org | ca8cb95 | 2014-03-12 10:26:52 +0000 | [diff] [blame] | 488 | // we have already pulled out CNG once. |
| 489 | for (int cng_time_ms = 10; cng_time_ms < kCngPeriodMs; cng_time_ms += 10) { |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 490 | ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 491 | ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); |
henrik.lundin | 55480f5 | 2016-03-08 02:37:57 -0800 | [diff] [blame] | 492 | EXPECT_EQ(AudioFrame::kCNG, out_frame_.speech_type_); |
henrik.lundin | 114c1b3 | 2017-04-26 07:47:32 -0700 | [diff] [blame] | 493 | EXPECT_FALSE( |
| 494 | neteq_->GetPlayoutTimestamp()); // Returns empty value during CNG. |
turaj@webrtc.org | 8d1cdaa | 2014-04-11 18:47:55 +0000 | [diff] [blame] | 495 | EXPECT_EQ(timestamp - algorithmic_delay_samples, |
henrik.lundin | 0d96ab7 | 2016-04-06 12:28:26 -0700 | [diff] [blame] | 496 | out_frame_.timestamp_ + out_frame_.samples_per_channel_); |
henrik.lundin@webrtc.org | ca8cb95 | 2014-03-12 10:26:52 +0000 | [diff] [blame] | 497 | } |
| 498 | |
henrik.lundin@webrtc.org | ca8cb95 | 2014-03-12 10:26:52 +0000 | [diff] [blame] | 499 | ++seq_no; |
| 500 | timestamp += kCngPeriodSamples; |
Jakob Ivarsson | fa68ac0 | 2021-11-09 12:58:45 +0100 | [diff] [blame] | 501 | uint32_t first_speech_timestamp = timestamp; |
| 502 | // Insert speech again. |
| 503 | for (int i = 0; i < 3; ++i) { |
| 504 | PopulateRtpInfo(seq_no, timestamp, &rtp_info); |
| 505 | ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload)); |
| 506 | ++seq_no; |
| 507 | timestamp += kSamples; |
| 508 | } |
henrik.lundin@webrtc.org | ca8cb95 | 2014-03-12 10:26:52 +0000 | [diff] [blame] | 509 | |
| 510 | // Pull audio once and verify that the output is speech again. |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 511 | ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 512 | ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); |
henrik.lundin | 55480f5 | 2016-03-08 02:37:57 -0800 | [diff] [blame] | 513 | EXPECT_EQ(AudioFrame::kNormalSpeech, out_frame_.speech_type_); |
Danil Chapovalov | b602123 | 2018-06-19 13:26:36 +0200 | [diff] [blame] | 514 | absl::optional<uint32_t> playout_timestamp = neteq_->GetPlayoutTimestamp(); |
henrik.lundin | 0d96ab7 | 2016-04-06 12:28:26 -0700 | [diff] [blame] | 515 | ASSERT_TRUE(playout_timestamp); |
Jakob Ivarsson | fa68ac0 | 2021-11-09 12:58:45 +0100 | [diff] [blame] | 516 | EXPECT_EQ(first_speech_timestamp + kSamples - algorithmic_delay_samples, |
henrik.lundin | 0d96ab7 | 2016-04-06 12:28:26 -0700 | [diff] [blame] | 517 | *playout_timestamp); |
wu@webrtc.org | 94454b7 | 2014-06-05 20:34:08 +0000 | [diff] [blame] | 518 | } |
| 519 | |
henrik.lundin@webrtc.org | c93437e | 2014-12-01 11:42:42 +0000 | [diff] [blame] | 520 | TEST_F(NetEqDecodingTest, CngFirst) { |
| 521 | uint16_t seq_no = 0; |
| 522 | uint32_t timestamp = 0; |
| 523 | const int kFrameSizeMs = 10; |
| 524 | const int kSampleRateKhz = 16; |
| 525 | const int kSamples = kFrameSizeMs * kSampleRateKhz; |
| 526 | const int kPayloadBytes = kSamples * 2; |
| 527 | const int kCngPeriodMs = 100; |
| 528 | const int kCngPeriodSamples = kCngPeriodMs * kSampleRateKhz; |
| 529 | size_t payload_len; |
| 530 | |
| 531 | uint8_t payload[kPayloadBytes] = {0}; |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 532 | RTPHeader rtp_info; |
henrik.lundin@webrtc.org | c93437e | 2014-12-01 11:42:42 +0000 | [diff] [blame] | 533 | |
| 534 | PopulateCng(seq_no, timestamp, &rtp_info, payload, &payload_len); |
Karl Wiberg | 45eb135 | 2019-10-10 14:23:00 +0200 | [diff] [blame] | 535 | ASSERT_EQ(NetEq::kOK, |
| 536 | neteq_->InsertPacket( |
| 537 | rtp_info, rtc::ArrayView<const uint8_t>(payload, payload_len))); |
henrik.lundin@webrtc.org | c93437e | 2014-12-01 11:42:42 +0000 | [diff] [blame] | 538 | ++seq_no; |
| 539 | timestamp += kCngPeriodSamples; |
| 540 | |
| 541 | // Pull audio once and make sure CNG is played. |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 542 | bool muted; |
| 543 | ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 544 | ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); |
henrik.lundin | 55480f5 | 2016-03-08 02:37:57 -0800 | [diff] [blame] | 545 | EXPECT_EQ(AudioFrame::kCNG, out_frame_.speech_type_); |
henrik.lundin@webrtc.org | c93437e | 2014-12-01 11:42:42 +0000 | [diff] [blame] | 546 | |
| 547 | // Insert some speech packets. |
henrik.lundin | 549d80b | 2016-08-25 00:44:24 -0700 | [diff] [blame] | 548 | const uint32_t first_speech_timestamp = timestamp; |
| 549 | int timeout_counter = 0; |
| 550 | do { |
| 551 | ASSERT_LT(timeout_counter++, 20) << "Test timed out"; |
henrik.lundin@webrtc.org | c93437e | 2014-12-01 11:42:42 +0000 | [diff] [blame] | 552 | PopulateRtpInfo(seq_no, timestamp, &rtp_info); |
Karl Wiberg | 45eb135 | 2019-10-10 14:23:00 +0200 | [diff] [blame] | 553 | ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload)); |
henrik.lundin@webrtc.org | c93437e | 2014-12-01 11:42:42 +0000 | [diff] [blame] | 554 | ++seq_no; |
| 555 | timestamp += kSamples; |
| 556 | |
| 557 | // Pull audio once. |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 558 | ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 559 | ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); |
henrik.lundin | 549d80b | 2016-08-25 00:44:24 -0700 | [diff] [blame] | 560 | } while (!IsNewerTimestamp(out_frame_.timestamp_, first_speech_timestamp)); |
henrik.lundin@webrtc.org | c93437e | 2014-12-01 11:42:42 +0000 | [diff] [blame] | 561 | // Verify speech output. |
henrik.lundin | 55480f5 | 2016-03-08 02:37:57 -0800 | [diff] [blame] | 562 | EXPECT_EQ(AudioFrame::kNormalSpeech, out_frame_.speech_type_); |
henrik.lundin@webrtc.org | c93437e | 2014-12-01 11:42:42 +0000 | [diff] [blame] | 563 | } |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 564 | |
| 565 | class NetEqDecodingTestWithMutedState : public NetEqDecodingTest { |
| 566 | public: |
| 567 | NetEqDecodingTestWithMutedState() : NetEqDecodingTest() { |
| 568 | config_.enable_muted_state = true; |
| 569 | } |
| 570 | |
| 571 | protected: |
| 572 | static constexpr size_t kSamples = 10 * 16; |
| 573 | static constexpr size_t kPayloadBytes = kSamples * 2; |
| 574 | |
| 575 | void InsertPacket(uint32_t rtp_timestamp) { |
| 576 | uint8_t payload[kPayloadBytes] = {0}; |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 577 | RTPHeader rtp_info; |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 578 | PopulateRtpInfo(0, rtp_timestamp, &rtp_info); |
Karl Wiberg | 45eb135 | 2019-10-10 14:23:00 +0200 | [diff] [blame] | 579 | EXPECT_EQ(0, neteq_->InsertPacket(rtp_info, payload)); |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 580 | } |
| 581 | |
henrik.lundin | 42feb51 | 2016-09-20 06:51:40 -0700 | [diff] [blame] | 582 | void InsertCngPacket(uint32_t rtp_timestamp) { |
| 583 | uint8_t payload[kPayloadBytes] = {0}; |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 584 | RTPHeader rtp_info; |
henrik.lundin | 42feb51 | 2016-09-20 06:51:40 -0700 | [diff] [blame] | 585 | size_t payload_len; |
| 586 | PopulateCng(0, rtp_timestamp, &rtp_info, payload, &payload_len); |
Karl Wiberg | 45eb135 | 2019-10-10 14:23:00 +0200 | [diff] [blame] | 587 | EXPECT_EQ(NetEq::kOK, |
| 588 | neteq_->InsertPacket(rtp_info, rtc::ArrayView<const uint8_t>( |
| 589 | payload, payload_len))); |
henrik.lundin | 42feb51 | 2016-09-20 06:51:40 -0700 | [diff] [blame] | 590 | } |
| 591 | |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 592 | bool GetAudioReturnMuted() { |
| 593 | bool muted; |
| 594 | EXPECT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); |
| 595 | return muted; |
| 596 | } |
| 597 | |
| 598 | void GetAudioUntilMuted() { |
| 599 | while (!GetAudioReturnMuted()) { |
| 600 | ASSERT_LT(counter_++, 1000) << "Test timed out"; |
| 601 | } |
| 602 | } |
| 603 | |
| 604 | void GetAudioUntilNormal() { |
| 605 | bool muted = false; |
| 606 | while (out_frame_.speech_type_ != AudioFrame::kNormalSpeech) { |
| 607 | EXPECT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); |
| 608 | ASSERT_LT(counter_++, 1000) << "Test timed out"; |
| 609 | } |
| 610 | EXPECT_FALSE(muted); |
| 611 | } |
| 612 | |
| 613 | int counter_ = 0; |
| 614 | }; |
| 615 | |
| 616 | // Verifies that NetEq goes in and out of muted state as expected. |
| 617 | TEST_F(NetEqDecodingTestWithMutedState, MutedState) { |
| 618 | // Insert one speech packet. |
| 619 | InsertPacket(0); |
| 620 | // Pull out audio once and expect it not to be muted. |
| 621 | EXPECT_FALSE(GetAudioReturnMuted()); |
| 622 | // Pull data until faded out. |
| 623 | GetAudioUntilMuted(); |
henrik.lundin | a449107 | 2017-07-06 05:23:53 -0700 | [diff] [blame] | 624 | EXPECT_TRUE(out_frame_.muted()); |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 625 | |
| 626 | // Verify that output audio is not written during muted mode. Other parameters |
| 627 | // should be correct, though. |
| 628 | AudioFrame new_frame; |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 629 | int16_t* frame_data = new_frame.mutable_data(); |
| 630 | for (size_t i = 0; i < AudioFrame::kMaxDataSizeSamples; i++) { |
| 631 | frame_data[i] = 17; |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 632 | } |
| 633 | bool muted; |
| 634 | EXPECT_EQ(0, neteq_->GetAudio(&new_frame, &muted)); |
| 635 | EXPECT_TRUE(muted); |
henrik.lundin | a449107 | 2017-07-06 05:23:53 -0700 | [diff] [blame] | 636 | EXPECT_TRUE(out_frame_.muted()); |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 637 | for (size_t i = 0; i < AudioFrame::kMaxDataSizeSamples; i++) { |
| 638 | EXPECT_EQ(17, frame_data[i]); |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 639 | } |
| 640 | EXPECT_EQ(out_frame_.timestamp_ + out_frame_.samples_per_channel_, |
| 641 | new_frame.timestamp_); |
| 642 | EXPECT_EQ(out_frame_.samples_per_channel_, new_frame.samples_per_channel_); |
| 643 | EXPECT_EQ(out_frame_.sample_rate_hz_, new_frame.sample_rate_hz_); |
| 644 | EXPECT_EQ(out_frame_.num_channels_, new_frame.num_channels_); |
| 645 | EXPECT_EQ(out_frame_.speech_type_, new_frame.speech_type_); |
| 646 | EXPECT_EQ(out_frame_.vad_activity_, new_frame.vad_activity_); |
| 647 | |
| 648 | // Insert new data. Timestamp is corrected for the time elapsed since the last |
| 649 | // packet. Verify that normal operation resumes. |
| 650 | InsertPacket(kSamples * counter_); |
| 651 | GetAudioUntilNormal(); |
henrik.lundin | a449107 | 2017-07-06 05:23:53 -0700 | [diff] [blame] | 652 | EXPECT_FALSE(out_frame_.muted()); |
henrik.lundin | 612c25e | 2016-05-25 08:21:04 -0700 | [diff] [blame] | 653 | |
| 654 | NetEqNetworkStatistics stats; |
| 655 | EXPECT_EQ(0, neteq_->NetworkStatistics(&stats)); |
| 656 | // NetEqNetworkStatistics::expand_rate tells the fraction of samples that were |
| 657 | // concealment samples, in Q14 (16384 = 100%) .The vast majority should be |
| 658 | // concealment samples in this test. |
| 659 | EXPECT_GT(stats.expand_rate, 14000); |
| 660 | // And, it should be greater than the speech_expand_rate. |
| 661 | EXPECT_GT(stats.expand_rate, stats.speech_expand_rate); |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 662 | } |
| 663 | |
| 664 | // Verifies that NetEq goes out of muted state when given a delayed packet. |
| 665 | TEST_F(NetEqDecodingTestWithMutedState, MutedStateDelayedPacket) { |
| 666 | // Insert one speech packet. |
| 667 | InsertPacket(0); |
| 668 | // Pull out audio once and expect it not to be muted. |
| 669 | EXPECT_FALSE(GetAudioReturnMuted()); |
| 670 | // Pull data until faded out. |
| 671 | GetAudioUntilMuted(); |
| 672 | // Insert new data. Timestamp is only corrected for the half of the time |
| 673 | // elapsed since the last packet. That is, the new packet is delayed. Verify |
| 674 | // that normal operation resumes. |
| 675 | InsertPacket(kSamples * counter_ / 2); |
| 676 | GetAudioUntilNormal(); |
| 677 | } |
| 678 | |
| 679 | // Verifies that NetEq goes out of muted state when given a future packet. |
| 680 | TEST_F(NetEqDecodingTestWithMutedState, MutedStateFuturePacket) { |
| 681 | // Insert one speech packet. |
| 682 | InsertPacket(0); |
| 683 | // Pull out audio once and expect it not to be muted. |
| 684 | EXPECT_FALSE(GetAudioReturnMuted()); |
| 685 | // Pull data until faded out. |
| 686 | GetAudioUntilMuted(); |
| 687 | // Insert new data. Timestamp is over-corrected for the time elapsed since the |
| 688 | // last packet. That is, the new packet is too early. Verify that normal |
| 689 | // operation resumes. |
| 690 | InsertPacket(kSamples * counter_ * 2); |
| 691 | GetAudioUntilNormal(); |
| 692 | } |
| 693 | |
| 694 | // Verifies that NetEq goes out of muted state when given an old packet. |
| 695 | TEST_F(NetEqDecodingTestWithMutedState, MutedStateOldPacket) { |
| 696 | // Insert one speech packet. |
| 697 | InsertPacket(0); |
| 698 | // Pull out audio once and expect it not to be muted. |
| 699 | EXPECT_FALSE(GetAudioReturnMuted()); |
| 700 | // Pull data until faded out. |
| 701 | GetAudioUntilMuted(); |
| 702 | |
| 703 | EXPECT_NE(AudioFrame::kNormalSpeech, out_frame_.speech_type_); |
Jakob Ivarsson | 80fb978 | 2020-10-09 13:41:06 +0200 | [diff] [blame] | 704 | // Insert a few packets which are older than the first packet. |
| 705 | for (int i = 0; i < 5; ++i) { |
| 706 | InsertPacket(kSamples * (i - 1000)); |
| 707 | } |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 708 | EXPECT_FALSE(GetAudioReturnMuted()); |
| 709 | EXPECT_EQ(AudioFrame::kNormalSpeech, out_frame_.speech_type_); |
| 710 | } |
| 711 | |
henrik.lundin | 42feb51 | 2016-09-20 06:51:40 -0700 | [diff] [blame] | 712 | // Verifies that NetEq doesn't enter muted state when CNG mode is active and the |
| 713 | // packet stream is suspended for a long time. |
| 714 | TEST_F(NetEqDecodingTestWithMutedState, DoNotMuteExtendedCngWithoutPackets) { |
| 715 | // Insert one CNG packet. |
| 716 | InsertCngPacket(0); |
| 717 | |
| 718 | // Pull 10 seconds of audio (10 ms audio generated per lap). |
| 719 | for (int i = 0; i < 1000; ++i) { |
| 720 | bool muted; |
| 721 | EXPECT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); |
| 722 | ASSERT_FALSE(muted); |
| 723 | } |
| 724 | EXPECT_EQ(AudioFrame::kCNG, out_frame_.speech_type_); |
| 725 | } |
| 726 | |
| 727 | // Verifies that NetEq goes back to normal after a long CNG period with the |
| 728 | // packet stream suspended. |
| 729 | TEST_F(NetEqDecodingTestWithMutedState, RecoverAfterExtendedCngWithoutPackets) { |
| 730 | // Insert one CNG packet. |
| 731 | InsertCngPacket(0); |
| 732 | |
| 733 | // Pull 10 seconds of audio (10 ms audio generated per lap). |
| 734 | for (int i = 0; i < 1000; ++i) { |
| 735 | bool muted; |
| 736 | EXPECT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); |
| 737 | } |
| 738 | |
| 739 | // Insert new data. Timestamp is corrected for the time elapsed since the last |
| 740 | // packet. Verify that normal operation resumes. |
| 741 | InsertPacket(kSamples * counter_); |
| 742 | GetAudioUntilNormal(); |
| 743 | } |
| 744 | |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 745 | namespace { |
| 746 | ::testing::AssertionResult AudioFramesEqualExceptData(const AudioFrame& a, |
| 747 | const AudioFrame& b) { |
| 748 | if (a.timestamp_ != b.timestamp_) |
| 749 | return ::testing::AssertionFailure() << "timestamp_ diff (" << a.timestamp_ |
| 750 | << " != " << b.timestamp_ << ")"; |
| 751 | if (a.sample_rate_hz_ != b.sample_rate_hz_) |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 752 | return ::testing::AssertionFailure() |
| 753 | << "sample_rate_hz_ diff (" << a.sample_rate_hz_ |
| 754 | << " != " << b.sample_rate_hz_ << ")"; |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 755 | if (a.samples_per_channel_ != b.samples_per_channel_) |
| 756 | return ::testing::AssertionFailure() |
| 757 | << "samples_per_channel_ diff (" << a.samples_per_channel_ |
| 758 | << " != " << b.samples_per_channel_ << ")"; |
| 759 | if (a.num_channels_ != b.num_channels_) |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 760 | return ::testing::AssertionFailure() |
| 761 | << "num_channels_ diff (" << a.num_channels_ |
| 762 | << " != " << b.num_channels_ << ")"; |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 763 | if (a.speech_type_ != b.speech_type_) |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 764 | return ::testing::AssertionFailure() |
| 765 | << "speech_type_ diff (" << a.speech_type_ |
| 766 | << " != " << b.speech_type_ << ")"; |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 767 | if (a.vad_activity_ != b.vad_activity_) |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 768 | return ::testing::AssertionFailure() |
| 769 | << "vad_activity_ diff (" << a.vad_activity_ |
| 770 | << " != " << b.vad_activity_ << ")"; |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 771 | return ::testing::AssertionSuccess(); |
| 772 | } |
| 773 | |
| 774 | ::testing::AssertionResult AudioFramesEqual(const AudioFrame& a, |
| 775 | const AudioFrame& b) { |
| 776 | ::testing::AssertionResult res = AudioFramesEqualExceptData(a, b); |
| 777 | if (!res) |
| 778 | return res; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 779 | if (memcmp(a.data(), b.data(), |
| 780 | a.samples_per_channel_ * a.num_channels_ * sizeof(*a.data())) != |
| 781 | 0) { |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 782 | return ::testing::AssertionFailure() << "data_ diff"; |
| 783 | } |
| 784 | return ::testing::AssertionSuccess(); |
| 785 | } |
| 786 | |
| 787 | } // namespace |
| 788 | |
| 789 | TEST_F(NetEqDecodingTestTwoInstances, CompareMutedStateOnOff) { |
| 790 | ASSERT_FALSE(config_.enable_muted_state); |
| 791 | config2_.enable_muted_state = true; |
| 792 | CreateSecondInstance(); |
| 793 | |
| 794 | // Insert one speech packet into both NetEqs. |
| 795 | const size_t kSamples = 10 * 16; |
| 796 | const size_t kPayloadBytes = kSamples * 2; |
| 797 | uint8_t payload[kPayloadBytes] = {0}; |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 798 | RTPHeader rtp_info; |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 799 | PopulateRtpInfo(0, 0, &rtp_info); |
Karl Wiberg | 45eb135 | 2019-10-10 14:23:00 +0200 | [diff] [blame] | 800 | EXPECT_EQ(0, neteq_->InsertPacket(rtp_info, payload)); |
| 801 | EXPECT_EQ(0, neteq2_->InsertPacket(rtp_info, payload)); |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 802 | |
| 803 | AudioFrame out_frame1, out_frame2; |
| 804 | bool muted; |
| 805 | for (int i = 0; i < 1000; ++i) { |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame] | 806 | rtc::StringBuilder ss; |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 807 | ss << "i = " << i; |
| 808 | SCOPED_TRACE(ss.str()); // Print out the loop iterator on failure. |
| 809 | EXPECT_EQ(0, neteq_->GetAudio(&out_frame1, &muted)); |
| 810 | EXPECT_FALSE(muted); |
| 811 | EXPECT_EQ(0, neteq2_->GetAudio(&out_frame2, &muted)); |
| 812 | if (muted) { |
| 813 | EXPECT_TRUE(AudioFramesEqualExceptData(out_frame1, out_frame2)); |
| 814 | } else { |
| 815 | EXPECT_TRUE(AudioFramesEqual(out_frame1, out_frame2)); |
| 816 | } |
| 817 | } |
| 818 | EXPECT_TRUE(muted); |
| 819 | |
| 820 | // Insert new data. Timestamp is corrected for the time elapsed since the last |
| 821 | // packet. |
Jakob Ivarsson | 80fb978 | 2020-10-09 13:41:06 +0200 | [diff] [blame] | 822 | for (int i = 0; i < 5; ++i) { |
| 823 | PopulateRtpInfo(0, kSamples * 1000 + kSamples * i, &rtp_info); |
| 824 | EXPECT_EQ(0, neteq_->InsertPacket(rtp_info, payload)); |
| 825 | EXPECT_EQ(0, neteq2_->InsertPacket(rtp_info, payload)); |
| 826 | } |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 827 | |
| 828 | int counter = 0; |
| 829 | while (out_frame1.speech_type_ != AudioFrame::kNormalSpeech) { |
| 830 | ASSERT_LT(counter++, 1000) << "Test timed out"; |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame] | 831 | rtc::StringBuilder ss; |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 832 | ss << "counter = " << counter; |
| 833 | SCOPED_TRACE(ss.str()); // Print out the loop iterator on failure. |
| 834 | EXPECT_EQ(0, neteq_->GetAudio(&out_frame1, &muted)); |
| 835 | EXPECT_FALSE(muted); |
| 836 | EXPECT_EQ(0, neteq2_->GetAudio(&out_frame2, &muted)); |
| 837 | if (muted) { |
| 838 | EXPECT_TRUE(AudioFramesEqualExceptData(out_frame1, out_frame2)); |
| 839 | } else { |
| 840 | EXPECT_TRUE(AudioFramesEqual(out_frame1, out_frame2)); |
| 841 | } |
| 842 | } |
| 843 | EXPECT_FALSE(muted); |
| 844 | } |
| 845 | |
Gustaf Ullberg | 9a2e906 | 2017-09-18 09:28:20 +0200 | [diff] [blame] | 846 | TEST_F(NetEqDecodingTest, TestConcealmentEvents) { |
| 847 | const int kNumConcealmentEvents = 19; |
| 848 | const size_t kSamples = 10 * 16; |
| 849 | const size_t kPayloadBytes = kSamples * 2; |
| 850 | int seq_no = 0; |
| 851 | RTPHeader rtp_info; |
| 852 | rtp_info.ssrc = 0x1234; // Just an arbitrary SSRC. |
| 853 | rtp_info.payloadType = 94; // PCM16b WB codec. |
| 854 | rtp_info.markerBit = 0; |
| 855 | const uint8_t payload[kPayloadBytes] = {0}; |
| 856 | bool muted; |
| 857 | |
| 858 | for (int i = 0; i < kNumConcealmentEvents; i++) { |
| 859 | // Insert some packets of 10 ms size. |
| 860 | for (int j = 0; j < 10; j++) { |
| 861 | rtp_info.sequenceNumber = seq_no++; |
| 862 | rtp_info.timestamp = rtp_info.sequenceNumber * kSamples; |
Karl Wiberg | 45eb135 | 2019-10-10 14:23:00 +0200 | [diff] [blame] | 863 | neteq_->InsertPacket(rtp_info, payload); |
Gustaf Ullberg | 9a2e906 | 2017-09-18 09:28:20 +0200 | [diff] [blame] | 864 | neteq_->GetAudio(&out_frame_, &muted); |
| 865 | } |
| 866 | |
| 867 | // Lose a number of packets. |
| 868 | int num_lost = 1 + i; |
| 869 | for (int j = 0; j < num_lost; j++) { |
| 870 | seq_no++; |
| 871 | neteq_->GetAudio(&out_frame_, &muted); |
| 872 | } |
| 873 | } |
| 874 | |
| 875 | // Check number of concealment events. |
| 876 | NetEqLifetimeStatistics stats = neteq_->GetLifetimeStatistics(); |
| 877 | EXPECT_EQ(kNumConcealmentEvents, static_cast<int>(stats.concealment_events)); |
| 878 | } |
| 879 | |
Gustaf Ullberg | b0a0207 | 2017-10-02 12:00:34 +0200 | [diff] [blame] | 880 | // Test that the jitter buffer delay stat is computed correctly. |
| 881 | void NetEqDecodingTestFaxMode::TestJitterBufferDelay(bool apply_packet_loss) { |
| 882 | const int kNumPackets = 10; |
| 883 | const int kDelayInNumPackets = 2; |
| 884 | const int kPacketLenMs = 10; // All packets are of 10 ms size. |
| 885 | const size_t kSamples = kPacketLenMs * 16; |
| 886 | const size_t kPayloadBytes = kSamples * 2; |
| 887 | RTPHeader rtp_info; |
| 888 | rtp_info.ssrc = 0x1234; // Just an arbitrary SSRC. |
| 889 | rtp_info.payloadType = 94; // PCM16b WB codec. |
| 890 | rtp_info.markerBit = 0; |
| 891 | const uint8_t payload[kPayloadBytes] = {0}; |
| 892 | bool muted; |
| 893 | int packets_sent = 0; |
| 894 | int packets_received = 0; |
| 895 | int expected_delay = 0; |
Artem Titov | e618cc9 | 2020-03-11 11:18:54 +0100 | [diff] [blame] | 896 | int expected_target_delay = 0; |
Chen Xing | 0acffb5 | 2019-01-15 15:46:29 +0100 | [diff] [blame] | 897 | uint64_t expected_emitted_count = 0; |
Gustaf Ullberg | b0a0207 | 2017-10-02 12:00:34 +0200 | [diff] [blame] | 898 | while (packets_received < kNumPackets) { |
| 899 | // Insert packet. |
| 900 | if (packets_sent < kNumPackets) { |
| 901 | rtp_info.sequenceNumber = packets_sent++; |
| 902 | rtp_info.timestamp = rtp_info.sequenceNumber * kSamples; |
Karl Wiberg | 45eb135 | 2019-10-10 14:23:00 +0200 | [diff] [blame] | 903 | neteq_->InsertPacket(rtp_info, payload); |
Gustaf Ullberg | b0a0207 | 2017-10-02 12:00:34 +0200 | [diff] [blame] | 904 | } |
| 905 | |
| 906 | // Get packet. |
| 907 | if (packets_sent > kDelayInNumPackets) { |
| 908 | neteq_->GetAudio(&out_frame_, &muted); |
| 909 | packets_received++; |
| 910 | |
| 911 | // The delay reported by the jitter buffer never exceeds |
| 912 | // the number of samples previously fetched with GetAudio |
| 913 | // (hence the min()). |
| 914 | int packets_delay = std::min(packets_received, kDelayInNumPackets + 1); |
| 915 | |
| 916 | // The increase of the expected delay is the product of |
| 917 | // the current delay of the jitter buffer in ms * the |
| 918 | // number of samples that are sent for play out. |
| 919 | int current_delay_ms = packets_delay * kPacketLenMs; |
| 920 | expected_delay += current_delay_ms * kSamples; |
Artem Titov | e618cc9 | 2020-03-11 11:18:54 +0100 | [diff] [blame] | 921 | expected_target_delay += neteq_->TargetDelayMs() * kSamples; |
Chen Xing | 0acffb5 | 2019-01-15 15:46:29 +0100 | [diff] [blame] | 922 | expected_emitted_count += kSamples; |
Gustaf Ullberg | b0a0207 | 2017-10-02 12:00:34 +0200 | [diff] [blame] | 923 | } |
| 924 | } |
| 925 | |
| 926 | if (apply_packet_loss) { |
| 927 | // Extra call to GetAudio to cause concealment. |
| 928 | neteq_->GetAudio(&out_frame_, &muted); |
| 929 | } |
| 930 | |
| 931 | // Check jitter buffer delay. |
| 932 | NetEqLifetimeStatistics stats = neteq_->GetLifetimeStatistics(); |
Artem Titov | e618cc9 | 2020-03-11 11:18:54 +0100 | [diff] [blame] | 933 | EXPECT_EQ(expected_delay, |
| 934 | rtc::checked_cast<int>(stats.jitter_buffer_delay_ms)); |
Chen Xing | 0acffb5 | 2019-01-15 15:46:29 +0100 | [diff] [blame] | 935 | EXPECT_EQ(expected_emitted_count, stats.jitter_buffer_emitted_count); |
Artem Titov | e618cc9 | 2020-03-11 11:18:54 +0100 | [diff] [blame] | 936 | EXPECT_EQ(expected_target_delay, |
| 937 | rtc::checked_cast<int>(stats.jitter_buffer_target_delay_ms)); |
Gustaf Ullberg | b0a0207 | 2017-10-02 12:00:34 +0200 | [diff] [blame] | 938 | } |
| 939 | |
| 940 | TEST_F(NetEqDecodingTestFaxMode, TestJitterBufferDelayWithoutLoss) { |
| 941 | TestJitterBufferDelay(false); |
| 942 | } |
| 943 | |
| 944 | TEST_F(NetEqDecodingTestFaxMode, TestJitterBufferDelayWithLoss) { |
| 945 | TestJitterBufferDelay(true); |
| 946 | } |
| 947 | |
Jakob Ivarsson | 26c59ff | 2019-02-28 09:55:49 +0100 | [diff] [blame] | 948 | TEST_F(NetEqDecodingTestFaxMode, TestJitterBufferDelayWithAcceleration) { |
| 949 | const int kPacketLenMs = 10; // All packets are of 10 ms size. |
| 950 | const size_t kSamples = kPacketLenMs * 16; |
| 951 | const size_t kPayloadBytes = kSamples * 2; |
| 952 | RTPHeader rtp_info; |
| 953 | rtp_info.ssrc = 0x1234; // Just an arbitrary SSRC. |
| 954 | rtp_info.payloadType = 94; // PCM16b WB codec. |
| 955 | rtp_info.markerBit = 0; |
| 956 | const uint8_t payload[kPayloadBytes] = {0}; |
| 957 | |
Artem Titov | e618cc9 | 2020-03-11 11:18:54 +0100 | [diff] [blame] | 958 | int expected_target_delay = neteq_->TargetDelayMs() * kSamples; |
Karl Wiberg | 45eb135 | 2019-10-10 14:23:00 +0200 | [diff] [blame] | 959 | neteq_->InsertPacket(rtp_info, payload); |
Jakob Ivarsson | 26c59ff | 2019-02-28 09:55:49 +0100 | [diff] [blame] | 960 | |
| 961 | bool muted; |
| 962 | neteq_->GetAudio(&out_frame_, &muted); |
| 963 | |
| 964 | rtp_info.sequenceNumber += 1; |
| 965 | rtp_info.timestamp += kSamples; |
Karl Wiberg | 45eb135 | 2019-10-10 14:23:00 +0200 | [diff] [blame] | 966 | neteq_->InsertPacket(rtp_info, payload); |
Jakob Ivarsson | 26c59ff | 2019-02-28 09:55:49 +0100 | [diff] [blame] | 967 | rtp_info.sequenceNumber += 1; |
| 968 | rtp_info.timestamp += kSamples; |
Karl Wiberg | 45eb135 | 2019-10-10 14:23:00 +0200 | [diff] [blame] | 969 | neteq_->InsertPacket(rtp_info, payload); |
Jakob Ivarsson | 26c59ff | 2019-02-28 09:55:49 +0100 | [diff] [blame] | 970 | |
Artem Titov | e618cc9 | 2020-03-11 11:18:54 +0100 | [diff] [blame] | 971 | expected_target_delay += neteq_->TargetDelayMs() * 2 * kSamples; |
Jakob Ivarsson | 26c59ff | 2019-02-28 09:55:49 +0100 | [diff] [blame] | 972 | // We have two packets in the buffer and kAccelerate operation will |
| 973 | // extract 20 ms of data. |
Tommi | 3cc68ec | 2021-06-09 19:30:41 +0200 | [diff] [blame] | 974 | neteq_->GetAudio(&out_frame_, &muted, nullptr, NetEq::Operation::kAccelerate); |
Jakob Ivarsson | 26c59ff | 2019-02-28 09:55:49 +0100 | [diff] [blame] | 975 | |
| 976 | // Check jitter buffer delay. |
| 977 | NetEqLifetimeStatistics stats = neteq_->GetLifetimeStatistics(); |
| 978 | EXPECT_EQ(10 * kSamples * 3, stats.jitter_buffer_delay_ms); |
| 979 | EXPECT_EQ(kSamples * 3, stats.jitter_buffer_emitted_count); |
Artem Titov | e618cc9 | 2020-03-11 11:18:54 +0100 | [diff] [blame] | 980 | EXPECT_EQ(expected_target_delay, |
| 981 | rtc::checked_cast<int>(stats.jitter_buffer_target_delay_ms)); |
Jakob Ivarsson | 26c59ff | 2019-02-28 09:55:49 +0100 | [diff] [blame] | 982 | } |
| 983 | |
Henrik Lundin | 7687ad5 | 2018-07-02 10:14:46 +0200 | [diff] [blame] | 984 | namespace test { |
Henrik Lundin | 7687ad5 | 2018-07-02 10:14:46 +0200 | [diff] [blame] | 985 | TEST(NetEqNoTimeStretchingMode, RunTest) { |
| 986 | NetEq::Config config; |
| 987 | config.for_test_no_time_stretching = true; |
| 988 | auto codecs = NetEqTest::StandardDecoderMap(); |
Henrik Lundin | 7687ad5 | 2018-07-02 10:14:46 +0200 | [diff] [blame] | 989 | NetEqPacketSourceInput::RtpHeaderExtensionMap rtp_ext_map = { |
| 990 | {1, kRtpExtensionAudioLevel}, |
| 991 | {3, kRtpExtensionAbsoluteSendTime}, |
| 992 | {5, kRtpExtensionTransportSequenceNumber}, |
| 993 | {7, kRtpExtensionVideoContentType}, |
| 994 | {8, kRtpExtensionVideoTiming}}; |
| 995 | std::unique_ptr<NetEqInput> input(new NetEqRtpDumpInput( |
| 996 | webrtc::test::ResourcePath("audio_coding/neteq_universal_new", "rtp"), |
Bjorn Terelius | 5350d1c | 2018-10-11 16:51:23 +0200 | [diff] [blame] | 997 | rtp_ext_map, absl::nullopt /*No SSRC filter*/)); |
Henrik Lundin | 7687ad5 | 2018-07-02 10:14:46 +0200 | [diff] [blame] | 998 | std::unique_ptr<TimeLimitedNetEqInput> input_time_limit( |
| 999 | new TimeLimitedNetEqInput(std::move(input), 20000)); |
| 1000 | std::unique_ptr<AudioSink> output(new VoidAudioSink); |
| 1001 | NetEqTest::Callbacks callbacks; |
Ivo Creusen | cee751a | 2020-01-16 17:17:09 +0100 | [diff] [blame] | 1002 | NetEqTest test(config, CreateBuiltinAudioDecoderFactory(), codecs, |
| 1003 | /*text_log=*/nullptr, /*neteq_factory=*/nullptr, |
| 1004 | /*input=*/std::move(input_time_limit), std::move(output), |
| 1005 | callbacks); |
Henrik Lundin | 7687ad5 | 2018-07-02 10:14:46 +0200 | [diff] [blame] | 1006 | test.Run(); |
| 1007 | const auto stats = test.SimulationStats(); |
| 1008 | EXPECT_EQ(0, stats.accelerate_rate); |
| 1009 | EXPECT_EQ(0, stats.preemptive_rate); |
| 1010 | } |
Henrik Lundin | 7687ad5 | 2018-07-02 10:14:46 +0200 | [diff] [blame] | 1011 | |
| 1012 | } // namespace test |
henrik.lundin@webrtc.org | e7ce437 | 2014-01-09 14:01:55 +0000 | [diff] [blame] | 1013 | } // namespace webrtc |