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