From: Clément Stenac Date: Mon, 23 Oct 2006 21:02:45 +0000 (+0000) Subject: Clean up and improve core handling for album art. Still only "always fetch" implemented X-Git-Tag: 0.9.0-test0~9800 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=d3217fc729bc813a19e6743db7c5b18c7d66524c;p=vlc Clean up and improve core handling for album art. Still only "always fetch" implemented --- diff --git a/include/vlc_common.h b/include/vlc_common.h index 71162e40e2..23f4bc924e 100644 --- a/include/vlc_common.h +++ b/include/vlc_common.h @@ -236,7 +236,7 @@ typedef struct services_discovery_t services_discovery_t; typedef struct services_discovery_sys_t services_discovery_sys_t; typedef struct playlist_add_t playlist_add_t; typedef struct playlist_preparse_t playlist_preparse_t; -typedef struct playlist_secondary_preparse_t playlist_secondary_preparse_t; +typedef struct playlist_fetcher_t playlist_fetcher_t; /* Modules */ typedef struct module_bank_t module_bank_t; @@ -635,6 +635,8 @@ static int64_t GCD( int64_t a, int64_t b ) #define FREENULL(a) if( a ) { free( a ); a = NULL; } #define FREE(a) if( a ) { free( a ); } +#define EMPTY_STR(str) (!str || !*str) + #include /* MSB (big endian)/LSB (little endian) conversions - network order is always diff --git a/include/vlc_input.h b/include/vlc_input.h index fee622196a..d81452e08c 100644 --- a/include/vlc_input.h +++ b/include/vlc_input.h @@ -474,11 +474,17 @@ VLC_EXPORT( int, __input_Read, ( vlc_object_t *, input_item_t *, vlc_bool_t ) ); VLC_EXPORT( void, input_StopThread, ( input_thread_t * ) ); VLC_EXPORT( void, input_DestroyThread, ( input_thread_t * ) ); +typedef struct playlist_album_t +{ + char *psz_artist; + char *psz_album; + vlc_bool_t b_found; +} playlist_album_t; int input_MetaFetch ( playlist_t *, input_item_t * ); -int input_ArtFetch ( playlist_t *, input_item_t * ); +int input_ArtFind ( playlist_t *, input_item_t * ); vlc_bool_t input_MetaSatisfied ( playlist_t*, input_item_t*, - uint32_t*, uint32_t*, vlc_bool_t ); + uint32_t*, uint32_t* ); int input_DownloadAndCacheArt ( playlist_t *, input_item_t * ); enum input_query_e diff --git a/include/vlc_meta.h b/include/vlc_meta.h index d12b432227..ed5c8611d4 100644 --- a/include/vlc_meta.h +++ b/include/vlc_meta.h @@ -51,6 +51,7 @@ #define ITEM_META_FETCHED 0x02 #define ITEM_ARTURL_FETCHED 0x04 #define ITEM_ART_FETCHED 0x08 +#define ITEM_ART_NOTFOUND 0x10 struct vlc_meta_t { @@ -193,7 +194,8 @@ enum { ALBUM_ART_NEVER, ALBUM_ART_WHEN_ASKED, ALBUM_ART_WHEN_PLAYED, - ALBUM_ART_ALL }; + ALBUM_ART_ALL +}; struct meta_export_t { diff --git a/include/vlc_playlist.h b/include/vlc_playlist.h index a8a98aa7b2..5fea4f90cd 100644 --- a/include/vlc_playlist.h +++ b/include/vlc_playlist.h @@ -141,7 +141,7 @@ struct playlist_t mtime_t gc_date; vlc_bool_t b_cant_sleep; playlist_preparse_t *p_preparse; /**< Preparser object */ - playlist_secondary_preparse_t *p_secondary_preparse;/**< Preparser object */ + playlist_fetcher_t *p_fetcher;/**< Meta and art fetcher object */ vlc_mutex_t gc_lock; /**< Lock to protect the garbage collection */ diff --git a/modules/gui/qt4/main_interface.cpp b/modules/gui/qt4/main_interface.cpp index 31da1b2678..b9058efe8c 100644 --- a/modules/gui/qt4/main_interface.cpp +++ b/modules/gui/qt4/main_interface.cpp @@ -82,42 +82,37 @@ QSize savedVideoSize; MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf ) { + /* Configuration */ settings = new QSettings( "VideoLAN", "VLC" ); settings->beginGroup( "MainWindow" ); - setAcceptDrops(true); - need_components_update = false; bgWidget = NULL; videoWidget = NULL; playlistWidget = NULL; embeddedPlaylistWasActive = videoIsActive = false; - /* Fetch configuration from settings and vlc config */ videoEmbeddedFlag = false; - if( config_GetInt( p_intf, "embedded-video" ) ) - videoEmbeddedFlag = true; + if( config_GetInt( p_intf, "embedded-video" ) ) videoEmbeddedFlag = true; alwaysVideoFlag = false; if( videoEmbeddedFlag && config_GetInt( p_intf, "qt-always-video" )) alwaysVideoFlag = true; - playlistEmbeddedFlag = settings->value( "playlist-embedded", true ). - toBool(); + playlistEmbeddedFlag = settings->value("playlist-embedded", true).toBool(); advControlsEnabled= settings->value( "adv-controls", false ).toBool(); visualSelectorEnabled= settings->value( "visual-selector", false ).toBool(); + /* UI */ setWindowTitle( QString::fromUtf8( _("VLC media player") ) ); handleMainUi( settings ); - QVLCMenu::createMenuBar( this, p_intf, playlistEmbeddedFlag, advControlsEnabled, visualSelectorEnabled ); - - /* Status bar */ timeLabel = new QLabel( 0 ); nameLabel = new QLabel( 0 ); statusBar()->addWidget( nameLabel, 4 ); statusBar()->addPermanentWidget( timeLabel, 1 ); setFocusPolicy( Qt::StrongFocus ); + setAcceptDrops(true); /* Init input manager */ MainInputManager::getInstance( p_intf ); @@ -140,51 +135,6 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf ) p_intf->b_interaction = VLC_TRUE; } -void MainInterface::dropEvent(QDropEvent *event) -{ - const QMimeData *mimeData = event->mimeData(); - - /* D&D of a subtitles file, add it on the fly */ - if( mimeData->urls().size() == 1 ) - { - if( THEMIM->getIM()->hasInput() ) - { - if( input_AddSubtitles( THEMIM->getInput(), - qtu( mimeData->urls()[0].toString() ), - VLC_TRUE ) ) - { - event->acceptProposedAction(); - return; - } - } - } - bool first = true; - foreach( QUrl url, mimeData->urls() ) { - QString s = url.toString(); - if( s.length() > 0 ) { - playlist_PlaylistAdd( THEPL, qtu(s), NULL, - PLAYLIST_APPEND | (first ? PLAYLIST_GO:0), - PLAYLIST_END ); - first = false; - } - } - event->acceptProposedAction(); -} -void MainInterface::dragEnterEvent(QDragEnterEvent *event) -{ - event->acceptProposedAction(); -} -void MainInterface::dragMoveEvent(QDragMoveEvent *event) -{ - event->acceptProposedAction(); -} -void MainInterface::dragLeaveEvent(QDragLeaveEvent *event) -{ - event->accept(); -} - - - MainInterface::~MainInterface() { settings->setValue( "playlist-embedded", playlistEmbeddedFlag ); @@ -389,8 +339,6 @@ int MainInterface::controlVideo( void *p_window, int i_query, va_list args ) { unsigned int i_width = va_arg( args, unsigned int ); unsigned int i_height = va_arg( args, unsigned int ); -// if( !i_width && p_vout ) i_width = p_vout->i_window_width; -// if( !i_height && p_vout ) i_height = p_vout->i_window_height; videoWidget->widgetSize = QSize( i_width, i_height ); videoWidget->updateGeometry(); need_components_update = true; @@ -462,8 +410,7 @@ void MainInterface::playlist() QSize( 650, 310 ) ).toSize(); playlistWidget->hide(); } - /// Todo, reset its size ? - if( VISIBLE( playlistWidget) ) + if( VISIBLE( playlistWidget ) ) { playlistWidget->hide(); if( videoIsActive ) @@ -535,6 +482,53 @@ void MainInterface::customEvent( QEvent *event ) } } + +/************************************************************************ + * D&D + ************************************************************************/ +void MainInterface::dropEvent(QDropEvent *event) +{ + const QMimeData *mimeData = event->mimeData(); + + /* D&D of a subtitles file, add it on the fly */ + if( mimeData->urls().size() == 1 ) + { + if( THEMIM->getIM()->hasInput() ) + { + if( input_AddSubtitles( THEMIM->getInput(), + qtu( mimeData->urls()[0].toString() ), + VLC_TRUE ) ) + { + event->acceptProposedAction(); + return; + } + } + } + bool first = true; + foreach( QUrl url, mimeData->urls() ) { + QString s = url.toString(); + if( s.length() > 0 ) { + playlist_PlaylistAdd( THEPL, qtu(s), NULL, + PLAYLIST_APPEND | (first ? PLAYLIST_GO:0), + PLAYLIST_END ); + first = false; + } + } + event->acceptProposedAction(); +} +void MainInterface::dragEnterEvent(QDragEnterEvent *event) +{ + event->acceptProposedAction(); +} +void MainInterface::dragMoveEvent(QDragMoveEvent *event) +{ + event->acceptProposedAction(); +} +void MainInterface::dragLeaveEvent(QDragLeaveEvent *event) +{ + event->accept(); +} + /************************************************************************ * Other stuff ************************************************************************/ diff --git a/src/input/meta.c b/src/input/meta.c index 3b8efcba5e..577cdbe57a 100644 --- a/src/input/meta.c +++ b/src/input/meta.c @@ -27,6 +27,7 @@ #include #include "vlc_playlist.h" #include "charset.h" +#include "../playlist/playlist_internal.h" #ifdef HAVE_SYS_STAT_H # include @@ -35,16 +36,9 @@ int input_FindArtInCache( playlist_t *p_playlist, input_item_t *p_item ); vlc_bool_t input_MetaSatisfied( playlist_t *p_playlist, input_item_t *p_item, - uint32_t *pi_mandatory, uint32_t *pi_optional, - vlc_bool_t b_check_cache ) + uint32_t *pi_mandatory, uint32_t *pi_optional ) { - // FIXME don't var_Stuff at each loop - int i_policy = var_CreateGetInteger( p_playlist, "album-art" ); - if( b_check_cache ) - input_FindArtInCache( p_playlist, p_item ); - - *pi_mandatory = VLC_META_ENGINE_TITLE | VLC_META_ENGINE_ARTIST | - (i_policy == ALBUM_ART_ALL ? VLC_META_ENGINE_ART_URL : 0 ); + *pi_mandatory = VLC_META_ENGINE_TITLE | VLC_META_ENGINE_ARTIST; uint32_t i_meta = input_CurrentMetaFlags( p_item->p_meta ); *pi_mandatory &= ~i_meta; @@ -59,12 +53,11 @@ int input_MetaFetch( playlist_t *p_playlist, input_item_t *p_item ) if( !p_item->p_meta ) return VLC_EGENERIC; - input_MetaSatisfied( p_playlist, p_item, - &i_mandatory, &i_optional, VLC_FALSE ); - + input_MetaSatisfied( p_playlist, p_item, &i_mandatory, &i_optional ); // Meta shouldn't magically appear assert( i_mandatory ); + /* FIXME: object creation is overkill, use p_private */ p_me = vlc_object_create( p_playlist, VLC_OBJECT_META_ENGINE ); p_me->i_flags |= OBJECT_FLAGS_NOINTERACT; p_me->i_flags |= OBJECT_FLAGS_QUIET; @@ -78,37 +71,70 @@ int input_MetaFetch( playlist_t *p_playlist, input_item_t *p_item ) vlc_object_destroy( p_me ); return VLC_EGENERIC; } - module_Unneed( p_me, p_me->p_module ); vlc_object_destroy( p_me ); - return VLC_SUCCESS; } -int input_ArtFetch( playlist_t *p_playlist, input_item_t *p_item ) +/* Return codes: + * 0 : Art is in cache + * 1 : Art found, need to download + * -X : Error/not found + */ +int input_ArtFind( playlist_t *p_playlist, input_item_t *p_item ) { - if( !p_item->p_meta ) return VLC_EGENERIC; + int i_ret = VLC_EGENERIC; + module_t *p_module; + if( !p_item->p_meta || !p_item->p_meta->psz_album || + !p_item->p_meta->psz_artist ) + return VLC_EGENERIC; - if( !p_item->p_meta->psz_arturl || !*p_item->p_meta->psz_arturl ) - { - module_t *p_module; - PL_LOCK; - p_playlist->p_private = p_item; - p_module = module_Need( p_playlist, "art finder", 0, VLC_FALSE ); - if( !p_module ) + /* If we already checked this album in this session, skip */ + FOREACH_ARRAY( playlist_album_t album, p_playlist->p_fetcher->albums ) + if( !strcmp( album.psz_artist, p_item->p_meta->psz_artist ) && + !strcmp( album.psz_album, p_item->p_meta->psz_album ) ) { - msg_Dbg( p_playlist, "unable to find art" ); - PL_UNLOCK; - return VLC_EGENERIC; + msg_Dbg( p_playlist, " %s - %s has already been searched", + p_item->p_meta->psz_artist, p_item->p_meta->psz_album ); + if( album.b_found ) + { + /* Actually get URL from cache */ + input_FindArtInCache( p_playlist, p_item ); + return 0; + } + else + return VLC_EGENERIC; } + FOREACH_END(); + + input_FindArtInCache( p_playlist, p_item ); + if( !EMPTY_STR( p_item->p_meta->psz_arturl ) ) + return 0; + + PL_LOCK; + p_playlist->p_private = p_item; + msg_Dbg( p_playlist, "searching art for %s - %s", + p_item->p_meta->psz_artist, p_item->p_meta->psz_album ); + p_module = module_Need( p_playlist, "art finder", 0, VLC_FALSE ); + + if( p_module ) + i_ret = 1; + else + msg_Dbg( p_playlist, "unable to find art" ); + + /* Record this album */ + playlist_album_t a; + a.psz_artist = strdup( p_item->p_meta->psz_artist ); + a.psz_album = strdup( p_item->p_meta->psz_album ); + a.b_found = (i_ret == VLC_EGENERIC ? VLC_FALSE : VLC_TRUE ); + ARRAY_APPEND( p_playlist->p_fetcher->albums, a ); + + if( p_module ) module_Unneed( p_playlist, p_module ); - p_playlist->p_private = NULL; - PL_UNLOCK; + p_playlist->p_private = NULL; + PL_UNLOCK; - if( !p_item->p_meta->psz_arturl || !*p_item->p_meta->psz_arturl ) - return VLC_EGENERIC; - } - return input_DownloadAndCacheArt( p_playlist, p_item ); + return i_ret; } #ifndef MAX_PATH @@ -118,7 +144,7 @@ int input_FindArtInCache( playlist_t *p_playlist, input_item_t *p_item ) { char *psz_artist; char *psz_album; - char psz_filename[MAX_PATH]; + char psz_filename[MAX_PATH+1]; int i; struct stat a; const char *ppsz_type[] = { ".jpg", ".png", ".gif", ".bmp", "" }; @@ -143,7 +169,6 @@ int input_FindArtInCache( playlist_t *p_playlist, input_item_t *p_item ) return VLC_SUCCESS; } } - return VLC_EGENERIC; } @@ -155,28 +180,20 @@ int input_DownloadAndCacheArt( playlist_t *p_playlist, input_item_t *p_item ) { int i_status = VLC_EGENERIC; stream_t *p_stream; - char psz_filename[MAX_PATH], psz_dir[MAX_PATH]; + char psz_filename[MAX_PATH+1], psz_dir[MAX_PATH+1]; char *psz_artist; char *psz_album; char *psz_type; psz_artist = p_item->p_meta->psz_artist; psz_album = p_item->p_meta->psz_album; - /* You dummy ! How am I supposed to download NULL ? */ - if( !p_item->p_meta || !p_item->p_meta->psz_arturl - || !*p_item->p_meta->psz_arturl ) - return VLC_EGENERIC; + assert( p_item->p_meta && !EMPTY_STR(p_item->p_meta->psz_arturl) ); /* FIXME: use an alternate saving filename scheme if we don't have * the artist or album name */ - if( !p_item->p_meta->psz_artist - || !p_item->p_meta->psz_album ) + if( !p_item->p_meta->psz_artist || !p_item->p_meta->psz_album ) return VLC_EGENERIC; - /* Check if file doesn't already exist */ - if( input_FindArtInCache( p_playlist, p_item ) == VLC_SUCCESS ) - return VLC_SUCCESS; - psz_type = strrchr( p_item->p_meta->psz_arturl, '.' ); /* Todo: get a helper to do this */ @@ -202,9 +219,13 @@ int input_DownloadAndCacheArt( playlist_t *p_playlist, input_item_t *p_item ) psz_artist, psz_album ); utf8_mkdir( psz_dir ); - /* Todo: check for stuff that needs a downloader module */ - p_stream = stream_UrlNew( p_playlist, p_item->p_meta->psz_arturl ); + if( !strncmp( p_item->p_meta->psz_arturl , "APIC", 4 ) ) + { + msg_Warn( p_playlist, "APIC fetch not supported yet" ); + return VLC_EGENERIC; + } + p_stream = stream_UrlNew( p_playlist, p_item->p_meta->psz_arturl ); if( p_stream ) { void *p_buffer = malloc( 1<<16 ); @@ -235,15 +256,19 @@ uint32_t input_CurrentMetaFlags( vlc_meta_t *p_meta ) CHECK( title, TITLE ) CHECK( artist, ARTIST ) + CHECK( album, COLLECTION ) +#if 0 + /* As this is not used at the moment, don't uselessly check for it. + * Re-enable this when it is used */ CHECK( genre, GENRE ) CHECK( copyright, COPYRIGHT ) - CHECK( album, COLLECTION ) CHECK( tracknum, SEQ_NUM ) CHECK( description, DESCRIPTION ) CHECK( rating, RATING ) CHECK( date, DATE ) CHECK( url, URL ) CHECK( language, LANGUAGE ) +#endif CHECK( arturl, ART_URL ) return i_meta; diff --git a/src/input/stream.c b/src/input/stream.c index 3dad4ef47b..f40a4f5b54 100644 --- a/src/input/stream.c +++ b/src/input/stream.c @@ -1416,7 +1416,7 @@ char * stream_ReadLine( stream_t *s ) { int i_bom_size = 0; char *psz_encoding = NULL; - + if( p_data[0] == 0xEF && p_data[1] == 0xBB && p_data[2] == 0xBF ) { psz_encoding = strdup( "UTF-8" ); diff --git a/src/playlist/control.c b/src/playlist/control.c index f6703e0297..6fa949576d 100644 --- a/src/playlist/control.c +++ b/src/playlist/control.c @@ -223,16 +223,16 @@ int playlist_AskForArtEnqueue( playlist_t *p_playlist, p.p_item = p_item; p.b_fetch_art = VLC_TRUE; - vlc_mutex_lock( &p_playlist->p_secondary_preparse->object_lock ); - for( i = 0; i < p_playlist->p_secondary_preparse->i_waiting && - p_playlist->p_secondary_preparse->p_waiting->b_fetch_art == VLC_TRUE; + vlc_mutex_lock( &p_playlist->p_fetcher->object_lock ); + for( i = 0; i < p_playlist->p_fetcher->i_waiting && + p_playlist->p_fetcher->p_waiting->b_fetch_art == VLC_TRUE; i++ ); vlc_gc_incref( p_item ); - INSERT_ELEM( p_playlist->p_secondary_preparse->p_waiting, - p_playlist->p_secondary_preparse->i_waiting, + INSERT_ELEM( p_playlist->p_fetcher->p_waiting, + p_playlist->p_fetcher->i_waiting, i, p ); - vlc_mutex_unlock( &p_playlist->p_secondary_preparse->object_lock ); - vlc_cond_signal( &p_playlist->p_secondary_preparse->object_wait ); + vlc_mutex_unlock( &p_playlist->p_fetcher->object_lock ); + vlc_cond_signal( &p_playlist->p_fetcher->object_wait ); return VLC_SUCCESS; } diff --git a/src/playlist/engine.c b/src/playlist/engine.c index 86a3c14623..6c798e1fc6 100644 --- a/src/playlist/engine.c +++ b/src/playlist/engine.c @@ -21,6 +21,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ + #include #include #include @@ -147,11 +148,11 @@ void playlist_Destroy( playlist_t *p_playlist ) playlist_MLDump( p_playlist ); vlc_thread_join( p_playlist->p_preparse ); - vlc_thread_join( p_playlist->p_secondary_preparse ); + vlc_thread_join( p_playlist->p_fetcher ); vlc_thread_join( p_playlist ); vlc_object_detach( p_playlist->p_preparse ); - vlc_object_detach( p_playlist->p_secondary_preparse ); + vlc_object_detach( p_playlist->p_fetcher ); var_Destroy( p_playlist, "intf-change" ); var_Destroy( p_playlist, "item-change" ); @@ -191,7 +192,7 @@ void playlist_Destroy( playlist_t *p_playlist ) vlc_mutex_destroy( &p_playlist->gc_lock ); vlc_object_destroy( p_playlist->p_preparse ); - vlc_object_destroy( p_playlist->p_secondary_preparse ); + vlc_object_destroy( p_playlist->p_fetcher ); vlc_object_detach( p_playlist ); vlc_object_destroy( p_playlist ); @@ -511,29 +512,47 @@ void playlist_PreparseLoop( playlist_preparse_t *p_obj ) PL_LOCK; /* If we haven't retrieved enough meta, add to secondary queue - * which will run the "meta fetchers" - * TODO: - * don't do this for things we won't get meta for, like - * videos + * which will run the "meta fetchers". + * This only checks for meta, not for art + * \todo don't do this for things we won't get meta for, like vids */ - if( !input_MetaSatisfied( p_playlist, p_current, &i_m, &i_o, - VLC_TRUE ) ) + if( !input_MetaSatisfied( p_playlist, p_current, &i_m, &i_o ) ) { preparse_item_t p; + PL_DEBUG("need to fetch meta for %s", p_current->psz_name ); p.p_item = p_current; p.b_fetch_art = VLC_FALSE; - vlc_mutex_lock( &p_playlist->p_secondary_preparse->object_lock); - INSERT_ELEM( p_playlist->p_secondary_preparse->p_waiting, - p_playlist->p_secondary_preparse->i_waiting, - p_playlist->p_secondary_preparse->i_waiting, + vlc_mutex_lock( &p_playlist->p_fetcher->object_lock ); + INSERT_ELEM( p_playlist->p_fetcher->p_waiting, + p_playlist->p_fetcher->i_waiting, + p_playlist->p_fetcher->i_waiting, + p ); + vlc_mutex_unlock( &p_playlist->p_fetcher->object_lock ); + vlc_cond_signal( &p_playlist->p_fetcher->object_wait ); + } + /* We already have all needed meta, but we need art right now */ + else if( p_playlist->p_fetcher->i_art_policy == ALBUM_ART_ALL && + EMPTY_STR( p_current->p_meta->psz_arturl ) ) + { + preparse_item_t p; + PL_DEBUG("meta ok for %s, need to fetch art", + p_current->psz_name ); + p.p_item = p_current; + p.b_fetch_art = VLC_TRUE; + vlc_mutex_lock( &p_playlist->p_fetcher->object_lock ); + INSERT_ELEM( p_playlist->p_fetcher->p_waiting, + p_playlist->p_fetcher->i_waiting, + p_playlist->p_fetcher->i_waiting, p ); - vlc_mutex_unlock( - &p_playlist->p_secondary_preparse->object_lock); - vlc_cond_signal( - &p_playlist->p_secondary_preparse->object_wait ); + vlc_mutex_unlock( &p_playlist->p_fetcher->object_lock ); + vlc_cond_signal( &p_playlist->p_fetcher->object_wait ); } else + { + PL_DEBUG( "no fetch required for %s (art currently %s)", + p_current->psz_name, p_current->p_meta->psz_arturl ); vlc_gc_decref( p_current ); + } PL_UNLOCK; } else @@ -549,7 +568,7 @@ void playlist_PreparseLoop( playlist_preparse_t *p_obj ) } /** Main loop for secondary preparser queue */ -void playlist_SecondaryPreparseLoop( playlist_secondary_preparse_t *p_obj ) +void playlist_FetcherLoop( playlist_fetcher_t *p_obj ) { playlist_t *p_playlist = (playlist_t *)p_obj->p_parent; vlc_bool_t b_fetch_art; @@ -581,24 +600,43 @@ void playlist_SecondaryPreparseLoop( playlist_secondary_preparse_t *p_obj ) p_item->p_meta->i_status |= ITEM_META_FETCHED; var_SetInteger( p_playlist, "item-change", p_item->i_id ); /* Fetch right now */ - if( var_GetInteger( p_playlist, "album-art" ) == ALBUM_ART_ALL ) + if( p_playlist->p_fetcher->i_art_policy == ALBUM_ART_ALL ) { vlc_mutex_lock( &p_obj->object_lock ); preparse_item_t p; p.p_item = p_item; p.b_fetch_art = VLC_TRUE; - INSERT_ELEM( p_playlist->p_secondary_preparse->p_waiting, - p_playlist->p_secondary_preparse->i_waiting, + INSERT_ELEM( p_playlist->p_fetcher->p_waiting, + p_playlist->p_fetcher->i_waiting, 0, p ); + PL_DEBUG("meta fetched for %s, get art", p_item->psz_name); vlc_mutex_unlock( &p_obj->object_lock ); + continue; } else vlc_gc_decref( p_item ); } else { - input_ArtFetch( p_playlist, p_item ); - p_item->p_meta->i_status |= ITEM_ART_FETCHED; + int i_ret = input_ArtFind( p_playlist, p_item ); + if( i_ret == 1 ) + { + PL_DEBUG("downloading art for %s", p_item->psz_name ); + if( !input_DownloadAndCacheArt( p_playlist, p_item ) ) + p_item->p_meta->i_status |= ITEM_ART_NOTFOUND; + else + p_item->p_meta->i_status |= ITEM_ART_FETCHED; + } + else if( i_ret == 0 ) /* Was in cache */ + { + PL_DEBUG("found art for %s in cache", p_item->psz_name ); + p_item->p_meta->i_status |= ITEM_ART_FETCHED; + } + else + { + PL_DEBUG("art not found for %s", p_item->psz_name ); + p_item->p_meta->i_status |= ITEM_ART_NOTFOUND; + } vlc_gc_decref( p_item ); } } diff --git a/src/playlist/playlist_internal.h b/src/playlist/playlist_internal.h index b77a2bf99c..979200fb83 100644 --- a/src/playlist/playlist_internal.h +++ b/src/playlist/playlist_internal.h @@ -45,12 +45,15 @@ typedef struct preparse_item_t vlc_bool_t b_fetch_art; } preparse_item_t; -struct playlist_secondary_preparse_t +struct playlist_fetcher_t { VLC_COMMON_MEMBERS vlc_mutex_t lock; + int i_art_policy; int i_waiting; preparse_item_t *p_waiting; + + DECL_ARRAY(playlist_album_t) albums; }; /***************************************************************************** @@ -65,7 +68,7 @@ void playlist_Destroy ( playlist_t * ); void playlist_MainLoop( playlist_t * ); void playlist_LastLoop( playlist_t * ); void playlist_PreparseLoop( playlist_preparse_t * ); -void playlist_SecondaryPreparseLoop( playlist_secondary_preparse_t * ); +void playlist_FetcherLoop( playlist_fetcher_t * ); void ResetCurrentlyPlaying( playlist_t *, vlc_bool_t, playlist_item_t * ); @@ -100,8 +103,8 @@ playlist_item_t *playlist_GetLastLeaf( playlist_t *p_playlist, * @} */ -//#define PLAYLIST_DEBUG 1 -#undef PLAYLIST_DEBUG +#define PLAYLIST_DEBUG 1 +//#undef PLAYLIST_DEBUG #ifdef PLAYLIST_DEBUG #define PL_DEBUG( msg, args... ) msg_Dbg( p_playlist, msg, ## args ) diff --git a/src/playlist/thread.c b/src/playlist/thread.c index 0c08a8bc0c..635af4e09b 100644 --- a/src/playlist/thread.c +++ b/src/playlist/thread.c @@ -33,7 +33,7 @@ *****************************************************************************/ static void RunControlThread ( playlist_t * ); static void RunPreparse( playlist_preparse_t * ); -static void RunSecondaryPreparse( playlist_secondary_preparse_t * ); +static void RunFetcher( playlist_fetcher_t * ); static playlist_t * CreatePlaylist( vlc_object_t *p_parent ); static void EndPlaylist( playlist_t * ); @@ -92,26 +92,28 @@ void __playlist_ThreadCreate( vlc_object_t *p_parent ) } // Secondary Preparse - p_playlist->p_secondary_preparse = vlc_object_create( p_playlist, - sizeof( playlist_secondary_preparse_t ) ); - if( !p_playlist->p_secondary_preparse ) + p_playlist->p_fetcher = vlc_object_create( p_playlist, + sizeof( playlist_fetcher_t ) ); + if( !p_playlist->p_fetcher ) { msg_Err( p_playlist, "unable to create secondary preparser" ); vlc_object_destroy( p_playlist ); return; } - p_playlist->p_secondary_preparse->i_waiting = 0; - p_playlist->p_secondary_preparse->p_waiting = NULL; - - vlc_object_attach( p_playlist->p_secondary_preparse, p_playlist ); - if( vlc_thread_create( p_playlist->p_secondary_preparse, - "secondary preparser", - RunSecondaryPreparse, + p_playlist->p_fetcher->i_waiting = 0; + p_playlist->p_fetcher->p_waiting = NULL; + p_playlist->p_fetcher->i_art_policy = var_CreateGetInteger( p_playlist, + "album-art" ); + + vlc_object_attach( p_playlist->p_fetcher, p_playlist ); + if( vlc_thread_create( p_playlist->p_fetcher, + "fetcher", + RunFetcher, VLC_THREAD_PRIORITY_LOW, VLC_TRUE ) ) { msg_Err( p_playlist, "cannot spawn secondary preparse thread" ); - vlc_object_detach( p_playlist->p_secondary_preparse ); - vlc_object_destroy( p_playlist->p_secondary_preparse ); + vlc_object_detach( p_playlist->p_fetcher ); + vlc_object_destroy( p_playlist->p_fetcher ); return; } @@ -146,10 +148,10 @@ int playlist_ThreadDestroy( playlist_t * p_playlist ) vlc_cond_signal( &p_playlist->p_preparse->object_wait ); free( p_playlist->p_preparse->pp_waiting ); } - if( p_playlist->p_secondary_preparse ) + if( p_playlist->p_fetcher ) { - vlc_cond_signal( &p_playlist->p_secondary_preparse->object_wait ); - free( p_playlist->p_secondary_preparse->p_waiting ); + vlc_cond_signal( &p_playlist->p_fetcher->object_wait ); + free( p_playlist->p_fetcher->p_waiting ); } DestroyInteraction( p_playlist ); @@ -221,11 +223,11 @@ static void RunPreparse ( playlist_preparse_t *p_obj ) playlist_PreparseLoop( p_obj ); } -static void RunSecondaryPreparse( playlist_secondary_preparse_t *p_obj ) +static void RunFetcher( playlist_fetcher_t *p_obj ) { /* Tell above that we're ready */ vlc_thread_ready( p_obj ); - playlist_SecondaryPreparseLoop( p_obj ); + playlist_FetcherLoop( p_obj ); } /*****************************************************************************