]> git.sesse.net Git - kdenlive/blobdiff - src/docclipbase.cpp
Move undo commands to their own subdirectory
[kdenlive] / src / docclipbase.cpp
index ef78b24207ef0e5176defd4a4a684f312d7fedd4..c1facc9a94de737a931a1e9658d50ce6124a6e57 100644 (file)
@@ -98,6 +98,8 @@ DocClipBase::~DocClipBase()
         m_audioTimer->stop();
         delete m_audioTimer;
     }
+    qDeleteAll(m_toDeleteProducers);
+    m_toDeleteProducers.clear();
     qDeleteAll(m_baseTrackProducers);
     m_baseTrackProducers.clear();
     qDeleteAll(m_audioTrackProducers);
@@ -163,11 +165,6 @@ const QString &DocClipBase::getId() const
     return m_id;
 }
 
-void DocClipBase::setId(const QString &newId)
-{
-    m_id = newId;
-}
-
 const CLIPTYPE & DocClipBase::clipType() const
 {
     return m_clipType;
@@ -418,7 +415,7 @@ void DocClipBase::clearThumbProducer()
 
 void DocClipBase::deleteProducers()
 {
-    m_thumbProd->clearProducer();
+    if (m_thumbProd) m_thumbProd->clearProducer();
     
     if (numReferences() > 0) {
         // Clip is used in timeline, delay producers deletion
@@ -443,6 +440,20 @@ void DocClipBase::deleteProducers()
 
 void DocClipBase::cleanupProducers()
 {
+    /*
+    int ct = 0;
+    kDebug()<<"----------------------------------------------------------------------------------";
+    for (int i = 0; i < m_toDeleteProducers.count(); i++) {
+        if (m_toDeleteProducers.at(i) != NULL) {
+            Mlt::Properties props(m_toDeleteProducers.at(i)->get_properties());
+            if (props.ref_count() > 2) {
+                kDebug()<<"PRODUCER: "<<i<<", COUNTS: "<<props.ref_count();
+                //exit(1);
+            }
+            ct++;
+        }
+    }*/
+
     qDeleteAll(m_toDeleteProducers);
     m_toDeleteProducers.clear();
     m_replaceMutex.unlock();
@@ -496,12 +507,14 @@ void DocClipBase::setProducer(Mlt::Producer *producer, bool reset, bool readProp
                 m_audioTrackProducers[pos] = producer;
                 updated = true;
             }
+            else delete producer;
             return;
         } else if (id.endsWith("video")) {
             if (m_videoOnlyProducer == NULL) {
                 m_videoOnlyProducer = producer;
                 updated = true;
             }
+            else delete producer;
             return;
         }
         int pos = id.toInt();
@@ -514,6 +527,7 @@ void DocClipBase::setProducer(Mlt::Producer *producer, bool reset, bool readProp
             m_baseTrackProducers[pos] = producer;
             updated = true;
         }
+        else delete producer;
     } else {
         if (m_baseTrackProducers.isEmpty()) {
             m_baseTrackProducers.append(producer);
@@ -523,6 +537,7 @@ void DocClipBase::setProducer(Mlt::Producer *producer, bool reset, bool readProp
             m_baseTrackProducers[0] = producer;
             updated = true;
         }
+        else delete producer;
     }
     if (updated && readPropertiesFromProducer && (m_clipType != COLOR && m_clipType != IMAGE && m_clipType != TEXT))
         setDuration(GenTime(producer->get_length(), KdenliveSettings::project_fps()));
@@ -606,6 +621,45 @@ Mlt::Producer *DocClipBase::videoProducer()
     return m_videoOnlyProducer;
 }
 
+Mlt::Producer *DocClipBase::getCloneProducer()
+{
+    Mlt::Producer *source = NULL;
+    Mlt::Producer *prod = NULL;
+    if (m_clipType != AUDIO && m_clipType != AV && m_clipType != PLAYLIST) {
+        source = getProducer();
+        if (!source) return NULL;
+    }
+    if (m_clipType == COLOR) {
+        prod = new Mlt::Producer(*(source->profile()), 0, QString("colour:" + QString(source->get("resource"))).toUtf8().constData());
+    } else if (m_clipType == TEXT) {
+        prod = new Mlt::Producer(*(source->profile()), 0, QString("kdenlivetitle:" + QString(source->get("resource"))).toUtf8().constData());
+        if (prod && prod->is_valid() && m_properties.contains("xmldata"))
+            prod->set("xmldata", m_properties.value("xmldata").toUtf8().constData());
+    }
+    if (!prod) {
+        if (!source) {
+            QMutexLocker locker(&m_producerMutex);
+            for (int i = 0; i < m_baseTrackProducers.count(); i++) {
+                if (m_baseTrackProducers.at(i) != NULL) {
+                    source = m_baseTrackProducers.at(i);
+                    break;
+                }
+            }
+            if (!source) return NULL;
+        }
+        prod = cloneProducer(source);
+    }
+    if (prod) {
+        adjustProducerProperties(prod, getId() + "_", false, false);
+        if (!m_properties.contains("proxy_out")) {
+            // Adjust length in case...
+            if (m_properties.contains("duration")) prod->set("length", m_properties.value("duration").toInt());
+            if (m_properties.contains("out"))prod->set("out", m_properties.value("out").toInt());
+        }
+    }
+    return prod;
+}
+
 Mlt::Producer *DocClipBase::getProducer(int track)
 {
     QMutexLocker locker(&m_producerMutex);
@@ -634,8 +688,9 @@ Mlt::Producer *DocClipBase::getProducer(int track)
             // Could not find a valid producer for that clip, check in 
             return NULL;
         }
-        m_baseTrackProducers[track] = cloneProducer(m_baseTrackProducers.at(i));
-        adjustProducerProperties(m_baseTrackProducers.at(track), QString(getId() + '_' + QString::number(track)), false, false);
+        Mlt::Producer *prod = cloneProducer(m_baseTrackProducers.at(i));
+        adjustProducerProperties(prod, QString(getId() + '_' + QString::number(track)), false, false);
+        m_baseTrackProducers[track] = prod;
     }
     return m_baseTrackProducers.at(track);
 }
@@ -1154,10 +1209,10 @@ bool DocClipBase::hasAudioCodec(const QString &codec) const
 }
 
 
-void DocClipBase::slotExtractImage(int frame, int frame2)
+void DocClipBase::slotExtractImage(QList <int> frames)
 {
     if (m_thumbProd == NULL) return;
-    m_thumbProd->extractImage(frame, frame2);
+    m_thumbProd->extractImage(frames);
 }
 
 QPixmap DocClipBase::extractImage(int frame, int width, int height)