mirror of
https://github.com/mpv-player/mpv
synced 2025-04-04 15:34:31 +00:00
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
This commit is contained in:
parent
720bcd79d0
commit
cda8f1613f
@ -420,7 +420,8 @@ char *format_file_size(int64_t size);
|
||||
#define UPDATE_VO_RESIZE (1 << 19) // --android-surface-size
|
||||
#define UPDATE_HWDEC (1 << 20) // --hwdec
|
||||
#define UPDATE_DVB_PROG (1 << 21) // some --dvbin-...
|
||||
#define UPDATE_OPT_LAST (1 << 21)
|
||||
#define UPDATE_SUB_HARD (1 << 22) // subtitle opts. that need full reinit
|
||||
#define UPDATE_OPT_LAST (1 << 22)
|
||||
|
||||
// All bits between _FIRST and _LAST (inclusive)
|
||||
#define UPDATE_OPTS_MASK \
|
||||
|
@ -235,7 +235,7 @@ const struct m_sub_options mp_subtitle_sub_opts = {
|
||||
{"sub-pos", OPT_INT(sub_pos), M_RANGE(0, 100)},
|
||||
{"sub-gauss", OPT_FLOAT(sub_gauss), M_RANGE(0.0, 3.0)},
|
||||
{"sub-gray", OPT_FLAG(sub_gray)},
|
||||
{"sub-ass", OPT_FLAG(ass_enabled)},
|
||||
{"sub-ass", OPT_FLAG(ass_enabled), .flags = UPDATE_SUB_HARD},
|
||||
{"sub-scale", OPT_FLOAT(sub_scale), M_RANGE(0, 100)},
|
||||
{"sub-ass-line-spacing", OPT_FLOAT(ass_line_spacing),
|
||||
M_RANGE(-1000, 1000)},
|
||||
@ -245,9 +245,11 @@ const struct m_sub_options mp_subtitle_sub_opts = {
|
||||
{"sub-ass-vsfilter-color-compat", OPT_CHOICE(ass_vsfilter_color_compat,
|
||||
{"no", 0}, {"basic", 1}, {"full", 2}, {"force-601", 3})},
|
||||
{"sub-ass-vsfilter-blur-compat", OPT_FLAG(ass_vsfilter_blur_compat)},
|
||||
{"embeddedfonts", OPT_FLAG(use_embedded_fonts)},
|
||||
{"sub-ass-force-style", OPT_STRINGLIST(ass_force_style_list)},
|
||||
{"sub-ass-styles", OPT_STRING(ass_styles_file), .flags = M_OPT_FILE},
|
||||
{"embeddedfonts", OPT_FLAG(use_embedded_fonts), .flags = UPDATE_SUB_HARD},
|
||||
{"sub-ass-force-style", OPT_STRINGLIST(ass_force_style_list),
|
||||
.flags = UPDATE_SUB_HARD},
|
||||
{"sub-ass-styles", OPT_STRING(ass_styles_file), .flags = M_OPT_FILE,
|
||||
.flags = UPDATE_SUB_HARD},
|
||||
{"sub-ass-hinting", OPT_CHOICE(ass_hinting,
|
||||
{"none", 0}, {"light", 1}, {"normal", 2}, {"native", 3})},
|
||||
{"sub-ass-shaper", OPT_CHOICE(ass_shaper,
|
||||
|
@ -6362,7 +6362,7 @@ void mp_option_change_callback(void *ctx, struct m_config_option *co, int flags,
|
||||
if (flags & UPDATE_TERM)
|
||||
mp_update_logging(mpctx, false);
|
||||
|
||||
if (flags & (UPDATE_OSD | UPDATE_SUB_FILT)) {
|
||||
if (flags & (UPDATE_OSD | UPDATE_SUB_FILT | UPDATE_SUB_HARD)) {
|
||||
for (int n = 0; n < num_ptracks[STREAM_SUB]; n++) {
|
||||
struct track *track = mpctx->current_track[n][STREAM_SUB];
|
||||
struct dec_sub *sub = track ? track->d_sub : NULL;
|
||||
@ -6372,6 +6372,8 @@ void mp_option_change_callback(void *ctx, struct m_config_option *co, int flags,
|
||||
}
|
||||
}
|
||||
osd_changed(mpctx->osd);
|
||||
if (flags & (UPDATE_SUB_FILT | UPDATE_SUB_HARD))
|
||||
mp_force_video_refresh(mpctx);
|
||||
mp_wakeup_core(mpctx);
|
||||
}
|
||||
|
||||
|
@ -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}
|
||||
};
|
||||
|
||||
|
75
sub/sd_ass.c
75
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:
|
||||
|
Loading…
Reference in New Issue
Block a user