[vlc-devel] [PATCH 1/8] input: source: add a refcount

Thomas Guillem thomas at gllm.fr
Fri Feb 28 08:36:23 CET 2020


The input_source_t will be passed to slave es_out via input_EsOutSourceNew().
It need to be refcounted since the es_out timeshift might use it
asynchronously.
---
 src/input/input.c          | 16 +++++++++++++++-
 src/input/input_internal.h | 13 +++++++++++++
 2 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/src/input/input.c b/src/input/input.c
index 0834bbd8385..5e3f7fce7eb 100644
--- a/src/input/input.c
+++ b/src/input/input.c
@@ -2487,6 +2487,8 @@ static input_source_t *InputSourceNew( input_thread_t *p_input,
         return NULL;
     }
 
+    vlc_atomic_rc_init( &in->rc );
+
     /* Split uri */
     input_SplitMRL( &psz_access, &psz_demux, &psz_path, &psz_anchor, psz_dup );
 
@@ -2695,6 +2697,18 @@ static input_source_t *InputSourceNew( input_thread_t *p_input,
     return in;
 }
 
+input_source_t *input_source_Hold( input_source_t *in )
+{
+    vlc_atomic_rc_inc( &in->rc );
+    return in;
+}
+
+void input_source_Release( input_source_t *in )
+{
+    if( vlc_atomic_rc_dec( &in->rc ) )
+        free( in );
+}
+
 /*****************************************************************************
  * InputSourceDestroy:
  *****************************************************************************/
@@ -2712,7 +2726,7 @@ static void InputSourceDestroy( input_source_t *in )
     }
     TAB_CLEAN( in->i_title, in->title );
 
-    free( in );
+    input_source_Release( in );
 }
 
 /*****************************************************************************
diff --git a/src/input/input_internal.h b/src/input/input_internal.h
index 8914c4678b1..f10b6243e35 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_atomic.h>
 #include <libvlc.h>
 #include "input_interface.h"
 #include "misc/interrupt.h"
@@ -366,6 +367,8 @@ input_item_t* input_GetItem( input_thread_t * ) VLC_USED;
 /* input_source_t: gathers all information per input source */
 typedef struct
 {
+    vlc_atomic_rc_t rc;
+
     demux_t  *p_demux; /**< Demux object (most downstream) */
 
     /* Title infos for that input */
@@ -635,6 +638,16 @@ int input_GetAttachments(input_thread_t *input, input_attachment_t ***attachment
 
 input_attachment_t *input_GetAttachment(input_thread_t *input, const char *name);
 
+/**
+ * Hold the input_source_t
+ */
+input_source_t *input_source_Hold( input_source_t *in );
+
+/**
+ * Release the input_source_t
+ */
+void input_source_Release( input_source_t *in );
+
 /* Bound pts_delay */
 #define INPUT_PTS_DELAY_MAX VLC_TICK_FROM_SEC(60)
 
-- 
2.20.1



More information about the vlc-devel mailing list