[vlc-devel] [PATCH 3/4] decoder: factorize the code to replace/reset the SPU vout

Steve Lhomme robux4 at ycbcr.xyz
Tue Sep 3 11:59:33 CEST 2019


- If the old vout is different than the new, we always release the old vout
(before it was done separately).
- i_deleted_spu_channel is first set to VOUT_SPU_CHANNEL_INVALID then the lock
is release/held if a new one is needed (fixed in next patch).
---
 src/input/decoder.c | 57 +++++++++++++++------------------------------
 1 file changed, 19 insertions(+), 38 deletions(-)

diff --git a/src/input/decoder.c b/src/input/decoder.c
index 21da23d23c..1a1778e662 100644
--- a/src/input/decoder.c
+++ b/src/input/decoder.c
@@ -607,49 +607,33 @@ static subpicture_t *spu_new_buffer( decoder_t *p_dec,
         vlc_tick_sleep( DECODER_SPU_VOUT_WAIT_DURATION );
     }
 
-    if( !p_vout )
-    {
-        msg_Warn( p_dec, "no vout found, dropping subpicture" );
-        vlc_mutex_lock( &p_owner->lock );
-        vout_thread_t *p_old_vout = p_owner->p_vout;
-        ssize_t i_deleted_spu_channel = p_owner->i_spu_channel;
+    vlc_mutex_lock( &p_owner->lock );
+    ssize_t i_deleted_spu_channel = p_owner->i_spu_channel;
+    vout_thread_t *p_old_vout = p_owner->p_vout;
 
-        p_owner->p_vout = NULL;
-        p_owner->i_spu_channel = VOUT_SPU_CHANNEL_INVALID;
-        vlc_mutex_unlock( &p_owner->lock );
+    p_owner->i_spu_channel = VOUT_SPU_CHANNEL_INVALID;
+    p_owner->p_vout = p_vout;
+    vlc_mutex_unlock( &p_owner->lock );
 
-        if( p_old_vout )
-        {
-            assert(i_deleted_spu_channel != VOUT_SPU_CHANNEL_INVALID);
-            decoder_Notify(p_owner, on_vout_deleted, p_old_vout);
+    if (p_old_vout && p_old_vout != p_vout)
+    {
+        /* notify the previous vout deletion unlocked */
+        decoder_Notify(p_owner, on_vout_deleted, p_old_vout);
 
-            vout_UnregisterSubpictureChannel(p_old_vout,
-                                             i_deleted_spu_channel);
+        /* Unregister the SPU channel of the previous vout */
+        assert(i_deleted_spu_channel != VOUT_SPU_CHANNEL_INVALID);
+        vout_UnregisterSubpictureChannel(p_old_vout, i_deleted_spu_channel);
+        vout_Release(p_old_vout);
+    }
 
-            vout_Release(p_old_vout);
-        }
+    if( !p_vout )
+    {
+        msg_Warn( p_dec, "no vout found, dropping subpicture" );
         return NULL;
     }
 
-    if( p_owner->p_vout != p_vout )
+    if( p_old_vout != p_vout )
     {
-        vlc_mutex_lock(&p_owner->lock);
-        vout_thread_t *p_old_vout = p_owner->p_vout;
-        ssize_t i_deleted_spu_channel = p_owner->i_spu_channel;
-        vlc_mutex_unlock( &p_owner->lock );
-
-        if (p_old_vout)
-        {
-            /* notify the previous vout deletion unlocked */
-            decoder_Notify(p_owner, on_vout_deleted, p_old_vout);
-
-            /* Unregister the SPU channel of the previous vout */
-            assert(i_deleted_spu_channel != VOUT_SPU_CHANNEL_INVALID);
-            vout_UnregisterSubpictureChannel(p_old_vout,
-                                             i_deleted_spu_channel);
-            vout_Release(p_old_vout);
-        }
-
         vlc_mutex_lock(&p_owner->lock);
 
         enum vlc_vout_order channel_order;
@@ -667,14 +651,11 @@ static subpicture_t *spu_new_buffer( decoder_t *p_dec,
             return NULL;
         }
 
-        p_owner->p_vout = p_vout;
         vlc_mutex_unlock(&p_owner->lock);
 
         assert(channel_order != VLC_VOUT_ORDER_NONE);
         decoder_Notify(p_owner, on_vout_added, p_vout, channel_order);
     }
-    else
-        vout_Release(p_vout);
 
     p_subpic = subpicture_New( p_updater );
     if( p_subpic )
-- 
2.17.1



More information about the vlc-devel mailing list