|
88 | 88 | #define DEFAULT_VIDEO_FRAME_HEIGHT 1080
|
89 | 89 | #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
|
90 | 90 |
|
| 91 | +enum { |
| 92 | + DEFAULT_RTSP_PORT = 554, |
| 93 | +}; |
| 94 | + |
91 | 95 | /* error handling macros */
|
92 | 96 | #define my_curl_easy_setopt(A, B, C, action_fail) \
|
93 | 97 | { \
|
@@ -457,6 +461,40 @@ vidcap_rtsp_grab(void *state, struct audio_frame **audio) {
|
457 | 461 | }
|
458 | 462 | }
|
459 | 463 |
|
| 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 | + |
460 | 498 | #define INIT_FAIL(msg) log_msg(LOG_LEVEL_ERROR, MOD_NAME msg); \
|
461 | 499 | vidcap_rtsp_done(s); \
|
462 | 500 | show_help(false); \
|
@@ -553,7 +591,7 @@ vidcap_rtsp_init(struct vidcap_params *params, void **state) {
|
553 | 591 | }
|
554 | 592 |
|
555 | 593 | //re-check parameters
|
556 |
| - if (strcmp(s->uri, "rtsp://") == 0) { |
| 594 | + if (!check_uri(sizeof s->uri, s->uri)) { |
557 | 595 | INIT_FAIL("No URI given!\n");
|
558 | 596 | }
|
559 | 597 |
|
|
0 commit comments