Skip to content

Commit 546c42e

Browse files
committed
added hls_fragment_naming_granularity
1 parent 2eb36e3 commit 546c42e

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

hls/ngx_rtmp_hls_module.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ typedef struct {
101101
ngx_flag_t cleanup;
102102
ngx_array_t *variant;
103103
ngx_str_t base_url;
104+
ngx_int_t granularity;
104105
} ngx_rtmp_hls_app_conf_t;
105106

106107

@@ -260,6 +261,13 @@ static ngx_command_t ngx_rtmp_hls_commands[] = {
260261
offsetof(ngx_rtmp_hls_app_conf_t, base_url),
261262
NULL },
262263

264+
{ ngx_string("hls_fragment_naming_granularity"),
265+
NGX_RTMP_MAIN_CONF|NGX_RTMP_SRV_CONF|NGX_RTMP_APP_CONF|NGX_CONF_TAKE1,
266+
ngx_conf_set_num_slot,
267+
NGX_RTMP_APP_CONF_OFFSET,
268+
offsetof(ngx_rtmp_hls_app_conf_t, granularity),
269+
NULL },
270+
263271
ngx_null_command
264272
};
265273

@@ -770,17 +778,26 @@ static ngx_int_t
770778
ngx_rtmp_hls_open_fragment(ngx_rtmp_session_t *s, uint64_t ts,
771779
ngx_int_t discont)
772780
{
773-
ngx_rtmp_hls_ctx_t *ctx;
774-
ngx_rtmp_hls_frag_t *f;
775-
uint64_t id;
781+
uint64_t id;
782+
ngx_uint_t g;
783+
ngx_rtmp_hls_ctx_t *ctx;
784+
ngx_rtmp_hls_frag_t *f;
785+
ngx_rtmp_hls_app_conf_t *hacf;
776786

777787
ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_hls_module);
778788
if (ctx->opened) {
779789
return NGX_OK;
780790
}
781791

792+
hacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_hls_module);
793+
782794
id = ngx_rtmp_hls_get_fragment_id(s, ts);
783795

796+
if (hacf->granularity) {
797+
g = (ngx_uint_t) hacf->granularity;
798+
id = (uint64_t) (id / g) * g;
799+
}
800+
784801
*ngx_sprintf(ctx->stream.data + ctx->stream.len, "%uL.ts", id) = 0;
785802

786803
ngx_log_debug5(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
@@ -2067,6 +2084,7 @@ ngx_rtmp_hls_create_app_conf(ngx_conf_t *cf)
20672084
conf->max_audio_delay = NGX_CONF_UNSET_MSEC;
20682085
conf->audio_buffer_size = NGX_CONF_UNSET_SIZE;
20692086
conf->cleanup = NGX_CONF_UNSET;
2087+
conf->granularity = NGX_CONF_UNSET;
20702088

20712089
return conf;
20722090
}
@@ -2100,6 +2118,7 @@ ngx_rtmp_hls_merge_app_conf(ngx_conf_t *cf, void *parent, void *child)
21002118
NGX_RTMP_HLS_BUFSIZE);
21012119
ngx_conf_merge_value(conf->cleanup, prev->cleanup, 1);
21022120
ngx_conf_merge_str_value(conf->base_url, prev->base_url, "");
2121+
ngx_conf_merge_value(conf->granularity, prev->granularity, 0);
21032122

21042123
if (conf->fraglen) {
21052124
conf->winfrags = conf->playlen / conf->fraglen;

0 commit comments

Comments
 (0)