From: spdfrk Date: Wed, 2 Mar 2016 20:47:37 +0000 (+0100) Subject: Add RTSP body support and request position in keep alive loop X-Git-Tag: v4.2.1~856 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0e76557a64a1989043bd049b5626283f29c83e91;p=thirdparty%2Ftvheadend.git Add RTSP body support and request position in keep alive loop --- diff --git a/src/http.h b/src/http.h index 22ae0d32b..3fe7dc04b 100644 --- a/src/http.h +++ b/src/http.h @@ -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 ); @@ -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 ); diff --git a/src/input/mpegts/iptv/iptv_rtsp.c b/src/input/mpegts/iptv/iptv_rtsp.c index 80f2adbb1..04d5a3e26 100644 --- a/src/input/mpegts/iptv/iptv_rtsp.c +++ b/src/input/mpegts/iptv/iptv_rtsp.c @@ -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 diff --git a/src/rtsp.c b/src/rtsp.c index 2b59edfbd..78c990ec9 100644 --- a/src/rtsp.c +++ b/src/rtsp.c @@ -28,9 +28,10 @@ * 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) + @@ -38,6 +39,7 @@ rtsp_send( http_client_t *hc, http_cmd_t cmd, (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) { @@ -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