From f660d73b6c4bd5936b20276d26c547a894bc8984 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Mardelle Date: Sun, 23 Oct 2011 22:07:09 +0000 Subject: [PATCH] Fix crash when enabling a proxy clip svn path=/trunk/kdenlive/; revision=5982 --- src/mainwindow.cpp | 9 ++------- src/mainwindow.h | 2 -- src/projectlist.cpp | 36 ++++++++++++++---------------------- src/projectlist.h | 7 ++----- src/renderer.cpp | 20 +++++++++++++++----- src/renderer.h | 2 +- 6 files changed, 34 insertions(+), 42 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 48559efb..270bdb86 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -840,6 +840,7 @@ void MainWindow::slotAddEffect(const QDomElement effect) void MainWindow::slotUpdateClip(const QString &id) { if (!m_activeDocument) return; + kDebug()<<"//\n\n RECIEVED UPDATED PRODUCER FOR: "<clipManager()->getClipById(id); if (clip->numReferences() > 0) m_activeTimeline->projectView()->slotUpdateClip(id); if (m_clipMonitor->activeClip() && m_clipMonitor->activeClip()->getId() == id) { @@ -859,7 +860,7 @@ void MainWindow::slotConnectMonitors() connect(m_projectList, SIGNAL(showClipProperties(QList , QMap)), this, SLOT(slotShowClipProperties(QList , QMap))); connect(m_projectMonitor->render, SIGNAL(replyGetImage(const QString &, const QString &, int, int)), m_projectList, SLOT(slotReplyGetImage(const QString &, const QString &, int, int))); connect(m_projectMonitor->render, SIGNAL(replyGetImage(const QString &, const QImage &)), m_projectList, SLOT(slotReplyGetImage(const QString &, const QImage &))); - connect(m_projectMonitor->render, SIGNAL(replyGetFileProperties(const QString &, Mlt::Producer*, const stringMap &, const stringMap &, bool, bool)), this, SLOT(slotReplyGetFileProperties(const QString &, Mlt::Producer*, const stringMap &, const stringMap &, bool, bool))); + connect(m_projectMonitor->render, SIGNAL(replyGetFileProperties(const QString &, Mlt::Producer*, const stringMap &, const stringMap &, bool)), m_projectList, SLOT(slotReplyGetFileProperties(const QString &, Mlt::Producer*, const stringMap &, const stringMap &, bool))); connect(m_projectMonitor->render, SIGNAL(removeInvalidClip(const QString &, bool)), m_projectList, SLOT(slotRemoveInvalidClip(const QString &, bool))); @@ -4386,12 +4387,6 @@ void MainWindow::slotOpenBackupDialog(const KUrl url) delete dia; } -void MainWindow::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const stringMap &properties, const stringMap &metadata, bool replace, bool refreshThumbnail) -{ - m_projectList->slotReplyGetFileProperties(clipId, producer, properties, metadata, replace, refreshThumbnail); -} - - void MainWindow::slotElapsedTime() { kDebug()<<"-----------------------------------------\n"<<"Time elapsed: "<addWidget(searchView); //int s = style()->pixelMetric(QStyle::PM_SmallIconSize); //m_toolbar->setIconSize(QSize(s, s)); @@ -625,7 +621,6 @@ void ProjectList::setRenderer(Render *projectRender) void ProjectList::slotClipSelected() { - m_refreshMonitorTimer.stop(); QTreeWidgetItem *item = m_listView->currentItem(); ProjectItem *clip = NULL; if (item) { @@ -1143,6 +1138,12 @@ void ProjectList::slotGotProxy(ProjectItem *item) { if (item == NULL || !m_refreshed) return; DocClipBase *clip = item->referencedClip(); + if (!clip || !clip->isClean() || m_render->isProcessing(item->clipId())) { + // Clip is being reprocessed, abort + kDebug()<<"//// TRYING TO PROXY: "<clipId()<<", but it is busy"; + return; + } + // Proxy clip successfully created QDomElement e = clip->toXML().cloneNode().toElement(); @@ -1720,18 +1721,8 @@ void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update) } } -void ProjectList::slotRefreshMonitor() -{ - if (m_listView->selectedItems().count() == 1 && m_render && m_render->processingItems() == 0) { - if (m_listView->currentItem() && m_listView->currentItem()->type() != PROJECTFOLDERTYPE) { - ProjectItem *item = static_cast (m_listView->currentItem()); - DocClipBase *clip = item->referencedClip(); - if (clip && clip->isClean() && !m_render->isProcessing(item->clipId())) emit clipSelected(clip); - } - } -} -void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const stringMap &properties, const stringMap &metadata, bool replace, bool refreshThumbnail) +void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const stringMap &properties, const stringMap &metadata, bool replace) { QString toReload; ProjectItem *item = getItemById(clipId); @@ -1753,7 +1744,7 @@ void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Produce item->setProperties(properties, metadata); clip->setProducer(producer, replace); clip->askForAudioThumbs(); - if (refreshThumbnail) getCachedThumbnail(item); + // Proxy stuff QString size = properties.value("frame_size"); if (!useProxy() && clip->getProperty("proxy").isEmpty()) setProxyStatus(item, NOPROXY); @@ -1781,7 +1772,7 @@ void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Produce } } - if (!replace && item->data(0, Qt::DecorationRole).isNull() && !refreshThumbnail) { + if (!replace && item->data(0, Qt::DecorationRole).isNull()) { requestClipThumbnail(clipId); } if (!toReload.isEmpty()) @@ -1810,9 +1801,6 @@ void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Produce } if (replace && item) { toReload = clipId; - // update clip in clip monitor - /*if (queue == 0 && item->isSelected() && m_listView->selectedItems().count() == 1) - m_refreshMonitorTimer.start();*/ } if (!item) { // no item for producer, delete it @@ -2602,7 +2590,11 @@ void ProjectList::slotProxyCurrentItem(bool doProxy) if ((t == VIDEO || t == AV || t == UNKNOWN || t == IMAGE || t == PLAYLIST) && item->referencedClip()) { if ((doProxy && item->hasProxy()) || (!doProxy && !item->hasProxy())) continue; DocClipBase *clip = item->referencedClip(); - if (!clip->isClean() || m_render->isProcessing(item->clipId())) continue; + if (!clip || !clip->isClean() || m_render->isProcessing(item->clipId())) { + kDebug()<<"//// TRYING TO PROXY: "<clipId()<<", but it is busy"; + continue; + } + resetThumbsProducer(clip); oldProps = clip->properties(); if (doProxy) { diff --git a/src/projectlist.h b/src/projectlist.h index fbebd9f6..7aa86310 100644 --- a/src/projectlist.h +++ b/src/projectlist.h @@ -242,7 +242,7 @@ public slots: void updateAllClips(bool displayRatioChanged, bool fpsChanged); void slotReplyGetImage(const QString &clipId, const QImage &img); void slotReplyGetImage(const QString &clipId, const QString &name, int width, int height); - void slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const stringMap &properties, const stringMap &metadata, bool replace, bool refreshThumbnail); + void slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const stringMap &properties, const stringMap &metadata, bool replace); void slotAddClip(DocClipBase *clip, bool getProperties); void slotDeleteClip(const QString &clipId); void slotUpdateClip(const QString &id); @@ -309,7 +309,6 @@ private: QList m_proxyList; QFutureSynchronizer m_proxyThreads; InvalidDialog *m_invalidClipDialog; - QTimer m_refreshMonitorTimer; void requestClipThumbnail(const QString id); @@ -382,9 +381,7 @@ private slots: /** @brief Stop creation of this clip's proxy. */ void slotAbortProxy(const QString id, const QString path); /** @brief Start creation of proxy clip. */ - void slotGenerateProxy();//const QString destPath, const QString sourcePath, int clipType, int exif); - /** @brief Timer triggering a refresh of the clip monitor. */ - void slotRefreshMonitor(); + void slotGenerateProxy(); signals: void clipSelected(DocClipBase *, QPoint zone = QPoint()); diff --git a/src/renderer.cpp b/src/renderer.cpp index 576ba1fe..88666e0f 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -748,20 +748,30 @@ void Render::processFileProperties() if (info.xml.hasAttribute("templatetext")) producer->set("templatetext", info.xml.attribute("templatetext").toUtf8().constData()); + + int imageWidth = (int)((double) info.imageHeight * m_mltProfile->width() / m_mltProfile->height() + 0.5); + int fullWidth = (int)((double) info.imageHeight * m_mltProfile->dar() + 0.5); + int frameNumber = info.xml.attribute("thumbnail", "-1").toInt(); if ((!info.replaceProducer && info.xml.hasAttribute("file_hash")) || proxyProducer) { // Clip already has all properties - emit replyGetFileProperties(info.clipId, producer, stringMap(), stringMap(), info.replaceProducer, true); + if (proxyProducer) { + // Recreate clip thumb + if (frameNumber > 0) producer->seek(frameNumber); + Mlt::Frame *frame = producer->get_frame(); + if (frame && frame->is_valid()) { + QImage img = KThumb::getFrame(frame, imageWidth, fullWidth, info.imageHeight); + delete frame; + emit replyGetImage(info.clipId, img); + } + } + emit replyGetFileProperties(info.clipId, producer, stringMap(), stringMap(), info.replaceProducer); m_processingClipId.clear(); continue; } - int imageWidth = (int)((double) info.imageHeight * m_mltProfile->width() / m_mltProfile->height() + 0.5); - int fullWidth = (int)((double) info.imageHeight * m_mltProfile->dar() + 0.5); stringMap filePropertyMap; stringMap metadataPropertyMap; - - int frameNumber = info.xml.attribute("thumbnail", "-1").toInt(); if (frameNumber > 0) producer->seek(frameNumber); duration = duration > 0 ? duration : producer->get_playtime(); diff --git a/src/renderer.h b/src/renderer.h index a8de89ea..4fb5b1b5 100644 --- a/src/renderer.h +++ b/src/renderer.h @@ -372,7 +372,7 @@ private slots: signals: /** @brief The renderer received a reply to a getFileProperties request. */ - void replyGetFileProperties(const QString &clipId, Mlt::Producer*, const stringMap &, const stringMap &, bool replaceProducer, bool refreshThumbnail = false); + void replyGetFileProperties(const QString &clipId, Mlt::Producer*, const stringMap &, const stringMap &, bool replaceProducer); /** @brief The renderer received a reply to a getImage request. */ void replyGetImage(const QString &, const QString &, int, int); -- 2.39.2