]> git.sesse.net Git - kdenlive/blobdiff - src/docclipbase.cpp
automatically select if we should export audio or not:
[kdenlive] / src / docclipbase.cpp
index 122ea7e5701486742d17af1bbda95b6757568ba1..4e26b005f95650ea4786ff89171f3cc196ddcc1a 100644 (file)
@@ -34,6 +34,8 @@
 
 #include <QCryptographicHash>
 
+#include <cstdio>
+
 DocClipBase::DocClipBase(ClipManager *clipManager, QDomElement xml, const QString &id) :
         QObject(),
         m_audioFrameCache(),
@@ -41,7 +43,7 @@ DocClipBase::DocClipBase(ClipManager *clipManager, QDomElement xml, const QStrin
         m_baseTrackProducers(),
         m_audioTrackProducers(),
         m_videoOnlyProducer(NULL),
-        m_snapMarkers(),
+        m_snapMarkers(QList < CommentedTime >()),
         m_duration(),
         m_audioTimer(NULL),
         m_thumbProd(NULL),
@@ -55,7 +57,10 @@ DocClipBase::DocClipBase(ClipManager *clipManager, QDomElement xml, const QStrin
     if (m_placeHolder) xml.removeAttribute("placeholder");
     QDomNamedNodeMap attributes = xml.attributes();
     for (int i = 0; i < attributes.count(); i++) {
-        m_properties.insert(attributes.item(i).nodeName(), attributes.item(i).nodeValue());
+        QString name = attributes.item(i).nodeName();
+        if (name.startsWith("meta.attr.")) {
+            m_metadata.insert(name.section('.', 2, 3), attributes.item(i).nodeValue());
+        } else m_properties.insert(name, attributes.item(i).nodeValue());
     }
 
     if (xml.hasAttribute("cutzones")) {
@@ -124,23 +129,20 @@ void DocClipBase::setZone(QPoint zone)
 
 QPoint DocClipBase::zone() const
 {
-    QPoint zone;
-    zone.setX(m_properties.value("zone_in").toInt());
-    zone.setY(m_properties.value("zone_out", "50").toInt());
+    QPoint zone(m_properties.value("zone_in", "0").toInt(), m_properties.value("zone_out", "50").toInt());
     return zone;
 }
 
 void DocClipBase::slotCreateAudioTimer()
 {
     connect(m_thumbProd, SIGNAL(audioThumbReady(QMap <int, QMap <int, QByteArray> >)), this , SLOT(updateAudioThumbnail(QMap <int, QMap <int, QByteArray> >)));
-    connect(this, SIGNAL(getAudioThumbs()), this , SLOT(slotGetAudioThumbs()));
     m_audioTimer = new QTimer(this);
     connect(m_audioTimer, SIGNAL(timeout()), this, SLOT(slotGetAudioThumbs()));
 }
 
 void DocClipBase::askForAudioThumbs()
 {
-    if (m_thumbProd && m_audioTimer) slotGetAudioThumbs();
+    if (m_thumbProd && m_audioTimer) m_thumbProd->askForAudioThumbs(getId());
 }
 
 void DocClipBase::slotClearAudioCache()
@@ -323,10 +325,6 @@ QList < CommentedTime > DocClipBase::commentedSnapMarkers() const
     return m_snapMarkers;
 }
 
-void DocClipBase::setSnapMarkers(QList < CommentedTime > markers)
-{
-    m_snapMarkers = markers;
-}
 
 void DocClipBase::addSnapMarker(const GenTime & time, QString comment)
 {
@@ -433,10 +431,10 @@ void DocClipBase::clearProducers()
     m_baseTrackProducers.clear();
 }
 
-void DocClipBase::deleteProducers()
+void DocClipBase::deleteProducers(bool clearThumbCreator)
 {
     kDebug() << "// CLIP KILL PRODS ct: " << m_baseTrackProducers.count();
-    if (m_thumbProd) m_thumbProd->clearProducer();
+    if (clearThumbCreator && m_thumbProd) m_thumbProd->clearProducer();
     /*kDebug()<<"// CLIP KILL PRODS ct: "<<m_baseTrackProducers.count();
     int max = m_baseTrackProducers.count();
     for (int i = 0; i < max; i++) {
@@ -458,13 +456,19 @@ void DocClipBase::deleteProducers()
     m_audioTrackProducers.clear();
 }
 
+void DocClipBase::setValid()
+{
+    m_placeHolder = false;
+}
+
 void DocClipBase::setProducer(Mlt::Producer *producer, bool reset)
 {
-    if (producer == NULL) return;
+    if (producer == NULL || (m_placeHolder && !reset)) return;
+    if (m_thumbProd && (reset || !m_thumbProd->hasProducer())) m_thumbProd->setProducer(producer);
     if (reset) {
         // Clear all previous producers
         kDebug() << "/+++++++++++++++   DELETE ALL PRODS " << producer->get("id");
-        deleteProducers();
+        deleteProducers(false);
     }
     QString id = producer->get("id");
     if (id.contains('_')) {
@@ -496,7 +500,6 @@ void DocClipBase::setProducer(Mlt::Producer *producer, bool reset)
     }
     //m_clipProducer = producer;
     //m_clipProducer->set("transparency", m_properties.value("transparency").toInt());
-    if (m_thumbProd && (reset || !m_thumbProd->hasProducer())) m_thumbProd->setProducer(producer);
 }
 
 Mlt::Producer *DocClipBase::audioProducer(int track)
@@ -510,6 +513,7 @@ Mlt::Producer *DocClipBase::audioProducer(int track)
         Mlt::Producer *base = producer();
         m_audioTrackProducers[track] = new Mlt::Producer(*(base->profile()), base->get("resource"));
         if (m_properties.contains("force_aspect_ratio")) m_audioTrackProducers.at(track)->set("force_aspect_ratio", m_properties.value("force_aspect_ratio").toDouble());
+        if (m_properties.contains("force_fps")) m_audioTrackProducers.at(track)->set("force_fps", m_properties.value("force_fps").toDouble());
         if (m_properties.contains("force_progressive")) m_audioTrackProducers.at(track)->set("force_progressive", m_properties.value("force_progressive").toInt());
         if (m_properties.contains("threads")) m_audioTrackProducers.at(track)->set("threads", m_properties.value("threads").toInt());
         m_audioTrackProducers.at(track)->set("video_index", -1);
@@ -530,6 +534,7 @@ Mlt::Producer *DocClipBase::videoProducer()
         if (i >= m_baseTrackProducers.count()) return NULL;
         m_videoOnlyProducer = new Mlt::Producer(*m_baseTrackProducers.at(i)->profile(), m_baseTrackProducers.at(i)->get("resource"));
         if (m_properties.contains("force_aspect_ratio")) m_videoOnlyProducer->set("force_aspect_ratio", m_properties.value("force_aspect_ratio").toDouble());
+        if (m_properties.contains("force_fps")) m_videoOnlyProducer->set("force_fps", m_properties.value("force_fps").toDouble());
         if (m_properties.contains("force_progressive")) m_videoOnlyProducer->set("force_progressive", m_properties.value("force_progressive").toInt());
         if (m_properties.contains("threads")) m_videoOnlyProducer->set("threads", m_properties.value("threads").toInt());
         m_videoOnlyProducer->set("audio_index", -1);
@@ -572,8 +577,8 @@ Mlt::Producer *DocClipBase::producer(int track)
             m_baseTrackProducers[track] = NULL;
             return NULL;
         }
-
         if (m_properties.contains("force_aspect_ratio")) m_baseTrackProducers[track]->set("force_aspect_ratio", m_properties.value("force_aspect_ratio").toDouble());
+        if (m_properties.contains("force_fps")) m_baseTrackProducers[track]->set("force_fps", m_properties.value("force_fps").toDouble());
         if (m_properties.contains("force_progressive")) m_baseTrackProducers[track]->set("force_progressive", m_properties.value("force_progressive").toInt());
         if (m_properties.contains("threads")) m_baseTrackProducers[track]->set("threads", m_properties.value("threads").toInt());
         if (m_properties.contains("video_index")) m_baseTrackProducers[track]->set("video_index", m_properties.value("video_index").toInt());
@@ -613,6 +618,14 @@ void DocClipBase::setProducerProperty(const char *name, const char *data)
     }
 }
 
+void DocClipBase::resetProducerProperty(const char *name)
+{
+    for (int i = 0; i < m_baseTrackProducers.count(); i++) {
+        if (m_baseTrackProducers.at(i) != NULL)
+            m_baseTrackProducers[i]->set(name, (const char*) NULL);
+    }
+}
+
 const char *DocClipBase::producerProperty(const char *name) const
 {
     for (int i = 0; i < m_baseTrackProducers.count(); i++) {
@@ -710,7 +723,15 @@ void DocClipBase::setProperties(QMap <QString, QString> properties)
 
 void DocClipBase::setMetadata(QMap <QString, QString> properties)
 {
-    m_metadata = properties;
+    QMapIterator<QString, QString> i(properties);
+    while (i.hasNext()) {
+        i.next();
+        if (i.value().isEmpty() && m_metadata.contains(i.key())) {
+            m_metadata.remove(i.key());
+        } else {
+            m_metadata.insert(i.key(), i.value());
+        }
+    }
 }
 
 QMap <QString, QString> DocClipBase::metadata() const
@@ -748,6 +769,13 @@ void DocClipBase::getFileHash(const QString url)
     }
 }
 
+bool DocClipBase::checkHash() const
+{
+    KUrl url = fileURL();
+    if (!url.isEmpty() && getClipHash() != getHash(url.path())) return false;
+    return true;
+}
+
 QString DocClipBase::getClipHash() const
 {
     QString hash;
@@ -758,6 +786,11 @@ QString DocClipBase::getClipHash() const
     return hash;
 }
 
+void DocClipBase::setPlaceHolder(bool place)
+{
+    m_placeHolder = place;
+}
+
 // static
 QString DocClipBase::getHash(const QString &path)
 {
@@ -811,12 +844,17 @@ void DocClipBase::setProperty(const QString &key, const QString &value)
     } else if (key == "force_aspect_ratio") {
         if (value.isEmpty()) {
             m_properties.remove("force_aspect_ratio");
-            setProducerProperty("force_aspect_ratio", NULL);
+            resetProducerProperty("force_aspect_ratio");
         } else setProducerProperty("force_aspect_ratio", value.toDouble());
+    } else if (key == "force_fps") {
+        if (value.isEmpty()) {
+            m_properties.remove("force_fps");
+            resetProducerProperty("force_fps");
+        } else setProducerProperty("force_fps", value.toDouble());
     } else if (key == "force_progressive") {
         if (value.isEmpty()) {
             m_properties.remove("force_progressive");
-            setProducerProperty("force_progressive", NULL);
+            resetProducerProperty("force_progressive");
         } else setProducerProperty("force_progressive", value.toInt());
     } else if (key == "threads") {
         if (value.isEmpty()) {
@@ -913,3 +951,38 @@ QList <CutZoneInfo> DocClipBase::cutZones() const
     return m_cutZones;
 }
 
+bool DocClipBase::hasVideoCodec(const QString &codec) const
+{
+    Mlt::Producer *prod = NULL;
+    if (m_baseTrackProducers.count() == 0) return false;
+    for (int i = 0; i < m_baseTrackProducers.count(); i++) {
+        if (m_baseTrackProducers.at(i) != NULL) {
+            prod = m_baseTrackProducers.at(i);
+            break;
+        }
+    }
+
+    if (!prod) return false;
+    int default_video = prod->get_int("video_index");
+    char property[200];
+    snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
+    return prod->get(property) == codec;
+}
+
+bool DocClipBase::hasAudioCodec(const QString &codec) const
+{
+    Mlt::Producer *prod = NULL;
+    if (m_baseTrackProducers.count() == 0) return false;
+    for (int i = 0; i < m_baseTrackProducers.count(); i++) {
+        if (m_baseTrackProducers.at(i) != NULL) {
+            prod = m_baseTrackProducers.at(i);
+            break;
+        }
+    }
+    if (!prod) return false;
+    int default_video = prod->get_int("audio_index");
+    char property[200];
+    snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
+    return prod->get(property) == codec;
+}
+