summaryrefslogtreecommitdiffstats
path: root/options
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2017-12-29 17:19:25 +0100
committerKevin Mitchell <kevmitch@gmail.com>2018-01-02 14:27:37 -0800
commit6aad532aa39481a8100910612fad039dd75236b9 (patch)
tree53c790d6c66917e66039c25a13cdf27f90bbf0d9 /options
parent3bf7df4a5e1f46248c78e9e596cd8dab6ff57356 (diff)
downloadmpv-6aad532aa39481a8100910612fad039dd75236b9.tar.bz2
mpv-6aad532aa39481a8100910612fad039dd75236b9.tar.xz
options: move most subtitle and OSD rendering options to sub structs
Remove them from the big MPOpts struct and move them to their sub structs. In the places where their fields are used, create a private copy of the structs, instead of accessing the semi-deprecated global option struct instance (mpv_global.opts) directly. This actually makes accessing these options finally thread-safe. They weren't even if they should have for years. (Including some potential for undefined behavior when e.g. the OSD font was changed at runtime.) This is mostly transparent. All options get moved around, but most users of the options just need to access a different struct (changing sd.opts to a different type changes a lot of uses, for example). One thing which has to be considered and could cause potential regressions is that the new option copies must be explicitly updated. sub_update_opts() takes care of this for example. Another thing is that writing to the option structs manually won't work, because the changes won't be propagated to other copies. Apparently the only affected case is the implementation of the sub-step command, which tries to change sub_delay. Handle this one explicitly (osd_changed() doesn't need to be called anymore, because changing the option triggers UPDATE_OSD, and updates the OSD as a consequence). The way the option value is propagated is rather hacky, but for now this will do.
Diffstat (limited to 'options')
-rw-r--r--options/m_config.c14
-rw-r--r--options/m_config.h4
-rw-r--r--options/options.c171
-rw-r--r--options/options.h99
4 files changed, 172 insertions, 116 deletions
diff --git a/options/m_config.c b/options/m_config.c
index 6f22fd50c5..8bf7e0ef91 100644
--- a/options/m_config.c
+++ b/options/m_config.c
@@ -1340,6 +1340,20 @@ void m_config_notify_change_co(struct m_config *config,
}
}
+void m_config_notify_change_opt_ptr(struct m_config *config, void *ptr)
+{
+ for (int n = 0; n < config->num_opts; n++) {
+ struct m_config_option *co = &config->opts[n];
+ if (co->data == ptr) {
+ m_config_notify_change_co(config, co);
+ return;
+ }
+ }
+ // ptr doesn't point to any config->optstruct field declared in the
+ // option list?
+ assert(false);
+}
+
void m_config_cache_set_wakeup_cb(struct m_config_cache *cache,
void (*cb)(void *ctx), void *cb_ctx)
{
diff --git a/options/m_config.h b/options/m_config.h
index fc32ca5bf0..6c4e9b759f 100644
--- a/options/m_config.h
+++ b/options/m_config.h
@@ -201,6 +201,10 @@ int m_config_option_requires_param(struct m_config *config, bstr name);
// Notify m_config_cache users that the option has (probably) changed its value.
void m_config_notify_change_co(struct m_config *config,
struct m_config_option *co);
+// Like m_config_notify_change_co(), but automatically find the option by its
+// pointer within the global option struct (config->optstruct). In practice,
+// it means it works only on fields in MPContext.opts.
+void m_config_notify_change_opt_ptr(struct m_config *config, void *ptr);
bool m_config_is_in_group(struct m_config *config,
const struct m_sub_options *group,
diff --git a/options/options.c b/options/options.c
index 5eb2cb525b..4e40d77a90 100644
--- a/options/options.c
+++ b/options/options.c
@@ -184,6 +184,101 @@ const struct m_sub_options vo_sub_opts = {
};
#undef OPT_BASE_STRUCT
+#define OPT_BASE_STRUCT struct mp_subtitle_opts
+
+const struct m_sub_options mp_subtitle_sub_opts = {
+ .opts = (const struct m_option[]){
+ OPT_FLOAT("sub-delay", sub_delay, 0),
+ OPT_FLOAT("sub-fps", sub_fps, 0),
+ OPT_FLOAT("sub-speed", sub_speed, 0),
+ OPT_FLAG("sub-visibility", sub_visibility, 0),
+ OPT_FLAG("sub-forced-only", forced_subs_only, 0),
+ OPT_FLAG("stretch-dvd-subs", stretch_dvd_subs, 0),
+ OPT_FLAG("stretch-image-subs-to-screen", stretch_image_subs, 0),
+ OPT_FLAG("image-subs-video-resolution", image_subs_video_res, 0),
+ OPT_FLAG("sub-fix-timing", sub_fix_timing, 0),
+ OPT_INTRANGE("sub-pos", sub_pos, 0, 0, 100),
+ OPT_FLOATRANGE("sub-gauss", sub_gauss, 0, 0.0, 3.0),
+ OPT_FLAG("sub-gray", sub_gray, 0),
+ OPT_FLAG("sub-ass", ass_enabled, 0),
+ OPT_FLAG("sub-filter-sdh", sub_filter_SDH, 0),
+ OPT_FLAG("sub-filter-sdh-harder", sub_filter_SDH_harder, 0),
+ OPT_FLOATRANGE("sub-scale", sub_scale, 0, 0, 100),
+ OPT_FLOATRANGE("sub-ass-line-spacing", ass_line_spacing, 0, -1000, 1000),
+ OPT_FLAG("sub-use-margins", sub_use_margins, 0),
+ OPT_FLAG("sub-ass-force-margins", ass_use_margins, 0),
+ OPT_FLAG("sub-ass-vsfilter-aspect-compat", ass_vsfilter_aspect_compat, 0),
+ OPT_CHOICE("sub-ass-vsfilter-color-compat", ass_vsfilter_color_compat, 0,
+ ({"no", 0}, {"basic", 1}, {"full", 2}, {"force-601", 3})),
+ OPT_FLAG("sub-ass-vsfilter-blur-compat", ass_vsfilter_blur_compat, 0),
+ OPT_FLAG("embeddedfonts", use_embedded_fonts, 0),
+ OPT_STRINGLIST("sub-ass-force-style", ass_force_style_list, 0),
+ OPT_STRING("sub-ass-styles", ass_styles_file, M_OPT_FILE),
+ OPT_CHOICE("sub-ass-hinting", ass_hinting, 0,
+ ({"none", 0}, {"light", 1}, {"normal", 2}, {"native", 3})),
+ OPT_CHOICE("sub-ass-shaper", ass_shaper, 0,
+ ({"simple", 0}, {"complex", 1})),
+ OPT_FLAG("sub-ass-justify", ass_justify, 0),
+ OPT_CHOICE("sub-ass-override", ass_style_override, 0,
+ ({"no", 0}, {"yes", 1}, {"force", 3}, {"scale", 4}, {"strip", 5})),
+ OPT_FLAG("sub-scale-by-window", sub_scale_by_window, 0),
+ OPT_FLAG("sub-scale-with-window", sub_scale_with_window, 0),
+ OPT_FLAG("sub-ass-scale-with-window", ass_scale_with_window, 0),
+ OPT_SUBSTRUCT("sub", sub_style, sub_style_conf, 0),
+ OPT_FLAG("sub-clear-on-seek", sub_clear_on_seek, 0),
+ OPT_INTRANGE("teletext-page", teletext_page, 0, 1, 999),
+ {0}
+ },
+ .size = sizeof(OPT_BASE_STRUCT),
+ .defaults = &(OPT_BASE_STRUCT){
+ .sub_visibility = 1,
+ .sub_pos = 100,
+ .sub_speed = 1.0,
+ .ass_enabled = 1,
+ .sub_scale_by_window = 1,
+ .ass_use_margins = 0,
+ .sub_use_margins = 1,
+ .ass_scale_with_window = 0,
+ .sub_scale_with_window = 1,
+ .teletext_page = 100,
+ .sub_scale = 1,
+ .ass_vsfilter_aspect_compat = 1,
+ .ass_vsfilter_color_compat = 1,
+ .ass_vsfilter_blur_compat = 1,
+ .ass_style_override = 1,
+ .ass_shaper = 1,
+ .use_embedded_fonts = 1,
+ },
+ .change_flags = UPDATE_OSD,
+};
+
+#undef OPT_BASE_STRUCT
+#define OPT_BASE_STRUCT struct mp_osd_render_opts
+
+const struct m_sub_options mp_osd_render_sub_opts = {
+ .opts = (const struct m_option[]){
+ OPT_FLOATRANGE("osd-bar-align-x", osd_bar_align_x, 0, -1.0, +1.0),
+ OPT_FLOATRANGE("osd-bar-align-y", osd_bar_align_y, 0, -1.0, +1.0),
+ OPT_FLOATRANGE("osd-bar-w", osd_bar_w, 0, 1, 100),
+ OPT_FLOATRANGE("osd-bar-h", osd_bar_h, 0, 0.1, 50),
+ OPT_SUBSTRUCT("osd", osd_style, osd_style_conf, 0),
+ OPT_FLOATRANGE("osd-scale", osd_scale, 0, 0, 100),
+ OPT_FLAG("osd-scale-by-window", osd_scale_by_window, 0),
+ OPT_FLAG("force-rgba-osd-rendering", force_rgba_osd, 0),
+ {0}
+ },
+ .size = sizeof(OPT_BASE_STRUCT),
+ .defaults = &(OPT_BASE_STRUCT){
+ .osd_bar_align_y = 0.5,
+ .osd_bar_w = 75.0,
+ .osd_bar_h = 3.125,
+ .osd_scale = 1,
+ .osd_scale_by_window = 1,
+ },
+ .change_flags = UPDATE_OSD,
+};
+
+#undef OPT_BASE_STRUCT
#define OPT_BASE_STRUCT struct dvd_opts
const struct m_sub_options dvd_conf = {
@@ -429,55 +524,15 @@ const m_option_t mp_opts[] = {
OPT_PATHLIST("external-files", external_files, 0),
OPT_CLI_ALIAS("external-file", "external-files-append"),
OPT_FLAG("autoload-files", autoload_files, 0),
- OPT_FLOAT("sub-delay", sub_delay, UPDATE_OSD),
- OPT_FLOAT("sub-fps", sub_fps, UPDATE_OSD),
- OPT_FLOAT("sub-speed", sub_speed, UPDATE_OSD),
- OPT_FLAG("sub-visibility", sub_visibility, UPDATE_OSD),
- OPT_FLAG("sub-forced-only", forced_subs_only, UPDATE_OSD),
- OPT_FLAG("stretch-dvd-subs", stretch_dvd_subs, UPDATE_OSD),
- OPT_FLAG("stretch-image-subs-to-screen", stretch_image_subs, UPDATE_OSD),
- OPT_FLAG("image-subs-video-resolution", image_subs_video_res, UPDATE_OSD),
- OPT_FLAG("sub-fix-timing", sub_fix_timing, 0),
OPT_CHOICE("sub-auto", sub_auto, 0,
({"no", -1}, {"exact", 0}, {"fuzzy", 1}, {"all", 2})),
OPT_CHOICE("audio-file-auto", audiofile_auto, 0,
({"no", -1}, {"exact", 0}, {"fuzzy", 1}, {"all", 2})),
- OPT_INTRANGE("sub-pos", sub_pos, UPDATE_OSD, 0, 100),
- OPT_FLOATRANGE("sub-gauss", sub_gauss, UPDATE_OSD, 0.0, 3.0),
- OPT_FLAG("sub-gray", sub_gray, UPDATE_OSD),
- OPT_FLAG("sub-ass", ass_enabled, 0),
- OPT_FLAG("sub-filter-sdh", sub_filter_SDH, 0),
- OPT_FLAG("sub-filter-sdh-harder", sub_filter_SDH_harder, 0),
- OPT_FLOATRANGE("sub-scale", sub_scale, UPDATE_OSD, 0, 100),
- OPT_FLOATRANGE("sub-ass-line-spacing", ass_line_spacing, UPDATE_OSD, -1000, 1000),
- OPT_FLAG("sub-use-margins", sub_use_margins, UPDATE_OSD),
- OPT_FLAG("sub-ass-force-margins", ass_use_margins, UPDATE_OSD),
- OPT_FLAG("sub-ass-vsfilter-aspect-compat", ass_vsfilter_aspect_compat, UPDATE_OSD),
- OPT_CHOICE("sub-ass-vsfilter-color-compat", ass_vsfilter_color_compat, UPDATE_OSD,
- ({"no", 0}, {"basic", 1}, {"full", 2}, {"force-601", 3})),
- OPT_FLAG("sub-ass-vsfilter-blur-compat", ass_vsfilter_blur_compat, UPDATE_OSD),
- OPT_FLAG("embeddedfonts", use_embedded_fonts, 0),
- OPT_STRINGLIST("sub-ass-force-style", ass_force_style_list, UPDATE_OSD),
- OPT_STRING("sub-ass-styles", ass_styles_file, M_OPT_FILE),
- OPT_CHOICE("sub-ass-hinting", ass_hinting, UPDATE_OSD,
- ({"none", 0}, {"light", 1}, {"normal", 2}, {"native", 3})),
- OPT_CHOICE("sub-ass-shaper", ass_shaper, UPDATE_OSD,
- ({"simple", 0}, {"complex", 1})),
- OPT_FLAG("sub-ass-justify", ass_justify, 0),
- OPT_CHOICE("sub-ass-override", ass_style_override, UPDATE_OSD,
- ({"no", 0}, {"yes", 1}, {"force", 3}, {"scale", 4}, {"strip", 5})),
- OPT_FLAG("sub-scale-by-window", sub_scale_by_window, UPDATE_OSD),
- OPT_FLAG("sub-scale-with-window", sub_scale_with_window, UPDATE_OSD),
- OPT_FLAG("sub-ass-scale-with-window", ass_scale_with_window, UPDATE_OSD),
+
+ OPT_SUBSTRUCT("", subs_rend, mp_subtitle_sub_opts, 0),
+ OPT_SUBSTRUCT("", osd_rend, mp_osd_render_sub_opts, 0),
+
OPT_FLAG("osd-bar", osd_bar_visible, UPDATE_OSD),
- OPT_FLOATRANGE("osd-bar-align-x", osd_bar_align_x, UPDATE_OSD, -1.0, +1.0),
- OPT_FLOATRANGE("osd-bar-align-y", osd_bar_align_y, UPDATE_OSD, -1.0, +1.0),
- OPT_FLOATRANGE("osd-bar-w", osd_bar_w, UPDATE_OSD, 1, 100),
- OPT_FLOATRANGE("osd-bar-h", osd_bar_h, UPDATE_OSD, 0.1, 50),
- OPT_SUBSTRUCT("osd", osd_style, osd_style_conf, 0),
- OPT_SUBSTRUCT("sub", sub_style, sub_style_conf, 0),
- OPT_FLAG("sub-clear-on-seek", sub_clear_on_seek, 0),
- OPT_INTRANGE("teletext-page", teletext_page, 0, 1, 999),
//---------------------- libao/libvo options ------------------------
OPT_SETTINGSLIST("ao", audio_driver_list, 0, &ao_obj_list, ),
@@ -513,8 +568,6 @@ const m_option_t mp_opts[] = {
OPT_STRING("title", wintitle, 0),
OPT_STRING("force-media-title", media_title, 0),
- // set aspect ratio of monitor - useful for 16:9 TV-out
- OPT_FLAG("force-rgba-osd-rendering", force_rgba_osd, 0),
OPT_CHOICE_OR_INT("video-rotate", video_rotate, UPDATE_IMGPAR, 0, 359,
({"no", -1})),
OPT_CHOICE_C("video-stereo-mode", video_stereo_mode, UPDATE_IMGPAR,
@@ -533,8 +586,6 @@ const m_option_t mp_opts[] = {
({"0", 0}, {"1", 1}, {"2", 2}, {"3", 3})),
OPT_INTRANGE("osd-duration", osd_duration, 0, 0, 3600000),
OPT_FLAG("osd-fractions", osd_fractions, 0),
- OPT_FLOATRANGE("osd-scale", osd_scale, UPDATE_OSD, 0, 100),
- OPT_FLAG("osd-scale-by-window", osd_scale_by_window, 0),
OPT_DOUBLE("sstep", step_sec, CONF_MIN, 0),
@@ -821,17 +872,6 @@ const struct MPOpts mp_default_opts = {
.video_osd = 1,
.osd_level = 1,
.osd_duration = 1000,
- .osd_bar_align_y = 0.5,
- .osd_bar_w = 75.0,
- .osd_bar_h = 3.125,
- .osd_scale = 1,
- .osd_scale_by_window = 1,
- .sub_scale_by_window = 1,
- .ass_use_margins = 0,
- .sub_use_margins = 1,
- .ass_scale_with_window = 0,
- .sub_scale_with_window = 1,
- .teletext_page = 100,
#if HAVE_LUA
.lua_load_osc = 1,
.lua_load_ytdl = 1,
@@ -878,9 +918,6 @@ const struct MPOpts mp_default_opts = {
[STREAM_SUB] = -2, }, },
.stream_auto_sel = 1,
.audio_display = 1,
- .sub_visibility = 1,
- .sub_pos = 100,
- .sub_speed = 1.0,
.audio_output_format = 0, // AF_FORMAT_UNKNOWN
.playback_speed = 1.,
.pitch_correction = 1,
@@ -889,16 +926,6 @@ const struct MPOpts mp_default_opts = {
.sub_auto = 0,
.audiofile_auto = -1,
.osd_bar_visible = 1,
-#if HAVE_LIBASS
- .ass_enabled = 1,
-#endif
- .sub_scale = 1,
- .ass_vsfilter_aspect_compat = 1,
- .ass_vsfilter_color_compat = 1,
- .ass_vsfilter_blur_compat = 1,
- .ass_style_override = 1,
- .ass_shaper = 1,
- .use_embedded_fonts = 1,
.screenshot_template = "mpv-shot%n",
.hwdec_api = HAVE_RPI ? "mmal" : "no",
diff --git a/options/options.h b/options/options.h
index 211284ff75..3f90a2b78f 100644
--- a/options/options.h
+++ b/options/options.h
@@ -66,6 +66,56 @@ struct mp_cache_opts {
int file_max;
};
+// Subtitle options needed by the subtitle decoders/renderers.
+struct mp_subtitle_opts {
+ int sub_visibility;
+ int sub_pos;
+ float sub_delay;
+ float sub_fps;
+ float sub_speed;
+ int forced_subs_only;
+ int stretch_dvd_subs;
+ int stretch_image_subs;
+ int image_subs_video_res;
+ int sub_fix_timing;
+ int sub_scale_by_window;
+ int sub_scale_with_window;
+ int ass_scale_with_window;
+ struct osd_style_opts *sub_style;
+ float sub_scale;
+ float sub_gauss;
+ int sub_gray;
+ int sub_filter_SDH;
+ int sub_filter_SDH_harder;
+ int ass_enabled;
+ float ass_line_spacing;
+ int ass_use_margins;
+ int sub_use_margins;
+ int ass_vsfilter_aspect_compat;
+ int ass_vsfilter_color_compat;
+ int ass_vsfilter_blur_compat;
+ int use_embedded_fonts;
+ char **ass_force_style_list;
+ char *ass_styles_file;
+ int ass_style_override;
+ int ass_hinting;
+ int ass_shaper;
+ int ass_justify;
+ int sub_clear_on_seek;
+ int teletext_page;
+};
+
+struct mp_osd_render_opts {
+ float osd_bar_align_x;
+ float osd_bar_align_y;
+ float osd_bar_w;
+ float osd_bar_h;
+ float osd_scale;
+ int osd_scale_by_window;
+ struct osd_style_opts *osd_style;
+ int force_rgba_osd;
+};
+
typedef struct MPOpts {
int property_print_help;
int use_terminal;
@@ -113,7 +163,6 @@ typedef struct MPOpts {
char *wintitle;
char *media_title;
- int force_rgba_osd;
struct mp_csp_equalizer_opts *video_equalizer;
@@ -128,6 +177,9 @@ typedef struct MPOpts {
char *video_decoders;
char *audio_spdif;
+ struct mp_subtitle_opts *subs_rend;
+ struct mp_osd_render_opts *osd_rend;
+
int osd_level;
int osd_duration;
int osd_fractions;
@@ -202,17 +254,6 @@ typedef struct MPOpts {
int stream_auto_sel;
int audio_display;
char **display_tags;
- int sub_visibility;
- int sub_pos;
- float sub_delay;
- float sub_fps;
- float sub_speed;
- int forced_subs_only;
- int stretch_dvd_subs;
- int stretch_image_subs;
- int image_subs_video_res;
-
- int sub_fix_timing;
char **audio_files;
char *demuxer_name;
@@ -249,38 +290,6 @@ typedef struct MPOpts {
int sub_auto;
int audiofile_auto;
int osd_bar_visible;
- float osd_bar_align_x;
- float osd_bar_align_y;
- float osd_bar_w;
- float osd_bar_h;
- float osd_scale;
- int osd_scale_by_window;
- int sub_scale_by_window;
- int sub_scale_with_window;
- int ass_scale_with_window;
- struct osd_style_opts *osd_style;
- struct osd_style_opts *sub_style;
- float sub_scale;
- float sub_gauss;
- int sub_gray;
- int sub_filter_SDH;
- int sub_filter_SDH_harder;
- int ass_enabled;
- float ass_line_spacing;
- int ass_use_margins;
- int sub_use_margins;
- int ass_vsfilter_aspect_compat;
- int ass_vsfilter_color_compat;
- int ass_vsfilter_blur_compat;
- int use_embedded_fonts;
- char **ass_force_style_list;
- char *ass_styles_file;
- int ass_style_override;
- int ass_hinting;
- int ass_shaper;
- int ass_justify;
- int sub_clear_on_seek;
- int teletext_page;
char *hwdec_api;
char *hwdec_codecs;
@@ -345,6 +354,8 @@ extern const struct MPOpts mp_default_opts;
extern const struct m_sub_options vo_sub_opts;
extern const struct m_sub_options stream_cache_conf;
extern const struct m_sub_options dvd_conf;
+extern const struct m_sub_options mp_subtitle_sub_opts;
+extern const struct m_sub_options mp_osd_render_sub_opts;
int hwdec_validate_opt(struct mp_log *log, const m_option_t *opt,
struct bstr name, struct bstr param);