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

derive sample rate from mp4a codec config #890

Open
wants to merge 1 commit 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions vod/codec_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
{
Expand All @@ -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;
}
3 changes: 2 additions & 1 deletion vod/codec_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion vod/media_format.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion vod/mkv/mkv_format.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 1 addition & 7 deletions vod/mp4/mp4_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down