From: Jean-Baptiste Mardelle Date: Sat, 22 Oct 2011 22:49:41 +0000 (+0000) Subject: Fix some more threading crashes, almost there :) X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=a830589d50452bf5ba05da1273c57bcfa33985e9;p=kdenlive Fix some more threading crashes, almost there :) svn path=/trunk/kdenlive/; revision=5980 --- diff --git a/src/docclipbase.cpp b/src/docclipbase.cpp index b7fa0d20..4d3a3bf0 100644 --- a/src/docclipbase.cpp +++ b/src/docclipbase.cpp @@ -163,11 +163,6 @@ const QString &DocClipBase::getId() const return m_id; } -void DocClipBase::setId(const QString &newId) -{ - m_id = newId; -} - const CLIPTYPE & DocClipBase::clipType() const { return m_clipType; @@ -653,7 +648,7 @@ Mlt::Producer *DocClipBase::getCloneProducer() prod = cloneProducer(source); } if (prod) { - adjustProducerProperties(prod, getId() + "_monitor", false, false); + adjustProducerProperties(prod, getId() + "_", false, false); } return prod; } diff --git a/src/docclipbase.h b/src/docclipbase.h index 97a68693..337a1373 100644 --- a/src/docclipbase.h +++ b/src/docclipbase.h @@ -82,7 +82,6 @@ Q_OBJECT public: /** Returns the internal unique id of the clip. */ const QString &getId() const; - void setId(const QString &newId); //KThumb *thumbCreator; bool audioThumbCreated() const; diff --git a/src/kthumb.cpp b/src/kthumb.cpp index 71f2bfc9..6eb212a7 100644 --- a/src/kthumb.cpp +++ b/src/kthumb.cpp @@ -57,7 +57,9 @@ KThumb::KThumb(ClipManager *clipManager, KUrl url, const QString &id, const QStr KThumb::~KThumb() { + m_listMutex.lock(); m_requestedThumbs.clear(); + m_listMutex.unlock(); m_intraFramesQueue.clear(); if (m_audioThumbProducer.isRunning()) { m_stopAudioThumbs = true; @@ -70,7 +72,9 @@ KThumb::~KThumb() void KThumb::setProducer(Mlt::Producer *producer) { + m_listMutex.lock(); m_requestedThumbs.clear(); + m_listMutex.unlock(); m_intraFramesQueue.clear(); m_future.waitForFinished(); m_intra.waitForFinished(); @@ -116,9 +120,11 @@ QPixmap KThumb::getImage(KUrl url, int width, int height) void KThumb::extractImage(int frame, int frame2) { if (!KdenliveSettings::videothumbnails() || m_producer == NULL) return; + m_listMutex.lock(); if (frame != -1 && !m_requestedThumbs.contains(frame)) m_requestedThumbs.append(frame); if (frame2 != -1 && !m_requestedThumbs.contains(frame2)) m_requestedThumbs.append(frame2); qSort(m_requestedThumbs); + m_listMutex.unlock(); if (!m_future.isRunning()) { m_future = QtConcurrent::run(this, &KThumb::doGetThumbs); } @@ -131,7 +137,9 @@ void KThumb::doGetThumbs() const int dwidth = (int)(theight * m_dar + 0.5); while (!m_requestedThumbs.isEmpty()) { + m_listMutex.lock(); int frame = m_requestedThumbs.takeFirst(); + m_listMutex.unlock(); if (frame != -1) { QImage img = getProducerFrame(frame, swidth, dwidth, theight); emit thumbReady(frame, img); diff --git a/src/kthumb.h b/src/kthumb.h index dd23ed21..f90051d7 100644 --- a/src/kthumb.h +++ b/src/kthumb.h @@ -121,6 +121,7 @@ private: /** @brief List of frame numbers from which we want to extract thumbnails. */ QList m_intraFramesQueue; QMutex m_mutex; + QMutex m_listMutex; void doGetThumbs(); QImage getProducerFrame(int framepos, int frameWidth, int displayWidth, int height); diff --git a/src/projectlist.cpp b/src/projectlist.cpp index e798466b..72a7acbb 100644 --- a/src/projectlist.cpp +++ b/src/projectlist.cpp @@ -523,8 +523,8 @@ void ProjectList::slotReloadClip(const QString &id) e.setAttribute("length", length); } } - m_render->getFileProperties(e, item->clipId(), m_listView->iconSize().height(), true); resetThumbsProducer(clip); + m_render->getFileProperties(e, item->clipId(), m_listView->iconSize().height(), true); } } } @@ -1085,8 +1085,8 @@ void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties) m_listView->processLayout(); QDomElement e = clip->toXML().cloneNode().toElement(); e.removeAttribute("file_hash"); - m_render->getFileProperties(e, clip->getId(), m_listView->iconSize().height(), true); resetThumbsProducer(clip); + m_render->getFileProperties(e, clip->getId(), m_listView->iconSize().height(), true); } else if (item->hasProxy() && !item->isProxyRunning()) { slotCreateProxy(clip->getId()); @@ -1154,6 +1154,7 @@ void ProjectList::slotGotProxy(ProjectItem *item) e.setAttribute("length", length); } } + resetThumbsProducer(clip); m_render->getFileProperties(e, clip->getId(), m_listView->iconSize().height(), true); } @@ -1237,8 +1238,8 @@ void ProjectList::updateAllClips(bool displayRatioChanged, bool fpsChanged) xml.removeAttribute("proxy_out"); } bool replace = xml.attribute("replace") == "1"; - m_render->getFileProperties(xml, clip->getId(), m_listView->iconSize().height(), replace); if (replace) resetThumbsProducer(clip); + m_render->getFileProperties(xml, clip->getId(), m_listView->iconSize().height(), replace); } else { item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled); @@ -1641,7 +1642,8 @@ void ProjectList::resetThumbsProducer(DocClipBase *clip) { if (!clip) return; clip->clearThumbProducer(); - m_thumbnailQueue.removeAll(clip->getId()); + QString id = clip->getId(); + m_thumbnailQueue.removeAll(id); } void ProjectList::slotProcessNextThumbnail() diff --git a/src/renderer.cpp b/src/renderer.cpp index c9c23e29..be627e3b 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -977,13 +977,14 @@ int Render::setProducer(Mlt::Producer *producer, int position) QString currentId; int consumerPosition = 0; if (m_winid == -1) return -1; + if (m_mltProducer) m_mltProducer->set_speed(0); if (m_mltConsumer) { + m_mltConsumer->set("refresh", 0); + m_mltConsumer->purge(); consumerPosition = m_mltConsumer->position(); if (!m_mltConsumer->is_stopped()) { m_mltConsumer->stop(); - m_mltConsumer->purge(); } - m_mltConsumer->set("refresh", 0); } else { return -1; @@ -991,7 +992,6 @@ int Render::setProducer(Mlt::Producer *producer, int position) if (m_mltProducer) { currentId = m_mltProducer->get("id"); - m_mltProducer->set_speed(0); delete m_mltProducer; m_mltProducer = NULL; emit stopped();