X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Frenderer.cpp;h=301e2c34eccffd0bf434b942dc8e200559292118;hb=8fc4ca35f2a709a30a91fbaf170980fc6d13ce03;hp=a126f55135070ba364e5e0b924f655f8e7ee842b;hpb=cd6d679212de9a4b123b4402a7452aabd920ed31;p=kdenlive diff --git a/src/renderer.cpp b/src/renderer.cpp index a126f551..301e2c34 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -30,10 +30,6 @@ #include "slideshowclip.h" #include "profilesdialog.h" -#ifdef USE_BLACKMAGIC -#include "blackmagic/devices.h" -#endif - #include #include @@ -57,15 +53,16 @@ static void kdenlive_callback(void* /*ptr*/, int level, const char* fmt, va_list vl) { -// kDebug() << "log level" << level << QString().vsprintf(fmt, vl).simplified(); if (level > MLT_LOG_ERROR) return; + //kDebug() << "log level" << level << QString().vsprintf(fmt, vl).simplified(); QString error; QApplication::postEvent(qApp->activeWindow(), new MltErrorEvent(error.vsprintf(fmt, vl).simplified())); va_end(vl); } -static void consumer_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr) +//static +void Render::consumer_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr) { // detect if the producer has finished playing. Is there a better way to do it? self->emitFrameNumber(); @@ -77,48 +74,61 @@ static void consumer_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr if (self->analyseAudio) { self->showAudio(frame); } - if (frame.get_double("_speed") < 0.0 && mlt_frame_get_position(frame_ptr) <= 0) { + if (frame.get_double("_speed") == 0) self->emitConsumerStopped(); + else if (frame.get_double("_speed") < 0.0 && mlt_frame_get_position(frame_ptr) <= 0) { self->pause(); - self->emitConsumerStopped(); + self->emitConsumerStopped(true); } } - -static void consumer_paused(mlt_consumer, Render * self, mlt_frame /*frame_ptr*/) +/* +static void consumer_paused(mlt_consumer, Render * self, mlt_frame frame_ptr) { // detect if the producer has finished playing. Is there a better way to do it? - self->emitConsumerStopped(); -} - + Mlt::Frame frame(frame_ptr); + if (!frame.is_valid()) return; + if (frame.get_double("_speed") < 0.0 && mlt_frame_get_position(frame_ptr) <= 0) { + self->pause(); + self->emitConsumerStopped(true); + } + else self->emitConsumerStopped(); +}*/ -static void consumer_gl_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr) +// static +void Render::consumer_gl_frame_show(mlt_consumer consumer, Render * self, mlt_frame frame_ptr) { // detect if the producer has finished playing. Is there a better way to do it? + if (self->externalConsumer && !self->analyseAudio && !self->sendFrameForAnalysis) { + emit self->rendererPosition((int) mlt_consumer_position(consumer)); + return; + } Mlt::Frame frame(frame_ptr); - if (frame.get_double("_speed") < 0.0 && mlt_frame_get_position(frame_ptr) <= 0) { + if (frame.get_double("_speed") == 0) self->emitConsumerStopped(); + else if (frame.get_double("_speed") < 0.0 && mlt_frame_get_position(frame_ptr) <= 0) { self->pause(); - self->emitConsumerStopped(); + self->emitConsumerStopped(true); } - else if (frame.get_double("_speed") == 0) self->emitConsumerStopped(); - self->showFrame(frame); + emit self->mltFrameReceived(new Mlt::Frame(frame_ptr)); } Render::Render(Kdenlive::MONITORID rendererName, int winid, QString profile, QWidget *parent) : AbstractRender(rendererName, parent), requestedSeekPosition(SEEK_INACTIVE), + showFrameSemaphore(1), + externalConsumer(false), m_name(rendererName), m_mltConsumer(NULL), m_mltProducer(NULL), m_mltProfile(NULL), m_showFrameEvent(NULL), m_pauseEvent(NULL), - m_externalConsumer(false), m_isZoneMode(false), m_isLoopMode(false), m_isSplitView(false), m_blackClip(NULL), m_winid(winid), - m_paused(true) + m_paused(true), + m_isActive(false) { qRegisterMetaType ("stringMap"); analyseAudio = KdenliveSettings::monitor_audio(); @@ -130,8 +140,9 @@ Render::Render(Kdenlive::MONITORID rendererName, int winid, QString profile, QWi m_refreshTimer.setSingleShot(true); m_refreshTimer.setInterval(100); connect(&m_refreshTimer, SIGNAL(timeout()), this, SLOT(refresh())); - connect(this, SIGNAL(multiStreamFound(const QString &,QList,QList,stringMap)), this, SLOT(slotMultiStreamProducerFound(const QString &,QList,QList,stringMap))); + connect(this, SIGNAL(multiStreamFound(QString,QList,QList,stringMap)), this, SLOT(slotMultiStreamProducerFound(QString,QList,QList,stringMap))); connect(this, SIGNAL(checkSeeking()), this, SLOT(slotCheckSeeking())); + connect(this, SIGNAL(mltFrameReceived(Mlt::Frame*)), this, SLOT(showFrame(Mlt::Frame*)), Qt::UniqueConnection); } Render::~Render() @@ -212,35 +223,34 @@ void Render::buildConsumer(const QString &profileName) setenv("MLT_PROFILE", m_activeProfile.toUtf8().constData(), 1); m_mltProfile->set_explicit(true); - m_blackClip = new Mlt::Producer(*m_mltProfile, "colour", "black"); + m_blackClip = new Mlt::Producer(*m_mltProfile, "colour:black"); m_blackClip->set("id", "black"); m_blackClip->set("mlt_type", "producer"); - - if (KdenliveSettings::external_display() && m_name != Kdenlive::clipMonitor) { -#ifdef USE_BLACKMAGIC + if (KdenliveSettings::external_display() && m_name != Kdenlive::clipMonitor && m_winid != 0) { // Use blackmagic card for video output - QMap< QString, QString > profileProperties = ProfilesDialog::getSettingsFromFile(profileName); int device = KdenliveSettings::blackmagic_output_device(); if (device >= 0) { - if (BMInterface::isSupportedProfile(device, profileProperties)) { - QString decklink = "decklink:" + QString::number(KdenliveSettings::blackmagic_output_device()); - if (!m_mltConsumer) { - m_mltConsumer = new Mlt::Consumer(*m_mltProfile, decklink.toUtf8().constData()); - m_showFrameEvent = m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show); - mlt_log_set_callback(kdenlive_callback); - } - if (m_mltConsumer->is_valid()) { - m_externalConsumer = true; - m_mltConsumer->set("terminate_on_pause", 0); - m_mltConsumer->set("deinterlace_method", "onefield"); - m_mltConsumer->set("real_time", KdenliveSettings::mltthreads()); - } - if (m_mltConsumer && m_mltConsumer->is_valid()) return; - } else KMessageBox::informationList(qApp->activeWindow(), i18n("Your project's profile %1 is not compatible with the blackmagic output card. Please see supported profiles below. Switching to normal video display.", m_mltProfile->description()), BMInterface::supportedModes(KdenliveSettings::blackmagic_output_device())); + QString decklink = "decklink:" + QString::number(KdenliveSettings::blackmagic_output_device()); + if (!m_mltConsumer) { + m_mltConsumer = new Mlt::Consumer(*m_mltProfile, decklink.toUtf8().constData()); + m_showFrameEvent = m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show); + mlt_log_set_callback(kdenlive_callback); + } + if (m_mltConsumer->is_valid()) { + externalConsumer = true; + m_mltConsumer->set("terminate_on_pause", 0); + m_mltConsumer->set("deinterlace_method", KdenliveSettings::mltdeinterlacer().toUtf8().constData()); + m_mltConsumer->set("rescale", KdenliveSettings::mltinterpolation().toUtf8().constData()); + m_mltConsumer->set("buffer", "1"); + m_mltConsumer->set("real_time", KdenliveSettings::mltthreads()); + } + if (m_mltConsumer && m_mltConsumer->is_valid()) { + return; + } + KMessageBox::information(qApp->activeWindow(), i18n("Your project's profile %1 is not compatible with the blackmagic output card. Please see supported profiles below. Switching to normal video display.", m_mltProfile->description())); } -#endif } - m_externalConsumer = false; + externalConsumer = false; QString videoDriver = KdenliveSettings::videodrivername(); if (!videoDriver.isEmpty()) { if (videoDriver == "x11_noaccel") { @@ -256,23 +266,41 @@ void Render::buildConsumer(const QString &profileName) if (m_winid == 0) { // OpenGL monitor if (!m_mltConsumer) { - m_mltConsumer = new Mlt::Consumer(*m_mltProfile, "sdl_audio"); + if (KdenliveSettings::external_display() && m_name != Kdenlive::clipMonitor) { + int device = KdenliveSettings::blackmagic_output_device(); + if (device >= 0) { + QString decklink = "decklink:" + QString::number(KdenliveSettings::blackmagic_output_device()); + m_mltConsumer = new Mlt::Consumer(*m_mltProfile, decklink.toUtf8().constData()); + // Set defaults for decklink consumer + if (m_mltConsumer) { + m_mltConsumer->set("terminate_on_pause", 0); + m_mltConsumer->set("deinterlace_method", KdenliveSettings::mltdeinterlacer().toUtf8().constData()); + externalConsumer = true; + } + } + } + if (!m_mltConsumer || !m_mltConsumer->is_valid()) { + m_mltConsumer = new Mlt::Consumer(*m_mltProfile, "sdl_audio"); + m_mltConsumer->set("scrub_audio", 1); + m_mltConsumer->set("preview_off", 1); + m_mltConsumer->set("audio_buffer", 512); + m_mltConsumer->set("preview_format", mlt_image_rgb24a); + } + m_mltConsumer->set("buffer", "1"); m_showFrameEvent = m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_gl_frame_show); } - m_mltConsumer->set("preview_off", 1); - m_mltConsumer->set("preview_format", mlt_image_rgb24a); } else { if (!m_mltConsumer) { m_mltConsumer = new Mlt::Consumer(*m_mltProfile, "sdl_preview"); m_showFrameEvent = m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show); - m_pauseEvent = m_mltConsumer->listen("consumer-sdl-paused", this, (mlt_listener) consumer_paused); + //m_pauseEvent = m_mltConsumer->listen("consumer-sdl-paused", this, (mlt_listener) consumer_paused); + m_mltConsumer->set("progressive", 1); } m_mltConsumer->set("window_id", m_winid); } - m_mltConsumer->set("resize", 1); - m_mltConsumer->set("terminate_on_pause", 1); + //m_mltConsumer->set("resize", 1); m_mltConsumer->set("window_background", KdenliveSettings::window_background().name().toUtf8().constData()); - m_mltConsumer->set("rescale", "nearest"); + m_mltConsumer->set("rescale", KdenliveSettings::mltinterpolation().toUtf8().constData()); mlt_log_set_callback(kdenlive_callback); QString audioDevice = KdenliveSettings::audiodevicename(); @@ -293,8 +321,6 @@ void Render::buildConsumer(const QString &profileName) if (!audioDriver.isEmpty()) m_mltConsumer->set("audio_driver", audioDriver.toUtf8().constData()); - m_mltConsumer->set("progressive", 1); - m_mltConsumer->set("audio_buffer", 1024); m_mltConsumer->set("frequency", 48000); m_mltConsumer->set("real_time", KdenliveSettings::mltthreads()); } @@ -325,7 +351,7 @@ int Render::resetProfile(const QString &profileName, bool dropSceneList) { m_refreshTimer.stop(); if (m_mltConsumer) { - if (m_externalConsumer == KdenliveSettings::external_display()) { + if (externalConsumer == KdenliveSettings::external_display()) { if (KdenliveSettings::external_display() && m_activeProfile == profileName) return 1; QString videoDriver = KdenliveSettings::videodrivername(); QString currentDriver = m_mltConsumer->get("video_driver"); @@ -387,7 +413,7 @@ int Render::resetProfile(const QString &profileName, bool dropSceneList) void Render::seek(GenTime time) { - if (!m_mltProducer) + if (!m_mltProducer || !m_isActive) return; int pos = time.frames(m_fps); seek(pos); @@ -396,12 +422,21 @@ void Render::seek(GenTime time) void Render::seek(int time) { resetZoneMode(); + time = qMax(0, 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) { - refresh(); + if (m_paused && !externalConsumer) { + m_mltConsumer->set("refresh", 1); + m_paused = false; + } + else if (m_winid != 0 && m_mltProducer->get_speed() == 0) { + // workaround specific bug in MLT's SDL consumer + m_mltConsumer->stop(); + m_mltConsumer->start(); + m_mltConsumer->set("refresh", 1); } } else requestedSeekPosition = time; @@ -531,7 +566,7 @@ void Render::slotSplitView(bool doit) if (service.type() != tractor_type || tractor.count() < 2) return; Mlt::Field *field = tractor.field(); if (doit) { - for (int i = 1, screen = 0; i < tractor.count() && screen < 4; i++) { + for (int i = 1, screen = 0; i < tractor.count() && screen < 4; ++i) { Mlt::Producer trackProducer(tractor.track(i)); kDebug() << "// TRACK: " << i << ", HIDE: " << trackProducer.get("hide"); if (QString(trackProducer.get("hide")).toInt() != 1) { @@ -593,14 +628,24 @@ void Render::slotSplitView(bool doit) void Render::getFileProperties(const QDomElement &xml, const QString &clipId, int imageHeight, bool replaceProducer) { + // Make sure we don't request the info for same clip twice + m_infoMutex.lock(); + if (m_processingClipId.contains(clipId)) { + m_infoMutex.unlock(); + return; + } + for (int i = 0; i < m_requestList.count(); ++i) { + if (m_requestList.at(i).clipId == clipId) { + // Clip is already queued + m_infoMutex.unlock(); + return; + } + } requestClipInfo info; info.xml = xml; info.clipId = clipId; info.imageHeight = imageHeight; info.replaceProducer = replaceProducer; - // Make sure we don't request the info for same clip twice - m_infoMutex.lock(); - m_requestList.removeAll(info); m_requestList.append(info); m_infoMutex.unlock(); if (!m_infoThread.isRunning()) { @@ -610,9 +655,9 @@ void Render::getFileProperties(const QDomElement &xml, const QString &clipId, in void Render::forceProcessing(const QString &id) { - if (m_processingClipId == id) return; + if (m_processingClipId.contains(id)) return; QMutexLocker lock(&m_infoMutex); - for (int i = 0; i < m_requestList.count(); i++) { + for (int i = 0; i < m_requestList.count(); ++i) { requestClipInfo info = m_requestList.at(i); if (info.clipId == id) { if (i == 0) break; @@ -628,21 +673,22 @@ void Render::forceProcessing(const QString &id) int Render::processingItems() { QMutexLocker lock(&m_infoMutex); - int count = m_requestList.count(); - if (!m_processingClipId.isEmpty()) { - // one clip is currently processed - count++; - } + int count = m_requestList.count() + m_processingClipId.count(); return count; } +void Render::processingDone(const QString &id) +{ + QMutexLocker lock(&m_infoMutex); + m_processingClipId.removeAll(id); +} + bool Render::isProcessing(const QString &id) { - if (m_processingClipId == id) return true; + if (m_processingClipId.contains(id)) return true; QMutexLocker lock(&m_infoMutex); - for (int i = 0; i < m_requestList.count(); i++) { - requestClipInfo info = m_requestList.at(i); - if (info.clipId == id) { + for (int i = 0; i < m_requestList.count(); ++i) { + if (m_requestList.at(i).clipId == id) { return true; } } @@ -656,7 +702,7 @@ void Render::processFileProperties() while (!m_requestList.isEmpty()) { m_infoMutex.lock(); info = m_requestList.takeFirst(); - m_processingClipId = info.clipId; + m_processingClipId.append(info.clipId); m_infoMutex.unlock(); QString path; @@ -707,7 +753,7 @@ void Render::processFileProperties() if (producer == NULL || producer->is_blank() || !producer->is_valid()) { kDebug() << " / / / / / / / / ERROR / / / / // CANNOT LOAD PRODUCER: "<set("out", info.xml.attribute("proxy_out").toInt()); if (producer->get_out() != info.xml.attribute("proxy_out").toInt()) { // Proxy file length is different than original clip length, this will corrupt project so disable this proxy clip - m_processingClipId.clear(); + m_processingClipId.removeAll(info.clipId); emit removeInvalidProxy(info.clipId, true); delete producer; continue; @@ -790,9 +836,17 @@ void Render::processFileProperties() length = info.xml.attribute("length").toInt(); clipOut = length - 1; } - else length = info.xml.attribute("out").toInt() - info.xml.attribute("in").toInt(); - producer->set("length", length); - duration = length; + else length = info.xml.attribute("out").toInt() - info.xml.attribute("in").toInt() + 1; + // Pass duration if it was forced + if (info.xml.hasAttribute("duration")) { + duration = info.xml.attribute("duration").toInt(); + if (length < duration) { + length = duration; + if (clipOut > 0) clipOut = length - 1; + } + } + if (duration == 0) duration = length; + producer->set("length", length); } if (clipOut > 0) producer->set_in_and_out(info.xml.attribute("in").toInt(), clipOut); @@ -818,7 +872,6 @@ void Render::processFileProperties() } if (frame) delete frame; } - m_processingClipId.clear(); emit replyGetFileProperties(info.clipId, producer, stringMap(), stringMap(), info.replaceProducer); continue; } @@ -900,7 +953,7 @@ void Render::processFileProperties() int streams = producer->get_int("meta.media.nb_streams"); QList audio_list; QList video_list; - for (int i = 0; i < streams; i++) { + for (int i = 0; i < streams; ++i) { QByteArray propertyName = QString("meta.media.%1.stream.type").arg(i).toLocal8Bit(); QString type = producer->get(propertyName.data()); if (type == "audio") audio_list.append(i); @@ -933,15 +986,20 @@ void Render::processFileProperties() Mlt::Frame *frame = producer->get_frame(); if (frame && frame->is_valid()) { filePropertyMap["frame_size"] = QString::number(frame->get_int("width")) + 'x' + QString::number(frame->get_int("height")); - filePropertyMap["frequency"] = QString::number(frame->get_int("frequency")); - filePropertyMap["channels"] = QString::number(frame->get_int("channels")); + int af = frame->get_int("audio_frequency"); + int ac = frame->get_int("audio_channels"); + // keep for compatibility with MLT <= 0.8.6 + if (af == 0) af = frame->get_int("frequency"); + if (ac == 0) ac = frame->get_int("channels"); + if (af > 0) filePropertyMap["frequency"] = QString::number(af); + if (ac > 0) filePropertyMap["channels"] = QString::number(ac); if (!filePropertyMap.contains("aspect_ratio")) filePropertyMap["aspect_ratio"] = frame->get("aspect_ratio"); if (frame->get_int("test_image") == 0) { if (mltService == "xml" || mltService == "consumer") { filePropertyMap["type"] = "playlist"; metadataPropertyMap["comment"] = QString::fromUtf8(producer->get("title")); - } else if (frame->get_int("test_audio") == 0) + } else if (!mlt_frame_is_test_audio(frame->get_frame())) filePropertyMap["type"] = "av"; else filePropertyMap["type"] = "video"; @@ -1005,10 +1063,10 @@ void Render::processFileProperties() snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", vindex); if (producer->get(property)) { filePropertyMap["videocodec"] = producer->get(property); - } else { - snprintf(property, sizeof(property), "meta.media.%d.codec.name", vindex); - if (producer->get(property)) - filePropertyMap["videocodec"] = producer->get(property); + } + snprintf(property, sizeof(property), "meta.media.%d.codec.name", vindex); + if (producer->get(property)) { + filePropertyMap["videocodecid"] = producer->get(property); } QString query; query = QString("meta.media.%1.codec.pix_fmt").arg(vindex); @@ -1037,14 +1095,12 @@ void Render::processFileProperties() for (int i = 0; i < count; i ++) { QString name = metadata.get_name(i); QString value = QString::fromUtf8(metadata.get(i)); - if (name.endsWith("markup") && !value.isEmpty()) + if (name.endsWith(".markup") && !value.isEmpty()) metadataPropertyMap[ name.section('.', 0, -2)] = value; } producer->seek(0); - m_processingClipId.clear(); emit replyGetFileProperties(info.clipId, producer, filePropertyMap, metadataPropertyMap, info.replaceProducer); } - m_processingClipId.clear(); } @@ -1086,6 +1142,12 @@ void Render::initSceneList() } #endif +void Render::loadUrl(const QString &url) +{ + Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile, url.toUtf8().constData()); + setProducer(producer, 0); +} + int Render::setProducer(Mlt::Producer *producer, int position) { m_refreshTimer.stop(); @@ -1187,11 +1249,7 @@ void Render::startConsumer() { return; } 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 - Mlt::Event *ev = m_mltConsumer->setup_wait_for("consumer-frame-show"); - m_mltConsumer->wait_for(ev); - delete ev; + m_isActive = true; } int Render::setSceneList(QDomDocument list, int position) @@ -1280,6 +1338,7 @@ int Render::setSceneList(QString playlist, int position) m_mltProducer = m_blackClip->cut(0, 1); error = -1; } + m_mltProducer->set("eof", "pause"); checkMaxThreads(); int volume = KdenliveSettings::volume(); m_mltProducer->set("meta.volume", (double)volume / 100); @@ -1416,7 +1475,7 @@ void Render::saveZone(KUrl url, QString desc, QPoint zone) } -bool Render::saveClip(int track, GenTime position, KUrl url, QString desc) +bool Render::saveClip(int track, const GenTime &position, const KUrl &url, const QString &desc) { // find clip Mlt::Service service(m_mltProducer->parent().get_service()); @@ -1493,7 +1552,10 @@ void Render::start() kDebug() << "----- BROKEN MONITOR: " << m_name << ", RESTART"; return; } - if (!m_mltConsumer) return; + if (!m_mltConsumer) { + kDebug()<<" / - - - STARTED BEFORE CONSUMER!!!"; + return; + } if (m_mltConsumer->is_stopped()) { if (m_mltConsumer->start() == -1) { //KMessageBox::error(qApp->activeWindow(), i18n("Could not create the video preview window.\nThere is something wrong with your Kdenlive install or your driver settings, please fix it.")); @@ -1510,9 +1572,11 @@ void Render::stop() requestedSeekPosition = SEEK_INACTIVE; m_refreshTimer.stop(); QMutexLocker locker(&m_mutex); + m_isActive = false; if (m_mltProducer == NULL) return; - if (m_mltConsumer && !m_mltConsumer->is_stopped()) { - m_mltConsumer->stop(); + if (m_mltConsumer) { + m_mltConsumer->set("refresh", 0); + if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop(); m_mltConsumer->purge(); } @@ -1527,6 +1591,7 @@ void Render::stop(const GenTime & startTime) requestedSeekPosition = SEEK_INACTIVE; m_refreshTimer.stop(); QMutexLocker locker(&m_mutex); + m_isActive = false; if (m_mltProducer) { if (m_isZoneMode) resetZoneMode(); m_mltProducer->set_speed(0.0); @@ -1538,44 +1603,57 @@ void Render::stop(const GenTime & startTime) void Render::pause() { requestedSeekPosition = SEEK_INACTIVE; - if (!m_mltProducer || !m_mltConsumer) + if (!m_mltProducer || !m_mltConsumer || !m_isActive) return; m_paused = true; m_mltProducer->set_speed(0.0); - m_mltConsumer->set("refresh", 0); - if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop(); - m_mltProducer->seek(m_mltConsumer->position()); + /*m_mltConsumer->set("refresh", 0); + //if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop(); + m_mltProducer->seek(m_mltConsumer->position());*/ +} + +void Render::setActiveMonitor() +{ + if (!m_isActive) emit activateMonitor(m_name); } void Render::switchPlay(bool play) { QMutexLocker locker(&m_mutex); requestedSeekPosition = SEEK_INACTIVE; - if (!m_mltProducer || !m_mltConsumer) + if (!m_mltProducer || !m_mltConsumer || !m_isActive) return; if (m_isZoneMode) resetZoneMode(); if (play && m_paused) { if (m_name == Kdenlive::clipMonitor && m_mltConsumer->position() == m_mltProducer->get_out()) m_mltProducer->seek(0); m_paused = false; + m_mltProducer->set_speed(1.0); if (m_mltConsumer->is_stopped()) { m_mltConsumer->start(); } - m_mltProducer->set_speed(1.0); m_mltConsumer->set("refresh", 1); } else if (!play) { m_paused = true; - m_mltProducer->set_speed(0.0); - m_mltConsumer->set("refresh", 0); - if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop(); - m_mltProducer->seek(m_mltConsumer->position()); + if (m_winid == 0) { + // OpenGL consumer + m_mltProducer->set_speed(0.0); + } + else { + // SDL consumer, hack to allow pausing near the end of the playlist + m_mltConsumer->set("refresh", 0); + m_mltConsumer->stop(); + m_mltProducer->set_speed(0.0); + m_mltProducer->seek(m_mltConsumer->position()); + m_mltConsumer->start(); + } } } void Render::play(double speed) { requestedSeekPosition = SEEK_INACTIVE; - if (!m_mltProducer) return; - double current_speed = m_mltProducer->get_speed(); + if (!m_mltProducer || !m_isActive) return; + double current_speed = m_mltProducer->get_speed(); if (current_speed == speed) return; if (m_isZoneMode) resetZoneMode(); // if (speed == 0.0) m_mltProducer->set("out", m_mltProducer->get_length() - 1); @@ -1590,7 +1668,7 @@ void Render::play(double speed) void Render::play(const GenTime & startTime) { requestedSeekPosition = SEEK_INACTIVE; - if (!m_mltProducer || !m_mltConsumer) + if (!m_mltProducer || !m_mltConsumer || !m_isActive) return; m_paused = false; m_mltProducer->seek((int)(startTime.frames(m_fps))); @@ -1601,7 +1679,7 @@ void Render::play(const GenTime & startTime) void Render::loopZone(const GenTime & startTime, const GenTime & stopTime) { requestedSeekPosition = SEEK_INACTIVE; - if (!m_mltProducer || !m_mltConsumer) + if (!m_mltProducer || !m_mltConsumer || !m_isActive) return; //m_mltProducer->set("eof", "loop"); m_isLoopMode = true; @@ -1612,14 +1690,14 @@ void Render::loopZone(const GenTime & startTime, const GenTime & stopTime) void Render::playZone(const GenTime & startTime, const GenTime & stopTime) { requestedSeekPosition = SEEK_INACTIVE; - if (!m_mltProducer || !m_mltConsumer) + if (!m_mltProducer || !m_mltConsumer || !m_isActive) return; m_mltProducer->set("out", (int)(stopTime.frames(m_fps))); m_mltProducer->seek((int)(startTime.frames(m_fps))); m_paused = false; m_mltProducer->set_speed(1.0); - m_mltConsumer->set("refresh", 1); if (m_mltConsumer->is_stopped()) m_mltConsumer->start(); + m_mltConsumer->set("refresh", 1); m_isZoneMode = true; } @@ -1627,14 +1705,13 @@ 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; } void Render::seekToFrame(int pos) { - if (!m_mltProducer) + if (!m_mltProducer || !m_isActive) return; resetZoneMode(); seek(pos); @@ -1642,7 +1719,7 @@ void Render::seekToFrame(int pos) void Render::seekToFrameDiff(int diff) { - if (!m_mltProducer) + if (!m_mltProducer || !m_isActive) return; resetZoneMode(); if (requestedSeekPosition == SEEK_INACTIVE) @@ -1652,24 +1729,24 @@ void Render::seekToFrameDiff(int diff) void Render::refreshIfActive() { - if (!m_mltConsumer->is_stopped() && m_mltProducer && m_paused) m_refreshTimer.start(); + if (!m_mltConsumer->is_stopped() && m_mltProducer && m_paused && m_isActive) m_refreshTimer.start(); } void Render::doRefresh() { - if (m_mltProducer && m_paused) m_refreshTimer.start(); + if (m_mltProducer && m_paused && m_isActive) m_refreshTimer.start(); } void Render::refresh() { + m_refreshTimer.stop(); QMutexLocker locker(&m_mutex); - if (!m_mltProducer) + if (!m_mltProducer || !m_isActive) return; if (m_mltConsumer) { if (m_mltConsumer->is_stopped()) m_mltConsumer->start(); - m_paused = false; + m_mltConsumer->set("refresh", 1); //m_mltConsumer->purge(); - m_mltConsumer->set("refresh", 1); } } @@ -1680,11 +1757,7 @@ void Render::setDropFrames(bool show) int dropFrames = KdenliveSettings::mltthreads(); if (show == false) dropFrames = -dropFrames; m_mltConsumer->stop(); - if (m_winid == 0) - m_mltConsumer->set("real_time", dropFrames); - else - m_mltConsumer->set("play.real_time", dropFrames); - + m_mltConsumer->set("real_time", dropFrames); if (m_mltConsumer->start() == -1) { kDebug(QtWarningMsg) << "ERROR, Cannot start monitor"; } @@ -1692,6 +1765,19 @@ void Render::setDropFrames(bool show) } } +void Render::setConsumerProperty(const QString &name, const QString &value) +{ + QMutexLocker locker(&m_mutex); + if (m_mltConsumer) { + m_mltConsumer->stop(); + m_mltConsumer->set(name.toUtf8().constData(), value.toUtf8().constData()); + if (m_isActive && m_mltConsumer->start() == -1) { + kDebug(QtWarningMsg) << "ERROR, Cannot start monitor"; + } + + } +} + bool Render::isPlaying() const { if (!m_mltConsumer || m_mltConsumer->is_stopped()) return false; @@ -1720,33 +1806,43 @@ int Render::seekFramePosition() const void Render::emitFrameUpdated(Mlt::Frame& frame) { - mlt_image_format format = mlt_image_rgb24a; + mlt_image_format format = mlt_image_rgb24; int width = 0; int height = 0; const uchar* image = frame.get_image(format, width, height); - QImage qimage(width, height, QImage::Format_ARGB32_Premultiplied); - memcpy(qimage.scanLine(0), image, width * height * 4); - emit frameUpdated(qimage.rgbSwapped()); + QImage qimage(width, height, QImage::Format_RGB888); //Format_ARGB32_Premultiplied); + memcpy(qimage.scanLine(0), image, width * height * 3); + emit frameUpdated(qimage); +} + +int Render::getCurrentSeekPosition() const +{ + if (requestedSeekPosition != SEEK_INACTIVE) return requestedSeekPosition; + return (int) m_mltProducer->position(); } void Render::emitFrameNumber() { int currentPos = m_mltConsumer->position(); - if (currentPos == requestedSeekPosition) requestedSeekPosition = SEEK_INACTIVE; + if (currentPos == requestedSeekPosition) { + requestedSeekPosition = SEEK_INACTIVE; + m_paused = true; + } emit rendererPosition(currentPos); if (requestedSeekPosition != SEEK_INACTIVE) { + m_mltConsumer->purge(); m_mltProducer->seek(requestedSeekPosition); - if (m_paused) { - refresh(); + if (m_mltProducer->get_speed() == 0 && !m_paused) { + m_mltConsumer->set("refresh", 1); } requestedSeekPosition = SEEK_INACTIVE; } } -void Render::emitConsumerStopped() +void Render::emitConsumerStopped(bool forcePause) { // This is used to know when the playing stopped - if (m_mltProducer) { + if (m_mltProducer && (forcePause || (!m_paused && m_mltProducer->get_speed() == 0))) { double pos = m_mltProducer->position(); m_paused = true; if (m_isLoopMode) play(m_loopStart); @@ -1760,7 +1856,7 @@ void Render::exportFileToFirewire(QString /*srcFileName*/, int /*port*/, GenTime KMessageBox::sorry(0, i18n("Firewire is not enabled on your system.\n Please install Libiec61883 and recompile Kdenlive")); } -void Render::exportCurrentFrame(KUrl url, bool /*notify*/) +void Render::exportCurrentFrame(const KUrl &url, bool /*notify*/) { if (!m_mltProducer) { KMessageBox::sorry(qApp->activeWindow(), i18n("There is no clip, cannot extract frame.")); @@ -1787,24 +1883,26 @@ void Render::exportCurrentFrame(KUrl url, bool /*notify*/) } -void Render::showFrame(Mlt::Frame& frame) +void Render::showFrame(Mlt::Frame* frame) { int currentPos = m_mltConsumer->position(); if (currentPos == requestedSeekPosition) requestedSeekPosition = SEEK_INACTIVE; emit rendererPosition(currentPos); - if (frame.is_valid()) { - mlt_image_format format = mlt_image_rgb24a; + if (frame->is_valid()) { + mlt_image_format format = mlt_image_rgb24; int width = 0; int height = 0; - const uchar* image = frame.get_image(format, width, height); - QImage qimage(width, height, QImage::Format_ARGB32_Premultiplied); - memcpy(qimage.scanLine(0), image, width * height * 4); + const uchar* image = frame->get_image(format, width, height); + QImage qimage(width, height, QImage::Format_RGB888); //Format_ARGB32_Premultiplied); + memcpy(qimage.scanLine(0), image, width * height * 3); + if (analyseAudio) showAudio(*frame); + delete frame; emit showImageSignal(qimage); - if (analyseAudio) showAudio(frame); - if (sendFrameForAnalysis && frame.get_frame()->convert_image) { - emit frameUpdated(qimage.rgbSwapped()); + if (sendFrameForAnalysis) { + emit frameUpdated(qimage); } - } + } else delete frame; + showFrameSemaphore.release(); emit checkSeeking(); } @@ -1834,6 +1932,7 @@ void Render::showAudio(Mlt::Frame& frame) if (!frame.is_valid() || frame.get_int("test_audio") != 0) { return; } + mlt_audio_format audio_format = mlt_audio_s16; //FIXME: should not be hardcoded.. int freq = 48000; @@ -1909,6 +2008,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); } @@ -1992,6 +2095,7 @@ int Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *pro int clipIndex = trackPlaylist.get_clip_index_at(insertPos); trackPlaylist.insert_blank(clipIndex, cutDuration); } + trackPlaylist.consolidate_blanks(0); int newIndex = trackPlaylist.insert_at(insertPos, clip, 1); delete clip; /*if (QString(prod->get("transparency")).toInt() == 1) @@ -2005,7 +2109,7 @@ int Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *pro } -bool Render::mltCutClip(int track, GenTime position) +bool Render::mltCutClip(int track, const GenTime &position) { Mlt::Service service(m_mltProducer->parent().get_service()); if (service.type() != tractor_type) { @@ -2020,7 +2124,7 @@ bool Render::mltCutClip(int track, GenTime position) /* // Display playlist info kDebug()<<"//////////// BEFORE"; - for (int i = 0; i < trackPlaylist.count(); i++) { + for (int i = 0; i < trackPlaylist.count(); ++i) { int blankStart = trackPlaylist.clip_start(i); int blankDuration = trackPlaylist.clip_length(i) - 1; QString blk; @@ -2065,7 +2169,7 @@ bool Render::mltCutClip(int track, GenTime position) Mlt::Filter *dup = new Mlt::Filter(*m_mltProfile, filter->get("mlt_service")); if (dup && dup->is_valid()) { Mlt::Properties entries(filter->get_properties()); - for (int i = 0; i < entries.count(); i++) { + for (int i = 0; i < entries.count(); ++i) { dup->set(entries.get_name(i), entries.get(i)); } dupService.attach(*dup); @@ -2077,7 +2181,7 @@ bool Render::mltCutClip(int track, GenTime position) return true; /* // Display playlist info kDebug()<<"//////////// AFTER"; - for (int i = 0; i < trackPlaylist.count(); i++) { + for (int i = 0; i < trackPlaylist.count(); ++i) { int blankStart = trackPlaylist.clip_start(i); int blankDuration = trackPlaylist.clip_length(i) - 1; QString blk; @@ -2161,7 +2265,7 @@ bool Render::mltUpdateClip(Mlt::Tractor *tractor, ItemInfo info, QDomElement ele delete clip2; if (!filtersList.isEmpty()) { - for (int i = 0; i < filtersList.count(); i++) + for (int i = 0; i < filtersList.count(); ++i) destService.attach(*(filtersList.at(i))); } return true; @@ -2171,12 +2275,13 @@ 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"; return false; } - //service.lock(); + service.lock(); Mlt::Tractor tractor(service); Mlt::Producer trackProducer(tractor.track(track)); Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service()); @@ -2184,7 +2289,7 @@ bool Render::mltRemoveClip(int track, GenTime position) if (trackPlaylist.is_blank(clipIndex)) { kDebug() << "// WARNING, TRYING TO REMOVE A BLANK: " << position.frames(m_fps); - //service.unlock(); + service.unlock(); return false; } Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex); @@ -2193,14 +2298,14 @@ bool Render::mltRemoveClip(int track, GenTime position) /* // Display playlist info kDebug()<<"//// AFTER"; - for (int i = 0; i < trackPlaylist.count(); i++) { + for (int i = 0; i < trackPlaylist.count(); ++i) { int blankStart = trackPlaylist.clip_start(i); int blankDuration = trackPlaylist.clip_length(i) - 1; QString blk; if (trackPlaylist.is_blank(i)) blk = "(blank)"; kDebug()<<"CLIP "< trackClipStartList, QMap /* kDebug()<<"-------------\nTRACK "<is_valid()) { + kDebug()<<"// Something is wrong with producer"; + return -1; + } service.lock(); Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex); @@ -2747,10 +2856,10 @@ bool Render::mltAddEffect(Mlt::Service service, EffectsParameterList params, int filter = service.filter(ct); } - addFilterToService(service, params, duration); + bool success = addFilterToService(service, params, duration); // re-add following filters - for (int i = 0; i < filtersList.count(); i++) { + for (int i = 0; i < filtersList.count(); ++i) { Mlt::Filter *filter = filtersList.at(i); if (updateIndex) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") + 1); @@ -2758,7 +2867,7 @@ bool Render::mltAddEffect(Mlt::Service service, EffectsParameterList params, int } service.unlock(); if (doRefresh) refresh(); - return true; + return success; } @@ -2767,10 +2876,8 @@ bool Render::addFilterToService(Mlt::Service service, EffectsParameterList param // create filter QString tag = params.paramValue("tag"); //kDebug() << " / / INSERTING EFFECT: " << tag << ", REGI: " << region; - char *filterTag = qstrdup(tag.toUtf8().constData()); - char *filterId = qstrdup(params.paramValue("id").toUtf8().constData()); QString kfr = params.paramValue("keyframes"); - if (!kfr.isEmpty()) { + if (!kfr.isEmpty()) { QStringList keyFrames = kfr.split(';', QString::SkipEmptyParts); //kDebug() << "// ADDING KEYFRAME EFFECT: " << params.paramValue("keyframes"); char *starttag = qstrdup(params.paramValue("starttag", "start").toUtf8().constData()); @@ -2790,9 +2897,9 @@ bool Render::addFilterToService(Mlt::Service service, EffectsParameterList param int offset = 0; // Special case, only one keyframe, means we want a constant value if (keyFrames.count() == 1) { - Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag); + Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, qstrdup(tag.toUtf8().constData())); if (filter && filter->is_valid()) { - filter->set("kdenlive_id", filterId); + filter->set("kdenlive_id", qstrdup(params.paramValue("id").toUtf8().constData())); int x1 = keyFrames.at(0).section(':', 0, 0).toInt(); double y1 = keyFrames.at(0).section(':', 1, 1).toDouble(); for (int j = 0; j < params.count(); j++) { @@ -2802,11 +2909,17 @@ bool Render::addFilterToService(Mlt::Service service, EffectsParameterList param //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<set(starttag, m_locale.toString(((min + y1) - paramOffset) / factor).toUtf8().data()); service.attach(*filter); - } + } else { + delete[] starttag; + delete[] endtag; + kDebug() << "filter is NULL"; + service.unlock(); + return false; + } } else for (int i = 0; i < keyFrames.size() - 1; ++i) { - Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag); + Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, qstrdup(tag.toUtf8().constData())); if (filter && filter->is_valid()) { - filter->set("kdenlive_id", filterId); + filter->set("kdenlive_id", qstrdup(params.paramValue("id").toUtf8().constData())); int x1 = keyFrames.at(i).section(':', 0, 0).toInt() + offset; double y1 = keyFrames.at(i).section(':', 1, 1).toDouble(); int x2 = keyFrames.at(i + 1).section(':', 0, 0).toInt(); @@ -2824,16 +2937,22 @@ bool Render::addFilterToService(Mlt::Service service, EffectsParameterList param filter->set(endtag, m_locale.toString(((min + y2) - paramOffset) / factor).toUtf8().data()); service.attach(*filter); offset = 1; - } + } else { + delete[] starttag; + delete[] endtag; + kDebug() << "filter is NULL"; + service.unlock(); + return false; + } } delete[] starttag; delete[] endtag; } else { Mlt::Filter *filter; QString prefix; - filter = new Mlt::Filter(*m_mltProfile, filterTag); + filter = new Mlt::Filter(*m_mltProfile, qstrdup(tag.toUtf8().constData())); if (filter && filter->is_valid()) { - filter->set("kdenlive_id", filterId); + filter->set("kdenlive_id", qstrdup(params.paramValue("id").toUtf8().constData())); } else { kDebug() << "filter is NULL"; service.unlock(); @@ -2868,9 +2987,6 @@ bool Render::addFilterToService(Mlt::Service service, EffectsParameterList param // attach filter to the clip service.attach(*filter); } - - delete[] filterId; - delete[] filterTag; return true; } @@ -3190,7 +3306,7 @@ void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos) } } - for (int i = 0; i < filtersList.count(); i++) { + for (int i = 0; i < filtersList.count(); ++i) { clipService.attach(*(filtersList.at(i))); } @@ -3251,13 +3367,13 @@ void Render::mltMoveTrackEffect(int track, int oldPos, int newPos) } } - for (int i = 0; i < filtersList.count(); i++) { + for (int i = 0; i < filtersList.count(); ++i) { clipService.attach(*(filtersList.at(i))); } 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); @@ -3266,7 +3382,7 @@ bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration) /* // Display playlist info kDebug()<<"//////////// BEFORE RESIZE"; - for (int i = 0; i < trackPlaylist.count(); i++) { + for (int i = 0; i < trackPlaylist.count(); ++i) { int blankStart = trackPlaylist.clip_start(i); int blankDuration = trackPlaylist.clip_length(i) - 1; QString blk; @@ -3335,7 +3451,7 @@ bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration) transpinfo.track = info.track; mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt()); }*/ - m_mltConsumer->set("refresh", 1); + if (refresh) m_mltConsumer->set("refresh", 1); return true; } @@ -3375,7 +3491,7 @@ void Render::mltChangeTrackState(int track, bool mute, bool blind) int Render::getLowestNonMutedAudioTrack(Mlt::Tractor tractor) { - for (int i = 1; i < tractor.count(); i++) { + for (int i = 1; i < tractor.count(); ++i) { Mlt::Producer trackProducer(tractor.track(i)); if (trackProducer.get_int("hide") < 2) return i; } @@ -3412,7 +3528,7 @@ void Render::fixAudioMixing(Mlt::Tractor tractor) } // Re-add correct audio transitions - for (int i = lowestTrack + 1; i < tractor.count(); i++) { + for (int i = lowestTrack + 1; i < tractor.count(); ++i) { Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix"); transition->set("always_active", 1); transition->set("combine", 1); @@ -3581,6 +3697,12 @@ bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEn bool checkLength = false; if (endTrack == startTrack) { Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex); + if (!clipProducer) { + kDebug() << "// Cannot get clip at index: "<is_valid() || clipProducer->is_blank()) { @@ -3606,12 +3728,12 @@ bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEn service.unlock(); return false; } - } - - if (overwrite) { + } else { + // Overwrite mode trackPlaylist.remove_region(moveEnd, clipProducer->get_playtime()); - int clipIndex = trackPlaylist.get_clip_index_at(moveEnd); - trackPlaylist.insert_blank(clipIndex, clipProducer->get_playtime() - 1); + int ix = trackPlaylist.get_clip_index_at(moveEnd); + trackPlaylist.insert_blank(ix, clipProducer->get_playtime() - 1); + trackPlaylist.consolidate_blanks(0); } int newIndex = trackPlaylist.insert_at(moveEnd, clipProducer, 1); if (newIndex == -1) { @@ -3621,9 +3743,9 @@ bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEn service.unlock(); return false; } - trackPlaylist.consolidate_blanks(1); + trackPlaylist.consolidate_blanks(0); delete clipProducer; - if (newIndex + 1 == trackPlaylist.count()) checkLength = true; + if (newIndex + 1 >= trackPlaylist.count()) checkLength = true; } else { Mlt::Producer destTrackProducer(tractor.track(endTrack)); Mlt::Playlist destTrackPlaylist((mlt_playlist) destTrackProducer.get_service()); @@ -3667,6 +3789,7 @@ bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEn destTrackPlaylist.remove_region(moveEnd, clip->get_playtime()); int clipIndex = destTrackPlaylist.get_clip_index_at(moveEnd); destTrackPlaylist.insert_blank(clipIndex, clip->get_playtime() - 1); + destTrackPlaylist.consolidate_blanks(0); } int newIndex = destTrackPlaylist.insert_at(moveEnd, clip, 1); @@ -3709,7 +3832,7 @@ QList Render::checkTrackSequence(int track) Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service()); int clipNb = trackPlaylist.count(); //kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb; - for (int i = 0; i < clipNb; i++) { + for (int i = 0; i < clipNb; ++i) { Mlt::Producer *c = trackPlaylist.get_clip(i); int pos = trackPlaylist.clip_start(i); if (!list.contains(pos)) list.append(pos); @@ -3762,11 +3885,11 @@ bool Render::mltMoveTransition(QString type, int startTrack, int newTrack, int n Mlt::Properties trans_props(transition.get_properties()); Mlt::Transition new_transition(*m_mltProfile, transition.get("mlt_service")); Mlt::Properties new_trans_props(new_transition.get_properties()); - new_trans_props.inherit(trans_props); - new_transition.set_in_and_out(new_in, new_out); + // We cannot use MLT's property inherit because it also clones internal values like _unique_id which messes up the playlist + cloneProperties(new_trans_props, trans_props); + new_transition.set_in_and_out(new_in, new_out); field->disconnect_service(transition); mltPlantTransition(field, new_transition, newTransitionTrack, newTrack); - //field->plant_transition(new_transition, newTransitionTrack, newTrack); } else transition.set_in_and_out(new_in, new_out); break; } @@ -3781,6 +3904,20 @@ bool Render::mltMoveTransition(QString type, int startTrack, int newTrack, int n return found; } +void Render::cloneProperties(Mlt::Properties &dest, Mlt::Properties &source) +{ + int count = source.count(); + int i = 0; + for ( i = 0; i < count; i ++ ) + { + char *value = source.get(i); + if ( value != NULL ) + { + char *name = source.get_name( i ); + if (name != NULL && name[0] != '_') dest.set(name, value); + } + } +} void Render::mltPlantTransition(Mlt::Field *field, Mlt::Transition &tr, int a_track, int b_track) { @@ -3802,7 +3939,8 @@ void Render::mltPlantTransition(Mlt::Field *field, Mlt::Transition &tr, int a_tr Mlt::Properties trans_props(transition.get_properties()); Mlt::Transition *cp = new Mlt::Transition(*m_mltProfile, transition.get("mlt_service")); Mlt::Properties new_trans_props(cp->get_properties()); - new_trans_props.inherit(trans_props); + //new_trans_props.inherit(trans_props); + cloneProperties(new_trans_props, trans_props); trList.append(cp); field->disconnect_service(transition); } @@ -3816,7 +3954,7 @@ void Render::mltPlantTransition(Mlt::Field *field, Mlt::Transition &tr, int a_tr field->plant_transition(tr, a_track, b_track); // re-add upper transitions - for (int i = trList.count() - 1; i >= 0; i--) { + for (int i = trList.count() - 1; i >= 0; --i) { //kDebug()<< "REPLANT ON TK: "<get_a_track()<<", "<get_b_track(); field->plant_transition(*trList.at(i), trList.at(i)->get_a_track(), trList.at(i)->get_b_track()); } @@ -3869,7 +4007,7 @@ void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, G QStringList permanentProps; permanentProps << "factory" << "kdenlive_id" << "mlt_service" << "mlt_type" << "in"; permanentProps << "out" << "a_track" << "b_track"; - for (int i = 0; i < mlt_properties_count(transproperties); i++) { + for (int i = 0; i < mlt_properties_count(transproperties); ++i) { QString propName = mlt_properties_get_name(transproperties, i); if (!propName.startsWith('_') && ! permanentProps.contains(propName)) { mlt_properties_set(transproperties, propName.toUtf8().constData(), ""); @@ -3947,7 +4085,7 @@ QMap Render::mltGetTransitionParamsFromXml(QDomElement xml) { QDomNodeList attribs = xml.elementsByTagName("parameter"); QMap map; - for (int i = 0; i < attribs.count(); i++) { + for (int i = 0; i < attribs.count(); ++i) { QDomElement e = attribs.item(i).toElement(); QString name = e.attribute("name"); //kDebug()<<"-- TRANSITION PARAM: "< Render::mltGetTransitionParamsFromXml(QDomElement xml) if (values.size() > 0) txtNeu << (int)values[0].toDouble(); int i = 0; - for (i = 0; i < separators.size() && i + 1 < values.size(); i++) { + for (i = 0; i < separators.size() && i + 1 < values.size(); ++i) { txtNeu << separators[i]; txtNeu << (int)(values[i+1].toDouble()); } @@ -4182,7 +4320,7 @@ const QList Render::producersList() Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service()); if (!trackPlaylist.is_valid()) continue; int clipNb = trackPlaylist.count(); - for (int i = 0; i < clipNb; i++) { + for (int i = 0; i < clipNb; ++i) { Mlt::Producer *c = trackPlaylist.get_clip(i); if (c == NULL) continue; QString prodId = c->parent().get("id"); @@ -4215,7 +4353,7 @@ void Render::fillSlowMotionProducers() Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service()); if (!trackPlaylist.is_valid()) continue; int clipNb = trackPlaylist.count(); - for (int i = 0; i < clipNb; i++) { + for (int i = 0; i < clipNb; ++i) { Mlt::Producer *c = trackPlaylist.get_clip(i); Mlt::Producer *nprod = new Mlt::Producer(c->get_parent()); if (nprod) { @@ -4304,7 +4442,8 @@ QList Render::mltInsertTrack(int ix, bool videoTrack) Mlt::Properties trans_props(transition.get_properties()); Mlt::Transition *cp = new Mlt::Transition(*m_mltProfile, transition.get("mlt_service")); Mlt::Properties new_trans_props(cp->get_properties()); - new_trans_props.inherit(trans_props); + cloneProperties(new_trans_props, trans_props); + //new_trans_props.inherit(trans_props); if (trackChanged) { // Transition track needs to be adjusted @@ -4339,7 +4478,7 @@ QList Render::mltInsertTrack(int ix, bool videoTrack) mltPlantTransition(field, transition, 1, ct); // re-add transitions - for (int i = trList.count() - 1; i >= 0; i--) { + for (int i = trList.count() - 1; i >= 0; --i) { field->plant_transition(*trList.at(i), trList.at(i)->get_a_track(), trList.at(i)->get_b_track()); } qDeleteAll(trList); @@ -4358,7 +4497,7 @@ void Render::mltDeleteTrack(int ix) QDomNode track = doc.elementsByTagName("track").at(ix); QDomNode tractor = doc.elementsByTagName("tractor").at(0); QDomNodeList transitions = doc.elementsByTagName("transition"); - for (int i = 0; i < transitions.count(); i++) { + for (int i = 0; i < transitions.count(); ++i) { QDomElement e = transitions.at(i).toElement(); QDomNodeList props = e.elementsByTagName("property"); QMap mappedProps; @@ -4368,7 +4507,7 @@ void Render::mltDeleteTrack(int ix) } if (mappedProps.value("mlt_service") == "mix" && mappedProps.value("b_track").toInt() == tracksCount) { tractor.removeChild(transitions.at(i)); - i--; + --i; } else if (mappedProps.value("mlt_service") != "mix" && (mappedProps.value("b_track").toInt() >= ix || mappedProps.value("a_track").toInt() >= ix)) { // Transition needs to be moved int a_track = mappedProps.value("a_track").toInt(); @@ -4377,7 +4516,7 @@ void Render::mltDeleteTrack(int ix) if (b_track == ix) { // transition was on the deleted track, so remove it tractor.removeChild(transitions.at(i)); - i--; + --i; continue; } if (b_track > 0 && b_track > ix) b_track --; @@ -4428,7 +4567,7 @@ QString Render::updateSceneListFps(double current_fps, double new_fps, QString s double factor = new_fps / current_fps; QDomNodeList producers = doc.elementsByTagName("producer"); - for (int i = 0; i < producers.count(); i++) { + for (int i = 0; i < producers.count(); ++i) { QDomElement prod = producers.at(i).toElement(); prod.removeAttribute("in"); prod.removeAttribute("out"); @@ -4445,7 +4584,7 @@ QString Render::updateSceneListFps(double current_fps, double new_fps, QString s } QDomNodeList entries = doc.elementsByTagName("entry"); - for (int i = 0; i < entries.count(); i++) { + for (int i = 0; i < entries.count(); ++i) { QDomElement entry = entries.at(i).toElement(); int in = entry.attribute("in").toInt(); int out = entry.attribute("out").toInt(); @@ -4456,7 +4595,7 @@ QString Render::updateSceneListFps(double current_fps, double new_fps, QString s } QDomNodeList blanks = doc.elementsByTagName("blank"); - for (int i = 0; i < blanks.count(); i++) { + for (int i = 0; i < blanks.count(); ++i) { QDomElement blank = blanks.at(i).toElement(); int length = blank.attribute("length").toInt(); length = factor * length + 0.5; @@ -4464,7 +4603,7 @@ QString Render::updateSceneListFps(double current_fps, double new_fps, QString s } QDomNodeList filters = doc.elementsByTagName("filter"); - for (int i = 0; i < filters.count(); i++) { + for (int i = 0; i < filters.count(); ++i) { QDomElement filter = filters.at(i).toElement(); int in = filter.attribute("in").toInt(); int out = filter.attribute("out").toInt(); @@ -4475,7 +4614,7 @@ QString Render::updateSceneListFps(double current_fps, double new_fps, QString s } QDomNodeList transitions = doc.elementsByTagName("transition"); - for (int i = 0; i < transitions.count(); i++) { + for (int i = 0; i < transitions.count(); ++i) { QDomElement transition = transitions.at(i).toElement(); int in = transition.attribute("in").toInt(); int out = transition.attribute("out").toInt(); @@ -4537,9 +4676,9 @@ const QString Render::activeClipId() } //static -bool Render::getBlackMagicDeviceList(KComboBox *devicelist) +bool Render::getBlackMagicDeviceList(KComboBox *devicelist, bool force) { - if (!KdenliveSettings::decklink_device_found()) return false; + if (!force && !KdenliveSettings::decklink_device_found()) return false; Mlt::Profile profile; Mlt::Producer bm(profile, "decklink"); int found_devices = 0; @@ -4552,7 +4691,8 @@ bool Render::getBlackMagicDeviceList(KComboBox *devicelist) devicelist->setEnabled(false); return false; } - for (int i = 0; i < found_devices; i++) { + KdenliveSettings::setDecklink_device_found(true); + for (int i = 0; i < found_devices; ++i) { char *tmp = qstrdup(QString("device.%1").arg(i).toUtf8().constData()); devicelist->addItem(bm.get(tmp)); delete[] tmp; @@ -4560,14 +4700,14 @@ bool Render::getBlackMagicDeviceList(KComboBox *devicelist) return true; } -bool Render::getBlackMagicOutputDeviceList(KComboBox *devicelist) +bool Render::getBlackMagicOutputDeviceList(KComboBox *devicelist, bool force) { - if (!KdenliveSettings::decklink_device_found()) return false; + if (!force && !KdenliveSettings::decklink_device_found()) return false; Mlt::Profile profile; Mlt::Consumer bm(profile, "decklink"); int found_devices = 0; if (bm.is_valid()) { - bm.set("list_devices", 1); + bm.set("list_devices", 1);; found_devices = bm.get_int("devices"); } else KdenliveSettings::setDecklink_device_found(false); @@ -4575,7 +4715,8 @@ bool Render::getBlackMagicOutputDeviceList(KComboBox *devicelist) devicelist->setEnabled(false); return false; } - for (int i = 0; i < found_devices; i++) { + KdenliveSettings::setDecklink_device_found(true); + for (int i = 0; i < found_devices; ++i) { char *tmp = qstrdup(QString("device.%1").arg(i).toUtf8().constData()); devicelist->addItem(bm.get(tmp)); delete[] tmp; @@ -4586,7 +4727,7 @@ bool Render::getBlackMagicOutputDeviceList(KComboBox *devicelist) void Render::slotMultiStreamProducerFound(const QString path, QList audio_list, QList video_list, stringMap data) { if (KdenliveSettings::automultistreams()) { - for (int i = 1; i < video_list.count(); i++) { + for (int i = 1; i < video_list.count(); ++i) { int vindex = video_list.at(i); int aindex = 0; if (i <= audio_list.count() -1) { @@ -4642,7 +4783,7 @@ void Render::slotMultiStreamProducerFound(const QString path, QList audio_l } if (dialog.exec() == QDialog::Accepted) { // import selected streams - for (int i = 0; i < groupList.count(); i++) { + for (int i = 0; i < groupList.count(); ++i) { if (groupList.at(i)->isChecked()) { int vindex = groupList.at(i)->property("vindex").toInt(); int aindex = comboList.at(i)->itemData(comboList.at(i)->currentIndex()).toInt(); @@ -4655,5 +4796,19 @@ void Render::slotMultiStreamProducerFound(const QString path, QList audio_l } } +//static +bool Render::checkX11Grab() +{ + if (KdenliveSettings::rendererpath().isEmpty() || KdenliveSettings::ffmpegpath().isEmpty()) return false; + QProcess p; + QStringList args; + args << "avformat:f-list"; + p.start(KdenliveSettings::rendererpath(), args); + if (!p.waitForStarted()) return false; + if (!p.waitForFinished()) return false; + QByteArray result = p.readAllStandardError(); + return result.contains("x11grab"); +} + #include "renderer.moc"