]> git.sesse.net Git - kdenlive/commitdiff
Fix scene detection jobs not running concurrently and possible crash: http://kdenlive...
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Wed, 19 Dec 2012 23:16:37 +0000 (00:16 +0100)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Wed, 19 Dec 2012 23:16:37 +0000 (00:16 +0100)
src/projectlist.cpp
src/projecttree/meltjob.cpp
src/projecttree/meltjob.h

index 6113f5bb25f26cfe31b9db73a17507b82d14b344..12b19abe0ac0f44a22631650fd74f6b3ee5aa17f 100644 (file)
@@ -2948,8 +2948,9 @@ void ProjectList::slotCheckJobProcess()
             }
     }
     if (m_jobList.isEmpty()) return;
-    int count = 0;
+
     m_jobMutex.lock();
+    int count = 0;
     for (int i = 0; i < m_jobList.count(); i++) {
         if (m_jobList.at(i)->status() == JOBWORKING || m_jobList.at(i)->status() == JOBWAITING)
             count ++;
@@ -2960,10 +2961,8 @@ void ProjectList::slotCheckJobProcess()
             i--;
         }
     }
-
-    emit jobCount(count);
+    emit jobCount(count);    
     m_jobMutex.unlock();
-    
     if (m_jobThreads.futures().isEmpty() || m_jobThreads.futures().count() < KdenliveSettings::proxythreads()) m_jobThreads.addFuture(QtConcurrent::run(this, &ProjectList::slotProcessJobs));
 }
 
@@ -3032,7 +3031,7 @@ void ProjectList::slotProcessJobs()
             MeltJob *jb = static_cast<MeltJob *> (job);
             jb->setProducer(currentClip->getProducer(), currentClip->fileURL());
            if (jb->isProjectFilter())
-             connect(job, SIGNAL(gotFilterJobResults(QString,int, int, stringMap,stringMap)), this, SLOT(slotGotFilterJobResults(QString,int, int,stringMap,stringMap)));
+               connect(job, SIGNAL(gotFilterJobResults(QString,int, int, stringMap,stringMap)), this, SLOT(slotGotFilterJobResults(QString,int, int,stringMap,stringMap)));
            else
                connect(job, SIGNAL(gotFilterJobResults(QString,int, int, stringMap,stringMap)), this, SIGNAL(gotFilterJobResults(QString,int, int,stringMap,stringMap)));
         }
@@ -3600,9 +3599,10 @@ void ProjectList::processClipJob(QStringList ids, const QString&destination, boo
         job->description = description;
         m_jobList.append(job);
         setJobStatus(item, job->jobType, JOBWAITING, 0, job->statusMessage());
+       slotCheckJobProcess();
     }
-    slotCheckJobProcess();
 }
+   
 
 void ProjectList::slotPrepareJobsMenu()
 {
@@ -3659,6 +3659,7 @@ void ProjectList::slotGotFilterJobResults(QString id, int , int , stringMap resu
     //kDebug()<<"// FILTER RES:\n"<<filterInfo<<"\n--------------\n"<<results;
     ProjectItem *clip = getItemById(id);
     if (!clip) return;
+
     // Check for return value
     int markersType = -1;
     if (filterInfo.contains("addmarkers")) markersType = filterInfo.value("addmarkers").toInt();
index 0500bf5ea5551980dac68fc213a5272922f9b5d9..1e97d8f400a6a232a95f4d4935965a3eda41efd0 100644 (file)
@@ -31,7 +31,6 @@
 
 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?
     Mlt::Frame frame(frame_ptr);
     self->emitFrameNumber((int) frame.get_position());
 }
@@ -39,6 +38,10 @@ static void consumer_frame_render(mlt_consumer, MeltJob * self, mlt_frame frame_
 MeltJob::MeltJob(CLIPTYPE cType, const QString &id, QStringList parameters,  QMap <QString, QString>extraParams) : AbstractClipJob(MLTJOB, cType, id, parameters),
     addClipToProject(0),
     m_consumer(NULL),
+    m_producer(NULL),
+    m_profile(NULL),
+    m_filter(NULL),
+    m_showFrameEvent(NULL),
     m_length(0),
     m_extra(extraParams)
 {
@@ -85,7 +88,6 @@ void MeltJob::startJob()
         setStatus(JOBCRASHED);
         return;
     }
-    Mlt::Producer *prod ;
     if (m_extra.contains("producer_profile")) {
        m_profile = new Mlt::Profile;
        m_profile->set_explicit(false);
@@ -98,23 +100,28 @@ void MeltJob::startJob()
        m_profile->set_width(m_profile->height() * m_profile->sar());
     }
     if (out == -1) {
-       prod = new Mlt::Producer(*m_profile,  m_url.toUtf8().constData());
-       m_length = prod->get_length();
+       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());
-        prod = tmp->cut(in, out);
+        if (tmp) m_producer = tmp->cut(in, out);
        delete tmp;
-       m_length = prod->get_playtime();
+       if (m_producer) m_length = m_producer->get_playtime();
+    }
+    if (!m_producer || !m_producer->is_valid()) {
+       return;
+       m_errorMessage.append(i18n("Invalid clip"));
+        setStatus(JOBCRASHED);
     }
     if (m_extra.contains("producer_profile")) {
-       m_profile->from_producer(*prod);
+       m_profile->from_producer(*m_producer);
        m_profile->set_explicit(true);
     }
     QStringList list = producerParams.split(' ', QString::SkipEmptyParts);
     foreach(const QString &data, list) {
         if (data.contains('=')) {
-            prod->set(data.section('=', 0, 0).toUtf8().constData(), data.section('=', 1, 1).toUtf8().constData());
+            m_producer->set(data.section('=', 0, 0).toUtf8().constData(), data.section('=', 1, 1).toUtf8().constData());
         }
     }
     if (consumer.contains(":")) {
@@ -142,50 +149,51 @@ void MeltJob::startJob()
         }
     }
     
-    Mlt::Filter mltFilter(*m_profile, filter.toUtf8().data());
-    if (!mltFilter.is_valid()) {
+    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);
-       delete m_consumer;
-       delete prod;
        return;
     }
     list = filterParams.split(' ', QString::SkipEmptyParts);
     foreach(const QString &data, list) {
         if (data.contains('=')) {
             kDebug()<<"// filter p: "<<data;
-            mltFilter.set(data.section('=', 0, 0).toUtf8().constData(), data.section('=', 1, 1).toUtf8().constData());
+            m_filter->set(data.section('=', 0, 0).toUtf8().constData(), data.section('=', 1, 1).toUtf8().constData());
         }
     }
     Mlt::Tractor tractor;
     Mlt::Playlist playlist;
-    playlist.append(*prod);
+    playlist.append(*m_producer);
     tractor.set_track(playlist, 0);
     m_consumer->connect(tractor);
-    prod->set_speed(0);
-    prod->seek(0);
-    prod->attach(mltFilter);
-    Mlt::Event *showFrameEvent = m_consumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_render);
-    prod->set_speed(1);
-
+    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_producer->set_speed(1);
     m_consumer->run();
+    
     QMap <QString, QString> jobResults;
     if (m_jobStatus != JOBABORTED && m_extra.contains("key")) {
-       QString result = mltFilter.get(m_extra.value("key").toUtf8().constData());
+       QString result = m_filter->get(m_extra.value("key").toUtf8().constData());
        jobResults.insert(m_extra.value("key"), result);
     }
-    setStatus(JOBDONE);
-    delete prod;
-    delete showFrameEvent;
-    if (!jobResults.isEmpty() && m_jobStatus != JOBABORTED) emit gotFilterJobResults(m_clipId, startPos, track, jobResults, m_extra);
-    return;
+    if (!jobResults.isEmpty() && m_jobStatus != JOBABORTED) {
+       m_jobStatus = JOBDONE;
+       emit gotFilterJobResults(m_clipId, startPos, track, jobResults, m_extra);
+    }
+    if (m_jobStatus == JOBABORTED) m_jobStatus = JOBDONE;
 }
 
 
 MeltJob::~MeltJob()
 {
-    delete m_consumer;
-    delete m_profile;
+    if (m_showFrameEvent) delete m_showFrameEvent;
+    if (m_filter) delete m_filter;
+    if (m_producer) delete m_producer;
+    if (m_consumer) delete m_consumer;
+    if (m_profile) delete m_profile;
 }
 
 const QString MeltJob::destination() const
@@ -233,4 +241,3 @@ void MeltJob::setStatus(CLIPJOBSTATUS status)
     if (status == JOBABORTED && m_consumer) m_consumer->stop();
 }
 
-
index abd231dd08d303c7ee499a6f87581f73b06c9757..f4c5f05ece55e2ced197ed512271c34b71d5bbb9 100644 (file)
@@ -56,7 +56,10 @@ public:
     
 private:
     Mlt::Consumer *m_consumer;
+    Mlt::Producer *m_producer;
     Mlt::Profile *m_profile;
+    Mlt::Filter *m_filter;
+    Mlt::Event *m_showFrameEvent;
     QStringList m_params;
     QString m_dest;
     QString m_url;