lavfi: use const for AVFilterPad declarations in all filters.
[FFMpeg-mirror/mplayer-patches.git] / libavcodec / mpegaudio_parser.c
blob017d6e1cda483bccc432d46b6ca89825d303d49a
1 /*
2 * MPEG Audio parser
3 * Copyright (c) 2003 Fabrice Bellard
4 * Copyright (c) 2003 Michael Niedermayer
6 * This file is part of Libav.
8 * Libav is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * Libav is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with Libav; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 #include "parser.h"
24 #include "mpegaudiodecheader.h"
27 typedef struct MpegAudioParseContext {
28 ParseContext pc;
29 int frame_size;
30 uint32_t header;
31 int header_count;
32 } MpegAudioParseContext;
34 #define MPA_HEADER_SIZE 4
36 /* header + layer + bitrate + freq + lsf/mpeg25 */
37 #define SAME_HEADER_MASK \
38 (0xffe00000 | (3 << 17) | (3 << 10) | (3 << 19))
40 static int mpegaudio_parse(AVCodecParserContext *s1,
41 AVCodecContext *avctx,
42 const uint8_t **poutbuf, int *poutbuf_size,
43 const uint8_t *buf, int buf_size)
45 MpegAudioParseContext *s = s1->priv_data;
46 ParseContext *pc = &s->pc;
47 uint32_t state= pc->state;
48 int i;
49 int next= END_NOT_FOUND;
51 for(i=0; i<buf_size; ){
52 if(s->frame_size){
53 int inc= FFMIN(buf_size - i, s->frame_size);
54 i += inc;
55 s->frame_size -= inc;
57 if(!s->frame_size){
58 next= i;
59 break;
61 }else{
62 while(i<buf_size){
63 int ret, sr, channels, bit_rate, frame_size;
65 state= (state<<8) + buf[i++];
67 ret = avpriv_mpa_decode_header(avctx, state, &sr, &channels, &frame_size, &bit_rate);
68 if (ret < 4) {
69 if (i > 4)
70 s->header_count = -2;
71 } else {
72 if((state&SAME_HEADER_MASK) != (s->header&SAME_HEADER_MASK) && s->header)
73 s->header_count= -3;
74 s->header= state;
75 s->header_count++;
76 s->frame_size = ret-4;
78 if (s->header_count > 0) {
79 avctx->sample_rate= sr;
80 avctx->channels = channels;
81 s1->duration = frame_size;
82 avctx->bit_rate = bit_rate;
84 break;
90 pc->state= state;
91 if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) {
92 *poutbuf = NULL;
93 *poutbuf_size = 0;
94 return buf_size;
97 *poutbuf = buf;
98 *poutbuf_size = buf_size;
99 return next;
103 AVCodecParser ff_mpegaudio_parser = {
104 .codec_ids = { CODEC_ID_MP1, CODEC_ID_MP2, CODEC_ID_MP3 },
105 .priv_data_size = sizeof(MpegAudioParseContext),
106 .parser_parse = mpegaudio_parse,
107 .parser_close = ff_parse_close,