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}
diff --git a/webrtc/modules/audio_coding/BUILD.gn b/webrtc/modules/audio_coding/BUILD.gn
index abe064f..50819f1 100644
--- a/webrtc/modules/audio_coding/BUILD.gn
+++ b/webrtc/modules/audio_coding/BUILD.gn
@@ -1395,7 +1395,6 @@
       "../../test:test_support",
       "../rtp_rtcp",
       "//testing/gtest",
-      "//third_party/gflags:gflags",
     ]
   }  # delay_test
 
@@ -1425,7 +1424,6 @@
       "../../test:test_support",
       "../rtp_rtcp",
       "//testing/gtest",
-      "//third_party/gflags:gflags",
     ]
   }  # insert_packet_with_timing
 
@@ -1520,7 +1518,6 @@
         "../../rtc_base:rtc_base_approved",
         "../../system_wrappers:system_wrappers_default",
         "../../test:test_support",
-        "//third_party/gflags",
       ]
     }
   }
@@ -1792,9 +1789,9 @@
       ":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 @@
       ":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 b835499..c58381f 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 <iostream>
 
-#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<int>(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<int>(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 @@
       "  --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 c11394b..d6647e4 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 <limits.h>  // For ULONG_MAX returned by strtoul.
 #include <stdio.h>
 #include <stdlib.h>  // For strtoul.
+#include <string.h>
 
 #include <algorithm>
 #include <ios>
@@ -21,7 +22,6 @@
 #include <numeric>
 #include <string>
 
-#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 @@
 }
 
 // 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<int>(value));
+  printf("Payload type must be between 0 and 127, not %d\n",
+         static_cast<int>(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<int>(value));
+  printf("Extension ID must be between 1 and 255, not %d\n",
+         static_cast<int>(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 @@
               "",
               "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 @@
   }
 }
 
-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<int> 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<int>(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<int>(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<int>(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<int>(48000);
-  if (payload_type == FLAGS_red)
+  if (payload_type == FLAG_red)
     return rtc::Optional<int>(0);
   return rtc::Optional<int>();
 }
@@ -460,31 +418,61 @@
 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<NetEqInput> input;
@@ -500,9 +488,9 @@
   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 @@
   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<AudioDecoder> 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 @@
     };
 
     std::set<uint8_t> 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<uint8_t> 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<InputAudioFile>(
-            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 @@
 
   NetEqTest::Callbacks callbacks;
   std::unique_ptr<NetEqDelayAnalyzer> delay_analyzer;
-  if (FLAGS_matlabplot) {
+  if (FLAG_matlabplot) {
     delay_analyzer.reset(new NetEqDelayAnalyzer);
   }
 
@@ -641,7 +629,7 @@
 
   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 74c64e0..23f96c5 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 <memory>
 #include <vector>
 
-#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<int>(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<int>(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 @@
       "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<webrtc::test::RtpFileSource> 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 @@
     }
     fprintf(out_file, "\n");
 
-    if (packet->header().payloadType == FLAGS_red) {
+    if (packet->header().payloadType == FLAG_red) {
       std::list<webrtc::RTPHeader*> 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 ce24493..0ce7fd2 100644
--- a/webrtc/modules/audio_coding/test/delay_test.cc
+++ b/webrtc/modules/audio_coding/test/delay_test.cc
@@ -10,11 +10,11 @@
 
 #include <assert.h>
 #include <math.h>
+#include <string.h>
 
 #include <iostream>
 #include <memory>
 
-#include "gflags/gflags.h"
 #include "webrtc/common_types.h"
 #include "webrtc/modules/audio_coding/codecs/audio_format_conversion.h"
 #include "webrtc/modules/audio_coding/include/audio_coding_module.h"
@@ -22,19 +22,21 @@
 #include "webrtc/modules/audio_coding/test/Channel.h"
 #include "webrtc/modules/audio_coding/test/PCMFile.h"
 #include "webrtc/modules/audio_coding/test/utility.h"
+#include "webrtc/rtc_base/flags.h"
 #include "webrtc/system_wrappers/include/event_wrapper.h"
 #include "webrtc/test/gtest.h"
 #include "webrtc/test/testsupport/fileutils.h"
 #include "webrtc/typedefs.h"
 
 DEFINE_string(codec, "isac", "Codec Name");
-DEFINE_int32(sample_rate_hz, 16000, "Sampling rate in Hertz.");
-DEFINE_int32(num_channels, 1, "Number of Channels.");
+DEFINE_int(sample_rate_hz, 16000, "Sampling rate in Hertz.");
+DEFINE_int(num_channels, 1, "Number of Channels.");
 DEFINE_string(input_file, "", "Input file, PCM16 32 kHz, optional.");
-DEFINE_int32(delay, 0, "Delay in millisecond.");
+DEFINE_int(delay, 0, "Delay in millisecond.");
 DEFINE_bool(dtx, false, "Enable DTX at the sender side.");
 DEFINE_bool(packet_loss, false, "Apply packet loss, c.f. Channel{.cc, .h}.");
 DEFINE_bool(fec, false, "Use Forward Error Correction (FEC).");
+DEFINE_bool(help, false, "Print this message.");
 
 namespace webrtc {
 
@@ -80,16 +82,16 @@
     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 @@
 
   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 @@
 }  // 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 4fa4e52..db58289 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 <stdio.h>
+#include <string.h>
 
 #include <memory>
 
-#include "gflags/gflags.h"
 #include "webrtc/common_types.h"
 #include "webrtc/modules/audio_coding/codecs/audio_format_conversion.h"
 #include "webrtc/modules/audio_coding/include/audio_coding_module.h"
 #include "webrtc/modules/audio_coding/test/Channel.h"
 #include "webrtc/modules/audio_coding/test/PCMFile.h"
 #include "webrtc/modules/include/module_common_types.h"
+#include "webrtc/rtc_base/flags.h"
 #include "webrtc/system_wrappers/include/clock.h"
 #include "webrtc/test/gtest.h"
 #include "webrtc/test/testsupport/fileutils.h"
 
 // Codec.
 DEFINE_string(codec, "opus", "Codec Name");
-DEFINE_int32(codec_sample_rate_hz, 48000, "Sampling rate in Hertz.");
-DEFINE_int32(codec_channels, 1, "Number of channels of the codec.");
+DEFINE_int(codec_sample_rate_hz, 48000, "Sampling rate in Hertz.");
+DEFINE_int(codec_channels, 1, "Number of channels of the codec.");
 
 // PCM input/output.
 DEFINE_string(input, "", "Input PCM file at 16 kHz.");
 DEFINE_bool(input_stereo, false, "Input is stereo.");
-DEFINE_int32(input_fs_hz, 32000, "Input sample rate Hz.");
+DEFINE_int(input_fs_hz, 32000, "Input sample rate Hz.");
 DEFINE_string(output, "insert_rtp_with_timing_out.pcm", "OutputFile");
-DEFINE_int32(output_fs_hz, 32000, "Output sample rate Hz");
+DEFINE_int(output_fs_hz, 32000, "Output sample rate Hz");
 
 // Timing files
 DEFINE_string(seq_num, "seq_num", "Sequence number file.");
@@ -45,7 +46,9 @@
 
 // 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 @@
         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 @@
     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 @@
     channel_->RegisterReceiverACM(receive_acm_.get());
     send_acm_->RegisterTransportCallback(channel_);
 
-    if (FLAGS_input.size() == 0) {
+    if (strlen(FLAG_input) == 0) {
       std::string file_name = test::ResourcePath("audio_coding/testfile32kHz",
                                                  "pcm");
       pcm_in_fid_.Open(file_name, 32000, "r", true);  // auto-rewind
       std::cout << "Input file " << file_name << " 32 kHz mono." << std::endl;
     } else {
-      pcm_in_fid_.Open(FLAGS_input, static_cast<uint16_t>(FLAGS_input_fs_hz),
+      pcm_in_fid_.Open(FLAG_input, static_cast<uint16_t>(FLAG_input_fs_hz),
                     "r", true);  // auto-rewind
-      std::cout << "Input file " << FLAGS_input << "at " << FLAGS_input_fs_hz
-          << " Hz in " << ((FLAGS_input_stereo) ? "stereo." : "mono.")
+      std::cout << "Input file " << FLAG_input << "at " << FLAG_input_fs_hz
+          << " Hz in " << ((FLAG_input_stereo) ? "stereo." : "mono.")
           << std::endl;
-      pcm_in_fid_.ReadStereo(FLAGS_input_stereo);
+      pcm_in_fid_.ReadStereo(FLAG_input_stereo);
     }
 
     ASSERT_TRUE(pcm_out_fid_ != NULL);
-    std::cout << "Output file " << FLAGS_output << " at " << FLAGS_output_fs_hz
+    std::cout << "Output file " << FLAG_output << " at " << FLAG_output_fs_hz
         << " Hz." << std::endl;
 
     // Other setups
-    if (FLAGS_loss_rate > 0)
-      loss_threshold_ = RAND_MAX * FLAGS_loss_rate;
+    if (FLAG_loss_rate > 0)
+      loss_threshold_ = RAND_MAX * FLAG_loss_rate;
     else
       loss_threshold_ = 0;
   }
@@ -144,7 +147,7 @@
     if (time_to_playout_audio_ms_ == 0) {
       time_to_playout_audio_ms_ = kPlayoutPeriodMs;
       bool muted;
-      receive_acm_->PlayoutData10Ms(static_cast<int>(FLAGS_output_fs_hz),
+      receive_acm_->PlayoutData10Ms(static_cast<int>(FLAG_output_fs_hz),
                                     &frame_, &muted);
       ASSERT_FALSE(muted);
       fwrite(frame_.data(), sizeof(*frame_.data()),
@@ -180,7 +183,7 @@
         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 @@
 }  // 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);