Commit 5fe63eb3 authored by Romain Vimont's avatar Romain Vimont
Browse files

preparser: use fetcher callbacks

After a preparsing, the preparser may request to fetch art, and trigger
the "preparse end" event only after the art have been fetched.

For that purpose, the fetcher and the preparser were highly coupled: the
fetcher was aware of a "preparse status", and was responsible to notify
"preparse ended" on the input item when necessary.

In order to make the fetcher more independant of the preparser, make the
preparser trigger the "preparse ended" event when it is notified of the
"fetch ended" event.

This also paves the way to remove preparsing events on the input item
directly.
parent 7725b102
......@@ -53,7 +53,6 @@ struct input_fetcher_t {
struct fetcher_request {
input_item_t* item;
vlc_atomic_rc_t rc;
int preparse_status;
int options;
const input_fetcher_callbacks_t *cbs;
void *userdata;
......@@ -218,13 +217,6 @@ static int SearchByScope( input_fetcher_t* fetcher,
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);
}
......@@ -455,7 +447,7 @@ 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,
const input_fetcher_callbacks_t *cbs, void *cbs_userdata )
{
struct fetcher_request* req = malloc( sizeof *req );
......@@ -465,7 +457,6 @@ 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;
......
......@@ -47,7 +47,7 @@ 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,
const input_fetcher_callbacks_t *, void * );
/**
......
......@@ -52,6 +52,7 @@ typedef struct input_preparser_task_t
{
input_preparser_req_t *req;
input_preparser_t* preparser;
int preparse_status;
input_thread_t* input;
atomic_int state;
atomic_bool done;
......@@ -135,6 +136,7 @@ static int PreparserOpenInput( void* preparser_, void* req_, void** out )
goto error;
task->req = req;
task->preparse_status = -1;
if( input_Start( task->input ) )
{
......@@ -162,6 +164,28 @@ static int PreparserProbeInput( void* preparser_, void* task_ )
VLC_UNUSED( preparser_ );
}
static void on_art_fetch_ended(input_item_t *item, bool fetched, void *userdata)
{
VLC_UNUSED(item);
VLC_UNUSED(fetched);
input_preparser_task_t *task = userdata;
input_preparser_req_t *req = task->req;
input_item_SetPreparsed(req->item, true);
/* TODO remove legacy input_item_SignalPreparseEnded() */
input_item_SignalPreparseEnded(req->item, task->preparse_status);
if (req->cbs && req->cbs->on_preparse_ended)
req->cbs->on_preparse_ended(req->item, task->preparse_status, req->userdata);
ReqRelease(req);
free(task);
}
static const input_fetcher_callbacks_t input_fetcher_callbacks = {
.on_art_fetch_ended = on_art_fetch_ended,
};
static void PreparserCloseInput( void* preparser_, void* task_ )
{
input_preparser_task_t* task = task_;
......@@ -187,15 +211,19 @@ static void PreparserCloseInput( void* preparser_, void* task_ )
input_Stop( input );
input_Close( input );
free( task );
if( preparser->fetcher )
{
if( !input_fetcher_Push( preparser->fetcher, item, 0, status,
NULL, NULL ) )
task->preparse_status = status;
if (!input_fetcher_Push(preparser->fetcher, item, 0,
&input_fetcher_callbacks, task))
{
ReqHold(task->req);
return;
}
}
free(task);
input_item_SetPreparsed( item, true );
/* TODO remove legacy input_item_SignalPreparseEnded() */
input_item_SignalPreparseEnded( item, status );
......@@ -288,7 +316,7 @@ void input_preparser_fetcher_Push( input_preparser_t *preparser,
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,
cbs, cbs_userdata );
}
......
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