Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add RTSP body support and request position in keep alive loop
  • Loading branch information
spdfrk authored and perexg committed Mar 16, 2016
1 parent 8f86549 commit 0e76557
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
15 changes: 12 additions & 3 deletions src/http.h
Expand Up @@ -391,8 +391,14 @@ void http_client_unpause( http_client_t *hc );
* RTSP helpers
*/

int rtsp_send( http_client_t *hc, http_cmd_t cmd, const char *path,
const char *query, http_arg_list_t *hdr );
int rtsp_send_ext( http_client_t *hc, http_cmd_t cmd, const char *path,
const char *query, http_arg_list_t *hdr, const char *body, size_t size );

static inline int
rtsp_send( http_client_t *hc, http_cmd_t cmd, const char *path,
const char *query, http_arg_list_t *hdr ) {
return rtsp_send_ext( hc, cmd, path, query, hdr, NULL, 0 );
}

void rtsp_clear_session( http_client_t *hc );

Expand Down Expand Up @@ -421,7 +427,10 @@ rtsp_teardown( http_client_t *hc, const char *path, const char *query ) {
}

static inline int rtsp_get_parameter( http_client_t *hc, const char *parameter ) {
return rtsp_send(hc, RTSP_CMD_GET_PARAMETER, NULL, parameter, NULL);
http_arg_list_t hdr;
http_arg_init(&hdr);
http_arg_set(&hdr, "Content-Type", "text/parameters");
return rtsp_send_ext(hc, RTSP_CMD_GET_PARAMETER, NULL, NULL, &hdr, parameter, strlen(parameter));
}

int rtsp_describe_decode( http_client_t *hc );
Expand Down
2 changes: 1 addition & 1 deletion src/input/mpegts/iptv/iptv_rtsp.c
Expand Up @@ -53,7 +53,7 @@ iptv_rtsp_alive_cb ( void *aux )
iptv_mux_t *im = aux;
rtsp_priv_t *rp = im->im_data;
if(rp->hc->hc_rtsp_keep_alive_cmd == RTSP_CMD_GET_PARAMETER)
rtsp_get_parameter(rp->hc, "");
rtsp_get_parameter(rp->hc, "position");
else if(rp->hc->hc_rtsp_keep_alive_cmd == RTSP_CMD_OPTIONS)
rtsp_send(rp->hc, RTSP_CMD_OPTIONS, rp->path, rp->query, NULL);
else
Expand Down
23 changes: 20 additions & 3 deletions src/rtsp.c
Expand Up @@ -28,16 +28,18 @@
* Utils
*/
int
rtsp_send( http_client_t *hc, http_cmd_t cmd,
rtsp_send_ext( http_client_t *hc, http_cmd_t cmd,
const char *path, const char *query,
http_arg_list_t *hdr )
http_arg_list_t *hdr,
const char *body, size_t size )
{
http_arg_list_t h;
size_t blen = 7 + strlen(hc->hc_host) +
(hc->hc_port != 554 ? 7 : 0) +
(path ? strlen(path) : 1) + 1;
char *buf = alloca(blen);
char buf2[7];
char buf_body[size + 3];

if (hc->hc_rtsp_session) {
if (hdr == NULL) {
Expand All @@ -46,13 +48,28 @@ rtsp_send( http_client_t *hc, http_cmd_t cmd,
}
http_arg_set(hdr, "Session", hc->hc_rtsp_session);
}

if (size > 0) {
if (hdr == NULL) {
hdr = &h;
http_arg_init(&h);
}
strncpy(buf_body, body, sizeof(buf_body));
strncat(buf_body, "\r\n", 2);
snprintf(buf2, sizeof(buf2), "%lu", size + 2);
http_arg_set(hdr, "Content-Length", buf2);
}

http_client_basic_auth(hc, hdr, hc->hc_rtsp_user, hc->hc_rtsp_pass);
if (hc->hc_port != 554)
snprintf(buf2, sizeof(buf2), ":%d", hc->hc_port);
else
buf2[0] = '\0';
snprintf(buf, blen, "rtsp://%s%s%s", hc->hc_host, buf2, path ? path : "/");
return http_client_send(hc, cmd, buf, query, hdr, NULL, 0);
if(size > 0)
return http_client_send(hc, cmd, buf, query, hdr, buf_body, size + 2);
else
return http_client_send(hc, cmd, buf, query, hdr, NULL, 0);
}

void
Expand Down

0 comments on commit 0e76557

Please sign in to comment.