From 1b9506db4ec032b92afaadf051a3a696fe7e6414 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Mardelle Date: Tue, 25 Dec 2012 23:49:38 +0100 Subject: [PATCH] Revert my freezing "stability patch" and fix some refresh related crashes: http://kdenlive.org/mantis/view.php?id=2892 --- src/commands/addtimelineclipcommand.cpp | 12 +++---- src/commands/addtimelineclipcommand.h | 1 - src/customtrackview.cpp | 22 +++++++++--- src/renderer.cpp | 46 +++++++++++-------------- src/renderer.h | 4 +-- 5 files changed, 44 insertions(+), 41 deletions(-) diff --git a/src/commands/addtimelineclipcommand.cpp b/src/commands/addtimelineclipcommand.cpp index 3a13ad54..2f309efc 100644 --- a/src/commands/addtimelineclipcommand.cpp +++ b/src/commands/addtimelineclipcommand.cpp @@ -37,25 +37,21 @@ AddTimelineClipCommand::AddTimelineClipCommand(CustomTrackView *view, QDomElemen { if (!m_remove) setText(i18n("Add timeline clip")); else setText(i18n("Delete timeline clip")); - if (parent) { - // command has a parent, so there are several operations ongoing, do not refresh monitor - m_refresh = false; - } else m_refresh = true; } // virtual void AddTimelineClipCommand::undo() { - if (!m_remove) m_view->deleteClip(m_clipInfo, m_refresh); - else m_view->addClip(m_xml, m_clipId, m_clipInfo, m_effects, m_overwrite, m_push, m_refresh); + if (!m_remove) m_view->deleteClip(m_clipInfo); + else m_view->addClip(m_xml, m_clipId, m_clipInfo, m_effects, m_overwrite, m_push); } // virtual void AddTimelineClipCommand::redo() { if (m_doIt) { - if (!m_remove) m_view->addClip(m_xml, m_clipId, m_clipInfo, m_effects, m_overwrite, m_push, m_refresh); - else m_view->deleteClip(m_clipInfo, m_refresh); + if (!m_remove) m_view->addClip(m_xml, m_clipId, m_clipInfo, m_effects, m_overwrite, m_push); + else m_view->deleteClip(m_clipInfo); } m_doIt = true; } diff --git a/src/commands/addtimelineclipcommand.h b/src/commands/addtimelineclipcommand.h index 015e7a3c..7058473b 100644 --- a/src/commands/addtimelineclipcommand.h +++ b/src/commands/addtimelineclipcommand.h @@ -46,7 +46,6 @@ private: QDomElement m_xml; bool m_doIt; bool m_remove; - bool m_refresh; bool m_overwrite; bool m_push; }; diff --git a/src/customtrackview.cpp b/src/customtrackview.cpp index 89e46511..01274517 100644 --- a/src/customtrackview.cpp +++ b/src/customtrackview.cpp @@ -1577,9 +1577,15 @@ void CustomTrackView::insertClipCut(DocClipBase *clip, int in, int out) return; } - AddTimelineClipCommand *command = new AddTimelineClipCommand(this, clip->toXML(), clip->getId(), pasteInfo, EffectsList(), m_scene->editMode() == OVERWRITEEDIT, m_scene->editMode() == INSERTEDIT, true, false); - updateTrackDuration(pasteInfo.track, command); - m_commandStack->push(command); + // Add refresh command for undo + QUndoCommand *addCommand = new QUndoCommand(); + addCommand->setText(i18n("Add timeline clip")); + new RefreshMonitorCommand(this, false, true, addCommand); + new AddTimelineClipCommand(this, clip->toXML(), clip->getId(), pasteInfo, EffectsList(), m_scene->editMode() == OVERWRITEEDIT, m_scene->editMode() == INSERTEDIT, true, false, addCommand); + new RefreshMonitorCommand(this, true, false, addCommand); + updateTrackDuration(pasteInfo.track, addCommand); + + m_commandStack->push(addCommand); selectClip(true, false); // Automatic audio split @@ -2432,7 +2438,7 @@ ClipItem *CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut, boo ItemInfo clipinfo = item->info(); clipinfo.track = m_document->tracksCount() - clipinfo.track; - bool success = m_document->renderer()->mltResizeClipEnd(clipinfo, info.endPos - info.startPos); + bool success = m_document->renderer()->mltResizeClipEnd(clipinfo, info.endPos - info.startPos, false); if (success) { item->resizeEnd((int) info.endPos.frames(m_document->fps())); setDocumentModified(); @@ -2670,6 +2676,9 @@ void CustomTrackView::dropEvent(QDropEvent * event) QUndoCommand *addCommand = new QUndoCommand(); addCommand->setText(i18n("Add timeline clip")); QList brokenClips; + + // Add refresh command for undo + new RefreshMonitorCommand(this, false, true, addCommand); for (int i = 0; i < items.count(); i++) { ClipItem *item = static_cast (items.at(i)); @@ -2710,6 +2719,9 @@ void CustomTrackView::dropEvent(QDropEvent * event) } item->setSelected(true); } + // Add refresh command for redo + new RefreshMonitorCommand(this, false, false, addCommand); + qDeleteAll(brokenClips); brokenClips.clear(); if (addCommand->childCount() > 0) m_commandStack->push(addCommand); @@ -6422,6 +6434,7 @@ void CustomTrackView::deleteTimelineTrack(int ix, TrackInfo trackinfo) QList selection = m_scene->items(r); QUndoCommand *deleteTrack = new QUndoCommand(); deleteTrack->setText("Delete track"); + new RefreshMonitorCommand(this, false, true, deleteTrack); // Delete all clips in selected track for (int i = 0; i < selection.count(); i++) { @@ -6442,6 +6455,7 @@ void CustomTrackView::deleteTimelineTrack(int ix, TrackInfo trackinfo) } new AddTrackCommand(this, ix, trackinfo, false, deleteTrack); + new RefreshMonitorCommand(this, true, false, deleteTrack); m_commandStack->push(deleteTrack); } diff --git a/src/renderer.cpp b/src/renderer.cpp index 96c22f5b..34fe631b 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -425,11 +425,10 @@ void Render::seek(int time) time = qMin(m_mltProducer->get_playtime(), time); if (requestedSeekPosition == SEEK_INACTIVE) { requestedSeekPosition = time; + m_mltConsumer->purge(); m_mltProducer->seek(time); - //m_mltConsumer->purge(); if (m_paused && !externalConsumer) { m_mltConsumer->set("refresh", 1); - //refresh(); } } else requestedSeekPosition = time; @@ -593,7 +592,7 @@ void Render::slotSplitView(bool doit) screen++; } } - refreshConsumerDisplay(); + m_mltConsumer->set("refresh", 1); } else { mlt_service serv = m_mltProducer->parent().get_service(); mlt_service nextservice = mlt_service_get_producer(serv); @@ -614,7 +613,7 @@ void Render::slotSplitView(bool doit) properties = MLT_SERVICE_PROPERTIES(nextservice); mlt_type = mlt_properties_get(properties, "mlt_type"); resource = mlt_properties_get(properties, "mlt_service"); - refreshConsumerDisplay(); + m_mltConsumer->set("refresh", 1); } } } @@ -1230,15 +1229,7 @@ void Render::startConsumer() { m_mltConsumer = NULL; return; } - refreshConsumerDisplay(); -} - -void Render::refreshConsumerDisplay() -{ m_mltConsumer->set("refresh", 1); - // Make sure the first frame is displayed, otherwise if we change producer too fast - // We can crash the avformat producer - m_mltConsumer->wait_for("consumer-frame-show"); } int Render::setSceneList(QDomDocument list, int position) @@ -1548,7 +1539,7 @@ void Render::start() kDebug(QtWarningMsg) << "/ / / / CANNOT START MONITOR"; } else { m_mltConsumer->purge(); - refreshConsumerDisplay(); + m_mltConsumer->set("refresh", 1); } } } @@ -1609,7 +1600,7 @@ void Render::switchPlay(bool play) if (m_mltConsumer->is_stopped()) { m_mltConsumer->start(); } - refreshConsumerDisplay(); + m_mltConsumer->set("refresh", 1); } else if (!play) { m_paused = true; m_mltProducer->set_speed(0.0); @@ -1629,7 +1620,7 @@ void Render::play(double speed) m_mltConsumer->start(); } m_paused = speed == 0; - if (current_speed == 0 && speed != 0) refreshConsumerDisplay(); + if (current_speed == 0 && speed != 0) m_mltConsumer->set("refresh", 1); } void Render::play(const GenTime & startTime) @@ -1640,7 +1631,7 @@ void Render::play(const GenTime & startTime) m_paused = false; m_mltProducer->seek((int)(startTime.frames(m_fps))); m_mltProducer->set_speed(1.0); - refreshConsumerDisplay(); + m_mltConsumer->set("refresh", 1); } void Render::loopZone(const GenTime & startTime, const GenTime & stopTime) @@ -1664,7 +1655,7 @@ void Render::playZone(const GenTime & startTime, const GenTime & stopTime) m_paused = false; m_mltProducer->set_speed(1.0); if (m_mltConsumer->is_stopped()) m_mltConsumer->start(); - refreshConsumerDisplay(); + m_mltConsumer->set("refresh", 1); m_isZoneMode = true; } @@ -1672,7 +1663,6 @@ void Render::resetZoneMode() { if (!m_isZoneMode && !m_isLoopMode) return; m_mltProducer->set("out", m_mltProducer->get_length()); - //m_mltProducer->set("eof", "pause"); m_isZoneMode = false; m_isLoopMode = false; } @@ -1707,12 +1697,13 @@ void Render::doRefresh() void Render::refresh() { + m_refreshTimer.stop(); QMutexLocker locker(&m_mutex); if (!m_mltProducer) return; if (m_mltConsumer) { if (m_mltConsumer->is_stopped()) m_mltConsumer->start(); - refreshConsumerDisplay(); + m_mltConsumer->set("refresh", 1); //m_mltConsumer->purge(); } } @@ -1779,7 +1770,9 @@ void Render::emitFrameNumber() if (currentPos == requestedSeekPosition) requestedSeekPosition = SEEK_INACTIVE; emit rendererPosition(currentPos); if (requestedSeekPosition != SEEK_INACTIVE) { + m_mltConsumer->purge(); m_mltProducer->seek(requestedSeekPosition); + if (m_mltProducer->get_speed() == 0) m_mltConsumer->set("refresh", 1); requestedSeekPosition = SEEK_INACTIVE; } } @@ -1953,6 +1946,10 @@ void Render::mltCheckLength(Mlt::Tractor *tractor) } delete blackclip; + if (m_mltConsumer->position() > duration) { + m_mltConsumer->purge(); + m_mltProducer->seek(duration); + } m_mltProducer->set("out", duration); emit durationChanged(duration); } @@ -2215,7 +2212,6 @@ bool Render::mltUpdateClip(Mlt::Tractor *tractor, ItemInfo info, QDomElement ele bool Render::mltRemoveClip(int track, GenTime position) { m_refreshTimer.stop(); - Mlt::Service service(m_mltProducer->parent().get_service()); if (service.type() != tractor_type) { kWarning() << "// TRACTOR PROBLEM"; @@ -2433,7 +2429,7 @@ void Render::mltInsertSpace(QMap trackClipStartList, QMap } service.unlock(); mltCheckLength(&tractor); - refreshConsumerDisplay(); + m_mltConsumer->set("refresh", 1); } @@ -3302,7 +3298,7 @@ void Render::mltMoveTrackEffect(int track, int oldPos, int newPos) refresh(); } -bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration) +bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration, bool refresh) { Mlt::Service service(m_mltProducer->parent().get_service()); Mlt::Tractor tractor(service); @@ -3380,7 +3376,7 @@ bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration) transpinfo.track = info.track; mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt()); }*/ - refreshConsumerDisplay(); + if (refresh) m_mltConsumer->set("refresh", 1); return true; } @@ -3497,7 +3493,7 @@ bool Render::mltResizeClipCrop(ItemInfo info, GenTime newCropStart) int frameOffset = newCropFrame - previousStart; trackPlaylist.resize_clip(clipIndex, newCropFrame, previousOut + frameOffset); service.unlock(); - refreshConsumerDisplay(); + m_mltConsumer->set("refresh", 1); return true; } @@ -3569,7 +3565,7 @@ bool Render::mltResizeClipStart(ItemInfo info, GenTime diff) }*/ //m_mltConsumer->set("refresh", 1); service.unlock(); - refreshConsumerDisplay(); + m_mltConsumer->set("refresh", 1); return true; } diff --git a/src/renderer.h b/src/renderer.h index 1320c5c0..0955b243 100644 --- a/src/renderer.h +++ b/src/renderer.h @@ -221,7 +221,7 @@ Q_OBJECT public: /** @brief Returns the duration/length of @param track as reported by the track producer. */ int mltTrackDuration(int track); - bool mltResizeClipEnd(ItemInfo info, GenTime clipDuration); + bool mltResizeClipEnd(ItemInfo info, GenTime clipDuration, bool refresh = true); bool mltResizeClipStart(ItemInfo info, GenTime diff); bool mltResizeClipCrop(ItemInfo info, GenTime newCropStart); bool mltMoveClip(int startTrack, int endTrack, GenTime pos, GenTime moveStart, Mlt::Producer *prod, bool overwrite = false, bool insert = false); @@ -399,8 +399,6 @@ private: void fixAudioMixing(Mlt::Tractor tractor); /** @brief Make sure we inform MLT if we need a lot of threads for avformat producer */ void checkMaxThreads(); - /** @brief Refresh consumer and wait until frame is displayed */ - void refreshConsumerDisplay(); private slots: -- 2.39.2