]> git.sesse.net Git - kdenlive/blobdiff - src/renderer.cpp
* Cleanup monitor / MLT communication
[kdenlive] / src / renderer.cpp
index 2744f6619f57fd19282b2572ca417e86bd1926b7..8ca08514e914f847d2d8f7558d0831deff5ac1dc 100644 (file)
 
 #include <QTimer>
 #include <QDir>
+#include <QString>
 #include <QApplication>
 
-#include <stdlib.h>
+#include <cstdlib>
+#include <cstdarg>
 
 
 
@@ -49,6 +51,7 @@ static void kdenlive_callback(void* /*ptr*/, int level, const char* fmt, va_list
     if (level > MLT_LOG_ERROR) return;
     QString error;
     QApplication::postEvent(qApp->activeWindow() , new MltErrorEvent(error.vsprintf(fmt, vl).simplified()));
+    va_end(vl);
 }
 
 
@@ -60,13 +63,17 @@ static void consumer_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr
 #ifdef Q_WS_MAC
     self->showFrame(frame);
 #endif
+
+    self->emitFrameNumber(mlt_frame_get_position(frame_ptr));
     if (frame.get_double("_speed") == 0.0) {
         self->emitConsumerStopped();
-    } else {
-        self->emitFrameNumber(mlt_frame_get_position(frame_ptr));
+    } else if (frame.get_double("_speed") < 0.0 && mlt_frame_get_position(frame_ptr) <= 0) {
+        self->pause();
+        self->emitConsumerStopped();
     }
 }
 
+
 Render::Render(const QString & rendererName, int winid, int /* extid */, QString profile, QWidget *parent) :
         QObject(parent),
         m_isBlocked(0),
@@ -148,6 +155,11 @@ void Render::closeMlt()
     //delete m_osdInfo;
 }
 
+void Render::slotSwitchFullscreen()
+{
+    if (m_mltConsumer) m_mltConsumer->set("full_screen", 1);
+}
+
 void Render::buildConsumer(const QString profileName)
 {
     char *tmp;
@@ -227,22 +239,27 @@ void Render::buildConsumer(const QString profileName)
 
     m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
     m_blackClip->set("id", "black");
+    m_blackClip->set("mlt_type", "producer");
 
 }
 
 int Render::resetProfile(const QString profileName)
 {
-    if (!m_mltConsumer) return 0;
-    if (m_activeProfile == profileName) {
-        kDebug() << "reset to same profile, nothing to do";
-        return 1;
+    if (m_mltConsumer) {
+        QString videoDriver = KdenliveSettings::videodrivername();
+        QString currentDriver = m_mltConsumer->get("video_driver");
+        if (getenv("SDL_VIDEO_YUV_HWACCEL") != NULL && currentDriver == "x11") currentDriver = "x11_noaccel";
+        if (m_activeProfile == profileName && currentDriver == videoDriver) {
+            kDebug() << "reset to same profile, nothing to do";
+            return 1;
+        }
+
+        if (m_isSplitView) slotSplitView(false);
+        if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
+        m_mltConsumer->purge();
+        delete m_mltConsumer;
+        m_mltConsumer = NULL;
     }
-    kDebug() << "// RESETTING PROFILE FROM: " << m_activeProfile << " TO: " << profileName; //KdenliveSettings::current_profile();
-    if (m_isSplitView) slotSplitView(false);
-    if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
-    m_mltConsumer->purge();
-    delete m_mltConsumer;
-    m_mltConsumer = NULL;
     QString scene = sceneList();
     int pos = 0;
     double current_fps = m_mltProfile->fps();
@@ -574,7 +591,7 @@ void Render::slotSplitView(bool doit)
     }
 }
 
-void Render::getFileProperties(const QDomElement xml, const QString &clipId, bool replaceProducer)
+void Render::getFileProperties(const QDomElement xml, const QString &clipId, int imageHeight, bool replaceProducer)
 {
     KUrl url = KUrl(xml.attribute("resource", QString()));
     Mlt::Producer *producer = NULL;
@@ -623,6 +640,17 @@ void Render::getFileProperties(const QDomElement xml, const QString &clipId, boo
         double aspect = xml.attribute("force_aspect_ratio").toDouble();
         if (aspect > 0) producer->set("force_aspect_ratio", aspect);
     }
+
+    if (xml.hasAttribute("force_fps")) {
+        double fps = xml.attribute("force_fps").toDouble();
+        if (fps > 0) producer->set("force_fps", fps);
+    }
+
+    if (xml.hasAttribute("force_progressive")) {
+        bool ok;
+        int progressive = xml.attribute("force_progressive").toInt(&ok);
+        if (ok) producer->set("force_progressive", progressive);
+    }
     if (xml.hasAttribute("threads")) {
         int threads = xml.attribute("threads").toInt();
         if (threads != 1) producer->set("threads", threads);
@@ -654,8 +682,7 @@ void Render::getFileProperties(const QDomElement xml, const QString &clipId, boo
         return;
     }
 
-    int height = 50;
-    int width = (int)(height  * m_mltProfile->dar());
+    int width = (int)(imageHeight  * m_mltProfile->dar());
     QMap < QString, QString > filePropertyMap;
     QMap < QString, QString > metadataPropertyMap;
 
@@ -710,8 +737,8 @@ void Render::getFileProperties(const QDomElement xml, const QString &clipId, boo
 
             mlt_image_format format = mlt_image_rgb24a;
             int frame_width = width;
-            int frame_height = height;
-            QPixmap pix(width, height);
+            int frame_height = imageHeight;
+            QPixmap pix(width, imageHeight);
             uint8_t *data = frame->get_image(format, frame_width, frame_height, 0);
             QImage image((uchar *)data, frame_width, frame_height, QImage::Format_ARGB32);
 
@@ -723,7 +750,7 @@ void Render::getFileProperties(const QDomElement xml, const QString &clipId, boo
             emit replyGetImage(clipId, pix);
 
         } else if (frame->get_int("test_audio") == 0) {
-            QPixmap pixmap = KIcon("audio-x-generic").pixmap(QSize(width, height));
+            QPixmap pixmap = KIcon("audio-x-generic").pixmap(QSize(width, imageHeight));
             emit replyGetImage(clipId, pixmap);
             filePropertyMap["type"] = "audio";
         }
@@ -805,7 +832,7 @@ void Render::getFileProperties(const QDomElement xml, const QString &clipId, boo
         if (name.endsWith("markup") && !value.isEmpty())
             metadataPropertyMap[ name.section('.', 0, -2)] = value;
     }
-
+    producer->seek(0);
     emit replyGetFileProperties(clipId, producer, filePropertyMap, metadataPropertyMap, replaceProducer);
     kDebug() << "REquested fuile info for: " << url.path();
     delete frame;
@@ -886,6 +913,7 @@ int Render::setProducer(Mlt::Producer *producer, int position)
 
     m_fps = m_mltProducer->get_fps();
     int error = connectPlaylist();
+
     if (position != -1) {
         m_mltProducer->seek(position);
         emit rendererPosition(position);
@@ -907,20 +935,19 @@ int Render::setSceneList(QString playlist, int position)
 {
     if (m_winid == -1) return -1;
     m_isBlocked = true;
-    int error;
+    int error = 0;
 
     kDebug() << "//////  RENDER, SET SCENE LIST: " << playlist;
 
-    if (m_mltConsumer == NULL) {
+    if (m_mltConsumer) {
+        if (!m_mltConsumer->is_stopped()) {
+            m_mltConsumer->stop();
+        }
+        m_mltConsumer->set("refresh", 0);
+    } else {
         kWarning() << "///////  ERROR, TRYING TO USE NULL MLT CONSUMER";
-        m_isBlocked = false;
-        return -1;
-    }
-
-    if (!m_mltConsumer->is_stopped()) {
-        m_mltConsumer->stop();
+        error = -1;
     }
-    m_mltConsumer->set("refresh", 0);
 
     if (m_mltProducer) {
         m_mltProducer->set_speed(0);
@@ -975,6 +1002,7 @@ int Render::setSceneList(QString playlist, int position)
     if (!m_mltProducer || !m_mltProducer->is_valid()) {
         kDebug() << " WARNING - - - - -INVALID PLAYLIST: " << tmp;
         m_mltProducer = m_blackClip->cut(0, 50);
+        error = -1;
     }
     delete[] tmp;
 
@@ -1010,7 +1038,8 @@ int Render::setSceneList(QString playlist, int position)
     }
 
     kDebug() << "// NEW SCENE LIST DURATION SET TO: " << m_mltProducer->get_playtime();
-    error = connectPlaylist();
+    if (error == 0) error = connectPlaylist();
+    else connectPlaylist();
     fillSlowMotionProducers();
 
     m_isBlocked = false;
@@ -1111,9 +1140,8 @@ int Render::connectPlaylist()
     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."));
-        emit blockMonitors();
-        delete m_mltProducer;
-        m_mltProducer = NULL;
+        delete m_mltConsumer;
+        m_mltConsumer = NULL;
         return -1;
     }
     emit durationChanged(m_mltProducer->get_playtime());
@@ -1180,10 +1208,8 @@ void Render::start()
     if (m_mltConsumer && m_mltConsumer->is_stopped()) {
         kDebug() << "-----  MONITOR: " << m_name << " WAS 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."));
-            emit blockMonitors();
-            delete m_mltProducer;
-            m_mltProducer = NULL;
+            //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."));
+            kdWarning() << "/ / / / CANNOT START MONITOR";
         } else {
             kDebug() << "-----  MONITOR: " << m_name << " REFRESH";
             m_isBlocked = false;
@@ -1237,8 +1263,10 @@ void Render::pause()
     m_isBlocked = true;
     m_mltConsumer->set("refresh", 0);
     m_mltProducer->set_speed(0.0);
+    /*
+    The 2 lines below create a flicker loop
     emit rendererPosition(m_framePosition);
-    m_mltProducer->seek(m_framePosition);
+    m_mltProducer->seek(m_framePosition);*/
     m_mltConsumer->purge();
 }
 
@@ -1255,7 +1283,7 @@ void Render::switchPlay()
         m_isBlocked = true;
         m_mltConsumer->set("refresh", 0);
         m_mltProducer->set_speed(0.0);
-        emit rendererPosition(m_framePosition);
+        //emit rendererPosition(m_framePosition);
         m_mltProducer->seek(m_framePosition);
         m_mltConsumer->purge();
         //kDebug()<<" *********  RENDER PAUSE: "<<m_mltProducer->get_speed();
@@ -1378,9 +1406,7 @@ void Render::setDropFrames(bool show)
         m_mltConsumer->set("play.real_time", dropFrames);
 #endif
         if (m_mltConsumer->start() == -1) {
-            emit blockMonitors();
-            delete m_mltProducer;
-            m_mltProducer = NULL;
+            kdWarning() << "ERROR, Cannot start monitor";
         }
 
     }
@@ -1497,7 +1523,7 @@ void Render::mltCheckLength(Mlt::Tractor *tractor)
     while (trackNb > 1) {
         Mlt::Producer trackProducer(tractor->track(trackNb - 1));
         trackDuration = trackProducer.get_playtime() - 1;
-        //kDebug() << " / / /DURATON FOR TRACK " << trackNb - 1 << " = " << trackDuration;
+        // kDebug() << " / / /DURATON FOR TRACK " << trackNb - 1 << " = " << trackDuration;
         if (trackDuration > duration) duration = trackDuration;
         trackNb--;
     }
@@ -1514,17 +1540,17 @@ void Render::mltCheckLength(Mlt::Tractor *tractor)
 
         if (blackclip == NULL || blackTrackPlaylist.count() != 1) {
             blackTrackPlaylist.clear();
-            m_blackClip->set("length", duration);
-            m_blackClip->set("out", duration - 1);
-            blackclip = m_blackClip->cut(0, duration - 1);
+            m_blackClip->set("length", duration + 1);
+            m_blackClip->set("out", duration);
+            blackclip = m_blackClip->cut(0, duration);
             blackTrackPlaylist.insert_at(0, blackclip, 1);
         } else {
             if (duration > blackclip->parent().get_length()) {
-                blackclip->parent().set("length", duration);
-                blackclip->parent().set("out", duration - 1);
-                blackclip->set("length", duration);
+                blackclip->parent().set("length", duration + 1);
+                blackclip->parent().set("out", duration);
+                blackclip->set("length", duration + 1);
             }
-            blackTrackPlaylist.resize_clip(0, 0, duration - 1);
+            blackTrackPlaylist.resize_clip(0, 0, duration);
         }
 
         delete blackclip;
@@ -2064,8 +2090,12 @@ int Render::mltChangeClipSpeed(ItemInfo info, ItemInfo speedIndependantInfo, dou
             // copy producer props
             double ar = original->parent().get_double("force_aspect_ratio");
             if (ar != 0.0) slowprod->set("force_aspect_ratio", ar);
+            double fps = original->parent().get_double("force_fps");
+            if (fps != 0.0) slowprod->set("force_fps", fps);
             int threads = original->parent().get_int("threads");
             if (threads != 0) slowprod->set("threads", threads);
+            if (original->parent().get("force_progressive"))
+                slowprod->set("force_progressive", original->parent().get_int("force_progressive"));
             int ix = original->parent().get_int("video_index");
             if (ix != 0) slowprod->set("video_index", ix);
             m_slowmotionProducers.insert(url, slowprod);
@@ -2137,6 +2167,10 @@ int Render::mltChangeClipSpeed(ItemInfo info, ItemInfo speedIndependantInfo, dou
             // copy producer props
             double ar = original->parent().get_double("force_aspect_ratio");
             if (ar != 0.0) slowprod->set("force_aspect_ratio", ar);
+            double fps = original->parent().get_double("force_fps");
+            if (fps != 0.0) slowprod->set("force_fps", fps);
+            if (original->parent().get("force_progressive"))
+                slowprod->set("force_progressive", original->parent().get_int("force_progressive"));
             int threads = original->parent().get_int("threads");
             if (threads != 0) slowprod->set("threads", threads);
             int ix = original->parent().get_int("video_index");