X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fdocclipbase.cpp;h=b2b26de81dc6c4e785cd650d7769b525ba1357eb;hb=ff83737cdf5e888500934231a2de90c9b383218c;hp=18e900bdaf31ea8dcbacbf2bfa08b3e8d054e845;hpb=8ba54776b07f6ff36fcde4cd84c21b7a9b231c5a;p=kdenlive diff --git a/src/docclipbase.cpp b/src/docclipbase.cpp index 18e900bd..b2b26de8 100644 --- a/src/docclipbase.cpp +++ b/src/docclipbase.cpp @@ -15,6 +15,8 @@ * * ***************************************************************************/ +#include + #include #include "kdenlivesettings.h" @@ -23,10 +25,9 @@ #include "clipmanager.h" DocClipBase::DocClipBase(ClipManager *clipManager, QDomElement xml, const QString &id): - m_id(id), m_description(QString()), m_refcount(0), m_audioThumbCreated(false), m_duration(GenTime()), m_thumbProd(NULL), m_audioTimer(NULL), m_clipProducer(NULL) { + m_id(id), m_description(QString()), m_refcount(0), m_audioThumbCreated(false), m_duration(GenTime()), m_thumbProd(NULL), m_audioTimer(NULL), m_properties(QMap ()), audioFrameChache(QMap > ()), m_baseTrackProducers(QList ()), m_snapMarkers(QList < CommentedTime > ()) { int type = xml.attribute("type").toInt(); m_clipType = (CLIPTYPE) type; - m_name = xml.attribute("name"); QDomNamedNodeMap attributes = xml.attributes(); for (unsigned int i = 0; i < attributes.count(); i++) { @@ -34,6 +35,7 @@ DocClipBase::DocClipBase(ClipManager *clipManager, QDomElement xml, const QStrin } KUrl url = KUrl(xml.attribute("resource")); + if (!m_properties.contains("file_hash") && !url.isEmpty()) getFileHash(url.path()); int out = xml.attribute("out").toInt(); if (out != 0) { setDuration(GenTime(out, KdenliveSettings::project_fps())); @@ -41,11 +43,11 @@ DocClipBase::DocClipBase(ClipManager *clipManager, QDomElement xml, const QStrin out = xml.attribute("duration").toInt(); if (out != 0) setDuration(GenTime(out, KdenliveSettings::project_fps())); } - if (m_name.isEmpty()) m_name = url.fileName(); + 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_thumbProd = new KThumb(clipManager, url, m_id, m_properties.value("file_hash")); if (m_clipType == AV || m_clipType == AUDIO) slotCreateAudioTimer(); } //kDebug() << "type is video" << (m_clipType == AV) << " " << m_clipType; @@ -63,8 +65,15 @@ DocClipBase::DocClipBase(ClipManager *clipManager, QDomElement xml, const QStrin }*/ DocClipBase::~DocClipBase() { - if (m_thumbProd) delete m_thumbProd; - if (m_clipProducer) delete m_clipProducer; + if (m_thumbProd) { + delete m_thumbProd; + } + if (m_audioTimer) { + m_audioTimer->stop(); + delete m_audioTimer; + } + qDeleteAll(m_baseTrackProducers); + m_baseTrackProducers.clear(); } void DocClipBase::slotCreateAudioTimer() { @@ -74,8 +83,8 @@ void DocClipBase::slotCreateAudioTimer() { connect(m_audioTimer, SIGNAL(timeout()), this, SLOT(slotGetAudioThumbs())); } -void DocClipBase::slotRequestAudioThumbs() { - emit getAudioThumbs(); +void DocClipBase::askForAudioThumbs() { + if (m_thumbProd) m_thumbProd->askForAudioThumbs(getId()); } void DocClipBase::slotClearAudioCache() { @@ -85,6 +94,10 @@ void DocClipBase::slotClearAudioCache() { m_audioThumbCreated = false; } +/*void DocClipBase::getClipMainThumb() { + if (m_thumbProd) m_thumbProd->getMainThumb(m_properties.value("thumbnail").toInt()); +}*/ + KThumb *DocClipBase::thumbProducer() { return m_thumbProd; } @@ -93,13 +106,9 @@ bool DocClipBase::audioThumbCreated() const { return m_audioThumbCreated; } -void DocClipBase::setName(const QString name) { - m_name = name; -} - const QString & DocClipBase::name() const { - return m_name; + return m_properties.value("name"); } const QString &DocClipBase::getId() const { @@ -116,6 +125,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)) slotCreateAudioTimer(); @@ -158,7 +168,7 @@ const GenTime &DocClipBase::duration() const { const GenTime &DocClipBase::maxDuration() const { if (m_clipType == COLOR || m_clipType == IMAGE || m_clipType == TEXT || (m_clipType == SLIDESHOW && m_properties.value("loop") == "1")) { - const GenTime dur(10000, KdenliveSettings::project_fps()); + const GenTime dur(15000, KdenliveSettings::project_fps()); return dur; } return m_duration; @@ -243,7 +253,7 @@ const QPixmap & DocClipBase::thumbnail() const { } void DocClipBase::updateAudioThumbnail(QMap > data) { - kDebug() << "CLIPBASE RECIEDVED AUDIO DATA*********************************************"; + //kDebug() << "CLIPBASE RECIEDVED AUDIO DATA*********************************************"; audioFrameChache = data; m_audioThumbCreated = true; emit gotAudioData(); @@ -360,18 +370,96 @@ QString DocClipBase::markerComment(GenTime t) { return QString::null; } +void DocClipBase::deleteProducers() { + qDeleteAll(m_baseTrackProducers); + m_baseTrackProducers.clear(); + if (m_thumbProd) m_thumbProd->clearProducer(); +} + void DocClipBase::setProducer(Mlt::Producer *producer) { - m_clipProducer = producer; - m_clipProducer->set("transparency", m_properties.value("transparency").toInt()); - if (m_thumbProd) m_thumbProd->setProducer(producer); + if (producer == NULL) return; + QString id = producer->get("id"); + if (id.contains('_')) { + // this is a subtrack producer, insert it at correct place + int pos = id.section('_', 1, 1).toInt(); + if (pos >= m_baseTrackProducers.count()) { + while (m_baseTrackProducers.count() - 1 < pos) { + m_baseTrackProducers.append(NULL); + } + } + if (m_baseTrackProducers.at(pos) == NULL) m_baseTrackProducers[pos] = producer; + } else { + if (m_baseTrackProducers.isEmpty()) m_baseTrackProducers.append(producer); + else if (m_baseTrackProducers.at(0) == NULL) m_baseTrackProducers[0] = producer; + } + //m_clipProducer = producer; + //m_clipProducer->set("transparency", m_properties.value("transparency").toInt()); + if (m_thumbProd && !m_thumbProd->hasProducer()) m_thumbProd->setProducer(producer); +} + +Mlt::Producer *DocClipBase::producer(int track) { + /*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; + int i; + for (int i = 0; i < m_baseTrackProducers.count(); i++) + if (m_baseTrackProducers.at(i) != NULL) return m_baseTrackProducers.at(i); + return NULL; + } + if (track >= m_baseTrackProducers.count()) { + while (m_baseTrackProducers.count() - 1 < track) { + m_baseTrackProducers.append(NULL); + } + } + if (m_baseTrackProducers.at(track) == 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_baseTrackProducers[track] = new Mlt::Producer(*m_baseTrackProducers.at(i)->profile(), m_baseTrackProducers.at(i)->get("resource")); + 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("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); + 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"); + } + } + return m_baseTrackProducers.at(track); } -Mlt::Producer *DocClipBase::producer() { - return m_clipProducer; +void DocClipBase::setProducerProperty(const char *name, int data) { + for (int i = 0; i < m_baseTrackProducers.count(); i++) { + if (m_baseTrackProducers.at(i) != NULL) + m_baseTrackProducers[i]->set(name, data); + } +} + +void DocClipBase::setProducerProperty(const char *name, const char *data) { + for (int i = 0; i < m_baseTrackProducers.count(); i++) { + if (m_baseTrackProducers.at(i) != NULL) + m_baseTrackProducers[i]->set(name, data); + } +} + +const char *DocClipBase::producerProperty(const char *name) const { + for (int i = 0; i < m_baseTrackProducers.count(); i++) { + if (m_baseTrackProducers.at(i) != NULL) { + return m_baseTrackProducers.at(i)->get(name); + } + } + return NULL; } + void DocClipBase::slotRefreshProducer() { - if (m_clipProducer == NULL) return; + if (m_baseTrackProducers.count() == 0) return; kDebug() << "//////////// REFRESH CLIP !!!!!!!!!!!!!!!!"; if (m_clipType == SLIDESHOW) { /*char *tmp = (char *) qstrdup(getProperty("resource").toUtf8().data()); @@ -380,12 +468,12 @@ void DocClipBase::slotRefreshProducer() { 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());*/ - m_clipProducer->set("ttl", getProperty("ttl").toInt()); + setProducerProperty("ttl", getProperty("ttl").toInt()); //m_clipProducer->set("id", getProperty("id")); if (getProperty("fade") == "1") { // we want a fade filter effect kDebug() << "//////////// FADE WANTED"; - Mlt::Service clipService(m_clipProducer->get_service()); + Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service()); int ct = 0; Mlt::Filter *filter = clipService.filter(ct); while (filter) { @@ -409,7 +497,7 @@ void DocClipBase::slotRefreshProducer() { } } else { // filter does not exist, create it... - Mlt::Filter *filter = new Mlt::Filter(*(m_clipProducer->profile()), "luma"); + 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"); @@ -424,7 +512,7 @@ void DocClipBase::slotRefreshProducer() { } } else { kDebug() << "//////////// FADE NOT WANTED!!!"; - Mlt::Service clipService(m_clipProducer->get_service()); + Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service()); int ct = 0; Mlt::Filter *filter = clipService.filter(0); while (filter) { @@ -446,33 +534,94 @@ void DocClipBase::setProperties(QMap properties) { keys << "luma_duration" << "luma_file" << "fade" << "ttl" << "softness"; while (i.hasNext()) { i.next(); - m_properties.insert(i.key(), i.value()); - if (i.key() == "resource") m_thumbProd->updateClipUrl(KUrl(i.value())); - else if (i.key() == "out") setDuration(GenTime(i.value().toInt(), KdenliveSettings::project_fps())); - else if (m_clipType == SLIDESHOW && keys.contains(i.key())) refreshProducer = true; - else if (i.key() == "transparency") m_clipProducer->set("transparency", i.value().toInt()); - else if (i.key() == "colour") { - char *tmp = (char *) qstrdup(i.value().toUtf8().data()); - m_clipProducer->set("colour", tmp); - delete[] tmp; - } else if (i.key() == "xmldata") { - m_clipProducer->set("force_reload", 1); - } + setProperty(i.key(), i.value()); + if (m_clipType == SLIDESHOW && keys.contains(i.key())) refreshProducer = true; } if (refreshProducer) slotRefreshProducer(); } -void DocClipBase::setProperty(QString key, QString value) { +void DocClipBase::setMetadata(QMap properties) { + m_metadata = properties; +} + +QMap DocClipBase::metadata() const { + return m_metadata; +} + +void DocClipBase::clearProperty(const QString &key) { + m_properties.remove(key); +} + +void DocClipBase::getFileHash(const QString &url) { + if (m_clipType == SLIDESHOW) return; + QFile file(url); + if (file.open(QIODevice::ReadOnly)) { // write size and hash only if resource points to a file + QByteArray fileData; + QByteArray fileHash; + //kDebug() << "SETTING HASH of" << value; + m_properties.insert("file_size", QString::number(file.size())); + /* + * 1 MB = 1 second per 450 files (or faster) + * 10 MB = 9 seconds per 450 files (or faster) + */ + if (file.size() > 1000000*2) { + fileData = file.read(1000000); + if (file.seek(file.size() - 1000000)) + fileData.append(file.readAll()); + } else + fileData = file.readAll(); + file.close(); + fileHash = QCryptographicHash::hash(fileData, QCryptographicHash::Md5); + m_properties.insert("file_hash", QString(fileHash.toHex())); + //kDebug() << file.fileName() << file.size() << fileHash.toHex(); + } +} + +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 hash = m_properties.value("file_hash"); + return hash; +} + +void DocClipBase::refreshThumbUrl() { + if (m_thumbProd) m_thumbProd->updateThumbUrl(m_properties.value("file_hash")); +} + +void DocClipBase::setProperty(const QString &key, const QString &value) { m_properties.insert(key, value); - if (key == "resource") m_thumbProd->updateClipUrl(KUrl(value)); - else if (key == "out") setDuration(GenTime(value.toInt(), KdenliveSettings::project_fps())); - else if (key == "transparency") m_clipProducer->set("transparency", value.toInt()); + if (key == "resource") { + getFileHash(value); + if (m_thumbProd) m_thumbProd->updateClipUrl(KUrl(value), m_properties.value("file_hash")); + } 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()); - m_clipProducer->set("colour", tmp); + setProducerProperty("colour", tmp); delete[] tmp; } else if (key == "xmldata") { - m_clipProducer->set("force_reload", 1); + setProducerProperty("force_reload", 1); + } else if (key == "force_aspect_ratio") { + if (value.isEmpty()) { + m_properties.remove("force_aspect_ratio"); + setProducerProperty("force_aspect_ratio", 0); + } else setProducerProperty("force_aspect_ratio", value.toDouble()); + } else if (key == "threads") { + if (value.isEmpty()) { + m_properties.remove("threads"); + setProducerProperty("threads", 1); + } else setProducerProperty("threads", value.toInt()); + } else if (key == "video_index") { + if (value.isEmpty()) { + m_properties.remove("video_index"); + setProducerProperty("video_index", m_properties.value("default_video").toInt()); + } else setProducerProperty("video_index", value.toInt()); + } else if (key == "audio_index") { + if (value.isEmpty()) { + m_properties.remove("audio_index"); + setProducerProperty("audio_index", m_properties.value("default_audio").toInt()); + } else setProducerProperty("audio_index", value.toInt()); } } @@ -480,17 +629,21 @@ QMap DocClipBase::properties() const { return m_properties; } -void DocClipBase::slotGetAudioThumbs() { - if (m_thumbProd == NULL) return; +bool DocClipBase::slotGetAudioThumbs() { + if (m_thumbProd == NULL) return false; + if (!KdenliveSettings::audiothumbnails()) { + if (m_audioTimer != NULL) m_audioTimer->stop(); + return false; + } if (m_audioThumbCreated) { - if (m_audioTimer != NULL) - m_audioTimer->stop(); - } else { - if (m_audioTimer != NULL) - m_audioTimer->start(2000); - double lengthInFrames = duration().frames(/*framesPerSecond()*/25); - m_thumbProd->getAudioThumbs(2, 0, lengthInFrames /*must be number of frames*/, 20); + if (m_audioTimer != NULL) m_audioTimer->stop(); + return false; } + if (m_audioTimer != NULL) + m_audioTimer->start(1500); + double lengthInFrames = duration().frames(KdenliveSettings::project_fps()); + m_thumbProd->getAudioThumbs(2, 0, lengthInFrames /*must be number of frames*/, 20); + return true; }