@@ -101,6 +101,7 @@ typedef struct {
101
101
ngx_flag_t cleanup ;
102
102
ngx_array_t * variant ;
103
103
ngx_str_t base_url ;
104
+ ngx_int_t granularity ;
104
105
} ngx_rtmp_hls_app_conf_t ;
105
106
106
107
@@ -260,6 +261,13 @@ static ngx_command_t ngx_rtmp_hls_commands[] = {
260
261
offsetof(ngx_rtmp_hls_app_conf_t , base_url ),
261
262
NULL },
262
263
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
+
263
271
ngx_null_command
264
272
};
265
273
@@ -770,17 +778,26 @@ static ngx_int_t
770
778
ngx_rtmp_hls_open_fragment (ngx_rtmp_session_t * s , uint64_t ts ,
771
779
ngx_int_t discont )
772
780
{
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 ;
776
786
777
787
ctx = ngx_rtmp_get_module_ctx (s , ngx_rtmp_hls_module );
778
788
if (ctx -> opened ) {
779
789
return NGX_OK ;
780
790
}
781
791
792
+ hacf = ngx_rtmp_get_module_app_conf (s , ngx_rtmp_hls_module );
793
+
782
794
id = ngx_rtmp_hls_get_fragment_id (s , ts );
783
795
796
+ if (hacf -> granularity ) {
797
+ g = (ngx_uint_t ) hacf -> granularity ;
798
+ id = (uint64_t ) (id / g ) * g ;
799
+ }
800
+
784
801
* ngx_sprintf (ctx -> stream .data + ctx -> stream .len , "%uL.ts" , id ) = 0 ;
785
802
786
803
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)
2067
2084
conf -> max_audio_delay = NGX_CONF_UNSET_MSEC ;
2068
2085
conf -> audio_buffer_size = NGX_CONF_UNSET_SIZE ;
2069
2086
conf -> cleanup = NGX_CONF_UNSET ;
2087
+ conf -> granularity = NGX_CONF_UNSET ;
2070
2088
2071
2089
return conf ;
2072
2090
}
@@ -2100,6 +2118,7 @@ ngx_rtmp_hls_merge_app_conf(ngx_conf_t *cf, void *parent, void *child)
2100
2118
NGX_RTMP_HLS_BUFSIZE );
2101
2119
ngx_conf_merge_value (conf -> cleanup , prev -> cleanup , 1 );
2102
2120
ngx_conf_merge_str_value (conf -> base_url , prev -> base_url , "" );
2121
+ ngx_conf_merge_value (conf -> granularity , prev -> granularity , 0 );
2103
2122
2104
2123
if (conf -> fraglen ) {
2105
2124
conf -> winfrags = conf -> playlen / conf -> fraglen ;
0 commit comments