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; }
93 int maxTextureSize()
const {
return m_maxTextureSize; }
97 void setGrid(
int grid);
98 void setZoom(
float zoom);
99 void setOffsetX(
int x);
100 void setOffsetY(
int y);
101 void setBlankScene();
102 void setCurrentFilter(QmlFilter* filter, QmlMetadata* meta);
103 void setSnapToGrid(
bool snap);
109 void gpuNotSupported();
116 void offsetChanged();
118 void snapToGridChanged();
119 void toggleZoom(
bool);
125 QOpenGLShaderProgram* m_shader;
127 Filter* m_glslManager;
128 QSemaphore m_initSem;
129 bool m_isInitialized;
130 Event* m_threadStartEvent;
131 Event* m_threadStopEvent;
132 Event* m_threadCreateEvent;
133 Event* m_threadJoinEvent;
134 FrameRenderer* m_frameRenderer;
135 int m_projectionLocation;
136 int m_modelViewLocation;
137 int m_vertexLocation;
138 int m_texCoordLocation;
139 int m_colorspaceLocation;
140 int m_textureLocation[3];
143 QOffscreenSurface m_offscreenSurface;
144 QOpenGLContext* m_shareContext;
147 QUrl m_savedQmlSource;
149 QTimer m_refreshTimer;
151 GLint m_maxTextureSize;
153 static void on_frame_show(mlt_consumer,
void*
self, mlt_frame frame);
157 void resizeGL(
int width,
int height);
158 void updateTexture(GLuint yName, GLuint uName, GLuint vName);
160 void onRefreshTimeout();
163 void resizeEvent(QResizeEvent* event);
164 void mousePressEvent(QMouseEvent *);
165 void mouseMoveEvent(QMouseEvent *);
166 void keyPressEvent(QKeyEvent* event);
167 bool event(QEvent* event);
171 class RenderThread :
public QThread
175 RenderThread(thread_function_t
function,
void* data, QOpenGLContext *context, QSurface* surface);
181 thread_function_t m_function;
183 QOpenGLContext* m_context;
187 class FrameRenderer :
public QThread
191 FrameRenderer(QOpenGLContext* shareContext, QSurface* surface);
193 QSemaphore* semaphore() {
return &m_semaphore; }
194 QOpenGLContext* context()
const {
return m_context; }
196 Q_INVOKABLE
void showFrame(Mlt::Frame frame);
198 QImage image()
const {
return m_image; }
204 void textureReady(GLuint yName, GLuint uName = 0, GLuint vName = 0);
209 QSemaphore m_semaphore;
211 QOpenGLContext* m_context;
213 qint64 m_previousMSecs;
214 bool m_imageRequested;
218 GLuint m_renderTexture[3];
219 GLuint m_displayTexture[3];
220 QOpenGLFunctions_3_2_Core* m_gl32;
The SharedFrame provides thread safe access to Mlt::Frame data.
Definition: sharedframe.h:48