]> git.sesse.net Git - vlc/blobdiff - src/playlist/thread.c
sd: Factorize function dispatch for better code readability.
[vlc] / src / playlist / thread.c
index 88036193ac068a34876ce6a0f61c1327e4d17570..25292e60d929a3ab8e7f5325300dfd6570139779 100644 (file)
@@ -25,6 +25,8 @@
 # include "config.h"
 #endif
 
+#include <assert.h>
+
 #include <vlc_common.h>
 #include <vlc_es.h>
 #include <vlc_input.h>
@@ -55,16 +57,6 @@ void playlist_Activate( playlist_t *p_playlist )
     /* */
     playlist_private_t *p_sys = pl_priv(p_playlist);
 
-    /* Fetcher */
-    p_sys->p_fetcher = playlist_fetcher_New( p_playlist );
-    if( !p_sys->p_fetcher )
-        msg_Err( p_playlist, "cannot create playlist fetcher" );
-
-    /* Preparse */
-    p_sys->p_preparser = playlist_preparser_New( p_playlist, p_sys->p_fetcher );
-    if( !p_sys->p_preparser )
-        msg_Err( p_playlist, "cannot create playlist preparser" );
-
     /* Start the playlist thread */
     if( vlc_clone( &p_sys->thread, Thread, p_playlist,
                    VLC_THREAD_PRIORITY_LOW ) )
@@ -81,34 +73,21 @@ void playlist_Deactivate( playlist_t *p_playlist )
 
     msg_Dbg( p_playlist, "Deactivate" );
 
-    vlc_object_kill( p_playlist );
     PL_LOCK;
+    vlc_object_kill( p_playlist );
     vlc_cond_signal( &p_sys->signal );
     PL_UNLOCK;
 
     vlc_join( p_sys->thread, NULL );
     assert( !p_sys->p_input );
 
-    PL_LOCK;
-    playlist_preparser_t *p_preparser = p_sys->p_preparser;
-    playlist_fetcher_t *p_fetcher = p_sys->p_fetcher;
-
-    p_sys->p_preparser = NULL;
-    p_sys->p_fetcher = NULL;
-    PL_UNLOCK;
-
-    if( p_preparser )
-        playlist_preparser_Delete( p_preparser );
-    if( p_fetcher )
-        playlist_fetcher_Delete( p_fetcher );
+    /* release input resources */
+    if( p_sys->p_input_resource )
+        input_resource_Delete( p_sys->p_input_resource );
+    p_sys->p_input_resource = NULL;
 
-    /* release input ressources */
-    if( p_sys->p_input_ressource )
-        input_ressource_Delete( p_sys->p_input_ressource );
-    p_sys->p_input_ressource = NULL;
-
-    /* */
-    playlist_MLDump( p_playlist );
+    if( var_InheritBool( p_playlist, "media-library" ) )
+        playlist_MLDump( p_playlist );
 
     PL_LOCK;
 
@@ -251,17 +230,22 @@ static int PlayItem( playlist_t *p_playlist, playlist_item_t *p_item )
 
     assert( p_sys->p_input == NULL );
 
-    input_thread_t *p_input_thread =
-        input_CreateThreadExtended( p_playlist, p_input, NULL, p_sys->p_input_ressource );
-
+    input_thread_t *p_input_thread = input_Create( p_playlist, p_input, NULL, p_sys->p_input_resource );
     if( p_input_thread )
     {
         p_sys->p_input = p_input_thread;
-
         var_AddCallback( p_input_thread, "intf-event", InputEvent, p_playlist );
+
+        var_SetAddress( p_playlist, "input-current", p_input_thread );
+
+        if( input_Start( p_sys->p_input ) )
+        {
+            vlc_object_release( p_input_thread );
+            p_sys->p_input = p_input_thread = NULL;
+        }
     }
 
-    p_sys->p_input_ressource = NULL;
+    p_sys->p_input_resource = NULL;
 
     char *psz_uri = input_item_GetURI( p_item->p_input );
     if( psz_uri && ( !strncmp( psz_uri, "directory:", 10 ) ||
@@ -287,14 +271,14 @@ static int PlayItem( playlist_t *p_playlist, playlist_item_t *p_item )
         if( !b_has_art || strncmp( psz_arturl, "attachment://", 13 ) )
         {
             PL_DEBUG( "requesting art for %s", psz_name );
-            playlist_AskForArtEnqueue( p_playlist, p_input, pl_Locked );
+            playlist_AskForArtEnqueue( p_playlist, p_input );
         }
         free( psz_arturl );
         free( psz_name );
     }
-
+    /* FIXME: this is not safe !!*/
     PL_UNLOCK;
-    var_SetInteger( p_playlist, "playlist-current", p_input->i_id );
+    var_SetAddress( p_playlist, "item-current", p_input );
     PL_LOCK;
 
     return VLC_SUCCESS;
@@ -473,7 +457,7 @@ static int LoopInput( playlist_t *p_playlist )
     if( ( p_sys->request.b_request || !vlc_object_alive( p_playlist ) ) && !p_input->b_die )
     {
         PL_DEBUG( "incoming request - stopping current input" );
-        input_StopThread( p_input );
+        input_Stop( p_input, true );
     }
 
     /* This input is dead. Remove it ! */
@@ -481,16 +465,16 @@ static int LoopInput( playlist_t *p_playlist )
     {
         PL_DEBUG( "dead input" );
 
-        assert( p_sys->p_input_ressource == NULL );
+        assert( p_sys->p_input_resource == NULL );
 
-        p_sys->p_input_ressource = input_DetachRessource( p_input );
+        p_sys->p_input_resource = input_DetachResource( p_input );
 
         PL_UNLOCK;
         /* We can unlock as we return VLC_EGENERIC (no event will be lost) */
 
-        /* input_ressource_t must be manipulated without playlist lock */
+        /* input_resource_t must be manipulated without playlist lock */
         if( !var_CreateGetBool( p_input, "sout-keep" ) )
-            input_ressource_TerminateSout( p_sys->p_input_ressource );
+            input_resource_TerminateSout( p_sys->p_input_resource );
 
         /* The DelCallback must be issued without playlist lock */
         var_DelCallback( p_input, "intf-event", InputEvent, p_playlist );
@@ -514,7 +498,7 @@ static int LoopInput( playlist_t *p_playlist )
     else if( p_input->b_error || p_input->b_eof )
     {
         PL_DEBUG( "finished input" );
-        input_StopThread( p_input );
+        input_Stop( p_input, false );
     }
     return VLC_SUCCESS;
 }
@@ -537,23 +521,22 @@ static void LoopRequest( playlist_t *p_playlist )
     {
         p_sys->status.i_status = PLAYLIST_STOPPED;
 
-        if( p_sys->p_input_ressource &&
-            input_ressource_HasVout( p_sys->p_input_ressource ) )
+        if( p_sys->p_input_resource &&
+            input_resource_HasVout( p_sys->p_input_resource ) )
         {
             /* XXX We can unlock if we don't issue the wait as we will be
              * call again without anything else done between the calls */
             PL_UNLOCK;
 
-            /* input_ressource_t must be manipulated without playlist lock */
-            input_ressource_TerminateVout( p_sys->p_input_ressource );
+            /* input_resource_t must be manipulated without playlist lock */
+            input_resource_TerminateVout( p_sys->p_input_resource );
 
             PL_LOCK;
         }
         else
         {
             if( vlc_object_alive( p_playlist ) )
-                vlc_cond_wait( &pl_priv(p_playlist)->signal,
-                               &vlc_internals(p_playlist)->lock );
+                vlc_cond_wait( &p_sys->signal, &p_sys->lock );
         }
         return;
     }
@@ -584,7 +567,7 @@ static void *Thread ( void *data )
     playlist_t *p_playlist = data;
     playlist_private_t *p_sys = pl_priv(p_playlist);
 
-    vlc_object_lock( p_playlist );
+    playlist_Lock( p_playlist );
     while( vlc_object_alive( p_playlist ) || p_sys->p_input )
     {
         /* FIXME: what's that ! */
@@ -598,12 +581,11 @@ static void *Thread ( void *data )
 
         /* If there is an input, check that it doesn't need to die. */
         while( !LoopInput( p_playlist ) )
-            vlc_cond_wait( &pl_priv(p_playlist)->signal,
-                           &vlc_internals(p_playlist)->lock );
+            vlc_cond_wait( &p_sys->signal, &p_sys->lock );
 
         LoopRequest( p_playlist );
     }
-    vlc_object_unlock( p_playlist );
+    playlist_Unlock( p_playlist );
 
     return NULL;
 }