aboutsummaryrefslogtreecommitdiff
path: root/modules/audio_coding
diff options
context:
space:
mode:
authorAlessio Bazzica <alessiob@webrtc.org>2020-02-13 09:18:24 +0100
committerCommit Bot <commit-bot@chromium.org>2020-02-13 09:05:55 +0000
commitb28e57e72580b0269cecf91754b4c3a1937e0712 (patch)
treeeea6f672134ac72f1dd16b8066fcb14b0ed086f6 /modules/audio_coding
parentea820932d8502074bc8c2c401eaea172773288ae (diff)
downloadwebrtc-b28e57e72580b0269cecf91754b4c3a1937e0712.tar.gz
NetEQ audio decoder unit test: use ParsePayload
AudioDecoder::Decode() is obsolete. This CL replaces it with ParsePayload() in the audio decoder NetEQ unit tests. Bug: webrtc:10098 Change-Id: I602b0330adbe1d0921b0c4524aa7305b500f2ebf Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/168486 Commit-Queue: Alessio Bazzica <alessiob@webrtc.org> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Cr-Commit-Position: refs/heads/master@{#30511}
Diffstat (limited to 'modules/audio_coding')
-rw-r--r--modules/audio_coding/neteq/audio_decoder_unittest.cc74
1 files changed, 37 insertions, 37 deletions
diff --git a/modules/audio_coding/neteq/audio_decoder_unittest.cc b/modules/audio_coding/neteq/audio_decoder_unittest.cc
index c3281b444f..773e73b6bf 100644
--- a/modules/audio_coding/neteq/audio_decoder_unittest.cc
+++ b/modules/audio_coding/neteq/audio_decoder_unittest.cc
@@ -11,6 +11,7 @@
#include <assert.h>
#include <stdlib.h>
+#include <array>
#include <memory>
#include <string>
#include <vector>
@@ -162,7 +163,6 @@ class AudioDecoderTest : public ::testing::Test {
ASSERT_GE(channel_diff_tolerance, 0)
<< "Test must define a channel_diff_tolerance >= 0";
size_t processed_samples = 0u;
- rtc::Buffer encoded;
size_t encoded_bytes = 0u;
InitEncoder();
std::vector<int16_t> input;
@@ -174,16 +174,20 @@ class AudioDecoderTest : public ::testing::Test {
ASSERT_GE(input.size() - processed_samples, frame_size_);
ASSERT_TRUE(input_audio_.Read(frame_size_, codec_input_rate_hz_,
&input[processed_samples]));
+ rtc::Buffer encoded;
size_t enc_len =
EncodeFrame(&input[processed_samples], frame_size_, &encoded);
// Make sure that frame_size_ * channels_ samples are allocated and free.
decoded.resize((processed_samples + frame_size_) * channels_, 0);
- AudioDecoder::SpeechType speech_type;
- size_t dec_len = decoder_->Decode(
- &encoded.data()[encoded_bytes], enc_len, codec_input_rate_hz_,
- frame_size_ * channels_ * sizeof(int16_t),
- &decoded[processed_samples * channels_], &speech_type);
- EXPECT_EQ(frame_size_ * channels_, dec_len);
+
+ const std::vector<AudioDecoder::ParseResult> parse_result =
+ decoder_->ParsePayload(std::move(encoded), /*timestamp=*/0);
+ RTC_CHECK_EQ(parse_result.size(), size_t{1});
+ auto decode_result = parse_result[0].frame->Decode(
+ rtc::ArrayView<int16_t>(&decoded[processed_samples * channels_],
+ frame_size_ * channels_ * sizeof(int16_t)));
+ RTC_CHECK(decode_result.has_value());
+ EXPECT_EQ(frame_size_ * channels_, decode_result->num_decoded_samples);
encoded_bytes += enc_len;
processed_samples += frame_size_;
}
@@ -210,29 +214,23 @@ class AudioDecoderTest : public ::testing::Test {
std::unique_ptr<int16_t[]> input(new int16_t[frame_size_]);
ASSERT_TRUE(
input_audio_.Read(frame_size_, codec_input_rate_hz_, input.get()));
- rtc::Buffer encoded;
- size_t enc_len = EncodeFrame(input.get(), frame_size_, &encoded);
- size_t dec_len;
- AudioDecoder::SpeechType speech_type1, speech_type2;
- decoder_->Reset();
- std::unique_ptr<int16_t[]> output1(new int16_t[frame_size_ * channels_]);
- dec_len = decoder_->Decode(encoded.data(), enc_len, codec_input_rate_hz_,
- frame_size_ * channels_ * sizeof(int16_t),
- output1.get(), &speech_type1);
- ASSERT_LE(dec_len, frame_size_ * channels_);
- EXPECT_EQ(frame_size_ * channels_, dec_len);
- // Re-init decoder and decode again.
- decoder_->Reset();
- std::unique_ptr<int16_t[]> output2(new int16_t[frame_size_ * channels_]);
- dec_len = decoder_->Decode(encoded.data(), enc_len, codec_input_rate_hz_,
- frame_size_ * channels_ * sizeof(int16_t),
- output2.get(), &speech_type2);
- ASSERT_LE(dec_len, frame_size_ * channels_);
- EXPECT_EQ(frame_size_ * channels_, dec_len);
- for (unsigned int n = 0; n < frame_size_; ++n) {
- ASSERT_EQ(output1[n], output2[n]) << "Exit test on first diff; n = " << n;
+ std::array<rtc::Buffer, 2> encoded;
+ EncodeFrame(input.get(), frame_size_, &encoded[0]);
+ // Make a copy.
+ encoded[1].SetData(encoded[0].data(), encoded[0].size());
+
+ std::array<std::vector<int16_t>, 2> outputs;
+ for (size_t i = 0; i < outputs.size(); ++i) {
+ outputs[i].resize(frame_size_ * channels_);
+ decoder_->Reset();
+ const std::vector<AudioDecoder::ParseResult> parse_result =
+ decoder_->ParsePayload(std::move(encoded[i]), /*timestamp=*/0);
+ RTC_CHECK_EQ(parse_result.size(), size_t{1});
+ auto decode_result = parse_result[0].frame->Decode(outputs[i]);
+ RTC_CHECK(decode_result.has_value());
+ EXPECT_EQ(frame_size_ * channels_, decode_result->num_decoded_samples);
}
- EXPECT_EQ(speech_type1, speech_type2);
+ EXPECT_EQ(outputs[0], outputs[1]);
}
// Call DecodePlc and verify that the correct number of samples is produced.
@@ -242,18 +240,20 @@ class AudioDecoderTest : public ::testing::Test {
ASSERT_TRUE(
input_audio_.Read(frame_size_, codec_input_rate_hz_, input.get()));
rtc::Buffer encoded;
- size_t enc_len = EncodeFrame(input.get(), frame_size_, &encoded);
- AudioDecoder::SpeechType speech_type;
+ EncodeFrame(input.get(), frame_size_, &encoded);
decoder_->Reset();
- std::unique_ptr<int16_t[]> output(new int16_t[frame_size_ * channels_]);
- size_t dec_len = decoder_->Decode(
- encoded.data(), enc_len, codec_input_rate_hz_,
- frame_size_ * channels_ * sizeof(int16_t), output.get(), &speech_type);
- EXPECT_EQ(frame_size_ * channels_, dec_len);
+ std::vector<int16_t> output(frame_size_ * channels_);
+ const std::vector<AudioDecoder::ParseResult> parse_result =
+ decoder_->ParsePayload(std::move(encoded), /*timestamp=*/0);
+ RTC_CHECK_EQ(parse_result.size(), size_t{1});
+ auto decode_result = parse_result[0].frame->Decode(output);
+ RTC_CHECK(decode_result.has_value());
+ EXPECT_EQ(frame_size_ * channels_, decode_result->num_decoded_samples);
// Call DecodePlc and verify that we get one frame of data.
// (Overwrite the output from the above Decode call, but that does not
// matter.)
- dec_len = decoder_->DecodePlc(1, output.get());
+ size_t dec_len =
+ decoder_->DecodePlc(/*num_frames=*/1, /*decoded=*/output.data());
EXPECT_EQ(frame_size_ * channels_, dec_len);
}