[vlc-commits] medialibrary: metadata extractor: Handle timeouts

Hugo Beauzée-Luyssen git at videolan.org
Wed Jan 23 10:01:38 CET 2019


vlc | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Fri Nov 30 15:28:44 2018 +0100| [1d661618ebd355d00de8b9fb9e728407a9823a74] | committer: Hugo Beauzée-Luyssen

medialibrary: metadata extractor: Handle timeouts

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

 modules/misc/medialibrary/MetadataExtractor.cpp | 11 ++++++++++-
 modules/misc/medialibrary/medialibrary.h        | 12 +++++++-----
 2 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/modules/misc/medialibrary/MetadataExtractor.cpp b/modules/misc/medialibrary/MetadataExtractor.cpp
index 7440bd4db3..fc04ba870d 100644
--- a/modules/misc/medialibrary/MetadataExtractor.cpp
+++ b/modules/misc/medialibrary/MetadataExtractor.cpp
@@ -170,9 +170,18 @@ medialibrary::parser::Status MetadataExtractor::run( medialibrary::parser::IItem
 
     {
         vlc::threads::mutex_locker lock( ctx.m_mutex );
+        auto deadline = vlc_tick_now() + VLC_TICK_FROM_SEC( 5 );
         while ( ctx.needsProbing == false )
         {
-            ctx.m_cond.wait( ctx.m_mutex );
+            auto res = ctx.m_cond.timedwait( ctx.m_mutex, deadline );
+            if ( res != 0 )
+            {
+                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 )
diff --git a/modules/misc/medialibrary/medialibrary.h b/modules/misc/medialibrary/medialibrary.h
index 759fd38b1a..f339ab77d8 100644
--- a/modules/misc/medialibrary/medialibrary.h
+++ b/modules/misc/medialibrary/medialibrary.h
@@ -49,23 +49,25 @@ private:
     struct ParseContext
     {
         ParseContext( MetadataExtractor* mde, medialibrary::parser::IItem& item )
-            : inputItem( nullptr, &input_item_Release )
-            , input( nullptr, &input_Close )
-            , needsProbing( false )
+            : needsProbing( false )
             , state( INIT_S )
             , mde( mde )
             , item( item )
+            , inputItem( nullptr, &input_item_Release )
+            , input( nullptr, &input_Close )
         {
         }
 
-        std::unique_ptr<input_item_t, decltype(&input_item_Release)> inputItem;
-        std::unique_ptr<input_thread_t, decltype(&input_Close)> input;
         vlc::threads::condition_variable m_cond;
         vlc::threads::mutex m_mutex;
         bool needsProbing;
         input_state_e state;
         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;
     };
 
 public:



More information about the vlc-commits mailing list