23 #include <QQuickWidget> 24 #include <QOpenGLFunctions> 25 #include <QOpenGLShaderProgram> 26 #include <QOpenGLFramebufferObject> 27 #include <QOpenGLContext> 28 #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(QRect 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);
80 int displayWidth()
const {
return m_rect.width(); }
81 int displayHeight()
const {
return m_rect.height(); }
83 QObject* videoWidget() {
return this; }
84 Filter* glslManager()
const {
return m_glslManager; }
85 QRect rect()
const {
return m_rect; }
86 int grid()
const {
return m_grid; }
87 float zoom()
const {
return m_zoom * MLT.profile().width() / m_rect.width(); }
88 QPoint offset()
const;
90 void requestImage()
const;
91 bool snapToGrid()
const {
return m_snapToGrid; }
95 void setGrid(
int grid);
96 void setZoom(
float zoom);
97 void setOffsetX(
int x);
98 void setOffsetY(
int y);
100 void setCurrentFilter(QmlFilter* filter, QmlMetadata* meta);
101 void setSnapToGrid(
bool snap);
107 void gpuNotSupported();
114 void offsetChanged();
116 void snapToGridChanged();
122 QOpenGLShaderProgram* m_shader;
124 Filter* m_glslManager;
125 QSemaphore m_initSem;
126 bool m_isInitialized;
127 Event* m_threadStartEvent;
128 Event* m_threadStopEvent;
129 Event* m_threadCreateEvent;
130 Event* m_threadJoinEvent;
131 FrameRenderer* m_frameRenderer;
132 int m_projectionLocation;
133 int m_modelViewLocation;
134 int m_vertexLocation;
135 int m_texCoordLocation;
136 int m_colorspaceLocation;
137 int m_textureLocation[3];
140 QOffscreenSurface m_offscreenSurface;
141 QOpenGLContext* m_shareContext;
144 QUrl m_savedQmlSource;
147 static void on_frame_show(mlt_consumer,
void*
self, mlt_frame frame);
151 void resizeGL(
int width,
int height);
152 void updateTexture(GLuint yName, GLuint uName, GLuint vName);
156 void resizeEvent(QResizeEvent* event);
157 void mousePressEvent(QMouseEvent *);
158 void mouseMoveEvent(QMouseEvent *);
159 void keyPressEvent(QKeyEvent* event);
163 class RenderThread :
public QThread
167 RenderThread(thread_function_t
function,
void* data, QOpenGLContext *context, QSurface* surface);
173 thread_function_t m_function;
175 QOpenGLContext* m_context;
179 class FrameRenderer :
public QThread
183 FrameRenderer(QOpenGLContext* shareContext, QSurface* surface);
185 QSemaphore* semaphore() {
return &m_semaphore; }
186 QOpenGLContext* context()
const {
return m_context; }
188 Q_INVOKABLE
void showFrame(Mlt::Frame frame);
190 QImage image()
const {
return m_image; }
196 void textureReady(GLuint yName, GLuint uName = 0, GLuint vName = 0);
201 QSemaphore m_semaphore;
203 QOpenGLContext* m_context;
205 qint64 m_previousMSecs;
206 bool m_imageRequested;
210 GLuint m_renderTexture[3];
211 GLuint m_displayTexture[3];
212 QOpenGLFunctions_3_2_Core* m_gl32;
Definition: encodedock.h:35
The SharedFrame provides thread safe access to Mlt::Frame data.
Definition: sharedframe.h:48