[vlc-devel] [PATCH 06/10] Adds VLC_ENEEDBROSE and make input report an item need browsing

Julien 'Lta' BALLET elthariel at gmail.com
Mon May 26 11:41:46 CEST 2014


From: Julien 'Lta' BALLET <contact at lta.io>

---
 include/vlc_common.h |  1 +
 src/input/input.c    | 52 ++++++++++++++++++++++++++++++++++++++--------------
 2 files changed, 39 insertions(+), 14 deletions(-)

diff --git a/include/vlc_common.h b/include/vlc_common.h
index 38ce2a6..fe2ae16 100644
--- a/include/vlc_common.h
+++ b/include/vlc_common.h
@@ -381,6 +381,7 @@ struct vlc_list_t
 #define VLC_ENOVAR         (-6) /**< Variable not found */
 #define VLC_EBADVAR        (-7) /**< Bad variable value */
 #define VLC_ENOITEM        (-8) /**< Item not found */
+#define VLC_ENEEDBROWSE    (-9) /**< The item needs browsing */
 
 /*****************************************************************************
  * Variable callbacks
diff --git a/src/input/input.c b/src/input/input.c
index 7e71d4e..0837cde 100644
--- a/src/input/input.c
+++ b/src/input/input.c
@@ -166,14 +166,20 @@ int input_Read( vlc_object_t *p_parent, input_item_t *p_item )
     if( !p_input )
         return VLC_EGENERIC;
 
-    if( !Init( p_input ) )
+    int i_res = Init( p_input );
+    if( !i_res )
     {
         MainLoop( p_input, false );
         End( p_input );
     }
 
     vlc_object_release( p_input );
-    return VLC_SUCCESS;
+
+    /* Uncomment if VLC_SUCCESS is required whenever Create succeeds */
+    /* if (i_res ==  VLC_ENEEDBROWSE) */
+        return i_res;
+    /* else
+        return VLC_SUCCESS; */
 }
 
 /**
@@ -182,7 +188,8 @@ int input_Read( vlc_object_t *p_parent, input_item_t *p_item )
  *
  * \param p_parent a vlc_object_t
  * \param p_item an input item
- * \return VLC_SUCCESS or an error
+ * \return VLC_SUCCESS or an error. More especially, it'll return
+ * VLC_ENEEDBROWSE if you try to preparse a folder
  */
 int input_Preparse( vlc_object_t *p_parent, input_item_t *p_item )
 {
@@ -193,12 +200,17 @@ int input_Preparse( vlc_object_t *p_parent, input_item_t *p_item )
     if( !p_input )
         return VLC_EGENERIC;
 
-    if( !Init( p_input ) )
+    int i_res = Init( p_input );
+    if( !i_res )
         End( p_input );
 
     vlc_object_release( p_input );
 
-    return VLC_SUCCESS;
+    /* Uncomment if VLC_SUCCESS is required whenever Create succeeds */
+    /* if (i_res ==  VLC_ENEEDBROWSE) */
+        return i_res;
+    /* else
+        return VLC_SUCCESS; */
 }
 
 /**
@@ -515,7 +527,8 @@ static void *Run( void *obj )
     input_thread_t *p_input = (input_thread_t *)obj;
     const int canc = vlc_savecancel();
 
-    if( Init( p_input ) )
+    int i_res = Init( p_input );
+    if( i_res )
         goto exit;
 
     MainLoop( p_input, true ); /* FIXME it can be wrong (like with VLM) */
@@ -529,6 +542,9 @@ exit:
     const bool b_abort = p_input->p->b_abort;
     vlc_mutex_unlock( &p_input->p->lock_control );
 
+    if( i_res == VLC_ENEEDBROWSE )
+        input_SendEventBrowse( p_input );
+
     if( b_abort )
         input_SendEventAbort( p_input );
     input_SendEventDead( p_input );
@@ -1178,7 +1194,7 @@ static void InitPrograms( input_thread_t * p_input )
 static int Init( input_thread_t * p_input )
 {
     vlc_meta_t *p_meta;
-    int i;
+    int i, i_res;
 
     for( i = 0; i < p_input->p->p_item->i_options; i++ )
     {
@@ -1196,7 +1212,7 @@ static int Init( input_thread_t * p_input )
 
     InitStatistics( p_input );
 #ifdef ENABLE_SOUT
-    if( InitSout( p_input ) )
+    if( ( i_res = InitSout( p_input ) ) )
         goto error;
 #endif
 
@@ -1208,8 +1224,9 @@ static int Init( input_thread_t * p_input )
     input_SendEventCache( p_input, 0.0 );
 
     /* */
-    if( InputSourceInit( p_input, &p_input->p->input,
-                         p_input->p->p_item->psz_uri, NULL, false ) )
+    if( ( i_res = InputSourceInit( p_input, &p_input->p->input,
+                                   p_input->p->p_item->psz_uri,
+                                   NULL, false ) ) )
     {
         goto error;
     }
@@ -1333,7 +1350,7 @@ error:
     p_input->p->p_es_out = NULL;
     p_input->p->p_sout = NULL;
 
-    return VLC_EGENERIC;
+    return i_res;
 }
 
 /*****************************************************************************
@@ -2210,6 +2227,7 @@ static int InputSourceInit( input_thread_t *p_input,
     const char *psz_access, *psz_demux, *psz_path, *psz_anchor = NULL;
     char *psz_var_demux = NULL;
     double f_fps;
+    int i_error = VLC_EGENERIC;
 
     assert( psz_mrl );
     char *psz_dup = strdup( psz_mrl );
@@ -2302,9 +2320,15 @@ static int InputSourceInit( input_thread_t *p_input,
     {   /* Now try a real access */
         access_t *p_access = access_New( p_input, p_input,
                                          psz_access, psz_demux, psz_path );
-        if( p_access == NULL )
+        if( p_access == NULL)
         {
-            if( vlc_object_alive( p_input ) )
+            if( input_item_NeedsBrowsing( input_GetItem(p_input) ) )
+            {
+                msg_Dbg( p_input, "open of %s failed, it needs browsing first",
+                         psz_mrl );
+                i_error = VLC_ENEEDBROWSE;
+            }
+            else if( vlc_object_alive( p_input ))
             {
                 msg_Err( p_input, "open of `%s' failed", psz_mrl );
                 if( !b_in_can_fail )
@@ -2506,7 +2530,7 @@ error:
     free( psz_var_demux );
     free( psz_dup );
 
-    return VLC_EGENERIC;
+    return i_error;
 }
 
 /*****************************************************************************
-- 
1.9.3




More information about the vlc-devel mailing list