comparison parser.c @ 1696:f5af91b8be17 libavcodec

pts and dts support in parser API
author bellard
date Tue, 16 Dec 2003 11:17:06 +0000
parents 13169235c306
children d9e067853051
comparison
equal deleted inserted replaced
1695:2d11403fde4e 1696:f5af91b8be17
66 /* NOTE: buf_size == 0 is used to signal EOF so that the last frame 66 /* NOTE: buf_size == 0 is used to signal EOF so that the last frame
67 can be returned if necessary */ 67 can be returned if necessary */
68 int av_parser_parse(AVCodecParserContext *s, 68 int av_parser_parse(AVCodecParserContext *s,
69 AVCodecContext *avctx, 69 AVCodecContext *avctx,
70 uint8_t **poutbuf, int *poutbuf_size, 70 uint8_t **poutbuf, int *poutbuf_size,
71 const uint8_t *buf, int buf_size) 71 const uint8_t *buf, int buf_size,
72 { 72 int64_t pts, int64_t dts)
73 int index; 73 {
74 int index, i, k;
74 uint8_t dummy_buf[FF_INPUT_BUFFER_PADDING_SIZE]; 75 uint8_t dummy_buf[FF_INPUT_BUFFER_PADDING_SIZE];
75 76
76 if (buf_size == 0) { 77 if (buf_size == 0) {
77 /* padding is always necessary even if EOF, so we add it here */ 78 /* padding is always necessary even if EOF, so we add it here */
78 memset(dummy_buf, 0, sizeof(dummy_buf)); 79 memset(dummy_buf, 0, sizeof(dummy_buf));
79 buf = dummy_buf; 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 /* WARNING: the returned index can be negative */ 96 /* WARNING: the returned index can be negative */
83 index = s->parser->parser_parse(s, avctx, poutbuf, poutbuf_size, buf, buf_size); 97 index = s->parser->parser_parse(s, avctx, poutbuf, poutbuf_size, buf, buf_size);
84 /* update the file pointer */ 98 /* update the file pointer */
85 if (*poutbuf_size) { 99 if (*poutbuf_size) {
100 /* fill the data for the current frame */
86 s->frame_offset = s->last_frame_offset; 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 s->last_frame_offset = s->cur_offset + index; 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 if (index < 0) 122 if (index < 0)
90 index = 0; 123 index = 0;
91 s->cur_offset += index; 124 s->cur_offset += index;
92 return index; 125 return index;