Commit e3f0531d authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Playlist: put private data after public data

parent 8df80e5e
...@@ -153,8 +153,6 @@ struct playlist_item_t ...@@ -153,8 +153,6 @@ struct playlist_item_t
typedef enum typedef enum
{ PLAYLIST_STOPPED,PLAYLIST_RUNNING,PLAYLIST_PAUSED } playlist_status_t; { PLAYLIST_STOPPED,PLAYLIST_RUNNING,PLAYLIST_PAUSED } playlist_status_t;
typedef struct playlist_private_t playlist_private_t;
/** Structure containing information about the playlist */ /** Structure containing information about the playlist */
struct playlist_t struct playlist_t
{ {
...@@ -224,10 +222,6 @@ struct playlist_t ...@@ -224,10 +222,6 @@ struct playlist_t
when processing the request */ when processing the request */
vlc_mutex_t lock; /**< Lock to protect request */ vlc_mutex_t lock; /**< Lock to protect request */
} 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 */ /** Helper to add an item */
......
...@@ -99,7 +99,7 @@ int input_ArtFind( playlist_t *p_playlist, input_item_t *p_item ) ...@@ -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 we already checked this album in this session, skip */
if( psz_artist && psz_album ) 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 ) && if( !strcmp( album.psz_artist, psz_artist ) &&
!strcmp( album.psz_album, psz_album ) ) !strcmp( album.psz_album, psz_album ) )
{ {
...@@ -179,7 +179,7 @@ int input_ArtFind( playlist_t *p_playlist, input_item_t *p_item ) ...@@ -179,7 +179,7 @@ int input_ArtFind( playlist_t *p_playlist, input_item_t *p_item )
a.psz_album = psz_album; a.psz_album = psz_album;
a.psz_arturl = input_item_GetArtURL( p_item ); a.psz_arturl = input_item_GetArtURL( p_item );
a.b_found = (i_ret == VLC_EGENERIC ? false : true ); 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 else
{ {
......
...@@ -189,7 +189,7 @@ static int PlaylistVAControl( playlist_t * p_playlist, int i_query, va_list args ...@@ -189,7 +189,7 @@ static int PlaylistVAControl( playlist_t * p_playlist, int i_query, va_list args
int playlist_PreparseEnqueue( playlist_t *p_playlist, int playlist_PreparseEnqueue( playlist_t *p_playlist,
input_item_t *p_item ) 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 ); vlc_gc_incref( p_item );
...@@ -206,7 +206,7 @@ int playlist_PreparseEnqueue( playlist_t *p_playlist, ...@@ -206,7 +206,7 @@ int playlist_PreparseEnqueue( playlist_t *p_playlist,
int playlist_PreparseEnqueueItem( playlist_t *p_playlist, int playlist_PreparseEnqueueItem( playlist_t *p_playlist,
playlist_item_t *p_item ) 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_object_lock( p_playlist );
vlc_mutex_lock( &p_preparse->lock ); vlc_mutex_lock( &p_preparse->lock );
...@@ -219,26 +219,26 @@ int playlist_PreparseEnqueueItem( playlist_t *p_playlist, ...@@ -219,26 +219,26 @@ int playlist_PreparseEnqueueItem( playlist_t *p_playlist,
int playlist_AskForArtEnqueue( playlist_t *p_playlist, int playlist_AskForArtEnqueue( playlist_t *p_playlist,
input_item_t *p_item ) input_item_t *p_item )
{ {
vlc_object_lock( p_playlist->p->p_fetcher ); playlist_fetcher_t *p_fetcher = pl_priv(p_playlist)->p_fetcher;
if( !vlc_object_alive( p_playlist->p->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; return VLC_EGENERIC;
} }
vlc_gc_incref( p_item ); vlc_gc_incref( p_item );
INSERT_ELEM( p_playlist->p->p_fetcher->pp_waiting, INSERT_ELEM( p_fetcher->pp_waiting, p_fetcher->i_waiting,
p_playlist->p->p_fetcher->i_waiting, p_fetcher->i_waiting, p_item );
p_playlist->p->p_fetcher->i_waiting, p_item ); vlc_object_signal_unlocked( p_fetcher );
vlc_object_signal_unlocked( p_playlist->p->p_fetcher ); vlc_object_unlock( p_fetcher );
vlc_object_unlock( p_playlist->p->p_fetcher );
return VLC_SUCCESS; return VLC_SUCCESS;
} }
static void PreparseEnqueueItemSub( playlist_t *p_playlist, static void PreparseEnqueueItemSub( playlist_t *p_playlist,
playlist_item_t *p_item ) 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 ) if( p_item->i_children == -1 )
{ {
...@@ -505,7 +505,7 @@ playlist_item_t * playlist_NextItem( playlist_t *p_playlist ) ...@@ -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 ) int playlist_PlayItem( playlist_t *p_playlist, playlist_item_t *p_item )
{ {
input_item_t *p_input = p_item->p_input; 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" ) ; int i_activity = var_GetInteger( p_playlist, "activity" ) ;
msg_Dbg( p_playlist, "creating new input thread" ); msg_Dbg( p_playlist, "creating new input thread" );
...@@ -534,8 +534,8 @@ int playlist_PlayItem( playlist_t *p_playlist, playlist_item_t *p_item ) ...@@ -534,8 +534,8 @@ int playlist_PlayItem( playlist_t *p_playlist, playlist_item_t *p_item )
} }
free( psz_uri ); free( psz_uri );
if( p_playlist->p->p_fetcher && if( pl_priv(p_playlist)->p_fetcher &&
p_playlist->p->p_fetcher->i_art_policy == ALBUM_ART_WHEN_PLAYED ) pl_priv(p_playlist)->p_fetcher->i_art_policy == ALBUM_ART_WHEN_PLAYED )
{ {
bool b_has_art; bool b_has_art;
......
...@@ -61,24 +61,24 @@ playlist_t * playlist_Create( vlc_object_t *p_parent ) ...@@ -61,24 +61,24 @@ playlist_t * playlist_Create( vlc_object_t *p_parent )
{ {
static const char playlist_name[] = "playlist"; static const char playlist_name[] = "playlist";
playlist_t *p_playlist; playlist_t *p_playlist;
playlist_private_t *p;
bool b_save; bool b_save;
/* Allocate structure */ /* Allocate structure */
p_playlist = vlc_custom_create( p_parent, sizeof( *p_playlist ), p = vlc_custom_create( p_parent, sizeof( *p ),
VLC_OBJECT_GENERIC, playlist_name ); VLC_OBJECT_GENERIC, playlist_name );
if( !p_playlist ) if( !p )
return NULL; 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 ); 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; libvlc_priv(p_parent->p_libvlc)->p_playlist = p_playlist;
VariablesInit( p_playlist ); VariablesInit( p_playlist );
/* Initialise data structures */ /* Initialise data structures */
p_playlist->p->p_playlist = p_playlist;
p_playlist->i_last_playlist_id = 0; p_playlist->i_last_playlist_id = 0;
p_playlist->p_input = NULL; p_playlist->p_input = NULL;
...@@ -176,7 +176,7 @@ playlist_t * playlist_Create( vlc_object_t *p_parent ) ...@@ -176,7 +176,7 @@ playlist_t * playlist_Create( vlc_object_t *p_parent )
static void playlist_Destructor( vlc_object_t * p_this ) static void playlist_Destructor( vlc_object_t * p_this )
{ {
playlist_t * p_playlist = (playlist_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 */ /* Destroy the item preparser */
if (p_preparse->up) if (p_preparse->up)
...@@ -193,9 +193,9 @@ static void playlist_Destructor( vlc_object_t * p_this ) ...@@ -193,9 +193,9 @@ static void playlist_Destructor( vlc_object_t * p_this )
vlc_mutex_destroy (&p_preparse->lock); vlc_mutex_destroy (&p_preparse->lock);
/* Destroy the item meta-infos fetcher */ /* 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" ); msg_Dbg( p_this, "Destroyed" );
} }
...@@ -379,7 +379,7 @@ check_input: ...@@ -379,7 +379,7 @@ check_input:
{ {
int i_activity; int i_activity;
input_thread_t *p_input; 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" ); PL_DEBUG( "dead input" );
...@@ -520,7 +520,7 @@ void playlist_LastLoop( playlist_t *p_playlist ) ...@@ -520,7 +520,7 @@ void playlist_LastLoop( playlist_t *p_playlist )
#ifdef ENABLE_SOUT #ifdef ENABLE_SOUT
/* close the remaining sout-keep (if there was no input atm) */ /* 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) if (p_sout)
sout_DeleteInstance( p_sout ); sout_DeleteInstance( p_sout );
#endif #endif
...@@ -530,8 +530,8 @@ void playlist_LastLoop( playlist_t *p_playlist ) ...@@ -530,8 +530,8 @@ void playlist_LastLoop( playlist_t *p_playlist )
playlist_ServicesDiscoveryKillAll( p_playlist ); playlist_ServicesDiscoveryKillAll( p_playlist );
playlist_MLDump( p_playlist ); playlist_MLDump( p_playlist );
vlc_object_kill( p_playlist->p->p_fetcher ); vlc_object_kill( pl_priv(p_playlist)->p_fetcher );
vlc_thread_join( p_playlist->p->p_fetcher ); vlc_thread_join( pl_priv(p_playlist)->p_fetcher );
PL_LOCK; PL_LOCK;
...@@ -569,8 +569,8 @@ void playlist_LastLoop( playlist_t *p_playlist ) ...@@ -569,8 +569,8 @@ void playlist_LastLoop( playlist_t *p_playlist )
void *playlist_PreparseLoop( void *data ) void *playlist_PreparseLoop( void *data )
{ {
playlist_preparse_t *p_preparse = data; playlist_preparse_t *p_preparse = data;
playlist_t *p_playlist = ((playlist_private_t *)(((char *)p_preparse) playlist_t *p_playlist = &((playlist_private_t *)(((char *)p_preparse)
- offsetof(playlist_private_t, preparse)))->p_playlist; - offsetof(playlist_private_t, preparse)))->public_data;
int i_activity; int i_activity;
for( ;; ) for( ;; )
...@@ -615,21 +615,21 @@ void *playlist_PreparseLoop( void *data ) ...@@ -615,21 +615,21 @@ void *playlist_PreparseLoop( void *data )
*/ */
char *psz_arturl = input_item_GetArtURL( p_current ); char *psz_arturl = input_item_GetArtURL( p_current );
char *psz_name = input_item_GetName( p_current ); char *psz_name = input_item_GetName( p_current );
if( p_playlist->p->p_fetcher->i_art_policy == ALBUM_ART_ALL && playlist_fetcher_t *p_fetcher = pl_priv(p_playlist)->p_fetcher;
( !psz_arturl || strncmp( psz_arturl, "file://", 7 ) ) ) 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 ); PL_DEBUG("meta ok for %s, need to fetch art", psz_name );
vlc_object_lock( p_playlist->p->p_fetcher ); vlc_object_lock( p_fetcher );
if( vlc_object_alive( p_playlist->p->p_fetcher ) ) if( vlc_object_alive( p_fetcher ) )
{ {
INSERT_ELEM( p_playlist->p->p_fetcher->pp_waiting, INSERT_ELEM( p_fetcher->pp_waiting, p_fetcher->i_waiting,
p_playlist->p->p_fetcher->i_waiting, p_fetcher->i_waiting, p_current);
p_playlist->p->p_fetcher->i_waiting, p_current); vlc_object_signal_unlocked( p_fetcher );
vlc_object_signal_unlocked( p_playlist->p->p_fetcher );
} }
else else
vlc_gc_decref( p_current ); vlc_gc_decref( p_current );
vlc_object_unlock( p_playlist->p->p_fetcher ); vlc_object_unlock( p_fetcher );
} }
else else
{ {
......
...@@ -58,13 +58,15 @@ typedef struct playlist_fetcher_t ...@@ -58,13 +58,15 @@ typedef struct playlist_fetcher_t
DECL_ARRAY(playlist_album_t) albums; DECL_ARRAY(playlist_album_t) albums;
} playlist_fetcher_t; } 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_preparse_t preparse; /**< Preparser data */
playlist_fetcher_t *p_fetcher; /**< Meta and art fetcher object */ playlist_fetcher_t *p_fetcher; /**< Meta and art fetcher object */
sout_instance_t *p_sout; /**< Kept sout instance */ sout_instance_t *p_sout; /**< Kept sout instance */
}; } playlist_private_t;
#define pl_priv( pl ) ((playlist_private_t *)(pl))
/***************************************************************************** /*****************************************************************************
* Prototypes * Prototypes
......
...@@ -57,7 +57,7 @@ void __playlist_ThreadCreate( vlc_object_t *p_parent ) ...@@ -57,7 +57,7 @@ void __playlist_ThreadCreate( vlc_object_t *p_parent )
if( !p_playlist ) return; if( !p_playlist ) return;
// Preparse // 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_mutex_init (&p_preparse->lock);
vlc_cond_init (&p_preparse->wait); vlc_cond_init (&p_preparse->wait);
p_preparse->i_waiting = 0; p_preparse->i_waiting = 0;
...@@ -74,30 +74,27 @@ void __playlist_ThreadCreate( vlc_object_t *p_parent ) ...@@ -74,30 +74,27 @@ void __playlist_ThreadCreate( vlc_object_t *p_parent )
// Secondary Preparse // Secondary Preparse
static const char fname[] = "fetcher"; 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_custom_create( p_playlist, sizeof( playlist_fetcher_t ),
VLC_OBJECT_GENERIC, fname ); VLC_OBJECT_GENERIC, fname );
if( !p_playlist->p->p_fetcher ) if( !p_fetcher )
{ {
msg_Err( p_playlist, "unable to create secondary preparser" ); msg_Err( p_playlist, "unable to create secondary preparser" );
vlc_object_release( p_playlist ); vlc_object_release( p_playlist );
return; return;
} }
p_playlist->p->p_fetcher->i_waiting = 0; p_fetcher->i_waiting = 0;
p_playlist->p->p_fetcher->pp_waiting = NULL; p_fetcher->pp_waiting = NULL;
p_playlist->p->p_fetcher->i_art_policy = var_CreateGetInteger( p_playlist, p_fetcher->i_art_policy = var_CreateGetInteger( p_playlist, "album-art" );
"album-art" );
vlc_object_set_destructor( p_playlist->p->p_fetcher, FetcherDestructor ); vlc_object_set_destructor( p_fetcher, FetcherDestructor );
vlc_object_attach( p_fetcher, p_playlist );
vlc_object_attach( p_playlist->p->p_fetcher, p_playlist ); if( vlc_thread_create( p_fetcher, "fetcher", RunFetcher,
if( vlc_thread_create( p_playlist->p->p_fetcher,
"fetcher",
RunFetcher,
VLC_THREAD_PRIORITY_LOW, false ) ) VLC_THREAD_PRIORITY_LOW, false ) )
{ {
msg_Err( p_playlist, "cannot spawn secondary preparse thread" ); msg_Err( p_playlist, "cannot spawn secondary preparse thread" );
vlc_object_release( p_playlist->p->p_fetcher ); vlc_object_release( p_fetcher );
return; return;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment