Mercurial > libavcodec.hg
comparison h263dec.c @ 842:e460775adb38 libavcodec
cleanup (breaks compatibility, requested by fabrice)
remove CODEC_FLAG_NOT_TRUNCATED & add CODEC_FLAG_TRUNCATED
add CODEC_CAP_TRUNCATED
add alpha plane to AVPicture
remove CODEC_ID_MSMPEG4
remove various unused stuff
support "truncated" mpeg4 streams
author | michaelni |
---|---|
date | Fri, 08 Nov 2002 18:35:39 +0000 |
parents | 14f4598ec793 |
children | 32de034be20e |
comparison
equal
deleted
inserted
replaced
841:4033915880d9 | 842:e460775adb38 |
---|---|
123 /** | 123 /** |
124 * retunrs the number of bytes consumed for building the current frame | 124 * retunrs the number of bytes consumed for building the current frame |
125 */ | 125 */ |
126 static int get_consumed_bytes(MpegEncContext *s, int buf_size){ | 126 static int get_consumed_bytes(MpegEncContext *s, int buf_size){ |
127 int pos= (get_bits_count(&s->gb)+7)>>3; | 127 int pos= (get_bits_count(&s->gb)+7)>>3; |
128 | |
128 if(s->divx_version>=500){ | 129 if(s->divx_version>=500){ |
129 //we would have to scan through the whole buf to handle the weird reordering ... | 130 //we would have to scan through the whole buf to handle the weird reordering ... |
130 return buf_size; | 131 return buf_size; |
132 }else if(s->flags&CODEC_FLAG_TRUNCATED){ | |
133 pos -= s->parse_context.last_index; | |
134 if(pos<0) pos=0; // padding is not really read so this might be -1 | |
135 return pos; | |
131 }else{ | 136 }else{ |
132 if(pos==0) pos=1; //avoid infinite loops (i doubt thats needed but ...) | 137 if(pos==0) pos=1; //avoid infinite loops (i doubt thats needed but ...) |
133 if(pos+10>buf_size) pos=buf_size; // oops ;) | 138 if(pos+10>buf_size) pos=buf_size; // oops ;) |
134 | 139 |
135 return pos; | 140 return pos; |
297 s->gb.size*8 - get_bits_count(&s->gb), | 302 s->gb.size*8 - get_bits_count(&s->gb), |
298 show_bits(&s->gb, 24)); | 303 show_bits(&s->gb, 24)); |
299 return -1; | 304 return -1; |
300 } | 305 } |
301 | 306 |
307 /** | |
308 * finds the end of the current frame in the bitstream. | |
309 * @return the position of the first byte of the next frame, or -1 | |
310 */ | |
311 static int mpeg4_find_frame_end(MpegEncContext *s, UINT8 *buf, int buf_size){ | |
312 ParseContext *pc= &s->parse_context; | |
313 int vop_found, i; | |
314 uint32_t state; | |
315 | |
316 vop_found= pc->frame_start_found; | |
317 state= pc->state; | |
318 | |
319 i=0; | |
320 if(!vop_found){ | |
321 for(i=0; i<buf_size; i++){ | |
322 state= (state<<8) | buf[i]; | |
323 if(state == 0x1B6){ | |
324 i++; | |
325 vop_found=1; | |
326 break; | |
327 } | |
328 } | |
329 } | |
330 | |
331 for(; i<buf_size; i++){ | |
332 state= (state<<8) | buf[i]; | |
333 if((state&0xFFFFFF00) == 0x100){ | |
334 pc->frame_start_found=0; | |
335 pc->state=-1; | |
336 return i-3; | |
337 } | |
338 } | |
339 pc->frame_start_found= vop_found; | |
340 pc->state= state; | |
341 return -1; | |
342 } | |
343 | |
302 static int h263_decode_frame(AVCodecContext *avctx, | 344 static int h263_decode_frame(AVCodecContext *avctx, |
303 void *data, int *data_size, | 345 void *data, int *data_size, |
304 UINT8 *buf, int buf_size) | 346 UINT8 *buf, int buf_size) |
305 { | 347 { |
306 MpegEncContext *s = avctx->priv_data; | 348 MpegEncContext *s = avctx->priv_data; |
322 *data_size = 0; | 364 *data_size = 0; |
323 | 365 |
324 /* no supplementary picture */ | 366 /* no supplementary picture */ |
325 if (buf_size == 0) { | 367 if (buf_size == 0) { |
326 return 0; | 368 return 0; |
369 } | |
370 | |
371 if(s->flags&CODEC_FLAG_TRUNCATED){ | |
372 int next; | |
373 ParseContext *pc= &s->parse_context; | |
374 | |
375 pc->last_index= pc->index; | |
376 | |
377 if(s->codec_id==CODEC_ID_MPEG4){ | |
378 next= mpeg4_find_frame_end(s, buf, buf_size); | |
379 }else{ | |
380 fprintf(stderr, "this codec doesnt support truncated bitstreams\n"); | |
381 return -1; | |
382 } | |
383 if(next==-1){ | |
384 if(buf_size + FF_INPUT_BUFFER_PADDING_SIZE + pc->index > pc->buffer_size){ | |
385 pc->buffer_size= buf_size + pc->index + 10*1024; | |
386 pc->buffer= realloc(pc->buffer, pc->buffer_size); | |
387 } | |
388 | |
389 memcpy(&pc->buffer[pc->index], buf, buf_size); | |
390 pc->index += buf_size; | |
391 return buf_size; | |
392 } | |
393 | |
394 if(pc->index){ | |
395 if(next + FF_INPUT_BUFFER_PADDING_SIZE + pc->index > pc->buffer_size){ | |
396 pc->buffer_size= next + pc->index + 10*1024; | |
397 pc->buffer= realloc(pc->buffer, pc->buffer_size); | |
398 } | |
399 | |
400 memcpy(&pc->buffer[pc->index], buf, next + FF_INPUT_BUFFER_PADDING_SIZE ); | |
401 pc->index = 0; | |
402 buf= pc->buffer; | |
403 buf_size= pc->last_index + next; | |
404 } | |
327 } | 405 } |
328 | 406 |
329 retry: | 407 retry: |
330 | 408 |
331 if(s->bitstream_buffer_size && buf_size<20){ //divx 5.01+ frame reorder | 409 if(s->bitstream_buffer_size && buf_size<20){ //divx 5.01+ frame reorder |
625 sizeof(MpegEncContext), | 703 sizeof(MpegEncContext), |
626 h263_decode_init, | 704 h263_decode_init, |
627 NULL, | 705 NULL, |
628 h263_decode_end, | 706 h263_decode_end, |
629 h263_decode_frame, | 707 h263_decode_frame, |
630 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1, | 708 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED, |
631 }; | 709 }; |
632 | 710 |
633 AVCodec h263_decoder = { | 711 AVCodec h263_decoder = { |
634 "h263", | 712 "h263", |
635 CODEC_TYPE_VIDEO, | 713 CODEC_TYPE_VIDEO, |