[vlmc-devel] commit: Media: Avoid a potential race condition when computing metadata. ( Hugo Beauzée-Luyssen )

git at videolan.org git at videolan.org
Sun Sep 26 22:50:02 CEST 2010


vlmc | branch: master | Hugo Beauzée-Luyssen <beauze.h at gmail.com> | Sun Sep 26 19:20:06 2010 +0200| [8ae624c423d507b0614496261b6e7389abc9f995] | committer: Hugo Beauzée-Luyssen 

Media: Avoid a potential race condition when computing metadata.

Signal was connected after the metadata computing was started.
If metadata computing appens to end before the signal is connected,
things can go wrong.

> http://git.videolan.org/gitweb.cgi/vlmc.git/?a=commit;h=8ae624c423d507b0614496261b6e7389abc9f995
---

 src/Gui/import/ImportController.cpp |    3 ++-
 src/Library/Library.cpp             |    1 +
 src/Library/MediaContainer.cpp      |    1 -
 src/Media/Media.cpp                 |    6 ++++++
 src/Media/Media.h                   |    7 +++++++
 5 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/src/Gui/import/ImportController.cpp b/src/Gui/import/ImportController.cpp
index 6c4c9c5..a96f297 100644
--- a/src/Gui/import/ImportController.cpp
+++ b/src/Gui/import/ImportController.cpp
@@ -149,6 +149,8 @@ ImportController::importMedia( const QString &filePath )
         return ;
 
     Media*  media = m_temporaryMedias->addMedia( filePath );
+    connect( media, SIGNAL( metaDataComputed( const Media* ) ), this, SLOT( mediaLoaded() ) );
+    media->computeMetadata();
     if ( media == NULL )
     {
         qCritical() << "An error occurred while loading media:" << filePath;
@@ -159,7 +161,6 @@ ImportController::importMedia( const QString &filePath )
     m_temporaryMedias->addClip( clip );
     ++m_nbMediaToLoad;
     m_ui->progressBar->setMaximum( m_nbMediaToLoad );
-    connect( media, SIGNAL( metaDataComputed( const Media* ) ), this, SLOT( mediaLoaded() ) );
 }
 
 void
diff --git a/src/Library/Library.cpp b/src/Library/Library.cpp
index b4dcd1f..3dc2d55 100644
--- a/src/Library/Library.cpp
+++ b/src/Library/Library.cpp
@@ -73,6 +73,7 @@ Library::loadProject( const QDomElement& doc )
                      this, SLOT( mediaLoaded( const Media* ) ), Qt::QueuedConnection );
             m_medias[mrl] = m;
             m_nbMediaToLoad.fetchAndAddAcquire( 1 );
+            m->computeMetadata();
         }
         media = media.nextSiblingElement();
     }
diff --git a/src/Library/MediaContainer.cpp b/src/Library/MediaContainer.cpp
index 9390489..717d591 100644
--- a/src/Library/MediaContainer.cpp
+++ b/src/Library/MediaContainer.cpp
@@ -89,7 +89,6 @@ MediaContainer::addMedia( const QFileInfo& fileInfo )
             return NULL;
     }
     Media* media = new Media( fileInfo.filePath() );
-    MetaDataManager::getInstance()->computeMediaMetadata( media );
     return media;
 }
 
diff --git a/src/Media/Media.cpp b/src/Media/Media.cpp
index 9da28bf..33ff213 100644
--- a/src/Media/Media.cpp
+++ b/src/Media/Media.cpp
@@ -315,3 +315,9 @@ Media::setFilePath( const QString &filePath )
     }
     emit workspaceStateChanged( m_inWorkspace );
 }
+
+void
+Media::computeMetadata()
+{
+    MetaDataManager::getInstance()->computeMediaMetadata( this );
+}
diff --git a/src/Media/Media.h b/src/Media/Media.h
index 97feebe..46ff828 100644
--- a/src/Media/Media.h
+++ b/src/Media/Media.h
@@ -152,6 +152,13 @@ public:
 
     bool                        isInWorkspace() const;
 
+    /**
+     *  \brief      Just an helper to compute metadata.
+     *
+     *  Actual computing is performed by MetadataManager
+     */
+    void                        computeMetadata();
+
 private:
     void                        setFileType();
 



More information about the Vlmc-devel mailing list