summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVal Doroshchuk <valentyn.doroshchuk@qt.io>2018-07-26 15:08:28 +0200
committerVal Doroshchuk <valentyn.doroshchuk@qt.io>2019-11-12 13:04:59 +0100
commitf9a576826c0d770aaae8aadbedaf83e1c0b72e0a (patch)
treeaa0069bf51310e0e88e8475338db6449100254b3
parent3d33ebd547d5cdc16e6f8700282035ac3b96e604 (diff)
Android: Fix fetching video frame data from the GUI thread5.13
If QAbstractVideoSurface is not used on rendering thread added a way to pass shared opengl context via GLContext surface property. Camera and media players that are created in Qt Quick will usually have their rendering done on the render thread, but the callback for custom video surface(s) (or probes) will usually be handle on the GUI thread, so to make it convenient to for the user to access the frame data, which is rendered on request, we now set-up context sharing and render to a fbo on the calling thread, if needed. Task-number: QTBUG-69333 Change-Id: I4cc5c1f741c82376f1402a047b946b59281c9a4c Reviewed-by: Christian Strømme <christian.stromme@qt.io>
-rw-r--r--src/plugins/android/src/common/qandroidvideooutput.cpp33
-rw-r--r--src/plugins/android/src/common/qandroidvideooutput.h5
2 files changed, 38 insertions, 0 deletions
diff --git a/src/plugins/android/src/common/qandroidvideooutput.cpp b/src/plugins/android/src/common/qandroidvideooutput.cpp
index 083ceff2..a4f4dbd5 100644
--- a/src/plugins/android/src/common/qandroidvideooutput.cpp
+++ b/src/plugins/android/src/common/qandroidvideooutput.cpp
@@ -49,6 +49,8 @@
#include <qopenglshaderprogram.h>
#include <qopenglframebufferobject.h>
#include <QtCore/private/qjnihelpers_p.h>
+#include <QtGui/QWindow>
+#include <QtGui/QOffscreenSurface>
QT_BEGIN_NAMESPACE
@@ -182,6 +184,8 @@ QAndroidTextureVideoOutput::QAndroidTextureVideoOutput(QObject *parent)
QAndroidTextureVideoOutput::~QAndroidTextureVideoOutput()
{
+ delete m_offscreenSurface;
+ delete m_glContext;
clearSurfaceTexture();
if (m_glDeleter) { // Make sure all of these are deleted on the render thread.
@@ -345,6 +349,35 @@ bool QAndroidTextureVideoOutput::renderFrameToFbo()
if (!m_nativeSize.isValid() || !m_surfaceTexture)
return false;
+ // Make sure we have an OpenGL context to make current.
+ if (!QOpenGLContext::currentContext() && !m_glContext) {
+ // Create Hidden QWindow surface to create context in this thread.
+ m_offscreenSurface = new QWindow();
+ m_offscreenSurface->setSurfaceType(QWindow::OpenGLSurface);
+ // Needs geometry to be a valid surface, but size is not important.
+ m_offscreenSurface->setGeometry(0, 0, 1, 1);
+ m_offscreenSurface->create();
+
+ // Create OpenGL context and set share context from surface.
+ m_glContext = new QOpenGLContext();
+ m_glContext->setFormat(m_offscreenSurface->requestedFormat());
+
+ auto surface = qobject_cast<QAbstractVideoSurface *>(m_surface->property("videoSurface").value<QObject *>());
+ if (!surface)
+ surface = m_surface;
+ auto shareContext = qobject_cast<QOpenGLContext *>(surface->property("GLContext").value<QObject *>());
+ if (shareContext)
+ m_glContext->setShareContext(shareContext);
+
+ if (!m_glContext->create()) {
+ qWarning("Failed to create QOpenGLContext");
+ return false;
+ }
+ }
+
+ if (m_glContext)
+ m_glContext->makeCurrent(m_offscreenSurface);
+
createGLResources();
m_surfaceTexture->updateTexImage();
diff --git a/src/plugins/android/src/common/qandroidvideooutput.h b/src/plugins/android/src/common/qandroidvideooutput.h
index 2a35247e..456fe8e2 100644
--- a/src/plugins/android/src/common/qandroidvideooutput.h
+++ b/src/plugins/android/src/common/qandroidvideooutput.h
@@ -51,6 +51,8 @@ class AndroidSurfaceHolder;
class QOpenGLFramebufferObject;
class QOpenGLShaderProgram;
class QAbstractVideoSurface;
+class QWindow;
+class QOpenGLContext;
class QAndroidVideoOutput : public QObject
{
@@ -132,6 +134,9 @@ private:
bool m_surfaceTextureCanAttachToContext;
+ QWindow *m_offscreenSurface = nullptr;
+ QOpenGLContext *m_glContext = nullptr;
+
friend class AndroidTextureVideoBuffer;
};