Revision c33d9814 libavcodec/h263dec.c

View differences:

libavcodec/h263dec.c
28 28
#include "avcodec.h"
29 29
#include "dsputil.h"
30 30
#include "mpegvideo.h"
31
#include "h263_parser.h"
31 32

  
32 33
//#define DEBUG
33 34
//#define PRINT_FRAME_TIME
......
358 359
    return END_NOT_FOUND;
359 360
}
360 361

  
361
static int h263_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size){
362
    int vop_found, i;
363
    uint32_t state;
364

  
365
    vop_found= pc->frame_start_found;
366
    state= pc->state;
367

  
368
    i=0;
369
    if(!vop_found){
370
        for(i=0; i<buf_size; i++){
371
            state= (state<<8) | buf[i];
372
            if(state>>(32-22) == 0x20){
373
                i++;
374
                vop_found=1;
375
                break;
376
            }
377
        }
378
    }
379

  
380
    if(vop_found){
381
      for(; i<buf_size; i++){
382
        state= (state<<8) | buf[i];
383
        if(state>>(32-22) == 0x20){
384
            pc->frame_start_found=0;
385
            pc->state=-1;
386
            return i-3;
387
        }
388
      }
389
    }
390
    pc->frame_start_found= vop_found;
391
    pc->state= state;
392

  
393
    return END_NOT_FOUND;
394
}
395

  
396
#ifdef CONFIG_H263_PARSER
397
static int h263_parse(AVCodecParserContext *s,
398
                           AVCodecContext *avctx,
399
                           const uint8_t **poutbuf, int *poutbuf_size,
400
                           const uint8_t *buf, int buf_size)
401
{
402
    ParseContext *pc = s->priv_data;
403
    int next;
404

  
405
    next= h263_find_frame_end(pc, buf, buf_size);
406

  
407
    if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) {
408
        *poutbuf = NULL;
409
        *poutbuf_size = 0;
410
        return buf_size;
411
    }
412

  
413
    *poutbuf = buf;
414
    *poutbuf_size = buf_size;
415
    return next;
416
}
417
#endif
418

  
419 362
int ff_h263_decode_frame(AVCodecContext *avctx,
420 363
                             void *data, int *data_size,
421 364
                             uint8_t *buf, int buf_size)
......
454 397
        if(s->codec_id==CODEC_ID_MPEG4){
455 398
            next= ff_mpeg4_find_frame_end(&s->parse_context, buf, buf_size);
456 399
        }else if(s->codec_id==CODEC_ID_H263){
457
            next= h263_find_frame_end(&s->parse_context, buf, buf_size);
400
            next= ff_h263_find_frame_end(&s->parse_context, buf, buf_size);
458 401
        }else{
459 402
            av_log(s->avctx, AV_LOG_ERROR, "this codec does not support truncated bitstreams\n");
460 403
            return -1;
......
902 845
    ff_h263_decode_frame,
903 846
    CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1
904 847
};
905

  
906
#ifdef CONFIG_H263_PARSER
907
AVCodecParser h263_parser = {
908
    { CODEC_ID_H263 },
909
    sizeof(ParseContext),
910
    NULL,
911
    h263_parse,
912
    ff_parse_close,
913
};
914
#endif

Also available in: Unified diff