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