[vlc-devel] [PATCH 06/10] Hotkey support for secondary subtitles (Part 1) - Toggle control of primary/secondary subtitles - Adjust Secondary subtitle margin (NB: Margin is only applied the first time the subtitle is rendered.)
Roland Bewick
roland.bewick at gmail.com
Sun May 5 12:01:46 CEST 2019
---
include/vlc_actions.h | 2 ++
modules/control/hotkeys.c | 18 ++++++++++++++++--
src/input/player.c | 5 ++++-
src/libvlc-module.c | 6 ++++++
src/misc/actions.c | 1 +
src/video_output/video_output.c | 4 ++--
src/video_output/vout_internal.h | 4 ++--
src/video_output/vout_intf.c | 21 ++++++++++++++++++++-
src/video_output/vout_subpictures.c | 9 ++++++---
9 files changed, 59 insertions(+), 11 deletions(-)
diff --git a/include/vlc_actions.h b/include/vlc_actions.h
index 62f0afae53..e8e2224c80 100644
--- a/include/vlc_actions.h
+++ b/include/vlc_actions.h
@@ -191,6 +191,8 @@ typedef enum vlc_action_id {
ACTIONID_SUBDELAY_UP,
/* subtitle toggle */
ACTIONID_SUBTITLE_TOGGLE,
+ /* dual subtitle control */
+ ACTIONID_SUBTITLE_CONTROL_SECONDARY,
/* subtitle sync */
ACTIONID_SUBSYNC_MARKAUDIO,
ACTIONID_SUBSYNC_MARKSUB,
diff --git a/modules/control/hotkeys.c b/modules/control/hotkeys.c
index 774d833b87..d520d8a7ed 100644
--- a/modules/control/hotkeys.c
+++ b/modules/control/hotkeys.c
@@ -51,6 +51,8 @@ struct intf_sys_t
static void handle_action(intf_thread_t *, vlc_action_id_t);
+static bool b_control_secondary_subtitles = false;
+
/*****************************
* interface action handling *
*****************************/
@@ -447,6 +449,14 @@ PLAYER_ACTION_HANDLER(ToggleSubtitle)
vlc_player_ToggleSubtitle(player);
}
+PLAYER_ACTION_HANDLER(ControlSubtitleSecondary)
+{
+ VLC_UNUSED(action_id);
+ b_control_secondary_subtitles = !b_control_secondary_subtitles;
+ vlc_player_vout_OSDMessage(player, _("%s subtitle control"),
+ b_control_secondary_subtitles ? "Secondary" : "Primary");
+}
+
PLAYER_ACTION_HANDLER(SyncSubtitle)
{
switch (action_id)
@@ -762,13 +772,15 @@ VOUT_ACTION_HANDLER(Deinterlace)
VOUT_ACTION_HANDLER(SubtitleDisplay)
{
+ char* psz_sub_margin = b_control_secondary_subtitles ?
+ "secondary-sub-margin" : "sub-margin";
switch (action_id)
{
case ACTIONID_SUBPOS_DOWN:
- var_DecInteger(vout, "sub-margin");
+ var_DecInteger(vout, psz_sub_margin);
break;
case ACTIONID_SUBPOS_UP:
- var_IncInteger(vout, "sub-margin");
+ var_IncInteger(vout, psz_sub_margin);
break;
default:
{
@@ -858,6 +870,8 @@ static struct vlc_action const actions[] =
VLC_ACTION_PLAYER(AUDIODELAY_DOWN, SUBDELAY_UP, Delay, true)
VLC_ACTION_PLAYER(RATE_NORMAL, RATE_FASTER_FINE, Rate, true)
VLC_ACTION_PLAYER(SUBTITLE_TOGGLE, SUBTITLE_TOGGLE, ToggleSubtitle, true)
+ VLC_ACTION_PLAYER(SUBTITLE_CONTROL_SECONDARY, SUBTITLE_CONTROL_SECONDARY,
+ ControlSubtitleSecondary, true)
VLC_ACTION_PLAYER(SUBSYNC_MARKAUDIO, SUBSYNC_RESET, SyncSubtitle, true)
VLC_ACTION_PLAYER(NAV_ACTIVATE, NAV_RIGHT, Navigate, true)
VLC_ACTION_PLAYER(VIEWPOINT_FOV_IN, VIEWPOINT_ROLL_ANTICLOCK, Viewpoint, true)
diff --git a/src/input/player.c b/src/input/player.c
index 977fc95d94..483f6f0947 100644
--- a/src/input/player.c
+++ b/src/input/player.c
@@ -1795,7 +1795,7 @@ vlc_player_input_HandleVoutEvent(struct vlc_player_input *input,
static const char osd_vars[][sizeof("deinterlace-mode")] = {
"aspect-ratio", "autoscale", "crop", "crop-bottom",
"crop-top", "crop-left", "crop-right", "deinterlace",
- "deinterlace-mode", "sub-margin", "zoom"
+ "deinterlace-mode", "sub-margin", "secondary-sub-margin", "zoom"
};
vlc_player_t *player = input->player;
@@ -3287,6 +3287,9 @@ vlc_player_VoutOSDCallback(vlc_object_t *this, const char *var,
else if (strcmp(var, "sub-margin") == 0)
vouts_osd_Message(&vout, 1, _("Subtitle position %d px"), newval.i_int);
+
+ else if (strcmp(var, "secondary-sub-margin") == 0)
+ vouts_osd_Message(&vout, 1, _("Secondary subtitle position %d px"), newval.i_int);
else if (strcmp(var, "sub-text-scale") == 0)
vouts_osd_Message(&vout, 1, _("Subtitle text scale %d%%"), newval.i_int);
diff --git a/src/libvlc-module.c b/src/libvlc-module.c
index bbc21a32a5..c6e793695f 100644
--- a/src/libvlc-module.c
+++ b/src/libvlc-module.c
@@ -1460,6 +1460,8 @@ static const char *const mouse_wheel_texts[] = {
#define SUBTITLE_TRACK_KEY_LONGTEXT N_("Cycle through the available subtitle tracks.")
#define SUBTITLE_TOGGLE_KEY_TEXT N_("Toggle subtitles")
#define SUBTITLE_TOGGLE_KEY_LONGTEXT N_("Toggle subtitle track visibility.")
+#define SUBTITLE_CONTROL_SECONDARY_KEY_TEXT N_("Toggle secondary subtitle control")
+#define SUBTITLE_CONTROL_SECONDARY_KEY_LONGTEXT N_("Use original subtitle controls to manage secondary subtitles.")
#define PROGRAM_SID_NEXT_KEY_TEXT N_("Cycle next program Service ID")
#define PROGRAM_SID_NEXT_KEY_LONGTEXT N_("Cycle through the available next program Service IDs (SIDs).")
#define PROGRAM_SID_PREV_KEY_TEXT N_("Cycle previous program Service ID")
@@ -2360,6 +2362,7 @@ vlc_module_begin ()
# define KEY_AUDIO_TRACK "l"
# define KEY_SUBTITLE_TRACK "s"
# define KEY_SUBTITLE_TOGGLE "Shift+s"
+# define KEY_SUBTITLE_CONTROL_S "Command+Shift+v"
# define KEY_SUBTITLE_REVTRACK "Alt+s"
# define KEY_PROGRAM_SID_NEXT "x"
# define KEY_PROGRAM_SID_PREV "Shift+x"
@@ -2503,6 +2506,7 @@ vlc_module_begin ()
# define KEY_AUDIO_TRACK "b"
# define KEY_SUBTITLE_TRACK "v"
# define KEY_SUBTITLE_TOGGLE "Shift+v"
+# define KEY_SUBTITLE_CONTROL_S "Ctrl+Shift+v"
# define KEY_SUBTITLE_REVTRACK "Alt+v"
# define KEY_PROGRAM_SID_NEXT "x"
# define KEY_PROGRAM_SID_PREV "Shift+x"
@@ -2672,6 +2676,8 @@ vlc_module_begin ()
SUBTITLE_TRACK_KEY_TEXT, SUBTITLE_TRACK_KEY_LONGTEXT)
add_key("key-subtitle-toggle", KEY_SUBTITLE_TOGGLE,
SUBTITLE_TOGGLE_KEY_TEXT, SUBTITLE_TOGGLE_KEY_LONGTEXT)
+ add_key("key-subtitle-control-secondary", KEY_SUBTITLE_CONTROL_S,
+ SUBTITLE_CONTROL_SECONDARY_KEY_TEXT, SUBTITLE_CONTROL_SECONDARY_KEY_LONGTEXT)
add_key("key-program-sid-next", KEY_PROGRAM_SID_NEXT,
PROGRAM_SID_NEXT_KEY_TEXT, PROGRAM_SID_NEXT_KEY_LONGTEXT)
add_key("key-program-sid-prev", KEY_PROGRAM_SID_PREV,
diff --git a/src/misc/actions.c b/src/misc/actions.c
index e10eb94790..b6e76e75d9 100644
--- a/src/misc/actions.c
+++ b/src/misc/actions.c
@@ -347,6 +347,7 @@ static const struct name2action
{ "subsync-markaudio", ACTIONID_SUBSYNC_MARKAUDIO, },
{ "subsync-marksub", ACTIONID_SUBSYNC_MARKSUB, },
{ "subsync-reset", ACTIONID_SUBSYNC_RESET, },
+ { "subtitle-control-secondary", ACTIONID_SUBTITLE_CONTROL_SECONDARY, },
{ "subtitle-revtrack", ACTIONID_SUBTITLE_REVERSE_TRACK, },
{ "subtitle-text-scale-down", ACTIONID_SUBTITLE_TEXT_SCALE_DOWN, },
{ "subtitle-text-scale-normal", ACTIONID_SUBTITLE_TEXT_SCALE_NORMAL, },
diff --git a/src/video_output/video_output.c b/src/video_output/video_output.c
index 4043369b6f..39136e1275 100644
--- a/src/video_output/video_output.c
+++ b/src/video_output/video_output.c
@@ -572,13 +572,13 @@ void vout_ControlChangeSubFilters(vout_thread_t *vout, const char *filters)
vlc_mutex_unlock(&vout->p->spu_lock);
}
-void vout_ChangeSubMargin(vout_thread_t *vout, int margin)
+void vout_ChangeSubMargin(vout_thread_t *vout, int margin, bool b_secondary)
{
if (unlikely(vout->p->spu == NULL))
return;
vlc_mutex_lock(&vout->p->spu_lock);
- spu_ChangeMargin(vout->p->spu, margin);
+ spu_ChangeMargin(vout->p->spu, margin, b_secondary);
vlc_mutex_unlock(&vout->p->spu_lock);
}
diff --git a/src/video_output/vout_internal.h b/src/video_output/vout_internal.h
index 9e4473b384..2375418a60 100644
--- a/src/video_output/vout_internal.h
+++ b/src/video_output/vout_internal.h
@@ -237,7 +237,7 @@ void vout_ChangeCropBorder(vout_thread_t *, int left, int top, int right, int bo
void vout_ControlChangeFilters(vout_thread_t *, const char *);
void vout_ControlChangeSubSources(vout_thread_t *, const char *);
void vout_ControlChangeSubFilters(vout_thread_t *, const char *);
-void vout_ChangeSubMargin(vout_thread_t *, int);
+void vout_ChangeSubMargin(vout_thread_t *, int, bool b_secondary);
void vout_ChangeViewpoint( vout_thread_t *, const vlc_viewpoint_t *);
/* */
@@ -259,7 +259,7 @@ void spu_Detach( spu_t * );
void spu_clock_Set(spu_t *, vlc_clock_t *, bool b_secondary);
void spu_clock_Reset(spu_t *, bool b_secondary);
void spu_clock_SetDelay(spu_t *spu, vlc_tick_t delay, bool b_secondary);
-void spu_ChangeMargin(spu_t *, int);
+void spu_ChangeMargin(spu_t *, int, bool b_secondary);
void spu_SetHighlight(spu_t *, const vlc_spu_highlight_t*);
/**
diff --git a/src/video_output/vout_intf.c b/src/video_output/vout_intf.c
index 260c160ab4..b0a4469a04 100644
--- a/src/video_output/vout_intf.c
+++ b/src/video_output/vout_intf.c
@@ -74,6 +74,8 @@ static int SubFilterCallback( vlc_object_t *, char const *,
vlc_value_t, vlc_value_t, void * );
static int SubMarginCallback( vlc_object_t *, char const *,
vlc_value_t, vlc_value_t, void * );
+static int SecondarySubMarginCallback( vlc_object_t *, char const *,
+ vlc_value_t, vlc_value_t, void * );
static int ViewpointCallback( vlc_object_t *, char const *,
vlc_value_t, vlc_value_t, void * );
@@ -286,6 +288,11 @@ void vout_IntfInit( vout_thread_t *p_vout )
VLC_VAR_INTEGER | VLC_VAR_DOINHERIT | VLC_VAR_ISCOMMAND );
var_AddCallback( p_vout, "sub-margin", SubMarginCallback, NULL );
+ /* Add secondary-sub-margin variable (dual subtitles) */
+ var_Create( p_vout, "secondary-sub-margin",
+ VLC_VAR_INTEGER | VLC_VAR_DOINHERIT | VLC_VAR_ISCOMMAND );
+ var_AddCallback( p_vout, "secondary-sub-margin", SecondarySubMarginCallback, NULL );
+
/* Mouse coordinates */
var_Create( p_vout, "mouse-button-down", VLC_VAR_INTEGER );
var_Create( p_vout, "mouse-moved", VLC_VAR_COORDS );
@@ -309,12 +316,14 @@ void vout_IntfReinit( vout_thread_t *p_vout )
var_TriggerCallback( p_vout, "sub-source" );
var_TriggerCallback( p_vout, "sub-filter" );
var_TriggerCallback( p_vout, "sub-margin" );
+ var_TriggerCallback( p_vout, "secondary-sub-margin" );
}
void vout_IntfDeinit(vlc_object_t *obj)
{
var_DelCallback(obj, "viewpoint", ViewpointCallback, NULL);
var_DelCallback(obj, "sub-margin", SubMarginCallback, NULL);
+ var_DelCallback(obj, "secondary-sub-margin", SecondarySubMarginCallback, NULL);
var_DelCallback(obj, "sub-filter", SubFilterCallback, NULL);
var_DelCallback(obj, "sub-source", SubSourceCallback, NULL);
var_DelCallback(obj, "video-filter", VideoFilterCallback, NULL);
@@ -610,7 +619,17 @@ static int SubMarginCallback( vlc_object_t *p_this, char const *psz_cmd,
vout_thread_t *p_vout = (vout_thread_t *)p_this;
VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
- vout_ChangeSubMargin(p_vout, newval.i_int);
+ vout_ChangeSubMargin(p_vout, newval.i_int, false);
+ return VLC_SUCCESS;
+}
+
+static int SecondarySubMarginCallback( vlc_object_t *p_this, char const *psz_cmd,
+ vlc_value_t oldval, vlc_value_t newval, void *p_data)
+{
+ vout_thread_t *p_vout = (vout_thread_t *)p_this;
+ VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
+
+ vout_ChangeSubMargin(p_vout, newval.i_int, true);
return VLC_SUCCESS;
}
diff --git a/src/video_output/vout_subpictures.c b/src/video_output/vout_subpictures.c
index 52aab98900..7349a22482 100644
--- a/src/video_output/vout_subpictures.c
+++ b/src/video_output/vout_subpictures.c
@@ -94,7 +94,7 @@ struct spu_private_t {
video_palette_t palette; /**< force palette of subpicture */
int secondary_sub_alignment; /**< force alignment for secondary subs */
- int secondary_sub_margin; /**< move the secondary sub vertically */
+ atomic_int secondary_sub_margin;/**< move the secondary sub vertically */
/* Subpiture filters */
char *source_chain_current;
@@ -1855,11 +1855,14 @@ void spu_ChangeFilters(spu_t *spu, const char *filters)
vlc_mutex_unlock(&sys->lock);
}
-void spu_ChangeMargin(spu_t *spu, int margin)
+void spu_ChangeMargin(spu_t *spu, int margin, bool b_secondary)
{
spu_private_t *sys = spu->p;
- atomic_store(&sys->margin, margin);
+ if (!b_secondary)
+ atomic_store(&sys->margin, margin);
+ else
+ atomic_store(&sys->secondary_sub_margin, margin);
}
void spu_SetHighlight(spu_t *spu, const vlc_spu_highlight_t *hl)
--
2.17.1
More information about the vlc-devel
mailing list