Commit 8ae624c4 authored by Hugo Beauzée-Luyssen's avatar 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.
parent 3258f496
...@@ -149,6 +149,8 @@ ImportController::importMedia( const QString &filePath ) ...@@ -149,6 +149,8 @@ ImportController::importMedia( const QString &filePath )
return ; return ;
Media* media = m_temporaryMedias->addMedia( filePath ); Media* media = m_temporaryMedias->addMedia( filePath );
connect( media, SIGNAL( metaDataComputed( const Media* ) ), this, SLOT( mediaLoaded() ) );
media->computeMetadata();
if ( media == NULL ) if ( media == NULL )
{ {
qCritical() << "An error occurred while loading media:" << filePath; qCritical() << "An error occurred while loading media:" << filePath;
...@@ -159,7 +161,6 @@ ImportController::importMedia( const QString &filePath ) ...@@ -159,7 +161,6 @@ ImportController::importMedia( const QString &filePath )
m_temporaryMedias->addClip( clip ); m_temporaryMedias->addClip( clip );
++m_nbMediaToLoad; ++m_nbMediaToLoad;
m_ui->progressBar->setMaximum( m_nbMediaToLoad ); m_ui->progressBar->setMaximum( m_nbMediaToLoad );
connect( media, SIGNAL( metaDataComputed( const Media* ) ), this, SLOT( mediaLoaded() ) );
} }
void void
......
...@@ -73,6 +73,7 @@ Library::loadProject( const QDomElement& doc ) ...@@ -73,6 +73,7 @@ Library::loadProject( const QDomElement& doc )
this, SLOT( mediaLoaded( const Media* ) ), Qt::QueuedConnection ); this, SLOT( mediaLoaded( const Media* ) ), Qt::QueuedConnection );
m_medias[mrl] = m; m_medias[mrl] = m;
m_nbMediaToLoad.fetchAndAddAcquire( 1 ); m_nbMediaToLoad.fetchAndAddAcquire( 1 );
m->computeMetadata();
} }
media = media.nextSiblingElement(); media = media.nextSiblingElement();
} }
......
...@@ -89,7 +89,6 @@ MediaContainer::addMedia( const QFileInfo& fileInfo ) ...@@ -89,7 +89,6 @@ MediaContainer::addMedia( const QFileInfo& fileInfo )
return NULL; return NULL;
} }
Media* media = new Media( fileInfo.filePath() ); Media* media = new Media( fileInfo.filePath() );
MetaDataManager::getInstance()->computeMediaMetadata( media );
return media; return media;
} }
......
...@@ -315,3 +315,9 @@ Media::setFilePath( const QString &filePath ) ...@@ -315,3 +315,9 @@ Media::setFilePath( const QString &filePath )
} }
emit workspaceStateChanged( m_inWorkspace ); emit workspaceStateChanged( m_inWorkspace );
} }
void
Media::computeMetadata()
{
MetaDataManager::getInstance()->computeMediaMetadata( this );
}
...@@ -152,6 +152,13 @@ public: ...@@ -152,6 +152,13 @@ public:
bool isInWorkspace() const; bool isInWorkspace() const;
/**
* \brief Just an helper to compute metadata.
*
* Actual computing is performed by MetadataManager
*/
void computeMetadata();
private: private:
void setFileType(); void setFileType();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment