Add NetEqPcmuQualityTest

This is virtually the same as NetEq{Isac,Opus}QualityTest but for PCMu.

BUG=2692
R=minyue@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/54379004

Cr-Commit-Position: refs/heads/master@{#9176}
This commit is contained in:
Henrik Lundin
2015-05-12 12:09:59 +02:00
parent fade1790a7
commit e5ff00a1c6
6 changed files with 118 additions and 34 deletions

View File

@ -220,6 +220,22 @@
],
},
{
'target_name': 'neteq_pcmu_quality_test',
'type': 'executable',
'dependencies': [
'neteq',
'neteq_test_support',
'G711',
'<(DEPTH)/testing/gtest.gyp:gtest',
'<(DEPTH)/third_party/gflags/gflags.gyp:gflags',
'<(webrtc_root)/test/test.gyp:test_support_main',
],
'sources': [
'test/neteq_pcmu_quality_test.cc',
],
},
{
'target_name': 'neteq_test_tools',
# Collection of useful functions used in other tests.

View File

@ -36,19 +36,6 @@ DEFINE_int32(bit_rate_kbps, 32, "Target bit rate (kbps).");
static const bool bit_rate_dummy =
RegisterFlagValidator(&FLAGS_bit_rate_kbps, &ValidateBitRate);
// Define switch for runtime.
static bool ValidateRuntime(const char* flagname, int32_t value) {
if (value > 0)
return true;
printf("Invalid runtime, should be greater than 0.");
return false;
}
DEFINE_int32(runtime_ms, 10000, "Simulated runtime (milliseconds).");
static const bool runtime_dummy =
RegisterFlagValidator(&FLAGS_runtime_ms, &ValidateRuntime);
} // namespace
class NetEqIsacQualityTest : public NetEqQualityTest {
@ -110,7 +97,7 @@ int NetEqIsacQualityTest::EncodeBlock(int16_t* in_data,
}
TEST_F(NetEqIsacQualityTest, Test) {
Simulate(FLAGS_runtime_ms);
Simulate();
}
} // namespace test

View File

@ -78,18 +78,6 @@ DEFINE_int32(reported_loss_rate, 10, "Reported percentile of packet loss.");
static const bool reported_loss_rate_dummy =
RegisterFlagValidator(&FLAGS_reported_loss_rate, &ValidatePacketLossRate);
// Define switch for runtime.
static bool ValidateRuntime(const char* flagname, int32_t value) {
if (value > 0)
return true;
printf("Invalid runtime, should be greater than 0.");
return false;
}
DEFINE_int32(runtime_ms, 10000, "Simulated runtime (milliseconds).");
static const bool runtime_dummy =
RegisterFlagValidator(&FLAGS_runtime_ms, &ValidateRuntime);
DEFINE_bool(fec, true, "Whether to enable FEC for encoding.");
DEFINE_bool(dtx, true, "Whether to enable DTX for encoding.");
@ -197,7 +185,7 @@ int NetEqOpusQualityTest::EncodeBlock(int16_t* in_data,
}
TEST_F(NetEqOpusQualityTest, Test) {
Simulate(FLAGS_runtime_ms);
Simulate();
}
} // namespace test

View File

@ -0,0 +1,82 @@
/*
* Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "webrtc/base/checks.h"
#include "webrtc/base/safe_conversions.h"
#include "webrtc/base/scoped_ptr.h"
#include "webrtc/modules/audio_coding/codecs/g711/include/audio_encoder_pcm.h"
#include "webrtc/modules/audio_coding/neteq/tools/neteq_quality_test.h"
#include "webrtc/test/testsupport/fileutils.h"
using google::RegisterFlagValidator;
using google::ParseCommandLineFlags;
using std::string;
using testing::InitGoogleTest;
namespace webrtc {
namespace test {
namespace {
static const int kInputSampleRateKhz = 8;
static const int kOutputSampleRateKhz = 8;
// Define switch for frame size.
static bool ValidateFrameSize(const char* flagname, int32_t value) {
if (value >= 10 && value <= 60 && (value % 10) == 0)
return true;
printf("Invalid frame size, should be 10, 20, ..., 60 ms.");
return false;
}
DEFINE_int32(frame_size_ms, 20, "Codec frame size (milliseconds).");
static const bool frame_size_dummy =
RegisterFlagValidator(&FLAGS_frame_size_ms, &ValidateFrameSize);
} // namespace
class NetEqPcmuQualityTest : public NetEqQualityTest {
protected:
NetEqPcmuQualityTest()
: NetEqQualityTest(FLAGS_frame_size_ms,
kInputSampleRateKhz,
kOutputSampleRateKhz,
kDecoderPCMu,
1) {
AudioEncoderPcmU::Config config;
config.frame_size_ms = FLAGS_frame_size_ms;
encoder_.reset(new AudioEncoderPcmU(config));
}
int EncodeBlock(int16_t* in_data,
int block_size_samples,
uint8_t* payload,
int max_bytes) override {
const int kFrameSizeSamples = 80; // Samples per 10 ms.
int encoded_samples = 0;
uint32_t dummy_timestamp = 0;
AudioEncoder::EncodedInfo info;
do {
info = encoder_->Encode(dummy_timestamp, &in_data[encoded_samples],
kFrameSizeSamples, max_bytes, payload);
encoded_samples += kFrameSizeSamples;
} while (info.encoded_bytes == 0);
return rtc::checked_cast<int>(info.encoded_bytes);
}
private:
rtc::scoped_ptr<AudioEncoderPcmU> encoder_;
};
TEST_F(NetEqPcmuQualityTest, Test) {
Simulate();
}
} // namespace test
} // namespace webrtc

View File

@ -90,6 +90,19 @@ static bool ValidatePacketLossRate(const char* /* flag_name */, int32_t value) {
return false;
}
// Define switch for runtime.
static bool ValidateRuntime(const char* flagname, int32_t value) {
if (value > 0)
return true;
printf("Invalid runtime, should be greater than 0.");
return false;
}
DEFINE_int32(runtime_ms, 10000, "Simulated runtime (milliseconds).");
static const bool runtime_dummy =
RegisterFlagValidator(&FLAGS_runtime_ms, &ValidateRuntime);
DEFINE_int32(packet_loss_rate, 10, "Percentile of packet loss.");
static const bool packet_loss_rate_dummy =
@ -368,10 +381,10 @@ int NetEqQualityTest::DecodeBlock() {
}
}
void NetEqQualityTest::Simulate(int end_time_ms) {
void NetEqQualityTest::Simulate() {
int audio_size_samples;
while (decoded_time_ms_ < end_time_ms) {
while (decoded_time_ms_ < FLAGS_runtime_ms) {
// Assume 10 packets in packets buffer.
while (decodable_time_ms_ - 10 * block_duration_ms_ < decoded_time_ms_) {
ASSERT_TRUE(in_file_->Read(in_size_samples_ * channels_, &in_data_[0]));
@ -386,7 +399,7 @@ void NetEqQualityTest::Simulate(int end_time_ms) {
decoded_time_ms_ += audio_size_samples / out_sampling_khz_;
}
}
fprintf(log_file_, "%f", 8.0f * total_payload_size_bytes_ / end_time_ms);
fprintf(log_file_, "%f", 8.0f * total_payload_size_bytes_ / FLAGS_runtime_ms);
}
} // namespace test

View File

@ -90,10 +90,8 @@ class NetEqQualityTest : public ::testing::Test {
// |neteq_|.
int Transmit();
// Simulate(...) runs encoding / transmitting / decoding up to |end_time_ms|
// (miliseconds), the resulted audio is stored in the file with the name of
// |out_filename_|.
void Simulate(int end_time_ms);
// Runs encoding / transmitting / decoding.
void Simulate();
private:
int decoded_time_ms_;