Mercurial > libavformat.hg
comparison ffmdec.c @ 3492:6facc89bece8 libavformat
cosmetics, pts->dts
author | bcoudurier |
---|---|
date | Sun, 22 Jun 2008 08:53:44 +0000 |
parents | e9876fb1c84f |
children | 255a1b73b4e3 |
comparison
equal
deleted
inserted
replaced
3491:31aa7b51c13b | 3492:6facc89bece8 |
---|---|
97 if (url_ftell(pb) == ffm->file_size) | 97 if (url_ftell(pb) == ffm->file_size) |
98 url_fseek(pb, ffm->packet_size, SEEK_SET); | 98 url_fseek(pb, ffm->packet_size, SEEK_SET); |
99 retry_read: | 99 retry_read: |
100 get_be16(pb); /* PACKET_ID */ | 100 get_be16(pb); /* PACKET_ID */ |
101 fill_size = get_be16(pb); | 101 fill_size = get_be16(pb); |
102 ffm->pts = get_be64(pb); | 102 ffm->dts = get_be64(pb); |
103 frame_offset = get_be16(pb); | 103 frame_offset = get_be16(pb); |
104 get_buffer(pb, ffm->packet, ffm->packet_size - FFM_HEADER_SIZE); | 104 get_buffer(pb, ffm->packet, ffm->packet_size - FFM_HEADER_SIZE); |
105 ffm->packet_end = ffm->packet + (ffm->packet_size - FFM_HEADER_SIZE - fill_size); | 105 ffm->packet_end = ffm->packet + (ffm->packet_size - FFM_HEADER_SIZE - fill_size); |
106 if (ffm->packet_end < ffm->packet || frame_offset < 0) | 106 if (ffm->packet_end < ffm->packet || frame_offset < 0) |
107 return -1; | 107 return -1; |
154 av_log(s, AV_LOG_DEBUG, "seek to %"PRIx64" -> %"PRIx64"\n", pos1, pos); | 154 av_log(s, AV_LOG_DEBUG, "seek to %"PRIx64" -> %"PRIx64"\n", pos1, pos); |
155 #endif | 155 #endif |
156 url_fseek(pb, pos, SEEK_SET); | 156 url_fseek(pb, pos, SEEK_SET); |
157 } | 157 } |
158 | 158 |
159 static int64_t get_pts(AVFormatContext *s, offset_t pos) | 159 static int64_t get_dts(AVFormatContext *s, offset_t pos) |
160 { | 160 { |
161 ByteIOContext *pb = s->pb; | 161 ByteIOContext *pb = s->pb; |
162 int64_t pts; | 162 int64_t dts; |
163 | 163 |
164 ffm_seek1(s, pos); | 164 ffm_seek1(s, pos); |
165 url_fskip(pb, 4); | 165 url_fskip(pb, 4); |
166 pts = get_be64(pb); | 166 dts = get_be64(pb); |
167 #ifdef DEBUG_SEEK | 167 #ifdef DEBUG_SEEK |
168 av_log(s, AV_LOG_DEBUG, "pts=%0.6f\n", pts / 1000000.0); | 168 av_log(s, AV_LOG_DEBUG, "pts=%0.6f\n", pts / 1000000.0); |
169 #endif | 169 #endif |
170 return pts; | 170 return dts; |
171 } | 171 } |
172 | 172 |
173 static void adjust_write_index(AVFormatContext *s) | 173 static void adjust_write_index(AVFormatContext *s) |
174 { | 174 { |
175 FFMContext *ffm = s->priv_data; | 175 FFMContext *ffm = s->priv_data; |
182 | 182 |
183 | 183 |
184 pos_min = 0; | 184 pos_min = 0; |
185 pos_max = ffm->file_size - 2 * FFM_PACKET_SIZE; | 185 pos_max = ffm->file_size - 2 * FFM_PACKET_SIZE; |
186 | 186 |
187 pts_start = get_pts(s, pos_min); | 187 pts_start = get_dts(s, pos_min); |
188 | 188 |
189 pts = get_pts(s, pos_max); | 189 pts = get_dts(s, pos_max); |
190 | 190 |
191 if (pts - 100000 > pts_start) | 191 if (pts - 100000 > pts_start) |
192 goto end; | 192 goto end; |
193 | 193 |
194 ffm->write_index = FFM_PACKET_SIZE; | 194 ffm->write_index = FFM_PACKET_SIZE; |
195 | 195 |
196 pts_start = get_pts(s, pos_min); | 196 pts_start = get_dts(s, pos_min); |
197 | 197 |
198 pts = get_pts(s, pos_max); | 198 pts = get_dts(s, pos_max); |
199 | 199 |
200 if (pts - 100000 <= pts_start) { | 200 if (pts - 100000 <= pts_start) { |
201 while (1) { | 201 while (1) { |
202 offset_t newpos; | 202 offset_t newpos; |
203 int64_t newpts; | 203 int64_t newpts; |
205 newpos = ((pos_max + pos_min) / (2 * FFM_PACKET_SIZE)) * FFM_PACKET_SIZE; | 205 newpos = ((pos_max + pos_min) / (2 * FFM_PACKET_SIZE)) * FFM_PACKET_SIZE; |
206 | 206 |
207 if (newpos == pos_min) | 207 if (newpos == pos_min) |
208 break; | 208 break; |
209 | 209 |
210 newpts = get_pts(s, newpos); | 210 newpts = get_dts(s, newpos); |
211 | 211 |
212 if (newpts - 100000 <= pts) { | 212 if (newpts - 100000 <= pts) { |
213 pos_max = newpos; | 213 pos_max = newpos; |
214 pts = newpts; | 214 pts = newpts; |
215 } else { | 215 } else { |
218 } | 218 } |
219 ffm->write_index += pos_max; | 219 ffm->write_index += pos_max; |
220 } | 220 } |
221 | 221 |
222 //printf("Adjusted write index from %"PRId64" to %"PRId64": pts=%0.6f\n", orig_write_index, ffm->write_index, pts / 1000000.); | 222 //printf("Adjusted write index from %"PRId64" to %"PRId64": pts=%0.6f\n", orig_write_index, ffm->write_index, pts / 1000000.); |
223 //printf("pts range %0.6f - %0.6f\n", get_pts(s, 0) / 1000000. , get_pts(s, ffm->file_size - 2 * FFM_PACKET_SIZE) / 1000000. ); | 223 //printf("pts range %0.6f - %0.6f\n", get_dts(s, 0) / 1000000. , get_dts(s, ffm->file_size - 2 * FFM_PACKET_SIZE) / 1000000. ); |
224 | 224 |
225 end: | 225 end: |
226 url_fseek(pb, ptr, SEEK_SET); | 226 url_fseek(pb, ptr, SEEK_SET); |
227 } | 227 } |
228 | 228 |
335 | 335 |
336 /* init packet demux */ | 336 /* init packet demux */ |
337 ffm->packet_ptr = ffm->packet; | 337 ffm->packet_ptr = ffm->packet; |
338 ffm->packet_end = ffm->packet; | 338 ffm->packet_end = ffm->packet; |
339 ffm->frame_offset = 0; | 339 ffm->frame_offset = 0; |
340 ffm->pts = 0; | 340 ffm->dts = 0; |
341 ffm->read_state = READ_HEADER; | 341 ffm->read_state = READ_HEADER; |
342 ffm->first_packet = 1; | 342 ffm->first_packet = 1; |
343 return 0; | 343 return 0; |
344 fail: | 344 fail: |
345 for(i=0;i<s->nb_streams;i++) { | 345 for(i=0;i<s->nb_streams;i++) { |
429 /* find the position using linear interpolation (better than | 429 /* find the position using linear interpolation (better than |
430 dichotomy in typical cases) */ | 430 dichotomy in typical cases) */ |
431 pos_min = 0; | 431 pos_min = 0; |
432 pos_max = ffm->file_size - 2 * FFM_PACKET_SIZE; | 432 pos_max = ffm->file_size - 2 * FFM_PACKET_SIZE; |
433 while (pos_min <= pos_max) { | 433 while (pos_min <= pos_max) { |
434 pts_min = get_pts(s, pos_min); | 434 pts_min = get_dts(s, pos_min); |
435 pts_max = get_pts(s, pos_max); | 435 pts_max = get_dts(s, pos_max); |
436 /* linear interpolation */ | 436 /* linear interpolation */ |
437 pos1 = (double)(pos_max - pos_min) * (double)(wanted_pts - pts_min) / | 437 pos1 = (double)(pos_max - pos_min) * (double)(wanted_pts - pts_min) / |
438 (double)(pts_max - pts_min); | 438 (double)(pts_max - pts_min); |
439 pos = (((int64_t)pos1) / FFM_PACKET_SIZE) * FFM_PACKET_SIZE; | 439 pos = (((int64_t)pos1) / FFM_PACKET_SIZE) * FFM_PACKET_SIZE; |
440 if (pos <= pos_min) | 440 if (pos <= pos_min) |
441 pos = pos_min; | 441 pos = pos_min; |
442 else if (pos >= pos_max) | 442 else if (pos >= pos_max) |
443 pos = pos_max; | 443 pos = pos_max; |
444 pts = get_pts(s, pos); | 444 pts = get_dts(s, pos); |
445 /* check if we are lucky */ | 445 /* check if we are lucky */ |
446 if (pts == wanted_pts) { | 446 if (pts == wanted_pts) { |
447 goto found; | 447 goto found; |
448 } else if (pts > wanted_pts) { | 448 } else if (pts > wanted_pts) { |
449 pos_max = pos - FFM_PACKET_SIZE; | 449 pos_max = pos - FFM_PACKET_SIZE; |