22 #include <QQuickWidget> 23 #include <QOpenGLFunctions> 24 #include <QOpenGLShaderProgram> 25 #include <QOpenGLFramebufferObject> 26 #include <QOpenGLContext> 27 #include <QOffscreenSurface> 31 #include "mltcontroller.h" 32 #include "sharedframe.h" 34 class QOpenGLFunctions_3_2_Core;
45 typedef void* ( *thread_function_t )(
void* );
47 class GLWidget :
public QQuickWidget,
public Controller,
protected QOpenGLFunctions
50 Q_PROPERTY(QRect rect READ rect NOTIFY rectChanged)
51 Q_PROPERTY(
int grid READ grid NOTIFY gridChanged)
52 Q_PROPERTY(
bool snapToGrid READ snapToGrid NOTIFY snapToGridChanged)
53 Q_PROPERTY(
float zoom READ zoom NOTIFY zoomChanged)
54 Q_PROPERTY(QPoint offset READ offset NOTIFY offsetChanged)
57 GLWidget(QObject *parent = 0);
60 void createThread(RenderThread** thread, thread_function_t
function,
void* data);
63 int setProducer(Mlt::Producer*,
bool isMulti =
false);
64 int reconfigure(
bool isMulti);
66 void play(
double speed = 1.0) {
67 Controller::play(speed);
68 if (speed == 0) emit paused();
71 void seek(
int position) {
72 Controller::seek(position);
79 int displayWidth()
const {
return m_rect.width(); }
80 int displayHeight()
const {
return m_rect.height(); }
82 QObject* videoWidget() {
return this; }
83 Filter* glslManager()
const {
return m_glslManager; }
84 QRect rect()
const {
return m_rect; }
85 int grid()
const {
return m_grid; }
86 float zoom()
const {
return m_zoom * MLT.profile().width() / m_rect.width(); }
87 QPoint offset()
const;
89 void requestImage()
const;
90 bool snapToGrid()
const {
return m_snapToGrid; }
94 void setGrid(
int grid);
95 void setZoom(
float zoom);
96 void setOffsetX(
int x);
97 void setOffsetY(
int y);
99 void setCurrentFilter(QmlFilter* filter, QmlMetadata* meta);
100 void setSnapToGrid(
bool snap);
106 void gpuNotSupported();
113 void offsetChanged();
115 void snapToGridChanged();
116 void toggleZoom(
bool);
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);
160 bool event(QEvent* event);
164 class RenderThread :
public QThread
168 RenderThread(thread_function_t
function,
void* data, QOpenGLContext *context, QSurface* surface);
174 thread_function_t m_function;
176 QOpenGLContext* m_context;
180 class FrameRenderer :
public QThread
184 FrameRenderer(QOpenGLContext* shareContext, QSurface* surface);
186 QSemaphore* semaphore() {
return &m_semaphore; }
187 QOpenGLContext* context()
const {
return m_context; }
189 Q_INVOKABLE
void showFrame(Mlt::Frame frame);
191 QImage image()
const {
return m_image; }
197 void textureReady(GLuint yName, GLuint uName = 0, GLuint vName = 0);
202 QSemaphore m_semaphore;
204 QOpenGLContext* m_context;
206 qint64 m_previousMSecs;
207 bool m_imageRequested;
211 GLuint m_renderTexture[3];
212 GLuint m_displayTexture[3];
213 QOpenGLFunctions_3_2_Core* m_gl32;
The SharedFrame provides thread safe access to Mlt::Frame data.
Definition: sharedframe.h:48