Replace remaining gflags usages with rtc_base/flags
Continued from https://codereview.webrtc.org/2995363002 BUG=webrtc:7644 Review-Url: https://codereview.webrtc.org/3005483002 Cr-Commit-Position: refs/heads/master@{#19624}
This commit is contained in:
@ -10,11 +10,11 @@
|
||||
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
|
||||
#include "gflags/gflags.h"
|
||||
#include "webrtc/common_types.h"
|
||||
#include "webrtc/modules/audio_coding/codecs/audio_format_conversion.h"
|
||||
#include "webrtc/modules/audio_coding/include/audio_coding_module.h"
|
||||
@ -22,19 +22,21 @@
|
||||
#include "webrtc/modules/audio_coding/test/Channel.h"
|
||||
#include "webrtc/modules/audio_coding/test/PCMFile.h"
|
||||
#include "webrtc/modules/audio_coding/test/utility.h"
|
||||
#include "webrtc/rtc_base/flags.h"
|
||||
#include "webrtc/system_wrappers/include/event_wrapper.h"
|
||||
#include "webrtc/test/gtest.h"
|
||||
#include "webrtc/test/testsupport/fileutils.h"
|
||||
#include "webrtc/typedefs.h"
|
||||
|
||||
DEFINE_string(codec, "isac", "Codec Name");
|
||||
DEFINE_int32(sample_rate_hz, 16000, "Sampling rate in Hertz.");
|
||||
DEFINE_int32(num_channels, 1, "Number of Channels.");
|
||||
DEFINE_int(sample_rate_hz, 16000, "Sampling rate in Hertz.");
|
||||
DEFINE_int(num_channels, 1, "Number of Channels.");
|
||||
DEFINE_string(input_file, "", "Input file, PCM16 32 kHz, optional.");
|
||||
DEFINE_int32(delay, 0, "Delay in millisecond.");
|
||||
DEFINE_int(delay, 0, "Delay in millisecond.");
|
||||
DEFINE_bool(dtx, false, "Enable DTX at the sender side.");
|
||||
DEFINE_bool(packet_loss, false, "Apply packet loss, c.f. Channel{.cc, .h}.");
|
||||
DEFINE_bool(fec, false, "Use Forward Error Correction (FEC).");
|
||||
DEFINE_bool(help, false, "Print this message.");
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
@ -80,16 +82,16 @@ class DelayTest {
|
||||
test_cntr_ = 0;
|
||||
std::string file_name = webrtc::test::ResourcePath(
|
||||
"audio_coding/testfile32kHz", "pcm");
|
||||
if (FLAGS_input_file.size() > 0)
|
||||
file_name = FLAGS_input_file;
|
||||
if (strlen(FLAG_input_file) > 0)
|
||||
file_name = FLAG_input_file;
|
||||
in_file_a_.Open(file_name, 32000, "rb");
|
||||
ASSERT_EQ(0, acm_a_->InitializeReceiver()) <<
|
||||
"Couldn't initialize receiver.\n";
|
||||
ASSERT_EQ(0, acm_b_->InitializeReceiver()) <<
|
||||
"Couldn't initialize receiver.\n";
|
||||
|
||||
if (FLAGS_delay > 0) {
|
||||
ASSERT_EQ(0, acm_b_->SetMinimumPlayoutDelay(FLAGS_delay)) <<
|
||||
if (FLAG_delay > 0) {
|
||||
ASSERT_EQ(0, acm_b_->SetMinimumPlayoutDelay(FLAG_delay)) <<
|
||||
"Failed to set minimum delay.\n";
|
||||
}
|
||||
|
||||
@ -166,8 +168,8 @@ class DelayTest {
|
||||
|
||||
void OpenOutFile(const char* output_id) {
|
||||
std::stringstream file_stream;
|
||||
file_stream << "delay_test_" << FLAGS_codec << "_" << FLAGS_sample_rate_hz
|
||||
<< "Hz" << "_" << FLAGS_delay << "ms.pcm";
|
||||
file_stream << "delay_test_" << FLAG_codec << "_" << FLAG_sample_rate_hz
|
||||
<< "Hz" << "_" << FLAG_delay << "ms.pcm";
|
||||
std::cout << "Output file: " << file_stream.str() << std::endl << std::endl;
|
||||
std::string file_name = webrtc::test::OutputPath() + file_stream.str();
|
||||
out_file_b_.Open(file_name.c_str(), 32000, "wb");
|
||||
@ -240,26 +242,33 @@ class DelayTest {
|
||||
} // namespace webrtc
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
google::ParseCommandLineFlags(&argc, &argv, true);
|
||||
webrtc::TestSettings test_setting;
|
||||
strcpy(test_setting.codec.name, FLAGS_codec.c_str());
|
||||
if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true)) {
|
||||
return 1;
|
||||
}
|
||||
if (FLAG_help) {
|
||||
rtc::FlagList::Print(nullptr, false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (FLAGS_sample_rate_hz != 8000 &&
|
||||
FLAGS_sample_rate_hz != 16000 &&
|
||||
FLAGS_sample_rate_hz != 32000 &&
|
||||
FLAGS_sample_rate_hz != 48000) {
|
||||
webrtc::TestSettings test_setting;
|
||||
strcpy(test_setting.codec.name, FLAG_codec);
|
||||
|
||||
if (FLAG_sample_rate_hz != 8000 &&
|
||||
FLAG_sample_rate_hz != 16000 &&
|
||||
FLAG_sample_rate_hz != 32000 &&
|
||||
FLAG_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) {
|
||||
test_setting.codec.sample_rate_hz = FLAG_sample_rate_hz;
|
||||
if (FLAG_num_channels < 1 || FLAG_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;
|
||||
test_setting.codec.num_channels = FLAG_num_channels;
|
||||
test_setting.acm.dtx = FLAG_dtx;
|
||||
test_setting.acm.fec = FLAG_fec;
|
||||
test_setting.packet_loss = FLAG_packet_loss;
|
||||
|
||||
webrtc::DelayTest delay_test;
|
||||
delay_test.Initialize();
|
||||
|
||||
@ -9,31 +9,32 @@
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "gflags/gflags.h"
|
||||
#include "webrtc/common_types.h"
|
||||
#include "webrtc/modules/audio_coding/codecs/audio_format_conversion.h"
|
||||
#include "webrtc/modules/audio_coding/include/audio_coding_module.h"
|
||||
#include "webrtc/modules/audio_coding/test/Channel.h"
|
||||
#include "webrtc/modules/audio_coding/test/PCMFile.h"
|
||||
#include "webrtc/modules/include/module_common_types.h"
|
||||
#include "webrtc/rtc_base/flags.h"
|
||||
#include "webrtc/system_wrappers/include/clock.h"
|
||||
#include "webrtc/test/gtest.h"
|
||||
#include "webrtc/test/testsupport/fileutils.h"
|
||||
|
||||
// Codec.
|
||||
DEFINE_string(codec, "opus", "Codec Name");
|
||||
DEFINE_int32(codec_sample_rate_hz, 48000, "Sampling rate in Hertz.");
|
||||
DEFINE_int32(codec_channels, 1, "Number of channels of the codec.");
|
||||
DEFINE_int(codec_sample_rate_hz, 48000, "Sampling rate in Hertz.");
|
||||
DEFINE_int(codec_channels, 1, "Number of channels of the codec.");
|
||||
|
||||
// PCM input/output.
|
||||
DEFINE_string(input, "", "Input PCM file at 16 kHz.");
|
||||
DEFINE_bool(input_stereo, false, "Input is stereo.");
|
||||
DEFINE_int32(input_fs_hz, 32000, "Input sample rate Hz.");
|
||||
DEFINE_int(input_fs_hz, 32000, "Input sample rate Hz.");
|
||||
DEFINE_string(output, "insert_rtp_with_timing_out.pcm", "OutputFile");
|
||||
DEFINE_int32(output_fs_hz, 32000, "Output sample rate Hz");
|
||||
DEFINE_int(output_fs_hz, 32000, "Output sample rate Hz");
|
||||
|
||||
// Timing files
|
||||
DEFINE_string(seq_num, "seq_num", "Sequence number file.");
|
||||
@ -45,7 +46,9 @@ DEFINE_string(delay, "", "Log for delay.");
|
||||
|
||||
// Other setups
|
||||
DEFINE_bool(verbose, false, "Verbosity.");
|
||||
DEFINE_double(loss_rate, 0, "Rate of packet loss < 1");
|
||||
DEFINE_float(loss_rate, 0, "Rate of packet loss < 1");
|
||||
|
||||
DEFINE_bool(help, false, "Prints this message.");
|
||||
|
||||
const int32_t kAudioPlayedOut = 0x00000001;
|
||||
const int32_t kPacketPushedIn = 0x00000001 << 1;
|
||||
@ -61,10 +64,10 @@ class InsertPacketWithTiming {
|
||||
send_acm_(AudioCodingModule::Create(0, sender_clock_)),
|
||||
receive_acm_(AudioCodingModule::Create(0, receiver_clock_)),
|
||||
channel_(new Channel),
|
||||
seq_num_fid_(fopen(FLAGS_seq_num.c_str(), "rt")),
|
||||
send_ts_fid_(fopen(FLAGS_send_ts.c_str(), "rt")),
|
||||
receive_ts_fid_(fopen(FLAGS_receive_ts.c_str(), "rt")),
|
||||
pcm_out_fid_(fopen(FLAGS_output.c_str(), "wb")),
|
||||
seq_num_fid_(fopen(FLAG_seq_num, "rt")),
|
||||
send_ts_fid_(fopen(FLAG_send_ts, "rt")),
|
||||
receive_ts_fid_(fopen(FLAG_receive_ts, "rt")),
|
||||
pcm_out_fid_(fopen(FLAG_output, "wb")),
|
||||
samples_in_1ms_(48),
|
||||
num_10ms_in_codec_frame_(2), // Typical 20 ms frames.
|
||||
time_to_insert_packet_ms_(3), // An arbitrary offset on pushing packet.
|
||||
@ -90,9 +93,9 @@ class InsertPacketWithTiming {
|
||||
next_receive_ts_ = ReceiveTimestamp();
|
||||
|
||||
CodecInst codec;
|
||||
ASSERT_EQ(0, AudioCodingModule::Codec(FLAGS_codec.c_str(), &codec,
|
||||
FLAGS_codec_sample_rate_hz,
|
||||
FLAGS_codec_channels));
|
||||
ASSERT_EQ(0, AudioCodingModule::Codec(FLAG_codec, &codec,
|
||||
FLAG_codec_sample_rate_hz,
|
||||
FLAG_codec_channels));
|
||||
ASSERT_EQ(0, receive_acm_->InitializeReceiver());
|
||||
ASSERT_EQ(0, send_acm_->RegisterSendCodec(codec));
|
||||
ASSERT_EQ(true, receive_acm_->RegisterReceiveCodec(codec.pltype,
|
||||
@ -105,27 +108,27 @@ class InsertPacketWithTiming {
|
||||
channel_->RegisterReceiverACM(receive_acm_.get());
|
||||
send_acm_->RegisterTransportCallback(channel_);
|
||||
|
||||
if (FLAGS_input.size() == 0) {
|
||||
if (strlen(FLAG_input) == 0) {
|
||||
std::string file_name = test::ResourcePath("audio_coding/testfile32kHz",
|
||||
"pcm");
|
||||
pcm_in_fid_.Open(file_name, 32000, "r", true); // auto-rewind
|
||||
std::cout << "Input file " << file_name << " 32 kHz mono." << std::endl;
|
||||
} else {
|
||||
pcm_in_fid_.Open(FLAGS_input, static_cast<uint16_t>(FLAGS_input_fs_hz),
|
||||
pcm_in_fid_.Open(FLAG_input, static_cast<uint16_t>(FLAG_input_fs_hz),
|
||||
"r", true); // auto-rewind
|
||||
std::cout << "Input file " << FLAGS_input << "at " << FLAGS_input_fs_hz
|
||||
<< " Hz in " << ((FLAGS_input_stereo) ? "stereo." : "mono.")
|
||||
std::cout << "Input file " << FLAG_input << "at " << FLAG_input_fs_hz
|
||||
<< " Hz in " << ((FLAG_input_stereo) ? "stereo." : "mono.")
|
||||
<< std::endl;
|
||||
pcm_in_fid_.ReadStereo(FLAGS_input_stereo);
|
||||
pcm_in_fid_.ReadStereo(FLAG_input_stereo);
|
||||
}
|
||||
|
||||
ASSERT_TRUE(pcm_out_fid_ != NULL);
|
||||
std::cout << "Output file " << FLAGS_output << " at " << FLAGS_output_fs_hz
|
||||
std::cout << "Output file " << FLAG_output << " at " << FLAG_output_fs_hz
|
||||
<< " Hz." << std::endl;
|
||||
|
||||
// Other setups
|
||||
if (FLAGS_loss_rate > 0)
|
||||
loss_threshold_ = RAND_MAX * FLAGS_loss_rate;
|
||||
if (FLAG_loss_rate > 0)
|
||||
loss_threshold_ = RAND_MAX * FLAG_loss_rate;
|
||||
else
|
||||
loss_threshold_ = 0;
|
||||
}
|
||||
@ -144,7 +147,7 @@ class InsertPacketWithTiming {
|
||||
if (time_to_playout_audio_ms_ == 0) {
|
||||
time_to_playout_audio_ms_ = kPlayoutPeriodMs;
|
||||
bool muted;
|
||||
receive_acm_->PlayoutData10Ms(static_cast<int>(FLAGS_output_fs_hz),
|
||||
receive_acm_->PlayoutData10Ms(static_cast<int>(FLAG_output_fs_hz),
|
||||
&frame_, &muted);
|
||||
ASSERT_FALSE(muted);
|
||||
fwrite(frame_.data(), sizeof(*frame_.data()),
|
||||
@ -180,7 +183,7 @@ class InsertPacketWithTiming {
|
||||
lost = true;
|
||||
}
|
||||
|
||||
if (FLAGS_verbose) {
|
||||
if (FLAG_verbose) {
|
||||
if (!lost) {
|
||||
std::cout << "\nInserting packet number " << seq_num
|
||||
<< " timestamp " << ts << std::endl;
|
||||
@ -279,13 +282,20 @@ class InsertPacketWithTiming {
|
||||
} // webrtc
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
google::ParseCommandLineFlags(&argc, &argv, true);
|
||||
if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true)) {
|
||||
return 1;
|
||||
}
|
||||
if (FLAG_help) {
|
||||
rtc::FlagList::Print(nullptr, false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
webrtc::InsertPacketWithTiming test;
|
||||
test.SetUp();
|
||||
|
||||
FILE* delay_log = NULL;
|
||||
if (FLAGS_delay.size() > 0) {
|
||||
delay_log = fopen(FLAGS_delay.c_str(), "wt");
|
||||
if (strlen(FLAG_delay) > 0) {
|
||||
delay_log = fopen(FLAG_delay, "wt");
|
||||
if (delay_log == NULL) {
|
||||
std::cout << "Cannot open the file to log delay values." << std::endl;
|
||||
exit(1);
|
||||
|
||||
Reference in New Issue
Block a user