[vlc-devel] [PATCH 12/16] Add hotkey support for secondary subtitles (Part 2)

Roland Bewick roland.bewick at gmail.com
Tue May 21 20:08:36 CEST 2019


- Secondary subtitle delay
---
 include/vlc_input.h                               |  8 ++++-
 include/vlc_player.h                              |  9 +++--
 modules/control/hotkeys.c                         |  3 +-
 modules/gui/macosx/playlist/VLCPlayerController.m |  4 ++-
 modules/gui/qt/components/player_controller.cpp   | 19 +++++++---
 modules/lua/libs/input.c                          |  6 ++--
 src/input/es_out.c                                | 17 ++++++---
 src/input/es_out.h                                |  6 ++--
 src/input/event.h                                 |  5 +--
 src/input/input.c                                 | 39 +++++++++++++++------
 src/input/input_internal.h                        |  4 ++-
 src/input/player.c                                | 42 ++++++++++++++++-------
 src/input/var.c                                   | 12 +++++--
 13 files changed, 125 insertions(+), 49 deletions(-)

diff --git a/include/vlc_input.h b/include/vlc_input.h
index e6bd8440e3..a5f1eb8b16 100644
--- a/include/vlc_input.h
+++ b/include/vlc_input.h
@@ -477,6 +477,12 @@ struct vlc_input_event_vout
     vout_thread_t *vout;
 };
 
+struct vlc_input_event_subtitle_delay
+{
+    vlc_tick_t i_delay;
+    int i_spu_id;
+};
+
 struct vlc_input_event
 {
     input_event_type_e type;
@@ -509,7 +515,7 @@ struct vlc_input_event
         /* INPUT_EVENT_AUDIO_DELAY */
         vlc_tick_t audio_delay;
         /* INPUT_EVENT_SUBTITLE_DELAY */
-        vlc_tick_t subtitle_delay;
+        struct vlc_input_event_subtitle_delay subtitle_delay;
         /* INPUT_EVENT_CACHE */
         float cache;
         /* INPUT_EVENT_VOUT */
diff --git a/include/vlc_player.h b/include/vlc_player.h
index aa0c736782..efbf8d8fd7 100644
--- a/include/vlc_player.h
+++ b/include/vlc_player.h
@@ -679,10 +679,11 @@ struct vlc_player_cbs
      *
      * @param player locked player instance
      * @param new_delay subtitle delay
+     * @param i_spu_id id of selected spu track to apply delay to
      * @param data opaque pointer set by vlc_player_AddListener()
      */
     void (*on_subtitle_delay_changed)(vlc_player_t *player,
-        vlc_tick_t new_delay, void *data);
+        vlc_tick_t new_delay, int i_spu_id, void *data);
 
     /**
      * Called when associated subtitle has changed
@@ -2428,9 +2429,10 @@ vlc_player_SetAudioDelay(vlc_player_t *player, vlc_tick_t delay,
  * @see vlc_player_cbs.on_subtitle_delay_changed
  *
  * @param player locked player instance
+ * @param i_spu_id retrieve delay for specific subtitle track
  */
 VLC_API vlc_tick_t
-vlc_player_GetSubtitleDelay(vlc_player_t *player);
+vlc_player_GetSubtitleDelay(vlc_player_t *player, int i_spu_id);
 
 /**
  * Set subtitle synchronisation
@@ -2461,10 +2463,11 @@ vlc_player_SetSubtitleSync(vlc_player_t *player,
  * @param player locked player instance
  * @param delay a valid time
  * @param whence absolute or relative
+ * @param i_spu_id apply to specific subtitle track
  */
 VLC_API void
 vlc_player_SetSubtitleDelay(vlc_player_t *player, vlc_tick_t delay,
-                            enum vlc_player_whence whence);
+                            enum vlc_player_whence whence, int i_spu_id);
 
 /**
  * Set the subtitle text scaling factor
diff --git a/modules/control/hotkeys.c b/modules/control/hotkeys.c
index 825b803a4a..f30a9cf695 100644
--- a/modules/control/hotkeys.c
+++ b/modules/control/hotkeys.c
@@ -392,7 +392,8 @@ PLAYER_ACTION_HANDLER(Delay)
     if (type == AUDIODELAY)
         vlc_player_SetAudioDelay(player, delta, whence);
     else
-        vlc_player_SetSubtitleDelay(player, delta, whence);
+        vlc_player_SetSubtitleDelay(player, delta, whence,
+                                    i_control_spu_id);
 }
 
 static inline float
diff --git a/modules/gui/macosx/playlist/VLCPlayerController.m b/modules/gui/macosx/playlist/VLCPlayerController.m
index d23770995f..332c436a7a 100644
--- a/modules/gui/macosx/playlist/VLCPlayerController.m
+++ b/modules/gui/macosx/playlist/VLCPlayerController.m
@@ -23,6 +23,7 @@
 #import "VLCPlayerController.h"
 
 #import <vlc_url.h>
+#import <vlc_spu.h>
 
 #import "extensions/NSString+Helpers.h"
 #import "main/VLCMain.h"
@@ -1265,7 +1266,8 @@ static const struct vlc_player_aout_cbs player_aout_callbacks = {
 - (void)setSubtitlesDelay:(vlc_tick_t)subtitlesDelay
 {
     vlc_player_Lock(_p_player);
-    vlc_player_SetSubtitleDelay(_p_player, subtitlesDelay, VLC_PLAYER_WHENCE_ABSOLUTE);
+    vlc_player_SetSubtitleDelay(_p_player, subtitlesDelay,
+                                           VLC_PLAYER_WHENCE_ABSOLUTE, SPU_ID_PRIMARY);
     vlc_player_Unlock(_p_player);
 }
 
diff --git a/modules/gui/qt/components/player_controller.cpp b/modules/gui/qt/components/player_controller.cpp
index 011f9916f6..4f10514c6e 100644
--- a/modules/gui/qt/components/player_controller.cpp
+++ b/modules/gui/qt/components/player_controller.cpp
@@ -31,6 +31,7 @@
 #include <vlc_es.h>
 #include <vlc_cxx_helpers.hpp>
 #include <vlc_vout.h>
+#include <vlc_spu.h>
 
 #include <QApplication>
 #include <QFile>
@@ -587,13 +588,20 @@ static void on_player_audio_delay_changed(vlc_player_t *, vlc_tick_t new_delay,
 }
 
 static void on_player_subtitle_delay_changed(vlc_player_t *, vlc_tick_t new_delay,
-                                  void *data)
+                                             int i_spu_id, void *data)
 {
     PlayerControllerPrivate* that = static_cast<PlayerControllerPrivate*>(data);
     msg_Dbg( that->p_intf, "on_player_subtitle_delay_changed");
-    that->callAsync([that,new_delay] (){
-        that->m_subtitleDelay = new_delay;
-        emit that->q_func()->subtitleDelayChanged( new_delay );
+    that->callAsync([that,new_delay,i_spu_id] (){
+        if (i_spu_id == SPU_ID_PRIMARY)
+        {
+            that->m_subtitleDelay = new_delay;
+            emit that->q_func()->subtitleDelayChanged( new_delay );
+        }
+        else
+        {
+            // TODO: Support dual subtitles
+        }
     });
 }
 
@@ -1056,7 +1064,8 @@ void PlayerController::setSubtitleDelay(VLCTick delay)
 {
     Q_D(PlayerController);
     vlc_player_locker lock{ d->m_player };
-    vlc_player_SetSubtitleDelay( d->m_player, delay, VLC_PLAYER_WHENCE_ABSOLUTE );
+    vlc_player_SetSubtitleDelay( d->m_player, delay,
+                                 VLC_PLAYER_WHENCE_ABSOLUTE, SPU_ID_PRIMARY );
 }
 
 void PlayerController::setSubtitleFPS(float fps)
diff --git a/modules/lua/libs/input.c b/modules/lua/libs/input.c
index ac69f1f7b7..6091e14ca7 100644
--- a/modules/lua/libs/input.c
+++ b/modules/lua/libs/input.c
@@ -37,6 +37,7 @@
 #include <vlc_url.h>
 #include <vlc_playlist.h>
 #include <vlc_player.h>
+#include <vlc_spu.h>
 
 #include <assert.h>
 
@@ -491,7 +492,7 @@ static int vlclua_player_get_subtitle_delay(lua_State *L)
     vlc_player_t *player = vlclua_get_player_internal(L);
 
     vlc_player_Lock(player);
-    vlc_tick_t delay = vlc_player_GetSubtitleDelay(player);
+    vlc_tick_t delay = vlc_player_GetSubtitleDelay(player, SPU_ID_PRIMARY);
     vlc_player_Unlock(player);
 
     double delay_sec = secf_from_vlc_tick(delay);
@@ -508,7 +509,8 @@ static int vlclua_player_set_subtitle_delay(lua_State *L)
     vlc_tick_t delay = vlc_tick_from_sec(delay_sec);
 
     vlc_player_Lock(player);
-    vlc_player_SetSubtitleDelay(player, delay, VLC_PLAYER_WHENCE_ABSOLUTE);
+    vlc_player_SetSubtitleDelay(player, delay,
+                                VLC_PLAYER_WHENCE_ABSOLUTE, SPU_ID_PRIMARY);
     vlc_player_Unlock(player);
 
     return 0;
diff --git a/src/input/es_out.c b/src/input/es_out.c
index 0afa500f7c..de3e8d4779 100644
--- a/src/input/es_out.c
+++ b/src/input/es_out.c
@@ -39,6 +39,7 @@
 #include <vlc_fourcc.h>
 #include <vlc_meta.h>
 #include <vlc_list.h>
+#include <vlc_spu.h>
 
 #include "input_internal.h"
 #include "../clock/input_clock.h"
@@ -182,7 +183,7 @@ typedef struct
 
     /* delay */
     vlc_tick_t i_audio_delay;
-    vlc_tick_t i_spu_delay;
+    vlc_tick_t spu_delays[SPU_MAX_CLOCKS]; /* Primary / Secondary subtitle delay */
 
     /* Clock configuration */
     vlc_tick_t  i_pts_delay;
@@ -565,7 +566,8 @@ static bool EsOutDecodersIsEmpty( es_out_t *out )
     return true;
 }
 
-static void EsOutSetDelay( es_out_t *out, int i_cat, vlc_tick_t i_delay )
+static void EsOutSetDelay( es_out_t *out, int i_cat, vlc_tick_t i_delay,
+                           int i_spu_id )
 {
     es_out_sys_t *p_sys = container_of(out, es_out_sys_t, out);
     es_out_id_t *es;
@@ -573,7 +575,7 @@ static void EsOutSetDelay( es_out_t *out, int i_cat, vlc_tick_t i_delay )
     if( i_cat == AUDIO_ES )
         p_sys->i_audio_delay = i_delay;
     else if( i_cat == SPU_ES )
-        p_sys->i_spu_delay = i_delay;
+        p_sys->spu_delays[i_spu_id - SPU_ID_PRIMARY] = i_delay;
 
     foreach_es_then_es_slaves(es)
         EsOutDecoderChangeDelay(out, es);
@@ -909,7 +911,10 @@ static void EsOutDecoderChangeDelay( es_out_t *out, es_out_id_t *p_es )
     if( p_es->fmt.i_cat == AUDIO_ES )
         i_delay = p_sys->i_audio_delay;
     else if( p_es->fmt.i_cat == SPU_ES )
-        i_delay = p_sys->i_spu_delay;
+    {
+        int i_spu_id = p_es->p_dec ? input_DecoderGetSpuId(p_es->p_dec) : SPU_ID_PRIMARY;
+        i_delay = p_sys->spu_delays[i_spu_id - SPU_ID_PRIMARY];
+    }
     else
         return;
 
@@ -1969,6 +1974,7 @@ static void EsOutSelectEs( es_out_t *out, es_out_id_t *es )
     {
         input_DecoderSetSpuId( es->p_dec,
                                EsOutCountSelected( p_sys, es->fmt.i_cat ) );
+        EsOutDecoderChangeDelay(out, es);
     }
 }
 
@@ -3057,7 +3063,8 @@ static int EsOutVaControlLocked( es_out_t *out, int i_query, va_list args )
     {
         const int i_cat = va_arg( args, int );
         const vlc_tick_t i_delay = va_arg( args, vlc_tick_t );
-        EsOutSetDelay( out, i_cat, i_delay );
+        const int i_spu_id = va_arg( args, int );
+        EsOutSetDelay( out, i_cat, i_delay, i_spu_id );
         return VLC_SUCCESS;
     }
 
diff --git a/src/input/es_out.h b/src/input/es_out.h
index 7cbea71728..5cc8fa16fc 100644
--- a/src/input/es_out.h
+++ b/src/input/es_out.h
@@ -121,9 +121,11 @@ static inline bool es_out_GetEmpty( es_out_t *p_out )
     assert( !i_ret );
     return b;
 }
-static inline void es_out_SetDelay( es_out_t *p_out, int i_cat, vlc_tick_t i_delay )
+static inline void es_out_SetDelay( es_out_t *p_out, int i_cat,
+                                    vlc_tick_t i_delay, int i_spu_id )
 {
-    int i_ret = es_out_Control( p_out, ES_OUT_SET_DELAY, i_cat, i_delay );
+    int i_ret = es_out_Control( p_out, ES_OUT_SET_DELAY, i_cat,
+                                i_delay, i_spu_id );
     assert( !i_ret );
 }
 static inline int es_out_SetRecordState( es_out_t *p_out, bool b_record )
diff --git a/src/input/event.h b/src/input/event.h
index 5da39053d2..da8ca287b0 100644
--- a/src/input/event.h
+++ b/src/input/event.h
@@ -101,11 +101,12 @@ static inline void input_SendEventAudioDelay(input_thread_t *p_input,
 }
 
 static inline void input_SendEventSubtitleDelay(input_thread_t *p_input,
-                                                 vlc_tick_t i_delay)
+                                                 vlc_tick_t i_delay,
+                                                 int i_spu_id)
 {
     input_SendEvent(p_input, &(struct vlc_input_event) {
         .type = INPUT_EVENT_SUBTITLE_DELAY,
-        .subtitle_delay = i_delay,
+        .subtitle_delay = {i_delay, i_spu_id},
     });
 }
 
diff --git a/src/input/input.c b/src/input/input.c
index 31761c9671..3cae0c0f7e 100644
--- a/src/input/input.c
+++ b/src/input/input.c
@@ -53,6 +53,7 @@
 #include <vlc_stream.h>
 #include <vlc_stream_extractor.h>
 #include <vlc_renderer_discovery.h>
+#include <vlc_spu.h>
 
 /*****************************************************************************
  * Local prototypes
@@ -426,7 +427,8 @@ static input_thread_t *Create( vlc_object_t *p_parent,
 
     priv->i_audio_delay =
         VLC_TICK_FROM_MS( var_GetInteger( p_input, "audio-desync" ) );
-    priv->i_spu_delay = 0;
+    for (int i = 0; i < SPU_MAX_CLOCKS; i++)
+        priv->spu_delays[i] = 0;
 
     /* */
     if( !priv->b_preparsing )
@@ -1059,10 +1061,13 @@ static void SetSubtitlesOptions( input_thread_t *p_input )
     int64_t sub_delay = var_InheritInteger( p_input, "sub-delay" );
     if( sub_delay != 0 )
     {
-        priv->i_spu_delay = vlc_tick_from_samples(sub_delay, 10);
-        input_SendEventSubtitleDelay( p_input, priv->i_spu_delay );
+        priv->spu_delays[0] = vlc_tick_from_samples(sub_delay, 10);
+        input_SendEventSubtitleDelay( p_input, priv->spu_delays[0],
+                                      SPU_ID_PRIMARY );
         /* UpdatePtsDelay will be called next by InitPrograms */
     }
+
+    /* TODO: Support secondary subtitle delay */
 }
 
 static void GetVarSlaves( input_thread_t *p_input,
@@ -1279,7 +1284,12 @@ static void UpdatePtsDelay( input_thread_t *p_input )
         i_pts_delay = 0;
 
     /* Take care of audio/spu delay */
-    const vlc_tick_t i_extra_delay = __MIN( p_sys->i_audio_delay, p_sys->i_spu_delay );
+    vlc_tick_t i_extra_delay = p_sys->i_audio_delay;
+    for( int i = 0; i < SPU_MAX_CLOCKS; i++ )
+    {
+        i_extra_delay = __MIN( i_extra_delay, p_sys->spu_delays[i] );
+    }
+
     if( i_extra_delay < 0 )
         i_pts_delay -= i_extra_delay;
 
@@ -1288,9 +1298,12 @@ static void UpdatePtsDelay( input_thread_t *p_input )
 
     /* */
     es_out_SetDelay( input_priv(p_input)->p_es_out_display, AUDIO_ES,
-                     p_sys->i_audio_delay );
-    es_out_SetDelay( input_priv(p_input)->p_es_out_display, SPU_ES,
-                     p_sys->i_spu_delay );
+                     p_sys->i_audio_delay, SPU_ID_PRIMARY );
+    for ( int i = 0; i < SPU_MAX_CLOCKS; i++ )
+    {
+        es_out_SetDelay( input_priv(p_input)->p_es_out_display, SPU_ES,
+                        p_sys->spu_delays[i], SPU_ID_PRIMARY + i );
+    }
     es_out_SetJitter( input_priv(p_input)->p_es_out, i_pts_delay, 0, i_cr_average );
 }
 
@@ -2202,14 +2215,18 @@ static bool Control( input_thread_t *p_input,
             break;
 
         case INPUT_CONTROL_SET_SPU_DELAY:
+        {
+            int i_spu_delay_index = param.delay.i_spu_id - SPU_ID_PRIMARY;
             if( param.delay.b_absolute )
-                priv->i_spu_delay = param.delay.i_val;
+                priv->spu_delays[i_spu_delay_index] = param.delay.i_val;
             else
-                priv->i_spu_delay += param.delay.i_val;
-            input_SendEventSubtitleDelay( p_input, priv->i_spu_delay );
+                priv->spu_delays[i_spu_delay_index] += param.delay.i_val;
+            input_SendEventSubtitleDelay( p_input,
+                                          priv->spu_delays[i_spu_delay_index],
+                                          param.delay.i_spu_id );
             UpdatePtsDelay( p_input );
             break;
-
+        }
         case INPUT_CONTROL_SET_TITLE:
         case INPUT_CONTROL_SET_TITLE_NEXT:
         case INPUT_CONTROL_SET_TITLE_PREV:
diff --git a/src/input/input_internal.h b/src/input/input_internal.h
index 3bcb5a9f83..6b41ee346a 100644
--- a/src/input/input_internal.h
+++ b/src/input/input_internal.h
@@ -30,6 +30,7 @@
 #include <vlc_demux.h>
 #include <vlc_input.h>
 #include <vlc_viewpoint.h>
+#include <vlc_spu.h>
 #include <libvlc.h>
 #include "input_interface.h"
 #include "misc/interrupt.h"
@@ -99,6 +100,7 @@ typedef union
     struct {
         bool b_absolute;
         vlc_tick_t i_val;
+        int i_spu_id;
     } delay;
     struct {
         vlc_es_id_t *id;
@@ -145,7 +147,7 @@ typedef struct input_thread_private_t
 
     /* Delays */
     vlc_tick_t  i_audio_delay;
-    vlc_tick_t  i_spu_delay;
+    vlc_tick_t  spu_delays[SPU_MAX_CLOCKS]; /* Primary and secondary subtitle delay */
 
     /* Output */
     bool            b_out_pace_control; /* XXX Move it ot es_sout ? */
diff --git a/src/input/player.c b/src/input/player.c
index f86cb9d4e1..7529d09912 100644
--- a/src/input/player.c
+++ b/src/input/player.c
@@ -108,7 +108,7 @@ struct vlc_player_input
     struct input_stats_t stats;
 
     vlc_tick_t audio_delay;
-    vlc_tick_t subtitle_delay;
+    vlc_tick_t subtitle_delays[SPU_MAX_CLOCKS];
 
     struct
     {
@@ -650,7 +650,11 @@ vlc_player_input_New(vlc_player_t *player, input_item_t *item)
 
     memset(&input->stats, 0, sizeof(input->stats));
 
-    input->audio_delay = input->subtitle_delay = 0;
+    input->audio_delay = 0;
+    for (int i = 0; i < SPU_MAX_CLOCKS; i++)
+    {
+        input->subtitle_delays[i] = 0;
+    }
 
     input->subsync.audio_time =
     input->subsync.subtitle_time = VLC_TICK_INVALID;
@@ -2051,10 +2055,16 @@ input_thread_Events(input_thread_t *input_thread,
                                  input->audio_delay);
             break;
         case INPUT_EVENT_SUBTITLE_DELAY:
-            input->subtitle_delay = event->subtitle_delay;
+        {
+            int i_spu_id = event->subtitle_delay.i_spu_id;
+            int i_delay = event->subtitle_delay.i_delay;
+            int i_delay_index = i_spu_id - SPU_ID_PRIMARY;
+            input->subtitle_delays[i_delay_index] = i_delay;
             vlc_player_SendEvent(player, on_subtitle_delay_changed,
-                                 input->subtitle_delay);
+                                 input->subtitle_delays[i_delay_index],
+                                 i_spu_id);
             break;
+        }
         case INPUT_EVENT_CACHE:
             input->cache = event->cache;
             vlc_player_SendEvent(player, on_buffering_changed, event->cache);
@@ -2818,6 +2828,7 @@ vlc_player_SetAudioDelay(vlc_player_t *player, vlc_tick_t delay,
             .delay = {
                 .b_absolute = whence == VLC_PLAYER_WHENCE_ABSOLUTE,
                 .i_val = delay,
+                .i_spu_id = SPU_ID_PRIMARY,
             },
     });
 
@@ -2836,7 +2847,8 @@ vlc_player_GetAudioDelay(vlc_player_t *player)
 
 static void
 vlc_player_SetSubtitleDelayInternal(vlc_player_t *player, vlc_tick_t delay,
-                                    enum vlc_player_whence whence)
+                                    enum vlc_player_whence whence,
+                                    int i_spu_id)
 {
     bool absolute = whence == VLC_PLAYER_WHENCE_ABSOLUTE;
     struct vlc_player_input *input = vlc_player_get_input_locked(player);
@@ -2848,16 +2860,19 @@ vlc_player_SetSubtitleDelayInternal(vlc_player_t *player, vlc_tick_t delay,
             .delay = {
                 .b_absolute = absolute,
                 .i_val = delay,
+                .i_spu_id = i_spu_id,
             },
     });
 }
 
 void
 vlc_player_SetSubtitleDelay(vlc_player_t *player, vlc_tick_t delay,
-                            enum vlc_player_whence whence)
+                            enum vlc_player_whence whence,
+                            int i_spu_id)
 {
-    vlc_player_SetSubtitleDelayInternal(player, delay, whence);
-    vlc_player_vout_OSDMessage(player, _("Subtitle delay: %s%i ms"),
+    vlc_player_SetSubtitleDelayInternal(player, delay, whence, i_spu_id);
+    vlc_player_vout_OSDMessage(player, _("%subtitle delay: %s%i ms"),
+                               i_spu_id > SPU_ID_PRIMARY ? "Secondary s" : "S",
                                whence == VLC_PLAYER_WHENCE_ABSOLUTE ? "" : "+",
                                (int)MS_FROM_VLC_TICK(delay));
 }
@@ -2949,10 +2964,10 @@ vlc_player_SubtitleSyncApply(vlc_player_t *player)
     input->subsync.audio_time = VLC_TICK_INVALID;
     input->subsync.subtitle_time = VLC_TICK_INVALID;
     vlc_player_SetSubtitleDelayInternal(player, delay,
-                                        VLC_PLAYER_WHENCE_RELATIVE);
+                                        VLC_PLAYER_WHENCE_RELATIVE, SPU_ID_PRIMARY);
 
     long long delay_ms = MS_FROM_VLC_TICK(delay);
-    long long totdelay_ms = MS_FROM_VLC_TICK(input->subtitle_delay + delay);
+    long long totdelay_ms = MS_FROM_VLC_TICK(input->subtitle_delays[0] + delay);
     vlc_player_vout_OSDMessage(player, _("Sub sync: corrected %"PRId64
                                " ms (total delay = %"PRId64" ms)"),
                                delay_ms, totdelay_ms);
@@ -2964,7 +2979,8 @@ vlc_player_SubtitleSyncReset(vlc_player_t *player)
     struct vlc_player_input *input = vlc_player_get_input_locked(player);
     if (!input)
         return;
-    vlc_player_SetSubtitleDelayInternal(player, 0, VLC_PLAYER_WHENCE_ABSOLUTE);
+    vlc_player_SetSubtitleDelayInternal(player, 0, VLC_PLAYER_WHENCE_ABSOLUTE,
+                                        SPU_ID_PRIMARY);
     input->subsync.audio_time = VLC_TICK_INVALID;
     input->subsync.subtitle_time = VLC_TICK_INVALID;
     vlc_player_vout_OSDMessage(player, _("Sub sync: delay reset"));
@@ -2994,10 +3010,10 @@ vlc_player_SetSubtitleSync(vlc_player_t *player,
 }
 
 vlc_tick_t
-vlc_player_GetSubtitleDelay(vlc_player_t *player)
+vlc_player_GetSubtitleDelay(vlc_player_t *player, int i_spu_id)
 {
     struct vlc_player_input *input = vlc_player_get_input_locked(player);
-    return input ? input->subtitle_delay : 0;
+    return input ? input->subtitle_delays[i_spu_id - SPU_ID_PRIMARY] : 0;
 }
 
 int
diff --git a/src/input/var.c b/src/input/var.c
index 9110624eab..b0af2a6c6d 100644
--- a/src/input/var.c
+++ b/src/input/var.c
@@ -410,9 +410,15 @@ void input_LegacyEvents( input_thread_t *p_input,
             var_Change( p_input, "audio-delay", VLC_VAR_SETVALUE, val );
             break;
         case INPUT_EVENT_SUBTITLE_DELAY:
-            val.i_int = event->subtitle_delay;
-            var_Change( p_input, "spu-delay", VLC_VAR_SETVALUE, val );
+        {
+            /* Dual subtitles are not supported in legacy GUI */
+            if ( event->subtitle_delay.i_spu_id == SPU_ID_PRIMARY )
+            {
+                val.i_int = event->subtitle_delay.i_delay;
+                var_Change( p_input, "spu-delay", VLC_VAR_SETVALUE, val );
+            }
             break;
+        }
         case INPUT_EVENT_BOOKMARK:
             UpdateBookmarksOption( p_input );
             break;
@@ -1073,6 +1079,8 @@ static int EsDelayCallback ( vlc_object_t *p_this, char const *psz_cmd,
         .delay = {
             .b_absolute = true,
             .i_val = newval.i_int,
+            /* Dual subtitles are not supported in legacy GUI */
+            .i_spu_id = SPU_ID_PRIMARY,
         },
     };
     if( !strcmp( psz_cmd, "audio-delay" ) )
-- 
2.11.0



More information about the vlc-devel mailing list