[vlc-devel] [PATCH 2/7] input: add b_net variable in item

Thomas Guillem thomas at gllm.fr
Tue Mar 24 18:22:15 CET 2015


When an item was a NET/STREAM type, there was no way to distinguish if the item
was a file, a playlist or directory.

Add a new variable, b_net in addition to i_type. This variable is automatically
set when creating a new Item (set to true for ITEM_TYPE_STREAM). It can be
overridden via the new input_item_NewWithTypeExt function. This new function
will allow accesses to create FILE, or DIRECTORY items with b_net set to true.

Unless forced, the preparser won't parse items with b_net == true.
---
 include/vlc_input_item.h         |  12 ++++
 modules/services_discovery/sap.c |   1 +
 src/input/item.c                 | 139 +++++++++++++++++++++++----------------
 src/libvlccore.sym               |   1 +
 src/playlist/preparser.c         |   6 +-
 5 files changed, 98 insertions(+), 61 deletions(-)

diff --git a/include/vlc_input_item.h b/include/vlc_input_item.h
index 1bd86fb..d0a6854 100644
--- a/include/vlc_input_item.h
+++ b/include/vlc_input_item.h
@@ -85,6 +85,8 @@ struct input_item_t
     vlc_mutex_t lock;                 /**< Lock for the item */
 
     uint8_t     i_type;              /**< Type (file, disc, ... see input_item_type_e) */
+    bool        b_net;               /**< Net: always true for TYPE_STREAM, it
+                                          depends for others types */
     bool        b_error_when_reading;/**< Error When Reading */
 };
 
@@ -258,6 +260,16 @@ VLC_API input_item_t * input_item_NewWithType( const char *psz_uri, const char *
 /**
  * This function creates a new input_item_t with the provided information.
  *
+ * \param i_net 1/0: force b_net to true/false, -1: default (guess it)
+ *
+ * XXX You may also use input_item_New, input_item_NewExt, or
+ * input_item_NewWithType as they need less arguments.
+ */
+VLC_API input_item_t * input_item_NewWithTypeExt( const char *psz_uri, const char *psz_name, int i_options, const char *const *ppsz_options, unsigned i_option_flags, mtime_t i_duration, int i_type, int i_net ) VLC_USED;
+
+/**
+ * This function creates a new input_item_t with the provided information.
+ *
  * Provided for convenience.
  */
 VLC_API input_item_t * input_item_NewExt( const char *psz_uri, const char *psz_name, int i_options, const char *const *ppsz_options, unsigned i_option_flags, mtime_t i_duration ) VLC_USED;
diff --git a/modules/services_discovery/sap.c b/modules/services_discovery/sap.c
index 631c16d..4b06b1f 100644
--- a/modules/services_discovery/sap.c
+++ b/modules/services_discovery/sap.c
@@ -644,6 +644,7 @@ static int Demux( demux_t *p_demux )
     vlc_mutex_lock( &p_parent_input->lock );
 
     p_parent_input->i_type = ITEM_TYPE_STREAM;
+    p_parent_input->b_net = true;
 
     vlc_mutex_unlock( &p_parent_input->lock );
     vlc_object_release( p_input );
diff --git a/src/input/item.c b/src/input/item.c
index 5acb532..f907974 100644
--- a/src/input/item.c
+++ b/src/input/item.c
@@ -35,7 +35,7 @@
 #include "item.h"
 #include "info.h"
 
-static int GuessType( const input_item_t *p_item );
+static int GuessType( const input_item_t *p_item, bool *p_net );
 
 void input_item_SetErrorWhenReading( input_item_t *p_i, bool b_error )
 {
@@ -306,7 +306,7 @@ void input_item_SetURI( input_item_t *p_i, const char *psz_uri )
     free( p_i->psz_uri );
     p_i->psz_uri = strdup( psz_uri );
 
-    p_i->i_type = GuessType( p_i );
+    p_i->i_type = GuessType( p_i, &p_i->b_net );
 
     if( p_i->psz_name )
         ;
@@ -831,9 +831,10 @@ input_item_t *input_item_NewExt( const char *psz_uri,
 
 
 input_item_t *
-input_item_NewWithType( const char *psz_uri, const char *psz_name,
-                        int i_options, const char *const *ppsz_options,
-                        unsigned flags, mtime_t duration, int type )
+input_item_NewWithTypeExt( const char *psz_uri, const char *psz_name,
+                           int i_options, const char *const *ppsz_options,
+                           unsigned flags, mtime_t duration, int type,
+                           int i_net )
 {
     static atomic_uint last_input_id = ATOMIC_VAR_INIT(0);
 
@@ -886,9 +887,24 @@ input_item_NewWithType( const char *psz_uri, const char *psz_name,
     if( type != ITEM_TYPE_UNKNOWN )
         p_input->i_type = type;
     p_input->b_error_when_reading = false;
+
+    if( i_net != -1 )
+        p_input->b_net = !!i_net;
+    else if( p_input->i_type == ITEM_TYPE_STREAM )
+        p_input->b_net = true;
     return p_input;
 }
 
+input_item_t *
+input_item_NewWithType( const char *psz_uri, const char *psz_name,
+                        int i_options, const char *const *ppsz_options,
+                        unsigned flags, mtime_t duration, int type )
+{
+    return input_item_NewWithTypeExt( psz_uri, psz_name, i_options,
+                                      ppsz_options, flags, duration, type,
+                                      -1 );
+}
+
 input_item_t *input_item_Copy( input_item_t *p_input )
 {
     vlc_mutex_lock( &p_input->lock );
@@ -923,6 +939,7 @@ struct item_type_entry
 {
     const char psz_scheme[7];
     uint8_t    i_type;
+    bool       b_net;
 };
 
 static int typecmp( const void *key, const void *entry )
@@ -934,61 +951,61 @@ static int typecmp( const void *key, const void *entry )
 }
 
 /* Guess the type of the item using the beginning of the mrl */
-static int GuessType( const input_item_t *p_item )
+static int GuessType( const input_item_t *p_item, bool *p_net )
 {
     static const struct item_type_entry tab[] =
     {   /* /!\ Alphabetical order /!\ */
         /* Short match work, not just exact match */
-        { "alsa",   ITEM_TYPE_CARD },
-        { "atsc",   ITEM_TYPE_CARD },
-        { "bd",     ITEM_TYPE_DISC },
-        { "cable",  ITEM_TYPE_CARD },
-        { "cdda",   ITEM_TYPE_CDDA },
-        { "cqam",   ITEM_TYPE_CARD },
-        { "dc1394", ITEM_TYPE_CARD },
-        { "dccp",   ITEM_TYPE_STREAM },
-        { "deckli", ITEM_TYPE_CARD }, /* decklink */
-        { "dir",    ITEM_TYPE_DIRECTORY },
-        { "dshow",  ITEM_TYPE_CARD },
-        { "dv",     ITEM_TYPE_CARD },
-        { "dvb",    ITEM_TYPE_CARD },
-        { "dvd",    ITEM_TYPE_DISC },
-        { "dtv",    ITEM_TYPE_CARD },
-        { "eyetv",  ITEM_TYPE_CARD },
-        { "fd",     ITEM_TYPE_UNKNOWN },
-        { "ftp",    ITEM_TYPE_STREAM },
-        { "http",   ITEM_TYPE_STREAM },
-        { "icyx",   ITEM_TYPE_STREAM },
-        { "imem",   ITEM_TYPE_UNKNOWN },
-        { "itpc",   ITEM_TYPE_STREAM },
-        { "jack",   ITEM_TYPE_CARD },
-        { "linsys", ITEM_TYPE_CARD },
-        { "live",   ITEM_TYPE_STREAM }, /* livedotcom */
-        { "mms",    ITEM_TYPE_STREAM },
-        { "mtp",    ITEM_TYPE_DISC },
-        { "ofdm",   ITEM_TYPE_CARD },
-        { "oss",    ITEM_TYPE_CARD },
-        { "pnm",    ITEM_TYPE_STREAM },
-        { "qam",    ITEM_TYPE_CARD },
-        { "qpsk",   ITEM_TYPE_CARD },
-        { "qtcapt", ITEM_TYPE_CARD }, /* qtcapture */
-        { "raw139", ITEM_TYPE_CARD }, /* raw1394 */
-        { "rt",     ITEM_TYPE_STREAM }, /* rtp, rtsp, rtmp */
-        { "satell", ITEM_TYPE_CARD }, /* sattelite */
-        { "screen", ITEM_TYPE_CARD },
-        { "sdp",    ITEM_TYPE_STREAM },
-        { "sftp",   ITEM_TYPE_STREAM },
-        { "shm",    ITEM_TYPE_CARD },
-        { "smb",    ITEM_TYPE_STREAM },
-        { "svcd",   ITEM_TYPE_DISC },
-        { "tcp",    ITEM_TYPE_STREAM },
-        { "terres", ITEM_TYPE_CARD }, /* terrestrial */
-        { "udp",    ITEM_TYPE_STREAM },  /* udplite too */
-        { "unsv",   ITEM_TYPE_STREAM },
-        { "usdigi", ITEM_TYPE_CARD }, /* usdigital */
-        { "v4l",    ITEM_TYPE_CARD },
-        { "vcd",    ITEM_TYPE_DISC },
-        { "window", ITEM_TYPE_CARD },
+        { "alsa",   ITEM_TYPE_CARD, false },
+        { "atsc",   ITEM_TYPE_CARD, false },
+        { "bd",     ITEM_TYPE_DISC, false },
+        { "cable",  ITEM_TYPE_CARD, false },
+        { "cdda",   ITEM_TYPE_CDDA, false },
+        { "cqam",   ITEM_TYPE_CARD, false },
+        { "dc1394", ITEM_TYPE_CARD, false },
+        { "dccp",   ITEM_TYPE_STREAM, true },
+        { "deckli", ITEM_TYPE_CARD, false }, /* decklink */
+        { "dir",    ITEM_TYPE_DIRECTORY, false },
+        { "dshow",  ITEM_TYPE_CARD, false },
+        { "dv",     ITEM_TYPE_CARD, false },
+        { "dvb",    ITEM_TYPE_CARD, false },
+        { "dvd",    ITEM_TYPE_DISC, false },
+        { "dtv",    ITEM_TYPE_CARD, false },
+        { "eyetv",  ITEM_TYPE_CARD, false },
+        { "fd",     ITEM_TYPE_UNKNOWN, false },
+        { "ftp",    ITEM_TYPE_FILE, true },
+        { "http",   ITEM_TYPE_FILE, true },
+        { "icyx",   ITEM_TYPE_STREAM, true },
+        { "imem",   ITEM_TYPE_UNKNOWN, false },
+        { "itpc",   ITEM_TYPE_PLAYLIST, true },
+        { "jack",   ITEM_TYPE_CARD, false },
+        { "linsys", ITEM_TYPE_CARD, false },
+        { "live",   ITEM_TYPE_STREAM, true }, /* livedotcom */
+        { "mms",    ITEM_TYPE_STREAM, true },
+        { "mtp",    ITEM_TYPE_DISC, false },
+        { "ofdm",   ITEM_TYPE_CARD, false },
+        { "oss",    ITEM_TYPE_CARD, false },
+        { "pnm",    ITEM_TYPE_STREAM, true },
+        { "qam",    ITEM_TYPE_CARD, false },
+        { "qpsk",   ITEM_TYPE_CARD, false },
+        { "qtcapt", ITEM_TYPE_CARD, false }, /* qtcapture */
+        { "raw139", ITEM_TYPE_CARD, false }, /* raw1394 */
+        { "rt",     ITEM_TYPE_STREAM, true }, /* rtp, rtsp, rtmp */
+        { "satell", ITEM_TYPE_CARD, false }, /* sattelite */
+        { "screen", ITEM_TYPE_CARD, false },
+        { "sdp",    ITEM_TYPE_STREAM, true },
+        { "sftp",   ITEM_TYPE_FILE, true },
+        { "shm",    ITEM_TYPE_CARD, false },
+        { "smb",    ITEM_TYPE_FILE, true },
+        { "svcd",   ITEM_TYPE_DISC, false },
+        { "tcp",    ITEM_TYPE_STREAM, true },
+        { "terres", ITEM_TYPE_CARD, false }, /* terrestrial */
+        { "udp",    ITEM_TYPE_STREAM, true },  /* udplite too */
+        { "unsv",   ITEM_TYPE_STREAM, true },
+        { "usdigi", ITEM_TYPE_CARD, false }, /* usdigital */
+        { "v4l",    ITEM_TYPE_CARD, false },
+        { "vcd",    ITEM_TYPE_DISC, false },
+        { "window", ITEM_TYPE_CARD, false },
     };
     const struct item_type_entry *e;
 
@@ -997,7 +1014,15 @@ static int GuessType( const input_item_t *p_item )
 
     e = bsearch( p_item->psz_uri, tab, sizeof( tab ) / sizeof( tab[0] ),
                  sizeof( tab[0] ), typecmp );
-    return e ? e->i_type : ITEM_TYPE_FILE;
+    if( e )
+    {
+        *p_net = e->b_net;
+        return e->i_type;
+    } else
+    {
+        *p_net = false;
+        return ITEM_TYPE_FILE;
+    }
 }
 
 input_item_node_t *input_item_node_Create( input_item_t *p_input )
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index 1b39c0e..2d88c8d 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -199,6 +199,7 @@ input_item_MetaMatch
 input_item_MergeInfos
 input_item_NewExt
 input_item_NewWithType
+input_item_NewWithTypeExt
 input_item_Hold
 input_item_Release
 input_item_node_AppendItem
diff --git a/src/playlist/preparser.c b/src/playlist/preparser.c
index 0acdfd9..f1c1d1f 100644
--- a/src/playlist/preparser.c
+++ b/src/playlist/preparser.c
@@ -147,6 +147,7 @@ static void Preparse( vlc_object_t *obj, input_item_t *p_item,
 {
     vlc_mutex_lock( &p_item->lock );
     int i_type = p_item->i_type;
+    bool b_net = p_item->b_net;
     vlc_mutex_unlock( &p_item->lock );
 
     bool b_preparse = false;
@@ -155,10 +156,7 @@ static void Preparse( vlc_object_t *obj, input_item_t *p_item,
     case ITEM_TYPE_DIRECTORY:
     case ITEM_TYPE_PLAYLIST:
     case ITEM_TYPE_NODE:
-        b_preparse = true;
-        break;
-    case ITEM_TYPE_STREAM:
-        if (i_options & META_REQUEST_OPTION_SCOPE_NETWORK)
+        if (!b_net || i_options & META_REQUEST_OPTION_SCOPE_NETWORK)
             b_preparse = true;
         break;
     }
-- 
2.1.3




More information about the vlc-devel mailing list