From: Jaroslav Kysela Date: Mon, 11 Jan 2016 15:13:10 +0000 (+0100) Subject: iptv: fix the time buffer limit configuration, fixes #3480 X-Git-Tag: v4.2.1~1178 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5966e61730d23db4df28f6068c1d9ee6ef408191;p=thirdparty%2Ftvheadend.git iptv: fix the time buffer limit configuration, fixes #3480 --- diff --git a/src/input/mpegts/iptv/iptv.c b/src/input/mpegts/iptv/iptv.c index d4f577223..66fe4a593 100644 --- a/src/input/mpegts/iptv/iptv.c +++ b/src/input/mpegts/iptv/iptv.c @@ -410,18 +410,25 @@ iptv_input_display_name ( mpegts_input_t *mi, char *buf, size_t len ) static inline int iptv_input_pause_check ( iptv_mux_t *im ) { - int64_t s64; + int64_t s64, limit; if (im->im_pcr == PTS_UNSET) return 0; + limit = im->mm_iptv_buffer_limit; + if (!limit) + limit = im->im_handler->buffer_limit; + if (limit == UINT32_MAX) + return 0; + limit *= 1000; s64 = getmonoclock() - im->im_pcr_start; im->im_pcr_start += s64; im->im_pcr += (((s64 / 10LL) * 9LL) + 4LL) / 10LL; im->im_pcr &= PTS_MASK; - tvhtrace("iptv-pcr", "pcr: updated %"PRId64", time start %"PRId64, im->im_pcr, im->im_pcr_start); + tvhtrace("iptv-pcr", "pcr: updated %"PRId64", time start %"PRId64", limit %"PRId64, + im->im_pcr, im->im_pcr_start, limit); /* queued more than 3 seconds? trigger the pause */ - return im->im_pcr_end - im->im_pcr_start >= 3000000LL; + return im->im_pcr_end - im->im_pcr_start >= limit; } void diff --git a/src/input/mpegts/iptv/iptv_file.c b/src/input/mpegts/iptv/iptv_file.c index 6b7f627bb..eaff540e9 100644 --- a/src/input/mpegts/iptv/iptv_file.c +++ b/src/input/mpegts/iptv/iptv_file.c @@ -137,6 +137,7 @@ iptv_file_init ( void ) static iptv_handler_t ih[] = { { .scheme = "file", + .buffer_limit = 5000, .start = iptv_file_start, .stop = iptv_file_stop }, diff --git a/src/input/mpegts/iptv/iptv_http.c b/src/input/mpegts/iptv/iptv_http.c index 2102f008c..07d0de3ae 100644 --- a/src/input/mpegts/iptv/iptv_http.c +++ b/src/input/mpegts/iptv/iptv_http.c @@ -592,12 +592,14 @@ iptv_http_init ( void ) static iptv_handler_t ih[] = { { .scheme = "http", + .buffer_limit = 5000, .start = iptv_http_start, .stop = iptv_http_stop, .pause = iptv_http_pause }, { .scheme = "https", + .buffer_limit = 5000, .start = iptv_http_start, .stop = iptv_http_stop, .pause = iptv_http_pause diff --git a/src/input/mpegts/iptv/iptv_mux.c b/src/input/mpegts/iptv/iptv_mux.c index 6f12fb6df..4398bec8f 100644 --- a/src/input/mpegts/iptv/iptv_mux.c +++ b/src/input/mpegts/iptv/iptv_mux.c @@ -246,6 +246,16 @@ const idclass_t iptv_mux_class = .off = offsetof(iptv_mux_t, mm_iptv_satip_dvbt_freq), .opts = PO_ADVANCED }, + { + .type = PT_U32, + .id = "iptv_buffer_limit", + .name = N_("Buffering limit (ms)"), + .desc = N_("Specifies the incoming buffering limit in milliseconds (PCR based). " + "If PCR time difference from the system clock is higher, the incoming " + "stream is paused."), + .off = offsetof(iptv_mux_t, mm_iptv_buffer_limit), + .opts = PO_ADVANCED, + }, {} } }; diff --git a/src/input/mpegts/iptv/iptv_pipe.c b/src/input/mpegts/iptv/iptv_pipe.c index 2b9aaac24..4902c5208 100644 --- a/src/input/mpegts/iptv/iptv_pipe.c +++ b/src/input/mpegts/iptv/iptv_pipe.c @@ -162,6 +162,7 @@ iptv_pipe_init ( void ) static iptv_handler_t ih[] = { { .scheme = "pipe", + .buffer_limit = 5000, .start = iptv_pipe_start, .stop = iptv_pipe_stop, .read = iptv_pipe_read, diff --git a/src/input/mpegts/iptv/iptv_private.h b/src/input/mpegts/iptv/iptv_private.h index 1350be756..2188adbc2 100644 --- a/src/input/mpegts/iptv/iptv_private.h +++ b/src/input/mpegts/iptv/iptv_private.h @@ -49,6 +49,9 @@ typedef struct iptv_handler iptv_handler_t; struct iptv_handler { const char *scheme; + + uint32_t buffer_limit; + int (*start) ( iptv_mux_t *im, const char *raw, const url_t *url ); void (*stop) ( iptv_mux_t *im ); ssize_t (*read) ( iptv_mux_t *im ); @@ -141,6 +144,8 @@ struct iptv_mux sbuf_t mm_iptv_buffer; + uint32_t mm_iptv_buffer_limit; + iptv_handler_t *im_handler; gtimer_t im_pause_timer; diff --git a/src/input/mpegts/iptv/iptv_udp.c b/src/input/mpegts/iptv/iptv_udp.c index f701c2108..ab6636c9d 100644 --- a/src/input/mpegts/iptv/iptv_udp.c +++ b/src/input/mpegts/iptv/iptv_udp.c @@ -184,6 +184,7 @@ iptv_udp_init ( void ) static iptv_handler_t ih[] = { { .scheme = "udp", + .buffer_limit = UINT32_MAX, /* unlimited */ .start = iptv_udp_start, .stop = iptv_udp_stop, .read = iptv_udp_read, @@ -191,6 +192,7 @@ iptv_udp_init ( void ) }, { .scheme = "rtp", + .buffer_limit = UINT32_MAX, /* unlimited */ .start = iptv_udp_start, .stop = iptv_udp_stop, .read = iptv_udp_rtp_read,