Revision e4cb187d libavcodec/h263dec.c

View differences:

libavcodec/h263dec.c
306 306
 * finds the end of the current frame in the bitstream.
307 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){
310
    ParseContext *pc= &s->parse_context;
309
int ff_mpeg4_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size){
311 310
    int vop_found, i;
312 311
    uint32_t state;
313 312
    
......
326 325
        }
327 326
    }
328 327

  
329
    if(vop_found){    
330
      for(; i<buf_size; i++){
331
        state= (state<<8) | buf[i];
332
        if((state&0xFFFFFF00) == 0x100){
333
            pc->frame_start_found=0;
334
            pc->state=-1; 
335
            return i-3;
328
    if(vop_found){
329
        /* EOF considered as end of frame */
330
        if (buf_size == 0)
331
            return 0;
332
        for(; i<buf_size; i++){
333
            state= (state<<8) | buf[i];
334
            if((state&0xFFFFFF00) == 0x100){
335
                pc->frame_start_found=0;
336
                pc->state=-1; 
337
                return i-3;
338
            }
336 339
        }
337
      }
338 340
    }
339 341
    pc->frame_start_found= vop_found;
340 342
    pc->state= state;
341 343
    return END_NOT_FOUND;
342 344
}
343 345

  
344
static int h263_find_frame_end(MpegEncContext *s, uint8_t *buf, int buf_size){
345
    ParseContext *pc= &s->parse_context;
346
static int h263_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size){
346 347
    int vop_found, i;
347 348
    uint32_t state;
348 349
    
......
377 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 402
int ff_h263_decode_frame(AVCodecContext *avctx, 
381 403
                             void *data, int *data_size,
382 404
                             uint8_t *buf, int buf_size)
......
414 436
        int next;
415 437
        
416 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 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 442
        }else{
421 443
            av_log(s->avctx, AV_LOG_ERROR, "this codec doesnt support truncated bitstreams\n");
422 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 448
            return buf_size;
427 449
    }
428 450

  
......
843 865
    ff_h263_decode_frame,
844 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
};

Also available in: Unified diff