Commit b063dca4 authored by Thomas Guillem's avatar Thomas Guillem
Browse files

prepaser: change options handling

Reminder of the current behavior: the meta fetcher is either always triggered
after the preparser is finished or manually.

This commit aims to give more controls so that the meta fetcher is not
necessarily triggered after a preparsng.

The current behavior of macOS/playlist/mediatree is unchanged (the components
touching the preparser).

Here are the API changes for

libvlc_MetadataRequest():

 - Can't be called without a valid META_REQUEST_OPTION_SCOPE_* flag

 - The flag META_REQUEST_OPTION_SCOPE_* is not fetching meta anymore. Use
   (META_REQUEST_OPTION_SCOPE_*|META_REQUEST_OPTION_FETCH_*) to fetch meta when
   the preparsing ends.

libvlc_ArtRequest():

 - Can't be called without a valid META_REQUEST_OPTION_FETCH_* flag.

 - The META_REQUEST_OPTION_FETCH_NETWORK flag will now only fetch meta via
   network.

libvlc_media_parse_with_options():

 - The flag libvlc_media_parse_* is not fetching meta anymore. Use
   libvlc_media_fetch_* to fetch meta when the preparsing ends.
 - The libvlc_media_fetch_network flag will now only fetch meta via network.
parent f6b2e629
......@@ -462,7 +462,10 @@ typedef enum input_item_meta_request_option_t
META_REQUEST_OPTION_SCOPE_LOCAL = 0x01,
META_REQUEST_OPTION_SCOPE_NETWORK = 0x02,
META_REQUEST_OPTION_SCOPE_ANY = 0x03,
META_REQUEST_OPTION_DO_INTERACT = 0x04
META_REQUEST_OPTION_FETCH_LOCAL = 0x04,
META_REQUEST_OPTION_FETCH_NETWORK = 0x08,
META_REQUEST_OPTION_FETCH_ANY = 0x0C,
META_REQUEST_OPTION_DO_INTERACT = 0x10,
} input_item_meta_request_option_t;
/* status of the on_preparse_ended() callback */
......
......@@ -806,9 +806,14 @@ static int media_parse(libvlc_media_t *media, bool b_async,
if (parse_flag & libvlc_media_parse_network)
parse_scope |= META_REQUEST_OPTION_SCOPE_NETWORK;
if (parse_flag & libvlc_media_fetch_local)
parse_scope |= META_REQUEST_OPTION_FETCH_LOCAL;
if (parse_flag & libvlc_media_do_interact)
parse_scope |= META_REQUEST_OPTION_DO_INTERACT;
ret = libvlc_MetadataRequest(libvlc, item, parse_scope, &input_preparser_callbacks, media, timeout, media);
ret = libvlc_MetadataRequest(libvlc, item, parse_scope,
&input_preparser_callbacks, media,
timeout, media);
if (ret != VLC_SUCCESS)
return ret;
}
......
......@@ -542,7 +542,8 @@ static const struct input_preparser_callbacks_t preparseCallbacks = {
return libvlc_MetadataRequest(vlc_object_instance(getIntf()),
_vlcInputItem,
META_REQUEST_OPTION_SCOPE_ANY,
META_REQUEST_OPTION_SCOPE_ANY |
META_REQUEST_OPTION_FETCH_LOCAL,
&preparseCallbacks,
(__bridge void *)self,
-1, NULL);
......
......@@ -1436,8 +1436,8 @@ void PlayerController::requestArtUpdate( input_item_t *p_item, bool b_forced )
return;
}
libvlc_ArtRequest( vlc_object_instance(d->p_intf), p_item,
(b_forced) ? META_REQUEST_OPTION_SCOPE_ANY
: META_REQUEST_OPTION_NONE,
(b_forced) ? META_REQUEST_OPTION_FETCH_ANY
: META_REQUEST_OPTION_FETCH_LOCAL,
&input_fetcher_cbs, this );
}
}
......
......@@ -537,6 +537,7 @@ int libvlc_MetadataRequest(libvlc_int_t *libvlc, input_item_t *item,
int timeout, void *id)
{
libvlc_priv_t *priv = libvlc_priv(libvlc);
assert(i_options & META_REQUEST_OPTION_SCOPE_ANY);
if (unlikely(priv->parser == NULL))
return VLC_ENOMEM;
......@@ -559,11 +560,13 @@ int libvlc_ArtRequest(libvlc_int_t *libvlc, input_item_t *item,
void *cbs_userdata)
{
libvlc_priv_t *priv = libvlc_priv(libvlc);
assert(i_options & META_REQUEST_OPTION_FETCH_ANY);
if (unlikely(priv->parser == NULL))
return VLC_ENOMEM;
input_preparser_fetcher_Push(priv->parser, item, i_options, cbs, cbs_userdata);
input_preparser_fetcher_Push(priv->parser, item, i_options,
cbs, cbs_userdata);
return VLC_SUCCESS;
}
......
......@@ -329,8 +329,7 @@ vlc_media_tree_Preparse(vlc_media_tree_t *tree, libvlc_int_t *libvlc,
VLC_UNUSED(input_preparser_callbacks);
#else
media->i_preparse_depth = 1;
vlc_MetadataRequest(libvlc, media, META_REQUEST_OPTION_SCOPE_LOCAL |
META_REQUEST_OPTION_SCOPE_NETWORK,
vlc_MetadataRequest(libvlc, media, META_REQUEST_OPTION_SCOPE_ANY,
&input_preparser_callbacks, tree, -1, NULL);
#endif
}
......@@ -120,7 +120,9 @@ vlc_playlist_Preparse(vlc_playlist_t *playlist, input_item_t *input)
VLC_UNUSED(input_preparser_callbacks);
#else
/* vlc_MetadataRequest is not exported */
vlc_MetadataRequest(playlist->libvlc, input, META_REQUEST_OPTION_NONE,
vlc_MetadataRequest(playlist->libvlc, input,
META_REQUEST_OPTION_SCOPE_LOCAL |
META_REQUEST_OPTION_FETCH_LOCAL,
&input_preparser_callbacks, playlist, -1, NULL);
#endif
}
......
......@@ -294,7 +294,7 @@ static void SearchLocal( input_fetcher_t* fetcher, struct fetcher_request* req )
return; /* done */
if( var_InheritBool( fetcher->owner, "metadata-network-access" ) ||
req->options & META_REQUEST_OPTION_SCOPE_NETWORK )
req->options & META_REQUEST_OPTION_FETCH_NETWORK )
{
if( background_worker_Push( fetcher->network, req, NULL, 0 ) )
NotifyArtFetchEnded(req, false);
......@@ -451,6 +451,7 @@ int input_fetcher_Push( input_fetcher_t* fetcher, input_item_t* item,
input_item_meta_request_option_t options,
const input_fetcher_callbacks_t *cbs, void *cbs_userdata )
{
assert(options & META_REQUEST_OPTION_FETCH_ANY);
struct fetcher_request* req = malloc( sizeof *req );
if( unlikely( !req ) )
......@@ -464,7 +465,9 @@ int input_fetcher_Push( input_fetcher_t* fetcher, input_item_t* item,
vlc_atomic_rc_init( &req->rc );
input_item_Hold( item );
if( background_worker_Push( fetcher->local, req, NULL, 0 ) )
struct background_worker* worker =
options & META_REQUEST_OPTION_FETCH_LOCAL ? fetcher->local : fetcher->network;
if( background_worker_Push( worker, req, NULL, 0 ) )
NotifyArtFetchEnded(req, false);
RequestRelease( req );
......
......@@ -42,6 +42,7 @@ struct input_preparser_t
typedef struct input_preparser_req_t
{
input_item_t *item;
input_item_meta_request_option_t options;
const input_preparser_callbacks_t *cbs;
void *userdata;
vlc_atomic_rc_t rc;
......@@ -58,6 +59,7 @@ typedef struct input_preparser_task_t
} input_preparser_task_t;
static input_preparser_req_t *ReqCreate(input_item_t *item,
input_item_meta_request_option_t options,
const input_preparser_callbacks_t *cbs,
void *userdata)
{
......@@ -66,6 +68,7 @@ static input_preparser_req_t *ReqCreate(input_item_t *item,
return NULL;
req->item = item;
req->options = options;
req->cbs = cbs;
req->userdata = userdata;
vlc_atomic_rc_init(&req->rc);
......@@ -197,11 +200,12 @@ static void PreparserCloseInput( void* preparser_, void* task_ )
input_item_parser_id_Release( task->parser );
if( preparser->fetcher )
if( preparser->fetcher && (req->options & META_REQUEST_OPTION_FETCH_ANY) )
{
task->preparse_status = status;
if (!input_fetcher_Push(preparser->fetcher, item, 0,
&input_fetcher_callbacks, task))
if (!input_fetcher_Push(preparser->fetcher, item,
req->options & META_REQUEST_OPTION_FETCH_ANY,
&input_fetcher_callbacks, task))
{
ReqHold(task->req);
return;
......@@ -280,7 +284,8 @@ void input_preparser_Push( input_preparser_t *preparser,
return;
}
struct input_preparser_req_t *req = ReqCreate(item, cbs, cbs_userdata);
struct input_preparser_req_t *req = ReqCreate(item, i_options,
cbs, cbs_userdata);
if (background_worker_Push(preparser->worker, req, id, timeout))
if (req->cbs && cbs->on_preparse_ended)
......
......@@ -159,7 +159,8 @@ static void test_input_metadata_timeout(libvlc_instance_t *vlc, int timeout,
.on_preparse_ended = input_item_preparse_timeout,
};
i_ret = libvlc_MetadataRequest(vlc->p_libvlc_int, p_item,
META_REQUEST_OPTION_SCOPE_LOCAL,
META_REQUEST_OPTION_SCOPE_LOCAL |
META_REQUEST_OPTION_FETCH_LOCAL,
&cbs, &sem, timeout, vlc);
assert(i_ret == 0);
......
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