Mercurial > libavformat.hg
comparison matroska.c @ 1468:3f467725b70f libavformat
add support for AAC in matroska
author | aurel |
---|---|
date | Wed, 08 Nov 2006 20:13:30 +0000 |
parents | 24c082e20a6a |
children | 49d5a5ca2987 |
comparison
equal
deleted
inserted
replaced
1467:24c082e20a6a | 1468:3f467725b70f |
---|---|
221 // {"A_PCM/FLOAT/IEEE" , CODEC_ID_NONE}, | 221 // {"A_PCM/FLOAT/IEEE" , CODEC_ID_NONE}, |
222 {"A_AC3" , CODEC_ID_AC3}, | 222 {"A_AC3" , CODEC_ID_AC3}, |
223 {"A_DTS" , CODEC_ID_DTS}, | 223 {"A_DTS" , CODEC_ID_DTS}, |
224 {"A_VORBIS" , CODEC_ID_VORBIS}, | 224 {"A_VORBIS" , CODEC_ID_VORBIS}, |
225 {"A_AAC/MPEG2/" , CODEC_ID_AAC}, | 225 {"A_AAC/MPEG2/" , CODEC_ID_AAC}, |
226 {"A_AAC/MPEG4/" , CODEC_ID_AAC}, | 226 {"A_AAC/MPEG4/" , CODEC_ID_MPEG4AAC}, |
227 {"A_WAVPACK4" , CODEC_ID_WAVPACK}, | 227 {"A_WAVPACK4" , CODEC_ID_WAVPACK}, |
228 {NULL , CODEC_ID_NONE} | 228 {NULL , CODEC_ID_NONE} |
229 /* TODO: AC3-9/10 (?), Real, Musepack, Quicktime */ | 229 /* TODO: AC3-9/10 (?), Real, Musepack, Quicktime */ |
230 }; | 230 }; |
231 | 231 |
2020 } | 2020 } |
2021 | 2021 |
2022 return res; | 2022 return res; |
2023 } | 2023 } |
2024 | 2024 |
2025 #define ARRAY_SIZE(x) (sizeof(x)/sizeof(*x)) | |
2026 | |
2027 static int | |
2028 matroska_aac_profile (char *codec_id) | |
2029 { | |
2030 static const char *aac_profiles[] = { | |
2031 "MAIN", "LC", "SSR" | |
2032 }; | |
2033 int profile; | |
2034 | |
2035 for (profile=0; profile<ARRAY_SIZE(aac_profiles); profile++) | |
2036 if (strstr(codec_id, aac_profiles[profile])) | |
2037 break; | |
2038 return profile + 1; | |
2039 } | |
2040 | |
2041 static int | |
2042 matroska_aac_sri (int samplerate) | |
2043 { | |
2044 static const int aac_sample_rates[] = { | |
2045 96000, 88200, 64000, 48000, 44100, 32000, | |
2046 24000, 22050, 16000, 12000, 11025, 8000, | |
2047 }; | |
2048 int sri; | |
2049 | |
2050 for (sri=0; sri<ARRAY_SIZE(aac_sample_rates); sri++) | |
2051 if (aac_sample_rates[sri] == samplerate) | |
2052 break; | |
2053 return sri; | |
2054 } | |
2055 | |
2025 static int | 2056 static int |
2026 matroska_read_header (AVFormatContext *s, | 2057 matroska_read_header (AVFormatContext *s, |
2027 AVFormatParameters *ap) | 2058 AVFormatParameters *ap) |
2028 { | 2059 { |
2029 MatroskaDemuxContext *matroska = s->priv_data; | 2060 MatroskaDemuxContext *matroska = s->priv_data; |
2162 MatroskaTrack *track; | 2193 MatroskaTrack *track; |
2163 AVStream *st; | 2194 AVStream *st; |
2164 | 2195 |
2165 for (i = 0; i < matroska->num_tracks; i++) { | 2196 for (i = 0; i < matroska->num_tracks; i++) { |
2166 enum CodecID codec_id = CODEC_ID_NONE; | 2197 enum CodecID codec_id = CODEC_ID_NONE; |
2167 void *extradata = NULL; | 2198 uint8_t *extradata = NULL; |
2168 int extradata_size = 0; | 2199 int extradata_size = 0; |
2169 track = matroska->tracks[i]; | 2200 track = matroska->tracks[i]; |
2170 | 2201 |
2171 /* libavformat does not really support subtitles. | 2202 /* libavformat does not really support subtitles. |
2172 * Also apply some sanity checks. */ | 2203 * Also apply some sanity checks. */ |
2173 if ((track->type == MATROSKA_TRACK_TYPE_SUBTITLE) || | 2204 if ((track->type == MATROSKA_TRACK_TYPE_SUBTITLE) || |
2174 (track->codec_id == NULL)) | 2205 (track->codec_id == NULL)) |
2175 continue; | 2206 continue; |
2176 | 2207 |
2177 for(j=0; codec_tags[j].str; j++){ | 2208 for(j=0; codec_tags[j].str; j++){ |
2178 if(!strcmp(codec_tags[j].str, track->codec_id)){ | 2209 if(!strncmp(codec_tags[j].str, track->codec_id, |
2210 strlen(codec_tags[j].str))){ | |
2179 codec_id= codec_tags[j].id; | 2211 codec_id= codec_tags[j].id; |
2180 break; | 2212 break; |
2181 } | 2213 } |
2182 } | 2214 } |
2183 | 2215 |
2210 /* Offset of wFormatTag. Stored in LE. */ | 2242 /* Offset of wFormatTag. Stored in LE. */ |
2211 p = (unsigned char *)track->codec_priv; | 2243 p = (unsigned char *)track->codec_priv; |
2212 tag = (p[1] << 8) | p[0]; | 2244 tag = (p[1] << 8) | p[0]; |
2213 codec_id = codec_get_wav_id(tag); | 2245 codec_id = codec_get_wav_id(tag); |
2214 | 2246 |
2247 } | |
2248 | |
2249 if (codec_id==CODEC_ID_AAC || codec_id==CODEC_ID_MPEG4AAC) { | |
2250 MatroskaAudioTrack *audiotrack = (MatroskaAudioTrack *) track; | |
2251 int profile = matroska_aac_profile(track->codec_id); | |
2252 int sri = matroska_aac_sri(audiotrack->internal_samplerate); | |
2253 extradata = av_malloc(5); | |
2254 if (extradata == NULL) | |
2255 return AVERROR_NOMEM; | |
2256 extradata[0] = (profile << 3) | ((sri&0x0E) >> 1); | |
2257 extradata[1] = ((sri&0x01) << 7) | (audiotrack->channels<<3); | |
2258 if (strstr(track->codec_id, "SBR")) { | |
2259 sri = matroska_aac_sri(audiotrack->samplerate); | |
2260 extradata[2] = 0x56; | |
2261 extradata[3] = 0xE5; | |
2262 extradata[4] = 0x80 | (sri<<3); | |
2263 extradata_size = 5; | |
2264 } else { | |
2265 extradata_size = 2; | |
2266 } | |
2215 } | 2267 } |
2216 | 2268 |
2217 if (codec_id == CODEC_ID_NONE) { | 2269 if (codec_id == CODEC_ID_NONE) { |
2218 av_log(matroska->ctx, AV_LOG_INFO, | 2270 av_log(matroska->ctx, AV_LOG_INFO, |
2219 "Unknown/unsupported CodecID %s.\n", | 2271 "Unknown/unsupported CodecID %s.\n", |