comparison h263dec.c @ 1988:b5753525f9a8 libavcodec

remove duplicated find_frame_end() code move codec specific code from parser.c -> <codecname>.c as far as its easily possible
author michael
date Thu, 29 Apr 2004 14:21:33 +0000
parents 71fe2180024c
children ec6bfd8d92fc
comparison
equal deleted inserted replaced
1987:d9e067853051 1988:b5753525f9a8
304 304
305 /** 305 /**
306 * finds the end of the current frame in the bitstream. 306 * finds the end of the current frame in the bitstream.
307 * @return the position of the first byte of the next frame, or -1 307 * @return the position of the first byte of the next frame, or -1
308 */ 308 */
309 static int mpeg4_find_frame_end(MpegEncContext *s, uint8_t *buf, int buf_size){ 309 int ff_mpeg4_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size){
310 ParseContext *pc= &s->parse_context;
311 int vop_found, i; 310 int vop_found, i;
312 uint32_t state; 311 uint32_t state;
313 312
314 vop_found= pc->frame_start_found; 313 vop_found= pc->frame_start_found;
315 state= pc->state; 314 state= pc->state;
324 break; 323 break;
325 } 324 }
326 } 325 }
327 } 326 }
328 327
329 if(vop_found){ 328 if(vop_found){
330 for(; i<buf_size; i++){ 329 /* EOF considered as end of frame */
331 state= (state<<8) | buf[i]; 330 if (buf_size == 0)
332 if((state&0xFFFFFF00) == 0x100){ 331 return 0;
333 pc->frame_start_found=0; 332 for(; i<buf_size; i++){
334 pc->state=-1; 333 state= (state<<8) | buf[i];
335 return i-3; 334 if((state&0xFFFFFF00) == 0x100){
336 } 335 pc->frame_start_found=0;
337 } 336 pc->state=-1;
337 return i-3;
338 }
339 }
338 } 340 }
339 pc->frame_start_found= vop_found; 341 pc->frame_start_found= vop_found;
340 pc->state= state; 342 pc->state= state;
341 return END_NOT_FOUND; 343 return END_NOT_FOUND;
342 } 344 }
343 345
344 static int h263_find_frame_end(MpegEncContext *s, uint8_t *buf, int buf_size){ 346 static int h263_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size){
345 ParseContext *pc= &s->parse_context;
346 int vop_found, i; 347 int vop_found, i;
347 uint32_t state; 348 uint32_t state;
348 349
349 vop_found= pc->frame_start_found; 350 vop_found= pc->frame_start_found;
350 state= pc->state; 351 state= pc->state;
375 pc->state= state; 376 pc->state= state;
376 377
377 return END_NOT_FOUND; 378 return END_NOT_FOUND;
378 } 379 }
379 380
381 static int h263_parse(AVCodecParserContext *s,
382 AVCodecContext *avctx,
383 uint8_t **poutbuf, int *poutbuf_size,
384 const uint8_t *buf, int buf_size)
385 {
386 ParseContext *pc = s->priv_data;
387 int next;
388
389 next= h263_find_frame_end(pc, buf, buf_size);
390
391 if (ff_combine_frame(pc, next, (uint8_t **)&buf, &buf_size) < 0) {
392 *poutbuf = NULL;
393 *poutbuf_size = 0;
394 return buf_size;
395 }
396
397 *poutbuf = (uint8_t *)buf;
398 *poutbuf_size = buf_size;
399 return next;
400 }
401
380 int ff_h263_decode_frame(AVCodecContext *avctx, 402 int ff_h263_decode_frame(AVCodecContext *avctx,
381 void *data, int *data_size, 403 void *data, int *data_size,
382 uint8_t *buf, int buf_size) 404 uint8_t *buf, int buf_size)
383 { 405 {
384 MpegEncContext *s = avctx->priv_data; 406 MpegEncContext *s = avctx->priv_data;
412 434
413 if(s->flags&CODEC_FLAG_TRUNCATED){ 435 if(s->flags&CODEC_FLAG_TRUNCATED){
414 int next; 436 int next;
415 437
416 if(s->codec_id==CODEC_ID_MPEG4){ 438 if(s->codec_id==CODEC_ID_MPEG4){
417 next= mpeg4_find_frame_end(s, buf, buf_size); 439 next= ff_mpeg4_find_frame_end(&s->parse_context, buf, buf_size);
418 }else if(s->codec_id==CODEC_ID_H263){ 440 }else if(s->codec_id==CODEC_ID_H263){
419 next= h263_find_frame_end(s, buf, buf_size); 441 next= h263_find_frame_end(&s->parse_context, buf, buf_size);
420 }else{ 442 }else{
421 av_log(s->avctx, AV_LOG_ERROR, "this codec doesnt support truncated bitstreams\n"); 443 av_log(s->avctx, AV_LOG_ERROR, "this codec doesnt support truncated bitstreams\n");
422 return -1; 444 return -1;
423 } 445 }
424 446
425 if( ff_combine_frame(s, next, &buf, &buf_size) < 0 ) 447 if( ff_combine_frame(&s->parse_context, next, &buf, &buf_size) < 0 )
426 return buf_size; 448 return buf_size;
427 } 449 }
428 450
429 451
430 retry: 452 retry:
841 NULL, 863 NULL,
842 ff_h263_decode_end, 864 ff_h263_decode_end,
843 ff_h263_decode_frame, 865 ff_h263_decode_frame,
844 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 866 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1
845 }; 867 };
868
869 AVCodecParser h263_parser = {
870 { CODEC_ID_H263 },
871 sizeof(ParseContext),
872 NULL,
873 h263_parse,
874 ff_parse_close,
875 };