[vlmc-devel] commit: MetaDataManager: Don' t crash when a media has been deleted before processing. ( Hugo Beauzée-Luyssen )
git at videolan.org
git at videolan.org
Sun Apr 18 17:12:00 CEST 2010
vlmc | branch: master | Hugo Beauzée-Luyssen <beauze.h at gmail.com> | Fri Apr 16 01:54:24 2010 +0200| [89ecbf8d6773a83759897d497e1cab22c6d4ed3a] | committer: Hugo Beauzée-Luyssen
MetaDataManager: Don't crash when a media has been deleted before processing.
> http://git.videolan.org/gitweb.cgi/vlmc.git/?a=commit;h=89ecbf8d6773a83759897d497e1cab22c6d4ed3a
---
src/Metadata/MetaDataManager.cpp | 18 ++++++++++++++++--
src/Metadata/MetaDataManager.h | 1 +
2 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/src/Metadata/MetaDataManager.cpp b/src/Metadata/MetaDataManager.cpp
index 6d53462..ca88040 100644
--- a/src/Metadata/MetaDataManager.cpp
+++ b/src/Metadata/MetaDataManager.cpp
@@ -41,7 +41,8 @@ MetaDataManager::~MetaDataManager()
delete m_mediaPlayer;
}
-void MetaDataManager::launchComputing( Media *media )
+void
+MetaDataManager::launchComputing( Media *media )
{
m_computeInProgress = true;
m_mediaPlayer = new LibVLCpp::MediaPlayer;
@@ -55,7 +56,8 @@ void MetaDataManager::launchComputing( Media *media )
worker->compute();
}
-void MetaDataManager::computingCompleted()
+void
+MetaDataManager::computingCompleted()
{
QMutexLocker lock( m_computingMutex );
@@ -79,6 +81,8 @@ MetaDataManager::computeMediaMetadata( Media *media )
{
QMutexLocker lock( m_computingMutex );
+ connect( media, SIGNAL( destroyed( QObject* ) ),
+ this, SLOT( mediaDestroyed( QObject*) ), Qt::DirectConnection );
if ( m_computeInProgress == true )
{
m_mediaToCompute.enqueue( media );
@@ -88,3 +92,13 @@ MetaDataManager::computeMediaMetadata( Media *media )
launchComputing( media );
}
}
+
+void
+MetaDataManager::mediaDestroyed( QObject *sender )
+{
+ QMutexLocker lock( m_computingMutex );
+
+ Media* media = reinterpret_cast<Media*>( sender );
+ if ( m_mediaToCompute.contains( media ) )
+ m_mediaToCompute.removeAll( media );
+}
diff --git a/src/Metadata/MetaDataManager.h b/src/Metadata/MetaDataManager.h
index 81f0e77..5d52c8b 100644
--- a/src/Metadata/MetaDataManager.h
+++ b/src/Metadata/MetaDataManager.h
@@ -57,6 +57,7 @@ class MetaDataManager : public QObject, public Singleton<MetaDataManager>
private slots:
void computingCompleted();
void computingFailed( Media* media );
+ void mediaDestroyed( QObject* sender );
signals:
void failedToCompute( Media* );
More information about the Vlmc-devel
mailing list