X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fprojecttree%2Fmeltjob.cpp;h=a324b84f83f19b0a7ca229fdce50db707dcabe60;hb=f69a24d18f8134c93e407ea485967ac31187da47;hp=258797549609380c6c7b71fbfc5f59c0fb58a673;hpb=a1f0a54b93ab364a37fd8242c1881c61d066ada7;p=kdenlive diff --git a/src/projecttree/meltjob.cpp b/src/projecttree/meltjob.cpp index 25879754..a324b84f 100644 --- a/src/projecttree/meltjob.cpp +++ b/src/projecttree/meltjob.cpp @@ -23,94 +23,120 @@ #include "kdenlivedoc.h" #include -#include +#include +#include #include -static void consumer_frame_render(mlt_consumer, MeltJob * self, mlt_frame /*frame_ptr*/) +static void consumer_frame_render(mlt_consumer, MeltJob * self, mlt_frame frame_ptr) { - // detect if the producer has finished playing. Is there a better way to do it? - self->emitFrameNumber(); + Mlt::Frame frame(frame_ptr); + self->emitFrameNumber((int) frame.get_position()); } -MeltJob::MeltJob(CLIPTYPE cType, const QString &id, QStringList parameters) : AbstractClipJob(MLTJOB, cType, id, parameters), +MeltJob::MeltJob(ClipType cType, const QString &id, const QStringList ¶meters, const QMap &extraParams) + : AbstractClipJob(MLTJOB, cType, id, parameters), + addClipToProject(0), + m_consumer(NULL), m_producer(NULL), m_profile(NULL), - m_consumer(NULL), - m_length(0) + m_filter(NULL), + m_showFrameEvent(NULL), + m_length(0), + m_extra(extraParams) { - jobStatus = JOBWAITING; + m_jobStatus = JobWaiting; m_params = parameters; description = i18n("Process clip"); QString consum = m_params.at(5); - if (consum.contains(":")) m_dest = consum.section(":", 1); + if (consum.contains(QLatin1Char(':'))) + m_dest = consum.section(QLatin1Char(':'), 1); } -void MeltJob::setProducer(Mlt::Producer *producer) +void MeltJob::setProducer(Mlt::Producer *producer, const KUrl &url) { - m_producer = producer; + m_url = QString::fromUtf8(producer->get("resource")); + if (m_url == QLatin1String("") || m_url == QLatin1String("") || m_url == QLatin1String("")) + m_url == url.path(); } void MeltJob::startJob() { - if (!m_producer) { + if (m_url.isEmpty()) { m_errorMessage.append(i18n("No producer for this clip.")); - setStatus(JOBCRASHED); + setStatus(JobCrashed); return; } int in = m_params.takeFirst().toInt(); + if (in > 0 && !m_extra.contains(QLatin1String("offset"))) m_extra.insert(QLatin1String("offset"), QString::number(in)); int out = m_params.takeFirst().toInt(); QString producerParams =m_params.takeFirst(); QString filter = m_params.takeFirst(); QString filterParams = m_params.takeFirst(); QString consumer = m_params.takeFirst(); - kDebug()<<"consumer: "<profile(); - - Mlt::Producer *prod; + if (m_extra.contains(QLatin1String("producer_profile"))) { + m_profile = new Mlt::Profile; + m_profile->set_explicit(false); + } + else { + m_profile = new Mlt::Profile(KdenliveSettings::current_profile().toUtf8().constData()); + } + if (m_extra.contains(QLatin1String("resize_profile"))) { + m_profile->set_height(m_extra.value(QLatin1String("resize_profile")).toInt()); + m_profile->set_width(m_profile->height() * m_profile->sar()); + } if (out == -1) { - QString url = QString::fromUtf8(m_producer->get("resource")); - prod = new Mlt::Producer(*m_profile, url.toUtf8().constData()); - } - else - prod = m_producer->cut(in, out); - QStringList list = producerParams.split(' ', QString::SkipEmptyParts); - foreach(QString data, list) { - if (data.contains('=')) { - prod->set(data.section('=', 0, 0).toUtf8().constData(), data.section('=', 1, 1).toUtf8().constData()); + m_producer = new Mlt::Producer(*m_profile, m_url.toUtf8().constData()); + if (m_producer) m_length = m_producer->get_length(); + } + else { + Mlt::Producer *tmp = new Mlt::Producer(*m_profile, m_url.toUtf8().constData()); + if (tmp) m_producer = tmp->cut(in, out); + delete tmp; + if (m_producer) m_length = m_producer->get_playtime(); + } + if (!m_producer || !m_producer->is_valid()) { + // Clip was removed or something went wrong, Notify user? + //m_errorMessage.append(i18n("Invalid clip")); + setStatus(JobCrashed); + return; + } + if (m_extra.contains(QLatin1String("producer_profile"))) { + m_profile->from_producer(*m_producer); + m_profile->set_explicit(true); + } + QStringList list = producerParams.split(QLatin1Char(' '), QString::SkipEmptyParts); + foreach(const QString &data, list) { + if (data.contains(QLatin1Char('='))) { + m_producer->set(data.section(QLatin1Char('='), 0, 0).toUtf8().constData(), data.section(QLatin1Char('='), 1, 1).toUtf8().constData()); } } - - if (consumer.contains(":")) { - m_consumer = new Mlt::Consumer(*m_profile, consumer.section(":", 0, 0).toUtf8().constData(), consumer.section(":", 1).toUtf8().constData()); + if (consumer.contains(QLatin1String(":"))) { + m_consumer = new Mlt::Consumer(*m_profile, consumer.section(QLatin1Char(':'), 0, 0).toUtf8().constData(), consumer.section(QLatin1Char(':'), 1).toUtf8().constData()); } else { m_consumer = new Mlt::Consumer(*m_profile, consumer.toUtf8().constData()); } if (!m_consumer || !m_consumer->is_valid()) { m_errorMessage.append(i18n("Cannot create consumer %1.", consumer)); - setStatus(JOBCRASHED); + setStatus(JobCrashed); return; } @@ -118,52 +144,59 @@ void MeltJob::startJob() //m_consumer->set("eof", "pause" ); m_consumer->set("real_time", -KdenliveSettings::mltthreads() ); - list = consumerParams.split(' ', QString::SkipEmptyParts); - foreach(QString data, list) { - if (data.contains('=')) { + + list = consumerParams.split(QLatin1Char(' '), QString::SkipEmptyParts); + foreach(const QString &data, list) { + if (data.contains(QLatin1Char('='))) { kDebug()<<"// filter con: "<set(data.section('=', 0, 0).toUtf8().constData(), data.section('=', 1, 1).toUtf8().constData()); + m_consumer->set(data.section(QLatin1Char('='), 0, 0).toUtf8().constData(), data.section(QLatin1Char('='), 1, 1).toUtf8().constData()); } } - Mlt::Filter mltFilter(*m_profile, filter.toUtf8().data()); - list = filterParams.split(' ', QString::SkipEmptyParts); - foreach(QString data, list) { - if (data.contains('=')) { + m_filter = new Mlt::Filter(*m_profile, filter.toUtf8().data()); + if (!m_filter || !m_filter->is_valid()) { + m_errorMessage = i18n("Filter %1 crashed", filter); + setStatus(JobCrashed); + return; + } + list = filterParams.split(QLatin1Char(' '), QString::SkipEmptyParts); + foreach(const QString &data, list) { + if (data.contains(QLatin1Char('='))) { kDebug()<<"// filter p: "<set(data.section(QLatin1Char('='), 0, 0).toUtf8().constData(), data.section(QLatin1Char('='), 1, 1).toUtf8().constData()); } } + Mlt::Tractor tractor; Mlt::Playlist playlist; - playlist.append(*prod); - m_length = prod->get_length(); - m_consumer->connect(playlist); - prod->set_speed(0); - prod->seek(0); - prod->attach(mltFilter); + playlist.append(*m_producer); + tractor.set_track(playlist, 0); + m_consumer->connect(tractor); + m_producer->set_speed(0); + m_producer->seek(0); + m_producer->attach(*m_filter); m_showFrameEvent = m_consumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_render); - m_consumer->start(); - prod->set_speed(1); - while (jobStatus != JOBABORTED && !m_consumer->is_stopped()) { - - } - m_consumer->stop(); - QStringList wanted = properties.split(',', QString::SkipEmptyParts); - stringMap jobResults; - foreach(const QString key, wanted) { - QString value = mltFilter.get(key.toUtf8().constData()); - jobResults.insert(key, value); - } - if (!jobResults.isEmpty()) emit gotFilterJobResults(m_clipId, startPos, track, finalFilter, jobResults); - setStatus(JOBDONE); - delete m_consumer; - delete prod; - return; + m_producer->set_speed(1); + m_consumer->run(); + + QMap jobResults; + if (m_jobStatus != JobAborted && m_extra.contains(QLatin1String("key"))) { + QString result = QString::fromLatin1(m_filter->get(m_extra.value(QLatin1String("key")).toUtf8().constData())); + jobResults.insert(m_extra.value(QLatin1String("key")), result); + } + if (!jobResults.isEmpty() && m_jobStatus != JobAborted) { + emit gotFilterJobResults(m_clipId, startPos, track, jobResults, m_extra); + } + if (m_jobStatus == JobAborted || m_jobStatus == JobWorking) m_jobStatus = JobDone; } MeltJob::~MeltJob() { + delete m_showFrameEvent; + delete m_filter; + delete m_producer; + delete m_consumer; + delete m_profile; } const QString MeltJob::destination() const @@ -180,11 +213,11 @@ stringMap MeltJob::cancelProperties() const QString MeltJob::statusMessage() { QString statusInfo; - switch (jobStatus) { - case JOBWORKING: + switch (m_jobStatus) { + case JobWorking: statusInfo = description; break; - case JOBWAITING: + case JobWaiting: statusInfo = i18n("Waiting to process clip"); break; default: @@ -193,9 +226,23 @@ const QString MeltJob::statusMessage() return statusInfo; } -void MeltJob::emitFrameNumber() +void MeltJob::emitFrameNumber(int pos) { - if (m_consumer && m_length > 0) { - emit jobProgress(m_clipId, (int) (100 * m_consumer->position() / m_length), jobType); + if (m_length > 0) { + emit jobProgress(m_clipId, (int) (100 * pos / m_length), jobType); } -} \ No newline at end of file +} + +bool MeltJob::isProjectFilter() const +{ + return m_extra.contains(QLatin1String("projecttreefilter")); +} + +void MeltJob::setStatus(ClipJobStatus status) +{ + m_jobStatus = status; + if (status == JobAborted && m_consumer) m_consumer->stop(); +} + + +#include "meltjob.moc"