From 88f10ec84f116bca4580a454b711dbaec7dfd04f Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 24 Sep 2016 19:56:13 +0200 Subject: player: fix instant subtitle refresh on track switches When switching a subtitle track, the subtitle wasn't necessarily updated, especially when playback was paused. Some awfully subtle and complex interactions here. First off (and not so subtle), the subtitle decoder will read packets only on explicit update_subtitles() calls, which, if video is active, is called only when a new video frame is shown. (A simply video frame redraw doesn't trigger this.) So call it explicitly. But only if playback is "initialized", i.e. not when it does initial track selection and decoder init, during which no packets should be read. The second issue is that the demuxer thread simply will not read new packets just because a track was switched, especially if playback is paused. That's fine, but if a refresh seek is to be done, it really should do this. So if there's either 1. a refresh seek requested, or 2. a refresh seek ongoing, then read more packets. Note that it's entirely possible that we overflow the packet queue with this in unpredicated weird corner cases, but the queue limit will still be enforced, so this shouldn't make the situation worse. --- demux/demux.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'demux/demux.c') diff --git a/demux/demux.c b/demux/demux.c index 9404629ad4..3af0651dae 100644 --- a/demux/demux.c +++ b/demux/demux.c @@ -598,7 +598,7 @@ static bool read_packet(struct demux_internal *in) for (int n = 0; n < in->num_streams; n++) { struct demux_stream *ds = in->streams[n]->ds; active |= ds->active; - read_more |= ds->active && !ds->head; + read_more |= (ds->active && !ds->head) || ds->refreshing; packs += ds->packs; bytes += ds->bytes; if (ds->active && ds->last_ts != MP_NOPTS_VALUE && in->min_secs > 0 && @@ -632,11 +632,13 @@ static bool read_packet(struct demux_internal *in) return false; } + double seek_pts = get_refresh_seek_pts(in); + bool refresh_seek = seek_pts != MP_NOPTS_VALUE; + read_more |= refresh_seek; + if (!read_more) return false; - double seek_pts = get_refresh_seek_pts(in); - // Actually read a packet. Drop the lock while doing so, because waiting // for disk or network I/O can take time. in->idle = false; @@ -645,7 +647,7 @@ static bool read_packet(struct demux_internal *in) struct demuxer *demux = in->d_thread; - if (seek_pts != MP_NOPTS_VALUE) { + if (refresh_seek) { MP_VERBOSE(in, "refresh seek to %f\n", seek_pts); demux->desc->seek(demux, seek_pts, SEEK_BACKWARD | SEEK_HR); } -- cgit v1.2.3