It avoid locking the whole playlist_t when fetching art, which can take a lot
of time...
*****************************************************************************/
static int FindMeta( vlc_object_t *p_this )
{
*****************************************************************************/
static int FindMeta( vlc_object_t *p_this )
{
- playlist_t *p_playlist = (playlist_t *)p_this;
- input_item_t *p_item = (input_item_t *)(p_playlist->p_private);
+ input_item_t *p_item = (input_item_t *)p_this->p_private;
bool b_have_art = false;
int i = 0;
bool b_have_art = false;
int i = 0;
*****************************************************************************/
int FindArt( vlc_object_t *p_this )
{
*****************************************************************************/
int FindArt( vlc_object_t *p_this )
{
- playlist_t *p_playlist = (playlist_t *)p_this;
- input_item_t *p_item = (input_item_t *)(p_playlist->p_private);
- lua_State *L = vlclua_meta_init( p_this, p_item );
+ playlist_t *p_playlist = pl_Hold( p_this );
+ if( !p_playlist )
+ return VLC_EGENERIC;
+ input_item_t *p_item = (input_item_t *)p_this->p_private;
+ lua_State *L = vlclua_meta_init( p_this, p_item );
int i_ret = vlclua_scripts_batch_execute( p_this, "meta", &fetch_art, L, p_item );
lua_close( L );
int i_ret = vlclua_scripts_batch_execute( p_this, "meta", &fetch_art, L, p_item );
lua_close( L );
+
+ pl_Release( p_this );
*****************************************************************************/
struct playlist_fetcher_t
{
*****************************************************************************/
struct playlist_fetcher_t
{
playlist_t *p_playlist;
vlc_thread_t thread;
playlist_t *p_playlist;
vlc_thread_t thread;
*****************************************************************************/
playlist_fetcher_t *playlist_fetcher_New( playlist_t *p_playlist )
{
*****************************************************************************/
playlist_fetcher_t *playlist_fetcher_New( playlist_t *p_playlist )
{
- playlist_fetcher_t *p_fetcher = malloc( sizeof(*p_fetcher) );
+ playlist_fetcher_t *p_fetcher =
+ vlc_custom_create( p_playlist, sizeof(*p_fetcher),
+ VLC_OBJECT_GENERIC, "playlist fetcher" );
+
if( !p_fetcher )
return NULL;
if( !p_fetcher )
return NULL;
if( vlc_clone( &p_fetcher->thread, Thread, p_fetcher,
VLC_THREAD_PRIORITY_LOW ) )
{
if( vlc_clone( &p_fetcher->thread, Thread, p_fetcher,
VLC_THREAD_PRIORITY_LOW ) )
{
- msg_Err( p_playlist, "cannot spawn secondary preparse thread" );
+ msg_Err( p_fetcher, "cannot spawn secondary preparse thread" );
free( p_fetcher );
return NULL;
}
free( p_fetcher );
return NULL;
}
}
vlc_cond_destroy( &p_fetcher->wait );
vlc_mutex_destroy( &p_fetcher->lock );
}
vlc_cond_destroy( &p_fetcher->wait );
vlc_mutex_destroy( &p_fetcher->lock );
+ vlc_object_release( p_fetcher );
*/
static int FindArt( playlist_fetcher_t *p_fetcher, input_item_t *p_item )
{
*/
static int FindArt( playlist_fetcher_t *p_fetcher, input_item_t *p_item )
{
- playlist_t *p_playlist = p_fetcher->p_playlist;
- int i_ret = VLC_EGENERIC;
module_t *p_module;
char *psz_title, *psz_artist, *psz_album;
module_t *p_module;
char *psz_title, *psz_artist, *psz_album;
if( !strcmp( album.psz_artist, psz_artist ) &&
!strcmp( album.psz_album, psz_album ) )
{
if( !strcmp( album.psz_artist, psz_artist ) &&
!strcmp( album.psz_album, psz_album ) )
{
- msg_Dbg( p_playlist, " %s - %s has already been searched",
+ msg_Dbg( p_fetcher, " %s - %s has already been searched",
psz_artist, psz_album );
/* TODO-fenrir if we cache art filename too, we can go faster */
free( psz_artist );
psz_artist, psz_album );
/* TODO-fenrir if we cache art filename too, we can go faster */
free( psz_artist );
- PL_LOCK;
- p_playlist->p_private = p_item;
psz_album = input_item_GetAlbum( p_item );
psz_artist = input_item_GetArtist( p_item );
psz_title = input_item_GetTitle( p_item );
psz_album = input_item_GetAlbum( p_item );
psz_artist = input_item_GetArtist( p_item );
psz_title = input_item_GetTitle( p_item );
if( psz_album && psz_artist )
{
if( psz_album && psz_artist )
{
- msg_Dbg( p_playlist, "searching art for %s - %s",
+ msg_Dbg( p_fetcher, "searching art for %s - %s",
psz_artist, psz_album );
}
else
{
psz_artist, psz_album );
}
else
{
- msg_Dbg( p_playlist, "searching art for %s",
+ msg_Dbg( p_fetcher, "searching art for %s",
psz_title );
}
free( psz_title );
psz_title );
}
free( psz_title );
- p_module = module_need( p_playlist, "art finder", NULL, false );
+ /* Fetch the art url */
+ p_fetcher->p_private = p_item;
+
+ p_module = module_need( p_fetcher, "art finder", NULL, false );
+ {
+ module_unneed( p_fetcher, p_module );
- msg_Dbg( p_playlist, "unable to find art" );
+ {
+ msg_Dbg( p_fetcher, "unable to find art" );
+ i_ret = VLC_EGENERIC;
+ }
/* Record this album */
if( psz_artist && psz_album )
/* Record this album */
if( psz_artist && psz_album )
- if( p_module )
- module_unneed( p_playlist, p_module );
- p_playlist->p_private = NULL;
- PL_UNLOCK;
-
* Download the art using the URL or an art downloaded
* This function should be called only if data is not already in cache
*/
* Download the art using the URL or an art downloaded
* This function should be called only if data is not already in cache
*/
-static int DownloadArt( playlist_t *p_playlist, input_item_t *p_item )
+static int DownloadArt( playlist_fetcher_t *p_fetcher, input_item_t *p_item )
{
char *psz_arturl = input_item_GetArtURL( p_item );
assert( *psz_arturl );
if( !strncmp( psz_arturl , "file://", 7 ) )
{
{
char *psz_arturl = input_item_GetArtURL( p_item );
assert( *psz_arturl );
if( !strncmp( psz_arturl , "file://", 7 ) )
{
- msg_Dbg( p_playlist, "Album art is local file, no need to cache" );
+ msg_Dbg( p_fetcher, "Album art is local file, no need to cache" );
free( psz_arturl );
return VLC_SUCCESS;
}
if( !strncmp( psz_arturl , "APIC", 4 ) )
{
free( psz_arturl );
return VLC_SUCCESS;
}
if( !strncmp( psz_arturl , "APIC", 4 ) )
{
- msg_Warn( p_playlist, "APIC fetch not supported yet" );
+ msg_Warn( p_fetcher, "APIC fetch not supported yet" );
- stream_t *p_stream = stream_UrlNew( p_playlist, psz_arturl );
+ stream_t *p_stream = stream_UrlNew( p_fetcher, psz_arturl );
if( !p_stream )
goto error;
if( !p_stream )
goto error;
if( psz_type && strlen( psz_type ) > 5 )
psz_type = NULL; /* remove extension if it's > to 4 characters */
if( psz_type && strlen( psz_type ) > 5 )
psz_type = NULL; /* remove extension if it's > to 4 characters */
- playlist_SaveArt( p_playlist, p_item, p_data, i_data, psz_type );
+ playlist_SaveArt( p_fetcher->p_playlist, p_item, p_data, i_data, psz_type );
*/
static void WaitPreparsed( playlist_fetcher_t *p_fetcher, input_item_t *p_item )
{
*/
static void WaitPreparsed( playlist_fetcher_t *p_fetcher, input_item_t *p_item )
{
- playlist_t *p_playlist = p_fetcher->p_playlist;
-
if( input_item_IsPreparsed( p_item ) )
return;
if( input_item_IsPreparsed( p_item ) )
return;
- input_thread_t *p_input = playlist_CurrentInput( p_playlist );
+ input_thread_t *p_input = playlist_CurrentInput( p_fetcher->p_playlist );
/* Find art, and download it if needed */
int i_ret = FindArt( p_fetcher, p_item );
if( i_ret == 1 )
/* Find art, and download it if needed */
int i_ret = FindArt( p_fetcher, p_item );
if( i_ret == 1 )
- i_ret = DownloadArt( p_playlist, p_item );
+ i_ret = DownloadArt( p_fetcher, p_item );
/* */
char *psz_name = input_item_GetName( p_item );
/* */
char *psz_name = input_item_GetName( p_item );