Skip to content

Commit 1c12910

Browse files
Copilotmpromonet
andauthored
Replace getopt with cxxopts for modern C++ option parsing (#808)
* Initial plan * Replace getopt with cxxopts for option parsing Co-authored-by: mpromonet <1367630+mpromonet@users.noreply.github.com> * Fix STUN/TURN URL handling to use std::string consistently Co-authored-by: mpromonet <1367630+mpromonet@users.noreply.github.com> * Improve verbose and audio-layer option handling Co-authored-by: mpromonet <1367630+mpromonet@users.noreply.github.com> * Remove getopt submodule as it's no longer needed Co-authored-by: mpromonet <1367630+mpromonet@users.noreply.github.com> * fix build * update readme --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: mpromonet <1367630+mpromonet@users.noreply.github.com> Co-authored-by: Michel Promonet <michel.promonet@free.fr>
1 parent 57af94c commit 1c12910

File tree

6 files changed

+249
-189
lines changed

6 files changed

+249
-189
lines changed

.gitmodules

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
[submodule "html"]
88
path = html
99
url = https://github.com/mpromonet/webrtc-streamer-html
10-
[submodule "getopt"]
11-
path = getopt
12-
url = https://github.com/kimgr/getopt_port
1310
[submodule "prometheus-cpp"]
1411
path = prometheus-cpp
1512
url = https://github.com/jupp0r/prometheus-cpp
1613
[submodule "libv4l2cpp"]
1714
path = libv4l2cpp
1815
url = https://github.com/mpromonet/libv4l2cpp
16+
[submodule "cxxopts"]
17+
path = cxxopts
18+
url = https://github.com/jarro2783/cxxopts.git

CMakeLists.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ if (NOT EXISTS ${WEBRTCOBJS}/${CMAKE_STATIC_LIBRARY_PREFIX}webrtc${CMAKE_STATIC_
105105
file(COPY ${WEBRTCROOT}/src/third_party/ffmpeg/config.h DESTINATION ${WEBRTCROOT}/src/third_party/ffmpeg/chromium/config/Chrome/linux/arm/)
106106
file(COPY ${WEBRTCROOT}/src/third_party/ffmpeg/config_components.h DESTINATION ${WEBRTCROOT}/src/third_party/ffmpeg/chromium/config/Chrome/linux/arm/)
107107
file(COPY ${WEBRTCROOT}/src/third_party/ffmpeg/libavutil/avconfig.h DESTINATION ${WEBRTCROOT}/src/third_party/ffmpeg/chromium/config/Chrome/linux/arm/libavutil/)
108-
file(COPY ${WEBRTCROOT}/src/third_party/ffmpeg/libavfilter/filter_list.c DESTINATION ${WEBRTCROOT}/src/third_party/ffmpeg/chromium/config/Chrome/linux/arm/libavutil/)
108+
file(COPY ${WEBRTCROOT}/src/third_party/ffmpeg/libavfilter/filter_list.c DESTINATION ${WEBRTCROOT}/src/third_party/ffmpeg/chromium/config/Chrome/linux/arm/libavfilter/)
109109
file(COPY ${WEBRTCROOT}/src/third_party/ffmpeg/libavcodec/codec_list.c DESTINATION ${WEBRTCROOT}/src/third_party/ffmpeg/chromium/config/Chrome/linux/arm/libavcodec/)
110110
file(COPY ${WEBRTCROOT}/src/third_party/ffmpeg/libavcodec/parser_list.c DESTINATION ${WEBRTCROOT}/src/third_party/ffmpeg/chromium/config/Chrome/linux/arm/libavcodec/)
111111
file(COPY ${WEBRTCROOT}/src/third_party/ffmpeg/libavcodec/bsf_list.c DESTINATION ${WEBRTCROOT}/src/third_party/ffmpeg/chromium/config/Chrome/linux/arm/libavcodec/)
@@ -213,6 +213,7 @@ target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE inc)
213213
# webrtc
214214
set (WEBRTCINCLUDE ${WEBRTCROOT}/src ${WEBRTCROOT}/src/third_party/abseil-cpp ${WEBRTCROOT}/src/third_party/jsoncpp/source/include ${WEBRTCROOT}/src/third_party/jsoncpp/generated ${WEBRTCROOT}/src/third_party/libyuv/include)
215215
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE ${WEBRTCINCLUDE})
216+
216217
set(WEBRTC_LIBS_INFO
217218
"${WEBRTCOBJS}/api/${CMAKE_STATIC_LIBRARY_PREFIX}field_trials${CMAKE_STATIC_LIBRARY_SUFFIX}"
218219
"${WEBRTCOBJS}/api/video_codecs/${CMAKE_STATIC_LIBRARY_PREFIX}rtc_software_fallback_wrappers${CMAKE_STATIC_LIBRARY_SUFFIX}"
@@ -227,6 +228,10 @@ foreach(LIB ${WEBRTC_LIBS_INFO})
227228
endforeach()
228229
add_definitions(-DHAVE_JPEG)
229230

231+
# cxxopts
232+
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE cxxopts/include)
233+
target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE CXXOPTS_NO_RTTI)
234+
230235
# thread
231236
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
232237
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
@@ -260,11 +265,6 @@ if (WIN32)
260265
string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
261266
endforeach()
262267

263-
# getopt
264-
add_library (getopt getopt/getopt.c)
265-
target_include_directories(getopt PUBLIC getopt)
266-
target_link_libraries (${CMAKE_PROJECT_NAME} getopt)
267-
268268
# webrtc
269269
add_definitions(-DWEBRTC_WIN -EHsc -DNOMINMAX -D__PRETTY_FUNCTION__=__FUNCTION__ -D_HAS_ITERATOR_DEBUGGING=0)
270270
add_definitions(-DUSE_X11 -DHAVE_SOUND -D_WINSOCKAPI_)

README.md

Lines changed: 43 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -31,31 +31,46 @@ Experimentation to stream WebRTC media sources like capture devices, screen capt
3131
## Usage
3232

3333
```roff
34-
./webrtc-streamer [-H http port] [-S[embeded stun address]] -[v[v]] [urls...]
35-
./webrtc-streamer [-H http port] [-s[external stun address]] -[v[v]] [urls...]
36-
./webrtc-streamer -V
37-
-v[v[v]] : verbosity
38-
-V : print version
39-
-C config.json : load urls from JSON config file
40-
-n name -u videourl -U audiourl : register a name for a video url and an audio url
41-
[url] : url to register in the source list
42-
43-
-H [hostname:]port : HTTP server binding (default 0.0.0.0:8000)
44-
-w webroot : path to get files
45-
-c sslkeycert : path to private key and certificate for HTTPS
46-
-N nbthreads : number of threads for HTTP server
47-
-A passwd : password file for HTTP server access
48-
-D authDomain : authentication domain for HTTP server access (default:mydomain.com)
49-
50-
-S[stun_address] : start embeded STUN server bind to address (default 0.0.0.0:3478)
51-
-s[stun_address] : use an external STUN server (default:stun.l.google.com:19302 , -:means no STUN)
52-
-T[username:password@]turn_address : start embeded TURN server (default:disabled)
53-
-t[username:password@]turn_address : use an external TURN relay server (default:disabled)
54-
-R [Udp port range min:max] : Set the webrtc udp port range (default 0:65535)
55-
-W webrtc_trials_fields : Set the webrtc trials fields (default:WebRTC-FrameDropper/Disabled/)
56-
-a[audio layer] : spefify audio capture layer to use (default:0)
57-
-q[filter] : spefify publish filter (default:.*)
58-
-o : use null codec (keep frame encoded)
34+
Usage:
35+
./webrtc-streamer [OPTION...] [urls...]
36+
37+
General options:
38+
-h, --help Print help
39+
-V, --version Print version
40+
-v, --verbose Verbosity level (use multiple times for more verbosity)
41+
-C, --config arg Load urls from JSON config file
42+
-n, --name arg Register a stream with name
43+
-u, --video arg Video URL for the named stream
44+
-U, --audio arg Audio URL for the named stream
45+
46+
HTTP options:
47+
-H, --http arg HTTP server binding (default 0.0.0.0:8000)
48+
-w, --webroot arg Path to get static files
49+
-c, --cert arg Path to private key and certificate for HTTPS
50+
-N, --threads arg Number of threads for HTTP server
51+
-A, --passwd arg Password file for HTTP server access
52+
-D, --domain arg Authentication domain for HTTP server access
53+
(default:mydomain.com)
54+
-X, --disable-xframe Disable X-Frame-Options header
55+
-B, --base-path arg Base path for HTTP server
56+
57+
WebRTC options:
58+
-m, --maxpc arg Maximum number of peer connections
59+
-I, --ice-transport arg Set ice transport type
60+
-T, --turn-server [=arg(=turn:turn@0.0.0.0:3478)]
61+
Start embedded TURN server
62+
-t, --turn arg Use an external TURN relay server
63+
-S, --stun-server [=arg(=0.0.0.0:3478)]
64+
Start embedded STUN server bind to address
65+
-s, --stun [=arg(=0.0.0.0:3478)]
66+
Use an external STUN server
67+
-R, --udp-range arg Set the webrtc udp port range
68+
-W, --trials arg Set the webrtc trials fields
69+
-a, --audio-layer [=arg(=)] Specify audio capture layer to use (omit
70+
value for dummy audio)
71+
-q, --publish-filter arg Specify publish filter
72+
-o, --null-codec Use null codec (keep frame encoded)
73+
-b, --plan-b Use sdp plan-B (default use unifiedPlan)
5974
```
6075

6176
Arguments of '-H' are forwarded to option
@@ -155,9 +170,9 @@ and [TURN](https://en.wikipedia.org/wiki/Traversal_Using_Relays_around_NAT)
155170
server and publish its URL:
156171

157172
```sh
158-
./webrtc-streamer -S0.0.0.0:3478 -s$(curl -s ifconfig.me):3478
159-
./webrtc-streamer -s- -T0.0.0.0:3478 -tturn:turn@$(curl -s ifconfig.me):3478
160-
./webrtc-streamer -S0.0.0.0:3478 -s$(curl -s ifconfig.me):3478 -T0.0.0.0:3479 -tturn:turn@$(curl -s ifconfig.me):3479
173+
./webrtc-streamer --stun-server=0.0.0.0:3478 --stun=$(curl -s ifconfig.me):3478
174+
./webrtc-streamer --stun=- --turn-server=0.0.0.0:3478 -tturn:turn@$(curl -s ifconfig.me):3478
175+
./webrtc-streamer --stun-server=0.0.0.0:3478 --stun=$(curl -s ifconfig.me):3478 --turn-server=0.0.0.0:3479 --turn=turn:turn@$(curl -s ifconfig.me):3479
161176
```
162177

163178
The command `curl -s ifconfig.me` is getting the public IP, it could also given

cxxopts

Submodule cxxopts added at 929bf2d

getopt

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)