Mercurial > libavcodec.hg
diff mpegaudio_parser.c @ 5050:a5f6fbc9fa66 libavcodec
loosen dependencies over mpegaudiodec
author | aurel |
---|---|
date | Sun, 20 May 2007 13:40:07 +0000 |
parents | 0d1cc37d9430 |
children | b908c67063c8 |
line wrap: on
line diff
--- a/mpegaudio_parser.c Sun May 20 05:07:44 2007 +0000 +++ b/mpegaudio_parser.c Sun May 20 13:40:07 2007 +0000 @@ -22,6 +22,7 @@ #include "parser.h" #include "mpegaudio.h" +#include "mpegaudiodecheader.h" typedef struct MpegAudioParseContext { @@ -41,6 +42,43 @@ #define SAME_HEADER_MASK \ (0xffe00000 | (3 << 17) | (3 << 10) | (3 << 19)) +/* useful helper to get mpeg audio stream infos. Return -1 if error in + header, otherwise the coded frame size in bytes */ +int mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate) +{ + MPADecodeContext s1, *s = &s1; + s1.avctx = avctx; + + if (ff_mpa_check_header(head) != 0) + return -1; + + if (decode_header(s, head) != 0) { + return -1; + } + + switch(s->layer) { + case 1: + avctx->frame_size = 384; + break; + case 2: + avctx->frame_size = 1152; + break; + default: + case 3: + if (s->lsf) + avctx->frame_size = 576; + else + avctx->frame_size = 1152; + break; + } + + *sample_rate = s->sample_rate; + avctx->channels = s->nb_channels; + avctx->bit_rate = s->bit_rate; + avctx->sub_id = s->layer; + return s->frame_size; +} + static int mpegaudio_parse_init(AVCodecParserContext *s1) { MpegAudioParseContext *s = s1->priv_data;