Skip to content

Commit f676ef4

Browse files
Merge pull request #1 from tmagnien/master
Add options for previously hardcoded values
2 parents e8a456d + 48a1d00 commit f676ef4

File tree

1 file changed

+71
-8
lines changed

1 file changed

+71
-8
lines changed

hls/ngx_rtmp_hls_module.c

Lines changed: 71 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ static char * ngx_rtmp_hls_merge_app_conf(ngx_conf_t *cf,
2828
static ngx_int_t ngx_rtmp_hls_flush_audio(ngx_rtmp_session_t *s);
2929
static ngx_int_t ngx_rtmp_hls_ensure_directory(ngx_rtmp_session_t *s,
3030
ngx_str_t *path);
31+
char * ngx_http_flv_set_permissions_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
3132

3233

3334
#define NGX_RTMP_HLS_BUFSIZE (1024*1024)
34-
#define NGX_RTMP_HLS_DIR_ACCESS 0744
35+
#define NGX_RTMP_HLS_DEFAULT_DIR_ACCESS 0744
3536

3637

3738
typedef struct {
@@ -115,6 +116,8 @@ typedef struct {
115116
ngx_str_t key_path;
116117
ngx_str_t key_url;
117118
ngx_uint_t frags_per_key;
119+
ngx_uint_t dir_access;
120+
ngx_str_t nested_index_filename;
118121
} ngx_rtmp_hls_app_conf_t;
119122

120123

@@ -309,6 +312,20 @@ static ngx_command_t ngx_rtmp_hls_commands[] = {
309312
offsetof(ngx_rtmp_hls_app_conf_t, frags_per_key),
310313
NULL },
311314

315+
{ ngx_string("hls_dir_access"),
316+
NGX_RTMP_MAIN_CONF|NGX_RTMP_SRV_CONF|NGX_RTMP_APP_CONF|NGX_CONF_TAKE1,
317+
ngx_http_flv_set_permissions_slot,
318+
NGX_RTMP_APP_CONF_OFFSET,
319+
offsetof(ngx_rtmp_hls_app_conf_t, dir_access),
320+
NULL },
321+
322+
{ ngx_string("hls_nested_index_filename"),
323+
NGX_RTMP_MAIN_CONF|NGX_RTMP_SRV_CONF|NGX_RTMP_APP_CONF|NGX_CONF_TAKE1,
324+
ngx_conf_set_str_slot,
325+
NGX_RTMP_APP_CONF_OFFSET,
326+
offsetof(ngx_rtmp_hls_app_conf_t, nested_index_filename),
327+
NULL },
328+
312329
ngx_null_command
313330
};
314331

@@ -450,7 +467,7 @@ ngx_rtmp_hls_write_variant_playlist(ngx_rtmp_session_t *s)
450467
ctx->name.len - ctx->var->suffix.len, ctx->name.data,
451468
&var->suffix);
452469
if (hacf->nested) {
453-
p = ngx_slprintf(p, last, "%s", "/index");
470+
p = ngx_slprintf(p, last, "/%V", &hacf->nested_index_filename);
454471
}
455472

456473
p = ngx_slprintf(p, last, "%s", ".m3u8\n");
@@ -1202,7 +1219,7 @@ ngx_rtmp_hls_ensure_directory(ngx_rtmp_session_t *s, ngx_str_t *path)
12021219

12031220
/* ENOENT */
12041221

1205-
if (ngx_create_dir(zpath, NGX_RTMP_HLS_DIR_ACCESS) == NGX_FILE_ERROR) {
1222+
if (ngx_create_dir(zpath, hacf->dir_access) == NGX_FILE_ERROR) {
12061223
ngx_log_error(NGX_LOG_ERR, s->connection->log, ngx_errno,
12071224
"hls: " ngx_create_dir_n " failed on '%V'", path);
12081225
return NGX_ERROR;
@@ -1264,7 +1281,7 @@ ngx_rtmp_hls_ensure_directory(ngx_rtmp_session_t *s, ngx_str_t *path)
12641281

12651282
/* NGX_ENOENT */
12661283

1267-
if (ngx_create_dir(zpath, NGX_RTMP_HLS_DIR_ACCESS) == NGX_FILE_ERROR) {
1284+
if (ngx_create_dir(zpath, hacf->dir_access) == NGX_FILE_ERROR) {
12681285
ngx_log_error(NGX_LOG_ERR, s->connection->log, ngx_errno,
12691286
"hls: " ngx_create_dir_n " failed on '%s'", zpath);
12701287
return NGX_ERROR;
@@ -1350,7 +1367,7 @@ ngx_rtmp_hls_publish(ngx_rtmp_session_t *s, ngx_rtmp_publish_t *v)
13501367

13511368
len = hacf->path.len + 1 + ctx->name.len + sizeof(".m3u8");
13521369
if (hacf->nested) {
1353-
len += sizeof("/index") - 1;
1370+
len += hacf->nested_index_filename.len + 1;
13541371
}
13551372

13561373
ctx->playlist.data = ngx_palloc(s->connection->pool, len);
@@ -1421,10 +1438,10 @@ ngx_rtmp_hls_publish(ngx_rtmp_session_t *s, ngx_rtmp_publish_t *v)
14211438
/* playlist path */
14221439

14231440
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);
1441+
p = ngx_cpymem(p, "/", sizeof("/") - 1);
1442+
p = ngx_cpymem(p, hacf->nested_index_filename.data, hacf->nested_index_filename.len);
14271443
}
1444+
p = ngx_cpymem(p, ".m3u8", sizeof(".m3u8") - 1);
14281445

14291446
ctx->playlist.len = p - ctx->playlist.data;
14301447

@@ -2322,6 +2339,49 @@ ngx_rtmp_hls_variant(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
23222339
return NGX_CONF_OK;
23232340
}
23242341

2342+
char *
2343+
ngx_http_flv_set_permissions_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
2344+
{
2345+
char *p = conf;
2346+
2347+
ngx_int_t *np;
2348+
ngx_str_t *value;
2349+
ngx_conf_post_t *post;
2350+
ngx_uint_t i;
2351+
ngx_uint_t f;
2352+
2353+
np = (ngx_int_t *) (p + cmd->offset);
2354+
2355+
if (*np != NGX_CONF_UNSET) {
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+
if (value[1].len != 4) {
2364+
return "invalid permission mask : should be exactly 4 characters long";
2365+
}
2366+
*np = 0;
2367+
f = 64;
2368+
2369+
for (i = 1; i < value[1].len; i++) {
2370+
if (value[1].data[i] < '0' || value[1].data[i] > '7') {
2371+
return "invalid octal number";
2372+
}
2373+
*np += (value[1].data[i] - '0') * f;
2374+
f /= 8;
2375+
}
2376+
2377+
if (cmd->post) {
2378+
post = cmd->post;
2379+
return post->post_handler(cf, post, np);
2380+
}
2381+
2382+
return NGX_CONF_OK;
2383+
}
2384+
23252385

23262386
static void *
23272387
ngx_rtmp_hls_create_app_conf(ngx_conf_t *cf)
@@ -2350,6 +2410,7 @@ ngx_rtmp_hls_create_app_conf(ngx_conf_t *cf)
23502410
conf->granularity = NGX_CONF_UNSET;
23512411
conf->keys = NGX_CONF_UNSET;
23522412
conf->frags_per_key = NGX_CONF_UNSET_UINT;
2413+
conf->dir_access = NGX_CONF_UNSET_UINT;
23532414

23542415
return conf;
23552416
}
@@ -2388,6 +2449,8 @@ ngx_rtmp_hls_merge_app_conf(ngx_conf_t *cf, void *parent, void *child)
23882449
/*ngx_conf_merge_str_value(conf->key_path, prev->key_path, "");*/
23892450
ngx_conf_merge_str_value(conf->key_url, prev->key_url, "");
23902451
ngx_conf_merge_uint_value(conf->frags_per_key, prev->frags_per_key, 0);
2452+
ngx_conf_merge_uint_value(conf->dir_access, prev->dir_access, NGX_RTMP_HLS_DEFAULT_DIR_ACCESS);
2453+
ngx_conf_merge_str_value(conf->nested_index_filename, prev->nested_index_filename, "index");
23912454

23922455
if (conf->fraglen) {
23932456
conf->winfrags = conf->playlen / conf->fraglen;

0 commit comments

Comments
 (0)