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}
This commit is contained in:

committed by
Commit Bot

parent
ea820932d8
commit
b28e57e725
@ -11,6 +11,7 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include <array>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -162,7 +163,6 @@ class AudioDecoderTest : public ::testing::Test {
|
|||||||
ASSERT_GE(channel_diff_tolerance, 0)
|
ASSERT_GE(channel_diff_tolerance, 0)
|
||||||
<< "Test must define a channel_diff_tolerance >= 0";
|
<< "Test must define a channel_diff_tolerance >= 0";
|
||||||
size_t processed_samples = 0u;
|
size_t processed_samples = 0u;
|
||||||
rtc::Buffer encoded;
|
|
||||||
size_t encoded_bytes = 0u;
|
size_t encoded_bytes = 0u;
|
||||||
InitEncoder();
|
InitEncoder();
|
||||||
std::vector<int16_t> input;
|
std::vector<int16_t> input;
|
||||||
@ -174,16 +174,20 @@ class AudioDecoderTest : public ::testing::Test {
|
|||||||
ASSERT_GE(input.size() - processed_samples, frame_size_);
|
ASSERT_GE(input.size() - processed_samples, frame_size_);
|
||||||
ASSERT_TRUE(input_audio_.Read(frame_size_, codec_input_rate_hz_,
|
ASSERT_TRUE(input_audio_.Read(frame_size_, codec_input_rate_hz_,
|
||||||
&input[processed_samples]));
|
&input[processed_samples]));
|
||||||
|
rtc::Buffer encoded;
|
||||||
size_t enc_len =
|
size_t enc_len =
|
||||||
EncodeFrame(&input[processed_samples], frame_size_, &encoded);
|
EncodeFrame(&input[processed_samples], frame_size_, &encoded);
|
||||||
// Make sure that frame_size_ * channels_ samples are allocated and free.
|
// Make sure that frame_size_ * channels_ samples are allocated and free.
|
||||||
decoded.resize((processed_samples + frame_size_) * channels_, 0);
|
decoded.resize((processed_samples + frame_size_) * channels_, 0);
|
||||||
AudioDecoder::SpeechType speech_type;
|
|
||||||
size_t dec_len = decoder_->Decode(
|
const std::vector<AudioDecoder::ParseResult> parse_result =
|
||||||
&encoded.data()[encoded_bytes], enc_len, codec_input_rate_hz_,
|
decoder_->ParsePayload(std::move(encoded), /*timestamp=*/0);
|
||||||
frame_size_ * channels_ * sizeof(int16_t),
|
RTC_CHECK_EQ(parse_result.size(), size_t{1});
|
||||||
&decoded[processed_samples * channels_], &speech_type);
|
auto decode_result = parse_result[0].frame->Decode(
|
||||||
EXPECT_EQ(frame_size_ * channels_, dec_len);
|
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;
|
encoded_bytes += enc_len;
|
||||||
processed_samples += frame_size_;
|
processed_samples += frame_size_;
|
||||||
}
|
}
|
||||||
@ -210,29 +214,23 @@ class AudioDecoderTest : public ::testing::Test {
|
|||||||
std::unique_ptr<int16_t[]> input(new int16_t[frame_size_]);
|
std::unique_ptr<int16_t[]> input(new int16_t[frame_size_]);
|
||||||
ASSERT_TRUE(
|
ASSERT_TRUE(
|
||||||
input_audio_.Read(frame_size_, codec_input_rate_hz_, input.get()));
|
input_audio_.Read(frame_size_, codec_input_rate_hz_, input.get()));
|
||||||
rtc::Buffer encoded;
|
std::array<rtc::Buffer, 2> encoded;
|
||||||
size_t enc_len = EncodeFrame(input.get(), frame_size_, &encoded);
|
EncodeFrame(input.get(), frame_size_, &encoded[0]);
|
||||||
size_t dec_len;
|
// Make a copy.
|
||||||
AudioDecoder::SpeechType speech_type1, speech_type2;
|
encoded[1].SetData(encoded[0].data(), encoded[0].size());
|
||||||
decoder_->Reset();
|
|
||||||
std::unique_ptr<int16_t[]> output1(new int16_t[frame_size_ * channels_]);
|
std::array<std::vector<int16_t>, 2> outputs;
|
||||||
dec_len = decoder_->Decode(encoded.data(), enc_len, codec_input_rate_hz_,
|
for (size_t i = 0; i < outputs.size(); ++i) {
|
||||||
frame_size_ * channels_ * sizeof(int16_t),
|
outputs[i].resize(frame_size_ * channels_);
|
||||||
output1.get(), &speech_type1);
|
decoder_->Reset();
|
||||||
ASSERT_LE(dec_len, frame_size_ * channels_);
|
const std::vector<AudioDecoder::ParseResult> parse_result =
|
||||||
EXPECT_EQ(frame_size_ * channels_, dec_len);
|
decoder_->ParsePayload(std::move(encoded[i]), /*timestamp=*/0);
|
||||||
// Re-init decoder and decode again.
|
RTC_CHECK_EQ(parse_result.size(), size_t{1});
|
||||||
decoder_->Reset();
|
auto decode_result = parse_result[0].frame->Decode(outputs[i]);
|
||||||
std::unique_ptr<int16_t[]> output2(new int16_t[frame_size_ * channels_]);
|
RTC_CHECK(decode_result.has_value());
|
||||||
dec_len = decoder_->Decode(encoded.data(), enc_len, codec_input_rate_hz_,
|
EXPECT_EQ(frame_size_ * channels_, decode_result->num_decoded_samples);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
EXPECT_EQ(speech_type1, speech_type2);
|
EXPECT_EQ(outputs[0], outputs[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call DecodePlc and verify that the correct number of samples is produced.
|
// Call DecodePlc and verify that the correct number of samples is produced.
|
||||||
@ -242,18 +240,20 @@ class AudioDecoderTest : public ::testing::Test {
|
|||||||
ASSERT_TRUE(
|
ASSERT_TRUE(
|
||||||
input_audio_.Read(frame_size_, codec_input_rate_hz_, input.get()));
|
input_audio_.Read(frame_size_, codec_input_rate_hz_, input.get()));
|
||||||
rtc::Buffer encoded;
|
rtc::Buffer encoded;
|
||||||
size_t enc_len = EncodeFrame(input.get(), frame_size_, &encoded);
|
EncodeFrame(input.get(), frame_size_, &encoded);
|
||||||
AudioDecoder::SpeechType speech_type;
|
|
||||||
decoder_->Reset();
|
decoder_->Reset();
|
||||||
std::unique_ptr<int16_t[]> output(new int16_t[frame_size_ * channels_]);
|
std::vector<int16_t> output(frame_size_ * channels_);
|
||||||
size_t dec_len = decoder_->Decode(
|
const std::vector<AudioDecoder::ParseResult> parse_result =
|
||||||
encoded.data(), enc_len, codec_input_rate_hz_,
|
decoder_->ParsePayload(std::move(encoded), /*timestamp=*/0);
|
||||||
frame_size_ * channels_ * sizeof(int16_t), output.get(), &speech_type);
|
RTC_CHECK_EQ(parse_result.size(), size_t{1});
|
||||||
EXPECT_EQ(frame_size_ * channels_, dec_len);
|
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.
|
// Call DecodePlc and verify that we get one frame of data.
|
||||||
// (Overwrite the output from the above Decode call, but that does not
|
// (Overwrite the output from the above Decode call, but that does not
|
||||||
// matter.)
|
// 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);
|
EXPECT_EQ(frame_size_ * channels_, dec_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user