mirror of
https://github.com/mpv-player/mpv
synced 2025-03-20 02:09:52 +00:00
sub: fix possible deadlock with --no-sub-ass and similar
This is a deadlock caused by a lock order issue: sub/osd.c locks the OSD first, then the subtitle decoder lock. player/sub.c does the reverse. Fix this by discussing away the requirement for locking (see below), which allows us to drop the broken sub lock. sub_get_text() still acquires and releases the sub decoder lock, but it's not held at the same time as the OSD lock anymore, so it should be fine. Originally, the sub lock was acquired because sub_get_text() returns a pointer to a mutable string. We simply declare that it's ok to call it unlocked, as long as only 1 thread accesses it, which works out fine in this case.
This commit is contained in:
parent
bdf49d137e
commit
197f18402e
@ -144,15 +144,10 @@ static void update_subtitle(struct MPContext *mpctx, int order)
|
||||
|
||||
// Handle displaying subtitles on terminal; never done for secondary subs
|
||||
if (order == 0) {
|
||||
if (!state.render_bitmap_subs || !mpctx->video_out) {
|
||||
sub_lock(dec_sub);
|
||||
if (!state.render_bitmap_subs || !mpctx->video_out)
|
||||
set_osd_subtitle(mpctx, sub_get_text(dec_sub, curpts_s));
|
||||
sub_unlock(dec_sub);
|
||||
}
|
||||
} else if (order == 1) {
|
||||
sub_lock(dec_sub);
|
||||
osd_set_text(mpctx->osd, obj, sub_get_text(dec_sub, curpts_s));
|
||||
sub_unlock(dec_sub);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -531,6 +531,8 @@ bool sub_has_get_text(struct dec_sub *sub)
|
||||
}
|
||||
|
||||
// See sub_get_bitmaps() for locking requirements.
|
||||
// It can be called unlocked too, but then only 1 thread must call this function
|
||||
// at a time (unless exclusive access is guaranteed).
|
||||
char *sub_get_text(struct dec_sub *sub, double pts)
|
||||
{
|
||||
pthread_mutex_lock(&sub->lock);
|
||||
|
Loading…
Reference in New Issue
Block a user