@@ -85,7 +85,7 @@ typedef struct {
85
85
typedef struct {
86
86
ngx_str_t path ;
87
87
ngx_msec_t playlen ;
88
- ngx_int_t frags_per_key ;
88
+ ngx_uint_t frags_per_key ;
89
89
} ngx_rtmp_hls_cleanup_t ;
90
90
91
91
@@ -113,7 +113,7 @@ typedef struct {
113
113
ngx_flag_t keys ;
114
114
ngx_str_t key_path ;
115
115
ngx_str_t key_url ;
116
- ngx_int_t frags_per_key ;
116
+ ngx_uint_t frags_per_key ;
117
117
} ngx_rtmp_hls_app_conf_t ;
118
118
119
119
@@ -879,8 +879,9 @@ ngx_rtmp_hls_open_fragment(ngx_rtmp_session_t *s, uint64_t ts,
879
879
ngx_sprintf (ctx -> stream .data + ctx -> stream .len , "%uL.ts%Z" , id );
880
880
881
881
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 ;
884
885
ctx -> key_id = id ;
885
886
886
887
if (RAND_bytes (ctx -> key , 16 ) < 0 ) {
@@ -911,12 +912,18 @@ ngx_rtmp_hls_open_fragment(ngx_rtmp_session_t *s, uint64_t ts,
911
912
912
913
ngx_close_file (fd );
913
914
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
+ }
920
927
}
921
928
}
922
929
@@ -2292,7 +2299,7 @@ ngx_rtmp_hls_create_app_conf(ngx_conf_t *cf)
2292
2299
conf -> cleanup = NGX_CONF_UNSET ;
2293
2300
conf -> granularity = NGX_CONF_UNSET ;
2294
2301
conf -> keys = NGX_CONF_UNSET ;
2295
- conf -> frags_per_key = NGX_CONF_UNSET ;
2302
+ conf -> frags_per_key = NGX_CONF_UNSET_UINT ;
2296
2303
2297
2304
return conf ;
2298
2305
}
@@ -2330,7 +2337,7 @@ ngx_rtmp_hls_merge_app_conf(ngx_conf_t *cf, void *parent, void *child)
2330
2337
ngx_conf_merge_value (conf -> keys , prev -> keys , 0 );
2331
2338
ngx_conf_merge_str_value (conf -> key_path , prev -> key_path , "" );
2332
2339
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 );
2334
2341
2335
2342
if (conf -> fraglen ) {
2336
2343
conf -> winfrags = conf -> playlen / conf -> fraglen ;
0 commit comments