0
0
mirror of https://github.com/mpv-player/mpv.git synced 2024-09-20 03:52:22 +02:00

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.
This commit is contained in:
Dudemanguy 2023-08-09 16:39:58 -05:00
parent 9ff2caff98
commit a323dfae42
3 changed files with 7 additions and 5 deletions

View File

@ -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)

View File

@ -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);

View File

@ -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);