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