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