path: root/sub/sd_ass.c
diff options
authorwm4 <wm4@nowhere>2015-07-06 21:55:37 +0200
committerwm4 <wm4@nowhere>2015-07-06 21:55:37 +0200
commit385febe27632075160c903a22502fcb78b160ae4 (patch)
tree8b9019f75492b42c22000558a9507294095eb1e5 /sub/sd_ass.c
parentdcd167ca37fcb14719f97ca637ec5f3efc3952d8 (diff)
sub: protect ASS_Renderer state
Each subtitle track gets its own decoder instance (sd_ass). But they use a shared ASS_Renderer. This is done mainly because of fontconfig. Initializing fontconfig is very slow when using it with memory fonts, so there's a practical need to cache this memory font state, which is done by not creating separate ASS_Renderers. This is very dirty and very evil, but we probably can't get rid of it any time soon. The shared ASS_Renderer was not properly synchronized. While the program logic guarantees that only one sd_ass instance is visible at a time, there are other interactions that require synchronization. In particular, I suspect concurrent execution of mp_ass_configure_fonts() and sd_ass.get_bitmaps cause issues in a newer libass development branch. So here's a shitty hack that hopefully fixes things, hopefully only until libass becomes less dependent on fontconfig.
Diffstat (limited to 'sub/sd_ass.c')
1 files changed, 9 insertions, 1 deletions
diff --git a/sub/sd_ass.c b/sub/sd_ass.c
index 6f3e24a6f9..f8b1180560 100644
--- a/sub/sd_ass.c
+++ b/sub/sd_ass.c
@@ -59,7 +59,7 @@ static bool supports_format(const char *format)
static int init(struct sd *sd)
struct MPOpts *opts = sd->opts;
- if (!sd->ass_library || !sd->ass_renderer || !sd->codec)
+ if (!sd->ass_library || !sd->ass_renderer || !sd->ass_lock || !sd->codec)
return -1;
struct sd_ass_priv *ctx = talloc_zero(NULL, struct sd_ass_priv);
@@ -67,6 +67,8 @@ static int init(struct sd *sd)
ctx->is_converted = sd->converted_from != NULL;
+ pthread_mutex_lock(sd->ass_lock);
ctx->ass_track = ass_new_track(sd->ass_library);
if (!ctx->is_converted)
ctx->ass_track->track_type = TRACK_TYPE_ASS;
@@ -78,6 +80,8 @@ static int init(struct sd *sd)
mp_ass_add_default_styles(ctx->ass_track, opts);
+ pthread_mutex_unlock(sd->ass_lock);
return 0;
@@ -197,6 +201,8 @@ static void get_bitmaps(struct sd *sd, struct mp_osd_res dim, double pts,
if (pts == MP_NOPTS_VALUE || !sd->ass_renderer)
+ pthread_mutex_lock(sd->ass_lock);
ASS_Renderer *renderer = sd->ass_renderer;
double scale = dim.display_par;
if (!ctx->is_converted && (!opts->ass_style_override ||
@@ -224,6 +230,8 @@ static void get_bitmaps(struct sd *sd, struct mp_osd_res dim, double pts,
if (!ctx->is_converted)
mangle_colors(sd, res);
+ pthread_mutex_unlock(sd->ass_lock);
struct buf {