From e8081fd94f1d7ae4483f0a5ca002af8a79d447eb Mon Sep 17 00:00:00 2001 From: Roman Arutyunyan Date: Mon, 2 Dec 2013 20:30:28 +0400 Subject: [PATCH] implemented dash discont handling --- dash/ngx_rtmp_dash_module.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/dash/ngx_rtmp_dash_module.c b/dash/ngx_rtmp_dash_module.c index c99f310..2a2e3ff 100644 --- a/dash/ngx_rtmp_dash_module.c +++ b/dash/ngx_rtmp_dash_module.c @@ -991,6 +991,7 @@ static void ngx_rtmp_dash_update_fragments(ngx_rtmp_session_t *s, ngx_int_t boundary, uint32_t timestamp) { + int32_t d; ngx_int_t hit; ngx_rtmp_dash_ctx_t *ctx; ngx_rtmp_dash_frag_t *f; @@ -1000,7 +1001,19 @@ ngx_rtmp_dash_update_fragments(ngx_rtmp_session_t *s, ngx_int_t boundary, ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_dash_module); f = ngx_rtmp_dash_get_frag(s, ctx->nfrags); - hit = (timestamp >= f->timestamp + dacf->fraglen); + d = (int32_t) (timestamp - f->timestamp); + + if (d >= 0) { + + f->duration = timestamp - f->timestamp; + hit = (f->duration >= dacf->fraglen); + + } else { + + /* sometimes clients generate slightly unordered frames */ + + hit = (-d > 1000); + } if (ctx->has_video && !hit) { boundary = 0; @@ -1022,8 +1035,6 @@ ngx_rtmp_dash_update_fragments(ngx_rtmp_session_t *s, ngx_int_t boundary, boundary = 1; } - f->duration = (timestamp - f->timestamp); - if (boundary) { ngx_rtmp_dash_close_fragments(s); ngx_rtmp_dash_open_fragments(s);