Remove vlc_object_find for playlist from the core
authorClément Stenac <zorglub@videolan.org>
Fri, 15 Sep 2006 22:10:37 +0000 (22:10 +0000)
committerClément Stenac <zorglub@videolan.org>
Fri, 15 Sep 2006 22:10:37 +0000 (22:10 +0000)
include/vlc_playlist.h
src/input/control.c
src/input/input.c
src/input/item.c
src/interface/interaction.c
src/video_output/video_output.c
src/video_output/vout_intf.c

index ac041fd..6018b90 100644 (file)
@@ -24,6 +24,8 @@
 #ifndef _VLC_PLAYLIST_H_
 #define _VLC_PLAYLIST_H_
 
+#include <assert.h>
+
 /**
  *  \file
  *  This file contain structures and function prototypes related
@@ -208,6 +210,16 @@ int           playlist_ThreadDestroy  ( playlist_t * );
 #define PL_LOCK vlc_mutex_lock( &p_playlist->object_lock );
 #define PL_UNLOCK vlc_mutex_unlock( &p_playlist->object_lock );
 
+#define pl_Get( a ) a->p_libvlc->p_playlist
+#define pl_Yield( a ) __pl_Yield( VLC_OBJECT(a) )
+static inline playlist_t *__pl_Yield( vlc_object_t *p_this )
+{
+    assert( p_this->p_libvlc->p_playlist );
+    vlc_object_yield( p_this->p_libvlc->p_playlist );
+    return p_this->p_libvlc->p_playlist;
+}
+#define pl_Release(a) vlc_object_release( a->p_libvlc->p_playlist );
+
 /* Playlist control */
 #define playlist_Play(p) playlist_LockControl(p,PLAYLIST_PLAY )
 #define playlist_Pause(p) playlist_LockControl(p,PLAYLIST_PAUSE )
index 7928182..87b96f8 100644 (file)
@@ -530,15 +530,10 @@ int input_vaControl( input_thread_t *p_input, int i_query, va_list args )
 
 static void NotifyPlaylist( input_thread_t *p_input )
 {
-    playlist_t *p_playlist =
-        (playlist_t *)vlc_object_find( p_input, VLC_OBJECT_PLAYLIST,
-                                       FIND_PARENT );
-    if( p_playlist )
-    {
-        var_SetInteger( p_playlist, "item-change",
-                        p_input->input.p_item->i_id );
-        vlc_object_release( p_playlist );
-    }
+    playlist_t *p_playlist = pl_Yield( p_input );
+    var_SetInteger( p_playlist, "item-change",
+                    p_input->input.p_item->i_id );
+    pl_Release( p_input );
 }
 
 static void UpdateBookmarksOption( input_thread_t *p_input )
index 3826284..26c85aa 100644 (file)
@@ -1135,8 +1135,6 @@ static void End( input_thread_t * p_input )
     /* Close optional stream output instance */
     if( p_input->p_sout )
     {
-        vlc_object_t *p_pl =
-            vlc_object_find( p_input, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
         vlc_value_t keep;
 
         vlc_mutex_lock( &p_input->counters.counters_lock );
@@ -1145,20 +1143,18 @@ static void End( input_thread_t * p_input )
         CL_CO( sout_send_bitrate );
         vlc_mutex_unlock( &p_input->counters.counters_lock );
 
-        if( var_Get( p_input, "sout-keep", &keep ) >= 0 && keep.b_bool && p_pl )
+        if( var_Get( p_input, "sout-keep", &keep ) >= 0 && keep.b_bool )
         {
             /* attach sout to the playlist */
             msg_Dbg( p_input, "keeping sout" );
             vlc_object_detach( p_input->p_sout );
-            vlc_object_attach( p_input->p_sout, p_pl );
+            vlc_object_attach( p_input->p_sout, p_input->p_libvlc->p_playlist );
         }
         else
         {
             msg_Dbg( p_input, "destroying sout" );
             sout_DeleteInstance( p_input->p_sout );
         }
-        if( p_pl )
-            vlc_object_release( p_pl );
     }
 
 #undef CL_CO
@@ -1824,21 +1820,16 @@ static int  UpdateMeta( input_thread_t *p_input, vlc_bool_t b_quick )
 static void UpdateItemLength( input_thread_t *p_input, int64_t i_length,
                               vlc_bool_t b_quick )
 {
-    playlist_t *p_playlist;
     char psz_buffer[MSTRTIME_MAX_SIZE];
 
     vlc_mutex_lock( &p_input->input.p_item->lock );
     p_input->input.p_item->i_duration = i_length;
     vlc_mutex_unlock( &p_input->input.p_item->lock );
 
-        p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST,
-                                               FIND_PARENT);
-    if( p_playlist )
-    {
-        var_SetInteger( p_playlist, "item-change",
-                        p_input->input.p_item->i_id );
-        vlc_object_release( p_playlist );
-    }
+    pl_Yield( p_input );
+    var_SetInteger( pl_Get( p_input ), "item-change",
+                    p_input->input.p_item->i_id );
+    pl_Release( p_input )
 
     input_Control( p_input, INPUT_ADD_INFO, _("General"), _("Duration"),
                    msecstotimestr( psz_buffer, i_length / 1000 ) );
index 4d7d94e..4b20b7d 100644 (file)
@@ -70,27 +70,22 @@ char *vlc_input_item_GetInfo( input_item_t *p_i,
 static void vlc_input_item_Destroy ( gc_object_t *p_this )
 {
     vlc_object_t *p_obj = (vlc_object_t *)p_this->p_destructor_arg;
-    int i;
     input_item_t *p_input = (input_item_t *) p_this;
+    int i;
 
-    playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_obj,
-                                          VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
-
+    playlist_t *p_playlist = pl_Yield( p_obj );
     vlc_input_item_Clean( p_input );
 
-    if( p_playlist )
+    for( i = 0 ; i< p_playlist->i_input_items ; i++ )
     {
-        for( i = 0 ; i< p_playlist->i_input_items ; i++ )
+        if( p_playlist->pp_input_items[i]->i_id == p_input->i_id )
         {
-            if( p_playlist->pp_input_items[i]->i_id == p_input->i_id )
-            {
-                REMOVE_ELEM( p_playlist->pp_input_items,
-                             p_playlist->i_input_items, i );
-                break;
-            }
+            REMOVE_ELEM( p_playlist->pp_input_items,
+                         p_playlist->i_input_items, i );
+            break;
         }
-        vlc_object_release( p_playlist );
     }
+    pl_Release( p_obj );
     free( p_input );
 }
 
@@ -208,20 +203,19 @@ input_item_t *input_ItemNewWithType( vlc_object_t *p_obj, const char *psz_uri,
                                 const char **ppsz_options, int i_duration,
                                 int i_type )
 {
-    /* FIXME DON'T SEARCH PLAYLIST */
-    /* FIXME SHOULD LOCK */
-    input_item_t *p_input = (input_item_t *)malloc( sizeof( input_item_t ) );
-    playlist_t *p_playlist = (playlist_t *) vlc_object_find( p_obj,
-                                VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
+    playlist_t *p_playlist = pl_Yield( p_obj );
+    DECMALLOC_NULL( p_input, input_item_t );
 
     vlc_input_item_Init( p_obj, p_input );
     vlc_gc_init( p_input, vlc_input_item_Destroy, (void *)p_obj );
 
+    PL_LOCK;
     p_input->i_id = ++p_playlist->i_last_input_id;
-
-    INSERT_ELEM( p_playlist->pp_input_items, p_playlist->i_input_items,
-                 p_playlist->i_input_items, p_input );
-    vlc_object_release( p_playlist );
+    TAB_APPEND( p_playlist->i_input_items,
+                p_playlist->pp_input_items,
+                p_input );
+    PL_UNLOCK;
+    pl_Release( p_obj );
 
     p_input->b_fixed_name = VLC_FALSE;
 
index 09cbd24..6b884b1 100644 (file)
@@ -445,20 +445,17 @@ void __intf_UserHide( vlc_object_t *p_this, int i_id )
 /* Get the interaction object. Create it if needed */
 static interaction_t * InteractionGet( vlc_object_t *p_this )
 {
-    playlist_t *p_playlist;
     interaction_t *p_interaction;
+    playlist_t *p_playlist = pl_Yield( p_this );
 
-    p_playlist = (playlist_t*) vlc_object_find( p_this, VLC_OBJECT_PLAYLIST,
-                                                FIND_ANYWHERE );
-    if( !p_playlist )
-        return NULL;
-
+    PL_LOCK;
     if( p_playlist->p_interaction == NULL )
        InteractionInit( p_playlist );
 
     p_interaction = p_playlist->p_interaction;
+    PL_UNLOCK;
 
-    vlc_object_release( p_playlist );
+    pl_Release( p_this );
     return p_interaction;
 }
 
index e6f60f1..8c8b8fb 100644 (file)
@@ -114,28 +114,14 @@ vout_thread_t *__vout_Request( vlc_object_t *p_this, vout_thread_t *p_vout,
 {
     if( !p_fmt )
     {
-        /* Reattach video output to input before bailing out */
+        /* Reattach video output to playlist before bailing out */
         if( p_vout )
         {
-            vlc_object_t *p_playlist;
-
-            p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST,
-                                          FIND_ANYWHERE );
-
-            if( p_playlist )
-            {
-                spu_Attach( p_vout->p_spu, p_this, VLC_FALSE );
-                vlc_object_detach( p_vout );
-                vlc_object_attach( p_vout, p_playlist );
-
-                vlc_object_release( p_playlist );
-            }
-            else
-            {
-                msg_Dbg( p_this, "cannot find playlist, destroying vout" );
-                vlc_object_detach( p_vout );
-                vout_Destroy( p_vout );
-            }
+            vlc_object_t *p_playlist = pl_Yield( p_this );
+            spu_Attach( p_vout->p_spu, p_this, VLC_FALSE );
+            vlc_object_detach( p_vout );
+            vlc_object_attach( p_vout, p_playlist );
+            pl_Release( p_this );
         }
         return NULL;
     }
@@ -151,24 +137,17 @@ vout_thread_t *__vout_Request( vlc_object_t *p_this, vout_thread_t *p_vout,
 
         if( !p_vout )
         {
-            playlist_t *p_playlist;
-
-            p_playlist = vlc_object_find( p_this,
-                                          VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
-            if( p_playlist )
+            playlist_t *p_playlist = pl_Yield( p_this );
+            vlc_mutex_lock( &p_playlist->gc_lock );
+            p_vout = vlc_object_find( p_playlist,
+                                      VLC_OBJECT_VOUT, FIND_CHILD );
+            /* only first children of p_input for unused vout */
+            if( p_vout && p_vout->p_parent != (vlc_object_t *)p_playlist )
             {
-                vlc_mutex_lock( &p_playlist->gc_lock );
-                p_vout = vlc_object_find( p_playlist,
-                                          VLC_OBJECT_VOUT, FIND_CHILD );
-                /* only first children of p_input for unused vout */
-                if( p_vout && p_vout->p_parent != (vlc_object_t *)p_playlist )
-                {
-                    vlc_object_release( p_vout );
-                    p_vout = NULL;
-                }
-                vlc_mutex_unlock( &p_playlist->gc_lock );
-                vlc_object_release( p_playlist );
+                vlc_object_release( p_vout );
+                p_vout = NULL;
             }
+            vlc_mutex_unlock( &p_playlist->gc_lock );
         }
     }
 
@@ -498,7 +477,8 @@ vout_thread_t * __vout_Create( vlc_object_t *p_parent, video_format_t *p_fmt )
  *****************************************************************************/
 void vout_Destroy( vout_thread_t *p_vout )
 {
-    vlc_object_t *p_playlist;
+    vout_thread_t *p_another_vout;
+    vlc_object_t *p_playlist = pl_Yield( p_vout );
 
     /* Request thread destruction */
     p_vout->b_die = VLC_TRUE;
@@ -506,31 +486,24 @@ void vout_Destroy( vout_thread_t *p_vout )
 
     var_Destroy( p_vout, "intf-change" );
 
-    p_playlist = vlc_object_find( p_vout, VLC_OBJECT_PLAYLIST,
-                                  FIND_ANYWHERE );
-
     if( p_vout->psz_filter_chain ) free( p_vout->psz_filter_chain );
 
     /* Free structure */
     vlc_object_destroy( p_vout );
 
-    /* If it was the last vout, tell the interface to show up */
-    if( p_playlist != NULL )
+    p_another_vout = vlc_object_find( p_playlist,
+                                      VLC_OBJECT_VOUT, FIND_ANYWHERE );
+    if( p_another_vout == NULL )
     {
-        vout_thread_t *p_another_vout = vlc_object_find( p_playlist,
-                                            VLC_OBJECT_VOUT, FIND_ANYWHERE );
-        if( p_another_vout == NULL )
-        {
-            vlc_value_t val;
-            val.b_bool = VLC_TRUE;
-            var_Set( p_playlist, "intf-show", val );
-        }
-        else
-        {
-            vlc_object_release( p_another_vout );
-        }
-        vlc_object_release( p_playlist );
+        vlc_value_t val;
+        val.b_bool = VLC_TRUE;
+        var_Set( p_playlist, "intf-show", val );
+    }
+    else
+    {
+        vlc_object_release( p_another_vout );
     }
+    vlc_object_release( p_playlist );
 }
 
 /*****************************************************************************
index 8f0944f..ede2e29 100644 (file)
@@ -1099,19 +1099,14 @@ static int OnTopCallback( vlc_object_t *p_this, char const *psz_cmd,
                          vlc_value_t oldval, vlc_value_t newval, void *p_data )
 {
     vout_thread_t *p_vout = (vout_thread_t *)p_this;
-    playlist_t *p_playlist;
+    playlist_t *p_playlist = pl_Yield( p_this );
     vout_Control( p_vout, VOUT_SET_STAY_ON_TOP, newval.b_bool );
 
-    p_playlist = (playlist_t *)vlc_object_find( p_this, VLC_OBJECT_PLAYLIST,
-                                                 FIND_PARENT );
-    if( p_playlist )
-    {
-        /* Modify playlist as well because the vout might have to be restarted */
-        var_Create( p_playlist, "video-on-top", VLC_VAR_BOOL );
-        var_Set( p_playlist, "video-on-top", newval );
+    /* Modify playlist as well because the vout might have to be restarted */
+    var_Create( p_playlist, "video-on-top", VLC_VAR_BOOL );
+    var_Set( p_playlist, "video-on-top", newval );
 
-        vlc_object_release( p_playlist );
-    }
+    pl_Release( p_this );
     return VLC_SUCCESS;
 }
 
@@ -1119,21 +1114,15 @@ static int FullscreenCallback( vlc_object_t *p_this, char const *psz_cmd,
                        vlc_value_t oldval, vlc_value_t newval, void *p_data )
 {
     vout_thread_t *p_vout = (vout_thread_t *)p_this;
-    playlist_t *p_playlist;
     vlc_value_t val;
+    playlist_t *p_playlist = pl_Yield( p_this );
 
     p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
 
-    p_playlist = (playlist_t *)vlc_object_find( p_this, VLC_OBJECT_PLAYLIST,
-                                                 FIND_PARENT );
-    if( p_playlist )
-    {
-        /* Modify playlist as well because the vout might have to be restarted */
-        var_Create( p_playlist, "fullscreen", VLC_VAR_BOOL );
-        var_Set( p_playlist, "fullscreen", newval );
-
-        vlc_object_release( p_playlist );
-    }
+    /* Modify playlist as well because the vout might have to be restarted */
+    var_Create( p_playlist, "fullscreen", VLC_VAR_BOOL );
+    var_Set( p_playlist, "fullscreen", newval );
+    pl_Release( p_playlist );
 
     /* Disable "always on top" in fullscreen mode */
     var_Get( p_vout, "video-on-top", &val );