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 )
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
......
......@@ -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();
}
......
......@@ -89,7 +89,6 @@ MediaContainer::addMedia( const QFileInfo& fileInfo )
return NULL;
}
Media* media = new Media( fileInfo.filePath() );
MetaDataManager::getInstance()->computeMediaMetadata( media );
return media;
}
......
......@@ -315,3 +315,9 @@ Media::setFilePath( const QString &filePath )
}
emit workspaceStateChanged( m_inWorkspace );
}
void
Media::computeMetadata()
{
MetaDataManager::getInstance()->computeMediaMetadata( this );
}
......@@ -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();
......
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