diff options
author | Dudemanguy <random342@airmail.cc> | 2024-04-14 16:37:32 -0500 |
---|---|---|
committer | Dudemanguy <random342@airmail.cc> | 2024-04-16 19:45:00 +0000 |
commit | 68bcbf66ef4a9bcab1ffd6c5c5cf8fd7fd39bb7e (patch) | |
tree | cc13fceb24c80de887186eb2e5810abe0016978b /player/playloop.c | |
parent | b2836bbaf19a1fe819785f26b697bbd725b4f4df (diff) | |
download | mpv-68bcbf66ef4a9bcab1ffd6c5c5cf8fd7fd39bb7e.tar.bz2 mpv-68bcbf66ef4a9bcab1ffd6c5c5cf8fd7fd39bb7e.tar.xz |
player: avoid busy looping during reinit_sub
If the player is paused, switching subtitle track requires us to read
subs packets for an indefinite amount of time in order to actually
display the subtitles. The problem with this is that it puts a blocking
loop in the play thread which can be slow in cases where it takes a long
time to fetch the subtitle (e.g. over a network).
9e27b1f523071db184443d78f7144cb599dd0829 alleviates this when a pause
happens because of buffering, but it's not complete. One could encounter
this if the user pauses the video first manually and then switches the
subtitle track.
To solve this better, make it so the loop has a time out (totally
arbitrary number) so the player isn't blocked forever. If subtitles are
not fetched within that time, we flag the track and try again later in
the playloop.
Diffstat (limited to 'player/playloop.c')
-rw-r--r-- | player/playloop.c | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/player/playloop.c b/player/playloop.c index bf903e54f7..12239d69ab 100644 --- a/player/playloop.c +++ b/player/playloop.c @@ -803,6 +803,22 @@ int get_cache_buffering_percentage(struct MPContext *mpctx) return mpctx->demuxer ? mpctx->cache_buffer : -1; } +static void handle_update_subtitles(struct MPContext *mpctx) +{ + if (mpctx->video_status == STATUS_EOF) { + update_subtitles(mpctx, mpctx->playback_pts); + return; + } + + for (int n = 0; n < mpctx->num_tracks; n++) { + struct track *track = mpctx->tracks[n]; + if (track->type == STREAM_SUB && !track->demuxer_ready) { + update_subtitles(mpctx, mpctx->playback_pts); + break; + } + } +} + static void handle_cursor_autohide(struct MPContext *mpctx) { struct MPOpts *opts = mpctx->opts; @@ -1233,8 +1249,8 @@ void run_playloop(struct MPContext *mpctx) handle_dummy_ticks(mpctx); update_osd_msg(mpctx); - if (mpctx->video_status == STATUS_EOF) - update_subtitles(mpctx, mpctx->playback_pts); + + handle_update_subtitles(mpctx); handle_each_frame_screenshot(mpctx); |