22#include <QQuickWidget>
27#include "mltcontroller.h"
28#include "sharedframe.h"
33class QOffscreenSurface;
41typedef void *( *thread_function_t )(
void * );
43class VideoWidget :
public QQuickWidget,
public Controller
46 Q_PROPERTY(QRectF rect READ rect NOTIFY rectChanged)
47 Q_PROPERTY(
int grid READ grid NOTIFY gridChanged)
48 Q_PROPERTY(
bool snapToGrid READ snapToGrid NOTIFY snapToGridChanged)
49 Q_PROPERTY(
float zoom READ zoom NOTIFY zoomChanged)
50 Q_PROPERTY(QPoint offset READ offset NOTIFY offsetChanged)
53 VideoWidget(QObject *parent = 0);
54 virtual ~VideoWidget();
56 int setProducer(Mlt::Producer *,
bool isMulti =
false);
57 void createThread(RenderThread **thread, thread_function_t function,
void *data);
60 int reconfigure(
bool isMulti);
62 void play(
double speed = 1.0)
64 Controller::play(speed);
65 if (speed == 0) emit paused();
68 void seek(
int position)
70 Controller::seek(position);
73 void refreshConsumer(
bool scrubAudio =
false);
79 int displayWidth()
const
81 return m_rect.width();
83 int displayHeight()
const
85 return m_rect.height();
88 QObject *videoWidget()
102 return m_zoom * MLT.profile().width() / m_rect.width();
104 QPoint offset()
const;
105 QImage image()
const;
106 bool imageIsProxy()
const;
107 void requestImage()
const;
108 bool snapToGrid()
const
112 int maxTextureSize()
const
114 return m_maxTextureSize;
118 void setGrid(
int grid);
119 void setZoom(
float zoom);
120 void setOffsetX(
int x);
121 void setOffsetY(
int y);
122 void setBlankScene();
123 void setCurrentFilter(QmlFilter *filter, QmlMetadata *meta);
124 void setSnapToGrid(
bool snap);
125 virtual void initialize();
126 virtual void beforeRendering() {};
127 virtual void renderVideo();
128 virtual void onFrameDisplayed(
const SharedFrame &frame);
134 void gpuNotSupported();
141 void offsetChanged(
const QPoint &offset = QPoint());
143 void snapToGridChanged();
144 void toggleZoom(
bool);
150 QSemaphore m_initSem;
151 bool m_isInitialized;
152 std::unique_ptr<Filter> m_glslManager;
153 std::unique_ptr<Event> m_threadStartEvent;
154 std::unique_ptr<Event> m_threadStopEvent;
155 std::unique_ptr<Event> m_threadCreateEvent;
156 std::unique_ptr<Event> m_threadJoinEvent;
157 FrameRenderer *m_frameRenderer;
160 QUrl m_savedQmlSource;
162 QTimer m_refreshTimer;
164 QPoint m_mousePosition;
165 std::unique_ptr<RenderThread> m_renderThread;
167 static void on_frame_show(mlt_consumer, VideoWidget *widget, mlt_event_data);
170 void resizeVideo(
int width,
int height);
171 void onRefreshTimeout();
174 void resizeEvent(QResizeEvent *event);
175 void mousePressEvent(QMouseEvent *);
176 void mouseMoveEvent(QMouseEvent *);
177 void keyPressEvent(QKeyEvent *event);
178 bool event(QEvent *event);
181 int m_maxTextureSize;
186class RenderThread :
public QThread
190 RenderThread(thread_function_t function,
void *data);
197 thread_function_t m_function;
199 std::unique_ptr<QOpenGLContext> m_context;
200 std::unique_ptr<QOffscreenSurface> m_surface;
203class FrameRenderer :
public QThread
209 QSemaphore *semaphore()
214 Q_INVOKABLE
void showFrame(Mlt::Frame frame);
226 QSemaphore m_semaphore;
228 bool m_imageRequested;
The SharedFrame provides thread safe access to Mlt::Frame data.
Definition sharedframe.h:49