[vlc-devel] [PATCH 05/10] Move spu_delay to spu and enable secondary delay

Roland Bewick roland.bewick at gmail.com
Sun May 5 12:01:45 CEST 2019


Optimally the spu_rate would be moved too (See TODO in vout_internal.h),
but I haven't been able to modify the spu speed in a clean VLC 3 or 4
(I've tried different formats such as SRT, .SUB, ...).
People on VLC forums also seem to have issues with this.
For now I won't add support for a separate spu speed for secondary subtitles.
---
 src/video_output/video_output.c     |  5 +----
 src/video_output/vout_internal.h    |  3 +--
 src/video_output/vout_subpictures.c | 20 ++++++++++++++++----
 3 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/src/video_output/video_output.c b/src/video_output/video_output.c
index 23ab21b536..4043369b6f 100644
--- a/src/video_output/video_output.c
+++ b/src/video_output/video_output.c
@@ -1282,7 +1282,6 @@ static void vout_FlushUnlocked(vout_thread_t *vout, bool below,
         for (int i = 0; i < 2; i++)
         {
             spu_clock_Reset(vout->p->spu, i);
-            spu_clock_SetDelay(vout->p->spu, vout->p->spu_delay, i);
         }
     }
     vlc_mutex_unlock(&vout->p->spu_lock);
@@ -1345,7 +1344,6 @@ void vout_ChangeSpuDelay(vout_thread_t *vout, vlc_tick_t delay,
     vlc_mutex_lock(&vout->p->spu_lock);
     if (vout->p->spu)
         spu_clock_SetDelay(vout->p->spu, delay, b_secondary);
-    vout->p->spu_delay = delay;
     vlc_mutex_unlock(&vout->p->spu_lock);
 }
 
@@ -1878,10 +1876,9 @@ int vout_Request(const vout_configuration_t *cfg, input_thread_t *input)
     } else
         vout_UpdateWindowSize(vout);
 
-    sys->delay = sys->spu_delay = 0;
+    sys->delay = 0;
     sys->rate = sys->spu_rate = 1.f;
     sys->clock = cfg->clock;
-    sys->delay = sys->spu_delay = 0;
 
     vlc_mutex_unlock(&sys->window_lock);
 
diff --git a/src/video_output/vout_internal.h b/src/video_output/vout_internal.h
index 43ad5e83b2..9e4473b384 100644
--- a/src/video_output/vout_internal.h
+++ b/src/video_output/vout_internal.h
@@ -69,9 +69,8 @@ struct vout_thread_sys_t
 
     vlc_clock_t     *clock;
     float           rate;
-    float           spu_rate;
+    float           spu_rate;  /* TODO: Move to spu_private_t */
     vlc_tick_t      delay;
-    vlc_tick_t      spu_delay;
 
     /* */
     video_format_t  original;   /* Original format ie coming from the decoder */
diff --git a/src/video_output/vout_subpictures.c b/src/video_output/vout_subpictures.c
index 86f7496442..52aab98900 100644
--- a/src/video_output/vout_subpictures.c
+++ b/src/video_output/vout_subpictures.c
@@ -72,7 +72,9 @@ struct spu_private_t {
     vlc_mutex_t  lock;            /* lock to protect all followings fields */
     input_thread_t *input;
 
-    vlc_clock_t *clocks[2];  /* clocks for primary and secondary subtitles */
+    /* TODO: Extract primary/secondary dependent members to a new object? */
+    vlc_clock_t *clocks[2];          /**< Primary/secondary subtitle clock */
+    vlc_tick_t      delays[2];       /**< Primary/secondary subtitle delay */
 
     spu_heap_t   heap;
 
@@ -1407,7 +1409,12 @@ spu_t *spu_Create(vlc_object_t *object, vout_thread_t *vout)
 
     SpuHeapInit(&sys->heap);
 
-    sys->clocks[0] = sys->clocks[1] = NULL;
+    for (int i = 0; i < 2; i++)
+    {
+        sys->clocks[i] = NULL;
+        sys->delays[i] = 0;
+    }
+
     sys->text = NULL;
     sys->scale = NULL;
     sys->scale_yuvp = NULL;
@@ -1524,14 +1531,19 @@ void spu_clock_Set(spu_t *spu, vlc_clock_t *clock, bool b_secondary)
 
 void spu_clock_Reset(spu_t *spu, bool b_secondary)
 {
-    if (spu->p->clocks[b_secondary])
-        vlc_clock_Reset(spu->p->clocks[b_secondary]);
+    vlc_clock_t *clock = spu->p->clocks[b_secondary];
+    if (clock)
+    {
+        vlc_clock_Reset(clock);
+        vlc_clock_SetDelay(clock, spu->p->delays[b_secondary]);
+    }
 }
 
 void spu_clock_SetDelay(spu_t *spu, vlc_tick_t delay, bool b_secondary)
 {
     if (spu->p->clocks[b_secondary])
         vlc_clock_SetDelay(spu->p->clocks[b_secondary], delay);
+    spu->p->delays[b_secondary] = delay;
 }
 
 /**
-- 
2.17.1



More information about the vlc-devel mailing list