Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BANDWIDTH / AVERAGE-BANDWIDTH #946 #1362

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
84 changes: 63 additions & 21 deletions ngx_http_vod_hls.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ ngx_http_vod_hls_init_encryption_iv(u_char* iv, uint32_t segment_index)

static ngx_int_t
ngx_http_vod_hls_get_iv_seed(
ngx_http_vod_submodule_context_t* submodule_context,
ngx_http_vod_submodule_context_t* submodule_context,
media_sequence_t* sequence,
ngx_str_t* result)
{
Expand Down Expand Up @@ -258,7 +258,45 @@ ngx_http_vod_hls_handle_master_playlist(
{
ngx_http_vod_loc_conf_t* conf = submodule_context->conf;
ngx_str_t base_url = ngx_null_string;
vod_status_t rc;
hls_encryption_params_t encryption_params;
vod_status_t rc;

ngx_uint_t container_format;



#if (NGX_HAVE_OPENSSL_EVP)
container_format = ngx_http_vod_hls_get_container_format(
&conf->hls,
&submodule_context->media_set);
rc = ngx_http_vod_hls_init_encryption_params(&encryption_params, submodule_context, container_format);
if (rc != NGX_OK)
{
return rc;
}

if (encryption_params.type != HLS_ENC_NONE)
{
if (conf->hls.encryption_key_uri != NULL)
{
if (ngx_http_complex_value(
submodule_context->r,
conf->hls.encryption_key_uri,
&encryption_params.key_uri) != NGX_OK)
{
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, submodule_context->request_context.log, 0,
"ngx_http_vod_hls_handle_index_playlist: ngx_http_complex_value failed");
return NGX_ERROR;
}
}
else
{
encryption_params.key_uri.len = 0;
}
}
#else
encryption_params.type = HLS_ENC_NONE;
#endif // NGX_HAVE_OPENSSL_EVP

if (conf->hls.absolute_master_urls)
{
Expand All @@ -275,6 +313,8 @@ ngx_http_vod_hls_handle_master_playlist(
conf->hls.encryption_method,
&base_url,
&submodule_context->media_set,
&conf->hls.mpegts_muxer_config,
&encryption_params,
response);
if (rc != VOD_OK)
{
Expand All @@ -285,11 +325,11 @@ ngx_http_vod_hls_handle_master_playlist(

content_type->data = m3u8_content_type;
content_type->len = sizeof(m3u8_content_type) - 1;

return NGX_OK;
}

static ngx_int_t
static ngx_int_t
ngx_http_vod_hls_handle_index_playlist(
ngx_http_vod_submodule_context_t* submodule_context,
ngx_str_t* response,
Expand Down Expand Up @@ -329,7 +369,7 @@ ngx_http_vod_hls_handle_index_playlist(
}

container_format = ngx_http_vod_hls_get_container_format(
&conf->hls,
&conf->hls,
&submodule_context->media_set);

#if (NGX_HAVE_OPENSSL_EVP)
Expand Down Expand Up @@ -380,7 +420,7 @@ ngx_http_vod_hls_handle_index_playlist(

content_type->data = m3u8_content_type;
content_type->len = sizeof(m3u8_content_type) - 1;

return NGX_OK;
}

Expand All @@ -393,7 +433,7 @@ ngx_http_vod_hls_handle_iframe_playlist(
ngx_http_vod_loc_conf_t* conf = submodule_context->conf;
ngx_str_t base_url = ngx_null_string;
vod_status_t rc;

if (conf->hls.encryption_method != HLS_ENC_NONE)
{
ngx_log_error(NGX_LOG_ERR, submodule_context->request_context.log, 0,
Expand Down Expand Up @@ -442,7 +482,7 @@ ngx_http_vod_hls_handle_iframe_playlist(

content_type->data = m3u8_content_type;
content_type->len = sizeof(m3u8_content_type) - 1;

return NGX_OK;
}

Expand Down Expand Up @@ -521,7 +561,7 @@ ngx_http_vod_hls_init_ts_frame_processor(
segment_writer->write_tail,
segment_writer->context,
reuse_output_buffers,
response_size,
response_size,
output_buffer,
&state);
if (rc != VOD_OK)
Expand All @@ -531,7 +571,7 @@ ngx_http_vod_hls_init_ts_frame_processor(
return ngx_http_vod_status_to_ngx_error(submodule_context->r, rc);
}

if (encryption_params.type == HLS_ENC_AES_128 &&
if (encryption_params.type == HLS_ENC_AES_128 &&
*response_size != 0)
{
*response_size = aes_round_up_to_block(*response_size);
Expand Down Expand Up @@ -853,7 +893,7 @@ ngx_http_vod_hls_handle_vtt_segment(
ngx_str_t* content_type)
{
vod_status_t rc;

rc = webvtt_builder_build(
&submodule_context->request_context,
&submodule_context->media_set,
Expand All @@ -872,14 +912,16 @@ ngx_http_vod_hls_handle_vtt_segment(
return NGX_OK;
}


static const ngx_http_vod_request_t hls_master_request = {
0,
PARSE_FLAG_DURATION_LIMITS_AND_TOTAL_SIZE | PARSE_FLAG_KEY_FRAME_BITRATE | PARSE_FLAG_CODEC_NAME | PARSE_FLAG_PARSED_EXTRA_DATA_SIZE | PARSE_FLAG_CODEC_TRANSFER_CHAR,
REQUEST_CLASS_OTHER,
SUPPORTED_CODECS | VOD_CODEC_FLAG(WEBVTT),
HLS_TIMESCALE,
ngx_http_vod_hls_handle_master_playlist,
NULL,
REQUEST_FLAG_PARSE_ALL_CLIPS,
PARSE_FLAG_DURATION_LIMITS_AND_TOTAL_SIZE | PARSE_FLAG_KEY_FRAME_BITRATE | PARSE_FLAG_CODEC_NAME |
PARSE_FLAG_PARSED_EXTRA_DATA_SIZE | PARSE_FLAG_CODEC_TRANSFER_CHAR | PARSE_FLAG_FRAMES_ALL_EXCEPT_OFFSETS,
REQUEST_CLASS_OTHER,
SUPPORTED_CODECS | VOD_CODEC_FLAG(WEBVTT),
HLS_TIMESCALE,
ngx_http_vod_hls_handle_master_playlist,
NULL,
};

static const ngx_http_vod_request_t hls_index_request = {
Expand Down Expand Up @@ -1022,12 +1064,12 @@ ngx_http_vod_hls_merge_loc_conf(
ngx_conf_merge_value(conf->mpegts_muxer_config.align_frames, prev->mpegts_muxer_config.align_frames, 1);
ngx_conf_merge_value(conf->mpegts_muxer_config.output_id3_timestamps, prev->mpegts_muxer_config.output_id3_timestamps, 0);
ngx_conf_merge_value(conf->mpegts_muxer_config.align_pts, prev->mpegts_muxer_config.align_pts, 0);

ngx_conf_merge_uint_value(conf->encryption_method, prev->encryption_method, HLS_ENC_NONE);

m3u8_builder_init_config(
&conf->m3u8_config,
base->segmenter.max_segment_duration,
base->segmenter.max_segment_duration,
conf->encryption_method);

switch (conf->encryption_method)
Expand Down Expand Up @@ -1058,7 +1100,7 @@ ngx_http_vod_hls_merge_loc_conf(
return NGX_CONF_OK;
}

static int
static int
ngx_http_vod_hls_get_file_path_components(ngx_str_t* uri)
{
return 1;
Expand Down
3 changes: 0 additions & 3 deletions vod/hds/hds_amf0_encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ hds_amf0_write_metadata(u_char* p, media_set_t* media_set, media_track_t** track
uint64_t duration;
uint32_t timescale;
uint32_t count;
uint32_t bitrate = 0;
uint8_t sound_format;

count = AMF0_COMMON_FIELDS_COUNT;
Expand Down Expand Up @@ -155,7 +154,6 @@ hds_amf0_write_metadata(u_char* p, media_set_t* media_set, media_track_t** track
if (tracks[MEDIA_TYPE_VIDEO] != NULL)
{
media_info = &tracks[MEDIA_TYPE_VIDEO]->media_info;
bitrate += media_info->bitrate;
p = hds_amf0_append_array_number_value(p, &amf0_width, media_info->u.video.width);
p = hds_amf0_append_array_number_value(p, &amf0_height, media_info->u.video.height);
p = hds_amf0_append_array_number_value(p, &amf0_videodatarate, (double)media_info->bitrate / 1000.0);
Expand All @@ -166,7 +164,6 @@ hds_amf0_write_metadata(u_char* p, media_set_t* media_set, media_track_t** track
if (tracks[MEDIA_TYPE_AUDIO] != NULL)
{
media_info = &tracks[MEDIA_TYPE_AUDIO]->media_info;
bitrate += media_info->bitrate;
p = hds_amf0_append_array_number_value(p, &amf0_audiodatarate, (double)media_info->bitrate / 1000.0);
p = hds_amf0_append_array_number_value(p, &amf0_audiosamplerate, media_info->u.audio.sample_rate);
p = hds_amf0_append_array_number_value(p, &amf0_audiosamplesize, media_info->u.audio.bits_per_sample);
Expand Down