comparison parser.c @ 2769:1394b45a7bf4 libavcodec

support changing in bitstream global headers into extradata style and back
author michael
date Mon, 27 Jun 2005 00:04:03 +0000
parents ef44d24680d1
children 09108466b7d0
comparison
equal deleted inserted replaced
2768:d2b3f948599d 2769:1394b45a7bf4
140 index = 0; 140 index = 0;
141 s->cur_offset += index; 141 s->cur_offset += index;
142 return index; 142 return index;
143 } 143 }
144 144
145 int av_parser_change(AVCodecParserContext *s,
146 AVCodecContext *avctx,
147 uint8_t **poutbuf, int *poutbuf_size,
148 const uint8_t *buf, int buf_size, int keyframe){
149
150 if(s && s->parser->split){
151 if((avctx->flags & CODEC_FLAG_GLOBAL_HEADER) && !(avctx->flags2 & CODEC_FLAG2_LOCAL_HEADER)){
152 int i= s->parser->split(avctx, buf, buf_size);
153 buf += i;
154 buf_size -= i;
155 }
156 }
157
158 *poutbuf= buf;
159 *poutbuf_size= buf_size;
160 if(avctx->extradata){
161 if( (keyframe && (avctx->flags2 & CODEC_FLAG2_LOCAL_HEADER))
162 /*||(s->pict_type != I_TYPE && (s->flags & PARSER_FLAG_DUMP_EXTRADATA_AT_NOKEY))*/
163 /*||(? && (s->flags & PARSER_FLAG_DUMP_EXTRADATA_AT_BEGIN)*/){
164 int size= buf_size + avctx->extradata_size;
165 *poutbuf_size= size;
166 *poutbuf= av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);
167
168 memcpy(*poutbuf, avctx->extradata, avctx->extradata_size);
169 memcpy((*poutbuf) + avctx->extradata_size, buf, buf_size);
170 return 1;
171 }
172 }
173
174 return 0;
175 }
176
145 void av_parser_close(AVCodecParserContext *s) 177 void av_parser_close(AVCodecParserContext *s)
146 { 178 {
147 if (s->parser->parser_close) 179 if (s->parser->parser_close)
148 s->parser->parser_close(s); 180 s->parser->parser_close(s);
149 av_free(s->priv_data); 181 av_free(s->priv_data);
292 int32_t start_code; 324 int32_t start_code;
293 int frame_rate_index, ext_type, bytes_left; 325 int frame_rate_index, ext_type, bytes_left;
294 int frame_rate_ext_n, frame_rate_ext_d; 326 int frame_rate_ext_n, frame_rate_ext_d;
295 int picture_structure, top_field_first, repeat_first_field, progressive_frame; 327 int picture_structure, top_field_first, repeat_first_field, progressive_frame;
296 int horiz_size_ext, vert_size_ext, bit_rate_ext; 328 int horiz_size_ext, vert_size_ext, bit_rate_ext;
297 329 //FIXME replace the crap with get_bits()
298 s->repeat_pict = 0; 330 s->repeat_pict = 0;
299 buf_end = buf + buf_size; 331 buf_end = buf + buf_size;
300 while (buf < buf_end) { 332 while (buf < buf_end) {
301 start_code = find_start_code(&buf, buf_end); 333 start_code = find_start_code(&buf, buf_end);
302 bytes_left = buf_end - buf; 334 bytes_left = buf_end - buf;
413 *poutbuf = (uint8_t *)buf; 445 *poutbuf = (uint8_t *)buf;
414 *poutbuf_size = buf_size; 446 *poutbuf_size = buf_size;
415 return next; 447 return next;
416 } 448 }
417 449
450 static int mpegvideo_split(AVCodecContext *avctx,
451 const uint8_t *buf, int buf_size)
452 {
453 int i;
454 uint32_t state= -1;
455
456 for(i=0; i<buf_size; i++){
457 state= (state<<8) | buf[i];
458 if(state != 0x1B3 && state != 0x1B5 && state < 0x200 && state >= 0x100)
459 return i-4;
460 }
461 return 0;
462 }
463
418 void ff_parse_close(AVCodecParserContext *s) 464 void ff_parse_close(AVCodecParserContext *s)
419 { 465 {
420 ParseContext *pc = s->priv_data; 466 ParseContext *pc = s->priv_data;
421 467
422 av_free(pc->buffer); 468 av_free(pc->buffer);
489 av_mpeg4_decode_header(s, avctx, buf, buf_size); 535 av_mpeg4_decode_header(s, avctx, buf, buf_size);
490 536
491 *poutbuf = (uint8_t *)buf; 537 *poutbuf = (uint8_t *)buf;
492 *poutbuf_size = buf_size; 538 *poutbuf_size = buf_size;
493 return next; 539 return next;
540 }
541
542 static int mpeg4video_split(AVCodecContext *avctx,
543 const uint8_t *buf, int buf_size)
544 {
545 int i;
546 uint32_t state= -1;
547
548 for(i=0; i<buf_size; i++){
549 state= (state<<8) | buf[i];
550 if(state == 0x1B3 || state == 0x1B6)
551 return i-4;
552 }
553 return 0;
494 } 554 }
495 555
496 /*************************/ 556 /*************************/
497 557
498 typedef struct MpegAudioParseContext { 558 typedef struct MpegAudioParseContext {
766 { CODEC_ID_MPEG1VIDEO, CODEC_ID_MPEG2VIDEO }, 826 { CODEC_ID_MPEG1VIDEO, CODEC_ID_MPEG2VIDEO },
767 sizeof(ParseContext1), 827 sizeof(ParseContext1),
768 NULL, 828 NULL,
769 mpegvideo_parse, 829 mpegvideo_parse,
770 parse1_close, 830 parse1_close,
831 mpegvideo_split,
771 }; 832 };
772 833
773 AVCodecParser mpeg4video_parser = { 834 AVCodecParser mpeg4video_parser = {
774 { CODEC_ID_MPEG4 }, 835 { CODEC_ID_MPEG4 },
775 sizeof(ParseContext1), 836 sizeof(ParseContext1),
776 mpeg4video_parse_init, 837 mpeg4video_parse_init,
777 mpeg4video_parse, 838 mpeg4video_parse,
778 parse1_close, 839 parse1_close,
840 mpeg4video_split,
779 }; 841 };
780 842
781 AVCodecParser mpegaudio_parser = { 843 AVCodecParser mpegaudio_parser = {
782 { CODEC_ID_MP2, CODEC_ID_MP3 }, 844 { CODEC_ID_MP2, CODEC_ID_MP3 },
783 sizeof(MpegAudioParseContext), 845 sizeof(MpegAudioParseContext),