From 104e18214cdb0f95a2a9661a5cd475baa3f67a4e Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 4 Nov 2017 17:43:22 +0100 Subject: demux: avoid excessive readahead after cache seek The base_ts field is used to guess the decoder position, and when set to NOPTS, it just read ahead arbitrarily. Also demux_add_packet() sets base_ts to the new timestamp when appending a packet, which would also make it readahead by a too large amount. Fix this by setting base_ts after a seek. This assumes that normally, a cached seek target will always have the timestamp set. This is actually not quite clear (as it calls recompute_keyframe_target_pts(), which looks at multiple packets), but maybe it works well enough. --- demux/demux.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/demux/demux.c b/demux/demux.c index 72758d0d8d..95aeb2435b 100644 --- a/demux/demux.c +++ b/demux/demux.c @@ -710,7 +710,7 @@ static bool read_packet(struct demux_internal *in) read_more |= (ds->active && !ds->reader_head) || ds->refreshing; bytes += ds->fw_bytes; if (ds->active && ds->last_ts != MP_NOPTS_VALUE && in->min_secs > 0 && - ds->last_ts >= ds->base_ts) + ds->base_ts != MP_NOPTS_VALUE && ds->last_ts >= ds->base_ts) prefetch_more |= ds->last_ts - ds->base_ts < in->min_secs; } MP_DBG(in, "bytes=%zd, active=%d, read_more=%d prefetch_more=%d\n", @@ -1769,6 +1769,8 @@ static bool try_seek_cache(struct demux_internal *in, double pts, int flags) ds->reader_head = target; ds->skip_to_keyframe = !target; recompute_buffers(ds); + if (ds->reader_head) + ds->base_ts = PTS_OR_DEF(ds->reader_head->pts, ds->reader_head->dts); MP_VERBOSE(in, "seeking stream %d (%s) to ", n, stream_type_name(ds->type)); -- cgit v1.2.3