21#include "mltcontroller.h"
22#include "sharedframe.h"
25#include <QQuickWidget>
34class QOffscreenSurface;
42typedef void *(*thread_function_t)(
void *);
44class VideoWidget :
public QQuickWidget,
public Controller
47 Q_PROPERTY(QRectF rect READ rect NOTIFY rectChanged)
48 Q_PROPERTY(
int grid READ grid NOTIFY gridChanged)
49 Q_PROPERTY(
bool snapToGrid READ snapToGrid NOTIFY snapToGridChanged)
50 Q_PROPERTY(
float zoom READ zoom NOTIFY zoomChanged)
51 Q_PROPERTY(QPoint offset READ offset NOTIFY offsetChanged)
54 VideoWidget(QObject *parent = 0);
55 virtual ~VideoWidget();
57 int setProducer(Mlt::Producer *,
bool isMulti =
false);
58 void createThread(RenderThread **thread, thread_function_t function,
void *data);
61 int reconfigure(
bool isMulti);
63 void play(
double speed = 1.0)
65 Controller::play(speed);
71 void seek(
int position)
73 Controller::seek(position);
76 void refreshConsumer(
bool scrubAudio =
false);
82 int displayWidth()
const {
return m_rect.width(); }
83 int displayHeight()
const {
return m_rect.height(); }
85 QObject *videoWidget() {
return this; }
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 bool imageIsProxy()
const;
92 void requestImage()
const;
93 bool snapToGrid()
const {
return m_snapToGrid; }
94 int maxTextureSize()
const {
return m_maxTextureSize; }
95 void toggleVuiDisplay();
98 void setGrid(
int grid);
99 void setZoom(
float zoom);
100 void setOffsetX(
int x);
101 void setOffsetY(
int y);
102 void setBlankScene();
103 void setCurrentFilter(QmlFilter *filter, QmlMetadata *meta);
104 void setSnapToGrid(
bool snap);
105 virtual void initialize();
106 virtual void beforeRendering(){};
107 virtual void renderVideo();
108 virtual void onFrameDisplayed(
const SharedFrame &frame);
111 void frameDisplayed(
const SharedFrame &frame);
114 void gpuNotSupported();
121 void offsetChanged(
const QPoint &offset = QPoint());
123 void snapToGridChanged();
124 void toggleZoom(
bool);
130 QSemaphore m_initSem;
131 bool m_isInitialized;
132 std::unique_ptr<Filter> m_glslManager;
133 std::unique_ptr<Event> m_threadStartEvent;
134 std::unique_ptr<Event> m_threadStopEvent;
135 std::unique_ptr<Event> m_threadCreateEvent;
136 std::unique_ptr<Event> m_threadJoinEvent;
137 FrameRenderer *m_frameRenderer;
140 QUrl m_savedQmlSource;
143 QTimer m_refreshTimer;
145 QPoint m_mousePosition;
146 std::unique_ptr<RenderThread> m_renderThread;
148 static void on_frame_show(mlt_consumer, VideoWidget *widget, mlt_event_data);
151 void resizeVideo(
int width,
int height);
152 void onRefreshTimeout();
155 void resizeEvent(QResizeEvent *event);
156 void mousePressEvent(QMouseEvent *);
157 void mouseMoveEvent(QMouseEvent *);
158 void keyPressEvent(QKeyEvent *event);
159 bool event(QEvent *event);
162 int m_maxTextureSize;
163 SharedFrame m_sharedFrame;
167class RenderThread :
public QThread
171 RenderThread(thread_function_t function,
void *data);
178 thread_function_t m_function;
180 std::unique_ptr<QOpenGLContext> m_context;
181 std::unique_ptr<QOffscreenSurface> m_surface;
184class FrameRenderer :
public QThread
190 QSemaphore *semaphore() {
return &m_semaphore; }
191 SharedFrame getDisplayFrame();
192 Q_INVOKABLE
void showFrame(Mlt::Frame frame);
194 QImage image()
const {
return m_image; }
197 void frameDisplayed(
const SharedFrame &frame);
201 QSemaphore m_semaphore;
202 SharedFrame m_displayFrame;
203 bool m_imageRequested;