[vlc-devel] [PATCH 6/8] decoder: use internal cancelable structure to cancel the picture pool on exit

Steve Lhomme robux4 at ycbcr.xyz
Mon Jul 27 15:45:27 CEST 2020


The cancelable structure is available to each decoder if they manage their own
picture pool instead of the default one.
---
 include/vlc_codec.h         |  7 +++++++
 src/input/decoder.c         | 20 +++++++++++---------
 src/input/decoder_helpers.c |  1 +
 3 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/include/vlc_codec.h b/include/vlc_codec.h
index 8ebdc111709..ec48f9f74f0 100644
--- a/include/vlc_codec.h
+++ b/include/vlc_codec.h
@@ -42,6 +42,7 @@
  */
 
 typedef struct decoder_cc_desc_t decoder_cc_desc_t;
+typedef struct vlc_cancelable    vlc_cancelable;
 
 struct decoder_owner_callbacks
 {
@@ -192,6 +193,12 @@ struct decoder_t
      * the decoder_QueueCc() function to pass closed captions. */
     block_t *           ( * pf_get_cc )      ( decoder_t *, decoder_cc_desc_t * );
 
+    /*
+     * Cancelable to use when using internal decoder pools so that threads
+     * waiting for pictures can be unlocked from the outide.
+     */
+    vlc_cancelable      *pool_cancel;
+
     /* Meta data at codec level
      *  The decoder owner set it back to NULL once it has retreived what it needs.
      *  The decoder owner is responsible of its release except when you overwrite it.
diff --git a/src/input/decoder.c b/src/input/decoder.c
index 7fa1e07f3ae..47446124ce3 100644
--- a/src/input/decoder.c
+++ b/src/input/decoder.c
@@ -103,6 +103,7 @@ struct vlc_input_decoder_t
     vlc_cond_t  wait_fifo; /* TODO: merge with wait_acknowledge */
 
     /* pool to use when the decoder doesn't use its own */
+    vlc_cancelable        pool_cancel;
     struct picture_pool_t *out_pool;
 
     /*
@@ -197,12 +198,14 @@ static inline vlc_input_decoder_t *dec_get_owner( decoder_t *p_dec )
 /**
  * Load a decoder module
  */
-static int LoadDecoder( decoder_t *p_dec, bool b_packetizer,
+static int LoadDecoder( decoder_t *p_dec, vlc_cancelable *pool_cancel,
+                        bool b_packetizer,
                         const es_format_t *restrict p_fmt )
 {
     decoder_Init( p_dec, p_fmt );
 
     p_dec->b_frame_drop_allowed = true;
+    p_dec->pool_cancel = pool_cancel;
 
     /* Find a suitable decoder/packetizer module */
     if( !b_packetizer )
@@ -256,7 +259,7 @@ static int DecoderThread_Reload( vlc_input_decoder_t *p_owner,
         }
     }
 
-    if( LoadDecoder( p_dec, false, &fmt_in ) )
+    if( LoadDecoder( p_dec, &p_owner->pool_cancel, false, &fmt_in ) )
     {
         p_owner->error = true;
         es_format_Clean( &fmt_in );
@@ -455,7 +458,7 @@ static int ModuleThread_UpdateVideoFormat( decoder_t *p_dec, vlc_video_context *
 
         p_owner->out_pool = picture_pool_NewFromFormat( &p_dec->fmt_out.video,
                             dpb_size + p_dec->i_extra_picture_buffers + 1,
-                            NULL );
+                            &p_owner->pool_cancel );
         if (p_owner->out_pool == NULL)
         {
             msg_Err(p_dec, "Failed to create a pool of %d %4.4s pictures",
@@ -1825,6 +1828,7 @@ CreateDecoder( vlc_object_t *p_parent,
     vlc_cond_init( &p_owner->wait_request );
     vlc_cond_init( &p_owner->wait_acknowledge );
     vlc_cond_init( &p_owner->wait_fifo );
+    vlc_cancelable_Init( &p_owner->pool_cancel );
 
     /* Load a packetizer module if the input is not already packetized */
     if( p_sout == NULL && !fmt->b_packetized )
@@ -1833,7 +1837,7 @@ CreateDecoder( vlc_object_t *p_parent,
             vlc_custom_create( p_parent, sizeof( decoder_t ), "packetizer" );
         if( p_owner->p_packetizer )
         {
-            if( LoadDecoder( p_owner->p_packetizer, true, fmt ) )
+            if( LoadDecoder( p_owner->p_packetizer, NULL, true, fmt ) )
             {
                 vlc_object_delete(p_owner->p_packetizer);
                 p_owner->p_packetizer = NULL;
@@ -1866,7 +1870,7 @@ CreateDecoder( vlc_object_t *p_parent,
     }
 
     /* Find a suitable decoder/packetizer module */
-    if( LoadDecoder( p_dec, p_sout != NULL, fmt ) )
+    if( LoadDecoder( p_dec, &p_owner->pool_cancel, p_sout != NULL, fmt ) )
         return p_owner;
 
     assert( p_dec->fmt_in.i_cat == p_dec->fmt_out.i_cat && fmt->i_cat == p_dec->fmt_in.i_cat);
@@ -1950,8 +1954,7 @@ static void DeleteDecoder( vlc_input_decoder_t *p_owner )
         case VIDEO_ES: {
             vout_thread_t *vout = p_owner->p_vout;
 
-            if (p_owner->out_pool)
-                picture_pool_Cancel( p_owner->out_pool, false );
+            vlc_cancelable_SetCanceled( &p_owner->pool_cancel, false );
 
             if (vout != NULL)
             {
@@ -2141,8 +2144,7 @@ void vlc_input_decoder_Delete( vlc_input_decoder_t *p_owner )
      * worker threads (if any) and the decoder thread to terminate. */
     if( p_dec->fmt_in.i_cat == VIDEO_ES && p_owner->p_vout != NULL )
     {
-        if (p_owner->out_pool)
-            picture_pool_Cancel( p_owner->out_pool, true );
+        vlc_cancelable_SetCanceled( &p_owner->pool_cancel, true );
     }
     vlc_mutex_unlock( &p_owner->lock );
 
diff --git a/src/input/decoder_helpers.c b/src/input/decoder_helpers.c
index c98e62bf214..b156fcaf447 100644
--- a/src/input/decoder_helpers.c
+++ b/src/input/decoder_helpers.c
@@ -44,6 +44,7 @@ void decoder_Init( decoder_t *p_dec, const es_format_t *restrict p_fmt )
     p_dec->pf_packetize = NULL;
     p_dec->pf_flush = NULL;
     p_dec->p_module = NULL;
+    p_dec->pool_cancel = NULL;
 
     es_format_Copy( &p_dec->fmt_in, p_fmt );
     es_format_Init( &p_dec->fmt_out, p_fmt->i_cat, 0 );
-- 
2.26.2



More information about the vlc-devel mailing list