Revision c5a60225 libavcodec/cavs.c

View differences:

libavcodec/cavs.c
30 30
#include "golomb.h"
31 31
#include "mpegvideo.h"
32 32
#include "cavs.h"
33
#ifdef CONFIG_CAVS_DECODER
34 33
#include "cavsdata.h"
35 34

  
36 35
typedef struct {
......
1458 1457
    CODEC_CAP_DR1 | CODEC_CAP_DELAY,
1459 1458
    .flush= cavs_flush,
1460 1459
};
1461
#endif /* CONFIG_CAVS_DECODER */
1462

  
1463
#ifdef CONFIG_CAVSVIDEO_PARSER
1464
/**
1465
 * finds the end of the current frame in the bitstream.
1466
 * @return the position of the first byte of the next frame, or -1
1467
 */
1468
static int cavs_find_frame_end(ParseContext *pc, const uint8_t *buf,
1469
                               int buf_size) {
1470
    int pic_found, i;
1471
    uint32_t state;
1472

  
1473
    pic_found= pc->frame_start_found;
1474
    state= pc->state;
1475

  
1476
    i=0;
1477
    if(!pic_found){
1478
        for(i=0; i<buf_size; i++){
1479
            state= (state<<8) | buf[i];
1480
            if(state == PIC_I_START_CODE || state == PIC_PB_START_CODE){
1481
                i++;
1482
                pic_found=1;
1483
                break;
1484
            }
1485
        }
1486
    }
1487

  
1488
    if(pic_found){
1489
        /* EOF considered as end of frame */
1490
        if (buf_size == 0)
1491
            return 0;
1492
        for(; i<buf_size; i++){
1493
            state= (state<<8) | buf[i];
1494
            if((state&0xFFFFFF00) == 0x100){
1495
                if(state < SLICE_MIN_START_CODE || state > SLICE_MAX_START_CODE){
1496
                    pc->frame_start_found=0;
1497
                    pc->state=-1;
1498
                    return i-3;
1499
                }
1500
            }
1501
        }
1502
    }
1503
    pc->frame_start_found= pic_found;
1504
    pc->state= state;
1505
    return END_NOT_FOUND;
1506
}
1507

  
1508
static int cavsvideo_parse(AVCodecParserContext *s,
1509
                           AVCodecContext *avctx,
1510
                           const uint8_t **poutbuf, int *poutbuf_size,
1511
                           const uint8_t *buf, int buf_size)
1512
{
1513
    ParseContext *pc = s->priv_data;
1514
    int next;
1515

  
1516
    if(s->flags & PARSER_FLAG_COMPLETE_FRAMES){
1517
        next= buf_size;
1518
    }else{
1519
        next= cavs_find_frame_end(pc, buf, buf_size);
1520

  
1521
        if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) {
1522
            *poutbuf = NULL;
1523
            *poutbuf_size = 0;
1524
            return buf_size;
1525
        }
1526
    }
1527
    *poutbuf = buf;
1528
    *poutbuf_size = buf_size;
1529
    return next;
1530
}
1531

  
1532
AVCodecParser cavsvideo_parser = {
1533
    { CODEC_ID_CAVS },
1534
    sizeof(ParseContext1),
1535
    NULL,
1536
    cavsvideo_parse,
1537
    ff_parse1_close,
1538
    ff_mpeg4video_split,
1539
};
1540
#endif /* CONFIG_CAVSVIDEO_PARSER */

Also available in: Unified diff