From 6e09d875fb28e49029fac798382e2c8df4a1f752 Mon Sep 17 00:00:00 2001 From: oprypin Date: Thu, 31 Aug 2017 03:21:39 -0700 Subject: [PATCH] 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} --- webrtc/logging/BUILD.gn | 3 - .../rtc_event_log/rtc_event_log2rtp_dump.cc | 46 +-- .../rtc_event_log/rtc_event_log2stats.cc | 20 +- .../rtc_event_log/rtc_event_log2text.cc | 49 +-- webrtc/modules/audio_coding/BUILD.gn | 7 +- .../neteq/test/neteq_speed_test.cc | 59 +--- .../audio_coding/neteq/tools/neteq_rtpplay.cc | 286 ++++++++------- .../audio_coding/neteq/tools/rtp_analyze.cc | 68 ++-- .../modules/audio_coding/test/delay_test.cc | 55 +-- .../test/insert_packet_with_timing.cc | 62 ++-- webrtc/modules/audio_processing/BUILD.gn | 7 +- .../beamformer/nonlinear_beamformer_test.cc | 26 +- .../test/intelligibility_proc.cc | 32 +- .../audio_processing/test/audioproc_float.cc | 328 +++++++++--------- .../test/conversational_speech/BUILD.gn | 1 - .../test/conversational_speech/generator.cc | 33 +- .../apm_quality_assessment_gencfgs.py | 2 +- .../modules/audio_processing/test/unpack.cc | 80 +++-- .../transient/transient_suppression_test.cc | 87 ++--- .../modules/remote_bitrate_estimator/BUILD.gn | 1 - .../remote_bitrate_estimator/tools/bwe_rtp.cc | 22 +- webrtc/modules/video_coding/BUILD.gn | 1 - .../codecs/tools/video_quality_measurement.cc | 205 +++++------ webrtc/video/BUILD.gn | 1 - webrtc/video/replay.cc | 150 ++++---- webrtc/voice_engine/BUILD.gn | 1 - .../test/auto_test/standard/rtp_rtcp_test.cc | 5 +- .../test/auto_test/voe_standard_test.cc | 12 +- .../test/auto_test/voe_standard_test.h | 3 - 29 files changed, 849 insertions(+), 803 deletions(-) diff --git a/webrtc/logging/BUILD.gn b/webrtc/logging/BUILD.gn index b8d17573c1..8f1e493209 100644 --- a/webrtc/logging/BUILD.gn +++ b/webrtc/logging/BUILD.gn @@ -142,7 +142,6 @@ if (rtc_enable_protobuf) { "../system_wrappers:field_trial_default", "../system_wrappers:metrics_default", "../test:rtp_test_utils", - "//third_party/gflags", ] if (!build_with_chromium && is_clang) { # Suppress warnings from the Chromium Clang plugin (bugs.webrtc.org/163). @@ -165,7 +164,6 @@ if (rtc_enable_protobuf) { # TODO(kwiberg): Remove this dependency. "../api/audio_codecs:audio_codecs_api", "../modules/rtp_rtcp:rtp_rtcp", - "//third_party/gflags", ] if (!build_with_chromium && is_clang) { # Suppress warnings from the Chromium Clang plugin (bugs.webrtc.org/163). @@ -184,7 +182,6 @@ if (rtc_enable_protobuf) { ":rtc_event_log_impl", ":rtc_event_log_proto", "../rtc_base:rtc_base_approved", - "//third_party/gflags", ] if (!build_with_chromium && is_clang) { # Suppress warnings from the Chromium Clang plugin (bugs.webrtc.org/163). diff --git a/webrtc/logging/rtc_event_log/rtc_event_log2rtp_dump.cc b/webrtc/logging/rtc_event_log/rtc_event_log2rtp_dump.cc index 23d69416e7..4275e5933f 100644 --- a/webrtc/logging/rtc_event_log/rtc_event_log2rtp_dump.cc +++ b/webrtc/logging/rtc_event_log/rtc_event_log2rtp_dump.cc @@ -8,17 +8,19 @@ * be found in the AUTHORS file in the root of the source tree. */ +#include + #include #include #include #include -#include "gflags/gflags.h" #include "webrtc/logging/rtc_event_log/rtc_event_log.h" #include "webrtc/logging/rtc_event_log/rtc_event_log_parser.h" #include "webrtc/modules/rtp_rtcp/source/byte_io.h" #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" #include "webrtc/rtc_base/checks.h" +#include "webrtc/rtc_base/flags.h" #include "webrtc/test/rtp_file_writer.h" namespace { @@ -44,6 +46,7 @@ DEFINE_string(ssrc, "", "Store only packets with this SSRC (decimal or hex, the latter " "starting with 0x)."); +DEFINE_bool(help, false, "Prints this message."); // Parses the input string for a valid SSRC. If a valid SSRC is found, it is // written to the output variable |ssrc|, and true is returned. Otherwise, @@ -73,22 +76,25 @@ int main(int argc, char* argv[]) { "Tool for converting an RtcEventLog file to an RTP dump file.\n" "Run " + program_name + - " --helpshort for usage.\n" + " --help for usage.\n" "Example usage:\n" + program_name + " input.rel output.rtp\n"; - google::SetUsageMessage(usage); - google::ParseCommandLineFlags(&argc, &argv, true); - - if (argc != 3) { - std::cout << google::ProgramUsage(); - return 0; + if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true) || + FLAG_help || argc != 3) { + std::cout << usage; + if (FLAG_help) { + rtc::FlagList::Print(nullptr, false); + return 0; + } + return 1; } + std::string input_file = argv[1]; std::string output_file = argv[2]; uint32_t ssrc_filter = 0; - if (!FLAGS_ssrc.empty()) - RTC_CHECK(ParseSsrc(FLAGS_ssrc, &ssrc_filter)) + if (strlen(FLAG_ssrc) > 0) + RTC_CHECK(ParseSsrc(FLAG_ssrc, &ssrc_filter)) << "Flag verification has failed."; webrtc::ParsedRtcEventLog parsed_stream; @@ -116,7 +122,7 @@ int main(int argc, char* argv[]) { // some required fields and we attempt to access them. We could consider // a softer failure option, but it does not seem useful to generate // RTP dumps based on broken event logs. - if (!FLAGS_nortp && + if (!FLAG_nortp && parsed_stream.GetEventType(i) == webrtc::ParsedRtcEventLog::RTP_EVENT) { webrtc::test::RtpPacket packet; webrtc::PacketDirection direction; @@ -137,13 +143,13 @@ int main(int argc, char* argv[]) { rtp_parser.Parse(&parsed_header); MediaType media_type = parsed_stream.GetMediaType(parsed_header.ssrc, direction); - if (FLAGS_noaudio && media_type == MediaType::AUDIO) + if (FLAG_noaudio && media_type == MediaType::AUDIO) continue; - if (FLAGS_novideo && media_type == MediaType::VIDEO) + if (FLAG_novideo && media_type == MediaType::VIDEO) continue; - if (FLAGS_nodata && media_type == MediaType::DATA) + if (FLAG_nodata && media_type == MediaType::DATA) continue; - if (!FLAGS_ssrc.empty()) { + if (strlen(FLAG_ssrc) > 0) { const uint32_t packet_ssrc = webrtc::ByteReader::ReadBigEndian( reinterpret_cast(packet.data + 8)); @@ -154,7 +160,7 @@ int main(int argc, char* argv[]) { rtp_writer->WritePacket(&packet); rtp_counter++; } - if (!FLAGS_nortcp && + if (!FLAG_nortcp && parsed_stream.GetEventType(i) == webrtc::ParsedRtcEventLog::RTCP_EVENT) { webrtc::test::RtpPacket packet; @@ -175,13 +181,13 @@ int main(int argc, char* argv[]) { const uint32_t packet_ssrc = webrtc::ByteReader::ReadBigEndian( reinterpret_cast(packet.data + 4)); MediaType media_type = parsed_stream.GetMediaType(packet_ssrc, direction); - if (FLAGS_noaudio && media_type == MediaType::AUDIO) + if (FLAG_noaudio && media_type == MediaType::AUDIO) continue; - if (FLAGS_novideo && media_type == MediaType::VIDEO) + if (FLAG_novideo && media_type == MediaType::VIDEO) continue; - if (FLAGS_nodata && media_type == MediaType::DATA) + if (FLAG_nodata && media_type == MediaType::DATA) continue; - if (!FLAGS_ssrc.empty()) { + if (strlen(FLAG_ssrc) > 0) { if (packet_ssrc != ssrc_filter) continue; } diff --git a/webrtc/logging/rtc_event_log/rtc_event_log2stats.cc b/webrtc/logging/rtc_event_log/rtc_event_log2stats.cc index 6b21cf1a7e..36fa1e34fb 100644 --- a/webrtc/logging/rtc_event_log/rtc_event_log2stats.cc +++ b/webrtc/logging/rtc_event_log/rtc_event_log2stats.cc @@ -19,9 +19,9 @@ #include #include -#include "gflags/gflags.h" #include "webrtc/logging/rtc_event_log/rtc_event_log.h" #include "webrtc/rtc_base/checks.h" +#include "webrtc/rtc_base/flags.h" #include "webrtc/rtc_base/ignore_wundef.h" #include "webrtc/rtc_base/logging.h" @@ -36,6 +36,8 @@ RTC_POP_IGNORING_WUNDEF() namespace { +DEFINE_bool(help, false, "Prints this message."); + struct Stats { int count = 0; size_t total_size = 0; @@ -176,15 +178,17 @@ int main(int argc, char* argv[]) { "Tool for file usage statistics from an RtcEventLog.\n" "Run " + program_name + - " --helpshort for usage.\n" + " --help for usage.\n" "Example usage:\n" + program_name + " input.rel\n"; - google::SetUsageMessage(usage); - google::ParseCommandLineFlags(&argc, &argv, true); - - if (argc != 2) { - std::cout << google::ProgramUsage(); - return 0; + if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true) || + FLAG_help || argc != 2) { + std::cout << usage; + if (FLAG_help) { + rtc::FlagList::Print(nullptr, false); + return 0; + } + return 1; } std::string file_name = argv[1]; diff --git a/webrtc/logging/rtc_event_log/rtc_event_log2text.cc b/webrtc/logging/rtc_event_log/rtc_event_log2text.cc index c7214e2bc8..3f0310853f 100644 --- a/webrtc/logging/rtc_event_log/rtc_event_log2text.cc +++ b/webrtc/logging/rtc_event_log/rtc_event_log2text.cc @@ -8,13 +8,14 @@ * be found in the AUTHORS file in the root of the source tree. */ +#include + #include #include #include #include #include // pair -#include "gflags/gflags.h" #include "webrtc/common_types.h" #include "webrtc/config.h" #include "webrtc/logging/rtc_event_log/rtc_event_log_parser.h" @@ -35,6 +36,7 @@ #include "webrtc/modules/rtp_rtcp/source/rtp_header_extensions.h" #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" #include "webrtc/rtc_base/checks.h" +#include "webrtc/rtc_base/flags.h" namespace { @@ -54,6 +56,7 @@ DEFINE_string(ssrc, "", "Print only packets with this SSRC (decimal or hex, the latter " "starting with 0x)."); +DEFINE_bool(help, false, "Prints this message."); using MediaType = webrtc::ParsedRtcEventLog::MediaType; @@ -81,17 +84,17 @@ bool ParseSsrc(std::string str) { bool ExcludePacket(webrtc::PacketDirection direction, MediaType media_type, uint32_t packet_ssrc) { - if (FLAGS_nooutgoing && direction == webrtc::kOutgoingPacket) + if (FLAG_nooutgoing && direction == webrtc::kOutgoingPacket) return true; - if (FLAGS_noincoming && direction == webrtc::kIncomingPacket) + if (FLAG_noincoming && direction == webrtc::kIncomingPacket) return true; - if (FLAGS_noaudio && media_type == MediaType::AUDIO) + if (FLAG_noaudio && media_type == MediaType::AUDIO) return true; - if (FLAGS_novideo && media_type == MediaType::VIDEO) + if (FLAG_novideo && media_type == MediaType::VIDEO) return true; - if (FLAGS_nodata && media_type == MediaType::DATA) + if (FLAG_nodata && media_type == MediaType::DATA) return true; - if (!FLAGS_ssrc.empty() && packet_ssrc != filtered_ssrc) + if (strlen(FLAG_ssrc) > 0 && packet_ssrc != filtered_ssrc) return true; return false; } @@ -357,20 +360,22 @@ int main(int argc, char* argv[]) { "Tool for printing packet information from an RtcEventLog as text.\n" "Run " + program_name + - " --helpshort for usage.\n" + " --help for usage.\n" "Example usage:\n" + program_name + " input.rel\n"; - google::SetUsageMessage(usage); - google::ParseCommandLineFlags(&argc, &argv, true); - - if (argc != 2) { - std::cout << google::ProgramUsage(); - return 0; + if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true) || + FLAG_help || argc != 2) { + std::cout << usage; + if (FLAG_help) { + rtc::FlagList::Print(nullptr, false); + return 0; + } + return 1; } std::string input_file = argv[1]; - if (!FLAGS_ssrc.empty()) - RTC_CHECK(ParseSsrc(FLAGS_ssrc)) << "Flag verification has failed."; + if (strlen(FLAG_ssrc) > 0) + RTC_CHECK(ParseSsrc(FLAG_ssrc)) << "Flag verification has failed."; webrtc::RtpHeaderExtensionMap default_map = GetDefaultHeaderExtensionMap(); @@ -381,7 +386,7 @@ int main(int argc, char* argv[]) { } for (size_t i = 0; i < parsed_stream.GetNumberOfEvents(); i++) { - if (!FLAGS_noconfig && !FLAGS_novideo && !FLAGS_noincoming && + if (!FLAG_noconfig && !FLAG_novideo && !FLAG_noincoming && parsed_stream.GetEventType(i) == webrtc::ParsedRtcEventLog::VIDEO_RECEIVER_CONFIG_EVENT) { webrtc::rtclog::StreamConfig config = @@ -402,7 +407,7 @@ int main(int argc, char* argv[]) { } std::cout << "}" << std::endl; } - if (!FLAGS_noconfig && !FLAGS_novideo && !FLAGS_nooutgoing && + if (!FLAG_noconfig && !FLAG_novideo && !FLAG_nooutgoing && parsed_stream.GetEventType(i) == webrtc::ParsedRtcEventLog::VIDEO_SENDER_CONFIG_EVENT) { std::vector configs = @@ -425,7 +430,7 @@ int main(int argc, char* argv[]) { std::cout << "}" << std::endl; } } - if (!FLAGS_noconfig && !FLAGS_noaudio && !FLAGS_noincoming && + if (!FLAG_noconfig && !FLAG_noaudio && !FLAG_noincoming && parsed_stream.GetEventType(i) == webrtc::ParsedRtcEventLog::AUDIO_RECEIVER_CONFIG_EVENT) { webrtc::rtclog::StreamConfig config = @@ -446,7 +451,7 @@ int main(int argc, char* argv[]) { } std::cout << "}" << std::endl; } - if (!FLAGS_noconfig && !FLAGS_noaudio && !FLAGS_nooutgoing && + if (!FLAG_noconfig && !FLAG_noaudio && !FLAG_nooutgoing && parsed_stream.GetEventType(i) == webrtc::ParsedRtcEventLog::AUDIO_SENDER_CONFIG_EVENT) { webrtc::rtclog::StreamConfig config = parsed_stream.GetAudioSendConfig(i); @@ -465,7 +470,7 @@ int main(int argc, char* argv[]) { } std::cout << "}" << std::endl; } - if (!FLAGS_nortp && + if (!FLAG_nortp && parsed_stream.GetEventType(i) == webrtc::ParsedRtcEventLog::RTP_EVENT) { size_t header_length; size_t total_length; @@ -516,7 +521,7 @@ int main(int argc, char* argv[]) { } std::cout << std::endl; } - if (!FLAGS_nortcp && + if (!FLAG_nortcp && parsed_stream.GetEventType(i) == webrtc::ParsedRtcEventLog::RTCP_EVENT) { size_t length; diff --git a/webrtc/modules/audio_coding/BUILD.gn b/webrtc/modules/audio_coding/BUILD.gn index abe064f3da..50819f19ca 100644 --- a/webrtc/modules/audio_coding/BUILD.gn +++ b/webrtc/modules/audio_coding/BUILD.gn @@ -1395,7 +1395,6 @@ if (rtc_include_tests) { "../../test:test_support", "../rtp_rtcp", "//testing/gtest", - "//third_party/gflags:gflags", ] } # delay_test @@ -1425,7 +1424,6 @@ if (rtc_include_tests) { "../../test:test_support", "../rtp_rtcp", "//testing/gtest", - "//third_party/gflags:gflags", ] } # insert_packet_with_timing @@ -1520,7 +1518,6 @@ if (rtc_include_tests) { "../../rtc_base:rtc_base_approved", "../../system_wrappers:system_wrappers_default", "../../test:test_support", - "//third_party/gflags", ] } } @@ -1792,9 +1789,9 @@ if (rtc_include_tests) { ":neteq", ":neteq_test_tools", ":pcm16b", + "../../rtc_base:rtc_base_approved", "../../system_wrappers:system_wrappers_default", "//testing/gtest", - "//third_party/gflags:gflags", ] if (!build_with_chromium && is_clang) { @@ -1832,9 +1829,9 @@ if (rtc_include_tests) { ":neteq", ":neteq_test_support", "../..:webrtc_common", + "../../rtc_base:rtc_base_approved", "../../system_wrappers:system_wrappers_default", "../../test:test_support", - "//third_party/gflags", ] } diff --git a/webrtc/modules/audio_coding/neteq/test/neteq_speed_test.cc b/webrtc/modules/audio_coding/neteq/test/neteq_speed_test.cc index b835499b29..c58381f6ac 100644 --- a/webrtc/modules/audio_coding/neteq/test/neteq_speed_test.cc +++ b/webrtc/modules/audio_coding/neteq/test/neteq_speed_test.cc @@ -12,43 +12,18 @@ #include -#include "gflags/gflags.h" #include "webrtc/modules/audio_coding/neteq/tools/neteq_performance_test.h" +#include "webrtc/rtc_base/flags.h" #include "webrtc/test/testsupport/fileutils.h" #include "webrtc/typedefs.h" -// Flag validators. -static bool ValidateRuntime(const char* flagname, int value) { - if (value > 0) // Value is ok. - return true; - printf("Invalid value for --%s: %d\n", flagname, static_cast(value)); - return false; -} -static bool ValidateLossrate(const char* flagname, int value) { - if (value >= 0) // Value is ok. - return true; - printf("Invalid value for --%s: %d\n", flagname, static_cast(value)); - return false; -} -static bool ValidateDriftfactor(const char* flagname, double value) { - if (value >= 0.0 && value < 1.0) // Value is ok. - return true; - printf("Invalid value for --%s: %f\n", flagname, value); - return false; -} - // Define command line flags. -DEFINE_int32(runtime_ms, 10000, "Simulated runtime in ms."); -static const bool runtime_ms_dummy = - google::RegisterFlagValidator(&FLAGS_runtime_ms, &ValidateRuntime); -DEFINE_int32(lossrate, 10, - "Packet lossrate; drop every N packets."); -static const bool lossrate_dummy = - google::RegisterFlagValidator(&FLAGS_lossrate, &ValidateLossrate); -DEFINE_double(drift, 0.1, +DEFINE_int(runtime_ms, 10000, "Simulated runtime in ms."); +DEFINE_int(lossrate, 10, + "Packet lossrate; drop every N packets."); +DEFINE_float(drift, 0.1f, "Clockdrift factor."); -static const bool drift_dummy = - google::RegisterFlagValidator(&FLAGS_drift, &ValidateDriftfactor); +DEFINE_bool(help, false, "Print this message."); int main(int argc, char* argv[]) { std::string program_name = argv[0]; @@ -58,19 +33,23 @@ int main(int argc, char* argv[]) { " --lossrate=N drop every N packets; default is 10\n" " --drift=F clockdrift factor between 0.0 and 1.0; " "default is 0.1\n"; - google::SetUsageMessage(usage); - google::ParseCommandLineFlags(&argc, &argv, true); webrtc::test::SetExecutablePath(argv[0]); - - if (argc != 1) { - // Print usage information. - std::cout << google::ProgramUsage(); - return 0; + if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true) || + FLAG_help || argc != 1) { + printf("%s", usage.c_str()); + if (FLAG_help) { + rtc::FlagList::Print(nullptr, false); + return 0; + } + return 1; } + RTC_CHECK_GT(FLAG_runtime_ms, 0); + RTC_CHECK_GE(FLAG_lossrate, 0); + RTC_CHECK(FLAG_drift >= 0.0 && FLAG_drift < 1.0); int64_t result = - webrtc::test::NetEqPerformanceTest::Run(FLAGS_runtime_ms, FLAGS_lossrate, - FLAGS_drift); + webrtc::test::NetEqPerformanceTest::Run(FLAG_runtime_ms, FLAG_lossrate, + FLAG_drift); if (result <= 0) { std::cout << "There was an error" << std::endl; return -1; diff --git a/webrtc/modules/audio_coding/neteq/tools/neteq_rtpplay.cc b/webrtc/modules/audio_coding/neteq/tools/neteq_rtpplay.cc index c11394b22f..d6647e42bc 100644 --- a/webrtc/modules/audio_coding/neteq/tools/neteq_rtpplay.cc +++ b/webrtc/modules/audio_coding/neteq/tools/neteq_rtpplay.cc @@ -13,6 +13,7 @@ #include // For ULONG_MAX returned by strtoul. #include #include // For strtoul. +#include #include #include @@ -21,7 +22,6 @@ #include #include -#include "gflags/gflags.h" #include "webrtc/modules/audio_coding/neteq/include/neteq.h" #include "webrtc/modules/audio_coding/neteq/tools/fake_decode_from_file.h" #include "webrtc/modules/audio_coding/neteq/tools/input_audio_file.h" @@ -34,6 +34,7 @@ #include "webrtc/modules/audio_coding/neteq/tools/rtp_file_source.h" #include "webrtc/modules/include/module_common_types.h" #include "webrtc/rtc_base/checks.h" +#include "webrtc/rtc_base/flags.h" #include "webrtc/test/testsupport/fileutils.h" #include "webrtc/typedefs.h" @@ -65,86 +66,51 @@ bool ParseSsrc(const std::string& str, uint32_t* ssrc) { } // Flag validators. -bool ValidatePayloadType(const char* flagname, int32_t value) { +bool ValidatePayloadType(int value) { if (value >= 0 && value <= 127) // Value is ok. return true; - printf("Invalid value for --%s: %d\n", flagname, static_cast(value)); + printf("Payload type must be between 0 and 127, not %d\n", + static_cast(value)); return false; } -bool ValidateSsrcValue(const char* flagname, const std::string& str) { +bool ValidateSsrcValue(const std::string& str) { uint32_t dummy_ssrc; - return ParseSsrc(str, &dummy_ssrc); + if (ParseSsrc(str, &dummy_ssrc)) // Value is ok. + return true; + printf("Invalid SSRC: %s\n", str.c_str()); + return false; } -static bool ValidateExtensionId(const char* flagname, int32_t value) { +static bool ValidateExtensionId(int value) { if (value > 0 && value <= 255) // Value is ok. return true; - printf("Invalid value for --%s: %d\n", flagname, static_cast(value)); + printf("Extension ID must be between 1 and 255, not %d\n", + static_cast(value)); return false; } // Define command line flags. -DEFINE_int32(pcmu, 0, "RTP payload type for PCM-u"); -const bool pcmu_dummy = - google::RegisterFlagValidator(&FLAGS_pcmu, &ValidatePayloadType); -DEFINE_int32(pcma, 8, "RTP payload type for PCM-a"); -const bool pcma_dummy = - google::RegisterFlagValidator(&FLAGS_pcma, &ValidatePayloadType); -DEFINE_int32(ilbc, 102, "RTP payload type for iLBC"); -const bool ilbc_dummy = - google::RegisterFlagValidator(&FLAGS_ilbc, &ValidatePayloadType); -DEFINE_int32(isac, 103, "RTP payload type for iSAC"); -const bool isac_dummy = - google::RegisterFlagValidator(&FLAGS_isac, &ValidatePayloadType); -DEFINE_int32(isac_swb, 104, "RTP payload type for iSAC-swb (32 kHz)"); -const bool isac_swb_dummy = - google::RegisterFlagValidator(&FLAGS_isac_swb, &ValidatePayloadType); -DEFINE_int32(opus, 111, "RTP payload type for Opus"); -const bool opus_dummy = - google::RegisterFlagValidator(&FLAGS_opus, &ValidatePayloadType); -DEFINE_int32(pcm16b, 93, "RTP payload type for PCM16b-nb (8 kHz)"); -const bool pcm16b_dummy = - google::RegisterFlagValidator(&FLAGS_pcm16b, &ValidatePayloadType); -DEFINE_int32(pcm16b_wb, 94, "RTP payload type for PCM16b-wb (16 kHz)"); -const bool pcm16b_wb_dummy = - google::RegisterFlagValidator(&FLAGS_pcm16b_wb, &ValidatePayloadType); -DEFINE_int32(pcm16b_swb32, 95, "RTP payload type for PCM16b-swb32 (32 kHz)"); -const bool pcm16b_swb32_dummy = - google::RegisterFlagValidator(&FLAGS_pcm16b_swb32, &ValidatePayloadType); -DEFINE_int32(pcm16b_swb48, 96, "RTP payload type for PCM16b-swb48 (48 kHz)"); -const bool pcm16b_swb48_dummy = - google::RegisterFlagValidator(&FLAGS_pcm16b_swb48, &ValidatePayloadType); -DEFINE_int32(g722, 9, "RTP payload type for G.722"); -const bool g722_dummy = - google::RegisterFlagValidator(&FLAGS_g722, &ValidatePayloadType); -DEFINE_int32(avt, 106, "RTP payload type for AVT/DTMF (8 kHz)"); -const bool avt_dummy = - google::RegisterFlagValidator(&FLAGS_avt, &ValidatePayloadType); -DEFINE_int32(avt_16, 114, "RTP payload type for AVT/DTMF (16 kHz)"); -const bool avt_16_dummy = - google::RegisterFlagValidator(&FLAGS_avt_16, &ValidatePayloadType); -DEFINE_int32(avt_32, 115, "RTP payload type for AVT/DTMF (32 kHz)"); -const bool avt_32_dummy = - google::RegisterFlagValidator(&FLAGS_avt_32, &ValidatePayloadType); -DEFINE_int32(avt_48, 116, "RTP payload type for AVT/DTMF (48 kHz)"); -const bool avt_48_dummy = - google::RegisterFlagValidator(&FLAGS_avt_48, &ValidatePayloadType); -DEFINE_int32(red, 117, "RTP payload type for redundant audio (RED)"); -const bool red_dummy = - google::RegisterFlagValidator(&FLAGS_red, &ValidatePayloadType); -DEFINE_int32(cn_nb, 13, "RTP payload type for comfort noise (8 kHz)"); -const bool cn_nb_dummy = - google::RegisterFlagValidator(&FLAGS_cn_nb, &ValidatePayloadType); -DEFINE_int32(cn_wb, 98, "RTP payload type for comfort noise (16 kHz)"); -const bool cn_wb_dummy = - google::RegisterFlagValidator(&FLAGS_cn_wb, &ValidatePayloadType); -DEFINE_int32(cn_swb32, 99, "RTP payload type for comfort noise (32 kHz)"); -const bool cn_swb32_dummy = - google::RegisterFlagValidator(&FLAGS_cn_swb32, &ValidatePayloadType); -DEFINE_int32(cn_swb48, 100, "RTP payload type for comfort noise (48 kHz)"); -const bool cn_swb48_dummy = - google::RegisterFlagValidator(&FLAGS_cn_swb48, &ValidatePayloadType); +DEFINE_int(pcmu, 0, "RTP payload type for PCM-u"); +DEFINE_int(pcma, 8, "RTP payload type for PCM-a"); +DEFINE_int(ilbc, 102, "RTP payload type for iLBC"); +DEFINE_int(isac, 103, "RTP payload type for iSAC"); +DEFINE_int(isac_swb, 104, "RTP payload type for iSAC-swb (32 kHz)"); +DEFINE_int(opus, 111, "RTP payload type for Opus"); +DEFINE_int(pcm16b, 93, "RTP payload type for PCM16b-nb (8 kHz)"); +DEFINE_int(pcm16b_wb, 94, "RTP payload type for PCM16b-wb (16 kHz)"); +DEFINE_int(pcm16b_swb32, 95, "RTP payload type for PCM16b-swb32 (32 kHz)"); +DEFINE_int(pcm16b_swb48, 96, "RTP payload type for PCM16b-swb48 (48 kHz)"); +DEFINE_int(g722, 9, "RTP payload type for G.722"); +DEFINE_int(avt, 106, "RTP payload type for AVT/DTMF (8 kHz)"); +DEFINE_int(avt_16, 114, "RTP payload type for AVT/DTMF (16 kHz)"); +DEFINE_int(avt_32, 115, "RTP payload type for AVT/DTMF (32 kHz)"); +DEFINE_int(avt_48, 116, "RTP payload type for AVT/DTMF (48 kHz)"); +DEFINE_int(red, 117, "RTP payload type for redundant audio (RED)"); +DEFINE_int(cn_nb, 13, "RTP payload type for comfort noise (8 kHz)"); +DEFINE_int(cn_wb, 98, "RTP payload type for comfort noise (16 kHz)"); +DEFINE_int(cn_swb32, 99, "RTP payload type for comfort noise (32 kHz)"); +DEFINE_int(cn_swb48, 100, "RTP payload type for comfort noise (48 kHz)"); DEFINE_bool(codec_map, false, "Prints the mapping between RTP payload type and " "codec"); DEFINE_string(replacement_audio_file, "", @@ -153,21 +119,13 @@ DEFINE_string(ssrc, "", "Only use packets with this SSRC (decimal or hex, the latter " "starting with 0x)"); -const bool hex_ssrc_dummy = - google::RegisterFlagValidator(&FLAGS_ssrc, &ValidateSsrcValue); -DEFINE_int32(audio_level, 1, "Extension ID for audio level (RFC 6464)"); -const bool audio_level_dummy = - google::RegisterFlagValidator(&FLAGS_audio_level, &ValidateExtensionId); -DEFINE_int32(abs_send_time, 3, "Extension ID for absolute sender time"); -const bool abs_send_time_dummy = - google::RegisterFlagValidator(&FLAGS_abs_send_time, &ValidateExtensionId); -DEFINE_int32(transport_seq_no, 5, "Extension ID for transport sequence number"); -const bool transport_seq_no_dummy = - google::RegisterFlagValidator(&FLAGS_transport_seq_no, - &ValidateExtensionId); +DEFINE_int(audio_level, 1, "Extension ID for audio level (RFC 6464)"); +DEFINE_int(abs_send_time, 3, "Extension ID for absolute sender time"); +DEFINE_int(transport_seq_no, 5, "Extension ID for transport sequence number"); DEFINE_bool(matlabplot, false, "Generates a matlab script for plotting the delay profile"); +DEFINE_bool(help, false, "Prints this message"); // Maps a codec type to a printable name string. std::string CodecName(NetEqDecoder codec) { @@ -218,51 +176,51 @@ std::string CodecName(NetEqDecoder codec) { } } -void PrintCodecMappingEntry(NetEqDecoder codec, google::int32 flag) { +void PrintCodecMappingEntry(NetEqDecoder codec, int flag) { std::cout << CodecName(codec) << ": " << flag << std::endl; } void PrintCodecMapping() { - PrintCodecMappingEntry(NetEqDecoder::kDecoderPCMu, FLAGS_pcmu); - PrintCodecMappingEntry(NetEqDecoder::kDecoderPCMa, FLAGS_pcma); - PrintCodecMappingEntry(NetEqDecoder::kDecoderILBC, FLAGS_ilbc); - PrintCodecMappingEntry(NetEqDecoder::kDecoderISAC, FLAGS_isac); - PrintCodecMappingEntry(NetEqDecoder::kDecoderISACswb, FLAGS_isac_swb); - PrintCodecMappingEntry(NetEqDecoder::kDecoderOpus, FLAGS_opus); - PrintCodecMappingEntry(NetEqDecoder::kDecoderPCM16B, FLAGS_pcm16b); - PrintCodecMappingEntry(NetEqDecoder::kDecoderPCM16Bwb, FLAGS_pcm16b_wb); + PrintCodecMappingEntry(NetEqDecoder::kDecoderPCMu, FLAG_pcmu); + PrintCodecMappingEntry(NetEqDecoder::kDecoderPCMa, FLAG_pcma); + PrintCodecMappingEntry(NetEqDecoder::kDecoderILBC, FLAG_ilbc); + PrintCodecMappingEntry(NetEqDecoder::kDecoderISAC, FLAG_isac); + PrintCodecMappingEntry(NetEqDecoder::kDecoderISACswb, FLAG_isac_swb); + PrintCodecMappingEntry(NetEqDecoder::kDecoderOpus, FLAG_opus); + PrintCodecMappingEntry(NetEqDecoder::kDecoderPCM16B, FLAG_pcm16b); + PrintCodecMappingEntry(NetEqDecoder::kDecoderPCM16Bwb, FLAG_pcm16b_wb); PrintCodecMappingEntry(NetEqDecoder::kDecoderPCM16Bswb32kHz, - FLAGS_pcm16b_swb32); + FLAG_pcm16b_swb32); PrintCodecMappingEntry(NetEqDecoder::kDecoderPCM16Bswb48kHz, - FLAGS_pcm16b_swb48); - PrintCodecMappingEntry(NetEqDecoder::kDecoderG722, FLAGS_g722); - PrintCodecMappingEntry(NetEqDecoder::kDecoderAVT, FLAGS_avt); - PrintCodecMappingEntry(NetEqDecoder::kDecoderAVT16kHz, FLAGS_avt_16); - PrintCodecMappingEntry(NetEqDecoder::kDecoderAVT32kHz, FLAGS_avt_32); - PrintCodecMappingEntry(NetEqDecoder::kDecoderAVT48kHz, FLAGS_avt_48); - PrintCodecMappingEntry(NetEqDecoder::kDecoderRED, FLAGS_red); - PrintCodecMappingEntry(NetEqDecoder::kDecoderCNGnb, FLAGS_cn_nb); - PrintCodecMappingEntry(NetEqDecoder::kDecoderCNGwb, FLAGS_cn_wb); - PrintCodecMappingEntry(NetEqDecoder::kDecoderCNGswb32kHz, FLAGS_cn_swb32); - PrintCodecMappingEntry(NetEqDecoder::kDecoderCNGswb48kHz, FLAGS_cn_swb48); + FLAG_pcm16b_swb48); + PrintCodecMappingEntry(NetEqDecoder::kDecoderG722, FLAG_g722); + PrintCodecMappingEntry(NetEqDecoder::kDecoderAVT, FLAG_avt); + PrintCodecMappingEntry(NetEqDecoder::kDecoderAVT16kHz, FLAG_avt_16); + PrintCodecMappingEntry(NetEqDecoder::kDecoderAVT32kHz, FLAG_avt_32); + PrintCodecMappingEntry(NetEqDecoder::kDecoderAVT48kHz, FLAG_avt_48); + PrintCodecMappingEntry(NetEqDecoder::kDecoderRED, FLAG_red); + PrintCodecMappingEntry(NetEqDecoder::kDecoderCNGnb, FLAG_cn_nb); + PrintCodecMappingEntry(NetEqDecoder::kDecoderCNGwb, FLAG_cn_wb); + PrintCodecMappingEntry(NetEqDecoder::kDecoderCNGswb32kHz, FLAG_cn_swb32); + PrintCodecMappingEntry(NetEqDecoder::kDecoderCNGswb48kHz, FLAG_cn_swb48); } rtc::Optional CodecSampleRate(uint8_t payload_type) { - if (payload_type == FLAGS_pcmu || payload_type == FLAGS_pcma || - payload_type == FLAGS_ilbc || payload_type == FLAGS_pcm16b || - payload_type == FLAGS_cn_nb || payload_type == FLAGS_avt) + if (payload_type == FLAG_pcmu || payload_type == FLAG_pcma || + payload_type == FLAG_ilbc || payload_type == FLAG_pcm16b || + payload_type == FLAG_cn_nb || payload_type == FLAG_avt) return rtc::Optional(8000); - if (payload_type == FLAGS_isac || payload_type == FLAGS_pcm16b_wb || - payload_type == FLAGS_g722 || payload_type == FLAGS_cn_wb || - payload_type == FLAGS_avt_16) + if (payload_type == FLAG_isac || payload_type == FLAG_pcm16b_wb || + payload_type == FLAG_g722 || payload_type == FLAG_cn_wb || + payload_type == FLAG_avt_16) return rtc::Optional(16000); - if (payload_type == FLAGS_isac_swb || payload_type == FLAGS_pcm16b_swb32 || - payload_type == FLAGS_cn_swb32 || payload_type == FLAGS_avt_32) + if (payload_type == FLAG_isac_swb || payload_type == FLAG_pcm16b_swb32 || + payload_type == FLAG_cn_swb32 || payload_type == FLAG_avt_32) return rtc::Optional(32000); - if (payload_type == FLAGS_opus || payload_type == FLAGS_pcm16b_swb48 || - payload_type == FLAGS_cn_swb48 || payload_type == FLAGS_avt_48) + if (payload_type == FLAG_opus || payload_type == FLAG_pcm16b_swb48 || + payload_type == FLAG_cn_swb48 || payload_type == FLAG_avt_48) return rtc::Optional(48000); - if (payload_type == FLAGS_red) + if (payload_type == FLAG_red) return rtc::Optional(0); return rtc::Optional(); } @@ -460,31 +418,61 @@ class StatsGetter : public NetEqGetAudioCallback { int RunTest(int argc, char* argv[]) { std::string program_name = argv[0]; std::string usage = "Tool for decoding an RTP dump file using NetEq.\n" - "Run " + program_name + " --helpshort for usage.\n" + "Run " + program_name + " --help for usage.\n" "Example usage:\n" + program_name + " input.rtp output.{pcm, wav}\n"; - google::SetUsageMessage(usage); - google::ParseCommandLineFlags(&argc, &argv, true); + if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true)) { + return 1; + } + if (FLAG_help) { + std::cout << usage; + rtc::FlagList::Print(nullptr, false); + return 0; + } - if (FLAGS_codec_map) { + if (FLAG_codec_map) { PrintCodecMapping(); } if (argc != 3) { - if (FLAGS_codec_map) { + if (FLAG_codec_map) { // We have already printed the codec map. Just end the program. return 0; } // Print usage information. - std::cout << google::ProgramUsage(); + std::cout << usage; return 0; } + RTC_CHECK(ValidatePayloadType(FLAG_pcmu)); + RTC_CHECK(ValidatePayloadType(FLAG_pcma)); + RTC_CHECK(ValidatePayloadType(FLAG_ilbc)); + RTC_CHECK(ValidatePayloadType(FLAG_isac)); + RTC_CHECK(ValidatePayloadType(FLAG_isac_swb)); + RTC_CHECK(ValidatePayloadType(FLAG_opus)); + RTC_CHECK(ValidatePayloadType(FLAG_pcm16b)); + RTC_CHECK(ValidatePayloadType(FLAG_pcm16b_wb)); + RTC_CHECK(ValidatePayloadType(FLAG_pcm16b_swb32)); + RTC_CHECK(ValidatePayloadType(FLAG_pcm16b_swb48)); + RTC_CHECK(ValidatePayloadType(FLAG_g722)); + RTC_CHECK(ValidatePayloadType(FLAG_avt)); + RTC_CHECK(ValidatePayloadType(FLAG_avt_16)); + RTC_CHECK(ValidatePayloadType(FLAG_avt_32)); + RTC_CHECK(ValidatePayloadType(FLAG_avt_48)); + RTC_CHECK(ValidatePayloadType(FLAG_red)); + RTC_CHECK(ValidatePayloadType(FLAG_cn_nb)); + RTC_CHECK(ValidatePayloadType(FLAG_cn_wb)); + RTC_CHECK(ValidatePayloadType(FLAG_cn_swb32)); + RTC_CHECK(ValidatePayloadType(FLAG_cn_swb48)); + RTC_CHECK(ValidateSsrcValue(FLAG_ssrc)); + RTC_CHECK(ValidateExtensionId(FLAG_audio_level)); + RTC_CHECK(ValidateExtensionId(FLAG_abs_send_time)); + RTC_CHECK(ValidateExtensionId(FLAG_transport_seq_no)); // Gather RTP header extensions in a map. NetEqPacketSourceInput::RtpHeaderExtensionMap rtp_ext_map = { - {FLAGS_audio_level, kRtpExtensionAudioLevel}, - {FLAGS_abs_send_time, kRtpExtensionAbsoluteSendTime}, - {FLAGS_transport_seq_no, kRtpExtensionTransportSequenceNumber}}; + {FLAG_audio_level, kRtpExtensionAudioLevel}, + {FLAG_abs_send_time, kRtpExtensionAbsoluteSendTime}, + {FLAG_transport_seq_no, kRtpExtensionTransportSequenceNumber}}; const std::string input_file_name = argv[1]; std::unique_ptr input; @@ -500,9 +488,9 @@ int RunTest(int argc, char* argv[]) { RTC_CHECK(!input->ended()) << "Input file is empty"; // Check if an SSRC value was provided. - if (!FLAGS_ssrc.empty()) { + if (strlen(FLAG_ssrc) > 0) { uint32_t ssrc; - RTC_CHECK(ParseSsrc(FLAGS_ssrc, &ssrc)) << "Flag verification has failed."; + RTC_CHECK(ParseSsrc(FLAG_ssrc, &ssrc)) << "Flag verification has failed."; input.reset(new FilterSsrcInput(std::move(input), ssrc)); } @@ -557,39 +545,39 @@ int RunTest(int argc, char* argv[]) { std::cout << "Output file: " << output_file_name << std::endl; NetEqTest::DecoderMap codecs = { - {FLAGS_pcmu, std::make_pair(NetEqDecoder::kDecoderPCMu, "pcmu")}, - {FLAGS_pcma, std::make_pair(NetEqDecoder::kDecoderPCMa, "pcma")}, - {FLAGS_ilbc, std::make_pair(NetEqDecoder::kDecoderILBC, "ilbc")}, - {FLAGS_isac, std::make_pair(NetEqDecoder::kDecoderISAC, "isac")}, - {FLAGS_isac_swb, + {FLAG_pcmu, std::make_pair(NetEqDecoder::kDecoderPCMu, "pcmu")}, + {FLAG_pcma, std::make_pair(NetEqDecoder::kDecoderPCMa, "pcma")}, + {FLAG_ilbc, std::make_pair(NetEqDecoder::kDecoderILBC, "ilbc")}, + {FLAG_isac, std::make_pair(NetEqDecoder::kDecoderISAC, "isac")}, + {FLAG_isac_swb, std::make_pair(NetEqDecoder::kDecoderISACswb, "isac-swb")}, - {FLAGS_opus, std::make_pair(NetEqDecoder::kDecoderOpus, "opus")}, - {FLAGS_pcm16b, std::make_pair(NetEqDecoder::kDecoderPCM16B, "pcm16-nb")}, - {FLAGS_pcm16b_wb, + {FLAG_opus, std::make_pair(NetEqDecoder::kDecoderOpus, "opus")}, + {FLAG_pcm16b, std::make_pair(NetEqDecoder::kDecoderPCM16B, "pcm16-nb")}, + {FLAG_pcm16b_wb, std::make_pair(NetEqDecoder::kDecoderPCM16Bwb, "pcm16-wb")}, - {FLAGS_pcm16b_swb32, + {FLAG_pcm16b_swb32, std::make_pair(NetEqDecoder::kDecoderPCM16Bswb32kHz, "pcm16-swb32")}, - {FLAGS_pcm16b_swb48, + {FLAG_pcm16b_swb48, std::make_pair(NetEqDecoder::kDecoderPCM16Bswb48kHz, "pcm16-swb48")}, - {FLAGS_g722, std::make_pair(NetEqDecoder::kDecoderG722, "g722")}, - {FLAGS_avt, std::make_pair(NetEqDecoder::kDecoderAVT, "avt")}, - {FLAGS_avt_16, std::make_pair(NetEqDecoder::kDecoderAVT16kHz, "avt-16")}, - {FLAGS_avt_32, + {FLAG_g722, std::make_pair(NetEqDecoder::kDecoderG722, "g722")}, + {FLAG_avt, std::make_pair(NetEqDecoder::kDecoderAVT, "avt")}, + {FLAG_avt_16, std::make_pair(NetEqDecoder::kDecoderAVT16kHz, "avt-16")}, + {FLAG_avt_32, std::make_pair(NetEqDecoder::kDecoderAVT32kHz, "avt-32")}, - {FLAGS_avt_48, + {FLAG_avt_48, std::make_pair(NetEqDecoder::kDecoderAVT48kHz, "avt-48")}, - {FLAGS_red, std::make_pair(NetEqDecoder::kDecoderRED, "red")}, - {FLAGS_cn_nb, std::make_pair(NetEqDecoder::kDecoderCNGnb, "cng-nb")}, - {FLAGS_cn_wb, std::make_pair(NetEqDecoder::kDecoderCNGwb, "cng-wb")}, - {FLAGS_cn_swb32, + {FLAG_red, std::make_pair(NetEqDecoder::kDecoderRED, "red")}, + {FLAG_cn_nb, std::make_pair(NetEqDecoder::kDecoderCNGnb, "cng-nb")}, + {FLAG_cn_wb, std::make_pair(NetEqDecoder::kDecoderCNGwb, "cng-wb")}, + {FLAG_cn_swb32, std::make_pair(NetEqDecoder::kDecoderCNGswb32kHz, "cng-swb32")}, - {FLAGS_cn_swb48, + {FLAG_cn_swb48, std::make_pair(NetEqDecoder::kDecoderCNGswb48kHz, "cng-swb48")}}; // Check if a replacement audio file was provided. std::unique_ptr replacement_decoder; NetEqTest::ExtDecoderMap ext_codecs; - if (!FLAGS_replacement_audio_file.empty()) { + if (strlen(FLAG_replacement_audio_file) > 0) { // Find largest unused payload type. int replacement_pt = 127; while (!(codecs.find(replacement_pt) == codecs.end() && @@ -607,16 +595,16 @@ int RunTest(int argc, char* argv[]) { }; std::set cn_types = std_set_int32_to_uint8( - {FLAGS_cn_nb, FLAGS_cn_wb, FLAGS_cn_swb32, FLAGS_cn_swb48}); + {FLAG_cn_nb, FLAG_cn_wb, FLAG_cn_swb32, FLAG_cn_swb48}); std::set forbidden_types = - std_set_int32_to_uint8({FLAGS_g722, FLAGS_red, FLAGS_avt, - FLAGS_avt_16, FLAGS_avt_32, FLAGS_avt_48}); + std_set_int32_to_uint8({FLAG_g722, FLAG_red, FLAG_avt, + FLAG_avt_16, FLAG_avt_32, FLAG_avt_48}); input.reset(new NetEqReplacementInput(std::move(input), replacement_pt, cn_types, forbidden_types)); replacement_decoder.reset(new FakeDecodeFromFile( std::unique_ptr( - new InputAudioFile(FLAGS_replacement_audio_file)), + new InputAudioFile(FLAG_replacement_audio_file)), 48000, false)); NetEqTest::ExternalDecoderInfo ext_dec_info = { replacement_decoder.get(), NetEqDecoder::kDecoderArbitrary, @@ -626,7 +614,7 @@ int RunTest(int argc, char* argv[]) { NetEqTest::Callbacks callbacks; std::unique_ptr delay_analyzer; - if (FLAGS_matlabplot) { + if (FLAG_matlabplot) { delay_analyzer.reset(new NetEqDelayAnalyzer); } @@ -641,7 +629,7 @@ int RunTest(int argc, char* argv[]) { int64_t test_duration_ms = test.Run(); - if (FLAGS_matlabplot) { + if (FLAG_matlabplot) { auto matlab_script_name = output_file_name; std::replace(matlab_script_name.begin(), matlab_script_name.end(), '.', '_'); diff --git a/webrtc/modules/audio_coding/neteq/tools/rtp_analyze.cc b/webrtc/modules/audio_coding/neteq/tools/rtp_analyze.cc index 74c64e0a8a..23f96c56b2 100644 --- a/webrtc/modules/audio_coding/neteq/tools/rtp_analyze.cc +++ b/webrtc/modules/audio_coding/neteq/tools/rtp_analyze.cc @@ -14,34 +14,17 @@ #include #include -#include "gflags/gflags.h" #include "webrtc/modules/audio_coding/neteq/tools/packet.h" #include "webrtc/modules/audio_coding/neteq/tools/rtp_file_source.h" - -// Flag validator. -static bool ValidatePayloadType(const char* flagname, int32_t value) { - if (value >= 0 && value <= 127) // Value is ok. - return true; - printf("Invalid value for --%s: %d\n", flagname, static_cast(value)); - return false; -} -static bool ValidateExtensionId(const char* flagname, int32_t value) { - if (value > 0 && value <= 255) // Value is ok. - return true; - printf("Invalid value for --%s: %d\n", flagname, static_cast(value)); - return false; -} +#include "webrtc/rtc_base/flags.h" // Define command line flags. -DEFINE_int32(red, 117, "RTP payload type for RED"); -static const bool red_dummy = - google::RegisterFlagValidator(&FLAGS_red, &ValidatePayloadType); -DEFINE_int32(audio_level, 1, "Extension ID for audio level (RFC 6464)"); -static const bool audio_level_dummy = - google::RegisterFlagValidator(&FLAGS_audio_level, &ValidateExtensionId); -DEFINE_int32(abs_send_time, 3, "Extension ID for absolute sender time"); -static const bool abs_send_time_dummy = - google::RegisterFlagValidator(&FLAGS_abs_send_time, &ValidateExtensionId); +DEFINE_int(red, 117, "RTP payload type for RED"); +DEFINE_int(audio_level, -1, "Extension ID for audio level (RFC 6464); " + "-1 not to print audio level"); +DEFINE_int(abs_send_time, -1, "Extension ID for absolute sender time; " + "-1 not to print absolute send time"); +DEFINE_bool(help, false, "Print this message"); int main(int argc, char* argv[]) { std::string program_name = argv[0]; @@ -49,36 +32,43 @@ int main(int argc, char* argv[]) { "Tool for parsing an RTP dump file to text output.\n" "Run " + program_name + - " --helpshort for usage.\n" + " --help for usage.\n" "Example usage:\n" + program_name + " input.rtp output.txt\n\n" + - "Output is sent to stdout if no output file is given." + - "Note that this tool can read files with our without payloads."; - google::SetUsageMessage(usage); - google::ParseCommandLineFlags(&argc, &argv, true); - - if (argc != 2 && argc != 3) { - // Print usage information. - printf("%s", google::ProgramUsage()); - return 0; + "Output is sent to stdout if no output file is given. " + + "Note that this tool can read files with or without payloads.\n"; + if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true) || + FLAG_help || (argc != 2 && argc != 3)) { + printf("%s", usage.c_str()); + if (FLAG_help) { + rtc::FlagList::Print(nullptr, false); + return 0; + } + return 1; } + RTC_CHECK(FLAG_red >= 0 && FLAG_red <= 127); // Payload type + RTC_CHECK(FLAG_audio_level == -1 || // Default + (FLAG_audio_level > 0 && FLAG_audio_level <= 255)); // Extension ID + RTC_CHECK(FLAG_abs_send_time == -1 || // Default + (FLAG_abs_send_time > 0 && FLAG_abs_send_time <= 255)); // Extension ID + printf("Input file: %s\n", argv[1]); std::unique_ptr file_source( webrtc::test::RtpFileSource::Create(argv[1])); assert(file_source.get()); // Set RTP extension IDs. bool print_audio_level = false; - if (!google::GetCommandLineFlagInfoOrDie("audio_level").is_default) { + if (FLAG_audio_level != -1) { print_audio_level = true; file_source->RegisterRtpHeaderExtension(webrtc::kRtpExtensionAudioLevel, - FLAGS_audio_level); + FLAG_audio_level); } bool print_abs_send_time = false; - if (!google::GetCommandLineFlagInfoOrDie("abs_send_time").is_default) { + if (FLAG_abs_send_time != -1) { print_abs_send_time = true; file_source->RegisterRtpHeaderExtension( - webrtc::kRtpExtensionAbsoluteSendTime, FLAGS_abs_send_time); + webrtc::kRtpExtensionAbsoluteSendTime, FLAG_abs_send_time); } FILE* out_file; @@ -160,7 +150,7 @@ int main(int argc, char* argv[]) { } fprintf(out_file, "\n"); - if (packet->header().payloadType == FLAGS_red) { + if (packet->header().payloadType == FLAG_red) { std::list red_headers; packet->ExtractRedHeaders(&red_headers); while (!red_headers.empty()) { diff --git a/webrtc/modules/audio_coding/test/delay_test.cc b/webrtc/modules/audio_coding/test/delay_test.cc index ce244932c8..0ce7fd226a 100644 --- a/webrtc/modules/audio_coding/test/delay_test.cc +++ b/webrtc/modules/audio_coding/test/delay_test.cc @@ -10,11 +10,11 @@ #include #include +#include #include #include -#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(); diff --git a/webrtc/modules/audio_coding/test/insert_packet_with_timing.cc b/webrtc/modules/audio_coding/test/insert_packet_with_timing.cc index 4fa4e5276c..db58289b16 100644 --- a/webrtc/modules/audio_coding/test/insert_packet_with_timing.cc +++ b/webrtc/modules/audio_coding/test/insert_packet_with_timing.cc @@ -9,31 +9,32 @@ */ #include +#include #include -#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(FLAGS_input_fs_hz), + pcm_in_fid_.Open(FLAG_input, static_cast(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(FLAGS_output_fs_hz), + receive_acm_->PlayoutData10Ms(static_cast(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); diff --git a/webrtc/modules/audio_processing/BUILD.gn b/webrtc/modules/audio_processing/BUILD.gn index a569bd1006..204a9889a0 100644 --- a/webrtc/modules/audio_processing/BUILD.gn +++ b/webrtc/modules/audio_processing/BUILD.gn @@ -724,7 +724,6 @@ if (rtc_include_tests) { "../../rtc_base:protobuf_utils", "../../rtc_base:rtc_base_approved", "../../system_wrappers:system_wrappers_default", - "//third_party/gflags:gflags", ] } # unpack_aecdump @@ -755,7 +754,6 @@ if (rtc_include_tests) { "aec_dump", "aec_dump:aec_dump_impl", "//testing/gtest", - "//third_party/gflags:gflags", ] } # audioproc_f } @@ -794,11 +792,11 @@ if (rtc_include_tests) { "..:module_api", "../..:webrtc_common", "../../common_audio:common_audio", + "../../rtc_base:rtc_base_approved", "../../system_wrappers:metrics_default", "../../system_wrappers:system_wrappers", "../../test:test_support", "//testing/gtest", - "//third_party/gflags", ] } @@ -828,7 +826,6 @@ if (rtc_include_tests) { "../../common_audio:common_audio", "../../rtc_base:rtc_base_approved", "../../system_wrappers:metrics_default", - "//third_party/gflags", ] } @@ -841,10 +838,10 @@ if (rtc_include_tests) { deps = [ ":audio_processing", ":audioproc_test_utils", + "../../rtc_base:rtc_base_approved", "../../system_wrappers:metrics_default", "../../test:test_support", "//testing/gtest", - "//third_party/gflags", ] } } diff --git a/webrtc/modules/audio_processing/beamformer/nonlinear_beamformer_test.cc b/webrtc/modules/audio_processing/beamformer/nonlinear_beamformer_test.cc index 3ac68d4435..11b172ab28 100644 --- a/webrtc/modules/audio_processing/beamformer/nonlinear_beamformer_test.cc +++ b/webrtc/modules/audio_processing/beamformer/nonlinear_beamformer_test.cc @@ -10,12 +10,12 @@ #include -#include "gflags/gflags.h" #include "webrtc/common_audio/channel_buffer.h" #include "webrtc/common_audio/wav_file.h" #include "webrtc/modules/audio_processing/beamformer/nonlinear_beamformer.h" #include "webrtc/modules/audio_processing/test/test_utils.h" #include "webrtc/rtc_base/checks.h" +#include "webrtc/rtc_base/flags.h" #include "webrtc/rtc_base/format_macros.h" DEFINE_string(i, "", "The name of the input file to read from."); @@ -24,6 +24,7 @@ DEFINE_string(mic_positions, "", "Space delimited cartesian coordinates of microphones in meters. " "The coordinates of each point are contiguous. " "For a two element array: \"x1 y1 z1 x2 y2 z2\""); +DEFINE_bool(help, false, "Prints this message."); namespace webrtc { namespace { @@ -34,29 +35,36 @@ const int kChunkSizeMs = 1000 / kChunksPerSecond; const char kUsage[] = "Command-line tool to run beamforming on WAV files. The signal is passed\n" "in as a single band, unlike the audio processing interface which splits\n" - "signals into multiple bands."; + "signals into multiple bands.\n"; } // namespace int main(int argc, char* argv[]) { - google::SetUsageMessage(kUsage); - google::ParseCommandLineFlags(&argc, &argv, true); + if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true) || + FLAG_help || argc != 1) { + printf("%s", kUsage); + if (FLAG_help) { + rtc::FlagList::Print(nullptr, false); + return 0; + } + return 1; + } - WavReader in_file(FLAGS_i); - WavWriter out_file(FLAGS_o, in_file.sample_rate(), in_file.num_channels()); + WavReader in_file(FLAG_i); + WavWriter out_file(FLAG_o, in_file.sample_rate(), in_file.num_channels()); const size_t num_mics = in_file.num_channels(); const std::vector array_geometry = - ParseArrayGeometry(FLAGS_mic_positions, num_mics); + ParseArrayGeometry(FLAG_mic_positions, num_mics); RTC_CHECK_EQ(array_geometry.size(), num_mics); NonlinearBeamformer bf(array_geometry, array_geometry.size()); bf.Initialize(kChunkSizeMs, in_file.sample_rate()); printf("Input file: %s\nChannels: %" PRIuS ", Sample rate: %d Hz\n\n", - FLAGS_i.c_str(), in_file.num_channels(), in_file.sample_rate()); + FLAG_i, in_file.num_channels(), in_file.sample_rate()); printf("Output file: %s\nChannels: %" PRIuS ", Sample rate: %d Hz\n\n", - FLAGS_o.c_str(), out_file.num_channels(), out_file.sample_rate()); + FLAG_o, out_file.num_channels(), out_file.sample_rate()); ChannelBuffer buf( rtc::CheckedDivExact(in_file.sample_rate(), kChunksPerSecond), diff --git a/webrtc/modules/audio_processing/intelligibility/test/intelligibility_proc.cc b/webrtc/modules/audio_processing/intelligibility/test/intelligibility_proc.cc index cd76a9557a..6045e9fd15 100644 --- a/webrtc/modules/audio_processing/intelligibility/test/intelligibility_proc.cc +++ b/webrtc/modules/audio_processing/intelligibility/test/intelligibility_proc.cc @@ -8,7 +8,6 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include "gflags/gflags.h" #include "webrtc/common_audio/channel_buffer.h" #include "webrtc/common_audio/include/audio_util.h" #include "webrtc/common_audio/wav_file.h" @@ -16,7 +15,7 @@ #include "webrtc/modules/audio_processing/intelligibility/intelligibility_enhancer.h" #include "webrtc/modules/audio_processing/noise_suppression_impl.h" #include "webrtc/rtc_base/criticalsection.h" -#include "webrtc/test/gtest.h" +#include "webrtc/rtc_base/flags.h" using std::complex; @@ -26,16 +25,24 @@ namespace { DEFINE_string(clear_file, "speech.wav", "Input file with clear speech."); DEFINE_string(noise_file, "noise.wav", "Input file with noise data."); DEFINE_string(out_file, "proc_enhanced.wav", "Enhanced output file."); +DEFINE_bool(help, false, "Print this message."); -// void function for gtest -void void_main(int argc, char* argv[]) { - google::SetUsageMessage( - "\n\nInput files must be little-endian 16-bit signed raw PCM.\n"); - google::ParseCommandLineFlags(&argc, &argv, true); +int int_main(int argc, char* argv[]) { + if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true)) { + return 1; + } + if (FLAG_help) { + rtc::FlagList::Print(nullptr, false); + return 0; + } + if (argc != 1) { + printf("\n\nInput files must be little-endian 16-bit signed raw PCM.\n"); + return 0; + } - WavReader in_file(FLAGS_clear_file); - WavReader noise_file(FLAGS_noise_file); - WavWriter out_file(FLAGS_out_file, in_file.sample_rate(), + WavReader in_file(FLAG_clear_file); + WavReader noise_file(FLAG_noise_file); + WavWriter out_file(FLAG_out_file, in_file.sample_rate(), in_file.num_channels()); rtc::CriticalSection crit; NoiseSuppressionImpl ns(&crit); @@ -77,12 +84,13 @@ void void_main(int argc, char* argv[]) { FloatToFloatS16(in.data(), in.size(), in.data()); out_file.WriteSamples(in.data(), in.size()); } + + return 0; } } // namespace } // namespace webrtc int main(int argc, char* argv[]) { - webrtc::void_main(argc, argv); - return 0; + return webrtc::int_main(argc, argv); } diff --git a/webrtc/modules/audio_processing/test/audioproc_float.cc b/webrtc/modules/audio_processing/test/audioproc_float.cc index a11f41c855..bdf49d7afa 100644 --- a/webrtc/modules/audio_processing/test/audioproc_float.cc +++ b/webrtc/modules/audio_processing/test/audioproc_float.cc @@ -13,11 +13,11 @@ #include -#include "gflags/gflags.h" #include "webrtc/modules/audio_processing/include/audio_processing.h" #include "webrtc/modules/audio_processing/test/aec_dump_based_simulator.h" #include "webrtc/modules/audio_processing/test/audio_processing_simulator.h" #include "webrtc/modules/audio_processing/test/wav_based_simulator.h" +#include "webrtc/rtc_base/flags.h" namespace webrtc { namespace test { @@ -32,7 +32,7 @@ const char kUsageDescription[] = "\n\n" "Command-line tool to simulate a call using the audio " "processing module, either based on wav files or " - "protobuf debug dump recordings."; + "protobuf debug dump recordings.\n"; DEFINE_string(dump_input, "", "Aec dump input filename"); DEFINE_string(dump_output, "", "Aec dump output filename"); @@ -41,126 +41,126 @@ DEFINE_string(o, "", "Forward stream output wav filename"); DEFINE_string(ri, "", "Reverse stream input wav filename"); DEFINE_string(ro, "", "Reverse stream output wav filename"); DEFINE_string(artificial_nearend, "", "Artificial nearend wav filename"); -DEFINE_int32(output_num_channels, - kParameterNotSpecifiedValue, - "Number of forward stream output channels"); -DEFINE_int32(reverse_output_num_channels, - kParameterNotSpecifiedValue, - "Number of Reverse stream output channels"); -DEFINE_int32(output_sample_rate_hz, - kParameterNotSpecifiedValue, - "Forward stream output sample rate in Hz"); -DEFINE_int32(reverse_output_sample_rate_hz, - kParameterNotSpecifiedValue, - "Reverse stream output sample rate in Hz"); +DEFINE_int(output_num_channels, + kParameterNotSpecifiedValue, + "Number of forward stream output channels"); +DEFINE_int(reverse_output_num_channels, + kParameterNotSpecifiedValue, + "Number of Reverse stream output channels"); +DEFINE_int(output_sample_rate_hz, + kParameterNotSpecifiedValue, + "Forward stream output sample rate in Hz"); +DEFINE_int(reverse_output_sample_rate_hz, + kParameterNotSpecifiedValue, + "Reverse stream output sample rate in Hz"); DEFINE_string(mic_positions, "", "Space delimited cartesian coordinates of microphones in " "meters. The coordinates of each point are contiguous. For a " "two element array: \"x1 y1 z1 x2 y2 z2\""); -DEFINE_int32(target_angle_degrees, - 90, - "The azimuth of the target in degrees (0-359). Only applies to " - "beamforming."); +DEFINE_int(target_angle_degrees, + 90, + "The azimuth of the target in degrees (0-359). Only applies to " + "beamforming."); DEFINE_bool(fixed_interface, false, "Use the fixed interface when operating on wav files"); -DEFINE_int32(aec, - kParameterNotSpecifiedValue, - "Activate (1) or deactivate(0) the echo canceller"); -DEFINE_int32(aecm, - kParameterNotSpecifiedValue, - "Activate (1) or deactivate(0) the mobile echo controller"); -DEFINE_int32(ed, - kParameterNotSpecifiedValue, - "Activate (1) or deactivate (0) the residual echo detector"); +DEFINE_int(aec, + kParameterNotSpecifiedValue, + "Activate (1) or deactivate(0) the echo canceller"); +DEFINE_int(aecm, + kParameterNotSpecifiedValue, + "Activate (1) or deactivate(0) the mobile echo controller"); +DEFINE_int(ed, + kParameterNotSpecifiedValue, + "Activate (1) or deactivate (0) the residual echo detector"); DEFINE_string(ed_graph, "", "Output filename for graph of echo likelihood"); -DEFINE_int32(agc, - kParameterNotSpecifiedValue, - "Activate (1) or deactivate(0) the AGC"); -DEFINE_int32(agc2, - kParameterNotSpecifiedValue, - "Activate (1) or deactivate(0) the AGC2"); -DEFINE_int32(hpf, - kParameterNotSpecifiedValue, - "Activate (1) or deactivate(0) the high-pass filter"); -DEFINE_int32(ns, - kParameterNotSpecifiedValue, - "Activate (1) or deactivate(0) the noise suppressor"); -DEFINE_int32(ts, - kParameterNotSpecifiedValue, - "Activate (1) or deactivate(0) the transient suppressor"); -DEFINE_int32(bf, - kParameterNotSpecifiedValue, - "Activate (1) or deactivate(0) the beamformer"); -DEFINE_int32(ie, - kParameterNotSpecifiedValue, - "Activate (1) or deactivate(0) the intelligibility enhancer"); -DEFINE_int32(vad, - kParameterNotSpecifiedValue, - "Activate (1) or deactivate(0) the voice activity detector"); -DEFINE_int32(le, - kParameterNotSpecifiedValue, - "Activate (1) or deactivate(0) the level estimator"); +DEFINE_int(agc, + kParameterNotSpecifiedValue, + "Activate (1) or deactivate(0) the AGC"); +DEFINE_int(agc2, + kParameterNotSpecifiedValue, + "Activate (1) or deactivate(0) the AGC2"); +DEFINE_int(hpf, + kParameterNotSpecifiedValue, + "Activate (1) or deactivate(0) the high-pass filter"); +DEFINE_int(ns, + kParameterNotSpecifiedValue, + "Activate (1) or deactivate(0) the noise suppressor"); +DEFINE_int(ts, + kParameterNotSpecifiedValue, + "Activate (1) or deactivate(0) the transient suppressor"); +DEFINE_int(bf, + kParameterNotSpecifiedValue, + "Activate (1) or deactivate(0) the beamformer"); +DEFINE_int(ie, + kParameterNotSpecifiedValue, + "Activate (1) or deactivate(0) the intelligibility enhancer"); +DEFINE_int(vad, + kParameterNotSpecifiedValue, + "Activate (1) or deactivate(0) the voice activity detector"); +DEFINE_int(le, + kParameterNotSpecifiedValue, + "Activate (1) or deactivate(0) the level estimator"); DEFINE_bool(all_default, false, "Activate all of the default components (will be overridden by any " "other settings)"); -DEFINE_int32(aec_suppression_level, - kParameterNotSpecifiedValue, - "Set the aec suppression level (0-2)"); -DEFINE_int32(delay_agnostic, - kParameterNotSpecifiedValue, - "Activate (1) or deactivate(0) the AEC delay agnostic mode"); -DEFINE_int32(extended_filter, - kParameterNotSpecifiedValue, - "Activate (1) or deactivate(0) the AEC extended filter mode"); -DEFINE_int32(drift_compensation, - kParameterNotSpecifiedValue, - "Activate (1) or deactivate(0) the drift compensation"); -DEFINE_int32(aec3, - kParameterNotSpecifiedValue, - "Activate (1) or deactivate(0) the experimental AEC mode AEC3"); -DEFINE_int32(lc, - kParameterNotSpecifiedValue, - "Activate (1) or deactivate(0) the level control"); -DEFINE_int32(experimental_agc, - kParameterNotSpecifiedValue, - "Activate (1) or deactivate(0) the experimental AGC"); -DEFINE_int32( +DEFINE_int(aec_suppression_level, + kParameterNotSpecifiedValue, + "Set the aec suppression level (0-2)"); +DEFINE_int(delay_agnostic, + kParameterNotSpecifiedValue, + "Activate (1) or deactivate(0) the AEC delay agnostic mode"); +DEFINE_int(extended_filter, + kParameterNotSpecifiedValue, + "Activate (1) or deactivate(0) the AEC extended filter mode"); +DEFINE_int(drift_compensation, + kParameterNotSpecifiedValue, + "Activate (1) or deactivate(0) the drift compensation"); +DEFINE_int(aec3, + kParameterNotSpecifiedValue, + "Activate (1) or deactivate(0) the experimental AEC mode AEC3"); +DEFINE_int(lc, + kParameterNotSpecifiedValue, + "Activate (1) or deactivate(0) the level control"); +DEFINE_int(experimental_agc, + kParameterNotSpecifiedValue, + "Activate (1) or deactivate(0) the experimental AGC"); +DEFINE_int( refined_adaptive_filter, kParameterNotSpecifiedValue, "Activate (1) or deactivate(0) the refined adaptive filter functionality"); -DEFINE_int32(aecm_routing_mode, - kParameterNotSpecifiedValue, - "Specify the AECM routing mode (0-4)"); -DEFINE_int32(aecm_comfort_noise, - kParameterNotSpecifiedValue, - "Activate (1) or deactivate(0) the AECM comfort noise"); -DEFINE_int32(agc_mode, - kParameterNotSpecifiedValue, - "Specify the AGC mode (0-2)"); -DEFINE_int32(agc_target_level, - kParameterNotSpecifiedValue, - "Specify the AGC target level (0-31)"); -DEFINE_int32(agc_limiter, - kParameterNotSpecifiedValue, - "Activate (1) or deactivate(0) the level estimator"); -DEFINE_int32(agc_compression_gain, - kParameterNotSpecifiedValue, - "Specify the AGC compression gain (0-90)"); -DEFINE_int32(vad_likelihood, - kParameterNotSpecifiedValue, - "Specify the VAD likelihood (0-3)"); -DEFINE_int32(ns_level, - kParameterNotSpecifiedValue, - "Specify the NS level (0-3)"); -DEFINE_int32(stream_delay, - kParameterNotSpecifiedValue, - "Specify the stream delay in ms to use"); -DEFINE_int32(stream_drift_samples, - kParameterNotSpecifiedValue, - "Specify the number of stream drift samples to use"); +DEFINE_int(aecm_routing_mode, + kParameterNotSpecifiedValue, + "Specify the AECM routing mode (0-4)"); +DEFINE_int(aecm_comfort_noise, + kParameterNotSpecifiedValue, + "Activate (1) or deactivate(0) the AECM comfort noise"); +DEFINE_int(agc_mode, + kParameterNotSpecifiedValue, + "Specify the AGC mode (0-2)"); +DEFINE_int(agc_target_level, + kParameterNotSpecifiedValue, + "Specify the AGC target level (0-31)"); +DEFINE_int(agc_limiter, + kParameterNotSpecifiedValue, + "Activate (1) or deactivate(0) the level estimator"); +DEFINE_int(agc_compression_gain, + kParameterNotSpecifiedValue, + "Specify the AGC compression gain (0-90)"); +DEFINE_int(vad_likelihood, + kParameterNotSpecifiedValue, + "Specify the VAD likelihood (0-3)"); +DEFINE_int(ns_level, + kParameterNotSpecifiedValue, + "Specify the NS level (0-3)"); +DEFINE_int(stream_delay, + kParameterNotSpecifiedValue, + "Specify the stream delay in ms to use"); +DEFINE_int(stream_drift_samples, + kParameterNotSpecifiedValue, + "Specify the number of stream drift samples to use"); DEFINE_bool(performance_report, false, "Report the APM performance "); DEFINE_bool(verbose, false, "Produce verbose output"); DEFINE_bool(bitexactness_report, @@ -173,6 +173,7 @@ DEFINE_bool(store_intermediate_output, false, "Creates new output files after each init"); DEFINE_string(custom_call_order_file, "", "Custom process API call order file"); +DEFINE_bool(help, false, "Print this message"); void SetSettingIfSpecified(const std::string value, rtc::Optional* parameter) { @@ -197,7 +198,7 @@ void SetSettingIfFlagSet(int32_t flag, rtc::Optional* parameter) { SimulationSettings CreateSettings() { SimulationSettings settings; - if (FLAGS_all_default) { + if (FLAG_all_default) { settings.use_le = rtc::Optional(true); settings.use_vad = rtc::Optional(true); settings.use_ie = rtc::Optional(false); @@ -210,70 +211,70 @@ SimulationSettings CreateSettings() { settings.use_aecm = rtc::Optional(false); settings.use_ed = rtc::Optional(false); } - SetSettingIfSpecified(FLAGS_dump_input, &settings.aec_dump_input_filename); - SetSettingIfSpecified(FLAGS_dump_output, &settings.aec_dump_output_filename); - SetSettingIfSpecified(FLAGS_i, &settings.input_filename); - SetSettingIfSpecified(FLAGS_o, &settings.output_filename); - SetSettingIfSpecified(FLAGS_ri, &settings.reverse_input_filename); - SetSettingIfSpecified(FLAGS_ro, &settings.reverse_output_filename); - SetSettingIfSpecified(FLAGS_artificial_nearend, + SetSettingIfSpecified(FLAG_dump_input, &settings.aec_dump_input_filename); + SetSettingIfSpecified(FLAG_dump_output, &settings.aec_dump_output_filename); + SetSettingIfSpecified(FLAG_i, &settings.input_filename); + SetSettingIfSpecified(FLAG_o, &settings.output_filename); + SetSettingIfSpecified(FLAG_ri, &settings.reverse_input_filename); + SetSettingIfSpecified(FLAG_ro, &settings.reverse_output_filename); + SetSettingIfSpecified(FLAG_artificial_nearend, &settings.artificial_nearend_filename); - SetSettingIfSpecified(FLAGS_output_num_channels, + SetSettingIfSpecified(FLAG_output_num_channels, &settings.output_num_channels); - SetSettingIfSpecified(FLAGS_reverse_output_num_channels, + SetSettingIfSpecified(FLAG_reverse_output_num_channels, &settings.reverse_output_num_channels); - SetSettingIfSpecified(FLAGS_output_sample_rate_hz, + SetSettingIfSpecified(FLAG_output_sample_rate_hz, &settings.output_sample_rate_hz); - SetSettingIfSpecified(FLAGS_reverse_output_sample_rate_hz, + SetSettingIfSpecified(FLAG_reverse_output_sample_rate_hz, &settings.reverse_output_sample_rate_hz); - SetSettingIfSpecified(FLAGS_mic_positions, &settings.microphone_positions); - settings.target_angle_degrees = FLAGS_target_angle_degrees; - SetSettingIfFlagSet(FLAGS_aec, &settings.use_aec); - SetSettingIfFlagSet(FLAGS_aecm, &settings.use_aecm); - SetSettingIfFlagSet(FLAGS_ed, &settings.use_ed); - SetSettingIfSpecified(FLAGS_ed_graph, &settings.ed_graph_output_filename); - SetSettingIfFlagSet(FLAGS_agc, &settings.use_agc); - SetSettingIfFlagSet(FLAGS_agc2, &settings.use_agc2); - SetSettingIfFlagSet(FLAGS_hpf, &settings.use_hpf); - SetSettingIfFlagSet(FLAGS_ns, &settings.use_ns); - SetSettingIfFlagSet(FLAGS_ts, &settings.use_ts); - SetSettingIfFlagSet(FLAGS_bf, &settings.use_bf); - SetSettingIfFlagSet(FLAGS_ie, &settings.use_ie); - SetSettingIfFlagSet(FLAGS_vad, &settings.use_vad); - SetSettingIfFlagSet(FLAGS_le, &settings.use_le); - SetSettingIfSpecified(FLAGS_aec_suppression_level, + SetSettingIfSpecified(FLAG_mic_positions, &settings.microphone_positions); + settings.target_angle_degrees = FLAG_target_angle_degrees; + SetSettingIfFlagSet(FLAG_aec, &settings.use_aec); + SetSettingIfFlagSet(FLAG_aecm, &settings.use_aecm); + SetSettingIfFlagSet(FLAG_ed, &settings.use_ed); + SetSettingIfSpecified(FLAG_ed_graph, &settings.ed_graph_output_filename); + SetSettingIfFlagSet(FLAG_agc, &settings.use_agc); + SetSettingIfFlagSet(FLAG_agc2, &settings.use_agc2); + SetSettingIfFlagSet(FLAG_hpf, &settings.use_hpf); + SetSettingIfFlagSet(FLAG_ns, &settings.use_ns); + SetSettingIfFlagSet(FLAG_ts, &settings.use_ts); + SetSettingIfFlagSet(FLAG_bf, &settings.use_bf); + SetSettingIfFlagSet(FLAG_ie, &settings.use_ie); + SetSettingIfFlagSet(FLAG_vad, &settings.use_vad); + SetSettingIfFlagSet(FLAG_le, &settings.use_le); + SetSettingIfSpecified(FLAG_aec_suppression_level, &settings.aec_suppression_level); - SetSettingIfFlagSet(FLAGS_delay_agnostic, &settings.use_delay_agnostic); - SetSettingIfFlagSet(FLAGS_extended_filter, &settings.use_extended_filter); - SetSettingIfFlagSet(FLAGS_drift_compensation, + SetSettingIfFlagSet(FLAG_delay_agnostic, &settings.use_delay_agnostic); + SetSettingIfFlagSet(FLAG_extended_filter, &settings.use_extended_filter); + SetSettingIfFlagSet(FLAG_drift_compensation, &settings.use_drift_compensation); - SetSettingIfFlagSet(FLAGS_refined_adaptive_filter, + SetSettingIfFlagSet(FLAG_refined_adaptive_filter, &settings.use_refined_adaptive_filter); - SetSettingIfFlagSet(FLAGS_aec3, &settings.use_aec3); - SetSettingIfFlagSet(FLAGS_lc, &settings.use_lc); - SetSettingIfFlagSet(FLAGS_experimental_agc, &settings.use_experimental_agc); - SetSettingIfSpecified(FLAGS_aecm_routing_mode, &settings.aecm_routing_mode); - SetSettingIfFlagSet(FLAGS_aecm_comfort_noise, + SetSettingIfFlagSet(FLAG_aec3, &settings.use_aec3); + SetSettingIfFlagSet(FLAG_lc, &settings.use_lc); + SetSettingIfFlagSet(FLAG_experimental_agc, &settings.use_experimental_agc); + SetSettingIfSpecified(FLAG_aecm_routing_mode, &settings.aecm_routing_mode); + SetSettingIfFlagSet(FLAG_aecm_comfort_noise, &settings.use_aecm_comfort_noise); - SetSettingIfSpecified(FLAGS_agc_mode, &settings.agc_mode); - SetSettingIfSpecified(FLAGS_agc_target_level, &settings.agc_target_level); - SetSettingIfFlagSet(FLAGS_agc_limiter, &settings.use_agc_limiter); - SetSettingIfSpecified(FLAGS_agc_compression_gain, + SetSettingIfSpecified(FLAG_agc_mode, &settings.agc_mode); + SetSettingIfSpecified(FLAG_agc_target_level, &settings.agc_target_level); + SetSettingIfFlagSet(FLAG_agc_limiter, &settings.use_agc_limiter); + SetSettingIfSpecified(FLAG_agc_compression_gain, &settings.agc_compression_gain); - SetSettingIfSpecified(FLAGS_vad_likelihood, &settings.vad_likelihood); - SetSettingIfSpecified(FLAGS_ns_level, &settings.ns_level); - SetSettingIfSpecified(FLAGS_stream_delay, &settings.stream_delay); - SetSettingIfSpecified(FLAGS_stream_drift_samples, + SetSettingIfSpecified(FLAG_vad_likelihood, &settings.vad_likelihood); + SetSettingIfSpecified(FLAG_ns_level, &settings.ns_level); + SetSettingIfSpecified(FLAG_stream_delay, &settings.stream_delay); + SetSettingIfSpecified(FLAG_stream_drift_samples, &settings.stream_drift_samples); - SetSettingIfSpecified(FLAGS_custom_call_order_file, + SetSettingIfSpecified(FLAG_custom_call_order_file, &settings.custom_call_order_filename); - settings.report_performance = FLAGS_performance_report; - settings.use_verbose_logging = FLAGS_verbose; - settings.report_bitexactness = FLAGS_bitexactness_report; - settings.discard_all_settings_in_aecdump = FLAGS_discard_settings_in_aecdump; - settings.fixed_interface = FLAGS_fixed_interface; - settings.store_intermediate_output = FLAGS_store_intermediate_output; + settings.report_performance = FLAG_performance_report; + settings.use_verbose_logging = FLAG_verbose; + settings.report_bitexactness = FLAG_bitexactness_report; + settings.discard_all_settings_in_aecdump = FLAG_discard_settings_in_aecdump; + settings.fixed_interface = FLAG_fixed_interface; + settings.store_intermediate_output = FLAG_store_intermediate_output; return settings; } @@ -422,8 +423,15 @@ void PerformBasicParameterSanityChecks(const SimulationSettings& settings) { } // namespace int main(int argc, char* argv[]) { - google::SetUsageMessage(kUsageDescription); - google::ParseCommandLineFlags(&argc, &argv, true); + if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true) || + FLAG_help || argc != 1) { + printf("%s", kUsageDescription); + if (FLAG_help) { + rtc::FlagList::Print(nullptr, false); + return 0; + } + return 1; + } SimulationSettings settings = CreateSettings(); PerformBasicParameterSanityChecks(settings); diff --git a/webrtc/modules/audio_processing/test/conversational_speech/BUILD.gn b/webrtc/modules/audio_processing/test/conversational_speech/BUILD.gn index 587663b7fc..5c681a05b7 100644 --- a/webrtc/modules/audio_processing/test/conversational_speech/BUILD.gn +++ b/webrtc/modules/audio_processing/test/conversational_speech/BUILD.gn @@ -24,7 +24,6 @@ rtc_executable("conversational_speech_generator") { ":lib", "../../../../rtc_base:rtc_base_approved", "../../../../test:test_support", - "//third_party/gflags", ] } diff --git a/webrtc/modules/audio_processing/test/conversational_speech/generator.cc b/webrtc/modules/audio_processing/test/conversational_speech/generator.cc index c7f86dec1e..53f7217c26 100644 --- a/webrtc/modules/audio_processing/test/conversational_speech/generator.cc +++ b/webrtc/modules/audio_processing/test/conversational_speech/generator.cc @@ -10,12 +10,12 @@ #include -#include "gflags/gflags.h" #include "webrtc/modules/audio_processing/test/conversational_speech/config.h" #include "webrtc/modules/audio_processing/test/conversational_speech/multiend_call.h" #include "webrtc/modules/audio_processing/test/conversational_speech/simulator.h" #include "webrtc/modules/audio_processing/test/conversational_speech/timing.h" #include "webrtc/modules/audio_processing/test/conversational_speech/wavreader_factory.h" +#include "webrtc/rtc_base/flags.h" #include "webrtc/rtc_base/ptr_util.h" #include "webrtc/test/testsupport/fileutils.h" @@ -23,14 +23,6 @@ namespace webrtc { namespace test { namespace { -// Adapting DirExists/FileExists interfaces to DEFINE_validator. -auto dir_exists = [](const char* c, const std::string& dirpath) { - return DirExists(dirpath); -}; -auto file_exists = [](const char* c, const std::string& filepath) { - return FileExists(filepath); -}; - const char kUsageDescription[] = "Usage: conversational_speech_generator\n" " -i \n" @@ -38,21 +30,30 @@ const char kUsageDescription[] = " -o \n" "\n\n" "Command-line tool to generate multiple-end audio tracks to simulate " - "conversational speech with two or more participants."; + "conversational speech with two or more participants.\n"; DEFINE_string(i, "", "Directory containing the speech turn wav files"); -DEFINE_validator(i, dir_exists); DEFINE_string(t, "", "Path to the timing text file"); -DEFINE_validator(t, file_exists); DEFINE_string(o, "", "Output wav files destination path"); -DEFINE_validator(o, dir_exists); +DEFINE_bool(help, false, "Prints this message"); } // namespace int main(int argc, char* argv[]) { - google::SetUsageMessage(kUsageDescription); - google::ParseCommandLineFlags(&argc, &argv, true); - conversational_speech::Config config(FLAGS_i, FLAGS_t, FLAGS_o); + if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true) || + FLAG_help || argc != 1) { + printf("%s", kUsageDescription); + if (FLAG_help) { + rtc::FlagList::Print(nullptr, false); + return 0; + } + return 1; + } + RTC_CHECK(DirExists(FLAG_i)); + RTC_CHECK(FileExists(FLAG_t)); + RTC_CHECK(DirExists(FLAG_o)); + + conversational_speech::Config config(FLAG_i, FLAG_t, FLAG_o); // Load timing. std::vector timing = diff --git a/webrtc/modules/audio_processing/test/py_quality_assessment/apm_quality_assessment_gencfgs.py b/webrtc/modules/audio_processing/test/py_quality_assessment/apm_quality_assessment_gencfgs.py index d2764b06d1..338c38c106 100755 --- a/webrtc/modules/audio_processing/test/py_quality_assessment/apm_quality_assessment_gencfgs.py +++ b/webrtc/modules/audio_processing/test/py_quality_assessment/apm_quality_assessment_gencfgs.py @@ -27,7 +27,7 @@ def _GenerateDefaultOverridden(config_override): The default settings are loaded via "-all_default". Check "src/webrtc/modules/audio_processing/test/audioproc_float.cc" and search - for "if (FLAGS_all_default) {". + for "if (FLAG_all_default) {". For instance, in 55eb6d621489730084927868fed195d3645a9ec9 the default is this: settings.use_aec = rtc::Optional(true); diff --git a/webrtc/modules/audio_processing/test/unpack.cc b/webrtc/modules/audio_processing/test/unpack.cc index 4c6c18dc47..13be279811 100644 --- a/webrtc/modules/audio_processing/test/unpack.cc +++ b/webrtc/modules/audio_processing/test/unpack.cc @@ -17,9 +17,9 @@ #include -#include "gflags/gflags.h" #include "webrtc/modules/audio_processing/test/protobuf_utils.h" #include "webrtc/modules/audio_processing/test/test_utils.h" +#include "webrtc/rtc_base/flags.h" #include "webrtc/rtc_base/format_macros.h" #include "webrtc/rtc_base/ignore_wundef.h" #include "webrtc/typedefs.h" @@ -45,6 +45,7 @@ DEFINE_bool(raw, false, "Write raw data instead of a WAV file."); DEFINE_bool(text, false, "Write non-audio files as text files instead of binary files."); +DEFINE_bool(help, false, "Print this message."); #define PRINT_CONFIG(field_name) \ if (msg.has_##field_name()) { \ @@ -70,11 +71,14 @@ int do_main(int argc, char* argv[]) { std::string program_name = argv[0]; std::string usage = "Commandline tool to unpack audioproc debug files.\n" "Example usage:\n" + program_name + " debug_dump.pb\n"; - google::SetUsageMessage(usage); - google::ParseCommandLineFlags(&argc, &argv, true); - if (argc < 2) { - printf("%s", google::ProgramUsage()); + if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true) || + FLAG_help || argc < 2) { + printf("%s", usage.c_str()); + if (FLAG_help) { + rtc::FlagList::Print(nullptr, false); + return 0; + } return 1; } @@ -95,7 +99,7 @@ int do_main(int argc, char* argv[]) { std::unique_ptr input_raw_file; std::unique_ptr output_raw_file; - FILE* settings_file = OpenFile(FLAGS_settings_file, "wb"); + FILE* settings_file = OpenFile(FLAG_settings_file, "wb"); while (ReadMessageFromFile(debug_file, &event_msg)) { if (event_msg.type() == Event::REVERSE_STREAM) { @@ -106,8 +110,9 @@ int do_main(int argc, char* argv[]) { const ReverseStream msg = event_msg.reverse_stream(); if (msg.has_data()) { - if (FLAGS_raw && !reverse_raw_file) { - reverse_raw_file.reset(new RawFile(FLAGS_reverse_file + ".pcm")); + if (FLAG_raw && !reverse_raw_file) { + reverse_raw_file.reset(new RawFile(std::string(FLAG_reverse_file) + + ".pcm")); } // TODO(aluebs): Replace "num_reverse_channels * // reverse_samples_per_channel" with "msg.data().size() / @@ -118,8 +123,9 @@ int do_main(int argc, char* argv[]) { reverse_wav_file.get(), reverse_raw_file.get()); } else if (msg.channel_size() > 0) { - if (FLAGS_raw && !reverse_raw_file) { - reverse_raw_file.reset(new RawFile(FLAGS_reverse_file + ".float")); + if (FLAG_raw && !reverse_raw_file) { + reverse_raw_file.reset(new RawFile(std::string(FLAG_reverse_file) + + ".float")); } std::unique_ptr data( new const float* [num_reverse_channels]); @@ -141,16 +147,18 @@ int do_main(int argc, char* argv[]) { const Stream msg = event_msg.stream(); if (msg.has_input_data()) { - if (FLAGS_raw && !input_raw_file) { - input_raw_file.reset(new RawFile(FLAGS_input_file + ".pcm")); + if (FLAG_raw && !input_raw_file) { + input_raw_file.reset(new RawFile(std::string(FLAG_input_file) + + ".pcm")); } WriteIntData(reinterpret_cast(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 (FLAGS_raw && !input_raw_file) { - input_raw_file.reset(new RawFile(FLAGS_input_file + ".float")); + if (FLAG_raw && !input_raw_file) { + input_raw_file.reset(new RawFile(std::string(FLAG_input_file) + + ".float")); } std::unique_ptr data( new const float* [num_input_channels]); @@ -165,16 +173,18 @@ int do_main(int argc, char* argv[]) { } if (msg.has_output_data()) { - if (FLAGS_raw && !output_raw_file) { - output_raw_file.reset(new RawFile(FLAGS_output_file + ".pcm")); + if (FLAG_raw && !output_raw_file) { + output_raw_file.reset(new RawFile(std::string(FLAG_output_file) + + ".pcm")); } WriteIntData(reinterpret_cast(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 (FLAGS_raw && !output_raw_file) { - output_raw_file.reset(new RawFile(FLAGS_output_file + ".float")); + if (FLAG_raw && !output_raw_file) { + output_raw_file.reset(new RawFile(std::string(FLAG_output_file) + + ".float")); } std::unique_ptr data( new const float* [num_output_channels]); @@ -189,45 +199,45 @@ int do_main(int argc, char* argv[]) { output_raw_file.get()); } - if (FLAGS_full) { + if (FLAG_full) { if (msg.has_delay()) { - static FILE* delay_file = OpenFile(FLAGS_delay_file, "wb"); + static FILE* delay_file = OpenFile(FLAG_delay_file, "wb"); int32_t delay = msg.delay(); - if (FLAGS_text) { + if (FLAG_text) { fprintf(delay_file, "%d\n", delay); } else { - WriteData(&delay, sizeof(delay), delay_file, FLAGS_delay_file); + WriteData(&delay, sizeof(delay), delay_file, FLAG_delay_file); } } if (msg.has_drift()) { - static FILE* drift_file = OpenFile(FLAGS_drift_file, "wb"); + static FILE* drift_file = OpenFile(FLAG_drift_file, "wb"); int32_t drift = msg.drift(); - if (FLAGS_text) { + if (FLAG_text) { fprintf(drift_file, "%d\n", drift); } else { - WriteData(&drift, sizeof(drift), drift_file, FLAGS_drift_file); + WriteData(&drift, sizeof(drift), drift_file, FLAG_drift_file); } } if (msg.has_level()) { - static FILE* level_file = OpenFile(FLAGS_level_file, "wb"); + static FILE* level_file = OpenFile(FLAG_level_file, "wb"); int32_t level = msg.level(); - if (FLAGS_text) { + if (FLAG_text) { fprintf(level_file, "%d\n", level); } else { - WriteData(&level, sizeof(level), level_file, FLAGS_level_file); + WriteData(&level, sizeof(level), level_file, FLAG_level_file); } } if (msg.has_keypress()) { - static FILE* keypress_file = OpenFile(FLAGS_keypress_file, "wb"); + static FILE* keypress_file = OpenFile(FLAG_keypress_file, "wb"); bool keypress = msg.keypress(); - if (FLAGS_text) { + if (FLAG_text) { fprintf(keypress_file, "%d\n", keypress); } else { WriteData(&keypress, sizeof(keypress), keypress_file, - FLAGS_keypress_file); + FLAG_keypress_file); } } } @@ -304,21 +314,21 @@ int do_main(int argc, char* argv[]) { output_samples_per_channel = static_cast(output_sample_rate / 100); - if (!FLAGS_raw) { + if (!FLAG_raw) { // The WAV files need to be reset every time, because they cant change // their sample rate or number of channels. std::stringstream reverse_name; - reverse_name << FLAGS_reverse_file << frame_count << ".wav"; + reverse_name << FLAG_reverse_file << frame_count << ".wav"; reverse_wav_file.reset(new WavWriter(reverse_name.str(), reverse_sample_rate, num_reverse_channels)); std::stringstream input_name; - input_name << FLAGS_input_file << frame_count << ".wav"; + input_name << FLAG_input_file << frame_count << ".wav"; input_wav_file.reset(new WavWriter(input_name.str(), input_sample_rate, num_input_channels)); std::stringstream output_name; - output_name << FLAGS_output_file << frame_count << ".wav"; + output_name << FLAG_output_file << frame_count << ".wav"; output_wav_file.reset(new WavWriter(output_name.str(), output_sample_rate, num_output_channels)); diff --git a/webrtc/modules/audio_processing/transient/transient_suppression_test.cc b/webrtc/modules/audio_processing/transient/transient_suppression_test.cc index 2158a81158..ea894bc12d 100644 --- a/webrtc/modules/audio_processing/transient/transient_suppression_test.cc +++ b/webrtc/modules/audio_processing/transient/transient_suppression_test.cc @@ -12,14 +12,15 @@ #include #include +#include #include #include -#include "gflags/gflags.h" #include "webrtc/common_audio/include/audio_util.h" #include "webrtc/modules/audio_processing/agc/agc.h" #include "webrtc/modules/include/module_common_types.h" +#include "webrtc/rtc_base/flags.h" #include "webrtc/test/gtest.h" #include "webrtc/test/testsupport/fileutils.h" #include "webrtc/typedefs.h" @@ -32,31 +33,20 @@ DEFINE_string(reference_file_name, "", "PCM file that contains the reference signal."); -static bool ValidatePositiveInt(const char* flagname, int32_t value) { - if (value <= 0) { - printf("%s must be a positive integer.\n", flagname); - return false; - } - return true; -} -DEFINE_int32(chunk_size_ms, - 10, - "Time between each chunk of samples in milliseconds."); -static const bool chunk_size_ms_dummy = - google::RegisterFlagValidator(&FLAGS_chunk_size_ms, &ValidatePositiveInt); +DEFINE_int(chunk_size_ms, + 10, + "Time between each chunk of samples in milliseconds."); -DEFINE_int32(sample_rate_hz, - 16000, - "Sampling frequency of the signal in Hertz."); -static const bool sample_rate_hz_dummy = - google::RegisterFlagValidator(&FLAGS_sample_rate_hz, &ValidatePositiveInt); -DEFINE_int32(detection_rate_hz, - 0, - "Sampling frequency of the detection signal in Hertz."); +DEFINE_int(sample_rate_hz, + 16000, + "Sampling frequency of the signal in Hertz."); +DEFINE_int(detection_rate_hz, + 0, + "Sampling frequency of the detection signal in Hertz."); -DEFINE_int32(num_channels, 1, "Number of channels."); -static const bool num_channels_dummy = - google::RegisterFlagValidator(&FLAGS_num_channels, &ValidatePositiveInt); +DEFINE_int(num_channels, 1, "Number of channels."); + +DEFINE_bool(help, false, "Print this message."); namespace webrtc { @@ -146,19 +136,19 @@ static void WritePCM(FILE* f, void void_main() { // TODO(aluebs): Remove all FileWrappers. // Prepare the input file. - FILE* in_file = fopen(FLAGS_in_file_name.c_str(), "rb"); + FILE* in_file = fopen(FLAG_in_file_name, "rb"); ASSERT_TRUE(in_file != NULL); // Prepare the detection file. FILE* detection_file = NULL; - if (!FLAGS_detection_file_name.empty()) { - detection_file = fopen(FLAGS_detection_file_name.c_str(), "rb"); + if (strlen(FLAG_detection_file_name) > 0) { + detection_file = fopen(FLAG_detection_file_name, "rb"); } // Prepare the reference file. FILE* reference_file = NULL; - if (!FLAGS_reference_file_name.empty()) { - reference_file = fopen(FLAGS_reference_file_name.c_str(), "rb"); + if (strlen(FLAG_reference_file_name) > 0) { + reference_file = fopen(FLAG_reference_file_name, "rb"); } // Prepare the output file. @@ -166,27 +156,27 @@ void void_main() { FILE* out_file = fopen(out_file_name.c_str(), "wb"); ASSERT_TRUE(out_file != NULL); - int detection_rate_hz = FLAGS_detection_rate_hz; + int detection_rate_hz = FLAG_detection_rate_hz; if (detection_rate_hz == 0) { - detection_rate_hz = FLAGS_sample_rate_hz; + detection_rate_hz = FLAG_sample_rate_hz; } Agc agc; TransientSuppressor suppressor; suppressor.Initialize( - FLAGS_sample_rate_hz, detection_rate_hz, FLAGS_num_channels); + FLAG_sample_rate_hz, detection_rate_hz, FLAG_num_channels); const size_t audio_buffer_size = - FLAGS_chunk_size_ms * FLAGS_sample_rate_hz / 1000; + FLAG_chunk_size_ms * FLAG_sample_rate_hz / 1000; const size_t detection_buffer_size = - FLAGS_chunk_size_ms * detection_rate_hz / 1000; + FLAG_chunk_size_ms * detection_rate_hz / 1000; // int16 and float variants of the same data. std::unique_ptr audio_buffer_i( - new int16_t[FLAGS_num_channels * audio_buffer_size]); + new int16_t[FLAG_num_channels * audio_buffer_size]); std::unique_ptr audio_buffer_f( - new float[FLAGS_num_channels * audio_buffer_size]); + new float[FLAG_num_channels * audio_buffer_size]); std::unique_ptr detection_buffer, reference_buffer; @@ -197,7 +187,7 @@ void void_main() { while (ReadBuffers(in_file, audio_buffer_size, - FLAGS_num_channels, + FLAG_num_channels, audio_buffer_i.get(), detection_file, detection_buffer_size, @@ -207,17 +197,17 @@ void void_main() { ASSERT_EQ(0, agc.Process(audio_buffer_i.get(), static_cast(audio_buffer_size), - FLAGS_sample_rate_hz)) + FLAG_sample_rate_hz)) << "The AGC could not process the frame"; - for (size_t i = 0; i < FLAGS_num_channels * audio_buffer_size; ++i) { + for (size_t i = 0; i < FLAG_num_channels * audio_buffer_size; ++i) { audio_buffer_f[i] = audio_buffer_i[i]; } ASSERT_EQ(0, suppressor.Suppress(audio_buffer_f.get(), audio_buffer_size, - FLAGS_num_channels, + FLAG_num_channels, detection_buffer.get(), detection_buffer_size, reference_buffer.get(), @@ -228,7 +218,7 @@ void void_main() { // Write result to out file. WritePCM( - out_file, audio_buffer_size, FLAGS_num_channels, audio_buffer_f.get()); + out_file, audio_buffer_size, FLAG_num_channels, audio_buffer_f.get()); } fclose(in_file); @@ -244,8 +234,19 @@ void void_main() { } // namespace webrtc int main(int argc, char* argv[]) { - google::SetUsageMessage(webrtc::kUsage); - google::ParseCommandLineFlags(&argc, &argv, true); + if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true) || + FLAG_help || argc != 1) { + printf("%s", webrtc::kUsage); + if (FLAG_help) { + rtc::FlagList::Print(nullptr, false); + return 0; + } + return 1; + } + RTC_CHECK_GT(FLAG_chunk_size_ms, 0); + RTC_CHECK_GT(FLAG_sample_rate_hz, 0); + RTC_CHECK_GT(FLAG_num_channels, 0); + webrtc::void_main(); return 0; } diff --git a/webrtc/modules/remote_bitrate_estimator/BUILD.gn b/webrtc/modules/remote_bitrate_estimator/BUILD.gn index 2de783028f..f13e8fcb0a 100644 --- a/webrtc/modules/remote_bitrate_estimator/BUILD.gn +++ b/webrtc/modules/remote_bitrate_estimator/BUILD.gn @@ -225,7 +225,6 @@ if (rtc_include_tests) { "../../test:test_main", "//testing/gmock", "//testing/gtest", - "//third_party/gflags", ] if (!build_with_chromium && is_clang) { diff --git a/webrtc/modules/remote_bitrate_estimator/tools/bwe_rtp.cc b/webrtc/modules/remote_bitrate_estimator/tools/bwe_rtp.cc index 2b2e2653d6..de0d5ea9e0 100644 --- a/webrtc/modules/remote_bitrate_estimator/tools/bwe_rtp.cc +++ b/webrtc/modules/remote_bitrate_estimator/tools/bwe_rtp.cc @@ -16,11 +16,11 @@ #include #include -#include "gflags/gflags.h" #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_send_time.h" #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_single_stream.h" #include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h" #include "webrtc/modules/rtp_rtcp/include/rtp_payload_registry.h" +#include "webrtc/rtc_base/flags.h" #include "webrtc/test/rtp_file_reader.h" namespace flags { @@ -30,17 +30,17 @@ DEFINE_string(extension_type, "Extension type, either abs for absolute send time or tsoffset " "for timestamp offset."); std::string ExtensionType() { - return static_cast(FLAGS_extension_type); + return static_cast(FLAG_extension_type); } -DEFINE_int32(extension_id, 3, "Extension id."); +DEFINE_int(extension_id, 3, "Extension id."); int ExtensionId() { - return static_cast(FLAGS_extension_id); + return static_cast(FLAG_extension_id); } DEFINE_string(input_file, "", "Input file."); std::string InputFile() { - return static_cast(FLAGS_input_file); + return static_cast(FLAG_input_file); } DEFINE_string(ssrc_filter, @@ -48,7 +48,7 @@ DEFINE_string(ssrc_filter, "Comma-separated list of SSRCs in hexadecimal which are to be " "used as input to the BWE (only applicable to pcap files)."); std::set SsrcFilter() { - std::string ssrc_filter_string = static_cast(FLAGS_ssrc_filter); + std::string ssrc_filter_string = static_cast(FLAG_ssrc_filter); if (ssrc_filter_string.empty()) return std::set(); std::stringstream ss; @@ -64,6 +64,8 @@ std::set SsrcFilter() { } return ssrcs; } + +DEFINE_bool(help, false, "Print this message."); } // namespace flags bool ParseArgsAndSetupEstimator(int argc, @@ -74,7 +76,13 @@ bool ParseArgsAndSetupEstimator(int argc, webrtc::RtpHeaderParser** parser, webrtc::RemoteBitrateEstimator** estimator, std::string* estimator_used) { - google::ParseCommandLineFlags(&argc, &argv, true); + if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true)) { + return 1; + } + if (FLAG_help) { + rtc::FlagList::Print(nullptr, false); + return 0; + } std::string filename = flags::InputFile(); std::set ssrc_filter = flags::SsrcFilter(); diff --git a/webrtc/modules/video_coding/BUILD.gn b/webrtc/modules/video_coding/BUILD.gn index 12f2f366be..d4fb6e4be1 100644 --- a/webrtc/modules/video_coding/BUILD.gn +++ b/webrtc/modules/video_coding/BUILD.gn @@ -350,7 +350,6 @@ if (rtc_include_tests) { "../../test:video_test_common", "../../test:video_test_support", "../video_capture", - "//third_party/gflags", ] } # video_quality_measurement diff --git a/webrtc/modules/video_coding/codecs/tools/video_quality_measurement.cc b/webrtc/modules/video_coding/codecs/tools/video_quality_measurement.cc index 48929b9df9..f82ba42803 100644 --- a/webrtc/modules/video_coding/codecs/tools/video_quality_measurement.cc +++ b/webrtc/modules/video_coding/codecs/tools/video_quality_measurement.cc @@ -11,6 +11,7 @@ #include #include #include +#include #include #include // To check for directory existence. @@ -19,13 +20,13 @@ #define S_ISDIR(mode) (((mode)&S_IFMT) == S_IFDIR) #endif -#include "gflags/gflags.h" #include "webrtc/common_types.h" #include "webrtc/modules/video_coding/codecs/test/packet_manipulator.h" #include "webrtc/modules/video_coding/codecs/test/stats.h" #include "webrtc/modules/video_coding/codecs/test/videoprocessor.h" #include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h" #include "webrtc/modules/video_coding/include/video_coding.h" +#include "webrtc/rtc_base/flags.h" #include "webrtc/rtc_base/format_macros.h" #include "webrtc/test/testsupport/frame_reader.h" #include "webrtc/test/testsupport/frame_writer.h" @@ -43,12 +44,12 @@ DEFINE_string(input_filename, "Input file. " "The source video file to be encoded and decoded. Must be in " ".yuv format"); -DEFINE_int32(width, -1, "Width in pixels of the frames in the input file."); -DEFINE_int32(height, -1, "Height in pixels of the frames in the input file."); -DEFINE_int32(framerate, - 30, - "Frame rate of the input file, in FPS " - "(frames-per-second). "); +DEFINE_int(width, -1, "Width in pixels of the frames in the input file."); +DEFINE_int(height, -1, "Height in pixels of the frames in the input file."); +DEFINE_int(framerate, + 30, + "Frame rate of the input file, in FPS " + "(frames-per-second). "); DEFINE_string(output_dir, ".", "Output directory. " @@ -76,40 +77,40 @@ DEFINE_string(output_filename, "The name of the output video file resulting of the processing " "of the source file. By default this is the same name as the " "input file with '_out' appended before the extension."); -DEFINE_int32(bitrate, 500, "Bit rate in kilobits/second."); -DEFINE_int32(keyframe_interval, - 0, - "Forces a keyframe every Nth frame. " - "0 means the encoder decides when to insert keyframes. Note that " - "the encoder may create a keyframe in other locations in addition " - "to the interval that is set using this parameter."); -DEFINE_int32(temporal_layers, - 0, - "The number of temporal layers to use " - "(VP8 specific codec setting). Must be 0-4."); -DEFINE_int32(packet_size, - 1500, - "Simulated network packet size in bytes (MTU). " - "Used for packet loss simulation."); -DEFINE_int32(max_payload_size, - 1440, - "Max payload size in bytes for the " - "encoder."); +DEFINE_int(bitrate, 500, "Bit rate in kilobits/second."); +DEFINE_int(keyframe_interval, + 0, + "Forces a keyframe every Nth frame. " + "0 means the encoder decides when to insert keyframes. Note that " + "the encoder may create a keyframe in other locations in addition " + "to the interval that is set using this parameter."); +DEFINE_int(temporal_layers, + 0, + "The number of temporal layers to use " + "(VP8 specific codec setting). Must be 0-4."); +DEFINE_int(packet_size, + 1500, + "Simulated network packet size in bytes (MTU). " + "Used for packet loss simulation."); +DEFINE_int(max_payload_size, + 1440, + "Max payload size in bytes for the " + "encoder."); DEFINE_string(packet_loss_mode, "uniform", "Packet loss mode. Two different " "packet loss models are supported: uniform or burst. This " "setting has no effect unless packet_loss_rate is >0. "); -DEFINE_double(packet_loss_probability, - 0.0, - "Packet loss probability. A value " - "between 0.0 and 1.0 that defines the probability of a packet " - "being lost. 0.1 means 10% and so on."); -DEFINE_int32(packet_loss_burst_length, - 1, - "Packet loss burst length. Defines " - "how many packets will be lost in a burst when a packet has been " - "decided to be lost. Must be >=1."); +DEFINE_float(packet_loss_probability, + 0.0f, + "Packet loss probability. A value " + "between 0.0 and 1.0 that defines the probability of a packet " + "being lost. 0.1 means 10% and so on."); +DEFINE_int(packet_loss_burst_length, + 1, + "Packet loss burst length. Defines " + "how many packets will be lost in a burst when a packet has been " + "decided to be lost. Must be >=1."); DEFINE_bool(csv, false, "CSV output. Enabling this will output all frame " @@ -126,12 +127,13 @@ DEFINE_bool(verbose, "Verbose mode. Prints a lot of debugging info. " "Suitable for tracking progress but not for capturing output. " "Disable with --noverbose flag."); +DEFINE_bool(help, false, "Prints this message."); // Custom log method that only prints if the verbose flag is given. // Supports all the standard printf parameters and formatting (just forwarded). int Log(const char* format, ...) { int result = 0; - if (FLAGS_verbose) { + if (FLAG_verbose) { va_list args; va_start(args, format); result = vprintf(format, args); @@ -143,55 +145,58 @@ int Log(const char* format, ...) { // Validates the arguments given as command line flags and fills in the // TestConfig struct with all configurations needed for video processing. // Returns 0 if everything is OK, otherwise an exit code. -int HandleCommandLineFlags(webrtc::test::TestConfig* config) { +int HandleCommandLineFlags(webrtc::test::TestConfig* config, + const std::string& usage) { // Validate the mandatory flags: - if (FLAGS_input_filename.empty() || FLAGS_width == -1 || FLAGS_height == -1) { - printf("%s\n", google::ProgramUsage()); + if (strlen(FLAG_input_filename) == 0 || + FLAG_width == -1 || FLAG_height == -1) { + printf("%s\n", usage.c_str()); return 1; } - config->name = FLAGS_test_name; - config->description = FLAGS_test_description; + config->name = FLAG_test_name; + config->description = FLAG_test_description; // Verify the input file exists and is readable. FILE* test_file; - test_file = fopen(FLAGS_input_filename.c_str(), "rb"); + test_file = fopen(FLAG_input_filename, "rb"); if (test_file == NULL) { fprintf(stderr, "Cannot read the specified input file: %s\n", - FLAGS_input_filename.c_str()); + FLAG_input_filename); return 2; } fclose(test_file); - config->input_filename = FLAGS_input_filename; + config->input_filename = FLAG_input_filename; // Verify the output dir exists. struct stat dir_info; - if (!(stat(FLAGS_output_dir.c_str(), &dir_info) == 0 && + if (!(stat(FLAG_output_dir, &dir_info) == 0 && S_ISDIR(dir_info.st_mode))) { fprintf(stderr, "Cannot find output directory: %s\n", - FLAGS_output_dir.c_str()); + FLAG_output_dir); return 3; } - config->output_dir = FLAGS_output_dir; + config->output_dir = FLAG_output_dir; // Manufacture an output filename if none was given. - if (FLAGS_output_filename.empty()) { + if (strlen(FLAG_output_filename) == 0) { // Cut out the filename without extension from the given input file // (which may include a path) - size_t startIndex = FLAGS_input_filename.find_last_of("/") + 1; + size_t startIndex = config->input_filename.find_last_of("/") + 1; if (startIndex == 0) { startIndex = 0; } - FLAGS_output_filename = - FLAGS_input_filename.substr( - startIndex, FLAGS_input_filename.find_last_of(".") - startIndex) + + config->output_filename = + config->input_filename.substr( + startIndex, config->input_filename.find_last_of(".") - startIndex) + "_out.yuv"; + } else { + config->output_filename = FLAG_output_filename; } // Verify output file can be written. - if (FLAGS_output_dir == ".") { - config->output_filename = FLAGS_output_filename; - } else { - config->output_filename = FLAGS_output_dir + "/" + FLAGS_output_filename; + if (config->output_dir != ".") { + config->output_filename = + config->output_dir + "/" + config->output_filename; } test_file = fopen(config->output_filename.c_str(), "wb"); if (test_file == NULL) { @@ -202,99 +207,98 @@ int HandleCommandLineFlags(webrtc::test::TestConfig* config) { fclose(test_file); // Check single core flag. - config->use_single_core = FLAGS_use_single_core; + config->use_single_core = FLAG_use_single_core; // Get codec specific configuration. webrtc::test::CodecSettings(webrtc::kVideoCodecVP8, &config->codec_settings); // Check the temporal layers. - if (FLAGS_temporal_layers < 0 || - FLAGS_temporal_layers > webrtc::kMaxTemporalStreams) { + if (FLAG_temporal_layers < 0 || + FLAG_temporal_layers > webrtc::kMaxTemporalStreams) { fprintf(stderr, "Temporal layers number must be 0-4, was: %d\n", - FLAGS_temporal_layers); + FLAG_temporal_layers); return 13; } - config->codec_settings.VP8()->numberOfTemporalLayers = FLAGS_temporal_layers; + config->codec_settings.VP8()->numberOfTemporalLayers = FLAG_temporal_layers; // Check the bit rate. - if (FLAGS_bitrate <= 0) { - fprintf(stderr, "Bit rate must be >0 kbps, was: %d\n", FLAGS_bitrate); + if (FLAG_bitrate <= 0) { + fprintf(stderr, "Bit rate must be >0 kbps, was: %d\n", FLAG_bitrate); return 5; } - config->codec_settings.startBitrate = FLAGS_bitrate; + config->codec_settings.startBitrate = FLAG_bitrate; // Check the keyframe interval. - if (FLAGS_keyframe_interval < 0) { + if (FLAG_keyframe_interval < 0) { fprintf(stderr, "Keyframe interval must be >=0, was: %d\n", - FLAGS_keyframe_interval); + FLAG_keyframe_interval); return 6; } - config->keyframe_interval = FLAGS_keyframe_interval; + config->keyframe_interval = FLAG_keyframe_interval; // Check packet size and max payload size. - if (FLAGS_packet_size <= 0) { + if (FLAG_packet_size <= 0) { fprintf(stderr, "Packet size must be >0 bytes, was: %d\n", - FLAGS_packet_size); + FLAG_packet_size); return 7; } config->networking_config.packet_size_in_bytes = - static_cast(FLAGS_packet_size); + static_cast(FLAG_packet_size); - if (FLAGS_max_payload_size <= 0) { + if (FLAG_max_payload_size <= 0) { fprintf(stderr, "Max payload size must be >0 bytes, was: %d\n", - FLAGS_max_payload_size); + FLAG_max_payload_size); return 8; } config->networking_config.max_payload_size_in_bytes = - static_cast(FLAGS_max_payload_size); + static_cast(FLAG_max_payload_size); // Check the width and height - if (FLAGS_width <= 0 || FLAGS_height <= 0) { + if (FLAG_width <= 0 || FLAG_height <= 0) { fprintf(stderr, "Width and height must be >0."); return 9; } - config->codec_settings.width = FLAGS_width; - config->codec_settings.height = FLAGS_height; - config->codec_settings.maxFramerate = FLAGS_framerate; + config->codec_settings.width = FLAG_width; + config->codec_settings.height = FLAG_height; + config->codec_settings.maxFramerate = FLAG_framerate; // Calculate the size of each frame to read (according to YUV spec). config->frame_length_in_bytes = 3 * config->codec_settings.width * config->codec_settings.height / 2; // Check packet loss settings - if (FLAGS_packet_loss_mode != "uniform" && - FLAGS_packet_loss_mode != "burst") { + if (strcmp(FLAG_packet_loss_mode, "uniform") == 0) { + config->networking_config.packet_loss_mode = webrtc::test::kUniform; + } else if (strcmp(FLAG_packet_loss_mode, "burst") == 0) { + config->networking_config.packet_loss_mode = webrtc::test::kBurst; + } else { fprintf(stderr, "Unsupported packet loss mode, must be 'uniform' or " "'burst'\n."); return 10; } - config->networking_config.packet_loss_mode = webrtc::test::kUniform; - if (FLAGS_packet_loss_mode == "burst") { - config->networking_config.packet_loss_mode = webrtc::test::kBurst; - } - if (FLAGS_packet_loss_probability < 0.0 || - FLAGS_packet_loss_probability > 1.0) { + if (FLAG_packet_loss_probability < 0.0 || + FLAG_packet_loss_probability > 1.0) { fprintf(stderr, "Invalid packet loss probability. Must be 0.0 - 1.0, " "was: %f\n", - FLAGS_packet_loss_probability); + FLAG_packet_loss_probability); return 11; } config->networking_config.packet_loss_probability = - FLAGS_packet_loss_probability; + FLAG_packet_loss_probability; - if (FLAGS_packet_loss_burst_length < 1) { + if (FLAG_packet_loss_burst_length < 1) { fprintf(stderr, "Invalid packet loss burst length, must be >=1, " "was: %d\n", - FLAGS_packet_loss_burst_length); + FLAG_packet_loss_burst_length); return 12; } config->networking_config.packet_loss_burst_length = - FLAGS_packet_loss_burst_length; - config->verbose = FLAGS_verbose; + FLAG_packet_loss_burst_length; + config->verbose = FLAG_verbose; return 0; } @@ -464,18 +468,21 @@ int main(int argc, char* argv[]) { "Quality test application for video comparisons.\n" "Run " + program_name + - " --helpshort for usage.\n" + " --help for usage.\n" "Example usage:\n" + program_name + " --input_filename=filename.yuv --width=352 --height=288\n"; - google::SetUsageMessage(usage); - google::ParseCommandLineFlags(&argc, &argv, true); + rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true); + if (FLAG_help) { + rtc::FlagList::Print(nullptr, false); + return 0; + } // Create TestConfig. webrtc::test::TestConfig config; - int return_code = HandleCommandLineFlags(&config); + int return_code = HandleCommandLineFlags(&config, usage); // Exit if an invalid argument is supplied. if (return_code != 0) { return return_code; @@ -500,7 +507,7 @@ int main(int argc, char* argv[]) { &packet_reader, config.networking_config, config.verbose); // By default the packet manipulator is seeded with a fixed random. // If disabled we must generate a new seed. - if (FLAGS_disable_fixed_random_seed) { + if (FLAG_disable_fixed_random_seed) { packet_manipulator.InitializeRandomSeed(time(NULL)); } webrtc::test::VideoProcessor* processor = new webrtc::test::VideoProcessor( @@ -539,10 +546,10 @@ int main(int argc, char* argv[]) { webrtc::test::QualityMetricsResult psnr_result; CalculatePsnrVideoMetrics(&config, &psnr_result); - if (FLAGS_csv) { + if (FLAG_csv) { PrintCsvOutput(stats, ssim_result, psnr_result); } - if (FLAGS_python) { + if (FLAG_python) { PrintPythonOutput(config, stats, ssim_result, psnr_result); } delete processor; diff --git a/webrtc/video/BUILD.gn b/webrtc/video/BUILD.gn index c85510567c..f3bba0ebf4 100644 --- a/webrtc/video/BUILD.gn +++ b/webrtc/video/BUILD.gn @@ -223,7 +223,6 @@ if (rtc_include_tests) { "../test:test_support", "../test:video_test_common", "../test:video_test_support", - "//third_party/gflags", ] if (!build_with_chromium && is_clang) { # Suppress warnings from the Chromium Clang plugin (bugs.webrtc.org/163). diff --git a/webrtc/video/replay.cc b/webrtc/video/replay.cc index e23ff2920f..5a391d69b0 100644 --- a/webrtc/video/replay.cc +++ b/webrtc/video/replay.cc @@ -14,13 +14,14 @@ #include #include -#include "gflags/gflags.h" #include "webrtc/api/video_codecs/video_decoder.h" #include "webrtc/call/call.h" #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" #include "webrtc/logging/rtc_event_log/rtc_event_log.h" #include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h" #include "webrtc/rtc_base/checks.h" +#include "webrtc/rtc_base/flags.h" +#include "webrtc/rtc_base/string_to_number.h" #include "webrtc/system_wrappers/include/clock.h" #include "webrtc/system_wrappers/include/sleep.h" #include "webrtc/test/call_test.h" @@ -36,121 +37,113 @@ #include "webrtc/test/video_renderer.h" #include "webrtc/typedefs.h" +namespace { + +static bool ValidatePayloadType(int32_t payload_type) { + return payload_type > 0 && payload_type <= 127; +} + +static bool ValidateSsrc(const char* ssrc_string) { + return rtc::StringToNumber(ssrc_string).has_value(); +} + +static bool ValidateOptionalPayloadType(int32_t payload_type) { + return payload_type == -1 || ValidatePayloadType(payload_type); +} + +static bool ValidateRtpHeaderExtensionId(int32_t extension_id) { + return extension_id >= -1 && extension_id < 15; +} + +bool ValidateInputFilenameNotEmpty(const std::string& string) { + return !string.empty(); +} + +} // namespace + namespace webrtc { namespace flags { // TODO(pbos): Multiple receivers. // Flag for payload type. -static bool ValidatePayloadType(const char* flagname, int32_t payload_type) { - return payload_type > 0 && payload_type <= 127; -} -DEFINE_int32(payload_type, test::CallTest::kPayloadTypeVP8, "Payload type"); -static int PayloadType() { return static_cast(FLAGS_payload_type); } -static const bool payload_dummy = - google::RegisterFlagValidator(&FLAGS_payload_type, &ValidatePayloadType); +DEFINE_int(payload_type, test::CallTest::kPayloadTypeVP8, "Payload type"); +static int PayloadType() { return static_cast(FLAG_payload_type); } -DEFINE_int32(payload_type_rtx, - test::CallTest::kSendRtxPayloadType, - "RTX payload type"); +DEFINE_int(payload_type_rtx, + test::CallTest::kSendRtxPayloadType, + "RTX payload type"); static int PayloadTypeRtx() { - return static_cast(FLAGS_payload_type_rtx); + return static_cast(FLAG_payload_type_rtx); } -static const bool payload_rtx_dummy = - google::RegisterFlagValidator(&FLAGS_payload_type_rtx, - &ValidatePayloadType); // Flag for SSRC. -static bool ValidateSsrc(const char* flagname, uint64_t ssrc) { - return ssrc > 0 && ssrc <= 0xFFFFFFFFu; +const std::string& DefaultSsrc() { + static const std::string ssrc = std::to_string( + test::CallTest::kVideoSendSsrcs[0]); + return ssrc; +} +DEFINE_string(ssrc, DefaultSsrc().c_str(), "Incoming SSRC"); +static uint32_t Ssrc() { + return rtc::StringToNumber(FLAG_ssrc).value(); } -DEFINE_uint64(ssrc, test::CallTest::kVideoSendSsrcs[0], "Incoming SSRC"); -static uint32_t Ssrc() { return static_cast(FLAGS_ssrc); } -static const bool ssrc_dummy = - google::RegisterFlagValidator(&FLAGS_ssrc, &ValidateSsrc); - -DEFINE_uint64(ssrc_rtx, test::CallTest::kSendRtxSsrcs[0], "Incoming RTX SSRC"); +const std::string& DefaultSsrcRtx() { + static const std::string ssrc_rtx = std::to_string( + test::CallTest::kSendRtxSsrcs[0]); + return ssrc_rtx; +} +DEFINE_string(ssrc_rtx, DefaultSsrcRtx().c_str(), "Incoming RTX SSRC"); static uint32_t SsrcRtx() { - return static_cast(FLAGS_ssrc_rtx); -} -static const bool ssrc_rtx_dummy = - google::RegisterFlagValidator(&FLAGS_ssrc_rtx, &ValidateSsrc); - -static bool ValidateOptionalPayloadType(const char* flagname, - int32_t payload_type) { - return payload_type == -1 || ValidatePayloadType(flagname, payload_type); + return rtc::StringToNumber(FLAG_ssrc_rtx).value(); } // Flag for RED payload type. -DEFINE_int32(red_payload_type, -1, "RED payload type"); +DEFINE_int(red_payload_type, -1, "RED payload type"); static int RedPayloadType() { - return static_cast(FLAGS_red_payload_type); + return static_cast(FLAG_red_payload_type); } -static const bool red_dummy = - google::RegisterFlagValidator(&FLAGS_red_payload_type, - &ValidateOptionalPayloadType); // Flag for ULPFEC payload type. -DEFINE_int32(fec_payload_type, -1, "ULPFEC payload type"); +DEFINE_int(fec_payload_type, -1, "ULPFEC payload type"); static int FecPayloadType() { - return static_cast(FLAGS_fec_payload_type); + return static_cast(FLAG_fec_payload_type); } -static const bool fec_dummy = - google::RegisterFlagValidator(&FLAGS_fec_payload_type, - &ValidateOptionalPayloadType); // Flag for abs-send-time id. -static bool ValidateRtpHeaderExtensionId(const char* flagname, - int32_t extension_id) { - return extension_id >= -1 || extension_id < 15; -} -DEFINE_int32(abs_send_time_id, -1, "RTP extension ID for abs-send-time"); -static int AbsSendTimeId() { return static_cast(FLAGS_abs_send_time_id); } -static const bool abs_send_time_dummy = - google::RegisterFlagValidator(&FLAGS_abs_send_time_id, - &ValidateRtpHeaderExtensionId); +DEFINE_int(abs_send_time_id, -1, "RTP extension ID for abs-send-time"); +static int AbsSendTimeId() { return static_cast(FLAG_abs_send_time_id); } // Flag for transmission-offset id. -DEFINE_int32(transmission_offset_id, - -1, - "RTP extension ID for transmission-offset"); +DEFINE_int(transmission_offset_id, + -1, + "RTP extension ID for transmission-offset"); static int TransmissionOffsetId() { - return static_cast(FLAGS_transmission_offset_id); + return static_cast(FLAG_transmission_offset_id); } -static const bool timestamp_offset_dummy = - google::RegisterFlagValidator(&FLAGS_transmission_offset_id, - &ValidateRtpHeaderExtensionId); // Flag for rtpdump input file. -bool ValidateInputFilenameNotEmpty(const char* flagname, - const std::string& string) { - return !string.empty(); -} - DEFINE_string(input_file, "", "input file"); static std::string InputFile() { - return static_cast(FLAGS_input_file); + return static_cast(FLAG_input_file); } -static const bool input_file_dummy = - google::RegisterFlagValidator(&FLAGS_input_file, - &ValidateInputFilenameNotEmpty); // Flag for raw output files. DEFINE_string(out_base, "", "Basename (excluding .jpg) for raw output"); static std::string OutBase() { - return static_cast(FLAGS_out_base); + return static_cast(FLAG_out_base); } DEFINE_string(decoder_bitstream_filename, "", "Decoder bitstream output file"); static std::string DecoderBitstreamFilename() { - return static_cast(FLAGS_decoder_bitstream_filename); + return static_cast(FLAG_decoder_bitstream_filename); } // Flag for video codec. DEFINE_string(codec, "VP8", "Video codec"); -static std::string Codec() { return static_cast(FLAGS_codec); } +static std::string Codec() { return static_cast(FLAG_codec); } +DEFINE_bool(help, false, "Print this message."); } // namespace flags static const uint32_t kReceiverLocalSsrc = 0x123456; @@ -330,7 +323,24 @@ void RtpReplay() { int main(int argc, char* argv[]) { ::testing::InitGoogleTest(&argc, argv); - google::ParseCommandLineFlags(&argc, &argv, true); + if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true)) { + return 1; + } + if (webrtc::flags::FLAG_help) { + rtc::FlagList::Print(nullptr, false); + return 0; + } + + RTC_CHECK(ValidatePayloadType(webrtc::flags::FLAG_payload_type)); + RTC_CHECK(ValidatePayloadType(webrtc::flags::FLAG_payload_type_rtx)); + RTC_CHECK(ValidateSsrc(webrtc::flags::FLAG_ssrc)); + RTC_CHECK(ValidateSsrc(webrtc::flags::FLAG_ssrc_rtx)); + RTC_CHECK(ValidateOptionalPayloadType(webrtc::flags::FLAG_red_payload_type)); + RTC_CHECK(ValidateOptionalPayloadType(webrtc::flags::FLAG_fec_payload_type)); + RTC_CHECK(ValidateRtpHeaderExtensionId(webrtc::flags::FLAG_abs_send_time_id)); + RTC_CHECK(ValidateRtpHeaderExtensionId( + webrtc::flags::FLAG_transmission_offset_id)); + RTC_CHECK(ValidateInputFilenameNotEmpty(webrtc::flags::FLAG_input_file)); webrtc::test::RunTest(webrtc::RtpReplay); return 0; diff --git a/webrtc/voice_engine/BUILD.gn b/webrtc/voice_engine/BUILD.gn index e458fee922..984d149d8d 100644 --- a/webrtc/voice_engine/BUILD.gn +++ b/webrtc/voice_engine/BUILD.gn @@ -260,7 +260,6 @@ if (rtc_include_tests) { "../test/:video_test_common", "//testing/gmock", "//testing/gtest", - "//third_party/gflags", ] sources = [ diff --git a/webrtc/voice_engine/test/auto_test/standard/rtp_rtcp_test.cc b/webrtc/voice_engine/test/auto_test/standard/rtp_rtcp_test.cc index 9af7f8653a..24bb0a7ed3 100644 --- a/webrtc/voice_engine/test/auto_test/standard/rtp_rtcp_test.cc +++ b/webrtc/voice_engine/test/auto_test/standard/rtp_rtcp_test.cc @@ -11,11 +11,14 @@ #include #include "webrtc/rtc_base/criticalsection.h" +#include "webrtc/rtc_base/flags.h" #include "webrtc/system_wrappers/include/event_wrapper.h" #include "webrtc/test/testsupport/fileutils.h" #include "webrtc/voice_engine/test/auto_test/fixtures/after_streaming_fixture.h" #include "webrtc/voice_engine/test/auto_test/voe_standard_test.h" +DECLARE_bool(include_timing_dependent_tests); + class TestRtpObserver : public webrtc::VoERTPObserver { public: TestRtpObserver() : changed_ssrc_event_(webrtc::EventWrapper::Create()) {} @@ -85,7 +88,7 @@ class RtpRtcpTest : public AfterStreamingFixture { }; TEST_F(RtpRtcpTest, RemoteRtcpCnameHasPropagatedToRemoteSide) { - if (!FLAGS_include_timing_dependent_tests) { + if (!FLAG_include_timing_dependent_tests) { TEST_LOG("Skipping test - running in slow execution environment...\n"); return; } diff --git a/webrtc/voice_engine/test/auto_test/voe_standard_test.cc b/webrtc/voice_engine/test/auto_test/voe_standard_test.cc index 5449a2f680..545be71619 100644 --- a/webrtc/voice_engine/test/auto_test/voe_standard_test.cc +++ b/webrtc/voice_engine/test/auto_test/voe_standard_test.cc @@ -14,6 +14,7 @@ #include #include +#include "webrtc/rtc_base/flags.h" #include "webrtc/system_wrappers/include/event_wrapper.h" #include "webrtc/typedefs.h" #include "webrtc/voice_engine/test/auto_test/automated_mode.h" @@ -26,6 +27,7 @@ DEFINE_bool(include_timing_dependent_tests, true, DEFINE_bool(automated, false, "If true, we'll run the automated tests we have in noninteractive " "mode."); +DEFINE_bool(help, false, "Print this message."); namespace webrtc { namespace voetest { @@ -101,9 +103,15 @@ int main(int argc, char** argv) { // This function and RunInAutomatedMode is defined in automated_mode.cc // to avoid macro clashes with googletest (for instance ASSERT_TRUE). webrtc::voetest::InitializeGoogleTest(&argc, 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; + } - if (FLAGS_automated) { + if (FLAG_automated) { return webrtc::voetest::RunInAutomatedMode(); } diff --git a/webrtc/voice_engine/test/auto_test/voe_standard_test.h b/webrtc/voice_engine/test/auto_test/voe_standard_test.h index 1fd27063b0..9eaed1c0b5 100644 --- a/webrtc/voice_engine/test/auto_test/voe_standard_test.h +++ b/webrtc/voice_engine/test/auto_test/voe_standard_test.h @@ -14,12 +14,9 @@ #include #include -#include "gflags/gflags.h" #include "webrtc/test/testsupport/fileutils.h" #include "webrtc/voice_engine/test/auto_test/voe_test_common.h" -DECLARE_bool(include_timing_dependent_tests); - namespace webrtc { namespace voetest {