From 2f64c84b446c389ce3c1afe210dd7b0df388f5ff Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 16 Jun 2019 16:13:23 +0200 Subject: demux: remove some redundancy in backward playback code This code tries to determine the "current" position, which is used as base for the seek target when it needs to seek back more (the point is to prevent seeking back too far). But compute_keyframe_times() almost computes the same thing, so use that. Unfortunately needs a forward declaration. ("Almost", because it differs in some details that should not really matter.) --- demux/demux.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/demux/demux.c b/demux/demux.c index e09a4e843c..49e75ef48f 100644 --- a/demux/demux.c +++ b/demux/demux.c @@ -416,6 +416,9 @@ static void add_packet_locked(struct sh_stream *stream, demux_packet_t *dp); static struct demux_packet *advance_reader_head(struct demux_stream *ds); static bool queue_seek(struct demux_internal *in, double seek_pts, int flags, bool clear_back_state); +static struct demux_packet *compute_keyframe_times(struct demux_packet *pkt, + double *out_kf_min, + double *out_kf_max); static uint64_t get_foward_buffered_bytes(struct demux_stream *ds) { @@ -1444,12 +1447,8 @@ static void find_backward_restart_pos(struct demux_stream *ds) assert(0); // target must be in list } - double seek_pts = MP_NOPTS_VALUE; - for (struct demux_packet *cur = target; cur; cur = cur->next) { - seek_pts = MP_PTS_MIN(seek_pts, cur->pts); - if (cur->next && cur->next->keyframe) - break; - } + double seek_pts; + compute_keyframe_times(target, &seek_pts, NULL); if (seek_pts != MP_NOPTS_VALUE) ds->back_seek_pos = seek_pts; -- cgit v1.2.3