Switch neteq tools to ABSL_FLAG.
Bug: webrtc:10616
Change-Id: I2aa688f0976d5618347e402f25d8701b0cf5a360
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/144027
Reviewed-by: Ivo Creusen <ivoc@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#28442}
diff --git a/modules/audio_coding/neteq/tools/rtp_encode.cc b/modules/audio_coding/neteq/tools/rtp_encode.cc
index a75802b..0379d21 100644
--- a/modules/audio_coding/neteq/tools/rtp_encode.cc
+++ b/modules/audio_coding/neteq/tools/rtp_encode.cc
@@ -20,7 +20,10 @@
#include <iostream>
#include <map>
#include <string>
+#include <vector>
+#include "absl/flags/flag.h"
+#include "absl/flags/parse.h"
#include "absl/memory/memory.h"
#include "api/audio/audio_frame.h"
#include "api/audio_codecs/L16/audio_encoder_L16.h"
@@ -35,30 +38,29 @@
#include "rtc_base/flags.h"
#include "rtc_base/numerics/safe_conversions.h"
+ABSL_FLAG(bool, list_codecs, false, "Enumerate all codecs");
+ABSL_FLAG(std::string, codec, "opus", "Codec to use");
+ABSL_FLAG(int,
+ frame_len,
+ 0,
+ "Frame length in ms; 0 indicates codec default value");
+ABSL_FLAG(int, bitrate, 0, "Bitrate in kbps; 0 indicates codec default value");
+ABSL_FLAG(int,
+ payload_type,
+ -1,
+ "RTP payload type; -1 indicates codec default value");
+ABSL_FLAG(int,
+ cng_payload_type,
+ -1,
+ "RTP payload type for CNG; -1 indicates default value");
+ABSL_FLAG(int, ssrc, 0, "SSRC to write to the RTP header");
+ABSL_FLAG(bool, dtx, false, "Use DTX/CNG");
+ABSL_FLAG(int, sample_rate, 48000, "Sample rate of the input file");
+
namespace webrtc {
namespace test {
namespace {
-// Define command line flags.
-WEBRTC_DEFINE_bool(list_codecs, false, "Enumerate all codecs");
-WEBRTC_DEFINE_string(codec, "opus", "Codec to use");
-WEBRTC_DEFINE_int(frame_len,
- 0,
- "Frame length in ms; 0 indicates codec default value");
-WEBRTC_DEFINE_int(bitrate,
- 0,
- "Bitrate in kbps; 0 indicates codec default value");
-WEBRTC_DEFINE_int(payload_type,
- -1,
- "RTP payload type; -1 indicates codec default value");
-WEBRTC_DEFINE_int(cng_payload_type,
- -1,
- "RTP payload type for CNG; -1 indicates default value");
-WEBRTC_DEFINE_int(ssrc, 0, "SSRC to write to the RTP header");
-WEBRTC_DEFINE_bool(dtx, false, "Use DTX/CNG");
-WEBRTC_DEFINE_int(sample_rate, 48000, "Sample rate of the input file");
-WEBRTC_DEFINE_bool(help, false, "Print this message");
-
// Add new codecs here, and to the map below.
enum class CodecType {
kOpus,
@@ -160,8 +162,8 @@
};
void SetFrameLenIfFlagIsPositive(int* config_frame_len) {
- if (FLAG_frame_len > 0) {
- *config_frame_len = FLAG_frame_len;
+ if (absl::GetFlag(FLAGS_frame_len) > 0) {
+ *config_frame_len = absl::GetFlag(FLAGS_frame_len);
}
}
@@ -199,10 +201,10 @@
switch (codec_type) {
case CodecType::kOpus: {
AudioEncoderOpus::Config config = GetCodecConfig<AudioEncoderOpus>();
- if (FLAG_bitrate > 0) {
- config.bitrate_bps = FLAG_bitrate;
+ if (absl::GetFlag(FLAGS_bitrate) > 0) {
+ config.bitrate_bps = absl::GetFlag(FLAGS_bitrate);
}
- config.dtx_enabled = FLAG_dtx;
+ config.dtx_enabled = absl::GetFlag(FLAGS_dtx);
RTC_CHECK(config.IsOk());
return AudioEncoderOpus::MakeAudioEncoder(config, payload_type);
}
@@ -261,33 +263,25 @@
}
return 0;
};
- cng_config.payload_type = FLAG_cng_payload_type != -1
- ? FLAG_cng_payload_type
+ cng_config.payload_type = absl::GetFlag(FLAGS_cng_payload_type) != -1
+ ? absl::GetFlag(FLAGS_cng_payload_type)
: default_payload_type();
return cng_config;
}
int RunRtpEncode(int argc, char* argv[]) {
- const std::string program_name = argv[0];
+ std::vector<char*> args = absl::ParseCommandLine(argc, argv);
const std::string usage =
"Tool for generating an RTP dump file from audio input.\n"
- "Run " +
- program_name +
- " --help for usage.\n"
- "Example usage:\n" +
- program_name + " input.pcm output.rtp --codec=[codec] " +
+ "Example usage:\n"
+ "./rtp_encode input.pcm output.rtp --codec=[codec] "
"--frame_len=[frame_len] --bitrate=[bitrate]\n\n";
- if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true) || FLAG_help ||
- (!FLAG_list_codecs && argc != 3)) {
+ if (!absl::GetFlag(FLAGS_list_codecs) && args.size() != 3) {
printf("%s", usage.c_str());
- if (FLAG_help) {
- rtc::FlagList::Print(nullptr, false);
- return 0;
- }
return 1;
}
- if (FLAG_list_codecs) {
+ if (absl::GetFlag(FLAGS_list_codecs)) {
printf("The following arguments are valid --codec parameters:\n");
for (const auto& c : CodecList()) {
printf(" %s\n", c.first.c_str());
@@ -295,22 +289,23 @@
return 0;
}
- const auto codec_it = CodecList().find(FLAG_codec);
+ const auto codec_it = CodecList().find(absl::GetFlag(FLAGS_codec));
if (codec_it == CodecList().end()) {
- printf("%s is not a valid codec name.\n", FLAG_codec);
+ printf("%s is not a valid codec name.\n",
+ absl::GetFlag(FLAGS_codec).c_str());
printf("Use argument --list_codecs to see all valid codec names.\n");
return 1;
}
// Create the codec.
- const int payload_type = FLAG_payload_type == -1
+ const int payload_type = absl::GetFlag(FLAGS_payload_type) == -1
? codec_it->second.default_payload_type
- : FLAG_payload_type;
+ : absl::GetFlag(FLAGS_payload_type);
std::unique_ptr<AudioEncoder> codec =
CreateEncoder(codec_it->second.type, payload_type);
// Create an external VAD/CNG encoder if needed.
- if (FLAG_dtx && !codec_it->second.internal_dtx) {
+ if (absl::GetFlag(FLAGS_dtx) && !codec_it->second.internal_dtx) {
AudioEncoderCngConfig cng_config = GetCngConfig(codec->SampleRateHz());
RTC_DCHECK(codec);
cng_config.speech_encoder = std::move(codec);
@@ -325,11 +320,11 @@
acm->SetEncoder(std::move(codec));
// Open files.
- printf("Input file: %s\n", argv[1]);
- InputAudioFile input_file(argv[1], false); // Open input in non-looping mode.
- FILE* out_file = fopen(argv[2], "wb");
- RTC_CHECK(out_file) << "Could not open file " << argv[2] << " for writing";
- printf("Output file: %s\n", argv[2]);
+ printf("Input file: %s\n", args[1]);
+ InputAudioFile input_file(args[1], false); // Open input in non-looping mode.
+ FILE* out_file = fopen(args[2], "wb");
+ RTC_CHECK(out_file) << "Could not open file " << args[2] << " for writing";
+ printf("Output file: %s\n", args[2]);
fprintf(out_file, "#!rtpplay1.0 \n"); //,
// Write 3 32-bit values followed by 2 16-bit values, all set to 0. This means
// a total of 16 bytes.
@@ -337,12 +332,13 @@
RTC_CHECK_EQ(fwrite(file_header, sizeof(file_header), 1, out_file), 1);
// Create and register the packetizer, which will write the packets to file.
- Packetizer packetizer(out_file, FLAG_ssrc, timestamp_rate_hz);
+ Packetizer packetizer(out_file, absl::GetFlag(FLAGS_ssrc), timestamp_rate_hz);
RTC_DCHECK_EQ(acm->RegisterTransportCallback(&packetizer), 0);
AudioFrame audio_frame;
- audio_frame.samples_per_channel_ = FLAG_sample_rate / 100; // 10 ms
- audio_frame.sample_rate_hz_ = FLAG_sample_rate;
+ audio_frame.samples_per_channel_ =
+ absl::GetFlag(FLAGS_sample_rate) / 100; // 10 ms
+ audio_frame.sample_rate_hz_ = absl::GetFlag(FLAGS_sample_rate);
audio_frame.num_channels_ = 1;
while (input_file.Read(audio_frame.samples_per_channel_,