Switch unpack_aecdump to ABSL_FLAG.
Bug: webrtc:10616
Change-Id: Ia6d0104d589b4b966ad6705493d88d3cb701c266
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/144600
Reviewed-by: Alessio Bazzica <alessiob@webrtc.org>
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#28486}
diff --git a/rtc_tools/BUILD.gn b/rtc_tools/BUILD.gn
index 5a7f03a..75b29f3 100644
--- a/rtc_tools/BUILD.gn
+++ b/rtc_tools/BUILD.gn
@@ -464,6 +464,8 @@
"../modules/audio_processing:audioproc_test_utils",
"../rtc_base:protobuf_utils",
"../rtc_base:rtc_base_approved",
+ "//third_party/abseil-cpp/absl/flags:flag",
+ "//third_party/abseil-cpp/absl/flags:parse",
]
} # unpack_aecdump
}
diff --git a/rtc_tools/unpack_aecdump/unpack.cc b/rtc_tools/unpack_aecdump/unpack.cc
index 88593fb..e833f32 100644
--- a/rtc_tools/unpack_aecdump/unpack.cc
+++ b/rtc_tools/unpack_aecdump/unpack.cc
@@ -21,6 +21,8 @@
#include <string>
#include <vector>
+#include "absl/flags/flag.h"
+#include "absl/flags/parse.h"
#include "api/function_view.h"
#include "common_audio/wav_file.h"
#include "modules/audio_processing/test/protobuf_utils.h"
@@ -32,38 +34,53 @@
RTC_PUSH_IGNORING_WUNDEF()
#include "modules/audio_processing/debug.pb.h"
-
RTC_POP_IGNORING_WUNDEF()
-// TODO(andrew): unpack more of the data.
-WEBRTC_DEFINE_string(input_file, "input", "The name of the input stream file.");
-WEBRTC_DEFINE_string(output_file,
- "ref_out",
- "The name of the reference output stream file.");
-WEBRTC_DEFINE_string(reverse_file,
- "reverse",
- "The name of the reverse input stream file.");
-WEBRTC_DEFINE_string(delay_file, "delay.int32", "The name of the delay file.");
-WEBRTC_DEFINE_string(drift_file, "drift.int32", "The name of the drift file.");
-WEBRTC_DEFINE_string(level_file, "level.int32", "The name of the level file.");
-WEBRTC_DEFINE_string(keypress_file,
- "keypress.bool",
- "The name of the keypress file.");
-WEBRTC_DEFINE_string(callorder_file,
- "callorder",
- "The name of the render/capture call order file.");
-WEBRTC_DEFINE_string(settings_file,
- "settings.txt",
- "The name of the settings file.");
-WEBRTC_DEFINE_bool(full,
- false,
- "Unpack the full set of files (normally not needed).");
-WEBRTC_DEFINE_bool(raw, false, "Write raw data instead of a WAV file.");
-WEBRTC_DEFINE_bool(
- text,
- false,
- "Write non-audio files as text files instead of binary files.");
-WEBRTC_DEFINE_bool(help, false, "Print this message.");
+ABSL_FLAG(std::string,
+ input_file,
+ "input",
+ "The name of the input stream file.");
+ABSL_FLAG(std::string,
+ output_file,
+ "ref_out",
+ "The name of the reference output stream file.");
+ABSL_FLAG(std::string,
+ reverse_file,
+ "reverse",
+ "The name of the reverse input stream file.");
+ABSL_FLAG(std::string,
+ delay_file,
+ "delay.int32",
+ "The name of the delay file.");
+ABSL_FLAG(std::string,
+ drift_file,
+ "drift.int32",
+ "The name of the drift file.");
+ABSL_FLAG(std::string,
+ level_file,
+ "level.int32",
+ "The name of the level file.");
+ABSL_FLAG(std::string,
+ keypress_file,
+ "keypress.bool",
+ "The name of the keypress file.");
+ABSL_FLAG(std::string,
+ callorder_file,
+ "callorder",
+ "The name of the render/capture call order file.");
+ABSL_FLAG(std::string,
+ settings_file,
+ "settings.txt",
+ "The name of the settings file.");
+ABSL_FLAG(bool,
+ full,
+ false,
+ "Unpack the full set of files (normally not needed).");
+ABSL_FLAG(bool, raw, false, "Write raw data instead of a WAV file.");
+ABSL_FLAG(bool,
+ text,
+ false,
+ "Write non-audio files as text files instead of binary files.");
#define PRINT_CONFIG(field_name) \
if (msg.has_##field_name()) { \
@@ -102,11 +119,11 @@
}
bool WritingCallOrderFile() {
- return FLAG_full;
+ return absl::GetFlag(FLAGS_full);
}
bool WritingRuntimeSettingFiles() {
- return FLAG_full;
+ return absl::GetFlag(FLAGS_full);
}
// Exports RuntimeSetting AEC dump events to Audacity-readable files.
@@ -210,23 +227,19 @@
} // namespace
int do_main(int argc, char* argv[]) {
- std::string program_name = argv[0];
+ std::vector<char*> args = absl::ParseCommandLine(argc, argv);
+ std::string program_name = args[0];
std::string usage =
"Commandline tool to unpack audioproc debug files.\n"
"Example usage:\n" +
program_name + " debug_dump.pb\n";
- if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true) || FLAG_help ||
- argc < 2) {
+ if (args.size() < 2) {
printf("%s", usage.c_str());
- if (FLAG_help) {
- rtc::FlagList::Print(nullptr, false);
- return 0;
- }
return 1;
}
- FILE* debug_file = OpenFile(argv[1], "rb");
+ FILE* debug_file = OpenFile(args[1], "rb");
Event event_msg;
int frame_count = 0;
@@ -244,11 +257,11 @@
std::unique_ptr<RawFile> output_raw_file;
rtc::StringBuilder callorder_raw_name;
- callorder_raw_name << FLAG_callorder_file << ".char";
+ callorder_raw_name << absl::GetFlag(FLAGS_callorder_file) << ".char";
FILE* callorder_char_file = WritingCallOrderFile()
? OpenFile(callorder_raw_name.str(), "wb")
: nullptr;
- FILE* settings_file = OpenFile(FLAG_settings_file, "wb");
+ FILE* settings_file = OpenFile(absl::GetFlag(FLAGS_settings_file), "wb");
std::vector<RuntimeSettingWriter> runtime_setting_writers =
RuntimeSettingWriters();
@@ -262,9 +275,9 @@
const ReverseStream msg = event_msg.reverse_stream();
if (msg.has_data()) {
- if (FLAG_raw && !reverse_raw_file) {
+ if (absl::GetFlag(FLAGS_raw) && !reverse_raw_file) {
reverse_raw_file.reset(
- new RawFile(std::string(FLAG_reverse_file) + ".pcm"));
+ new RawFile(absl::GetFlag(FLAGS_reverse_file) + ".pcm"));
}
// TODO(aluebs): Replace "num_reverse_channels *
// reverse_samples_per_channel" with "msg.data().size() /
@@ -274,9 +287,9 @@
num_reverse_channels * reverse_samples_per_channel,
reverse_wav_file.get(), reverse_raw_file.get());
} else if (msg.channel_size() > 0) {
- if (FLAG_raw && !reverse_raw_file) {
+ if (absl::GetFlag(FLAGS_raw) && !reverse_raw_file) {
reverse_raw_file.reset(
- new RawFile(std::string(FLAG_reverse_file) + ".float"));
+ new RawFile(absl::GetFlag(FLAGS_reverse_file) + ".float"));
}
std::unique_ptr<const float* []> data(
new const float*[num_reverse_channels]);
@@ -287,10 +300,10 @@
num_reverse_channels, reverse_wav_file.get(),
reverse_raw_file.get());
}
- if (FLAG_full) {
+ if (absl::GetFlag(FLAGS_full)) {
if (WritingCallOrderFile()) {
WriteCallOrderData(true /* render_call */, callorder_char_file,
- FLAG_callorder_file);
+ absl::GetFlag(FLAGS_callorder_file));
}
}
} else if (event_msg.type() == Event::STREAM) {
@@ -302,17 +315,17 @@
const Stream msg = event_msg.stream();
if (msg.has_input_data()) {
- if (FLAG_raw && !input_raw_file) {
+ if (absl::GetFlag(FLAGS_raw) && !input_raw_file) {
input_raw_file.reset(
- new RawFile(std::string(FLAG_input_file) + ".pcm"));
+ new RawFile(absl::GetFlag(FLAGS_input_file) + ".pcm"));
}
WriteIntData(reinterpret_cast<const int16_t*>(msg.input_data().data()),
num_input_channels * input_samples_per_channel,
input_wav_file.get(), input_raw_file.get());
} else if (msg.input_channel_size() > 0) {
- if (FLAG_raw && !input_raw_file) {
+ if (absl::GetFlag(FLAGS_raw) && !input_raw_file) {
input_raw_file.reset(
- new RawFile(std::string(FLAG_input_file) + ".float"));
+ new RawFile(absl::GetFlag(FLAGS_input_file) + ".float"));
}
std::unique_ptr<const float* []> data(
new const float*[num_input_channels]);
@@ -325,17 +338,17 @@
}
if (msg.has_output_data()) {
- if (FLAG_raw && !output_raw_file) {
+ if (absl::GetFlag(FLAGS_raw) && !output_raw_file) {
output_raw_file.reset(
- new RawFile(std::string(FLAG_output_file) + ".pcm"));
+ new RawFile(absl::GetFlag(FLAGS_output_file) + ".pcm"));
}
WriteIntData(reinterpret_cast<const int16_t*>(msg.output_data().data()),
num_output_channels * output_samples_per_channel,
output_wav_file.get(), output_raw_file.get());
} else if (msg.output_channel_size() > 0) {
- if (FLAG_raw && !output_raw_file) {
+ if (absl::GetFlag(FLAGS_raw) && !output_raw_file) {
output_raw_file.reset(
- new RawFile(std::string(FLAG_output_file) + ".float"));
+ new RawFile(absl::GetFlag(FLAGS_output_file) + ".float"));
}
std::unique_ptr<const float* []> data(
new const float*[num_output_channels]);
@@ -348,49 +361,56 @@
output_raw_file.get());
}
- if (FLAG_full) {
+ if (absl::GetFlag(FLAGS_full)) {
if (WritingCallOrderFile()) {
WriteCallOrderData(false /* render_call */, callorder_char_file,
- FLAG_callorder_file);
+ absl::GetFlag(FLAGS_callorder_file));
}
if (msg.has_delay()) {
- static FILE* delay_file = OpenFile(FLAG_delay_file, "wb");
+ static FILE* delay_file =
+ OpenFile(absl::GetFlag(FLAGS_delay_file), "wb");
int32_t delay = msg.delay();
- if (FLAG_text) {
+ if (absl::GetFlag(FLAGS_text)) {
fprintf(delay_file, "%d\n", delay);
} else {
- WriteData(&delay, sizeof(delay), delay_file, FLAG_delay_file);
+ WriteData(&delay, sizeof(delay), delay_file,
+ absl::GetFlag(FLAGS_delay_file));
}
}
if (msg.has_drift()) {
- static FILE* drift_file = OpenFile(FLAG_drift_file, "wb");
+ static FILE* drift_file =
+ OpenFile(absl::GetFlag(FLAGS_drift_file), "wb");
int32_t drift = msg.drift();
- if (FLAG_text) {
+ if (absl::GetFlag(FLAGS_text)) {
fprintf(drift_file, "%d\n", drift);
} else {
- WriteData(&drift, sizeof(drift), drift_file, FLAG_drift_file);
+ WriteData(&drift, sizeof(drift), drift_file,
+ absl::GetFlag(FLAGS_drift_file));
}
}
if (msg.has_level()) {
- static FILE* level_file = OpenFile(FLAG_level_file, "wb");
+ static FILE* level_file =
+ OpenFile(absl::GetFlag(FLAGS_level_file), "wb");
int32_t level = msg.level();
- if (FLAG_text) {
+ if (absl::GetFlag(FLAGS_text)) {
fprintf(level_file, "%d\n", level);
} else {
- WriteData(&level, sizeof(level), level_file, FLAG_level_file);
+ WriteData(&level, sizeof(level), level_file,
+ absl::GetFlag(FLAGS_level_file));
}
}
if (msg.has_keypress()) {
- static FILE* keypress_file = OpenFile(FLAG_keypress_file, "wb");
+ static FILE* keypress_file =
+ OpenFile(absl::GetFlag(FLAGS_keypress_file), "wb");
bool keypress = msg.keypress();
- if (FLAG_text) {
+ if (absl::GetFlag(FLAGS_text)) {
fprintf(keypress_file, "%d\n", keypress);
} else {
WriteData(&keypress, sizeof(keypress), keypress_file,
- FLAG_keypress_file);
+ absl::GetFlag(FLAGS_keypress_file));
}
}
}
@@ -472,25 +492,28 @@
output_samples_per_channel =
static_cast<size_t>(output_sample_rate / 100);
- if (!FLAG_raw) {
+ if (!absl::GetFlag(FLAGS_raw)) {
// The WAV files need to be reset every time, because they cant change
// their sample rate or number of channels.
rtc::StringBuilder reverse_name;
- reverse_name << FLAG_reverse_file << frame_count << ".wav";
+ reverse_name << absl::GetFlag(FLAGS_reverse_file) << frame_count
+ << ".wav";
reverse_wav_file.reset(new WavWriter(
reverse_name.str(), reverse_sample_rate, num_reverse_channels));
rtc::StringBuilder input_name;
- input_name << FLAG_input_file << frame_count << ".wav";
+ input_name << absl::GetFlag(FLAGS_input_file) << frame_count << ".wav";
input_wav_file.reset(new WavWriter(input_name.str(), input_sample_rate,
num_input_channels));
rtc::StringBuilder output_name;
- output_name << FLAG_output_file << frame_count << ".wav";
+ output_name << absl::GetFlag(FLAGS_output_file) << frame_count
+ << ".wav";
output_wav_file.reset(new WavWriter(
output_name.str(), output_sample_rate, num_output_channels));
if (WritingCallOrderFile()) {
rtc::StringBuilder callorder_name;
- callorder_name << FLAG_callorder_file << frame_count << ".char";
+ callorder_name << absl::GetFlag(FLAGS_callorder_file) << frame_count
+ << ".char";
callorder_char_file = OpenFile(callorder_name.str(), "wb");
}