mirror of
https://github.com/zotanmew/nginx-rtmp-module.git
synced 2024-05-19 09:41:07 +02:00
Adjusted time roundup, time string formating
This commit is contained in:
parent
341b07409d
commit
b4ecd58544
|
@ -257,7 +257,10 @@ ngx_rtmp_dash_write_playlist(ngx_rtmp_session_t *s)
|
||||||
struct tm tm;
|
struct tm tm;
|
||||||
ngx_str_t noname, *name;
|
ngx_str_t noname, *name;
|
||||||
ngx_uint_t i, frame_rate_num, frame_rate_denom;
|
ngx_uint_t i, frame_rate_num, frame_rate_denom;
|
||||||
ngx_uint_t depth_msec, update_period;
|
ngx_uint_t depth_msec, depth_sec;
|
||||||
|
ngx_uint_t update_period, update_period_msec;
|
||||||
|
ngx_uint_t buffer_time, buffer_time_msec;
|
||||||
|
ngx_uint_t presentation_delay, presentation_delay_msec;
|
||||||
ngx_rtmp_dash_ctx_t *ctx;
|
ngx_rtmp_dash_ctx_t *ctx;
|
||||||
ngx_rtmp_codec_ctx_t *codec_ctx;
|
ngx_rtmp_codec_ctx_t *codec_ctx;
|
||||||
ngx_rtmp_dash_frag_t *f;
|
ngx_rtmp_dash_frag_t *f;
|
||||||
|
@ -268,7 +271,7 @@ ngx_rtmp_dash_write_playlist(ngx_rtmp_session_t *s)
|
||||||
static u_char buffer[NGX_RTMP_DASH_BUFSIZE];
|
static u_char buffer[NGX_RTMP_DASH_BUFSIZE];
|
||||||
static u_char avaliable_time[NGX_RTMP_DASH_GMT_LENGTH];
|
static u_char avaliable_time[NGX_RTMP_DASH_GMT_LENGTH];
|
||||||
static u_char publish_time[NGX_RTMP_DASH_GMT_LENGTH];
|
static u_char publish_time[NGX_RTMP_DASH_GMT_LENGTH];
|
||||||
static u_char buffer_depth[sizeof("P00Y00M00DT00H00M00.00S")];
|
static u_char buffer_depth[sizeof("P00Y00M00DT00H00M00.000S")];
|
||||||
static u_char frame_rate[(NGX_INT_T_LEN * 2) + 2];
|
static u_char frame_rate[(NGX_INT_T_LEN * 2) + 2];
|
||||||
|
|
||||||
dacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_dash_module);
|
dacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_dash_module);
|
||||||
|
@ -300,10 +303,10 @@ ngx_rtmp_dash_write_playlist(ngx_rtmp_session_t *s)
|
||||||
" xmlns=\"urn:mpeg:dash:schema:mpd:2011\"\n" \
|
" xmlns=\"urn:mpeg:dash:schema:mpd:2011\"\n" \
|
||||||
" availabilityStartTime=\"%s\"\n" \
|
" availabilityStartTime=\"%s\"\n" \
|
||||||
" publishTime=\"%s\"\n" \
|
" publishTime=\"%s\"\n" \
|
||||||
" minimumUpdatePeriod=\"PT%ui.%uiS\"\n" \
|
" minimumUpdatePeriod=\"PT%ui.%03uiS\"\n" \
|
||||||
" minBufferTime=\"PT%ui.%uiS\"\n" \
|
" minBufferTime=\"PT%ui.%03uiS\"\n" \
|
||||||
" timeShiftBufferDepth=\"%s\"\n" \
|
" timeShiftBufferDepth=\"%s\"\n" \
|
||||||
" suggestedPresentationDelay=\"PT%ui.%uiS\"\n" \
|
" suggestedPresentationDelay=\"PT%ui.%03uiS\"\n" \
|
||||||
" profiles=\"urn:hbbtv:dash:profile:isoff-live:2012," \
|
" profiles=\"urn:hbbtv:dash:profile:isoff-live:2012," \
|
||||||
"urn:mpeg:dash:profile:isoff-live:2011\"\n" \
|
"urn:mpeg:dash:profile:isoff-live:2011\"\n" \
|
||||||
" xmlns:xsi=\"http://www.w3.org/2011/XMLSchema-instance\"\n" \
|
" xmlns:xsi=\"http://www.w3.org/2011/XMLSchema-instance\"\n" \
|
||||||
|
@ -401,18 +404,22 @@ ngx_rtmp_dash_write_playlist(ngx_rtmp_session_t *s)
|
||||||
/* Stream publish time */
|
/* Stream publish time */
|
||||||
*ngx_sprintf(publish_time, "%s", avaliable_time) = 0;
|
*ngx_sprintf(publish_time, "%s", avaliable_time) = 0;
|
||||||
|
|
||||||
depth_msec = (ngx_uint_t) (
|
depth_sec = (ngx_uint_t) (
|
||||||
ngx_rtmp_dash_get_frag(s, ctx->nfrags - 1)->timestamp +
|
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, ctx->nfrags - 1)->duration -
|
||||||
ngx_rtmp_dash_get_frag(s, 0)->timestamp);
|
ngx_rtmp_dash_get_frag(s, 0)->timestamp);
|
||||||
|
|
||||||
ngx_libc_gmtime((ngx_uint_t) (depth_msec / 1000), &tm);
|
depth_msec = depth_sec % 1000;
|
||||||
|
depth_sec -= depth_msec;
|
||||||
|
depth_sec /= 1000;
|
||||||
|
|
||||||
*ngx_sprintf(buffer_depth, "P%dY%02dM%02dDT%dH%02dM%02d.%02dS",
|
ngx_libc_gmtime(depth_sec, &tm);
|
||||||
|
|
||||||
|
*ngx_sprintf(buffer_depth, "P%dY%02dM%02dDT%dH%02dM%02d.%03dS",
|
||||||
tm.tm_year - 70, tm.tm_mon,
|
tm.tm_year - 70, tm.tm_mon,
|
||||||
tm.tm_mday - 1, tm.tm_hour,
|
tm.tm_mday - 1, tm.tm_hour,
|
||||||
tm.tm_min, tm.tm_sec,
|
tm.tm_min, tm.tm_sec,
|
||||||
(ngx_uint_t) ((depth_msec % 1000) / 10)) = 0;
|
depth_msec) = 0;
|
||||||
|
|
||||||
last = buffer + sizeof(buffer);
|
last = buffer + sizeof(buffer);
|
||||||
|
|
||||||
|
@ -431,19 +438,37 @@ ngx_rtmp_dash_write_playlist(ngx_rtmp_session_t *s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add 100 msec to make some update delay and trick int rounding
|
// Reasonable delay for streaming
|
||||||
update_period += 100;
|
presentation_delay = update_period * 2 + 1000;
|
||||||
|
presentation_delay_msec = presentation_delay % 1000;
|
||||||
|
presentation_delay -= presentation_delay_msec;
|
||||||
|
presentation_delay /= 1000;
|
||||||
|
|
||||||
|
// Calculate msec part and seconds
|
||||||
|
update_period_msec = update_period % 1000;
|
||||||
|
update_period -= update_period_msec;
|
||||||
|
update_period /= 1000;
|
||||||
|
|
||||||
|
// Buffer length by default fragment length
|
||||||
|
buffer_time = dacf->fraglen;
|
||||||
|
buffer_time_msec = buffer_time % 1000;
|
||||||
|
buffer_time -= buffer_time_msec;
|
||||||
|
buffer_time /= 1000;
|
||||||
|
|
||||||
|
// Fill DASH header
|
||||||
p = ngx_slprintf(buffer, last, NGX_RTMP_DASH_MANIFEST_HEADER,
|
p = ngx_slprintf(buffer, last, NGX_RTMP_DASH_MANIFEST_HEADER,
|
||||||
|
// availabilityStartTime
|
||||||
avaliable_time,
|
avaliable_time,
|
||||||
|
// publishTime
|
||||||
publish_time,
|
publish_time,
|
||||||
(ngx_uint_t) (update_period / 1000),
|
// minimumUpdatePeriod
|
||||||
(ngx_uint_t) ((update_period % 1000) / 10),
|
update_period, update_period_msec,
|
||||||
(ngx_uint_t) (update_period / 1000),
|
// minBufferTime
|
||||||
(ngx_uint_t) ((update_period % 1000) / 10),
|
buffer_time, buffer_time_msec,
|
||||||
|
// timeShiftBufferDepth
|
||||||
buffer_depth,
|
buffer_depth,
|
||||||
(ngx_uint_t) (update_period / 1000),
|
// suggestedPresentationDelay
|
||||||
(ngx_uint_t) ((update_period % 1000) / 10)
|
presentation_delay, presentation_delay_msec
|
||||||
);
|
);
|
||||||
|
|
||||||
/* UTCTiming value */
|
/* UTCTiming value */
|
||||||
|
|
Loading…
Reference in a new issue