Skip to content

Commit 1420c6e

Browse files
committed
vcomp/rtsp: hide rtp_rx_port
show only in fullhelp \+ added the fullhelp option \+ pretty-print the output (use colors) refers to GH-400
1 parent d687f8e commit 1420c6e

File tree

1 file changed

+26
-25
lines changed

1 file changed

+26
-25
lines changed

src/video_capture/rtsp.c

+26-25
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@
6565
#include "rtp/rtp_callback.h"
6666
#include "rtp/rtpdec_h264.h"
6767
#include "rtsp/rtsp_utils.h"
68-
#include "utils/macros.h"
68+
#include "utils/color_out.h" // for color_printf, TBOLD
69+
#include "utils/macros.h" // for MIN, STR_LEN
6970
#include "utils/text.h" // base64_decode
7071
#include "video_decompress.h"
7172

@@ -150,9 +151,6 @@ init_decompressor(struct video_rtsp_state *sr, struct video_desc desc);
150151
static void *
151152
vidcap_rtsp_thread(void *args);
152153

153-
static void
154-
show_help(void);
155-
156154
void getNewLine(const char* buffer, int* i, char* line);
157155

158156
void
@@ -251,13 +249,21 @@ struct rtsp_state {
251249
};
252250

253251
static void
254-
show_help() {
255-
printf("[rtsp] usage:\n");
256-
printf("\t-t rtsp:<uri>[:rtp_rx_port=<port>][:decompress]\n");
257-
printf("\t\t <uri> - RTSP server URI\n");
258-
printf("\t\t <port> - receiver port number \n");
259-
printf(
260-
"\t\t decompress - decompress the stream (default: disabled)\n\n");
252+
show_help(bool full) {
253+
color_printf(TBOLD("RTSP client") " usage:\n");
254+
color_printf("\t" TBOLD(TRED("-t rtsp:<uri>") "[:decompress]"));
255+
if (full) {
256+
color_printf(TBOLD("[:rtp_rx_port=<port>]"));
257+
}
258+
color_printf("\n\t" TBOLD("-t rtsp:[full]help") "\n");
259+
color_printf("\noptions:\n");
260+
color_printf("\t " TBOLD("<uri>") " - RTSP server URI\n");
261+
printf("\t " TBOLD("decompress") " - decompress the stream "
262+
"(default: disabled)\n");
263+
if (full) {
264+
printf("\t " TBOLD("<port>") " - video RTP receiver port number\n");
265+
}
266+
color_printf("\n");
261267
}
262268

263269
static void *
@@ -452,17 +458,16 @@ vidcap_rtsp_grab(void *state, struct audio_frame **audio) {
452458
}
453459

454460
#define INIT_FAIL(msg) log_msg(LOG_LEVEL_ERROR, MOD_NAME msg); \
455-
free(tmp); \
456461
vidcap_rtsp_done(s); \
457-
show_help(); \
462+
show_help(false); \
458463
return VIDCAP_INIT_FAIL
459464

460465
static int
461466
vidcap_rtsp_init(struct vidcap_params *params, void **state) {
462-
if (vidcap_params_get_fmt(params)
463-
&& strcmp(vidcap_params_get_fmt(params), "help") == 0)
464-
{
465-
show_help();
467+
char fmt[STR_LEN];
468+
snprintf(fmt, sizeof fmt, "%s", vidcap_params_get_fmt(params));
469+
if (strcmp(fmt, "help") == 0 || strcmp(fmt, "fullhelp") == 0) {
470+
show_help(strcmp(fmt, "fullhelp") == 0);
466471
return VIDCAP_INIT_NOERR;
467472
}
468473

@@ -501,24 +506,22 @@ vidcap_rtsp_init(struct vidcap_params *params, void **state) {
501506
s->vrtsp_state.h264_offset_len = 0;
502507

503508
s->curl = NULL;
504-
char *fmt = NULL;
505509

506510
pthread_mutex_init(&s->lock, NULL);
507511
pthread_cond_init(&s->keepalive_cv, NULL);
508512
pthread_mutex_init(&s->vrtsp_state.lock, NULL);
509513
pthread_cond_init(&s->vrtsp_state.boss_cv, NULL);
510514
pthread_cond_init(&s->vrtsp_state.worker_cv, NULL);
511515

512-
char *tmp, *item;
513-
fmt = strdup(vidcap_params_get_fmt(params));
514-
tmp = fmt;
516+
char *tmp = fmt;
517+
char *item = NULL;
515518
strcpy(s->uri, "rtsp://");
516519

517520
s->vrtsp_state.desc.tile_count = 1;
518521

519522
bool in_uri = true;
520-
while ((item = strtok_r(fmt, ":", &save_ptr))) {
521-
fmt = NULL;
523+
while ((item = strtok_r(tmp, ":", &save_ptr))) {
524+
tmp = NULL;
522525
bool option_given = true;
523526
if (strstr(item, "rtp_rx_port=") == item) {
524527
s->vrtsp_state.port = atoi(strchr(item, '=') + 1);
@@ -548,8 +551,6 @@ vidcap_rtsp_init(struct vidcap_params *params, void **state) {
548551
in_uri = false;
549552
}
550553
}
551-
free(tmp);
552-
tmp = NULL;
553554

554555
//re-check parameters
555556
if (strcmp(s->uri, "rtsp://") == 0) {

0 commit comments

Comments
 (0)