[vlc-commits] medialibrary: metadata: use input_item_Parse

Thomas Guillem git at videolan.org
Mon Jun 3 16:16:19 CEST 2019


vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Fri May 31 15:35:34 2019 +0200| [d147920356c39cac773bc3dec003dafec9d822a2] | committer: Thomas Guillem

medialibrary: metadata: use input_item_Parse

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

 modules/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..7348ab3be3 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 status )
 {
-    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 = status == 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 status, void *data )
+{
+    auto* ctx = static_cast<ParseContext*>( data );
+    ctx->mde->onParserEnded( *ctx, status );
+}
+
+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_id_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..ce3462874d 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_id_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_id_t, decltype(&input_item_parser_id_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 status );
     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 status, void *user_data );
+    static void onParserSubtreeAdded( input_item_t *, input_item_node_t *subtree,
+                                      void *user_data );
 
 private:
     vlc_object_t* m_obj;



More information about the vlc-commits mailing list