Revision b84f2a35 libavcodec/parser.c

View differences:

libavcodec/parser.c
68 68
int av_parser_parse(AVCodecParserContext *s, 
69 69
                    AVCodecContext *avctx,
70 70
                    uint8_t **poutbuf, int *poutbuf_size, 
71
                    const uint8_t *buf, int buf_size)
71
                    const uint8_t *buf, int buf_size,
72
                    int64_t pts, int64_t dts)
72 73
{
73
    int index;
74
    int index, i, k;
74 75
    uint8_t dummy_buf[FF_INPUT_BUFFER_PADDING_SIZE];
75 76
    
76 77
    if (buf_size == 0) {
77 78
        /* padding is always necessary even if EOF, so we add it here */
78 79
        memset(dummy_buf, 0, sizeof(dummy_buf));
79 80
        buf = dummy_buf;
81
    } else {
82
        /* add a new packet descriptor */
83
        k = (s->cur_frame_start_index + 1) & (AV_PARSER_PTS_NB - 1);
84
        s->cur_frame_start_index = k;
85
        s->cur_frame_offset[k] = s->cur_offset;
86
        s->cur_frame_pts[k] = pts;
87
        s->cur_frame_dts[k] = dts;
88

  
89
        /* fill first PTS/DTS */
90
        if (s->cur_offset == 0) {
91
            s->last_pts = pts;
92
            s->last_dts = dts;
93
        }
80 94
    }
81 95

  
82 96
    /* WARNING: the returned index can be negative */
83 97
    index = s->parser->parser_parse(s, avctx, poutbuf, poutbuf_size, buf, buf_size);
84 98
    /* update the file pointer */
85 99
    if (*poutbuf_size) {
100
        /* fill the data for the current frame */
86 101
        s->frame_offset = s->last_frame_offset;
102
        s->pts = s->last_pts;
103
        s->dts = s->last_dts;
104
        
105
        /* offset of the next frame */
87 106
        s->last_frame_offset = s->cur_offset + index;
107
        /* find the packet in which the new frame starts. It
108
           is tricky because of MPEG video start codes
109
           which can begin in one packet and finish in
110
           another packet. In the worst case, an MPEG
111
           video start code could be in 4 different
112
           packets. */
113
        k = s->cur_frame_start_index;
114
        for(i = 0; i < AV_PARSER_PTS_NB; i++) {
115
            if (s->last_frame_offset >= s->cur_frame_offset[k])
116
                break;
117
            k = (k - 1) & (AV_PARSER_PTS_NB - 1);
118
        }
119
        s->last_pts = s->cur_frame_pts[k];
120
        s->last_dts = s->cur_frame_dts[k];
88 121
    }
89 122
    if (index < 0)
90 123
        index = 0;

Also available in: Unified diff