mirror of
https://github.com/mpv-player/mpv
synced 2025-01-14 19:11:53 +00:00
sub: move sub decoder init to a function
Preparation for timeline rewrite.
This commit is contained in:
parent
733e0b23c8
commit
8aeaa34a5c
@ -46,8 +46,12 @@ struct dec_sub {
|
|||||||
pthread_mutex_t lock;
|
pthread_mutex_t lock;
|
||||||
|
|
||||||
struct mp_log *log;
|
struct mp_log *log;
|
||||||
|
struct mpv_global *global;
|
||||||
struct MPOpts *opts;
|
struct MPOpts *opts;
|
||||||
|
|
||||||
|
struct demuxer *demuxer;
|
||||||
|
struct mp_codec_params *codec;
|
||||||
|
|
||||||
struct sh_stream *sh;
|
struct sh_stream *sh;
|
||||||
double last_pkt_pts;
|
double last_pkt_pts;
|
||||||
|
|
||||||
@ -75,6 +79,31 @@ void sub_destroy(struct dec_sub *sub)
|
|||||||
talloc_free(sub);
|
talloc_free(sub);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct sd *init_decoder(struct dec_sub *sub)
|
||||||
|
{
|
||||||
|
for (int n = 0; sd_list[n]; n++) {
|
||||||
|
const struct sd_functions *driver = sd_list[n];
|
||||||
|
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 = sub->demuxer,
|
||||||
|
.codec = sub->codec,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (sd->driver->init(sd) >= 0)
|
||||||
|
return sd;
|
||||||
|
|
||||||
|
talloc_free(sd);
|
||||||
|
}
|
||||||
|
|
||||||
|
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,
|
// Thread-safety of the returned object: all functions are thread-safe,
|
||||||
// except sub_get_bitmaps() and sub_get_text(). Decoder backends (sd_*)
|
// except sub_get_bitmaps() and sub_get_text(). Decoder backends (sd_*)
|
||||||
// do not need to acquire locks.
|
// do not need to acquire locks.
|
||||||
@ -83,38 +112,23 @@ struct dec_sub *sub_create(struct mpv_global *global, struct demuxer *demuxer,
|
|||||||
{
|
{
|
||||||
assert(demuxer && sh && sh->type == STREAM_SUB);
|
assert(demuxer && sh && sh->type == STREAM_SUB);
|
||||||
|
|
||||||
struct mp_log *log = mp_log_new(NULL, global->log, "sub");
|
struct dec_sub *sub = talloc(NULL, struct dec_sub);
|
||||||
|
*sub = (struct dec_sub){
|
||||||
for (int n = 0; sd_list[n]; n++) {
|
.log = mp_log_new(sub, global->log, "sub"),
|
||||||
const struct sd_functions *driver = sd_list[n];
|
.global = global,
|
||||||
struct dec_sub *sub = talloc_zero(NULL, struct dec_sub);
|
.opts = global->opts,
|
||||||
sub->log = talloc_steal(sub, log),
|
.sh = sh,
|
||||||
sub->opts = global->opts;
|
.codec = sh->codec,
|
||||||
sub->sh = sh;
|
.demuxer = demuxer,
|
||||||
sub->last_pkt_pts = MP_NOPTS_VALUE;
|
.last_pkt_pts = MP_NOPTS_VALUE,
|
||||||
|
};
|
||||||
mpthread_mutex_init_recursive(&sub->lock);
|
mpthread_mutex_init_recursive(&sub->lock);
|
||||||
|
|
||||||
sub->sd = talloc(NULL, struct sd);
|
sub->sd = init_decoder(sub);
|
||||||
*sub->sd = (struct sd){
|
if (sub->sd)
|
||||||
.global = global,
|
|
||||||
.log = mp_log_new(sub->sd, sub->log, driver->name),
|
|
||||||
.opts = sub->opts,
|
|
||||||
.driver = driver,
|
|
||||||
.demuxer = demuxer,
|
|
||||||
.codec = sh->codec,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (sub->sd->driver->init(sub->sd) >= 0)
|
|
||||||
return sub;
|
return sub;
|
||||||
|
|
||||||
ta_set_parent(log, NULL);
|
|
||||||
talloc_free(sub->sd);
|
|
||||||
talloc_free(sub);
|
talloc_free(sub);
|
||||||
}
|
|
||||||
|
|
||||||
mp_err(log, "Could not find subtitle decoder for format '%s'.\n",
|
|
||||||
sh->codec->codec);
|
|
||||||
talloc_free(log);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user