Playlist: put private data after public data
authorRémi Denis-Courmont <rdenis@simphalempin.com>
Sun, 14 Sep 2008 09:35:42 +0000 (12:35 +0300)
committerRémi Denis-Courmont <rdenis@simphalempin.com>
Sun, 14 Sep 2008 09:35:42 +0000 (12:35 +0300)
include/vlc_playlist.h
src/input/meta.c
src/playlist/control.c
src/playlist/engine.c
src/playlist/playlist_internal.h
src/playlist/thread.c

index d11f65d..95b90cd 100644 (file)
@@ -153,8 +153,6 @@ struct playlist_item_t
 typedef enum
 { PLAYLIST_STOPPED,PLAYLIST_RUNNING,PLAYLIST_PAUSED } playlist_status_t;
 
-typedef struct playlist_private_t playlist_private_t;
-
 /** Structure containing information about the playlist */
 struct playlist_t
 {
@@ -224,10 +222,6 @@ struct playlist_t
                                            when processing the request */
         vlc_mutex_t         lock;     /**< Lock to protect request */
     } request;
-
-    /* All other data is PRIVATE. You can't access it
-     * outside of src/input */
-    playlist_private_t *p;
 };
 
 /** Helper to add an item */
index d2fd27e..3420e7c 100644 (file)
@@ -99,7 +99,7 @@ int input_ArtFind( playlist_t *p_playlist, input_item_t *p_item )
     /* If we already checked this album in this session, skip */
     if( psz_artist && psz_album )
     {
-        FOREACH_ARRAY( playlist_album_t album, p_playlist->p->p_fetcher->albums )
+        FOREACH_ARRAY( playlist_album_t album, pl_priv(p_playlist)->p_fetcher->albums )
             if( !strcmp( album.psz_artist, psz_artist ) &&
                 !strcmp( album.psz_album, psz_album ) )
             {
@@ -179,7 +179,7 @@ int input_ArtFind( playlist_t *p_playlist, input_item_t *p_item )
         a.psz_album = psz_album;
         a.psz_arturl = input_item_GetArtURL( p_item );
         a.b_found = (i_ret == VLC_EGENERIC ? false : true );
-        ARRAY_APPEND( p_playlist->p->p_fetcher->albums, a );
+        ARRAY_APPEND( pl_priv(p_playlist)->p_fetcher->albums, a );
     }
     else
     {
index c8a9dd2..3eb2d29 100644 (file)
@@ -189,7 +189,7 @@ static int PlaylistVAControl( playlist_t * p_playlist, int i_query, va_list args
 int playlist_PreparseEnqueue( playlist_t *p_playlist,
                               input_item_t *p_item )
 {
-    playlist_preparse_t *p_preparse = &p_playlist->p->preparse;
+    playlist_preparse_t *p_preparse = &pl_priv(p_playlist)->preparse;
 
     vlc_gc_incref( p_item );
 
@@ -206,7 +206,7 @@ int playlist_PreparseEnqueue( playlist_t *p_playlist,
 int playlist_PreparseEnqueueItem( playlist_t *p_playlist,
                                   playlist_item_t *p_item )
 {
-    playlist_preparse_t *p_preparse = &p_playlist->p->preparse;
+    playlist_preparse_t *p_preparse = &pl_priv(p_playlist)->preparse;
 
     vlc_object_lock( p_playlist );
     vlc_mutex_lock( &p_preparse->lock );
@@ -219,26 +219,26 @@ int playlist_PreparseEnqueueItem( playlist_t *p_playlist,
 int playlist_AskForArtEnqueue( playlist_t *p_playlist,
                                input_item_t *p_item )
 {
-    vlc_object_lock( p_playlist->p->p_fetcher );
-    if( !vlc_object_alive( p_playlist->p->p_fetcher ) )
+    playlist_fetcher_t *p_fetcher = pl_priv(p_playlist)->p_fetcher;
+    vlc_object_lock( p_fetcher );
+    if( !vlc_object_alive( p_fetcher ) )
     {
-        vlc_object_unlock( p_playlist->p->p_fetcher );
+        vlc_object_unlock( p_fetcher );
         return VLC_EGENERIC;
     }
 
     vlc_gc_incref( p_item );
-    INSERT_ELEM( p_playlist->p->p_fetcher->pp_waiting,
-                 p_playlist->p->p_fetcher->i_waiting,
-                 p_playlist->p->p_fetcher->i_waiting, p_item );
-    vlc_object_signal_unlocked( p_playlist->p->p_fetcher );
-    vlc_object_unlock( p_playlist->p->p_fetcher );
+    INSERT_ELEM( p_fetcher->pp_waiting, p_fetcher->i_waiting,
+                 p_fetcher->i_waiting, p_item );
+    vlc_object_signal_unlocked( p_fetcher );
+    vlc_object_unlock( p_fetcher );
     return VLC_SUCCESS;
 }
 
 static void PreparseEnqueueItemSub( playlist_t *p_playlist,
                                     playlist_item_t *p_item )
 {
-    playlist_preparse_t *p_preparse = &p_playlist->p->preparse;
+    playlist_preparse_t *p_preparse = &pl_priv(p_playlist)->preparse;
 
     if( p_item->i_children == -1 )
     {
@@ -505,7 +505,7 @@ playlist_item_t * playlist_NextItem( playlist_t *p_playlist )
 int playlist_PlayItem( playlist_t *p_playlist, playlist_item_t *p_item )
 {
     input_item_t *p_input = p_item->p_input;
-    sout_instance_t **pp_sout = &p_playlist->p->p_sout;
+    sout_instance_t **pp_sout = &pl_priv(p_playlist)->p_sout;
     int i_activity = var_GetInteger( p_playlist, "activity" ) ;
 
     msg_Dbg( p_playlist, "creating new input thread" );
@@ -534,8 +534,8 @@ int playlist_PlayItem( playlist_t *p_playlist, playlist_item_t *p_item )
     }
     free( psz_uri );
 
-    if( p_playlist->p->p_fetcher &&
-            p_playlist->p->p_fetcher->i_art_policy == ALBUM_ART_WHEN_PLAYED )
+    if( pl_priv(p_playlist)->p_fetcher &&
+        pl_priv(p_playlist)->p_fetcher->i_art_policy == ALBUM_ART_WHEN_PLAYED )
     {
         bool b_has_art;
 
index b26d567..7e04935 100644 (file)
@@ -61,24 +61,24 @@ playlist_t * playlist_Create( vlc_object_t *p_parent )
 {
     static const char playlist_name[] = "playlist";
     playlist_t *p_playlist;
+    playlist_private_t *p;
     bool b_save;
 
     /* Allocate structure */
-    p_playlist = vlc_custom_create( p_parent, sizeof( *p_playlist ),
-                                    VLC_OBJECT_GENERIC, playlist_name );
-    if( !p_playlist )
+    p = vlc_custom_create( p_parent, sizeof( *p ),
+                           VLC_OBJECT_GENERIC, playlist_name );
+    if( !p )
         return NULL;
 
+    assert( offsetof( playlist_private_t, public_data ) == 0 );
+    p_playlist = &p->public_data;
     TAB_INIT( p_playlist->i_sds, p_playlist->pp_sds );
-    MALLOC_NULL( p_playlist->p, playlist_private_t );
-    memset( p_playlist->p, 0, sizeof( playlist_private_t ) );
 
     libvlc_priv(p_parent->p_libvlc)->p_playlist = p_playlist;
 
     VariablesInit( p_playlist );
 
     /* Initialise data structures */
-    p_playlist->p->p_playlist = p_playlist;
     p_playlist->i_last_playlist_id = 0;
     p_playlist->p_input = NULL;
 
@@ -176,7 +176,7 @@ playlist_t * playlist_Create( vlc_object_t *p_parent )
 static void playlist_Destructor( vlc_object_t * p_this )
 {
     playlist_t * p_playlist = (playlist_t *)p_this;
-    playlist_preparse_t *p_preparse = &p_playlist->p->preparse;
+    playlist_preparse_t *p_preparse = &pl_priv(p_playlist)->preparse;
 
     /* Destroy the item preparser */
     if (p_preparse->up)
@@ -193,9 +193,9 @@ static void playlist_Destructor( vlc_object_t * p_this )
     vlc_mutex_destroy (&p_preparse->lock);
 
     /* Destroy the item meta-infos fetcher */
-    if( p_playlist->p->p_fetcher )
+    if( pl_priv(p_playlist)->p_fetcher )
     {
-        vlc_object_release( p_playlist->p->p_fetcher );
+        vlc_object_release( pl_priv(p_playlist)->p_fetcher );
     }
     msg_Dbg( p_this, "Destroyed" );
 }
@@ -379,7 +379,7 @@ check_input:
         {
             int i_activity;
             input_thread_t *p_input;
-            sout_instance_t **pp_sout = &p_playlist->p->p_sout;
+            sout_instance_t **pp_sout = &pl_priv(p_playlist)->p_sout;
 
             PL_DEBUG( "dead input" );
 
@@ -520,7 +520,7 @@ void playlist_LastLoop( playlist_t *p_playlist )
 
 #ifdef ENABLE_SOUT
     /* close the remaining sout-keep (if there was no input atm) */
-    sout_instance_t *p_sout = p_playlist->p->p_sout;
+    sout_instance_t *p_sout = pl_priv(p_playlist)->p_sout;
     if (p_sout)
         sout_DeleteInstance( p_sout );
 #endif
@@ -530,8 +530,8 @@ void playlist_LastLoop( playlist_t *p_playlist )
     playlist_ServicesDiscoveryKillAll( p_playlist );
     playlist_MLDump( p_playlist );
 
-    vlc_object_kill( p_playlist->p->p_fetcher );
-    vlc_thread_join( p_playlist->p->p_fetcher );
+    vlc_object_kill( pl_priv(p_playlist)->p_fetcher );
+    vlc_thread_join( pl_priv(p_playlist)->p_fetcher );
 
     PL_LOCK;
 
@@ -569,8 +569,8 @@ void playlist_LastLoop( playlist_t *p_playlist )
 void *playlist_PreparseLoop( void *data )
 {
     playlist_preparse_t *p_preparse = data;
-    playlist_t *p_playlist =  ((playlist_private_t *)(((char *)p_preparse)
-             - offsetof(playlist_private_t, preparse)))->p_playlist;
+    playlist_t *p_playlist = &((playlist_private_t *)(((char *)p_preparse)
+             - offsetof(playlist_private_t, preparse)))->public_data;
     int i_activity;
 
     for( ;; )
@@ -615,21 +615,21 @@ void *playlist_PreparseLoop( void *data )
              */
             char *psz_arturl = input_item_GetArtURL( p_current );
             char *psz_name = input_item_GetName( p_current );
-            if( p_playlist->p->p_fetcher->i_art_policy == ALBUM_ART_ALL &&
-                        ( !psz_arturl || strncmp( psz_arturl, "file://", 7 ) ) )
+            playlist_fetcher_t *p_fetcher = pl_priv(p_playlist)->p_fetcher;
+            if( p_fetcher->i_art_policy == ALBUM_ART_ALL &&
+                ( !psz_arturl || strncmp( psz_arturl, "file://", 7 ) ) )
             {
                 PL_DEBUG("meta ok for %s, need to fetch art", psz_name );
-                vlc_object_lock( p_playlist->p->p_fetcher );
-                if( vlc_object_alive( p_playlist->p->p_fetcher ) )
+                vlc_object_lock( p_fetcher );
+                if( vlc_object_alive( p_fetcher ) )
                 {
-                    INSERT_ELEM( p_playlist->p->p_fetcher->pp_waiting,
-                        p_playlist->p->p_fetcher->i_waiting,
-                        p_playlist->p->p_fetcher->i_waiting, p_current);
-                    vlc_object_signal_unlocked( p_playlist->p->p_fetcher );
+                    INSERT_ELEM( p_fetcher->pp_waiting, p_fetcher->i_waiting,
+                                 p_fetcher->i_waiting, p_current);
+                    vlc_object_signal_unlocked( p_fetcher );
                 }
                 else
                     vlc_gc_decref( p_current );
-                vlc_object_unlock( p_playlist->p->p_fetcher );
+                vlc_object_unlock( p_fetcher );
             }
             else
             {
index 6bcc6ba..1d0d2ee 100644 (file)
@@ -58,13 +58,15 @@ typedef struct playlist_fetcher_t
     DECL_ARRAY(playlist_album_t) albums;
 } playlist_fetcher_t;
 
-struct playlist_private_t
+typedef struct playlist_private_t
 {
-    playlist_t           *p_playlist; /**< Public data */
+    playlist_t           public_data;
     playlist_preparse_t  preparse; /**< Preparser data */
     playlist_fetcher_t   *p_fetcher; /**< Meta and art fetcher object */
     sout_instance_t      *p_sout; /**< Kept sout instance */
-};
+} playlist_private_t;
+
+#define pl_priv( pl ) ((playlist_private_t *)(pl))
 
 /*****************************************************************************
  * Prototypes
index b6be2b9..3701d48 100644 (file)
@@ -57,7 +57,7 @@ void __playlist_ThreadCreate( vlc_object_t *p_parent )
     if( !p_playlist ) return;
 
     // Preparse
-    playlist_preparse_t *p_preparse = &p_playlist->p->preparse;
+    playlist_preparse_t *p_preparse = &pl_priv(p_playlist)->preparse;
     vlc_mutex_init (&p_preparse->lock);
     vlc_cond_init (&p_preparse->wait);
     p_preparse->i_waiting = 0;
@@ -74,30 +74,27 @@ void __playlist_ThreadCreate( vlc_object_t *p_parent )
 
     // Secondary Preparse
     static const char fname[] = "fetcher";
-    p_playlist->p->p_fetcher =
+    playlist_fetcher_t *p_fetcher =
+    pl_priv(p_playlist)->p_fetcher =
         vlc_custom_create( p_playlist, sizeof( playlist_fetcher_t ),
                            VLC_OBJECT_GENERIC, fname );
-    if( !p_playlist->p->p_fetcher )
+    if( !p_fetcher )
     {
         msg_Err( p_playlist, "unable to create secondary preparser" );
         vlc_object_release( p_playlist );
         return;
     }
-    p_playlist->p->p_fetcher->i_waiting = 0;
-    p_playlist->p->p_fetcher->pp_waiting = NULL;
-    p_playlist->p->p_fetcher->i_art_policy = var_CreateGetInteger( p_playlist,
-                                                                "album-art" );
+    p_fetcher->i_waiting = 0;
+    p_fetcher->pp_waiting = NULL;
+    p_fetcher->i_art_policy = var_CreateGetInteger( p_playlist, "album-art" );
 
-    vlc_object_set_destructor( p_playlist->p->p_fetcher, FetcherDestructor );
-
-    vlc_object_attach( p_playlist->p->p_fetcher, p_playlist );
-    if( vlc_thread_create( p_playlist->p->p_fetcher,
-                           "fetcher",
-                           RunFetcher,
+    vlc_object_set_destructor( p_fetcher, FetcherDestructor );
+    vlc_object_attach( p_fetcher, p_playlist );
+    if( vlc_thread_create( p_fetcher, "fetcher", RunFetcher,
                            VLC_THREAD_PRIORITY_LOW, false ) )
     {
         msg_Err( p_playlist, "cannot spawn secondary preparse thread" );
-        vlc_object_release( p_playlist->p->p_fetcher );
+        vlc_object_release( p_fetcher );
         return;
     }