Commit 7725b102 authored by Romain Vimont's avatar Romain Vimont
Browse files

fetcher: provide events in callbacks

Notify "fetch ended" in callbacks.

This will allow to move the "preparse ended" trigger from the fetcher to
the preparser, and make the fetcher more independant.
parent 81257945
......@@ -394,13 +394,19 @@ typedef struct input_preparser_callbacks_t {
void (*on_subtree_added)(input_item_t *, input_item_node_t *subtree, void *userdata);
} input_preparser_callbacks_t;
typedef struct input_fetcher_callbacks_t {
void (*on_art_fetch_ended)(input_item_t *, bool fetched, void *userdata);
} input_fetcher_callbacks_t;
VLC_API int libvlc_MetadataRequest( libvlc_int_t *, input_item_t *,
input_item_meta_request_option_t,
const input_preparser_callbacks_t *cbs,
void *cbs_userdata,
int, void * );
VLC_API int libvlc_ArtRequest(libvlc_int_t *, input_item_t *,
input_item_meta_request_option_t );
input_item_meta_request_option_t,
const input_fetcher_callbacks_t *cbs,
void *cbs_userdata );
VLC_API void libvlc_MetadataCancel( libvlc_int_t *, void * );
/******************
......
......@@ -802,7 +802,8 @@ static int media_parse(libvlc_media_t *media, bool b_async,
if (parse_flag & libvlc_media_fetch_network)
{
ret = libvlc_ArtRequest(libvlc, item,
META_REQUEST_OPTION_SCOPE_NETWORK);
META_REQUEST_OPTION_SCOPE_NETWORK,
NULL, NULL);
if (ret != VLC_SUCCESS)
return ret;
}
......
......@@ -367,7 +367,8 @@ FREENULL( psz_##foo );
- (IBAction)downloadCoverArt:(id)sender
{
if (p_item)
libvlc_ArtRequest(getIntf()->obj.libvlc, p_item, META_REQUEST_OPTION_NONE);
libvlc_ArtRequest(getIntf()->obj.libvlc, p_item, META_REQUEST_OPTION_NONE,
NULL, NULL);
}
@end
......
......@@ -692,7 +692,8 @@ void InputManager::requestArtUpdate( input_item_t *p_item, bool b_forced )
}
libvlc_ArtRequest( p_intf->obj.libvlc, p_item,
(b_forced) ? META_REQUEST_OPTION_SCOPE_ANY
: META_REQUEST_OPTION_NONE );
: META_REQUEST_OPTION_NONE,
NULL, NULL );
/* No input will signal the cover art to update,
* let's do it ourself */
if ( b_current_item )
......
......@@ -521,14 +521,16 @@ int libvlc_MetadataRequest(libvlc_int_t *libvlc, input_item_t *item,
* The retrieval is performed asynchronously.
*/
int libvlc_ArtRequest(libvlc_int_t *libvlc, input_item_t *item,
input_item_meta_request_option_t i_options)
input_item_meta_request_option_t i_options,
const input_fetcher_callbacks_t *cbs,
void *cbs_userdata)
{
libvlc_priv_t *priv = libvlc_priv(libvlc);
if (unlikely(priv->parser == NULL))
return VLC_ENOMEM;
input_preparser_fetcher_Push(priv->parser, item, i_options);
input_preparser_fetcher_Push(priv->parser, item, i_options, cbs, cbs_userdata);
return VLC_SUCCESS;
}
......
......@@ -244,7 +244,7 @@ static bool PlayItem( playlist_t *p_playlist, playlist_item_t *p_item )
if( !b_has_art || strncmp( psz_arturl, "attachment://", 13 ) )
{
PL_DEBUG( "requesting art for new input thread" );
libvlc_ArtRequest( p_playlist->obj.libvlc, p_input, META_REQUEST_OPTION_NONE );
libvlc_ArtRequest( p_playlist->obj.libvlc, p_input, META_REQUEST_OPTION_NONE, NULL, NULL );
}
free( psz_arturl );
......
......@@ -55,6 +55,8 @@ struct fetcher_request {
vlc_atomic_rc_t rc;
int preparse_status;
int options;
const input_fetcher_callbacks_t *cbs;
void *userdata;
};
struct fetcher_thread {
......@@ -214,13 +216,17 @@ static int SearchByScope( input_fetcher_t* fetcher,
return VLC_EGENERIC;
}
static void SetPreparsed( struct fetcher_request* req )
static void NotifyArtFetchEnded( struct fetcher_request* req, bool fetched )
{
if( req->preparse_status != -1 )
{
input_item_SetPreparsed( req->item, true );
/* TODO remove legacy input_item_SignalPreparseEnded() */
input_item_SignalPreparseEnded( req->item, req->preparse_status );
}
if (req->cbs && req->cbs->on_art_fetch_ended)
req->cbs->on_art_fetch_ended(req->item, fetched, req->userdata);
}
static void Downloader( input_fetcher_t* fetcher,
......@@ -281,7 +287,7 @@ out:
}
free( psz_arturl );
SetPreparsed( req );
NotifyArtFetchEnded(req, psz_arturl != NULL);
return;
error:
......@@ -298,12 +304,12 @@ static void SearchLocal( input_fetcher_t* fetcher, struct fetcher_request* req )
req->options & META_REQUEST_OPTION_SCOPE_NETWORK )
{
if( background_worker_Push( fetcher->network, req, NULL, 0 ) )
SetPreparsed( req );
NotifyArtFetchEnded(req, false);
}
else
{
input_item_SetArtNotFound( req->item, true );
SetPreparsed( req );
NotifyArtFetchEnded(req, false);
}
}
......@@ -312,7 +318,7 @@ static void SearchNetwork( input_fetcher_t* fetcher, struct fetcher_request* req
if( SearchByScope( fetcher, req, FETCHER_SCOPE_NETWORK ) )
{
input_item_SetArtNotFound( req->item, true );
SetPreparsed( req );
NotifyArtFetchEnded(req, false);
}
}
......@@ -449,7 +455,8 @@ input_fetcher_t* input_fetcher_New( vlc_object_t* owner )
}
int input_fetcher_Push( input_fetcher_t* fetcher, input_item_t* item,
input_item_meta_request_option_t options, int preparse_status )
input_item_meta_request_option_t options, int preparse_status,
const input_fetcher_callbacks_t *cbs, void *cbs_userdata )
{
struct fetcher_request* req = malloc( sizeof *req );
......@@ -459,12 +466,14 @@ int input_fetcher_Push( input_fetcher_t* fetcher, input_item_t* item,
req->item = item;
req->options = options;
req->preparse_status = preparse_status;
req->cbs = cbs;
req->userdata = cbs_userdata;
vlc_atomic_rc_init( &req->rc );
input_item_Hold( item );
if( background_worker_Push( fetcher->local, req, NULL, 0 ) )
SetPreparsed( req );
NotifyArtFetchEnded(req, false);
RequestRelease( req );
return VLC_SUCCESS;
......
......@@ -47,7 +47,8 @@ input_fetcher_t *input_fetcher_New( vlc_object_t * );
* fetcher object is destroyed.
*/
int input_fetcher_Push( input_fetcher_t *, input_item_t *,
input_item_meta_request_option_t, int );
input_item_meta_request_option_t, int,
const input_fetcher_callbacks_t *, void * );
/**
* This function destroys the fetcher object and thread.
......
......@@ -191,7 +191,8 @@ static void PreparserCloseInput( void* preparser_, void* task_ )
if( preparser->fetcher )
{
if( !input_fetcher_Push( preparser->fetcher, item, 0, status ) )
if( !input_fetcher_Push( preparser->fetcher, item, 0, status,
NULL, NULL ) )
return;
}
......@@ -283,10 +284,12 @@ void input_preparser_Push( input_preparser_t *preparser,
}
void input_preparser_fetcher_Push( input_preparser_t *preparser,
input_item_t *item, input_item_meta_request_option_t options )
input_item_t *item, input_item_meta_request_option_t options,
const input_fetcher_callbacks_t *cbs, void *cbs_userdata )
{
if( preparser->fetcher )
input_fetcher_Push( preparser->fetcher, item, options, -1 );
input_fetcher_Push( preparser->fetcher, item, options, -1,
cbs, cbs_userdata );
}
void input_preparser_Cancel( input_preparser_t *preparser, void *id )
......
......@@ -59,7 +59,9 @@ void input_preparser_Push( input_preparser_t *, input_item_t *,
int timeout, void *id );
void input_preparser_fetcher_Push( input_preparser_t *, input_item_t *,
input_item_meta_request_option_t );
input_item_meta_request_option_t,
const input_fetcher_callbacks_t *cbs,
void *cbs_userdata );
/**
* This function cancel all preparsing requests for a given id
......
Supports Markdown
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