From 6de7c3104006c3aa919a697bc94ec99a3f0c4140 Mon Sep 17 00:00:00 2001 From: Jonas Rabbe Date: Mon, 6 Feb 2012 10:55:59 +1000 Subject: [PATCH] Added loading of video node factories from plugins This change will allow us to add new video node factories that can be loaded dynamically at runtime. The previous video node factories, I420 and RGB have been kept as static parts of the Qt Multimedia imports, but can be moved to plugins at a later date. For plugins to be able to find and use QSGVideoNode, the class has to be exported. Change-Id: Idbead9a8ad33619cebe90fcec92eb29cf52ae9bd Reviewed-by: Michael Goddard --- src/imports/multimedia/multimedia.pro | 4 +- .../multimedia/qdeclarativevideooutput.cpp | 15 +++- .../multimedia/qdeclarativevideooutput_p.h | 2 +- src/imports/multimedia/qsgvideonode_i420.cpp | 5 ++ src/imports/multimedia/qsgvideonode_i420.h | 3 +- src/imports/multimedia/qsgvideonode_rgb.cpp | 5 ++ src/imports/multimedia/qsgvideonode_rgb.h | 3 +- .../qsgvideonode_p.h | 21 ++++- .../qtmultimediaquickdefs_p.h | 90 +++++++++++++++++++ .../qsgvideonode_p.cpp} | 4 + .../qtmultimediaquicktools.pro | 30 +++++++ src/src.pro | 9 +- 12 files changed, 180 insertions(+), 11 deletions(-) rename src/{imports/multimedia => multimedia/qtmultimediaquicktools_headers}/qsgvideonode_p.h (83%) create mode 100644 src/multimedia/qtmultimediaquicktools_headers/qtmultimediaquickdefs_p.h rename src/{imports/multimedia/qsgvideonode.cpp => qtmultimediaquicktools/qsgvideonode_p.cpp} (99%) create mode 100644 src/qtmultimediaquicktools/qtmultimediaquicktools.pro diff --git a/src/imports/multimedia/multimedia.pro b/src/imports/multimedia/multimedia.pro index df01cc6b..6bf5fbad 100644 --- a/src/imports/multimedia/multimedia.pro +++ b/src/imports/multimedia/multimedia.pro @@ -8,12 +8,13 @@ QT += declarative quick network multimedia-private DESTDIR = $$QT.multimedia.imports/$$TARGETPATH target.path = $$[QT_INSTALL_IMPORTS]/$$TARGETPATH +LIBS += -lQtMultimediaQuick_p + HEADERS += \ qdeclarativeaudio_p.h \ qdeclarativemediabase_p.h \ qdeclarativemediametadata_p.h \ qdeclarativevideooutput_p.h \ - qsgvideonode_p.h \ qsgvideonode_i420.h \ qsgvideonode_rgb.h \ qdeclarativeradio_p.h \ @@ -36,7 +37,6 @@ SOURCES += \ qdeclarativeaudio.cpp \ qdeclarativemediabase.cpp \ qdeclarativevideooutput.cpp \ - qsgvideonode.cpp \ qsgvideonode_i420.cpp \ qsgvideonode_rgb.cpp \ qdeclarativeradio.cpp \ diff --git a/src/imports/multimedia/qdeclarativevideooutput.cpp b/src/imports/multimedia/qdeclarativevideooutput.cpp index 21c09904..58a2c819 100644 --- a/src/imports/multimedia/qdeclarativevideooutput.cpp +++ b/src/imports/multimedia/qdeclarativevideooutput.cpp @@ -40,7 +40,7 @@ ****************************************************************************/ #include "qdeclarativevideooutput_p.h" -#include "qsgvideonode_p.h" +#include #include "qsgvideonode_i420.h" #include "qsgvideonode_rgb.h" @@ -50,7 +50,7 @@ #include #include #include - +#include #include @@ -59,6 +59,9 @@ Q_DECLARE_METATYPE(QAbstractVideoSurface*) QT_BEGIN_NAMESPACE +Q_GLOBAL_STATIC_WITH_ARGS(QMediaPluginLoader, videoNodeFactoryLoader, + (QSGVideoNodeFactory_iid, QLatin1String("video"), Qt::CaseInsensitive)) + class QSGVideoItemSurface : public QAbstractVideoSurface { public: @@ -172,6 +175,14 @@ QDeclarativeVideoOutput::QDeclarativeVideoOutput(QQuickItem *parent) : connect(m_surface, SIGNAL(surfaceFormatChanged(QVideoSurfaceFormat)), this, SLOT(_q_updateNativeSize(QVideoSurfaceFormat)), Qt::QueuedConnection); + foreach (QObject *instance, videoNodeFactoryLoader()->instances(QSGVideoNodeFactoryPluginKey)) { + QSGVideoNodeFactory* plugin = qobject_cast(instance); + if (plugin) { + m_videoNodeFactories.append(plugin); + } + } + + // Append existing node factories as fallback if we have no plugins m_videoNodeFactories.append(new QSGVideoNodeFactory_I420); m_videoNodeFactories.append(new QSGVideoNodeFactory_RGB); } diff --git a/src/imports/multimedia/qdeclarativevideooutput_p.h b/src/imports/multimedia/qdeclarativevideooutput_p.h index 59e2ce37..13710b1a 100644 --- a/src/imports/multimedia/qdeclarativevideooutput_p.h +++ b/src/imports/multimedia/qdeclarativevideooutput_p.h @@ -52,7 +52,7 @@ #include #include -#include "qsgvideonode_p.h" +#include QT_BEGIN_NAMESPACE diff --git a/src/imports/multimedia/qsgvideonode_i420.cpp b/src/imports/multimedia/qsgvideonode_i420.cpp index ef075eb9..3ee9e851 100644 --- a/src/imports/multimedia/qsgvideonode_i420.cpp +++ b/src/imports/multimedia/qsgvideonode_i420.cpp @@ -65,6 +65,11 @@ QSGVideoNode *QSGVideoNodeFactory_I420::createNode(const QVideoSurfaceFormat &fo return 0; } +QStringList QSGVideoNodeFactory_I420::keys() const +{ + return QStringList() << QSGVideoNodeFactoryPluginKey; +} + class QSGVideoMaterialShader_YUV420 : public QSGMaterialShader { diff --git a/src/imports/multimedia/qsgvideonode_i420.h b/src/imports/multimedia/qsgvideonode_i420.h index e37abd9a..4ab1139f 100644 --- a/src/imports/multimedia/qsgvideonode_i420.h +++ b/src/imports/multimedia/qsgvideonode_i420.h @@ -42,7 +42,7 @@ #ifndef QSGVIDEONODE_I420_H #define QSGVIDEONODE_I420_H -#include "qsgvideonode_p.h" +#include #include class QSGVideoMaterial_YUV420; @@ -68,6 +68,7 @@ class QSGVideoNodeFactory_I420 : public QSGVideoNodeFactory { public: QList supportedPixelFormats(QAbstractVideoBuffer::HandleType handleType) const; QSGVideoNode *createNode(const QVideoSurfaceFormat &format); + QStringList keys() const; }; diff --git a/src/imports/multimedia/qsgvideonode_rgb.cpp b/src/imports/multimedia/qsgvideonode_rgb.cpp index b7fd9c79..30ebd54a 100644 --- a/src/imports/multimedia/qsgvideonode_rgb.cpp +++ b/src/imports/multimedia/qsgvideonode_rgb.cpp @@ -70,6 +70,11 @@ QSGVideoNode *QSGVideoNodeFactory_RGB::createNode(const QVideoSurfaceFormat &for return 0; } +QStringList QSGVideoNodeFactory_RGB::keys() const +{ + return QStringList() << QSGVideoNodeFactoryPluginKey; +} + class QSGVideoMaterialShader_RGB : public QSGMaterialShader { diff --git a/src/imports/multimedia/qsgvideonode_rgb.h b/src/imports/multimedia/qsgvideonode_rgb.h index dd5a852e..d4365352 100644 --- a/src/imports/multimedia/qsgvideonode_rgb.h +++ b/src/imports/multimedia/qsgvideonode_rgb.h @@ -42,7 +42,7 @@ #ifndef QSGVIDEONODE_RGB_H #define QSGVIDEONODE_RGB_H -#include "qsgvideonode_p.h" +#include #include class QSGVideoMaterial_RGB; @@ -68,6 +68,7 @@ class QSGVideoNodeFactory_RGB : public QSGVideoNodeFactory { public: QList supportedPixelFormats(QAbstractVideoBuffer::HandleType handleType) const; QSGVideoNode *createNode(const QVideoSurfaceFormat &format); + QStringList keys() const; }; diff --git a/src/imports/multimedia/qsgvideonode_p.h b/src/multimedia/qtmultimediaquicktools_headers/qsgvideonode_p.h similarity index 83% rename from src/imports/multimedia/qsgvideonode_p.h rename to src/multimedia/qtmultimediaquicktools_headers/qsgvideonode_p.h index 271eb868..f82a337e 100644 --- a/src/imports/multimedia/qsgvideonode_p.h +++ b/src/multimedia/qtmultimediaquicktools_headers/qsgvideonode_p.h @@ -43,12 +43,22 @@ #define QSGVIDEONODE_P_H #include +#include #include #include #include +#include -class QSGVideoNode : public QSGGeometryNode +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Multimedia) + +const QLatin1String QSGVideoNodeFactoryPluginKey("sgvideonodes"); + +class Q_MULTIMEDIAQUICK_EXPORT QSGVideoNode : public QSGGeometryNode { public: QSGVideoNode(); @@ -64,10 +74,17 @@ private: int m_orientation; }; -class QSGVideoNodeFactory { +class QSGVideoNodeFactory : public QFactoryInterface { public: virtual QList supportedPixelFormats(QAbstractVideoBuffer::HandleType handleType) const = 0; virtual QSGVideoNode *createNode(const QVideoSurfaceFormat &format) = 0; }; +#define QSGVideoNodeFactory_iid "com.nokia.Qt.QSGVideoNodeFactory" +Q_DECLARE_INTERFACE(QSGVideoNodeFactory, QSGVideoNodeFactory_iid) + +QT_END_NAMESPACE + +QT_END_HEADER + #endif // QSGVIDEONODE_H diff --git a/src/multimedia/qtmultimediaquicktools_headers/qtmultimediaquickdefs_p.h b/src/multimedia/qtmultimediaquicktools_headers/qtmultimediaquickdefs_p.h new file mode 100644 index 00000000..a204b5fe --- /dev/null +++ b/src/multimedia/qtmultimediaquicktools_headers/qtmultimediaquickdefs_p.h @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#ifndef QMULTIMEDIAQUICKDEFS_P_H +#define QMULTIMEDIAQUICKDEFS_P_H + +#include + +QT_BEGIN_HEADER + +#if defined(Q_OS_WIN) +# if defined(QT_NODLL) +# undef QT_MAKEDLL +# undef QT_DLL +# elif defined(QT_MAKEDLL) +# if defined(QT_DLL) +# undef QT_DLL +# endif +# if defined(QT_BUILD_QTMM_QUICK_LIB) +# define Q_MULTIMEDIAQUICK_EXPORT Q_DECL_EXPORT +# else +# define Q_MULTIMEDIAQUICK_EXPORT Q_DECL_IMPORT +# endif +# elif defined(QT_DLL) /* use a Qt DLL library */ +# define Q_MULTIMEDIAQUICK_EXPORT Q_DECL_IMPORT +# endif +#endif + +#if !defined(Q_MULTIMEDIAQUICK_EXPORT) +# if defined(QT_SHARED) +# define Q_MULTIMEDIAQUICK_EXPORT Q_DECL_EXPORT +# else +# define Q_MULTIMEDIAQUICK_EXPORT +# endif +#endif + +QT_END_HEADER + + +#endif // QMULTIMEDIAQUICKDEFS_P_H + diff --git a/src/imports/multimedia/qsgvideonode.cpp b/src/qtmultimediaquicktools/qsgvideonode_p.cpp similarity index 99% rename from src/imports/multimedia/qsgvideonode.cpp rename to src/qtmultimediaquicktools/qsgvideonode_p.cpp index b0d2ad32..2c9f2410 100644 --- a/src/imports/multimedia/qsgvideonode.cpp +++ b/src/qtmultimediaquicktools/qsgvideonode_p.cpp @@ -41,6 +41,8 @@ #include "qsgvideonode_p.h" +QT_BEGIN_NAMESPACE + QSGVideoNode::QSGVideoNode() : m_orientation(-1) { @@ -122,3 +124,5 @@ void QSGVideoNode::setTexturedRectGeometry(const QRectF &rect, const QRectF &tex markDirty(DirtyGeometry); } + +QT_END_NAMESPACE diff --git a/src/qtmultimediaquicktools/qtmultimediaquicktools.pro b/src/qtmultimediaquicktools/qtmultimediaquicktools.pro new file mode 100644 index 00000000..a94ab848 --- /dev/null +++ b/src/qtmultimediaquicktools/qtmultimediaquicktools.pro @@ -0,0 +1,30 @@ +load(qt_module) + +TEMPLATE = lib + +TARGET = QtMultimediaQuick_p +QPRO_PWD = $$PWD +QT = core quick multimedia-private + +!static:DEFINES += QT_MAKEDLL + +DEFINES += QT_BUILD_QTMM_QUICK_LIB + +# Header files must go inside source directory of a module +# to be installed by syncqt. +INCLUDEPATH += ../multimedia/qtmultimediaquicktools_headers/ +DEPENDPATH += ../multimedia/qtmultimediaquicktools_headers/ + +PRIVATE_HEADERS += \ + qsgvideonode_p.h \ + qtmultimediaquickdefs_p.h + +SOURCES += \ + qsgvideonode_p.cpp + +HEADERS += $$PRIVATE_HEADERS + +DESTDIR = $$QT.multimedia.libs +target.path = $$[QT_INSTALL_LIBS] + +INSTALLS += target diff --git a/src/src.pro b/src/src.pro index df94ec64..8a553710 100644 --- a/src/src.pro +++ b/src/src.pro @@ -6,6 +6,9 @@ SUBDIRS += multimedia src_qgsttools.subdir = gsttools src_qgsttools.depends = multimedia +src_qtmultimediaquicktools.subdir = qtmultimediaquicktools +src_qtmultimediaquicktools.depends = multimedia + src_qtmmwidgets.subdir = multimediawidgets src_qtmmwidgets.depends = multimedia @@ -13,9 +16,11 @@ src_plugins.subdir = plugins src_plugins.depends = multimedia src_imports.subdir = imports -src_imports.depends = multimedia +src_imports.depends = multimedia src_qtmultimediaquicktools -SUBDIRS += src_imports +SUBDIRS += \ + src_qtmultimediaquicktools \ + src_imports # Optional bits contains(config_test_gstreamer, yes):SUBDIRS += src_qgsttools