diff options
author | Lars Knoll <lars.knoll@qt.io> | 2021-03-18 09:25:03 +0100 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2021-04-06 08:08:33 +0000 |
commit | 782711418999c8e1f5914e805124ba7014687f93 (patch) | |
tree | 56dc4ee83659076591fbafee87a64b12e0ae544a | |
parent | 606cb4706ac770e84d5abe3936d1faa596d1815e (diff) |
Remove the QGstVideoRendererPlugin
It's unused. Also clean up some direct use of gst APIs.
Change-Id: Ifb573a861242c3f834eac8004240d0dbf75f2a5b
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Reviewed-by: Doris Verria <doris.verria@qt.io>
8 files changed, 43 insertions, 258 deletions
diff --git a/src/multimedia/CMakeLists.txt b/src/multimedia/CMakeLists.txt index e552bc6af..4dda49cd0 100644 --- a/src/multimedia/CMakeLists.txt +++ b/src/multimedia/CMakeLists.txt @@ -212,7 +212,6 @@ qt_internal_extend_target(Multimedia CONDITION QT_FEATURE_gstreamer platform/gstreamer/common/qgstreamervideosink.cpp platform/gstreamer/common/qgstreamervideosink_p.h platform/gstreamer/common/qgstutils.cpp platform/gstreamer/common/qgstutils_p.h platform/gstreamer/common/qgstvideobuffer.cpp platform/gstreamer/common/qgstvideobuffer_p.h - platform/gstreamer/common/qgstvideorendererplugin.cpp platform/gstreamer/common/qgstvideorendererplugin_p.h platform/gstreamer/common/qgstvideorenderersink.cpp platform/gstreamer/common/qgstvideorenderersink_p.h platform/gstreamer/qgstreamerdevicemanager.cpp platform/gstreamer/qgstreamerdevicemanager_p.h platform/gstreamer/qgstreamerformatinfo.cpp platform/gstreamer/qgstreamerformatinfo_p.h diff --git a/src/multimedia/platform/gstreamer/common/qgst_p.h b/src/multimedia/platform/gstreamer/common/qgst_p.h index 71da5ccb7..b4c6ee732 100644 --- a/src/multimedia/platform/gstreamer/common/qgst_p.h +++ b/src/multimedia/platform/gstreamer/common/qgst_p.h @@ -203,9 +203,10 @@ public: }; class QGstMutableCaps { - GstCaps *caps; + GstCaps *caps = nullptr; public: enum RefMode { HasRef, NeedsRef }; + QGstMutableCaps() = default; QGstMutableCaps(GstCaps *c, RefMode mode = HasRef) : caps(c) { diff --git a/src/multimedia/platform/gstreamer/common/qgstutils.cpp b/src/multimedia/platform/gstreamer/common/qgstutils.cpp index 443a45e7e..1cd40bb8e 100644 --- a/src/multimedia/platform/gstreamer/common/qgstutils.cpp +++ b/src/multimedia/platform/gstreamer/common/qgstutils.cpp @@ -251,7 +251,7 @@ QVideoSurfaceFormat QGstUtils::formatForCaps( return QVideoSurfaceFormat(); } -GstCaps *QGstUtils::capsForFormats(const QList<QVideoFrame::PixelFormat> &formats) +QGstMutableCaps QGstUtils::capsForFormats(const QList<QVideoFrame::PixelFormat> &formats) { GstCaps *caps = gst_caps_new_empty(); diff --git a/src/multimedia/platform/gstreamer/common/qgstutils_p.h b/src/multimedia/platform/gstreamer/common/qgstutils_p.h index 5fae20bcf..be6138a20 100644 --- a/src/multimedia/platform/gstreamer/common/qgstutils_p.h +++ b/src/multimedia/platform/gstreamer/common/qgstutils_p.h @@ -79,7 +79,7 @@ namespace QGstUtils { GstVideoInfo *info = 0, QVideoFrame::HandleType handleType = QVideoFrame::NoHandle); - Q_MULTIMEDIA_EXPORT GstCaps *capsForFormats(const QList<QVideoFrame::PixelFormat> &formats); + Q_MULTIMEDIA_EXPORT QGstMutableCaps capsForFormats(const QList<QVideoFrame::PixelFormat> &formats); void setFrameTimeStamps(QVideoFrame *frame, GstBuffer *buffer); Q_MULTIMEDIA_EXPORT bool useOpenGL(); diff --git a/src/multimedia/platform/gstreamer/common/qgstvideorendererplugin.cpp b/src/multimedia/platform/gstreamer/common/qgstvideorendererplugin.cpp deleted file mode 100644 index 5828cbd22..000000000 --- a/src/multimedia/platform/gstreamer/common/qgstvideorendererplugin.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 Jolla 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 "qgstvideorendererplugin_p.h" - -QT_BEGIN_NAMESPACE - -QGstVideoRendererPlugin::QGstVideoRendererPlugin(QObject *parent) : - QObject(parent) -{ -} - -QGstVideoRenderer::~QGstVideoRenderer() = default; - -QGstVideoRendererInterface::~QGstVideoRendererInterface() = default; - -QGstVideoRendererPlugin::~QGstVideoRendererPlugin() = default; - -QT_END_NAMESPACE - -#include "moc_qgstvideorendererplugin_p.cpp" - - diff --git a/src/multimedia/platform/gstreamer/common/qgstvideorendererplugin_p.h b/src/multimedia/platform/gstreamer/common/qgstvideorendererplugin_p.h deleted file mode 100644 index 97420842f..000000000 --- a/src/multimedia/platform/gstreamer/common/qgstvideorendererplugin_p.h +++ /dev/null @@ -1,107 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 Jolla 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 QGSTVIDEORENDERERPLUGIN_P_H -#define QGSTVIDEORENDERERPLUGIN_P_H - -// -// 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. -// - -#include <private/qtmultimediaglobal_p.h> -#include <qvideosurfaceformat.h> -#include <QtCore/qobject.h> -#include <QtCore/qplugin.h> - -#include <gst/gst.h> - -QT_BEGIN_NAMESPACE - -class QAbstractVideoSurface; - -class Q_MULTIMEDIA_EXPORT QGstVideoRenderer -{ -public: - virtual ~QGstVideoRenderer(); - - virtual GstCaps *getCaps(QAbstractVideoSurface *surface) = 0; - virtual bool start(QAbstractVideoSurface *surface, GstCaps *caps) = 0; - virtual void stop(QAbstractVideoSurface *surface) = 0; // surface may be null if unexpectedly deleted. - virtual bool proposeAllocation(GstQuery *query) = 0; // may be called from a thread. - - virtual bool present(QAbstractVideoSurface *surface, GstBuffer *buffer) = 0; - virtual void flush(QAbstractVideoSurface *surface) = 0; // surface may be null if unexpectedly deleted. -}; - -/* - Abstract interface for video buffers allocation. -*/ -class Q_MULTIMEDIA_EXPORT QGstVideoRendererInterface -{ -public: - virtual ~QGstVideoRendererInterface(); - - virtual QGstVideoRenderer *createRenderer() = 0; -}; - -#define QGstVideoRendererInterface_iid "org.qt-project.qt.gstvideorenderer/5.4" -Q_DECLARE_INTERFACE(QGstVideoRendererInterface, QGstVideoRendererInterface_iid) - -class Q_MULTIMEDIA_EXPORT QGstVideoRendererPlugin : public QObject, public QGstVideoRendererInterface -{ - Q_OBJECT - Q_INTERFACES(QGstVideoRendererInterface) -public: - explicit QGstVideoRendererPlugin(QObject *parent = 0); - virtual ~QGstVideoRendererPlugin(); - - QGstVideoRenderer *createRenderer() override = 0; - -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/multimedia/platform/gstreamer/common/qgstvideorenderersink.cpp b/src/multimedia/platform/gstreamer/common/qgstvideorenderersink.cpp index 9751652c9..86dc477aa 100644 --- a/src/multimedia/platform/gstreamer/common/qgstvideorenderersink.cpp +++ b/src/multimedia/platform/gstreamer/common/qgstvideorenderersink.cpp @@ -77,11 +77,11 @@ QT_BEGIN_NAMESPACE -QGstDefaultVideoRenderer::QGstDefaultVideoRenderer() = default; +QGstVideoRenderer::QGstVideoRenderer() = default; -QGstDefaultVideoRenderer::~QGstDefaultVideoRenderer() = default; +QGstVideoRenderer::~QGstVideoRenderer() = default; -GstCaps *QGstDefaultVideoRenderer::getCaps(QAbstractVideoSurface *surface) +QGstMutableCaps QGstVideoRenderer::getCaps(QAbstractVideoSurface *surface) { #if QT_CONFIG(gstreamer_gl) if (QGstUtils::useOpenGL()) { @@ -96,9 +96,9 @@ GstCaps *QGstDefaultVideoRenderer::getCaps(QAbstractVideoSurface *surface) formats = surface->supportedPixelFormats(m_handleType); } - GstCaps *caps = QGstUtils::capsForFormats(formats); - for (guint i = 0; i < gst_caps_get_size(caps); ++i) - gst_caps_set_features(caps, i, gst_caps_features_from_string("memory:GLMemory")); + QGstMutableCaps caps = QGstUtils::capsForFormats(formats); + for (int i = 0; i < caps.size(); ++i) + gst_caps_set_features(caps.get(), i, gst_caps_features_from_string("memory:GLMemory")); return caps; } @@ -106,7 +106,7 @@ GstCaps *QGstDefaultVideoRenderer::getCaps(QAbstractVideoSurface *surface) return QGstUtils::capsForFormats(surface->supportedPixelFormats(QVideoFrame::NoHandle)); } -bool QGstDefaultVideoRenderer::start(QAbstractVideoSurface *surface, GstCaps *caps) +bool QGstVideoRenderer::start(QAbstractVideoSurface *surface, GstCaps *caps) { m_flushed = true; m_format = QGstUtils::formatForCaps(caps, &m_videoInfo, m_handleType); @@ -114,14 +114,14 @@ bool QGstDefaultVideoRenderer::start(QAbstractVideoSurface *surface, GstCaps *ca return m_format.isValid() && surface->start(m_format); } -void QGstDefaultVideoRenderer::stop(QAbstractVideoSurface *surface) +void QGstVideoRenderer::stop(QAbstractVideoSurface *surface) { m_flushed = true; if (surface) surface->stop(); } -bool QGstDefaultVideoRenderer::present(QAbstractVideoSurface *surface, GstBuffer *buffer) +bool QGstVideoRenderer::present(QAbstractVideoSurface *surface, GstBuffer *buffer) { m_flushed = false; @@ -159,57 +159,40 @@ bool QGstDefaultVideoRenderer::present(QAbstractVideoSurface *surface, GstBuffer return surface->present(frame); } -void QGstDefaultVideoRenderer::flush(QAbstractVideoSurface *surface) +void QGstVideoRenderer::flush(QAbstractVideoSurface *surface) { if (surface && !m_flushed) surface->present(QVideoFrame()); m_flushed = true; } -bool QGstDefaultVideoRenderer::proposeAllocation(GstQuery *) +bool QGstVideoRenderer::proposeAllocation(GstQuery *) { return true; } -Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, rendererLoader, - (QGstVideoRendererInterface_iid, QLatin1String("video/gstvideorenderer"), Qt::CaseInsensitive)) - QVideoSurfaceGstDelegate::QVideoSurfaceGstDelegate(QAbstractVideoSurface *surface) : m_surface(surface) { - int i = 0; - while (QObject *instance = rendererLoader->instance(i)) { - auto plugin = qobject_cast<QGstVideoRendererInterface*>(instance); - if (QGstVideoRenderer *renderer = plugin ? plugin->createRenderer() : nullptr) - m_renderers.append(renderer); - ++i; - } - - m_renderers.append(new QGstDefaultVideoRenderer); + m_renderer = new QGstVideoRenderer; updateSupportedFormats(); connect(m_surface, SIGNAL(supportedFormatsChanged()), this, SLOT(updateSupportedFormats())); } QVideoSurfaceGstDelegate::~QVideoSurfaceGstDelegate() { - qDeleteAll(m_renderers); + delete m_renderer; - if (m_surfaceCaps) - gst_caps_unref(m_surfaceCaps); - if (m_startCaps) - gst_caps_unref(m_startCaps); #if QT_CONFIG(gstreamer_gl) if (m_gstGLDisplayContext) gst_object_unref(m_gstGLDisplayContext); #endif } -GstCaps *QVideoSurfaceGstDelegate::caps() +QGstMutableCaps QVideoSurfaceGstDelegate::caps() { QMutexLocker locker(&m_mutex); - gst_caps_ref(m_surfaceCaps); - return m_surfaceCaps; } @@ -222,10 +205,7 @@ bool QVideoSurfaceGstDelegate::start(GstCaps *caps) m_stop = true; } - if (m_startCaps) - gst_caps_unref(m_startCaps); m_startCaps = caps; - gst_caps_ref(m_startCaps); /* Waiting for start() to be invoked in the main thread may block @@ -238,10 +218,9 @@ bool QVideoSurfaceGstDelegate::start(GstCaps *caps) Currently start() fails if wait() timed out. */ - if (!waitForAsyncEvent(&locker, &m_setupCondition, 1000) && m_startCaps) { + if (!waitForAsyncEvent(&locker, &m_setupCondition, 1000) && !m_startCaps.isNull()) { qWarning() << "Failed to start video surface due to main thread blocked."; - gst_caps_unref(m_startCaps); - m_startCaps = nullptr; + m_startCaps = {}; } return m_activeRenderer != nullptr; @@ -257,10 +236,7 @@ void QVideoSurfaceGstDelegate::stop() m_flush = true; m_stop = true; - if (m_startCaps) { - gst_caps_unref(m_startCaps); - m_startCaps = nullptr; - } + m_startCaps = {}; waitForAsyncEvent(&locker, &m_setupCondition, 500); } @@ -452,16 +428,16 @@ bool QVideoSurfaceGstDelegate::handleEvent(QMutexLocker<QMutex> *locker) locker->relock(); } - } else if (m_startCaps) { + } else if (!m_startCaps.isNull()) { Q_ASSERT(!m_activeRenderer); - GstCaps * const startCaps = m_startCaps; + auto startCaps = m_startCaps; m_startCaps = nullptr; if (m_renderer && m_surface) { locker->unlock(); - const bool started = m_renderer->start(m_surface, startCaps); + const bool started = m_renderer->start(m_surface, startCaps.get()); locker->relock(); @@ -477,7 +453,6 @@ bool QVideoSurfaceGstDelegate::handleEvent(QMutexLocker<QMutex> *locker) locker->relock(); } - gst_caps_unref(startCaps); } else if (m_renderBuffer) { GstBuffer *buffer = m_renderBuffer; m_renderBuffer = nullptr; @@ -532,26 +507,7 @@ bool QVideoSurfaceGstDelegate::waitForAsyncEvent( void QVideoSurfaceGstDelegate::updateSupportedFormats() { - if (m_surfaceCaps) { - gst_caps_unref(m_surfaceCaps); - m_surfaceCaps = nullptr; - } - - for (QGstVideoRenderer *pool : qAsConst(m_renderers)) { - if (GstCaps *caps = pool->getCaps(m_surface)) { - if (gst_caps_is_empty(caps)) { - gst_caps_unref(caps); - continue; - } - - if (m_surfaceCaps) - gst_caps_unref(m_surfaceCaps); - - m_renderer = pool; - m_surfaceCaps = caps; - break; - } - } + m_surfaceCaps = m_renderer->getCaps(m_surface); } static GstVideoSinkClass *sink_parent_class; @@ -731,14 +687,12 @@ GstCaps *QGstVideoRendererSink::get_caps(GstBaseSink *base, GstCaps *filter) { VO_SINK(base); - GstCaps *caps = sink->delegate->caps(); - GstCaps *unfiltered = caps; - if (filter) { - caps = gst_caps_intersect(unfiltered, filter); - gst_caps_unref(unfiltered); - } + QGstMutableCaps caps = sink->delegate->caps(); + if (filter) + caps = gst_caps_intersect(caps.get(), filter); - return caps; + gst_caps_ref(caps.get()); + return caps.get(); } gboolean QGstVideoRendererSink::set_caps(GstBaseSink *base, GstCaps *caps) diff --git a/src/multimedia/platform/gstreamer/common/qgstvideorenderersink_p.h b/src/multimedia/platform/gstreamer/common/qgstvideorenderersink_p.h index 804798c30..b189854b1 100644 --- a/src/multimedia/platform/gstreamer/common/qgstvideorenderersink_p.h +++ b/src/multimedia/platform/gstreamer/common/qgstvideorenderersink_p.h @@ -63,9 +63,7 @@ #include <qvideosurfaceformat.h> #include <qvideoframe.h> -#include "qgstvideorendererplugin_p.h" - -#include "qgstvideorendererplugin_p.h" +#include <private/qgst_p.h> #if QT_CONFIG(gstreamer_gl) #ifndef GST_USE_UNSTABLE_API @@ -77,20 +75,20 @@ QT_BEGIN_NAMESPACE class QAbstractVideoSurface; -class QGstDefaultVideoRenderer : public QGstVideoRenderer +class QGstVideoRenderer { public: - QGstDefaultVideoRenderer(); - ~QGstDefaultVideoRenderer(); + QGstVideoRenderer(); + ~QGstVideoRenderer(); - GstCaps *getCaps(QAbstractVideoSurface *surface) override; - bool start(QAbstractVideoSurface *surface, GstCaps *caps) override; - void stop(QAbstractVideoSurface *surface) override; + QGstMutableCaps getCaps(QAbstractVideoSurface *surface); + bool start(QAbstractVideoSurface *surface, GstCaps *caps); + void stop(QAbstractVideoSurface *surface); - bool proposeAllocation(GstQuery *query) override; + bool proposeAllocation(GstQuery *query); - bool present(QAbstractVideoSurface *surface, GstBuffer *buffer) override; - void flush(QAbstractVideoSurface *surface) override; + bool present(QAbstractVideoSurface *surface, GstBuffer *buffer); + void flush(QAbstractVideoSurface *surface); private: QVideoSurfaceFormat m_format; @@ -106,7 +104,7 @@ public: QVideoSurfaceGstDelegate(QAbstractVideoSurface *surface); ~QVideoSurfaceGstDelegate(); - GstCaps *caps(); + QGstMutableCaps caps(); bool start(GstCaps *caps); void stop(); @@ -134,12 +132,11 @@ private: QWaitCondition m_setupCondition; QWaitCondition m_renderCondition; GstFlowReturn m_renderReturn = GST_FLOW_OK; - QList<QGstVideoRenderer *> m_renderers; QGstVideoRenderer *m_renderer = nullptr; QGstVideoRenderer *m_activeRenderer = nullptr; - GstCaps *m_surfaceCaps = nullptr; - GstCaps *m_startCaps = nullptr; + QGstMutableCaps m_surfaceCaps; + QGstMutableCaps m_startCaps; GstBuffer *m_renderBuffer = nullptr; #if QT_CONFIG(gstreamer_gl) GstGLContext *m_gstGLDisplayContext = nullptr; |