Commit 5e6e0a66 authored by Filip Roséen's avatar Filip Roséen Committed by Hugo Beauzée-Luyssen
Browse files

preparser: post-pone event until after art fetching is complete

Since one can request art to be fetched through
libvlc_media_parse_with_options, one would expect the event
originating from this request to be sent upon the completion of all
requested operations (not just the preparsing). The alternative would
be to monitor the libvlc_MediaMetaChanged, hoping for an artwork URL
change, but this can't account for error nor timeout.

--

The changes introduced were written after a discussion with Hugo
Beauzée-Luyssen where he expressed that he would, if possible, be able to
post-pone the preparsing events until the art fetching is complete.

Post-poning the event fixes issues that are currently reproducible where
medialibrary is used, and art is missing (because it listens to the preparse
event in order to generate the database contents).

It can be viewed as a follow-up to the below rejected patch (with the
same goal in mind):

 - https://patches.videolan.org/patch/15810/

Signed-off-by: Hugo Beauzée-Luyssen's avatarHugo Beauzée-Luyssen <hugo@beauzee.fr>
parent befb82c2
......@@ -53,6 +53,7 @@ struct playlist_fetcher_t {
struct fetcher_request {
input_item_t* item;
atomic_uint refs;
int preparse_status;
int options;
};
......@@ -206,13 +207,22 @@ static int SearchByScope( playlist_fetcher_t* fetcher,
! SearchArt( fetcher, item, scope ) )
{
AddAlbumCache( fetcher, req->item, false );
background_worker_Push( fetcher->downloader, req, NULL, 0 );
return VLC_SUCCESS;
if( !background_worker_Push( fetcher->downloader, req, NULL, 0 ) )
return VLC_SUCCESS;
}
return VLC_EGENERIC;
}
static void SetPreparsed( struct fetcher_request* req )
{
if( req->preparse_status != -1 )
{
input_item_SetPreparsed( req->item, true );
input_item_SignalPreparseEnded( req->item, req->preparse_status );
}
}
static void Downloader( playlist_fetcher_t* fetcher,
struct fetcher_request* req )
{
......@@ -271,6 +281,7 @@ out:
}
free( psz_arturl );
SetPreparsed( req );
return;
error:
......@@ -286,15 +297,23 @@ static void SearchLocal( playlist_fetcher_t* fetcher, struct fetcher_request* re
if( var_InheritBool( fetcher->owner, "metadata-network-access" ) ||
req->options & META_REQUEST_OPTION_SCOPE_NETWORK )
{
background_worker_Push( fetcher->network, req, NULL, 0 );
if( background_worker_Push( fetcher->network, req, NULL, 0 ) )
SetPreparsed( req );
}
else
{
input_item_SetArtNotFound( req->item, true );
SetPreparsed( req );
}
else input_item_SetArtNotFound( req->item, true );
}
static void SearchNetwork( playlist_fetcher_t* fetcher, struct fetcher_request* req )
{
if( SearchByScope( fetcher, req, FETCHER_SCOPE_NETWORK ) )
{
input_item_SetArtNotFound( req->item, true );
SetPreparsed( req );
}
}
static void RequestRelease( void* req_ )
......@@ -428,22 +447,26 @@ playlist_fetcher_t* playlist_fetcher_New( vlc_object_t* owner )
return fetcher;
}
void playlist_fetcher_Push( playlist_fetcher_t* fetcher, input_item_t* item,
input_item_meta_request_option_t options )
int playlist_fetcher_Push( playlist_fetcher_t* fetcher, input_item_t* item,
input_item_meta_request_option_t options, int preparse_status )
{
struct fetcher_request* req = malloc( sizeof *req );
if( unlikely( !req ) )
return;
return VLC_ENOMEM;
req->item = item;
req->options = options;
req->preparse_status = preparse_status;
atomic_init( &req->refs, 1 );
input_item_Hold( item );
background_worker_Push( fetcher->local, req, NULL, 0 );
if( background_worker_Push( fetcher->local, req, NULL, 0 ) )
SetPreparsed( req );
RequestRelease( req );
return VLC_SUCCESS;
}
void playlist_fetcher_Delete( playlist_fetcher_t* fetcher )
......
......@@ -46,8 +46,8 @@ playlist_fetcher_t *playlist_fetcher_New( vlc_object_t * );
* The input item is retained until the art fetching is done or until the
* fetcher object is destroyed.
*/
void playlist_fetcher_Push( playlist_fetcher_t *, input_item_t *,
input_item_meta_request_option_t );
int playlist_fetcher_Push( playlist_fetcher_t *, input_item_t *,
input_item_meta_request_option_t, int );
/**
* This function destroys the fetcher object and thread.
......
......@@ -95,7 +95,10 @@ static void PreparserCloseInput( void* preparser_, void* input_ )
input_Close( input );
if( preparser->fetcher )
playlist_fetcher_Push( preparser->fetcher, item, 0 );
{
if( !playlist_fetcher_Push( preparser->fetcher, item, 0, status ) )
return;
}
input_item_SetPreparsed( item, true );
input_item_SignalPreparseEnded( item, status );
......@@ -169,7 +172,7 @@ void playlist_preparser_fetcher_Push( playlist_preparser_t *preparser,
input_item_t *item, input_item_meta_request_option_t options )
{
if( preparser->fetcher )
playlist_fetcher_Push( preparser->fetcher, item, options );
playlist_fetcher_Push( preparser->fetcher, item, options, -1 );
}
void playlist_preparser_Cancel( playlist_preparser_t *preparser, void *id )
......
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