[vlc-devel] [PATCH 03/20] medialibrary: metadata: use input_item_Parse

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


---
 .../misc/medialibrary/MetadataExtractor.cpp   | 74 +++++++------------
 modules/misc/medialibrary/medialibrary.h      | 15 ++--
 2 files changed, 36 insertions(+), 53 deletions(-)

diff --git a/modules/misc/medialibrary/MetadataExtractor.cpp b/modules/misc/medialibrary/MetadataExtractor.cpp
index fc04ba870d..46920803fa 100644
--- a/modules/misc/medialibrary/MetadataExtractor.cpp
+++ b/modules/misc/medialibrary/MetadataExtractor.cpp
@@ -29,31 +29,14 @@ MetadataExtractor::MetadataExtractor( vlc_object_t* parent )
 {
 }
 
-void MetadataExtractor::onInputEvent( const vlc_input_event* ev,
-                                      ParseContext& ctx )
+void MetadataExtractor::onParserEnded( ParseContext& ctx, int ret )
 {
-    switch ( ev->type )
-    {
-        case INPUT_EVENT_SUBITEMS:
-            addSubtree( ctx, ev->subitems );
-            break;
-        case INPUT_EVENT_STATE:
-            {
-                vlc::threads::mutex_locker lock( ctx.m_mutex );
-                ctx.state = ev->state;
-            }
-            break;
-        case INPUT_EVENT_DEAD:
-            {
-                vlc::threads::mutex_locker lock( ctx.m_mutex );
-                // We need to probe the item now, but not from the input thread
-                ctx.needsProbing = true;
-            }
-            ctx.m_cond.signal();
-            break;
-        default:
-            break;
-    }
+    vlc::threads::mutex_locker lock( ctx.m_mutex );
+
+    // We need to probe the item now, but not from the input thread
+    ctx.success = ret == VLC_SUCCESS;
+    ctx.needsProbing = true;
+    ctx.m_cond.signal();
 }
 
 void MetadataExtractor::populateItem( medialibrary::parser::IItem& item, input_item_t* inputItem )
@@ -128,12 +111,18 @@ void MetadataExtractor::populateItem( medialibrary::parser::IItem& item, input_i
     }
 }
 
-void MetadataExtractor::onInputEvent( input_thread_t*,
-                                      const struct vlc_input_event *event,
-                                      void *data )
+void MetadataExtractor::onParserEnded( input_item_t *, int ret, void *data )
+{
+    auto* ctx = static_cast<ParseContext*>( data );
+    ctx->mde->onParserEnded( *ctx, ret );
+}
+
+void MetadataExtractor::onParserSubtreeAdded( input_item_t *,
+                                              input_item_node_t *subtree,
+                                              void *data )
 {
     auto* ctx = static_cast<ParseContext*>( data );
-    ctx->mde->onInputEvent( event, *ctx );
+    ctx->mde->addSubtree( *ctx, subtree );
 }
 
 void MetadataExtractor::addSubtree( ParseContext& ctx, input_item_node_t *root )
@@ -157,17 +146,20 @@ medialibrary::parser::Status MetadataExtractor::run( medialibrary::parser::IItem
     if ( ctx.inputItem == nullptr )
         return medialibrary::parser::Status::Fatal;
 
+    const input_item_parser_cbs_t cbs = {
+        &MetadataExtractor::onParserEnded,
+        &MetadataExtractor::onParserSubtreeAdded,
+    };
+
     ctx.inputItem->i_preparse_depth = 1;
-    ctx.input = {
-        input_CreatePreparser( m_obj, &MetadataExtractor::onInputEvent,
-                               std::addressof( ctx ), ctx.inputItem.get() ),
-        &input_Close
+    ctx.inputParser = {
+        input_item_Parse( ctx.inputItem.get(), m_obj, &cbs,
+                          std::addressof( ctx ) ),
+        &input_item_parser_Release
     };
-    if ( ctx.input == nullptr )
+    if ( ctx.inputParser == nullptr )
         return medialibrary::parser::Status::Fatal;
 
-    input_Start( ctx.input.get() );
-
     {
         vlc::threads::mutex_locker lock( ctx.m_mutex );
         auto deadline = vlc_tick_now() + VLC_TICK_FROM_SEC( 5 );
@@ -178,23 +170,13 @@ medialibrary::parser::Status MetadataExtractor::run( medialibrary::parser::IItem
             {
                 msg_Dbg( m_obj, "Timed out while extracting %s metadata",
                          item.mrl().c_str() );
-                ctx.state = ERROR_S;
-                input_Stop( ctx.input.get() );
                 break;
             }
-            if ( ctx.needsProbing == true )
-            {
-                if ( ctx.state == END_S || ctx.state == ERROR_S )
-                    break;
-                // Reset the probing flag for next event
-                ctx.needsProbing = false;
-            }
         }
     }
 
-    if ( ctx.state == ERROR_S )
+    if ( !ctx.success )
         return medialibrary::parser::Status::Fatal;
-    assert( ctx.state == END_S );
 
     populateItem( item, ctx.inputItem.get() );
 
diff --git a/modules/misc/medialibrary/medialibrary.h b/modules/misc/medialibrary/medialibrary.h
index f339ab77d8..04fa5c5b8d 100644
--- a/modules/misc/medialibrary/medialibrary.h
+++ b/modules/misc/medialibrary/medialibrary.h
@@ -50,24 +50,24 @@ private:
     {
         ParseContext( MetadataExtractor* mde, medialibrary::parser::IItem& item )
             : needsProbing( false )
-            , state( INIT_S )
+            , success( false )
             , mde( mde )
             , item( item )
             , inputItem( nullptr, &input_item_Release )
-            , input( nullptr, &input_Close )
+            , inputParser( nullptr, &input_item_parser_Release )
         {
         }
 
         vlc::threads::condition_variable m_cond;
         vlc::threads::mutex m_mutex;
         bool needsProbing;
-        input_state_e state;
+        bool success;
         MetadataExtractor* mde;
         medialibrary::parser::IItem& item;
         std::unique_ptr<input_item_t, decltype(&input_item_Release)> inputItem;
         // Needs to be last to be destroyed first, otherwise a late callback
         // could use some already destroyed fields
-        std::unique_ptr<input_thread_t, decltype(&input_Close)> input;
+        std::unique_ptr<input_item_parser_t, decltype(&input_item_parser_Release)> inputParser;
     };
 
 public:
@@ -85,12 +85,13 @@ private:
     virtual void onFlushing() override;
     virtual void onRestarted() override;
 
-    void onInputEvent( const vlc_input_event* event, ParseContext& ctx );
+    void onParserEnded( ParseContext& ctx, int ret );
     void addSubtree( ParseContext& ctx, input_item_node_t *root );
     void populateItem( medialibrary::parser::IItem& item, input_item_t* inputItem );
 
-    static void onInputEvent( input_thread_t *input,
-                              const struct vlc_input_event *event, void *user_data );
+    static void onParserEnded( input_item_t *, int ret, void *user_data );
+    static void onParserSubtreeAdded( input_item_t *, input_item_node_t *subtree,
+                                      void *user_data );
 
 private:
     vlc_object_t* m_obj;
-- 
2.20.1



More information about the vlc-devel mailing list