From: Jaroslav Kysela Date: Sat, 16 Sep 2017 11:54:56 +0000 (+0200) Subject: http: extra data - add may_discard flag for RTP data, issue #4598 X-Git-Tag: v4.2.4~45 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f6157c9a568f2f60f1fd17666b224a0e65255c50;p=thirdparty%2Ftvheadend.git http: extra data - add may_discard flag for RTP data, issue #4598 --- diff --git a/src/http.c b/src/http.c index 4423299bb..f336ccebc 100644 --- a/src/http.c +++ b/src/http.c @@ -794,22 +794,24 @@ http_extra_flush_partial(http_connection_t *hc) * */ int -http_extra_send(http_connection_t *hc, const void *data, size_t data_len) +http_extra_send(http_connection_t *hc, const void *data, + size_t data_len, int may_discard) { uint8_t *b = malloc(data_len); memcpy(b, data, data_len); - return http_extra_send_prealloc(hc, b, data_len); + return http_extra_send_prealloc(hc, b, data_len, may_discard); } /** * */ int -http_extra_send_prealloc(http_connection_t *hc, const void *data, size_t data_len) +http_extra_send_prealloc(http_connection_t *hc, const void *data, + size_t data_len, int may_discard) { if (data == NULL) return 0; pthread_mutex_lock(&hc->hc_extra_lock); - if (hc->hc_extra.hq_size <= 1024*1024) { + if (!may_discard || hc->hc_extra.hq_size <= 1024*1024) { atomic_add(&hc->hc_extra_chunks, 1); htsbuf_append_prealloc(&hc->hc_extra, data, data_len); } else { diff --git a/src/http.h b/src/http.h index 4dd9ee020..ad94a54b9 100644 --- a/src/http.h +++ b/src/http.h @@ -215,9 +215,11 @@ int http_extra_flush(http_connection_t *hc); int http_extra_flush_partial(http_connection_t *hc); -int http_extra_send(http_connection_t *hc, const void *data, size_t data_len); +int http_extra_send(http_connection_t *hc, const void *data, + size_t data_len, int may_discard); -int http_extra_send_prealloc(http_connection_t *hc, const void *data, size_t data_len); +int http_extra_send_prealloc(http_connection_t *hc, const void *data, + size_t data_len, int may_discard); static inline void http_send_begin(http_connection_t *hc) { diff --git a/src/satip/rtp.c b/src/satip/rtp.c index a7add1d4e..a062d5f98 100644 --- a/src/satip/rtp.c +++ b/src/satip/rtp.c @@ -268,14 +268,15 @@ found: } static int -satip_rtp_tcp_data(satip_rtp_session_t *rtp, uint8_t stream, uint8_t *data, size_t data_len) +satip_rtp_tcp_data(satip_rtp_session_t *rtp, uint8_t stream, + uint8_t *data, size_t data_len, int may_discard) { assert(data_len <= 0xffff); data[0] = '$'; data[1] = stream; data[2] = (data_len - 4) >> 8; data[3] = (data_len - 4) & 0xff; - return http_extra_send_prealloc(rtp->hc, data, data_len); + return http_extra_send_prealloc(rtp->hc, data, data_len, may_discard); } static inline int @@ -285,7 +286,7 @@ satip_rtp_flush_tcp_data(satip_rtp_session_t *rtp) int r = 0; if (v->iov_len) - r = satip_rtp_tcp_data(rtp, 0, v->iov_base, v->iov_len); + r = satip_rtp_tcp_data(rtp, 0, v->iov_base, v->iov_len, 1); else free(v->iov_base); v->iov_base = NULL; @@ -937,7 +938,7 @@ satip_rtcp_thread(void *aux) msg1 = malloc(len); if (msg1) { memcpy(msg1, msg, len); - err = satip_rtp_tcp_data(rtp, 1, msg1, len); + err = satip_rtp_tcp_data(rtp, 1, msg1, len, 0); r = err ? -1 : 0; } else { r = -1;