Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(79)

Side by Side Diff: webrtc/modules/audio_coding/neteq/neteq_stereo_unittest.cc

Issue 1750353002: Change NetEq::GetAudio to use AudioFrame (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebase Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2013 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
11 // Test to verify correct stereo and multi-channel operation. 11 // Test to verify correct stereo and multi-channel operation.
12 12
13 #include <algorithm> 13 #include <algorithm>
14 #include <memory> 14 #include <memory>
15 #include <string> 15 #include <string>
16 #include <list> 16 #include <list>
17 17
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 #include "webrtc/modules/audio_coding/codecs/pcm16b/pcm16b.h" 19 #include "webrtc/modules/audio_coding/codecs/pcm16b/pcm16b.h"
20 #include "webrtc/modules/audio_coding/neteq/include/neteq.h" 20 #include "webrtc/modules/audio_coding/neteq/include/neteq.h"
21 #include "webrtc/modules/audio_coding/neteq/tools/input_audio_file.h" 21 #include "webrtc/modules/audio_coding/neteq/tools/input_audio_file.h"
22 #include "webrtc/modules/audio_coding/neteq/tools/rtp_generator.h" 22 #include "webrtc/modules/audio_coding/neteq/tools/rtp_generator.h"
23 #include "webrtc/modules/include/module_common_types.h"
23 #include "webrtc/test/testsupport/fileutils.h" 24 #include "webrtc/test/testsupport/fileutils.h"
24 25
25 namespace webrtc { 26 namespace webrtc {
26 27
27 struct TestParameters { 28 struct TestParameters {
28 int frame_size; 29 int frame_size;
29 int sample_rate; 30 int sample_rate;
30 size_t num_channels; 31 size_t num_channels;
31 }; 32 };
32 33
(...skipping 29 matching lines...) Expand all
62 last_arrival_time_(0) { 63 last_arrival_time_(0) {
63 NetEq::Config config; 64 NetEq::Config config;
64 config.sample_rate_hz = sample_rate_hz_; 65 config.sample_rate_hz = sample_rate_hz_;
65 neteq_mono_ = NetEq::Create(config); 66 neteq_mono_ = NetEq::Create(config);
66 neteq_ = NetEq::Create(config); 67 neteq_ = NetEq::Create(config);
67 input_ = new int16_t[frame_size_samples_]; 68 input_ = new int16_t[frame_size_samples_];
68 encoded_ = new uint8_t[2 * frame_size_samples_]; 69 encoded_ = new uint8_t[2 * frame_size_samples_];
69 input_multi_channel_ = new int16_t[frame_size_samples_ * num_channels_]; 70 input_multi_channel_ = new int16_t[frame_size_samples_ * num_channels_];
70 encoded_multi_channel_ = new uint8_t[frame_size_samples_ * 2 * 71 encoded_multi_channel_ = new uint8_t[frame_size_samples_ * 2 *
71 num_channels_]; 72 num_channels_];
72 output_multi_channel_ = new int16_t[kMaxBlockSize * num_channels_];
73 } 73 }
74 74
75 ~NetEqStereoTest() { 75 ~NetEqStereoTest() {
76 delete neteq_mono_; 76 delete neteq_mono_;
77 delete neteq_; 77 delete neteq_;
78 delete [] input_; 78 delete [] input_;
79 delete [] encoded_; 79 delete [] encoded_;
80 delete [] input_multi_channel_; 80 delete [] input_multi_channel_;
81 delete [] encoded_multi_channel_; 81 delete [] encoded_multi_channel_;
82 delete [] output_multi_channel_;
83 } 82 }
84 83
85 virtual void SetUp() { 84 virtual void SetUp() {
86 const std::string file_name = 85 const std::string file_name =
87 webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm"); 86 webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm");
88 input_file_.reset(new test::InputAudioFile(file_name)); 87 input_file_.reset(new test::InputAudioFile(file_name));
89 NetEqDecoder mono_decoder; 88 NetEqDecoder mono_decoder;
90 NetEqDecoder multi_decoder; 89 NetEqDecoder multi_decoder;
91 switch (sample_rate_hz_) { 90 switch (sample_rate_hz_) {
92 case 8000: 91 case 8000:
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 return -1; 156 return -1;
158 } 157 }
159 rtp_generator_.GetRtpHeader(kPayloadTypeMulti, frame_size_samples_, 158 rtp_generator_.GetRtpHeader(kPayloadTypeMulti, frame_size_samples_,
160 &rtp_header_); 159 &rtp_header_);
161 return next_send_time; 160 return next_send_time;
162 } 161 }
163 162
164 virtual void VerifyOutput(size_t num_samples) { 163 virtual void VerifyOutput(size_t num_samples) {
165 for (size_t i = 0; i < num_samples; ++i) { 164 for (size_t i = 0; i < num_samples; ++i) {
166 for (size_t j = 0; j < num_channels_; ++j) { 165 for (size_t j = 0; j < num_channels_; ++j) {
167 ASSERT_EQ(output_[i], output_multi_channel_[i * num_channels_ + j]) << 166 ASSERT_EQ(output_.data_[i],
168 "Diff in sample " << i << ", channel " << j << "."; 167 output_multi_channel_.data_[i * num_channels_ + j])
168 << "Diff in sample " << i << ", channel " << j << ".";
169 } 169 }
170 } 170 }
171 } 171 }
172 172
173 virtual int GetArrivalTime(int send_time) { 173 virtual int GetArrivalTime(int send_time) {
174 int arrival_time = last_arrival_time_ + (send_time - last_send_time_); 174 int arrival_time = last_arrival_time_ + (send_time - last_send_time_);
175 last_send_time_ = send_time; 175 last_send_time_ = send_time;
176 last_arrival_time_ = arrival_time; 176 last_arrival_time_ = arrival_time;
177 return arrival_time; 177 return arrival_time;
178 } 178 }
(...skipping 27 matching lines...) Expand all
206 next_arrival_time)); 206 next_arrival_time));
207 // Get next input packets (mono and multi-channel). 207 // Get next input packets (mono and multi-channel).
208 do { 208 do {
209 next_send_time = GetNewPackets(); 209 next_send_time = GetNewPackets();
210 ASSERT_NE(-1, next_send_time); 210 ASSERT_NE(-1, next_send_time);
211 next_arrival_time = GetArrivalTime(next_send_time); 211 next_arrival_time = GetArrivalTime(next_send_time);
212 } while (Lost()); // If lost, immediately read the next packet. 212 } while (Lost()); // If lost, immediately read the next packet.
213 } 213 }
214 NetEqOutputType output_type; 214 NetEqOutputType output_type;
215 // Get audio from mono instance. 215 // Get audio from mono instance.
216 size_t samples_per_channel; 216 EXPECT_EQ(NetEq::kOK, neteq_mono_->GetAudio(&output_, &output_type));
217 size_t num_channels; 217 EXPECT_EQ(1u, output_.num_channels_);
218 EXPECT_EQ(NetEq::kOK, 218 EXPECT_EQ(output_size_samples_, output_.samples_per_channel_);
219 neteq_mono_->GetAudio(kMaxBlockSize, output_,
220 &samples_per_channel, &num_channels,
221 &output_type));
222 EXPECT_EQ(1u, num_channels);
223 EXPECT_EQ(output_size_samples_, samples_per_channel);
224 // Get audio from multi-channel instance. 219 // Get audio from multi-channel instance.
225 ASSERT_EQ(NetEq::kOK, 220 ASSERT_EQ(NetEq::kOK,
226 neteq_->GetAudio(kMaxBlockSize * num_channels_, 221 neteq_->GetAudio(&output_multi_channel_, &output_type));
227 output_multi_channel_, 222 EXPECT_EQ(num_channels_, output_multi_channel_.num_channels_);
228 &samples_per_channel, &num_channels, 223 EXPECT_EQ(output_size_samples_,
229 &output_type)); 224 output_multi_channel_.samples_per_channel_);
230 EXPECT_EQ(num_channels_, num_channels);
231 EXPECT_EQ(output_size_samples_, samples_per_channel);
232 std::ostringstream ss; 225 std::ostringstream ss;
233 ss << "Lap number " << k << "."; 226 ss << "Lap number " << k << ".";
234 SCOPED_TRACE(ss.str()); // Print out the parameter values on failure. 227 SCOPED_TRACE(ss.str()); // Print out the parameter values on failure.
235 // Compare mono and multi-channel. 228 // Compare mono and multi-channel.
236 ASSERT_NO_FATAL_FAILURE(VerifyOutput(output_size_samples_)); 229 ASSERT_NO_FATAL_FAILURE(VerifyOutput(output_size_samples_));
237 230
238 time_now += kTimeStepMs; 231 time_now += kTimeStepMs;
239 } 232 }
240 } 233 }
241 234
242 const size_t num_channels_; 235 const size_t num_channels_;
243 const int sample_rate_hz_; 236 const int sample_rate_hz_;
244 const int samples_per_ms_; 237 const int samples_per_ms_;
245 const int frame_size_ms_; 238 const int frame_size_ms_;
246 const size_t frame_size_samples_; 239 const size_t frame_size_samples_;
247 const size_t output_size_samples_; 240 const size_t output_size_samples_;
248 NetEq* neteq_mono_; 241 NetEq* neteq_mono_;
249 NetEq* neteq_; 242 NetEq* neteq_;
250 test::RtpGenerator rtp_generator_mono_; 243 test::RtpGenerator rtp_generator_mono_;
251 test::RtpGenerator rtp_generator_; 244 test::RtpGenerator rtp_generator_;
252 int16_t* input_; 245 int16_t* input_;
253 int16_t* input_multi_channel_; 246 int16_t* input_multi_channel_;
254 uint8_t* encoded_; 247 uint8_t* encoded_;
255 uint8_t* encoded_multi_channel_; 248 uint8_t* encoded_multi_channel_;
256 int16_t output_[kMaxBlockSize]; 249 AudioFrame output_;
257 int16_t* output_multi_channel_; 250 AudioFrame output_multi_channel_;
258 WebRtcRTPHeader rtp_header_mono_; 251 WebRtcRTPHeader rtp_header_mono_;
259 WebRtcRTPHeader rtp_header_; 252 WebRtcRTPHeader rtp_header_;
260 size_t payload_size_bytes_; 253 size_t payload_size_bytes_;
261 size_t multi_payload_size_bytes_; 254 size_t multi_payload_size_bytes_;
262 int last_send_time_; 255 int last_send_time_;
263 int last_arrival_time_; 256 int last_arrival_time_;
264 std::unique_ptr<test::InputAudioFile> input_file_; 257 std::unique_ptr<test::InputAudioFile> input_file_;
265 }; 258 };
266 259
267 class NetEqStereoTestNoJitter : public NetEqStereoTest { 260 class NetEqStereoTestNoJitter : public NetEqStereoTest {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 frame_index_(0) { 346 frame_index_(0) {
354 } 347 }
355 348
356 virtual bool Lost() { 349 virtual bool Lost() {
357 return (++frame_index_) % kLossInterval == 0; 350 return (++frame_index_) % kLossInterval == 0;
358 } 351 }
359 352
360 // TODO(hlundin): NetEq is not giving bitexact results for these cases. 353 // TODO(hlundin): NetEq is not giving bitexact results for these cases.
361 virtual void VerifyOutput(size_t num_samples) { 354 virtual void VerifyOutput(size_t num_samples) {
362 for (size_t i = 0; i < num_samples; ++i) { 355 for (size_t i = 0; i < num_samples; ++i) {
363 auto first_channel_sample = output_multi_channel_[i * num_channels_]; 356 auto first_channel_sample =
357 output_multi_channel_.data_[i * num_channels_];
364 for (size_t j = 0; j < num_channels_; ++j) { 358 for (size_t j = 0; j < num_channels_; ++j) {
365 const int kErrorMargin = 200; 359 const int kErrorMargin = 200;
366 EXPECT_NEAR(output_[i], output_multi_channel_[i * num_channels_ + j], 360 EXPECT_NEAR(output_.data_[i],
361 output_multi_channel_.data_[i * num_channels_ + j],
367 kErrorMargin) 362 kErrorMargin)
368 << "Diff in sample " << i << ", channel " << j << "."; 363 << "Diff in sample " << i << ", channel " << j << ".";
369 EXPECT_EQ(first_channel_sample, 364 EXPECT_EQ(first_channel_sample,
370 output_multi_channel_[i * num_channels_ + j]); 365 output_multi_channel_.data_[i * num_channels_ + j]);
371 } 366 }
372 } 367 }
373 } 368 }
374 369
375 int frame_index_; 370 int frame_index_;
376 }; 371 };
377 372
378 TEST_P(NetEqStereoTestLosses, RunTest) { 373 TEST_P(NetEqStereoTestLosses, RunTest) {
379 RunTest(100); 374 RunTest(100);
380 } 375 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 423
429 INSTANTIATE_TEST_CASE_P(MultiChannel, 424 INSTANTIATE_TEST_CASE_P(MultiChannel,
430 NetEqStereoTestDelays, 425 NetEqStereoTestDelays,
431 ::testing::ValuesIn(GetTestParameters())); 426 ::testing::ValuesIn(GetTestParameters()));
432 427
433 INSTANTIATE_TEST_CASE_P(MultiChannel, 428 INSTANTIATE_TEST_CASE_P(MultiChannel,
434 NetEqStereoTestLosses, 429 NetEqStereoTestLosses,
435 ::testing::ValuesIn(GetTestParameters())); 430 ::testing::ValuesIn(GetTestParameters()));
436 431
437 } // namespace webrtc 432 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/neteq/neteq_network_stats_unittest.cc ('k') | webrtc/modules/audio_coding/neteq/neteq_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698