]> git.sesse.net Git - kdenlive/blobdiff - src/renderer.cpp
Some cleanup in proxy creation
[kdenlive] / src / renderer.cpp
index 8aefda7abce5ccc225746ba92aba7015e7051d07..272acaf5ce5e7b55f04b95a38ffb360dc1198f89 100644 (file)
@@ -605,10 +605,15 @@ void Render::forceProcessing(const QString &id)
     m_infoMutex.unlock();
 }
 
-int Render::processingItems() const
+int Render::processingItems()
 {
+    m_infoMutex.lock();
     int count = m_requestList.count();
-    if (m_infoThread.isRunning()) count++;
+    if (!m_processingClipId.isEmpty()) {
+        // one clip is currently processed
+        count++;
+    }
+    m_infoMutex.unlock();
     return count;
 }
 
@@ -670,13 +675,13 @@ void Render::processFileProperties()
 
         if (producer == NULL || producer->is_blank() || !producer->is_valid()) {
             kDebug() << " / / / / / / / / ERROR / / / / // CANNOT LOAD PRODUCER: "<<path;
+            m_processingClipId.clear();
             if (proxyProducer) {
                 // Proxy file is corrupted
                 emit removeInvalidProxy(info.clipId, false);
             }
             else emit removeInvalidClip(info.clipId, info.replaceProducer);
             delete producer;
-            m_processingClipId.clear();
             continue;
         }
 
@@ -685,9 +690,9 @@ void Render::processFileProperties()
             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();
                 emit removeInvalidProxy(info.clipId, true);
                 delete producer;
-                m_processingClipId.clear();
                 continue;
             }
         }
@@ -781,13 +786,15 @@ void Render::processFileProperties()
                     emit replyGetImage(info.clipId, img);
                 }
             }
-            emit replyGetFileProperties(info.clipId, producer, stringMap(), stringMap(), info.replaceProducer);
             m_processingClipId.clear();
+            emit replyGetFileProperties(info.clipId, producer, stringMap(), stringMap(), info.replaceProducer);
             continue;
         }
 
         stringMap filePropertyMap;
         stringMap metadataPropertyMap;
+        char property[200];
+        
         if (frameNumber > 0) producer->seek(frameNumber);
         
         duration = duration > 0 ? duration : producer->get_playtime();
@@ -839,10 +846,20 @@ void Render::processFileProperties()
                 }
             }
         }
+        
+        // Get frame rate
+        int vindex = producer->get_int("video_index");     
+        if (vindex > -1) {
+            snprintf(property, sizeof(property), "meta.media.%d.stream.frame_rate", vindex);
+            if (producer->get(property))
+                filePropertyMap["fps"] = producer->get(property);
+        }
 
-        if (producer->get_double("meta.media.frame_rate_den") > 0) {
-            filePropertyMap["fps"] = locale.toString(producer->get_double("meta.media.frame_rate_num") / producer->get_double("meta.media.frame_rate_den"));
-        } else filePropertyMap["fps"] = producer->get("source_fps");
+        if (!filePropertyMap.contains("fps")) {
+            if (producer->get_double("meta.media.frame_rate_den") > 0) {
+                filePropertyMap["fps"] = locale.toString(producer->get_double("meta.media.frame_rate_num") / producer->get_double("meta.media.frame_rate_den"));
+            } else filePropertyMap["fps"] = producer->get("source_fps");
+        }
 
         Mlt::Frame *frame = producer->get_frame();
         if (frame && frame->is_valid()) {
@@ -876,7 +893,7 @@ void Render::processFileProperties()
                     }
                 } while (variance == -1);
                 delete frame;
-                if (frameNumber > -1) filePropertyMap["thumbnail"] = frameNumber;
+                if (frameNumber > -1) filePropertyMap["thumbnail"] = QString::number(frameNumber);
                 emit replyGetImage(info.clipId, img);
             } else if (frame->get_int("test_audio") == 0) {
                 emit replyGetImage(info.clipId, "audio-x-generic", fullWidth, info.imageHeight);
@@ -884,10 +901,9 @@ void Render::processFileProperties()
             }
         }
         // Retrieve audio / video codec name
-
         // If there is a
-        char property[200];
-        if (producer->get_int("video_index") > -1) {
+
+        if (vindex > -1) {
             /*if (context->duration == AV_NOPTS_VALUE) {
             kDebug() << " / / / / / / / /ERROR / / / CLIP HAS UNKNOWN DURATION";
                 emit removeInvalidClip(clipId);
@@ -895,7 +911,6 @@ void Render::processFileProperties()
             return;
             }*/
             // Get the video_index
-            int default_video = producer->get_int("video_index");
             int video_max = 0;
             int default_audio = producer->get_int("audio_index");
             int audio_max = 0;
@@ -909,21 +924,21 @@ void Render::processFileProperties()
                 else if (type == "audio")
                     audio_max = ix;
             }
-            filePropertyMap["default_video"] = QString::number(default_video);
+            filePropertyMap["default_video"] = QString::number(vindex);
             filePropertyMap["video_max"] = QString::number(video_max);
             filePropertyMap["default_audio"] = QString::number(default_audio);
             filePropertyMap["audio_max"] = QString::number(audio_max);
 
-            snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", default_video);
+            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", default_video);
+                snprintf(property, sizeof(property), "meta.media.%d.codec.name", vindex);
                 if (producer->get(property))
                     filePropertyMap["videocodec"] = producer->get(property);
             }
             QString query;
-            query = QString("meta.media.%1.codec.pix_fmt").arg(default_video);
+            query = QString("meta.media.%1.codec.pix_fmt").arg(vindex);
             filePropertyMap["pix_fmt"] = producer->get(query.toUtf8().constData());
             filePropertyMap["colorspace"] = producer->get("meta.media.colorspace");
 
@@ -952,6 +967,7 @@ void Render::processFileProperties()
                 metadataPropertyMap[ name.section('.', 0, -2)] = value;
         }
         producer->seek(0);
+        m_processingClipId.clear();
         emit replyGetFileProperties(info.clipId, producer, filePropertyMap, metadataPropertyMap, info.replaceProducer);
     }
     m_processingClipId.clear();
@@ -1002,7 +1018,11 @@ int Render::setProducer(Mlt::Producer *producer, int position)
     QMutexLocker locker(&m_mutex);
     QString currentId;
     int consumerPosition = 0;
-    if (m_winid == -1 || !m_mltConsumer) return -1;
+    if (m_winid == -1 || !m_mltConsumer) {
+        kDebug()<<" / / / / WARNING, MONITOR NOT READY";
+        if (producer) delete producer;
+        return -1;
+    }
     m_mltConsumer->set("refresh", 0);
     if (!m_mltConsumer->is_stopped()) {
         m_mltConsumer->stop();
@@ -1010,30 +1030,46 @@ int Render::setProducer(Mlt::Producer *producer, int position)
     m_mltConsumer->purge();
     consumerPosition = m_mltConsumer->position();
 
-    if (m_mltProducer) {
-        m_mltProducer->set_speed(0);
-        currentId = m_mltProducer->get("id");
-        delete m_mltProducer;
-        m_mltProducer = NULL;
-        emit stopped();
-    }
 
     blockSignals(true);
-    if (producer && producer->is_valid()) {
-        m_mltProducer = producer;
-    } else m_mltProducer = m_blackClip->cut(0, 1);
+    if (!producer || !producer->is_valid()) {
+        if (producer) delete producer;
+        producer = m_blackClip->cut(0, 1);
+    }
 
-    if (!m_mltProducer || !m_mltProducer->is_valid()) {
+    if (!producer || !producer->is_valid()) {
         kDebug() << " WARNING - - - - -INVALID PLAYLIST: ";
         return -1;
     }
-    if (position == -1 && m_mltProducer->get("id") == currentId) position = consumerPosition;
-    if (position != -1) m_mltProducer->seek(position);
+    if (m_mltProducer) currentId = m_mltProducer->get("id");
+    emit stopped();
+    if (position == -1 && producer->get("id") == currentId) position = consumerPosition;
+    if (position != -1) producer->seek(position);
     int volume = KdenliveSettings::volume();
-    m_mltProducer->set("meta.volume", (double)volume / 100);
-    m_fps = m_mltProducer->get_fps();
+    producer->set("meta.volume", (double)volume / 100);
+    m_fps = producer->get_fps();
     blockSignals(false);
-    int error = connectPlaylist();
+    m_mltConsumer->connect(*producer);
+
+    if (m_mltProducer) {
+        m_mltProducer->set_speed(0);
+        delete m_mltProducer;
+        m_mltProducer = NULL;
+    }
+    m_mltProducer = producer;
+    m_mltProducer->set_speed(0);
+    emit durationChanged(m_mltProducer->get_playtime());
+    if (m_mltConsumer->start() == -1) {
+        // ARGH CONSUMER BROKEN!!!!
+        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."));
+        if (m_showFrameEvent) delete m_showFrameEvent;
+        m_showFrameEvent = NULL;
+        if (m_pauseEvent) delete m_pauseEvent;
+        m_pauseEvent = NULL;
+        delete m_mltConsumer;
+        m_mltConsumer = NULL;
+        return -1;
+    }
 
     position = m_mltProducer->position();
     m_mltConsumer->set("refresh", 1);
@@ -1043,7 +1079,7 @@ int Render::setProducer(Mlt::Producer *producer, int position)
     m_mltConsumer->wait_for(ev);
     delete ev;
     emit rendererPosition(position);
-    return error;
+    return 0;
 }
 
 int Render::setSceneList(QDomDocument list, int position)
@@ -1165,10 +1201,11 @@ int Render::setSceneList(QString playlist, int position)
     }
 
     kDebug() << "// NEW SCENE LIST DURATION SET TO: " << m_mltProducer->get_playtime();
-    if (error == 0) error = connectPlaylist();
-    else connectPlaylist();
+    m_mltConsumer->connect(*m_mltProducer);
+    m_mltProducer->set_speed(0);
     fillSlowMotionProducers();
     blockSignals(false);
+    emit durationChanged(m_mltProducer->get_playtime());
 
     return error;
     //kDebug()<<"// SETSCN LST, POS: "<<position;
@@ -1269,27 +1306,6 @@ double Render::fps() const
     return m_fps;
 }
 
-int Render::connectPlaylist()
-{
-    if (!m_mltConsumer) return -1;
-    m_mltConsumer->connect(*m_mltProducer);
-    m_mltProducer->set_speed(0);
-    if (m_mltConsumer->start() == -1) {
-        // ARGH CONSUMER BROKEN!!!!
-        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."));
-        if (m_showFrameEvent) delete m_showFrameEvent;
-        m_showFrameEvent = NULL;
-        if (m_pauseEvent) delete m_pauseEvent;
-        m_pauseEvent = NULL;
-        delete m_mltConsumer;
-        m_mltConsumer = NULL;
-        return -1;
-    }
-    emit durationChanged(m_mltProducer->get_playtime());
-    return 0;
-}
-
-
 int Render::volume() const
 {
     if (!m_mltConsumer || !m_mltProducer) return -1;
@@ -1329,13 +1345,14 @@ void Render::slotOsdTimeout()
 
 void Render::start()
 {
+    m_refreshTimer.stop();
     QMutexLocker locker(&m_mutex);
     if (m_winid == -1) {
         kDebug() << "-----  BROKEN MONITOR: " << m_name << ", RESTART";
         return;
     }
-
-    if (m_mltConsumer && m_mltConsumer->is_stopped()) {
+    if (!m_mltConsumer) 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."));
             kDebug(QtWarningMsg) << "/ / / / CANNOT START MONITOR";
@@ -1348,6 +1365,7 @@ void Render::start()
 
 void Render::stop()
 {
+    m_refreshTimer.stop();
     QMutexLocker locker(&m_mutex);
     if (m_mltProducer == NULL) return;
     if (m_mltConsumer && !m_mltConsumer->is_stopped()) {
@@ -1363,6 +1381,7 @@ void Render::stop()
 
 void Render::stop(const GenTime & startTime)
 {
+    m_refreshTimer.stop();
     QMutexLocker locker(&m_mutex);
     if (m_mltProducer) {
         if (m_isZoneMode) resetZoneMode();
@@ -1490,16 +1509,7 @@ void Render::seekToFrameDiff(int diff)
 
 void Render::doRefresh()
 {
-    m_refreshTimer.start();
-    /*QMutexLocker locker(&m_mutex);
-    if (m_mltConsumer) {
-        if (m_mltConsumer->is_stopped()) {
-            kDebug()<<"pppppppppppppppp\n\nSTARTING CONSUMER: "<<m_name<<m_mltConsumer->start();
-        }
-        //m_mltProducer->set_speed(1);
-        m_mltConsumer->set("refresh", 1);
-        //m_mltProducer->set_speed(0);
-    }*/
+    if (m_mltProducer && m_mltProducer->get_speed() == 0) m_refreshTimer.start();
 }
 
 void Render::refresh()
@@ -4176,6 +4186,11 @@ Mlt::Producer* Render::getProducer()
     return m_mltProducer;
 }
 
+const QString Render::activeClipId()
+{
+    if (m_mltProducer) return m_mltProducer->get("id");
+    return QString();
+}
 
 #include "renderer.moc"