Skip to content

Commit 3cebc50

Browse files
committed
vcap/rtsp: use port 554 by default
If no port is included in the URI, use 554 (default RTSP). refer to GH-400
1 parent 1420c6e commit 3cebc50

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

src/video_capture/rtsp.c

+39-1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@
8888
#define DEFAULT_VIDEO_FRAME_HEIGHT 1080
8989
#define INITIAL_VIDEO_RECV_BUFFER_SIZE ((0.1*DEFAULT_VIDEO_FRAME_WIDTH*DEFAULT_VIDEO_FRAME_HEIGHT)*110/100) //command line net.core setup: sysctl -w net.core.rmem_max=9123840
9090

91+
enum {
92+
DEFAULT_RTSP_PORT = 554,
93+
};
94+
9195
/* error handling macros */
9296
#define my_curl_easy_setopt(A, B, C, action_fail) \
9397
{ \
@@ -457,6 +461,40 @@ vidcap_rtsp_grab(void *state, struct audio_frame **audio) {
457461
}
458462
}
459463

464+
/**
465+
* @brief check URI validity + append port if not given
466+
*
467+
* If port is not given in the URI, 554 (default) is appended (after
468+
* authority, before the path if there is any).
469+
*
470+
* Resulting URI is written to output.
471+
*/
472+
static bool
473+
check_uri(size_t uri_len, char *uri)
474+
{
475+
const char *rtsp_uri_pref = "rtsp://";
476+
if (strcmp(uri, rtsp_uri_pref) == 0) {
477+
return false;
478+
}
479+
char *authority = uri + strlen(rtsp_uri_pref);
480+
if (strchr(authority, ':') == NULL) {
481+
char *path = NULL;
482+
if (strchr(authority, '/') != NULL) { // store path
483+
path = strdup(strchr(authority, '/') + 1);
484+
*strchr(authority, '/') = '\0';
485+
}
486+
snprintf(uri + strlen(uri), uri_len - strlen(uri), ":%d",
487+
DEFAULT_RTSP_PORT);
488+
if (path != NULL) {
489+
snprintf(uri + strlen(uri), uri_len - strlen(uri), "/%s",
490+
path);
491+
free(path);
492+
}
493+
}
494+
MSG(INFO, "Using URI %s\n", uri);
495+
return true;
496+
}
497+
460498
#define INIT_FAIL(msg) log_msg(LOG_LEVEL_ERROR, MOD_NAME msg); \
461499
vidcap_rtsp_done(s); \
462500
show_help(false); \
@@ -553,7 +591,7 @@ vidcap_rtsp_init(struct vidcap_params *params, void **state) {
553591
}
554592

555593
//re-check parameters
556-
if (strcmp(s->uri, "rtsp://") == 0) {
594+
if (!check_uri(sizeof s->uri, s->uri)) {
557595
INIT_FAIL("No URI given!\n");
558596
}
559597

0 commit comments

Comments
 (0)