Skip to content

Commit ecff8a2

Browse files
committed
feat(cli): rename all CLI options to use hyphen-case
1 parent 6e8f4bc commit ecff8a2

File tree

2 files changed

+72
-65
lines changed

2 files changed

+72
-65
lines changed

src/args.h

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,35 @@
77
#include <linux/videodev2.h>
88

99
struct Args {
10+
// video input
1011
int cameraId = 0;
1112
int fps = 30;
1213
int width = 640;
1314
int height = 480;
14-
int jpeg_quality = 30;
1515
int rotation_angle = 0;
16+
bool use_libcamera = false;
17+
uint32_t format = V4L2_PIX_FMT_MJPEG;
18+
std::string camera = "libcamera:0";
19+
std::string v4l2_format = "mjpeg";
20+
21+
// audio input
1622
int sample_rate = 44100;
23+
bool no_audio = false;
24+
25+
// recording
26+
std::string record_path = "";
1727
int file_duration = 60;
28+
29+
// webrtc
30+
int jpeg_quality = 30;
1831
int peer_timeout = 10;
19-
bool no_audio = false;
2032
bool hw_accel = false;
2133
bool no_adaptive = false;
22-
bool use_libcamera = false;
23-
uint32_t format = V4L2_PIX_FMT_MJPEG;
24-
std::string camera = "libcamera:0";
25-
std::string v4l2_format = "mjpeg";
2634
std::string uid = "";
2735
std::string stun_url = "stun:stun.l.google.com:19302";
2836
std::string turn_url = "";
2937
std::string turn_username = "";
3038
std::string turn_password = "";
31-
std::string record_path = "";
3239

3340
// mqtt signaling
3441
bool use_mqtt = false;

src/parser.cpp

Lines changed: 58 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -27,63 +27,63 @@ void Parser::ParseArgs(int argc, char *argv[], Args &args) {
2727
("camera", bpo::value<std::string>()->default_value(args.camera),
2828
"Specify the camera using V4L2 or Libcamera. "
2929
"e.g. \"libcamera:0\" for Libcamera, \"v4l2:0\" for V4L2 at `/dev/video0`.")
30-
("v4l2_format", bpo::value<std::string>()->default_value(args.v4l2_format),
30+
("v4l2-format", bpo::value<std::string>()->default_value(args.v4l2_format),
3131
"The input format (`i420`, `mjpeg`, `h264`) of the V4L2 camera.")
3232
("uid", bpo::value<std::string>()->default_value(args.uid),
3333
"The unique id to identify the device.")
3434
("fps", bpo::value<int>()->default_value(args.fps), "Specify the camera frames per second.")
3535
("width", bpo::value<int>()->default_value(args.width), "Set camera frame width.")
3636
("height", bpo::value<int>()->default_value(args.height), "Set camera frame height.")
37-
("jpeg_quality", bpo::value<int>()->default_value(args.jpeg_quality),
38-
"Set the default quality of the snapshot and thumbnail images.")
39-
("rotation_angle", bpo::value<int>()->default_value(args.rotation_angle),
37+
("rotation-angle", bpo::value<int>()->default_value(args.rotation_angle),
4038
"Set the rotation angle of the camera (0, 90, 180, 270).")
41-
("sample_rate", bpo::value<int>()->default_value(args.sample_rate),
39+
("sample-rate", bpo::value<int>()->default_value(args.sample_rate),
4240
"Set the audio sample rate (in Hz).")
43-
("no_audio", bpo::bool_switch()->default_value(args.no_audio), "Runs without audio source.")
44-
("hw_accel", bpo::bool_switch()->default_value(args.hw_accel),
45-
"Enable hardware acceleration by sharing DMA buffers between the decoder, "
46-
"scaler, and encoder to reduce CPU usage.")
47-
("no_adaptive", bpo::bool_switch()->default_value(args.no_adaptive),
48-
"Disable WebRTC's adaptive resolution scaling. When enabled, "
49-
"the output resolution will remain fixed regardless of network or device conditions.")
50-
("record_path", bpo::value<std::string>()->default_value(args.record_path),
41+
("no-audio", bpo::bool_switch()->default_value(args.no_audio), "Runs without audio source.")
42+
("record-path", bpo::value<std::string>()->default_value(args.record_path),
5143
"Set the path where recording video files will be saved. "
5244
"If the value is empty or unavailable, the recorder will not start.")
53-
("file_duration", bpo::value<int>()->default_value(args.file_duration),
45+
("file-duration", bpo::value<int>()->default_value(args.file_duration),
5446
"The length (in seconds) of each MP4 recording.")
55-
("peer_timeout", bpo::value<int>()->default_value(args.peer_timeout),
47+
("jpeg-quality", bpo::value<int>()->default_value(args.jpeg_quality),
48+
"Set the quality of the snapshot and thumbnail images in range 0 to 100.")
49+
("peer-timeout", bpo::value<int>()->default_value(args.peer_timeout),
5650
"The connection timeout (in seconds) after receiving a remote offer")
57-
("stun_url", bpo::value<std::string>()->default_value(args.stun_url),
51+
("hw-accel", bpo::bool_switch()->default_value(args.hw_accel),
52+
"Enable hardware acceleration by sharing DMA buffers between the decoder, "
53+
"scaler, and encoder to reduce CPU usage.")
54+
("no-adaptive", bpo::bool_switch()->default_value(args.no_adaptive),
55+
"Disable WebRTC's adaptive resolution scaling. When enabled, "
56+
"the output resolution will remain fixed regardless of network or device conditions.")
57+
("stun-url", bpo::value<std::string>()->default_value(args.stun_url),
5858
"Set the STUN server URL for WebRTC. e.g. `stun:xxx.xxx.xxx`.")
59-
("turn_url", bpo::value<std::string>()->default_value(args.turn_url),
59+
("turn-url", bpo::value<std::string>()->default_value(args.turn_url),
6060
"Set the TURN server URL for WebRTC. e.g. `turn:xxx.xxx.xxx:3478?transport=tcp`.")
61-
("turn_username", bpo::value<std::string>()->default_value(args.turn_username),
61+
("turn-username", bpo::value<std::string>()->default_value(args.turn_username),
6262
"Set the TURN server username for WebRTC authentication.")
63-
("turn_password", bpo::value<std::string>()->default_value(args.turn_password),
63+
("turn-password", bpo::value<std::string>()->default_value(args.turn_password),
6464
"Set the TURN server password for WebRTC authentication.")
65-
("use_mqtt", bpo::bool_switch()->default_value(args.use_mqtt),
65+
("use-mqtt", bpo::bool_switch()->default_value(args.use_mqtt),
6666
"Use MQTT to exchange sdp and ice candidates.")
67-
("mqtt_host", bpo::value<std::string>()->default_value(args.mqtt_host),
67+
("mqtt-host", bpo::value<std::string>()->default_value(args.mqtt_host),
6868
"Set the MQTT server host.")
69-
("mqtt_port", bpo::value<int>()->default_value(args.mqtt_port), "Set the MQTT server port.")
70-
("mqtt_username", bpo::value<std::string>()->default_value(args.mqtt_username),
69+
("mqtt-port", bpo::value<int>()->default_value(args.mqtt_port), "Set the MQTT server port.")
70+
("mqtt-username", bpo::value<std::string>()->default_value(args.mqtt_username),
7171
"Set the MQTT server username.")
72-
("mqtt_password", bpo::value<std::string>()->default_value(args.mqtt_password),
72+
("mqtt-password", bpo::value<std::string>()->default_value(args.mqtt_password),
7373
"Set the MQTT server password.")
74-
("use_whep", bpo::bool_switch()->default_value(args.use_whep),
74+
("use-whep", bpo::bool_switch()->default_value(args.use_whep),
7575
"Use WHEP (WebRTC-HTTP Egress Protocol) to exchange SDP and ICE candidates.")
76-
("http_port", bpo::value<uint16_t>()->default_value(args.http_port),
76+
("http-port", bpo::value<uint16_t>()->default_value(args.http_port),
7777
"Local HTTP server port to handle signaling when using WHEP.")
78-
("use_websocket", bpo::bool_switch()->default_value(args.use_websocket),
78+
("use-websocket", bpo::bool_switch()->default_value(args.use_websocket),
7979
"Enables the WebSocket client to connect to the SFU server.")
80-
("use_tls", bpo::bool_switch()->default_value(args.use_tls),
80+
("use-tls", bpo::bool_switch()->default_value(args.use_tls),
8181
"Use TLS for the WebSocket connection. Use it when connecting to a `wss://` URL.")
82-
("ws_host", bpo::value<std::string>()->default_value(args.ws_host),
82+
("ws-host", bpo::value<std::string>()->default_value(args.ws_host),
8383
"The WebSocket host address of the SFU server.")
84-
("ws_room", bpo::value<std::string>()->default_value(args.ws_room),
84+
("ws-room", bpo::value<std::string>()->default_value(args.ws_room),
8585
"The room name to join on the SFU server.")
86-
("ws_key", bpo::value<std::string>()->default_value(args.ws_key),
86+
("ws-key", bpo::value<std::string>()->default_value(args.ws_key),
8787
"The API key used to authenticate with the SFU server.");
8888
// clang-format on
8989

@@ -102,37 +102,37 @@ void Parser::ParseArgs(int argc, char *argv[], Args &args) {
102102
}
103103

104104
SetIfExists(vm, "camera", args.camera);
105-
SetIfExists(vm, "v4l2_format", args.v4l2_format);
105+
SetIfExists(vm, "v4l2-format", args.v4l2_format);
106106
SetIfExists(vm, "uid", args.uid);
107107
SetIfExists(vm, "fps", args.fps);
108108
SetIfExists(vm, "width", args.width);
109109
SetIfExists(vm, "height", args.height);
110-
SetIfExists(vm, "jpeg_quality", args.jpeg_quality);
111-
SetIfExists(vm, "rotation_angle", args.rotation_angle);
112-
SetIfExists(vm, "sample_rate", args.sample_rate);
113-
SetIfExists(vm, "record_path", args.record_path);
114-
SetIfExists(vm, "file_duration", args.file_duration);
115-
SetIfExists(vm, "peer_timeout", args.peer_timeout);
116-
SetIfExists(vm, "stun_url", args.stun_url);
117-
SetIfExists(vm, "turn_url", args.turn_url);
118-
SetIfExists(vm, "turn_username", args.turn_username);
119-
SetIfExists(vm, "turn_password", args.turn_password);
120-
SetIfExists(vm, "mqtt_host", args.mqtt_host);
121-
SetIfExists(vm, "mqtt_port", args.mqtt_port);
122-
SetIfExists(vm, "mqtt_username", args.mqtt_username);
123-
SetIfExists(vm, "mqtt_password", args.mqtt_password);
124-
SetIfExists(vm, "http_port", args.http_port);
125-
SetIfExists(vm, "ws_host", args.ws_host);
126-
SetIfExists(vm, "ws_room", args.ws_room);
127-
SetIfExists(vm, "ws_key", args.ws_key);
128-
129-
args.no_audio = vm["no_audio"].as<bool>();
130-
args.hw_accel = vm["hw_accel"].as<bool>();
131-
args.no_adaptive = vm["no_adaptive"].as<bool>();
132-
args.use_mqtt = vm["use_mqtt"].as<bool>();
133-
args.use_whep = vm["use_whep"].as<bool>();
134-
args.use_websocket = vm["use_websocket"].as<bool>();
135-
args.use_tls = vm["use_tls"].as<bool>();
110+
SetIfExists(vm, "rotation-angle", args.rotation_angle);
111+
SetIfExists(vm, "sample-rate", args.sample_rate);
112+
SetIfExists(vm, "record-path", args.record_path);
113+
SetIfExists(vm, "file-duration", args.file_duration);
114+
SetIfExists(vm, "jpeg-quality", args.jpeg_quality);
115+
SetIfExists(vm, "peer-timeout", args.peer_timeout);
116+
SetIfExists(vm, "stun-url", args.stun_url);
117+
SetIfExists(vm, "turn-url", args.turn_url);
118+
SetIfExists(vm, "turn-username", args.turn_username);
119+
SetIfExists(vm, "turn-password", args.turn_password);
120+
SetIfExists(vm, "mqtt-host", args.mqtt_host);
121+
SetIfExists(vm, "mqtt-port", args.mqtt_port);
122+
SetIfExists(vm, "mqtt-username", args.mqtt_username);
123+
SetIfExists(vm, "mqtt-password", args.mqtt_password);
124+
SetIfExists(vm, "http-port", args.http_port);
125+
SetIfExists(vm, "ws-host", args.ws_host);
126+
SetIfExists(vm, "ws-room", args.ws_room);
127+
SetIfExists(vm, "ws-key", args.ws_key);
128+
129+
args.no_audio = vm["no-audio"].as<bool>();
130+
args.hw_accel = vm["hw-accel"].as<bool>();
131+
args.no_adaptive = vm["no-adaptive"].as<bool>();
132+
args.use_mqtt = vm["use-mqtt"].as<bool>();
133+
args.use_whep = vm["use-whep"].as<bool>();
134+
args.use_websocket = vm["use-websocket"].as<bool>();
135+
args.use_tls = vm["use-tls"].as<bool>();
136136

137137
if (!args.stun_url.empty() && args.stun_url.substr(0, 4) != "stun") {
138138
std::cout << "Stun url should not be empty and start with \"stun:\"" << std::endl;

0 commit comments

Comments
 (0)