diff --git a/ext/qt/gstplugin.cc b/ext/qt/gstplugin.cc index 196cf09b35..17ce9ffcbd 100644 --- a/ext/qt/gstplugin.cc +++ b/ext/qt/gstplugin.cc @@ -22,32 +22,22 @@ #include "config.h" #endif -#include "gstqtoverlay.h" -#include "gstqtsink.h" -#include "gstqtsrc.h" +#include "gstqtelements.h" +#include "qtitem.h" #include static gboolean plugin_init (GstPlugin * plugin) { - if (!gst_element_register (plugin, "qmlglsink", - GST_RANK_NONE, GST_TYPE_QT_SINK)) { - return FALSE; - } + gboolean ret = FALSE; - if (!gst_element_register (plugin, "qmlglsrc", - GST_RANK_NONE, GST_TYPE_QT_SRC)) { - return FALSE; - } + ret |= GST_ELEMENT_REGISTER (qmlglsink, plugin); - if (!gst_element_register (plugin, "qmlgloverlay", - GST_RANK_NONE, GST_TYPE_QT_OVERLAY)) { - return FALSE; - } - /* this means the plugin must be loaded before the qml engine is loaded */ - qmlRegisterType ("org.freedesktop.gstreamer.GLVideoItem", 1, 0, "GstGLVideoItem"); + ret |= GST_ELEMENT_REGISTER (qmlglsrc, plugin); - return TRUE; + ret |= GST_ELEMENT_REGISTER (qmlgloverlay, plugin); + + return ret; } #ifndef GST_PACKAGE_NAME diff --git a/ext/qt/gstqtelement.cc b/ext/qt/gstqtelement.cc new file mode 100644 index 0000000000..ad91f4fa9a --- /dev/null +++ b/ext/qt/gstqtelement.cc @@ -0,0 +1,39 @@ +/* + * GStreamer + * Copyright (C) 2015 Matthew Waters + * + * 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 "gstqtelements.h" +#include "qtitem.h" +#include + +gboolean +qt5_element_init (GstPlugin * plugin) +{ + static gsize res = FALSE; + if (g_once_init_enter (&res)) { + /* this means the plugin must be loaded before the qml engine is loaded */ + qmlRegisterType ("org.freedesktop.gstreamer.GLVideoItem", 1, 0, "GstGLVideoItem"); + g_once_init_leave (&res, TRUE); + } + return res; +} diff --git a/ext/qt/gstqtelements.h b/ext/qt/gstqtelements.h new file mode 100644 index 0000000000..0c35d33714 --- /dev/null +++ b/ext/qt/gstqtelements.h @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2020 Huawei Technologies Co., Ltd. + * @Author: Julian Bouzas + * + * 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_ELEMENTS_H__ +#define __GST_QT_ELEMENTS_H__ + +#include + +G_BEGIN_DECLS + +gboolean qt5_element_init (GstPlugin * plugin); + +GST_ELEMENT_REGISTER_DECLARE (qmlglsink); +GST_ELEMENT_REGISTER_DECLARE (qmlglsrc); +GST_ELEMENT_REGISTER_DECLARE (qmlgloverlay); + +G_END_DECLS + +#endif /* __GST_QT_ELEMENTS_H__ */ diff --git a/ext/qt/gstqtoverlay.cc b/ext/qt/gstqtoverlay.cc index e03dda5f3b..7a9f749840 100644 --- a/ext/qt/gstqtoverlay.cc +++ b/ext/qt/gstqtoverlay.cc @@ -79,6 +79,7 @@ #include "config.h" #endif +#include "gstqtelements.h" #include "gstqtoverlay.h" #include "qtglrenderer.h" #include "gstqtglutility.h" @@ -131,6 +132,10 @@ static guint gst_qt_overlay_signals[LAST_SIGNAL] = { 0 }; G_DEFINE_TYPE_WITH_CODE (GstQtOverlay, gst_qt_overlay, GST_TYPE_GL_FILTER, GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "qtoverlay", 0, "Qt Video Overlay")); +#define _do_init \ + ret |= qt5_element_init (plugin); +GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (qmlgloverlay, "qmlgloverlay", + GST_RANK_NONE, GST_TYPE_QT_OVERLAY, _do_init); static void gst_qt_overlay_class_init (GstQtOverlayClass * klass) diff --git a/ext/qt/gstqtsink.cc b/ext/qt/gstqtsink.cc index ebf4b241a9..17ca7f3b51 100644 --- a/ext/qt/gstqtsink.cc +++ b/ext/qt/gstqtsink.cc @@ -72,6 +72,7 @@ #include "config.h" #endif +#include "gstqtelements.h" #include "gstqtsink.h" #include @@ -134,6 +135,10 @@ enum G_DEFINE_TYPE_WITH_CODE (GstQtSink, gst_qt_sink, GST_TYPE_VIDEO_SINK, GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "qtsink", 0, "Qt Video Sink")); +#define _do_init \ + ret |= qt5_element_init (plugin); +GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (qmlglsink, "qmlglsink", + GST_RANK_NONE, GST_TYPE_QT_SINK, _do_init); static void gst_qt_sink_class_init (GstQtSinkClass * klass) diff --git a/ext/qt/gstqtsrc.cc b/ext/qt/gstqtsrc.cc index 1141365803..2d7a4f6f15 100644 --- a/ext/qt/gstqtsrc.cc +++ b/ext/qt/gstqtsrc.cc @@ -27,6 +27,7 @@ #include "config.h" #endif +#include "gstqtelements.h" #include "gstqtsrc.h" #include @@ -76,6 +77,10 @@ enum G_DEFINE_TYPE_WITH_CODE (GstQtSrc, gst_qt_src, GST_TYPE_PUSH_SRC, GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "qtsrc", 0, "Qt Video Src")); +#define _do_init \ + ret |= qt5_element_init (plugin); +GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (qmlglsrc, "qmlglsrc", + GST_RANK_NONE, GST_TYPE_QT_SRC, _do_init); static const gfloat vertical_flip_matrix[] = { 1.0f, 0.0f, 0.0f, 0.0f, diff --git a/ext/qt/meson.build b/ext/qt/meson.build index 90e967ed13..a49cc31d17 100644 --- a/ext/qt/meson.build +++ b/ext/qt/meson.build @@ -1,5 +1,6 @@ sources = [ 'gstplugin.cc', + 'gstqtelement.cc', 'gstqsgtexture.cc', 'gstqtglutility.cc', 'gstqtoverlay.cc', diff --git a/ext/qt/qtplugin.pro b/ext/qt/qtplugin.pro index 78ac512f76..d772ae5069 100644 --- a/ext/qt/qtplugin.pro +++ b/ext/qt/qtplugin.pro @@ -79,6 +79,7 @@ versionAtLeast(QT_VERSION, "5.5") { SOURCES += \ gstplugin.cc \ + gstqtelement.cc \ gstqtglutility.cc \ gstqsgtexture.cc \ gstqtoverlay.cc \ @@ -89,6 +90,7 @@ SOURCES += \ qtitem.cc HEADERS += \ + gstqtelements.h \ gstqsgtexture.h \ gstqtgl.h \ gstqtglutility.h \