Commit 66960061 authored by Haihua Hu's avatar Haihua Hu Committed by Matthew Waters

qt: implement qmlglsrc for qml view grab

[Matthew Waters]: gst-indent sources

https://bugzilla.gnome.org/show_bug.cgi?id=768160
parent ac35df33
plugin_LTLIBRARIES = libgstqtsink.la
plugin_LTLIBRARIES = libgstqmlgl.la
noinst_HEADERS = \
gstqsgtexture.h \
gstqtglutility.h \
gstqtsink.h \
qtitem.h
gstqtsrc.h \
qtitem.h \
qtwindow.h
moc_generated = \
moc_qtitem.cc \
moc_qtwindow.cc \
moc_gstqsgtexture.cc
#anything generated by the Qt tools...
BUILT_SOURCES = $(moc_generated)
CLEANFILES = $(moc_generated)
nodist_libgstqtsink_la_SOURCES = $(BUILT_SOURCES)
nodist_libgstqmlgl_la_SOURCES = $(BUILT_SOURCES)
libgstqtsink_la_SOURCES = \
libgstqmlgl_la_SOURCES = \
gstqsgtexture.cc \
gstqtglutility.cc \
qtitem.cc \
qtwindow.cc \
gstqtsink.cc \
gstqtsink.h \
gstqtsrc.cc \
gstqtsrc.h \
gstqtgl.h \
gstplugin.cc
libgstqtsink_la_CXXFLAGS = \
libgstqmlgl_la_CXXFLAGS = \
-I$(top_srcdir)/gst-libs \
-I$(top_builddir)/gst-libs \
$(GST_CXXFLAGS) \
......@@ -32,15 +40,15 @@ libgstqtsink_la_CXXFLAGS = \
$(QT_CFLAGS) \
$(GL_CFLAGS)
libgstqtsink_la_LIBADD = \
libgstqmlgl_la_LIBADD = \
$(GST_BASE_LIBS) \
$(GST_PLUGINS_BASE_LIBS) \
$(QT_LIBS) \
$(top_builddir)/gst-libs/gst/gl/libgstgl-$(GST_API_VERSION).la \
-lgstvideo-$(GST_API_VERSION)
libgstqtsink_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
libgstqtsink_la_LIBTOOLFLAGS = $(GST_PLUGIN_LIBTOOLFLAGS)
libgstqmlgl_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
libgstqmlgl_la_LIBTOOLFLAGS = $(GST_PLUGIN_LIBTOOLFLAGS)
$(moc_generated): moc_%.cc: %.h
......
......@@ -23,6 +23,7 @@
#endif
#include "gstqtsink.h"
#include "gstqtsrc.h"
#include <QtQml/QQmlApplicationEngine>
static gboolean
......@@ -32,6 +33,11 @@ plugin_init (GstPlugin * plugin)
GST_RANK_NONE, GST_TYPE_QT_SINK)) {
return FALSE;
}
if (!gst_element_register (plugin, "qmlglsrc",
GST_RANK_NONE, GST_TYPE_QT_SRC)) {
return FALSE;
}
/* this means the plugin must be loaded before the qml engine is loaded */
qmlRegisterType<QtGLVideoItem> ("org.freedesktop.gstreamer.GLVideoItem", 1, 0, "GstGLVideoItem");
......@@ -41,6 +47,6 @@ plugin_init (GstPlugin * plugin)
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
GST_VERSION_MINOR,
qt,
"Qt sink",
"Qt gl plugin",
plugin_init, PACKAGE_VERSION, GST_LICENSE, GST_PACKAGE_NAME,
GST_PACKAGE_ORIGIN)
/*
* GStreamer
* Copyright (C) 2016 Freescale Semiconductor, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "gstqtglutility.h"
#include <QtGui/QGuiApplication>
#if GST_GL_HAVE_WINDOW_X11 && GST_GL_HAVE_PLATFORM_GLX && defined (HAVE_QT_X11)
#include <QX11Info>
#include <gst/gl/x11/gstgldisplay_x11.h>
#include <gst/gl/x11/gstglcontext_glx.h>
#endif
#if GST_GL_HAVE_WINDOW_WAYLAND && GST_GL_HAVE_PLATFORM_EGL && defined (HAVE_QT_WAYLAND)
#include <qpa/qplatformnativeinterface.h>
#include <gst/gl/wayland/gstgldisplay_wayland.h>
#endif
#if GST_GL_HAVE_PLATFORM_EGL && defined (HAVE_QT_EGLFS)
#include <gst/gl/egl/gstgldisplay_egl.h>
#include <gst/gl/egl/gstglcontext_egl.h>
#endif
#if GST_GL_HAVE_WINDOW_COCOA && GST_GL_HAVE_PLATFORM_COCOA && defined (HAVE_QT_MAC)
#include <gst/gl/coaoa/gstgldisplay_cocoa.h>
#endif
#define GST_CAT_DEFAULT qt_gl_utils_debug
GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
GstGLDisplay *
gst_qt_get_gl_display ()
{
GstGLDisplay *display = NULL;
QGuiApplication *app = static_cast<QGuiApplication *> (QCoreApplication::instance ());
static volatile gsize _debug;
g_assert (app != NULL);
GST_INFO ("QGuiApplication::instance()->platformName() %s", app->platformName().toUtf8().data());
if (g_once_init_enter (&_debug)) {
GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "qtglutility", 0,
"Qt gl utility functions");
g_once_init_leave (&_debug, 1);
}
#if GST_GL_HAVE_WINDOW_X11 && defined (HAVE_QT_X11)
if (QString::fromUtf8 ("xcb") == app->platformName())
display = (GstGLDisplay *)
gst_gl_display_x11_new_with_display (QX11Info::display ());
#endif
#if GST_GL_HAVE_WINDOW_WAYLAND && GST_GL_HAVE_PLATFORM_EGL && defined (HAVE_QT_WAYLAND)
if (QString::fromUtf8 ("wayland") == app->platformName()
|| QString::fromUtf8 ("wayland-egl") == app->platformName()){
struct wl_display * wayland_display;
QPlatformNativeInterface *native =
QGuiApplication::platformNativeInterface();
wayland_display = (struct wl_display *)
native->nativeResourceForWindow("display", NULL);
display = (GstGLDisplay *)
gst_gl_display_wayland_new_with_display (wayland_display);
}
#endif
#if GST_GL_HAVE_PLATFORM_EGL && GST_GL_HAVE_WINDOW_ANDROID
if (QString::fromUtf8 ("android") == app->platformName())
display = (GstGLDisplay *) gst_gl_display_egl_new ();
#elif GST_GL_HAVE_PLATFORM_EGL && defined (HAVE_QT_EGLFS)
if (QString::fromUtf8("eglfs") == app->platformName())
display = (GstGLDisplay *) gst_gl_display_egl_new ();
#endif
#if GST_GL_HAVE_WINDOW_COCOA && GST_GL_HAVE_PLATFORM_COCOA && defined (HAVE_QT_MAC)
if (QString::fromUtf8 ("cocoa") == app->platformName())
display = (GstGLDisplay *) gst_gl_display_cocoa_new ();
#endif
#if GST_GL_HAVE_WINDOW_EAGL && GST_GL_HAVE_PLATFORM_EAGL && defined (HAVE_QT_IOS)
if (QString::fromUtf8 ("ios") == app->platformName())
display = gst_gl_display_new ();
#endif
#if GST_GL_HAVE_WINDOW_WIN32 && GST_GL_HAVE_PLATFORM_WGL && defined (HAVE_QT_WIN32)
if (QString::fromUtf8 ("windows") == app->platformName())
display = gst_gl_display_new ();
#endif
if (!display)
display = gst_gl_display_new ();
return display;
}
gboolean
gst_qt_get_gl_wrapcontext (GstGLDisplay * display,
GstGLContext **wrap_glcontext, GstGLContext **context)
{
GstGLPlatform platform = (GstGLPlatform) 0;
GstGLAPI gl_api;
guintptr gl_handle;
GError *error = NULL;
g_return_val_if_fail (display != NULL && wrap_glcontext != NULL, FALSE);
#if GST_GL_HAVE_WINDOW_X11 && defined (HAVE_QT_X11)
if (GST_IS_GL_DISPLAY_X11 (display)) {
platform = GST_GL_PLATFORM_GLX;
}
#endif
#if GST_GL_HAVE_WINDOW_WAYLAND && defined (HAVE_QT_WAYLAND)
if (GST_IS_GL_DISPLAY_WAYLAND (display)) {
platform = GST_GL_PLATFORM_EGL;
}
#endif
#if GST_GL_HAVE_PLATFORM_EGL && defined (HAVE_QT_EGLFS)
if (GST_IS_GL_DISPLAY_EGL (display)) {
platform = GST_GL_PLATFORM_EGL;
}
#endif
if (platform == 0) {
#if GST_GL_HAVE_WINDOW_COCOA && GST_GL_HAVE_PLATFORM_COCOA && defined (HAVE_QT_MAC)
platform = GST_GL_PLATFORM_CGL;
#elif GST_GL_HAVE_WINDOW_EAGL && GST_GL_HAVE_PLATFORM_EAGL && defined (HAVE_QT_IOS)
platform = GST_GL_PLATFORM_EAGL;
#elif GST_GL_HAVE_WINDOW_WIN32 && GST_GL_HAVE_PLATFORM_WGL && defined (HAVE_QT_WIN32)
platform = GST_GL_PLATFORM_WGL;
#else
GST_ERROR ("Unknown platform");
return FALSE;
#endif
}
gl_api = gst_gl_context_get_current_gl_api (platform, NULL, NULL);
gl_handle = gst_gl_context_get_current_gl_context (platform);
if (gl_handle)
*wrap_glcontext =
gst_gl_context_new_wrapped (display, gl_handle,
platform, gl_api);
if (!*wrap_glcontext) {
GST_ERROR ("cannot wrap qt OpenGL context");
return FALSE;
}
(void) platform;
(void) gl_api;
(void) gl_handle;
gst_gl_context_activate (*wrap_glcontext, TRUE);
if (!gst_gl_context_fill_info (*wrap_glcontext, &error)) {
GST_ERROR ("failed to retrieve qt context info: %s", error->message);
g_object_unref (*wrap_glcontext);
*wrap_glcontext = NULL;
return FALSE;
} else {
gst_gl_display_filter_gl_api (display, gst_gl_context_get_gl_api (*wrap_glcontext));
#if GST_GL_HAVE_WINDOW_WIN32 && GST_GL_HAVE_PLATFORM_WGL && defined (HAVE_QT_WIN32)
g_return_val_if_fail (context != NULL, FALSE);
if (!wglGetProcAddress ("wglCreateContextAttribsARB")) {
GstGLWindow *window;
HDC device;
/* If there's no wglCreateContextAttribsARB() support, then we would fallback to
* wglShareLists() which will fail with ERROR_BUSY (0xaa) if either of the GL
* contexts are current in any other thread.
*
* The workaround here is to temporarily disable Qt's GL context while we
* set up our own.
*/
*context = gst_gl_context_new (display);
window = gst_gl_context_get_window (*context);
device = (HDC) gst_gl_window_get_display (window);
wglMakeCurrent (device, 0);
gst_object_unref (window);
if (!gst_gl_context_create (*context, *wrap_glcontext, &error)) {
GST_ERROR ("%p failed to create shared GL context: %s", this, error->message);
g_object_unref (*context);
*context = NULL;
g_object_unref (*wrap_glcontext);
*wrap_glcontext = NULL;
wglMakeCurrent (device, (HGLRC) gl_handle);
return FALSE;
}
wglMakeCurrent (device, (HGLRC) gl_handle);
}
#endif
gst_gl_context_activate (*wrap_glcontext, FALSE);
}
return TRUE;
}
/*
* GStreamer
* Copyright (C) 2016 Freescale Semiconductor, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef __QT_GL_UTILS_H__
#define __QT_GL_UTILS_H__
#include <gst/gst.h>
#include <gst/gl/gl.h>
G_BEGIN_DECLS
GstGLDisplay * gst_qt_get_gl_display ();
gboolean gst_qt_get_gl_wrapcontext (GstGLDisplay * display,
GstGLContext **wrap_glcontext, GstGLContext **context);
G_END_DECLS
#endif /* __QT_GL_UTILS_H__ */
This diff is collapsed.
/*
* GStreamer
* Copyright (C) 2016 Freescale Semiconductor, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef __GST_QT_SRC_H__
#define __GST_QT_SRC_H__
#include <gst/gst.h>
#include <gst/base/gstpushsrc.h>
#include <gst/video/video.h>
#include <gst/gl/gl.h>
#include "qtwindow.h"
typedef struct _GstQtSrc GstQtSrc;
typedef struct _GstQtSrcClass GstQtSrcClass;
G_BEGIN_DECLS
GType gst_qt_src_get_type (void);
#define GST_TYPE_QT_SRC (gst_qt_src_get_type())
#define GST_QT_SRC(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_QT_SRC,GstQtSrc))
#define GST_QT_SRC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_QT_SRC,GstQtSrcClass))
#define GST_IS_QT_SRC(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_QT_SRC))
#define GST_IS_QT_SRC_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_QT_SRC))
#define GST_QT_SRC_CAST(obj) ((GstQtSrc*)(obj))
/**
* GstQtSrc:
*
* Opaque #GstQtSrc object
*/
struct _GstQtSrc
{
/* <private> */
GstPushSrc parent;
QQuickWindow *qwindow;
QtGLWindow *window;
GstVideoInfo v_info;
GstGLDisplay *display;
GstGLContext *context;
GstGLContext *qt_context;
gboolean default_fbo;
gboolean downstream_supports_affine_meta;
gboolean pending_image_orientation;
/* fps print support */
GstClockTime run_time;
};
/**
* GstQtSrcClass:
*
* The #GstQtSrcClass struct only contains private data
*/
struct _GstQtSrcClass
{
/* <private> */
GstPushSrcClass object_class;
};
G_END_DECLS
#endif /* __GST_QT_SRC_H__ */
......@@ -27,32 +27,13 @@
#include <gst/video/video.h>
#include "qtitem.h"
#include "gstqsgtexture.h"
#include "gstqtglutility.h"
#include <QtCore/QRunnable>
#include <QtGui/QGuiApplication>
#include <QtQuick/QQuickWindow>
#include <QtQuick/QSGSimpleTextureNode>
#if GST_GL_HAVE_WINDOW_X11 && GST_GL_HAVE_PLATFORM_GLX && defined (HAVE_QT_X11)
#include <QX11Info>
#include <gst/gl/x11/gstgldisplay_x11.h>
#include <gst/gl/x11/gstglcontext_glx.h>
#endif
#if GST_GL_HAVE_WINDOW_WAYLAND && GST_GL_HAVE_PLATFORM_EGL && defined (HAVE_QT_WAYLAND)
#include <qpa/qplatformnativeinterface.h>
#include <gst/gl/wayland/gstgldisplay_wayland.h>
#endif
#if GST_GL_HAVE_PLATFORM_EGL && defined (HAVE_QT_EGLFS)
#include <gst/gl/egl/gstgldisplay_egl.h>
#include <gst/gl/egl/gstglcontext_egl.h>
#endif
#if GST_GL_HAVE_WINDOW_COCOA && GST_GL_HAVE_PLATFORM_COCOA && defined (HAVE_QT_MAC)
#include <gst/gl/coaoa/gstgldisplay_cocoa.h>
#endif
/**
* SECTION:gtkgstglwidget
* @short_description: a #GtkGLArea that renders GStreamer video #GstBuffers
......@@ -123,11 +104,8 @@ void InitializeSceneGraph::run()
QtGLVideoItem::QtGLVideoItem()
{
QGuiApplication *app = static_cast<QGuiApplication *> (QCoreApplication::instance ());
static volatile gsize _debug;
g_assert (app != NULL);
if (g_once_init_enter (&_debug)) {
GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "qtglwidget", 0, "Qt GL Widget");
g_once_init_leave (&_debug, 1);
......@@ -143,48 +121,7 @@ QtGLVideoItem::QtGLVideoItem()
g_mutex_init (&this->priv->lock);
GST_INFO ("QGuiApplication::instance()->platformName() %s", app->platformName().toUtf8().data());
#if GST_GL_HAVE_WINDOW_X11 && defined (HAVE_QT_X11)
if (QString::fromUtf8 ("xcb") == app->platformName())
this->priv->display = (GstGLDisplay *)
gst_gl_display_x11_new_with_display (QX11Info::display ());
#endif
#if GST_GL_HAVE_WINDOW_WAYLAND && GST_GL_HAVE_PLATFORM_EGL && defined (HAVE_QT_WAYLAND)
if (QString::fromUtf8 ("wayland") == app->platformName()
|| QString::fromUtf8 ("wayland-egl") == app->platformName()){
struct wl_display * wayland_display;
QPlatformNativeInterface *native =
QGuiApplication::platformNativeInterface();
wayland_display = (struct wl_display *)
native->nativeResourceForWindow("display", NULL);
this->priv->display = (GstGLDisplay *)
gst_gl_display_wayland_new_with_display (wayland_display);
}
#endif
#if GST_GL_HAVE_PLATFORM_EGL && GST_GL_HAVE_WINDOW_ANDROID
if (QString::fromUtf8 ("android") == app->platformName())
this->priv->display = (GstGLDisplay *) gst_gl_display_egl_new ();
#elif GST_GL_HAVE_PLATFORM_EGL && defined (HAVE_QT_EGLFS)
if (QString::fromUtf8("eglfs") == app->platformName())
this->priv->display = (GstGLDisplay *) gst_gl_display_egl_new ();
#endif
#if GST_GL_HAVE_WINDOW_COCOA && GST_GL_HAVE_PLATFORM_COCOA && defined (HAVE_QT_MAC)
if (QString::fromUtf8 ("cocoa") == app->platformName())
this->priv->display = (GstGLDisplay *) gst_gl_display_cocoa_new ();
#endif
#if GST_GL_HAVE_WINDOW_EAGL && GST_GL_HAVE_PLATFORM_EAGL && defined (HAVE_QT_IOS)
if (QString::fromUtf8 ("ios") == app->platformName())
this->priv->display = gst_gl_display_new ();
#endif
#if GST_GL_HAVE_WINDOW_WIN32 && GST_GL_HAVE_PLATFORM_WGL && defined (HAVE_QT_WIN32)
if (QString::fromUtf8 ("windows") == app->platformName())
this->priv->display = gst_gl_display_new ();
#endif
if (!this->priv->display)
this->priv->display = gst_gl_display_new ();
this->priv->display = gst_qt_get_gl_display();
connect(this, SIGNAL(windowChanged(QQuickWindow*)), this,
SLOT(handleWindowChanged(QQuickWindow*)));
......@@ -318,10 +255,6 @@ qt_item_set_buffer (QtGLVideoItem * widget, GstBuffer * buffer)
void
QtGLVideoItem::onSceneGraphInitialized ()
{
GstGLPlatform platform = (GstGLPlatform) 0;
GstGLAPI gl_api;
guintptr gl_handle;
GST_DEBUG ("scene graph initialization with Qt GL context %p",
this->window()->openglContext ());
......@@ -334,89 +267,8 @@ QtGLVideoItem::onSceneGraphInitialized ()
return;
}
#if GST_GL_HAVE_WINDOW_X11 && defined (HAVE_QT_X11)
if (GST_IS_GL_DISPLAY_X11 (this->priv->display)) {
platform = GST_GL_PLATFORM_GLX;
}
#endif
#if GST_GL_HAVE_WINDOW_WAYLAND && defined (HAVE_QT_WAYLAND)
if (GST_IS_GL_DISPLAY_WAYLAND (this->priv->display)) {
platform = GST_GL_PLATFORM_EGL;
}
#endif
#if GST_GL_HAVE_PLATFORM_EGL && defined (HAVE_QT_EGLFS)
if (GST_IS_GL_DISPLAY_EGL (this->priv->display)) {
platform = GST_GL_PLATFORM_EGL;
}
#endif
if (platform == 0 && this->priv->display) {
#if GST_GL_HAVE_WINDOW_COCOA && GST_GL_HAVE_PLATFORM_COCOA && defined (HAVE_QT_MAC)
platform = GST_GL_PLATFORM_CGL;
#elif GST_GL_HAVE_WINDOW_EAGL && GST_GL_HAVE_PLATFORM_EAGL && defined (HAVE_QT_IOS)
platform = GST_GL_PLATFORM_EAGL;
#elif GST_GL_HAVE_WINDOW_WIN32 && GST_GL_HAVE_PLATFORM_WGL && defined (HAVE_QT_WIN32)
platform = GST_GL_PLATFORM_WGL;
#else
GST_ERROR ("Unknown platform");
return;
#endif
}
gl_api = gst_gl_context_get_current_gl_api (platform, NULL, NULL);
gl_handle = gst_gl_context_get_current_gl_context (platform);
if (gl_handle)
this->priv->other_context =
gst_gl_context_new_wrapped (this->priv->display, gl_handle,
platform, gl_api);
(void) platform;
(void) gl_api;
(void) gl_handle;
if (this->priv->other_context) {
GError *error = NULL;
gst_gl_context_activate (this->priv->other_context, TRUE);
if (!gst_gl_context_fill_info (this->priv->other_context, &error)) {
GST_ERROR ("%p failed to retrieve qt context info: %s", this, error->message);
g_object_unref (this->priv->other_context);
this->priv->other_context = NULL;
} else {
gst_gl_display_filter_gl_api (this->priv->display, gst_gl_context_get_gl_api (this->priv->other_context));
#if GST_GL_HAVE_WINDOW_WIN32 && GST_GL_HAVE_PLATFORM_WGL && defined (HAVE_QT_WIN32)
if (!wglGetProcAddress ("wglCreateContextAttribsARB")) {
GstGLWindow *window;
HDC device;
/* If there's no wglCreateContextAttribsARB() support, then we would fallback to
* wglShareLists() which will fail with ERROR_BUSY (0xaa) if either of the GL
* contexts are current in any other thread.
*
* The workaround here is to temporarily disable Qt's GL context while we
* set up our own.
*/
this->priv->context = gst_gl_context_new (this->priv->display);
window = gst_gl_context_get_window (this->priv->context);
device = (HDC) gst_gl_window_get_display (window);
wglMakeCurrent (device, 0);
gst_object_unref (window);
if (!gst_gl_context_create (this->priv->context, this->priv->other_context, &error)) {
GST_ERROR ("%p failed to create shared GL context: %s", this, error->message);
g_object_unref (this->priv->context);
this->priv->context = NULL;
g_object_unref (this->priv->other_context);
this->priv->other_context = NULL;
wglMakeCurrent (device, (HGLRC) gl_handle);
return;
}
wglMakeCurrent (device, (HGLRC) gl_handle);
}
#endif
gst_gl_context_activate (this->priv->other_context, FALSE);
m_openGlContextInitialized = true;
}
}
m_openGlContextInitialized = gst_qt_get_gl_wrapcontext (this->priv->display,
&this->priv->other_context, &this->priv->context);
GST_DEBUG ("%p created wrapped GL context %" GST_PTR_FORMAT, this,
this->priv->other_context);
......
/*
* GStreamer
* Copyright (C) 2016 Freescale Semiconductor, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <gst/video/video.h>
#include "qtwindow.h"
#include "gstqsgtexture.h"
#include "gstqtglutility.h"
#include <QtCore/QRunnable>
#include <QtGui/QGuiApplication>
#include <QtQuick/QQuickWindow>
#include <QOpenGLFramebufferObject>
/**
* SECTION:
*
* #QtGLWindow is an #QQuickWindow that grab QtQuick view to GStreamer OpenGL video buffers.
*/
GST_DEBUG_CATEGORY_STATIC (qt_window_debug);
#define GST_CAT_DEFAULT qt_window_debug
struct _QtGLWindowPrivate
{
GMutex lock;
GCond update_cond;
GstBuffer *buffer;
GstCaps *caps;
GstVideoInfo v_info;
gboolean initted;
gboolean updated;
gboolean quit;
gboolean result;
gboolean useDefaultFbo;
GstGLDisplay *display;
GstGLContext *other_context;
/* frames that qmlview rendered in its gl thread */
guint64 frames_rendered;
};
class InitQtGLContext : public QRunnable
{
public:
InitQtGLContext(QtGLWindow *window);
void run();
private:
QtGLWindow *window_;
};
InitQtGLContext::InitQtGLContext(QtGLWindow *window) :
window_(window)
{
}
void InitQtGLContext::run()
{
window_->onSceneGraphInitialized();
}
QtGLWindow::QtGLWindow ( QWindow * parent, QQuickWindow *src ) :
QQuickWindow( parent ), source (src)
{
QGuiApplication *app = static_cast<QGuiApplication *> (QCoreApplication::instance ());
static volatile gsize _debug;
g_assert (app != NULL);
if (g_once_init_enter (&_debug)) {
GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "qtglwindow", 0, "Qt GL QuickWindow");
g_once_init_leave (&_debug, 1);
}
this->priv = g_new0 (QtGLWindowPrivate, 1);
g_mutex_init (&this->priv->lock);
g_cond_init (&this->priv->update_cond);
this->priv->display = gst_qt_get_gl_display();
connect (source, SIGNAL(beforeRendering()), this, SLOT(beforeRendering()), Qt::DirectConnection);
connect (source, SIGNAL(afterRendering()), this, SLOT(afterRendering()), Qt::DirectConnection);
connect (app, SIGNAL(aboutToQuit()), this, SLOT(aboutToQuit()), Qt::DirectConnection);
if (source->isSceneGraphInitialized())
source->scheduleRenderJob(new InitQtGLContext(this), QQuickWindow::BeforeSynchronizingStage);
else
connect (source, SIGNAL(sceneGraphInitialized()), this, SLOT(onSceneGraphInitialized()), Qt::DirectConnection);
GST_DEBUG ("%p init Qt Window", this->priv->display);
}
QtGLWindow::~QtGLWindow()
{
GST_DEBUG ("deinit Qt Window");
g_mutex_clear (&this->priv->lock);
g_cond_clear (&this->priv->update_cond);
if (this->priv->other_context)
gst_object_unref(this->priv->other_context);
if (this->priv->display)
gst_object_unref(this->priv->display);
g_free (this->priv);
this->priv = NULL;
}
void
QtGLWindow::beforeRendering()
{