fix valid seeking range

Originally committed as revision 18098 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
Baptiste Coudurier 2009-03-21 07:35:52 +00:00
parent 7e24aa0c13
commit 92a0f33878
2 changed files with 21 additions and 23 deletions

View File

@ -165,17 +165,16 @@ static int ffm_read_data(AVFormatContext *s,
//#define DEBUG_SEEK //#define DEBUG_SEEK
/* pos is between 0 and file_size - FFM_PACKET_SIZE. It is translated /* ensure that acutal seeking happens between FFM_PACKET_SIZE
by the write position inside this function */ and file_size - FFM_PACKET_SIZE */
static void ffm_seek1(AVFormatContext *s, int64_t pos1) static void ffm_seek1(AVFormatContext *s, int64_t pos1)
{ {
FFMContext *ffm = s->priv_data; FFMContext *ffm = s->priv_data;
ByteIOContext *pb = s->pb; ByteIOContext *pb = s->pb;
int64_t pos; int64_t pos;
pos = pos1 + ffm->write_index; pos = FFMIN(pos1, ffm->file_size - FFM_PACKET_SIZE);
if (pos >= ffm->file_size) pos = FFMAX(pos, FFM_PACKET_SIZE);
pos -= (ffm->file_size - FFM_PACKET_SIZE);
#ifdef DEBUG_SEEK #ifdef DEBUG_SEEK
av_log(s, AV_LOG_DEBUG, "seek to %"PRIx64" -> %"PRIx64"\n", pos1, pos); av_log(s, AV_LOG_DEBUG, "seek to %"PRIx64" -> %"PRIx64"\n", pos1, pos);
#endif #endif
@ -454,8 +453,8 @@ static int ffm_seek(AVFormatContext *s, int stream_index, int64_t wanted_pts, in
#endif #endif
/* find the position using linear interpolation (better than /* find the position using linear interpolation (better than
dichotomy in typical cases) */ dichotomy in typical cases) */
pos_min = 0; pos_min = FFM_PACKET_SIZE;
pos_max = ffm->file_size - 2 * FFM_PACKET_SIZE; pos_max = ffm->file_size - FFM_PACKET_SIZE;
while (pos_min <= pos_max) { while (pos_min <= pos_max) {
pts_min = get_dts(s, pos_min); pts_min = get_dts(s, pos_min);
pts_max = get_dts(s, pos_max); pts_max = get_dts(s, pos_max);
@ -478,8 +477,7 @@ static int ffm_seek(AVFormatContext *s, int stream_index, int64_t wanted_pts, in
} }
} }
pos = (flags & AVSEEK_FLAG_BACKWARD) ? pos_min : pos_max; pos = (flags & AVSEEK_FLAG_BACKWARD) ? pos_min : pos_max;
if (pos > 0)
pos -= FFM_PACKET_SIZE;
found: found:
ffm_seek1(s, pos); ffm_seek1(s, pos);

View File

@ -2842,51 +2842,51 @@ ret: 0 st: 0 dts:-0.040000 pts:0.000000 pos:8192 size:24795 flags:1
ret: 0 st:-1 ts:-1.000000 flags:0 ret: 0 st:-1 ts:-1.000000 flags:0
ret: 0 st: 0 dts:-0.040000 pts:0.000000 pos:8192 size:24795 flags:1 ret: 0 st: 0 dts:-0.040000 pts:0.000000 pos:8192 size:24795 flags:1
ret: 0 st:-1 ts:1.894167 flags:1 ret: 0 st:-1 ts:1.894167 flags:1
ret: 0 st: 1 dts:0.888163 pts:0.888163 pos:356352 size:209 flags:1 ret: 0 st: 1 dts:0.940408 pts:0.940408 pos:380928 size:209 flags:1
ret: 0 st: 0 ts:0.788334 flags:0 ret: 0 st: 0 ts:0.788334 flags:0
ret: 0 st: 1 dts:0.783673 pts:0.783673 pos:319488 size:209 flags:1 ret: 0 st: 1 dts:0.783673 pts:0.783673 pos:319488 size:209 flags:1
ret: 0 st: 0 ts:-0.317499 flags:1 ret: 0 st: 0 ts:-0.317499 flags:1
ret: 0 st: 0 dts:-0.040000 pts:0.000000 pos:8192 size:24795 flags:1 ret: 0 st: 0 dts:-0.040000 pts:0.000000 pos:8192 size:24795 flags:1
ret: 0 st: 1 ts:2.576668 flags:0 ret: 0 st: 1 ts:2.576668 flags:0
ret: 0 st: 1 dts:0.888163 pts:0.888163 pos:356352 size:209 flags:1 ret: 0 st: 1 dts:0.940408 pts:0.940408 pos:380928 size:209 flags:1
ret: 0 st: 1 ts:1.470835 flags:1 ret: 0 st: 1 ts:1.470835 flags:1
ret: 0 st: 1 dts:0.888163 pts:0.888163 pos:356352 size:209 flags:1 ret: 0 st: 1 dts:0.940408 pts:0.940408 pos:380928 size:209 flags:1
ret: 0 st:-1 ts:0.365002 flags:0 ret: 0 st:-1 ts:0.365002 flags:0
ret: 0 st: 1 dts:0.339592 pts:0.339592 pos:159744 size:209 flags:1 ret: 0 st: 1 dts:0.339592 pts:0.339592 pos:159744 size:209 flags:1
ret: 0 st:-1 ts:-0.740831 flags:1 ret: 0 st:-1 ts:-0.740831 flags:1
ret: 0 st: 0 dts:-0.040000 pts:0.000000 pos:8192 size:24795 flags:1 ret: 0 st: 0 dts:-0.040000 pts:0.000000 pos:8192 size:24795 flags:1
ret: 0 st: 0 ts:2.153336 flags:0 ret: 0 st: 0 ts:2.153336 flags:0
ret: 0 st: 1 dts:0.888163 pts:0.888163 pos:356352 size:209 flags:1 ret: 0 st: 1 dts:0.940408 pts:0.940408 pos:380928 size:209 flags:1
ret: 0 st: 0 ts:1.047503 flags:1 ret: 0 st: 0 ts:1.047503 flags:1
ret: 0 st: 1 dts:0.888163 pts:0.888163 pos:356352 size:209 flags:1 ret: 0 st: 1 dts:0.940408 pts:0.940408 pos:380928 size:209 flags:1
ret: 0 st: 1 ts:-0.058330 flags:0 ret: 0 st: 1 ts:-0.058330 flags:0
ret: 0 st: 0 dts:-0.040000 pts:0.000000 pos:8192 size:24795 flags:1 ret: 0 st: 0 dts:-0.040000 pts:0.000000 pos:8192 size:24795 flags:1
ret: 0 st: 1 ts:2.835837 flags:1 ret: 0 st: 1 ts:2.835837 flags:1
ret: 0 st: 1 dts:0.888163 pts:0.888163 pos:356352 size:209 flags:1 ret: 0 st: 1 dts:0.940408 pts:0.940408 pos:380928 size:209 flags:1
ret: 0 st:-1 ts:1.730004 flags:0 ret: 0 st:-1 ts:1.730004 flags:0
ret: 0 st: 1 dts:0.888163 pts:0.888163 pos:356352 size:209 flags:1 ret: 0 st: 1 dts:0.940408 pts:0.940408 pos:380928 size:209 flags:1
ret: 0 st:-1 ts:0.624171 flags:1 ret: 0 st:-1 ts:0.624171 flags:1
ret: 0 st: 1 dts:0.600816 pts:0.600816 pos:266240 size:209 flags:1 ret: 0 st: 1 dts:0.653061 pts:0.653061 pos:282624 size:209 flags:1
ret: 0 st: 0 ts:-0.481662 flags:0 ret: 0 st: 0 ts:-0.481662 flags:0
ret: 0 st: 0 dts:-0.040000 pts:0.000000 pos:8192 size:24795 flags:1 ret: 0 st: 0 dts:-0.040000 pts:0.000000 pos:8192 size:24795 flags:1
ret: 0 st: 0 ts:2.412505 flags:1 ret: 0 st: 0 ts:2.412505 flags:1
ret: 0 st: 1 dts:0.888163 pts:0.888163 pos:356352 size:209 flags:1 ret: 0 st: 1 dts:0.940408 pts:0.940408 pos:380928 size:209 flags:1
ret: 0 st: 1 ts:1.306672 flags:0 ret: 0 st: 1 ts:1.306672 flags:0
ret: 0 st: 1 dts:0.888163 pts:0.888163 pos:356352 size:209 flags:1 ret: 0 st: 1 dts:0.940408 pts:0.940408 pos:380928 size:209 flags:1
ret: 0 st: 1 ts:0.200839 flags:1 ret: 0 st: 1 ts:0.200839 flags:1
ret: 0 st: 1 dts:0.182857 pts:0.182857 pos:102400 size:209 flags:1 ret: 0 st: 1 dts:0.208980 pts:0.208980 pos:118784 size:209 flags:1
ret: 0 st:-1 ts:-0.904994 flags:0 ret: 0 st:-1 ts:-0.904994 flags:0
ret: 0 st: 0 dts:-0.040000 pts:0.000000 pos:8192 size:24795 flags:1 ret: 0 st: 0 dts:-0.040000 pts:0.000000 pos:8192 size:24795 flags:1
ret: 0 st:-1 ts:1.989173 flags:1 ret: 0 st:-1 ts:1.989173 flags:1
ret: 0 st: 1 dts:0.888163 pts:0.888163 pos:356352 size:209 flags:1 ret: 0 st: 1 dts:0.940408 pts:0.940408 pos:380928 size:209 flags:1
ret: 0 st: 0 ts:0.883340 flags:0 ret: 0 st: 0 ts:0.883340 flags:0
ret: 0 st: 1 dts:0.862041 pts:0.862041 pos:344064 size:209 flags:1 ret: 0 st: 1 dts:0.862041 pts:0.862041 pos:344064 size:209 flags:1
ret: 0 st: 0 ts:-0.222493 flags:1 ret: 0 st: 0 ts:-0.222493 flags:1
ret: 0 st: 0 dts:-0.040000 pts:0.000000 pos:8192 size:24795 flags:1 ret: 0 st: 0 dts:-0.040000 pts:0.000000 pos:8192 size:24795 flags:1
ret: 0 st: 1 ts:2.671674 flags:0 ret: 0 st: 1 ts:2.671674 flags:0
ret: 0 st: 1 dts:0.888163 pts:0.888163 pos:356352 size:209 flags:1 ret: 0 st: 1 dts:0.940408 pts:0.940408 pos:380928 size:209 flags:1
ret: 0 st: 1 ts:1.565841 flags:1 ret: 0 st: 1 ts:1.565841 flags:1
ret: 0 st: 1 dts:0.888163 pts:0.888163 pos:356352 size:209 flags:1 ret: 0 st: 1 dts:0.940408 pts:0.940408 pos:380928 size:209 flags:1
ret: 0 st:-1 ts:0.460008 flags:0 ret: 0 st:-1 ts:0.460008 flags:0
ret: 0 st: 1 dts:0.444082 pts:0.444082 pos:208896 size:209 flags:1 ret: 0 st: 1 dts:0.444082 pts:0.444082 pos:208896 size:209 flags:1
ret: 0 st:-1 ts:-0.645825 flags:1 ret: 0 st:-1 ts:-0.645825 flags:1