m_endPix = QPixmap();
m_audioThumbCachePic.clear();
}
- //kDebug()<<"........... RESET THMBS: "<<clearExistingThumbs;
slotFetchThumbs();
}
return;
}
- if (m_endPix.isNull() && m_startPix.isNull()) {
+ QList <int> frames;
+ if (m_startPix.isNull()) {
m_startThumbRequested = true;
+ frames.append((int)m_speedIndependantInfo.cropStart.frames(m_fps));
+ }
+
+ if (m_endPix.isNull()) {
m_endThumbRequested = true;
- m_clip->slotExtractImage((int)m_speedIndependantInfo.cropStart.frames(m_fps), (int)(m_speedIndependantInfo.cropStart + m_speedIndependantInfo.cropDuration).frames(m_fps) - 1);
- } else {
- if (m_endPix.isNull()) {
- slotGetEndThumb();
- }
- if (m_startPix.isNull()) {
- slotGetStartThumb();
- }
+ frames.append((int)(m_speedIndependantInfo.cropStart + m_speedIndependantInfo.cropDuration).frames(m_fps) - 1);
}
+
+ m_clip->slotExtractImage(frames);
}
void ClipItem::slotGetStartThumb()
{
m_startThumbRequested = true;
- m_clip->slotExtractImage((int)m_speedIndependantInfo.cropStart.frames(m_fps), -1);
+ m_clip->slotExtractImage(QList<int>() << (int)m_speedIndependantInfo.cropStart.frames(m_fps));
}
void ClipItem::slotGetEndThumb()
{
m_endThumbRequested = true;
- m_clip->slotExtractImage(-1, (int)(m_speedIndependantInfo.cropStart + m_speedIndependantInfo.cropDuration).frames(m_fps) - 1);
+ m_clip->slotExtractImage(QList<int>() << (int)(m_speedIndependantInfo.cropStart + m_speedIndependantInfo.cropDuration).frames(m_fps) - 1);
}
#include "abstractclipitem.h"
#include "abstractgroupitem.h"
#include "titledocument.h"
+#include "kthumb.h"
#include <mlt++/Mlt.h>
#include <kio/netaccess.h>
#include <QGraphicsItemGroup>
+#include <QtConcurrentRun>
#include <KFileMetaInfo>
QObject(),
m_audioThumbsQueue(),
m_doc(doc),
- m_generatingAudioId()
+ m_generatingAudioId(),
+ m_abortThumb(false)
{
m_clipIdCounter = 1;
m_folderIdCounter = 1;
ClipManager::~ClipManager()
{
+ m_thumbsMutex.lock();
+ m_requestedThumbs.clear();
+ m_thumbsMutex.unlock();
+ m_abortThumb = true;
+ m_thumbsThread.waitForFinished();
m_audioThumbsQueue.clear();
m_generatingAudioId.clear();
+ m_thumbsMutex.lock();
+ m_requestedThumbs.clear();
+ m_thumbsMutex.unlock();
qDeleteAll(m_clipList);
m_clipList.clear();
#if KDE_IS_VERSION(4,5,0)
void ClipManager::clear()
{
+ m_thumbsMutex.lock();
+ m_requestedThumbs.clear();
+ m_thumbsMutex.unlock();
+ m_abortThumb = true;
+ m_thumbsThread.waitForFinished();
+ m_abortThumb = false;
m_folderList.clear();
m_audioThumbsQueue.clear();
m_modifiedClips.clear();
#endif
}
+void ClipManager::requestThumbs(const QString id, QList <int> frames)
+{
+ kDebug()<<"// Request thbs: "<<id<<": "<<frames;
+ m_thumbsMutex.lock();
+ foreach (int frame, frames) {
+ m_requestedThumbs.insertMulti(id, frame);
+ }
+ m_thumbsMutex.unlock();
+ if (!m_thumbsThread.isRunning() && !m_abortThumb) {
+ m_thumbsThread = QtConcurrent::run(this, &ClipManager::slotGetThumbs);
+ }
+}
+
+void ClipManager::stopThumbs(const QString &id)
+{
+ m_abortThumb = true;
+ m_thumbsThread.waitForFinished();
+ m_thumbsMutex.lock();
+ m_requestedThumbs.remove(id);
+ m_thumbsMutex.unlock();
+ m_abortThumb = false;
+ if (!m_thumbsThread.isRunning()) {
+ m_thumbsThread = QtConcurrent::run(this, &ClipManager::slotGetThumbs);
+ }
+}
+
+void ClipManager::slotGetThumbs()
+{
+ QMap<QString, int>::const_iterator i = m_requestedThumbs.constBegin();
+ while (i != m_requestedThumbs.constEnd() && !m_abortThumb) {
+ const QString producerId = i.key();
+ m_thumbsMutex.lock();
+ QList<int> values = m_requestedThumbs.values(producerId);
+ m_requestedThumbs.remove(producerId);
+ m_thumbsMutex.unlock();
+ qSort(values);
+ DocClipBase *clip = getClipById(producerId);
+ if (!clip) continue;
+ while (!values.isEmpty() && clip->thumbProducer() && !m_abortThumb) {
+ clip->thumbProducer()->getThumb(values.takeFirst());
+ }
+ if (m_abortThumb) {
+ // keep the requested frames that were not processed
+ m_thumbsMutex.lock();
+ foreach (int frame, values)
+ m_requestedThumbs.insertMulti(producerId, frame);
+ m_thumbsMutex.unlock();
+ }
+ i = m_requestedThumbs.constBegin();
+ }
+}
+
void ClipManager::checkAudioThumbs()
{
if (!KdenliveSettings::audiothumbnails()) {
#include <QPixmap>
#include <QObject>
#include <QTimer>
+#include <QMutex>
+#include <QFuture>
#include <KUrl>
#include <KUndoStack>
void removeGroup(AbstractGroupItem *group);
QDomElement groupsXml() const;
int clipsCount() const;
+ /** @brief Request creation of a clip thumbnail for specified frames. */
+ void requestThumbs(const QString id, QList <int> frames);
+ /** @brief remove a clip id from the queue list. */
+ void stopThumbs(const QString &id);
#if KDE_IS_VERSION(4,5,0)
KImageCache* pixmapCache;
void slotClipAvailable(const QString &path);
/** Check the list of externally modified clips, and process them if they were not modified in the last 1500 milliseconds */
void slotProcessModifiedClips();
+ void slotGetThumbs();
private: // Private attributes
/** the list of clips in the document */
QTimer m_modifiedTimer;
/** List of the clip IDs that need to be reloaded after being externally modified */
QMap <QString, QTime> m_modifiedClips;
+ /** Struct containing the list of clip thumbnails to request (clip id and frames) */
+ QMap <QString, int> m_requestedThumbs;
+ QMutex m_thumbsMutex;
+ QFuture<void> m_thumbsThread;
+ /** @brief If true, abort processing of clip thumbs before removing a clip. */
+ bool m_abortThumb;
signals:
void reloadClip(const QString &);
}
-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)
void setMetadata(QMap <QString, QString> properties);
QMap <QString, QString> properties() const;
QMap <QString, QString> metadata() const;
- void slotExtractImage(int frame, int frame2);
+ void slotExtractImage(QList <int> frames);
signals:
void gotAudioData();
KThumb::~KThumb()
{
- m_listMutex.lock();
- m_requestedThumbs.clear();
- m_listMutex.unlock();
+ m_clipManager->stopThumbs(m_id);
m_intraFramesQueue.clear();
if (m_audioThumbProducer.isRunning()) {
m_stopAudioThumbs = true;
m_audioThumbProducer.waitForFinished();
slotAudioThumbOver();
}
- m_future.waitForFinished();
m_intra.waitForFinished();
}
void KThumb::setProducer(Mlt::Producer *producer)
{
- m_listMutex.lock();
- m_requestedThumbs.clear();
- m_listMutex.unlock();
+ m_clipManager->stopThumbs(m_id);
m_intraFramesQueue.clear();
- m_future.waitForFinished();
m_intra.waitForFinished();
m_mutex.lock();
m_producer = producer;
return getImage(url, 0, width, height);
}
-void KThumb::extractImage(int frame, int frame2)
+void KThumb::extractImage(QList <int>frames)
{
if (!KdenliveSettings::videothumbnails() || m_producer == NULL) return;
- m_listMutex.lock();
- if (frame != -1 && !m_requestedThumbs.contains(frame)) m_requestedThumbs.append(frame);
- if (frame2 != -1 && !m_requestedThumbs.contains(frame2)) m_requestedThumbs.append(frame2);
- qSort(m_requestedThumbs);
- m_listMutex.unlock();
- if (!m_future.isRunning()) {
- m_future = QtConcurrent::run(this, &KThumb::doGetThumbs);
- }
+ m_clipManager->requestThumbs(m_id, frames);
}
-void KThumb::doGetThumbs()
+
+void KThumb::getThumb(int frame)
{
const int theight = KdenliveSettings::trackheight();
const int swidth = (int)(theight * m_ratio + 0.5);
const int dwidth = (int)(theight * m_dar + 0.5);
- while (!m_requestedThumbs.isEmpty()) {
- m_listMutex.lock();
- int frame = m_requestedThumbs.takeFirst();
- m_listMutex.unlock();
- if (frame != -1) {
- QImage img = getProducerFrame(frame, swidth, dwidth, theight);
- emit thumbReady(frame, img);
- }
- }
+ QImage img = getProducerFrame(frame, swidth, dwidth, theight);
+ emit thumbReady(frame, img);
}
QPixmap KThumb::extractImage(int frame, int width, int height)
int ow = frameWidth;
int oh = height;
mlt_image_format format = mlt_image_rgb24a;
-
+
const uchar* imagedata = frame->get_image(format, ow, oh);
- QImage image(imagedata, ow, oh, QImage::Format_ARGB32_Premultiplied);
+ QImage image(ow, oh, QImage::Format_ARGB32_Premultiplied);
+ memcpy(image.bits(), imagedata, ow * oh * 4);//.byteCount());
+
+ //const uchar* imagedata = frame->get_image(format, ow, oh);
+ //QImage image(imagedata, ow, oh, QImage::Format_ARGB32_Premultiplied);
if (!image.isNull()) {
if (ow > (2 * displayWidth)) {
void KThumb::slotCreateAudioThumbs()
{
- Mlt::Profile prof((char*) KdenliveSettings::current_profile().toUtf8().data());
- Mlt::Producer producer(prof, m_url.path().toUtf8().data());
+ Mlt::Profile prof((char*) KdenliveSettings::current_profile().toUtf8().constData());
+ Mlt::Producer producer(prof, m_url.path().toUtf8().constData());
if (!producer.is_valid()) {
kDebug() << "++++++++ INVALID CLIP: " << m_url.path();
return;
int last_val = 0;
int val = 0;
- //kDebug() << "for " << m_frame << " " << m_frameLength << " " << m_producer.is_valid();
+ mlt_audio_format m_audioFormat = mlt_audio_pcm;
+ double framesPerSecond = mlt_producer_get_fps(producer.get_producer());
+ Mlt::Frame *mlt_frame;
+
for (int z = (int) m_frame; z < (int)(m_frame + m_frameLength) && producer.is_valid(); z++) {
if (m_stopAudioThumbs) break;
val = (int)((z - m_frame) / (m_frame + m_frameLength) * 100.0);
last_val = val;
}
producer.seek(z);
- Mlt::Frame *mlt_frame = producer.get_frame();
+ mlt_frame = producer.get_frame();
if (mlt_frame && mlt_frame->is_valid()) {
- double m_framesPerSecond = mlt_producer_get_fps(producer.get_producer());
- int m_samples = mlt_sample_calculator(m_framesPerSecond, m_frequency, mlt_frame_get_position(mlt_frame->get_frame()));
- mlt_audio_format m_audioFormat = mlt_audio_pcm;
+ int m_samples = mlt_sample_calculator(framesPerSecond, m_frequency, mlt_frame_get_position(mlt_frame->get_frame()));
qint16* m_pcm = static_cast<qint16*>(mlt_frame->get_audio(m_audioFormat, m_frequency, m_channels, m_samples));
-
for (int c = 0; c < m_channels; c++) {
QByteArray m_array;
m_array.resize(m_arrayWidth);
bool hasProducer() const;
void clearProducer();
void updateThumbUrl(const QString &hash);
- void extractImage(int frame, int frame2);
+ void extractImage(QList <int> frames);
QPixmap extractImage(int frame, int width, int height);
#if KDE_IS_VERSION(4,5,0)
/** @brief Request thumbnails for the frame range. */
/** @brief Query cached thumbnail. */
QImage findCachedThumb(const QString path);
#endif
+ void getThumb(int frame);
public slots:
void updateClipUrl(KUrl url, const QString &hash);
Mlt::Producer *m_producer;
ClipManager *m_clipManager;
QString m_id;
- QList <int> m_requestedThumbs;
- /** @brief Controls the thumbnails process. */
- QFuture<void> m_future;
/** @brief Controls the intra frames thumbnails process (cached thumbnails). */
QFuture<void> m_intra;
QFile m_audioThumbFile;
/** @brief List of frame numbers from which we want to extract thumbnails. */
QList <int> m_intraFramesQueue;
QMutex m_mutex;
- QMutex m_listMutex;
- void doGetThumbs();
QImage getProducerFrame(int framepos, int frameWidth, int displayWidth, int height);
signals:
QDomDocument doc;
QDomElement prods = doc.createElement("producerlist");
doc.appendChild(prods);
- kDebug() << "//////////// PRO LIST BUILD PRDSLIST ";
QTreeWidgetItemIterator it(m_listView);
while (*it) {
if ((*it)->type() != PROJECTCLIPTYPE) {
{
if (m_render->processingItems() == 0 && m_thumbnailQueue.isEmpty()) {
if (!m_refreshed && m_allClipsProcessed) {
- kDebug()<<"// LOADING IS OVER!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
m_listView->setEnabled(true);
slotClipSelected();
- emit loadingIsOver();
+ QTimer::singleShot(500, this, SIGNAL(loadingIsOver()));
emit displayMessage(QString(), -1);
m_refreshed = true;
}