OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 // audio, the absolute difference between the two channels is compared vs | 164 // audio, the absolute difference between the two channels is compared vs |
165 // |channel_diff_tolerance|. | 165 // |channel_diff_tolerance|. |
166 void EncodeDecodeTest(size_t expected_bytes, int tolerance, double mse, | 166 void EncodeDecodeTest(size_t expected_bytes, int tolerance, double mse, |
167 int delay = 0, int channel_diff_tolerance = 0) { | 167 int delay = 0, int channel_diff_tolerance = 0) { |
168 ASSERT_GE(tolerance, 0) << "Test must define a tolerance >= 0"; | 168 ASSERT_GE(tolerance, 0) << "Test must define a tolerance >= 0"; |
169 ASSERT_GE(channel_diff_tolerance, 0) << | 169 ASSERT_GE(channel_diff_tolerance, 0) << |
170 "Test must define a channel_diff_tolerance >= 0"; | 170 "Test must define a channel_diff_tolerance >= 0"; |
171 size_t processed_samples = 0u; | 171 size_t processed_samples = 0u; |
172 encoded_bytes_ = 0u; | 172 encoded_bytes_ = 0u; |
173 InitEncoder(); | 173 InitEncoder(); |
174 EXPECT_EQ(0, decoder_->Init()); | |
175 std::vector<int16_t> input; | 174 std::vector<int16_t> input; |
176 std::vector<int16_t> decoded; | 175 std::vector<int16_t> decoded; |
177 while (processed_samples + frame_size_ <= data_length_) { | 176 while (processed_samples + frame_size_ <= data_length_) { |
178 // Extend input vector with |frame_size_|. | 177 // Extend input vector with |frame_size_|. |
179 input.resize(input.size() + frame_size_, 0); | 178 input.resize(input.size() + frame_size_, 0); |
180 // Read from input file. | 179 // Read from input file. |
181 ASSERT_GE(input.size() - processed_samples, frame_size_); | 180 ASSERT_GE(input.size() - processed_samples, frame_size_); |
182 ASSERT_TRUE(input_audio_.Read( | 181 ASSERT_TRUE(input_audio_.Read( |
183 frame_size_, codec_input_rate_hz_, &input[processed_samples])); | 182 frame_size_, codec_input_rate_hz_, &input[processed_samples])); |
184 size_t enc_len = EncodeFrame( | 183 size_t enc_len = EncodeFrame( |
(...skipping 28 matching lines...) Expand all Loading... |
213 // Encodes a payload and decodes it twice with decoder re-init before each | 212 // Encodes a payload and decodes it twice with decoder re-init before each |
214 // decode. Verifies that the decoded result is the same. | 213 // decode. Verifies that the decoded result is the same. |
215 void ReInitTest() { | 214 void ReInitTest() { |
216 InitEncoder(); | 215 InitEncoder(); |
217 rtc::scoped_ptr<int16_t[]> input(new int16_t[frame_size_]); | 216 rtc::scoped_ptr<int16_t[]> input(new int16_t[frame_size_]); |
218 ASSERT_TRUE( | 217 ASSERT_TRUE( |
219 input_audio_.Read(frame_size_, codec_input_rate_hz_, input.get())); | 218 input_audio_.Read(frame_size_, codec_input_rate_hz_, input.get())); |
220 size_t enc_len = EncodeFrame(input.get(), frame_size_, encoded_); | 219 size_t enc_len = EncodeFrame(input.get(), frame_size_, encoded_); |
221 size_t dec_len; | 220 size_t dec_len; |
222 AudioDecoder::SpeechType speech_type1, speech_type2; | 221 AudioDecoder::SpeechType speech_type1, speech_type2; |
223 EXPECT_EQ(0, decoder_->Init()); | 222 decoder_->Reset(); |
224 rtc::scoped_ptr<int16_t[]> output1(new int16_t[frame_size_ * channels_]); | 223 rtc::scoped_ptr<int16_t[]> output1(new int16_t[frame_size_ * channels_]); |
225 dec_len = decoder_->Decode(encoded_, enc_len, codec_input_rate_hz_, | 224 dec_len = decoder_->Decode(encoded_, enc_len, codec_input_rate_hz_, |
226 frame_size_ * channels_ * sizeof(int16_t), | 225 frame_size_ * channels_ * sizeof(int16_t), |
227 output1.get(), &speech_type1); | 226 output1.get(), &speech_type1); |
228 ASSERT_LE(dec_len, frame_size_ * channels_); | 227 ASSERT_LE(dec_len, frame_size_ * channels_); |
229 EXPECT_EQ(frame_size_ * channels_, dec_len); | 228 EXPECT_EQ(frame_size_ * channels_, dec_len); |
230 // Re-init decoder and decode again. | 229 // Re-init decoder and decode again. |
231 EXPECT_EQ(0, decoder_->Init()); | 230 decoder_->Reset(); |
232 rtc::scoped_ptr<int16_t[]> output2(new int16_t[frame_size_ * channels_]); | 231 rtc::scoped_ptr<int16_t[]> output2(new int16_t[frame_size_ * channels_]); |
233 dec_len = decoder_->Decode(encoded_, enc_len, codec_input_rate_hz_, | 232 dec_len = decoder_->Decode(encoded_, enc_len, codec_input_rate_hz_, |
234 frame_size_ * channels_ * sizeof(int16_t), | 233 frame_size_ * channels_ * sizeof(int16_t), |
235 output2.get(), &speech_type2); | 234 output2.get(), &speech_type2); |
236 ASSERT_LE(dec_len, frame_size_ * channels_); | 235 ASSERT_LE(dec_len, frame_size_ * channels_); |
237 EXPECT_EQ(frame_size_ * channels_, dec_len); | 236 EXPECT_EQ(frame_size_ * channels_, dec_len); |
238 for (unsigned int n = 0; n < frame_size_; ++n) { | 237 for (unsigned int n = 0; n < frame_size_; ++n) { |
239 ASSERT_EQ(output1[n], output2[n]) << "Exit test on first diff; n = " << n; | 238 ASSERT_EQ(output1[n], output2[n]) << "Exit test on first diff; n = " << n; |
240 } | 239 } |
241 EXPECT_EQ(speech_type1, speech_type2); | 240 EXPECT_EQ(speech_type1, speech_type2); |
242 } | 241 } |
243 | 242 |
244 // Call DecodePlc and verify that the correct number of samples is produced. | 243 // Call DecodePlc and verify that the correct number of samples is produced. |
245 void DecodePlcTest() { | 244 void DecodePlcTest() { |
246 InitEncoder(); | 245 InitEncoder(); |
247 rtc::scoped_ptr<int16_t[]> input(new int16_t[frame_size_]); | 246 rtc::scoped_ptr<int16_t[]> input(new int16_t[frame_size_]); |
248 ASSERT_TRUE( | 247 ASSERT_TRUE( |
249 input_audio_.Read(frame_size_, codec_input_rate_hz_, input.get())); | 248 input_audio_.Read(frame_size_, codec_input_rate_hz_, input.get())); |
250 size_t enc_len = EncodeFrame(input.get(), frame_size_, encoded_); | 249 size_t enc_len = EncodeFrame(input.get(), frame_size_, encoded_); |
251 AudioDecoder::SpeechType speech_type; | 250 AudioDecoder::SpeechType speech_type; |
252 EXPECT_EQ(0, decoder_->Init()); | 251 decoder_->Reset(); |
253 rtc::scoped_ptr<int16_t[]> output(new int16_t[frame_size_ * channels_]); | 252 rtc::scoped_ptr<int16_t[]> output(new int16_t[frame_size_ * channels_]); |
254 size_t dec_len = decoder_->Decode(encoded_, enc_len, codec_input_rate_hz_, | 253 size_t dec_len = decoder_->Decode(encoded_, enc_len, codec_input_rate_hz_, |
255 frame_size_ * channels_ * sizeof(int16_t), | 254 frame_size_ * channels_ * sizeof(int16_t), |
256 output.get(), &speech_type); | 255 output.get(), &speech_type); |
257 EXPECT_EQ(frame_size_ * channels_, dec_len); | 256 EXPECT_EQ(frame_size_ * channels_, dec_len); |
258 // Call DecodePlc and verify that we get one frame of data. | 257 // Call DecodePlc and verify that we get one frame of data. |
259 // (Overwrite the output from the above Decode call, but that does not | 258 // (Overwrite the output from the above Decode call, but that does not |
260 // matter.) | 259 // matter.) |
261 dec_len = decoder_->DecodePlc(1, output.get()); | 260 dec_len = decoder_->DecodePlc(1, output.get()); |
262 EXPECT_EQ(frame_size_ * channels_, dec_len); | 261 EXPECT_EQ(frame_size_ * channels_, dec_len); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 | 333 |
335 // Overload the default test since iLBC's function WebRtcIlbcfix_NetEqPlc does | 334 // Overload the default test since iLBC's function WebRtcIlbcfix_NetEqPlc does |
336 // not return any data. It simply resets a few states and returns 0. | 335 // not return any data. It simply resets a few states and returns 0. |
337 void DecodePlcTest() { | 336 void DecodePlcTest() { |
338 InitEncoder(); | 337 InitEncoder(); |
339 rtc::scoped_ptr<int16_t[]> input(new int16_t[frame_size_]); | 338 rtc::scoped_ptr<int16_t[]> input(new int16_t[frame_size_]); |
340 ASSERT_TRUE( | 339 ASSERT_TRUE( |
341 input_audio_.Read(frame_size_, codec_input_rate_hz_, input.get())); | 340 input_audio_.Read(frame_size_, codec_input_rate_hz_, input.get())); |
342 size_t enc_len = EncodeFrame(input.get(), frame_size_, encoded_); | 341 size_t enc_len = EncodeFrame(input.get(), frame_size_, encoded_); |
343 AudioDecoder::SpeechType speech_type; | 342 AudioDecoder::SpeechType speech_type; |
344 EXPECT_EQ(0, decoder_->Init()); | 343 decoder_->Reset(); |
345 rtc::scoped_ptr<int16_t[]> output(new int16_t[frame_size_ * channels_]); | 344 rtc::scoped_ptr<int16_t[]> output(new int16_t[frame_size_ * channels_]); |
346 size_t dec_len = decoder_->Decode(encoded_, enc_len, codec_input_rate_hz_, | 345 size_t dec_len = decoder_->Decode(encoded_, enc_len, codec_input_rate_hz_, |
347 frame_size_ * channels_ * sizeof(int16_t), | 346 frame_size_ * channels_ * sizeof(int16_t), |
348 output.get(), &speech_type); | 347 output.get(), &speech_type); |
349 EXPECT_EQ(frame_size_, dec_len); | 348 EXPECT_EQ(frame_size_, dec_len); |
350 // Simply call DecodePlc and verify that we get 0 as return value. | 349 // Simply call DecodePlc and verify that we get 0 as return value. |
351 EXPECT_EQ(0U, decoder_->DecodePlc(1, output.get())); | 350 EXPECT_EQ(0U, decoder_->DecodePlc(1, output.get())); |
352 } | 351 } |
353 }; | 352 }; |
354 | 353 |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
720 EXPECT_TRUE(CodecSupported(kDecoderCNGnb)); | 719 EXPECT_TRUE(CodecSupported(kDecoderCNGnb)); |
721 EXPECT_TRUE(CodecSupported(kDecoderCNGwb)); | 720 EXPECT_TRUE(CodecSupported(kDecoderCNGwb)); |
722 EXPECT_TRUE(CodecSupported(kDecoderCNGswb32kHz)); | 721 EXPECT_TRUE(CodecSupported(kDecoderCNGswb32kHz)); |
723 EXPECT_TRUE(CodecSupported(kDecoderCNGswb48kHz)); | 722 EXPECT_TRUE(CodecSupported(kDecoderCNGswb48kHz)); |
724 EXPECT_TRUE(CodecSupported(kDecoderArbitrary)); | 723 EXPECT_TRUE(CodecSupported(kDecoderArbitrary)); |
725 EXPECT_TRUE(CodecSupported(kDecoderOpus)); | 724 EXPECT_TRUE(CodecSupported(kDecoderOpus)); |
726 EXPECT_TRUE(CodecSupported(kDecoderOpus_2ch)); | 725 EXPECT_TRUE(CodecSupported(kDecoderOpus_2ch)); |
727 } | 726 } |
728 | 727 |
729 } // namespace webrtc | 728 } // namespace webrtc |
OLD | NEW |