[vlc-devel] [PATCH 10/14] Hotkey support for secondary subtitles (Part 2)

Roland Bewick roland.bewick at gmail.com
Sat May 11 08:32:14 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                                 | 38 ++++++++++++++------
 src/input/input_internal.h                        |  4 ++-
 src/input/player.c                                | 42 ++++++++++++++++-------
 src/input/var.c                                   | 12 +++++--
 13 files changed, 124 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 c09e226910..ae3c96d30b 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
@@ -2393,9 +2394,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
@@ -2426,10 +2428,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 45065d1b07..82ceb3c82e 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 82cbf9c49e..0a26c7680b 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;
@@ -567,7 +568,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;
@@ -575,7 +577,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);
@@ -911,7 +913,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;
 
@@ -2245,6 +2250,7 @@ static void EsOutSelect( es_out_t *out, es_out_id_t *es, bool b_force )
     if (es->fmt.i_cat == SPU_ES && es->p_dec)
     {
         input_DecoderSetSpuId( es->p_dec, EsOutCountSelected( p_sys, es->fmt.i_cat ) );
+        EsOutDecoderChangeDelay(out, es);
     }
 }
 
@@ -3039,7 +3045,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 3f37d73b68..760dd25cdf 100644
--- a/src/input/es_out.h
+++ b/src/input/es_out.h
@@ -124,9 +124,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 821a18ff2c..d380736daa 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,12 @@ 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], false );
         /* UpdatePtsDelay will be called next by InitPrograms */
     }
+
+    /* TODO: Support secondary subtitle delay */
 }
 
 static void GetVarSlaves( input_thread_t *p_input,
@@ -1279,7 +1283,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 +1297,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 );
 }
 
@@ -2178,14 +2190,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 914cebe7d4..6849aa93ae 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"
@@ -95,6 +96,7 @@ typedef union
     struct {
         bool b_absolute;
         vlc_tick_t i_val;
+        int i_spu_id;
     } delay;
     struct {
         vlc_es_id_t *id;
@@ -141,7 +143,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 626bb4c721..e66fc9552d 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;
@@ -1966,10 +1970,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);
@@ -2724,6 +2734,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,
             },
     });
 
@@ -2742,7 +2753,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);
@@ -2754,16 +2766,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));
 }
@@ -2855,10 +2870,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);
@@ -2870,7 +2885,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"));
@@ -2911,10 +2927,10 @@ vlc_player_SetSubtitleMultipleSelection(vlc_player_t *player, bool multiple)
 }
 
 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