[vlc-devel] [PATCH 2/3] vout: flush SPU channel on calling thread

RĂ©mi Denis-Courmont remi at remlab.net
Sun Jan 27 15:41:21 CET 2019


There is a mixture of subpicture-related calls, with some running on
the calling thread, and others running on the video output thread
control loop.

The later may be delayed, depending on other video output thread
processing, sleeping and pending control requests. This leads to a
race condition, and potentially inconsistent ordering of calls on the
SPU instance.

This patch runs vout_FlushSubpictureChannel() directly on the calling
thread and adds a missing check for nonexistent/destroyed SPU.
---
 src/video_output/control.h      |  1 -
 src/video_output/video_output.c | 18 ++++++++----------
 2 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/src/video_output/control.h b/src/video_output/control.h
index c161097f90..28174ad4cc 100644
--- a/src/video_output/control.h
+++ b/src/video_output/control.h
@@ -36,7 +36,6 @@ enum {
     VOUT_CONTROL_START,
     VOUT_CONTROL_STOP,
 #endif
-    VOUT_CONTROL_FLUSH_SUBPICTURE,      /* integer */
     VOUT_CONTROL_CHANGE_FILTERS,        /* string */
     VOUT_CONTROL_CHANGE_INTERLACE,      /* boolean */
 
diff --git a/src/video_output/video_output.c b/src/video_output/video_output.c
index c346f6d10c..d940ea1df1 100644
--- a/src/video_output/video_output.c
+++ b/src/video_output/video_output.c
@@ -552,11 +552,17 @@ int vout_RegisterSubpictureChannel( vout_thread_t *vout )
 
     return channel;
 }
+
 void vout_FlushSubpictureChannel( vout_thread_t *vout, int channel )
 {
-    vout_control_PushInteger(&vout->p->control, VOUT_CONTROL_FLUSH_SUBPICTURE,
-                             channel);
+    vout_thread_sys_t *sys = vout->p;
+
+    vlc_mutex_lock(&sys->spu_lock);
+    if (sys->spu != NULL)
+        spu_ClearChannel(vout->p->spu, channel);
+    vlc_mutex_unlock(&sys->spu_lock);
 }
+
 void vout_SetSpuHighlight( vout_thread_t *vout,
                         const vlc_spu_highlight_t *spu_hl )
 {
@@ -1481,11 +1487,6 @@ static int ThreadDisplayPicture(vout_thread_t *vout, vlc_tick_t *deadline)
     return force_refresh ? VLC_EGENERIC : ret;
 }
 
-static void ThreadFlushSubpicture(vout_thread_t *vout, int channel)
-{
-    spu_ClearChannel(vout->p->spu, channel);
-}
-
 static void ThreadChangePause(vout_thread_t *vout, bool is_paused, vlc_tick_t date)
 {
     assert(!vout->p->pause.is_on || !is_paused);
@@ -1783,9 +1784,6 @@ static int ThreadControl(vout_thread_t *vout, vout_control_cmd_t cmd)
     case VOUT_CONTROL_CANCEL:
         ThreadCancel(vout, cmd.boolean);
         break;
-    case VOUT_CONTROL_FLUSH_SUBPICTURE:
-        ThreadFlushSubpicture(vout, cmd.integer);
-        break;
     case VOUT_CONTROL_CHANGE_FILTERS:
         ThreadChangeFilters(vout, NULL,
                             cmd.string != NULL ?
-- 
2.20.1



More information about the vlc-devel mailing list