From 901922e0475c590140b3b947df58de458326b817 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Wed, 15 Jul 2015 03:35:08 +0200 Subject: avformat/utils: adjust short skip threshold in ff_configure_buffers_for_index() to avoid seeking if a packet is skiped Fixes Ticket4126 Signed-off-by: Michael Niedermayer --- libavformat/utils.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'libavformat/utils.c') diff --git a/libavformat/utils.c b/libavformat/utils.c index c40b4d2b27..16901786a9 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -1785,6 +1785,7 @@ void ff_configure_buffers_for_index(AVFormatContext *s, int64_t time_tolerance) { int ist1, ist2; int64_t pos_delta = 0; + int64_t skip = 0; //We could use URLProtocol flags here but as many user applications do not use URLProtocols this would be unreliable const char *proto = avio_find_protocol_name(s->filename); @@ -1804,6 +1805,7 @@ void ff_configure_buffers_for_index(AVFormatContext *s, int64_t time_tolerance) AVIndexEntry *e1 = &st1->index_entries[i1]; int64_t e1_pts = av_rescale_q(e1->timestamp, st1->time_base, AV_TIME_BASE_Q); + skip = FFMAX(skip, e1->size); for (; i2 < st2->nb_index_entries; i2++) { AVIndexEntry *e2 = &st2->index_entries[i2]; int64_t e2_pts = av_rescale_q(e2->timestamp, st2->time_base, AV_TIME_BASE_Q); @@ -1823,6 +1825,10 @@ void ff_configure_buffers_for_index(AVFormatContext *s, int64_t time_tolerance) ffio_set_buf_size(s->pb, pos_delta); s->pb->short_seek_threshold = FFMAX(s->pb->short_seek_threshold, pos_delta/2); } + + if (skip < (1<<23)) { + s->pb->short_seek_threshold = FFMAX(s->pb->short_seek_threshold, skip); + } } int av_index_search_timestamp(AVStream *st, int64_t wanted_timestamp, int flags) -- cgit v1.2.3