[vlc-commits] input: preparse in a thread (refs #14571)

Rémi Denis-Courmont git at videolan.org
Wed Oct 28 18:47:49 CET 2015


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Oct 28 18:43:36 2015 +0200| [d8e2c680c6025a99b13e890ac4b83551182bf930] | committer: Rémi Denis-Courmont

input: preparse in a thread (refs #14571)

This adds a new function to create a preparsing input thread, and
runs preparsing within a dedicated thread.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=d8e2c680c6025a99b13e890ac4b83551182bf930
---

 src/input/input.c           |   67 +++++++++++++++++++++++++++++--------------
 src/input/input_interface.h |   13 +++++++++
 2 files changed, 58 insertions(+), 22 deletions(-)

diff --git a/src/input/input.c b/src/input/input.c
index f6fc62f..04af6d4 100644
--- a/src/input/input.c
+++ b/src/input/input.c
@@ -55,7 +55,8 @@
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
-static  void *Run            ( void * );
+static  void *Run( void * );
+static  void *Preparse( void * );
 
 static input_thread_t * Create  ( vlc_object_t *, input_item_t *,
                                   const char *, bool, input_resource_t * );
@@ -149,6 +150,12 @@ int input_Read( vlc_object_t *p_parent, input_item_t *p_item )
     return VLC_SUCCESS;
 }
 
+input_thread_t *input_CreatePreparser( vlc_object_t *parent,
+                                       input_item_t *item )
+{
+    return Create( parent, item, NULL, true, NULL );
+}
+
 /**
  * Initialize an input and initialize it to preparse the item
  * This function is blocking. It will only accept parsing regular files.
@@ -160,30 +167,16 @@ int input_Read( vlc_object_t *p_parent, input_item_t *p_item )
 int input_Preparse( vlc_object_t *p_parent, input_item_t *p_item )
 {
     input_thread_t *p_input;
+    int ret;
 
     /* Allocate descriptor */
-    p_input = Create( p_parent, p_item, NULL, true, NULL );
+    p_input = input_CreatePreparser( p_parent, p_item );
     if( !p_input )
         return VLC_EGENERIC;
 
-    if( !Init( p_input ) ) {
-        /* if the demux is a playlist, call Mainloop that will call
-         * demux_Demux in order to fetch sub items */
-        bool b_is_playlist = false;
-
-        if ( input_item_ShouldPreparseSubItems( p_item )
-          && demux_Control( p_input->p->master->p_demux,
-                            DEMUX_IS_PLAYLIST,
-                            &b_is_playlist ) )
-            b_is_playlist = false;
-        if( b_is_playlist )
-            MainLoop( p_input, false );
-        End( p_input );
-    }
-
-    vlc_object_release( p_input );
-
-    return VLC_SUCCESS;
+    ret = input_Start( p_input );
+    input_Close( p_input );
+    return ret;
 }
 
 /**
@@ -195,10 +188,15 @@ int input_Preparse( vlc_object_t *p_parent, input_item_t *p_item )
  */
 int input_Start( input_thread_t *p_input )
 {
+    void *(*func)(void *) = Run;
+
+    if( p_input->b_preparsing )
+        func = Preparse;
+
     assert( !p_input->p->is_running );
     /* Create thread and wait for its readiness. */
-    p_input->p->is_running = !vlc_clone( &p_input->p->thread,
-                                         Run, p_input, VLC_THREAD_PRIORITY_INPUT );
+    p_input->p->is_running = !vlc_clone( &p_input->p->thread, func, p_input,
+                                         VLC_THREAD_PRIORITY_INPUT );
     if( !p_input->p->is_running )
     {
         input_ChangeState( p_input, ERROR_S );
@@ -508,6 +506,31 @@ static void *Run( void *obj )
     return NULL;
 }
 
+static void *Preparse( void *obj )
+{
+    input_thread_t *p_input = (input_thread_t *)obj;
+
+    vlc_interrupt_set(&p_input->p->interrupt);
+
+    if( !Init( p_input ) )
+    {   /* if the demux is a playlist, call Mainloop that will call
+         * demux_Demux in order to fetch sub items */
+        bool b_is_playlist = false;
+
+        if ( input_item_ShouldPreparseSubItems( p_input->p->p_item )
+          && demux_Control( p_input->p->master->p_demux,
+                            DEMUX_IS_PLAYLIST,
+                            &b_is_playlist ) )
+            b_is_playlist = false;
+        if( b_is_playlist )
+            MainLoop( p_input, false );
+        End( p_input );
+    }
+
+    input_SendEventDead( p_input );
+    return NULL;
+}
+
 bool input_Stopped( input_thread_t *input )
 {
     input_thread_private_t *sys = input->p;
diff --git a/src/input/input_interface.h b/src/input/input_interface.h
index e7b634a..3108d15 100644
--- a/src/input/input_interface.h
+++ b/src/input/input_interface.h
@@ -37,6 +37,19 @@ void input_item_SetArtFetched( input_item_t *p_i, bool b_art_fetched );
 void input_item_SetEpg( input_item_t *p_item, const vlc_epg_t *p_epg );
 void input_item_SetEpgOffline( input_item_t * );
 
+/**
+ * Creates an item preparser.
+ *
+ * Creates an input thread to preparse an item. The input needs to be started
+ * with input_Start() afterwards.
+ *
+ * @param obj parent object
+ * @param item input item to preparse
+ * @return an input thread or NULL on error
+ */
+input_thread_t *input_CreatePreparser(vlc_object_t *obj, input_item_t *item)
+VLC_USED;
+
 int input_Preparse( vlc_object_t *, input_item_t * );
 
 /* misc/stats.c



More information about the vlc-commits mailing list