From 6cc7b8c5ef03e7da94e24292bc5974d2d781cf95 Mon Sep 17 00:00:00 2001 From: igorshevach Date: Wed, 4 Sep 2024 21:01:48 +0300 Subject: [PATCH 01/12] add log to adts_encoder_set_media_info --- nginx-pckg-module/src/media/mpegts/adts_encoder_filter.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/nginx-pckg-module/src/media/mpegts/adts_encoder_filter.c b/nginx-pckg-module/src/media/mpegts/adts_encoder_filter.c index 8fcf4f98..30e4baa1 100644 --- a/nginx-pckg-module/src/media/mpegts/adts_encoder_filter.c +++ b/nginx-pckg-module/src/media/mpegts/adts_encoder_filter.c @@ -24,6 +24,7 @@ adts_encoder_set_media_info( { adts_encoder_state_t* state = get_context(context); mp4a_config_t* codec_config = &media_info->u.audio.codec_config; + request_context_t *request_context = context->request_context; if (context->request_context->simulation_only) { @@ -42,6 +43,13 @@ adts_encoder_set_media_info( adts_frame_header_set_channel_configuration(state->header, codec_config->channel_config); adts_frame_header_set_adts_buffer_fullness(state->header, 0x7ff); + ngx_log_error(NGX_LOG_INFO, &request_context->log, 0, + "adts_encoder_set_media_info: mp4a object_type: %D sample_rate_index: %D channel_config: %D", + codec_config->object_type, + codec_config->sample_rate_index, + codec_config->channel_config); + + return VOD_OK; } From 44031d23f6170cf75b44a0ee0169fb2c90a6dcb2 Mon Sep 17 00:00:00 2001 From: igorshevach Date: Wed, 4 Sep 2024 21:08:29 +0300 Subject: [PATCH 02/12] add log to adts_encoder_set_media_info --- nginx-pckg-module/src/media/mpegts/adts_encoder_filter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nginx-pckg-module/src/media/mpegts/adts_encoder_filter.c b/nginx-pckg-module/src/media/mpegts/adts_encoder_filter.c index 30e4baa1..e37ccfc7 100644 --- a/nginx-pckg-module/src/media/mpegts/adts_encoder_filter.c +++ b/nginx-pckg-module/src/media/mpegts/adts_encoder_filter.c @@ -43,7 +43,7 @@ adts_encoder_set_media_info( adts_frame_header_set_channel_configuration(state->header, codec_config->channel_config); adts_frame_header_set_adts_buffer_fullness(state->header, 0x7ff); - ngx_log_error(NGX_LOG_INFO, &request_context->log, 0, + ngx_log_error(NGX_LOG_INFO, request_context->log, 0, "adts_encoder_set_media_info: mp4a object_type: %D sample_rate_index: %D channel_config: %D", codec_config->object_type, codec_config->sample_rate_index, From b63be26e9d572816c45a3d0eb9c0957ab804c7f1 Mon Sep 17 00:00:00 2001 From: igorshevach Date: Thu, 5 Sep 2024 10:00:13 +0300 Subject: [PATCH 03/12] fix: re-read object_type in case of HE-AAC --- nginx-pckg-module/src/media/codec_config.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/nginx-pckg-module/src/media/codec_config.c b/nginx-pckg-module/src/media/codec_config.c index 27358472..04df1f8d 100644 --- a/nginx-pckg-module/src/media/codec_config.c +++ b/nginx-pckg-module/src/media/codec_config.c @@ -10,6 +10,10 @@ #define AOT_ESCAPE (31) +#define AOT_SBR (5) + +#define AOT_PS (29) + #define HVCC_HEADER_SIZE (22) @@ -497,6 +501,20 @@ codec_config_mp4a_config_parse( return VOD_BAD_DATA; } + if (result->object_type == AOT_SBR || result->object_type == AOT_PS ) + { + result->object_type = bit_read_stream_get(&reader, 5); + if (result->object_type == AOT_ESCAPE) + result->object_type = 32 + bit_read_stream_get(&reader, 6); + + if (reader.stream.eof_reached) + { + vod_log_error(VOD_LOG_ERR, log, 0, + "codec_config_mp4a_config_parse: failed to read all required audio extra data fields"); + return VOD_BAD_DATA; + } + } + return VOD_OK; } From dd087e62903df20f8a8e5518a4d03f1dfccba3ad Mon Sep 17 00:00:00 2001 From: igorshevach Date: Thu, 5 Sep 2024 13:38:52 +0300 Subject: [PATCH 04/12] fix: re-read object_type in case of HE-AAC --- nginx-pckg-module/src/media/codec_config.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/nginx-pckg-module/src/media/codec_config.c b/nginx-pckg-module/src/media/codec_config.c index 04df1f8d..c05808e9 100644 --- a/nginx-pckg-module/src/media/codec_config.c +++ b/nginx-pckg-module/src/media/codec_config.c @@ -496,26 +496,36 @@ codec_config_mp4a_config_parse( if (reader.stream.eof_reached) { - vod_log_error(VOD_LOG_ERR, log, 0, - "codec_config_mp4a_config_parse: failed to read all required audio extra data fields"); - return VOD_BAD_DATA; + goto error; } if (result->object_type == AOT_SBR || result->object_type == AOT_PS ) { + uint8_t ext_sample_rate_index = bit_read_stream_get(&reader, 4); + if (ext_sample_rate_index == 0x0f) + bit_read_stream_get(&reader, 24); + + if (reader.stream.eof_reached) + { + goto error; + } + result->object_type = bit_read_stream_get(&reader, 5); if (result->object_type == AOT_ESCAPE) result->object_type = 32 + bit_read_stream_get(&reader, 6); if (reader.stream.eof_reached) { - vod_log_error(VOD_LOG_ERR, log, 0, - "codec_config_mp4a_config_parse: failed to read all required audio extra data fields"); - return VOD_BAD_DATA; + goto error; } } return VOD_OK; +error: + + vod_log_error(VOD_LOG_ERR, log, 0, + "codec_config_mp4a_config_parse: failed to read all required audio extra data fields"); + return VOD_BAD_DATA; } uint32_t From 7a57bf24ebb9b06b4c82bb3166307e5497e72dab Mon Sep 17 00:00:00 2001 From: igorshevach Date: Thu, 5 Sep 2024 15:31:52 +0300 Subject: [PATCH 05/12] fix: re-read object_type in case of HE-AAC --- nginx-pckg-module/src/media/codec_config.c | 2 ++ nginx-pckg-module/src/media/mpegts/adts_encoder_filter.c | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/nginx-pckg-module/src/media/codec_config.c b/nginx-pckg-module/src/media/codec_config.c index c05808e9..ab903246 100644 --- a/nginx-pckg-module/src/media/codec_config.c +++ b/nginx-pckg-module/src/media/codec_config.c @@ -521,10 +521,12 @@ codec_config_mp4a_config_parse( } return VOD_OK; + error: vod_log_error(VOD_LOG_ERR, log, 0, "codec_config_mp4a_config_parse: failed to read all required audio extra data fields"); + return VOD_BAD_DATA; } diff --git a/nginx-pckg-module/src/media/mpegts/adts_encoder_filter.c b/nginx-pckg-module/src/media/mpegts/adts_encoder_filter.c index e37ccfc7..e0b57a93 100644 --- a/nginx-pckg-module/src/media/mpegts/adts_encoder_filter.c +++ b/nginx-pckg-module/src/media/mpegts/adts_encoder_filter.c @@ -24,7 +24,6 @@ adts_encoder_set_media_info( { adts_encoder_state_t* state = get_context(context); mp4a_config_t* codec_config = &media_info->u.audio.codec_config; - request_context_t *request_context = context->request_context; if (context->request_context->simulation_only) { @@ -43,12 +42,15 @@ adts_encoder_set_media_info( adts_frame_header_set_channel_configuration(state->header, codec_config->channel_config); adts_frame_header_set_adts_buffer_fullness(state->header, 0x7ff); - ngx_log_error(NGX_LOG_INFO, request_context->log, 0, +#if (VOD_DEBUG) + + ngx_log_error(NGX_LOG_INFO, context->request_context->log, 0, "adts_encoder_set_media_info: mp4a object_type: %D sample_rate_index: %D channel_config: %D", codec_config->object_type, codec_config->sample_rate_index, codec_config->channel_config); +#endif return VOD_OK; } From e3b7e33eba856587d78841cab1dee3ac90aa49e2 Mon Sep 17 00:00:00 2001 From: igorshevach Date: Sun, 8 Sep 2024 12:33:52 +0300 Subject: [PATCH 06/12] code convention --- nginx-pckg-module/src/media/codec_config.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nginx-pckg-module/src/media/codec_config.c b/nginx-pckg-module/src/media/codec_config.c index ab903246..4abfc273 100644 --- a/nginx-pckg-module/src/media/codec_config.c +++ b/nginx-pckg-module/src/media/codec_config.c @@ -479,6 +479,7 @@ codec_config_mp4a_config_parse( mp4a_config_t* result) { bit_reader_state_t reader; + uint8_t ext_sample_rate_index; vod_log_buffer(VOD_LOG_DEBUG_LEVEL, log, 0, "codec_config_mp4a_config_parse: extra data ", extra_data->data, extra_data->len); @@ -501,7 +502,7 @@ codec_config_mp4a_config_parse( if (result->object_type == AOT_SBR || result->object_type == AOT_PS ) { - uint8_t ext_sample_rate_index = bit_read_stream_get(&reader, 4); + ext_sample_rate_index = bit_read_stream_get(&reader, 4); if (ext_sample_rate_index == 0x0f) bit_read_stream_get(&reader, 24); From 24a6c4e6eac3368bedead9e77380508dcfd957e2 Mon Sep 17 00:00:00 2001 From: igorshevach Date: Sun, 8 Sep 2024 12:41:46 +0300 Subject: [PATCH 07/12] code convention --- nginx-pckg-module/src/media/codec_config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nginx-pckg-module/src/media/codec_config.c b/nginx-pckg-module/src/media/codec_config.c index 4abfc273..e9b05db7 100644 --- a/nginx-pckg-module/src/media/codec_config.c +++ b/nginx-pckg-module/src/media/codec_config.c @@ -500,7 +500,7 @@ codec_config_mp4a_config_parse( goto error; } - if (result->object_type == AOT_SBR || result->object_type == AOT_PS ) + if (result->object_type == AOT_SBR || result->object_type == AOT_PS) { ext_sample_rate_index = bit_read_stream_get(&reader, 4); if (ext_sample_rate_index == 0x0f) From f33de588a5b6449ccfcc794a5843a05ef0aca7c5 Mon Sep 17 00:00:00 2001 From: igorshevach Date: Sun, 8 Sep 2024 12:49:22 +0300 Subject: [PATCH 08/12] code convention --- nginx-pckg-module/src/media/codec_config.c | 4 +++- nginx-pckg-module/src/media/mpegts/adts_encoder_filter.c | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/nginx-pckg-module/src/media/codec_config.c b/nginx-pckg-module/src/media/codec_config.c index e9b05db7..1e49d0ed 100644 --- a/nginx-pckg-module/src/media/codec_config.c +++ b/nginx-pckg-module/src/media/codec_config.c @@ -504,11 +504,13 @@ codec_config_mp4a_config_parse( { ext_sample_rate_index = bit_read_stream_get(&reader, 4); if (ext_sample_rate_index == 0x0f) + { bit_read_stream_get(&reader, 24); + } if (reader.stream.eof_reached) { - goto error; + goto error; } result->object_type = bit_read_stream_get(&reader, 5); diff --git a/nginx-pckg-module/src/media/mpegts/adts_encoder_filter.c b/nginx-pckg-module/src/media/mpegts/adts_encoder_filter.c index e0b57a93..96ed8c1a 100644 --- a/nginx-pckg-module/src/media/mpegts/adts_encoder_filter.c +++ b/nginx-pckg-module/src/media/mpegts/adts_encoder_filter.c @@ -44,7 +44,7 @@ adts_encoder_set_media_info( #if (VOD_DEBUG) - ngx_log_error(NGX_LOG_INFO, context->request_context->log, 0, + vod_log_debug3(VOD_LOG_DEBUG_LEVEL, context->request_context->log, 0, "adts_encoder_set_media_info: mp4a object_type: %D sample_rate_index: %D channel_config: %D", codec_config->object_type, codec_config->sample_rate_index, From ad764fbd653dd032ab7bf4ad16539d4922f3b43c Mon Sep 17 00:00:00 2001 From: igorshevach Date: Sun, 8 Sep 2024 12:58:16 +0300 Subject: [PATCH 09/12] fix add validity checks when dealing with AOT_SBR as in ffmpeg --- nginx-pckg-module/src/media/codec_config.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/nginx-pckg-module/src/media/codec_config.c b/nginx-pckg-module/src/media/codec_config.c index 1e49d0ed..8de7e12a 100644 --- a/nginx-pckg-module/src/media/codec_config.c +++ b/nginx-pckg-module/src/media/codec_config.c @@ -478,7 +478,7 @@ codec_config_mp4a_config_parse( vod_str_t* extra_data, mp4a_config_t* result) { - bit_reader_state_t reader; + bit_reader_state_t reader, temp_reader; uint8_t ext_sample_rate_index; vod_log_buffer(VOD_LOG_DEBUG_LEVEL, log, 0, "codec_config_mp4a_config_parse: extra data ", extra_data->data, extra_data->len); @@ -500,7 +500,9 @@ codec_config_mp4a_config_parse( goto error; } - if (result->object_type == AOT_SBR || result->object_type == AOT_PS) +temp_reader = reader; +if (result->object_type == AOT_SBR || (result->object_type == AOT_PS && + !(bit_read_stream_get(&temp_reader, 3) & 0x03 && !(bit_read_stream_get(&temp_reader, 9) & 0x3f)))) { ext_sample_rate_index = bit_read_stream_get(&reader, 4); if (ext_sample_rate_index == 0x0f) From e05468a51249061461ac02fa4024d7328b720f99 Mon Sep 17 00:00:00 2001 From: igorshevach Date: Mon, 9 Sep 2024 00:56:46 +0300 Subject: [PATCH 10/12] missing indent --- nginx-pckg-module/src/media/codec_config.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nginx-pckg-module/src/media/codec_config.c b/nginx-pckg-module/src/media/codec_config.c index 8de7e12a..e045851d 100644 --- a/nginx-pckg-module/src/media/codec_config.c +++ b/nginx-pckg-module/src/media/codec_config.c @@ -500,9 +500,9 @@ codec_config_mp4a_config_parse( goto error; } -temp_reader = reader; -if (result->object_type == AOT_SBR || (result->object_type == AOT_PS && - !(bit_read_stream_get(&temp_reader, 3) & 0x03 && !(bit_read_stream_get(&temp_reader, 9) & 0x3f)))) + temp_reader = reader; + if (result->object_type == AOT_SBR || (result->object_type == AOT_PS && + !(bit_read_stream_get(&temp_reader, 3) & 0x03 && !(bit_read_stream_get(&temp_reader, 9) & 0x3f)))) { ext_sample_rate_index = bit_read_stream_get(&reader, 4); if (ext_sample_rate_index == 0x0f) From 312b17746bdf3ca8e2acd9d86ba0e01be28154c4 Mon Sep 17 00:00:00 2001 From: igorshevach Date: Mon, 9 Sep 2024 00:58:39 +0300 Subject: [PATCH 11/12] brackets --- nginx-pckg-module/src/media/codec_config.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nginx-pckg-module/src/media/codec_config.c b/nginx-pckg-module/src/media/codec_config.c index e045851d..aabb6ac9 100644 --- a/nginx-pckg-module/src/media/codec_config.c +++ b/nginx-pckg-module/src/media/codec_config.c @@ -517,7 +517,9 @@ codec_config_mp4a_config_parse( result->object_type = bit_read_stream_get(&reader, 5); if (result->object_type == AOT_ESCAPE) + { result->object_type = 32 + bit_read_stream_get(&reader, 6); + } if (reader.stream.eof_reached) { From 8f7b45e3a3ccafcbb114b0d9a1e9bb0b8629d85e Mon Sep 17 00:00:00 2001 From: igorshevach Date: Mon, 9 Sep 2024 01:00:28 +0300 Subject: [PATCH 12/12] remove unneeded #if --- nginx-pckg-module/src/media/mpegts/adts_encoder_filter.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/nginx-pckg-module/src/media/mpegts/adts_encoder_filter.c b/nginx-pckg-module/src/media/mpegts/adts_encoder_filter.c index 96ed8c1a..389710fb 100644 --- a/nginx-pckg-module/src/media/mpegts/adts_encoder_filter.c +++ b/nginx-pckg-module/src/media/mpegts/adts_encoder_filter.c @@ -42,16 +42,12 @@ adts_encoder_set_media_info( adts_frame_header_set_channel_configuration(state->header, codec_config->channel_config); adts_frame_header_set_adts_buffer_fullness(state->header, 0x7ff); -#if (VOD_DEBUG) - vod_log_debug3(VOD_LOG_DEBUG_LEVEL, context->request_context->log, 0, "adts_encoder_set_media_info: mp4a object_type: %D sample_rate_index: %D channel_config: %D", codec_config->object_type, codec_config->sample_rate_index, codec_config->channel_config); -#endif - return VOD_OK; }