From c078a7c3e08b5b2cbe74f4694e48e5a1ff372fb3 Mon Sep 17 00:00:00 2001 From: Matthieu Pepin Date: Thu, 22 Oct 2015 17:34:47 -0400 Subject: [PATCH 1/4] Freeze availabilityStartTime and adjust timeShiftBufferDepth --- dash/ngx_rtmp_dash_module.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/dash/ngx_rtmp_dash_module.c b/dash/ngx_rtmp_dash_module.c index b78f682..3d96f06 100644 --- a/dash/ngx_rtmp_dash_module.c +++ b/dash/ngx_rtmp_dash_module.c @@ -222,6 +222,7 @@ ngx_rtmp_dash_write_playlist(ngx_rtmp_session_t *s) struct tm tm; ngx_str_t noname, *name; ngx_uint_t i, frame_rate_num, frame_rate_denom; + ngx_uint_t depth_hour, depth_min, depth_msec; ngx_rtmp_dash_ctx_t *ctx; ngx_rtmp_codec_ctx_t *codec_ctx; ngx_rtmp_dash_frag_t *f; @@ -230,6 +231,7 @@ ngx_rtmp_dash_write_playlist(ngx_rtmp_session_t *s) static u_char buffer[NGX_RTMP_DASH_BUFSIZE]; static u_char start_time[sizeof("1970-09-28T12:00:00+06:00")]; static u_char end_time[sizeof("1970-09-28T12:00:00+06:00")]; + static u_char buffer_depth[sizeof("PT1234H00M00.00S")]; static u_char frame_rate[(NGX_INT_T_LEN * 2) + 2]; dacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_dash_module); @@ -263,7 +265,7 @@ ngx_rtmp_dash_write_playlist(ngx_rtmp_session_t *s) " availabilityEndTime=\"%s\"\n" \ " minimumUpdatePeriod=\"PT%uiS\"\n" \ " minBufferTime=\"PT%uiS\"\n" \ - " timeShiftBufferDepth=\"PT0H0M0.00S\"\n" \ + " timeShiftBufferDepth=\"%s\"\n" \ " suggestedPresentationDelay=\"PT%uiS\"\n" \ " profiles=\"urn:hbbtv:dash:profile:isoff-live:2012," \ "urn:mpeg:dash:profile:isoff-live:2011\"\n" \ @@ -342,8 +344,7 @@ ngx_rtmp_dash_write_playlist(ngx_rtmp_session_t *s) " \n" \ "\n" - ngx_libc_localtime(ctx->start_time.sec + - ngx_rtmp_dash_get_frag(s, 0)->timestamp / 1000, &tm); + ngx_libc_localtime(ctx->start_time.sec, &tm); *ngx_sprintf(start_time, "%4d-%02d-%02dT%02d:%02d:%02d%c%02d:%02d", tm.tm_year + 1900, tm.tm_mon + 1, @@ -366,6 +367,22 @@ ngx_rtmp_dash_write_playlist(ngx_rtmp_session_t *s) ngx_abs(ctx->start_time.gmtoff / 60), ngx_abs(ctx->start_time.gmtoff % 60)) = 0; + + depth_msec = (ngx_uint_t) ( + ngx_rtmp_dash_get_frag(s, ctx->nfrags - 1)->timestamp + + ngx_rtmp_dash_get_frag(s, ctx->nfrags - 1)->duration - + ngx_rtmp_dash_get_frag(s, 0)->timestamp); + + depth_hour = (ngx_uint_t) (depth_msec / 3600 / 1000); + depth_msec -= depth_hour * 3600000; + depth_min = (ngx_uint_t) (depth_msec / 60 / 1000); + depth_msec -= depth_min * 60000; + + *ngx_sprintf(buffer_depth, "PT%dH%02dM%02d.%02dS", + depth_hour, depth_min, + (ngx_uint_t) (depth_msec / 1000), + depth_msec % 1000); + last = buffer + sizeof(buffer); p = ngx_slprintf(buffer, last, NGX_RTMP_DASH_MANIFEST_HEADER, @@ -373,6 +390,7 @@ ngx_rtmp_dash_write_playlist(ngx_rtmp_session_t *s) end_time, (ngx_uint_t) (dacf->fraglen / 1000), (ngx_uint_t) (dacf->fraglen / 1000), + buffer_depth, (ngx_uint_t) (dacf->fraglen / 500)); n = ngx_write_fd(fd, buffer, p - buffer); From fd23b27f3f49a366262cde8aedcb7ae4a94598d0 Mon Sep 17 00:00:00 2001 From: Matthieu Pepin Date: Fri, 23 Oct 2015 10:58:52 -0400 Subject: [PATCH 2/4] Fix decimal places (msec, only 2 allowed) --- dash/ngx_rtmp_dash_module.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dash/ngx_rtmp_dash_module.c b/dash/ngx_rtmp_dash_module.c index 3d96f06..012f53e 100644 --- a/dash/ngx_rtmp_dash_module.c +++ b/dash/ngx_rtmp_dash_module.c @@ -231,7 +231,7 @@ ngx_rtmp_dash_write_playlist(ngx_rtmp_session_t *s) static u_char buffer[NGX_RTMP_DASH_BUFSIZE]; static u_char start_time[sizeof("1970-09-28T12:00:00+06:00")]; static u_char end_time[sizeof("1970-09-28T12:00:00+06:00")]; - static u_char buffer_depth[sizeof("PT1234H00M00.00S")]; + static u_char buffer_depth[sizeof("PT000D00H00M00.00S")]; static u_char frame_rate[(NGX_INT_T_LEN * 2) + 2]; dacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_dash_module); @@ -374,14 +374,14 @@ ngx_rtmp_dash_write_playlist(ngx_rtmp_session_t *s) ngx_rtmp_dash_get_frag(s, 0)->timestamp); depth_hour = (ngx_uint_t) (depth_msec / 3600 / 1000); - depth_msec -= depth_hour * 3600000; + depth_msec -= depth_hour * (3600 * 1000); depth_min = (ngx_uint_t) (depth_msec / 60 / 1000); - depth_msec -= depth_min * 60000; + depth_msec -= depth_min * (60 * 1000); *ngx_sprintf(buffer_depth, "PT%dH%02dM%02d.%02dS", depth_hour, depth_min, (ngx_uint_t) (depth_msec / 1000), - depth_msec % 1000); + (ngx_uint_t) ((depth_msec % 1000) / 10)); last = buffer + sizeof(buffer); From f9aa39668988a65212b491433ca2c1497a3ae969 Mon Sep 17 00:00:00 2001 From: Matthieu Pepin Date: Fri, 23 Oct 2015 13:12:01 -0400 Subject: [PATCH 3/4] Add year/month/days to timeShiftBufferDepth --- dash/ngx_rtmp_dash_module.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/dash/ngx_rtmp_dash_module.c b/dash/ngx_rtmp_dash_module.c index 012f53e..525fde4 100644 --- a/dash/ngx_rtmp_dash_module.c +++ b/dash/ngx_rtmp_dash_module.c @@ -222,7 +222,7 @@ ngx_rtmp_dash_write_playlist(ngx_rtmp_session_t *s) struct tm tm; ngx_str_t noname, *name; ngx_uint_t i, frame_rate_num, frame_rate_denom; - ngx_uint_t depth_hour, depth_min, depth_msec; + ngx_uint_t depth_msec; ngx_rtmp_dash_ctx_t *ctx; ngx_rtmp_codec_ctx_t *codec_ctx; ngx_rtmp_dash_frag_t *f; @@ -231,7 +231,7 @@ ngx_rtmp_dash_write_playlist(ngx_rtmp_session_t *s) static u_char buffer[NGX_RTMP_DASH_BUFSIZE]; static u_char start_time[sizeof("1970-09-28T12:00:00+06:00")]; static u_char end_time[sizeof("1970-09-28T12:00:00+06:00")]; - static u_char buffer_depth[sizeof("PT000D00H00M00.00S")]; + static u_char buffer_depth[sizeof("P00Y00M00DT00H00M00.00S")]; static u_char frame_rate[(NGX_INT_T_LEN * 2) + 2]; dacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_dash_module); @@ -373,14 +373,12 @@ ngx_rtmp_dash_write_playlist(ngx_rtmp_session_t *s) ngx_rtmp_dash_get_frag(s, ctx->nfrags - 1)->duration - ngx_rtmp_dash_get_frag(s, 0)->timestamp); - depth_hour = (ngx_uint_t) (depth_msec / 3600 / 1000); - depth_msec -= depth_hour * (3600 * 1000); - depth_min = (ngx_uint_t) (depth_msec / 60 / 1000); - depth_msec -= depth_min * (60 * 1000); + ngx_libc_gmtime((ngx_uint_t) (depth_msec / 1000), &tm); - *ngx_sprintf(buffer_depth, "PT%dH%02dM%02d.%02dS", - depth_hour, depth_min, - (ngx_uint_t) (depth_msec / 1000), + *ngx_sprintf(buffer_depth, "P%dY%02dM%02dDT%dH%02dM%02d.%02dS", + tm.tm_year - 70, tm.tm_mon, + tm.tm_mday - 1, tm.tm_hour, + tm.tm_min, tm.tm_sec, (ngx_uint_t) ((depth_msec % 1000) / 10)); last = buffer + sizeof(buffer); From 0f73f4e05be2184746d3d033ceeaa5e7275c5b11 Mon Sep 17 00:00:00 2001 From: Matthieu Pepin Date: Fri, 23 Oct 2015 13:14:55 -0400 Subject: [PATCH 4/4] Style (use spaces instead of tabs) --- dash/ngx_rtmp_dash_module.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dash/ngx_rtmp_dash_module.c b/dash/ngx_rtmp_dash_module.c index 525fde4..ee76679 100644 --- a/dash/ngx_rtmp_dash_module.c +++ b/dash/ngx_rtmp_dash_module.c @@ -376,9 +376,9 @@ ngx_rtmp_dash_write_playlist(ngx_rtmp_session_t *s) ngx_libc_gmtime((ngx_uint_t) (depth_msec / 1000), &tm); *ngx_sprintf(buffer_depth, "P%dY%02dM%02dDT%dH%02dM%02d.%02dS", - tm.tm_year - 70, tm.tm_mon, - tm.tm_mday - 1, tm.tm_hour, - tm.tm_min, tm.tm_sec, + tm.tm_year - 70, tm.tm_mon, + tm.tm_mday - 1, tm.tm_hour, + tm.tm_min, tm.tm_sec, (ngx_uint_t) ((depth_msec % 1000) / 10)); last = buffer + sizeof(buffer);