summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2019-05-31 22:42:59 +0200
committerwm4 <wm4@nowhere>2019-09-19 20:37:05 +0200
commit9c32997c65dde70e64b98006a60b522e5ad879e4 (patch)
treedd581c7d7aa938e1016dea8f7e908f01dd6b0b59
parentd25fbb081387ddb9679a31faf43946ad837c5d66 (diff)
downloadmpv-9c32997c65dde70e64b98006a60b522e5ad879e4.tar.bz2
mpv-9c32997c65dde70e64b98006a60b522e5ad879e4.tar.xz
demux: simplify and improve performance of backward playback stepping
The step_backwards function set reader_head to the start of the current cache range. This was completely unnecessary and made it _much_ slower. Remove the code that adjusts reader_head. Merge the rest of the code into the only caller and remove the function. The comment on the removed code was quite right. It was "inefficient". Removing it delegates going to an early position to the normal seek code, triggered by find_backward_restart_pos() incremental back seek logic. I suppose especially audio benefits from this, because this happens for every single audio packet (except maybe freaky bullshit like TrueHD, which has "keyframes"). The blabla about performance in the removed comments is still true, but now applies to the seek code itself only.
-rw-r--r--demux/demux.c39
1 files changed, 6 insertions, 33 deletions
diff --git a/demux/demux.c b/demux/demux.c
index 0582ccc661..892af331fb 100644
--- a/demux/demux.c
+++ b/demux/demux.c
@@ -1484,38 +1484,6 @@ static void back_demux_see_packets(struct demux_stream *ds)
find_backward_restart_pos(ds);
}
-// Resume demuxing from an earlier position for backward playback. May trigger
-// a seek.
-static void step_backwards(struct demux_stream *ds)
-{
- struct demux_internal *in = ds->in;
-
- assert(in->back_demuxing);
-
- assert(!ds->back_restarting);
- ds->back_restarting = true;
- ds->back_restart_eof = false;
- ds->back_restart_next = false;
-
- // Move to start of queue. This is inefficient, because we need to iterate
- // the entire fucking packet queue just to update the fw_* stats. But as
- // long as we don't have demux_packet.prev links or a complete index, it's
- // the thing to do.
- // Note: if the buffer forward is much larger than the one backward, it
- // would be worth looping until the previous reader_head and decrementing
- // fw_packs/fw_bytes - you could skip the full recompute_buffers().
- ds->reader_head = ds->queue->head;
- in->fw_bytes -= ds->fw_bytes;
- recompute_buffers(ds);
- in->fw_bytes += ds->fw_bytes;
-
- // Exclude weird special-cases (incomplete pruning? broken seeks?)
- while (ds->reader_head && !ds->reader_head->keyframe)
- advance_reader_head(ds);
-
- find_backward_restart_pos(ds);
-}
-
// Add the keyframe to the end of the index. Not all packets are actually added.
static void add_index_entry(struct demux_queue *queue, struct demux_packet *dp)
{
@@ -2285,7 +2253,12 @@ static int dequeue_packet(struct demux_stream *ds, struct demux_packet **res)
if (ds->back_range_started && !ds->back_range_min &&
((ds->reader_head && ds->reader_head->keyframe) || eof))
{
- step_backwards(ds);
+ ds->back_restarting = true;
+ ds->back_restart_eof = false;
+ ds->back_restart_next = false;
+
+ find_backward_restart_pos(ds);
+
if (ds->back_restarting)
return 0;
}