[vlc-devel] [PATCH 5/5] stream: replace input_thread_t by input_item_t

Thomas Guillem thomas at gllm.fr
Thu Jul 19 15:50:20 CEST 2018


This will prevent all demuxers/access/streams to mess with the input_thread_t
state.
---
 include/vlc_stream.h                          |  4 +--
 modules/access/http.c                         | 30 ++++++-------------
 modules/demux/directory.c                     |  5 ++--
 modules/demux/mp4/mp4.c                       |  5 ++--
 modules/demux/playlist/playlist.h             |  2 +-
 modules/services_discovery/sap.c              |  9 ++----
 modules/stream_filter/record.c                |  3 +-
 .../chromecast/chromecast_demux.cpp           |  3 +-
 src/input/access.c                            | 20 ++++++++-----
 src/input/demux.c                             |  7 +++--
 src/input/stream.c                            |  2 +-
 src/input/stream_extractor.c                  |  2 +-
 src/input/stream_filter.c                     |  2 +-
 13 files changed, 39 insertions(+), 55 deletions(-)

diff --git a/include/vlc_stream.h b/include/vlc_stream.h
index 007c8232e6..abcc3872f6 100644
--- a/include/vlc_stream.h
+++ b/include/vlc_stream.h
@@ -52,6 +52,7 @@ struct stream_t
     const char  *psz_location; /**< Location (URL with the scheme stripped) */
     char        *psz_filepath; /**< Local file path (if applicable) */
     bool         b_preparsing; /**< True if this access is used to preparse */
+    input_item_t *p_input_item;/**< Input item (can be NULL) */
 
     union {
         /**
@@ -153,9 +154,6 @@ struct stream_t
      * Private data pointer
      */
     void *p_sys;
-
-    /* Weak link to parent input */
-    input_thread_t *p_input;
 };
 
 /**
diff --git a/modules/access/http.c b/modules/access/http.c
index c2bedba461..0ffa56b33f 100644
--- a/modules/access/http.c
+++ b/modules/access/http.c
@@ -521,13 +521,9 @@ static int ReadICYMeta( stream_t *p_access )
                 free( psz_tmp );
 
             msg_Dbg( p_access, "New Icy-Title=%s", p_sys->psz_icy_title );
-            input_thread_t *p_input = p_access->p_input;
-            if( p_input )
-            {
-                input_item_t *p_input_item = input_GetItem( p_access->p_input );
-                if( p_input_item )
-                    input_item_SetMeta( p_input_item, vlc_meta_NowPlaying, p_sys->psz_icy_title );
-            }
+            if( p_access->p_input_item )
+                input_item_SetMeta( p_access->p_input_item, vlc_meta_NowPlaying,
+                                    p_sys->psz_icy_title );
         }
     }
     free( psz_meta );
@@ -892,13 +888,9 @@ static int Connect( stream_t *p_access )
             else
                 vlc_xml_decode( p_sys->psz_icy_name );
             msg_Dbg( p_access, "Icy-Name: %s", p_sys->psz_icy_name );
-            input_thread_t *p_input = p_access->p_input;
-            if ( p_input )
-            {
-                input_item_t *p_input_item = input_GetItem( p_access->p_input );
-                if ( p_input_item )
-                    input_item_SetMeta( p_input_item, vlc_meta_Title, p_sys->psz_icy_name );
-            }
+            if ( p_access->p_input_item )
+                input_item_SetMeta( p_access->p_input_item, vlc_meta_Title,
+                                    p_sys->psz_icy_name );
 
             p_sys->b_icecast = true; /* be on the safeside. set it here as well. */
             p_sys->b_reconnect = true;
@@ -913,13 +905,9 @@ static int Connect( stream_t *p_access )
             else
                 vlc_xml_decode( p_sys->psz_icy_genre );
             msg_Dbg( p_access, "Icy-Genre: %s", p_sys->psz_icy_genre );
-            input_thread_t *p_input = p_access->p_input;
-            if( p_input )
-            {
-                input_item_t *p_input_item = input_GetItem( p_access->p_input );
-                if( p_input_item )
-                    input_item_SetMeta( p_input_item, vlc_meta_Genre, p_sys->psz_icy_genre );
-            }
+            if( p_access->p_input_item )
+                input_item_SetMeta( p_access->p_input_item, vlc_meta_Genre,
+                                    p_sys->psz_icy_genre );
         }
         else if( !strncasecmp( psz, "Icy-Notice", 10 ) )
         {
diff --git a/modules/demux/directory.c b/modules/demux/directory.c
index 3510c77b45..ab46082d1c 100644
--- a/modules/demux/directory.c
+++ b/modules/demux/directory.c
@@ -32,8 +32,7 @@
 
 static int Demux( demux_t *p_demux )
 {
-    input_item_t *p_input = input_GetItem( p_demux->p_input );
-    input_item_node_t *p_node = input_item_node_Create( p_input );
+    input_item_node_t *p_node = input_item_node_Create( p_demux->p_input_item );
 
     if( vlc_stream_ReadDir( p_demux->s, p_node ) )
     {
@@ -78,7 +77,7 @@ static int Import_Dir( vlc_object_t *p_this )
 
     if( p_demux->s->pf_readdir == NULL )
         return VLC_EGENERIC;
-    if( p_demux->p_input == NULL )
+    if( p_demux->p_input_item == NULL )
         return VLC_ETIMEOUT;
 
     p_demux->pf_demux = Demux;
diff --git a/modules/demux/mp4/mp4.c b/modules/demux/mp4/mp4.c
index 7d72a3b9d1..5bdab8766e 100644
--- a/modules/demux/mp4/mp4.c
+++ b/modules/demux/mp4/mp4.c
@@ -851,15 +851,14 @@ static int Open( vlc_object_t * p_this )
     }
 
     MP4_Box_t *p_rmra = MP4_BoxGet( p_sys->p_root, "/moov/rmra" );
-    if( p_rmra != NULL && p_demux->p_input != NULL )
+    if( p_rmra != NULL && p_demux->p_input_item != NULL )
     {
         int        i_count = MP4_BoxCount( p_rmra, "rmda" );
         int        i;
 
         msg_Dbg( p_demux, "detected playlist mov file (%d ref)", i_count );
 
-        input_thread_t *p_input = p_demux->p_input;
-        input_item_t *p_current = input_GetItem( p_input );
+        input_item_t *p_current = p_demux->p_input_item;
 
         input_item_node_t *p_subitems = input_item_node_Create( p_current );
 
diff --git a/modules/demux/playlist/playlist.h b/modules/demux/playlist/playlist.h
index 51f3e4bcf6..883ca677df 100644
--- a/modules/demux/playlist/playlist.h
+++ b/modules/demux/playlist/playlist.h
@@ -60,7 +60,7 @@ int Import_iTML ( vlc_object_t * );
 int Import_WPL ( vlc_object_t * );
 void Close_WPL ( vlc_object_t * );
 
-#define GetCurrentItem(obj) input_GetItem((obj)->p_input)
+#define GetCurrentItem(obj) input_GetItem((obj)->p_input_item)
 #define GetSource(obj) ((obj)->s)
 
 #define CHECK_FILE(obj) \
diff --git a/modules/services_discovery/sap.c b/modules/services_discovery/sap.c
index e58647d5ad..a3233f3b26 100644
--- a/modules/services_discovery/sap.c
+++ b/modules/services_discovery/sap.c
@@ -616,19 +616,14 @@ static int Demux( demux_t *p_demux )
 {
     demux_sys_t *p_sys = p_demux->p_sys;
     sdp_t *p_sdp = p_sys->p_sdp;
-    input_thread_t *p_input = p_demux->p_input;
-    input_item_t *p_parent_input;
+    input_item_t *p_parent_input = p_demux->p_input_item;
 
-    if( !p_input )
+    if( !p_parent_input )
     {
         msg_Err( p_demux, "parent input could not be found" );
         return VLC_EGENERIC;
     }
 
-    /* This item hasn't been held by input_GetItem
-     * don't release it */
-    p_parent_input = input_GetItem( p_input );
-
     input_item_SetURI( p_parent_input, p_sdp->psz_uri );
     input_item_SetName( p_parent_input, p_sdp->psz_sessionname );
     if( p_sdp->rtcp_port )
diff --git a/modules/stream_filter/record.c b/modules/stream_filter/record.c
index d35fba73a9..3563663cb8 100644
--- a/modules/stream_filter/record.c
+++ b/modules/stream_filter/record.c
@@ -180,7 +180,8 @@ static int Start( stream_t *s, const char *psz_extension )
 
     /* Create file name
      * TODO allow prefix configuration */
-    psz_file = input_CreateFilename( s->p_input, NULL, psz_path, INPUT_RECORD_PREFIX, psz_extension );
+    psz_file = input_CreateFilename( NULL, s->p_input_item, psz_path,
+                                     INPUT_RECORD_PREFIX, psz_extension );
 
     free( psz_path );
 
diff --git a/modules/stream_out/chromecast/chromecast_demux.cpp b/modules/stream_out/chromecast/chromecast_demux.cpp
index d9f608d9b4..e0e374d66c 100644
--- a/modules/stream_out/chromecast/chromecast_demux.cpp
+++ b/modules/stream_out/chromecast/chromecast_demux.cpp
@@ -60,8 +60,7 @@ struct demux_cc
         vlc_meta_t *p_meta = vlc_meta_New();
         if( likely(p_meta != NULL) )
         {
-            input_item_t *p_item = p_demux->p_next->p_input ?
-                                   input_GetItem( p_demux->p_next->p_input ) : NULL;
+            input_item_t *p_item = p_demux->p_next->p_input_item;
             if( p_item )
             {
                 /* Favor Meta from the input item of the input_thread since
diff --git a/src/input/access.c b/src/input/access.c
index e0ff90a273..2365172d57 100644
--- a/src/input/access.c
+++ b/src/input/access.c
@@ -41,6 +41,7 @@
 struct vlc_access_private
 {
     module_t *module;
+    input_thread_t *input;
 };
 
 /* Decode URL (which has had its scheme stripped earlier) to a file path. */
@@ -87,13 +88,14 @@ static stream_t *access_New(vlc_object_t *parent, input_thread_t *input,
     if (unlikely(access == NULL))
         return NULL;
 
-    access->p_input = input;
+    access->p_input_item = input ? input_GetItem(input) : NULL;
     access->out = out;
     access->psz_name = NULL;
     access->psz_url = strdup(mrl);
     access->psz_filepath = NULL;
     access->b_preparsing = preparsing;
     priv = vlc_stream_Private(access);
+    priv->input = input;
 
     if (unlikely(access->psz_url == NULL))
         goto error;
@@ -196,7 +198,6 @@ int access_vaDirectoryControlHelper( stream_t *p_access, int i_query, va_list ar
 static block_t *AStreamReadBlock(stream_t *s, bool *restrict eof)
 {
     stream_t *access = s->p_sys;
-    input_thread_t *input = s->p_input;
     block_t * block;
 
     if (vlc_stream_Eof(access))
@@ -209,9 +210,11 @@ static block_t *AStreamReadBlock(stream_t *s, bool *restrict eof)
 
     block = vlc_stream_ReadBlock(access);
 
-    if (block != NULL && input != NULL)
+    if (block != NULL)
     {
-        struct input_stats *stats = input_priv(input)->stats;
+        struct vlc_access_private *priv = vlc_stream_Private(access);
+        struct input_stats *stats =
+            priv->input ? input_priv(priv->input)->stats : NULL;
         if (stats != NULL)
             input_rate_Add(&stats->input_bitrate, block->i_buffer);
     }
@@ -223,7 +226,6 @@ static block_t *AStreamReadBlock(stream_t *s, bool *restrict eof)
 static ssize_t AStreamReadStream(stream_t *s, void *buf, size_t len)
 {
     stream_t *access = s->p_sys;
-    input_thread_t *input = s->p_input;
 
     if (vlc_stream_Eof(access))
         return 0;
@@ -232,9 +234,11 @@ static ssize_t AStreamReadStream(stream_t *s, void *buf, size_t len)
 
     ssize_t val = vlc_stream_ReadPartial(access, buf, len);
 
-    if (val > 0 && input != NULL)
+    if (val > 0)
     {
-        struct input_stats *stats = input_priv(input)->stats;
+        struct vlc_access_private *priv = vlc_stream_Private(access);
+        struct input_stats *stats =
+            priv->input ? input_priv(priv->input)->stats : NULL;
         if (stats != NULL)
             input_rate_Add(&stats->input_bitrate, val);
     }
@@ -282,7 +286,7 @@ stream_t *stream_AccessNew(vlc_object_t *parent, input_thread_t *input,
             return NULL;
         }
 
-        s->p_input = input;
+        s->p_input_item = input ? input_GetItem(input) : NULL;
         s->psz_url = strdup(access->psz_url);
 
         if (access->pf_block != NULL)
diff --git a/src/input/demux.c b/src/input/demux.c
index bb87fa39c2..3631e08984 100644
--- a/src/input/demux.c
+++ b/src/input/demux.c
@@ -32,6 +32,7 @@
 #include <libvlc.h>
 #include <vlc_codec.h>
 #include <vlc_meta.h>
+#include <vlc_input.h>
 #include <vlc_url.h>
 #include <vlc_modules.h>
 #include <vlc_strings.h>
@@ -178,7 +179,7 @@ static int demux_Probe(void *func, va_list ap)
     return probe(VLC_OBJECT(demux));
 }
 
-demux_t *demux_NewAdvanced( vlc_object_t *p_obj, input_thread_t *p_parent_input,
+demux_t *demux_NewAdvanced( vlc_object_t *p_obj, input_thread_t *p_input,
                             const char *psz_demux, const char *url,
                             stream_t *s, es_out_t *out, bool b_preparsing )
 {
@@ -202,7 +203,7 @@ demux_t *demux_NewAdvanced( vlc_object_t *p_obj, input_thread_t *p_parent_input,
         }
     }
 
-    p_demux->p_input = p_parent_input;
+    p_demux->p_input_item = p_input ? input_GetItem(p_input) : NULL;
     p_demux->psz_name = strdup( psz_demux );
     if (unlikely(p_demux->psz_name == NULL))
         goto error;
@@ -485,7 +486,7 @@ static demux_t *demux_FilterNew( demux_t *p_next, const char *p_name )
 
     priv = vlc_stream_Private(p_demux);
     p_demux->p_next       = p_next;
-    p_demux->p_input      = NULL;
+    p_demux->p_input_item = NULL;
     p_demux->p_sys        = NULL;
     p_demux->psz_name     = NULL;
     p_demux->psz_url      = NULL;
diff --git a/src/input/stream.c b/src/input/stream.c
index c4224b0c08..684290a537 100644
--- a/src/input/stream.c
+++ b/src/input/stream.c
@@ -85,7 +85,7 @@ stream_t *vlc_stream_CustomNew(vlc_object_t *parent,
     s->pf_seek = NULL;
     s->pf_control = NULL;
     s->p_sys = NULL;
-    s->p_input = NULL;
+    s->p_input_item = NULL;
     assert(destroy != NULL);
     priv->destroy = destroy;
     priv->block = NULL;
diff --git a/src/input/stream_extractor.c b/src/input/stream_extractor.c
index 7ccc4b6296..c8e9298ab0 100644
--- a/src/input/stream_extractor.c
+++ b/src/input/stream_extractor.c
@@ -265,7 +265,7 @@ se_AttachWrapper( struct stream_extractor_private* priv, stream_t* source )
     }
 
     priv->wrapper = s;
-    priv->wrapper->p_input = source->p_input;
+    priv->wrapper->p_input_item = source->p_input_item;
     priv->wrapper->p_sys = priv;
 
     priv->source = source;
diff --git a/src/input/stream_filter.c b/src/input/stream_filter.c
index a14d34dd5e..ea6fd308a7 100644
--- a/src/input/stream_filter.c
+++ b/src/input/stream_filter.c
@@ -60,7 +60,7 @@ stream_t *vlc_stream_FilterNew( stream_t *p_source,
         return NULL;
 
     priv = vlc_stream_Private(s);
-    s->p_input = p_source->p_input;
+    s->p_input_item = p_source->p_input_item;
 
     if( p_source->psz_url != NULL )
     {
-- 
2.18.0



More information about the vlc-devel mailing list