mpv/DOCS
wm4 935e406d63 demux: support multiple seekable cached ranges
Until now, the demuxer cache was limited to a single range. Extend this
to multiple range. Should be useful for slow network streams.

This commit changes a lot in the internal demuxer cache logic, so
there's a lot of room for bugs and regressions. The logic without
demuxer cache is mostly untouched, but also involved with the code
changes. Or in other words, this commit probably fucks up shit.

There are two things which makes multiple cached ranges rather hard:

1. the need to resume the demuxer at the end of a cached range when
   seeking to it
2. joining two adjacent ranges when the lowe range "grows" into it (and
   resuming the demuxer at the end of the new joined range)

"Resuming" the demuxer means that we perform a low level seek to the end
of a cached range, and properly append new packets to it, without adding
packets multiple times or creating holes due to missing packets.

Since audio and video never line up exactly, there is no clean "cut"
possible, at which you could resume the demuxer cleanly (for 1.) or
which you could use to detect that two ranges are perfectly adjacent
(for 2.). The way how the demuxer interleaves multiple streams is also
unpredictable. Typically you will have to expect that it randomly allows
one of the streams to be ahead by a bit, and so on.

To deal with this, we have heuristics in place to detect when one packet
equals or is "behind" a packet that was demuxed earlier. We reuse the
refresh seek logic (used to "reread" packets into the demuxer cache when
enabling a track), which checks for certain packet invariants.
Currently, it observes whether either the raw packet position, or the
packet DTS is strictly monotonically increasing. If none of them are
true, we discard old ranges when creating a new one.

This heavily depends on the file format and the demuxer behavior. For
example, not all file formats have DTS, and the packet position can be
unset due to libavformat not always setting it (e.g. when parsers are
used).

At the same time, we must deal with all the complicated state used to
track prefetching and seek ranges. In some complicated corner cases, we
just give up and discard other seek ranges, even if the previously
mentioned packet invariants are fulfilled.

To handle joining, we're being particularly dumb, and require a small
overlap to be confident that two ranges join perfectly. (This could be
done incrementally with as little overlap as 1 packet, but corner cases
would eat us: each stream needs to be joined separately, and the cache
pruning logic could remove overlapping packets for other streams again.)

Another restriction is that switching the cached range will always
trigger an asynchronous low level seek to resume demuxing at the new
range. Some users might find this annoying.

Dealing with interleaved subtitles is not fully handled yet. It will
clamp the seekable range to where subtitle packets are.
2017-11-09 10:23:57 +01:00
..
man demux: support multiple seekable cached ranges 2017-11-09 10:23:57 +01:00
client-api-changes.rst client API: minor bump + change entry for DRM related opengl-cb changes 2017-10-23 21:11:44 +02:00
compile-windows.md DOCS/compile-windows.md: update for changes to mpv and MSYS2 2017-10-02 01:28:54 +11:00
contribute.md DOCS/contribute.md: coding style exception 2017-08-30 10:34:16 +02:00
edl-mpv.rst DOCS/edl-mpv.rst: fix typo 2017-02-05 16:02:58 +01:00
encoding.rst player: change default section when loading encoding-profiles.conf 2017-07-12 13:11:14 +02:00
interface-changes.rst demux: add a back buffer and the ability to seek into it 2017-10-21 19:26:33 +02:00
mplayer-changes.rst vo_opengl: refactor into vo_gpu 2017-09-21 15:00:55 +02:00
release-policy.md Release 0.25.0 2017-04-23 01:57:53 +02:00
tech-overview.txt DOCS/tech-overview.txt: updates 2017-06-29 17:31:55 +02:00
waf-buildsystem.rst DOCS/waf-buildsystem.rst: fix typo 2017-02-15 10:41:26 +01:00