[vlc-commits] preparser: use fetcher callbacks

Romain Vimont git at videolan.org
Mon Aug 20 13:59:13 CEST 2018


vlc | branch: master | Romain Vimont <rom1v at videolabs.io> | Tue Aug 14 16:01:58 2018 +0200| [5fe63eb3855dde00d0267d0034cedcd170ef2929] | committer: Romain Vimont

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.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=5fe63eb3855dde00d0267d0034cedcd170ef2929
---

 src/preparser/fetcher.c   | 11 +----------
 src/preparser/fetcher.h   |  2 +-
 src/preparser/preparser.c | 38 +++++++++++++++++++++++++++++++++-----
 3 files changed, 35 insertions(+), 16 deletions(-)

diff --git a/src/preparser/fetcher.c b/src/preparser/fetcher.c
index 973c850186..be38b07768 100644
--- a/src/preparser/fetcher.c
+++ b/src/preparser/fetcher.c
@@ -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;
 
diff --git a/src/preparser/fetcher.h b/src/preparser/fetcher.h
index 73b40e18c4..2aebf6ac40 100644
--- a/src/preparser/fetcher.h
+++ b/src/preparser/fetcher.h
@@ -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 * );
 
 /**
diff --git a/src/preparser/preparser.c b/src/preparser/preparser.c
index a91fa3e6e9..37f954a99f 100644
--- a/src/preparser/preparser.c
+++ b/src/preparser/preparser.c
@@ -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 );
 }
 



More information about the vlc-commits mailing list