@@ -19,19 +19,21 @@ static ngx_rtmp_stream_begin_pt next_stream_begin;
19
19
static ngx_rtmp_stream_eof_pt next_stream_eof ;
20
20
21
21
22
- static char * ngx_rtmp_hls_variant (ngx_conf_t * cf , ngx_command_t * cmd ,
22
+ static char * ngx_rtmp_hls_variant (ngx_conf_t * cf , ngx_command_t * cmd ,
23
23
void * conf );
24
24
static ngx_int_t ngx_rtmp_hls_postconfiguration (ngx_conf_t * cf );
25
- static void * ngx_rtmp_hls_create_app_conf (ngx_conf_t * cf );
26
- static char * ngx_rtmp_hls_merge_app_conf (ngx_conf_t * cf ,
25
+ static void * ngx_rtmp_hls_create_app_conf (ngx_conf_t * cf );
26
+ static char * ngx_rtmp_hls_merge_app_conf (ngx_conf_t * cf ,
27
27
void * parent , void * child );
28
28
static ngx_int_t ngx_rtmp_hls_flush_audio (ngx_rtmp_session_t * s );
29
29
static ngx_int_t ngx_rtmp_hls_ensure_directory (ngx_rtmp_session_t * s ,
30
30
ngx_str_t * path );
31
+ static char * ngx_rtmp_hls_set_permissions (ngx_conf_t * cf , ngx_command_t * cmd ,
32
+ void * conf );
31
33
32
34
33
35
#define NGX_RTMP_HLS_BUFSIZE (1024*1024)
34
- #define NGX_RTMP_HLS_DIR_ACCESS 0744
36
+ #define NGX_RTMP_HLS_DEFAULT_DIR_ACCESS 0744
35
37
36
38
37
39
typedef struct {
@@ -115,6 +117,8 @@ typedef struct {
115
117
ngx_str_t key_path ;
116
118
ngx_str_t key_url ;
117
119
ngx_uint_t frags_per_key ;
120
+ ngx_uint_t dir_access ;
121
+ ngx_str_t nested_index_filename ;
118
122
} ngx_rtmp_hls_app_conf_t ;
119
123
120
124
@@ -309,6 +313,20 @@ static ngx_command_t ngx_rtmp_hls_commands[] = {
309
313
offsetof(ngx_rtmp_hls_app_conf_t , frags_per_key ),
310
314
NULL },
311
315
316
+ { ngx_string ("hls_dir_access" ),
317
+ NGX_RTMP_MAIN_CONF |NGX_RTMP_SRV_CONF |NGX_RTMP_APP_CONF |NGX_CONF_TAKE1 ,
318
+ ngx_rtmp_hls_set_permissions ,
319
+ NGX_RTMP_APP_CONF_OFFSET ,
320
+ offsetof(ngx_rtmp_hls_app_conf_t , dir_access ),
321
+ NULL },
322
+
323
+ { ngx_string ("hls_nested_index_filename" ),
324
+ NGX_RTMP_MAIN_CONF |NGX_RTMP_SRV_CONF |NGX_RTMP_APP_CONF |NGX_CONF_TAKE1 ,
325
+ ngx_conf_set_str_slot ,
326
+ NGX_RTMP_APP_CONF_OFFSET ,
327
+ offsetof(ngx_rtmp_hls_app_conf_t , nested_index_filename ),
328
+ NULL },
329
+
312
330
ngx_null_command
313
331
};
314
332
@@ -450,7 +468,7 @@ ngx_rtmp_hls_write_variant_playlist(ngx_rtmp_session_t *s)
450
468
ctx -> name .len - ctx -> var -> suffix .len , ctx -> name .data ,
451
469
& var -> suffix );
452
470
if (hacf -> nested ) {
453
- p = ngx_slprintf (p , last , "%s " , "/index" );
471
+ p = ngx_slprintf (p , last , "/%V " , & hacf -> nested_index_filename );
454
472
}
455
473
456
474
p = ngx_slprintf (p , last , "%s" , ".m3u8\n" );
@@ -1202,7 +1220,7 @@ ngx_rtmp_hls_ensure_directory(ngx_rtmp_session_t *s, ngx_str_t *path)
1202
1220
1203
1221
/* ENOENT */
1204
1222
1205
- if (ngx_create_dir (zpath , NGX_RTMP_HLS_DIR_ACCESS ) == NGX_FILE_ERROR ) {
1223
+ if (ngx_create_dir (zpath , hacf -> dir_access ) == NGX_FILE_ERROR ) {
1206
1224
ngx_log_error (NGX_LOG_ERR , s -> connection -> log , ngx_errno ,
1207
1225
"hls: " ngx_create_dir_n " failed on '%V'" , path );
1208
1226
return NGX_ERROR ;
@@ -1264,7 +1282,7 @@ ngx_rtmp_hls_ensure_directory(ngx_rtmp_session_t *s, ngx_str_t *path)
1264
1282
1265
1283
/* NGX_ENOENT */
1266
1284
1267
- if (ngx_create_dir (zpath , NGX_RTMP_HLS_DIR_ACCESS ) == NGX_FILE_ERROR ) {
1285
+ if (ngx_create_dir (zpath , hacf -> dir_access ) == NGX_FILE_ERROR ) {
1268
1286
ngx_log_error (NGX_LOG_ERR , s -> connection -> log , ngx_errno ,
1269
1287
"hls: " ngx_create_dir_n " failed on '%s'" , zpath );
1270
1288
return NGX_ERROR ;
@@ -1350,7 +1368,7 @@ ngx_rtmp_hls_publish(ngx_rtmp_session_t *s, ngx_rtmp_publish_t *v)
1350
1368
1351
1369
len = hacf -> path .len + 1 + ctx -> name .len + sizeof (".m3u8" );
1352
1370
if (hacf -> nested ) {
1353
- len += sizeof ( "/index" ) - 1 ;
1371
+ len += hacf -> nested_index_filename . len + 1 ;
1354
1372
}
1355
1373
1356
1374
ctx -> playlist .data = ngx_palloc (s -> connection -> pool , len );
@@ -1421,11 +1439,13 @@ ngx_rtmp_hls_publish(ngx_rtmp_session_t *s, ngx_rtmp_publish_t *v)
1421
1439
/* playlist path */
1422
1440
1423
1441
if (hacf -> nested ) {
1424
- p = ngx_cpymem (p , "/index.m3u8 " , sizeof ("/index.m3u8 " ) - 1 );
1425
- } else {
1426
- p = ngx_cpymem ( p , ".m3u8" , sizeof ( ".m3u8" ) - 1 );
1442
+ p = ngx_cpymem (p , "/" , sizeof ("/" ) - 1 );
1443
+ p = ngx_cpymem ( p , hacf -> nested_index_filename . data ,
1444
+ hacf -> nested_index_filename . len );
1427
1445
}
1428
1446
1447
+ p = ngx_cpymem (p , ".m3u8" , sizeof (".m3u8" ) - 1 );
1448
+
1429
1449
ctx -> playlist .len = p - ctx -> playlist .data ;
1430
1450
1431
1451
* p = 0 ;
@@ -2323,6 +2343,52 @@ ngx_rtmp_hls_variant(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
2323
2343
}
2324
2344
2325
2345
2346
+ static char *
2347
+ ngx_rtmp_hls_set_permissions (ngx_conf_t * cf , ngx_command_t * cmd , void * conf )
2348
+ {
2349
+ ngx_rtmp_hls_app_conf_t * hacf = conf ;
2350
+
2351
+ size_t i ;
2352
+ ngx_uint_t f , base , step ;
2353
+ ngx_str_t * value ;
2354
+
2355
+ if (hacf -> dir_access != NGX_CONF_UNSET_UINT ) {
2356
+ return "is duplicate" ;
2357
+ }
2358
+
2359
+ value = cf -> args -> elts ;
2360
+ if (value [1 ].data [0 ] != '0' ) {
2361
+ return "invalid octal: should start with 0" ;
2362
+ }
2363
+
2364
+ if (value [1 ].len != 4 ) {
2365
+ return "invalid permission mask: should be exactly 4 characters long" ;
2366
+ }
2367
+
2368
+ hacf -> dir_access = 0 ;
2369
+ f = 1 ;
2370
+
2371
+ for (base = 8 , step = 0 ; base != 1 ; base >>= 1 ) {
2372
+ step ++ ;
2373
+ }
2374
+
2375
+ for (i = value [1 ].len - 2 ; i >= 1 ; i -- ) {
2376
+ f <<= step ;
2377
+ }
2378
+
2379
+ for (i = 1 ; i < value [1 ].len ; i ++ ) {
2380
+ if (value [1 ].data [i ] < '0' || value [1 ].data [i ] > '7' ) {
2381
+ return "invalid octal number" ;
2382
+ }
2383
+
2384
+ hacf -> dir_access += (value [1 ].data [i ] - '0' ) * f ;
2385
+ f >>= step ;
2386
+ }
2387
+
2388
+ return NGX_CONF_OK ;
2389
+ }
2390
+
2391
+
2326
2392
static void *
2327
2393
ngx_rtmp_hls_create_app_conf (ngx_conf_t * cf )
2328
2394
{
@@ -2350,6 +2416,7 @@ ngx_rtmp_hls_create_app_conf(ngx_conf_t *cf)
2350
2416
conf -> granularity = NGX_CONF_UNSET ;
2351
2417
conf -> keys = NGX_CONF_UNSET ;
2352
2418
conf -> frags_per_key = NGX_CONF_UNSET_UINT ;
2419
+ conf -> dir_access = NGX_CONF_UNSET_UINT ;
2353
2420
2354
2421
return conf ;
2355
2422
}
@@ -2385,9 +2452,12 @@ ngx_rtmp_hls_merge_app_conf(ngx_conf_t *cf, void *parent, void *child)
2385
2452
ngx_conf_merge_str_value (conf -> base_url , prev -> base_url , "" );
2386
2453
ngx_conf_merge_value (conf -> granularity , prev -> granularity , 0 );
2387
2454
ngx_conf_merge_value (conf -> keys , prev -> keys , 0 );
2388
- /*ngx_conf_merge_str_value(conf->key_path, prev->key_path, "");*/
2389
2455
ngx_conf_merge_str_value (conf -> key_url , prev -> key_url , "" );
2390
2456
ngx_conf_merge_uint_value (conf -> frags_per_key , prev -> frags_per_key , 0 );
2457
+ ngx_conf_merge_uint_value (conf -> dir_access , prev -> dir_access ,
2458
+ NGX_RTMP_HLS_DEFAULT_DIR_ACCESS );
2459
+ ngx_conf_merge_str_value (conf -> nested_index_filename ,
2460
+ prev -> nested_index_filename , "index" );
2391
2461
2392
2462
if (conf -> fraglen ) {
2393
2463
conf -> winfrags = conf -> playlen / conf -> fraglen ;
0 commit comments