diff options
author | wm4 <wm4@nowhere> | 2020-08-12 17:28:08 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2020-08-12 17:28:25 +0200 |
commit | cda8f1613ff307a9e0b5528743f3e941b05dcee7 (patch) | |
tree | 248182c3e4207b11abd11c39488303c76f4e4c32 /sub | |
parent | 720bcd79d0304dd82e607efa95d421f402c8a3dd (diff) | |
download | mpv-cda8f1613ff307a9e0b5528743f3e941b05dcee7.tar.bz2 mpv-cda8f1613ff307a9e0b5528743f3e941b05dcee7.tar.xz |
sd_ass: force full reinit if certain options change at runtime
Options like --sub-ass-force-style and others could not be changed at
runtime (the changes didn't take any effect). Fix this by using the
brutal approach, and completely reinit the subtitle state when this
happens. Maybe a bit clunky, but for now I'd rather not put more effort
into this.
Fixes: #7689
Diffstat (limited to 'sub')
-rw-r--r-- | sub/osd.c | 2 | ||||
-rw-r--r-- | sub/sd_ass.c | 75 |
2 files changed, 49 insertions, 28 deletions
@@ -66,7 +66,7 @@ static const m_option_t style_opts[] = { {"justify", OPT_CHOICE(justify, {"auto", 0}, {"left", 1}, {"center", 2}, {"right", 3})}, {"font-provider", OPT_CHOICE(font_provider, - {"auto", 0}, {"none", 1}, {"fontconfig", 2})}, + {"auto", 0}, {"none", 1}, {"fontconfig", 2}), .flags = UPDATE_SUB_HARD}, {0} }; diff --git a/sub/sd_ass.c b/sub/sd_ass.c index 46f16908b0..64d8735a7d 100644 --- a/sub/sd_ass.c +++ b/sub/sd_ass.c @@ -197,31 +197,10 @@ static void enable_output(struct sd *sd, bool enable) } } -static int init(struct sd *sd) +static void assobjects_init(struct sd *sd) { + struct sd_ass_priv *ctx = sd->priv; struct mp_subtitle_opts *opts = sd->opts; - struct sd_ass_priv *ctx = talloc_zero(sd, struct sd_ass_priv); - sd->priv = ctx; - - char *extradata = sd->codec->extradata; - int extradata_size = sd->codec->extradata_size; - - // Note: accept "null" as alias for "ass", so EDL delay_open subtitle - // streams work. - if (strcmp(sd->codec->codec, "ass") != 0 && - strcmp(sd->codec->codec, "null") != 0) - { - ctx->is_converted = true; - ctx->converter = lavc_conv_create(sd->log, sd->codec->codec, extradata, - extradata_size); - if (!ctx->converter) - return -1; - extradata = lavc_conv_get_extradata(ctx->converter); - extradata_size = extradata ? strlen(extradata) : 0; - - if (strcmp(sd->codec->codec, "eia_608") == 0) - ctx->duration_unknown = 1; - } ctx->ass_library = mp_ass_init(sd->global, sd->log); ass_set_extract_fonts(ctx->ass_library, opts->use_embedded_fonts); @@ -239,6 +218,8 @@ static int init(struct sd *sd) ctx->shadow_track->PlayResY = 288; mp_ass_add_default_styles(ctx->shadow_track, opts); + char *extradata = sd->codec->extradata; + int extradata_size = sd->codec->extradata_size; if (extradata) ass_process_codec_private(ctx->ass_track, extradata, extradata_size); @@ -249,6 +230,44 @@ static int init(struct sd *sd) #endif enable_output(sd, true); +} + +static void assobjects_destroy(struct sd *sd) +{ + struct sd_ass_priv *ctx = sd->priv; + + ass_free_track(ctx->ass_track); + ass_free_track(ctx->shadow_track); + enable_output(sd, false); + ass_library_done(ctx->ass_library); +} + +static int init(struct sd *sd) +{ + struct sd_ass_priv *ctx = talloc_zero(sd, struct sd_ass_priv); + sd->priv = ctx; + + // Note: accept "null" as alias for "ass", so EDL delay_open subtitle + // streams work. + if (strcmp(sd->codec->codec, "ass") != 0 && + strcmp(sd->codec->codec, "null") != 0) + { + char *extradata = sd->codec->extradata; + int extradata_size = sd->codec->extradata_size; + + ctx->is_converted = true; + ctx->converter = lavc_conv_create(sd->log, sd->codec->codec, extradata, + extradata_size); + if (!ctx->converter) + return -1; + extradata = lavc_conv_get_extradata(ctx->converter); + extradata_size = extradata ? strlen(extradata) : 0; + + if (strcmp(sd->codec->codec, "eia_608") == 0) + ctx->duration_unknown = 1; + } + + assobjects_init(sd); filters_init(sd); ctx->packer = mp_ass_packer_alloc(ctx); @@ -760,10 +779,7 @@ static void uninit(struct sd *sd) filters_destroy(sd); if (ctx->converter) lavc_conv_uninit(ctx->converter); - ass_free_track(ctx->ass_track); - ass_free_track(ctx->shadow_track); - enable_output(sd, false); - ass_library_done(ctx->ass_library); + assobjects_destroy(sd); talloc_free(ctx->copy_cache); } @@ -793,6 +809,11 @@ static int control(struct sd *sd, enum sd_ctrl cmd, void *arg) filters_init(sd); ctx->clear_once = true; // allow reloading on seeks } + if (flags & UPDATE_SUB_HARD) { + assobjects_destroy(sd); + assobjects_init(sd); + MP_WARN(sd, "reoinit\n"); + } return CONTROL_OK; } default: |