[vlc-devel] [PATCH 03/14] Add variable to enable/disable dual subtitles
Roland Bewick
roland.bewick at gmail.com
Sat May 11 08:32:07 CEST 2019
Added "Enable Dual Subtitles" option to QT subtitle menu
---
include/vlc_player.h | 24 +++++++++++++++++++++++
modules/gui/macosx/playlist/VLCPlayerController.m | 1 +
modules/gui/qt/components/player_controller.cpp | 19 ++++++++++++++++++
modules/gui/qt/components/player_controller.hpp | 4 ++++
modules/gui/qt/components/player_controller_p.hpp | 3 ++-
modules/gui/qt/main_interface.cpp | 7 +++++++
modules/gui/qt/main_interface.hpp | 5 +++++
modules/gui/qt/qml/menus/SubtitleMenu.qml | 8 ++++++++
src/input/es_out.c | 3 ++-
src/input/player.c | 11 +++++++++++
src/input/var.c | 1 +
src/libvlc-module.c | 23 ++++++++++++++++++++++
src/libvlccore.sym | 1 +
13 files changed, 108 insertions(+), 2 deletions(-)
diff --git a/include/vlc_player.h b/include/vlc_player.h
index 077b3883ad..c09e226910 100644
--- a/include/vlc_player.h
+++ b/include/vlc_player.h
@@ -695,6 +695,18 @@ struct vlc_player_cbs
*/
void (*on_associated_subs_fps_changed)(vlc_player_t *player,
float subs_fps, void *data);
+
+ /**
+ * Called when dual subtitles enabled has changed
+ *
+ * @see vlc_player_SetDualSubtitlesEnabled()
+ *
+ * @param player locked player instance
+ * @param enabled true if dual subtitle selection is enabled
+ * @param data opaque pointer set by vlc_player_AddListener()
+ */
+ void (*on_dual_subtitles_enabled_changed)(vlc_player_t *player,
+ bool enabled, void *data);
/**
* Called when a new renderer item is set
@@ -2260,6 +2272,18 @@ VLC_API float
vlc_player_GetAssociatedSubsFPS(vlc_player_t *player);
/**
+ * Enable or disable the abiltity to select multiple sub tracks.
+ *
+ * @note A successful call will trigger the
+ * vlc_player_cbs.on_dual_subtitles_enabled_changed event.
+ *
+ * @param player locked player instance
+ * @param enabled Enable dual subtitle track selection
+ */
+VLC_API void
+vlc_player_SetDualSubtitlesEnabled(vlc_player_t *player, bool enabled);
+
+/**
* Set the renderer
*
* Valid for the current media and all future ones.
diff --git a/modules/gui/macosx/playlist/VLCPlayerController.m b/modules/gui/macosx/playlist/VLCPlayerController.m
index 463bee5946..d23770995f 100644
--- a/modules/gui/macosx/playlist/VLCPlayerController.m
+++ b/modules/gui/macosx/playlist/VLCPlayerController.m
@@ -462,6 +462,7 @@ static const struct vlc_player_cbs player_callbacks = {
cb_player_audio_delay_changed,
cb_player_subtitle_delay_changed,
cb_player_associated_subs_fps_changed,
+ NULL, //cb_player_dual_subtitles_enabled_changed
cb_player_renderer_changed,
cb_player_record_changed,
NULL, //cb_player_signal_changed,
diff --git a/modules/gui/qt/components/player_controller.cpp b/modules/gui/qt/components/player_controller.cpp
index e42f7b5b9d..011f9916f6 100644
--- a/modules/gui/qt/components/player_controller.cpp
+++ b/modules/gui/qt/components/player_controller.cpp
@@ -607,6 +607,16 @@ static void on_player_associated_subs_fps_changed(vlc_player_t *, float subs_fps
});
}
+static void on_player_dual_subtitles_enabled_changed(vlc_player_t *, bool enabled, void *data)
+{
+ PlayerControllerPrivate* that = static_cast<PlayerControllerPrivate*>(data);
+ msg_Dbg( that->p_intf, "on_dual_subtitles_enabled_changed");
+ that->callAsync([that,enabled] (){
+ that->m_dualSubtitlesEnabled = enabled;
+ emit that->q_func()->dualSubtitlesEnabledChanged( enabled );
+ });
+}
+
void on_player_renderer_changed(vlc_player_t *, vlc_renderer_item_t *new_item, void *data)
{
VLC_UNUSED(new_item);
@@ -818,6 +828,7 @@ static const struct vlc_player_cbs player_cbs = {
on_player_audio_delay_changed,
on_player_subtitle_delay_changed,
on_player_associated_subs_fps_changed,
+ on_player_dual_subtitles_enabled_changed,
on_player_renderer_changed,
on_player_record_changed,
on_player_signal_changed,
@@ -1055,6 +1066,13 @@ void PlayerController::setSubtitleFPS(float fps)
vlc_player_SetAssociatedSubsFPS( d->m_player, fps );
}
+void PlayerController::setDualSubtitlesEnabled(bool enabled)
+{
+ Q_D(PlayerController);
+ vlc_player_locker lock{ d->m_player };
+ vlc_player_SetDualSubtitlesEnabled( d->m_player, enabled );
+}
+
//TITLE/CHAPTER/MENU
void PlayerController::sectionPrev()
@@ -1471,6 +1489,7 @@ PRIMITIVETYPE_GETTER(bool, isPausable, m_capabilities & VLC_INPUT_CAPABILITIES_P
PRIMITIVETYPE_GETTER(bool, isRecordable, m_capabilities & VLC_INPUT_CAPABILITIES_RECORDABLE)
PRIMITIVETYPE_GETTER(bool, isRateChangable, m_capabilities & VLC_INPUT_CAPABILITIES_CHANGE_RATE)
PRIMITIVETYPE_GETTER(float, getSubtitleFPS, m_subtitleFPS)
+PRIMITIVETYPE_GETTER(bool, areDualSubtitlesEnabled, m_dualSubtitlesEnabled)
PRIMITIVETYPE_GETTER(bool, hasVideoOutput, m_hasVideo)
PRIMITIVETYPE_GETTER(float, getBuffering, m_buffering)
PRIMITIVETYPE_GETTER(PlayerController::MediaStopAction, getMediaStopAction, m_mediaStopAction)
diff --git a/modules/gui/qt/components/player_controller.hpp b/modules/gui/qt/components/player_controller.hpp
index cdf7c8129d..dc474d836f 100644
--- a/modules/gui/qt/components/player_controller.hpp
+++ b/modules/gui/qt/components/player_controller.hpp
@@ -125,6 +125,7 @@ public:
Q_PROPERTY(VLCTick audioDelay READ getAudioDelay WRITE setAudioDelay NOTIFY audioDelayChanged)
Q_PROPERTY(VLCTick subtitleDelay READ getSubtitleDelay WRITE setSubtitleDelay NOTIFY subtitleDelayChanged)
Q_PROPERTY(float subtitleFPS READ getSubtitleFPS WRITE setSubtitleFPS NOTIFY subtitleFPSChanged)
+ Q_PROPERTY(bool dualSubtitlesEnabled READ areDualSubtitlesEnabled WRITE setDualSubtitlesEnabled NOTIFY dualSubtitlesEnabledChanged)
//title/chapters/menu
Q_PROPERTY(TitleListModel* titles READ getTitles CONSTANT)
@@ -271,6 +272,8 @@ public slots:
void setSubtitleDelay( VLCTick );
float getSubtitleFPS( ) const;
void setSubtitleFPS( float );
+ bool areDualSubtitlesEnabled() const;
+ void setDualSubtitlesEnabled( bool );
//title/chapters/menu
TitleListModel* getTitles();
@@ -353,6 +356,7 @@ signals:
void audioDelayChanged(VLCTick);
void subtitleDelayChanged(VLCTick);
void subtitleFPSChanged(float);
+ void dualSubtitlesEnabledChanged(bool);
//title/chapters/menu
void hasTitlesChanged( bool );
diff --git a/modules/gui/qt/components/player_controller_p.hpp b/modules/gui/qt/components/player_controller_p.hpp
index 3a52205aa2..c03da62da7 100644
--- a/modules/gui/qt/components/player_controller_p.hpp
+++ b/modules/gui/qt/components/player_controller_p.hpp
@@ -91,7 +91,8 @@ public:
VLCTick m_audioDelay = 0;
VLCTick m_subtitleDelay = 0;
- float m_subtitleFPS = 1.0;
+ float m_subtitleFPS = 1.0;
+ bool m_dualSubtitlesEnabled = false;
//title/chapters/menu
TitleListModel m_titleList;
diff --git a/modules/gui/qt/main_interface.cpp b/modules/gui/qt/main_interface.cpp
index ef185c3f25..ebb341ddfc 100644
--- a/modules/gui/qt/main_interface.cpp
+++ b/modules/gui/qt/main_interface.cpp
@@ -550,6 +550,13 @@ void MainInterface::setInterfaceAlwaysOnTop( bool on_top )
emit interfaceAlwaysOnTopChanged(on_top);
}
+void MainInterface::setDualSubtitlesEnabled( bool enabled )
+{
+ b_dualSubtitlesEnabled = enabled;
+ THEMIM->setDualSubtitlesEnabled(enabled);
+ emit dualSubtitlesEnabledChanged(enabled);
+}
+
/* Asynchronous calls for video window contrlos */
int MainInterface::enableVideo( vout_window_t *p_wnd,
const vout_window_cfg_t *cfg )
diff --git a/modules/gui/qt/main_interface.hpp b/modules/gui/qt/main_interface.hpp
index 3ceb91b40f..eab8500db9 100644
--- a/modules/gui/qt/main_interface.hpp
+++ b/modules/gui/qt/main_interface.hpp
@@ -66,6 +66,7 @@ class MainInterface : public QVLCMW
Q_PROPERTY(bool interfaceAlwaysOnTop READ isInterfaceAlwaysOnTop WRITE setInterfaceAlwaysOnTop NOTIFY interfaceAlwaysOnTopChanged)
Q_PROPERTY(bool interfaceFullScreen READ isInterfaceFullScreen WRITE setInterfaceFullScreen NOTIFY interfaceFullScreenChanged)
Q_PROPERTY(bool hasEmbededVideo READ hasEmbededVideo NOTIFY hasEmbededVideoChanged)
+ Q_PROPERTY(bool dualSubtitlesEnabled READ areDualSubtitlesEnabled WRITE setDualSubtitlesEnabled NOTIFY dualSubtitlesEnabledChanged)
Q_PROPERTY(VLCVarChoiceModel* extraInterfaces READ getExtraInterfaces CONSTANT)
public:
@@ -113,6 +114,7 @@ public:
bool isInterfaceFullScreen() { return b_interfaceFullScreen; }
bool isInterfaceAlwaysOnTop() { return b_interfaceOnTop; }
bool hasEmbededVideo() { return m_hasEmbededVideo; }
+ bool areDualSubtitlesEnabled() { return b_dualSubtitlesEnabled; }
QList<QQmlError> qmlErrors() const;
protected:
@@ -137,6 +139,7 @@ protected:
/* */
void setInterfaceFullScreen( bool );
+ void setDualSubtitlesEnabled( bool );
void computeMinimumSize();
/* */
@@ -187,6 +190,7 @@ protected:
bool b_plDocked; ///< Is the playlist docked ?
bool b_hasPausedWhenMinimized;
+ bool b_dualSubtitlesEnabled;
static const Qt::Key kc[10]; /* easter eggs */
int i_kc_offset;
@@ -245,6 +249,7 @@ signals:
void interfaceAlwaysOnTopChanged(bool);
void interfaceFullScreenChanged(bool);
void hasEmbededVideoChanged(bool);
+ void dualSubtitlesEnabledChanged(bool);
};
#endif
diff --git a/modules/gui/qt/qml/menus/SubtitleMenu.qml b/modules/gui/qt/qml/menus/SubtitleMenu.qml
index 7ac1a9da29..0c74076516 100644
--- a/modules/gui/qt/qml/menus/SubtitleMenu.qml
+++ b/modules/gui/qt/qml/menus/SubtitleMenu.qml
@@ -32,4 +32,12 @@ Utils.MenuExt {
enabled: player.isPlaying
model: player.subtitleTracks
}
+
+ Action {
+ text: qsTr("&Enable Dual Subtitles")
+ checkable: true
+ enabled: player.isPlaying
+ checked: rootWindow.dualSubtitlesEnabled
+ onTriggered: rootWindow.dualSubtitlesEnabled = !rootWindow.dualSubtitlesEnabled
+ }
}
diff --git a/src/input/es_out.c b/src/input/es_out.c
index a9f4e3012b..1f2afca557 100644
--- a/src/input/es_out.c
+++ b/src/input/es_out.c
@@ -2081,7 +2081,8 @@ static void EsOutSelect( es_out_t *out, es_out_id_t *es, bool b_force )
bool b_select_secondary_subtitle = es->fmt.i_cat == SPU_ES &&
p_sys->b_multiple_subtitle_selection &&
p_esprops->p_main_es != NULL &&
- EsIsSelected(p_esprops->p_main_es);
+ EsIsSelected(p_esprops->p_main_es) &&
+ var_GetBool( p_sys->p_input, "multiple-spus" );
if ( b_select_secondary_subtitle &&
EsOutCountSelected( p_sys, es->fmt.i_cat ) > 1 )
diff --git a/src/input/player.c b/src/input/player.c
index 843f86000c..47298e9fcd 100644
--- a/src/input/player.c
+++ b/src/input/player.c
@@ -2155,6 +2155,17 @@ vlc_player_GetAssociatedSubsFPS(vlc_player_t *player)
return var_GetFloat(player, "sub-fps");
}
+void
+vlc_player_SetDualSubtitlesEnabled(vlc_player_t *player, bool enabled)
+{
+ struct vlc_player_input *input = vlc_player_get_input_locked(player);
+ if (input)
+ {
+ var_SetBool(input->thread, "multiple-spus", enabled);
+ vlc_player_SendEvent(player, on_dual_subtitles_enabled_changed, enabled);
+ }
+}
+
void
vlc_player_InvalidateNextMedia(vlc_player_t *player)
{
diff --git a/src/input/var.c b/src/input/var.c
index 7822d66003..9110624eab 100644
--- a/src/input/var.c
+++ b/src/input/var.c
@@ -726,6 +726,7 @@ void input_ConfigVarInit ( input_thread_t *p_input )
var_Create( p_input, "video", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
var_Create( p_input, "audio", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
var_Create( p_input, "spu", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
+ var_Create( p_input, "multiple-spus", VLC_VAR_BOOL);
var_Create( p_input, "video-track", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
var_Create( p_input, "audio-track", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
diff --git a/src/libvlc-module.c b/src/libvlc-module.c
index aeddd1844b..aef485b45a 100644
--- a/src/libvlc-module.c
+++ b/src/libvlc-module.c
@@ -370,6 +370,11 @@ static const char *const ppsz_pos_descriptions[] =
{ N_("Center"), N_("Left"), N_("Right"), N_("Top"), N_("Bottom"),
N_("Top-Left"), N_("Top-Right"), N_("Bottom-Left"), N_("Bottom-Right") };
+static const int pi_sub_align_values[] = { -1, 0, 1, 2, 4, 8, 5, 6, 9, 10 };
+static const char *const ppsz_sub_align_descriptions[] =
+{ N_("Unset"), N_("Center"), N_("Left"), N_("Right"), N_("Top"), N_("Bottom"),
+ N_("Top-Left"), N_("Top-Right"), N_("Bottom-Left"), N_("Bottom-Right") };
+
#define SS_TEXT N_("Disable screensaver")
#define SS_LONGTEXT N_("Disable the screensaver during video playback." )
@@ -742,6 +747,15 @@ static const char *const ppsz_prefres[] = {
#define SPU_LONGTEXT N_( \
"You can completely disable the sub-picture processing.")
+#define SECONDARY_SPU_POSITION_TEXT N_("Position of secondary subtitles")
+#define SECONDARY_SPU_POSITION_LONGTEXT N_( \
+ "Place on video where to display secondary subtitles (default bottom center).")
+
+#define SECONDARY_SUB_MARGIN_TEXT N_("Force secondary subtitle position")
+#define SECONDARY_SUB_MARGIN_LONGTEXT N_( \
+ "You can use this option to vertically adjust the position secondary " \
+ "subtitles are displayed.")
+
#define OSD_TEXT N_("On Screen Display")
#define OSD_LONGTEXT N_( \
"VLC can display messages on the video. This is called OSD (On Screen " \
@@ -1752,6 +1766,15 @@ vlc_module_begin ()
add_module_list("sub-filter", "sub filter", NULL,
SUB_FILTER_TEXT, SUB_FILTER_LONGTEXT)
+ set_section( N_( "Dual Subtitles" ) , NULL )
+ add_integer( "secondary-spu-alignment", -1, SECONDARY_SPU_POSITION_TEXT,
+ SECONDARY_SPU_POSITION_LONGTEXT, false )
+ change_integer_list( pi_sub_align_values, ppsz_sub_align_descriptions )
+ /* Push the secondary subtitles up a bit so they won't overlap with
+ the primary subtitles using the default settings.*/
+ add_integer( "secondary-sub-margin", 100, SECONDARY_SUB_MARGIN_TEXT,
+ SECONDARY_SUB_MARGIN_LONGTEXT, true )
+
/* Input options */
set_category( CAT_INPUT )
set_subcategory( SUBCAT_INPUT_GENERAL )
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index d0070d42b8..175d9a9639 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -869,6 +869,7 @@ vlc_player_SetSubtitleDelay
vlc_player_SetSubtitleSync
vlc_player_SetSubtitleTextScale
vlc_player_SetSubtitleMultipleSelection
+vlc_player_SetDualSubtitlesEnabled
vlc_player_SetTeletextEnabled
vlc_player_SetTeletextTransparency
vlc_player_SetTrackCategoryEnabled
--
2.11.0
More information about the vlc-devel
mailing list