Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
iptv: fix the time buffer limit configuration, fixes #3480
  • Loading branch information
perexg committed Jan 11, 2016
1 parent bd36886 commit 5966e61
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/input/mpegts/iptv/iptv.c
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/input/mpegts/iptv/iptv_file.c
Expand Up @@ -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
},
Expand Down
2 changes: 2 additions & 0 deletions src/input/mpegts/iptv/iptv_http.c
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions src/input/mpegts/iptv/iptv_mux.c
Expand Up @@ -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,
},
{}
}
};
Expand Down
1 change: 1 addition & 0 deletions src/input/mpegts/iptv/iptv_pipe.c
Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions src/input/mpegts/iptv/iptv_private.h
Expand Up @@ -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 );
Expand Down Expand Up @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions src/input/mpegts/iptv/iptv_udp.c
Expand Up @@ -184,13 +184,15 @@ 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,
.pause = iptv_input_pause_handler
},
{
.scheme = "rtp",
.buffer_limit = UINT32_MAX, /* unlimited */
.start = iptv_udp_start,
.stop = iptv_udp_stop,
.read = iptv_udp_rtp_read,
Expand Down

0 comments on commit 5966e61

Please sign in to comment.