[vlc-devel] [PATCH 04/20] preparser: use input_item_Parse

Thomas Guillem thomas at gllm.fr
Fri May 31 15:59:30 CEST 2019


---
 src/preparser/preparser.c | 72 +++++++++++++++++----------------------
 1 file changed, 32 insertions(+), 40 deletions(-)

diff --git a/src/preparser/preparser.c b/src/preparser/preparser.c
index 9c35bc12bd..c01b2a06f1 100644
--- a/src/preparser/preparser.c
+++ b/src/preparser/preparser.c
@@ -52,7 +52,7 @@ typedef struct input_preparser_task_t
     input_preparser_req_t *req;
     input_preparser_t* preparser;
     int preparse_status;
-    input_thread_t* input;
+    input_item_parser_t *parser;
     atomic_int state;
     atomic_bool done;
 } input_preparser_task_t;
@@ -89,31 +89,25 @@ static void ReqRelease(input_preparser_req_t *req)
     }
 }
 
-static void InputEvent( input_thread_t *input,
-                        const struct vlc_input_event *event, void *task_ )
+static void OnParserEnded(input_item_t *item, int ret, void *task_)
 {
-    VLC_UNUSED( input );
+    VLC_UNUSED(item);
     input_preparser_task_t* task = task_;
 
-    switch( event->type )
-    {
-        case INPUT_EVENT_STATE:
-            atomic_store( &task->state, event->state );
-            break;
+    atomic_store( &task->state, ret );
+    atomic_store( &task->done, true );
+    background_worker_RequestProbe( task->preparser->worker );
+}
 
-        case INPUT_EVENT_DEAD:
-            atomic_store( &task->done, true );
-            background_worker_RequestProbe( task->preparser->worker );
-            break;
-        case INPUT_EVENT_SUBITEMS:
-        {
-            input_preparser_req_t *req = task->req;
-            if (req->cbs && req->cbs->on_subtree_added)
-                req->cbs->on_subtree_added(req->item, event->subitems, req->userdata);
-            break;
-        }
-        default: ;
-    }
+static void OnParserSubtreeAdded(input_item_t *item, input_item_node_t *subtree,
+                                 void *task_)
+{
+    VLC_UNUSED(item);
+    input_preparser_task_t* task = task_;
+    input_preparser_req_t *req = task->req;
+
+    if (req->cbs && req->cbs->on_subtree_added)
+        req->cbs->on_subtree_added(req->item, subtree, req->userdata);
 }
 
 static int PreparserOpenInput( void* preparser_, void* req_, void** out )
@@ -125,24 +119,23 @@ static int PreparserOpenInput( void* preparser_, void* req_, void** out )
     if( unlikely( !task ) )
         goto error;
 
-    atomic_init( &task->state, INIT_S );
+    static const input_item_parser_cbs_t cbs = {
+        .on_ended = OnParserEnded,
+        .on_subtree_added = OnParserSubtreeAdded,
+    };
+
+    atomic_init( &task->state, VLC_ETIMEOUT );
     atomic_init( &task->done, false );
 
     task->preparser = preparser_;
-    task->input = input_CreatePreparser( preparser->owner, InputEvent,
-                                         task, req->item );
-    if( !task->input )
+    task->parser = input_item_Parse( req->item, preparser->owner, &cbs,
+                                     task );
+    if( !task->parser )
         goto error;
 
     task->req = req;
     task->preparse_status = -1;
 
-    if( input_Start( task->input ) )
-    {
-        input_Close( task->input );
-        goto error;
-    }
-
     *out = task;
 
     return VLC_SUCCESS;
@@ -187,24 +180,23 @@ static void PreparserCloseInput( void* preparser_, void* task_ )
     input_preparser_req_t *req = task->req;
 
     input_preparser_t* preparser = preparser_;
-    input_thread_t* input = task->input;
-    input_item_t* item = input_priv(task->input)->p_item;
+    input_item_t* item = req->item;
 
     int status;
     switch( atomic_load( &task->state ) )
     {
-        case END_S:
+        case VLC_SUCCESS:
             status = ITEM_PREPARSE_DONE;
             break;
-        case ERROR_S:
-            status = ITEM_PREPARSE_FAILED;
+        case VLC_ETIMEOUT:
+            status = ITEM_PREPARSE_TIMEOUT;
             break;
         default:
-            status = ITEM_PREPARSE_TIMEOUT;
+            status = ITEM_PREPARSE_FAILED;
+            break;
     }
 
-    input_Stop( input );
-    input_Close( input );
+    input_item_parser_Release( task->parser );
 
     if( preparser->fetcher )
     {
-- 
2.20.1



More information about the vlc-devel mailing list