Skip to content

Commit eb1cfef

Browse files
committed
zero fragments_per_key now means one key per stream
1 parent 0b3d545 commit eb1cfef

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

hls/ngx_rtmp_hls_module.c

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ typedef struct {
8585
typedef struct {
8686
ngx_str_t path;
8787
ngx_msec_t playlen;
88-
ngx_int_t frags_per_key;
88+
ngx_uint_t frags_per_key;
8989
} ngx_rtmp_hls_cleanup_t;
9090

9191

@@ -113,7 +113,7 @@ typedef struct {
113113
ngx_flag_t keys;
114114
ngx_str_t key_path;
115115
ngx_str_t key_url;
116-
ngx_int_t frags_per_key;
116+
ngx_uint_t frags_per_key;
117117
} ngx_rtmp_hls_app_conf_t;
118118

119119

@@ -879,8 +879,9 @@ ngx_rtmp_hls_open_fragment(ngx_rtmp_session_t *s, uint64_t ts,
879879
ngx_sprintf(ctx->stream.data + ctx->stream.len, "%uL.ts%Z", id);
880880

881881
if (hacf->keys) {
882-
if (ctx->key_frags-- <= 1) {
883-
ctx->key_frags = hacf->frags_per_key;
882+
if (ctx->key_frags == 0) {
883+
884+
ctx->key_frags = hacf->frags_per_key - 1;
884885
ctx->key_id = id;
885886

886887
if (RAND_bytes(ctx->key, 16) < 0) {
@@ -911,12 +912,18 @@ ngx_rtmp_hls_open_fragment(ngx_rtmp_session_t *s, uint64_t ts,
911912

912913
ngx_close_file(fd);
913914

914-
} else if (ngx_set_file_time(ctx->keyfile.data, 0, ngx_cached_time->sec)
915-
!= NGX_OK)
916-
{
917-
ngx_log_error(NGX_LOG_ALERT, s->connection->log, ngx_errno,
918-
ngx_set_file_time_n " '%s' failed",
919-
ctx->keyfile.data);
915+
} else {
916+
if (hacf->frags_per_key) {
917+
ctx->key_frags--;
918+
}
919+
920+
if (ngx_set_file_time(ctx->keyfile.data, 0, ngx_cached_time->sec)
921+
!= NGX_OK)
922+
{
923+
ngx_log_error(NGX_LOG_ALERT, s->connection->log, ngx_errno,
924+
ngx_set_file_time_n " '%s' failed",
925+
ctx->keyfile.data);
926+
}
920927
}
921928
}
922929

@@ -2292,7 +2299,7 @@ ngx_rtmp_hls_create_app_conf(ngx_conf_t *cf)
22922299
conf->cleanup = NGX_CONF_UNSET;
22932300
conf->granularity = NGX_CONF_UNSET;
22942301
conf->keys = NGX_CONF_UNSET;
2295-
conf->frags_per_key = NGX_CONF_UNSET;
2302+
conf->frags_per_key = NGX_CONF_UNSET_UINT;
22962303

22972304
return conf;
22982305
}
@@ -2330,7 +2337,7 @@ ngx_rtmp_hls_merge_app_conf(ngx_conf_t *cf, void *parent, void *child)
23302337
ngx_conf_merge_value(conf->keys, prev->keys, 0);
23312338
ngx_conf_merge_str_value(conf->key_path, prev->key_path, "");
23322339
ngx_conf_merge_str_value(conf->key_url, prev->key_url, "");
2333-
ngx_conf_merge_value(conf->frags_per_key, prev->frags_per_key, 0);
2340+
ngx_conf_merge_uint_value(conf->frags_per_key, prev->frags_per_key, 0);
23342341

23352342
if (conf->fraglen) {
23362343
conf->winfrags = conf->playlen / conf->fraglen;

0 commit comments

Comments
 (0)