1 /***************************************************************************
3 * Copyright (C) 2011 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
22 #include "kdenlivesettings.h"
23 #include "kdenlivedoc.h"
28 #include <mlt++/Mlt.h>
31 static void consumer_frame_render(mlt_consumer, MeltJob * self, mlt_frame /*frame_ptr*/)
33 // detect if the producer has finished playing. Is there a better way to do it?
34 self->emitFrameNumber();
37 MeltJob::MeltJob(CLIPTYPE cType, const QString &id, QStringList parameters) : AbstractClipJob(MLTJOB, cType, id, parameters),
43 jobStatus = JOBWAITING;
44 m_params = parameters;
45 description = i18n("Process clip");
48 void MeltJob::setProducer(Mlt::Producer *producer)
50 m_producer = producer;
53 void MeltJob::startJob()
56 m_errorMessage.append(i18n("No producer for this clip."));
57 setStatus(JOBCRASHED);
60 QString filter = m_params.takeFirst();
61 QString filterParams = m_params.takeFirst();
62 QString consumer = m_params.takeFirst();
63 QString consumerParams = m_params.takeFirst();
64 QString properties = m_params.takeFirst();
65 m_profile = m_producer->profile();
66 m_consumer = new Mlt::Consumer(*m_profile, consumer.toUtf8().constData());
67 if (!m_consumer || !m_consumer->is_valid()) {
68 m_errorMessage.append(i18n("Cannot create consumer %1.", consumer));
69 setStatus(JOBCRASHED);
73 m_consumer->set("terminate_on_pause", 1 );
74 m_consumer->set("eof", "pause" );
75 m_consumer->set("real_time", -1 );
77 QStringList list = consumerParams.split(' ', QString::SkipEmptyParts);
78 foreach(QString data, list) {
79 if (data.contains('=')) {
80 m_consumer->set(data.section('=', 0, 0).toUtf8().constData(), data.section('=', 1, 1).toUtf8().constData());
84 Mlt::Filter mltFilter(*m_profile, filter.toUtf8().data());
85 list = filterParams.split(' ', QString::SkipEmptyParts);
86 foreach(QString data, list) {
87 if (data.contains('=')) {
88 mltFilter.set(data.section('=', 0, 0).toUtf8().constData(), data.section('=', 1, 1).toUtf8().constData());
91 m_producer->attach(mltFilter);
92 m_length = m_producer->get_length();
93 m_consumer->connect(*m_producer);
94 m_producer->set_speed(0);
96 m_showFrameEvent = m_consumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_render);
98 m_producer->set_speed(1);
99 while (jobStatus != JOBABORTED && !m_consumer->is_stopped()) {
103 QStringList wanted = properties.split(',', QString::SkipEmptyParts);
104 foreach(const QString key, wanted) {
105 QString value = mltFilter.get(key.toUtf8().constData());
106 kDebug()<<"RESULT: "<<key<<" = "<< value;
118 const QString MeltJob::destination() const
123 stringMap MeltJob::cancelProperties()
125 QMap <QString, QString> props;
129 const QString MeltJob::statusMessage()
134 statusInfo = i18n("Processing clip");
137 statusInfo = i18n("Waiting - process clip");
145 void MeltJob::emitFrameNumber()
147 if (m_consumer && m_length > 0) {
148 emit jobProgress(m_clipId, (int) (100 * m_consumer->position() / m_length), jobType);