]> git.sesse.net Git - kdenlive/blobdiff - src/renderer.cpp
[valgrind] unfixed memleak
[kdenlive] / src / renderer.cpp
index 66639e9534f40d1d8c3c7864b6bde6493a0b8241..ab45295d0e75f6fedda923f5dab4b925cbe0bb98 100644 (file)
@@ -55,18 +55,18 @@ static void consumer_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr
 
 Render::Render(const QString & rendererName, int winid, int extid, QWidget *parent) :
         QObject(parent),
+        m_isBlocked(true),
         m_name(rendererName),
         m_mltConsumer(NULL),
         m_mltProducer(NULL),
         m_mltTextProducer(NULL),
-        m_winid(winid),
-        m_externalwinid(extid),
         m_framePosition(0),
-        m_isBlocked(true),
-        m_blackClip(NULL),
-        m_isSplitView(false),
         m_isZoneMode(false),
-        m_isLoopMode(false)
+        m_isLoopMode(false),
+        m_isSplitView(false),
+        m_blackClip(NULL),
+        m_winid(winid),
+        m_externalwinid(extid)
 {
     kDebug() << "//////////  USING PROFILE: " << (char*)KdenliveSettings::current_profile().toUtf8().data();
     refreshTimer = new QTimer(this);
@@ -132,8 +132,11 @@ void Render::buildConsumer()
     m_mltConsumer->set("resize", 1);
     m_mltConsumer->set("window_id", m_winid);
     m_mltConsumer->set("terminate_on_pause", 1);
-    m_mltConsumer->set("window_background", decodedString(KdenliveSettings::window_background().name()));
+    tmp = decodedString(KdenliveSettings::window_background().name());
+    m_mltConsumer->set("window_background", tmp);
+    delete [] tmp;
 
+    // FIXME: the event object returned by the listen gets leaked...
     m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
     m_mltConsumer->set("rescale", "nearest");
 
@@ -523,6 +526,7 @@ void Render::getFileProperties(const QDomElement &xml, const QString &clipId, bo
     if (producer == NULL || producer->is_blank() || !producer->is_valid()) {
         kDebug() << " / / / / / / / / ERROR / / / / // CANNOT LOAD PRODUCER: ";
         emit removeInvalidClip(clipId);
+        delete producer;
         return;
     }
 
@@ -639,6 +643,7 @@ void Render::getFileProperties(const QDomElement &xml, const QString &clipId, bo
         /*if (context->duration == AV_NOPTS_VALUE) {
         kDebug() << " / / / / / / / /ERROR / / / CLIP HAS UNKNOWN DURATION";
             emit removeInvalidClip(clipId);
+            delete producer;
             return;
         }*/
         // Get the video_index
@@ -710,6 +715,7 @@ void Render::getFileProperties(const QDomElement &xml, const QString &clipId, bo
     emit replyGetFileProperties(clipId, producer, filePropertyMap, metadataPropertyMap, replaceProducer);
     kDebug() << "REquested fuile info for: " << url.path();
     if (frame) delete frame;
+    // FIXME: should delete this to avoid a leak...
     //if (producer) delete producer;
 }
 
@@ -803,6 +809,7 @@ void Render::setSceneList(QString playlist, int position)
 {
     if (m_winid == -1) return;
     m_isBlocked = true;
+    qDeleteAll(m_slowmotionProducers.values());
     m_slowmotionProducers.clear();
 
     //kWarning() << "//////  RENDER, SET SCENE LIST: " << playlist;
@@ -868,6 +875,7 @@ void Render::setSceneList(QString playlist, int position)
     }
     m_isBlocked = false;
     blockSignals(false);
+    emit refreshDocumentProducers();
     //kDebug()<<"// SETSCN LST, POS: "<<position;
     //if (position != 0) emit rendererPosition(position);
 }
@@ -964,6 +972,7 @@ void Render::connectPlaylist()
     /*
      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 {
@@ -1032,6 +1041,7 @@ void Render::start()
         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;
         } else {
@@ -1451,7 +1461,7 @@ void Render::mltCutClip(int track, GenTime position)
     int ct = 0;
     Mlt::Filter *filter = clipService.filter(ct);
     while (filter) {
-        if (filter->is_valid() && filter->get("kdenlive_id") != "") {
+        if (filter->is_valid() && strcmp(filter->get("kdenlive_id"), "")) {
             // looks like there is no easy way to duplicate a filter,
             // so we will create a new one and duplicate its properties
             Mlt::Filter *dup = new Mlt::Filter(*m_mltProfile, filter->get("mlt_service"));
@@ -1846,7 +1856,7 @@ bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool up
     int ct = 0;
     Mlt::Filter *filter = clipService.filter(ct);
     while (filter) {
-        if ((index == "-1" && filter->get("kdenlive_id") != "")  || filter->get("kdenlive_ix") == index) {// && filter->get("kdenlive_id") == id) {
+        if ((index == "-1" && strcmp(filter->get("kdenlive_id"), ""))  || filter->get("kdenlive_ix") == index) {// && filter->get("kdenlive_id") == id) {
             if (clipService.detach(*filter) == 0) success = true;
             kDebug() << " / / / DLEETED EFFECT: " << ct;
         } else if (updateIndex) {
@@ -2386,10 +2396,10 @@ bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEn
     kDebug() << "//////  LOOKING FOR CLIP TO MOVE, INDEX: " << clipIndex;
     bool checkLength = false;
     if (endTrack == startTrack) {
-        //mlt_service_lock(service.get_service());
         Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
         if (!trackPlaylist.is_blank_at(moveEnd) || clipProducer.is_blank()) {
             // error, destination is not empty
+            if (!trackPlaylist.is_blank_at(moveEnd)) trackPlaylist.insert_at(moveStart, clipProducer, 1);
             //int ix = trackPlaylist.get_clip_index_at(moveEnd);
             kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
             mlt_service_unlock(m_mltConsumer->get_service());
@@ -2430,7 +2440,15 @@ bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEn
             QString currentid = clipProducer.parent().get("id");
             if (serv == "framebuffer" || currentid.endsWith("_video")) {
                 clip = &clipProducer;
-            } else clip = prod->cut(clipProducer.get_in(), clipProducer.get_out());
+            } else {
+                if (prod == NULL) {
+                    // Special case: prod is null when using placeholder clips.
+                    // in that case, use the producer existing in playlist. Note that
+                    // it will bypass the one producer per track logic and might cause
+                    // Sound cracks if clip is moved so that it overlaps another copy of itself
+                    clip = clipProducer.cut(clipProducer.get_in(), clipProducer.get_out());
+                } else clip = prod->cut(clipProducer.get_in(), clipProducer.get_out());
+            }
 
             // move all effects to the correct producer
             Mlt::Service clipService(clipProducer.get_service());
@@ -2850,16 +2868,22 @@ QList <Mlt::Producer *> Render::producersList()
 
     int trackNb = tractor.count();
     for (int t = 1; t < trackNb; t++) {
-        Mlt::Producer trackProducer(tractor.track(t));
+        Mlt::Producer *tt = tractor.track(t);
+        Mlt::Producer trackProducer(tt);
+        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 *nprod = new Mlt::Producer(trackPlaylist.get_clip(i)->get_parent());
-            if (nprod && !nprod->is_blank() && !ids.contains(nprod->get("id"))) {
-                ids.append(nprod->get("id"));
-                prods.append(nprod);
+            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"))) {
+                    ids.append(nprod->get("id"));
+                    prods.append(nprod);
+                } else delete nprod;
             }
+            delete c;
         }
     }
     return prods;
@@ -2874,21 +2898,25 @@ void Render::fillSlowMotionProducers()
 
     int trackNb = tractor.count();
     for (int t = 1; t < trackNb; t++) {
-        Mlt::Producer trackProducer(tractor.track(t));
+        Mlt::Producer *tt = tractor.track(t);
+        Mlt::Producer trackProducer(tt);
+        delete tt;
         Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
         int clipNb = trackPlaylist.count();
         for (int i = 0; i < clipNb; i++) {
-            Mlt::Producer *nprod = new Mlt::Producer(trackPlaylist.get_clip(i)->get_parent());
-            if (nprod && !nprod->is_blank()) {
+            Mlt::Producer *c = trackPlaylist.get_clip(i);
+            Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
+            if (nprod) {
                 QString id = nprod->get("id");
-                if (id.startsWith("slowmotion:")) {
+                if (id.startsWith("slowmotion:") && !nprod->is_blank()) {
                     // this is a slowmotion producer, add it to the list
                     QString url = QString::fromUtf8(nprod->get("resource"));
                     if (!m_slowmotionProducers.contains(url)) {
                         m_slowmotionProducers.insert(url, nprod);
                     }
-                }
+                } else delete nprod;
             }
+            delete c;
         }
     }
 }