]> git.sesse.net Git - kdenlive/blobdiff - src/renderer.cpp
Don't crash when wrong sdl driver was selected by user (needs MLT patch):
[kdenlive] / src / renderer.cpp
index e3e9b428dcecfbe1d60000e99dedd8080698fbf1..e1207dc21b8521318dbdd2ef3139c476eb5967aa 100644 (file)
@@ -550,6 +550,12 @@ void Render::getFileProperties(const QDomElement &xml, const QString &clipId, bo
     producer->set("id", tmp);
     delete[] tmp;
 
+    if (!replaceProducer && xml.hasAttribute("file_hash")) {
+        // Clip  already has all properties
+        emit replyGetFileProperties(clipId, producer, QMap < QString, QString >(), QMap < QString, QString >(), replaceProducer);
+        return;
+    }
+
     int height = 50;
     int width = (int)(height  * m_mltProfile->dar());
     QMap < QString, QString > filePropertyMap;
@@ -758,13 +764,13 @@ void Render::initSceneList()
 
 
 /** Create the producer from the MLT XML QDomDocument */
-void Render::setProducer(Mlt::Producer *producer, int position)
+int Render::setProducer(Mlt::Producer *producer, int position)
 {
-    if (m_winid == -1) return;
+    if (m_winid == -1) return -1;
 
     if (m_mltConsumer) {
         m_mltConsumer->stop();
-    } else return;
+    } else return -1;
 
     m_mltConsumer->purge();
 
@@ -785,27 +791,29 @@ void Render::setProducer(Mlt::Producer *producer, int position)
     if (!m_mltProducer || !m_mltProducer->is_valid()) kDebug() << " WARNING - - - - -INVALID PLAYLIST: ";
 
     m_fps = m_mltProducer->get_fps();
-    connectPlaylist();
+    int error = connectPlaylist();
     if (position != -1) {
         m_mltProducer->seek(position);
         emit rendererPosition(position);
     }
     m_isBlocked = false;
+    return error;
 }
 
 
 
 /** Create the producer from the MLT XML QDomDocument */
-void Render::setSceneList(QDomDocument list, int position)
+int Render::setSceneList(QDomDocument list, int position)
 {
-    setSceneList(list.toString(), position);
+    return setSceneList(list.toString(), position);
 }
 
 /** Create the producer from the MLT XML QDomDocument */
-void Render::setSceneList(QString playlist, int position)
+int Render::setSceneList(QString playlist, int position)
 {
-    if (m_winid == -1) return;
+    if (m_winid == -1) return -1;
     m_isBlocked = true;
+    int error;
     qDeleteAll(m_slowmotionProducers.values());
     m_slowmotionProducers.clear();
 
@@ -814,7 +822,7 @@ void Render::setSceneList(QString playlist, int position)
     if (m_mltConsumer == NULL) {
         kWarning() << "///////  ERROR, TRYING TO USE NULL MLT CONSUMER";
         m_isBlocked = false;
-        return;
+        return -1;
     }
 
     if (!m_mltConsumer->is_stopped()) {
@@ -873,12 +881,13 @@ void Render::setSceneList(QString playlist, int position)
     }
 
     kDebug() << "// NEW SCENE LIST DURATION SET TO: " << m_mltProducer->get_playtime();
-    connectPlaylist();
+    error = connectPlaylist();
     fillSlowMotionProducers();
 
     m_isBlocked = false;
     blockSignals(false);
     emit refreshDocumentProducers();
+    return error;
     //kDebug()<<"// SETSCN LST, POS: "<<position;
     //if (position != 0) emit rendererPosition(position);
 }
@@ -963,24 +972,23 @@ double Render::fps() const
     return m_fps;
 }
 
-void Render::connectPlaylist()
+int Render::connectPlaylist()
 {
-    if (!m_mltConsumer) return;
+    if (!m_mltConsumer) return -1;
     //m_mltConsumer->set("refresh", "0");
     m_mltConsumer->connect(*m_mltProducer);
     m_mltProducer->set_speed(0);
-    m_mltConsumer->start();
+    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;
+        return -1;
+    }
     emit durationChanged(m_mltProducer->get_playtime());
+    return 0;
     //refresh();
-    /*
-     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."));
-          delete m_mltConsumer;
-          m_mltConsumer = NULL;
-     }
-     else {
-             refresh();
-     }*/
 }
 
 void Render::refreshDisplay()
@@ -1039,14 +1047,13 @@ void Render::start()
         kDebug() << "-----  BROKEN MONITOR: " << m_name << ", RESTART";
         return;
     }
-
     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."));
-            delete m_mltConsumer;
-            m_mltConsumer = NULL;
-            return;
+            emit blockMonitors();
+            delete m_mltProducer;
+            m_mltProducer = NULL;
         } else {
             kDebug() << "-----  MONITOR: " << m_name << " REFRESH";
             m_isBlocked = false;
@@ -1075,6 +1082,7 @@ void Render::clear()
 
 void Render::stop()
 {
+    if (m_mltProducer == NULL) return;
     if (m_mltConsumer && !m_mltConsumer->is_stopped()) {
         kDebug() << "/////////////   RENDER STOPPED: " << m_name;
         m_isBlocked = true;
@@ -1248,7 +1256,12 @@ void Render::setDropFrames(bool show)
         if (show == false) dropFrames = 0;
         m_mltConsumer->stop();
         m_mltConsumer->set("play.real_time", dropFrames);
-        m_mltConsumer->start();
+        if (m_mltConsumer->start() == -1) {
+            emit blockMonitors();
+            delete m_mltProducer;
+            m_mltProducer = NULL;
+        }
+
     }
 }
 
@@ -1733,6 +1746,24 @@ void Render::mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int>
     m_mltConsumer->set("refresh", 1);
 }
 
+
+void Render::mltPasteEffects(Mlt::Producer *source, Mlt::Producer *dest)
+{
+    Mlt::Service sourceService(source->get_service());
+    Mlt::Service destService(dest->get_service());
+
+    // move all effects to the correct producer
+    int ct = 0;
+    Mlt::Filter *filter = sourceService.filter(ct);
+    while (filter) {
+        if (filter->get("kdenlive_ix") != 0) {
+            sourceService.detach(*filter);
+            destService.attach(*filter);
+        } else ct++;
+        filter = sourceService.filter(ct);
+    }
+}
+
 int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, Mlt::Producer *prod)
 {
     m_isBlocked = true;
@@ -1762,7 +1793,7 @@ int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, Mlt
         delete clip;
         return -1;
     }
-    delete clip;
+
     QString serv = clipparent.get("mlt_service");
     QString id = clipparent.get("id");
     //kDebug() << "CLIP SERVICE: " << serv;
@@ -1791,6 +1822,10 @@ int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, Mlt
             GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
             cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
         } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart.frames(m_fps) + clipLength) / speed - 1));
+
+        // move all effects to the correct producer
+        mltPasteEffects(clip, cut);
+
         trackPlaylist.insert_at(startPos, *cut, 1);
         clipIndex = trackPlaylist.get_clip_index_at(startPos);
         newLength = trackPlaylist.clip_length(clipIndex);
@@ -1812,6 +1847,10 @@ int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, Mlt
             GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
             cut = prod->cut((int)(info.cropStart.frames(m_fps)), (int)(info.cropStart.frames(m_fps) + maxLength.frames(m_fps) - 1));
         } else cut = prod->cut((int)(info.cropStart.frames(m_fps)), (int)((info.cropStart + newDuration).frames(m_fps)) - 1);
+
+        // move all effects to the correct producer
+        mltPasteEffects(clip, cut);
+
         trackPlaylist.insert_at(startPos, *cut, 1);
         clipIndex = trackPlaylist.get_clip_index_at(startPos);
         newLength = trackPlaylist.clip_length(clipIndex);
@@ -1849,12 +1888,17 @@ int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, Mlt
             cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
         } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart / speed + newDuration).frames(m_fps) - 1));
 
+        // move all effects to the correct producer
+        mltPasteEffects(clip, cut);
+
         trackPlaylist.insert_at(startPos, *cut, 1);
         clipIndex = trackPlaylist.get_clip_index_at(startPos);
         newLength = trackPlaylist.clip_length(clipIndex);
 
         mlt_service_unlock(service.get_service());
     }
+
+    delete clip;
     if (clipIndex + 1 == trackPlaylist.count()) mltCheckLength();
     m_isBlocked = false;
     return newLength;
@@ -2394,18 +2438,7 @@ void Render::mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod)
     Mlt::Producer *clip = prod->cut(clipProducer.get_in(), clipProducer.get_out());
 
     // move all effects to the correct producer
-    Mlt::Service clipService(clipProducer.get_service());
-    Mlt::Service newClipService(clip->get_service());
-
-    int ct = 0;
-    Mlt::Filter *filter = clipService.filter(ct);
-    while (filter) {
-        if (filter->get("kdenlive_ix") != 0) {
-            clipService.detach(*filter);
-            newClipService.attach(*filter);
-        } else ct++;
-        filter = clipService.filter(ct);
-    }
+    mltPasteEffects(&clipProducer, clip);
 
     trackPlaylist.insert_at(pos, clip, 1);
     mlt_service_unlock(m_mltConsumer->get_service());
@@ -2482,18 +2515,7 @@ bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEn
             }
 
             // move all effects to the correct producer
-            Mlt::Service clipService(clipProducer.get_service());
-            Mlt::Service newClipService(clip->get_service());
-
-            int ct = 0;
-            Mlt::Filter *filter = clipService.filter(ct);
-            while (filter) {
-                if (filter->get("kdenlive_ix") != 0) {
-                    clipService.detach(*filter);
-                    newClipService.attach(*filter);
-                } else ct++;
-                filter = clipService.filter(ct);
-            }
+            mltPasteEffects(&clipProducer, clip);
 
             int newIndex = destTrackPlaylist.insert_at(moveEnd, clip, 1);
             destTrackPlaylist.consolidate_blanks(0);
@@ -2898,6 +2920,7 @@ void Render::mltSavePlaylist()
 QList <Mlt::Producer *> Render::producersList()
 {
     QList <Mlt::Producer *> prods;
+    if (m_mltProducer == NULL) return prods;
     Mlt::Service service(m_mltProducer->parent().get_service());
     if (service.type() != tractor_type) return prods;
     Mlt::Tractor tractor(service);
@@ -2928,6 +2951,7 @@ QList <Mlt::Producer *> Render::producersList()
 
 void Render::fillSlowMotionProducers()
 {
+    if (m_mltProducer == NULL) return;
     Mlt::Service service(m_mltProducer->parent().get_service());
     if (service.type() != tractor_type) return;