demux: demux multiple audio frames in backward playback

Until now, this usually passed a single audio frame to the decoder, and
then did a backstep operation (cache seek + frame search) again. This is
probably not very efficient, especially considering it has to search the
packet queue from the "start" every time again.

Also, with most audio codecs, an additional "preroll" frame was passed
first. In these cases, the preroll frame would make up 50% of audio
decoding time. Also not very efficient.

Attempt to fix this by returning multiple frames at once. This reduces
the number of backstep operations and the ratio the preoll frames. In
theory, this should help efficiency. I didn't test it though, why would
I do this? It's just a pain. Set it to unscientific 10 frames.
(Actually, these are 10 keyframes, so it's much more for codecs like
TrueHD. But I don't care about TrueHD.)

This commit changes some other implementation details. Since we can
return more than 1 non-preroll keyframe to the decoder, some new state
is needed to remember how much. The resume packet search is adjusted to
find N ("total") keyframe packets in general, not just preroll frames.
I'm removing the special case for 1 preroll packet; audio used this, but
doesn't anymore, and it's premature optimization anyway.

Expose the new mechanism with 2 new options. They're almost completely
pointless, since nobody will try them, and if they do, they won't
understand what these options truly do. And if they actually do, they
most likely would be capable of editing the source code, and we could
just hardcode the parameters. Just so you know that I know that the
added options are pointless.

The following two things are truly unrelated to this commit, and more
like general refactoring, but fortunately nobody can stop me.

Don't set back_seek_pos in dequeue_packet() anymore. This was sort of
pointless, since it was set in find_backward_restart_pos() anyway (using
some of the same packets). The latter function tries to restrict this to
the first keyframe range though, which is an optimization that in theory
might break with broken files (duh), but in these cases a lot of other
things would be broken anyway.

Don't set back_restart_* in dequeue_packet(). I think this is an
artifact of the old restart code (cf. ad9e473c55). It can be done
directly in find_backward_restart_pos() now. Although this adds another
shitty packet search loop, I prefer this, because clearer what's
actually happening.
This commit is contained in:
wm4
2019-06-02 02:14:54 +02:00
parent e62afe4055
commit f439064e7f
2 changed files with 81 additions and 39 deletions

View File

@@ -568,6 +568,21 @@ Playback Control
depending on the exact conditions. You may have to use the
``--vd-lavc-show-all`` option as well.
``--video-backward-batch=<number>``, ``--audio-backward-batch=<number>``
Number of keyframe ranges to decode at once when backward decoding (default:
1 for video, 10 for audio). Another pointless tuning parameter nobody should
use. This should affect performance only. In theory, setting a number higher
than 1 for audio will reduce overhead due to less frequent backstep
operations and less redundant decoding work due to fewer decoded overlap
frames (see ``--audio-backward-overlap``). On the other hand, it requires
a larger reversal buffer, and could make playback less smooth due to
breaking pipelining (e.g. by decoding a lot, and then doing nothing for a
while).
It probably never makes sense to set ``--video-backward-batch``. But in
theory, it could help with intra-only video codecs by reducing backstep
operations.
``--demuxer-backward-playback-step=<seconds>``
Number of seconds the demuxer should seek back to get new packets during
backward playback (default: 60). This is useful for tuning backward