forked from mpc-qt/mpc-qt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththumbnailerwindow.h
147 lines (120 loc) · 3.3 KB
/
thumbnailerwindow.h
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#ifndef THUMBNAILERWINDOW_H
#define THUMBNAILERWINDOW_H
#include <QImage>
#include <QOpenGLWidget>
#include <QWidget>
#include <QQueue>
#include <QUrl>
#include "mpvwidget.h"
namespace Ui {
class ThumbnailerWindow;
}
class MpvThumbnailDrawer;
class MpvThumbnailer;
class ThumbnailerWindow : public QWidget
{
Q_OBJECT
public:
explicit ThumbnailerWindow(QWidget *parent = nullptr);
~ThumbnailerWindow();
public slots:
void open(QUrl sourceUrl);
void begin();
void setScreenshotDirectory(QString folder);
void setScreenshotFormat(QString format);
private slots:
void on_saveImageBrowse_clicked();
void thumbnailer_setProgress(int percent);
void thumbnailer_finished();
private:
Ui::ThumbnailerWindow *ui = nullptr;
MpvThumbnailer *thumbnailer = nullptr;
QString screenshotDirectory;
QString screenshotFormat = "png";
};
class MpvThumbnailer : public QObject {
Q_OBJECT
enum ThumbnailingState {
AvailableState, // Available for use
StartedState, // File opened
StaleState, // File opened, but no video size yet
SeekingState, // Seek command sent
PlayingState, // Playing video until frozen
WaitingForTimer, // Waiting for snapshot timer
FinishedState // Playback finished
};
struct ThumbPts {
int x, y;
double pts;
int percent, index;
QImage thumb;
};
public:
struct Params {
QUrl sourceUrl;
QString imageFile;
int jpegQuality, imageWidth;
int cols, rows;
};
explicit MpvThumbnailer(QObject *parent);
~MpvThumbnailer();
void execute(const Params &p);
signals:
void progress(int percent);
void finished();
private:
void initPlayer();
void deinitPlayer();
void initThumbPts();
void processThumb();
bool seekNextFrame();
void renderImage();
void saveImage();
private slots:
void mpv_fileSizeChanged(int64_t bytes);
void mpv_videoSizeChanged(QSize size);
void mpv_playLengthChanged(double length);
void mpv_playTimeChanged(double time);
void mpv_playbackFinished();
void mpv_eofReachedChanged();
void timer_navigateTick();
private:
Params p;
MpvObject *mpv = nullptr;
MpvThumbnailDrawer *thumbnailer = nullptr;
ThumbnailingState thumbState = AvailableState;
double mpvTime = -1;
double mpvDuration = -1;
Helpers::TimeFormat osdTimeFormat = Helpers::ShortFormat;
int64_t mpvFileSize = 0;
QSize mpvVideoSize = {-1,-1};
QQueue<ThumbPts> pendingPts;
QQueue<ThumbPts> processedPts;
QImage render;
QSize thumbSize;
};
class MpvThumbnailDrawer : public QOpenGLWidget, public MpvWidgetInterface {
Q_OBJECT
Q_INTERFACES(MpvWidgetInterface)
public:
explicit MpvThumbnailDrawer(MpvObject *object);
~MpvThumbnailDrawer();
QWidget *self();
void initMpv();
void setLogoUrl(const QString &filename);
void setLogoBackground(const QColor &color);
void setDrawLogo(bool yes);
signals:
void renderedFrame();
protected:
void initializeGL();
void paintGL();
void resizeGL(int w, int h);
private slots:
void alwaysUpdate();
private:
static void render_update(void *ctx);
mpv_render_context *render = nullptr;
int glWidth, glHeight;
};
#endif // THUMBNAILERWINDOW_H