annotate parser.c @ 1642:e83980313d3f libavcodec

rv20 sub_id == 0x20200002 support
author michael
date Sun, 30 Nov 2003 18:08:35 +0000
parents 6c82ef97d3e6
children 27a272442d6b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1613
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
1 /*
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
2 * Audio and Video frame extraction
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
3 * Copyright (c) 2003 Fabrice Bellard.
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
4 * Copyright (c) 2003 Michael Niedermayer.
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
5 *
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
6 * This library is free software; you can redistribute it and/or
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
7 * modify it under the terms of the GNU Lesser General Public
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
8 * License as published by the Free Software Foundation; either
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
9 * version 2 of the License, or (at your option) any later version.
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
10 *
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
11 * This library is distributed in the hope that it will be useful,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
14 * Lesser General Public License for more details.
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
15 *
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
16 * You should have received a copy of the GNU Lesser General Public
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
17 * License along with this library; if not, write to the Free Software
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
19 */
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
20 #include "avcodec.h"
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
21 #include "mpegvideo.h"
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
22 #include "mpegaudio.h"
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
23
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
24 AVCodecParser *av_first_parser = NULL;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
25
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
26 void av_register_codec_parser(AVCodecParser *parser)
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
27 {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
28 parser->next = av_first_parser;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
29 av_first_parser = parser;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
30 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
31
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
32 AVCodecParserContext *av_parser_init(int codec_id)
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
33 {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
34 AVCodecParserContext *s;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
35 AVCodecParser *parser;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
36 int ret;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
37
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
38 for(parser = av_first_parser; parser != NULL; parser = parser->next) {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
39 if (parser->codec_ids[0] == codec_id ||
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
40 parser->codec_ids[1] == codec_id ||
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
41 parser->codec_ids[2] == codec_id)
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
42 goto found;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
43 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
44 return NULL;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
45 found:
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
46 s = av_mallocz(sizeof(AVCodecParserContext));
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
47 if (!s)
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
48 return NULL;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
49 s->parser = parser;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
50 s->priv_data = av_mallocz(parser->priv_data_size);
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
51 if (!s->priv_data) {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
52 av_free(s);
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
53 return NULL;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
54 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
55 if (parser->parser_init) {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
56 ret = parser->parser_init(s);
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
57 if (ret != 0) {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
58 av_free(s->priv_data);
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
59 av_free(s);
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
60 return NULL;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
61 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
62 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
63 return s;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
64 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
65
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
66 int av_parser_parse(AVCodecParserContext *s,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
67 AVCodecContext *avctx,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
68 uint8_t **poutbuf, int *poutbuf_size,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
69 const uint8_t *buf, int buf_size)
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
70 {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
71 int index;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
72 /* WARNING: the returned index can be negative */
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
73 index = s->parser->parser_parse(s, avctx, poutbuf, poutbuf_size, buf, buf_size);
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
74 /* update the file pointer */
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
75 if (*poutbuf_size) {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
76 s->frame_offset = s->last_frame_offset;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
77 s->last_frame_offset = s->cur_offset + index;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
78 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
79 if (index < 0)
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
80 index = 0;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
81 s->cur_offset += index;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
82 return index;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
83 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
84
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
85 void av_parser_close(AVCodecParserContext *s)
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
86 {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
87 if (s->parser->parser_close)
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
88 s->parser->parser_close(s);
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
89 av_free(s->priv_data);
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
90 av_free(s);
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
91 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
92
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
93 /*****************************************************/
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
94
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
95 //#define END_NOT_FOUND (-100)
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
96
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
97 #define PICTURE_START_CODE 0x00000100
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
98 #define SEQ_START_CODE 0x000001b3
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
99 #define EXT_START_CODE 0x000001b5
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
100 #define SLICE_MIN_START_CODE 0x00000101
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
101 #define SLICE_MAX_START_CODE 0x000001af
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
102
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
103 typedef struct ParseContext1{
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
104 uint8_t *buffer;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
105 int index;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
106 int last_index;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
107 int buffer_size;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
108 uint32_t state; ///< contains the last few bytes in MSB order
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
109 int frame_start_found;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
110 int overread; ///< the number of bytes which where irreversibly read from the next frame
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
111 int overread_index; ///< the index into ParseContext1.buffer of the overreaded bytes
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
112
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
113 /* MPEG2 specific */
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
114 int frame_rate;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
115 int progressive_sequence;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
116 int width, height;
1614
6c82ef97d3e6 also parse extradata for MPEG4
bellard
parents: 1613
diff changeset
117
1613
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
118 /* XXX: suppress that, needed by MPEG4 */
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
119 MpegEncContext *enc;
1614
6c82ef97d3e6 also parse extradata for MPEG4
bellard
parents: 1613
diff changeset
120 int first_picture;
1613
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
121 } ParseContext1;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
122
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
123 /**
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
124 * combines the (truncated) bitstream to a complete frame
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
125 * @returns -1 if no complete frame could be created
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
126 */
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
127 static int ff_combine_frame1(ParseContext1 *pc, int next, uint8_t **buf, int *buf_size)
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
128 {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
129 #if 0
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
130 if(pc->overread){
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
131 printf("overread %d, state:%X next:%d index:%d o_index:%d\n", pc->overread, pc->state, next, pc->index, pc->overread_index);
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
132 printf("%X %X %X %X\n", (*buf)[0], (*buf)[1],(*buf)[2],(*buf)[3]);
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
133 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
134 #endif
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
135
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
136 /* copy overreaded bytes from last frame into buffer */
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
137 for(; pc->overread>0; pc->overread--){
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
138 pc->buffer[pc->index++]= pc->buffer[pc->overread_index++];
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
139 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
140
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
141 pc->last_index= pc->index;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
142
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
143 /* copy into buffer end return */
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
144 if(next == END_NOT_FOUND){
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
145 pc->buffer= av_fast_realloc(pc->buffer, &pc->buffer_size, (*buf_size) + pc->index + FF_INPUT_BUFFER_PADDING_SIZE);
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
146
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
147 memcpy(&pc->buffer[pc->index], *buf, *buf_size);
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
148 pc->index += *buf_size;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
149 return -1;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
150 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
151
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
152 *buf_size=
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
153 pc->overread_index= pc->index + next;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
154
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
155 /* append to buffer */
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
156 if(pc->index){
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
157 pc->buffer= av_fast_realloc(pc->buffer, &pc->buffer_size, next + pc->index + FF_INPUT_BUFFER_PADDING_SIZE);
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
158
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
159 memcpy(&pc->buffer[pc->index], *buf, next + FF_INPUT_BUFFER_PADDING_SIZE );
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
160 pc->index = 0;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
161 *buf= pc->buffer;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
162 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
163
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
164 /* store overread bytes */
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
165 for(;next < 0; next++){
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
166 pc->state = (pc->state<<8) | pc->buffer[pc->last_index + next];
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
167 pc->overread++;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
168 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
169
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
170 #if 0
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
171 if(pc->overread){
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
172 printf("overread %d, state:%X next:%d index:%d o_index:%d\n", pc->overread, pc->state, next, pc->index, pc->overread_index);
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
173 printf("%X %X %X %X\n", (*buf)[0], (*buf)[1],(*buf)[2],(*buf)[3]);
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
174 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
175 #endif
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
176
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
177 return 0;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
178 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
179
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
180 /**
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
181 * finds the end of the current frame in the bitstream.
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
182 * @return the position of the first byte of the next frame, or -1
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
183 */
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
184 static int mpeg1_find_frame_end(ParseContext1 *pc, const uint8_t *buf, int buf_size)
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
185 {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
186 int i;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
187 uint32_t state;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
188
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
189 state= pc->state;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
190
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
191 i=0;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
192 if(!pc->frame_start_found){
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
193 for(i=0; i<buf_size; i++){
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
194 state= (state<<8) | buf[i];
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
195 if(state >= SLICE_MIN_START_CODE && state <= SLICE_MAX_START_CODE){
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
196 i++;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
197 pc->frame_start_found=1;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
198 break;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
199 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
200 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
201 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
202
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
203 if(pc->frame_start_found){
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
204 for(; i<buf_size; i++){
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
205 state= (state<<8) | buf[i];
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
206 if((state&0xFFFFFF00) == 0x100){
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
207 if(state < SLICE_MIN_START_CODE || state > SLICE_MAX_START_CODE){
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
208 pc->frame_start_found=0;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
209 pc->state=-1;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
210 return i-3;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
211 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
212 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
213 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
214 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
215 pc->state= state;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
216 return END_NOT_FOUND;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
217 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
218
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
219 static int find_start_code(const uint8_t **pbuf_ptr, const uint8_t *buf_end)
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
220 {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
221 const uint8_t *buf_ptr;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
222 unsigned int state=0xFFFFFFFF, v;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
223 int val;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
224
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
225 buf_ptr = *pbuf_ptr;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
226 while (buf_ptr < buf_end) {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
227 v = *buf_ptr++;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
228 if (state == 0x000001) {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
229 state = ((state << 8) | v) & 0xffffff;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
230 val = state;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
231 goto found;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
232 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
233 state = ((state << 8) | v) & 0xffffff;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
234 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
235 val = -1;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
236 found:
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
237 *pbuf_ptr = buf_ptr;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
238 return val;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
239 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
240
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
241 /* XXX: merge with libavcodec ? */
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
242 #define MPEG1_FRAME_RATE_BASE 1001
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
243
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
244 static const int frame_rate_tab[16] = {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
245 0,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
246 24000,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
247 24024,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
248 25025,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
249 30000,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
250 30030,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
251 50050,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
252 60000,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
253 60060,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
254 // Xing's 15fps: (9)
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
255 15015,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
256 // libmpeg3's "Unofficial economy rates": (10-13)
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
257 5005,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
258 10010,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
259 12012,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
260 15015,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
261 // random, just to avoid segfault !never encode these
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
262 25025,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
263 25025,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
264 };
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
265
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
266 static void mpegvideo_extract_headers(AVCodecParserContext *s,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
267 AVCodecContext *avctx,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
268 const uint8_t *buf, int buf_size)
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
269 {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
270 ParseContext1 *pc = s->priv_data;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
271 const uint8_t *buf_end;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
272 int32_t start_code;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
273 int frame_rate_index, ext_type, bytes_left;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
274 int frame_rate_ext_n, frame_rate_ext_d;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
275 int top_field_first, repeat_first_field, progressive_frame;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
276 int horiz_size_ext, vert_size_ext;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
277
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
278 s->repeat_pict = 0;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
279 buf_end = buf + buf_size;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
280 while (buf < buf_end) {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
281 start_code = find_start_code(&buf, buf_end);
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
282 bytes_left = buf_end - buf;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
283 switch(start_code) {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
284 case PICTURE_START_CODE:
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
285 if (bytes_left >= 2) {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
286 s->pict_type = (buf[1] >> 3) & 7;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
287 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
288 break;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
289 case SEQ_START_CODE:
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
290 if (bytes_left >= 4) {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
291 pc->width = avctx->width = (buf[0] << 4) | (buf[1] >> 4);
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
292 pc->height = avctx->height = ((buf[1] & 0x0f) << 8) | buf[2];
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
293 frame_rate_index = buf[3] & 0xf;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
294 pc->frame_rate = avctx->frame_rate = frame_rate_tab[frame_rate_index];
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
295 avctx->frame_rate_base = MPEG1_FRAME_RATE_BASE;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
296 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
297 break;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
298 case EXT_START_CODE:
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
299 if (bytes_left >= 1) {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
300 ext_type = (buf[0] >> 4);
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
301 switch(ext_type) {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
302 case 0x1: /* sequence extension */
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
303 if (bytes_left >= 6) {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
304 horiz_size_ext = ((buf[1] & 1) << 1) | (buf[2] >> 7);
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
305 vert_size_ext = (buf[2] >> 5) & 3;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
306 frame_rate_ext_n = (buf[5] >> 5) & 3;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
307 frame_rate_ext_d = (buf[5] & 0x1f);
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
308 pc->progressive_sequence = buf[1] & (1 << 3);
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
309
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
310 avctx->width = pc->width | (horiz_size_ext << 12);
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
311 avctx->height = pc->height | (vert_size_ext << 12);
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
312 avctx->frame_rate = pc->frame_rate * (frame_rate_ext_n + 1);
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
313 avctx->frame_rate_base = MPEG1_FRAME_RATE_BASE * (frame_rate_ext_d + 1);
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
314 avctx->sub_id = 2; /* forces MPEG2 */
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
315 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
316 break;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
317 case 0x8: /* picture coding extension */
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
318 if (bytes_left >= 5) {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
319 top_field_first = buf[3] & (1 << 7);
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
320 repeat_first_field = buf[3] & (1 << 1);
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
321 progressive_frame = buf[4] & (1 << 7);
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
322
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
323 /* check if we must repeat the frame */
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
324 if (repeat_first_field) {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
325 if (pc->progressive_sequence) {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
326 if (top_field_first)
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
327 s->repeat_pict = 4;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
328 else
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
329 s->repeat_pict = 2;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
330 } else if (progressive_frame) {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
331 s->repeat_pict = 1;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
332 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
333 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
334 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
335 break;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
336 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
337 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
338 break;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
339 case -1:
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
340 goto the_end;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
341 default:
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
342 /* we stop parsing when we encounter a slice. It ensures
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
343 that this function takes a negligible amount of time */
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
344 if (start_code >= SLICE_MIN_START_CODE &&
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
345 start_code <= SLICE_MAX_START_CODE)
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
346 goto the_end;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
347 break;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
348 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
349 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
350 the_end: ;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
351 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
352
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
353 static int mpegvideo_parse(AVCodecParserContext *s,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
354 AVCodecContext *avctx,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
355 uint8_t **poutbuf, int *poutbuf_size,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
356 const uint8_t *buf, int buf_size)
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
357 {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
358 ParseContext1 *pc = s->priv_data;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
359 int next;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
360
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
361 next= mpeg1_find_frame_end(pc, buf, buf_size);
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
362
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
363 if (ff_combine_frame1(pc, next, (uint8_t **)&buf, &buf_size) < 0) {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
364 *poutbuf = NULL;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
365 *poutbuf_size = 0;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
366 return buf_size;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
367 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
368 /* we have a full frame : we just parse the first few MPEG headers
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
369 to have the full timing information. The time take by this
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
370 function should be negligible for uncorrupted streams */
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
371 mpegvideo_extract_headers(s, avctx, buf, buf_size);
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
372 #if 0
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
373 printf("pict_type=%d frame_rate=%0.3f repeat_pict=%d\n",
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
374 s->pict_type, (double)avctx->frame_rate / avctx->frame_rate_base, s->repeat_pict);
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
375 #endif
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
376
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
377 *poutbuf = (uint8_t *)buf;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
378 *poutbuf_size = buf_size;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
379 return next;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
380 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
381
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
382 static void mpegvideo_parse_close(AVCodecParserContext *s)
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
383 {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
384 ParseContext1 *pc = s->priv_data;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
385
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
386 av_free(pc->buffer);
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
387 av_free(pc->enc);
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
388 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
389
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
390 /*************************/
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
391
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
392 /**
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
393 * finds the end of the current frame in the bitstream.
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
394 * @return the position of the first byte of the next frame, or -1
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
395 */
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
396 static int mpeg4_find_frame_end(ParseContext1 *pc,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
397 const uint8_t *buf, int buf_size)
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
398 {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
399 int vop_found, i;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
400 uint32_t state;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
401
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
402 vop_found= pc->frame_start_found;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
403 state= pc->state;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
404
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
405 i=0;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
406 if(!vop_found){
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
407 for(i=0; i<buf_size; i++){
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
408 state= (state<<8) | buf[i];
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
409 if(state == 0x1B6){
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
410 i++;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
411 vop_found=1;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
412 break;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
413 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
414 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
415 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
416
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
417 if(vop_found){
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
418 for(; i<buf_size; i++){
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
419 state= (state<<8) | buf[i];
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
420 if((state&0xFFFFFF00) == 0x100){
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
421 pc->frame_start_found=0;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
422 pc->state=-1;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
423 return i-3;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
424 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
425 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
426 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
427 pc->frame_start_found= vop_found;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
428 pc->state= state;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
429 return END_NOT_FOUND;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
430 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
431
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
432 /* used by parser */
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
433 /* XXX: make it use less memory */
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
434 static int av_mpeg4_decode_header(AVCodecParserContext *s1,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
435 AVCodecContext *avctx,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
436 const uint8_t *buf, int buf_size)
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
437 {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
438 ParseContext1 *pc = s1->priv_data;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
439 MpegEncContext *s = pc->enc;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
440 GetBitContext gb1, *gb = &gb1;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
441 int ret;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
442
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
443 s->avctx = avctx;
1614
6c82ef97d3e6 also parse extradata for MPEG4
bellard
parents: 1613
diff changeset
444 s->current_picture_ptr = &s->current_picture;
6c82ef97d3e6 also parse extradata for MPEG4
bellard
parents: 1613
diff changeset
445
6c82ef97d3e6 also parse extradata for MPEG4
bellard
parents: 1613
diff changeset
446 if (avctx->extradata_size && pc->first_picture){
6c82ef97d3e6 also parse extradata for MPEG4
bellard
parents: 1613
diff changeset
447 init_get_bits(gb, avctx->extradata, avctx->extradata_size*8);
6c82ef97d3e6 also parse extradata for MPEG4
bellard
parents: 1613
diff changeset
448 ret = ff_mpeg4_decode_picture_header(s, gb);
6c82ef97d3e6 also parse extradata for MPEG4
bellard
parents: 1613
diff changeset
449 }
6c82ef97d3e6 also parse extradata for MPEG4
bellard
parents: 1613
diff changeset
450
1613
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
451 init_get_bits(gb, buf, 8 * buf_size);
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
452 ret = ff_mpeg4_decode_picture_header(s, gb);
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
453 if (s->width) {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
454 avctx->width = s->width;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
455 avctx->height = s->height;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
456 }
1614
6c82ef97d3e6 also parse extradata for MPEG4
bellard
parents: 1613
diff changeset
457 pc->first_picture = 0;
1613
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
458 return ret;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
459 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
460
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
461 int mpeg4video_parse_init(AVCodecParserContext *s)
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
462 {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
463 ParseContext1 *pc = s->priv_data;
1614
6c82ef97d3e6 also parse extradata for MPEG4
bellard
parents: 1613
diff changeset
464
1613
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
465 pc->enc = av_mallocz(sizeof(MpegEncContext));
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
466 if (!pc->enc)
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
467 return -1;
1614
6c82ef97d3e6 also parse extradata for MPEG4
bellard
parents: 1613
diff changeset
468 pc->first_picture = 1;
1613
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
469 return 0;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
470 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
471
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
472 static int mpeg4video_parse(AVCodecParserContext *s,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
473 AVCodecContext *avctx,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
474 uint8_t **poutbuf, int *poutbuf_size,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
475 const uint8_t *buf, int buf_size)
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
476 {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
477 ParseContext1 *pc = s->priv_data;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
478 int next;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
479
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
480 next= mpeg4_find_frame_end(pc, buf, buf_size);
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
481
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
482 if (ff_combine_frame1(pc, next, (uint8_t **)&buf, &buf_size) < 0) {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
483 *poutbuf = NULL;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
484 *poutbuf_size = 0;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
485 return buf_size;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
486 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
487 av_mpeg4_decode_header(s, avctx, buf, buf_size);
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
488
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
489 *poutbuf = (uint8_t *)buf;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
490 *poutbuf_size = buf_size;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
491 return next;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
492 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
493
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
494 /*************************/
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
495
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
496 static int h263_find_frame_end(ParseContext1 *pc, const uint8_t *buf, int buf_size)
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
497 {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
498 int vop_found, i;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
499 uint32_t state;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
500
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
501 vop_found= pc->frame_start_found;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
502 state= pc->state;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
503
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
504 i=0;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
505 if(!vop_found){
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
506 for(i=0; i<buf_size; i++){
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
507 state= (state<<8) | buf[i];
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
508 if(state>>(32-22) == 0x20){
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
509 i++;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
510 vop_found=1;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
511 break;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
512 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
513 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
514 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
515
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
516 if(vop_found){
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
517 for(; i<buf_size; i++){
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
518 state= (state<<8) | buf[i];
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
519 if(state>>(32-22) == 0x20){
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
520 pc->frame_start_found=0;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
521 pc->state=-1;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
522 return i-3;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
523 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
524 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
525 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
526 pc->frame_start_found= vop_found;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
527 pc->state= state;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
528
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
529 return END_NOT_FOUND;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
530 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
531
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
532 static int h263_parse(AVCodecParserContext *s,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
533 AVCodecContext *avctx,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
534 uint8_t **poutbuf, int *poutbuf_size,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
535 const uint8_t *buf, int buf_size)
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
536 {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
537 ParseContext1 *pc = s->priv_data;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
538 int next;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
539
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
540 next= h263_find_frame_end(pc, buf, buf_size);
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
541
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
542 if (ff_combine_frame1(pc, next, (uint8_t **)&buf, &buf_size) < 0) {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
543 *poutbuf = NULL;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
544 *poutbuf_size = 0;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
545 return buf_size;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
546 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
547
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
548 *poutbuf = (uint8_t *)buf;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
549 *poutbuf_size = buf_size;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
550 return next;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
551 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
552
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
553 /*************************/
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
554
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
555 /**
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
556 * finds the end of the current frame in the bitstream.
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
557 * @return the position of the first byte of the next frame, or -1
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
558 */
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
559 static int h264_find_frame_end(ParseContext1 *pc, const uint8_t *buf, int buf_size)
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
560 {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
561 int i;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
562 uint32_t state;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
563 //printf("first %02X%02X%02X%02X\n", buf[0], buf[1],buf[2],buf[3]);
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
564 // mb_addr= pc->mb_addr - 1;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
565 state= pc->state;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
566 //FIXME this will fail with slices
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
567 for(i=0; i<buf_size; i++){
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
568 state= (state<<8) | buf[i];
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
569 if((state&0xFFFFFF1F) == 0x101 || (state&0xFFFFFF1F) == 0x102 || (state&0xFFFFFF1F) == 0x105){
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
570 if(pc->frame_start_found){
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
571 pc->state=-1;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
572 pc->frame_start_found= 0;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
573 return i-3;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
574 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
575 pc->frame_start_found= 1;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
576 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
577 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
578
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
579 pc->state= state;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
580 return END_NOT_FOUND;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
581 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
582
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
583 static int h264_parse(AVCodecParserContext *s,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
584 AVCodecContext *avctx,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
585 uint8_t **poutbuf, int *poutbuf_size,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
586 const uint8_t *buf, int buf_size)
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
587 {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
588 ParseContext1 *pc = s->priv_data;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
589 int next;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
590
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
591 next= h264_find_frame_end(pc, buf, buf_size);
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
592
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
593 if (ff_combine_frame1(pc, next, (uint8_t **)&buf, &buf_size) < 0) {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
594 *poutbuf = NULL;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
595 *poutbuf_size = 0;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
596 return buf_size;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
597 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
598
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
599 *poutbuf = (uint8_t *)buf;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
600 *poutbuf_size = buf_size;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
601 return next;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
602 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
603
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
604 /*************************/
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
605
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
606 typedef struct MpegAudioParseContext {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
607 uint8_t inbuf[MPA_MAX_CODED_FRAME_SIZE]; /* input buffer */
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
608 uint8_t *inbuf_ptr;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
609 int frame_size;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
610 int free_format_frame_size;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
611 int free_format_next_header;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
612 } MpegAudioParseContext;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
613
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
614 #define MPA_HEADER_SIZE 4
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
615
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
616 /* header + layer + bitrate + freq + lsf/mpeg25 */
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
617 #define SAME_HEADER_MASK \
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
618 (0xffe00000 | (3 << 17) | (0xf << 12) | (3 << 10) | (3 << 19))
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
619
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
620 static int mpegaudio_parse_init(AVCodecParserContext *s1)
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
621 {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
622 MpegAudioParseContext *s = s1->priv_data;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
623 s->inbuf_ptr = s->inbuf;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
624 return 0;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
625 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
626
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
627 static int mpegaudio_parse(AVCodecParserContext *s1,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
628 AVCodecContext *avctx,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
629 uint8_t **poutbuf, int *poutbuf_size,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
630 const uint8_t *buf, int buf_size)
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
631 {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
632 MpegAudioParseContext *s = s1->priv_data;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
633 int len, ret;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
634 uint32_t header;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
635 const uint8_t *buf_ptr;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
636
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
637 *poutbuf = NULL;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
638 *poutbuf_size = 0;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
639 buf_ptr = buf;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
640 while (buf_size > 0) {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
641 len = s->inbuf_ptr - s->inbuf;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
642 if (s->frame_size == 0) {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
643 /* special case for next header for first frame in free
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
644 format case (XXX: find a simpler method) */
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
645 if (s->free_format_next_header != 0) {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
646 s->inbuf[0] = s->free_format_next_header >> 24;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
647 s->inbuf[1] = s->free_format_next_header >> 16;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
648 s->inbuf[2] = s->free_format_next_header >> 8;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
649 s->inbuf[3] = s->free_format_next_header;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
650 s->inbuf_ptr = s->inbuf + 4;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
651 s->free_format_next_header = 0;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
652 goto got_header;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
653 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
654 /* no header seen : find one. We need at least MPA_HEADER_SIZE
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
655 bytes to parse it */
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
656 len = MPA_HEADER_SIZE - len;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
657 if (len > buf_size)
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
658 len = buf_size;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
659 if (len > 0) {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
660 memcpy(s->inbuf_ptr, buf_ptr, len);
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
661 buf_ptr += len;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
662 buf_size -= len;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
663 s->inbuf_ptr += len;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
664 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
665 if ((s->inbuf_ptr - s->inbuf) >= MPA_HEADER_SIZE) {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
666 got_header:
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
667 header = (s->inbuf[0] << 24) | (s->inbuf[1] << 16) |
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
668 (s->inbuf[2] << 8) | s->inbuf[3];
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
669
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
670 ret = mpa_decode_header(avctx, header);
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
671 if (ret < 0) {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
672 /* no sync found : move by one byte (inefficient, but simple!) */
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
673 memmove(s->inbuf, s->inbuf + 1, s->inbuf_ptr - s->inbuf - 1);
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
674 s->inbuf_ptr--;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
675 dprintf("skip %x\n", header);
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
676 /* reset free format frame size to give a chance
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
677 to get a new bitrate */
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
678 s->free_format_frame_size = 0;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
679 } else {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
680 s->frame_size = ret;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
681 #if 0
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
682 /* free format: prepare to compute frame size */
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
683 if (decode_header(s, header) == 1) {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
684 s->frame_size = -1;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
685 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
686 #endif
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
687 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
688 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
689 } else
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
690 #if 0
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
691 if (s->frame_size == -1) {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
692 /* free format : find next sync to compute frame size */
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
693 len = MPA_MAX_CODED_FRAME_SIZE - len;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
694 if (len > buf_size)
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
695 len = buf_size;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
696 if (len == 0) {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
697 /* frame too long: resync */
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
698 s->frame_size = 0;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
699 memmove(s->inbuf, s->inbuf + 1, s->inbuf_ptr - s->inbuf - 1);
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
700 s->inbuf_ptr--;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
701 } else {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
702 uint8_t *p, *pend;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
703 uint32_t header1;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
704 int padding;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
705
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
706 memcpy(s->inbuf_ptr, buf_ptr, len);
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
707 /* check for header */
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
708 p = s->inbuf_ptr - 3;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
709 pend = s->inbuf_ptr + len - 4;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
710 while (p <= pend) {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
711 header = (p[0] << 24) | (p[1] << 16) |
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
712 (p[2] << 8) | p[3];
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
713 header1 = (s->inbuf[0] << 24) | (s->inbuf[1] << 16) |
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
714 (s->inbuf[2] << 8) | s->inbuf[3];
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
715 /* check with high probability that we have a
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
716 valid header */
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
717 if ((header & SAME_HEADER_MASK) ==
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
718 (header1 & SAME_HEADER_MASK)) {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
719 /* header found: update pointers */
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
720 len = (p + 4) - s->inbuf_ptr;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
721 buf_ptr += len;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
722 buf_size -= len;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
723 s->inbuf_ptr = p;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
724 /* compute frame size */
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
725 s->free_format_next_header = header;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
726 s->free_format_frame_size = s->inbuf_ptr - s->inbuf;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
727 padding = (header1 >> 9) & 1;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
728 if (s->layer == 1)
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
729 s->free_format_frame_size -= padding * 4;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
730 else
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
731 s->free_format_frame_size -= padding;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
732 dprintf("free frame size=%d padding=%d\n",
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
733 s->free_format_frame_size, padding);
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
734 decode_header(s, header1);
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
735 goto next_data;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
736 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
737 p++;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
738 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
739 /* not found: simply increase pointers */
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
740 buf_ptr += len;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
741 s->inbuf_ptr += len;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
742 buf_size -= len;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
743 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
744 } else
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
745 #endif
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
746 if (len < s->frame_size) {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
747 if (s->frame_size > MPA_MAX_CODED_FRAME_SIZE)
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
748 s->frame_size = MPA_MAX_CODED_FRAME_SIZE;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
749 len = s->frame_size - len;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
750 if (len > buf_size)
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
751 len = buf_size;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
752 memcpy(s->inbuf_ptr, buf_ptr, len);
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
753 buf_ptr += len;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
754 s->inbuf_ptr += len;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
755 buf_size -= len;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
756 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
757 // next_data:
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
758 if (s->frame_size > 0 &&
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
759 (s->inbuf_ptr - s->inbuf) >= s->frame_size) {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
760 *poutbuf = s->inbuf;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
761 *poutbuf_size = s->inbuf_ptr - s->inbuf;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
762 s->inbuf_ptr = s->inbuf;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
763 s->frame_size = 0;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
764 break;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
765 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
766 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
767 return buf_ptr - buf;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
768 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
769
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
770 #ifdef CONFIG_AC3
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
771 extern int a52_syncinfo (const uint8_t * buf, int * flags,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
772 int * sample_rate, int * bit_rate);
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
773
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
774 typedef struct AC3ParseContext {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
775 uint8_t inbuf[4096]; /* input buffer */
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
776 uint8_t *inbuf_ptr;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
777 int frame_size;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
778 int flags;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
779 } AC3ParseContext;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
780
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
781 #define AC3_HEADER_SIZE 7
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
782 #define A52_LFE 16
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
783
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
784 static int ac3_parse_init(AVCodecParserContext *s1)
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
785 {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
786 AC3ParseContext *s = s1->priv_data;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
787 s->inbuf_ptr = s->inbuf;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
788 return 0;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
789 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
790
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
791 static int ac3_parse(AVCodecParserContext *s1,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
792 AVCodecContext *avctx,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
793 uint8_t **poutbuf, int *poutbuf_size,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
794 const uint8_t *buf, int buf_size)
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
795 {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
796 AC3ParseContext *s = s1->priv_data;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
797 const uint8_t *buf_ptr;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
798 int len, sample_rate, bit_rate;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
799 static const int ac3_channels[8] = {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
800 2, 1, 2, 3, 3, 4, 4, 5
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
801 };
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
802
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
803 *poutbuf = NULL;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
804 *poutbuf_size = 0;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
805
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
806 buf_ptr = buf;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
807 while (buf_size > 0) {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
808 len = s->inbuf_ptr - s->inbuf;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
809 if (s->frame_size == 0) {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
810 /* no header seen : find one. We need at least 7 bytes to parse it */
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
811 len = AC3_HEADER_SIZE - len;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
812 if (len > buf_size)
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
813 len = buf_size;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
814 memcpy(s->inbuf_ptr, buf_ptr, len);
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
815 buf_ptr += len;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
816 s->inbuf_ptr += len;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
817 buf_size -= len;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
818 if ((s->inbuf_ptr - s->inbuf) == AC3_HEADER_SIZE) {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
819 len = a52_syncinfo(s->inbuf, &s->flags, &sample_rate, &bit_rate);
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
820 if (len == 0) {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
821 /* no sync found : move by one byte (inefficient, but simple!) */
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
822 memmove(s->inbuf, s->inbuf + 1, AC3_HEADER_SIZE - 1);
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
823 s->inbuf_ptr--;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
824 } else {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
825 s->frame_size = len;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
826 /* update codec info */
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
827 avctx->sample_rate = sample_rate;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
828 avctx->channels = ac3_channels[s->flags & 7];
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
829 if (s->flags & A52_LFE)
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
830 avctx->channels++;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
831 avctx->bit_rate = bit_rate;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
832 avctx->frame_size = 6 * 256;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
833 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
834 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
835 } else if (len < s->frame_size) {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
836 len = s->frame_size - len;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
837 if (len > buf_size)
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
838 len = buf_size;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
839
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
840 memcpy(s->inbuf_ptr, buf_ptr, len);
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
841 buf_ptr += len;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
842 s->inbuf_ptr += len;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
843 buf_size -= len;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
844 } else {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
845 *poutbuf = s->inbuf;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
846 *poutbuf_size = s->frame_size;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
847 s->inbuf_ptr = s->inbuf;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
848 s->frame_size = 0;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
849 break;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
850 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
851 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
852 return buf_ptr - buf;
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
853 }
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
854 #endif
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
855
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
856 AVCodecParser mpegvideo_parser = {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
857 { CODEC_ID_MPEG1VIDEO, CODEC_ID_MPEG2VIDEO },
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
858 sizeof(ParseContext1),
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
859 NULL,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
860 mpegvideo_parse,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
861 mpegvideo_parse_close,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
862 };
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
863
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
864 AVCodecParser mpeg4video_parser = {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
865 { CODEC_ID_MPEG4 },
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
866 sizeof(ParseContext1),
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
867 mpeg4video_parse_init,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
868 mpeg4video_parse,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
869 mpegvideo_parse_close,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
870 };
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
871
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
872 AVCodecParser h263_parser = {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
873 { CODEC_ID_H263 },
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
874 sizeof(ParseContext1),
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
875 NULL,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
876 h263_parse,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
877 mpegvideo_parse_close,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
878 };
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
879
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
880 AVCodecParser h264_parser = {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
881 { CODEC_ID_H264 },
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
882 sizeof(ParseContext1),
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
883 NULL,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
884 h264_parse,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
885 mpegvideo_parse_close,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
886 };
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
887
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
888 AVCodecParser mpegaudio_parser = {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
889 { CODEC_ID_MP2, CODEC_ID_MP3 },
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
890 sizeof(MpegAudioParseContext),
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
891 mpegaudio_parse_init,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
892 mpegaudio_parse,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
893 NULL,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
894 };
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
895
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
896 #ifdef CONFIG_AC3
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
897 AVCodecParser ac3_parser = {
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
898 { CODEC_ID_AC3 },
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
899 sizeof(AC3ParseContext),
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
900 ac3_parse_init,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
901 ac3_parse,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
902 NULL,
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
903 };
0279c6c61f11 new audio/video parser API
bellard
parents:
diff changeset
904 #endif