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

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

Issue 1697823002: Replace scoped_ptr with unique_ptr in webrtc/modules/audio_coding/neteq/ (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@up-codecs
Patch Set: Created 4 years, 10 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) 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
11 #include "webrtc/modules/audio_coding/neteq/audio_decoder_impl.h" 11 #include "webrtc/modules/audio_coding/neteq/audio_decoder_impl.h"
12 12
13 #include <assert.h> 13 #include <assert.h>
14 #include <stdlib.h> 14 #include <stdlib.h>
15 15
16 #include <memory>
16 #include <string> 17 #include <string>
17 #include <vector> 18 #include <vector>
18 19
19 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
20 #include "webrtc/base/scoped_ptr.h"
21 #include "webrtc/modules/audio_coding/codecs/g711/audio_decoder_pcm.h" 21 #include "webrtc/modules/audio_coding/codecs/g711/audio_decoder_pcm.h"
22 #include "webrtc/modules/audio_coding/codecs/g711/audio_encoder_pcm.h" 22 #include "webrtc/modules/audio_coding/codecs/g711/audio_encoder_pcm.h"
23 #include "webrtc/modules/audio_coding/codecs/g722/audio_decoder_g722.h" 23 #include "webrtc/modules/audio_coding/codecs/g722/audio_decoder_g722.h"
24 #include "webrtc/modules/audio_coding/codecs/g722/audio_encoder_g722.h" 24 #include "webrtc/modules/audio_coding/codecs/g722/audio_encoder_g722.h"
25 #include "webrtc/modules/audio_coding/codecs/ilbc/audio_decoder_ilbc.h" 25 #include "webrtc/modules/audio_coding/codecs/ilbc/audio_decoder_ilbc.h"
26 #include "webrtc/modules/audio_coding/codecs/ilbc/audio_encoder_ilbc.h" 26 #include "webrtc/modules/audio_coding/codecs/ilbc/audio_encoder_ilbc.h"
27 #include "webrtc/modules/audio_coding/codecs/isac/fix/include/audio_decoder_isac fix.h" 27 #include "webrtc/modules/audio_coding/codecs/isac/fix/include/audio_decoder_isac fix.h"
28 #include "webrtc/modules/audio_coding/codecs/isac/fix/include/audio_encoder_isac fix.h" 28 #include "webrtc/modules/audio_coding/codecs/isac/fix/include/audio_encoder_isac fix.h"
29 #include "webrtc/modules/audio_coding/codecs/isac/main/include/audio_decoder_isa c.h" 29 #include "webrtc/modules/audio_coding/codecs/isac/main/include/audio_decoder_isa c.h"
30 #include "webrtc/modules/audio_coding/codecs/isac/main/include/audio_encoder_isa c.h" 30 #include "webrtc/modules/audio_coding/codecs/isac/main/include/audio_encoder_isa c.h"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 139
140 // TODO(henrik.lundin) Change return type to size_t once most/all overriding 140 // TODO(henrik.lundin) Change return type to size_t once most/all overriding
141 // implementations are gone. 141 // implementations are gone.
142 virtual int EncodeFrame(const int16_t* input, 142 virtual int EncodeFrame(const int16_t* input,
143 size_t input_len_samples, 143 size_t input_len_samples,
144 uint8_t* output) { 144 uint8_t* output) {
145 encoded_info_.encoded_bytes = 0; 145 encoded_info_.encoded_bytes = 0;
146 const size_t samples_per_10ms = audio_encoder_->SampleRateHz() / 100; 146 const size_t samples_per_10ms = audio_encoder_->SampleRateHz() / 100;
147 RTC_CHECK_EQ(samples_per_10ms * audio_encoder_->Num10MsFramesInNextPacket(), 147 RTC_CHECK_EQ(samples_per_10ms * audio_encoder_->Num10MsFramesInNextPacket(),
148 input_len_samples); 148 input_len_samples);
149 rtc::scoped_ptr<int16_t[]> interleaved_input( 149 std::unique_ptr<int16_t[]> interleaved_input(
150 new int16_t[channels_ * samples_per_10ms]); 150 new int16_t[channels_ * samples_per_10ms]);
151 for (size_t i = 0; i < audio_encoder_->Num10MsFramesInNextPacket(); ++i) { 151 for (size_t i = 0; i < audio_encoder_->Num10MsFramesInNextPacket(); ++i) {
152 EXPECT_EQ(0u, encoded_info_.encoded_bytes); 152 EXPECT_EQ(0u, encoded_info_.encoded_bytes);
153 153
154 // Duplicate the mono input signal to however many channels the test 154 // Duplicate the mono input signal to however many channels the test
155 // wants. 155 // wants.
156 test::InputAudioFile::DuplicateInterleaved(input + i * samples_per_10ms, 156 test::InputAudioFile::DuplicateInterleaved(input + i * samples_per_10ms,
157 samples_per_10ms, channels_, 157 samples_per_10ms, channels_,
158 interleaved_input.get()); 158 interleaved_input.get());
159 159
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 decoded, processed_samples, channels_, channel_diff_tolerance); 216 decoded, processed_samples, channels_, channel_diff_tolerance);
217 EXPECT_LE( 217 EXPECT_LE(
218 MseInputOutput(input, decoded, processed_samples, channels_, delay), 218 MseInputOutput(input, decoded, processed_samples, channels_, delay),
219 mse); 219 mse);
220 } 220 }
221 221
222 // Encodes a payload and decodes it twice with decoder re-init before each 222 // Encodes a payload and decodes it twice with decoder re-init before each
223 // decode. Verifies that the decoded result is the same. 223 // decode. Verifies that the decoded result is the same.
224 void ReInitTest() { 224 void ReInitTest() {
225 InitEncoder(); 225 InitEncoder();
226 rtc::scoped_ptr<int16_t[]> input(new int16_t[frame_size_]); 226 std::unique_ptr<int16_t[]> input(new int16_t[frame_size_]);
227 ASSERT_TRUE( 227 ASSERT_TRUE(
228 input_audio_.Read(frame_size_, codec_input_rate_hz_, input.get())); 228 input_audio_.Read(frame_size_, codec_input_rate_hz_, input.get()));
229 size_t enc_len = EncodeFrame(input.get(), frame_size_, encoded_); 229 size_t enc_len = EncodeFrame(input.get(), frame_size_, encoded_);
230 size_t dec_len; 230 size_t dec_len;
231 AudioDecoder::SpeechType speech_type1, speech_type2; 231 AudioDecoder::SpeechType speech_type1, speech_type2;
232 decoder_->Reset(); 232 decoder_->Reset();
233 rtc::scoped_ptr<int16_t[]> output1(new int16_t[frame_size_ * channels_]); 233 std::unique_ptr<int16_t[]> output1(new int16_t[frame_size_ * channels_]);
234 dec_len = decoder_->Decode(encoded_, enc_len, codec_input_rate_hz_, 234 dec_len = decoder_->Decode(encoded_, enc_len, codec_input_rate_hz_,
235 frame_size_ * channels_ * sizeof(int16_t), 235 frame_size_ * channels_ * sizeof(int16_t),
236 output1.get(), &speech_type1); 236 output1.get(), &speech_type1);
237 ASSERT_LE(dec_len, frame_size_ * channels_); 237 ASSERT_LE(dec_len, frame_size_ * channels_);
238 EXPECT_EQ(frame_size_ * channels_, dec_len); 238 EXPECT_EQ(frame_size_ * channels_, dec_len);
239 // Re-init decoder and decode again. 239 // Re-init decoder and decode again.
240 decoder_->Reset(); 240 decoder_->Reset();
241 rtc::scoped_ptr<int16_t[]> output2(new int16_t[frame_size_ * channels_]); 241 std::unique_ptr<int16_t[]> output2(new int16_t[frame_size_ * channels_]);
242 dec_len = decoder_->Decode(encoded_, enc_len, codec_input_rate_hz_, 242 dec_len = decoder_->Decode(encoded_, enc_len, codec_input_rate_hz_,
243 frame_size_ * channels_ * sizeof(int16_t), 243 frame_size_ * channels_ * sizeof(int16_t),
244 output2.get(), &speech_type2); 244 output2.get(), &speech_type2);
245 ASSERT_LE(dec_len, frame_size_ * channels_); 245 ASSERT_LE(dec_len, frame_size_ * channels_);
246 EXPECT_EQ(frame_size_ * channels_, dec_len); 246 EXPECT_EQ(frame_size_ * channels_, dec_len);
247 for (unsigned int n = 0; n < frame_size_; ++n) { 247 for (unsigned int n = 0; n < frame_size_; ++n) {
248 ASSERT_EQ(output1[n], output2[n]) << "Exit test on first diff; n = " << n; 248 ASSERT_EQ(output1[n], output2[n]) << "Exit test on first diff; n = " << n;
249 } 249 }
250 EXPECT_EQ(speech_type1, speech_type2); 250 EXPECT_EQ(speech_type1, speech_type2);
251 } 251 }
252 252
253 // Call DecodePlc and verify that the correct number of samples is produced. 253 // Call DecodePlc and verify that the correct number of samples is produced.
254 void DecodePlcTest() { 254 void DecodePlcTest() {
255 InitEncoder(); 255 InitEncoder();
256 rtc::scoped_ptr<int16_t[]> input(new int16_t[frame_size_]); 256 std::unique_ptr<int16_t[]> input(new int16_t[frame_size_]);
257 ASSERT_TRUE( 257 ASSERT_TRUE(
258 input_audio_.Read(frame_size_, codec_input_rate_hz_, input.get())); 258 input_audio_.Read(frame_size_, codec_input_rate_hz_, input.get()));
259 size_t enc_len = EncodeFrame(input.get(), frame_size_, encoded_); 259 size_t enc_len = EncodeFrame(input.get(), frame_size_, encoded_);
260 AudioDecoder::SpeechType speech_type; 260 AudioDecoder::SpeechType speech_type;
261 decoder_->Reset(); 261 decoder_->Reset();
262 rtc::scoped_ptr<int16_t[]> output(new int16_t[frame_size_ * channels_]); 262 std::unique_ptr<int16_t[]> output(new int16_t[frame_size_ * channels_]);
263 size_t dec_len = decoder_->Decode(encoded_, enc_len, codec_input_rate_hz_, 263 size_t dec_len = decoder_->Decode(encoded_, enc_len, codec_input_rate_hz_,
264 frame_size_ * channels_ * sizeof(int16_t), 264 frame_size_ * channels_ * sizeof(int16_t),
265 output.get(), &speech_type); 265 output.get(), &speech_type);
266 EXPECT_EQ(frame_size_ * channels_, dec_len); 266 EXPECT_EQ(frame_size_ * channels_, dec_len);
267 // Call DecodePlc and verify that we get one frame of data. 267 // Call DecodePlc and verify that we get one frame of data.
268 // (Overwrite the output from the above Decode call, but that does not 268 // (Overwrite the output from the above Decode call, but that does not
269 // matter.) 269 // matter.)
270 dec_len = decoder_->DecodePlc(1, output.get()); 270 dec_len = decoder_->DecodePlc(1, output.get());
271 EXPECT_EQ(frame_size_ * channels_, dec_len); 271 EXPECT_EQ(frame_size_ * channels_, dec_len);
272 } 272 }
273 273
274 test::ResampleInputAudioFile input_audio_; 274 test::ResampleInputAudioFile input_audio_;
275 int codec_input_rate_hz_; 275 int codec_input_rate_hz_;
276 uint8_t* encoded_; 276 uint8_t* encoded_;
277 size_t frame_size_; 277 size_t frame_size_;
278 size_t data_length_; 278 size_t data_length_;
279 size_t encoded_bytes_; 279 size_t encoded_bytes_;
280 size_t channels_; 280 size_t channels_;
281 const int payload_type_; 281 const int payload_type_;
282 AudioEncoder::EncodedInfo encoded_info_; 282 AudioEncoder::EncodedInfo encoded_info_;
283 AudioDecoder* decoder_; 283 AudioDecoder* decoder_;
284 rtc::scoped_ptr<AudioEncoder> audio_encoder_; 284 std::unique_ptr<AudioEncoder> audio_encoder_;
285 }; 285 };
286 286
287 class AudioDecoderPcmUTest : public AudioDecoderTest { 287 class AudioDecoderPcmUTest : public AudioDecoderTest {
288 protected: 288 protected:
289 AudioDecoderPcmUTest() : AudioDecoderTest() { 289 AudioDecoderPcmUTest() : AudioDecoderTest() {
290 frame_size_ = 160; 290 frame_size_ = 160;
291 data_length_ = 10 * frame_size_; 291 data_length_ = 10 * frame_size_;
292 decoder_ = new AudioDecoderPcmU(1); 292 decoder_ = new AudioDecoderPcmU(1);
293 AudioEncoderPcmU::Config config; 293 AudioEncoderPcmU::Config config;
294 config.frame_size_ms = static_cast<int>(frame_size_ / 8); 294 config.frame_size_ms = static_cast<int>(frame_size_ / 8);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 AudioEncoderIlbc::Config config; 338 AudioEncoderIlbc::Config config;
339 config.frame_size_ms = 30; 339 config.frame_size_ms = 30;
340 config.payload_type = payload_type_; 340 config.payload_type = payload_type_;
341 audio_encoder_.reset(new AudioEncoderIlbc(config)); 341 audio_encoder_.reset(new AudioEncoderIlbc(config));
342 } 342 }
343 343
344 // Overload the default test since iLBC's function WebRtcIlbcfix_NetEqPlc does 344 // Overload the default test since iLBC's function WebRtcIlbcfix_NetEqPlc does
345 // not return any data. It simply resets a few states and returns 0. 345 // not return any data. It simply resets a few states and returns 0.
346 void DecodePlcTest() { 346 void DecodePlcTest() {
347 InitEncoder(); 347 InitEncoder();
348 rtc::scoped_ptr<int16_t[]> input(new int16_t[frame_size_]); 348 std::unique_ptr<int16_t[]> input(new int16_t[frame_size_]);
349 ASSERT_TRUE( 349 ASSERT_TRUE(
350 input_audio_.Read(frame_size_, codec_input_rate_hz_, input.get())); 350 input_audio_.Read(frame_size_, codec_input_rate_hz_, input.get()));
351 size_t enc_len = EncodeFrame(input.get(), frame_size_, encoded_); 351 size_t enc_len = EncodeFrame(input.get(), frame_size_, encoded_);
352 AudioDecoder::SpeechType speech_type; 352 AudioDecoder::SpeechType speech_type;
353 decoder_->Reset(); 353 decoder_->Reset();
354 rtc::scoped_ptr<int16_t[]> output(new int16_t[frame_size_ * channels_]); 354 std::unique_ptr<int16_t[]> output(new int16_t[frame_size_ * channels_]);
355 size_t dec_len = decoder_->Decode(encoded_, enc_len, codec_input_rate_hz_, 355 size_t dec_len = decoder_->Decode(encoded_, enc_len, codec_input_rate_hz_,
356 frame_size_ * channels_ * sizeof(int16_t), 356 frame_size_ * channels_ * sizeof(int16_t),
357 output.get(), &speech_type); 357 output.get(), &speech_type);
358 EXPECT_EQ(frame_size_, dec_len); 358 EXPECT_EQ(frame_size_, dec_len);
359 // Simply call DecodePlc and verify that we get 0 as return value. 359 // Simply call DecodePlc and verify that we get 0 as return value.
360 EXPECT_EQ(0U, decoder_->DecodePlc(1, output.get())); 360 EXPECT_EQ(0U, decoder_->DecodePlc(1, output.get()));
361 } 361 }
362 }; 362 };
363 363
364 class AudioDecoderIsacFloatTest : public AudioDecoderTest { 364 class AudioDecoderIsacFloatTest : public AudioDecoderTest {
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 EXPECT_TRUE(CodecSupported(NetEqDecoder::kDecoderCNGnb)); 742 EXPECT_TRUE(CodecSupported(NetEqDecoder::kDecoderCNGnb));
743 EXPECT_TRUE(CodecSupported(NetEqDecoder::kDecoderCNGwb)); 743 EXPECT_TRUE(CodecSupported(NetEqDecoder::kDecoderCNGwb));
744 EXPECT_TRUE(CodecSupported(NetEqDecoder::kDecoderCNGswb32kHz)); 744 EXPECT_TRUE(CodecSupported(NetEqDecoder::kDecoderCNGswb32kHz));
745 EXPECT_TRUE(CodecSupported(NetEqDecoder::kDecoderCNGswb48kHz)); 745 EXPECT_TRUE(CodecSupported(NetEqDecoder::kDecoderCNGswb48kHz));
746 EXPECT_TRUE(CodecSupported(NetEqDecoder::kDecoderArbitrary)); 746 EXPECT_TRUE(CodecSupported(NetEqDecoder::kDecoderArbitrary));
747 EXPECT_EQ(has_opus, CodecSupported(NetEqDecoder::kDecoderOpus)); 747 EXPECT_EQ(has_opus, CodecSupported(NetEqDecoder::kDecoderOpus));
748 EXPECT_EQ(has_opus, CodecSupported(NetEqDecoder::kDecoderOpus_2ch)); 748 EXPECT_EQ(has_opus, CodecSupported(NetEqDecoder::kDecoderOpus_2ch));
749 } 749 }
750 750
751 } // namespace webrtc 751 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/neteq/audio_classifier_unittest.cc ('k') | webrtc/modules/audio_coding/neteq/audio_vector.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698