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