mirror of
https://github.com/zotanmew/nginx-rtmp-module.git
synced 2024-05-20 09:51:08 +02:00
Fix HLS/DASH playlists cleanup
- use x2 hls max frgment duration - do more recent cleanup - half playlist duration - adjust expiration times for playlist files - add more debug to dash fragments update function
This commit is contained in:
parent
292a6c1ca8
commit
4ce7ea8b9d
|
@ -1049,6 +1049,10 @@ 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);
|
ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_dash_module);
|
||||||
f = ngx_rtmp_dash_get_frag(s, ctx->nfrags);
|
f = ngx_rtmp_dash_get_frag(s, ctx->nfrags);
|
||||||
|
|
||||||
|
ngx_log_debug4(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
|
||||||
|
"dash: update_fragments: timestamp=%ui, f-timestamp=%ui, boundary=%i, dacf-fraglen=%ui",
|
||||||
|
timestamp, f->timestamp, boundary, dacf->fraglen);
|
||||||
|
|
||||||
d = (int32_t) (timestamp - f->timestamp);
|
d = (int32_t) (timestamp - f->timestamp);
|
||||||
|
|
||||||
if (d >= 0) {
|
if (d >= 0) {
|
||||||
|
@ -1063,26 +1067,44 @@ ngx_rtmp_dash_update_fragments(ngx_rtmp_session_t *s, ngx_int_t boundary,
|
||||||
hit = (-d > 1000);
|
hit = (-d > 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ngx_log_debug3(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
|
||||||
|
"dash: update_fragments: d=%i, f-duration=%ui, hit=%i",
|
||||||
|
d, f->duration, hit);
|
||||||
|
|
||||||
if (ctx->has_video && !hit) {
|
if (ctx->has_video && !hit) {
|
||||||
boundary = 0;
|
boundary = 0;
|
||||||
|
ngx_log_debug0(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
|
||||||
|
"dash: update_fragments: boundary=0 cos has_video && !hit");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ctx->has_video && ctx->has_audio) {
|
if (!ctx->has_video && ctx->has_audio) {
|
||||||
boundary = hit;
|
boundary = hit;
|
||||||
|
ngx_log_debug0(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
|
||||||
|
"dash: update_fragments: boundary=hit cos !has_video && has_audio");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx->audio.mdat_size >= NGX_RTMP_DASH_MAX_MDAT) {
|
if (ctx->audio.mdat_size >= NGX_RTMP_DASH_MAX_MDAT) {
|
||||||
boundary = 1;
|
boundary = 1;
|
||||||
|
ngx_log_debug0(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
|
||||||
|
"dash: update_fragments: boundary=1 cos audio max mdat");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx->video.mdat_size >= NGX_RTMP_DASH_MAX_MDAT) {
|
if (ctx->video.mdat_size >= NGX_RTMP_DASH_MAX_MDAT) {
|
||||||
boundary = 1;
|
boundary = 1;
|
||||||
|
ngx_log_debug0(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
|
||||||
|
"dash: update_fragments: boundary=1 cos video max mdat");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ctx->opened) {
|
if (!ctx->opened) {
|
||||||
boundary = 1;
|
boundary = 1;
|
||||||
|
ngx_log_debug0(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
|
||||||
|
"dash: update_fragments: boundary=1 cos !opened");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ngx_log_debug1(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
|
||||||
|
"dash: update_fragments: boundary=%i",
|
||||||
|
boundary);
|
||||||
|
|
||||||
if (boundary) {
|
if (boundary) {
|
||||||
ngx_rtmp_dash_close_fragments(s);
|
ngx_rtmp_dash_close_fragments(s);
|
||||||
ngx_rtmp_dash_open_fragments(s);
|
ngx_rtmp_dash_open_fragments(s);
|
||||||
|
@ -1432,7 +1454,7 @@ ngx_rtmp_dash_cleanup_dir(ngx_str_t *ppath, ngx_msec_t playlen)
|
||||||
name.data[name.len - 2] == 'a' &&
|
name.data[name.len - 2] == 'a' &&
|
||||||
name.data[name.len - 1] == 'w')
|
name.data[name.len - 1] == 'w')
|
||||||
{
|
{
|
||||||
max_age = playlen / 1000;
|
max_age = playlen / 500;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
ngx_log_debug1(NGX_LOG_DEBUG_RTMP, ngx_cycle->log, 0,
|
ngx_log_debug1(NGX_LOG_DEBUG_RTMP, ngx_cycle->log, 0,
|
||||||
|
@ -1468,7 +1490,8 @@ ngx_rtmp_dash_cleanup(void *data)
|
||||||
|
|
||||||
ngx_rtmp_dash_cleanup_dir(&cleanup->path, cleanup->playlen);
|
ngx_rtmp_dash_cleanup_dir(&cleanup->path, cleanup->playlen);
|
||||||
|
|
||||||
return cleanup->playlen / 500;
|
// Next callback in half of playlist length time
|
||||||
|
return cleanup->playlen / 2000;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ngx_int_t
|
static ngx_int_t
|
||||||
|
|
|
@ -2305,7 +2305,7 @@ ngx_rtmp_hls_cleanup_dir(ngx_str_t *ppath, ngx_msec_t playlen)
|
||||||
name.data[name.len - 2] == 'u' &&
|
name.data[name.len - 2] == 'u' &&
|
||||||
name.data[name.len - 1] == '8')
|
name.data[name.len - 1] == '8')
|
||||||
{
|
{
|
||||||
max_age = playlen / 1000;
|
max_age = playlen / 500;
|
||||||
|
|
||||||
} else if (name.len >= 4 && name.data[name.len - 4] == '.' &&
|
} else if (name.len >= 4 && name.data[name.len - 4] == '.' &&
|
||||||
name.data[name.len - 3] == 'k' &&
|
name.data[name.len - 3] == 'k' &&
|
||||||
|
@ -2348,7 +2348,8 @@ ngx_rtmp_hls_cleanup(void *data)
|
||||||
|
|
||||||
ngx_rtmp_hls_cleanup_dir(&cleanup->path, cleanup->playlen);
|
ngx_rtmp_hls_cleanup_dir(&cleanup->path, cleanup->playlen);
|
||||||
|
|
||||||
return cleanup->playlen / 500;
|
// Next callback in half of playlist length time
|
||||||
|
return cleanup->playlen / 2000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2454,7 +2455,7 @@ ngx_rtmp_hls_merge_app_conf(ngx_conf_t *cf, void *parent, void *child)
|
||||||
ngx_conf_merge_value(conf->hls, prev->hls, 0);
|
ngx_conf_merge_value(conf->hls, prev->hls, 0);
|
||||||
ngx_conf_merge_msec_value(conf->fraglen, prev->fraglen, 5000);
|
ngx_conf_merge_msec_value(conf->fraglen, prev->fraglen, 5000);
|
||||||
ngx_conf_merge_msec_value(conf->max_fraglen, prev->max_fraglen,
|
ngx_conf_merge_msec_value(conf->max_fraglen, prev->max_fraglen,
|
||||||
conf->fraglen * 10);
|
conf->fraglen * 2);
|
||||||
ngx_conf_merge_msec_value(conf->muxdelay, prev->muxdelay, 700);
|
ngx_conf_merge_msec_value(conf->muxdelay, prev->muxdelay, 700);
|
||||||
ngx_conf_merge_msec_value(conf->sync, prev->sync, 2);
|
ngx_conf_merge_msec_value(conf->sync, prev->sync, 2);
|
||||||
ngx_conf_merge_msec_value(conf->playlen, prev->playlen, 30000);
|
ngx_conf_merge_msec_value(conf->playlen, prev->playlen, 30000);
|
||||||
|
|
Loading…
Reference in a new issue