0
0
mirror of https://github.com/mpv-player/mpv.git synced 2024-09-20 03:52:22 +02:00

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.
This commit is contained in:
wm4 2017-11-04 17:43:22 +01:00
parent c1f981f863
commit 104e18214c

View File

@ -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));