Skip to content

Commit 1ba6a5d

Browse files
committed
[dev] merged branch 'streamingsystems-master' (#273).
2 parents e8a456d + 7a1bad6 commit 1ba6a5d

File tree

1 file changed

+82
-12
lines changed

1 file changed

+82
-12
lines changed

hls/ngx_rtmp_hls_module.c

+82-12
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,21 @@ static ngx_rtmp_stream_begin_pt next_stream_begin;
1919
static ngx_rtmp_stream_eof_pt next_stream_eof;
2020

2121

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,
2323
void *conf);
2424
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,
2727
void *parent, void *child);
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+
static char *ngx_rtmp_hls_set_permissions(ngx_conf_t *cf, ngx_command_t *cmd,
32+
void *conf);
3133

3234

3335
#define NGX_RTMP_HLS_BUFSIZE (1024*1024)
34-
#define NGX_RTMP_HLS_DIR_ACCESS 0744
36+
#define NGX_RTMP_HLS_DEFAULT_DIR_ACCESS 0744
3537

3638

3739
typedef struct {
@@ -115,6 +117,8 @@ typedef struct {
115117
ngx_str_t key_path;
116118
ngx_str_t key_url;
117119
ngx_uint_t frags_per_key;
120+
ngx_uint_t dir_access;
121+
ngx_str_t nested_index_filename;
118122
} ngx_rtmp_hls_app_conf_t;
119123

120124

@@ -309,6 +313,20 @@ static ngx_command_t ngx_rtmp_hls_commands[] = {
309313
offsetof(ngx_rtmp_hls_app_conf_t, frags_per_key),
310314
NULL },
311315

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+
312330
ngx_null_command
313331
};
314332

@@ -450,7 +468,7 @@ ngx_rtmp_hls_write_variant_playlist(ngx_rtmp_session_t *s)
450468
ctx->name.len - ctx->var->suffix.len, ctx->name.data,
451469
&var->suffix);
452470
if (hacf->nested) {
453-
p = ngx_slprintf(p, last, "%s", "/index");
471+
p = ngx_slprintf(p, last, "/%V", &hacf->nested_index_filename);
454472
}
455473

456474
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)
12021220

12031221
/* ENOENT */
12041222

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) {
12061224
ngx_log_error(NGX_LOG_ERR, s->connection->log, ngx_errno,
12071225
"hls: " ngx_create_dir_n " failed on '%V'", path);
12081226
return NGX_ERROR;
@@ -1264,7 +1282,7 @@ ngx_rtmp_hls_ensure_directory(ngx_rtmp_session_t *s, ngx_str_t *path)
12641282

12651283
/* NGX_ENOENT */
12661284

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) {
12681286
ngx_log_error(NGX_LOG_ERR, s->connection->log, ngx_errno,
12691287
"hls: " ngx_create_dir_n " failed on '%s'", zpath);
12701288
return NGX_ERROR;
@@ -1350,7 +1368,7 @@ ngx_rtmp_hls_publish(ngx_rtmp_session_t *s, ngx_rtmp_publish_t *v)
13501368

13511369
len = hacf->path.len + 1 + ctx->name.len + sizeof(".m3u8");
13521370
if (hacf->nested) {
1353-
len += sizeof("/index") - 1;
1371+
len += hacf->nested_index_filename.len + 1;
13541372
}
13551373

13561374
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)
14211439
/* playlist path */
14221440

14231441
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);
14271445
}
14281446

1447+
p = ngx_cpymem(p, ".m3u8", sizeof(".m3u8") - 1);
1448+
14291449
ctx->playlist.len = p - ctx->playlist.data;
14301450

14311451
*p = 0;
@@ -2323,6 +2343,52 @@ ngx_rtmp_hls_variant(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
23232343
}
23242344

23252345

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+
23262392
static void *
23272393
ngx_rtmp_hls_create_app_conf(ngx_conf_t *cf)
23282394
{
@@ -2350,6 +2416,7 @@ ngx_rtmp_hls_create_app_conf(ngx_conf_t *cf)
23502416
conf->granularity = NGX_CONF_UNSET;
23512417
conf->keys = NGX_CONF_UNSET;
23522418
conf->frags_per_key = NGX_CONF_UNSET_UINT;
2419+
conf->dir_access = NGX_CONF_UNSET_UINT;
23532420

23542421
return conf;
23552422
}
@@ -2385,9 +2452,12 @@ ngx_rtmp_hls_merge_app_conf(ngx_conf_t *cf, void *parent, void *child)
23852452
ngx_conf_merge_str_value(conf->base_url, prev->base_url, "");
23862453
ngx_conf_merge_value(conf->granularity, prev->granularity, 0);
23872454
ngx_conf_merge_value(conf->keys, prev->keys, 0);
2388-
/*ngx_conf_merge_str_value(conf->key_path, prev->key_path, "");*/
23892455
ngx_conf_merge_str_value(conf->key_url, prev->key_url, "");
23902456
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");
23912461

23922462
if (conf->fraglen) {
23932463
conf->winfrags = conf->playlen / conf->fraglen;

0 commit comments

Comments
 (0)