Commit 0ea2713b authored by luyikei's avatar luyikei

ThumbnailWorker: Asynchronous

parent 72aca0c0
......@@ -302,12 +302,18 @@ MainWorkflow::addEffect( const QString &clipUuid, const QString &effectId )
void
MainWorkflow::takeThumbnail( const QString& uuid, quint32 pos )
{
ThumbnailWorker worker;
connect( &worker, &ThumbnailWorker::imageReady, this, &MainWorkflow::thumbnailUpdated, Qt::DirectConnection );
auto clip = m_sequenceWorkflow->clip( uuid );
worker.run( uuid, clip->media()->fileInfo()->absoluteFilePath(),
clip->begin() + pos, clip->input()->width(),
clip->input()->height() );
auto worker = new ThumbnailWorker( uuid, clip->media()->fileInfo()->absoluteFilePath(),
clip->begin() + pos, clip->input()->width(),
clip->input()->height() );
auto t = new QThread;
worker->moveToThread( t );
connect( t, &QThread::started, worker, &ThumbnailWorker::run );
connect( worker, &ThumbnailWorker::imageReady, this, &MainWorkflow::thumbnailUpdated, Qt::DirectConnection );
connect( worker, &ThumbnailWorker::imageReady, t, &QThread::quit );
connect( t, &QThread::finished, worker, &ThumbnailWorker::deleteLater );
connect( t, &QThread::finished, t, &QThread::deleteLater );
t->start();
}
bool
......
......@@ -5,22 +5,27 @@
#include "Backend/MLT/MLTInput.h"
ThumbnailWorker::ThumbnailWorker( QObject* parent )
ThumbnailWorker::ThumbnailWorker( const QString& uuid, const QString& filePath, qint64 pos, quint32 width, quint32 height, QObject* parent )
: QObject( parent )
, m_uuid( uuid )
, m_filePath( filePath )
, m_pos( pos )
, m_width( width )
, m_height( height )
{
}
void
ThumbnailWorker::run( const QString& uuid, const QString& filePath, qint64 pos, quint32 width, quint32 height )
ThumbnailWorker::run()
{
Backend::MLT::MLTInput input( qPrintable( filePath ) );
input.setPosition( pos );
auto image = input.image( width, height );
QImage qImg( image, width, height,
Backend::MLT::MLTInput input( qPrintable( m_filePath ) );
input.setPosition( m_pos );
auto image = input.image( m_width, m_height );
QImage qImg( image, m_width, m_height,
QImage::Format_RGBA8888, []( void* buf ){ delete[] (uchar*) buf; } );
auto qPix = QPixmap::fromImage( qImg );
// Use Qt::DirectConnection or the pixmap will be deleted!
emit imageReady( uuid, pos, qPix );
emit imageReady( m_uuid, m_pos, qPix );
}
......@@ -9,13 +9,20 @@ class ThumbnailWorker : public QObject
{
Q_OBJECT
public:
explicit ThumbnailWorker( QObject* parent = 0 );
explicit ThumbnailWorker( const QString& uuid, const QString& filePath, qint64 pos, quint32 width, quint32 height , QObject* parent = 0 );
signals:
void imageReady( const QString& uuid, qint64 pos, const QPixmap& pixmap );
public slots:
void run( const QString& uuid, const QString& filePath, qint64 pos, quint32 width, quint32 height );
void run();
private:
QString m_uuid;
QString m_filePath;
qint64 m_pos;
quint32 m_width;
quint32 m_height;
};
#endif // THUMBNAILWORKER_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment