summaryrefslogtreecommitdiffstats
path: root/options/options.c
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/options.c
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/options.c')
-rw-r--r--options/options.c171
1 files changed, 99 insertions, 72 deletions
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",