Skip to content

Commit

Permalink
Fixed MPEG-DASH playback and MPD validity.
Browse files Browse the repository at this point in the history
  • Loading branch information
arut committed Jun 10, 2017
1 parent ed23a34 commit 1cdeb07
Showing 1 changed file with 20 additions and 34 deletions.
54 changes: 20 additions & 34 deletions dash/ngx_rtmp_dash_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ ngx_rtmp_dash_write_playlist(ngx_rtmp_session_t *s)
ngx_rtmp_dash_app_conf_t *dacf;

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 start_time[sizeof("1970-09-28T12:00:00Z")];
static u_char pub_time[sizeof("1970-09-28T12:00:00Z")];

dacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_dash_module);
ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_dash_module);
Expand Down Expand Up @@ -259,11 +259,10 @@ ngx_rtmp_dash_write_playlist(ngx_rtmp_session_t *s)
" type=\"dynamic\"\n" \
" xmlns=\"urn:mpeg:dash:schema:mpd:2011\"\n" \
" availabilityStartTime=\"%s\"\n" \
" availabilityEndTime=\"%s\"\n" \
" publishTime=\"%s\"\n" \
" minimumUpdatePeriod=\"PT%uiS\"\n" \
" minBufferTime=\"PT%uiS\"\n" \
" timeShiftBufferDepth=\"PT0H0M0.00S\"\n" \
" suggestedPresentationDelay=\"PT%uiS\"\n" \
" timeShiftBufferDepth=\"PT%uiS\"\n" \
" profiles=\"urn:hbbtv:dash:profile:isoff-live:2012," \
"urn:mpeg:dash:profile:isoff-live:2011\"\n" \
" xmlns:xsi=\"http://www.w3.org/2011/XMLSchema-instance\"\n" \
Expand All @@ -285,11 +284,9 @@ ngx_rtmp_dash_write_playlist(ngx_rtmp_session_t *s)
" width=\"%ui\"\n" \
" height=\"%ui\"\n" \
" frameRate=\"%ui\"\n" \
" sar=\"1:1\"\n" \
" startWithSAP=\"1\"\n" \
" bandwidth=\"%ui\">\n" \
" <SegmentTemplate\n" \
" presentationTimeOffset=\"0\"\n" \
" timescale=\"1000\"\n" \
" media=\"%V%s$Time$.m4v\"\n" \
" initialization=\"%V%sinit.m4v\">\n" \
Expand Down Expand Up @@ -323,7 +320,6 @@ ngx_rtmp_dash_write_playlist(ngx_rtmp_session_t *s)
" startWithSAP=\"1\"\n" \
" bandwidth=\"%ui\">\n" \
" <SegmentTemplate\n" \
" presentationTimeOffset=\"0\"\n" \
" timescale=\"1000\"\n" \
" media=\"%V%s$Time$.m4a\"\n" \
" initialization=\"%V%sinit.m4a\">\n" \
Expand All @@ -341,38 +337,28 @@ ngx_rtmp_dash_write_playlist(ngx_rtmp_session_t *s)
" </Period>\n" \
"</MPD>\n"

ngx_libc_localtime(ctx->start_time.sec +
ngx_rtmp_dash_get_frag(s, 0)->timestamp / 1000, &tm);

*ngx_sprintf(start_time, "%4d-%02d-%02dT%02d:%02d:%02d%c%02d:%02d",
tm.tm_year + 1900, tm.tm_mon + 1,
tm.tm_mday, tm.tm_hour,
tm.tm_min, tm.tm_sec,
ctx->start_time.gmtoff < 0 ? '-' : '+',
ngx_abs(ctx->start_time.gmtoff / 60),
ngx_abs(ctx->start_time.gmtoff % 60)) = 0;

ngx_libc_localtime(ctx->start_time.sec +
(ngx_rtmp_dash_get_frag(s, ctx->nfrags - 1)->timestamp +
ngx_rtmp_dash_get_frag(s, ctx->nfrags - 1)->duration) /
1000, &tm);

*ngx_sprintf(end_time, "%4d-%02d-%02dT%02d:%02d:%02d%c%02d:%02d",
tm.tm_year + 1900, tm.tm_mon + 1,
tm.tm_mday, tm.tm_hour,
tm.tm_min, tm.tm_sec,
ctx->start_time.gmtoff < 0 ? '-' : '+',
ngx_abs(ctx->start_time.gmtoff / 60),
ngx_abs(ctx->start_time.gmtoff % 60)) = 0;
ngx_libc_gmtime(ctx->start_time.sec / 1000, &tm);

ngx_sprintf(start_time, "%4d-%02d-%02dT%02d:%02d:%02dZ%Z",
tm.tm_year + 1900, tm.tm_mon + 1,
tm.tm_mday, tm.tm_hour,
tm.tm_min, tm.tm_sec);

ngx_libc_gmtime(ngx_time(), &tm);

ngx_sprintf(pub_time, "%4d-%02d-%02dT%02d:%02d:%02dZ%Z",
tm.tm_year + 1900, tm.tm_mon + 1,
tm.tm_mday, tm.tm_hour,
tm.tm_min, tm.tm_sec);

last = buffer + sizeof(buffer);

p = ngx_slprintf(buffer, last, NGX_RTMP_DASH_MANIFEST_HEADER,
start_time,
end_time,
(ngx_uint_t) (dacf->fraglen / 1000),
pub_time,
(ngx_uint_t) (dacf->fraglen / 1000),
(ngx_uint_t) (dacf->fraglen / 500));
(ngx_uint_t) (dacf->fraglen / 500),
(ngx_uint_t) (dacf->playlen / 1000));

n = ngx_write_fd(fd, buffer, p - buffer);

Expand Down

0 comments on commit 1cdeb07

Please sign in to comment.