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

Unified Diff: webrtc/modules/audio_coding/neteq/audio_decoder_unittest.cc

Issue 1725143003: Changed AudioEncoder::Encode to take an rtc::Buffer* instead of uint8_t* and a maximum size. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Reverted unnecessary change to buffer_unittest.cc 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/audio_coding/neteq/audio_decoder_unittest.cc
diff --git a/webrtc/modules/audio_coding/neteq/audio_decoder_unittest.cc b/webrtc/modules/audio_coding/neteq/audio_decoder_unittest.cc
index 58dd6c6680f0c7c9f7f1f164f51e96e8f14de26b..35831ca683a938702d9ca9d21078cb5ac25e47fd 100644
--- a/webrtc/modules/audio_coding/neteq/audio_decoder_unittest.cc
+++ b/webrtc/modules/audio_coding/neteq/audio_decoder_unittest.cc
@@ -100,7 +100,6 @@ class AudioDecoderTest : public ::testing::Test {
webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm"),
32000),
codec_input_rate_hz_(32000), // Legacy default value.
- encoded_(NULL),
frame_size_(0),
data_length_(0),
encoded_bytes_(0),
@@ -115,8 +114,8 @@ class AudioDecoderTest : public ::testing::Test {
codec_input_rate_hz_ = audio_encoder_->SampleRateHz();
// Create arrays.
ASSERT_GT(data_length_, 0u) << "The test must set data_length_ > 0";
- // Longest encoded data is produced by PCM16b with 2 bytes per sample.
- encoded_ = new uint8_t[data_length_ * 2];
+ // Make sure the encode buffer is empty at the start of each test.
+ encoded_.Clear();
kwiberg-webrtc 2016/02/25 00:29:04 Can you allocate a Buffer on the stack for each te
ossu 2016/02/25 10:39:51 Sure.
// Logging to view input and output in Matlab.
// Use 'gyp -Denable_data_logging=1' to enable logging.
DataLog::CreateLog();
@@ -128,9 +127,6 @@ class AudioDecoderTest : public ::testing::Test {
virtual void TearDown() {
delete decoder_;
decoder_ = NULL;
- // Delete arrays.
- delete [] encoded_;
- encoded_ = NULL;
// Close log.
DataLog::ReturnLog();
}
@@ -141,7 +137,7 @@ class AudioDecoderTest : public ::testing::Test {
// implementations are gone.
virtual int EncodeFrame(const int16_t* input,
size_t input_len_samples,
- uint8_t* output) {
+ rtc::Buffer* output) {
encoded_info_.encoded_bytes = 0;
const size_t samples_per_10ms = audio_encoder_->SampleRateHz() / 100;
RTC_CHECK_EQ(samples_per_10ms * audio_encoder_->Num10MsFramesInNextPacket(),
@@ -162,7 +158,7 @@ class AudioDecoderTest : public ::testing::Test {
audio_encoder_->NumChannels() *
audio_encoder_->SampleRateHz() /
100),
- data_length_ * 2, output);
+ output);
}
EXPECT_EQ(payload_type_, encoded_info_.payload_type);
return static_cast<int>(encoded_info_.encoded_bytes);
@@ -179,6 +175,7 @@ class AudioDecoderTest : public ::testing::Test {
ASSERT_GE(channel_diff_tolerance, 0) <<
"Test must define a channel_diff_tolerance >= 0";
size_t processed_samples = 0u;
+ encoded_.Clear();
encoded_bytes_ = 0u;
InitEncoder();
std::vector<int16_t> input;
@@ -191,12 +188,12 @@ class AudioDecoderTest : public ::testing::Test {
ASSERT_TRUE(input_audio_.Read(
frame_size_, codec_input_rate_hz_, &input[processed_samples]));
size_t enc_len = EncodeFrame(
- &input[processed_samples], frame_size_, &encoded_[encoded_bytes_]);
+ &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_[encoded_bytes_], enc_len, codec_input_rate_hz_,
+ &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);
@@ -226,12 +223,13 @@ 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()));
- size_t enc_len = EncodeFrame(input.get(), frame_size_, encoded_);
+ encoded_.Clear();
+ 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_, enc_len, codec_input_rate_hz_,
+ 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_);
@@ -239,7 +237,7 @@ class AudioDecoderTest : public ::testing::Test {
// 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_, enc_len, codec_input_rate_hz_,
+ 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_);
@@ -256,11 +254,13 @@ 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()));
- size_t enc_len = EncodeFrame(input.get(), frame_size_, encoded_);
+ encoded_.Clear();
+ size_t enc_len = EncodeFrame(input.get(), frame_size_, &encoded_);
AudioDecoder::SpeechType speech_type;
decoder_->Reset();
std::unique_ptr<int16_t[]> output(new int16_t[frame_size_ * channels_]);
- size_t dec_len = decoder_->Decode(encoded_, enc_len, codec_input_rate_hz_,
+ 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);
@@ -273,7 +273,7 @@ class AudioDecoderTest : public ::testing::Test {
test::ResampleInputAudioFile input_audio_;
int codec_input_rate_hz_;
- uint8_t* encoded_;
+ rtc::Buffer encoded_;
size_t frame_size_;
size_t data_length_;
size_t encoded_bytes_;
@@ -348,11 +348,13 @@ class AudioDecoderIlbcTest : public AudioDecoderTest {
std::unique_ptr<int16_t[]> input(new int16_t[frame_size_]);
ASSERT_TRUE(
input_audio_.Read(frame_size_, codec_input_rate_hz_, input.get()));
- size_t enc_len = EncodeFrame(input.get(), frame_size_, encoded_);
+ encoded_.Clear();
+ size_t enc_len = EncodeFrame(input.get(), frame_size_, &encoded_);
AudioDecoder::SpeechType speech_type;
decoder_->Reset();
std::unique_ptr<int16_t[]> output(new int16_t[frame_size_ * channels_]);
- size_t dec_len = decoder_->Decode(encoded_, enc_len, codec_input_rate_hz_,
+ 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_, dec_len);

Powered by Google App Engine
This is Rietveld 408576698