Mercurial > libavcodec.hg
comparison parser.c @ 6977:de032bcdeff9 libavcodec
Simplify parser core.
author | michael |
---|---|
date | Mon, 02 Jun 2008 02:55:30 +0000 |
parents | ef70c05f77e8 |
children | 4257fdcf664e |
comparison
equal
deleted
inserted
replaced
6976:4e96557381d9 | 6977:de032bcdeff9 |
---|---|
116 } else { | 116 } else { |
117 /* add a new packet descriptor */ | 117 /* add a new packet descriptor */ |
118 k = (s->cur_frame_start_index + 1) & (AV_PARSER_PTS_NB - 1); | 118 k = (s->cur_frame_start_index + 1) & (AV_PARSER_PTS_NB - 1); |
119 s->cur_frame_start_index = k; | 119 s->cur_frame_start_index = k; |
120 s->cur_frame_offset[k] = s->cur_offset; | 120 s->cur_frame_offset[k] = s->cur_offset; |
121 s->cur_frame_end[k] = s->cur_offset + buf_size; | |
121 s->cur_frame_pts[k] = pts; | 122 s->cur_frame_pts[k] = pts; |
122 s->cur_frame_dts[k] = dts; | 123 s->cur_frame_dts[k] = dts; |
123 | 124 } |
124 /* fill first PTS/DTS */ | 125 |
125 if (s->fetch_timestamp){ | 126 if (s->fetch_timestamp){ |
126 s->fetch_timestamp=0; | 127 s->fetch_timestamp=0; |
127 s->last_pts = pts; | 128 s->last_pts = s->pts; |
128 s->last_dts = dts; | 129 s->last_dts = s->dts; |
129 s->last_offset = 0; | 130 s->dts= s->pts= AV_NOPTS_VALUE; |
130 s->cur_frame_pts[k] = | 131 s->offset= 0; |
131 s->cur_frame_dts[k] = AV_NOPTS_VALUE; | 132 for(i = 0; i < AV_PARSER_PTS_NB; i++) { |
133 if ( s->last_frame_offset >= s->cur_frame_offset[i] | |
134 &&(s-> frame_offset < s->cur_frame_offset[i] || !s->frame_offset) | |
135 && s->last_frame_offset < s->cur_frame_end[i]){ | |
136 s->dts= s->cur_frame_dts[i]; | |
137 s->pts= s->cur_frame_pts[i]; | |
138 s->offset = s->last_frame_offset - s->cur_frame_offset[i]; | |
139 } | |
132 } | 140 } |
133 } | 141 } |
134 | 142 |
135 /* WARNING: the returned index can be negative */ | 143 /* WARNING: the returned index can be negative */ |
136 index = s->parser->parser_parse(s, avctx, (const uint8_t **)poutbuf, poutbuf_size, buf, buf_size); | 144 index = s->parser->parser_parse(s, avctx, (const uint8_t **)poutbuf, poutbuf_size, buf, buf_size); |
137 //av_log(NULL, AV_LOG_DEBUG, "parser: in:%"PRId64", %"PRId64", out:%"PRId64", %"PRId64", in:%d out:%d id:%d\n", pts, dts, s->last_pts, s->last_dts, buf_size, *poutbuf_size, avctx->codec_id); | 145 //av_log(NULL, AV_LOG_DEBUG, "parser: in:%"PRId64", %"PRId64", out:%"PRId64", %"PRId64", in:%d out:%d id:%d\n", pts, dts, s->last_pts, s->last_dts, buf_size, *poutbuf_size, avctx->codec_id); |
138 /* update the file pointer */ | 146 /* update the file pointer */ |
139 if (*poutbuf_size) { | 147 if (*poutbuf_size) { |
140 /* fill the data for the current frame */ | 148 /* fill the data for the current frame */ |
141 s->frame_offset = s->last_frame_offset; | 149 s->frame_offset = s->last_frame_offset; |
142 s->pts = s->last_pts; | |
143 s->dts = s->last_dts; | |
144 s->offset = s->last_offset; | |
145 | 150 |
146 /* offset of the next frame */ | 151 /* offset of the next frame */ |
147 s->last_frame_offset = s->cur_offset + index; | 152 s->last_frame_offset = s->cur_offset + index; |
148 /* find the packet in which the new frame starts. It | |
149 is tricky because of MPEG video start codes | |
150 which can begin in one packet and finish in | |
151 another packet. In the worst case, an MPEG | |
152 video start code could be in 4 different | |
153 packets. */ | |
154 k = s->cur_frame_start_index; | |
155 for(i = 0; i < AV_PARSER_PTS_NB; i++) { | |
156 if (s->last_frame_offset >= s->cur_frame_offset[k]) | |
157 break; | |
158 k = (k - 1) & (AV_PARSER_PTS_NB - 1); | |
159 } | |
160 | |
161 s->last_pts = s->cur_frame_pts[k]; | |
162 s->last_dts = s->cur_frame_dts[k]; | |
163 s->last_offset = s->last_frame_offset - s->cur_frame_offset[k]; | |
164 | |
165 /* some parsers tell us the packet size even before seeing the first byte of the next packet, | |
166 so the next pts/dts is in the next chunk */ | |
167 if(index == buf_size){ | |
168 s->fetch_timestamp=1; | 153 s->fetch_timestamp=1; |
169 } | |
170 } | 154 } |
171 if (index < 0) | 155 if (index < 0) |
172 index = 0; | 156 index = 0; |
173 s->cur_offset += index; | 157 s->cur_offset += index; |
174 return index; | 158 return index; |