tina.legrand@webrtc.org | 73222cf | 2013-03-15 13:29:17 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "modules/audio_coding/test/opus_test.h" |
tina.legrand@webrtc.org | 73222cf | 2013-03-15 13:29:17 +0000 | [diff] [blame] | 12 | |
pbos@webrtc.org | 12dc1a3 | 2013-08-05 16:22:53 +0000 | [diff] [blame] | 13 | #include <assert.h> |
| 14 | |
tina.legrand@webrtc.org | 73222cf | 2013-03-15 13:29:17 +0000 | [diff] [blame] | 15 | #include <string> |
| 16 | |
Mirko Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame] | 17 | #include "common_types.h" // NOLINT(build/include) |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 18 | #include "modules/audio_coding/codecs/audio_format_conversion.h" |
| 19 | #include "modules/audio_coding/codecs/opus/opus_interface.h" |
| 20 | #include "modules/audio_coding/include/audio_coding_module_typedefs.h" |
| 21 | #include "modules/audio_coding/test/TestStereo.h" |
| 22 | #include "modules/audio_coding/test/utility.h" |
| 23 | #include "test/gtest.h" |
| 24 | #include "test/testsupport/fileutils.h" |
Mirko Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame] | 25 | #include "typedefs.h" // NOLINT(build/include) |
tina.legrand@webrtc.org | 73222cf | 2013-03-15 13:29:17 +0000 | [diff] [blame] | 26 | |
| 27 | namespace webrtc { |
| 28 | |
henrik.lundin@webrtc.org | adaf809 | 2014-04-17 08:29:10 +0000 | [diff] [blame] | 29 | OpusTest::OpusTest() |
solenberg | c7b4a45 | 2017-09-28 07:37:11 -0700 | [diff] [blame^] | 30 | : acm_receiver_(AudioCodingModule::Create()), |
tina.legrand@webrtc.org | 73222cf | 2013-03-15 13:29:17 +0000 | [diff] [blame] | 31 | channel_a2b_(NULL), |
| 32 | counter_(0), |
| 33 | payload_type_(255), |
henrik.lundin@webrtc.org | adaf809 | 2014-04-17 08:29:10 +0000 | [diff] [blame] | 34 | rtp_timestamp_(0) {} |
tina.legrand@webrtc.org | 73222cf | 2013-03-15 13:29:17 +0000 | [diff] [blame] | 35 | |
| 36 | OpusTest::~OpusTest() { |
tina.legrand@webrtc.org | 73222cf | 2013-03-15 13:29:17 +0000 | [diff] [blame] | 37 | if (channel_a2b_ != NULL) { |
| 38 | delete channel_a2b_; |
| 39 | channel_a2b_ = NULL; |
| 40 | } |
| 41 | if (opus_mono_encoder_ != NULL) { |
| 42 | WebRtcOpus_EncoderFree(opus_mono_encoder_); |
| 43 | opus_mono_encoder_ = NULL; |
| 44 | } |
| 45 | if (opus_stereo_encoder_ != NULL) { |
| 46 | WebRtcOpus_EncoderFree(opus_stereo_encoder_); |
| 47 | opus_stereo_encoder_ = NULL; |
| 48 | } |
tina.legrand@webrtc.org | bd21fb5 | 2013-08-08 11:01:07 +0000 | [diff] [blame] | 49 | if (opus_mono_decoder_ != NULL) { |
| 50 | WebRtcOpus_DecoderFree(opus_mono_decoder_); |
| 51 | opus_mono_decoder_ = NULL; |
| 52 | } |
| 53 | if (opus_stereo_decoder_ != NULL) { |
| 54 | WebRtcOpus_DecoderFree(opus_stereo_decoder_); |
| 55 | opus_stereo_decoder_ = NULL; |
| 56 | } |
tina.legrand@webrtc.org | 73222cf | 2013-03-15 13:29:17 +0000 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | void OpusTest::Perform() { |
| 60 | #ifndef WEBRTC_CODEC_OPUS |
| 61 | // Opus isn't defined, exit. |
| 62 | return; |
| 63 | #else |
| 64 | uint16_t frequency_hz; |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 65 | size_t audio_channels; |
tina.legrand@webrtc.org | 73222cf | 2013-03-15 13:29:17 +0000 | [diff] [blame] | 66 | int16_t test_cntr = 0; |
| 67 | |
| 68 | // Open both mono and stereo test files in 32 kHz. |
| 69 | const std::string file_name_stereo = |
| 70 | webrtc::test::ResourcePath("audio_coding/teststereo32kHz", "pcm"); |
| 71 | const std::string file_name_mono = |
| 72 | webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm"); |
| 73 | frequency_hz = 32000; |
| 74 | in_file_stereo_.Open(file_name_stereo, frequency_hz, "rb"); |
| 75 | in_file_stereo_.ReadStereo(true); |
| 76 | in_file_mono_.Open(file_name_mono, frequency_hz, "rb"); |
| 77 | in_file_mono_.ReadStereo(false); |
| 78 | |
| 79 | // Create Opus encoders for mono and stereo. |
minyue@webrtc.org | 7dba786 | 2015-01-20 16:01:50 +0000 | [diff] [blame] | 80 | ASSERT_GT(WebRtcOpus_EncoderCreate(&opus_mono_encoder_, 1, 0), -1); |
| 81 | ASSERT_GT(WebRtcOpus_EncoderCreate(&opus_stereo_encoder_, 2, 1), -1); |
tina.legrand@webrtc.org | 73222cf | 2013-03-15 13:29:17 +0000 | [diff] [blame] | 82 | |
tina.legrand@webrtc.org | bd21fb5 | 2013-08-08 11:01:07 +0000 | [diff] [blame] | 83 | // Create Opus decoders for mono and stereo for stand-alone testing of Opus. |
| 84 | ASSERT_GT(WebRtcOpus_DecoderCreate(&opus_mono_decoder_, 1), -1); |
| 85 | ASSERT_GT(WebRtcOpus_DecoderCreate(&opus_stereo_decoder_, 2), -1); |
Karl Wiberg | 4376648 | 2015-08-27 15:22:11 +0200 | [diff] [blame] | 86 | WebRtcOpus_DecoderInit(opus_mono_decoder_); |
| 87 | WebRtcOpus_DecoderInit(opus_stereo_decoder_); |
tina.legrand@webrtc.org | bd21fb5 | 2013-08-08 11:01:07 +0000 | [diff] [blame] | 88 | |
andrew@webrtc.org | 89df092 | 2013-09-12 01:27:43 +0000 | [diff] [blame] | 89 | ASSERT_TRUE(acm_receiver_.get() != NULL); |
tina.legrand@webrtc.org | 73222cf | 2013-03-15 13:29:17 +0000 | [diff] [blame] | 90 | EXPECT_EQ(0, acm_receiver_->InitializeReceiver()); |
| 91 | |
| 92 | // Register Opus stereo as receiving codec. |
| 93 | CodecInst opus_codec_param; |
| 94 | int codec_id = acm_receiver_->Codec("opus", 48000, 2); |
| 95 | EXPECT_EQ(0, acm_receiver_->Codec(codec_id, &opus_codec_param)); |
| 96 | payload_type_ = opus_codec_param.pltype; |
kwiberg | da2bf4e | 2016-10-24 13:47:09 -0700 | [diff] [blame] | 97 | EXPECT_EQ(true, |
| 98 | acm_receiver_->RegisterReceiveCodec( |
| 99 | opus_codec_param.pltype, CodecInstToSdp(opus_codec_param))); |
tina.legrand@webrtc.org | 73222cf | 2013-03-15 13:29:17 +0000 | [diff] [blame] | 100 | |
| 101 | // Create and connect the channel. |
| 102 | channel_a2b_ = new TestPackStereo; |
andrew@webrtc.org | 89df092 | 2013-09-12 01:27:43 +0000 | [diff] [blame] | 103 | channel_a2b_->RegisterReceiverACM(acm_receiver_.get()); |
tina.legrand@webrtc.org | 73222cf | 2013-03-15 13:29:17 +0000 | [diff] [blame] | 104 | |
| 105 | // |
| 106 | // Test Stereo. |
| 107 | // |
| 108 | |
| 109 | channel_a2b_->set_codec_mode(kStereo); |
| 110 | audio_channels = 2; |
| 111 | test_cntr++; |
| 112 | OpenOutFile(test_cntr); |
| 113 | |
| 114 | // Run Opus with 2.5 ms frame size. |
| 115 | Run(channel_a2b_, audio_channels, 64000, 120); |
| 116 | |
| 117 | // Run Opus with 5 ms frame size. |
| 118 | Run(channel_a2b_, audio_channels, 64000, 240); |
| 119 | |
| 120 | // Run Opus with 10 ms frame size. |
| 121 | Run(channel_a2b_, audio_channels, 64000, 480); |
| 122 | |
| 123 | // Run Opus with 20 ms frame size. |
| 124 | Run(channel_a2b_, audio_channels, 64000, 960); |
| 125 | |
| 126 | // Run Opus with 40 ms frame size. |
| 127 | Run(channel_a2b_, audio_channels, 64000, 1920); |
| 128 | |
| 129 | // Run Opus with 60 ms frame size. |
| 130 | Run(channel_a2b_, audio_channels, 64000, 2880); |
| 131 | |
| 132 | out_file_.Close(); |
tina.legrand@webrtc.org | bd21fb5 | 2013-08-08 11:01:07 +0000 | [diff] [blame] | 133 | out_file_standalone_.Close(); |
| 134 | |
| 135 | // |
| 136 | // Test Opus stereo with packet-losses. |
| 137 | // |
| 138 | |
| 139 | test_cntr++; |
| 140 | OpenOutFile(test_cntr); |
| 141 | |
| 142 | // Run Opus with 20 ms frame size, 1% packet loss. |
| 143 | Run(channel_a2b_, audio_channels, 64000, 960, 1); |
| 144 | |
| 145 | // Run Opus with 20 ms frame size, 5% packet loss. |
| 146 | Run(channel_a2b_, audio_channels, 64000, 960, 5); |
| 147 | |
| 148 | // Run Opus with 20 ms frame size, 10% packet loss. |
| 149 | Run(channel_a2b_, audio_channels, 64000, 960, 10); |
| 150 | |
| 151 | out_file_.Close(); |
| 152 | out_file_standalone_.Close(); |
tina.legrand@webrtc.org | 73222cf | 2013-03-15 13:29:17 +0000 | [diff] [blame] | 153 | |
| 154 | // |
| 155 | // Test Mono. |
| 156 | // |
| 157 | channel_a2b_->set_codec_mode(kMono); |
| 158 | audio_channels = 1; |
| 159 | test_cntr++; |
| 160 | OpenOutFile(test_cntr); |
| 161 | |
| 162 | // Register Opus mono as receiving codec. |
| 163 | opus_codec_param.channels = 1; |
kwiberg | da2bf4e | 2016-10-24 13:47:09 -0700 | [diff] [blame] | 164 | EXPECT_EQ(true, |
| 165 | acm_receiver_->RegisterReceiveCodec( |
| 166 | opus_codec_param.pltype, CodecInstToSdp(opus_codec_param))); |
tina.legrand@webrtc.org | 73222cf | 2013-03-15 13:29:17 +0000 | [diff] [blame] | 167 | |
| 168 | // Run Opus with 2.5 ms frame size. |
| 169 | Run(channel_a2b_, audio_channels, 32000, 120); |
| 170 | |
| 171 | // Run Opus with 5 ms frame size. |
| 172 | Run(channel_a2b_, audio_channels, 32000, 240); |
| 173 | |
| 174 | // Run Opus with 10 ms frame size. |
| 175 | Run(channel_a2b_, audio_channels, 32000, 480); |
| 176 | |
| 177 | // Run Opus with 20 ms frame size. |
| 178 | Run(channel_a2b_, audio_channels, 32000, 960); |
| 179 | |
| 180 | // Run Opus with 40 ms frame size. |
| 181 | Run(channel_a2b_, audio_channels, 32000, 1920); |
| 182 | |
| 183 | // Run Opus with 60 ms frame size. |
| 184 | Run(channel_a2b_, audio_channels, 32000, 2880); |
| 185 | |
tina.legrand@webrtc.org | bd21fb5 | 2013-08-08 11:01:07 +0000 | [diff] [blame] | 186 | out_file_.Close(); |
| 187 | out_file_standalone_.Close(); |
| 188 | |
| 189 | // |
| 190 | // Test Opus mono with packet-losses. |
| 191 | // |
| 192 | test_cntr++; |
| 193 | OpenOutFile(test_cntr); |
| 194 | |
| 195 | // Run Opus with 20 ms frame size, 1% packet loss. |
| 196 | Run(channel_a2b_, audio_channels, 64000, 960, 1); |
| 197 | |
| 198 | // Run Opus with 20 ms frame size, 5% packet loss. |
| 199 | Run(channel_a2b_, audio_channels, 64000, 960, 5); |
| 200 | |
| 201 | // Run Opus with 20 ms frame size, 10% packet loss. |
| 202 | Run(channel_a2b_, audio_channels, 64000, 960, 10); |
| 203 | |
tina.legrand@webrtc.org | 73222cf | 2013-03-15 13:29:17 +0000 | [diff] [blame] | 204 | // Close the files. |
| 205 | in_file_stereo_.Close(); |
| 206 | in_file_mono_.Close(); |
| 207 | out_file_.Close(); |
tina.legrand@webrtc.org | bd21fb5 | 2013-08-08 11:01:07 +0000 | [diff] [blame] | 208 | out_file_standalone_.Close(); |
tina.legrand@webrtc.org | 73222cf | 2013-03-15 13:29:17 +0000 | [diff] [blame] | 209 | #endif |
| 210 | } |
| 211 | |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 212 | void OpusTest::Run(TestPackStereo* channel, size_t channels, int bitrate, |
pkasting | 25702cb | 2016-01-08 13:50:27 -0800 | [diff] [blame] | 213 | size_t frame_length, int percent_loss) { |
tina.legrand@webrtc.org | 73222cf | 2013-03-15 13:29:17 +0000 | [diff] [blame] | 214 | AudioFrame audio_frame; |
| 215 | int32_t out_freq_hz_b = out_file_.SamplingFrequency(); |
pkasting | 25702cb | 2016-01-08 13:50:27 -0800 | [diff] [blame] | 216 | const size_t kBufferSizeSamples = 480 * 12 * 2; // 120 ms stereo audio. |
henrik.lundin@webrtc.org | 439a4c4 | 2014-04-24 19:05:33 +0000 | [diff] [blame] | 217 | int16_t audio[kBufferSizeSamples]; |
| 218 | int16_t out_audio[kBufferSizeSamples]; |
tina.legrand@webrtc.org | bd21fb5 | 2013-08-08 11:01:07 +0000 | [diff] [blame] | 219 | int16_t audio_type; |
pkasting | 25702cb | 2016-01-08 13:50:27 -0800 | [diff] [blame] | 220 | size_t written_samples = 0; |
| 221 | size_t read_samples = 0; |
| 222 | size_t decoded_samples = 0; |
minyue@webrtc.org | f563e85 | 2014-07-18 21:11:27 +0000 | [diff] [blame] | 223 | bool first_packet = true; |
| 224 | uint32_t start_time_stamp = 0; |
minyue@webrtc.org | 3e42726 | 2013-11-11 22:03:52 +0000 | [diff] [blame] | 225 | |
tina.legrand@webrtc.org | 73222cf | 2013-03-15 13:29:17 +0000 | [diff] [blame] | 226 | channel->reset_payload_size(); |
tina.legrand@webrtc.org | bd21fb5 | 2013-08-08 11:01:07 +0000 | [diff] [blame] | 227 | counter_ = 0; |
tina.legrand@webrtc.org | 73222cf | 2013-03-15 13:29:17 +0000 | [diff] [blame] | 228 | |
| 229 | // Set encoder rate. |
| 230 | EXPECT_EQ(0, WebRtcOpus_SetBitRate(opus_mono_encoder_, bitrate)); |
| 231 | EXPECT_EQ(0, WebRtcOpus_SetBitRate(opus_stereo_encoder_, bitrate)); |
| 232 | |
tina.legrand@webrtc.org | 92c0e29 | 2014-03-24 14:38:36 +0000 | [diff] [blame] | 233 | #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) || defined(WEBRTC_ARCH_ARM) |
| 234 | // If we are on Android, iOS and/or ARM, use a lower complexity setting as |
| 235 | // default. |
| 236 | const int kOpusComplexity5 = 5; |
| 237 | EXPECT_EQ(0, WebRtcOpus_SetComplexity(opus_mono_encoder_, kOpusComplexity5)); |
| 238 | EXPECT_EQ(0, WebRtcOpus_SetComplexity(opus_stereo_encoder_, |
| 239 | kOpusComplexity5)); |
| 240 | #endif |
| 241 | |
Henrik Lundin | 4d68208 | 2015-12-10 16:24:39 +0100 | [diff] [blame] | 242 | // Fast-forward 1 second (100 blocks) since the files start with silence. |
| 243 | in_file_stereo_.FastForward(100); |
| 244 | in_file_mono_.FastForward(100); |
| 245 | |
| 246 | // Limit the runtime to 1000 blocks of 10 ms each. |
| 247 | for (size_t audio_length = 0; audio_length < 1000; audio_length += 10) { |
tina.legrand@webrtc.org | bd21fb5 | 2013-08-08 11:01:07 +0000 | [diff] [blame] | 248 | bool lost_packet = false; |
tina.legrand@webrtc.org | 73222cf | 2013-03-15 13:29:17 +0000 | [diff] [blame] | 249 | |
| 250 | // Get 10 msec of audio. |
| 251 | if (channels == 1) { |
| 252 | if (in_file_mono_.EndOfFile()) { |
| 253 | break; |
| 254 | } |
| 255 | in_file_mono_.Read10MsData(audio_frame); |
| 256 | } else { |
| 257 | if (in_file_stereo_.EndOfFile()) { |
| 258 | break; |
| 259 | } |
| 260 | in_file_stereo_.Read10MsData(audio_frame); |
| 261 | } |
| 262 | |
tina.legrand@webrtc.org | bd21fb5 | 2013-08-08 11:01:07 +0000 | [diff] [blame] | 263 | // If input audio is sampled at 32 kHz, resampling to 48 kHz is required. |
henrik.lundin@webrtc.org | adaf809 | 2014-04-17 08:29:10 +0000 | [diff] [blame] | 264 | EXPECT_EQ(480, |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 265 | resampler_.Resample10Msec(audio_frame.data(), |
henrik.lundin@webrtc.org | adaf809 | 2014-04-17 08:29:10 +0000 | [diff] [blame] | 266 | audio_frame.sample_rate_hz_, |
| 267 | 48000, |
| 268 | channels, |
henrik.lundin@webrtc.org | 439a4c4 | 2014-04-24 19:05:33 +0000 | [diff] [blame] | 269 | kBufferSizeSamples - written_samples, |
henrik.lundin@webrtc.org | adaf809 | 2014-04-17 08:29:10 +0000 | [diff] [blame] | 270 | &audio[written_samples])); |
tina.legrand@webrtc.org | 73222cf | 2013-03-15 13:29:17 +0000 | [diff] [blame] | 271 | written_samples += 480 * channels; |
| 272 | |
| 273 | // Sometimes we need to loop over the audio vector to produce the right |
| 274 | // number of packets. |
pkasting | 25702cb | 2016-01-08 13:50:27 -0800 | [diff] [blame] | 275 | size_t loop_encode = (written_samples - read_samples) / |
tina.legrand@webrtc.org | 73222cf | 2013-03-15 13:29:17 +0000 | [diff] [blame] | 276 | (channels * frame_length); |
| 277 | |
| 278 | if (loop_encode > 0) { |
pkasting | 25702cb | 2016-01-08 13:50:27 -0800 | [diff] [blame] | 279 | const size_t kMaxBytes = 1000; // Maximum number of bytes for one packet. |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 280 | size_t bitstream_len_byte; |
tina.legrand@webrtc.org | 73222cf | 2013-03-15 13:29:17 +0000 | [diff] [blame] | 281 | uint8_t bitstream[kMaxBytes]; |
pkasting | 25702cb | 2016-01-08 13:50:27 -0800 | [diff] [blame] | 282 | for (size_t i = 0; i < loop_encode; i++) { |
Peter Kasting | bba7807 | 2015-06-11 19:02:46 -0700 | [diff] [blame] | 283 | int bitstream_len_byte_int = WebRtcOpus_Encode( |
| 284 | (channels == 1) ? opus_mono_encoder_ : opus_stereo_encoder_, |
| 285 | &audio[read_samples], frame_length, kMaxBytes, bitstream); |
| 286 | ASSERT_GE(bitstream_len_byte_int, 0); |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 287 | bitstream_len_byte = static_cast<size_t>(bitstream_len_byte_int); |
tina.legrand@webrtc.org | bd21fb5 | 2013-08-08 11:01:07 +0000 | [diff] [blame] | 288 | |
| 289 | // Simulate packet loss by setting |packet_loss_| to "true" in |
| 290 | // |percent_loss| percent of the loops. |
| 291 | // TODO(tlegrand): Move handling of loss simulation to TestPackStereo. |
| 292 | if (percent_loss > 0) { |
| 293 | if (counter_ == floor((100 / percent_loss) + 0.5)) { |
| 294 | counter_ = 0; |
| 295 | lost_packet = true; |
| 296 | channel->set_lost_packet(true); |
| 297 | } else { |
| 298 | lost_packet = false; |
| 299 | channel->set_lost_packet(false); |
| 300 | } |
| 301 | counter_++; |
| 302 | } |
| 303 | |
| 304 | // Run stand-alone Opus decoder, or decode PLC. |
| 305 | if (channels == 1) { |
| 306 | if (!lost_packet) { |
minyue@webrtc.org | 33ccdfa | 2014-12-04 12:14:12 +0000 | [diff] [blame] | 307 | decoded_samples += WebRtcOpus_Decode( |
tina.legrand@webrtc.org | bd21fb5 | 2013-08-08 11:01:07 +0000 | [diff] [blame] | 308 | opus_mono_decoder_, bitstream, bitstream_len_byte, |
| 309 | &out_audio[decoded_samples * channels], &audio_type); |
| 310 | } else { |
| 311 | decoded_samples += WebRtcOpus_DecodePlc( |
| 312 | opus_mono_decoder_, &out_audio[decoded_samples * channels], 1); |
| 313 | } |
| 314 | } else { |
| 315 | if (!lost_packet) { |
minyue@webrtc.org | 33ccdfa | 2014-12-04 12:14:12 +0000 | [diff] [blame] | 316 | decoded_samples += WebRtcOpus_Decode( |
tina.legrand@webrtc.org | bd21fb5 | 2013-08-08 11:01:07 +0000 | [diff] [blame] | 317 | opus_stereo_decoder_, bitstream, bitstream_len_byte, |
| 318 | &out_audio[decoded_samples * channels], &audio_type); |
| 319 | } else { |
| 320 | decoded_samples += WebRtcOpus_DecodePlc( |
| 321 | opus_stereo_decoder_, &out_audio[decoded_samples * channels], |
| 322 | 1); |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | // Send data to the channel. "channel" will handle the loss simulation. |
tina.legrand@webrtc.org | 73222cf | 2013-03-15 13:29:17 +0000 | [diff] [blame] | 327 | channel->SendData(kAudioFrameSpeech, payload_type_, rtp_timestamp_, |
| 328 | bitstream, bitstream_len_byte, NULL); |
minyue@webrtc.org | f563e85 | 2014-07-18 21:11:27 +0000 | [diff] [blame] | 329 | if (first_packet) { |
| 330 | first_packet = false; |
| 331 | start_time_stamp = rtp_timestamp_; |
| 332 | } |
pkasting | 25702cb | 2016-01-08 13:50:27 -0800 | [diff] [blame] | 333 | rtp_timestamp_ += static_cast<uint32_t>(frame_length); |
tina.legrand@webrtc.org | 73222cf | 2013-03-15 13:29:17 +0000 | [diff] [blame] | 334 | read_samples += frame_length * channels; |
| 335 | } |
| 336 | if (read_samples == written_samples) { |
| 337 | read_samples = 0; |
| 338 | written_samples = 0; |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | // Run received side of ACM. |
henrik.lundin | d4ccb00 | 2016-05-17 12:21:55 -0700 | [diff] [blame] | 343 | bool muted; |
| 344 | ASSERT_EQ( |
| 345 | 0, acm_receiver_->PlayoutData10Ms(out_freq_hz_b, &audio_frame, &muted)); |
| 346 | ASSERT_FALSE(muted); |
tina.legrand@webrtc.org | 73222cf | 2013-03-15 13:29:17 +0000 | [diff] [blame] | 347 | |
| 348 | // Write output speech to file. |
| 349 | out_file_.Write10MsData( |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 350 | audio_frame.data(), |
tina.legrand@webrtc.org | 73222cf | 2013-03-15 13:29:17 +0000 | [diff] [blame] | 351 | audio_frame.samples_per_channel_ * audio_frame.num_channels_); |
tina.legrand@webrtc.org | bd21fb5 | 2013-08-08 11:01:07 +0000 | [diff] [blame] | 352 | |
| 353 | // Write stand-alone speech to file. |
pkasting | 25702cb | 2016-01-08 13:50:27 -0800 | [diff] [blame] | 354 | out_file_standalone_.Write10MsData(out_audio, decoded_samples * channels); |
tina.legrand@webrtc.org | ba5a6c3 | 2014-03-23 09:58:48 +0000 | [diff] [blame] | 355 | |
minyue@webrtc.org | f563e85 | 2014-07-18 21:11:27 +0000 | [diff] [blame] | 356 | if (audio_frame.timestamp_ > start_time_stamp) { |
| 357 | // Number of channels should be the same for both stand-alone and |
| 358 | // ACM-decoding. |
| 359 | EXPECT_EQ(audio_frame.num_channels_, channels); |
| 360 | } |
tina.legrand@webrtc.org | ba5a6c3 | 2014-03-23 09:58:48 +0000 | [diff] [blame] | 361 | |
tina.legrand@webrtc.org | bd21fb5 | 2013-08-08 11:01:07 +0000 | [diff] [blame] | 362 | decoded_samples = 0; |
tina.legrand@webrtc.org | 73222cf | 2013-03-15 13:29:17 +0000 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | if (in_file_mono_.EndOfFile()) { |
| 366 | in_file_mono_.Rewind(); |
| 367 | } |
| 368 | if (in_file_stereo_.EndOfFile()) { |
| 369 | in_file_stereo_.Rewind(); |
| 370 | } |
| 371 | // Reset in case we ended with a lost packet. |
| 372 | channel->set_lost_packet(false); |
| 373 | } |
| 374 | |
| 375 | void OpusTest::OpenOutFile(int test_number) { |
| 376 | std::string file_name; |
| 377 | std::stringstream file_stream; |
| 378 | file_stream << webrtc::test::OutputPath() << "opustest_out_" |
| 379 | << test_number << ".pcm"; |
| 380 | file_name = file_stream.str(); |
minyue@webrtc.org | f563e85 | 2014-07-18 21:11:27 +0000 | [diff] [blame] | 381 | out_file_.Open(file_name, 48000, "wb"); |
tina.legrand@webrtc.org | bd21fb5 | 2013-08-08 11:01:07 +0000 | [diff] [blame] | 382 | file_stream.str(""); |
| 383 | file_name = file_stream.str(); |
| 384 | file_stream << webrtc::test::OutputPath() << "opusstandalone_out_" |
| 385 | << test_number << ".pcm"; |
| 386 | file_name = file_stream.str(); |
minyue@webrtc.org | f563e85 | 2014-07-18 21:11:27 +0000 | [diff] [blame] | 387 | out_file_standalone_.Open(file_name, 48000, "wb"); |
tina.legrand@webrtc.org | 73222cf | 2013-03-15 13:29:17 +0000 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | } // namespace webrtc |