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