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)
69 Controller::play(speed);
70 if (speed == 0) emit paused();
73 void seek(
int position)
75 Controller::seek(position);
78 void refreshConsumer(
bool scrubAudio =
false);
84 int displayWidth()
const
86 return m_rect.width();
88 int displayHeight()
const
90 return m_rect.height();
93 QObject *videoWidget()
97 Filter *glslManager()
const
111 return m_zoom * MLT.profile().width() / m_rect.width();
113 QPoint offset()
const;
114 QImage image()
const;
115 bool imageIsProxy()
const;
116 void requestImage()
const;
117 bool snapToGrid()
const
121 int maxTextureSize()
const
123 return m_maxTextureSize;
128 void setGrid(
int grid);
129 void setZoom(
float zoom);
130 void setOffsetX(
int x);
131 void setOffsetY(
int y);
132 void setBlankScene();
133 void setCurrentFilter(QmlFilter *filter, QmlMetadata *meta);
134 void setSnapToGrid(
bool snap);
140 void gpuNotSupported();
147 void offsetChanged(
const QPoint &offset = QPoint());
149 void snapToGridChanged();
150 void toggleZoom(
bool);
156 QOpenGLShaderProgram *m_shader;
158 Filter *m_glslManager;
159 QSemaphore m_initSem;
160 bool m_isInitialized;
161 Event *m_threadStartEvent;
162 Event *m_threadStopEvent;
163 Event *m_threadCreateEvent;
164 Event *m_threadJoinEvent;
165 FrameRenderer *m_frameRenderer;
166 int m_projectionLocation;
167 int m_modelViewLocation;
168 int m_vertexLocation;
169 int m_texCoordLocation;
170 int m_colorspaceLocation;
171 int m_textureLocation[3];
174 QOffscreenSurface m_offscreenSurface;
175 QOpenGLContext *m_shareContext;
178 QUrl m_savedQmlSource;
180 QTimer m_refreshTimer;
182 GLint m_maxTextureSize;
183 QPoint m_mousePosition;
186 static void on_frame_show(mlt_consumer, GLWidget *widget, mlt_event_data);
190 void resizeGL(
int width,
int height);
191 void updateTexture(GLuint yName, GLuint uName, GLuint vName);
193 void onRefreshTimeout();
196 void resizeEvent(QResizeEvent *event);
197 void mousePressEvent(QMouseEvent *);
198 void mouseMoveEvent(QMouseEvent *);
199 void keyPressEvent(QKeyEvent *event);
200 bool event(QEvent *event);
204 class RenderThread :
public QThread
208 RenderThread(thread_function_t
function,
void *data, QOpenGLContext *context, QSurface *surface);
214 thread_function_t m_function;
216 QOpenGLContext *m_context;
220 class FrameRenderer :
public QThread
224 FrameRenderer(QOpenGLContext *shareContext, QSurface *surface);
226 QSemaphore *semaphore()
230 QOpenGLContext *context()
const
235 Q_INVOKABLE
void showFrame(Mlt::Frame frame);
246 void textureReady(GLuint yName, GLuint uName = 0, GLuint vName = 0);
251 QSemaphore m_semaphore;
253 QOpenGLContext *m_context;
255 qint64 m_previousMSecs;
256 bool m_imageRequested;
260 GLuint m_renderTexture[3];
261 GLuint m_displayTexture[3];
262 QOpenGLFunctions_3_2_Core *m_gl32;
The SharedFrame provides thread safe access to Mlt::Frame data.
Definition: sharedframe.h:49