From 1a4d0d41d536399761a8297f585a26fc6b212c30 Mon Sep 17 00:00:00 2001 From: VaL Doroshchuk Date: Fri, 25 May 2018 13:17:36 +0200 Subject: [PATCH] Add hole punching --- .gitignore | 2 +- .qmake.conf | 3 + .../playback/qgstreamermediaplayer.cpp | 8 ++ .../playback/qgstreamermediaplayer.h | 2 + src/plugins/plugins.pro | 2 + .../qtransparentvideobackend.cpp | 98 +++++++++++++++++++ .../qtransparentvideobackend.h | 59 +++++++++++ .../transparentvideobackend.json | 4 + .../transparentvideobackend.pro | 14 +++ src/plugins/video/video.pro | 3 + src/src.pro | 4 + 11 files changed, 198 insertions(+), 1 deletion(-) create mode 100644 .qmake.conf create mode 100644 src/plugins/video/transparentvideobackend/qtransparentvideobackend.cpp create mode 100644 src/plugins/video/transparentvideobackend/qtransparentvideobackend.h create mode 100644 src/plugins/video/transparentvideobackend/transparentvideobackend.json create mode 100644 src/plugins/video/transparentvideobackend/transparentvideobackend.pro create mode 100644 src/plugins/video/video.pro diff --git a/.gitignore b/.gitignore index 1a9addc..86ba931 100644 --- a/.gitignore +++ b/.gitignore @@ -31,7 +31,7 @@ src/gstreamer/qtgstreamerversion.h QtGstreamer.version* *-config* config.* -.qmake* +.qmake.cache .pch uic_* *_wrapper.sh diff --git a/.qmake.conf b/.qmake.conf new file mode 100644 index 0000000..097d8b9 --- /dev/null +++ b/.qmake.conf @@ -0,0 +1,3 @@ +load(qt_build_config) + +MODULE_VERSION = 5.12.0 diff --git a/src/gstreamerextras/playback/qgstreamermediaplayer.cpp b/src/gstreamerextras/playback/qgstreamermediaplayer.cpp index 2284a53..e78247a 100644 --- a/src/gstreamerextras/playback/qgstreamermediaplayer.cpp +++ b/src/gstreamerextras/playback/qgstreamermediaplayer.cpp @@ -355,5 +355,13 @@ QVariantMap QGstreamerMediaPlayer::textStreamProperties(int i) return d->session ? d->session->textStreamProperties(i) : QVariantMap(); } +void QGstreamerMediaPlayer::set(const QString &elementName, const QVariantMap& map) +{ + Q_D(QGstreamerMediaPlayer); + + if (d->session) + d->session->setGstProperties(elementName, map); +} + #include "moc_qgstreamermediaplayer.cpp" QT_END_NAMESPACE diff --git a/src/gstreamerextras/playback/qgstreamermediaplayer.h b/src/gstreamerextras/playback/qgstreamermediaplayer.h index 17fbbb1..84edd64 100644 --- a/src/gstreamerextras/playback/qgstreamermediaplayer.h +++ b/src/gstreamerextras/playback/qgstreamermediaplayer.h @@ -101,6 +101,8 @@ public: void setTextStream(int i); Q_INVOKABLE QVariantMap textStreamProperties(int i); + Q_INVOKABLE void set(const QString &elementName, const QVariantMap& map); + Q_SIGNALS: void sourceChanged(); void mediaObjectChanged(); diff --git a/src/plugins/plugins.pro b/src/plugins/plugins.pro index 9671085..58a87fa 100644 --- a/src/plugins/plugins.pro +++ b/src/plugins/plugins.pro @@ -1 +1,3 @@ TEMPLATE = subdirs + +SUBDIRS += video diff --git a/src/plugins/video/transparentvideobackend/qtransparentvideobackend.cpp b/src/plugins/video/transparentvideobackend/qtransparentvideobackend.cpp new file mode 100644 index 0000000..26da5b2 --- /dev/null +++ b/src/plugins/video/transparentvideobackend/qtransparentvideobackend.cpp @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qtransparentvideobackend.h" + +#include +#include +#include +#include + +class QTransparentVideoRendererBackend : public QDeclarativeVideoRendererBackend +{ +public: + QTransparentVideoRendererBackend(QDeclarativeVideoOutput *parent) + : QDeclarativeVideoRendererBackend(parent) + {} + + void itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &changeData) override; + QSGNode *updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *data) override; + +private: + QSGContext *m_context = nullptr; +}; + +void QTransparentVideoRendererBackend::itemChange(QQuickItem::ItemChange change, + const QQuickItem::ItemChangeData &changeData) +{ + Q_UNUSED(change); + if (!changeData.window) + return; + + m_context = static_cast(QObjectPrivate::get(changeData.window))->context->sceneGraphContext(); + + QSurfaceFormat fmt = changeData.window->requestedFormat(); + if (fmt.alphaBufferSize() != 8) { + fmt.setAlphaBufferSize(8); + changeData.window->setFormat(fmt); + } +} + +QSGNode *QTransparentVideoRendererBackend::updatePaintNode(QSGNode *oldNode, + QQuickItem::UpdatePaintNodeData *data) +{ + Q_UNUSED(data); + if (!m_context) + return nullptr; + + QSGInternalRectangleNode *rect = static_cast(oldNode); + if (!rect) + rect = m_context->createInternalRectangleNode(); + + rect->setColor(QColor(0, 0, 0, 0)); + rect->setRect(QRectF(0, 0, q->width(), q->height())); + rect->update(); + + return rect; +} + +QDeclarativeVideoBackend *QTransparentVideoNodeBackend::create(QDeclarativeVideoOutput *parent) +{ + return parent->punchHole() ? new QTransparentVideoRendererBackend(parent) : nullptr; +} diff --git a/src/plugins/video/transparentvideobackend/qtransparentvideobackend.h b/src/plugins/video/transparentvideobackend/qtransparentvideobackend.h new file mode 100644 index 0000000..c1904ab --- /dev/null +++ b/src/plugins/video/transparentvideobackend/qtransparentvideobackend.h @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QTRANSPARENTVIDEOBACKEND_H +#define QTRANSPARENTVIDEOBACKEND_H + +#include + +QT_BEGIN_NAMESPACE + +class QTransparentVideoNodeBackend : public QObject, public QDeclarativeVideoBackendFactoryInterface +{ + Q_OBJECT + Q_INTERFACES(QDeclarativeVideoBackendFactoryInterface) + Q_PLUGIN_METADATA(IID "org.qt-project.qt.declarativevideobackendfactory/5.2" FILE "transparentvideobackend.json") +public: + QDeclarativeVideoBackend *create(QDeclarativeVideoOutput *parent) override; +}; + +QT_END_NAMESPACE + +#endif + diff --git a/src/plugins/video/transparentvideobackend/transparentvideobackend.json b/src/plugins/video/transparentvideobackend/transparentvideobackend.json new file mode 100644 index 0000000..00eb8bd --- /dev/null +++ b/src/plugins/video/transparentvideobackend/transparentvideobackend.json @@ -0,0 +1,4 @@ +{ + "Keys": ["transparentvideobackend"], + "Services": ["declarativevideobackend"] +} diff --git a/src/plugins/video/transparentvideobackend/transparentvideobackend.pro b/src/plugins/video/transparentvideobackend/transparentvideobackend.pro new file mode 100644 index 0000000..0d01d6c --- /dev/null +++ b/src/plugins/video/transparentvideobackend/transparentvideobackend.pro @@ -0,0 +1,14 @@ +TARGET = transparentvideobackend + +QT += qtmultimediaquicktools-private quick-private + +HEADERS += \ + qtransparentvideobackend.h + +SOURCES += \ + qtransparentvideobackend.cpp + +PLUGIN_TYPE = video/declarativevideobackend +PLUGIN_EXTENDS = quick +PLUGIN_CLASS_NAME = QTransparentVideoNodeBackend +load(qt_plugin) diff --git a/src/plugins/video/video.pro b/src/plugins/video/video.pro new file mode 100644 index 0000000..e55d892 --- /dev/null +++ b/src/plugins/video/video.pro @@ -0,0 +1,3 @@ +TEMPLATE = subdirs + +SUBDIRS += transparentvideobackend diff --git a/src/src.pro b/src/src.pro index 08f2b87..7a62a3c 100644 --- a/src/src.pro +++ b/src/src.pro @@ -9,3 +9,7 @@ qtHaveModule(quick):qtConfig(opengl) { SUBDIRS += \ src_imports } + +src_plugins.subdir = plugins + +SUBDIRS += src_plugins \ No newline at end of file -- GitLab