Revision b84f2a35

View differences:

libavcodec/avcodec.h
17 17

  
18 18
#define FFMPEG_VERSION_INT     0x000408
19 19
#define FFMPEG_VERSION         "0.4.8"
20
#define LIBAVCODEC_BUILD       4696
20
#define LIBAVCODEC_BUILD       4697
21 21

  
22 22
#define LIBAVCODEC_VERSION_INT FFMPEG_VERSION_INT
23 23
#define LIBAVCODEC_VERSION     FFMPEG_VERSION
......
1932 1932
    /* video info */
1933 1933
    int pict_type; /* XXX: put it back in AVCodecContext */
1934 1934
    int repeat_pict; /* XXX: put it back in AVCodecContext */
1935
    int64_t pts;     /* in us, if given by the codec (used by raw mpeg4) */
1936
    int64_t dts;     /* in us, if given by the codec (used by raw mpeg4) */
1935
    int64_t pts;     /* pts of the current frame */
1936
    int64_t dts;     /* dts of the current frame */
1937

  
1938
    /* private data */
1939
    int64_t last_pts;
1940
    int64_t last_dts;
1941

  
1942
#define AV_PARSER_PTS_NB 4
1943
    int cur_frame_start_index;
1944
    int64_t cur_frame_offset[AV_PARSER_PTS_NB];
1945
    int64_t cur_frame_pts[AV_PARSER_PTS_NB];
1946
    int64_t cur_frame_dts[AV_PARSER_PTS_NB];
1937 1947
} AVCodecParserContext;
1938 1948

  
1939 1949
typedef struct AVCodecParser {
......
1955 1965
int av_parser_parse(AVCodecParserContext *s, 
1956 1966
                    AVCodecContext *avctx,
1957 1967
                    uint8_t **poutbuf, int *poutbuf_size, 
1958
                    const uint8_t *buf, int buf_size);
1968
                    const uint8_t *buf, int buf_size,
1969
                    int64_t pts, int64_t dts);
1959 1970
void av_parser_close(AVCodecParserContext *s);
1960 1971

  
1961 1972
extern AVCodecParser mpegvideo_parser;
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