From a323dfae426e43451f4d3e08a9a63cb7d1c1ace9 Mon Sep 17 00:00:00 2001 From: Dudemanguy Date: Wed, 9 Aug 2023 16:39:58 -0500 Subject: [PATCH] sub: fix switching tracks while paused Internal subtitles were not shown when switching between tracks while mpv was paused. The reason for this is simply because the demuxer data isn't available yet when the track switch happens. Fixing it is basically just retrying until the packet is actually available when the player is paused. Fixes #8311. --- player/sub.c | 6 ++++-- sub/dec_sub.c | 4 ++-- sub/dec_sub.h | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/player/sub.c b/player/sub.c index e1df0a7386..7dd1f2ccb6 100644 --- a/player/sub.c +++ b/player/sub.c @@ -100,7 +100,7 @@ static bool update_subtitle(struct MPContext *mpctx, double video_pts, sub_preload(dec_sub); } - if (!sub_read_packets(dec_sub, video_pts)) + if (!sub_read_packets(dec_sub, video_pts, mpctx->paused)) return false; // Handle displaying subtitles on terminal; never done for secondary subs @@ -201,8 +201,10 @@ void reinit_sub(struct MPContext *mpctx, struct track *track) osd_set_sub(mpctx->osd, order, track->d_sub); sub_control(track->d_sub, SD_CTRL_SET_TOP, &order); + // When paused we have to wait for packets to be available. + // So just retry until we get a packet in this case. if (mpctx->playback_initialized) - update_subtitles(mpctx, mpctx->playback_pts); + while (!update_subtitles(mpctx, mpctx->playback_pts) && mpctx->paused); } void reinit_sub_all(struct MPContext *mpctx) diff --git a/sub/dec_sub.c b/sub/dec_sub.c index 30f5b651b0..b31178ced7 100644 --- a/sub/dec_sub.c +++ b/sub/dec_sub.c @@ -273,7 +273,7 @@ static bool is_new_segment(struct dec_sub *sub, struct demux_packet *p) // 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). -bool sub_read_packets(struct dec_sub *sub, double video_pts) +bool sub_read_packets(struct dec_sub *sub, double video_pts, bool force) { bool r = true; pthread_mutex_lock(&sub->lock); @@ -295,7 +295,7 @@ bool sub_read_packets(struct dec_sub *sub, double video_pts) break; // (Use this mechanism only if sub_delay matters to avoid corner cases.) - double min_pts = sub->opts->sub_delay < 0 ? video_pts : MP_NOPTS_VALUE; + double min_pts = sub->opts->sub_delay < 0 || force ? video_pts : MP_NOPTS_VALUE; struct demux_packet *pkt; int st = demux_read_packet_async_until(sub->sh, min_pts, &pkt); diff --git a/sub/dec_sub.h b/sub/dec_sub.h index 21579bcde2..4a68cf6aaa 100644 --- a/sub/dec_sub.h +++ b/sub/dec_sub.h @@ -43,7 +43,7 @@ void sub_destroy(struct dec_sub *sub); bool sub_can_preload(struct dec_sub *sub); void sub_preload(struct dec_sub *sub); -bool sub_read_packets(struct dec_sub *sub, double video_pts); +bool sub_read_packets(struct dec_sub *sub, double video_pts, bool force); struct sub_bitmaps *sub_get_bitmaps(struct dec_sub *sub, struct mp_osd_res dim, int format, double pts); char *sub_get_text(struct dec_sub *sub, double pts, enum sd_text_type type);