From fe0d8051797131e873d8501c8c43583619ad7b5b Mon Sep 17 00:00:00 2001 From: Roman Arutyunyan Date: Thu, 2 Jan 2014 10:19:57 +0400 Subject: [PATCH] improved hls boundary check --- hls/ngx_rtmp_hls_module.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/hls/ngx_rtmp_hls_module.c b/hls/ngx_rtmp_hls_module.c index 6a4440a..5fa904a 100644 --- a/hls/ngx_rtmp_hls_module.c +++ b/hls/ngx_rtmp_hls_module.c @@ -501,7 +501,7 @@ ngx_rtmp_hls_write_playlist(ngx_rtmp_session_t *s) "%s" "#EXTINF:%.3f,\n" "%V%V%s%uL.ts\n", - f->discont ? "#EXT-X-DISCONTINUITY\n" : "", + /*f->discont ? "#EXT-X-DISCONTINUITY\n" :*/ "", f->duration, &hacf->base_url, &name_part, sep, f->id); ngx_log_debug5(NGX_LOG_DEBUG_RTMP, s->connection->log, 0, @@ -1348,22 +1348,24 @@ ngx_rtmp_hls_update_fragment(ngx_rtmp_session_t *s, uint64_t ts, ngx_msec_t ts_frag_len; ngx_int_t same_frag; ngx_buf_t *b; + int64_t d; hacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_hls_module); - ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_hls_module); - f = NULL; if (ctx->opened) { - f = ngx_rtmp_hls_get_frag(s, ctx->nfrags); - f->duration = (ts - ctx->frag_ts) / 90000.; + d = (int64_t) (ts - ctx->frag_ts); - if (f->duration * 1000 > hacf->max_fraglen) { + if (d > (int64_t) hacf->max_fraglen * 90 || d < -90000) { ngx_log_error(NGX_LOG_ERR, s->connection->log, 0, - "hls: max fragment length reached"); + "hls: max fragment length reached: %.3f sec, ", + f->duration); boundary = 1; + + } else { + f->duration = (ts - ctx->frag_ts) / 90000.; } }