From 26f06877b0f2a2336e59cda93a3de18d7b23a3e2 Mon Sep 17 00:00:00 2001 From: Nonthawat Srichad Date: Mon, 18 Mar 2024 21:17:19 +0700 Subject: [PATCH] hls: add vod_hls_encryption_output_iv directive (#1514) * hls: add vod_hls_encryption_output_iv variable * remove complexity just return IV when vod_hls_encryption_output_iv is enabled --- README.md | 7 +++++++ ngx_http_vod_hls.c | 4 +++- ngx_http_vod_hls_commands.h | 7 +++++++ ngx_http_vod_hls_conf.h | 1 + 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2d905563..0c768e06 100644 --- a/README.md +++ b/README.md @@ -1714,6 +1714,13 @@ The parameter value can contain variables. When enabled, the module will shift back the dts timestamps by the pts delay of the initial frame. This can help keep the pts timestamps aligned across multiple renditions. +#### vod_hls_encryption_output_iv +* **syntax**: `vod_hls_encryption_output_iv on/off` +* **default**: `off` +* **context**: `http`, `server`, `location` + +When enabled, the module outputs the `IV` attribute in returned `#EXT-X-KEY` tags. + ### Configuration directives - MSS #### vod_mss_manifest_file_name_prefix diff --git a/ngx_http_vod_hls.c b/ngx_http_vod_hls.c index 4cbf9edd..1f916fe5 100644 --- a/ngx_http_vod_hls.c +++ b/ngx_http_vod_hls.c @@ -171,7 +171,7 @@ ngx_http_vod_hls_init_encryption_params( } encryption_params->iv = encryption_params->iv_buf; - encryption_params->return_iv = FALSE; + encryption_params->return_iv = conf->hls.output_iv; sequence = &submodule_context->media_set.sequences[0]; @@ -1116,6 +1116,7 @@ ngx_http_vod_hls_create_loc_conf( conf->align_pts = NGX_CONF_UNSET; conf->output_id3_timestamps = NGX_CONF_UNSET; conf->encryption_method = NGX_CONF_UNSET_UINT; + conf->output_iv = NGX_CONF_UNSET; conf->m3u8_config.output_iframes_playlist = NGX_CONF_UNSET; conf->m3u8_config.force_unmuxed_segments = NGX_CONF_UNSET; conf->m3u8_config.container_format = NGX_CONF_UNSET_UINT; @@ -1131,6 +1132,7 @@ ngx_http_vod_hls_merge_loc_conf( ngx_conf_merge_value(conf->absolute_master_urls, prev->absolute_master_urls, 1); ngx_conf_merge_value(conf->absolute_index_urls, prev->absolute_index_urls, 1); ngx_conf_merge_value(conf->absolute_iframe_urls, prev->absolute_iframe_urls, 0); + ngx_conf_merge_value(conf->output_iv, prev->output_iv, 0); ngx_conf_merge_value(conf->m3u8_config.output_iframes_playlist, prev->m3u8_config.output_iframes_playlist, 1); ngx_conf_merge_str_value(conf->master_file_name_prefix, prev->master_file_name_prefix, "master"); diff --git a/ngx_http_vod_hls_commands.h b/ngx_http_vod_hls_commands.h index 5f68b33c..a98d6b55 100644 --- a/ngx_http_vod_hls_commands.h +++ b/ngx_http_vod_hls_commands.h @@ -35,6 +35,13 @@ NGX_HTTP_LOC_CONF_OFFSET, BASE_OFFSET + offsetof(ngx_http_vod_hls_loc_conf_t, m3u8_config.encryption_key_format_versions), NULL }, + + { ngx_string("vod_hls_encryption_output_iv"), + NGX_HTTP_MAIN_CONF | NGX_HTTP_SRV_CONF | NGX_HTTP_LOC_CONF | NGX_CONF_TAKE1, + ngx_conf_set_flag_slot, + NGX_HTTP_LOC_CONF_OFFSET, + BASE_OFFSET + offsetof(ngx_http_vod_hls_loc_conf_t, output_iv), + NULL }, #endif // NGX_HAVE_OPENSSL_EVP { ngx_string("vod_hls_container_format"), diff --git a/ngx_http_vod_hls_conf.h b/ngx_http_vod_hls_conf.h index 8a3098c5..fd422874 100644 --- a/ngx_http_vod_hls_conf.h +++ b/ngx_http_vod_hls_conf.h @@ -19,6 +19,7 @@ typedef struct ngx_http_complex_value_t* id3_data; vod_uint_t encryption_method; ngx_http_complex_value_t* encryption_key_uri; + bool_t output_iv; // derived fields m3u8_config_t m3u8_config;