Commit d3217fc7 authored by Clément Stenac's avatar Clément Stenac

Clean up and improve core handling for album art. Still only "always fetch" implemented

parent d6050322
...@@ -236,7 +236,7 @@ typedef struct services_discovery_t services_discovery_t; ...@@ -236,7 +236,7 @@ typedef struct services_discovery_t services_discovery_t;
typedef struct services_discovery_sys_t services_discovery_sys_t; typedef struct services_discovery_sys_t services_discovery_sys_t;
typedef struct playlist_add_t playlist_add_t; typedef struct playlist_add_t playlist_add_t;
typedef struct playlist_preparse_t playlist_preparse_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 */ /* Modules */
typedef struct module_bank_t module_bank_t; typedef struct module_bank_t module_bank_t;
...@@ -635,6 +635,8 @@ static int64_t GCD( int64_t a, int64_t b ) ...@@ -635,6 +635,8 @@ static int64_t GCD( int64_t a, int64_t b )
#define FREENULL(a) if( a ) { free( a ); a = NULL; } #define FREENULL(a) if( a ) { free( a ); a = NULL; }
#define FREE(a) if( a ) { free( a ); } #define FREE(a) if( a ) { free( a ); }
#define EMPTY_STR(str) (!str || !*str)
#include <vlc_arrays.h> #include <vlc_arrays.h>
/* MSB (big endian)/LSB (little endian) conversions - network order is always /* MSB (big endian)/LSB (little endian) conversions - network order is always
......
...@@ -474,11 +474,17 @@ VLC_EXPORT( int, __input_Read, ( vlc_object_t *, input_item_t *, vlc_bool_t ) ); ...@@ -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_StopThread, ( input_thread_t * ) );
VLC_EXPORT( void, input_DestroyThread, ( 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_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*, 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 * ); int input_DownloadAndCacheArt ( playlist_t *, input_item_t * );
enum input_query_e enum input_query_e
......
...@@ -51,6 +51,7 @@ ...@@ -51,6 +51,7 @@
#define ITEM_META_FETCHED 0x02 #define ITEM_META_FETCHED 0x02
#define ITEM_ARTURL_FETCHED 0x04 #define ITEM_ARTURL_FETCHED 0x04
#define ITEM_ART_FETCHED 0x08 #define ITEM_ART_FETCHED 0x08
#define ITEM_ART_NOTFOUND 0x10
struct vlc_meta_t struct vlc_meta_t
{ {
...@@ -193,7 +194,8 @@ enum { ...@@ -193,7 +194,8 @@ enum {
ALBUM_ART_NEVER, ALBUM_ART_NEVER,
ALBUM_ART_WHEN_ASKED, ALBUM_ART_WHEN_ASKED,
ALBUM_ART_WHEN_PLAYED, ALBUM_ART_WHEN_PLAYED,
ALBUM_ART_ALL }; ALBUM_ART_ALL
};
struct meta_export_t struct meta_export_t
{ {
......
...@@ -141,7 +141,7 @@ struct playlist_t ...@@ -141,7 +141,7 @@ struct playlist_t
mtime_t gc_date; mtime_t gc_date;
vlc_bool_t b_cant_sleep; vlc_bool_t b_cant_sleep;
playlist_preparse_t *p_preparse; /**< Preparser object */ 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 */ vlc_mutex_t gc_lock; /**< Lock to protect the garbage collection */
......
...@@ -82,42 +82,37 @@ QSize savedVideoSize; ...@@ -82,42 +82,37 @@ QSize savedVideoSize;
MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf ) MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
{ {
/* Configuration */
settings = new QSettings( "VideoLAN", "VLC" ); settings = new QSettings( "VideoLAN", "VLC" );
settings->beginGroup( "MainWindow" ); settings->beginGroup( "MainWindow" );
setAcceptDrops(true);
need_components_update = false; need_components_update = false;
bgWidget = NULL; videoWidget = NULL; playlistWidget = NULL; bgWidget = NULL; videoWidget = NULL; playlistWidget = NULL;
embeddedPlaylistWasActive = videoIsActive = false; embeddedPlaylistWasActive = videoIsActive = false;
/* Fetch configuration from settings and vlc config */
videoEmbeddedFlag = false; videoEmbeddedFlag = false;
if( config_GetInt( p_intf, "embedded-video" ) ) if( config_GetInt( p_intf, "embedded-video" ) ) videoEmbeddedFlag = true;
videoEmbeddedFlag = true;
alwaysVideoFlag = false; alwaysVideoFlag = false;
if( videoEmbeddedFlag && config_GetInt( p_intf, "qt-always-video" )) if( videoEmbeddedFlag && config_GetInt( p_intf, "qt-always-video" ))
alwaysVideoFlag = true; alwaysVideoFlag = true;
playlistEmbeddedFlag = settings->value( "playlist-embedded", true ). playlistEmbeddedFlag = settings->value("playlist-embedded", true).toBool();
toBool();
advControlsEnabled= settings->value( "adv-controls", false ).toBool(); advControlsEnabled= settings->value( "adv-controls", false ).toBool();
visualSelectorEnabled= settings->value( "visual-selector", false ).toBool(); visualSelectorEnabled= settings->value( "visual-selector", false ).toBool();
/* UI */
setWindowTitle( QString::fromUtf8( _("VLC media player") ) ); setWindowTitle( QString::fromUtf8( _("VLC media player") ) );
handleMainUi( settings ); handleMainUi( settings );
QVLCMenu::createMenuBar( this, p_intf, playlistEmbeddedFlag, QVLCMenu::createMenuBar( this, p_intf, playlistEmbeddedFlag,
advControlsEnabled, visualSelectorEnabled ); advControlsEnabled, visualSelectorEnabled );
/* Status bar */
timeLabel = new QLabel( 0 ); timeLabel = new QLabel( 0 );
nameLabel = new QLabel( 0 ); nameLabel = new QLabel( 0 );
statusBar()->addWidget( nameLabel, 4 ); statusBar()->addWidget( nameLabel, 4 );
statusBar()->addPermanentWidget( timeLabel, 1 ); statusBar()->addPermanentWidget( timeLabel, 1 );
setFocusPolicy( Qt::StrongFocus ); setFocusPolicy( Qt::StrongFocus );
setAcceptDrops(true);
/* Init input manager */ /* Init input manager */
MainInputManager::getInstance( p_intf ); MainInputManager::getInstance( p_intf );
...@@ -140,51 +135,6 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf ) ...@@ -140,51 +135,6 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
p_intf->b_interaction = VLC_TRUE; 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() MainInterface::~MainInterface()
{ {
settings->setValue( "playlist-embedded", playlistEmbeddedFlag ); settings->setValue( "playlist-embedded", playlistEmbeddedFlag );
...@@ -389,8 +339,6 @@ int MainInterface::controlVideo( void *p_window, int i_query, va_list args ) ...@@ -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_width = va_arg( args, unsigned int );
unsigned int i_height = 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->widgetSize = QSize( i_width, i_height );
videoWidget->updateGeometry(); videoWidget->updateGeometry();
need_components_update = true; need_components_update = true;
...@@ -462,8 +410,7 @@ void MainInterface::playlist() ...@@ -462,8 +410,7 @@ void MainInterface::playlist()
QSize( 650, 310 ) ).toSize(); QSize( 650, 310 ) ).toSize();
playlistWidget->hide(); playlistWidget->hide();
} }
/// Todo, reset its size ? if( VISIBLE( playlistWidget ) )
if( VISIBLE( playlistWidget) )
{ {
playlistWidget->hide(); playlistWidget->hide();
if( videoIsActive ) if( videoIsActive )
...@@ -535,6 +482,53 @@ void MainInterface::customEvent( QEvent *event ) ...@@ -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 * Other stuff
************************************************************************/ ************************************************************************/
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <vlc_meta.h> #include <vlc_meta.h>
#include "vlc_playlist.h" #include "vlc_playlist.h"
#include "charset.h" #include "charset.h"
#include "../playlist/playlist_internal.h"
#ifdef HAVE_SYS_STAT_H #ifdef HAVE_SYS_STAT_H
# include <sys/stat.h> # include <sys/stat.h>
...@@ -35,16 +36,9 @@ ...@@ -35,16 +36,9 @@
int input_FindArtInCache( playlist_t *p_playlist, input_item_t *p_item ); 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, vlc_bool_t input_MetaSatisfied( playlist_t *p_playlist, input_item_t *p_item,
uint32_t *pi_mandatory, uint32_t *pi_optional, uint32_t *pi_mandatory, uint32_t *pi_optional )
vlc_bool_t b_check_cache )
{ {
// FIXME don't var_Stuff at each loop *pi_mandatory = VLC_META_ENGINE_TITLE | VLC_META_ENGINE_ARTIST;
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 );
uint32_t i_meta = input_CurrentMetaFlags( p_item->p_meta ); uint32_t i_meta = input_CurrentMetaFlags( p_item->p_meta );
*pi_mandatory &= ~i_meta; *pi_mandatory &= ~i_meta;
...@@ -59,12 +53,11 @@ int input_MetaFetch( playlist_t *p_playlist, input_item_t *p_item ) ...@@ -59,12 +53,11 @@ int input_MetaFetch( playlist_t *p_playlist, input_item_t *p_item )
if( !p_item->p_meta ) return VLC_EGENERIC; if( !p_item->p_meta ) return VLC_EGENERIC;
input_MetaSatisfied( p_playlist, p_item, input_MetaSatisfied( p_playlist, p_item, &i_mandatory, &i_optional );
&i_mandatory, &i_optional, VLC_FALSE );
// Meta shouldn't magically appear // Meta shouldn't magically appear
assert( i_mandatory ); assert( i_mandatory );
/* FIXME: object creation is overkill, use p_private */
p_me = vlc_object_create( p_playlist, VLC_OBJECT_META_ENGINE ); p_me = vlc_object_create( p_playlist, VLC_OBJECT_META_ENGINE );
p_me->i_flags |= OBJECT_FLAGS_NOINTERACT; p_me->i_flags |= OBJECT_FLAGS_NOINTERACT;
p_me->i_flags |= OBJECT_FLAGS_QUIET; p_me->i_flags |= OBJECT_FLAGS_QUIET;
...@@ -78,37 +71,70 @@ int input_MetaFetch( playlist_t *p_playlist, input_item_t *p_item ) ...@@ -78,37 +71,70 @@ int input_MetaFetch( playlist_t *p_playlist, input_item_t *p_item )
vlc_object_destroy( p_me ); vlc_object_destroy( p_me );
return VLC_EGENERIC; return VLC_EGENERIC;
} }
module_Unneed( p_me, p_me->p_module ); module_Unneed( p_me, p_me->p_module );
vlc_object_destroy( p_me ); vlc_object_destroy( p_me );
return VLC_SUCCESS; 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 ) /* 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 ) )
{ {
module_t *p_module; 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; PL_LOCK;
p_playlist->p_private = p_item; 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 ); p_module = module_Need( p_playlist, "art finder", 0, VLC_FALSE );
if( !p_module )
{ if( p_module )
i_ret = 1;
else
msg_Dbg( p_playlist, "unable to find art" ); msg_Dbg( p_playlist, "unable to find art" );
PL_UNLOCK;
return VLC_EGENERIC; /* 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 ); module_Unneed( p_playlist, p_module );
p_playlist->p_private = NULL; p_playlist->p_private = NULL;
PL_UNLOCK; PL_UNLOCK;
if( !p_item->p_meta->psz_arturl || !*p_item->p_meta->psz_arturl ) return i_ret;
return VLC_EGENERIC;
}
return input_DownloadAndCacheArt( p_playlist, p_item );
} }
#ifndef MAX_PATH #ifndef MAX_PATH
...@@ -118,7 +144,7 @@ int input_FindArtInCache( playlist_t *p_playlist, input_item_t *p_item ) ...@@ -118,7 +144,7 @@ int input_FindArtInCache( playlist_t *p_playlist, input_item_t *p_item )
{ {
char *psz_artist; char *psz_artist;
char *psz_album; char *psz_album;
char psz_filename[MAX_PATH]; char psz_filename[MAX_PATH+1];
int i; int i;
struct stat a; struct stat a;
const char *ppsz_type[] = { ".jpg", ".png", ".gif", ".bmp", "" }; const char *ppsz_type[] = { ".jpg", ".png", ".gif", ".bmp", "" };
...@@ -143,7 +169,6 @@ int input_FindArtInCache( playlist_t *p_playlist, input_item_t *p_item ) ...@@ -143,7 +169,6 @@ int input_FindArtInCache( playlist_t *p_playlist, input_item_t *p_item )
return VLC_SUCCESS; return VLC_SUCCESS;
} }
} }
return VLC_EGENERIC; return VLC_EGENERIC;
} }
...@@ -155,28 +180,20 @@ int input_DownloadAndCacheArt( playlist_t *p_playlist, input_item_t *p_item ) ...@@ -155,28 +180,20 @@ int input_DownloadAndCacheArt( playlist_t *p_playlist, input_item_t *p_item )
{ {
int i_status = VLC_EGENERIC; int i_status = VLC_EGENERIC;
stream_t *p_stream; 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_artist;
char *psz_album; char *psz_album;
char *psz_type; char *psz_type;
psz_artist = p_item->p_meta->psz_artist; psz_artist = p_item->p_meta->psz_artist;
psz_album = p_item->p_meta->psz_album; psz_album = p_item->p_meta->psz_album;
/* You dummy ! How am I supposed to download NULL ? */ assert( p_item->p_meta && !EMPTY_STR(p_item->p_meta->psz_arturl) );
if( !p_item->p_meta || !p_item->p_meta->psz_arturl
|| !*p_item->p_meta->psz_arturl )
return VLC_EGENERIC;
/* FIXME: use an alternate saving filename scheme if we don't have /* FIXME: use an alternate saving filename scheme if we don't have
* the artist or album name */ * the artist or album name */
if( !p_item->p_meta->psz_artist if( !p_item->p_meta->psz_artist || !p_item->p_meta->psz_album )
|| !p_item->p_meta->psz_album )
return VLC_EGENERIC; 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, '.' ); psz_type = strrchr( p_item->p_meta->psz_arturl, '.' );
/* Todo: get a helper to do this */ /* Todo: get a helper to do this */
...@@ -202,9 +219,13 @@ int input_DownloadAndCacheArt( playlist_t *p_playlist, input_item_t *p_item ) ...@@ -202,9 +219,13 @@ int input_DownloadAndCacheArt( playlist_t *p_playlist, input_item_t *p_item )
psz_artist, psz_album ); psz_artist, psz_album );
utf8_mkdir( psz_dir ); utf8_mkdir( psz_dir );
/* Todo: check for stuff that needs a downloader module */ if( !strncmp( p_item->p_meta->psz_arturl , "APIC", 4 ) )
p_stream = stream_UrlNew( p_playlist, p_item->p_meta->psz_arturl ); {
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 ) if( p_stream )
{ {
void *p_buffer = malloc( 1<<16 ); void *p_buffer = malloc( 1<<16 );
...@@ -235,15 +256,19 @@ uint32_t input_CurrentMetaFlags( vlc_meta_t *p_meta ) ...@@ -235,15 +256,19 @@ uint32_t input_CurrentMetaFlags( vlc_meta_t *p_meta )
CHECK( title, TITLE ) CHECK( title, TITLE )
CHECK( artist, ARTIST ) 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( genre, GENRE )
CHECK( copyright, COPYRIGHT ) CHECK( copyright, COPYRIGHT )
CHECK( album, COLLECTION )
CHECK( tracknum, SEQ_NUM ) CHECK( tracknum, SEQ_NUM )
CHECK( description, DESCRIPTION ) CHECK( description, DESCRIPTION )
CHECK( rating, RATING ) CHECK( rating, RATING )
CHECK( date, DATE ) CHECK( date, DATE )
CHECK( url, URL ) CHECK( url, URL )
CHECK( language, LANGUAGE ) CHECK( language, LANGUAGE )
#endif
CHECK( arturl, ART_URL ) CHECK( arturl, ART_URL )
return i_meta; return i_meta;
......
...@@ -223,16 +223,16 @@ int playlist_AskForArtEnqueue( playlist_t *p_playlist, ...@@ -223,16 +223,16 @@ int playlist_AskForArtEnqueue( playlist_t *p_playlist,
p.p_item = p_item; p.p_item = p_item;
p.b_fetch_art = VLC_TRUE; p.b_fetch_art = VLC_TRUE;
vlc_mutex_lock( &p_playlist->p_secondary_preparse->object_lock ); vlc_mutex_lock( &p_playlist->p_fetcher->object_lock );
for( i = 0; i < p_playlist->p_secondary_preparse->i_waiting && for( i = 0; i < p_playlist->p_fetcher->i_waiting &&
p_playlist->p_secondary_preparse->p_waiting->b_fetch_art == VLC_TRUE; p_playlist->p_fetcher->p_waiting->b_fetch_art == VLC_TRUE;
i++ ); i++ );
vlc_gc_incref( p_item ); vlc_gc_incref( p_item );
INSERT_ELEM( p_playlist->p_secondary_preparse->p_waiting, INSERT_ELEM( p_playlist->p_fetcher->p_waiting,
p_playlist->p_secondary_preparse->i_waiting, p_playlist->p_fetcher->i_waiting,
i, p ); i, p );
vlc_mutex_unlock( &p_playlist->p_secondary_preparse->object_lock ); vlc_mutex_unlock( &p_playlist->p_fetcher->object_lock );
vlc_cond_signal( &p_playlist->p_secondary_preparse->object_wait ); vlc_cond_signal( &p_playlist->p_fetcher->object_wait );
return VLC_SUCCESS; return VLC_SUCCESS;
} }
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/ *****************************************************************************/
#include <vlc/vlc.h> #include <vlc/vlc.h>
#include <vlc/vout.h> #include <vlc/vout.h>
#include <vlc/sout.h> #include <vlc/sout.h>
...@@ -147,11 +148,11 @@ void playlist_Destroy( playlist_t *p_playlist ) ...@@ -147,11 +148,11 @@ void playlist_Destroy( playlist_t *p_playlist )
playlist_MLDump( p_playlist ); playlist_MLDump( p_playlist );
vlc_thread_join( p_playlist->p_preparse ); 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_thread_join( p_playlist );
vlc_object_detach( p_playlist->p_preparse ); 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, "intf-change" );
var_Destroy( p_playlist, "item-change" ); var_Destroy( p_playlist, "item-change" );
...@@ -191,7 +192,7 @@ void playlist_Destroy( playlist_t *p_playlist ) ...@@ -191,7 +192,7 @@ void playlist_Destroy( playlist_t *p_playlist )
vlc_mutex_destroy( &p_playlist->gc_lock ); vlc_mutex_destroy( &p_playlist->gc_lock );
vlc_object_destroy( p_playlist->p_preparse ); 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_detach( p_playlist );
vlc_object_destroy( p_playlist ); vlc_object_destroy( p_playlist );
...@@ -511,29 +512,47 @@ void playlist_PreparseLoop( playlist_preparse_t *p_obj ) ...@@ -511,29 +512,47 @@ void playlist_PreparseLoop( playlist_preparse_t *p_obj )
PL_LOCK; PL_LOCK;
/* If we haven't retrieved enough meta, add to secondary queue /* If we haven't retrieved enough meta, add to secondary queue
* which will run the "meta fetchers" * which will run the "meta fetchers".
* TODO: * This only checks for meta, not for art
* don't do this for things we won't get meta for, like * \todo don't do this for things we won't get meta for, like vids
* videos
*/ */
if( !input_MetaSatisfied( p_playlist, p_current, &i_m, &i_o, if( !input_MetaSatisfied( p_playlist, p_current, &i_m, &i_o ) )
VLC_TRUE ) )
{ {
preparse_item_t p; preparse_item_t p;
PL_DEBUG("need to fetch meta for %s", p_current->psz_name );
p.p_item = p_current; p.p_item = p_current;
p.b_fetch_art = VLC_FALSE; p.b_fetch_art = VLC_FALSE;
vlc_mutex_lock( &p_playlist->p_secondary_preparse->object_lock); vlc_mutex_lock( &p_playlist->p_fetcher->object_lock );
INSERT_ELEM( p_playlist->p_secondary_preparse->p_waiting, INSERT_ELEM( p_playlist->p_fetcher->p_waiting,
p_playlist->p_secondary_preparse->i_waiting, p_playlist->p_fetcher->i_waiting,
p_playlist->p_secondary_preparse->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 ); p );
vlc_mutex_unlock( vlc_mutex_unlock( &p_playlist->p_fetcher->object_lock );
&p_playlist->p_secondary_preparse->object_lock); vlc_cond_signal( &p_playlist->p_fetcher->object_wait );
vlc_cond_signal(
&p_playlist->p_secondary_preparse->object_wait );
} }
else 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 ); vlc_gc_decref( p_current );
}
PL_UNLOCK; PL_UNLOCK;
} }
else else
...@@ -549,7 +568,7 @@ void playlist_PreparseLoop( playlist_preparse_t *p_obj ) ...@@ -549,7 +568,7 @@ void playlist_PreparseLoop( playlist_preparse_t *p_obj )
} }
/** Main loop for secondary preparser queue */ /** 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; playlist_t *p_playlist = (playlist_t *)p_obj->p_parent;
vlc_bool_t b_fetch_art; vlc_bool_t b_fetch_art;
...@@ -581,24 +600,43 @@ void playlist_SecondaryPreparseLoop( playlist_secondary_preparse_t *p_obj ) ...@@ -581,24 +600,43 @@ void playlist_SecondaryPreparseLoop( playlist_secondary_preparse_t *p_obj )
p_item->p_meta->i_status |= ITEM_META_FETCHED; p_item->p_meta->i_status |= ITEM_META_FETCHED;
var_SetInteger( p_playlist, "item-change", p_item->i_id ); var_SetInteger( p_playlist, "item-change", p_item->i_id );
/* Fetch right now */ /* 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 ); vlc_mutex_lock( &p_obj->object_lock );
preparse_item_t p; preparse_item_t p;
p.p_item = p_item; p.p_item = p_item;
p.b_fetch_art = VLC_TRUE; p.b_fetch_art = VLC_TRUE;
INSERT_ELEM( p_playlist->p_secondary_preparse->p_waiting, INSERT_ELEM( p_playlist->p_fetcher->p_waiting,
p_playlist->p_secondary_preparse->i_waiting, p_playlist->p_fetcher->i_waiting,
0, p ); 0, p );
PL_DEBUG("meta fetched for %s, get art", p_item->psz_name);
vlc_mutex_unlock( &p_obj->object_lock ); vlc_mutex_unlock( &p_obj->object_lock );
continue;
} }
else else
vlc_gc_decref( p_item ); vlc_gc_decref( p_item );
} }
else else
{ {
input_ArtFetch( p_playlist, p_item ); 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; 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 ); vlc_gc_decref( p_item );
} }
} }
......
...@@ -45,12 +45,15 @@ typedef struct preparse_item_t ...@@ -45,12 +45,15 @@ typedef struct preparse_item_t
vlc_bool_t b_fetch_art; vlc_bool_t b_fetch_art;
} preparse_item_t; } preparse_item_t;
struct playlist_secondary_preparse_t struct playlist_fetcher_t
{ {
VLC_COMMON_MEMBERS VLC_COMMON_MEMBERS
vlc_mutex_t lock; vlc_mutex_t lock;
int i_art_policy;
int i_waiting; int i_waiting;
preparse_item_t *p_waiting; preparse_item_t *p_waiting;
DECL_ARRAY(playlist_album_t) albums;
}; };
/***************************************************************************** /*****************************************************************************
...@@ -65,7 +68,7 @@ void playlist_Destroy ( playlist_t * ); ...@@ -65,7 +68,7 @@ void playlist_Destroy ( playlist_t * );
void playlist_MainLoop( playlist_t * ); void playlist_MainLoop( playlist_t * );
void playlist_LastLoop( playlist_t * ); void playlist_LastLoop( playlist_t * );
void playlist_PreparseLoop( playlist_preparse_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 * ); void ResetCurrentlyPlaying( playlist_t *, vlc_bool_t, playlist_item_t * );
...@@ -100,8 +103,8 @@ playlist_item_t *playlist_GetLastLeaf( playlist_t *p_playlist, ...@@ -100,8 +103,8 @@ playlist_item_t *playlist_GetLastLeaf( playlist_t *p_playlist,
* @} * @}
*/ */
//#define PLAYLIST_DEBUG 1 #define PLAYLIST_DEBUG 1
#undef PLAYLIST_DEBUG //#undef PLAYLIST_DEBUG
#ifdef PLAYLIST_DEBUG #ifdef PLAYLIST_DEBUG
#define PL_DEBUG( msg, args... ) msg_Dbg( p_playlist, msg, ## args ) #define PL_DEBUG( msg, args... ) msg_Dbg( p_playlist, msg, ## args )
......
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
*****************************************************************************/ *****************************************************************************/
static void RunControlThread ( playlist_t * ); static void RunControlThread ( playlist_t * );
static void RunPreparse( playlist_preparse_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 playlist_t * CreatePlaylist( vlc_object_t *p_parent );
static void EndPlaylist( playlist_t * ); static void EndPlaylist( playlist_t * );
...@@ -92,26 +92,28 @@ void __playlist_ThreadCreate( vlc_object_t *p_parent ) ...@@ -92,26 +92,28 @@ void __playlist_ThreadCreate( vlc_object_t *p_parent )
} }
// Secondary Preparse // Secondary Preparse
p_playlist->p_secondary_preparse = vlc_object_create( p_playlist, p_playlist->p_fetcher = vlc_object_create( p_playlist,
sizeof( playlist_secondary_preparse_t ) ); sizeof( playlist_fetcher_t ) );
if( !p_playlist->p_secondary_preparse ) if( !p_playlist->p_fetcher )
{ {
msg_Err( p_playlist, "unable to create secondary preparser" ); msg_Err( p_playlist, "unable to create secondary preparser" );
vlc_object_destroy( p_playlist ); vlc_object_destroy( p_playlist );
return; return;
} }
p_playlist->p_secondary_preparse->i_waiting = 0; p_playlist->p_fetcher->i_waiting = 0;
p_playlist->p_secondary_preparse->p_waiting = NULL; p_playlist->p_fetcher->p_waiting = NULL;
p_playlist->p_fetcher->i_art_policy = var_CreateGetInteger( p_playlist,
vlc_object_attach( p_playlist->p_secondary_preparse, p_playlist ); "album-art" );
if( vlc_thread_create( p_playlist->p_secondary_preparse,
"secondary preparser", vlc_object_attach( p_playlist->p_fetcher, p_playlist );
RunSecondaryPreparse, if( vlc_thread_create( p_playlist->p_fetcher,
"fetcher",
RunFetcher,
VLC_THREAD_PRIORITY_LOW, VLC_TRUE ) ) VLC_THREAD_PRIORITY_LOW, VLC_TRUE ) )
{ {
msg_Err( p_playlist, "cannot spawn secondary preparse thread" ); msg_Err( p_playlist, "cannot spawn secondary preparse thread" );
vlc_object_detach( p_playlist->p_secondary_preparse ); vlc_object_detach( p_playlist->p_fetcher );
vlc_object_destroy( p_playlist->p_secondary_preparse ); vlc_object_destroy( p_playlist->p_fetcher );
return; return;
} }
...@@ -146,10 +148,10 @@ int playlist_ThreadDestroy( playlist_t * p_playlist ) ...@@ -146,10 +148,10 @@ int playlist_ThreadDestroy( playlist_t * p_playlist )
vlc_cond_signal( &p_playlist->p_preparse->object_wait ); vlc_cond_signal( &p_playlist->p_preparse->object_wait );
free( p_playlist->p_preparse->pp_waiting ); 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 ); vlc_cond_signal( &p_playlist->p_fetcher->object_wait );
free( p_playlist->p_secondary_preparse->p_waiting ); free( p_playlist->p_fetcher->p_waiting );
} }
DestroyInteraction( p_playlist ); DestroyInteraction( p_playlist );
...@@ -221,11 +223,11 @@ static void RunPreparse ( playlist_preparse_t *p_obj ) ...@@ -221,11 +223,11 @@ static void RunPreparse ( playlist_preparse_t *p_obj )
playlist_PreparseLoop( 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 */ /* Tell above that we're ready */
vlc_thread_ready( p_obj ); vlc_thread_ready( p_obj );
playlist_SecondaryPreparseLoop( p_obj ); playlist_FetcherLoop( p_obj );
} }
/***************************************************************************** /*****************************************************************************
......
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