From 10d0963d851fad338d5d4457172fb20e76bc88aa Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 4 Nov 2017 23:02:25 +0100 Subject: demux: improve and optimize cache pruning and seek range determination The main purpose of this commit is avoiding any hidden O(n^2) algorithms in the code for pruning the demuxer cache, and for determining the seekable boundaries of the cache. The old code could loop over the whole packet queue on every packet pruned in certain corner cases. There are two ways how to reach the goal: 1) commit a cardinal sin 2) do everything incrementally The cardinal sin is adding an extra field to demux_packet, which caches the determined seekable range for a keyframe range. demux_packet is a rather general data structure and thus shouldn't have any fields that are not inherent to its use, and are only needed as an implementation detail of code using it. But what are you gonna do, sue me? In the future, demux.c might have its own packet struct though. Then the other existing cardinal sin (the "next" field, from MPlayer times) could be removed as well. This commit also changes slightly how the seek end is determined. There is a note on the manpage in case anyone finds the new behavior confusing. It's somewhat cleaner and might be needed for supporting multiple ranges (although that's unclear). --- demux/packet.c | 1 + 1 file changed, 1 insertion(+) (limited to 'demux/packet.c') diff --git a/demux/packet.c b/demux/packet.c index 0a13b0e6a5..156222737c 100644 --- a/demux/packet.c +++ b/demux/packet.c @@ -54,6 +54,7 @@ struct demux_packet *new_demux_packet_from_avpacket(struct AVPacket *avpkt) .end = MP_NOPTS_VALUE, .stream = -1, .avpacket = talloc_zero(dp, AVPacket), + .kf_seek_pts = MP_NOPTS_VALUE, }; av_init_packet(dp->avpacket); int r = -1; -- cgit v1.2.3