From a55e8ff31cc974843e28282ccbdc46dd3e70a5af Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 9 Nov 2016 16:34:45 +0100 Subject: dec_sub: avoid full reinit on switches to the same segment The previous commit means subtitles were reinitialized on every seek (even within a segment). This commit restores the old behavior. To check whether the segment changed at all, we don't reset the current start/end values. This assumes the decoder wrapper is always fed by a stream which doesn't mix segment and non-segment packets, which is currently always true. --- sub/dec_sub.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'sub/dec_sub.c') diff --git a/sub/dec_sub.c b/sub/dec_sub.c index 39eb032982..b9f04b3123 100644 --- a/sub/dec_sub.c +++ b/sub/dec_sub.c @@ -198,6 +198,12 @@ void sub_preload(struct dec_sub *sub) pthread_mutex_unlock(&sub->lock); } +static bool is_new_segment(struct dec_sub *sub, struct demux_packet *p) +{ + return p->new_segment && + (p->start != sub->start || p->end != sub->end || p->codec != sub->codec); +} + // Read packets from the demuxer stream passed to sub_create(). Return true if // enough packets were read, false if the player should wait until the demuxer // signals new packets available (and then should retry). @@ -236,7 +242,7 @@ bool sub_read_packets(struct dec_sub *sub, double video_pts) sub->last_pkt_pts = pkt->pts; - if (pkt->new_segment) { + if (is_new_segment(sub, pkt)) { sub->new_segment = pkt; // Note that this can be delayed to a much later point in time. update_segment(sub); @@ -294,7 +300,6 @@ void sub_reset(struct dec_sub *sub) if (sub->sd->driver->reset) sub->sd->driver->reset(sub->sd); sub->last_pkt_pts = MP_NOPTS_VALUE; - sub->start = sub->end = MP_NOPTS_VALUE; sub->last_vo_pts = MP_NOPTS_VALUE; talloc_free(sub->new_segment); sub->new_segment = NULL; -- cgit v1.2.3