21#include "mltcontroller.h"
23#include "sharedframe.h"
26#include <QQuickWidget>
35class QOffscreenSurface;
43typedef void *(*thread_function_t)(
void *);
45class VideoWidget :
public QQuickWidget,
public Controller
48 Q_PROPERTY(QRectF rect READ rect NOTIFY rectChanged)
49 Q_PROPERTY(
int grid READ grid NOTIFY gridChanged)
50 Q_PROPERTY(
bool snapToGrid READ snapToGrid NOTIFY snapToGridChanged)
51 Q_PROPERTY(
float zoom READ zoom NOTIFY zoomChanged)
52 Q_PROPERTY(QPoint offset READ offset NOTIFY offsetChanged)
55 VideoWidget(QObject *parent = 0);
56 virtual ~VideoWidget();
58 int setProducer(Mlt::Producer *,
bool isMulti =
false)
override;
59 void createThread(RenderThread **thread, thread_function_t function,
void *data);
62 int reconfigure(
bool isMulti)
override;
64 void play(
double speed = 1.0)
override
66 Controller::play(speed);
72 void seek(
int position)
override
74 Controller::seek(position);
75 if (Settings.playerPauseAfterSeek())
78 void refreshConsumer(
bool scrubAudio =
false)
override;
79 void pause(
int position = -1)
override
84 int displayWidth()
const override {
return m_rect.width(); }
85 int displayHeight()
const override {
return m_rect.height(); }
87 QObject *videoWidget()
override {
return this; }
88 QRectF rect()
const {
return m_rect; }
89 int grid()
const {
return m_grid; }
90 float zoom()
const {
return m_zoom * MLT.profile().width() / m_rect.width(); }
91 QPoint offset()
const;
93 bool imageIsProxy()
const;
94 void requestImage()
const;
95 bool snapToGrid()
const {
return m_snapToGrid; }
96 int maxTextureSize()
const {
return m_maxTextureSize; }
97 void toggleVuiDisplay();
100 void setGrid(
int grid);
101 void setZoom(
float zoom);
102 void setOffsetX(
int x);
103 void setOffsetY(
int y);
104 void setBlankScene();
105 void setCurrentFilter(QmlFilter *filter, QmlMetadata *meta);
106 void setSnapToGrid(
bool snap);
107 virtual void initialize();
108 virtual void beforeRendering(){};
109 virtual void renderVideo();
110 virtual void onFrameDisplayed(
const SharedFrame &frame);
113 void frameDisplayed(
const SharedFrame &frame);
116 void gpuNotSupported();
123 void offsetChanged(
const QPoint &offset = QPoint());
125 void snapToGridChanged();
126 void toggleZoom(
bool);
132 QSemaphore m_initSem;
133 bool m_isInitialized;
134 std::unique_ptr<Filter> m_glslManager;
135 std::unique_ptr<Event> m_threadStartEvent;
136 std::unique_ptr<Event> m_threadStopEvent;
137 std::unique_ptr<Event> m_threadCreateEvent;
138 std::unique_ptr<Event> m_threadJoinEvent;
139 FrameRenderer *m_frameRenderer;
142 QUrl m_savedQmlSource;
145 QTimer m_refreshTimer;
147 QPoint m_mousePosition;
148 std::unique_ptr<RenderThread> m_renderThread;
150 static void on_frame_show(mlt_consumer, VideoWidget *widget, mlt_event_data);
153 void resizeVideo(
int width,
int height);
154 void onRefreshTimeout();
157 void resizeEvent(QResizeEvent *event)
override;
158 void mousePressEvent(QMouseEvent *)
override;
159 void mouseMoveEvent(QMouseEvent *)
override;
160 void keyPressEvent(QKeyEvent *event)
override;
161 bool event(QEvent *event)
override;
164 int m_maxTextureSize;
165 SharedFrame m_sharedFrame;
169class RenderThread :
public QThread
173 RenderThread(thread_function_t function,
void *data);
180 thread_function_t m_function;
182 std::unique_ptr<QOpenGLContext> m_context;
183 std::unique_ptr<QOffscreenSurface> m_surface;
186class FrameRenderer :
public QThread
192 QSemaphore *semaphore() {
return &m_semaphore; }
193 SharedFrame getDisplayFrame();
194 Q_INVOKABLE
void showFrame(Mlt::Frame frame);
196 QImage image()
const {
return m_image; }
199 void frameDisplayed(
const SharedFrame &frame);
203 QSemaphore m_semaphore;
204 SharedFrame m_displayFrame;
205 bool m_imageRequested;