Adding back main() to the test. Now it is possible to choose between ACM1 and ACM2, furthermore, the test can simulate a channel with packet loss and FEC can be activated. Packet loss pattern is based on channel implementation in Channel{.cc,.h}, which currently is a determenistic pattern with 1 every 3rd packet is discarded.
The main() was deleted in r4731. BUG= R=andrew@webrtc.org, minyue@webrtc.org Review URL: https://webrtc-codereview.appspot.com/2370004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@5132 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
9c5fb76662
commit
7a05ae5c69
@ -117,7 +117,7 @@
|
|||||||
'dependencies': [
|
'dependencies': [
|
||||||
'audio_coding_module',
|
'audio_coding_module',
|
||||||
'<(DEPTH)/testing/gtest.gyp:gtest',
|
'<(DEPTH)/testing/gtest.gyp:gtest',
|
||||||
'<(webrtc_root)/test/test.gyp:test_support_main',
|
'<(webrtc_root)/test/test.gyp:test_support',
|
||||||
'<(webrtc_root)/system_wrappers/source/system_wrappers.gyp:system_wrappers',
|
'<(webrtc_root)/system_wrappers/source/system_wrappers.gyp:system_wrappers',
|
||||||
'<(DEPTH)/third_party/gflags/gflags.gyp:gflags',
|
'<(DEPTH)/third_party/gflags/gflags.gyp:gflags',
|
||||||
],
|
],
|
||||||
@ -125,6 +125,7 @@
|
|||||||
'../test/delay_test.cc',
|
'../test/delay_test.cc',
|
||||||
'../test/Channel.cc',
|
'../test/Channel.cc',
|
||||||
'../test/PCMFile.cc',
|
'../test/PCMFile.cc',
|
||||||
|
'../test/utility.cc',
|
||||||
],
|
],
|
||||||
}, # delay_test
|
}, # delay_test
|
||||||
{
|
{
|
||||||
@ -133,7 +134,7 @@
|
|||||||
'dependencies': [
|
'dependencies': [
|
||||||
'audio_coding_module',
|
'audio_coding_module',
|
||||||
'<(DEPTH)/testing/gtest.gyp:gtest',
|
'<(DEPTH)/testing/gtest.gyp:gtest',
|
||||||
'<(webrtc_root)/test/test.gyp:test_support_main',
|
'<(webrtc_root)/test/test.gyp:test_support',
|
||||||
'<(webrtc_root)/system_wrappers/source/system_wrappers.gyp:system_wrappers',
|
'<(webrtc_root)/system_wrappers/source/system_wrappers.gyp:system_wrappers',
|
||||||
'<(DEPTH)/third_party/gflags/gflags.gyp:gflags',
|
'<(DEPTH)/third_party/gflags/gflags.gyp:gflags',
|
||||||
],
|
],
|
||||||
|
@ -8,8 +8,6 @@
|
|||||||
* be found in the AUTHORS file in the root of the source tree.
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "webrtc/modules/audio_coding/main/interface/audio_coding_module.h"
|
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
@ -17,8 +15,10 @@
|
|||||||
|
|
||||||
#include "gflags/gflags.h"
|
#include "gflags/gflags.h"
|
||||||
#include "testing/gtest/include/gtest/gtest.h"
|
#include "testing/gtest/include/gtest/gtest.h"
|
||||||
|
#include "webrtc/common.h"
|
||||||
#include "webrtc/common_types.h"
|
#include "webrtc/common_types.h"
|
||||||
#include "webrtc/engine_configurations.h"
|
#include "webrtc/engine_configurations.h"
|
||||||
|
#include "webrtc/modules/audio_coding/main/interface/audio_coding_module.h"
|
||||||
#include "webrtc/modules/audio_coding/main/interface/audio_coding_module_typedefs.h"
|
#include "webrtc/modules/audio_coding/main/interface/audio_coding_module_typedefs.h"
|
||||||
#include "webrtc/modules/audio_coding/main/acm2/acm_common_defs.h"
|
#include "webrtc/modules/audio_coding/main/acm2/acm_common_defs.h"
|
||||||
#include "webrtc/modules/audio_coding/main/test/Channel.h"
|
#include "webrtc/modules/audio_coding/main/test/Channel.h"
|
||||||
@ -35,68 +35,76 @@ DEFINE_string(input_file, "", "Input file, PCM16 32 kHz, optional.");
|
|||||||
DEFINE_int32(delay, 0, "Delay in millisecond.");
|
DEFINE_int32(delay, 0, "Delay in millisecond.");
|
||||||
DEFINE_int32(init_delay, 0, "Initial delay in millisecond.");
|
DEFINE_int32(init_delay, 0, "Initial delay in millisecond.");
|
||||||
DEFINE_bool(dtx, false, "Enable DTX at the sender side.");
|
DEFINE_bool(dtx, false, "Enable DTX at the sender side.");
|
||||||
|
DEFINE_bool(acm2, false, "Run the test with ACM2.");
|
||||||
|
DEFINE_bool(packet_loss, false, "Apply packet loss, c.f. Channel{.cc, .h}.");
|
||||||
|
DEFINE_bool(fec, false, "Use Forward Error Correction (FEC).");
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
struct CodecConfig {
|
struct CodecSettings {
|
||||||
char name[50];
|
char name[50];
|
||||||
int sample_rate_hz;
|
int sample_rate_hz;
|
||||||
int num_channels;
|
int num_channels;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct AcmConfig {
|
struct AcmSettings {
|
||||||
bool dtx;
|
bool dtx;
|
||||||
bool fec;
|
bool fec;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Config {
|
struct TestSettings {
|
||||||
CodecConfig codec;
|
CodecSettings codec;
|
||||||
AcmConfig acm;
|
AcmSettings acm;
|
||||||
bool packet_loss;
|
bool packet_loss;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
class DelayTest {
|
class DelayTest {
|
||||||
public:
|
public:
|
||||||
|
explicit DelayTest(const Config& config)
|
||||||
DelayTest()
|
: acm_a_(config.Get<AudioCodingModuleFactory>().Create(0)),
|
||||||
: acm_a_(AudioCodingModule::Create(0)),
|
acm_b_(config.Get<AudioCodingModuleFactory>().Create(1)),
|
||||||
acm_b_(AudioCodingModule::Create(1)),
|
channel_a2b_(new Channel),
|
||||||
channel_a2b_(NULL),
|
|
||||||
test_cntr_(0),
|
test_cntr_(0),
|
||||||
encoding_sample_rate_hz_(8000) {}
|
encoding_sample_rate_hz_(8000) {}
|
||||||
|
|
||||||
~DelayTest() {}
|
~DelayTest() {
|
||||||
|
|
||||||
void TearDown() {
|
|
||||||
if (channel_a2b_ != NULL) {
|
if (channel_a2b_ != NULL) {
|
||||||
delete channel_a2b_;
|
delete channel_a2b_;
|
||||||
channel_a2b_ = NULL;
|
channel_a2b_ = NULL;
|
||||||
}
|
}
|
||||||
|
in_file_a_.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetUp() {
|
void Initialize() {
|
||||||
test_cntr_ = 0;
|
test_cntr_ = 0;
|
||||||
std::string file_name = webrtc::test::ResourcePath(
|
std::string file_name = webrtc::test::ResourcePath(
|
||||||
"audio_coding/testfile32kHz", "pcm");
|
"audio_coding/testfile32kHz", "pcm");
|
||||||
if (FLAGS_input_file.size() > 0)
|
if (FLAGS_input_file.size() > 0)
|
||||||
file_name = FLAGS_input_file;
|
file_name = FLAGS_input_file;
|
||||||
in_file_a_.Open(file_name, 32000, "rb");
|
in_file_a_.Open(file_name, 32000, "rb");
|
||||||
acm_a_->InitializeReceiver();
|
ASSERT_EQ(0, acm_a_->InitializeReceiver()) <<
|
||||||
acm_b_->InitializeReceiver();
|
"Couldn't initialize receiver.\n";
|
||||||
|
ASSERT_EQ(0, acm_b_->InitializeReceiver()) <<
|
||||||
|
"Couldn't initialize receiver.\n";
|
||||||
if (FLAGS_init_delay > 0) {
|
if (FLAGS_init_delay > 0) {
|
||||||
ASSERT_EQ(0, acm_b_->SetInitialPlayoutDelay(FLAGS_init_delay));
|
ASSERT_EQ(0, acm_b_->SetInitialPlayoutDelay(FLAGS_init_delay)) <<
|
||||||
|
"Failed to set initial delay.\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FLAGS_delay > 0) {
|
if (FLAGS_delay > 0) {
|
||||||
ASSERT_EQ(0, acm_b_->SetMinimumPlayoutDelay(FLAGS_delay));
|
ASSERT_EQ(0, acm_b_->SetMinimumPlayoutDelay(FLAGS_delay)) <<
|
||||||
|
"Failed to set minimum delay.\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t num_encoders = acm_a_->NumberOfCodecs();
|
int num_encoders = acm_a_->NumberOfCodecs();
|
||||||
CodecInst my_codec_param;
|
CodecInst my_codec_param;
|
||||||
for (int n = 0; n < num_encoders; n++) {
|
for (int n = 0; n < num_encoders; n++) {
|
||||||
acm_b_->Codec(n, &my_codec_param);
|
EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param)) <<
|
||||||
|
"Failed to get codec.";
|
||||||
if (STR_CASE_CMP(my_codec_param.plname, "opus") == 0)
|
if (STR_CASE_CMP(my_codec_param.plname, "opus") == 0)
|
||||||
my_codec_param.channels = 1;
|
my_codec_param.channels = 1;
|
||||||
else if (my_codec_param.channels > 1)
|
else if (my_codec_param.channels > 1)
|
||||||
@ -106,16 +114,17 @@ class DelayTest {
|
|||||||
continue;
|
continue;
|
||||||
if (STR_CASE_CMP(my_codec_param.plname, "telephone-event") == 0)
|
if (STR_CASE_CMP(my_codec_param.plname, "telephone-event") == 0)
|
||||||
continue;
|
continue;
|
||||||
acm_b_->RegisterReceiveCodec(my_codec_param);
|
ASSERT_EQ(0, acm_b_->RegisterReceiveCodec(my_codec_param)) <<
|
||||||
|
"Couldn't register receive codec.\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create and connect the channel
|
// Create and connect the channel
|
||||||
channel_a2b_ = new Channel;
|
ASSERT_EQ(0, acm_a_->RegisterTransportCallback(channel_a2b_)) <<
|
||||||
acm_a_->RegisterTransportCallback(channel_a2b_);
|
"Couldn't register Transport callback.\n";
|
||||||
channel_a2b_->RegisterReceiverACM(acm_b_.get());
|
channel_a2b_->RegisterReceiverACM(acm_b_.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Perform(const Config* config, size_t num_tests, int duration_sec,
|
void Perform(const TestSettings* config, size_t num_tests, int duration_sec,
|
||||||
const char* output_prefix) {
|
const char* output_prefix) {
|
||||||
for (size_t n = 0; n < num_tests; ++n) {
|
for (size_t n = 0; n < num_tests; ++n) {
|
||||||
ApplyConfig(config[n]);
|
ApplyConfig(config[n]);
|
||||||
@ -124,8 +133,7 @@ class DelayTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void ApplyConfig(const TestSettings& config) {
|
||||||
void ApplyConfig(const Config& config) {
|
|
||||||
printf("====================================\n");
|
printf("====================================\n");
|
||||||
printf("Test %d \n"
|
printf("Test %d \n"
|
||||||
"Codec: %s, %d kHz, %d channel(s)\n"
|
"Codec: %s, %d kHz, %d channel(s)\n"
|
||||||
@ -140,19 +148,22 @@ class DelayTest {
|
|||||||
ConfigChannel(config.packet_loss);
|
ConfigChannel(config.packet_loss);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SendCodec(const CodecConfig& config) {
|
void SendCodec(const CodecSettings& config) {
|
||||||
CodecInst my_codec_param;
|
CodecInst my_codec_param;
|
||||||
ASSERT_EQ(
|
ASSERT_EQ(0, AudioCodingModule::Codec(
|
||||||
0,
|
config.name, &my_codec_param, config.sample_rate_hz,
|
||||||
AudioCodingModule::Codec(config.name, &my_codec_param,
|
config.num_channels)) << "Specified codec is not supported.\n";
|
||||||
config.sample_rate_hz, config.num_channels));
|
|
||||||
encoding_sample_rate_hz_ = my_codec_param.plfreq;
|
encoding_sample_rate_hz_ = my_codec_param.plfreq;
|
||||||
ASSERT_EQ(0, acm_a_->RegisterSendCodec(my_codec_param));
|
ASSERT_EQ(0, acm_a_->RegisterSendCodec(my_codec_param)) <<
|
||||||
|
"Failed to register send-codec.\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigAcm(const AcmConfig& config) {
|
void ConfigAcm(const AcmSettings& config) {
|
||||||
ASSERT_EQ(0, acm_a_->SetVAD(config.dtx, config.dtx, VADAggr));
|
ASSERT_EQ(0, acm_a_->SetVAD(config.dtx, config.dtx, VADAggr)) <<
|
||||||
ASSERT_EQ(0, acm_a_->SetFECStatus(config.fec));
|
"Failed to set VAD.\n";
|
||||||
|
ASSERT_EQ(0, acm_a_->SetFECStatus(config.fec)) <<
|
||||||
|
"Failed to set FEC.\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigChannel(bool packet_loss) {
|
void ConfigChannel(bool packet_loss) {
|
||||||
@ -230,19 +241,39 @@ class DelayTest {
|
|||||||
int encoding_sample_rate_hz_;
|
int encoding_sample_rate_hz_;
|
||||||
};
|
};
|
||||||
|
|
||||||
void RunTest() {
|
|
||||||
Config config;
|
|
||||||
strcpy(config.codec.name, FLAGS_codec.c_str());
|
|
||||||
config.codec.sample_rate_hz = FLAGS_sample_rate_hz;
|
|
||||||
config.codec.num_channels = FLAGS_num_channels;
|
|
||||||
config.acm.dtx = FLAGS_dtx;
|
|
||||||
config.acm.fec = false;
|
|
||||||
config.packet_loss = false;
|
|
||||||
|
|
||||||
DelayTest delay_test;
|
|
||||||
delay_test.SetUp();
|
|
||||||
delay_test.Perform(&config, 1, 240, "delay_test");
|
|
||||||
delay_test.TearDown();
|
|
||||||
}
|
|
||||||
} // namespace
|
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
|
|
||||||
|
int main(int argc, char* argv[]) {
|
||||||
|
google::ParseCommandLineFlags(&argc, &argv, true);
|
||||||
|
webrtc::Config config;
|
||||||
|
webrtc::TestSettings test_setting;
|
||||||
|
strcpy(test_setting.codec.name, FLAGS_codec.c_str());
|
||||||
|
|
||||||
|
if (FLAGS_sample_rate_hz != 8000 &&
|
||||||
|
FLAGS_sample_rate_hz != 16000 &&
|
||||||
|
FLAGS_sample_rate_hz != 32000 &&
|
||||||
|
FLAGS_sample_rate_hz != 48000) {
|
||||||
|
std::cout << "Invalid sampling rate.\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
test_setting.codec.sample_rate_hz = FLAGS_sample_rate_hz;
|
||||||
|
if (FLAGS_num_channels < 1 || FLAGS_num_channels > 2) {
|
||||||
|
std::cout << "Only mono and stereo are supported.\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
test_setting.codec.num_channels = FLAGS_num_channels;
|
||||||
|
test_setting.acm.dtx = FLAGS_dtx;
|
||||||
|
test_setting.acm.fec = FLAGS_fec;
|
||||||
|
test_setting.packet_loss = FLAGS_packet_loss;
|
||||||
|
|
||||||
|
if (FLAGS_acm2) {
|
||||||
|
webrtc::UseNewAcm(&config);
|
||||||
|
} else {
|
||||||
|
webrtc::UseLegacyAcm(&config);
|
||||||
|
}
|
||||||
|
|
||||||
|
webrtc::DelayTest delay_test(config);
|
||||||
|
delay_test.Initialize();
|
||||||
|
delay_test.Perform(&test_setting, 1, 240, "delay_test");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user