Switch pc client and stunprober to ABSL_FLAG.

Bug: webrtc:10616
Change-Id: I74e65a527da88a7f723c5000e5097dc1766826dd
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/144624
Reviewed-by: Tommi <tommi@webrtc.org>
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#28588}
This commit is contained in:
Mirko Bonadei
2019-07-16 18:40:05 +02:00
committed by Commit Bot
parent f43cc6905f
commit 0be40bf53f
6 changed files with 73 additions and 61 deletions

View File

@ -707,6 +707,8 @@ if (is_linux || is_win) {
"../rtc_base:rtc_base_approved",
"../rtc_base:rtc_json",
"../test:video_test_common",
"//third_party/abseil-cpp/absl/flags:flag",
"//third_party/abseil-cpp/absl/flags:parse",
"//third_party/libyuv",
]
}
@ -870,6 +872,8 @@ if (!build_with_chromium) {
"../rtc_base",
"../rtc_base:checks",
"../rtc_base:rtc_base_approved",
"//third_party/abseil-cpp/absl/flags:flag",
"//third_party/abseil-cpp/absl/flags:parse",
]
}
}

View File

@ -11,7 +11,9 @@
#ifndef EXAMPLES_PEERCONNECTION_CLIENT_FLAG_DEFS_H_
#define EXAMPLES_PEERCONNECTION_CLIENT_FLAG_DEFS_H_
#include "rtc_base/flags.h"
#include <string>
#include "absl/flags/flag.h"
extern const uint16_t kDefaultServerPort; // From defaults.[h|cc]
@ -19,23 +21,26 @@ extern const uint16_t kDefaultServerPort; // From defaults.[h|cc]
// header file so that they can be shared across the different main.cc's
// for each platform.
WEBRTC_DEFINE_bool(help, false, "Prints this message");
WEBRTC_DEFINE_bool(autoconnect,
false,
"Connect to the server without user "
"intervention.");
WEBRTC_DEFINE_string(server, "localhost", "The server to connect to.");
WEBRTC_DEFINE_int(port,
kDefaultServerPort,
"The port on which the server is listening.");
WEBRTC_DEFINE_bool(
ABSL_FLAG(bool,
autoconnect,
false,
"Connect to the server without user "
"intervention.");
ABSL_FLAG(std::string, server, "localhost", "The server to connect to.");
ABSL_FLAG(int,
port,
kDefaultServerPort,
"The port on which the server is listening.");
ABSL_FLAG(
bool,
autocall,
false,
"Call the first available other client on "
"the server without user intervention. Note: this flag should only be set "
"to true on one of the two clients.");
WEBRTC_DEFINE_string(
ABSL_FLAG(
std::string,
force_fieldtrials,
"",
"Field trials control experimental features. This flag specifies the field "

View File

@ -12,12 +12,12 @@
#include <gtk/gtk.h>
#include <stdio.h>
#include "absl/flags/parse.h"
#include "api/scoped_refptr.h"
#include "examples/peerconnection/client/conductor.h"
#include "examples/peerconnection/client/flag_defs.h"
#include "examples/peerconnection/client/linux/main_wnd.h"
#include "examples/peerconnection/client/peer_connection_client.h"
#include "rtc_base/flags.h"
#include "rtc_base/message_queue.h"
#include "rtc_base/physical_socket_server.h"
#include "rtc_base/ref_counted_object.h"
@ -77,24 +77,25 @@ int main(int argc, char* argv[]) {
g_thread_init(NULL);
#endif
rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true);
if (FLAG_help) {
rtc::FlagList::Print(NULL, false);
return 0;
}
absl::ParseCommandLine(argc, argv);
// InitFieldTrialsFromString stores the char*, so the char array must outlive
// the application.
webrtc::field_trial::InitFieldTrialsFromString(FLAG_force_fieldtrials);
const std::string forced_field_trials =
absl::GetFlag(FLAGS_force_fieldtrials);
webrtc::field_trial::InitFieldTrialsFromString(forced_field_trials.c_str());
// Abort if the user specifies a port that is outside the allowed
// range [1, 65535].
if ((FLAG_port < 1) || (FLAG_port > 65535)) {
printf("Error: %i is not a valid port.\n", FLAG_port);
if ((absl::GetFlag(FLAGS_port) < 1) || (absl::GetFlag(FLAGS_port) > 65535)) {
printf("Error: %i is not a valid port.\n", absl::GetFlag(FLAGS_port));
return -1;
}
GtkMainWnd wnd(FLAG_server, FLAG_port, FLAG_autoconnect, FLAG_autocall);
const std::string server = absl::GetFlag(FLAGS_server);
GtkMainWnd wnd(server.c_str(), absl::GetFlag(FLAGS_port),
absl::GetFlag(FLAGS_autoconnect),
absl::GetFlag(FLAGS_autocall));
wnd.Create();
CustomSocketServer socket_server(&wnd);

View File

@ -17,6 +17,7 @@
#include <string>
#include <vector>
#include "absl/flags/parse.h"
#include "examples/peerconnection/client/conductor.h"
#include "examples/peerconnection/client/flag_defs.h"
#include "examples/peerconnection/client/main_wnd.h"
@ -41,13 +42,13 @@ class WindowsCommandLineArguments {
WindowsCommandLineArguments();
int argc() { return argv_.size(); }
const char** argv() { return argv_.data(); }
char** argv() { return argv_.data(); }
private:
// Owned argument strings.
std::vector<std::string> args_;
// Pointers, to get layout compatible with char** argv.
std::vector<const char*> argv_;
std::vector<char*> argv_;
private:
RTC_DISALLOW_COPY_AND_ASSIGN(WindowsCommandLineArguments);
@ -64,7 +65,7 @@ WindowsCommandLineArguments::WindowsCommandLineArguments() {
for (int i = 0; i < argc; ++i) {
args_.push_back(rtc::ToUtf8(wide_argv[i], wcslen(wide_argv[i])));
// make sure the argv array points to the string data.
argv_.push_back(args_.back().c_str());
argv_.push_back(const_cast<char*>(args_.back().c_str()));
}
LocalFree(wide_argv);
}
@ -81,26 +82,26 @@ int PASCAL wWinMain(HINSTANCE instance,
WindowsCommandLineArguments win_args;
int argc = win_args.argc();
const char** argv = win_args.argv();
char** argv = win_args.argv();
rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true);
if (FLAG_help) {
rtc::FlagList::Print(NULL, false);
return 0;
}
absl::ParseCommandLine(argc, argv);
// InitFieldTrialsFromString stores the char*, so the char array must outlive
// the application.
webrtc::field_trial::InitFieldTrialsFromString(FLAG_force_fieldtrials);
const std::string forced_field_trials =
absl::GetFlag(FLAGS_force_fieldtrials);
webrtc::field_trial::InitFieldTrialsFromString(forced_field_trials.c_str());
// Abort if the user specifies a port that is outside the allowed
// range [1, 65535].
if ((FLAG_port < 1) || (FLAG_port > 65535)) {
printf("Error: %i is not a valid port.\n", FLAG_port);
if ((absl::GetFlag(FLAGS_port) < 1) || (absl::GetFlag(FLAGS_port) > 65535)) {
printf("Error: %i is not a valid port.\n", absl::GetFlag(FLAGS_port));
return -1;
}
MainWnd wnd(FLAG_server, FLAG_port, FLAG_autoconnect, FLAG_autocall);
const std::string server = absl::GetFlag(FLAGS_server);
MainWnd wnd(server.c_str(), absl::GetFlag(FLAGS_port),
absl::GetFlag(FLAGS_autoconnect), absl::GetFlag(FLAGS_autocall));
if (!wnd.Create()) {
RTC_NOTREACHED();
return -1;

View File

@ -72,8 +72,8 @@ int main(int argc, char* argv[]) {
// InitFieldTrialsFromString stores the char*, so the char array must outlive
// the application.
webrtc::field_trial::InitFieldTrialsFromString(
absl::GetFlag(FLAGS_force_fieldtrials).c_str());
const std::string force_field_trials = absl::GetFlag(FLAGS_force_fieldtrials);
webrtc::field_trial::InitFieldTrialsFromString(force_field_trials.c_str());
int port = absl::GetFlag(FLAGS_port);

View File

@ -14,9 +14,10 @@
#include <string>
#include <vector>
#include "absl/flags/flag.h"
#include "absl/flags/parse.h"
#include "p2p/base/basic_packet_socket_factory.h"
#include "p2p/stunprober/stun_prober.h"
#include "rtc_base/flags.h"
#include "rtc_base/helpers.h"
#include "rtc_base/logging.h"
#include "rtc_base/network.h"
@ -28,21 +29,24 @@
using stunprober::AsyncCallback;
using stunprober::StunProber;
WEBRTC_DEFINE_bool(help, false, "Prints this message");
WEBRTC_DEFINE_int(interval,
10,
"Interval of consecutive stun pings in milliseconds");
WEBRTC_DEFINE_bool(shared_socket,
false,
"Share socket mode for different remote IPs");
WEBRTC_DEFINE_int(pings_per_ip,
10,
"Number of consecutive stun pings to send for each IP");
WEBRTC_DEFINE_int(
timeout,
1000,
"Milliseconds of wait after the last ping sent before exiting");
WEBRTC_DEFINE_string(
ABSL_FLAG(int,
interval,
10,
"Interval of consecutive stun pings in milliseconds");
ABSL_FLAG(bool,
shared_socket,
false,
"Share socket mode for different remote IPs");
ABSL_FLAG(int,
pings_per_ip,
10,
"Number of consecutive stun pings to send for each IP");
ABSL_FLAG(int,
timeout,
1000,
"Milliseconds of wait after the last ping sent before exiting");
ABSL_FLAG(
std::string,
servers,
"stun.l.google.com:19302,stun1.l.google.com:19302,stun2.l.google.com:19302",
"Comma separated STUN server addresses with ports");
@ -102,14 +106,10 @@ void StopTrial(rtc::Thread* thread, StunProber* prober, int result) {
} // namespace
int main(int argc, char* argv[]) {
rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true);
if (FLAG_help) {
rtc::FlagList::Print(nullptr, false);
return 0;
}
absl::ParseCommandLine(argc, argv);
std::vector<rtc::SocketAddress> server_addresses;
std::istringstream servers(FLAG_servers);
std::istringstream servers(absl::GetFlag(FLAGS_servers));
std::string server;
while (getline(servers, server, ',')) {
rtc::SocketAddress addr;
@ -134,8 +134,9 @@ int main(int argc, char* argv[]) {
auto finish_callback = [thread](StunProber* prober, int result) {
StopTrial(thread, prober, result);
};
prober->Start(server_addresses, FLAG_shared_socket, FLAG_interval,
FLAG_pings_per_ip, FLAG_timeout,
prober->Start(server_addresses, absl::GetFlag(FLAGS_shared_socket),
absl::GetFlag(FLAGS_interval),
absl::GetFlag(FLAGS_pings_per_ip), absl::GetFlag(FLAGS_timeout),
AsyncCallback(finish_callback));
thread->Run();
delete prober;