22 #include <QQuickWidget> 23 #include <QOpenGLFunctions> 24 #include <QOpenGLShaderProgram> 25 #include <QOpenGLFramebufferObject> 26 #include <QOpenGLContext> 27 #include <QOffscreenSurface> 32 #include "mltcontroller.h" 33 #include "sharedframe.h" 35 class QOpenGLFunctions_3_2_Core;
46 typedef void* ( *thread_function_t )(
void* );
48 class GLWidget :
public QQuickWidget,
public Controller,
protected QOpenGLFunctions
51 Q_PROPERTY(QRectF rect READ rect NOTIFY rectChanged)
52 Q_PROPERTY(
int grid READ grid NOTIFY gridChanged)
53 Q_PROPERTY(
bool snapToGrid READ snapToGrid NOTIFY snapToGridChanged)
54 Q_PROPERTY(
float zoom READ zoom NOTIFY zoomChanged)
55 Q_PROPERTY(QPoint offset READ offset NOTIFY offsetChanged)
58 GLWidget(QObject *parent = 0);
61 void createThread(RenderThread** thread, thread_function_t
function,
void* data);
64 int setProducer(Mlt::Producer*,
bool isMulti =
false);
65 int reconfigure(
bool isMulti);
67 void play(
double speed = 1.0) {
68 Controller::play(speed);
69 if (speed == 0) emit paused();
72 void seek(
int position) {
73 Controller::seek(position);
76 void refreshConsumer(
bool scrubAudio =
false);
81 int displayWidth()
const {
return m_rect.width(); }
82 int displayHeight()
const {
return m_rect.height(); }
84 QObject* videoWidget() {
return this; }
85 Filter* glslManager()
const {
return m_glslManager; }
86 QRectF rect()
const {
return m_rect; }
87 int grid()
const {
return m_grid; }
88 float zoom()
const {
return m_zoom * MLT.profile().width() / m_rect.width(); }
89 QPoint offset()
const;
91 void requestImage()
const;
92 bool snapToGrid()
const {
return m_snapToGrid; }
96 void setGrid(
int grid);
97 void setZoom(
float zoom);
98 void setOffsetX(
int x);
99 void setOffsetY(
int y);
100 void setBlankScene();
101 void setCurrentFilter(QmlFilter* filter, QmlMetadata* meta);
102 void setSnapToGrid(
bool snap);
108 void gpuNotSupported();
115 void offsetChanged();
117 void snapToGridChanged();
118 void toggleZoom(
bool);
124 QOpenGLShaderProgram* m_shader;
126 Filter* m_glslManager;
127 QSemaphore m_initSem;
128 bool m_isInitialized;
129 Event* m_threadStartEvent;
130 Event* m_threadStopEvent;
131 Event* m_threadCreateEvent;
132 Event* m_threadJoinEvent;
133 FrameRenderer* m_frameRenderer;
134 int m_projectionLocation;
135 int m_modelViewLocation;
136 int m_vertexLocation;
137 int m_texCoordLocation;
138 int m_colorspaceLocation;
139 int m_textureLocation[3];
142 QOffscreenSurface m_offscreenSurface;
143 QOpenGLContext* m_shareContext;
146 QUrl m_savedQmlSource;
148 QTimer m_refreshTimer;
151 static void on_frame_show(mlt_consumer,
void*
self, mlt_frame frame);
155 void resizeGL(
int width,
int height);
156 void updateTexture(GLuint yName, GLuint uName, GLuint vName);
158 void onRefreshTimeout();
161 void resizeEvent(QResizeEvent* event);
162 void mousePressEvent(QMouseEvent *);
163 void mouseMoveEvent(QMouseEvent *);
164 void keyPressEvent(QKeyEvent* event);
165 bool event(QEvent* event);
169 class RenderThread :
public QThread
173 RenderThread(thread_function_t
function,
void* data, QOpenGLContext *context, QSurface* surface);
179 thread_function_t m_function;
181 QOpenGLContext* m_context;
185 class FrameRenderer :
public QThread
189 FrameRenderer(QOpenGLContext* shareContext, QSurface* surface);
191 QSemaphore* semaphore() {
return &m_semaphore; }
192 QOpenGLContext* context()
const {
return m_context; }
194 Q_INVOKABLE
void showFrame(Mlt::Frame frame);
196 QImage image()
const {
return m_image; }
202 void textureReady(GLuint yName, GLuint uName = 0, GLuint vName = 0);
207 QSemaphore m_semaphore;
209 QOpenGLContext* m_context;
211 qint64 m_previousMSecs;
212 bool m_imageRequested;
216 GLuint m_renderTexture[3];
217 GLuint m_displayTexture[3];
218 QOpenGLFunctions_3_2_Core* m_gl32;
The SharedFrame provides thread safe access to Mlt::Frame data.
Definition: sharedframe.h:48