Mercurial > libavformat.hg
changeset 4762:af176c4a2ad2 libavformat
fix valid seeking range
author | bcoudurier |
---|---|
date | Sat, 21 Mar 2009 07:35:52 +0000 |
parents | a079bfd0192b |
children | e69e94c9d3e2 |
files | ffmdec.c |
diffstat | 1 files changed, 7 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/ffmdec.c Sat Mar 21 00:50:51 2009 +0000 +++ b/ffmdec.c Sat Mar 21 07:35:52 2009 +0000 @@ -165,17 +165,16 @@ //#define DEBUG_SEEK -/* pos is between 0 and file_size - FFM_PACKET_SIZE. It is translated - by the write position inside this function */ +/* ensure that acutal seeking happens between FFM_PACKET_SIZE + and file_size - FFM_PACKET_SIZE */ static void ffm_seek1(AVFormatContext *s, int64_t pos1) { FFMContext *ffm = s->priv_data; ByteIOContext *pb = s->pb; int64_t pos; - pos = pos1 + ffm->write_index; - if (pos >= ffm->file_size) - pos -= (ffm->file_size - FFM_PACKET_SIZE); + pos = FFMIN(pos1, ffm->file_size - FFM_PACKET_SIZE); + pos = FFMAX(pos, FFM_PACKET_SIZE); #ifdef DEBUG_SEEK av_log(s, AV_LOG_DEBUG, "seek to %"PRIx64" -> %"PRIx64"\n", pos1, pos); #endif @@ -454,8 +453,8 @@ #endif /* find the position using linear interpolation (better than dichotomy in typical cases) */ - pos_min = 0; - pos_max = ffm->file_size - 2 * FFM_PACKET_SIZE; + pos_min = FFM_PACKET_SIZE; + pos_max = ffm->file_size - FFM_PACKET_SIZE; while (pos_min <= pos_max) { pts_min = get_dts(s, pos_min); pts_max = get_dts(s, pos_max); @@ -478,8 +477,7 @@ } } pos = (flags & AVSEEK_FLAG_BACKWARD) ? pos_min : pos_max; - if (pos > 0) - pos -= FFM_PACKET_SIZE; + found: ffm_seek1(s, pos);