From 92a9f11a0b4fda60c8880014be5920dcf3e95253 Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 17 Jan 2014 23:13:09 +0100 Subject: sub: uglify sub decoder with locking The plan is to make the whole OSD thread-safe, and we start with this. We just put locks on all entry points (fortunately, dec_sub.c and all sd_*.c decoders are very closed off, and only the entry points in dec_sub.h let you access it). I think this is pretty ugly, but at least it's very simple. There's a special case with sub_get_bitmaps(): this function returns pointers to decoder data (specifically, libass images). There's no way to synchronize this internally, so expose sub_lock/sub_unlock functions. To make things simpler, and especially because the lock is sort-of exposed to the outside world, make the locks recursive. Although the only case where this is actually needed (although trivial) is sub_set_extradata(). One corner case are ASS subtitles: for some reason, we keep a single ASS_Renderer instance for subtitles around (probably to avoid rescanning fonts with ordered chapters), and this ASS_Renderer instance is not synchronized. Also, demux_libass.c loads ASS_Track objects, which are directly passed to sd_ass.c. These things are not synchronized (and would be hard to synchronize), and basically we're out of luck. But I think for now, accesses happen reasonably serialized, so there is no actual problem yet, even if we start to access OSD from other threads. --- player/sub.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'player') diff --git a/player/sub.c b/player/sub.c index 734cbcf7e4..6d39ef2299 100644 --- a/player/sub.c +++ b/player/sub.c @@ -136,10 +136,15 @@ static void update_subtitle(struct MPContext *mpctx, int order) // Handle displaying subtitles on terminal; never done for secondary subs if (order == 0) { - if (!osd_obj->render_bitmap_subs || !mpctx->video_out) + if (!osd_obj->render_bitmap_subs || !mpctx->video_out) { + sub_lock(dec_sub); 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_sub(mpctx->osd, osd_obj, sub_get_text(dec_sub, curpts_s)); + sub_unlock(dec_sub); } } -- cgit v1.2.3