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