diff --git a/vod/codec_config.c b/vod/codec_config.c index 8863ff5e..1d7251c2 100644 --- a/vod/codec_config.c +++ b/vod/codec_config.c @@ -10,6 +10,13 @@ #define AOT_ESCAPE (31) +static const uint32_t mp4a_sample_rates[] = { + 96000, 88200, 64000, 48000, + 44100, 32000, 24000, 22050, + 16000, 12000, 11025, 8000, + 7350, +}; + vod_status_t codec_config_avcc_get_nal_units( request_context_t* request_context, @@ -484,23 +491,30 @@ vod_status_t codec_config_mp4a_config_parse( request_context_t* request_context, vod_str_t* extra_data, - mp4a_config_t* result) + audio_media_info_t* result) { bit_reader_state_t reader; + mp4a_config_t* codec_config = &result->codec_config; vod_log_buffer(VOD_LOG_DEBUG_LEVEL, request_context->log, 0, "codec_config_mp4a_config_parse: extra data ", extra_data->data, extra_data->len); bit_read_stream_init(&reader, extra_data->data, extra_data->len); - 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); + codec_config->object_type = bit_read_stream_get(&reader, 5); + if (codec_config->object_type == AOT_ESCAPE) + codec_config->object_type = 32 + bit_read_stream_get(&reader, 6); - result->sample_rate_index = bit_read_stream_get(&reader, 4); - if (result->sample_rate_index == 0x0f) - bit_read_stream_get(&reader, 24); + codec_config->sample_rate_index = bit_read_stream_get(&reader, 4); + if (codec_config->sample_rate_index == 0x0f) + { + result->sample_rate = bit_read_stream_get(&reader, 24); + } + else if (codec_config->sample_rate_index < vod_array_entries(mp4a_sample_rates)) + { + result->sample_rate = mp4a_sample_rates[codec_config->sample_rate_index]; + } - result->channel_config = bit_read_stream_get(&reader, 4); + codec_config->channel_config = bit_read_stream_get(&reader, 4); if (reader.stream.eof_reached) { @@ -509,5 +523,9 @@ codec_config_mp4a_config_parse( return VOD_BAD_DATA; } + vod_log_debug3(VOD_LOG_DEBUG_LEVEL, request_context->log, 0, + "mp4_parser_read_config_descriptor: codec config: 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; } diff --git a/vod/codec_config.h b/vod/codec_config.h index eb41a8e0..8e3c8f94 100644 --- a/vod/codec_config.h +++ b/vod/codec_config.h @@ -6,6 +6,7 @@ // typedefs struct media_info_s; +struct audio_media_info_s; typedef vod_status_t (*codec_config_get_nal_units_t)( request_context_t* request_context, @@ -88,7 +89,7 @@ vod_status_t codec_config_get_audio_codec_name(request_context_t* request_contex vod_status_t codec_config_mp4a_config_parse( request_context_t* request_context, vod_str_t* extra_data, - mp4a_config_t* result); + struct audio_media_info_s* result); vod_status_t codec_config_hevc_config_parse( request_context_t* request_context, diff --git a/vod/media_format.h b/vod/media_format.h index 8147c592..68c2e432 100644 --- a/vod/media_format.h +++ b/vod/media_format.h @@ -148,7 +148,7 @@ typedef struct { uint32_t key_frame_bitrate; } video_media_info_t; -typedef struct { +typedef struct audio_media_info_s { uint8_t object_type_id; uint16_t channels; uint16_t bits_per_sample; diff --git a/vod/mkv/mkv_format.c b/vod/mkv/mkv_format.c index 032769b4..8d8b3853 100644 --- a/vod/mkv/mkv_format.c +++ b/vod/mkv/mkv_format.c @@ -851,7 +851,7 @@ mkv_metadata_parse( rc = codec_config_mp4a_config_parse( request_context, &track.codec_private, - &cur_track->media_info.u.audio.codec_config); + &cur_track->media_info.u.audio); if (rc != VOD_OK) { return rc; diff --git a/vod/mp4/mp4_parser.c b/vod/mp4/mp4_parser.c index 7643baed..499464c9 100644 --- a/vod/mp4/mp4_parser.c +++ b/vod/mp4/mp4_parser.c @@ -2025,7 +2025,6 @@ mp4_parser_parse_es_descriptor(simple_read_stream_t* stream) // ff_mp4_par static vod_status_t mp4_parser_read_config_descriptor(metadata_parse_context_t* context, simple_read_stream_t* stream) // ff_mp4_read_dec_config_descr { - mp4a_config_t* codec_config; vod_status_t rc; unsigned len; int tag; @@ -2046,19 +2045,14 @@ mp4_parser_read_config_descriptor(metadata_parse_context_t* context, simple_read context->media_info.extra_data.len = len; context->media_info.extra_data.data = (u_char*)stream->cur_pos; - codec_config = &context->media_info.u.audio.codec_config; rc = codec_config_mp4a_config_parse( context->request_context, &context->media_info.extra_data, - codec_config); + &context->media_info.u.audio); if (rc != VOD_OK) { return rc; } - - vod_log_debug3(VOD_LOG_DEBUG_LEVEL, context->request_context->log, 0, - "mp4_parser_read_config_descriptor: codec config: 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;