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