X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fdocclipbase.cpp;h=be5a321f3de53e93a981407e500068b3cd0a99d9;hb=b4a0ec0fffc1cbbf21d2ea9fc418885e3b34bce8;hp=122ea7e5701486742d17af1bbda95b6757568ba1;hpb=f4b215cd23e90afa5f962d0c29c146a798a77dbf;p=kdenlive diff --git a/src/docclipbase.cpp b/src/docclipbase.cpp index 122ea7e5..be5a321f 100644 --- a/src/docclipbase.cpp +++ b/src/docclipbase.cpp @@ -28,11 +28,16 @@ #include "kdenlivesettings.h" #include "kthumb.h" #include "clipmanager.h" +#include "slideshowclip.h" #include +#include #include #include +#include + +#include DocClipBase::DocClipBase(ClipManager *clipManager, QDomElement xml, const QString &id) : QObject(), @@ -41,9 +46,8 @@ 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), m_audioThumbCreated(false), m_id(id), @@ -55,7 +59,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")) { @@ -79,35 +86,22 @@ DocClipBase::DocClipBase(ClipManager *clipManager, QDomElement xml, const QStrin if (!m_properties.contains("name")) m_properties.insert("name", url.fileName()); - //if (!url.isEmpty() && QFile::exists(url.path())) - { - m_thumbProd = new KThumb(clipManager, url, m_id, m_properties.value("file_hash")); - if (m_clipType == AV || m_clipType == AUDIO || m_clipType == PLAYLIST) slotCreateAudioTimer(); - } - //kDebug() << "type is video" << (m_clipType == AV) << " " << m_clipType; + m_thumbProd = new KThumb(clipManager, url, m_id, m_properties.value("file_hash")); + + // Setup timer to trigger audio thumbs creation + m_audioTimer.setSingleShot(true); + m_audioTimer.setInterval(800); + connect(&m_audioTimer, SIGNAL(timeout()), m_thumbProd, SLOT(slotCreateAudioThumbs())); + } -/*DocClipBase & DocClipBase::operator=(const DocClipBase & clip) { - DocClipBase::operator=(clip); - m_id = clip.getId(); - m_clipType = clip.clipType(); - m_name = clip.name(); - m_duration = clip.duration(); - m_audioThumbCreated = clip.audioThumbCreated(); - m_properties = clip.properties(); - return *this; -}*/ - DocClipBase::~DocClipBase() { - kDebug() << "CLIP " << m_id << " DELETED******************************"; + m_audioTimer.stop(); delete m_thumbProd; - if (m_audioTimer) { - m_audioTimer->stop(); - delete m_audioTimer; - } - /*kDebug() <<" * * *CNT "< 0) kDebug()<<"YOYO: "<get_out()<<", CUT: "<is_cut();*/ + m_thumbProd = NULL; + qDeleteAll(m_toDeleteProducers); + m_toDeleteProducers.clear(); qDeleteAll(m_baseTrackProducers); m_baseTrackProducers.clear(); qDeleteAll(m_audioTrackProducers); @@ -124,29 +118,19 @@ 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 >)), this , SLOT(updateAudioThumbnail(QMap >))); - connect(this, SIGNAL(getAudioThumbs()), this , SLOT(slotGetAudioThumbs())); - m_audioTimer = new QTimer(this); - connect(m_audioTimer, SIGNAL(timeout()), this, SLOT(slotGetAudioThumbs())); -} -void DocClipBase::askForAudioThumbs() +bool DocClipBase::hasAudioThumb() const { - if (m_thumbProd && m_audioTimer) slotGetAudioThumbs(); + if (m_clipType == AUDIO || m_clipType == AV || m_clipType == PLAYLIST) return true; + return false; } void DocClipBase::slotClearAudioCache() { - if (m_thumbProd) m_thumbProd->stopAudioThumbs(); - if (m_audioTimer != NULL) m_audioTimer->stop(); m_audioFrameCache.clear(); m_audioThumbCreated = false; } @@ -176,11 +160,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; @@ -189,10 +168,7 @@ const CLIPTYPE & DocClipBase::clipType() const void DocClipBase::setClipType(CLIPTYPE type) { m_clipType = type; - m_properties.insert("type", QString::number((int) type)); - if (m_thumbProd && m_audioTimer == NULL && (m_clipType == AV || m_clipType == AUDIO || m_clipType == PLAYLIST)) - slotCreateAudioTimer(); } KUrl DocClipBase::fileURL() const @@ -222,7 +198,7 @@ bool DocClipBase::isTransparent() const return (m_properties.value("transparency") == "1"); } -const QString DocClipBase::getProperty(const QString prop) const +const QString DocClipBase::getProperty(const QString &prop) const { return m_properties.value(prop); } @@ -259,7 +235,7 @@ qulonglong DocClipBase::fileSize() const } // virtual -QDomElement DocClipBase::toXML() const +QDomElement DocClipBase::toXML(bool hideTemporaryProperties) const { QDomDocument doc; QDomElement clip = doc.createElement("producer"); @@ -267,6 +243,7 @@ QDomElement DocClipBase::toXML() const QMapIterator i(m_properties); while (i.hasNext()) { i.next(); + if (hideTemporaryProperties && i.key().startsWith("_")) continue; if (!i.value().isEmpty()) clip.setAttribute(i.key(), i.value()); } doc.appendChild(clip); @@ -288,18 +265,7 @@ void DocClipBase::setAudioThumbCreated(bool isDone) m_audioThumbCreated = isDone; } - -void DocClipBase::setThumbnail(const QPixmap & pixmap) -{ - m_thumbnail = pixmap; -} - -const QPixmap & DocClipBase::thumbnail() const -{ - return m_thumbnail; -} - -void DocClipBase::updateAudioThumbnail(QMap > data) +void DocClipBase::updateAudioThumbnail(const audioByteArray& data) { //kDebug() << "CLIPBASE RECIEDVED AUDIO DATA*********************************************"; m_audioFrameCache = data; @@ -323,10 +289,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) { @@ -428,45 +390,100 @@ QString DocClipBase::markerComment(GenTime t) return QString(); } -void DocClipBase::clearProducers() +void DocClipBase::clearThumbProducer() { - m_baseTrackProducers.clear(); + if (m_thumbProd) m_thumbProd->clearProducer(); +} + +void DocClipBase::reloadThumbProducer() +{ + if (m_thumbProd && !m_thumbProd->hasProducer()) + m_thumbProd->setProducer(getProducer()); } void DocClipBase::deleteProducers() { - kDebug() << "// CLIP KILL PRODS ct: " << m_baseTrackProducers.count(); if (m_thumbProd) m_thumbProd->clearProducer(); - /*kDebug()<<"// CLIP KILL PRODS ct: "< 0 && (!m_baseTrackProducers.isEmpty() || m_videoOnlyProducer || !m_audioTrackProducers.isEmpty())) { + // Clip is used in timeline, delay producers deletion + if (m_videoOnlyProducer) m_toDeleteProducers.append(m_videoOnlyProducer); + for (int i = 0; i < m_baseTrackProducers.count(); i++) { + m_toDeleteProducers.append(m_baseTrackProducers.at(i)); + } + for (int i = 0; i < m_audioTrackProducers.count(); i++) { + m_toDeleteProducers.append(m_audioTrackProducers.at(i)); + } + } + else { + delete m_videoOnlyProducer; + qDeleteAll(m_baseTrackProducers); + qDeleteAll(m_audioTrackProducers); + m_replaceMutex.unlock(); + } m_videoOnlyProducer = NULL; - - qDeleteAll(m_baseTrackProducers); m_baseTrackProducers.clear(); - qDeleteAll(m_audioTrackProducers); m_audioTrackProducers.clear(); } -void DocClipBase::setProducer(Mlt::Producer *producer, bool reset) +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: "<get("id"); + QMutexLocker locker(&m_producerMutex); + m_replaceMutex.lock(); deleteProducers(); } QString id = producer->get("id"); + if (m_placeHolder || !producer->is_valid()) { + char *tmp = qstrdup(i18n("Missing clip").toUtf8().constData()); + producer->set("markup", tmp); + producer->set("bgcolour", "0xff0000ff"); + producer->set("pad", "10"); + delete[] tmp; + } + else if (m_thumbProd && !m_thumbProd->hasProducer()) { + if (m_clipType != AUDIO) { + if (!id.endsWith("_audio")) + m_thumbProd->setProducer(producer); + } + else m_thumbProd->setProducer(producer); + getAudioThumbs(); + } + bool updated = false; if (id.contains('_')) { // this is a subtrack producer, insert it at correct place id = id.section('_', 1); @@ -477,10 +494,18 @@ void DocClipBase::setProducer(Mlt::Producer *producer, bool reset) m_audioTrackProducers.append(NULL); } } - if (m_audioTrackProducers.at(pos) == NULL) m_audioTrackProducers[pos] = producer; + if (m_audioTrackProducers.at(pos) == NULL) { + m_audioTrackProducers[pos] = producer; + updated = true; + } + else delete producer; return; } else if (id.endsWith("video")) { - m_videoOnlyProducer = producer; + if (m_videoOnlyProducer == NULL) { + m_videoOnlyProducer = producer; + updated = true; + } + else delete producer; return; } int pos = id.toInt(); @@ -489,68 +514,155 @@ void DocClipBase::setProducer(Mlt::Producer *producer, bool reset) m_baseTrackProducers.append(NULL); } } - if (m_baseTrackProducers.at(pos) == NULL) m_baseTrackProducers[pos] = producer; + if (m_baseTrackProducers.at(pos) == NULL) { + m_baseTrackProducers[pos] = producer; + updated = true; + } + else delete producer; } else { - if (m_baseTrackProducers.isEmpty()) m_baseTrackProducers.append(producer); - else if (m_baseTrackProducers.at(0) == NULL) m_baseTrackProducers[0] = producer; + if (m_baseTrackProducers.isEmpty()) { + m_baseTrackProducers.append(producer); + updated = true; + } + else if (m_baseTrackProducers.at(0) == NULL) { + m_baseTrackProducers[0] = producer; + updated = true; + } + else delete producer; } - //m_clipProducer = producer; - //m_clipProducer->set("transparency", m_properties.value("transparency").toInt()); - if (m_thumbProd && (reset || !m_thumbProd->hasProducer())) m_thumbProd->setProducer(producer); + if (updated && readPropertiesFromProducer && (m_clipType != COLOR && m_clipType != IMAGE && m_clipType != TEXT)) + setDuration(GenTime(producer->get_length(), KdenliveSettings::project_fps())); +} + +static double getPixelAspect(QMap& props) { + int width = props.value("frame_size").section('x', 0, 0).toInt(); + int height = props.value("frame_size").section('x', 1, 1).toInt(); + int aspectNumerator = props.value("force_aspect_num").toInt(); + int aspectDenominator = props.value("force_aspect_den").toInt(); + if (aspectDenominator != 0 && width != 0) + return double(height) * aspectNumerator / aspectDenominator / width; + else + return 1.0; } Mlt::Producer *DocClipBase::audioProducer(int track) { + QMutexLocker locker(&m_producerMutex); if (m_audioTrackProducers.count() <= track) { while (m_audioTrackProducers.count() - 1 < track) { m_audioTrackProducers.append(NULL); } } if (m_audioTrackProducers.at(track) == NULL) { - 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_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); - if (m_properties.contains("audio_index")) m_audioTrackProducers.at(track)->set("audio_index", m_properties.value("audio_index").toInt()); - char *tmp = (char *) qstrdup(QString(getId() + '_' + QString::number(track) + "_audio").toUtf8().data()); - m_audioTrackProducers.at(track)->set("id", tmp); - delete[] tmp; + int i; + for (i = 0; i < m_audioTrackProducers.count(); i++) + if (m_audioTrackProducers.at(i) != NULL) break; + Mlt::Producer *base; + if (i >= m_audioTrackProducers.count()) { + // Could not find a valid producer for that clip + locker.unlock(); + base = getProducer(); + if (base == NULL) { + return NULL; + } + locker.relock(); + } + else base = m_audioTrackProducers.at(i); + m_audioTrackProducers[track] = cloneProducer(base); + adjustProducerProperties(m_audioTrackProducers.at(track), QString(getId() + '_' + QString::number(track) + "_audio"), false, true); } return m_audioTrackProducers.at(track); } + +void DocClipBase::adjustProducerProperties(Mlt::Producer *prod, const QString &id, bool mute, bool blind) +{ + if (m_properties.contains("force_aspect_num") && m_properties.contains("force_aspect_den") && m_properties.contains("frame_size")) + prod->set("force_aspect_ratio", getPixelAspect(m_properties)); + if (m_properties.contains("force_fps")) prod->set("force_fps", m_properties.value("force_fps").toDouble()); + if (m_properties.contains("force_progressive")) prod->set("force_progressive", m_properties.value("force_progressive").toInt()); + if (m_properties.contains("force_tff")) prod->set("force_tff", m_properties.value("force_tff").toInt()); + if (m_properties.contains("threads")) prod->set("threads", m_properties.value("threads").toInt()); + if (mute) prod->set("audio_index", -1); + else if (m_properties.contains("audio_index")) prod->set("audio_index", m_properties.value("audio_index").toInt()); + if (blind) prod->set("video_index", -1); + else if (m_properties.contains("video_index")) prod->set("video_index", m_properties.value("video_index").toInt()); + prod->set("id", id.toUtf8().constData()); + if (m_properties.contains("force_colorspace")) prod->set("force_colorspace", m_properties.value("force_colorspace").toInt()); + if (m_properties.contains("full_luma")) prod->set("set.force_full_luma", m_properties.value("full_luma").toInt()); + if (m_properties.contains("proxy_out")) { + // We have a proxy clip, make sure the proxy has same duration as original + prod->set("length", m_properties.value("duration").toInt()); + prod->set("out", m_properties.value("proxy_out").toInt()); + } + +} + Mlt::Producer *DocClipBase::videoProducer() { + QMutexLocker locker(&m_producerMutex); if (m_videoOnlyProducer == NULL) { int i; for (i = 0; i < m_baseTrackProducers.count(); i++) if (m_baseTrackProducers.at(i) != NULL) break; 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_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); - if (m_properties.contains("video_index")) m_videoOnlyProducer->set("video_index", m_properties.value("video_index").toInt()); - char *tmp = (char *) qstrdup(QString(getId() + "_video").toUtf8().data()); - m_videoOnlyProducer->set("id", tmp); - delete[] tmp; + m_videoOnlyProducer = cloneProducer(m_baseTrackProducers.at(i)); + adjustProducerProperties(m_videoOnlyProducer, QString(getId() + "_video"), true, false); } return m_videoOnlyProducer; } -Mlt::Producer *DocClipBase::producer(int track) +Mlt::Producer *DocClipBase::getCloneProducer() { - /*for (int i = 0; i < m_baseTrackProducers.count(); i++) { - if (m_baseTrackProducers.at(i)) kDebug() << "// PROD: " << i << ", ID: " << m_baseTrackProducers.at(i)->get("id"); - }*/ - if (track == -1 || (m_clipType != AUDIO && m_clipType != AV)) { - if (m_baseTrackProducers.count() == 0) return NULL; + 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); + if (track == -1 || (m_clipType != AUDIO && m_clipType != AV && m_clipType != PLAYLIST)) { + if (m_baseTrackProducers.count() == 0) { + return NULL; + } for (int i = 0; i < m_baseTrackProducers.count(); i++) { - if (m_baseTrackProducers.at(i) != NULL) + if (m_baseTrackProducers.at(i) != NULL) { return m_baseTrackProducers.at(i); + } } return NULL; } @@ -564,33 +676,48 @@ Mlt::Producer *DocClipBase::producer(int track) for (i = 0; i < m_baseTrackProducers.count(); i++) if (m_baseTrackProducers.at(i) != NULL) break; - if (i >= m_baseTrackProducers.count()) return NULL; - - if (KIO::NetAccess::exists(KUrl(m_baseTrackProducers.at(i)->get("resource")), KIO::NetAccess::SourceSide, 0)) - m_baseTrackProducers[track] = new Mlt::Producer(*m_baseTrackProducers.at(i)->profile(), m_baseTrackProducers.at(i)->get("resource")); - else { // special case for placeholder clips - m_baseTrackProducers[track] = NULL; + if (i >= m_baseTrackProducers.count()) { + // Could not find a valid producer for that clip, check in return NULL; } + 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); +} + - 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_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()); - if (m_properties.contains("audio_index")) m_baseTrackProducers[track]->set("audio_index", m_properties.value("audio_index").toInt()); - char *tmp = (char *) qstrdup(QString(getId() + '_' + QString::number(track)).toUtf8().data()); - m_baseTrackProducers[track]->set("id", tmp); +Mlt::Producer *DocClipBase::cloneProducer(Mlt::Producer *source) +{ + Mlt::Producer *result = NULL; + QString url = QString::fromUtf8(source->get("resource")); + if (m_clipType == SLIDESHOW || KIO::NetAccess::exists(KUrl(url), KIO::NetAccess::SourceSide, 0)) { + result = new Mlt::Producer(*(source->profile()), url.toUtf8().constData()); + } + if (result == NULL || !result->is_valid()) { + // placeholder clip + QString txt = "+" + i18n("Missing clip") + ".txt"; + char *tmp = qstrdup(txt.toUtf8().constData()); + result = new Mlt::Producer(*source->profile(), tmp); delete[] tmp; - if (KdenliveSettings::dropbframes() && m_baseTrackProducers.at(i)->get("skip_loop_filter") && strcmp(m_baseTrackProducers.at(i)->get("skip_loop_filter"), "all") == 0) { - m_baseTrackProducers[track]->set("skip_loop_filter", "all"); - m_baseTrackProducers[track]->set("skip_frame", "bidir"); + if (result == NULL || !result->is_valid()) + result = new Mlt::Producer(*(source->profile()), "colour:red"); + else { + result->set("bgcolour", "0xff0000ff"); + result->set("pad", "10"); } + return result; } - return m_baseTrackProducers.at(track); + /*Mlt::Properties src_props(source->get_properties()); + Mlt::Properties props(result->get_properties()); + props.inherit(src_props);*/ + return result; } void DocClipBase::setProducerProperty(const char *name, int data) { + QMutexLocker locker(&m_producerMutex); for (int i = 0; i < m_baseTrackProducers.count(); i++) { if (m_baseTrackProducers.at(i) != NULL) m_baseTrackProducers[i]->set(name, data); @@ -599,6 +726,7 @@ void DocClipBase::setProducerProperty(const char *name, int data) void DocClipBase::setProducerProperty(const char *name, double data) { + QMutexLocker locker(&m_producerMutex); for (int i = 0; i < m_baseTrackProducers.count(); i++) { if (m_baseTrackProducers.at(i) != NULL) m_baseTrackProducers[i]->set(name, data); @@ -607,12 +735,22 @@ void DocClipBase::setProducerProperty(const char *name, double data) void DocClipBase::setProducerProperty(const char *name, const char *data) { + QMutexLocker locker(&m_producerMutex); for (int i = 0; i < m_baseTrackProducers.count(); i++) { if (m_baseTrackProducers.at(i) != NULL) m_baseTrackProducers[i]->set(name, data); } } +void DocClipBase::resetProducerProperty(const char *name) +{ + QMutexLocker locker(&m_producerMutex); + 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++) { @@ -627,16 +765,51 @@ const char *DocClipBase::producerProperty(const char *name) const void DocClipBase::slotRefreshProducer() { if (m_baseTrackProducers.count() == 0) return; - kDebug() << "//////////// REFRESH CLIP !!!!!!!!!!!!!!!!"; if (m_clipType == SLIDESHOW) { - /*char *tmp = (char *) qstrdup(getProperty("resource").toUtf8().data()); - Mlt::Producer producer(*(m_clipProducer->profile()), tmp); - delete[] tmp; - delete m_clipProducer; - m_clipProducer = new Mlt::Producer(producer.get_producer()); - if (!getProperty("out").isEmpty()) m_clipProducer->set_in_and_out(getProperty("in").toInt(), getProperty("out").toInt());*/ setProducerProperty("ttl", getProperty("ttl").toInt()); //m_clipProducer->set("id", getProperty("id")); + if (!getProperty("animation").isEmpty()) { + Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service()); + int ct = 0; + Mlt::Filter *filter = clipService.filter(ct); + while (filter) { + if (strcmp(filter->get("mlt_service"), "affine") == 0) { + break; + } else if (strcmp(filter->get("mlt_service"), "boxblur") == 0) { + clipService.detach(*filter); + } else ct++; + filter = clipService.filter(ct); + } + + if (!filter || strcmp(filter->get("mlt_service"), "affine")) { + // filter does not exist, create it. + Mlt::Filter *filter = new Mlt::Filter(*(m_baseTrackProducers.at(0)->profile()), "affine"); + if (filter && filter->is_valid()) { + int cycle = getProperty("ttl").toInt(); + QString geometry = SlideshowClip::animationToGeometry(getProperty("animation"), cycle); + if (!geometry.isEmpty()) { + if (getProperty("animation").contains("low-pass")) { + Mlt::Filter *blur = new Mlt::Filter(*(m_baseTrackProducers.at(0)->profile()), "boxblur"); + if (blur && blur->is_valid()) + clipService.attach(*blur); + } + filter->set("transition.geometry", geometry.toUtf8().data()); + filter->set("transition.cycle", cycle); + clipService.attach(*filter); + } + } + } + } else { + Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service()); + int ct = 0; + Mlt::Filter *filter = clipService.filter(0); + while (filter) { + if (strcmp(filter->get("mlt_service"), "affine") == 0 || strcmp(filter->get("mlt_service"), "boxblur") == 0) { + clipService.detach(*filter); + } else ct++; + filter = clipService.filter(ct); + } + } if (getProperty("fade") == "1") { // we want a fade filter effect kDebug() << "//////////// FADE WANTED"; @@ -652,12 +825,9 @@ void DocClipBase::slotRefreshProducer() } if (filter && strcmp(filter->get("mlt_service"), "luma") == 0) { - filter->set("period", getProperty("ttl").toInt() - 1); - filter->set("luma.out", getProperty("luma_duration").toInt()); - QString resource = getProperty("luma_file"); - char *tmp = (char *) qstrdup(resource.toUtf8().data()); - filter->set("luma.resource", tmp); - delete[] tmp; + filter->set("cycle", getProperty("ttl").toInt()); + filter->set("duration", getProperty("luma_duration").toInt()); + filter->set("luma.resource", getProperty("luma_file").toUtf8().data()); if (!getProperty("softness").isEmpty()) { int soft = getProperty("softness").toInt(); filter->set("luma.softness", (double) soft / 100.0); @@ -665,12 +835,9 @@ void DocClipBase::slotRefreshProducer() } else { // filter does not exist, create it... Mlt::Filter *filter = new Mlt::Filter(*(m_baseTrackProducers.at(0)->profile()), "luma"); - filter->set("period", getProperty("ttl").toInt() - 1); - filter->set("luma.out", getProperty("luma_duration").toInt()); - QString resource = getProperty("luma_file"); - char *tmp = (char *) qstrdup(resource.toUtf8().data()); - filter->set("luma.resource", tmp); - delete[] tmp; + filter->set("cycle", getProperty("ttl").toInt()); + filter->set("duration", getProperty("luma_duration").toInt()); + filter->set("luma.resource", getProperty("luma_file").toUtf8().data()); if (!getProperty("softness").isEmpty()) { int soft = getProperty("softness").toInt(); filter->set("luma.softness", (double) soft / 100.0); @@ -689,6 +856,36 @@ void DocClipBase::slotRefreshProducer() filter = clipService.filter(ct); } } + if (getProperty("crop") == "1") { + // we want a center crop filter effect + Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service()); + int ct = 0; + Mlt::Filter *filter = clipService.filter(ct); + while (filter) { + if (strcmp(filter->get("mlt_service"), "crop") == 0) { + break; + } + ct++; + filter = clipService.filter(ct); + } + + if (!filter || strcmp(filter->get("mlt_service"), "crop")) { + // filter does not exist, create it... + Mlt::Filter *filter = new Mlt::Filter(*(m_baseTrackProducers.at(0)->profile()), "crop"); + filter->set("center", 1); + clipService.attach(*filter); + } + } else { + Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service()); + int ct = 0; + Mlt::Filter *filter = clipService.filter(0); + while (filter) { + if (strcmp(filter->get("mlt_service"), "crop") == 0) { + clipService.detach(*filter); + } else ct++; + filter = clipService.filter(ct); + } + } } } @@ -699,18 +896,38 @@ void DocClipBase::setProperties(QMap properties) QMapIterator i(properties); bool refreshProducer = false; QStringList keys; - keys << "luma_duration" << "luma_file" << "fade" << "ttl" << "softness"; + keys << "luma_duration" << "luma_file" << "fade" << "ttl" << "softness" << "crop" << "animation"; + QString oldProxy = m_properties.value("proxy"); while (i.hasNext()) { i.next(); setProperty(i.key(), i.value()); if (m_clipType == SLIDESHOW && keys.contains(i.key())) refreshProducer = true; } + if (properties.contains("proxy")) { + QString value = properties.value("proxy"); + // If value is "-", that means user manually disabled proxy on this clip + if (value.isEmpty() || value == "-") { + // reset proxy + emit abortProxy(m_id, oldProxy); + } + else { + emit createProxy(m_id); + } + } if (refreshProducer) slotRefreshProducer(); } void DocClipBase::setMetadata(QMap properties) { - m_metadata = properties; + QMapIterator 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 DocClipBase::metadata() const @@ -723,7 +940,7 @@ void DocClipBase::clearProperty(const QString &key) m_properties.remove(key); } -void DocClipBase::getFileHash(const QString url) +void DocClipBase::getFileHash(const QString &url) { if (m_clipType == SLIDESHOW) return; QFile file(url); @@ -748,16 +965,32 @@ 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; if (m_clipType == SLIDESHOW) hash = QCryptographicHash::hash(m_properties.value("resource").toAscii().data(), QCryptographicHash::Md5).toHex(); else if (m_clipType == COLOR) hash = QCryptographicHash::hash(m_properties.value("colour").toAscii().data(), QCryptographicHash::Md5).toHex(); else if (m_clipType == TEXT) hash = QCryptographicHash::hash(QString("title" + getId() + m_properties.value("xmldata")).toUtf8().data(), QCryptographicHash::Md5).toHex(); - else hash = m_properties.value("file_hash"); + else { + if (m_properties.contains("file_hash")) hash = m_properties.value("file_hash"); + if (hash.isEmpty()) hash = getHash(fileURL().path()); + + } return hash; } +void DocClipBase::setPlaceHolder(bool place) +{ + m_placeHolder = place; +} + // static QString DocClipBase::getHash(const QString &path) { @@ -795,29 +1028,38 @@ void DocClipBase::setProperty(const QString &key, const QString &value) } else if (key == "out") setDuration(GenTime(value.toInt(), KdenliveSettings::project_fps())); //else if (key == "transparency") m_clipProducer->set("transparency", value.toInt()); else if (key == "colour") { - char *tmp = (char *) qstrdup(value.toUtf8().data()); - setProducerProperty("colour", tmp); - delete[] tmp; + setProducerProperty("colour", value.toUtf8().data()); } else if (key == "templatetext") { - char *tmp = (char *) qstrdup(value.toUtf8().data()); - setProducerProperty("templatetext", tmp); - delete[] tmp; + setProducerProperty("templatetext", value.toUtf8().data()); setProducerProperty("force_reload", 1); } else if (key == "xmldata") { - char *tmp = (char *) qstrdup(value.toUtf8().data()); - setProducerProperty("xmldata", tmp); - delete[] tmp; + setProducerProperty("xmldata", value.toUtf8().data()); setProducerProperty("force_reload", 1); - } else if (key == "force_aspect_ratio") { + } else if (key == "force_aspect_num") { if (value.isEmpty()) { - m_properties.remove("force_aspect_ratio"); - setProducerProperty("force_aspect_ratio", NULL); - } else setProducerProperty("force_aspect_ratio", value.toDouble()); + m_properties.remove("force_aspect_num"); + resetProducerProperty("force_aspect_ratio"); + } else setProducerProperty("force_aspect_ratio", getPixelAspect(m_properties)); + } else if (key == "force_aspect_den") { + if (value.isEmpty()) { + m_properties.remove("force_aspect_den"); + resetProducerProperty("force_aspect_ratio"); + } else setProducerProperty("force_aspect_ratio", getPixelAspect(m_properties)); + } 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 == "force_tff") { + if (value.isEmpty()) { + m_properties.remove("force_tff"); + resetProducerProperty("force_tff"); + } else setProducerProperty("force_tff", value.toInt()); } else if (key == "threads") { if (value.isEmpty()) { m_properties.remove("threads"); @@ -833,6 +1075,16 @@ void DocClipBase::setProperty(const QString &key, const QString &value) m_properties.remove("audio_index"); setProducerProperty("audio_index", m_properties.value("default_audio").toInt()); } else setProducerProperty("audio_index", value.toInt()); + } else if (key == "force_colorspace") { + if (value.isEmpty()) { + m_properties.remove("force_colorspace"); + resetProducerProperty("force_colorspace"); + } else setProducerProperty("force_colorspace", value.toInt()); + } else if (key == "full_luma") { + if (value.isEmpty()) { + m_properties.remove("full_luma"); + resetProducerProperty("set.force_full_luma"); + } else setProducerProperty("set.force_full_luma", value.toInt()); } } @@ -841,20 +1093,24 @@ QMap DocClipBase::properties() const return m_properties; } -bool DocClipBase::slotGetAudioThumbs() +QMap DocClipBase::currentProperties(QMap props) { - if (m_thumbProd == NULL) return false; - if (!KdenliveSettings::audiothumbnails() || m_audioTimer == NULL) { - if (m_audioTimer != NULL) m_audioTimer->stop(); - return false; + QMap currentProps; + QMap::const_iterator i = props.constBegin(); + while (i != props.constEnd()) { + currentProps.insert(i.key(), m_properties.value(i.key())); + ++i; } + return currentProps; +} + +bool DocClipBase::getAudioThumbs() +{ + if (m_thumbProd == NULL || isPlaceHolder() || !KdenliveSettings::audiothumbnails()) return false; if (m_audioThumbCreated) { - m_audioTimer->stop(); return false; } - m_audioTimer->start(1500); - double lengthInFrames = duration().frames(KdenliveSettings::project_fps()); - m_thumbProd->getAudioThumbs(2, 0, lengthInFrames /*must be number of frames*/, 20); + m_audioTimer.start(); return true; } @@ -913,3 +1169,53 @@ QList 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; +} + + +void DocClipBase::slotExtractImage(QList frames) +{ + if (m_thumbProd == NULL) return; + m_thumbProd->extractImage(frames); +} + +QImage DocClipBase::extractImage(int frame, int width, int height) +{ + if (m_thumbProd == NULL) return QImage(); + QMutexLocker locker(&m_producerMutex); + return m_thumbProd->extractImage(frame, width, height); +} + +