summaryrefslogtreecommitdiffstats
path: root/options
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2020-02-16 01:02:17 +0100
committerwm4 <wm4@nowhere>2020-02-16 02:07:24 +0100
commit0b35b4c91796fb020e13d955efd450021eb5eedb (patch)
tree2223d7c7f32afc60efb12b0051343e99e6bf727b /options
parente162bcb5a09b5ad514636684314e8e797ab2a47b (diff)
downloadmpv-0b35b4c91796fb020e13d955efd450021eb5eedb.tar.bz2
mpv-0b35b4c91796fb020e13d955efd450021eb5eedb.tar.xz
sub: make filter_sdh a "proper" filter, allow runtime changes
Until now, filter_sdh was simply a function that was called by sd_ass directly (if enabled). I want to add another filter, so it's time to turn this into a somewhat more general subtitle filtering infrastructure. I pondered whether to reuse the audio/video filtering stuff - but better not. Also, since subtitles are horrible and tend to refuse proper abstraction, it's still messed into sd_ass, instead of working on the dec_sub.c level. Actually mpv used to have subtitle "filters" and even made subtitle converters part of it, but it was fairly horrible, so don't do that again. In addition, make runtime changes possible. Since this was supposed to be a quick hack, I just decided to put all subtitle filter options into a separate option group (=> simpler change notification), to manually push the change through the playloop (like it was sort of before for OSD options), and to recreate the sub filter chain completely in every change. Should be good enough. One strangeness is that due to prefetching and such, most subtitle packets (or those some time ahead) are actually done filtering when we change, so the user still needs to manually seek to actually refresh everything. And since subtitle data is usually cached in ASS_Track (for other terrible but user-friendly reasons), we also must clear the subtitle data, but of course only on seek, since otherwise all subtitles would just disappear. What a fucking mess, but such is life. We could trigger a "refresh seek" to make this more automatic, but I don't feel like it currently. This is slightly inefficient (lots of allocations and copying), but I decided that it doesn't matter. Could matter slightly for crazy ASS subtitles that render with thousands of events. Not very well tested. Still seems to work, but I didn't have many test cases.
Diffstat (limited to 'options')
-rw-r--r--options/m_option.h1
-rw-r--r--options/options.c16
-rw-r--r--options/options.h9
3 files changed, 22 insertions, 4 deletions
diff --git a/options/m_option.h b/options/m_option.h
index a78def276b..9eb994a5cf 100644
--- a/options/m_option.h
+++ b/options/m_option.h
@@ -413,6 +413,7 @@ char *format_file_size(int64_t size);
// certain groups of options.
#define UPDATE_OPT_FIRST (1 << 8)
#define UPDATE_TERM (1 << 8) // terminal options
+#define UPDATE_SUB_FILT (1 << 9) // subtitle filter options
#define UPDATE_OSD (1 << 10) // related to OSD rendering
#define UPDATE_BUILTIN_SCRIPTS (1 << 11) // osc/ytdl/stats
#define UPDATE_IMGPAR (1 << 12) // video image params overrides
diff --git a/options/options.c b/options/options.c
index 489f1bc4ed..73cd7ff76c 100644
--- a/options/options.c
+++ b/options/options.c
@@ -195,6 +195,19 @@ const struct m_sub_options vo_sub_opts = {
};
#undef OPT_BASE_STRUCT
+#define OPT_BASE_STRUCT struct mp_sub_filter_opts
+
+const struct m_sub_options mp_sub_filter_opts = {
+ .opts = (const struct m_option[]){
+ OPT_FLAG("sub-filter-sdh", sub_filter_SDH, 0),
+ OPT_FLAG("sub-filter-sdh-harder", sub_filter_SDH_harder, 0),
+ {0}
+ },
+ .size = sizeof(OPT_BASE_STRUCT),
+ .change_flags = UPDATE_SUB_FILT,
+};
+
+#undef OPT_BASE_STRUCT
#define OPT_BASE_STRUCT struct mp_subtitle_opts
const struct m_sub_options mp_subtitle_sub_opts = {
@@ -212,8 +225,6 @@ const struct m_sub_options mp_subtitle_sub_opts = {
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),
@@ -555,6 +566,7 @@ static const m_option_t mp_opts[] = {
({"no", -1}, {"exact", 0}, {"fuzzy", 1}, {"all", 2})),
OPT_SUBSTRUCT("", subs_rend, mp_subtitle_sub_opts, 0),
+ OPT_SUBSTRUCT("", subs_filt, mp_sub_filter_opts, 0),
OPT_SUBSTRUCT("", osd_rend, mp_osd_render_sub_opts, 0),
OPT_FLAG("osd-bar", osd_bar_visible, UPDATE_OSD),
diff --git a/options/options.h b/options/options.h
index bc0f1b3e89..8fbec3161c 100644
--- a/options/options.h
+++ b/options/options.h
@@ -82,8 +82,6 @@ struct mp_subtitle_opts {
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;
@@ -102,6 +100,11 @@ struct mp_subtitle_opts {
int teletext_page;
};
+struct mp_sub_filter_opts {
+ int sub_filter_SDH;
+ int sub_filter_SDH_harder;
+};
+
struct mp_osd_render_opts {
float osd_bar_align_x;
float osd_bar_align_y;
@@ -173,6 +176,7 @@ typedef struct MPOpts {
char *audio_spdif;
struct mp_subtitle_opts *subs_rend;
+ struct mp_sub_filter_opts *subs_filt;
struct mp_osd_render_opts *osd_rend;
int osd_level;
@@ -361,6 +365,7 @@ struct filter_opts {
extern const struct m_sub_options vo_sub_opts;
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_sub_filter_opts;
extern const struct m_sub_options mp_osd_render_sub_opts;
extern const struct m_sub_options filter_conf;
extern const struct m_sub_options resample_conf;