Skip to content

Commit

Permalink
Fix RTSP SETUP when url includes query string parameters (fixes #1869) (
Browse files Browse the repository at this point in the history
  • Loading branch information
lminiero authored Dec 4, 2019
1 parent 0f98b15 commit 8c4998e
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions plugins/janus_streaming.c
Original file line number Diff line number Diff line change
Expand Up @@ -5576,24 +5576,38 @@ static int janus_streaming_rtsp_connect_to_server(janus_streaming_mountpoint *mp
return -7;
}

/* Check if a query string is part of the URL, as that may impact the SETUP request */
char *rtsp_url = source->rtsp_url, *rtsp_querystring = NULL;
char **parts = g_strsplit(source->rtsp_url, "?", 2);
if(parts[0] != NULL) {
rtsp_url = parts[0];
rtsp_querystring = parts[1];
}

if(vresult != -1) {
/* Send an RTSP SETUP for video */
g_free(curldata->buffer);
curldata->buffer = g_malloc0(1);
curldata->size = 0;
if(strstr(vcontrol, source->rtsp_url) == vcontrol) {
gboolean add_qs = (rtsp_querystring != NULL);
if(add_qs && strstr(vcontrol, rtsp_querystring) != NULL)
add_qs = FALSE;
if(strstr(vcontrol, rtsp_url) == vcontrol) {
/* The control attribute already contains the whole URL? */
g_snprintf(uri, sizeof(uri), "%s", vcontrol);
g_snprintf(uri, sizeof(uri), "%s%s%s", vcontrol,
add_qs ? "?" : "", add_qs ? rtsp_querystring : "");
} else {
/* Append the control attribute to the URL */
g_snprintf(uri, sizeof(uri), "%s/%s", source->rtsp_url, vcontrol);
g_snprintf(uri, sizeof(uri), "%s/%s%s%s", rtsp_url, vcontrol,
add_qs ? "?" : "", add_qs ? rtsp_querystring : "");
}
curl_easy_setopt(curl, CURLOPT_RTSP_STREAM_URI, uri);
curl_easy_setopt(curl, CURLOPT_RTSP_TRANSPORT, vtransport);
curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, (long)CURL_RTSPREQ_SETUP);
res = curl_easy_perform(curl);
if(res != CURLE_OK) {
JANUS_LOG(LOG_ERR, "Couldn't send SETUP request: %s\n", curl_easy_strerror(res));
g_strfreev(parts);
curl_easy_cleanup(curl);
g_free(curldata->buffer);
g_free(curldata);
Expand All @@ -5604,6 +5618,7 @@ static int janus_streaming_rtsp_connect_to_server(janus_streaming_mountpoint *mp
return -5;
} else if(code != 200) {
JANUS_LOG(LOG_ERR, "Couldn't get SETUP code: %ld\n", code);
g_strfreev(parts);
curl_easy_cleanup(curl);
g_free(curldata->buffer);
g_free(curldata);
Expand Down Expand Up @@ -5755,19 +5770,25 @@ static int janus_streaming_rtsp_connect_to_server(janus_streaming_mountpoint *mp
g_free(curldata->buffer);
curldata->buffer = g_malloc0(1);
curldata->size = 0;
if(strstr(acontrol, source->rtsp_url) == acontrol) {
gboolean add_qs = (rtsp_querystring != NULL);
if(add_qs && strstr(acontrol, rtsp_querystring) != NULL)
add_qs = FALSE;
if(strstr(acontrol, rtsp_url) == acontrol) {
/* The control attribute already contains the whole URL? */
g_snprintf(uri, sizeof(uri), "%s", acontrol);
g_snprintf(uri, sizeof(uri), "%s%s%s", acontrol,
add_qs ? "?" : "", add_qs ? rtsp_querystring : "");
} else {
/* Append the control attribute to the URL */
g_snprintf(uri, sizeof(uri), "%s/%s", source->rtsp_url, acontrol);
g_snprintf(uri, sizeof(uri), "%s/%s%s%s", rtsp_url, acontrol,
add_qs ? "?" : "", add_qs ? rtsp_querystring : "");
}
curl_easy_setopt(curl, CURLOPT_RTSP_STREAM_URI, uri);
curl_easy_setopt(curl, CURLOPT_RTSP_TRANSPORT, atransport);
curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, (long)CURL_RTSPREQ_SETUP);
res = curl_easy_perform(curl);
if(res != CURLE_OK) {
JANUS_LOG(LOG_ERR, "Couldn't send SETUP request: %s\n", curl_easy_strerror(res));
g_strfreev(parts);
curl_easy_cleanup(curl);
g_free(curldata->buffer);
g_free(curldata);
Expand All @@ -5778,6 +5799,7 @@ static int janus_streaming_rtsp_connect_to_server(janus_streaming_mountpoint *mp
return -6;
} else if(code != 200) {
JANUS_LOG(LOG_ERR, "Couldn't get SETUP code: %ld\n", code);
g_strfreev(parts);
curl_easy_cleanup(curl);
g_free(curldata->buffer);
g_free(curldata);
Expand Down Expand Up @@ -5928,6 +5950,7 @@ static int janus_streaming_rtsp_connect_to_server(janus_streaming_mountpoint *mp
JANUS_LOG(LOG_WARN, "No host address for the RTSP audio stream, no latching will be performed\n");
}
}
g_strfreev(parts);

/* Update the source (but check if ptype/rtpmap/fmtp need to be overridden) */
if(mp->codecs.audio_pt == -1)
Expand Down

0 comments on commit 8c4998e

Please sign in to comment.