[vlc-commits] fetcher: provide events in callbacks
Romain Vimont
git at videolan.org
Mon Aug 20 13:59:12 CEST 2018
vlc | branch: master | Romain Vimont <rom1v at videolabs.io> | Tue Aug 14 15:38:55 2018 +0200| [7725b1025494b3355eb7810cd078d4f0161f7621] | committer: Romain Vimont
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.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=7725b1025494b3355eb7810cd078d4f0161f7621
---
include/vlc_input_item.h | 8 +++++++-
lib/media.c | 3 ++-
modules/gui/macosx/VLCPlaylistInfo.m | 3 ++-
modules/gui/qt/input_manager.cpp | 3 ++-
src/libvlc.c | 6 ++++--
src/playlist/thread.c | 2 +-
src/preparser/fetcher.c | 23 ++++++++++++++++-------
src/preparser/fetcher.h | 3 ++-
src/preparser/preparser.c | 9 ++++++---
src/preparser/preparser.h | 4 +++-
10 files changed, 45 insertions(+), 19 deletions(-)
diff --git a/include/vlc_input_item.h b/include/vlc_input_item.h
index cd22b3277d..57fc16193c 100644
--- a/include/vlc_input_item.h
+++ b/include/vlc_input_item.h
@@ -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 * );
/******************
diff --git a/lib/media.c b/lib/media.c
index 5ed5e2eaa1..81c39436cb 100644
--- a/lib/media.c
+++ b/lib/media.c
@@ -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;
}
diff --git a/modules/gui/macosx/VLCPlaylistInfo.m b/modules/gui/macosx/VLCPlaylistInfo.m
index fdd4cfbe05..4b52187285 100644
--- a/modules/gui/macosx/VLCPlaylistInfo.m
+++ b/modules/gui/macosx/VLCPlaylistInfo.m
@@ -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
diff --git a/modules/gui/qt/input_manager.cpp b/modules/gui/qt/input_manager.cpp
index 8f9c981866..9509adfa2c 100644
--- a/modules/gui/qt/input_manager.cpp
+++ b/modules/gui/qt/input_manager.cpp
@@ -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 )
diff --git a/src/libvlc.c b/src/libvlc.c
index 55604c1b79..f12f980936 100644
--- a/src/libvlc.c
+++ b/src/libvlc.c
@@ -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;
}
diff --git a/src/playlist/thread.c b/src/playlist/thread.c
index b072d72198..0823ed54a9 100644
--- a/src/playlist/thread.c
+++ b/src/playlist/thread.c
@@ -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 );
diff --git a/src/preparser/fetcher.c b/src/preparser/fetcher.c
index 6d095963af..973c850186 100644
--- a/src/preparser/fetcher.c
+++ b/src/preparser/fetcher.c
@@ -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;
diff --git a/src/preparser/fetcher.h b/src/preparser/fetcher.h
index 1dc6336ada..73b40e18c4 100644
--- a/src/preparser/fetcher.h
+++ b/src/preparser/fetcher.h
@@ -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.
diff --git a/src/preparser/preparser.c b/src/preparser/preparser.c
index 78e41f045a..a91fa3e6e9 100644
--- a/src/preparser/preparser.c
+++ b/src/preparser/preparser.c
@@ -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 )
diff --git a/src/preparser/preparser.h b/src/preparser/preparser.h
index 9fe4ae8e87..d37dab1b11 100644
--- a/src/preparser/preparser.h
+++ b/src/preparser/preparser.h
@@ -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
More information about the vlc-commits
mailing list