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" |
Ivo Creusen | 3ce44a3 | 2019-10-31 14:38:11 +0100 | [diff] [blame] | 26 | #include "api/test/neteq_factory_with_codecs.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 27 | #include "modules/audio_coding/codecs/pcm16b/pcm16b.h" |
| 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" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 31 | #include "modules/audio_coding/neteq/tools/rtp_file_source.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 32 | #include "modules/include/module_common_types_public.h" |
Niels Möller | 53382cb | 2018-11-27 14:05:08 +0100 | [diff] [blame] | 33 | #include "modules/rtp_rtcp/include/rtcp_statistics.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 34 | #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 35 | #include "rtc_base/ignore_wundef.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 36 | #include "rtc_base/message_digest.h" |
Karl Wiberg | e40468b | 2017-11-22 10:42:26 +0100 | [diff] [blame] | 37 | #include "rtc_base/numerics/safe_conversions.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 38 | #include "rtc_base/string_encode.h" |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame] | 39 | #include "rtc_base/strings/string_builder.h" |
Niels Möller | a12c42a | 2018-07-25 16:05:48 +0200 | [diff] [blame] | 40 | #include "rtc_base/system/arch.h" |
Alessio Bazzica | 8f319a3 | 2019-07-24 16:47:02 +0000 | [diff] [blame] | 41 | #include "system_wrappers/include/clock.h" |
Henrik Lundin | e9619f8 | 2017-11-27 14:05:27 +0100 | [diff] [blame] | 42 | #include "test/field_trial.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 43 | #include "test/gtest.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 44 | #include "test/testsupport/file_utils.h" |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 45 | |
minyue | 5f026d0 | 2015-12-16 07:36:04 -0800 | [diff] [blame] | 46 | #ifdef WEBRTC_NETEQ_UNITTEST_BITEXACT |
kwiberg | 77eab70 | 2016-09-28 17:42:01 -0700 | [diff] [blame] | 47 | RTC_PUSH_IGNORING_WUNDEF() |
minyue | 5f026d0 | 2015-12-16 07:36:04 -0800 | [diff] [blame] | 48 | #ifdef WEBRTC_ANDROID_PLATFORM_BUILD |
| 49 | #include "external/webrtc/webrtc/modules/audio_coding/neteq/neteq_unittest.pb.h" |
| 50 | #else |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 51 | #include "modules/audio_coding/neteq/neteq_unittest.pb.h" |
minyue | 5f026d0 | 2015-12-16 07:36:04 -0800 | [diff] [blame] | 52 | #endif |
kwiberg | 77eab70 | 2016-09-28 17:42:01 -0700 | [diff] [blame] | 53 | RTC_POP_IGNORING_WUNDEF() |
minyue | 5f026d0 | 2015-12-16 07:36:04 -0800 | [diff] [blame] | 54 | #endif |
| 55 | |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 56 | ABSL_FLAG(bool, gen_ref, false, "Generate reference files."); |
turaj@webrtc.org | a6101d7 | 2013-10-01 22:01:09 +0000 | [diff] [blame] | 57 | |
kwiberg | 5adaf73 | 2016-10-04 09:33:27 -0700 | [diff] [blame] | 58 | namespace webrtc { |
| 59 | |
minyue | 5f026d0 | 2015-12-16 07:36:04 -0800 | [diff] [blame] | 60 | namespace { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 61 | |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 62 | const std::string& PlatformChecksum(const std::string& checksum_general, |
Henrik Lundin | 8cd750d | 2017-10-12 13:07:11 +0200 | [diff] [blame] | 63 | const std::string& checksum_android_32, |
| 64 | const std::string& checksum_android_64, |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 65 | const std::string& checksum_win_32, |
| 66 | const std::string& checksum_win_64) { |
kwiberg | 77eab70 | 2016-09-28 17:42:01 -0700 | [diff] [blame] | 67 | #if defined(WEBRTC_ANDROID) |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 68 | #ifdef WEBRTC_ARCH_64_BITS |
| 69 | return checksum_android_64; |
| 70 | #else |
| 71 | return checksum_android_32; |
| 72 | #endif // WEBRTC_ARCH_64_BITS |
kwiberg | 77eab70 | 2016-09-28 17:42:01 -0700 | [diff] [blame] | 73 | #elif defined(WEBRTC_WIN) |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 74 | #ifdef WEBRTC_ARCH_64_BITS |
| 75 | return checksum_win_64; |
| 76 | #else |
| 77 | return checksum_win_32; |
| 78 | #endif // WEBRTC_ARCH_64_BITS |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 79 | #else |
| 80 | return checksum_general; |
| 81 | #endif // WEBRTC_WIN |
| 82 | } |
| 83 | |
minyue | 5f026d0 | 2015-12-16 07:36:04 -0800 | [diff] [blame] | 84 | #ifdef WEBRTC_NETEQ_UNITTEST_BITEXACT |
| 85 | void Convert(const webrtc::NetEqNetworkStatistics& stats_raw, |
| 86 | webrtc::neteq_unittest::NetEqNetworkStatistics* stats) { |
| 87 | stats->set_current_buffer_size_ms(stats_raw.current_buffer_size_ms); |
| 88 | stats->set_preferred_buffer_size_ms(stats_raw.preferred_buffer_size_ms); |
| 89 | stats->set_jitter_peaks_found(stats_raw.jitter_peaks_found); |
| 90 | stats->set_packet_loss_rate(stats_raw.packet_loss_rate); |
minyue | 5f026d0 | 2015-12-16 07:36:04 -0800 | [diff] [blame] | 91 | stats->set_expand_rate(stats_raw.expand_rate); |
| 92 | stats->set_speech_expand_rate(stats_raw.speech_expand_rate); |
| 93 | stats->set_preemptive_rate(stats_raw.preemptive_rate); |
| 94 | stats->set_accelerate_rate(stats_raw.accelerate_rate); |
| 95 | stats->set_secondary_decoded_rate(stats_raw.secondary_decoded_rate); |
minyue-webrtc | 0c3ca75 | 2017-08-23 15:59:38 +0200 | [diff] [blame] | 96 | stats->set_secondary_discarded_rate(stats_raw.secondary_discarded_rate); |
minyue | 5f026d0 | 2015-12-16 07:36:04 -0800 | [diff] [blame] | 97 | stats->set_added_zero_samples(stats_raw.added_zero_samples); |
| 98 | stats->set_mean_waiting_time_ms(stats_raw.mean_waiting_time_ms); |
| 99 | stats->set_median_waiting_time_ms(stats_raw.median_waiting_time_ms); |
| 100 | stats->set_min_waiting_time_ms(stats_raw.min_waiting_time_ms); |
| 101 | stats->set_max_waiting_time_ms(stats_raw.max_waiting_time_ms); |
| 102 | } |
| 103 | |
| 104 | void Convert(const webrtc::RtcpStatistics& stats_raw, |
| 105 | webrtc::neteq_unittest::RtcpStatistics* stats) { |
| 106 | stats->set_fraction_lost(stats_raw.fraction_lost); |
srte | 186d9c3 | 2017-08-04 05:03:53 -0700 | [diff] [blame] | 107 | stats->set_cumulative_lost(stats_raw.packets_lost); |
minyue | 5f026d0 | 2015-12-16 07:36:04 -0800 | [diff] [blame] | 108 | stats->set_extended_max_sequence_number( |
srte | 186d9c3 | 2017-08-04 05:03:53 -0700 | [diff] [blame] | 109 | stats_raw.extended_highest_sequence_number); |
minyue | 5f026d0 | 2015-12-16 07:36:04 -0800 | [diff] [blame] | 110 | stats->set_jitter(stats_raw.jitter); |
| 111 | } |
| 112 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 113 | void AddMessage(FILE* file, |
| 114 | rtc::MessageDigest* digest, |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 115 | const std::string& message) { |
minyue | 5f026d0 | 2015-12-16 07:36:04 -0800 | [diff] [blame] | 116 | int32_t size = message.length(); |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 117 | if (file) |
| 118 | ASSERT_EQ(1u, fwrite(&size, sizeof(size), 1, file)); |
| 119 | digest->Update(&size, sizeof(size)); |
| 120 | |
| 121 | if (file) |
| 122 | ASSERT_EQ(static_cast<size_t>(size), |
| 123 | fwrite(message.data(), sizeof(char), size, file)); |
| 124 | digest->Update(message.data(), sizeof(char) * size); |
minyue | 5f026d0 | 2015-12-16 07:36:04 -0800 | [diff] [blame] | 125 | } |
| 126 | |
minyue | 5f026d0 | 2015-12-16 07:36:04 -0800 | [diff] [blame] | 127 | #endif // WEBRTC_NETEQ_UNITTEST_BITEXACT |
| 128 | |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 129 | void LoadDecoders(webrtc::NetEq* neteq) { |
kwiberg | 5adaf73 | 2016-10-04 09:33:27 -0700 | [diff] [blame] | 130 | ASSERT_EQ(true, |
| 131 | neteq->RegisterPayloadType(0, SdpAudioFormat("pcmu", 8000, 1))); |
Niels Möller | 0554368 | 2019-01-10 16:55:06 +0100 | [diff] [blame] | 132 | ASSERT_EQ(true, |
| 133 | neteq->RegisterPayloadType(8, SdpAudioFormat("pcma", 8000, 1))); |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 134 | #ifdef WEBRTC_CODEC_ILBC |
kwiberg | 5adaf73 | 2016-10-04 09:33:27 -0700 | [diff] [blame] | 135 | ASSERT_EQ(true, |
| 136 | neteq->RegisterPayloadType(102, SdpAudioFormat("ilbc", 8000, 1))); |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 137 | #endif |
| 138 | #if defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX) |
kwiberg | 5adaf73 | 2016-10-04 09:33:27 -0700 | [diff] [blame] | 139 | ASSERT_EQ(true, |
| 140 | neteq->RegisterPayloadType(103, SdpAudioFormat("isac", 16000, 1))); |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 141 | #endif |
| 142 | #ifdef WEBRTC_CODEC_ISAC |
kwiberg | 5adaf73 | 2016-10-04 09:33:27 -0700 | [diff] [blame] | 143 | ASSERT_EQ(true, |
| 144 | neteq->RegisterPayloadType(104, SdpAudioFormat("isac", 32000, 1))); |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 145 | #endif |
| 146 | #ifdef WEBRTC_CODEC_OPUS |
kwiberg | 5adaf73 | 2016-10-04 09:33:27 -0700 | [diff] [blame] | 147 | ASSERT_EQ(true, |
| 148 | neteq->RegisterPayloadType( |
| 149 | 111, SdpAudioFormat("opus", 48000, 2, {{"stereo", "0"}}))); |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 150 | #endif |
kwiberg | 5adaf73 | 2016-10-04 09:33:27 -0700 | [diff] [blame] | 151 | ASSERT_EQ(true, |
| 152 | neteq->RegisterPayloadType(93, SdpAudioFormat("L16", 8000, 1))); |
| 153 | ASSERT_EQ(true, |
| 154 | neteq->RegisterPayloadType(94, SdpAudioFormat("L16", 16000, 1))); |
| 155 | ASSERT_EQ(true, |
| 156 | neteq->RegisterPayloadType(95, SdpAudioFormat("L16", 32000, 1))); |
| 157 | ASSERT_EQ(true, |
| 158 | neteq->RegisterPayloadType(13, SdpAudioFormat("cn", 8000, 1))); |
| 159 | ASSERT_EQ(true, |
| 160 | neteq->RegisterPayloadType(98, SdpAudioFormat("cn", 16000, 1))); |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 161 | } |
minyue | 5f026d0 | 2015-12-16 07:36:04 -0800 | [diff] [blame] | 162 | } // namespace |
| 163 | |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 164 | class ResultSink { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 165 | public: |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 166 | explicit ResultSink(const std::string& output_file); |
| 167 | ~ResultSink(); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 168 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 169 | template <typename T> |
| 170 | void AddResult(const T* test_results, size_t length); |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 171 | |
| 172 | void AddResult(const NetEqNetworkStatistics& stats); |
| 173 | void AddResult(const RtcpStatistics& stats); |
| 174 | |
| 175 | void VerifyChecksum(const std::string& ref_check_sum); |
| 176 | |
| 177 | private: |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 178 | FILE* output_fp_; |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 179 | std::unique_ptr<rtc::MessageDigest> digest_; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 180 | }; |
| 181 | |
Joachim Bauch | 4e90919 | 2017-12-19 22:27:51 +0100 | [diff] [blame] | 182 | ResultSink::ResultSink(const std::string& output_file) |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 183 | : output_fp_(nullptr), |
Joachim Bauch | 4e90919 | 2017-12-19 22:27:51 +0100 | [diff] [blame] | 184 | digest_(rtc::MessageDigestFactory::Create(rtc::DIGEST_SHA_1)) { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 185 | if (!output_file.empty()) { |
| 186 | output_fp_ = fopen(output_file.c_str(), "wb"); |
| 187 | EXPECT_TRUE(output_fp_ != NULL); |
| 188 | } |
| 189 | } |
| 190 | |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 191 | ResultSink::~ResultSink() { |
| 192 | if (output_fp_) |
| 193 | fclose(output_fp_); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 194 | } |
| 195 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 196 | template <typename T> |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 197 | void ResultSink::AddResult(const T* test_results, size_t length) { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 198 | if (output_fp_) { |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 199 | ASSERT_EQ(length, fwrite(test_results, sizeof(T), length, output_fp_)); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 200 | } |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 201 | digest_->Update(test_results, sizeof(T) * length); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 202 | } |
| 203 | |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 204 | void ResultSink::AddResult(const NetEqNetworkStatistics& stats_raw) { |
minyue | 5f026d0 | 2015-12-16 07:36:04 -0800 | [diff] [blame] | 205 | #ifdef WEBRTC_NETEQ_UNITTEST_BITEXACT |
minyue | 5f026d0 | 2015-12-16 07:36:04 -0800 | [diff] [blame] | 206 | neteq_unittest::NetEqNetworkStatistics stats; |
| 207 | Convert(stats_raw, &stats); |
| 208 | |
Mirko Bonadei | e45c688 | 2019-02-16 09:59:29 +0100 | [diff] [blame] | 209 | std::string stats_string; |
minyue | 5f026d0 | 2015-12-16 07:36:04 -0800 | [diff] [blame] | 210 | ASSERT_TRUE(stats.SerializeToString(&stats_string)); |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 211 | AddMessage(output_fp_, digest_.get(), stats_string); |
minyue | 5f026d0 | 2015-12-16 07:36:04 -0800 | [diff] [blame] | 212 | #else |
| 213 | FAIL() << "Writing to reference file requires Proto Buffer."; |
| 214 | #endif // WEBRTC_NETEQ_UNITTEST_BITEXACT |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 215 | } |
| 216 | |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 217 | void ResultSink::AddResult(const RtcpStatistics& stats_raw) { |
minyue | 5f026d0 | 2015-12-16 07:36:04 -0800 | [diff] [blame] | 218 | #ifdef WEBRTC_NETEQ_UNITTEST_BITEXACT |
minyue | 5f026d0 | 2015-12-16 07:36:04 -0800 | [diff] [blame] | 219 | neteq_unittest::RtcpStatistics stats; |
| 220 | Convert(stats_raw, &stats); |
| 221 | |
Mirko Bonadei | e45c688 | 2019-02-16 09:59:29 +0100 | [diff] [blame] | 222 | std::string stats_string; |
minyue | 5f026d0 | 2015-12-16 07:36:04 -0800 | [diff] [blame] | 223 | ASSERT_TRUE(stats.SerializeToString(&stats_string)); |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 224 | AddMessage(output_fp_, digest_.get(), stats_string); |
minyue | 5f026d0 | 2015-12-16 07:36:04 -0800 | [diff] [blame] | 225 | #else |
| 226 | FAIL() << "Writing to reference file requires Proto Buffer."; |
| 227 | #endif // WEBRTC_NETEQ_UNITTEST_BITEXACT |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 228 | } |
| 229 | |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 230 | void ResultSink::VerifyChecksum(const std::string& checksum) { |
| 231 | std::vector<char> buffer; |
| 232 | buffer.resize(digest_->Size()); |
| 233 | digest_->Finish(&buffer[0], buffer.size()); |
| 234 | const std::string result = rtc::hex_encode(&buffer[0], digest_->Size()); |
Yves Gerey | a038e71 | 2018-11-14 10:45:50 +0100 | [diff] [blame] | 235 | if (checksum.size() == result.size()) { |
| 236 | EXPECT_EQ(checksum, result); |
| 237 | } else { |
| 238 | // Check result is one the '|'-separated checksums. |
| 239 | EXPECT_NE(checksum.find(result), std::string::npos) |
| 240 | << result << " should be one of these:\n" |
| 241 | << checksum; |
| 242 | } |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | class NetEqDecodingTest : public ::testing::Test { |
| 246 | protected: |
| 247 | // NetEQ must be polled for data once every 10 ms. Thus, neither of the |
| 248 | // constants below can be changed. |
| 249 | static const int kTimeStepMs = 10; |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 250 | static const size_t kBlockSize8kHz = kTimeStepMs * 8; |
| 251 | static const size_t kBlockSize16kHz = kTimeStepMs * 16; |
| 252 | static const size_t kBlockSize32kHz = kTimeStepMs * 32; |
minyue | 93c08b7 | 2015-12-22 09:57:41 -0800 | [diff] [blame] | 253 | static const size_t kBlockSize48kHz = kTimeStepMs * 48; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 254 | static const int kInitSampleRateHz = 8000; |
| 255 | |
| 256 | NetEqDecodingTest(); |
| 257 | virtual void SetUp(); |
| 258 | virtual void TearDown(); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 259 | void OpenInputFile(const std::string& rtp_file); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 260 | void Process(); |
minyue | 5f026d0 | 2015-12-16 07:36:04 -0800 | [diff] [blame] | 261 | |
henrik.lundin@webrtc.org | 4e4b098 | 2014-08-11 14:48:49 +0000 | [diff] [blame] | 262 | void DecodeAndCompare(const std::string& rtp_file, |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 263 | const std::string& output_checksum, |
| 264 | const std::string& network_stats_checksum, |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 265 | bool gen_ref); |
minyue | 5f026d0 | 2015-12-16 07:36:04 -0800 | [diff] [blame] | 266 | |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 267 | static void PopulateRtpInfo(int frame_index, |
| 268 | int timestamp, |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 269 | RTPHeader* rtp_info); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 270 | static void PopulateCng(int frame_index, |
| 271 | int timestamp, |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 272 | RTPHeader* rtp_info, |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 273 | uint8_t* payload, |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 274 | size_t* payload_len); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 275 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 276 | void WrapTest(uint16_t start_seq_no, |
| 277 | uint32_t start_timestamp, |
turaj@webrtc.org | 78b41a0 | 2013-11-22 20:27:07 +0000 | [diff] [blame] | 278 | const std::set<uint16_t>& drop_seq_numbers, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 279 | bool expect_seq_no_wrap, |
| 280 | bool expect_timestamp_wrap); |
turaj@webrtc.org | 78b41a0 | 2013-11-22 20:27:07 +0000 | [diff] [blame] | 281 | |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 282 | void LongCngWithClockDrift(double drift_factor, |
| 283 | double network_freeze_ms, |
| 284 | bool pull_audio_during_freeze, |
| 285 | int delay_tolerance_ms, |
| 286 | int max_time_to_speech_ms); |
| 287 | |
henrik.lundin@webrtc.org | ca8cb95 | 2014-03-12 10:26:52 +0000 | [diff] [blame] | 288 | void DuplicateCng(); |
henrik.lundin@webrtc.org | fcfc6a9 | 2014-02-13 11:42:28 +0000 | [diff] [blame] | 289 | |
Alessio Bazzica | 8f319a3 | 2019-07-24 16:47:02 +0000 | [diff] [blame] | 290 | SimulatedClock clock_; |
Ivo Creusen | 3ce44a3 | 2019-10-31 14:38:11 +0100 | [diff] [blame] | 291 | std::unique_ptr<NetEq> neteq_; |
henrik.lundin@webrtc.org | ea25784 | 2014-08-07 12:27:37 +0000 | [diff] [blame] | 292 | NetEq::Config config_; |
kwiberg | 2d0c332 | 2016-02-14 09:28:33 -0800 | [diff] [blame] | 293 | std::unique_ptr<test::RtpFileSource> rtp_source_; |
| 294 | std::unique_ptr<test::Packet> packet_; |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 295 | AudioFrame out_frame_; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 296 | int output_sample_rate_; |
turaj@webrtc.org | 8d1cdaa | 2014-04-11 18:47:55 +0000 | [diff] [blame] | 297 | int algorithmic_delay_ms_; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 298 | }; |
| 299 | |
| 300 | // Allocating the static const so that it can be passed by reference. |
| 301 | const int NetEqDecodingTest::kTimeStepMs; |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 302 | const size_t NetEqDecodingTest::kBlockSize8kHz; |
| 303 | const size_t NetEqDecodingTest::kBlockSize16kHz; |
| 304 | const size_t NetEqDecodingTest::kBlockSize32kHz; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 305 | const int NetEqDecodingTest::kInitSampleRateHz; |
| 306 | |
| 307 | NetEqDecodingTest::NetEqDecodingTest() |
Alessio Bazzica | 8f319a3 | 2019-07-24 16:47:02 +0000 | [diff] [blame] | 308 | : clock_(0), |
henrik.lundin@webrtc.org | ea25784 | 2014-08-07 12:27:37 +0000 | [diff] [blame] | 309 | config_(), |
turaj@webrtc.org | 8d1cdaa | 2014-04-11 18:47:55 +0000 | [diff] [blame] | 310 | output_sample_rate_(kInitSampleRateHz), |
| 311 | algorithmic_delay_ms_(0) { |
henrik.lundin@webrtc.org | ea25784 | 2014-08-07 12:27:37 +0000 | [diff] [blame] | 312 | config_.sample_rate_hz = kInitSampleRateHz; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | void NetEqDecodingTest::SetUp() { |
Ivo Creusen | 3ce44a3 | 2019-10-31 14:38:11 +0100 | [diff] [blame] | 316 | std::unique_ptr<NetEqFactory> neteq_factory = CreateNetEqFactoryWithCodecs(); |
| 317 | neteq_ = neteq_factory->CreateNetEq(config_, &clock_); |
turaj@webrtc.org | 8d1cdaa | 2014-04-11 18:47:55 +0000 | [diff] [blame] | 318 | NetEqNetworkStatistics stat; |
| 319 | ASSERT_EQ(0, neteq_->NetworkStatistics(&stat)); |
| 320 | algorithmic_delay_ms_ = stat.current_buffer_size_ms; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 321 | ASSERT_TRUE(neteq_); |
Ivo Creusen | 3ce44a3 | 2019-10-31 14:38:11 +0100 | [diff] [blame] | 322 | LoadDecoders(neteq_.get()); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 323 | } |
| 324 | |
Ivo Creusen | 3ce44a3 | 2019-10-31 14:38:11 +0100 | [diff] [blame] | 325 | void NetEqDecodingTest::TearDown() {} |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 326 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 327 | void NetEqDecodingTest::OpenInputFile(const std::string& rtp_file) { |
henrik.lundin@webrtc.org | 966a708 | 2014-11-17 09:08:38 +0000 | [diff] [blame] | 328 | rtp_source_.reset(test::RtpFileSource::Create(rtp_file)); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 329 | } |
| 330 | |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 331 | void NetEqDecodingTest::Process() { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 332 | // Check if time to receive. |
Alessio Bazzica | 8f319a3 | 2019-07-24 16:47:02 +0000 | [diff] [blame] | 333 | while (packet_ && clock_.TimeInMilliseconds() >= packet_->time_ms()) { |
henrik.lundin@webrtc.org | 966a708 | 2014-11-17 09:08:38 +0000 | [diff] [blame] | 334 | if (packet_->payload_length_bytes() > 0) { |
ivoc | 72c08ed | 2016-01-20 07:26:24 -0800 | [diff] [blame] | 335 | #ifndef WEBRTC_CODEC_ISAC |
| 336 | // Ignore payload type 104 (iSAC-swb) if ISAC is not supported. |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 337 | if (packet_->header().payloadType != 104) |
ivoc | 72c08ed | 2016-01-20 07:26:24 -0800 | [diff] [blame] | 338 | #endif |
Karl Wiberg | 45eb135 | 2019-10-10 14:23:00 +0200 | [diff] [blame] | 339 | ASSERT_EQ( |
| 340 | 0, neteq_->InsertPacket( |
| 341 | packet_->header(), |
| 342 | rtc::ArrayView<const uint8_t>( |
| 343 | packet_->payload(), packet_->payload_length_bytes()))); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 344 | } |
| 345 | // Get next packet. |
henrik.lundin | 46ba49c | 2016-05-24 22:50:47 -0700 | [diff] [blame] | 346 | packet_ = rtp_source_->NextPacket(); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 347 | } |
| 348 | |
henrik.lundin@webrtc.org | e1d468c | 2013-01-30 07:37:20 +0000 | [diff] [blame] | 349 | // Get audio from NetEq. |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 350 | bool muted; |
| 351 | ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); |
| 352 | ASSERT_FALSE(muted); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 353 | ASSERT_TRUE((out_frame_.samples_per_channel_ == kBlockSize8kHz) || |
| 354 | (out_frame_.samples_per_channel_ == kBlockSize16kHz) || |
| 355 | (out_frame_.samples_per_channel_ == kBlockSize32kHz) || |
| 356 | (out_frame_.samples_per_channel_ == kBlockSize48kHz)); |
| 357 | output_sample_rate_ = out_frame_.sample_rate_hz_; |
henrik.lundin | d89814b | 2015-11-23 06:49:25 -0800 | [diff] [blame] | 358 | EXPECT_EQ(output_sample_rate_, neteq_->last_output_sample_rate_hz()); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 359 | |
| 360 | // Increase time. |
Alessio Bazzica | 8f319a3 | 2019-07-24 16:47:02 +0000 | [diff] [blame] | 361 | clock_.AdvanceTimeMilliseconds(kTimeStepMs); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 362 | } |
| 363 | |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 364 | void NetEqDecodingTest::DecodeAndCompare( |
| 365 | const std::string& rtp_file, |
| 366 | const std::string& output_checksum, |
| 367 | const std::string& network_stats_checksum, |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 368 | bool gen_ref) { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 369 | OpenInputFile(rtp_file); |
| 370 | |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 371 | std::string ref_out_file = |
| 372 | gen_ref ? webrtc::test::OutputPath() + "neteq_universal_ref.pcm" : ""; |
| 373 | ResultSink output(ref_out_file); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 374 | |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 375 | std::string stat_out_file = |
| 376 | gen_ref ? webrtc::test::OutputPath() + "neteq_network_stats.dat" : ""; |
| 377 | ResultSink network_stats(stat_out_file); |
henrik.lundin@webrtc.org | 4e4b098 | 2014-08-11 14:48:49 +0000 | [diff] [blame] | 378 | |
henrik.lundin | 46ba49c | 2016-05-24 22:50:47 -0700 | [diff] [blame] | 379 | packet_ = rtp_source_->NextPacket(); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 380 | int i = 0; |
Henrik Lundin | ac0a503 | 2017-09-25 12:22:46 +0200 | [diff] [blame] | 381 | uint64_t last_concealed_samples = 0; |
| 382 | uint64_t last_total_samples_received = 0; |
henrik.lundin@webrtc.org | 966a708 | 2014-11-17 09:08:38 +0000 | [diff] [blame] | 383 | while (packet_) { |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame] | 384 | rtc::StringBuilder ss; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 385 | ss << "Lap number " << i++ << " in DecodeAndCompare while loop"; |
| 386 | SCOPED_TRACE(ss.str()); // Print out the parameter values on failure. |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 387 | ASSERT_NO_FATAL_FAILURE(Process()); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 388 | ASSERT_NO_FATAL_FAILURE( |
| 389 | output.AddResult(out_frame_.data(), out_frame_.samples_per_channel_)); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 390 | |
| 391 | // Query the network statistics API once per second |
Alessio Bazzica | 8f319a3 | 2019-07-24 16:47:02 +0000 | [diff] [blame] | 392 | if (clock_.TimeInMilliseconds() % 1000 == 0) { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 393 | // Process NetworkStatistics. |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 394 | NetEqNetworkStatistics current_network_stats; |
| 395 | ASSERT_EQ(0, neteq_->NetworkStatistics(¤t_network_stats)); |
| 396 | ASSERT_NO_FATAL_FAILURE(network_stats.AddResult(current_network_stats)); |
| 397 | |
Henrik Lundin | ac0a503 | 2017-09-25 12:22:46 +0200 | [diff] [blame] | 398 | // Verify that liftime stats and network stats report similar loss |
| 399 | // concealment rates. |
| 400 | auto lifetime_stats = neteq_->GetLifetimeStatistics(); |
| 401 | const uint64_t delta_concealed_samples = |
| 402 | lifetime_stats.concealed_samples - last_concealed_samples; |
| 403 | last_concealed_samples = lifetime_stats.concealed_samples; |
| 404 | const uint64_t delta_total_samples_received = |
| 405 | lifetime_stats.total_samples_received - last_total_samples_received; |
| 406 | last_total_samples_received = lifetime_stats.total_samples_received; |
| 407 | // The tolerance is 1% but expressed in Q14. |
| 408 | EXPECT_NEAR( |
| 409 | (delta_concealed_samples << 14) / delta_total_samples_received, |
| 410 | current_network_stats.expand_rate, (2 << 14) / 100.0); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 411 | } |
| 412 | } |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 413 | |
| 414 | SCOPED_TRACE("Check output audio."); |
| 415 | output.VerifyChecksum(output_checksum); |
| 416 | SCOPED_TRACE("Check network stats."); |
| 417 | network_stats.VerifyChecksum(network_stats_checksum); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | void NetEqDecodingTest::PopulateRtpInfo(int frame_index, |
| 421 | int timestamp, |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 422 | RTPHeader* rtp_info) { |
| 423 | rtp_info->sequenceNumber = frame_index; |
| 424 | rtp_info->timestamp = timestamp; |
| 425 | rtp_info->ssrc = 0x1234; // Just an arbitrary SSRC. |
| 426 | rtp_info->payloadType = 94; // PCM16b WB codec. |
| 427 | rtp_info->markerBit = 0; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | void NetEqDecodingTest::PopulateCng(int frame_index, |
| 431 | int timestamp, |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 432 | RTPHeader* rtp_info, |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 433 | uint8_t* payload, |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 434 | size_t* payload_len) { |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 435 | rtp_info->sequenceNumber = frame_index; |
| 436 | rtp_info->timestamp = timestamp; |
| 437 | rtp_info->ssrc = 0x1234; // Just an arbitrary SSRC. |
| 438 | rtp_info->payloadType = 98; // WB CNG. |
| 439 | rtp_info->markerBit = 0; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 440 | payload[0] = 64; // Noise level -64 dBov, quite arbitrarily chosen. |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 441 | *payload_len = 1; // Only noise level, no spectral parameters. |
| 442 | } |
| 443 | |
ivoc | 72c08ed | 2016-01-20 07:26:24 -0800 | [diff] [blame] | 444 | #if !defined(WEBRTC_IOS) && defined(WEBRTC_NETEQ_UNITTEST_BITEXACT) && \ |
| 445 | (defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX)) && \ |
Karl Wiberg | eb254b4 | 2017-11-01 15:08:12 +0100 | [diff] [blame] | 446 | defined(WEBRTC_CODEC_ILBC) && !defined(WEBRTC_ARCH_ARM64) |
minyue | 5f026d0 | 2015-12-16 07:36:04 -0800 | [diff] [blame] | 447 | #define MAYBE_TestBitExactness TestBitExactness |
kwiberg | 98ab3a4 | 2015-09-30 21:54:21 -0700 | [diff] [blame] | 448 | #else |
minyue | 5f026d0 | 2015-12-16 07:36:04 -0800 | [diff] [blame] | 449 | #define MAYBE_TestBitExactness DISABLED_TestBitExactness |
kwiberg | 98ab3a4 | 2015-09-30 21:54:21 -0700 | [diff] [blame] | 450 | #endif |
minyue | 5f026d0 | 2015-12-16 07:36:04 -0800 | [diff] [blame] | 451 | TEST_F(NetEqDecodingTest, MAYBE_TestBitExactness) { |
minyue | 49c454e | 2016-01-08 11:30:14 -0800 | [diff] [blame] | 452 | const std::string input_rtp_file = |
| 453 | webrtc::test::ResourcePath("audio_coding/neteq_universal_new", "rtp"); |
henrik.lundin@webrtc.org | 4e4b098 | 2014-08-11 14:48:49 +0000 | [diff] [blame] | 454 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 455 | const std::string output_checksum = |
Jakob Ivarsson | 507f434 | 2019-09-03 13:04:41 +0200 | [diff] [blame] | 456 | PlatformChecksum("6ae9f643dc3e5f3452d28a772eef7e00e74158bc", |
| 457 | "f4374430e870d66268c1b8e22fb700eb072d567e", "not used", |
| 458 | "6ae9f643dc3e5f3452d28a772eef7e00e74158bc", |
| 459 | "8d73c98645917cdeaaa01c20cf095ccc5a10b2b5"); |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 460 | |
henrik.lundin | 2979f55 | 2017-05-05 05:04:16 -0700 | [diff] [blame] | 461 | const std::string network_stats_checksum = |
Jakob Ivarsson | 507f434 | 2019-09-03 13:04:41 +0200 | [diff] [blame] | 462 | PlatformChecksum("3d186ea7e243abfdbd3d39b8ebf8f02a318117e4", |
| 463 | "0b725774133da5dd823f2046663c12a76e0dbd79", "not used", |
| 464 | "3d186ea7e243abfdbd3d39b8ebf8f02a318117e4", |
| 465 | "3d186ea7e243abfdbd3d39b8ebf8f02a318117e4"); |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 466 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 467 | DecodeAndCompare(input_rtp_file, output_checksum, network_stats_checksum, |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 468 | absl::GetFlag(FLAGS_gen_ref)); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 469 | } |
| 470 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 471 | #if !defined(WEBRTC_IOS) && defined(WEBRTC_NETEQ_UNITTEST_BITEXACT) && \ |
minyue-webrtc | 516711c | 2017-07-27 17:45:49 +0200 | [diff] [blame] | 472 | defined(WEBRTC_CODEC_OPUS) |
minyue | 93c08b7 | 2015-12-22 09:57:41 -0800 | [diff] [blame] | 473 | #define MAYBE_TestOpusBitExactness TestOpusBitExactness |
| 474 | #else |
| 475 | #define MAYBE_TestOpusBitExactness DISABLED_TestOpusBitExactness |
| 476 | #endif |
minyue-webrtc | adb58b8 | 2017-07-26 17:59:59 +0200 | [diff] [blame] | 477 | TEST_F(NetEqDecodingTest, MAYBE_TestOpusBitExactness) { |
minyue | 93c08b7 | 2015-12-22 09:57:41 -0800 | [diff] [blame] | 478 | const std::string input_rtp_file = |
| 479 | webrtc::test::ResourcePath("audio_coding/neteq_opus", "rtp"); |
minyue | 93c08b7 | 2015-12-22 09:57:41 -0800 | [diff] [blame] | 480 | |
Yves Gerey | a038e71 | 2018-11-14 10:45:50 +0100 | [diff] [blame] | 481 | // Checksum depends on libopus being compiled with or without SSE. |
| 482 | const std::string maybe_sse = |
Jakob Ivarsson | a36c591 | 2019-06-27 10:12:02 +0200 | [diff] [blame] | 483 | "6b602683ca7285a98118b4824d72f4257952c18f|" |
| 484 | "eb0b68bddcac00fc85403df64f83126f8ea9bc93"; |
Yves Gerey | a038e71 | 2018-11-14 10:45:50 +0100 | [diff] [blame] | 485 | const std::string output_checksum = PlatformChecksum( |
Yves Gerey | 75e2290 | 2019-09-06 03:07:55 +0200 | [diff] [blame] | 486 | maybe_sse, "f95f2a220c9ca5d60b81c4653d46e0de2bee159f", |
| 487 | "6f288a03d34958f62496f18fa85655593eef4dbe", maybe_sse, maybe_sse); |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 488 | |
Yves Gerey | 75e2290 | 2019-09-06 03:07:55 +0200 | [diff] [blame] | 489 | const std::string network_stats_checksum = |
| 490 | PlatformChecksum("87d2d3e5ca7f1b3fb7a501ffaa51ae29aea74544", |
| 491 | "6b8c29e39c82f5479f59726744d0cf3e88e725d3", |
| 492 | "c876f2a04c4f0a91da7f084f80e87871b7c5a4a1", |
| 493 | "87d2d3e5ca7f1b3fb7a501ffaa51ae29aea74544", |
| 494 | "87d2d3e5ca7f1b3fb7a501ffaa51ae29aea74544"); |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 495 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 496 | DecodeAndCompare(input_rtp_file, output_checksum, network_stats_checksum, |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 497 | absl::GetFlag(FLAGS_gen_ref)); |
minyue | 93c08b7 | 2015-12-22 09:57:41 -0800 | [diff] [blame] | 498 | } |
| 499 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 500 | #if !defined(WEBRTC_IOS) && defined(WEBRTC_NETEQ_UNITTEST_BITEXACT) && \ |
Henrik Lundin | e9619f8 | 2017-11-27 14:05:27 +0100 | [diff] [blame] | 501 | defined(WEBRTC_CODEC_OPUS) |
| 502 | #define MAYBE_TestOpusDtxBitExactness TestOpusDtxBitExactness |
| 503 | #else |
| 504 | #define MAYBE_TestOpusDtxBitExactness DISABLED_TestOpusDtxBitExactness |
| 505 | #endif |
Henrik Lundin | 4f2a4a1 | 2018-01-26 17:32:56 +0100 | [diff] [blame] | 506 | TEST_F(NetEqDecodingTest, MAYBE_TestOpusDtxBitExactness) { |
Henrik Lundin | e9619f8 | 2017-11-27 14:05:27 +0100 | [diff] [blame] | 507 | const std::string input_rtp_file = |
| 508 | webrtc::test::ResourcePath("audio_coding/neteq_opus_dtx", "rtp"); |
| 509 | |
Yves Gerey | a038e71 | 2018-11-14 10:45:50 +0100 | [diff] [blame] | 510 | const std::string maybe_sse = |
Minyue Li | 8e83c7a | 2019-11-04 14:47:52 +0100 | [diff] [blame] | 511 | "0bdeb4ccf95a2577e38274360903ad099fc46787|" |
| 512 | "f7bbf5d92a0595a2a3445ffbaddfb20e98b6e94e"; |
Yves Gerey | a038e71 | 2018-11-14 10:45:50 +0100 | [diff] [blame] | 513 | const std::string output_checksum = PlatformChecksum( |
Minyue Li | 8e83c7a | 2019-11-04 14:47:52 +0100 | [diff] [blame] | 514 | maybe_sse, "6d200cc51a001b6137abf67db2bb8eeb0375cdee", |
| 515 | "36d43761de86b12520cf2e63f97372a2b7c6f939", maybe_sse, maybe_sse); |
Henrik Lundin | e9619f8 | 2017-11-27 14:05:27 +0100 | [diff] [blame] | 516 | |
| 517 | const std::string network_stats_checksum = |
Jakob Ivarsson | 65024d9 | 2019-08-30 15:37:07 +0200 | [diff] [blame] | 518 | "8caf49765f35b6862066d3f17531ce44d8e25f60"; |
Henrik Lundin | e9619f8 | 2017-11-27 14:05:27 +0100 | [diff] [blame] | 519 | |
Henrik Lundin | e9619f8 | 2017-11-27 14:05:27 +0100 | [diff] [blame] | 520 | DecodeAndCompare(input_rtp_file, output_checksum, network_stats_checksum, |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 521 | absl::GetFlag(FLAGS_gen_ref)); |
Henrik Lundin | e9619f8 | 2017-11-27 14:05:27 +0100 | [diff] [blame] | 522 | } |
| 523 | |
henrik.lundin@webrtc.org | 7cbc4f9 | 2014-10-07 06:37:39 +0000 | [diff] [blame] | 524 | // Use fax mode to avoid time-scaling. This is to simplify the testing of |
| 525 | // packet waiting times in the packet buffer. |
| 526 | class NetEqDecodingTestFaxMode : public NetEqDecodingTest { |
| 527 | protected: |
| 528 | NetEqDecodingTestFaxMode() : NetEqDecodingTest() { |
Henrik Lundin | 7687ad5 | 2018-07-02 10:14:46 +0200 | [diff] [blame] | 529 | config_.for_test_no_time_stretching = true; |
henrik.lundin@webrtc.org | 7cbc4f9 | 2014-10-07 06:37:39 +0000 | [diff] [blame] | 530 | } |
Gustaf Ullberg | b0a0207 | 2017-10-02 12:00:34 +0200 | [diff] [blame] | 531 | void TestJitterBufferDelay(bool apply_packet_loss); |
henrik.lundin@webrtc.org | 7cbc4f9 | 2014-10-07 06:37:39 +0000 | [diff] [blame] | 532 | }; |
| 533 | |
| 534 | TEST_F(NetEqDecodingTestFaxMode, TestFrameWaitingTimeStatistics) { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 535 | // Insert 30 dummy packets at once. Each packet contains 10 ms 16 kHz audio. |
| 536 | size_t num_frames = 30; |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 537 | const size_t kSamples = 10 * 16; |
| 538 | const size_t kPayloadBytes = kSamples * 2; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 539 | for (size_t i = 0; i < num_frames; ++i) { |
kwiberg | ee2bac2 | 2015-11-11 10:34:00 -0800 | [diff] [blame] | 540 | const uint8_t payload[kPayloadBytes] = {0}; |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 541 | RTPHeader rtp_info; |
Mirko Bonadei | a811027 | 2017-10-18 14:22:50 +0200 | [diff] [blame] | 542 | rtp_info.sequenceNumber = rtc::checked_cast<uint16_t>(i); |
| 543 | rtp_info.timestamp = rtc::checked_cast<uint32_t>(i * kSamples); |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 544 | rtp_info.ssrc = 0x1234; // Just an arbitrary SSRC. |
| 545 | rtp_info.payloadType = 94; // PCM16b WB codec. |
| 546 | rtp_info.markerBit = 0; |
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 | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 548 | } |
| 549 | // Pull out all data. |
| 550 | for (size_t i = 0; i < num_frames; ++i) { |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 551 | bool muted; |
| 552 | ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 553 | ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 554 | } |
| 555 | |
Henrik Lundin | 1bb8cf8 | 2015-08-25 13:08:04 +0200 | [diff] [blame] | 556 | NetEqNetworkStatistics stats; |
| 557 | EXPECT_EQ(0, neteq_->NetworkStatistics(&stats)); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 558 | // Since all frames are dumped into NetEQ at once, but pulled out with 10 ms |
| 559 | // 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] | 560 | // each packet. Thus, we are calculating the statistics for a series from 10 |
| 561 | // to 300, in steps of 10 ms. |
| 562 | EXPECT_EQ(155, stats.mean_waiting_time_ms); |
| 563 | EXPECT_EQ(155, stats.median_waiting_time_ms); |
| 564 | EXPECT_EQ(10, stats.min_waiting_time_ms); |
| 565 | EXPECT_EQ(300, stats.max_waiting_time_ms); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 566 | |
| 567 | // Check statistics again and make sure it's been reset. |
Henrik Lundin | 1bb8cf8 | 2015-08-25 13:08:04 +0200 | [diff] [blame] | 568 | EXPECT_EQ(0, neteq_->NetworkStatistics(&stats)); |
| 569 | EXPECT_EQ(-1, stats.mean_waiting_time_ms); |
| 570 | EXPECT_EQ(-1, stats.median_waiting_time_ms); |
| 571 | EXPECT_EQ(-1, stats.min_waiting_time_ms); |
| 572 | EXPECT_EQ(-1, stats.max_waiting_time_ms); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 573 | } |
| 574 | |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 575 | void NetEqDecodingTest::LongCngWithClockDrift(double drift_factor, |
| 576 | double network_freeze_ms, |
| 577 | bool pull_audio_during_freeze, |
| 578 | int delay_tolerance_ms, |
| 579 | int max_time_to_speech_ms) { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 580 | uint16_t seq_no = 0; |
| 581 | uint32_t timestamp = 0; |
| 582 | const int kFrameSizeMs = 30; |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 583 | const size_t kSamples = kFrameSizeMs * 16; |
| 584 | const size_t kPayloadBytes = kSamples * 2; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 585 | double next_input_time_ms = 0.0; |
| 586 | double t_ms; |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 587 | bool muted; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 588 | |
| 589 | // Insert speech for 5 seconds. |
| 590 | const int kSpeechDurationMs = 5000; |
| 591 | for (t_ms = 0; t_ms < kSpeechDurationMs; t_ms += 10) { |
| 592 | // Each turn in this for loop is 10 ms. |
| 593 | while (next_input_time_ms <= t_ms) { |
| 594 | // Insert one 30 ms speech frame. |
| 595 | uint8_t payload[kPayloadBytes] = {0}; |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 596 | RTPHeader rtp_info; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 597 | PopulateRtpInfo(seq_no, timestamp, &rtp_info); |
Karl Wiberg | 45eb135 | 2019-10-10 14:23:00 +0200 | [diff] [blame] | 598 | ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload)); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 599 | ++seq_no; |
| 600 | timestamp += kSamples; |
henrik.lundin@webrtc.org | fcfc6a9 | 2014-02-13 11:42:28 +0000 | [diff] [blame] | 601 | next_input_time_ms += static_cast<double>(kFrameSizeMs) * drift_factor; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 602 | } |
| 603 | // Pull out data once. |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 604 | ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 605 | ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 606 | } |
| 607 | |
henrik.lundin | 55480f5 | 2016-03-08 02:37:57 -0800 | [diff] [blame] | 608 | EXPECT_EQ(AudioFrame::kNormalSpeech, out_frame_.speech_type_); |
Danil Chapovalov | b602123 | 2018-06-19 13:26:36 +0200 | [diff] [blame] | 609 | absl::optional<uint32_t> playout_timestamp = neteq_->GetPlayoutTimestamp(); |
henrik.lundin | 0d96ab7 | 2016-04-06 12:28:26 -0700 | [diff] [blame] | 610 | ASSERT_TRUE(playout_timestamp); |
| 611 | int32_t delay_before = timestamp - *playout_timestamp; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 612 | |
| 613 | // Insert CNG for 1 minute (= 60000 ms). |
| 614 | const int kCngPeriodMs = 100; |
| 615 | const int kCngPeriodSamples = kCngPeriodMs * 16; // Period in 16 kHz samples. |
| 616 | const int kCngDurationMs = 60000; |
| 617 | for (; t_ms < kSpeechDurationMs + kCngDurationMs; t_ms += 10) { |
| 618 | // Each turn in this for loop is 10 ms. |
| 619 | while (next_input_time_ms <= t_ms) { |
| 620 | // Insert one CNG frame each 100 ms. |
| 621 | uint8_t payload[kPayloadBytes]; |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 622 | size_t payload_len; |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 623 | RTPHeader rtp_info; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 624 | PopulateCng(seq_no, timestamp, &rtp_info, payload, &payload_len); |
Karl Wiberg | 45eb135 | 2019-10-10 14:23:00 +0200 | [diff] [blame] | 625 | ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, rtc::ArrayView<const uint8_t>( |
| 626 | payload, payload_len))); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 627 | ++seq_no; |
| 628 | timestamp += kCngPeriodSamples; |
henrik.lundin@webrtc.org | fcfc6a9 | 2014-02-13 11:42:28 +0000 | [diff] [blame] | 629 | next_input_time_ms += static_cast<double>(kCngPeriodMs) * drift_factor; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 630 | } |
| 631 | // Pull out data once. |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 632 | ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 633 | ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 634 | } |
| 635 | |
henrik.lundin | 55480f5 | 2016-03-08 02:37:57 -0800 | [diff] [blame] | 636 | EXPECT_EQ(AudioFrame::kCNG, out_frame_.speech_type_); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 637 | |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 638 | if (network_freeze_ms > 0) { |
| 639 | // First keep pulling audio for |network_freeze_ms| without inserting |
| 640 | // any data, then insert CNG data corresponding to |network_freeze_ms| |
| 641 | // without pulling any output audio. |
| 642 | const double loop_end_time = t_ms + network_freeze_ms; |
| 643 | for (; t_ms < loop_end_time; t_ms += 10) { |
| 644 | // Pull out data once. |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 645 | ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 646 | ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); |
henrik.lundin | 55480f5 | 2016-03-08 02:37:57 -0800 | [diff] [blame] | 647 | EXPECT_EQ(AudioFrame::kCNG, out_frame_.speech_type_); |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 648 | } |
| 649 | bool pull_once = pull_audio_during_freeze; |
| 650 | // If |pull_once| is true, GetAudio will be called once half-way through |
| 651 | // the network recovery period. |
| 652 | double pull_time_ms = (t_ms + next_input_time_ms) / 2; |
| 653 | while (next_input_time_ms <= t_ms) { |
| 654 | if (pull_once && next_input_time_ms >= pull_time_ms) { |
| 655 | pull_once = false; |
| 656 | // Pull out data once. |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 657 | ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 658 | ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); |
henrik.lundin | 55480f5 | 2016-03-08 02:37:57 -0800 | [diff] [blame] | 659 | EXPECT_EQ(AudioFrame::kCNG, out_frame_.speech_type_); |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 660 | t_ms += 10; |
| 661 | } |
| 662 | // Insert one CNG frame each 100 ms. |
| 663 | uint8_t payload[kPayloadBytes]; |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 664 | size_t payload_len; |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 665 | RTPHeader rtp_info; |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 666 | PopulateCng(seq_no, timestamp, &rtp_info, payload, &payload_len); |
Karl Wiberg | 45eb135 | 2019-10-10 14:23:00 +0200 | [diff] [blame] | 667 | ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, rtc::ArrayView<const uint8_t>( |
| 668 | payload, payload_len))); |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 669 | ++seq_no; |
| 670 | timestamp += kCngPeriodSamples; |
| 671 | next_input_time_ms += kCngPeriodMs * drift_factor; |
| 672 | } |
| 673 | } |
| 674 | |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 675 | // Insert speech again until output type is speech. |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 676 | double speech_restart_time_ms = t_ms; |
henrik.lundin | 55480f5 | 2016-03-08 02:37:57 -0800 | [diff] [blame] | 677 | while (out_frame_.speech_type_ != AudioFrame::kNormalSpeech) { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 678 | // Each turn in this for loop is 10 ms. |
| 679 | while (next_input_time_ms <= t_ms) { |
| 680 | // Insert one 30 ms speech frame. |
| 681 | uint8_t payload[kPayloadBytes] = {0}; |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 682 | RTPHeader rtp_info; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 683 | PopulateRtpInfo(seq_no, timestamp, &rtp_info); |
Karl Wiberg | 45eb135 | 2019-10-10 14:23:00 +0200 | [diff] [blame] | 684 | ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload)); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 685 | ++seq_no; |
| 686 | timestamp += kSamples; |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 687 | next_input_time_ms += kFrameSizeMs * drift_factor; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 688 | } |
| 689 | // Pull out data once. |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 690 | ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 691 | ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 692 | // Increase clock. |
| 693 | t_ms += 10; |
| 694 | } |
| 695 | |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 696 | // Check that the speech starts again within reasonable time. |
| 697 | double time_until_speech_returns_ms = t_ms - speech_restart_time_ms; |
| 698 | EXPECT_LT(time_until_speech_returns_ms, max_time_to_speech_ms); |
henrik.lundin | 114c1b3 | 2017-04-26 07:47:32 -0700 | [diff] [blame] | 699 | playout_timestamp = neteq_->GetPlayoutTimestamp(); |
henrik.lundin | 0d96ab7 | 2016-04-06 12:28:26 -0700 | [diff] [blame] | 700 | ASSERT_TRUE(playout_timestamp); |
| 701 | int32_t delay_after = timestamp - *playout_timestamp; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 702 | // Compare delay before and after, and make sure it differs less than 20 ms. |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 703 | EXPECT_LE(delay_after, delay_before + delay_tolerance_ms * 16); |
| 704 | EXPECT_GE(delay_after, delay_before - delay_tolerance_ms * 16); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 705 | } |
| 706 | |
henrik.lundin@webrtc.org | b4e80e0 | 2014-05-15 07:14:00 +0000 | [diff] [blame] | 707 | TEST_F(NetEqDecodingTest, LongCngWithNegativeClockDrift) { |
henrik.lundin@webrtc.org | fcfc6a9 | 2014-02-13 11:42:28 +0000 | [diff] [blame] | 708 | // Apply a clock drift of -25 ms / s (sender faster than receiver). |
| 709 | const double kDriftFactor = 1000.0 / (1000.0 + 25.0); |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 710 | const double kNetworkFreezeTimeMs = 0.0; |
| 711 | const bool kGetAudioDuringFreezeRecovery = false; |
| 712 | const int kDelayToleranceMs = 20; |
| 713 | const int kMaxTimeToSpeechMs = 100; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 714 | LongCngWithClockDrift(kDriftFactor, kNetworkFreezeTimeMs, |
| 715 | kGetAudioDuringFreezeRecovery, kDelayToleranceMs, |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 716 | kMaxTimeToSpeechMs); |
henrik.lundin@webrtc.org | fcfc6a9 | 2014-02-13 11:42:28 +0000 | [diff] [blame] | 717 | } |
| 718 | |
henrik.lundin@webrtc.org | b4e80e0 | 2014-05-15 07:14:00 +0000 | [diff] [blame] | 719 | TEST_F(NetEqDecodingTest, LongCngWithPositiveClockDrift) { |
henrik.lundin@webrtc.org | fcfc6a9 | 2014-02-13 11:42:28 +0000 | [diff] [blame] | 720 | // Apply a clock drift of +25 ms / s (sender slower than receiver). |
| 721 | const double kDriftFactor = 1000.0 / (1000.0 - 25.0); |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 722 | const double kNetworkFreezeTimeMs = 0.0; |
| 723 | const bool kGetAudioDuringFreezeRecovery = false; |
Jakob Ivarsson | 507f434 | 2019-09-03 13:04:41 +0200 | [diff] [blame] | 724 | const int kDelayToleranceMs = 40; |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 725 | const int kMaxTimeToSpeechMs = 100; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 726 | LongCngWithClockDrift(kDriftFactor, kNetworkFreezeTimeMs, |
| 727 | kGetAudioDuringFreezeRecovery, kDelayToleranceMs, |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 728 | kMaxTimeToSpeechMs); |
| 729 | } |
| 730 | |
henrik.lundin@webrtc.org | b4e80e0 | 2014-05-15 07:14:00 +0000 | [diff] [blame] | 731 | TEST_F(NetEqDecodingTest, LongCngWithNegativeClockDriftNetworkFreeze) { |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 732 | // Apply a clock drift of -25 ms / s (sender faster than receiver). |
| 733 | const double kDriftFactor = 1000.0 / (1000.0 + 25.0); |
| 734 | const double kNetworkFreezeTimeMs = 5000.0; |
| 735 | const bool kGetAudioDuringFreezeRecovery = false; |
Jakob Ivarsson | a36c591 | 2019-06-27 10:12:02 +0200 | [diff] [blame] | 736 | const int kDelayToleranceMs = 60; |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 737 | const int kMaxTimeToSpeechMs = 200; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 738 | LongCngWithClockDrift(kDriftFactor, kNetworkFreezeTimeMs, |
| 739 | kGetAudioDuringFreezeRecovery, kDelayToleranceMs, |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 740 | kMaxTimeToSpeechMs); |
| 741 | } |
| 742 | |
henrik.lundin@webrtc.org | b4e80e0 | 2014-05-15 07:14:00 +0000 | [diff] [blame] | 743 | TEST_F(NetEqDecodingTest, LongCngWithPositiveClockDriftNetworkFreeze) { |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 744 | // Apply a clock drift of +25 ms / s (sender slower than receiver). |
| 745 | const double kDriftFactor = 1000.0 / (1000.0 - 25.0); |
| 746 | const double kNetworkFreezeTimeMs = 5000.0; |
| 747 | const bool kGetAudioDuringFreezeRecovery = false; |
Jakob Ivarsson | 507f434 | 2019-09-03 13:04:41 +0200 | [diff] [blame] | 748 | const int kDelayToleranceMs = 40; |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 749 | const int kMaxTimeToSpeechMs = 100; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 750 | LongCngWithClockDrift(kDriftFactor, kNetworkFreezeTimeMs, |
| 751 | kGetAudioDuringFreezeRecovery, kDelayToleranceMs, |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 752 | kMaxTimeToSpeechMs); |
| 753 | } |
| 754 | |
henrik.lundin@webrtc.org | b4e80e0 | 2014-05-15 07:14:00 +0000 | [diff] [blame] | 755 | TEST_F(NetEqDecodingTest, LongCngWithPositiveClockDriftNetworkFreezeExtraPull) { |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 756 | // Apply a clock drift of +25 ms / s (sender slower than receiver). |
| 757 | const double kDriftFactor = 1000.0 / (1000.0 - 25.0); |
| 758 | const double kNetworkFreezeTimeMs = 5000.0; |
| 759 | const bool kGetAudioDuringFreezeRecovery = true; |
Jakob Ivarsson | 507f434 | 2019-09-03 13:04:41 +0200 | [diff] [blame] | 760 | const int kDelayToleranceMs = 40; |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 761 | const int kMaxTimeToSpeechMs = 100; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 762 | LongCngWithClockDrift(kDriftFactor, kNetworkFreezeTimeMs, |
| 763 | kGetAudioDuringFreezeRecovery, kDelayToleranceMs, |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 764 | kMaxTimeToSpeechMs); |
| 765 | } |
| 766 | |
henrik.lundin@webrtc.org | b4e80e0 | 2014-05-15 07:14:00 +0000 | [diff] [blame] | 767 | TEST_F(NetEqDecodingTest, LongCngWithoutClockDrift) { |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 768 | const double kDriftFactor = 1.0; // No drift. |
| 769 | const double kNetworkFreezeTimeMs = 0.0; |
| 770 | const bool kGetAudioDuringFreezeRecovery = false; |
| 771 | const int kDelayToleranceMs = 10; |
| 772 | const int kMaxTimeToSpeechMs = 50; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 773 | LongCngWithClockDrift(kDriftFactor, kNetworkFreezeTimeMs, |
| 774 | kGetAudioDuringFreezeRecovery, kDelayToleranceMs, |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 775 | kMaxTimeToSpeechMs); |
henrik.lundin@webrtc.org | fcfc6a9 | 2014-02-13 11:42:28 +0000 | [diff] [blame] | 776 | } |
| 777 | |
henrik.lundin@webrtc.org | b4e80e0 | 2014-05-15 07:14:00 +0000 | [diff] [blame] | 778 | TEST_F(NetEqDecodingTest, UnknownPayloadType) { |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 779 | const size_t kPayloadBytes = 100; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 780 | uint8_t payload[kPayloadBytes] = {0}; |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 781 | RTPHeader rtp_info; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 782 | PopulateRtpInfo(0, 0, &rtp_info); |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 783 | rtp_info.payloadType = 1; // Not registered as a decoder. |
Karl Wiberg | 45eb135 | 2019-10-10 14:23:00 +0200 | [diff] [blame] | 784 | EXPECT_EQ(NetEq::kFail, neteq_->InsertPacket(rtp_info, payload)); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 785 | } |
| 786 | |
Peter Boström | e2976c8 | 2016-01-04 22:44:05 +0100 | [diff] [blame] | 787 | #if defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX) |
ivoc | 72c08ed | 2016-01-20 07:26:24 -0800 | [diff] [blame] | 788 | #define MAYBE_DecoderError DecoderError |
| 789 | #else |
| 790 | #define MAYBE_DecoderError DISABLED_DecoderError |
| 791 | #endif |
| 792 | |
Peter Boström | e2976c8 | 2016-01-04 22:44:05 +0100 | [diff] [blame] | 793 | TEST_F(NetEqDecodingTest, MAYBE_DecoderError) { |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 794 | const size_t kPayloadBytes = 100; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 795 | uint8_t payload[kPayloadBytes] = {0}; |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 796 | RTPHeader rtp_info; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 797 | PopulateRtpInfo(0, 0, &rtp_info); |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 798 | rtp_info.payloadType = 103; // iSAC, but the payload is invalid. |
Karl Wiberg | 45eb135 | 2019-10-10 14:23:00 +0200 | [diff] [blame] | 799 | EXPECT_EQ(0, neteq_->InsertPacket(rtp_info, payload)); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 800 | // Set all of |out_data_| to 1, and verify that it was set to 0 by the call |
| 801 | // to GetAudio. |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 802 | int16_t* out_frame_data = out_frame_.mutable_data(); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 803 | for (size_t i = 0; i < AudioFrame::kMaxDataSizeSamples; ++i) { |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 804 | out_frame_data[i] = 1; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 805 | } |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 806 | bool muted; |
| 807 | EXPECT_EQ(NetEq::kFail, neteq_->GetAudio(&out_frame_, &muted)); |
| 808 | ASSERT_FALSE(muted); |
ivoc | 72c08ed | 2016-01-20 07:26:24 -0800 | [diff] [blame] | 809 | |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 810 | // Verify that the first 160 samples are set to 0. |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 811 | static const int kExpectedOutputLength = 160; // 10 ms at 16 kHz sample rate. |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 812 | const int16_t* const_out_frame_data = out_frame_.data(); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 813 | for (int i = 0; i < kExpectedOutputLength; ++i) { |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame] | 814 | rtc::StringBuilder ss; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 815 | ss << "i = " << i; |
| 816 | SCOPED_TRACE(ss.str()); // Print out the parameter values on failure. |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 817 | EXPECT_EQ(0, const_out_frame_data[i]); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 818 | } |
| 819 | } |
| 820 | |
henrik.lundin@webrtc.org | b4e80e0 | 2014-05-15 07:14:00 +0000 | [diff] [blame] | 821 | TEST_F(NetEqDecodingTest, GetAudioBeforeInsertPacket) { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 822 | // Set all of |out_data_| to 1, and verify that it was set to 0 by the call |
| 823 | // to GetAudio. |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 824 | int16_t* out_frame_data = out_frame_.mutable_data(); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 825 | for (size_t i = 0; i < AudioFrame::kMaxDataSizeSamples; ++i) { |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 826 | out_frame_data[i] = 1; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 827 | } |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 828 | bool muted; |
| 829 | EXPECT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); |
| 830 | ASSERT_FALSE(muted); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 831 | // Verify that the first block of samples is set to 0. |
| 832 | static const int kExpectedOutputLength = |
| 833 | kInitSampleRateHz / 100; // 10 ms at initial sample rate. |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 834 | const int16_t* const_out_frame_data = out_frame_.data(); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 835 | for (int i = 0; i < kExpectedOutputLength; ++i) { |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame] | 836 | rtc::StringBuilder ss; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 837 | ss << "i = " << i; |
| 838 | SCOPED_TRACE(ss.str()); // Print out the parameter values on failure. |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 839 | EXPECT_EQ(0, const_out_frame_data[i]); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 840 | } |
henrik.lundin | d89814b | 2015-11-23 06:49:25 -0800 | [diff] [blame] | 841 | // Verify that the sample rate did not change from the initial configuration. |
| 842 | 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] | 843 | } |
turaj@webrtc.org | ff43c85 | 2013-09-25 00:07:27 +0000 | [diff] [blame] | 844 | |
henrik.lundin@webrtc.org | 9b8102c | 2014-08-21 08:27:44 +0000 | [diff] [blame] | 845 | class NetEqBgnTest : public NetEqDecodingTest { |
henrik.lundin@webrtc.org | ea25784 | 2014-08-07 12:27:37 +0000 | [diff] [blame] | 846 | protected: |
henrik.lundin@webrtc.org | 9b8102c | 2014-08-21 08:27:44 +0000 | [diff] [blame] | 847 | void CheckBgn(int sampling_rate_hz) { |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 848 | size_t expected_samples_per_channel = 0; |
henrik.lundin@webrtc.org | ea25784 | 2014-08-07 12:27:37 +0000 | [diff] [blame] | 849 | uint8_t payload_type = 0xFF; // Invalid. |
| 850 | if (sampling_rate_hz == 8000) { |
| 851 | expected_samples_per_channel = kBlockSize8kHz; |
| 852 | payload_type = 93; // PCM 16, 8 kHz. |
| 853 | } else if (sampling_rate_hz == 16000) { |
| 854 | expected_samples_per_channel = kBlockSize16kHz; |
| 855 | payload_type = 94; // PCM 16, 16 kHZ. |
| 856 | } else if (sampling_rate_hz == 32000) { |
| 857 | expected_samples_per_channel = kBlockSize32kHz; |
| 858 | payload_type = 95; // PCM 16, 32 kHz. |
| 859 | } else { |
| 860 | ASSERT_TRUE(false); // Unsupported test case. |
| 861 | } |
turaj@webrtc.org | ff43c85 | 2013-09-25 00:07:27 +0000 | [diff] [blame] | 862 | |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 863 | AudioFrame output; |
henrik.lundin@webrtc.org | 9b8102c | 2014-08-21 08:27:44 +0000 | [diff] [blame] | 864 | test::AudioLoop input; |
| 865 | // We are using the same 32 kHz input file for all tests, regardless of |
| 866 | // |sampling_rate_hz|. The output may sound weird, but the test is still |
| 867 | // valid. |
| 868 | ASSERT_TRUE(input.Init( |
| 869 | webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm"), |
| 870 | 10 * sampling_rate_hz, // Max 10 seconds loop length. |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 871 | expected_samples_per_channel)); |
henrik.lundin@webrtc.org | ea25784 | 2014-08-07 12:27:37 +0000 | [diff] [blame] | 872 | |
| 873 | // Payload of 10 ms of PCM16 32 kHz. |
| 874 | uint8_t payload[kBlockSize32kHz * sizeof(int16_t)]; |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 875 | RTPHeader rtp_info; |
henrik.lundin@webrtc.org | ea25784 | 2014-08-07 12:27:37 +0000 | [diff] [blame] | 876 | PopulateRtpInfo(0, 0, &rtp_info); |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 877 | rtp_info.payloadType = payload_type; |
henrik.lundin@webrtc.org | ea25784 | 2014-08-07 12:27:37 +0000 | [diff] [blame] | 878 | |
henrik.lundin@webrtc.org | ea25784 | 2014-08-07 12:27:37 +0000 | [diff] [blame] | 879 | uint32_t receive_timestamp = 0; |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 880 | bool muted; |
henrik.lundin@webrtc.org | ea25784 | 2014-08-07 12:27:37 +0000 | [diff] [blame] | 881 | for (int n = 0; n < 10; ++n) { // Insert few packets and get audio. |
kwiberg | 288886b | 2015-11-06 01:21:35 -0800 | [diff] [blame] | 882 | auto block = input.GetNextBlock(); |
| 883 | ASSERT_EQ(expected_samples_per_channel, block.size()); |
| 884 | size_t enc_len_bytes = |
| 885 | WebRtcPcm16b_Encode(block.data(), block.size(), payload); |
henrik.lundin@webrtc.org | 9b8102c | 2014-08-21 08:27:44 +0000 | [diff] [blame] | 886 | ASSERT_EQ(enc_len_bytes, expected_samples_per_channel * 2); |
| 887 | |
Karl Wiberg | 45eb135 | 2019-10-10 14:23:00 +0200 | [diff] [blame] | 888 | ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, rtc::ArrayView<const uint8_t>( |
| 889 | payload, enc_len_bytes))); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 890 | output.Reset(); |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 891 | ASSERT_EQ(0, neteq_->GetAudio(&output, &muted)); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 892 | ASSERT_EQ(1u, output.num_channels_); |
| 893 | ASSERT_EQ(expected_samples_per_channel, output.samples_per_channel_); |
henrik.lundin | 55480f5 | 2016-03-08 02:37:57 -0800 | [diff] [blame] | 894 | ASSERT_EQ(AudioFrame::kNormalSpeech, output.speech_type_); |
henrik.lundin@webrtc.org | ea25784 | 2014-08-07 12:27:37 +0000 | [diff] [blame] | 895 | |
| 896 | // Next packet. |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 897 | rtp_info.timestamp += |
| 898 | rtc::checked_cast<uint32_t>(expected_samples_per_channel); |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 899 | rtp_info.sequenceNumber++; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 900 | receive_timestamp += |
| 901 | rtc::checked_cast<uint32_t>(expected_samples_per_channel); |
henrik.lundin@webrtc.org | ea25784 | 2014-08-07 12:27:37 +0000 | [diff] [blame] | 902 | } |
| 903 | |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 904 | output.Reset(); |
henrik.lundin@webrtc.org | ea25784 | 2014-08-07 12:27:37 +0000 | [diff] [blame] | 905 | |
| 906 | // Get audio without inserting packets, expecting PLC and PLC-to-CNG. Pull |
| 907 | // one frame without checking speech-type. This is the first frame pulled |
| 908 | // without inserting any packet, and might not be labeled as PLC. |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 909 | ASSERT_EQ(0, neteq_->GetAudio(&output, &muted)); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 910 | ASSERT_EQ(1u, output.num_channels_); |
| 911 | ASSERT_EQ(expected_samples_per_channel, output.samples_per_channel_); |
henrik.lundin@webrtc.org | ea25784 | 2014-08-07 12:27:37 +0000 | [diff] [blame] | 912 | |
| 913 | // To be able to test the fading of background noise we need at lease to |
| 914 | // pull 611 frames. |
| 915 | const int kFadingThreshold = 611; |
| 916 | |
| 917 | // Test several CNG-to-PLC packet for the expected behavior. The number 20 |
| 918 | // is arbitrary, but sufficiently large to test enough number of frames. |
| 919 | const int kNumPlcToCngTestFrames = 20; |
| 920 | bool plc_to_cng = false; |
| 921 | for (int n = 0; n < kFadingThreshold + kNumPlcToCngTestFrames; ++n) { |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 922 | output.Reset(); |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 923 | // Set to non-zero. |
| 924 | memset(output.mutable_data(), 1, AudioFrame::kMaxDataSizeBytes); |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 925 | ASSERT_EQ(0, neteq_->GetAudio(&output, &muted)); |
| 926 | ASSERT_FALSE(muted); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 927 | ASSERT_EQ(1u, output.num_channels_); |
| 928 | ASSERT_EQ(expected_samples_per_channel, output.samples_per_channel_); |
henrik.lundin | 55480f5 | 2016-03-08 02:37:57 -0800 | [diff] [blame] | 929 | if (output.speech_type_ == AudioFrame::kPLCCNG) { |
henrik.lundin@webrtc.org | ea25784 | 2014-08-07 12:27:37 +0000 | [diff] [blame] | 930 | plc_to_cng = true; |
| 931 | double sum_squared = 0; |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 932 | const int16_t* output_data = output.data(); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 933 | for (size_t k = 0; |
| 934 | k < output.num_channels_ * output.samples_per_channel_; ++k) |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 935 | sum_squared += output_data[k] * output_data[k]; |
Henrik Lundin | 6719017 | 2018-04-20 15:34:48 +0200 | [diff] [blame] | 936 | EXPECT_EQ(0, sum_squared); |
henrik.lundin@webrtc.org | ea25784 | 2014-08-07 12:27:37 +0000 | [diff] [blame] | 937 | } else { |
henrik.lundin | 55480f5 | 2016-03-08 02:37:57 -0800 | [diff] [blame] | 938 | EXPECT_EQ(AudioFrame::kPLC, output.speech_type_); |
henrik.lundin@webrtc.org | ea25784 | 2014-08-07 12:27:37 +0000 | [diff] [blame] | 939 | } |
| 940 | } |
| 941 | EXPECT_TRUE(plc_to_cng); // Just to be sure that PLC-to-CNG has occurred. |
| 942 | } |
| 943 | }; |
| 944 | |
Henrik Lundin | 6719017 | 2018-04-20 15:34:48 +0200 | [diff] [blame] | 945 | TEST_F(NetEqBgnTest, RunTest) { |
henrik.lundin@webrtc.org | 9b8102c | 2014-08-21 08:27:44 +0000 | [diff] [blame] | 946 | CheckBgn(8000); |
| 947 | CheckBgn(16000); |
| 948 | CheckBgn(32000); |
| 949 | } |
henrik.lundin@webrtc.org | ea25784 | 2014-08-07 12:27:37 +0000 | [diff] [blame] | 950 | |
turaj@webrtc.org | 78b41a0 | 2013-11-22 20:27:07 +0000 | [diff] [blame] | 951 | void NetEqDecodingTest::WrapTest(uint16_t start_seq_no, |
| 952 | uint32_t start_timestamp, |
| 953 | const std::set<uint16_t>& drop_seq_numbers, |
| 954 | bool expect_seq_no_wrap, |
| 955 | bool expect_timestamp_wrap) { |
| 956 | uint16_t seq_no = start_seq_no; |
| 957 | uint32_t timestamp = start_timestamp; |
| 958 | const int kBlocksPerFrame = 3; // Number of 10 ms blocks per frame. |
| 959 | const int kFrameSizeMs = kBlocksPerFrame * kTimeStepMs; |
| 960 | const int kSamples = kBlockSize16kHz * kBlocksPerFrame; |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 961 | const size_t kPayloadBytes = kSamples * sizeof(int16_t); |
turaj@webrtc.org | 78b41a0 | 2013-11-22 20:27:07 +0000 | [diff] [blame] | 962 | double next_input_time_ms = 0.0; |
turaj@webrtc.org | 78b41a0 | 2013-11-22 20:27:07 +0000 | [diff] [blame] | 963 | uint32_t receive_timestamp = 0; |
| 964 | |
henrik.lundin@webrtc.org | ca8cb95 | 2014-03-12 10:26:52 +0000 | [diff] [blame] | 965 | // Insert speech for 2 seconds. |
turaj@webrtc.org | 78b41a0 | 2013-11-22 20:27:07 +0000 | [diff] [blame] | 966 | const int kSpeechDurationMs = 2000; |
| 967 | int packets_inserted = 0; |
| 968 | uint16_t last_seq_no; |
| 969 | uint32_t last_timestamp; |
| 970 | bool timestamp_wrapped = false; |
| 971 | bool seq_no_wrapped = false; |
| 972 | for (double t_ms = 0; t_ms < kSpeechDurationMs; t_ms += 10) { |
| 973 | // Each turn in this for loop is 10 ms. |
| 974 | while (next_input_time_ms <= t_ms) { |
| 975 | // Insert one 30 ms speech frame. |
| 976 | uint8_t payload[kPayloadBytes] = {0}; |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 977 | RTPHeader rtp_info; |
turaj@webrtc.org | 78b41a0 | 2013-11-22 20:27:07 +0000 | [diff] [blame] | 978 | PopulateRtpInfo(seq_no, timestamp, &rtp_info); |
| 979 | if (drop_seq_numbers.find(seq_no) == drop_seq_numbers.end()) { |
| 980 | // This sequence number was not in the set to drop. Insert it. |
Karl Wiberg | 45eb135 | 2019-10-10 14:23:00 +0200 | [diff] [blame] | 981 | ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload)); |
turaj@webrtc.org | 78b41a0 | 2013-11-22 20:27:07 +0000 | [diff] [blame] | 982 | ++packets_inserted; |
| 983 | } |
| 984 | NetEqNetworkStatistics network_stats; |
| 985 | ASSERT_EQ(0, neteq_->NetworkStatistics(&network_stats)); |
| 986 | |
| 987 | // Due to internal NetEq logic, preferred buffer-size is about 4 times the |
| 988 | // packet size for first few packets. Therefore we refrain from checking |
| 989 | // the criteria. |
| 990 | if (packets_inserted > 4) { |
| 991 | // Expect preferred and actual buffer size to be no more than 2 frames. |
| 992 | EXPECT_LE(network_stats.preferred_buffer_size_ms, kFrameSizeMs * 2); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 993 | EXPECT_LE(network_stats.current_buffer_size_ms, |
| 994 | kFrameSizeMs * 2 + algorithmic_delay_ms_); |
turaj@webrtc.org | 78b41a0 | 2013-11-22 20:27:07 +0000 | [diff] [blame] | 995 | } |
| 996 | last_seq_no = seq_no; |
| 997 | last_timestamp = timestamp; |
| 998 | |
| 999 | ++seq_no; |
| 1000 | timestamp += kSamples; |
| 1001 | receive_timestamp += kSamples; |
| 1002 | next_input_time_ms += static_cast<double>(kFrameSizeMs); |
| 1003 | |
| 1004 | seq_no_wrapped |= seq_no < last_seq_no; |
| 1005 | timestamp_wrapped |= timestamp < last_timestamp; |
| 1006 | } |
| 1007 | // Pull out data once. |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 1008 | AudioFrame output; |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 1009 | bool muted; |
| 1010 | ASSERT_EQ(0, neteq_->GetAudio(&output, &muted)); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 1011 | ASSERT_EQ(kBlockSize16kHz, output.samples_per_channel_); |
| 1012 | ASSERT_EQ(1u, output.num_channels_); |
turaj@webrtc.org | 78b41a0 | 2013-11-22 20:27:07 +0000 | [diff] [blame] | 1013 | |
| 1014 | // Expect delay (in samples) to be less than 2 packets. |
Danil Chapovalov | b602123 | 2018-06-19 13:26:36 +0200 | [diff] [blame] | 1015 | absl::optional<uint32_t> playout_timestamp = neteq_->GetPlayoutTimestamp(); |
henrik.lundin | 0d96ab7 | 2016-04-06 12:28:26 -0700 | [diff] [blame] | 1016 | ASSERT_TRUE(playout_timestamp); |
| 1017 | EXPECT_LE(timestamp - *playout_timestamp, |
turaj@webrtc.org | 78b41a0 | 2013-11-22 20:27:07 +0000 | [diff] [blame] | 1018 | static_cast<uint32_t>(kSamples * 2)); |
turaj@webrtc.org | 78b41a0 | 2013-11-22 20:27:07 +0000 | [diff] [blame] | 1019 | } |
| 1020 | // Make sure we have actually tested wrap-around. |
| 1021 | ASSERT_EQ(expect_seq_no_wrap, seq_no_wrapped); |
| 1022 | ASSERT_EQ(expect_timestamp_wrap, timestamp_wrapped); |
| 1023 | } |
| 1024 | |
| 1025 | TEST_F(NetEqDecodingTest, SequenceNumberWrap) { |
| 1026 | // Start with a sequence number that will soon wrap. |
| 1027 | std::set<uint16_t> drop_seq_numbers; // Don't drop any packets. |
| 1028 | WrapTest(0xFFFF - 10, 0, drop_seq_numbers, true, false); |
| 1029 | } |
| 1030 | |
| 1031 | TEST_F(NetEqDecodingTest, SequenceNumberWrapAndDrop) { |
| 1032 | // Start with a sequence number that will soon wrap. |
| 1033 | std::set<uint16_t> drop_seq_numbers; |
| 1034 | drop_seq_numbers.insert(0xFFFF); |
| 1035 | drop_seq_numbers.insert(0x0); |
| 1036 | WrapTest(0xFFFF - 10, 0, drop_seq_numbers, true, false); |
| 1037 | } |
| 1038 | |
| 1039 | TEST_F(NetEqDecodingTest, TimestampWrap) { |
| 1040 | // Start with a timestamp that will soon wrap. |
| 1041 | std::set<uint16_t> drop_seq_numbers; |
| 1042 | WrapTest(0, 0xFFFFFFFF - 3000, drop_seq_numbers, false, true); |
| 1043 | } |
| 1044 | |
| 1045 | TEST_F(NetEqDecodingTest, TimestampAndSequenceNumberWrap) { |
| 1046 | // Start with a timestamp and a sequence number that will wrap at the same |
| 1047 | // time. |
| 1048 | std::set<uint16_t> drop_seq_numbers; |
| 1049 | WrapTest(0xFFFF - 10, 0xFFFFFFFF - 5000, drop_seq_numbers, true, true); |
| 1050 | } |
| 1051 | |
henrik.lundin@webrtc.org | ca8cb95 | 2014-03-12 10:26:52 +0000 | [diff] [blame] | 1052 | void NetEqDecodingTest::DuplicateCng() { |
| 1053 | uint16_t seq_no = 0; |
| 1054 | uint32_t timestamp = 0; |
| 1055 | const int kFrameSizeMs = 10; |
| 1056 | const int kSampleRateKhz = 16; |
| 1057 | const int kSamples = kFrameSizeMs * kSampleRateKhz; |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 1058 | const size_t kPayloadBytes = kSamples * 2; |
henrik.lundin@webrtc.org | ca8cb95 | 2014-03-12 10:26:52 +0000 | [diff] [blame] | 1059 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1060 | const int algorithmic_delay_samples = |
| 1061 | std::max(algorithmic_delay_ms_ * kSampleRateKhz, 5 * kSampleRateKhz / 8); |
henrik.lundin@webrtc.org | c93437e | 2014-12-01 11:42:42 +0000 | [diff] [blame] | 1062 | // 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] | 1063 | // correct. |
henrik.lundin@webrtc.org | ca8cb95 | 2014-03-12 10:26:52 +0000 | [diff] [blame] | 1064 | uint8_t payload[kPayloadBytes] = {0}; |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 1065 | RTPHeader rtp_info; |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 1066 | bool muted; |
henrik.lundin@webrtc.org | ca8cb95 | 2014-03-12 10:26:52 +0000 | [diff] [blame] | 1067 | for (int i = 0; i < 3; ++i) { |
| 1068 | PopulateRtpInfo(seq_no, timestamp, &rtp_info); |
Karl Wiberg | 45eb135 | 2019-10-10 14:23:00 +0200 | [diff] [blame] | 1069 | ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload)); |
henrik.lundin@webrtc.org | ca8cb95 | 2014-03-12 10:26:52 +0000 | [diff] [blame] | 1070 | ++seq_no; |
| 1071 | timestamp += kSamples; |
| 1072 | |
| 1073 | // Pull audio once. |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 1074 | ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 1075 | ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); |
henrik.lundin@webrtc.org | ca8cb95 | 2014-03-12 10:26:52 +0000 | [diff] [blame] | 1076 | } |
| 1077 | // Verify speech output. |
henrik.lundin | 55480f5 | 2016-03-08 02:37:57 -0800 | [diff] [blame] | 1078 | EXPECT_EQ(AudioFrame::kNormalSpeech, out_frame_.speech_type_); |
henrik.lundin@webrtc.org | ca8cb95 | 2014-03-12 10:26:52 +0000 | [diff] [blame] | 1079 | |
| 1080 | // Insert same CNG packet twice. |
| 1081 | const int kCngPeriodMs = 100; |
| 1082 | const int kCngPeriodSamples = kCngPeriodMs * kSampleRateKhz; |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 1083 | size_t payload_len; |
henrik.lundin@webrtc.org | ca8cb95 | 2014-03-12 10:26:52 +0000 | [diff] [blame] | 1084 | PopulateCng(seq_no, timestamp, &rtp_info, payload, &payload_len); |
| 1085 | // This is the first time this CNG packet is inserted. |
Karl Wiberg | 45eb135 | 2019-10-10 14:23:00 +0200 | [diff] [blame] | 1086 | ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, rtc::ArrayView<const uint8_t>( |
| 1087 | payload, payload_len))); |
henrik.lundin@webrtc.org | ca8cb95 | 2014-03-12 10:26:52 +0000 | [diff] [blame] | 1088 | |
| 1089 | // Pull audio once and make sure CNG is played. |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 1090 | ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 1091 | ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); |
henrik.lundin | 55480f5 | 2016-03-08 02:37:57 -0800 | [diff] [blame] | 1092 | EXPECT_EQ(AudioFrame::kCNG, out_frame_.speech_type_); |
henrik.lundin | 114c1b3 | 2017-04-26 07:47:32 -0700 | [diff] [blame] | 1093 | EXPECT_FALSE( |
| 1094 | neteq_->GetPlayoutTimestamp()); // Returns empty value during CNG. |
henrik.lundin | 0d96ab7 | 2016-04-06 12:28:26 -0700 | [diff] [blame] | 1095 | EXPECT_EQ(timestamp - algorithmic_delay_samples, |
| 1096 | out_frame_.timestamp_ + out_frame_.samples_per_channel_); |
henrik.lundin@webrtc.org | ca8cb95 | 2014-03-12 10:26:52 +0000 | [diff] [blame] | 1097 | |
| 1098 | // Insert the same CNG packet again. Note that at this point it is old, since |
| 1099 | // we have already decoded the first copy of it. |
Karl Wiberg | 45eb135 | 2019-10-10 14:23:00 +0200 | [diff] [blame] | 1100 | ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, rtc::ArrayView<const uint8_t>( |
| 1101 | payload, payload_len))); |
henrik.lundin@webrtc.org | ca8cb95 | 2014-03-12 10:26:52 +0000 | [diff] [blame] | 1102 | |
| 1103 | // Pull audio until we have played |kCngPeriodMs| of CNG. Start at 10 ms since |
| 1104 | // we have already pulled out CNG once. |
| 1105 | 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] | 1106 | ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 1107 | ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); |
henrik.lundin | 55480f5 | 2016-03-08 02:37:57 -0800 | [diff] [blame] | 1108 | EXPECT_EQ(AudioFrame::kCNG, out_frame_.speech_type_); |
henrik.lundin | 114c1b3 | 2017-04-26 07:47:32 -0700 | [diff] [blame] | 1109 | EXPECT_FALSE( |
| 1110 | neteq_->GetPlayoutTimestamp()); // Returns empty value during CNG. |
turaj@webrtc.org | 8d1cdaa | 2014-04-11 18:47:55 +0000 | [diff] [blame] | 1111 | EXPECT_EQ(timestamp - algorithmic_delay_samples, |
henrik.lundin | 0d96ab7 | 2016-04-06 12:28:26 -0700 | [diff] [blame] | 1112 | out_frame_.timestamp_ + out_frame_.samples_per_channel_); |
henrik.lundin@webrtc.org | ca8cb95 | 2014-03-12 10:26:52 +0000 | [diff] [blame] | 1113 | } |
| 1114 | |
| 1115 | // Insert speech again. |
| 1116 | ++seq_no; |
| 1117 | timestamp += kCngPeriodSamples; |
| 1118 | PopulateRtpInfo(seq_no, timestamp, &rtp_info); |
Karl Wiberg | 45eb135 | 2019-10-10 14:23:00 +0200 | [diff] [blame] | 1119 | ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload)); |
henrik.lundin@webrtc.org | ca8cb95 | 2014-03-12 10:26:52 +0000 | [diff] [blame] | 1120 | |
| 1121 | // Pull audio once and verify that the output is speech again. |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 1122 | ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 1123 | ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); |
henrik.lundin | 55480f5 | 2016-03-08 02:37:57 -0800 | [diff] [blame] | 1124 | EXPECT_EQ(AudioFrame::kNormalSpeech, out_frame_.speech_type_); |
Danil Chapovalov | b602123 | 2018-06-19 13:26:36 +0200 | [diff] [blame] | 1125 | absl::optional<uint32_t> playout_timestamp = neteq_->GetPlayoutTimestamp(); |
henrik.lundin | 0d96ab7 | 2016-04-06 12:28:26 -0700 | [diff] [blame] | 1126 | ASSERT_TRUE(playout_timestamp); |
turaj@webrtc.org | 8d1cdaa | 2014-04-11 18:47:55 +0000 | [diff] [blame] | 1127 | EXPECT_EQ(timestamp + kSamples - algorithmic_delay_samples, |
henrik.lundin | 0d96ab7 | 2016-04-06 12:28:26 -0700 | [diff] [blame] | 1128 | *playout_timestamp); |
wu@webrtc.org | 94454b7 | 2014-06-05 20:34:08 +0000 | [diff] [blame] | 1129 | } |
| 1130 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1131 | TEST_F(NetEqDecodingTest, DiscardDuplicateCng) { |
| 1132 | DuplicateCng(); |
| 1133 | } |
henrik.lundin@webrtc.org | c93437e | 2014-12-01 11:42:42 +0000 | [diff] [blame] | 1134 | |
| 1135 | TEST_F(NetEqDecodingTest, CngFirst) { |
| 1136 | uint16_t seq_no = 0; |
| 1137 | uint32_t timestamp = 0; |
| 1138 | const int kFrameSizeMs = 10; |
| 1139 | const int kSampleRateKhz = 16; |
| 1140 | const int kSamples = kFrameSizeMs * kSampleRateKhz; |
| 1141 | const int kPayloadBytes = kSamples * 2; |
| 1142 | const int kCngPeriodMs = 100; |
| 1143 | const int kCngPeriodSamples = kCngPeriodMs * kSampleRateKhz; |
| 1144 | size_t payload_len; |
| 1145 | |
| 1146 | uint8_t payload[kPayloadBytes] = {0}; |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 1147 | RTPHeader rtp_info; |
henrik.lundin@webrtc.org | c93437e | 2014-12-01 11:42:42 +0000 | [diff] [blame] | 1148 | |
| 1149 | PopulateCng(seq_no, timestamp, &rtp_info, payload, &payload_len); |
Karl Wiberg | 45eb135 | 2019-10-10 14:23:00 +0200 | [diff] [blame] | 1150 | ASSERT_EQ(NetEq::kOK, |
| 1151 | neteq_->InsertPacket( |
| 1152 | rtp_info, rtc::ArrayView<const uint8_t>(payload, payload_len))); |
henrik.lundin@webrtc.org | c93437e | 2014-12-01 11:42:42 +0000 | [diff] [blame] | 1153 | ++seq_no; |
| 1154 | timestamp += kCngPeriodSamples; |
| 1155 | |
| 1156 | // Pull audio once and make sure CNG is played. |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 1157 | bool muted; |
| 1158 | ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 1159 | ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); |
henrik.lundin | 55480f5 | 2016-03-08 02:37:57 -0800 | [diff] [blame] | 1160 | EXPECT_EQ(AudioFrame::kCNG, out_frame_.speech_type_); |
henrik.lundin@webrtc.org | c93437e | 2014-12-01 11:42:42 +0000 | [diff] [blame] | 1161 | |
| 1162 | // Insert some speech packets. |
henrik.lundin | 549d80b | 2016-08-25 00:44:24 -0700 | [diff] [blame] | 1163 | const uint32_t first_speech_timestamp = timestamp; |
| 1164 | int timeout_counter = 0; |
| 1165 | do { |
| 1166 | ASSERT_LT(timeout_counter++, 20) << "Test timed out"; |
henrik.lundin@webrtc.org | c93437e | 2014-12-01 11:42:42 +0000 | [diff] [blame] | 1167 | PopulateRtpInfo(seq_no, timestamp, &rtp_info); |
Karl Wiberg | 45eb135 | 2019-10-10 14:23:00 +0200 | [diff] [blame] | 1168 | ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload)); |
henrik.lundin@webrtc.org | c93437e | 2014-12-01 11:42:42 +0000 | [diff] [blame] | 1169 | ++seq_no; |
| 1170 | timestamp += kSamples; |
| 1171 | |
| 1172 | // Pull audio once. |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 1173 | ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 1174 | ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); |
henrik.lundin | 549d80b | 2016-08-25 00:44:24 -0700 | [diff] [blame] | 1175 | } while (!IsNewerTimestamp(out_frame_.timestamp_, first_speech_timestamp)); |
henrik.lundin@webrtc.org | c93437e | 2014-12-01 11:42:42 +0000 | [diff] [blame] | 1176 | // Verify speech output. |
henrik.lundin | 55480f5 | 2016-03-08 02:37:57 -0800 | [diff] [blame] | 1177 | EXPECT_EQ(AudioFrame::kNormalSpeech, out_frame_.speech_type_); |
henrik.lundin@webrtc.org | c93437e | 2014-12-01 11:42:42 +0000 | [diff] [blame] | 1178 | } |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 1179 | |
| 1180 | class NetEqDecodingTestWithMutedState : public NetEqDecodingTest { |
| 1181 | public: |
| 1182 | NetEqDecodingTestWithMutedState() : NetEqDecodingTest() { |
| 1183 | config_.enable_muted_state = true; |
| 1184 | } |
| 1185 | |
| 1186 | protected: |
| 1187 | static constexpr size_t kSamples = 10 * 16; |
| 1188 | static constexpr size_t kPayloadBytes = kSamples * 2; |
| 1189 | |
| 1190 | void InsertPacket(uint32_t rtp_timestamp) { |
| 1191 | uint8_t payload[kPayloadBytes] = {0}; |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 1192 | RTPHeader rtp_info; |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 1193 | PopulateRtpInfo(0, rtp_timestamp, &rtp_info); |
Karl Wiberg | 45eb135 | 2019-10-10 14:23:00 +0200 | [diff] [blame] | 1194 | EXPECT_EQ(0, neteq_->InsertPacket(rtp_info, payload)); |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 1195 | } |
| 1196 | |
henrik.lundin | 42feb51 | 2016-09-20 06:51:40 -0700 | [diff] [blame] | 1197 | void InsertCngPacket(uint32_t rtp_timestamp) { |
| 1198 | uint8_t payload[kPayloadBytes] = {0}; |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 1199 | RTPHeader rtp_info; |
henrik.lundin | 42feb51 | 2016-09-20 06:51:40 -0700 | [diff] [blame] | 1200 | size_t payload_len; |
| 1201 | PopulateCng(0, rtp_timestamp, &rtp_info, payload, &payload_len); |
Karl Wiberg | 45eb135 | 2019-10-10 14:23:00 +0200 | [diff] [blame] | 1202 | EXPECT_EQ(NetEq::kOK, |
| 1203 | neteq_->InsertPacket(rtp_info, rtc::ArrayView<const uint8_t>( |
| 1204 | payload, payload_len))); |
henrik.lundin | 42feb51 | 2016-09-20 06:51:40 -0700 | [diff] [blame] | 1205 | } |
| 1206 | |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 1207 | bool GetAudioReturnMuted() { |
| 1208 | bool muted; |
| 1209 | EXPECT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); |
| 1210 | return muted; |
| 1211 | } |
| 1212 | |
| 1213 | void GetAudioUntilMuted() { |
| 1214 | while (!GetAudioReturnMuted()) { |
| 1215 | ASSERT_LT(counter_++, 1000) << "Test timed out"; |
| 1216 | } |
| 1217 | } |
| 1218 | |
| 1219 | void GetAudioUntilNormal() { |
| 1220 | bool muted = false; |
| 1221 | while (out_frame_.speech_type_ != AudioFrame::kNormalSpeech) { |
| 1222 | EXPECT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); |
| 1223 | ASSERT_LT(counter_++, 1000) << "Test timed out"; |
| 1224 | } |
| 1225 | EXPECT_FALSE(muted); |
| 1226 | } |
| 1227 | |
| 1228 | int counter_ = 0; |
| 1229 | }; |
| 1230 | |
| 1231 | // Verifies that NetEq goes in and out of muted state as expected. |
| 1232 | TEST_F(NetEqDecodingTestWithMutedState, MutedState) { |
| 1233 | // Insert one speech packet. |
| 1234 | InsertPacket(0); |
| 1235 | // Pull out audio once and expect it not to be muted. |
| 1236 | EXPECT_FALSE(GetAudioReturnMuted()); |
| 1237 | // Pull data until faded out. |
| 1238 | GetAudioUntilMuted(); |
henrik.lundin | a449107 | 2017-07-06 05:23:53 -0700 | [diff] [blame] | 1239 | EXPECT_TRUE(out_frame_.muted()); |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 1240 | |
| 1241 | // Verify that output audio is not written during muted mode. Other parameters |
| 1242 | // should be correct, though. |
| 1243 | AudioFrame new_frame; |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 1244 | int16_t* frame_data = new_frame.mutable_data(); |
| 1245 | for (size_t i = 0; i < AudioFrame::kMaxDataSizeSamples; i++) { |
| 1246 | frame_data[i] = 17; |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 1247 | } |
| 1248 | bool muted; |
| 1249 | EXPECT_EQ(0, neteq_->GetAudio(&new_frame, &muted)); |
| 1250 | EXPECT_TRUE(muted); |
henrik.lundin | a449107 | 2017-07-06 05:23:53 -0700 | [diff] [blame] | 1251 | EXPECT_TRUE(out_frame_.muted()); |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 1252 | for (size_t i = 0; i < AudioFrame::kMaxDataSizeSamples; i++) { |
| 1253 | EXPECT_EQ(17, frame_data[i]); |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 1254 | } |
| 1255 | EXPECT_EQ(out_frame_.timestamp_ + out_frame_.samples_per_channel_, |
| 1256 | new_frame.timestamp_); |
| 1257 | EXPECT_EQ(out_frame_.samples_per_channel_, new_frame.samples_per_channel_); |
| 1258 | EXPECT_EQ(out_frame_.sample_rate_hz_, new_frame.sample_rate_hz_); |
| 1259 | EXPECT_EQ(out_frame_.num_channels_, new_frame.num_channels_); |
| 1260 | EXPECT_EQ(out_frame_.speech_type_, new_frame.speech_type_); |
| 1261 | EXPECT_EQ(out_frame_.vad_activity_, new_frame.vad_activity_); |
| 1262 | |
| 1263 | // Insert new data. Timestamp is corrected for the time elapsed since the last |
| 1264 | // packet. Verify that normal operation resumes. |
| 1265 | InsertPacket(kSamples * counter_); |
| 1266 | GetAudioUntilNormal(); |
henrik.lundin | a449107 | 2017-07-06 05:23:53 -0700 | [diff] [blame] | 1267 | EXPECT_FALSE(out_frame_.muted()); |
henrik.lundin | 612c25e | 2016-05-25 08:21:04 -0700 | [diff] [blame] | 1268 | |
| 1269 | NetEqNetworkStatistics stats; |
| 1270 | EXPECT_EQ(0, neteq_->NetworkStatistics(&stats)); |
| 1271 | // NetEqNetworkStatistics::expand_rate tells the fraction of samples that were |
| 1272 | // concealment samples, in Q14 (16384 = 100%) .The vast majority should be |
| 1273 | // concealment samples in this test. |
| 1274 | EXPECT_GT(stats.expand_rate, 14000); |
| 1275 | // And, it should be greater than the speech_expand_rate. |
| 1276 | EXPECT_GT(stats.expand_rate, stats.speech_expand_rate); |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 1277 | } |
| 1278 | |
| 1279 | // Verifies that NetEq goes out of muted state when given a delayed packet. |
| 1280 | TEST_F(NetEqDecodingTestWithMutedState, MutedStateDelayedPacket) { |
| 1281 | // Insert one speech packet. |
| 1282 | InsertPacket(0); |
| 1283 | // Pull out audio once and expect it not to be muted. |
| 1284 | EXPECT_FALSE(GetAudioReturnMuted()); |
| 1285 | // Pull data until faded out. |
| 1286 | GetAudioUntilMuted(); |
| 1287 | // Insert new data. Timestamp is only corrected for the half of the time |
| 1288 | // elapsed since the last packet. That is, the new packet is delayed. Verify |
| 1289 | // that normal operation resumes. |
| 1290 | InsertPacket(kSamples * counter_ / 2); |
| 1291 | GetAudioUntilNormal(); |
| 1292 | } |
| 1293 | |
| 1294 | // Verifies that NetEq goes out of muted state when given a future packet. |
| 1295 | TEST_F(NetEqDecodingTestWithMutedState, MutedStateFuturePacket) { |
| 1296 | // Insert one speech packet. |
| 1297 | InsertPacket(0); |
| 1298 | // Pull out audio once and expect it not to be muted. |
| 1299 | EXPECT_FALSE(GetAudioReturnMuted()); |
| 1300 | // Pull data until faded out. |
| 1301 | GetAudioUntilMuted(); |
| 1302 | // Insert new data. Timestamp is over-corrected for the time elapsed since the |
| 1303 | // last packet. That is, the new packet is too early. Verify that normal |
| 1304 | // operation resumes. |
| 1305 | InsertPacket(kSamples * counter_ * 2); |
| 1306 | GetAudioUntilNormal(); |
| 1307 | } |
| 1308 | |
| 1309 | // Verifies that NetEq goes out of muted state when given an old packet. |
| 1310 | TEST_F(NetEqDecodingTestWithMutedState, MutedStateOldPacket) { |
| 1311 | // Insert one speech packet. |
| 1312 | InsertPacket(0); |
| 1313 | // Pull out audio once and expect it not to be muted. |
| 1314 | EXPECT_FALSE(GetAudioReturnMuted()); |
| 1315 | // Pull data until faded out. |
| 1316 | GetAudioUntilMuted(); |
| 1317 | |
| 1318 | EXPECT_NE(AudioFrame::kNormalSpeech, out_frame_.speech_type_); |
| 1319 | // Insert packet which is older than the first packet. |
| 1320 | InsertPacket(kSamples * (counter_ - 1000)); |
| 1321 | EXPECT_FALSE(GetAudioReturnMuted()); |
| 1322 | EXPECT_EQ(AudioFrame::kNormalSpeech, out_frame_.speech_type_); |
| 1323 | } |
| 1324 | |
henrik.lundin | 42feb51 | 2016-09-20 06:51:40 -0700 | [diff] [blame] | 1325 | // Verifies that NetEq doesn't enter muted state when CNG mode is active and the |
| 1326 | // packet stream is suspended for a long time. |
| 1327 | TEST_F(NetEqDecodingTestWithMutedState, DoNotMuteExtendedCngWithoutPackets) { |
| 1328 | // Insert one CNG packet. |
| 1329 | InsertCngPacket(0); |
| 1330 | |
| 1331 | // Pull 10 seconds of audio (10 ms audio generated per lap). |
| 1332 | for (int i = 0; i < 1000; ++i) { |
| 1333 | bool muted; |
| 1334 | EXPECT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); |
| 1335 | ASSERT_FALSE(muted); |
| 1336 | } |
| 1337 | EXPECT_EQ(AudioFrame::kCNG, out_frame_.speech_type_); |
| 1338 | } |
| 1339 | |
| 1340 | // Verifies that NetEq goes back to normal after a long CNG period with the |
| 1341 | // packet stream suspended. |
| 1342 | TEST_F(NetEqDecodingTestWithMutedState, RecoverAfterExtendedCngWithoutPackets) { |
| 1343 | // Insert one CNG packet. |
| 1344 | InsertCngPacket(0); |
| 1345 | |
| 1346 | // Pull 10 seconds of audio (10 ms audio generated per lap). |
| 1347 | for (int i = 0; i < 1000; ++i) { |
| 1348 | bool muted; |
| 1349 | EXPECT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); |
| 1350 | } |
| 1351 | |
| 1352 | // Insert new data. Timestamp is corrected for the time elapsed since the last |
| 1353 | // packet. Verify that normal operation resumes. |
| 1354 | InsertPacket(kSamples * counter_); |
| 1355 | GetAudioUntilNormal(); |
| 1356 | } |
| 1357 | |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 1358 | class NetEqDecodingTestTwoInstances : public NetEqDecodingTest { |
| 1359 | public: |
| 1360 | NetEqDecodingTestTwoInstances() : NetEqDecodingTest() {} |
| 1361 | |
| 1362 | void SetUp() override { |
| 1363 | NetEqDecodingTest::SetUp(); |
| 1364 | config2_ = config_; |
| 1365 | } |
| 1366 | |
| 1367 | void CreateSecondInstance() { |
Ivo Creusen | 3ce44a3 | 2019-10-31 14:38:11 +0100 | [diff] [blame] | 1368 | std::unique_ptr<NetEqFactory> neteq_factory = |
| 1369 | CreateNetEqFactoryWithCodecs(); |
| 1370 | neteq2_ = neteq_factory->CreateNetEq(config2_, &clock_); |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 1371 | ASSERT_TRUE(neteq2_); |
| 1372 | LoadDecoders(neteq2_.get()); |
| 1373 | } |
| 1374 | |
| 1375 | protected: |
| 1376 | std::unique_ptr<NetEq> neteq2_; |
| 1377 | NetEq::Config config2_; |
| 1378 | }; |
| 1379 | |
| 1380 | namespace { |
| 1381 | ::testing::AssertionResult AudioFramesEqualExceptData(const AudioFrame& a, |
| 1382 | const AudioFrame& b) { |
| 1383 | if (a.timestamp_ != b.timestamp_) |
| 1384 | return ::testing::AssertionFailure() << "timestamp_ diff (" << a.timestamp_ |
| 1385 | << " != " << b.timestamp_ << ")"; |
| 1386 | if (a.sample_rate_hz_ != b.sample_rate_hz_) |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1387 | return ::testing::AssertionFailure() |
| 1388 | << "sample_rate_hz_ diff (" << a.sample_rate_hz_ |
| 1389 | << " != " << b.sample_rate_hz_ << ")"; |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 1390 | if (a.samples_per_channel_ != b.samples_per_channel_) |
| 1391 | return ::testing::AssertionFailure() |
| 1392 | << "samples_per_channel_ diff (" << a.samples_per_channel_ |
| 1393 | << " != " << b.samples_per_channel_ << ")"; |
| 1394 | if (a.num_channels_ != b.num_channels_) |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1395 | return ::testing::AssertionFailure() |
| 1396 | << "num_channels_ diff (" << a.num_channels_ |
| 1397 | << " != " << b.num_channels_ << ")"; |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 1398 | if (a.speech_type_ != b.speech_type_) |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1399 | return ::testing::AssertionFailure() |
| 1400 | << "speech_type_ diff (" << a.speech_type_ |
| 1401 | << " != " << b.speech_type_ << ")"; |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 1402 | if (a.vad_activity_ != b.vad_activity_) |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1403 | return ::testing::AssertionFailure() |
| 1404 | << "vad_activity_ diff (" << a.vad_activity_ |
| 1405 | << " != " << b.vad_activity_ << ")"; |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 1406 | return ::testing::AssertionSuccess(); |
| 1407 | } |
| 1408 | |
| 1409 | ::testing::AssertionResult AudioFramesEqual(const AudioFrame& a, |
| 1410 | const AudioFrame& b) { |
| 1411 | ::testing::AssertionResult res = AudioFramesEqualExceptData(a, b); |
| 1412 | if (!res) |
| 1413 | return res; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1414 | if (memcmp(a.data(), b.data(), |
| 1415 | a.samples_per_channel_ * a.num_channels_ * sizeof(*a.data())) != |
| 1416 | 0) { |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 1417 | return ::testing::AssertionFailure() << "data_ diff"; |
| 1418 | } |
| 1419 | return ::testing::AssertionSuccess(); |
| 1420 | } |
| 1421 | |
| 1422 | } // namespace |
| 1423 | |
| 1424 | TEST_F(NetEqDecodingTestTwoInstances, CompareMutedStateOnOff) { |
| 1425 | ASSERT_FALSE(config_.enable_muted_state); |
| 1426 | config2_.enable_muted_state = true; |
| 1427 | CreateSecondInstance(); |
| 1428 | |
| 1429 | // Insert one speech packet into both NetEqs. |
| 1430 | const size_t kSamples = 10 * 16; |
| 1431 | const size_t kPayloadBytes = kSamples * 2; |
| 1432 | uint8_t payload[kPayloadBytes] = {0}; |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 1433 | RTPHeader rtp_info; |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 1434 | PopulateRtpInfo(0, 0, &rtp_info); |
Karl Wiberg | 45eb135 | 2019-10-10 14:23:00 +0200 | [diff] [blame] | 1435 | EXPECT_EQ(0, neteq_->InsertPacket(rtp_info, payload)); |
| 1436 | EXPECT_EQ(0, neteq2_->InsertPacket(rtp_info, payload)); |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 1437 | |
| 1438 | AudioFrame out_frame1, out_frame2; |
| 1439 | bool muted; |
| 1440 | for (int i = 0; i < 1000; ++i) { |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame] | 1441 | rtc::StringBuilder ss; |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 1442 | ss << "i = " << i; |
| 1443 | SCOPED_TRACE(ss.str()); // Print out the loop iterator on failure. |
| 1444 | EXPECT_EQ(0, neteq_->GetAudio(&out_frame1, &muted)); |
| 1445 | EXPECT_FALSE(muted); |
| 1446 | EXPECT_EQ(0, neteq2_->GetAudio(&out_frame2, &muted)); |
| 1447 | if (muted) { |
| 1448 | EXPECT_TRUE(AudioFramesEqualExceptData(out_frame1, out_frame2)); |
| 1449 | } else { |
| 1450 | EXPECT_TRUE(AudioFramesEqual(out_frame1, out_frame2)); |
| 1451 | } |
| 1452 | } |
| 1453 | EXPECT_TRUE(muted); |
| 1454 | |
| 1455 | // Insert new data. Timestamp is corrected for the time elapsed since the last |
| 1456 | // packet. |
| 1457 | PopulateRtpInfo(0, kSamples * 1000, &rtp_info); |
Karl Wiberg | 45eb135 | 2019-10-10 14:23:00 +0200 | [diff] [blame] | 1458 | EXPECT_EQ(0, neteq_->InsertPacket(rtp_info, payload)); |
| 1459 | EXPECT_EQ(0, neteq2_->InsertPacket(rtp_info, payload)); |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 1460 | |
| 1461 | int counter = 0; |
| 1462 | while (out_frame1.speech_type_ != AudioFrame::kNormalSpeech) { |
| 1463 | ASSERT_LT(counter++, 1000) << "Test timed out"; |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame] | 1464 | rtc::StringBuilder ss; |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 1465 | ss << "counter = " << counter; |
| 1466 | SCOPED_TRACE(ss.str()); // Print out the loop iterator on failure. |
| 1467 | EXPECT_EQ(0, neteq_->GetAudio(&out_frame1, &muted)); |
| 1468 | EXPECT_FALSE(muted); |
| 1469 | EXPECT_EQ(0, neteq2_->GetAudio(&out_frame2, &muted)); |
| 1470 | if (muted) { |
| 1471 | EXPECT_TRUE(AudioFramesEqualExceptData(out_frame1, out_frame2)); |
| 1472 | } else { |
| 1473 | EXPECT_TRUE(AudioFramesEqual(out_frame1, out_frame2)); |
| 1474 | } |
| 1475 | } |
| 1476 | EXPECT_FALSE(muted); |
| 1477 | } |
| 1478 | |
henrik.lundin | 114c1b3 | 2017-04-26 07:47:32 -0700 | [diff] [blame] | 1479 | TEST_F(NetEqDecodingTest, LastDecodedTimestampsEmpty) { |
| 1480 | EXPECT_TRUE(neteq_->LastDecodedTimestamps().empty()); |
| 1481 | |
| 1482 | // Pull out data once. |
| 1483 | AudioFrame output; |
| 1484 | bool muted; |
| 1485 | ASSERT_EQ(0, neteq_->GetAudio(&output, &muted)); |
| 1486 | |
| 1487 | EXPECT_TRUE(neteq_->LastDecodedTimestamps().empty()); |
| 1488 | } |
| 1489 | |
| 1490 | TEST_F(NetEqDecodingTest, LastDecodedTimestampsOneDecoded) { |
| 1491 | // Insert one packet with PCM16b WB data (this is what PopulateRtpInfo does by |
| 1492 | // default). Make the length 10 ms. |
| 1493 | constexpr size_t kPayloadSamples = 16 * 10; |
| 1494 | constexpr size_t kPayloadBytes = 2 * kPayloadSamples; |
| 1495 | uint8_t payload[kPayloadBytes] = {0}; |
| 1496 | |
| 1497 | RTPHeader rtp_info; |
| 1498 | constexpr uint32_t kRtpTimestamp = 0x1234; |
| 1499 | PopulateRtpInfo(0, kRtpTimestamp, &rtp_info); |
Karl Wiberg | 45eb135 | 2019-10-10 14:23:00 +0200 | [diff] [blame] | 1500 | EXPECT_EQ(0, neteq_->InsertPacket(rtp_info, payload)); |
henrik.lundin | 114c1b3 | 2017-04-26 07:47:32 -0700 | [diff] [blame] | 1501 | |
| 1502 | // Pull out data once. |
| 1503 | AudioFrame output; |
| 1504 | bool muted; |
| 1505 | ASSERT_EQ(0, neteq_->GetAudio(&output, &muted)); |
| 1506 | |
| 1507 | EXPECT_EQ(std::vector<uint32_t>({kRtpTimestamp}), |
| 1508 | neteq_->LastDecodedTimestamps()); |
| 1509 | |
| 1510 | // Nothing decoded on the second call. |
| 1511 | ASSERT_EQ(0, neteq_->GetAudio(&output, &muted)); |
| 1512 | EXPECT_TRUE(neteq_->LastDecodedTimestamps().empty()); |
| 1513 | } |
| 1514 | |
| 1515 | TEST_F(NetEqDecodingTest, LastDecodedTimestampsTwoDecoded) { |
| 1516 | // Insert two packets with PCM16b WB data (this is what PopulateRtpInfo does |
| 1517 | // by default). Make the length 5 ms so that NetEq must decode them both in |
| 1518 | // the same GetAudio call. |
| 1519 | constexpr size_t kPayloadSamples = 16 * 5; |
| 1520 | constexpr size_t kPayloadBytes = 2 * kPayloadSamples; |
| 1521 | uint8_t payload[kPayloadBytes] = {0}; |
| 1522 | |
| 1523 | RTPHeader rtp_info; |
| 1524 | constexpr uint32_t kRtpTimestamp1 = 0x1234; |
| 1525 | PopulateRtpInfo(0, kRtpTimestamp1, &rtp_info); |
Karl Wiberg | 45eb135 | 2019-10-10 14:23:00 +0200 | [diff] [blame] | 1526 | EXPECT_EQ(0, neteq_->InsertPacket(rtp_info, payload)); |
henrik.lundin | 114c1b3 | 2017-04-26 07:47:32 -0700 | [diff] [blame] | 1527 | constexpr uint32_t kRtpTimestamp2 = kRtpTimestamp1 + kPayloadSamples; |
| 1528 | PopulateRtpInfo(1, kRtpTimestamp2, &rtp_info); |
Karl Wiberg | 45eb135 | 2019-10-10 14:23:00 +0200 | [diff] [blame] | 1529 | EXPECT_EQ(0, neteq_->InsertPacket(rtp_info, payload)); |
henrik.lundin | 114c1b3 | 2017-04-26 07:47:32 -0700 | [diff] [blame] | 1530 | |
| 1531 | // Pull out data once. |
| 1532 | AudioFrame output; |
| 1533 | bool muted; |
| 1534 | ASSERT_EQ(0, neteq_->GetAudio(&output, &muted)); |
| 1535 | |
| 1536 | EXPECT_EQ(std::vector<uint32_t>({kRtpTimestamp1, kRtpTimestamp2}), |
| 1537 | neteq_->LastDecodedTimestamps()); |
| 1538 | } |
| 1539 | |
Gustaf Ullberg | 9a2e906 | 2017-09-18 09:28:20 +0200 | [diff] [blame] | 1540 | TEST_F(NetEqDecodingTest, TestConcealmentEvents) { |
| 1541 | const int kNumConcealmentEvents = 19; |
| 1542 | const size_t kSamples = 10 * 16; |
| 1543 | const size_t kPayloadBytes = kSamples * 2; |
| 1544 | int seq_no = 0; |
| 1545 | RTPHeader rtp_info; |
| 1546 | rtp_info.ssrc = 0x1234; // Just an arbitrary SSRC. |
| 1547 | rtp_info.payloadType = 94; // PCM16b WB codec. |
| 1548 | rtp_info.markerBit = 0; |
| 1549 | const uint8_t payload[kPayloadBytes] = {0}; |
| 1550 | bool muted; |
| 1551 | |
| 1552 | for (int i = 0; i < kNumConcealmentEvents; i++) { |
| 1553 | // Insert some packets of 10 ms size. |
| 1554 | for (int j = 0; j < 10; j++) { |
| 1555 | rtp_info.sequenceNumber = seq_no++; |
| 1556 | rtp_info.timestamp = rtp_info.sequenceNumber * kSamples; |
Karl Wiberg | 45eb135 | 2019-10-10 14:23:00 +0200 | [diff] [blame] | 1557 | neteq_->InsertPacket(rtp_info, payload); |
Gustaf Ullberg | 9a2e906 | 2017-09-18 09:28:20 +0200 | [diff] [blame] | 1558 | neteq_->GetAudio(&out_frame_, &muted); |
| 1559 | } |
| 1560 | |
| 1561 | // Lose a number of packets. |
| 1562 | int num_lost = 1 + i; |
| 1563 | for (int j = 0; j < num_lost; j++) { |
| 1564 | seq_no++; |
| 1565 | neteq_->GetAudio(&out_frame_, &muted); |
| 1566 | } |
| 1567 | } |
| 1568 | |
| 1569 | // Check number of concealment events. |
| 1570 | NetEqLifetimeStatistics stats = neteq_->GetLifetimeStatistics(); |
| 1571 | EXPECT_EQ(kNumConcealmentEvents, static_cast<int>(stats.concealment_events)); |
| 1572 | } |
| 1573 | |
Gustaf Ullberg | b0a0207 | 2017-10-02 12:00:34 +0200 | [diff] [blame] | 1574 | // Test that the jitter buffer delay stat is computed correctly. |
| 1575 | void NetEqDecodingTestFaxMode::TestJitterBufferDelay(bool apply_packet_loss) { |
| 1576 | const int kNumPackets = 10; |
| 1577 | const int kDelayInNumPackets = 2; |
| 1578 | const int kPacketLenMs = 10; // All packets are of 10 ms size. |
| 1579 | const size_t kSamples = kPacketLenMs * 16; |
| 1580 | const size_t kPayloadBytes = kSamples * 2; |
| 1581 | RTPHeader rtp_info; |
| 1582 | rtp_info.ssrc = 0x1234; // Just an arbitrary SSRC. |
| 1583 | rtp_info.payloadType = 94; // PCM16b WB codec. |
| 1584 | rtp_info.markerBit = 0; |
| 1585 | const uint8_t payload[kPayloadBytes] = {0}; |
| 1586 | bool muted; |
| 1587 | int packets_sent = 0; |
| 1588 | int packets_received = 0; |
| 1589 | int expected_delay = 0; |
Chen Xing | 0acffb5 | 2019-01-15 15:46:29 +0100 | [diff] [blame] | 1590 | uint64_t expected_emitted_count = 0; |
Gustaf Ullberg | b0a0207 | 2017-10-02 12:00:34 +0200 | [diff] [blame] | 1591 | while (packets_received < kNumPackets) { |
| 1592 | // Insert packet. |
| 1593 | if (packets_sent < kNumPackets) { |
| 1594 | rtp_info.sequenceNumber = packets_sent++; |
| 1595 | rtp_info.timestamp = rtp_info.sequenceNumber * kSamples; |
Karl Wiberg | 45eb135 | 2019-10-10 14:23:00 +0200 | [diff] [blame] | 1596 | neteq_->InsertPacket(rtp_info, payload); |
Gustaf Ullberg | b0a0207 | 2017-10-02 12:00:34 +0200 | [diff] [blame] | 1597 | } |
| 1598 | |
| 1599 | // Get packet. |
| 1600 | if (packets_sent > kDelayInNumPackets) { |
| 1601 | neteq_->GetAudio(&out_frame_, &muted); |
| 1602 | packets_received++; |
| 1603 | |
| 1604 | // The delay reported by the jitter buffer never exceeds |
| 1605 | // the number of samples previously fetched with GetAudio |
| 1606 | // (hence the min()). |
| 1607 | int packets_delay = std::min(packets_received, kDelayInNumPackets + 1); |
| 1608 | |
| 1609 | // The increase of the expected delay is the product of |
| 1610 | // the current delay of the jitter buffer in ms * the |
| 1611 | // number of samples that are sent for play out. |
| 1612 | int current_delay_ms = packets_delay * kPacketLenMs; |
| 1613 | expected_delay += current_delay_ms * kSamples; |
Chen Xing | 0acffb5 | 2019-01-15 15:46:29 +0100 | [diff] [blame] | 1614 | expected_emitted_count += kSamples; |
Gustaf Ullberg | b0a0207 | 2017-10-02 12:00:34 +0200 | [diff] [blame] | 1615 | } |
| 1616 | } |
| 1617 | |
| 1618 | if (apply_packet_loss) { |
| 1619 | // Extra call to GetAudio to cause concealment. |
| 1620 | neteq_->GetAudio(&out_frame_, &muted); |
| 1621 | } |
| 1622 | |
| 1623 | // Check jitter buffer delay. |
| 1624 | NetEqLifetimeStatistics stats = neteq_->GetLifetimeStatistics(); |
| 1625 | EXPECT_EQ(expected_delay, static_cast<int>(stats.jitter_buffer_delay_ms)); |
Chen Xing | 0acffb5 | 2019-01-15 15:46:29 +0100 | [diff] [blame] | 1626 | EXPECT_EQ(expected_emitted_count, stats.jitter_buffer_emitted_count); |
Gustaf Ullberg | b0a0207 | 2017-10-02 12:00:34 +0200 | [diff] [blame] | 1627 | } |
| 1628 | |
| 1629 | TEST_F(NetEqDecodingTestFaxMode, TestJitterBufferDelayWithoutLoss) { |
| 1630 | TestJitterBufferDelay(false); |
| 1631 | } |
| 1632 | |
| 1633 | TEST_F(NetEqDecodingTestFaxMode, TestJitterBufferDelayWithLoss) { |
| 1634 | TestJitterBufferDelay(true); |
| 1635 | } |
| 1636 | |
Jakob Ivarsson | 26c59ff | 2019-02-28 09:55:49 +0100 | [diff] [blame] | 1637 | TEST_F(NetEqDecodingTestFaxMode, TestJitterBufferDelayWithAcceleration) { |
| 1638 | const int kPacketLenMs = 10; // All packets are of 10 ms size. |
| 1639 | const size_t kSamples = kPacketLenMs * 16; |
| 1640 | const size_t kPayloadBytes = kSamples * 2; |
| 1641 | RTPHeader rtp_info; |
| 1642 | rtp_info.ssrc = 0x1234; // Just an arbitrary SSRC. |
| 1643 | rtp_info.payloadType = 94; // PCM16b WB codec. |
| 1644 | rtp_info.markerBit = 0; |
| 1645 | const uint8_t payload[kPayloadBytes] = {0}; |
| 1646 | |
Karl Wiberg | 45eb135 | 2019-10-10 14:23:00 +0200 | [diff] [blame] | 1647 | neteq_->InsertPacket(rtp_info, payload); |
Jakob Ivarsson | 26c59ff | 2019-02-28 09:55:49 +0100 | [diff] [blame] | 1648 | |
| 1649 | bool muted; |
| 1650 | neteq_->GetAudio(&out_frame_, &muted); |
| 1651 | |
| 1652 | rtp_info.sequenceNumber += 1; |
| 1653 | rtp_info.timestamp += kSamples; |
Karl Wiberg | 45eb135 | 2019-10-10 14:23:00 +0200 | [diff] [blame] | 1654 | neteq_->InsertPacket(rtp_info, payload); |
Jakob Ivarsson | 26c59ff | 2019-02-28 09:55:49 +0100 | [diff] [blame] | 1655 | rtp_info.sequenceNumber += 1; |
| 1656 | rtp_info.timestamp += kSamples; |
Karl Wiberg | 45eb135 | 2019-10-10 14:23:00 +0200 | [diff] [blame] | 1657 | neteq_->InsertPacket(rtp_info, payload); |
Jakob Ivarsson | 26c59ff | 2019-02-28 09:55:49 +0100 | [diff] [blame] | 1658 | |
| 1659 | // We have two packets in the buffer and kAccelerate operation will |
| 1660 | // extract 20 ms of data. |
Ivo Creusen | 3ce44a3 | 2019-10-31 14:38:11 +0100 | [diff] [blame] | 1661 | neteq_->GetAudio(&out_frame_, &muted, NetEq::Operation::kAccelerate); |
Jakob Ivarsson | 26c59ff | 2019-02-28 09:55:49 +0100 | [diff] [blame] | 1662 | |
| 1663 | // Check jitter buffer delay. |
| 1664 | NetEqLifetimeStatistics stats = neteq_->GetLifetimeStatistics(); |
| 1665 | EXPECT_EQ(10 * kSamples * 3, stats.jitter_buffer_delay_ms); |
| 1666 | EXPECT_EQ(kSamples * 3, stats.jitter_buffer_emitted_count); |
| 1667 | } |
| 1668 | |
Henrik Lundin | 7687ad5 | 2018-07-02 10:14:46 +0200 | [diff] [blame] | 1669 | namespace test { |
Henrik Lundin | 7687ad5 | 2018-07-02 10:14:46 +0200 | [diff] [blame] | 1670 | TEST(NetEqNoTimeStretchingMode, RunTest) { |
| 1671 | NetEq::Config config; |
| 1672 | config.for_test_no_time_stretching = true; |
| 1673 | auto codecs = NetEqTest::StandardDecoderMap(); |
Henrik Lundin | 7687ad5 | 2018-07-02 10:14:46 +0200 | [diff] [blame] | 1674 | NetEqPacketSourceInput::RtpHeaderExtensionMap rtp_ext_map = { |
| 1675 | {1, kRtpExtensionAudioLevel}, |
| 1676 | {3, kRtpExtensionAbsoluteSendTime}, |
| 1677 | {5, kRtpExtensionTransportSequenceNumber}, |
| 1678 | {7, kRtpExtensionVideoContentType}, |
| 1679 | {8, kRtpExtensionVideoTiming}}; |
| 1680 | std::unique_ptr<NetEqInput> input(new NetEqRtpDumpInput( |
| 1681 | webrtc::test::ResourcePath("audio_coding/neteq_universal_new", "rtp"), |
Bjorn Terelius | 5350d1c | 2018-10-11 16:51:23 +0200 | [diff] [blame] | 1682 | rtp_ext_map, absl::nullopt /*No SSRC filter*/)); |
Henrik Lundin | 7687ad5 | 2018-07-02 10:14:46 +0200 | [diff] [blame] | 1683 | std::unique_ptr<TimeLimitedNetEqInput> input_time_limit( |
| 1684 | new TimeLimitedNetEqInput(std::move(input), 20000)); |
| 1685 | std::unique_ptr<AudioSink> output(new VoidAudioSink); |
| 1686 | NetEqTest::Callbacks callbacks; |
Niels Möller | bd6dee8 | 2019-01-02 09:39:47 +0100 | [diff] [blame] | 1687 | NetEqTest test(config, CreateBuiltinAudioDecoderFactory(), codecs, nullptr, |
| 1688 | std::move(input_time_limit), std::move(output), callbacks); |
Henrik Lundin | 7687ad5 | 2018-07-02 10:14:46 +0200 | [diff] [blame] | 1689 | test.Run(); |
| 1690 | const auto stats = test.SimulationStats(); |
| 1691 | EXPECT_EQ(0, stats.accelerate_rate); |
| 1692 | EXPECT_EQ(0, stats.preemptive_rate); |
| 1693 | } |
Henrik Lundin | 7687ad5 | 2018-07-02 10:14:46 +0200 | [diff] [blame] | 1694 | |
| 1695 | } // namespace test |
henrik.lundin@webrtc.org | e7ce437 | 2014-01-09 14:01:55 +0000 | [diff] [blame] | 1696 | } // namespace webrtc |