]> git.sesse.net Git - kdenlive/blobdiff - src/renderer.cpp
Fix "save zone" saving proxy instead of real clip:
[kdenlive] / src / renderer.cpp
index 646c5611802a116faeca0bdfc81dbb2fa00d1d08..fd6a48585b89985b35ce3a64613e5b40d9b96545 100644 (file)
@@ -71,14 +71,21 @@ static void consumer_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr
     if (self->analyseAudio) {
         self->showAudio(frame);
     }
-    if (frame.get_double("_speed") == 0.0) {
-        self->emitConsumerStopped();
-    } else if (frame.get_double("_speed") < 0.0 && mlt_frame_get_position(frame_ptr) <= 0) {
+    if (frame.get_double("_speed") < 0.0 && mlt_frame_get_position(frame_ptr) <= 0) {
         self->pause();
         self->emitConsumerStopped();
     }
 }
 
+
+static void consumer_paused(mlt_consumer, Render * self, mlt_frame /*frame_ptr*/)
+{
+    // detect if the producer has finished playing. Is there a better way to do it?
+    if (self->m_isBlocked) return;
+    self->emitConsumerStopped();
+}
+
+
 static void consumer_gl_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr)
 {
     // detect if the producer has finished playing. Is there a better way to do it?
@@ -94,10 +101,9 @@ static void consumer_gl_frame_show(mlt_consumer, Render * self, mlt_frame frame_
 }
 
 Render::Render(const QString & rendererName, int winid, QString profile, QWidget *parent) :
-    QObject(parent),
+    AbstractRender(rendererName, parent),
     m_isBlocked(0),
     analyseAudio(KdenliveSettings::monitor_audio()),
-    sendFrameForAnalysis(false),
     m_name(rendererName),
     m_mltConsumer(NULL),
     m_mltProducer(NULL),
@@ -179,7 +185,6 @@ void Render::buildConsumer(const QString profileName)
 {
     m_activeProfile = profileName;
     char *tmp = qstrdup(m_activeProfile.toUtf8().constData());
-    setenv("MLT_PROFILE", tmp, 1);
     delete m_blackClip;
     m_blackClip = NULL;
 
@@ -188,7 +193,7 @@ void Render::buildConsumer(const QString profileName)
     if (m_mltProfile) delete m_mltProfile;
 
     m_mltProfile = new Mlt::Profile(tmp);
-    m_mltProfile->get_profile()->is_explicit = 1;
+    m_mltProfile->set_explicit(true);
     delete[] tmp;
 
     m_blackClip = new Mlt::Producer(*m_mltProfile, "colour", "black");
@@ -241,6 +246,7 @@ void Render::buildConsumer(const QString profileName)
         m_mltConsumer = new Mlt::Consumer(*m_mltProfile, "sdl_preview");
         // FIXME: the event object returned by the listen gets leaked...
         m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
+        m_mltConsumer->listen("consumer-sdl-paused", this, (mlt_listener) consumer_paused);
         m_mltConsumer->set("window_id", m_winid);
     }
     m_mltConsumer->set("resize", 1);
@@ -283,6 +289,7 @@ Mlt::Producer *Render::invalidProducer(const QString &id)
 
 int Render::resetProfile(const QString profileName)
 {
+    QString scene = sceneList();
     if (m_mltConsumer) {
         if (m_externalConsumer == KdenliveSettings::external_display()) {
             if (KdenliveSettings::external_display() && m_activeProfile == profileName) return 1;
@@ -303,9 +310,9 @@ int Render::resetProfile(const QString profileName)
         delete m_mltConsumer;
         m_mltConsumer = NULL;
     }
-    QString scene = sceneList();
     int pos = 0;
     double current_fps = m_mltProfile->fps();
+    double current_dar = m_mltProfile->dar();
     delete m_blackClip;
     m_blackClip = NULL;
 
@@ -327,6 +334,7 @@ int Render::resetProfile(const QString profileName)
     m_mltProducer = NULL;
     buildConsumer(profileName);
     double new_fps = m_mltProfile->fps();
+    double new_dar = m_mltProfile->dar();
     if (current_fps != new_fps) {
         // fps changed, we must update the scenelist positions
         scene = updateSceneListFps(current_fps, new_fps, scene);
@@ -334,7 +342,7 @@ int Render::resetProfile(const QString profileName)
     //kDebug() << "//RESET WITHSCENE: " << scene;
     setSceneList(scene, pos);
     // producers have changed (different profile), so reset them...
-    emit refreshDocumentProducers();
+    emit refreshDocumentProducers(new_dar != current_dar, current_fps != new_fps);
     /*Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "xml-string", scene.toUtf8().constData());
     m_mltProducer = producer;
     m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
@@ -406,14 +414,26 @@ int Render::renderHeight() const
     return m_mltProfile->height();
 }
 
-QImage Render::extractFrame(int frame_position, int width, int height)
+QImage Render::extractFrame(int frame_position, QString path, int width, int height)
 {
     if (width == -1) {
         width = renderWidth();
         height = renderHeight();
     } else if (width % 2 == 1) width++;
 
-    if (!m_mltProducer) {
+    if (!path.isEmpty()) {
+        Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile, path.toUtf8().constData());
+        if (producer) {
+            if (producer->is_valid()) {
+                QImage img = KThumb::getFrame(producer, frame_position, width, height);
+                delete producer;
+                return img;
+            }
+            else delete producer;
+        }
+    }
+    
+    if (!m_mltProducer || !path.isEmpty()) {
         QImage pix(width, height, QImage::Format_RGB32);
         pix.fill(Qt::black);
         return pix;
@@ -555,7 +575,6 @@ void Render::getFileProperties(const QDomElement xml, const QString &clipId, int
         proxyProducer = false;
     }
 
-
     KUrl url = KUrl(path);
     Mlt::Producer *producer = NULL;
     CLIPTYPE type = (CLIPTYPE)xml.attribute("type").toInt();
@@ -595,9 +614,15 @@ void Render::getFileProperties(const QDomElement xml, const QString &clipId, int
         return;
     }
 
-    if (proxyProducer && xml.hasAttribute("proxy_out") && producer->get_out() != xml.attribute("proxy_out").toInt()) {
-        // Proxy file length is different than original clip length, this will corrupt project so disable this proxy clip
-        emit removeInvalidProxy(clipId, true);
+    if (proxyProducer && xml.hasAttribute("proxy_out")) {
+        producer->set("length", xml.attribute("proxy_out").toInt() + 1);
+        producer->set("out", xml.attribute("proxy_out").toInt());
+        if (producer->get_out() != xml.attribute("proxy_out").toInt()) {
+            // Proxy file length is different than original clip length, this will corrupt project so disable this proxy clip
+            emit removeInvalidProxy(clipId, true);
+            delete producer;
+            return;
+        }
     }
 
     if (xml.hasAttribute("force_aspect_ratio")) {
@@ -1001,6 +1026,7 @@ int Render::setSceneList(QString playlist, int position)
                 resource = mlt_properties_get(properties, "mlt_service");
             }
 
+
             for (int trackNb = tractor.count() - 1; trackNb >= 0; --trackNb) {
                 Mlt::Producer trackProducer(tractor.track(trackNb));
                 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
@@ -1250,7 +1276,6 @@ void Render::stop()
     if (m_mltProducer == NULL) return;
     if (m_mltConsumer && !m_mltConsumer->is_stopped()) {
         kDebug() << "/////////////   RENDER STOPPED: " << m_name;
-        m_isBlocked = true;
         //m_mltConsumer->set("refresh", 0);
         m_mltConsumer->stop();
         // delete m_mltConsumer;
@@ -1296,36 +1321,24 @@ void Render::pause()
     m_mltConsumer->purge();
 }
 
-void Render::switchPlay()
+void Render::switchPlay(bool play)
 {
     if (!m_mltProducer || !m_mltConsumer)
         return;
     if (m_isZoneMode) resetZoneMode();
-    if (m_mltProducer->get_speed() == 0.0) {
+    if (play && m_mltProducer->get_speed() == 0.0) {
         m_isBlocked = false;
         if (m_name == "clip" && m_framePosition == (int) m_mltProducer->get_out()) m_mltProducer->seek(0);
         m_mltProducer->set_speed(1.0);
         m_mltConsumer->set("refresh", 1);
-    } else {
+    } else if (!play) {
         m_isBlocked = true;
         m_mltConsumer->set("refresh", 0);
         m_mltProducer->set_speed(0.0);
         //emit rendererPosition(m_framePosition);
         m_mltProducer->seek(m_framePosition);
-        m_mltConsumer->purge();
-        //kDebug()<<" *********  RENDER PAUSE: "<<m_mltProducer->get_speed();
-        //m_mltConsumer->set("refresh", 0);
-        /*mlt_position position = mlt_producer_position( m_mltProducer->get_producer() );
-        m_mltProducer->set_speed(0);
-        m_mltProducer->seek( position );
-               //m_mltProducer->seek((int) m_framePosition);
-               m_isBlocked = false;*/
+        //m_mltConsumer->purge();
     }
-    /*if (speed == 0.0) {
-    m_mltProducer->seek((int) m_framePosition + 1);
-        m_mltConsumer->purge();
-    }*/
-    //refresh();
 }
 
 void Render::play(double speed)
@@ -1633,7 +1646,7 @@ Mlt::Producer *Render::checkSlowMotionProducer(Mlt::Producer *prod, QDomElement
     if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
     Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
     if (!slowprod || slowprod->get_producer() == NULL) {
-        slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", url.toUtf8().constData());
+        slowprod = new Mlt::Producer(*m_mltProfile, 0, ("framebuffer:" + url).toUtf8().constData());
         if (strobe > 1) slowprod->set("strobe", strobe);
         QString id = prod->get("id");
         if (id.contains('_')) id = id.section('_', 0, 0);
@@ -1806,7 +1819,7 @@ bool Render::mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *pr
         return false;
     }
     Mlt::Tractor tractor(service);
-    Mlt::Producer trackProducer(tractor.track(info.track));
+    Mlt::Producer trackProducer(tractor.track(tractor.count() - 1 - info.track));
     Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
     int startPos = info.startPos.frames(m_fps);
     int clipIndex = trackPlaylist.get_clip_index_at(startPos);
@@ -2462,7 +2475,6 @@ bool Render::mltAddEffect(Mlt::Service service, EffectsParameterList params, int
     // create filter
     QString tag =  params.paramValue("tag");
     kDebug() << " / / INSERTING EFFECT: " << tag << ", REGI: " << region;
-    if (tag.startsWith("ladspa")) tag = "ladspa";
     char *filterTag = qstrdup(tag.toUtf8().constData());
     char *filterId = qstrdup(params.paramValue("id").toUtf8().constData());
     QHash<QString, QString>::Iterator it;
@@ -3833,12 +3845,12 @@ const QList <Mlt::Producer *> Render::producersList()
         delete tt;
         Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
         int clipNb = trackPlaylist.count();
-        //kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
         for (int i = 0; i < clipNb; i++) {
             Mlt::Producer *c = trackPlaylist.get_clip(i);
             Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
             if (nprod) {
-                if (!nprod->is_blank() && !ids.contains(nprod->get("id"))) {
+                QString prodId = nprod->get("id");
+                if (!prodId.startsWith("slowmotion") && !prodId.isEmpty() && !nprod->is_blank() && !ids.contains(prodId)) {
                     ids.append(nprod->get("id"));
                     prods.append(nprod);
                 } else delete nprod;
@@ -4009,17 +4021,7 @@ void Render::mltDeleteTrack(int ix)
     tractor.removeChild(track);
     //kDebug() << "/////////// RESULT SCENE: \n" << doc.toString();
     setSceneList(doc.toString(), m_framePosition);
-
-    /*    if (m_mltProducer != NULL) {
-            Mlt::Producer parentProd(m_mltProducer->parent());
-            if (parentProd.get_producer() != NULL) {
-                Mlt::Service service(parentProd.get_service());
-                if (service.type() == tractor_type) {
-                    Mlt::Tractor tractor(service);
-                    mltCheckLength(&tractor);
-                }
-            }
-        }*/
+    emit refreshDocumentProducers(false, false);
 }
 
 
@@ -4148,6 +4150,11 @@ void Render::sendFrameUpdate()
     }
 }
 
+Mlt::Producer* Render::getProducer()
+{
+    return m_mltProducer;
+}
+
 
 #include "renderer.moc"