Skip to content

Commit

Permalink
Add quirk for RTSP servers
Browse files Browse the repository at this point in the history
Some RTSP Servers expect only the path, not the full url, for DESCRIBE, SETUP, and PLAY commands.
  • Loading branch information
jp-bennett committed Feb 28, 2022
1 parent 0caf8ed commit 588397b
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion plugins/janus_streaming.c
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,7 @@ typedef struct janus_streaming_rtp_source {
janus_streaming_buffer *curldata;
char *rtsp_url;
char *rtsp_username, *rtsp_password;
char *rtsp_stream_uri;
gint64 ka_timeout;
char *rtsp_ahost, *rtsp_vhost;
gboolean reconnecting;
Expand Down Expand Up @@ -5795,6 +5796,7 @@ static void janus_streaming_rtp_source_free(janus_streaming_rtp_source *source)
g_free(source->rtsp_url);
g_free(source->rtsp_username);
g_free(source->rtsp_password);
curl_free(source->rtsp_stream_uri);
g_free(source->rtsp_ahost);
g_free(source->rtsp_vhost);
janus_mutex_unlock(&source->rtsp_mutex);
Expand Down Expand Up @@ -6519,6 +6521,23 @@ static int janus_streaming_rtsp_connect_to_server(janus_streaming_mountpoint *mp
}
long code = 0;
res = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &code);
#if CURL_AT_LEAST_VERSION(7, 62, 0)
if(code == 404) { //Possibly a quirk in the RTSP server, where the DESCRIBE request expects a path only.
CURLU *curl_u;
char *path;
curl_u = curl_url();
if(!(curl_url_set(curl_u, CURLUPART_URL, source->rtsp_url, 0))) {
if(!(curl_url_get(curl_u, CURLUPART_PATH, &path, 0))) {
curl_easy_setopt(curl, CURLOPT_RTSP_STREAM_URI, path);
res = curl_easy_perform(curl);
source->rtsp_stream_uri = path;
//curl_free(path);
res = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &code);
}
}
curl_url_cleanup(curl_u);
}
#endif
if(res != CURLE_OK) {
JANUS_LOG(LOG_ERR, "Couldn't get DESCRIBE answer: %s\n", curl_easy_strerror(res));
curl_easy_cleanup(curl);
Expand Down Expand Up @@ -7073,7 +7092,10 @@ static int janus_streaming_rtsp_play(janus_streaming_rtp_source *source) {
source->curldata->buffer = g_malloc0(1);
source->curldata->size = 0;
JANUS_LOG(LOG_VERB, "Sending PLAY request...\n");
curl_easy_setopt(source->curl, CURLOPT_RTSP_STREAM_URI, source->rtsp_url);
if(source->rtsp_stream_uri)
curl_easy_setopt(source->curl, CURLOPT_RTSP_STREAM_URI, source->rtsp_stream_uri);
else
curl_easy_setopt(source->curl, CURLOPT_RTSP_STREAM_URI, source->rtsp_url);
curl_easy_setopt(source->curl, CURLOPT_RANGE, "npt=0.000-");
curl_easy_setopt(source->curl, CURLOPT_RTSP_REQUEST, (long)CURL_RTSPREQ_PLAY);
int res = curl_easy_perform(source->curl);
Expand Down Expand Up @@ -7166,6 +7188,7 @@ janus_streaming_mountpoint *janus_streaming_create_rtsp_source(
live_rtsp_source->rtsp_url = g_strdup(url);
live_rtsp_source->rtsp_username = username ? g_strdup(username) : NULL;
live_rtsp_source->rtsp_password = password ? g_strdup(password) : NULL;
live_rtsp_source->rtsp_stream_uri = NULL;
live_rtsp_source->arc = NULL;
live_rtsp_source->vrc = NULL;
live_rtsp_source->drc = NULL;
Expand Down

0 comments on commit 588397b

Please sign in to comment.