]> git.sesse.net Git - kdenlive/commitdiff
Fix possible concurrency issue in thumbs
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Wed, 12 Oct 2011 20:59:00 +0000 (20:59 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Wed, 12 Oct 2011 20:59:00 +0000 (20:59 +0000)
svn path=/trunk/kdenlive/; revision=5953

src/kthumb.cpp
src/kthumb.h

index b26b5f1ae4603744959c3dd649e1cc3e6e28d30d..2369dc37e0ac7f5813edcce0f7cbfd737b4a2a51 100644 (file)
@@ -74,7 +74,9 @@ void KThumb::setProducer(Mlt::Producer *producer)
     m_intraFramesQueue.clear();
     m_future.waitForFinished();
     m_intra.waitForFinished();
+    m_mutex.lock();
     m_producer = producer;
+    m_mutex.unlock();
     // FIXME: the profile() call leaks an object, but trying to free
     // it leads to a double-free in Profile::~Profile()
     if (producer) {
@@ -131,7 +133,9 @@ void KThumb::doGetThumbs()
     while (!m_requestedThumbs.isEmpty()) {
         int frame = m_requestedThumbs.takeFirst();
         if (frame != -1) {
+            m_mutex.lock();
             QImage img = getFrame(m_producer, frame, swidth, dwidth, theight);
+            m_mutex.unlock();
             emit thumbReady(frame, img);
         }
     }
@@ -139,7 +143,10 @@ void KThumb::doGetThumbs()
 
 QPixmap KThumb::extractImage(int frame, int width, int height)
 {
-    return QPixmap::fromImage(getFrame(m_producer, frame, (int) (height * m_ratio + 0.5), width, height));
+    m_mutex.lock();
+    QImage img = getFrame(m_producer, frame, (int) (height * m_ratio + 0.5), width, height);
+    m_mutex.unlock();
+    return QPixmap::fromImage(img);
 }
 
 //static
@@ -483,10 +490,12 @@ void KThumb::slotGetIntraThumbs()
     while (!m_intraFramesQueue.isEmpty()) {
         int pos = m_intraFramesQueue.takeFirst();
         if (!m_clipManager->pixmapCache->contains(path + QString::number(pos))) {
+            m_mutex.lock();
             if (m_clipManager->pixmapCache->insertImage(path + QString::number(pos), getFrame(m_producer, pos, frameWidth, displayWidth, theight))) {
                 addedThumbs = true;
             }
             else kDebug()<<"// INSERT FAILD FOR: "<<pos;
+            m_mutex.unlock();
         }
         m_intraFramesQueue.removeAll(pos);
     }
index 76885fc5b24044d9a8535b4e8b383a4d609a9aa2..45eca383aec534ffadc9fcb332b9b563387cd923 100644 (file)
@@ -118,6 +118,7 @@ private:
     int m_arrayWidth;
     /** @brief List of frame numbers from which we want to extract thumbnails. */
     QList <int> m_intraFramesQueue;
+    QMutex m_mutex;
     void doGetThumbs();
 
 signals: