OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 19 matching lines...) Expand all Loading... | |
30 #include "webrtc/modules/audio_coding/neteq/tools/rtp_file_source.h" | 30 #include "webrtc/modules/audio_coding/neteq/tools/rtp_file_source.h" |
31 #include "webrtc/modules/audio_coding/codecs/pcm16b/include/pcm16b.h" | 31 #include "webrtc/modules/audio_coding/codecs/pcm16b/include/pcm16b.h" |
32 #include "webrtc/test/testsupport/fileutils.h" | 32 #include "webrtc/test/testsupport/fileutils.h" |
33 #include "webrtc/test/testsupport/gtest_disable.h" | 33 #include "webrtc/test/testsupport/gtest_disable.h" |
34 #include "webrtc/typedefs.h" | 34 #include "webrtc/typedefs.h" |
35 | 35 |
36 DEFINE_bool(gen_ref, false, "Generate reference files."); | 36 DEFINE_bool(gen_ref, false, "Generate reference files."); |
37 | 37 |
38 namespace webrtc { | 38 namespace webrtc { |
39 | 39 |
40 static bool IsAllZero(const int16_t* buf, int buf_length) { | 40 static bool IsAllZero(const int16_t* buf, size_t buf_length) { |
41 bool all_zero = true; | 41 bool all_zero = true; |
42 for (int n = 0; n < buf_length && all_zero; ++n) | 42 for (size_t n = 0; n < buf_length && all_zero; ++n) |
43 all_zero = buf[n] == 0; | 43 all_zero = buf[n] == 0; |
44 return all_zero; | 44 return all_zero; |
45 } | 45 } |
46 | 46 |
47 static bool IsAllNonZero(const int16_t* buf, int buf_length) { | 47 static bool IsAllNonZero(const int16_t* buf, size_t buf_length) { |
48 bool all_non_zero = true; | 48 bool all_non_zero = true; |
49 for (int n = 0; n < buf_length && all_non_zero; ++n) | 49 for (size_t n = 0; n < buf_length && all_non_zero; ++n) |
50 all_non_zero = buf[n] != 0; | 50 all_non_zero = buf[n] != 0; |
51 return all_non_zero; | 51 return all_non_zero; |
52 } | 52 } |
53 | 53 |
54 class RefFiles { | 54 class RefFiles { |
55 public: | 55 public: |
56 RefFiles(const std::string& input_file, const std::string& output_file); | 56 RefFiles(const std::string& input_file, const std::string& output_file); |
57 ~RefFiles(); | 57 ~RefFiles(); |
58 template<class T> void ProcessReference(const T& test_results); | 58 template<class T> void ProcessReference(const T& test_results); |
59 template<typename T, size_t n> void ProcessReference( | 59 template<typename T, size_t n> void ProcessReference( |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
165 ASSERT_EQ(stats.current_buffer_size_ms, ref_stats.current_buffer_size_ms); | 165 ASSERT_EQ(stats.current_buffer_size_ms, ref_stats.current_buffer_size_ms); |
166 ASSERT_EQ(stats.preferred_buffer_size_ms, | 166 ASSERT_EQ(stats.preferred_buffer_size_ms, |
167 ref_stats.preferred_buffer_size_ms); | 167 ref_stats.preferred_buffer_size_ms); |
168 ASSERT_EQ(stats.jitter_peaks_found, ref_stats.jitter_peaks_found); | 168 ASSERT_EQ(stats.jitter_peaks_found, ref_stats.jitter_peaks_found); |
169 ASSERT_EQ(stats.packet_loss_rate, ref_stats.packet_loss_rate); | 169 ASSERT_EQ(stats.packet_loss_rate, ref_stats.packet_loss_rate); |
170 ASSERT_EQ(stats.packet_discard_rate, ref_stats.packet_discard_rate); | 170 ASSERT_EQ(stats.packet_discard_rate, ref_stats.packet_discard_rate); |
171 ASSERT_EQ(stats.expand_rate, ref_stats.expand_rate); | 171 ASSERT_EQ(stats.expand_rate, ref_stats.expand_rate); |
172 ASSERT_EQ(stats.preemptive_rate, ref_stats.preemptive_rate); | 172 ASSERT_EQ(stats.preemptive_rate, ref_stats.preemptive_rate); |
173 ASSERT_EQ(stats.accelerate_rate, ref_stats.accelerate_rate); | 173 ASSERT_EQ(stats.accelerate_rate, ref_stats.accelerate_rate); |
174 ASSERT_EQ(stats.clockdrift_ppm, ref_stats.clockdrift_ppm); | 174 ASSERT_EQ(stats.clockdrift_ppm, ref_stats.clockdrift_ppm); |
175 ASSERT_EQ(stats.added_zero_samples, ref_stats.added_zero_samples); | 175 ASSERT_EQ(stats.added_zero_samples, |
176 static_cast<size_t>(ref_stats.added_zero_samples)); | |
176 ASSERT_EQ(stats.secondary_decoded_rate, 0); | 177 ASSERT_EQ(stats.secondary_decoded_rate, 0); |
177 ASSERT_LE(stats.speech_expand_rate, ref_stats.expand_rate); | 178 ASSERT_LE(stats.speech_expand_rate, ref_stats.expand_rate); |
178 } | 179 } |
179 } | 180 } |
180 | 181 |
181 void RefFiles::WriteToFile(const RtcpStatistics& stats) { | 182 void RefFiles::WriteToFile(const RtcpStatistics& stats) { |
182 if (output_fp_) { | 183 if (output_fp_) { |
183 ASSERT_EQ(1u, fwrite(&(stats.fraction_lost), sizeof(stats.fraction_lost), 1, | 184 ASSERT_EQ(1u, fwrite(&(stats.fraction_lost), sizeof(stats.fraction_lost), 1, |
184 output_fp_)); | 185 output_fp_)); |
185 ASSERT_EQ(1u, fwrite(&(stats.cumulative_lost), | 186 ASSERT_EQ(1u, fwrite(&(stats.cumulative_lost), |
(...skipping 27 matching lines...) Expand all Loading... | |
213 stats.extended_max_sequence_number); | 214 stats.extended_max_sequence_number); |
214 ASSERT_EQ(ref_stats.jitter, stats.jitter); | 215 ASSERT_EQ(ref_stats.jitter, stats.jitter); |
215 } | 216 } |
216 } | 217 } |
217 | 218 |
218 class NetEqDecodingTest : public ::testing::Test { | 219 class NetEqDecodingTest : public ::testing::Test { |
219 protected: | 220 protected: |
220 // NetEQ must be polled for data once every 10 ms. Thus, neither of the | 221 // NetEQ must be polled for data once every 10 ms. Thus, neither of the |
221 // constants below can be changed. | 222 // constants below can be changed. |
222 static const int kTimeStepMs = 10; | 223 static const int kTimeStepMs = 10; |
223 static const int kBlockSize8kHz = kTimeStepMs * 8; | 224 static const size_t kBlockSize8kHz = kTimeStepMs * 8; |
224 static const int kBlockSize16kHz = kTimeStepMs * 16; | 225 static const size_t kBlockSize16kHz = kTimeStepMs * 16; |
225 static const int kBlockSize32kHz = kTimeStepMs * 32; | 226 static const size_t kBlockSize32kHz = kTimeStepMs * 32; |
226 static const size_t kMaxBlockSize = kBlockSize32kHz; | 227 static const size_t kMaxBlockSize = kBlockSize32kHz; |
227 static const int kInitSampleRateHz = 8000; | 228 static const int kInitSampleRateHz = 8000; |
228 | 229 |
229 NetEqDecodingTest(); | 230 NetEqDecodingTest(); |
230 virtual void SetUp(); | 231 virtual void SetUp(); |
231 virtual void TearDown(); | 232 virtual void TearDown(); |
232 void SelectDecoders(NetEqDecoder* used_codec); | 233 void SelectDecoders(NetEqDecoder* used_codec); |
233 void LoadDecoders(); | 234 void LoadDecoders(); |
234 void OpenInputFile(const std::string &rtp_file); | 235 void OpenInputFile(const std::string &rtp_file); |
235 void Process(int* out_len); | 236 void Process(size_t* out_len); |
236 void DecodeAndCompare(const std::string& rtp_file, | 237 void DecodeAndCompare(const std::string& rtp_file, |
237 const std::string& ref_file, | 238 const std::string& ref_file, |
238 const std::string& stat_ref_file, | 239 const std::string& stat_ref_file, |
239 const std::string& rtcp_ref_file); | 240 const std::string& rtcp_ref_file); |
240 static void PopulateRtpInfo(int frame_index, | 241 static void PopulateRtpInfo(int frame_index, |
241 int timestamp, | 242 int timestamp, |
242 WebRtcRTPHeader* rtp_info); | 243 WebRtcRTPHeader* rtp_info); |
243 static void PopulateCng(int frame_index, | 244 static void PopulateCng(int frame_index, |
244 int timestamp, | 245 int timestamp, |
245 WebRtcRTPHeader* rtp_info, | 246 WebRtcRTPHeader* rtp_info, |
(...skipping 19 matching lines...) Expand all Loading... | |
265 rtc::scoped_ptr<test::RtpFileSource> rtp_source_; | 266 rtc::scoped_ptr<test::RtpFileSource> rtp_source_; |
266 rtc::scoped_ptr<test::Packet> packet_; | 267 rtc::scoped_ptr<test::Packet> packet_; |
267 unsigned int sim_clock_; | 268 unsigned int sim_clock_; |
268 int16_t out_data_[kMaxBlockSize]; | 269 int16_t out_data_[kMaxBlockSize]; |
269 int output_sample_rate_; | 270 int output_sample_rate_; |
270 int algorithmic_delay_ms_; | 271 int algorithmic_delay_ms_; |
271 }; | 272 }; |
272 | 273 |
273 // Allocating the static const so that it can be passed by reference. | 274 // Allocating the static const so that it can be passed by reference. |
274 const int NetEqDecodingTest::kTimeStepMs; | 275 const int NetEqDecodingTest::kTimeStepMs; |
275 const int NetEqDecodingTest::kBlockSize8kHz; | 276 const size_t NetEqDecodingTest::kBlockSize8kHz; |
276 const int NetEqDecodingTest::kBlockSize16kHz; | 277 const size_t NetEqDecodingTest::kBlockSize16kHz; |
277 const int NetEqDecodingTest::kBlockSize32kHz; | 278 const size_t NetEqDecodingTest::kBlockSize32kHz; |
278 const size_t NetEqDecodingTest::kMaxBlockSize; | 279 const size_t NetEqDecodingTest::kMaxBlockSize; |
279 const int NetEqDecodingTest::kInitSampleRateHz; | 280 const int NetEqDecodingTest::kInitSampleRateHz; |
280 | 281 |
281 NetEqDecodingTest::NetEqDecodingTest() | 282 NetEqDecodingTest::NetEqDecodingTest() |
282 : neteq_(NULL), | 283 : neteq_(NULL), |
283 config_(), | 284 config_(), |
284 sim_clock_(0), | 285 sim_clock_(0), |
285 output_sample_rate_(kInitSampleRateHz), | 286 output_sample_rate_(kInitSampleRateHz), |
286 algorithmic_delay_ms_(0) { | 287 algorithmic_delay_ms_(0) { |
287 config_.sample_rate_hz = kInitSampleRateHz; | 288 config_.sample_rate_hz = kInitSampleRateHz; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
327 // Load CNG 8 kHz. | 328 // Load CNG 8 kHz. |
328 ASSERT_EQ(0, neteq_->RegisterPayloadType(kDecoderCNGnb, 13)); | 329 ASSERT_EQ(0, neteq_->RegisterPayloadType(kDecoderCNGnb, 13)); |
329 // Load CNG 16 kHz. | 330 // Load CNG 16 kHz. |
330 ASSERT_EQ(0, neteq_->RegisterPayloadType(kDecoderCNGwb, 98)); | 331 ASSERT_EQ(0, neteq_->RegisterPayloadType(kDecoderCNGwb, 98)); |
331 } | 332 } |
332 | 333 |
333 void NetEqDecodingTest::OpenInputFile(const std::string &rtp_file) { | 334 void NetEqDecodingTest::OpenInputFile(const std::string &rtp_file) { |
334 rtp_source_.reset(test::RtpFileSource::Create(rtp_file)); | 335 rtp_source_.reset(test::RtpFileSource::Create(rtp_file)); |
335 } | 336 } |
336 | 337 |
337 void NetEqDecodingTest::Process(int* out_len) { | 338 void NetEqDecodingTest::Process(size_t* out_len) { |
338 // Check if time to receive. | 339 // Check if time to receive. |
339 while (packet_ && sim_clock_ >= packet_->time_ms()) { | 340 while (packet_ && sim_clock_ >= packet_->time_ms()) { |
340 if (packet_->payload_length_bytes() > 0) { | 341 if (packet_->payload_length_bytes() > 0) { |
341 WebRtcRTPHeader rtp_header; | 342 WebRtcRTPHeader rtp_header; |
342 packet_->ConvertHeader(&rtp_header); | 343 packet_->ConvertHeader(&rtp_header); |
343 ASSERT_EQ(0, neteq_->InsertPacket( | 344 ASSERT_EQ(0, neteq_->InsertPacket( |
344 rtp_header, packet_->payload(), | 345 rtp_header, packet_->payload(), |
345 packet_->payload_length_bytes(), | 346 packet_->payload_length_bytes(), |
346 static_cast<uint32_t>( | 347 static_cast<uint32_t>( |
347 packet_->time_ms() * (output_sample_rate_ / 1000)))); | 348 packet_->time_ms() * (output_sample_rate_ / 1000)))); |
348 } | 349 } |
349 // Get next packet. | 350 // Get next packet. |
350 packet_.reset(rtp_source_->NextPacket()); | 351 packet_.reset(rtp_source_->NextPacket()); |
351 } | 352 } |
352 | 353 |
353 // Get audio from NetEq. | 354 // Get audio from NetEq. |
354 NetEqOutputType type; | 355 NetEqOutputType type; |
355 int num_channels; | 356 int num_channels; |
356 ASSERT_EQ(0, neteq_->GetAudio(kMaxBlockSize, out_data_, out_len, | 357 ASSERT_EQ(0, neteq_->GetAudio(kMaxBlockSize, out_data_, out_len, |
357 &num_channels, &type)); | 358 &num_channels, &type)); |
358 ASSERT_TRUE((*out_len == kBlockSize8kHz) || | 359 ASSERT_TRUE((*out_len == kBlockSize8kHz) || |
359 (*out_len == kBlockSize16kHz) || | 360 (*out_len == kBlockSize16kHz) || |
360 (*out_len == kBlockSize32kHz)); | 361 (*out_len == kBlockSize32kHz)); |
361 output_sample_rate_ = *out_len / 10 * 1000; | 362 output_sample_rate_ = static_cast<int>(*out_len / 10 * 1000); |
hlundin-webrtc
2015/08/10 11:30:01
rtc::checked_cast
Peter Kasting
2015/08/17 22:49:47
This shouldn't be necessary, as the ASSERT_TRUE ju
hlundin-webrtc
2015/08/18 07:19:18
Acknowledged.
| |
362 | 363 |
363 // Increase time. | 364 // Increase time. |
364 sim_clock_ += kTimeStepMs; | 365 sim_clock_ += kTimeStepMs; |
365 } | 366 } |
366 | 367 |
367 void NetEqDecodingTest::DecodeAndCompare(const std::string& rtp_file, | 368 void NetEqDecodingTest::DecodeAndCompare(const std::string& rtp_file, |
368 const std::string& ref_file, | 369 const std::string& ref_file, |
369 const std::string& stat_ref_file, | 370 const std::string& stat_ref_file, |
370 const std::string& rtcp_ref_file) { | 371 const std::string& rtcp_ref_file) { |
371 OpenInputFile(rtp_file); | 372 OpenInputFile(rtp_file); |
(...skipping 15 matching lines...) Expand all Loading... | |
387 rtcp_out_file = webrtc::test::OutputPath() + "neteq_rtcp_stats.dat"; | 388 rtcp_out_file = webrtc::test::OutputPath() + "neteq_rtcp_stats.dat"; |
388 } | 389 } |
389 RefFiles rtcp_stat_files(rtcp_ref_file, rtcp_out_file); | 390 RefFiles rtcp_stat_files(rtcp_ref_file, rtcp_out_file); |
390 | 391 |
391 packet_.reset(rtp_source_->NextPacket()); | 392 packet_.reset(rtp_source_->NextPacket()); |
392 int i = 0; | 393 int i = 0; |
393 while (packet_) { | 394 while (packet_) { |
394 std::ostringstream ss; | 395 std::ostringstream ss; |
395 ss << "Lap number " << i++ << " in DecodeAndCompare while loop"; | 396 ss << "Lap number " << i++ << " in DecodeAndCompare while loop"; |
396 SCOPED_TRACE(ss.str()); // Print out the parameter values on failure. | 397 SCOPED_TRACE(ss.str()); // Print out the parameter values on failure. |
397 int out_len = 0; | 398 size_t out_len = 0; |
398 ASSERT_NO_FATAL_FAILURE(Process(&out_len)); | 399 ASSERT_NO_FATAL_FAILURE(Process(&out_len)); |
399 ASSERT_NO_FATAL_FAILURE(ref_files.ProcessReference(out_data_, out_len)); | 400 ASSERT_NO_FATAL_FAILURE(ref_files.ProcessReference(out_data_, out_len)); |
400 | 401 |
401 // Query the network statistics API once per second | 402 // Query the network statistics API once per second |
402 if (sim_clock_ % 1000 == 0) { | 403 if (sim_clock_ % 1000 == 0) { |
403 // Process NetworkStatistics. | 404 // Process NetworkStatistics. |
404 NetEqNetworkStatistics network_stats; | 405 NetEqNetworkStatistics network_stats; |
405 ASSERT_EQ(0, neteq_->NetworkStatistics(&network_stats)); | 406 ASSERT_EQ(0, neteq_->NetworkStatistics(&network_stats)); |
406 ASSERT_NO_FATAL_FAILURE( | 407 ASSERT_NO_FATAL_FAILURE( |
407 network_stat_files.ProcessReference(network_stats)); | 408 network_stat_files.ProcessReference(network_stats)); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
491 rtp_info.header.ssrc = 0x1234; // Just an arbitrary SSRC. | 492 rtp_info.header.ssrc = 0x1234; // Just an arbitrary SSRC. |
492 rtp_info.header.payloadType = 94; // PCM16b WB codec. | 493 rtp_info.header.payloadType = 94; // PCM16b WB codec. |
493 rtp_info.header.markerBit = 0; | 494 rtp_info.header.markerBit = 0; |
494 ASSERT_EQ(0, neteq_->InsertPacket( | 495 ASSERT_EQ(0, neteq_->InsertPacket( |
495 rtp_info, | 496 rtp_info, |
496 reinterpret_cast<uint8_t*>(payload), | 497 reinterpret_cast<uint8_t*>(payload), |
497 kPayloadBytes, 0)); | 498 kPayloadBytes, 0)); |
498 } | 499 } |
499 // Pull out all data. | 500 // Pull out all data. |
500 for (size_t i = 0; i < num_frames; ++i) { | 501 for (size_t i = 0; i < num_frames; ++i) { |
501 int out_len; | 502 size_t out_len; |
502 int num_channels; | 503 int num_channels; |
503 NetEqOutputType type; | 504 NetEqOutputType type; |
504 ASSERT_EQ(0, neteq_->GetAudio(kMaxBlockSize, out_data_, &out_len, | 505 ASSERT_EQ(0, neteq_->GetAudio(kMaxBlockSize, out_data_, &out_len, |
505 &num_channels, &type)); | 506 &num_channels, &type)); |
506 ASSERT_EQ(kBlockSize16kHz, out_len); | 507 ASSERT_EQ(kBlockSize16kHz, out_len); |
507 } | 508 } |
508 | 509 |
509 std::vector<int> waiting_times; | 510 std::vector<int> waiting_times; |
510 neteq_->WaitingTimes(&waiting_times); | 511 neteq_->WaitingTimes(&waiting_times); |
511 EXPECT_EQ(num_frames, waiting_times.size()); | 512 EXPECT_EQ(num_frames, waiting_times.size()); |
(...skipping 17 matching lines...) Expand all Loading... | |
529 WebRtcRTPHeader rtp_info; | 530 WebRtcRTPHeader rtp_info; |
530 rtp_info.header.sequenceNumber = i; | 531 rtp_info.header.sequenceNumber = i; |
531 rtp_info.header.timestamp = i * kSamples; | 532 rtp_info.header.timestamp = i * kSamples; |
532 rtp_info.header.ssrc = 0x1235; // Just an arbitrary SSRC. | 533 rtp_info.header.ssrc = 0x1235; // Just an arbitrary SSRC. |
533 rtp_info.header.payloadType = 94; // PCM16b WB codec. | 534 rtp_info.header.payloadType = 94; // PCM16b WB codec. |
534 rtp_info.header.markerBit = 0; | 535 rtp_info.header.markerBit = 0; |
535 ASSERT_EQ(0, neteq_->InsertPacket( | 536 ASSERT_EQ(0, neteq_->InsertPacket( |
536 rtp_info, | 537 rtp_info, |
537 reinterpret_cast<uint8_t*>(payload), | 538 reinterpret_cast<uint8_t*>(payload), |
538 kPayloadBytes, 0)); | 539 kPayloadBytes, 0)); |
539 int out_len; | 540 size_t out_len; |
540 int num_channels; | 541 int num_channels; |
541 NetEqOutputType type; | 542 NetEqOutputType type; |
542 ASSERT_EQ(0, neteq_->GetAudio(kMaxBlockSize, out_data_, &out_len, | 543 ASSERT_EQ(0, neteq_->GetAudio(kMaxBlockSize, out_data_, &out_len, |
543 &num_channels, &type)); | 544 &num_channels, &type)); |
544 ASSERT_EQ(kBlockSize16kHz, out_len); | 545 ASSERT_EQ(kBlockSize16kHz, out_len); |
545 } | 546 } |
546 | 547 |
547 neteq_->WaitingTimes(&waiting_times); | 548 neteq_->WaitingTimes(&waiting_times); |
548 EXPECT_EQ(100u, waiting_times.size()); | 549 EXPECT_EQ(100u, waiting_times.size()); |
549 } | 550 } |
550 | 551 |
551 TEST_F(NetEqDecodingTest, TestAverageInterArrivalTimeNegative) { | 552 TEST_F(NetEqDecodingTest, TestAverageInterArrivalTimeNegative) { |
552 const int kNumFrames = 3000; // Needed for convergence. | 553 const int kNumFrames = 3000; // Needed for convergence. |
553 int frame_index = 0; | 554 int frame_index = 0; |
554 const size_t kSamples = 10 * 16; | 555 const size_t kSamples = 10 * 16; |
555 const size_t kPayloadBytes = kSamples * 2; | 556 const size_t kPayloadBytes = kSamples * 2; |
556 while (frame_index < kNumFrames) { | 557 while (frame_index < kNumFrames) { |
557 // Insert one packet each time, except every 10th time where we insert two | 558 // Insert one packet each time, except every 10th time where we insert two |
558 // packets at once. This will create a negative clock-drift of approx. 10%. | 559 // packets at once. This will create a negative clock-drift of approx. 10%. |
559 int num_packets = (frame_index % 10 == 0 ? 2 : 1); | 560 int num_packets = (frame_index % 10 == 0 ? 2 : 1); |
560 for (int n = 0; n < num_packets; ++n) { | 561 for (int n = 0; n < num_packets; ++n) { |
561 uint8_t payload[kPayloadBytes] = {0}; | 562 uint8_t payload[kPayloadBytes] = {0}; |
562 WebRtcRTPHeader rtp_info; | 563 WebRtcRTPHeader rtp_info; |
563 PopulateRtpInfo(frame_index, frame_index * kSamples, &rtp_info); | 564 PopulateRtpInfo(frame_index, frame_index * kSamples, &rtp_info); |
564 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, kPayloadBytes, 0)); | 565 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, kPayloadBytes, 0)); |
565 ++frame_index; | 566 ++frame_index; |
566 } | 567 } |
567 | 568 |
568 // Pull out data once. | 569 // Pull out data once. |
569 int out_len; | 570 size_t out_len; |
570 int num_channels; | 571 int num_channels; |
571 NetEqOutputType type; | 572 NetEqOutputType type; |
572 ASSERT_EQ(0, neteq_->GetAudio(kMaxBlockSize, out_data_, &out_len, | 573 ASSERT_EQ(0, neteq_->GetAudio(kMaxBlockSize, out_data_, &out_len, |
573 &num_channels, &type)); | 574 &num_channels, &type)); |
574 ASSERT_EQ(kBlockSize16kHz, out_len); | 575 ASSERT_EQ(kBlockSize16kHz, out_len); |
575 } | 576 } |
576 | 577 |
577 NetEqNetworkStatistics network_stats; | 578 NetEqNetworkStatistics network_stats; |
578 ASSERT_EQ(0, neteq_->NetworkStatistics(&network_stats)); | 579 ASSERT_EQ(0, neteq_->NetworkStatistics(&network_stats)); |
579 EXPECT_EQ(-103196, network_stats.clockdrift_ppm); | 580 EXPECT_EQ(-103196, network_stats.clockdrift_ppm); |
(...skipping 10 matching lines...) Expand all Loading... | |
590 int num_packets = (i % 10 == 9 ? 0 : 1); | 591 int num_packets = (i % 10 == 9 ? 0 : 1); |
591 for (int n = 0; n < num_packets; ++n) { | 592 for (int n = 0; n < num_packets; ++n) { |
592 uint8_t payload[kPayloadBytes] = {0}; | 593 uint8_t payload[kPayloadBytes] = {0}; |
593 WebRtcRTPHeader rtp_info; | 594 WebRtcRTPHeader rtp_info; |
594 PopulateRtpInfo(frame_index, frame_index * kSamples, &rtp_info); | 595 PopulateRtpInfo(frame_index, frame_index * kSamples, &rtp_info); |
595 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, kPayloadBytes, 0)); | 596 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, kPayloadBytes, 0)); |
596 ++frame_index; | 597 ++frame_index; |
597 } | 598 } |
598 | 599 |
599 // Pull out data once. | 600 // Pull out data once. |
600 int out_len; | 601 size_t out_len; |
601 int num_channels; | 602 int num_channels; |
602 NetEqOutputType type; | 603 NetEqOutputType type; |
603 ASSERT_EQ(0, neteq_->GetAudio(kMaxBlockSize, out_data_, &out_len, | 604 ASSERT_EQ(0, neteq_->GetAudio(kMaxBlockSize, out_data_, &out_len, |
604 &num_channels, &type)); | 605 &num_channels, &type)); |
605 ASSERT_EQ(kBlockSize16kHz, out_len); | 606 ASSERT_EQ(kBlockSize16kHz, out_len); |
606 } | 607 } |
607 | 608 |
608 NetEqNetworkStatistics network_stats; | 609 NetEqNetworkStatistics network_stats; |
609 ASSERT_EQ(0, neteq_->NetworkStatistics(&network_stats)); | 610 ASSERT_EQ(0, neteq_->NetworkStatistics(&network_stats)); |
610 EXPECT_EQ(110946, network_stats.clockdrift_ppm); | 611 EXPECT_EQ(110946, network_stats.clockdrift_ppm); |
611 } | 612 } |
612 | 613 |
613 void NetEqDecodingTest::LongCngWithClockDrift(double drift_factor, | 614 void NetEqDecodingTest::LongCngWithClockDrift(double drift_factor, |
614 double network_freeze_ms, | 615 double network_freeze_ms, |
615 bool pull_audio_during_freeze, | 616 bool pull_audio_during_freeze, |
616 int delay_tolerance_ms, | 617 int delay_tolerance_ms, |
617 int max_time_to_speech_ms) { | 618 int max_time_to_speech_ms) { |
618 uint16_t seq_no = 0; | 619 uint16_t seq_no = 0; |
619 uint32_t timestamp = 0; | 620 uint32_t timestamp = 0; |
620 const int kFrameSizeMs = 30; | 621 const int kFrameSizeMs = 30; |
621 const size_t kSamples = kFrameSizeMs * 16; | 622 const size_t kSamples = kFrameSizeMs * 16; |
622 const size_t kPayloadBytes = kSamples * 2; | 623 const size_t kPayloadBytes = kSamples * 2; |
623 double next_input_time_ms = 0.0; | 624 double next_input_time_ms = 0.0; |
624 double t_ms; | 625 double t_ms; |
625 int out_len; | 626 size_t out_len; |
626 int num_channels; | 627 int num_channels; |
627 NetEqOutputType type; | 628 NetEqOutputType type; |
628 | 629 |
629 // Insert speech for 5 seconds. | 630 // Insert speech for 5 seconds. |
630 const int kSpeechDurationMs = 5000; | 631 const int kSpeechDurationMs = 5000; |
631 for (t_ms = 0; t_ms < kSpeechDurationMs; t_ms += 10) { | 632 for (t_ms = 0; t_ms < kSpeechDurationMs; t_ms += 10) { |
632 // Each turn in this for loop is 10 ms. | 633 // Each turn in this for loop is 10 ms. |
633 while (next_input_time_ms <= t_ms) { | 634 while (next_input_time_ms <= t_ms) { |
634 // Insert one 30 ms speech frame. | 635 // Insert one 30 ms speech frame. |
635 uint8_t payload[kPayloadBytes] = {0}; | 636 uint8_t payload[kPayloadBytes] = {0}; |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
847 PopulateRtpInfo(0, 0, &rtp_info); | 848 PopulateRtpInfo(0, 0, &rtp_info); |
848 rtp_info.header.payloadType = 103; // iSAC, but the payload is invalid. | 849 rtp_info.header.payloadType = 103; // iSAC, but the payload is invalid. |
849 EXPECT_EQ(0, neteq_->InsertPacket(rtp_info, payload, kPayloadBytes, 0)); | 850 EXPECT_EQ(0, neteq_->InsertPacket(rtp_info, payload, kPayloadBytes, 0)); |
850 NetEqOutputType type; | 851 NetEqOutputType type; |
851 // Set all of |out_data_| to 1, and verify that it was set to 0 by the call | 852 // Set all of |out_data_| to 1, and verify that it was set to 0 by the call |
852 // to GetAudio. | 853 // to GetAudio. |
853 for (size_t i = 0; i < kMaxBlockSize; ++i) { | 854 for (size_t i = 0; i < kMaxBlockSize; ++i) { |
854 out_data_[i] = 1; | 855 out_data_[i] = 1; |
855 } | 856 } |
856 int num_channels; | 857 int num_channels; |
857 int samples_per_channel; | 858 size_t samples_per_channel; |
858 EXPECT_EQ(NetEq::kFail, | 859 EXPECT_EQ(NetEq::kFail, |
859 neteq_->GetAudio(kMaxBlockSize, out_data_, | 860 neteq_->GetAudio(kMaxBlockSize, out_data_, |
860 &samples_per_channel, &num_channels, &type)); | 861 &samples_per_channel, &num_channels, &type)); |
861 // Verify that there is a decoder error to check. | 862 // Verify that there is a decoder error to check. |
862 EXPECT_EQ(NetEq::kDecoderErrorCode, neteq_->LastError()); | 863 EXPECT_EQ(NetEq::kDecoderErrorCode, neteq_->LastError()); |
863 // Code 6730 is an iSAC error code. | 864 // Code 6730 is an iSAC error code. |
864 EXPECT_EQ(6730, neteq_->LastDecoderError()); | 865 EXPECT_EQ(6730, neteq_->LastDecoderError()); |
865 // Verify that the first 160 samples are set to 0, and that the remaining | 866 // Verify that the first 160 samples are set to 0, and that the remaining |
866 // samples are left unmodified. | 867 // samples are left unmodified. |
867 static const int kExpectedOutputLength = 160; // 10 ms at 16 kHz sample rate. | 868 static const int kExpectedOutputLength = 160; // 10 ms at 16 kHz sample rate. |
(...skipping 12 matching lines...) Expand all Loading... | |
880 } | 881 } |
881 | 882 |
882 TEST_F(NetEqDecodingTest, GetAudioBeforeInsertPacket) { | 883 TEST_F(NetEqDecodingTest, GetAudioBeforeInsertPacket) { |
883 NetEqOutputType type; | 884 NetEqOutputType type; |
884 // Set all of |out_data_| to 1, and verify that it was set to 0 by the call | 885 // Set all of |out_data_| to 1, and verify that it was set to 0 by the call |
885 // to GetAudio. | 886 // to GetAudio. |
886 for (size_t i = 0; i < kMaxBlockSize; ++i) { | 887 for (size_t i = 0; i < kMaxBlockSize; ++i) { |
887 out_data_[i] = 1; | 888 out_data_[i] = 1; |
888 } | 889 } |
889 int num_channels; | 890 int num_channels; |
890 int samples_per_channel; | 891 size_t samples_per_channel; |
891 EXPECT_EQ(0, neteq_->GetAudio(kMaxBlockSize, out_data_, | 892 EXPECT_EQ(0, neteq_->GetAudio(kMaxBlockSize, out_data_, |
892 &samples_per_channel, | 893 &samples_per_channel, |
893 &num_channels, &type)); | 894 &num_channels, &type)); |
894 // Verify that the first block of samples is set to 0. | 895 // Verify that the first block of samples is set to 0. |
895 static const int kExpectedOutputLength = | 896 static const int kExpectedOutputLength = |
896 kInitSampleRateHz / 100; // 10 ms at initial sample rate. | 897 kInitSampleRateHz / 100; // 10 ms at initial sample rate. |
897 for (int i = 0; i < kExpectedOutputLength; ++i) { | 898 for (int i = 0; i < kExpectedOutputLength; ++i) { |
898 std::ostringstream ss; | 899 std::ostringstream ss; |
899 ss << "i = " << i; | 900 ss << "i = " << i; |
900 SCOPED_TRACE(ss.str()); // Print out the parameter values on failure. | 901 SCOPED_TRACE(ss.str()); // Print out the parameter values on failure. |
901 EXPECT_EQ(0, out_data_[i]); | 902 EXPECT_EQ(0, out_data_[i]); |
902 } | 903 } |
903 } | 904 } |
904 | 905 |
905 class NetEqBgnTest : public NetEqDecodingTest { | 906 class NetEqBgnTest : public NetEqDecodingTest { |
906 protected: | 907 protected: |
907 virtual void TestCondition(double sum_squared_noise, | 908 virtual void TestCondition(double sum_squared_noise, |
908 bool should_be_faded) = 0; | 909 bool should_be_faded) = 0; |
909 | 910 |
910 void CheckBgn(int sampling_rate_hz) { | 911 void CheckBgn(int sampling_rate_hz) { |
911 int16_t expected_samples_per_channel = 0; | 912 size_t expected_samples_per_channel = 0; |
912 uint8_t payload_type = 0xFF; // Invalid. | 913 uint8_t payload_type = 0xFF; // Invalid. |
913 if (sampling_rate_hz == 8000) { | 914 if (sampling_rate_hz == 8000) { |
914 expected_samples_per_channel = kBlockSize8kHz; | 915 expected_samples_per_channel = kBlockSize8kHz; |
915 payload_type = 93; // PCM 16, 8 kHz. | 916 payload_type = 93; // PCM 16, 8 kHz. |
916 } else if (sampling_rate_hz == 16000) { | 917 } else if (sampling_rate_hz == 16000) { |
917 expected_samples_per_channel = kBlockSize16kHz; | 918 expected_samples_per_channel = kBlockSize16kHz; |
918 payload_type = 94; // PCM 16, 16 kHZ. | 919 payload_type = 94; // PCM 16, 16 kHZ. |
919 } else if (sampling_rate_hz == 32000) { | 920 } else if (sampling_rate_hz == 32000) { |
920 expected_samples_per_channel = kBlockSize32kHz; | 921 expected_samples_per_channel = kBlockSize32kHz; |
921 payload_type = 95; // PCM 16, 32 kHz. | 922 payload_type = 95; // PCM 16, 32 kHz. |
922 } else { | 923 } else { |
923 ASSERT_TRUE(false); // Unsupported test case. | 924 ASSERT_TRUE(false); // Unsupported test case. |
924 } | 925 } |
925 | 926 |
926 NetEqOutputType type; | 927 NetEqOutputType type; |
927 int16_t output[kBlockSize32kHz]; // Maximum size is chosen. | 928 int16_t output[kBlockSize32kHz]; // Maximum size is chosen. |
928 test::AudioLoop input; | 929 test::AudioLoop input; |
929 // We are using the same 32 kHz input file for all tests, regardless of | 930 // We are using the same 32 kHz input file for all tests, regardless of |
930 // |sampling_rate_hz|. The output may sound weird, but the test is still | 931 // |sampling_rate_hz|. The output may sound weird, but the test is still |
931 // valid. | 932 // valid. |
932 ASSERT_TRUE(input.Init( | 933 ASSERT_TRUE(input.Init( |
933 webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm"), | 934 webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm"), |
934 10 * sampling_rate_hz, // Max 10 seconds loop length. | 935 10 * sampling_rate_hz, // Max 10 seconds loop length. |
935 static_cast<size_t>(expected_samples_per_channel))); | 936 expected_samples_per_channel)); |
936 | 937 |
937 // Payload of 10 ms of PCM16 32 kHz. | 938 // Payload of 10 ms of PCM16 32 kHz. |
938 uint8_t payload[kBlockSize32kHz * sizeof(int16_t)]; | 939 uint8_t payload[kBlockSize32kHz * sizeof(int16_t)]; |
939 WebRtcRTPHeader rtp_info; | 940 WebRtcRTPHeader rtp_info; |
940 PopulateRtpInfo(0, 0, &rtp_info); | 941 PopulateRtpInfo(0, 0, &rtp_info); |
941 rtp_info.header.payloadType = payload_type; | 942 rtp_info.header.payloadType = payload_type; |
942 | 943 |
943 int number_channels = 0; | 944 int number_channels = 0; |
944 int samples_per_channel = 0; | 945 size_t samples_per_channel = 0; |
945 | 946 |
946 uint32_t receive_timestamp = 0; | 947 uint32_t receive_timestamp = 0; |
947 for (int n = 0; n < 10; ++n) { // Insert few packets and get audio. | 948 for (int n = 0; n < 10; ++n) { // Insert few packets and get audio. |
948 int16_t enc_len_bytes = WebRtcPcm16b_Encode( | 949 size_t enc_len_bytes = WebRtcPcm16b_Encode( |
949 input.GetNextBlock(), expected_samples_per_channel, payload); | 950 input.GetNextBlock(), expected_samples_per_channel, payload); |
950 ASSERT_EQ(enc_len_bytes, expected_samples_per_channel * 2); | 951 ASSERT_EQ(enc_len_bytes, expected_samples_per_channel * 2); |
951 | 952 |
952 number_channels = 0; | 953 number_channels = 0; |
953 samples_per_channel = 0; | 954 samples_per_channel = 0; |
954 ASSERT_EQ(0, | 955 ASSERT_EQ(0, |
955 neteq_->InsertPacket(rtp_info, payload, | 956 neteq_->InsertPacket(rtp_info, payload, enc_len_bytes, |
956 static_cast<size_t>(enc_len_bytes), | |
957 receive_timestamp)); | 957 receive_timestamp)); |
958 ASSERT_EQ(0, | 958 ASSERT_EQ(0, |
959 neteq_->GetAudio(kBlockSize32kHz, | 959 neteq_->GetAudio(kBlockSize32kHz, |
960 output, | 960 output, |
961 &samples_per_channel, | 961 &samples_per_channel, |
962 &number_channels, | 962 &number_channels, |
963 &type)); | 963 &type)); |
964 ASSERT_EQ(1, number_channels); | 964 ASSERT_EQ(1, number_channels); |
965 ASSERT_EQ(expected_samples_per_channel, samples_per_channel); | 965 ASSERT_EQ(expected_samples_per_channel, samples_per_channel); |
966 ASSERT_EQ(kOutputNormal, type); | 966 ASSERT_EQ(kOutputNormal, type); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1002 neteq_->GetAudio(kBlockSize32kHz, | 1002 neteq_->GetAudio(kBlockSize32kHz, |
1003 output, | 1003 output, |
1004 &samples_per_channel, | 1004 &samples_per_channel, |
1005 &number_channels, | 1005 &number_channels, |
1006 &type)); | 1006 &type)); |
1007 ASSERT_EQ(1, number_channels); | 1007 ASSERT_EQ(1, number_channels); |
1008 ASSERT_EQ(expected_samples_per_channel, samples_per_channel); | 1008 ASSERT_EQ(expected_samples_per_channel, samples_per_channel); |
1009 if (type == kOutputPLCtoCNG) { | 1009 if (type == kOutputPLCtoCNG) { |
1010 plc_to_cng = true; | 1010 plc_to_cng = true; |
1011 double sum_squared = 0; | 1011 double sum_squared = 0; |
1012 for (int k = 0; k < number_channels * samples_per_channel; ++k) | 1012 for (size_t k = 0; k < number_channels * samples_per_channel; ++k) |
1013 sum_squared += output[k] * output[k]; | 1013 sum_squared += output[k] * output[k]; |
1014 TestCondition(sum_squared, n > kFadingThreshold); | 1014 TestCondition(sum_squared, n > kFadingThreshold); |
1015 } else { | 1015 } else { |
1016 EXPECT_EQ(kOutputPLC, type); | 1016 EXPECT_EQ(kOutputPLC, type); |
1017 } | 1017 } |
1018 } | 1018 } |
1019 EXPECT_TRUE(plc_to_cng); // Just to be sure that PLC-to-CNG has occurred. | 1019 EXPECT_TRUE(plc_to_cng); // Just to be sure that PLC-to-CNG has occurred. |
1020 } | 1020 } |
1021 }; | 1021 }; |
1022 | 1022 |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1161 uint8_t payload[kPayloadBytes]; | 1161 uint8_t payload[kPayloadBytes]; |
1162 int16_t decoded[kBlockSize16kHz]; | 1162 int16_t decoded[kBlockSize16kHz]; |
1163 int algorithmic_frame_delay = algorithmic_delay_ms_ / 10 + 1; | 1163 int algorithmic_frame_delay = algorithmic_delay_ms_ / 10 + 1; |
1164 for (size_t n = 0; n < kPayloadBytes; ++n) { | 1164 for (size_t n = 0; n < kPayloadBytes; ++n) { |
1165 payload[n] = (rand() & 0xF0) + 1; // Non-zero random sequence. | 1165 payload[n] = (rand() & 0xF0) + 1; // Non-zero random sequence. |
1166 } | 1166 } |
1167 // Insert some packets which decode to noise. We are not interested in | 1167 // Insert some packets which decode to noise. We are not interested in |
1168 // actual decoded values. | 1168 // actual decoded values. |
1169 NetEqOutputType output_type; | 1169 NetEqOutputType output_type; |
1170 int num_channels; | 1170 int num_channels; |
1171 int samples_per_channel; | 1171 size_t samples_per_channel; |
1172 uint32_t receive_timestamp = 0; | 1172 uint32_t receive_timestamp = 0; |
1173 for (int n = 0; n < 100; ++n) { | 1173 for (int n = 0; n < 100; ++n) { |
1174 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, kPayloadBytes, | 1174 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, kPayloadBytes, |
1175 receive_timestamp)); | 1175 receive_timestamp)); |
1176 ASSERT_EQ(0, neteq_->GetAudio(kBlockSize16kHz, decoded, | 1176 ASSERT_EQ(0, neteq_->GetAudio(kBlockSize16kHz, decoded, |
1177 &samples_per_channel, &num_channels, | 1177 &samples_per_channel, &num_channels, |
1178 &output_type)); | 1178 &output_type)); |
1179 ASSERT_EQ(kBlockSize16kHz, samples_per_channel); | 1179 ASSERT_EQ(kBlockSize16kHz, samples_per_channel); |
1180 ASSERT_EQ(1, num_channels); | 1180 ASSERT_EQ(1, num_channels); |
1181 | 1181 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1239 const size_t kPayloadBytes = kBlockSize16kHz * sizeof(int16_t); | 1239 const size_t kPayloadBytes = kBlockSize16kHz * sizeof(int16_t); |
1240 uint8_t payload[kPayloadBytes]; | 1240 uint8_t payload[kPayloadBytes]; |
1241 int16_t decoded[kBlockSize16kHz]; | 1241 int16_t decoded[kBlockSize16kHz]; |
1242 for (size_t n = 0; n < kPayloadBytes; ++n) { | 1242 for (size_t n = 0; n < kPayloadBytes; ++n) { |
1243 payload[n] = (rand() & 0xF0) + 1; // Non-zero random sequence. | 1243 payload[n] = (rand() & 0xF0) + 1; // Non-zero random sequence. |
1244 } | 1244 } |
1245 // Insert some packets which decode to noise. We are not interested in | 1245 // Insert some packets which decode to noise. We are not interested in |
1246 // actual decoded values. | 1246 // actual decoded values. |
1247 NetEqOutputType output_type; | 1247 NetEqOutputType output_type; |
1248 int num_channels; | 1248 int num_channels; |
1249 int samples_per_channel; | 1249 size_t samples_per_channel; |
1250 uint32_t receive_timestamp = 0; | 1250 uint32_t receive_timestamp = 0; |
1251 int algorithmic_frame_delay = algorithmic_delay_ms_ / 10 + 1; | 1251 int algorithmic_frame_delay = algorithmic_delay_ms_ / 10 + 1; |
1252 for (int n = 0; n < algorithmic_frame_delay; ++n) { | 1252 for (int n = 0; n < algorithmic_frame_delay; ++n) { |
1253 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, kPayloadBytes, | 1253 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, kPayloadBytes, |
1254 receive_timestamp)); | 1254 receive_timestamp)); |
1255 ASSERT_EQ(0, neteq_->GetAudio(kBlockSize16kHz, decoded, | 1255 ASSERT_EQ(0, neteq_->GetAudio(kBlockSize16kHz, decoded, |
1256 &samples_per_channel, &num_channels, | 1256 &samples_per_channel, &num_channels, |
1257 &output_type)); | 1257 &output_type)); |
1258 ASSERT_EQ(kBlockSize16kHz, samples_per_channel); | 1258 ASSERT_EQ(kBlockSize16kHz, samples_per_channel); |
1259 ASSERT_EQ(1, num_channels); | 1259 ASSERT_EQ(1, num_channels); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1308 bool expect_timestamp_wrap) { | 1308 bool expect_timestamp_wrap) { |
1309 uint16_t seq_no = start_seq_no; | 1309 uint16_t seq_no = start_seq_no; |
1310 uint32_t timestamp = start_timestamp; | 1310 uint32_t timestamp = start_timestamp; |
1311 const int kBlocksPerFrame = 3; // Number of 10 ms blocks per frame. | 1311 const int kBlocksPerFrame = 3; // Number of 10 ms blocks per frame. |
1312 const int kFrameSizeMs = kBlocksPerFrame * kTimeStepMs; | 1312 const int kFrameSizeMs = kBlocksPerFrame * kTimeStepMs; |
1313 const int kSamples = kBlockSize16kHz * kBlocksPerFrame; | 1313 const int kSamples = kBlockSize16kHz * kBlocksPerFrame; |
1314 const size_t kPayloadBytes = kSamples * sizeof(int16_t); | 1314 const size_t kPayloadBytes = kSamples * sizeof(int16_t); |
1315 double next_input_time_ms = 0.0; | 1315 double next_input_time_ms = 0.0; |
1316 int16_t decoded[kBlockSize16kHz]; | 1316 int16_t decoded[kBlockSize16kHz]; |
1317 int num_channels; | 1317 int num_channels; |
1318 int samples_per_channel; | 1318 size_t samples_per_channel; |
1319 NetEqOutputType output_type; | 1319 NetEqOutputType output_type; |
1320 uint32_t receive_timestamp = 0; | 1320 uint32_t receive_timestamp = 0; |
1321 | 1321 |
1322 // Insert speech for 2 seconds. | 1322 // Insert speech for 2 seconds. |
1323 const int kSpeechDurationMs = 2000; | 1323 const int kSpeechDurationMs = 2000; |
1324 int packets_inserted = 0; | 1324 int packets_inserted = 0; |
1325 uint16_t last_seq_no; | 1325 uint16_t last_seq_no; |
1326 uint32_t last_timestamp; | 1326 uint32_t last_timestamp; |
1327 bool timestamp_wrapped = false; | 1327 bool timestamp_wrapped = false; |
1328 bool seq_no_wrapped = false; | 1328 bool seq_no_wrapped = false; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1411 uint32_t timestamp = 0; | 1411 uint32_t timestamp = 0; |
1412 const int kFrameSizeMs = 10; | 1412 const int kFrameSizeMs = 10; |
1413 const int kSampleRateKhz = 16; | 1413 const int kSampleRateKhz = 16; |
1414 const int kSamples = kFrameSizeMs * kSampleRateKhz; | 1414 const int kSamples = kFrameSizeMs * kSampleRateKhz; |
1415 const size_t kPayloadBytes = kSamples * 2; | 1415 const size_t kPayloadBytes = kSamples * 2; |
1416 | 1416 |
1417 const int algorithmic_delay_samples = std::max( | 1417 const int algorithmic_delay_samples = std::max( |
1418 algorithmic_delay_ms_ * kSampleRateKhz, 5 * kSampleRateKhz / 8); | 1418 algorithmic_delay_ms_ * kSampleRateKhz, 5 * kSampleRateKhz / 8); |
1419 // Insert three speech packets. Three are needed to get the frame length | 1419 // Insert three speech packets. Three are needed to get the frame length |
1420 // correct. | 1420 // correct. |
1421 int out_len; | 1421 size_t out_len; |
1422 int num_channels; | 1422 int num_channels; |
1423 NetEqOutputType type; | 1423 NetEqOutputType type; |
1424 uint8_t payload[kPayloadBytes] = {0}; | 1424 uint8_t payload[kPayloadBytes] = {0}; |
1425 WebRtcRTPHeader rtp_info; | 1425 WebRtcRTPHeader rtp_info; |
1426 for (int i = 0; i < 3; ++i) { | 1426 for (int i = 0; i < 3; ++i) { |
1427 PopulateRtpInfo(seq_no, timestamp, &rtp_info); | 1427 PopulateRtpInfo(seq_no, timestamp, &rtp_info); |
1428 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, kPayloadBytes, 0)); | 1428 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, kPayloadBytes, 0)); |
1429 ++seq_no; | 1429 ++seq_no; |
1430 timestamp += kSamples; | 1430 timestamp += kSamples; |
1431 | 1431 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1508 uint8_t payload[kPayloadBytes] = {0}; | 1508 uint8_t payload[kPayloadBytes] = {0}; |
1509 WebRtcRTPHeader rtp_info; | 1509 WebRtcRTPHeader rtp_info; |
1510 | 1510 |
1511 PopulateCng(seq_no, timestamp, &rtp_info, payload, &payload_len); | 1511 PopulateCng(seq_no, timestamp, &rtp_info, payload, &payload_len); |
1512 ASSERT_EQ(NetEq::kOK, | 1512 ASSERT_EQ(NetEq::kOK, |
1513 neteq_->InsertPacket(rtp_info, payload, payload_len, 0)); | 1513 neteq_->InsertPacket(rtp_info, payload, payload_len, 0)); |
1514 ++seq_no; | 1514 ++seq_no; |
1515 timestamp += kCngPeriodSamples; | 1515 timestamp += kCngPeriodSamples; |
1516 | 1516 |
1517 // Pull audio once and make sure CNG is played. | 1517 // Pull audio once and make sure CNG is played. |
1518 int out_len; | 1518 size_t out_len; |
1519 int num_channels; | 1519 int num_channels; |
1520 NetEqOutputType type; | 1520 NetEqOutputType type; |
1521 ASSERT_EQ(0, neteq_->GetAudio(kMaxBlockSize, out_data_, &out_len, | 1521 ASSERT_EQ(0, neteq_->GetAudio(kMaxBlockSize, out_data_, &out_len, |
1522 &num_channels, &type)); | 1522 &num_channels, &type)); |
1523 ASSERT_EQ(kBlockSize16kHz, out_len); | 1523 ASSERT_EQ(kBlockSize16kHz, out_len); |
1524 EXPECT_EQ(kOutputCNG, type); | 1524 EXPECT_EQ(kOutputCNG, type); |
1525 | 1525 |
1526 // Insert some speech packets. | 1526 // Insert some speech packets. |
1527 for (int i = 0; i < 3; ++i) { | 1527 for (int i = 0; i < 3; ++i) { |
1528 PopulateRtpInfo(seq_no, timestamp, &rtp_info); | 1528 PopulateRtpInfo(seq_no, timestamp, &rtp_info); |
1529 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, kPayloadBytes, 0)); | 1529 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, kPayloadBytes, 0)); |
1530 ++seq_no; | 1530 ++seq_no; |
1531 timestamp += kSamples; | 1531 timestamp += kSamples; |
1532 | 1532 |
1533 // Pull audio once. | 1533 // Pull audio once. |
1534 ASSERT_EQ(0, neteq_->GetAudio(kMaxBlockSize, out_data_, &out_len, | 1534 ASSERT_EQ(0, neteq_->GetAudio(kMaxBlockSize, out_data_, &out_len, |
1535 &num_channels, &type)); | 1535 &num_channels, &type)); |
1536 ASSERT_EQ(kBlockSize16kHz, out_len); | 1536 ASSERT_EQ(kBlockSize16kHz, out_len); |
1537 } | 1537 } |
1538 // Verify speech output. | 1538 // Verify speech output. |
1539 EXPECT_EQ(kOutputNormal, type); | 1539 EXPECT_EQ(kOutputNormal, type); |
1540 } | 1540 } |
1541 | 1541 |
1542 } // namespace webrtc | 1542 } // namespace webrtc |
OLD | NEW |