From 09c2b9421dc74b9e97472d3f38a0a2a0b0ad21ca Mon Sep 17 00:00:00 2001 From: Aurelien Jacobs Date: Wed, 8 Nov 2006 20:13:30 +0000 Subject: [PATCH] add support for AAC in matroska Originally committed as revision 6947 to svn://svn.ffmpeg.org/ffmpeg/trunk --- libavformat/matroska.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 3 deletions(-) diff --git a/libavformat/matroska.c b/libavformat/matroska.c index 4917388..b798275 100644 --- a/libavformat/matroska.c +++ b/libavformat/matroska.c @@ -223,7 +223,7 @@ static CodecTags codec_tags[]={ {"A_DTS" , CODEC_ID_DTS}, {"A_VORBIS" , CODEC_ID_VORBIS}, {"A_AAC/MPEG2/" , CODEC_ID_AAC}, - {"A_AAC/MPEG4/" , CODEC_ID_AAC}, + {"A_AAC/MPEG4/" , CODEC_ID_MPEG4AAC}, {"A_WAVPACK4" , CODEC_ID_WAVPACK}, {NULL , CODEC_ID_NONE} /* TODO: AC3-9/10 (?), Real, Musepack, Quicktime */ @@ -2022,6 +2022,37 @@ matroska_parse_seekhead (MatroskaDemuxContext *matroska) return res; } +#define ARRAY_SIZE(x) (sizeof(x)/sizeof(*x)) + +static int +matroska_aac_profile (char *codec_id) +{ + static const char *aac_profiles[] = { + "MAIN", "LC", "SSR" + }; + int profile; + + for (profile=0; profilenum_tracks; i++) { enum CodecID codec_id = CODEC_ID_NONE; - void *extradata = NULL; + uint8_t *extradata = NULL; int extradata_size = 0; track = matroska->tracks[i]; @@ -2175,7 +2206,8 @@ matroska_read_header (AVFormatContext *s, continue; for(j=0; codec_tags[j].str; j++){ - if(!strcmp(codec_tags[j].str, track->codec_id)){ + if(!strncmp(codec_tags[j].str, track->codec_id, + strlen(codec_tags[j].str))){ codec_id= codec_tags[j].id; break; } @@ -2214,6 +2246,26 @@ matroska_read_header (AVFormatContext *s, } + if (codec_id==CODEC_ID_AAC || codec_id==CODEC_ID_MPEG4AAC) { + MatroskaAudioTrack *audiotrack = (MatroskaAudioTrack *) track; + int profile = matroska_aac_profile(track->codec_id); + int sri = matroska_aac_sri(audiotrack->internal_samplerate); + extradata = av_malloc(5); + if (extradata == NULL) + return AVERROR_NOMEM; + extradata[0] = (profile << 3) | ((sri&0x0E) >> 1); + extradata[1] = ((sri&0x01) << 7) | (audiotrack->channels<<3); + if (strstr(track->codec_id, "SBR")) { + sri = matroska_aac_sri(audiotrack->samplerate); + extradata[2] = 0x56; + extradata[3] = 0xE5; + extradata[4] = 0x80 | (sri<<3); + extradata_size = 5; + } else { + extradata_size = 2; + } + } + if (codec_id == CODEC_ID_NONE) { av_log(matroska->ctx, AV_LOG_INFO, "Unknown/unsupported CodecID %s.\n", -- 2.7.4