From e3f0531d93abd49f902a324241e31200de05b45d Mon Sep 17 00:00:00 2001 From: =?utf8?q?R=C3=A9mi=20Denis-Courmont?= Date: Sun, 14 Sep 2008 12:35:42 +0300 Subject: [PATCH] Playlist: put private data after public data --- include/vlc_playlist.h | 6 ---- src/input/meta.c | 4 +-- src/playlist/control.c | 28 +++++++++---------- src/playlist/engine.c | 48 ++++++++++++++++---------------- src/playlist/playlist_internal.h | 8 ++++-- src/playlist/thread.c | 25 ++++++++--------- 6 files changed, 56 insertions(+), 63 deletions(-) diff --git a/include/vlc_playlist.h b/include/vlc_playlist.h index d11f65d021..95b90cd66e 100644 --- a/include/vlc_playlist.h +++ b/include/vlc_playlist.h @@ -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 */ diff --git a/src/input/meta.c b/src/input/meta.c index d2fd27e10a..3420e7cef8 100644 --- a/src/input/meta.c +++ b/src/input/meta.c @@ -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 { diff --git a/src/playlist/control.c b/src/playlist/control.c index c8a9dd2b84..3eb2d2953d 100644 --- a/src/playlist/control.c +++ b/src/playlist/control.c @@ -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; diff --git a/src/playlist/engine.c b/src/playlist/engine.c index b26d5678b2..7e04935284 100644 --- a/src/playlist/engine.c +++ b/src/playlist/engine.c @@ -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 { diff --git a/src/playlist/playlist_internal.h b/src/playlist/playlist_internal.h index 6bcc6ba6c1..1d0d2ee38a 100644 --- a/src/playlist/playlist_internal.h +++ b/src/playlist/playlist_internal.h @@ -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 diff --git a/src/playlist/thread.c b/src/playlist/thread.c index b6be2b96a4..3701d48895 100644 --- a/src/playlist/thread.c +++ b/src/playlist/thread.c @@ -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; } -- 2.39.2