From 62f225ef9d6e30c286c6a94f3bef147f7114696c Mon Sep 17 00:00:00 2001 From: Zsolt Vadasz Date: Wed, 13 Jan 2021 16:59:08 +0100 Subject: [PATCH] sub/osd: hide secondary subtitles if secondary-sub-visibility is false --- etc/input.conf | 1 + options/options.c | 2 ++ options/options.h | 1 + player/command.c | 3 +++ sub/dec_sub.c | 5 +++++ sub/dec_sub.h | 2 +- sub/osd.c | 5 ++++- 7 files changed, 17 insertions(+), 2 deletions(-) diff --git a/etc/input.conf b/etc/input.conf index 538443a2e5..63da217f3c 100644 --- a/etc/input.conf +++ b/etc/input.conf @@ -127,6 +127,7 @@ #R add sub-pos +1 # down #t add sub-pos +1 # same as previous binding (discouraged) #v cycle sub-visibility +#Alt+v cycle secondary-sub-visibility # stretch SSA/ASS subtitles with anamorphic videos to match historical #V cycle sub-ass-vsfilter-aspect-compat # switch between applying no style overrides to SSA/ASS subtitles, and diff --git a/options/options.c b/options/options.c index 309626336b..bc903e655a 100644 --- a/options/options.c +++ b/options/options.c @@ -236,6 +236,7 @@ const struct m_sub_options mp_subtitle_sub_opts = { {"sub-fps", OPT_FLOAT(sub_fps)}, {"sub-speed", OPT_FLOAT(sub_speed)}, {"sub-visibility", OPT_FLAG(sub_visibility)}, + {"secondary-sub-visibility", OPT_FLAG(sec_sub_visibility)}, {"sub-forced-only", OPT_CHOICE(forced_subs_only, {"auto", -1}, {"no", 0}, {"yes", 1})}, {"stretch-dvd-subs", OPT_FLAG(stretch_dvd_subs)}, @@ -278,6 +279,7 @@ const struct m_sub_options mp_subtitle_sub_opts = { .size = sizeof(OPT_BASE_STRUCT), .defaults = &(OPT_BASE_STRUCT){ .sub_visibility = 1, + .sec_sub_visibility = 1, .forced_subs_only = -1, .sub_pos = 100, .sub_speed = 1.0, diff --git a/options/options.h b/options/options.h index f28c054500..2d8b5a68b4 100644 --- a/options/options.h +++ b/options/options.h @@ -73,6 +73,7 @@ typedef struct mp_vo_opts { // Subtitle options needed by the subtitle decoders/renderers. struct mp_subtitle_opts { int sub_visibility; + int sec_sub_visibility; int sub_pos; float sub_delay; float sub_fps; diff --git a/player/command.c b/player/command.c index 7e6e5170ef..b3844e4e17 100644 --- a/player/command.c +++ b/player/command.c @@ -3965,6 +3965,9 @@ static const struct property_osd_display { {"sub-visibility", .msg = "Subtitles ${!sub-visibility==yes:hidden}" "${?sub-visibility==yes:visible${?sub==no: (but no subtitles selected)}}"}, + {"secondary-sub-visibility", + .msg = "Secondary Subtitles ${!secondary-sub-visibility==yes:hidden}" + "${?secondary-sub-visibility==yes:visible${?secondary-sid==no: (but no secondary subtitles selected)}}"}, {"sub-forced-only", "Forced sub only"}, {"sub-scale", "Sub Scale"}, {"sub-ass-vsfilter-aspect-compat", "Subtitle VSFilter aspect compat"}, diff --git a/sub/dec_sub.c b/sub/dec_sub.c index ebf3ea35e7..607b97e582 100644 --- a/sub/dec_sub.c +++ b/sub/dec_sub.c @@ -449,3 +449,8 @@ void sub_set_play_dir(struct dec_sub *sub, int dir) sub->play_dir = dir; pthread_mutex_unlock(&sub->lock); } + +bool sub_is_secondary_visible(struct dec_sub *sub) +{ + return !!sub->opts->sec_sub_visibility; +} diff --git a/sub/dec_sub.h b/sub/dec_sub.h index f998b59f6b..542c24798f 100644 --- a/sub/dec_sub.h +++ b/sub/dec_sub.h @@ -10,7 +10,6 @@ struct sh_stream; struct mpv_global; struct demux_packet; struct mp_recorder_sink; - struct dec_sub; struct sd; @@ -52,6 +51,7 @@ void sub_reset(struct dec_sub *sub); void sub_select(struct dec_sub *sub, bool selected); void sub_set_recorder_sink(struct dec_sub *sub, struct mp_recorder_sink *sink); void sub_set_play_dir(struct dec_sub *sub, int dir); +bool sub_is_secondary_visible(struct dec_sub *sub); int sub_control(struct dec_sub *sub, enum sd_ctrl cmd, void *arg); diff --git a/sub/osd.c b/sub/osd.c index de63befe7f..f02693e921 100644 --- a/sub/osd.c +++ b/sub/osd.c @@ -290,9 +290,12 @@ static struct sub_bitmaps *render_object(struct osd_state *osd, check_obj_resize(osd, osdres, obj); - if (obj->type == OSDTYPE_SUB || obj->type == OSDTYPE_SUB2) { + if (obj->type == OSDTYPE_SUB) { if (obj->sub) res = sub_get_bitmaps(obj->sub, obj->vo_res, format, video_pts); + } else if (obj->type == OSDTYPE_SUB2) { + if (obj->sub && sub_is_secondary_visible(obj->sub)) + res = sub_get_bitmaps(obj->sub, obj->vo_res, format, video_pts); } else if (obj->type == OSDTYPE_EXTERNAL2) { if (obj->external2 && obj->external2->format) { res = sub_bitmaps_copy(NULL, obj->external2); // need to be owner