+#else // Qt 5
+
+#include <QThread>
+#include <QOpenGLContext>
+#include <QOffscreenSurface>
+
+typedef void* ( *thread_function_t )( void* );
+
+class RenderThread : public QThread
+{
+public:
+ RenderThread(thread_function_t function, void *data)
+ : QThread(0)
+ , m_function(function)
+ , m_data(data)
+ {
+ m_context = new QOpenGLContext;
+ m_context->create();
+ m_context->moveToThread(this);
+ m_surface = new QOffscreenSurface();
+ m_surface->create();
+ }
+ ~RenderThread()
+ {
+#ifndef Q_OS_WIN
+ m_surface->destroy();
+ delete m_surface;
+#endif
+ }
+
+protected:
+ void run()
+ {
+ Q_ASSERT(m_context->isValid());
+ m_context->makeCurrent(m_surface);
+ m_function(m_data);
+ m_context->doneCurrent();
+ delete m_context;
+ }
+
+private:
+ thread_function_t m_function;
+ void* m_data;
+ QOpenGLContext* m_context;
+ QOffscreenSurface* m_surface;
+};
+
+static void onThreadCreate(mlt_properties owner, mlt_consumer self,
+ RenderThread** thread, int* priority, thread_function_t function, void* data )
+{
+ Q_UNUSED(owner)
+ Q_UNUSED(priority)
+ (*thread) = new RenderThread(function, data);
+ (*thread)->start();
+}
+
+static void onThreadJoin(mlt_properties owner, mlt_consumer self, RenderThread* thread)
+{
+ Q_UNUSED(owner)
+ Q_UNUSED(self)
+ if (thread) {
+ thread->wait();
+ qApp->processEvents();
+ delete thread;
+ }
+}
+
+#endif // Qt 5
+