From 8aeaa34a5c9206392a23b1017a47df2c968c43fe Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 15 Feb 2016 20:26:01 +0100 Subject: sub: move sub decoder init to a function Preparation for timeline rewrite. --- sub/dec_sub.c | 74 +++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 44 insertions(+), 30 deletions(-) (limited to 'sub/dec_sub.c') diff --git a/sub/dec_sub.c b/sub/dec_sub.c index 641a5ab1da..5a952e4fd5 100644 --- a/sub/dec_sub.c +++ b/sub/dec_sub.c @@ -46,8 +46,12 @@ struct dec_sub { pthread_mutex_t lock; struct mp_log *log; + struct mpv_global *global; struct MPOpts *opts; + struct demuxer *demuxer; + struct mp_codec_params *codec; + struct sh_stream *sh; double last_pkt_pts; @@ -75,46 +79,56 @@ void sub_destroy(struct dec_sub *sub) talloc_free(sub); } -// Thread-safety of the returned object: all functions are thread-safe, -// except sub_get_bitmaps() and sub_get_text(). Decoder backends (sd_*) -// do not need to acquire locks. -struct dec_sub *sub_create(struct mpv_global *global, struct demuxer *demuxer, - struct sh_stream *sh) +static struct sd *init_decoder(struct dec_sub *sub) { - assert(demuxer && sh && sh->type == STREAM_SUB); - - struct mp_log *log = mp_log_new(NULL, global->log, "sub"); - for (int n = 0; sd_list[n]; n++) { const struct sd_functions *driver = sd_list[n]; - struct dec_sub *sub = talloc_zero(NULL, struct dec_sub); - sub->log = talloc_steal(sub, log), - sub->opts = global->opts; - sub->sh = sh; - sub->last_pkt_pts = MP_NOPTS_VALUE; - mpthread_mutex_init_recursive(&sub->lock); - - sub->sd = talloc(NULL, struct sd); - *sub->sd = (struct sd){ - .global = global, - .log = mp_log_new(sub->sd, sub->log, driver->name), + struct sd *sd = talloc(NULL, struct sd); + *sd = (struct sd){ + .global = sub->global, + .log = mp_log_new(sd, sub->log, driver->name), .opts = sub->opts, .driver = driver, - .demuxer = demuxer, - .codec = sh->codec, + .demuxer = sub->demuxer, + .codec = sub->codec, }; - if (sub->sd->driver->init(sub->sd) >= 0) - return sub; + if (sd->driver->init(sd) >= 0) + return sd; - ta_set_parent(log, NULL); - talloc_free(sub->sd); - talloc_free(sub); + talloc_free(sd); } - mp_err(log, "Could not find subtitle decoder for format '%s'.\n", - sh->codec->codec); - talloc_free(log); + MP_ERR(sub, "Could not find subtitle decoder for format '%s'.\n", + sub->codec->codec); + return NULL; +} + +// Thread-safety of the returned object: all functions are thread-safe, +// except sub_get_bitmaps() and sub_get_text(). Decoder backends (sd_*) +// do not need to acquire locks. +struct dec_sub *sub_create(struct mpv_global *global, struct demuxer *demuxer, + struct sh_stream *sh) +{ + assert(demuxer && sh && sh->type == STREAM_SUB); + + struct dec_sub *sub = talloc(NULL, struct dec_sub); + *sub = (struct dec_sub){ + .log = mp_log_new(sub, global->log, "sub"), + .global = global, + .opts = global->opts, + .sh = sh, + .codec = sh->codec, + .demuxer = demuxer, + .last_pkt_pts = MP_NOPTS_VALUE, + }; + mpthread_mutex_init_recursive(&sub->lock); + + sub->sd = init_decoder(sub); + if (sub->sd) + return sub; + + talloc_free(sub); return NULL; } -- cgit v1.2.3