aboutsummaryrefslogtreecommitdiffstats
path: root/core/videoframeextractor.h
blob: 26650af8d11b6f955ce2a27de5d7563e173311be (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// SPDX-License-Identifier: GPL-2.0
#ifndef VIDEOFRAMEEXTRACTOR_H
#define VIDEOFRAMEEXTRACTOR_H

#include "core/units.h"

#include <QMutex>
#include <QFuture>
#include <QThreadPool>
#include <QQueue>
#include <QString>
#include <QPair>

class VideoFrameExtractor : public QObject {
	Q_OBJECT
public:
	VideoFrameExtractor();
	static VideoFrameExtractor *instance();
signals:
	void extracted(QString filename, QImage, duration_t duration, duration_t offset);
	// There are two failure modes:
	//	failed() -> we failed to start ffmpeg. Write a thumbnail signalling "maybe try again".
	//	invalid() -> we started ffmpeg, but that couldn't extract an image. Signal "this file is broken".
	void failed(QString filename, duration_t duration);
	void invalid(QString filename, duration_t duration);
public slots:
	void extract(QString originalFilename, QString filename, duration_t duration);
	void clearWorkQueue();
private:
	void processItem(QString originalFilename, QString filename, duration_t duration);
	void fail(const QString &originalFilename, duration_t duration, bool isInvalid);
	mutable QMutex lock;
	QThreadPool pool;
	QMap<QString, QFuture<void>> workingOn;
};

#endif