diff options
author | Jonas Rabbe <jonas.rabbe@nokia.com> | 2011-10-11 15:25:36 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-10-12 08:58:30 +0200 |
commit | 48d95f0baac39fc5eb38a137a8e84eda2cdb2b79 (patch) | |
tree | 038a66510f91527c70a5fc416238484842a514c1 /src/plugins/gstreamer | |
parent | 126addddb5e5a1928a8decf84e9e20655ac24f8d (diff) |
Moved general gstreamer helper classes into separate library.
Cleaned up configuration of gstreamer with a separate config
test.
Change-Id: I1ec9ee466233687fbcfdc544a12d9fce578e4379
Reviewed-on: http://codereview.qt-project.org/6459
Sanity-Review: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Michael Goddard <michael.goddard@nokia.com>
Diffstat (limited to 'src/plugins/gstreamer')
31 files changed, 27 insertions, 2388 deletions
diff --git a/src/plugins/gstreamer/camerabin/camerabinimagecapture.cpp b/src/plugins/gstreamer/camerabin/camerabinimagecapture.cpp index a73ec4bc7..874361ec7 100644 --- a/src/plugins/gstreamer/camerabin/camerabinimagecapture.cpp +++ b/src/plugins/gstreamer/camerabin/camerabinimagecapture.cpp @@ -43,9 +43,9 @@ #include "camerabincapturedestination.h" #include "camerabincapturebufferformat.h" #include "camerabinsession.h" -#include "qgstvideobuffer.h" -#include "qvideosurfacegstsink.h" -#include "qgstutils.h" +#include <private/qgstvideobuffer_p.h> +#include <private/qvideosurfacegstsink_p.h> +#include <private/qgstutils_p.h> #include <QtCore/qdebug.h> #include <QtCore/qbuffer.h> #include <QtGui/qimagereader.h> diff --git a/src/plugins/gstreamer/camerabin/camerabinservice.cpp b/src/plugins/gstreamer/camerabin/camerabinservice.cpp index 3c994b0ff..f0aaca7b9 100644 --- a/src/plugins/gstreamer/camerabin/camerabinservice.cpp +++ b/src/plugins/gstreamer/camerabin/camerabinservice.cpp @@ -46,7 +46,6 @@ #include "camerabinaudioencoder.h" #include "camerabinvideoencoder.h" #include "camerabinimageencoder.h" -#include "qgstreamerbushelper.h" #include "camerabincontrol.h" #include "camerabinlocks.h" #include "camerabinmetadata.h" @@ -57,6 +56,7 @@ #include "camerabinimageprocessing.h" #include "camerabincapturebufferformat.h" #include "camerabincapturedestination.h" +#include <private/qgstreamerbushelper_p.h> #include "qgstreameraudioinputendpointselector.h" #include "qgstreamervideoinputdevicecontrol.h" diff --git a/src/plugins/gstreamer/camerabin/camerabinsession.cpp b/src/plugins/gstreamer/camerabin/camerabinsession.cpp index 251d44d8b..996e1495f 100644 --- a/src/plugins/gstreamer/camerabin/camerabinsession.cpp +++ b/src/plugins/gstreamer/camerabin/camerabinsession.cpp @@ -51,7 +51,7 @@ #include "camerabinlocks.h" #include "camerabincapturedestination.h" #include "camerabincapturebufferformat.h" -#include "qgstreamerbushelper.h" +#include <private/qgstreamerbushelper_p.h> #include "qgstreamervideorendererinterface.h" #include <qmediarecorder.h> #include <gst/interfaces/photography.h> diff --git a/src/plugins/gstreamer/gstreamer.pro b/src/plugins/gstreamer/gstreamer.pro index baec7175c..28becfb5b 100644 --- a/src/plugins/gstreamer/gstreamer.pro +++ b/src/plugins/gstreamer/gstreamer.pro @@ -8,6 +8,8 @@ PLUGIN_TYPE=mediaservice load(qt_plugin) DESTDIR = $$QT.multimedia.plugins/$${PLUGIN_TYPE} +LIBS += -lqgsttools_p + unix:!maemo*:contains(QT_CONFIG, alsa) { DEFINES += HAVE_ALSA LIBS += \ @@ -48,33 +50,22 @@ maemo6 { # Input HEADERS += \ - qgstreamermessage.h \ - qgstreamerbushelper.h \ qgstreamervideorendererinterface.h \ qgstreamerserviceplugin.h \ qgstreameraudioinputendpointselector.h \ qgstreamervideorenderer.h \ - qgstvideobuffer.h \ - qvideosurfacegstsink.h \ qgstreamervideoinputdevicecontrol.h \ gstvideoconnector.h \ - qabstractgstbufferpool.h \ qgstcodecsinfo.h \ - qgstutils.h SOURCES += \ - qgstreamermessage.cpp \ - qgstreamerbushelper.cpp \ qgstreamervideorendererinterface.cpp \ qgstreamerserviceplugin.cpp \ qgstreameraudioinputendpointselector.cpp \ qgstreamervideorenderer.cpp \ - qgstvideobuffer.cpp \ - qvideosurfacegstsink.cpp \ qgstreamervideoinputdevicecontrol.cpp \ qgstcodecsinfo.cpp \ gstvideoconnector.c \ - qgstutils.cpp !win32:!contains(QT_CONFIG,embedded):!mac:!simulator:!contains(QT_CONFIG, qpa) { @@ -85,14 +76,12 @@ SOURCES += \ qgstreamervideowindow.h \ qgstreamervideowidget.h \ qx11videosurface.h \ - qgstxvimagebuffer.h SOURCES += \ qgstreamervideooverlay.cpp \ qgstreamervideowindow.cpp \ qgstreamervideowidget.cpp \ qx11videosurface.cpp \ - qgstxvimagebuffer.cpp } include(mediaplayer/mediaplayer.pri) include(mediacapture/mediacapture.pri) diff --git a/src/plugins/gstreamer/mediacapture/qgstreamercaptureservice.cpp b/src/plugins/gstreamer/mediacapture/qgstreamercaptureservice.cpp index d063b0e13..ee64b2cc1 100644 --- a/src/plugins/gstreamer/mediacapture/qgstreamercaptureservice.cpp +++ b/src/plugins/gstreamer/mediacapture/qgstreamercaptureservice.cpp @@ -46,8 +46,8 @@ #include "qgstreameraudioencode.h" #include "qgstreamervideoencode.h" #include "qgstreamerimageencode.h" -#include "qgstreamerbushelper.h" #include "qgstreamercameracontrol.h" +#include <private/qgstreamerbushelper_p.h> #include "qgstreamerv4l2input.h" #include "qgstreamercapturemetadatacontrol.h" diff --git a/src/plugins/gstreamer/mediacapture/qgstreamercapturesession.cpp b/src/plugins/gstreamer/mediacapture/qgstreamercapturesession.cpp index b685f5466..8d87bb387 100644 --- a/src/plugins/gstreamer/mediacapture/qgstreamercapturesession.cpp +++ b/src/plugins/gstreamer/mediacapture/qgstreamercapturesession.cpp @@ -46,8 +46,8 @@ #include "qgstreameraudioencode.h" #include "qgstreamervideoencode.h" #include "qgstreamerimageencode.h" -#include "qgstreamerbushelper.h" #include <qmediarecorder.h> +#include <private/qgstreamerbushelper_p.h> #include <gst/gsttagsetter.h> #include <gst/gstversion.h> diff --git a/src/plugins/gstreamer/mediacapture/qgstreamercapturesession.h b/src/plugins/gstreamer/mediacapture/qgstreamercapturesession.h index e4c734600..aa5a09cdc 100644 --- a/src/plugins/gstreamer/mediacapture/qgstreamercapturesession.h +++ b/src/plugins/gstreamer/mediacapture/qgstreamercapturesession.h @@ -49,7 +49,7 @@ #include <gst/gst.h> -#include "qgstreamerbushelper.h" +#include <private/qgstreamerbushelper_p.h> QT_USE_NAMESPACE diff --git a/src/plugins/gstreamer/mediaplayer/qgstreamerplayersession.cpp b/src/plugins/gstreamer/mediaplayer/qgstreamerplayersession.cpp index 7aef9065e..49aa3fb8f 100644 --- a/src/plugins/gstreamer/mediaplayer/qgstreamerplayersession.cpp +++ b/src/plugins/gstreamer/mediaplayer/qgstreamerplayersession.cpp @@ -40,11 +40,11 @@ ****************************************************************************/ #include "qgstreamerplayersession.h" -#include "qgstreamerbushelper.h" +#include <private/qgstreamerbushelper_p.h> #include "qgstreamervideorendererinterface.h" #include "gstvideoconnector.h" -#include "qgstutils.h" +#include <private/qgstutils_p.h> #include <gst/gstvalue.h> #include <gst/base/gstbasesrc.h> diff --git a/src/plugins/gstreamer/mediaplayer/qgstreamerplayersession.h b/src/plugins/gstreamer/mediaplayer/qgstreamerplayersession.h index 208f0b5de..3380e6e7b 100644 --- a/src/plugins/gstreamer/mediaplayer/qgstreamerplayersession.h +++ b/src/plugins/gstreamer/mediaplayer/qgstreamerplayersession.h @@ -45,7 +45,7 @@ #include <QObject> #include <QtNetwork/qnetworkrequest.h> #include "qgstreamerplayercontrol.h" -#include "qgstreamerbushelper.h" +#include <private/qgstreamerbushelper_p.h> #include <qmediaplayer.h> #include <qmediastreamscontrol.h> diff --git a/src/plugins/gstreamer/qabstractgstbufferpool.h b/src/plugins/gstreamer/qabstractgstbufferpool.h deleted file mode 100644 index 5ab6b8866..000000000 --- a/src/plugins/gstreamer/qabstractgstbufferpool.h +++ /dev/null @@ -1,75 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** 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$ -** -****************************************************************************/ - -#ifndef QGSTBUFFERPOOL_H -#define QGSTBUFFERPOOL_H - -#include <qabstractvideobuffer.h> -#include <qvideosurfaceformat.h> - -#include <gst/gst.h> - -/*! - Abstract interface for video buffers allocation. -*/ -class QAbstractGstBufferPool -{ -public: - virtual ~QAbstractGstBufferPool() {} - - virtual bool isFormatSupported(const QVideoSurfaceFormat &format) const = 0; - - virtual GType bufferType() const = 0; - virtual GstBuffer *takeBuffer(const QVideoSurfaceFormat &format, GstCaps *caps) = 0; - virtual void clear() = 0; - - virtual QAbstractVideoBuffer::HandleType handleType() const = 0; - - /*! - Build an QAbstractVideoBuffer instance from compatible (mathcing gst buffer type) - GstBuffer. - - This method is called from gstreamer video sink thread. - */ - virtual QAbstractVideoBuffer *prepareVideoBuffer(GstBuffer *buffer, int bytesPerLine) = 0; -}; - -#endif diff --git a/src/plugins/gstreamer/qgstreamerbushelper.cpp b/src/plugins/gstreamer/qgstreamerbushelper.cpp deleted file mode 100644 index 92f2ee8b7..000000000 --- a/src/plugins/gstreamer/qgstreamerbushelper.cpp +++ /dev/null @@ -1,237 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** 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$ -** -****************************************************************************/ - -#include <QtCore/qmap.h> -#include <QtCore/qtimer.h> -#include <QtCore/qmutex.h> -#include <QtCore/qlist.h> - -#include "qgstreamerbushelper.h" - - -#ifndef QT_NO_GLIB -class QGstreamerBusHelperPrivate : public QObject -{ - Q_OBJECT - -public: - void addWatch(GstBus* bus, QGstreamerBusHelper* helper) - { - setParent(helper); - m_tag = gst_bus_add_watch_full(bus, 0, busCallback, this, NULL); - m_helper = helper; - } - - void removeWatch(QGstreamerBusHelper* helper) - { - Q_UNUSED(helper); - g_source_remove(m_tag); - } - - static QGstreamerBusHelperPrivate* instance() - { - return new QGstreamerBusHelperPrivate; - } - -private: - void processMessage(GstBus* bus, GstMessage* message) - { - Q_UNUSED(bus); - QGstreamerMessage msg(message); - foreach (QGstreamerBusMessageFilter *filter, busFilters) { - if (filter->processBusMessage(msg)) - break; - } - emit m_helper->message(msg); - } - - static gboolean busCallback(GstBus *bus, GstMessage *message, gpointer data) - { - reinterpret_cast<QGstreamerBusHelperPrivate*>(data)->processMessage(bus, message); - return TRUE; - } - - guint m_tag; - QGstreamerBusHelper* m_helper; - -public: - GstBus* bus; - QMutex filterMutex; - QList<QGstreamerSyncMessageFilter*> syncFilters; - QList<QGstreamerBusMessageFilter*> busFilters; -}; - -#else - -class QGstreamerBusHelperPrivate : public QObject -{ - Q_OBJECT - typedef QMap<QGstreamerBusHelper*, GstBus*> HelperMap; - -public: - void addWatch(GstBus* bus, QGstreamerBusHelper* helper) - { - m_helperMap.insert(helper, bus); - - if (m_helperMap.size() == 1) - m_intervalTimer->start(); - } - - void removeWatch(QGstreamerBusHelper* helper) - { - m_helperMap.remove(helper); - - if (m_helperMap.size() == 0) - m_intervalTimer->stop(); - } - - static QGstreamerBusHelperPrivate* instance() - { - static QGstreamerBusHelperPrivate self; - - return &self; - } - -private slots: - void interval() - { - for (HelperMap::iterator it = m_helperMap.begin(); it != m_helperMap.end(); ++it) { - GstMessage* message; - - while ((message = gst_bus_poll(it.value(), GST_MESSAGE_ANY, 0)) != 0) { - QGstreamerMessage msg(message); - foreach (QGstreamerBusMessageFilter *filter, busFilters) { - if (filter->processBusMessage(msg)) - break; - } - emit it.key()->message(msg); - - gst_message_unref(message); - } - - emit it.key()->message(QGstreamerMessage()); - } - } - -private: - QGstreamerBusHelperPrivate() - { - m_intervalTimer = new QTimer(this); - m_intervalTimer->setInterval(250); - - connect(m_intervalTimer, SIGNAL(timeout()), SLOT(interval())); - } - - HelperMap m_helperMap; - QTimer* m_intervalTimer; - -public: - GstBus* bus; - QMutex filterMutex; - QList<QGstreamerSyncMessageFilter*> syncFilters; - QList<QGstreamerBusMessageFilter*> busFilters; -}; -#endif - - -static GstBusSyncReply syncGstBusFilter(GstBus* bus, GstMessage* message, QGstreamerBusHelperPrivate *d) -{ - Q_UNUSED(bus); - QMutexLocker lock(&d->filterMutex); - - foreach (QGstreamerSyncMessageFilter *filter, d->syncFilters) { - if (filter->processSyncMessage(QGstreamerMessage(message))) - return GST_BUS_DROP; - } - - return GST_BUS_PASS; -} - - -/*! - \class gstreamer::QGstreamerBusHelper - \internal -*/ - -QGstreamerBusHelper::QGstreamerBusHelper(GstBus* bus, QObject* parent): - QObject(parent), - d(QGstreamerBusHelperPrivate::instance()) -{ - d->bus = bus; - d->addWatch(bus, this); - - gst_bus_set_sync_handler(bus, (GstBusSyncHandler)syncGstBusFilter, d); -} - -QGstreamerBusHelper::~QGstreamerBusHelper() -{ - d->removeWatch(this); - gst_bus_set_sync_handler(d->bus,0,0); -} - -void QGstreamerBusHelper::installMessageFilter(QObject *filter) -{ - QGstreamerSyncMessageFilter *syncFilter = qobject_cast<QGstreamerSyncMessageFilter*>(filter); - if (syncFilter) { - QMutexLocker lock(&d->filterMutex); - if (!d->syncFilters.contains(syncFilter)) - d->syncFilters.append(syncFilter); - } - - QGstreamerBusMessageFilter *busFilter = qobject_cast<QGstreamerBusMessageFilter*>(filter); - if (busFilter && !d->busFilters.contains(busFilter)) - d->busFilters.append(busFilter); -} - -void QGstreamerBusHelper::removeMessageFilter(QObject *filter) -{ - QGstreamerSyncMessageFilter *syncFilter = qobject_cast<QGstreamerSyncMessageFilter*>(filter); - if (syncFilter) { - QMutexLocker lock(&d->filterMutex); - d->syncFilters.removeAll(syncFilter); - } - - QGstreamerBusMessageFilter *busFilter = qobject_cast<QGstreamerBusMessageFilter*>(filter); - if (busFilter) - d->busFilters.removeAll(busFilter); -} - -#include "qgstreamerbushelper.moc" diff --git a/src/plugins/gstreamer/qgstreamerbushelper.h b/src/plugins/gstreamer/qgstreamerbushelper.h deleted file mode 100644 index d09192a42..000000000 --- a/src/plugins/gstreamer/qgstreamerbushelper.h +++ /dev/null @@ -1,89 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** 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$ -** -****************************************************************************/ - -#ifndef QGSTREAMERBUSHELPER_H -#define QGSTREAMERBUSHELPER_H - -#include <QObject> - -#include <qgstreamermessage.h> -#include <gst/gst.h> - -class QGstreamerSyncMessageFilter { -public: - //returns true if message was processed and should be dropped, false otherwise - virtual bool processSyncMessage(const QGstreamerMessage &message) = 0; -}; -#define QGstreamerSyncMessageFilter_iid "com.nokia.Qt.QGstreamerSyncMessageFilter/1.0" -Q_DECLARE_INTERFACE(QGstreamerSyncMessageFilter, QGstreamerSyncMessageFilter_iid) - - -class QGstreamerBusMessageFilter { -public: - //returns true if message was processed and should be dropped, false otherwise - virtual bool processBusMessage(const QGstreamerMessage &message) = 0; -}; -#define QGstreamerBusMessageFilter_iid "com.nokia.Qt.QGstreamerBusMessageFilter/1.0" -Q_DECLARE_INTERFACE(QGstreamerBusMessageFilter, QGstreamerBusMessageFilter_iid) - - -class QGstreamerBusHelperPrivate; - -class QGstreamerBusHelper : public QObject -{ - Q_OBJECT - friend class QGstreamerBusHelperPrivate; - -public: - QGstreamerBusHelper(GstBus* bus, QObject* parent = 0); - ~QGstreamerBusHelper(); - - void installMessageFilter(QObject *filter); - void removeMessageFilter(QObject *filter); - -signals: - void message(QGstreamerMessage const& message); - -private: - QGstreamerBusHelperPrivate* d; -}; - -#endif diff --git a/src/plugins/gstreamer/qgstreamergltexturerenderer.cpp b/src/plugins/gstreamer/qgstreamergltexturerenderer.cpp index 615d23d82..d9633aa79 100644 --- a/src/plugins/gstreamer/qgstreamergltexturerenderer.cpp +++ b/src/plugins/gstreamer/qgstreamergltexturerenderer.cpp @@ -39,9 +39,9 @@ ** ****************************************************************************/ -#include "qvideosurfacegstsink.h" -#include "qabstractvideosurface.h" -#include "qgstutils.h" +#include <private/qvideosurfacegstsink_p.h> +#include <qabstractvideosurface.h> +#include <private/qgstutils_p.h> #include <QtGui/qevent.h> #include <QtWidgets/qapplication.h> diff --git a/src/plugins/gstreamer/qgstreamergltexturerenderer.h b/src/plugins/gstreamer/qgstreamergltexturerenderer.h index 7a1bc65df..244e07fd3 100644 --- a/src/plugins/gstreamer/qgstreamergltexturerenderer.h +++ b/src/plugins/gstreamer/qgstreamergltexturerenderer.h @@ -43,8 +43,8 @@ #define QGSTREAMERGLTEXTURERENDERER_H #include <qvideorenderercontrol.h> -#include "qvideosurfacegstsink.h" -#include "qgstreamerbushelper.h" +#include <private/qvideosurfacegstsink_p.h> +#include <private/qgstreamerbushelper_p.h> #include "qgstreamervideorendererinterface.h" #include <QtGui/qcolor.h> diff --git a/src/plugins/gstreamer/qgstreamermessage.cpp b/src/plugins/gstreamer/qgstreamermessage.cpp deleted file mode 100644 index d7c09780f..000000000 --- a/src/plugins/gstreamer/qgstreamermessage.cpp +++ /dev/null @@ -1,93 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** 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$ -** -****************************************************************************/ - -#include <gst/gst.h> - -#include "qgstreamermessage.h" - - -static int wuchi = qRegisterMetaType<QGstreamerMessage>(); - - -/*! - \class gstreamer::QGstreamerMessage - \internal -*/ - -QGstreamerMessage::QGstreamerMessage(): - m_message(0) -{ -} - -QGstreamerMessage::QGstreamerMessage(GstMessage* message): - m_message(message) -{ - gst_message_ref(m_message); -} - -QGstreamerMessage::QGstreamerMessage(QGstreamerMessage const& m): - m_message(m.m_message) -{ - gst_message_ref(m_message); -} - - -QGstreamerMessage::~QGstreamerMessage() -{ - if (m_message != 0) - gst_message_unref(m_message); -} - -GstMessage* QGstreamerMessage::rawMessage() const -{ - return m_message; -} - -QGstreamerMessage& QGstreamerMessage::operator=(QGstreamerMessage const& rhs) -{ - if (m_message != 0) - gst_message_unref(m_message); - - if ((m_message = rhs.m_message) != 0) - gst_message_ref(m_message); - - return *this; -} diff --git a/src/plugins/gstreamer/qgstreamermessage.h b/src/plugins/gstreamer/qgstreamermessage.h deleted file mode 100644 index 478774e69..000000000 --- a/src/plugins/gstreamer/qgstreamermessage.h +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** 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$ -** -****************************************************************************/ - -#ifndef QGSTREAMERMESSAGE_H -#define QGSTREAMERMESSAGE_H - -#include <QMetaType> - -#include <gst/gst.h> - - -class QGstreamerMessage -{ -public: - QGstreamerMessage(); - QGstreamerMessage(GstMessage* message); - QGstreamerMessage(QGstreamerMessage const& m); - ~QGstreamerMessage(); - - GstMessage* rawMessage() const; - - QGstreamerMessage& operator=(QGstreamerMessage const& rhs); - -private: - GstMessage* m_message; -}; - -Q_DECLARE_METATYPE(QGstreamerMessage); - -#endif diff --git a/src/plugins/gstreamer/qgstreamervideooverlay.cpp b/src/plugins/gstreamer/qgstreamervideooverlay.cpp index 851ef2b87..f19ef6a83 100644 --- a/src/plugins/gstreamer/qgstreamervideooverlay.cpp +++ b/src/plugins/gstreamer/qgstreamervideooverlay.cpp @@ -40,11 +40,11 @@ ****************************************************************************/ #include "qgstreamervideooverlay.h" -#include "qvideosurfacegstsink.h" +#include <private/qvideosurfacegstsink_p.h> #include <qvideosurfaceformat.h> -#include "qx11videosurface.h" +#include <private/qx11videosurface_p.h> #ifndef QT_NO_XVIDEO diff --git a/src/plugins/gstreamer/qgstreamervideorenderer.cpp b/src/plugins/gstreamer/qgstreamervideorenderer.cpp index e924f8353..ead0bdcc0 100644 --- a/src/plugins/gstreamer/qgstreamervideorenderer.cpp +++ b/src/plugins/gstreamer/qgstreamervideorenderer.cpp @@ -40,8 +40,8 @@ ****************************************************************************/ #include "qgstreamervideorenderer.h" -#include "qvideosurfacegstsink.h" -#include "qabstractvideosurface.h" +#include <private/qvideosurfacegstsink_p.h> +#include <qabstractvideosurface.h> #include <QEvent> #include <QtWidgets/QApplication> diff --git a/src/plugins/gstreamer/qgstreamervideorenderer.h b/src/plugins/gstreamer/qgstreamervideorenderer.h index 4fb8dda35..fbd76f6c6 100644 --- a/src/plugins/gstreamer/qgstreamervideorenderer.h +++ b/src/plugins/gstreamer/qgstreamervideorenderer.h @@ -43,7 +43,7 @@ #define QGSTREAMERVIDEORENDERER_H #include <qvideorenderercontrol.h> -#include "qvideosurfacegstsink.h" +#include <private/qvideosurfacegstsink_p.h> #include "qgstreamervideorendererinterface.h" diff --git a/src/plugins/gstreamer/qgstreamervideowidget.cpp b/src/plugins/gstreamer/qgstreamervideowidget.cpp index 61c47f01b..a0fdab726 100644 --- a/src/plugins/gstreamer/qgstreamervideowidget.cpp +++ b/src/plugins/gstreamer/qgstreamervideowidget.cpp @@ -40,7 +40,7 @@ ****************************************************************************/ #include "qgstreamervideowidget.h" -#include "qgstutils.h" +#include <private/qgstutils_p.h> #include <QtCore/qcoreevent.h> #include <QtCore/qdebug.h> diff --git a/src/plugins/gstreamer/qgstreamervideowidget.h b/src/plugins/gstreamer/qgstreamervideowidget.h index 8f3d62316..53069faec 100644 --- a/src/plugins/gstreamer/qgstreamervideowidget.h +++ b/src/plugins/gstreamer/qgstreamervideowidget.h @@ -45,7 +45,7 @@ #include <qvideowidgetcontrol.h> #include "qgstreamervideorendererinterface.h" -#include "qgstreamerbushelper.h" +#include <private/qgstreamerbushelper_p.h> QT_USE_NAMESPACE diff --git a/src/plugins/gstreamer/qgstreamervideowindow.cpp b/src/plugins/gstreamer/qgstreamervideowindow.cpp index d8d822269..1c475bd55 100644 --- a/src/plugins/gstreamer/qgstreamervideowindow.cpp +++ b/src/plugins/gstreamer/qgstreamervideowindow.cpp @@ -40,7 +40,7 @@ ****************************************************************************/ #include "qgstreamervideowindow.h" -#include "qgstutils.h" +#include <private/qgstutils_p.h> #include <QtCore/qdebug.h> diff --git a/src/plugins/gstreamer/qgstreamervideowindow.h b/src/plugins/gstreamer/qgstreamervideowindow.h index 3a483e2c1..2182148a0 100644 --- a/src/plugins/gstreamer/qgstreamervideowindow.h +++ b/src/plugins/gstreamer/qgstreamervideowindow.h @@ -45,7 +45,7 @@ #include <qvideowindowcontrol.h> #include "qgstreamervideorendererinterface.h" -#include "qgstreamerbushelper.h" +#include <private/qgstreamerbushelper_p.h> QT_BEGIN_NAMESPACE class QAbstractVideoSurface; diff --git a/src/plugins/gstreamer/qgstutils.cpp b/src/plugins/gstreamer/qgstutils.cpp deleted file mode 100644 index 6f0194f24..000000000 --- a/src/plugins/gstreamer/qgstutils.cpp +++ /dev/null @@ -1,165 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** 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$ -** -****************************************************************************/ - -#include "qgstutils.h" - -#include <QtCore/qdatetime.h> -#include <QtCore/qbytearray.h> -#include <QtCore/qvariant.h> -#include <QtCore/qsize.h> - -//internal -static void addTagToMap(const GstTagList *list, - const gchar *tag, - gpointer user_data) -{ - QMap<QByteArray, QVariant> *map = reinterpret_cast<QMap<QByteArray, QVariant>* >(user_data); - - GValue val; - val.g_type = 0; - gst_tag_list_copy_value(&val,list,tag); - - switch( G_VALUE_TYPE(&val) ) { - case G_TYPE_STRING: - { - const gchar *str_value = g_value_get_string(&val); - map->insert(QByteArray(tag), QString::fromUtf8(str_value)); - break; - } - case G_TYPE_INT: - map->insert(QByteArray(tag), g_value_get_int(&val)); - break; - case G_TYPE_UINT: - map->insert(QByteArray(tag), g_value_get_uint(&val)); - break; - case G_TYPE_LONG: - map->insert(QByteArray(tag), qint64(g_value_get_long(&val))); - break; - case G_TYPE_BOOLEAN: - map->insert(QByteArray(tag), g_value_get_boolean(&val)); - break; - case G_TYPE_CHAR: - map->insert(QByteArray(tag), g_value_get_char(&val)); - break; - case G_TYPE_DOUBLE: - map->insert(QByteArray(tag), g_value_get_double(&val)); - break; - default: - // GST_TYPE_DATE is a function, not a constant, so pull it out of the switch - if (G_VALUE_TYPE(&val) == GST_TYPE_DATE) { - const GDate *date = gst_value_get_date(&val); - if (g_date_valid(date)) { - int year = g_date_get_year(date); - int month = g_date_get_month(date); - int day = g_date_get_day(date); - map->insert(QByteArray(tag), QDate(year,month,day)); - if (!map->contains("year")) - map->insert("year", year); - } - } else if (G_VALUE_TYPE(&val) == GST_TYPE_FRACTION) { - int nom = gst_value_get_fraction_numerator(&val); - int denom = gst_value_get_fraction_denominator(&val); - - if (denom > 0) { - map->insert(QByteArray(tag), double(nom)/denom); - } - } - break; - } - - g_value_unset(&val); -} - -/*! - Convert GstTagList structure to QMap<QByteArray, QVariant>. - - Mapping to int, bool, char, string, fractions and date are supported. - Fraction values are converted to doubles. -*/ -QMap<QByteArray, QVariant> QGstUtils::gstTagListToMap(const GstTagList *tags) -{ - QMap<QByteArray, QVariant> res; - gst_tag_list_foreach(tags, addTagToMap, &res); - - return res; -} - -/*! - Returns resolution of \a caps. - If caps doesn't have a valid size, and ampty QSize is returned. -*/ -QSize QGstUtils::capsResolution(const GstCaps *caps) -{ - QSize size; - - if (caps) { - const GstStructure *structure = gst_caps_get_structure(caps, 0); - gst_structure_get_int(structure, "width", &size.rwidth()); - gst_structure_get_int(structure, "height", &size.rheight()); - } - - return size; -} - -/*! - Returns aspect ratio corrected resolution of \a caps. - If caps doesn't have a valid size, and ampty QSize is returned. -*/ -QSize QGstUtils::capsCorrectedResolution(const GstCaps *caps) -{ - QSize size; - - if (caps) { - const GstStructure *structure = gst_caps_get_structure(caps, 0); - gst_structure_get_int(structure, "width", &size.rwidth()); - gst_structure_get_int(structure, "height", &size.rheight()); - - gint aspectNum = 0; - gint aspectDenum = 0; - if (!size.isEmpty() && gst_structure_get_fraction( - structure, "pixel-aspect-ratio", &aspectNum, &aspectDenum)) { - if (aspectDenum > 0) - size.setWidth(size.width()*aspectNum/aspectDenum); - } - } - - return size; -} diff --git a/src/plugins/gstreamer/qgstutils.h b/src/plugins/gstreamer/qgstutils.h deleted file mode 100644 index a6f2dabb7..000000000 --- a/src/plugins/gstreamer/qgstutils.h +++ /dev/null @@ -1,59 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** 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$ -** -****************************************************************************/ - -#ifndef QGSTUTILS_H -#define QGSTUTILS_H - -#include <QtCore/qmap.h> -#include <gst/gst.h> - -class QSize; -class QVariant; -class QByteArray; - -namespace QGstUtils { - QMap<QByteArray, QVariant> gstTagListToMap(const GstTagList *list); - - QSize capsResolution(const GstCaps *caps); - QSize capsCorrectedResolution(const GstCaps *caps); -} - -#endif diff --git a/src/plugins/gstreamer/qgstvideobuffer.cpp b/src/plugins/gstreamer/qgstvideobuffer.cpp deleted file mode 100644 index bc12ee9c8..000000000 --- a/src/plugins/gstreamer/qgstvideobuffer.cpp +++ /dev/null @@ -1,97 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** 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$ -** -****************************************************************************/ - -#include "qgstvideobuffer.h" - - -QGstVideoBuffer::QGstVideoBuffer(GstBuffer *buffer, int bytesPerLine) - : QAbstractVideoBuffer(NoHandle) - , m_buffer(buffer) - , m_bytesPerLine(bytesPerLine) - , m_mode(NotMapped) -{ - gst_buffer_ref(m_buffer); -} - -QGstVideoBuffer::QGstVideoBuffer(GstBuffer *buffer, int bytesPerLine, - QGstVideoBuffer::HandleType handleType, - const QVariant &handle) - : QAbstractVideoBuffer(handleType) - , m_buffer(buffer) - , m_bytesPerLine(bytesPerLine) - , m_mode(NotMapped) - , m_handle(handle) -{ - gst_buffer_ref(m_buffer); -} - -QGstVideoBuffer::~QGstVideoBuffer() -{ - gst_buffer_unref(m_buffer); -} - - -QAbstractVideoBuffer::MapMode QGstVideoBuffer::mapMode() const -{ - return m_mode; -} - -uchar *QGstVideoBuffer::map(MapMode mode, int *numBytes, int *bytesPerLine) -{ - if (mode != NotMapped && m_mode == NotMapped) { - if (numBytes) - *numBytes = m_buffer->size; - - if (bytesPerLine) - *bytesPerLine = m_bytesPerLine; - - m_mode = mode; - - return m_buffer->data; - } else { - return 0; - } -} -void QGstVideoBuffer::unmap() -{ - m_mode = NotMapped; -} - diff --git a/src/plugins/gstreamer/qgstvideobuffer.h b/src/plugins/gstreamer/qgstvideobuffer.h deleted file mode 100644 index 8884005a0..000000000 --- a/src/plugins/gstreamer/qgstvideobuffer.h +++ /dev/null @@ -1,72 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** 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$ -** -****************************************************************************/ - -#ifndef QGSTVIDEOBUFFER_H -#define QGSTVIDEOBUFFER_H - -#include <qabstractvideobuffer.h> -#include <QtCore/qvariant.h> - -#include <gst/gst.h> - -class QGstVideoBuffer : public QAbstractVideoBuffer -{ -public: - QGstVideoBuffer(GstBuffer *buffer, int bytesPerLine); - QGstVideoBuffer(GstBuffer *buffer, int bytesPerLine, - HandleType handleType, const QVariant &handle); - ~QGstVideoBuffer(); - - MapMode mapMode() const; - - uchar *map(MapMode mode, int *numBytes, int *bytesPerLine); - void unmap(); - - QVariant handle() const { return m_handle; } -private: - GstBuffer *m_buffer; - int m_bytesPerLine; - MapMode m_mode; - QVariant m_handle; -}; - - -#endif diff --git a/src/plugins/gstreamer/qgstxvimagebuffer.cpp b/src/plugins/gstreamer/qgstxvimagebuffer.cpp deleted file mode 100644 index 31839920b..000000000 --- a/src/plugins/gstreamer/qgstxvimagebuffer.cpp +++ /dev/null @@ -1,311 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** 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$ -** -****************************************************************************/ - -#include <QtCore/qdebug.h> -#include <QtCore/qthread.h> -#include <QtCore/qvariant.h> -#include <QtWidgets/qx11info_x11.h> - -#include "qgstxvimagebuffer.h" -#include "qvideosurfacegstsink.h" -#include "qgstvideobuffer.h" - -#ifndef QT_NO_XVIDEO - -GstBufferClass *QGstXvImageBuffer::parent_class = NULL; - -GType QGstXvImageBuffer::get_type(void) -{ - static GType buffer_type = 0; - - if (buffer_type == 0) { - static const GTypeInfo buffer_info = { - sizeof (GstBufferClass), - NULL, - NULL, - QGstXvImageBuffer::class_init, - NULL, - NULL, - sizeof(QGstXvImageBuffer), - 0, - (GInstanceInitFunc)QGstXvImageBuffer::buffer_init, - NULL - }; - buffer_type = g_type_register_static(GST_TYPE_BUFFER, - "QGstXvImageBuffer", &buffer_info, GTypeFlags(0)); - } - return buffer_type; -} - -void QGstXvImageBuffer::class_init(gpointer g_class, gpointer class_data) -{ - Q_UNUSED(class_data); - GST_MINI_OBJECT_CLASS(g_class)->finalize = - (GstMiniObjectFinalizeFunction)buffer_finalize; - parent_class = (GstBufferClass*)g_type_class_peek_parent(g_class); -} - -void QGstXvImageBuffer::buffer_init(QGstXvImageBuffer *xvImage, gpointer g_class) -{ - Q_UNUSED(g_class); - xvImage->pool = 0; - xvImage->shmInfo.shmaddr = ((char *) -1); - xvImage->shmInfo.shmid = -1; - xvImage->markedForDeletion = false; -} - -void QGstXvImageBuffer::buffer_finalize(QGstXvImageBuffer * xvImage) -{ - if (xvImage->pool) { - if (xvImage->markedForDeletion) - xvImage->pool->destroyBuffer(xvImage); - else - xvImage->pool->recycleBuffer(xvImage); - } -} - - -QGstXvImageBufferPool::QGstXvImageBufferPool(QObject *parent) - :QObject(parent) -{ - m_threadId = QThread::currentThreadId(); -} - -QGstXvImageBufferPool::~QGstXvImageBufferPool() -{ -} - -bool QGstXvImageBufferPool::isFormatSupported(const QVideoSurfaceFormat &surfaceFormat) const -{ - bool ok = true; - surfaceFormat.property("portId").toULongLong(&ok); - if (!ok) - return false; - - int xvFormatId = surfaceFormat.property("xvFormatId").toInt(&ok); - if (!ok || xvFormatId < 0) - return false; - - int dataSize = surfaceFormat.property("dataSize").toInt(&ok); - if (!ok || dataSize<=0) - return false; - - return true; -} - -GType QGstXvImageBufferPool::bufferType() const -{ - return QGstXvImageBuffer::get_type(); -} - -GstBuffer *QGstXvImageBufferPool::takeBuffer( - const QVideoSurfaceFormat &format, GstCaps *caps) -{ - m_poolMutex.lock(); - - m_caps = caps; - if (format != m_format) { - doClear(); - m_format = format; - } - - - if (m_pool.isEmpty()) { - //qDebug() << "QGstXvImageBufferPool::takeBuffer: no buffer available, allocate the new one" << QThread::currentThreadId() << m_threadId; - if (QThread::currentThreadId() == m_threadId) { - doAlloc(); - } else { - QMetaObject::invokeMethod(this, "queuedAlloc", Qt::QueuedConnection); - m_allocWaitCondition.wait(&m_poolMutex, 300); - } - } - QGstXvImageBuffer *res = 0; - - if (!m_pool.isEmpty()) { - res = m_pool.takeLast(); - } - - m_poolMutex.unlock(); - - return GST_BUFFER(res); -} - -QAbstractVideoBuffer::HandleType QGstXvImageBufferPool::handleType() const -{ - return QAbstractVideoBuffer::XvShmImageHandle; -} - -QAbstractVideoBuffer *QGstXvImageBufferPool::prepareVideoBuffer(GstBuffer *buffer, int bytesPerLine) -{ - QGstXvImageBuffer *xvBuffer = reinterpret_cast<QGstXvImageBuffer *>(buffer); - QVariant handle = QVariant::fromValue(xvBuffer->xvImage); - return new QGstVideoBuffer(buffer, bytesPerLine, QAbstractVideoBuffer::XvShmImageHandle, handle); -} - -void QGstXvImageBufferPool::queuedAlloc() -{ - QMutexLocker lock(&m_poolMutex); - doAlloc(); - m_allocWaitCondition.wakeOne(); -} - -void QGstXvImageBufferPool::doAlloc() -{ - //should be always called from the main thread with m_poolMutex locked - //Q_ASSERT(QThread::currentThread() == thread()); - - XSync(QX11Info::display(), false); - - QGstXvImageBuffer *xvBuffer = (QGstXvImageBuffer *)gst_mini_object_new(QGstXvImageBuffer::get_type()); - - quint64 portId = m_format.property("portId").toULongLong(); - int xvFormatId = m_format.property("xvFormatId").toInt(); - - xvBuffer->xvImage = XvShmCreateImage( - QX11Info::display(), - portId, - xvFormatId, - 0, - m_format.frameWidth(), - m_format.frameHeight(), - &xvBuffer->shmInfo - ); - - if (!xvBuffer->xvImage) { - qWarning() << "QGstXvImageBufferPool: XvShmCreateImage failed"; - return; - } - - XSync(QX11Info::display(), false); - - xvBuffer->shmInfo.shmid = shmget(IPC_PRIVATE, xvBuffer->xvImage->data_size, IPC_CREAT | 0777); - xvBuffer->shmInfo.shmaddr = xvBuffer->xvImage->data = (char*)shmat(xvBuffer->shmInfo.shmid, 0, 0); - xvBuffer->shmInfo.readOnly = False; - - if (!XShmAttach(QX11Info::display(), &xvBuffer->shmInfo)) { - qWarning() << "QGstXvImageBufferPool: XShmAttach failed"; - return; - } - - XSync(QX11Info::display(), false); - - shmctl (xvBuffer->shmInfo.shmid, IPC_RMID, NULL); - - xvBuffer->pool = this; - GST_MINI_OBJECT_CAST(xvBuffer)->flags = 0; - gst_buffer_set_caps(GST_BUFFER_CAST(xvBuffer), m_caps); - GST_BUFFER_DATA(xvBuffer) = (uchar*)xvBuffer->xvImage->data; - GST_BUFFER_SIZE(xvBuffer) = xvBuffer->xvImage->data_size; - - m_allBuffers.append(xvBuffer); - m_pool.append(xvBuffer); - - XSync(QX11Info::display(), false); -} - - -void QGstXvImageBufferPool::clear() -{ - QMutexLocker lock(&m_poolMutex); - doClear(); -} - -void QGstXvImageBufferPool::doClear() -{ - foreach (QGstXvImageBuffer *xvBuffer, m_allBuffers) { - xvBuffer->markedForDeletion = true; - } - m_allBuffers.clear(); - - foreach (QGstXvImageBuffer *xvBuffer, m_pool) { - gst_buffer_unref(GST_BUFFER(xvBuffer)); - } - m_pool.clear(); - - m_format = QVideoSurfaceFormat(); -} - -void QGstXvImageBufferPool::queuedDestroy() -{ - QMutexLocker lock(&m_destroyMutex); - - XSync(QX11Info::display(), false); - - foreach(XvShmImage xvImage, m_imagesToDestroy) { - if (xvImage.shmInfo.shmaddr != ((void *) -1)) { - XShmDetach(QX11Info::display(), &xvImage.shmInfo); - XSync(QX11Info::display(), false); - - shmdt(xvImage.shmInfo.shmaddr); - } - - if (xvImage.xvImage) - XFree(xvImage.xvImage); - } - - m_imagesToDestroy.clear(); - - XSync(QX11Info::display(), false); -} - -void QGstXvImageBufferPool::recycleBuffer(QGstXvImageBuffer *xvBuffer) -{ - QMutexLocker lock(&m_poolMutex); - gst_buffer_ref(GST_BUFFER_CAST(xvBuffer)); - m_pool.append(xvBuffer); -} - -void QGstXvImageBufferPool::destroyBuffer(QGstXvImageBuffer *xvBuffer) -{ - XvShmImage imageToDestroy; - imageToDestroy.xvImage = xvBuffer->xvImage; - imageToDestroy.shmInfo = xvBuffer->shmInfo; - - m_destroyMutex.lock(); - m_imagesToDestroy.append(imageToDestroy); - m_destroyMutex.unlock(); - - if (m_imagesToDestroy.size() == 1) - QMetaObject::invokeMethod(this, "queuedDestroy", Qt::QueuedConnection); -} - -#endif //QT_NO_XVIDEO - diff --git a/src/plugins/gstreamer/qgstxvimagebuffer.h b/src/plugins/gstreamer/qgstxvimagebuffer.h deleted file mode 100644 index 33f706329..000000000 --- a/src/plugins/gstreamer/qgstxvimagebuffer.h +++ /dev/null @@ -1,130 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** 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$ -** -****************************************************************************/ - -#ifndef QGSTXVIMAGEBUFFER_H -#define QGSTXVIMAGEBUFFER_H - -#include <qabstractvideobuffer.h> -#include <qvideosurfaceformat.h> -#include <QtCore/qmutex.h> -#include <QtCore/qwaitcondition.h> -#include <QtCore/qqueue.h> - -#ifndef QT_NO_XVIDEO - -#include <X11/Xlib.h> -#include <sys/ipc.h> -#include <sys/shm.h> -#include <X11/extensions/XShm.h> -#include <X11/Xlib.h> -#include <X11/extensions/Xv.h> -#include <X11/extensions/Xvlib.h> - - -#include <gst/gst.h> -#include "qabstractgstbufferpool.h" - -class QGstXvImageBufferPool; - -struct QGstXvImageBuffer { - GstBuffer buffer; - QGstXvImageBufferPool *pool; - XvImage *xvImage; - XShmSegmentInfo shmInfo; - bool markedForDeletion; - - static GType get_type(void); - static void class_init(gpointer g_class, gpointer class_data); - static void buffer_init(QGstXvImageBuffer *xvimage, gpointer g_class); - static void buffer_finalize(QGstXvImageBuffer * xvimage); - static GstBufferClass *parent_class; -}; - -Q_DECLARE_METATYPE(XvImage*) - -class QGstXvImageBufferPool : public QObject, public QAbstractGstBufferPool { -Q_OBJECT -friend class QGstXvImageBuffer; -public: - QGstXvImageBufferPool(QObject *parent = 0); - virtual ~QGstXvImageBufferPool(); - - bool isFormatSupported(const QVideoSurfaceFormat &format) const; - - GType bufferType() const; - GstBuffer *takeBuffer(const QVideoSurfaceFormat &format, GstCaps *caps); - void clear(); - - QAbstractVideoBuffer::HandleType handleType() const; - QAbstractVideoBuffer *prepareVideoBuffer(GstBuffer *buffer, int bytesPerLine); - -private slots: - void queuedAlloc(); - void queuedDestroy(); - - void doClear(); - - void recycleBuffer(QGstXvImageBuffer *); - void destroyBuffer(QGstXvImageBuffer *); - -private: - void doAlloc(); - - struct XvShmImage { - XvImage *xvImage; - XShmSegmentInfo shmInfo; - }; - - QMutex m_poolMutex; - QMutex m_allocMutex; - QWaitCondition m_allocWaitCondition; - QMutex m_destroyMutex; - QVideoSurfaceFormat m_format; - GstCaps *m_caps; - QList<QGstXvImageBuffer*> m_pool; - QList<QGstXvImageBuffer*> m_allBuffers; - QList<XvShmImage> m_imagesToDestroy; - Qt::HANDLE m_threadId; -}; - -#endif //QT_NO_XVIDEO - -#endif diff --git a/src/plugins/gstreamer/qvideosurfacegstsink.cpp b/src/plugins/gstreamer/qvideosurfacegstsink.cpp deleted file mode 100644 index 6ccc1b1c5..000000000 --- a/src/plugins/gstreamer/qvideosurfacegstsink.cpp +++ /dev/null @@ -1,791 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** 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$ -** -****************************************************************************/ - -#include <qabstractvideosurface.h> -#include <qvideoframe.h> -#include <QDebug> -#include <QMap> -#include <QDebug> -#include <QThread> - -#include "qgstvideobuffer.h" - -#if defined(Q_WS_X11) && !defined(QT_NO_XVIDEO) -#include <QtWidgets/qx11info_x11.h> -#include "qgstxvimagebuffer.h" -#endif - -#include "qvideosurfacegstsink.h" - -//#define DEBUG_VIDEO_SURFACE_SINK - - -Q_DECLARE_METATYPE(QVideoSurfaceFormat) - -QVideoSurfaceGstDelegate::QVideoSurfaceGstDelegate( - QAbstractVideoSurface *surface) - : m_surface(surface) - , m_pool(0) - , m_renderReturn(GST_FLOW_ERROR) - , m_bytesPerLine(0) - , m_startCanceled(false) -{ - if (m_surface) { -#if defined(Q_WS_X11) && !defined(QT_NO_XVIDEO) - m_pools.append(new QGstXvImageBufferPool()); -#endif - updateSupportedFormats(); - connect(m_surface, SIGNAL(supportedFormatsChanged()), this, SLOT(updateSupportedFormats())); - } -} - -QVideoSurfaceGstDelegate::~QVideoSurfaceGstDelegate() -{ - qDeleteAll(m_pools); -} - -QList<QVideoFrame::PixelFormat> QVideoSurfaceGstDelegate::supportedPixelFormats(QAbstractVideoBuffer::HandleType handleType) const -{ - QMutexLocker locker(const_cast<QMutex *>(&m_mutex)); - - if (!m_surface) - return QList<QVideoFrame::PixelFormat>(); - else if (handleType == QAbstractVideoBuffer::NoHandle) - return m_supportedPixelFormats; - else if (handleType == m_pool->handleType()) - return m_supportedPoolPixelFormats; - else - return m_surface->supportedPixelFormats(handleType); -} - -QVideoSurfaceFormat QVideoSurfaceGstDelegate::surfaceFormat() const -{ - QMutexLocker locker(const_cast<QMutex *>(&m_mutex)); - return m_format; -} - -bool QVideoSurfaceGstDelegate::start(const QVideoSurfaceFormat &format, int bytesPerLine) -{ - if (!m_surface) - return false; - - QMutexLocker locker(&m_mutex); - - m_format = format; - m_bytesPerLine = bytesPerLine; - - if (QThread::currentThread() == thread()) { - m_started = !m_surface.isNull() ? m_surface->start(m_format) : false; - } else { - m_started = false; - m_startCanceled = false; - QMetaObject::invokeMethod(this, "queuedStart", Qt::QueuedConnection); - - /* - Waiting for start() to be invoked in the main thread may block - if gstreamer blocks the main thread until this call is finished. - This situation is rare and usually caused by setState(Null) - while pipeline is being prerolled. - - The proper solution to this involves controlling gstreamer pipeline from - other thread than video surface. - - Currently start() fails if wait() timed out. - */ - if (!m_setupCondition.wait(&m_mutex, 1000)) { - qWarning() << "Failed to start video surface due to main thread blocked."; - m_startCanceled = true; - } - } - - m_format = m_surface->surfaceFormat(); - - return m_started; -} - -void QVideoSurfaceGstDelegate::stop() -{ - if (!m_surface) - return; - - QMutexLocker locker(&m_mutex); - - if (QThread::currentThread() == thread()) { - if (!m_surface.isNull()) - m_surface->stop(); - } else { - QMetaObject::invokeMethod(this, "queuedStop", Qt::QueuedConnection); - - // Waiting for stop() to be invoked in the main thread may block - // if gstreamer blocks the main thread until this call is finished. - m_setupCondition.wait(&m_mutex, 500); - } - - m_started = false; -} - -bool QVideoSurfaceGstDelegate::isActive() -{ - QMutexLocker locker(&m_mutex); - return !m_surface.isNull() && m_surface->isActive(); -} - -GstFlowReturn QVideoSurfaceGstDelegate::render(GstBuffer *buffer) -{ - if (!m_surface) { - qWarning() << "Rendering video frame to deleted surface, skip."; - //return GST_FLOW_NOT_NEGOTIATED; - return GST_FLOW_OK; - } - - QMutexLocker locker(&m_mutex); - - QAbstractVideoBuffer *videoBuffer = 0; - - if (m_pool && G_TYPE_CHECK_INSTANCE_TYPE(buffer, m_pool->bufferType())) - videoBuffer = m_pool->prepareVideoBuffer(buffer, m_bytesPerLine); - else - videoBuffer = new QGstVideoBuffer(buffer, m_bytesPerLine); - - m_frame = QVideoFrame( - videoBuffer, - m_format.frameSize(), - m_format.pixelFormat()); - - qint64 startTime = GST_BUFFER_TIMESTAMP(buffer); - - if (startTime >= 0) { - m_frame.setStartTime(startTime/G_GINT64_CONSTANT (1000000)); - - qint64 duration = GST_BUFFER_DURATION(buffer); - - if (duration >= 0) - m_frame.setEndTime((startTime + duration)/G_GINT64_CONSTANT (1000000)); - } - - QMetaObject::invokeMethod(this, "queuedRender", Qt::QueuedConnection); - - if (!m_renderCondition.wait(&m_mutex, 300)) { - m_frame = QVideoFrame(); - - return GST_FLOW_OK; - } else { - return m_renderReturn; - } -} - -void QVideoSurfaceGstDelegate::queuedStart() -{ - if (!m_startCanceled) { - QMutexLocker locker(&m_mutex); - m_started = m_surface->start(m_format); - m_setupCondition.wakeAll(); - } -} - -void QVideoSurfaceGstDelegate::queuedStop() -{ - QMutexLocker locker(&m_mutex); - - m_surface->stop(); - - m_setupCondition.wakeAll(); -} - -void QVideoSurfaceGstDelegate::queuedRender() -{ - QMutexLocker locker(&m_mutex); - - if (m_surface.isNull()) { - qWarning() << "Rendering video frame to deleted surface, skip the frame"; - m_renderReturn = GST_FLOW_OK; - } else if (m_surface->present(m_frame)) { - m_renderReturn = GST_FLOW_OK; - } else { - switch (m_surface->error()) { - case QAbstractVideoSurface::NoError: - m_renderReturn = GST_FLOW_OK; - break; - case QAbstractVideoSurface::StoppedError: - //It's likely we are in process of changing video output - //and the surface is already stopped, ignore the frame - m_renderReturn = GST_FLOW_OK; - break; - default: - qWarning() << "Failed to render video frame:" << m_surface->error(); - m_renderReturn = GST_FLOW_OK; - break; - } - } - - m_renderCondition.wakeAll(); -} - -void QVideoSurfaceGstDelegate::updateSupportedFormats() -{ - QAbstractGstBufferPool *newPool = 0; - foreach (QAbstractGstBufferPool *pool, m_pools) { - if (!m_surface->supportedPixelFormats(pool->handleType()).isEmpty()) { - newPool = pool; - break; - } - } - - if (newPool != m_pool) { - QMutexLocker lock(&m_poolMutex); - - if (m_pool) - m_pool->clear(); - m_pool = newPool; - } - - QMutexLocker locker(&m_mutex); - - m_supportedPixelFormats.clear(); - m_supportedPoolPixelFormats.clear(); - if (m_surface) { - m_supportedPixelFormats = m_surface->supportedPixelFormats(); - if (m_pool) - m_supportedPoolPixelFormats = m_surface->supportedPixelFormats(m_pool->handleType()); - } -} - -struct YuvFormat -{ - QVideoFrame::PixelFormat pixelFormat; - guint32 fourcc; - int bitsPerPixel; -}; - -static const YuvFormat qt_yuvColorLookup[] = -{ - { QVideoFrame::Format_YUV420P, GST_MAKE_FOURCC('I','4','2','0'), 8 }, - { QVideoFrame::Format_YV12, GST_MAKE_FOURCC('Y','V','1','2'), 8 }, - { QVideoFrame::Format_UYVY, GST_MAKE_FOURCC('U','Y','V','Y'), 16 }, - { QVideoFrame::Format_YUYV, GST_MAKE_FOURCC('Y','U','Y','2'), 16 }, - { QVideoFrame::Format_NV12, GST_MAKE_FOURCC('N','V','1','2'), 8 }, - { QVideoFrame::Format_NV21, GST_MAKE_FOURCC('N','V','2','1'), 8 }, - { QVideoFrame::Format_AYUV444, GST_MAKE_FOURCC('A','Y','U','V'), 32 } -}; - -static int indexOfYuvColor(QVideoFrame::PixelFormat format) -{ - const int count = sizeof(qt_yuvColorLookup) / sizeof(YuvFormat); - - for (int i = 0; i < count; ++i) - if (qt_yuvColorLookup[i].pixelFormat == format) - return i; - - return -1; -} - -static int indexOfYuvColor(guint32 fourcc) -{ - const int count = sizeof(qt_yuvColorLookup) / sizeof(YuvFormat); - - for (int i = 0; i < count; ++i) - if (qt_yuvColorLookup[i].fourcc == fourcc) - return i; - - return -1; -} - -struct RgbFormat -{ - QVideoFrame::PixelFormat pixelFormat; - int bitsPerPixel; - int depth; - int endianness; - int red; - int green; - int blue; - int alpha; -}; - -static const RgbFormat qt_rgbColorLookup[] = -{ - { QVideoFrame::Format_RGB32 , 32, 24, 4321, 0x0000FF00, 0x00FF0000, 0xFF000000, 0x00000000 }, - { QVideoFrame::Format_RGB32 , 32, 24, 1234, 0x00FF0000, 0x0000FF00, 0x000000FF, 0x00000000 }, - { QVideoFrame::Format_BGR32 , 32, 24, 4321, 0xFF000000, 0x00FF0000, 0x0000FF00, 0x00000000 }, - { QVideoFrame::Format_BGR32 , 32, 24, 1234, 0x000000FF, 0x0000FF00, 0x00FF0000, 0x00000000 }, - { QVideoFrame::Format_ARGB32, 32, 24, 4321, 0x0000FF00, 0x00FF0000, 0xFF000000, 0x000000FF }, - { QVideoFrame::Format_ARGB32, 32, 24, 1234, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000 }, - { QVideoFrame::Format_RGB24 , 24, 24, 4321, 0x00FF0000, 0x0000FF00, 0x000000FF, 0x00000000 }, - { QVideoFrame::Format_BGR24 , 24, 24, 4321, 0x000000FF, 0x0000FF00, 0x00FF0000, 0x00000000 }, - { QVideoFrame::Format_RGB565, 16, 16, 1234, 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 } -}; - -static int indexOfRgbColor( - int bits, int depth, int endianness, int red, int green, int blue, int alpha) -{ - const int count = sizeof(qt_rgbColorLookup) / sizeof(RgbFormat); - - for (int i = 0; i < count; ++i) { - if (qt_rgbColorLookup[i].bitsPerPixel == bits - && qt_rgbColorLookup[i].depth == depth - && qt_rgbColorLookup[i].endianness == endianness - && qt_rgbColorLookup[i].red == red - && qt_rgbColorLookup[i].green == green - && qt_rgbColorLookup[i].blue == blue - && qt_rgbColorLookup[i].alpha == alpha) { - return i; - } - } - return -1; -} - -static GstVideoSinkClass *sink_parent_class; - -#define VO_SINK(s) QVideoSurfaceGstSink *sink(reinterpret_cast<QVideoSurfaceGstSink *>(s)) - -QVideoSurfaceGstSink *QVideoSurfaceGstSink::createSink(QAbstractVideoSurface *surface) -{ - QVideoSurfaceGstSink *sink = reinterpret_cast<QVideoSurfaceGstSink *>( - g_object_new(QVideoSurfaceGstSink::get_type(), 0)); - - sink->delegate = new QVideoSurfaceGstDelegate(surface); - - return sink; -} - -GType QVideoSurfaceGstSink::get_type() -{ - static GType type = 0; - - if (type == 0) { - static const GTypeInfo info = - { - sizeof(QVideoSurfaceGstSinkClass), // class_size - base_init, // base_init - NULL, // base_finalize - class_init, // class_init - NULL, // class_finalize - NULL, // class_data - sizeof(QVideoSurfaceGstSink), // instance_size - 0, // n_preallocs - instance_init, // instance_init - 0 // value_table - }; - - type = g_type_register_static( - GST_TYPE_VIDEO_SINK, "QVideoSurfaceGstSink", &info, GTypeFlags(0)); - } - - return type; -} - -void QVideoSurfaceGstSink::class_init(gpointer g_class, gpointer class_data) -{ - Q_UNUSED(class_data); - - sink_parent_class = reinterpret_cast<GstVideoSinkClass *>(g_type_class_peek_parent(g_class)); - - GstBaseSinkClass *base_sink_class = reinterpret_cast<GstBaseSinkClass *>(g_class); - base_sink_class->get_caps = QVideoSurfaceGstSink::get_caps; - base_sink_class->set_caps = QVideoSurfaceGstSink::set_caps; - base_sink_class->buffer_alloc = QVideoSurfaceGstSink::buffer_alloc; - base_sink_class->start = QVideoSurfaceGstSink::start; - base_sink_class->stop = QVideoSurfaceGstSink::stop; - // base_sink_class->unlock = QVideoSurfaceGstSink::unlock; // Not implemented. - // base_sink_class->event = QVideoSurfaceGstSink::event; // Not implemented. - base_sink_class->preroll = QVideoSurfaceGstSink::preroll; - base_sink_class->render = QVideoSurfaceGstSink::render; - - GstElementClass *element_class = reinterpret_cast<GstElementClass *>(g_class); - element_class->change_state = QVideoSurfaceGstSink::change_state; - - GObjectClass *object_class = reinterpret_cast<GObjectClass *>(g_class); - object_class->finalize = QVideoSurfaceGstSink::finalize; -} - -void QVideoSurfaceGstSink::base_init(gpointer g_class) -{ - static GstStaticPadTemplate sink_pad_template = GST_STATIC_PAD_TEMPLATE( - "sink", GST_PAD_SINK, GST_PAD_ALWAYS, GST_STATIC_CAPS( - "video/x-raw-rgb, " - "framerate = (fraction) [ 0, MAX ], " - "width = (int) [ 1, MAX ], " - "height = (int) [ 1, MAX ]; " - "video/x-raw-yuv, " - "framerate = (fraction) [ 0, MAX ], " - "width = (int) [ 1, MAX ], " - "height = (int) [ 1, MAX ]")); - - gst_element_class_add_pad_template( - GST_ELEMENT_CLASS(g_class), gst_static_pad_template_get(&sink_pad_template)); -} - -void QVideoSurfaceGstSink::instance_init(GTypeInstance *instance, gpointer g_class) -{ - VO_SINK(instance); - - Q_UNUSED(g_class); - - sink->delegate = 0; - - sink->lastRequestedCaps = 0; - sink->lastBufferCaps = 0; - sink->lastSurfaceFormat = new QVideoSurfaceFormat; -} - -void QVideoSurfaceGstSink::finalize(GObject *object) -{ - VO_SINK(object); - - delete sink->lastSurfaceFormat; - sink->lastSurfaceFormat = 0; - - if (sink->lastBufferCaps) - gst_caps_unref(sink->lastBufferCaps); - sink->lastBufferCaps = 0; - - if (sink->lastRequestedCaps) - gst_caps_unref(sink->lastRequestedCaps); - sink->lastRequestedCaps = 0; -} - -GstStateChangeReturn QVideoSurfaceGstSink::change_state( - GstElement *element, GstStateChange transition) -{ - Q_UNUSED(element); - - return GST_ELEMENT_CLASS(sink_parent_class)->change_state( - element, transition); -} - -GstCaps *QVideoSurfaceGstSink::get_caps(GstBaseSink *base) -{ - VO_SINK(base); - - GstCaps *caps = gst_caps_new_empty(); - - foreach (QVideoFrame::PixelFormat format, sink->delegate->supportedPixelFormats()) { - int index = indexOfYuvColor(format); - - if (index != -1) { - gst_caps_append_structure(caps, gst_structure_new( - "video/x-raw-yuv", - "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, INT_MAX, 1, - "width" , GST_TYPE_INT_RANGE, 1, INT_MAX, - "height" , GST_TYPE_INT_RANGE, 1, INT_MAX, - "format" , GST_TYPE_FOURCC, qt_yuvColorLookup[index].fourcc, - NULL)); - continue; - } - - const int count = sizeof(qt_rgbColorLookup) / sizeof(RgbFormat); - - for (int i = 0; i < count; ++i) { - if (qt_rgbColorLookup[i].pixelFormat == format) { - GstStructure *structure = gst_structure_new( - "video/x-raw-rgb", - "framerate" , GST_TYPE_FRACTION_RANGE, 0, 1, INT_MAX, 1, - "width" , GST_TYPE_INT_RANGE, 1, INT_MAX, - "height" , GST_TYPE_INT_RANGE, 1, INT_MAX, - "bpp" , G_TYPE_INT, qt_rgbColorLookup[i].bitsPerPixel, - "depth" , G_TYPE_INT, qt_rgbColorLookup[i].depth, - "endianness", G_TYPE_INT, qt_rgbColorLookup[i].endianness, - "red_mask" , G_TYPE_INT, qt_rgbColorLookup[i].red, - "green_mask", G_TYPE_INT, qt_rgbColorLookup[i].green, - "blue_mask" , G_TYPE_INT, qt_rgbColorLookup[i].blue, - NULL); - - if (qt_rgbColorLookup[i].alpha != 0) { - gst_structure_set( - structure, "alpha_mask", G_TYPE_INT, qt_rgbColorLookup[i].alpha, NULL); - } - gst_caps_append_structure(caps, structure); - } - } - } - - return caps; -} - -gboolean QVideoSurfaceGstSink::set_caps(GstBaseSink *base, GstCaps *caps) -{ - VO_SINK(base); - -#ifdef DEBUG_VIDEO_SURFACE_SINK - qDebug() << "set_caps:"; - qDebug() << gst_caps_to_string(caps); -#endif - - if (!caps) { - sink->delegate->stop(); - - return TRUE; - } else { - int bytesPerLine = 0; - QVideoSurfaceFormat format = formatForCaps(caps, &bytesPerLine); - - if (sink->delegate->isActive()) { - QVideoSurfaceFormat surfaceFormst = sink->delegate->surfaceFormat(); - - if (format.pixelFormat() == surfaceFormst.pixelFormat() && - format.frameSize() == surfaceFormst.frameSize()) - return TRUE; - else - sink->delegate->stop(); - } - - if (sink->lastRequestedCaps) - gst_caps_unref(sink->lastRequestedCaps); - sink->lastRequestedCaps = 0; - -#ifdef DEBUG_VIDEO_SURFACE_SINK - qDebug() << "Staring video surface, format:"; - qDebug() << format; - qDebug() << "bytesPerLine:" << bytesPerLine; -#endif - - if (sink->delegate->start(format, bytesPerLine)) - return TRUE; - else - qWarning() << "Failed to start video surface"; - } - - return FALSE; -} - -QVideoSurfaceFormat QVideoSurfaceGstSink::formatForCaps(GstCaps *caps, int *bytesPerLine) -{ - const GstStructure *structure = gst_caps_get_structure(caps, 0); - - QVideoFrame::PixelFormat pixelFormat = QVideoFrame::Format_Invalid; - int bitsPerPixel = 0; - - QSize size; - gst_structure_get_int(structure, "width", &size.rwidth()); - gst_structure_get_int(structure, "height", &size.rheight()); - - if (qstrcmp(gst_structure_get_name(structure), "video/x-raw-yuv") == 0) { - guint32 fourcc = 0; - gst_structure_get_fourcc(structure, "format", &fourcc); - - int index = indexOfYuvColor(fourcc); - if (index != -1) { - pixelFormat = qt_yuvColorLookup[index].pixelFormat; - bitsPerPixel = qt_yuvColorLookup[index].bitsPerPixel; - } - } else if (qstrcmp(gst_structure_get_name(structure), "video/x-raw-rgb") == 0) { - int depth = 0; - int endianness = 0; - int red = 0; - int green = 0; - int blue = 0; - int alpha = 0; - - gst_structure_get_int(structure, "bpp", &bitsPerPixel); - gst_structure_get_int(structure, "depth", &depth); - gst_structure_get_int(structure, "endianness", &endianness); - gst_structure_get_int(structure, "red_mask", &red); - gst_structure_get_int(structure, "green_mask", &green); - gst_structure_get_int(structure, "blue_mask", &blue); - gst_structure_get_int(structure, "alpha_mask", &alpha); - - int index = indexOfRgbColor(bitsPerPixel, depth, endianness, red, green, blue, alpha); - - if (index != -1) - pixelFormat = qt_rgbColorLookup[index].pixelFormat; - } - - if (pixelFormat != QVideoFrame::Format_Invalid) { - QVideoSurfaceFormat format(size, pixelFormat); - - QPair<int, int> rate; - gst_structure_get_fraction(structure, "framerate", &rate.first, &rate.second); - - if (rate.second) - format.setFrameRate(qreal(rate.first)/rate.second); - - gint aspectNum = 0; - gint aspectDenum = 0; - if (gst_structure_get_fraction( - structure, "pixel-aspect-ratio", &aspectNum, &aspectDenum)) { - if (aspectDenum > 0) - format.setPixelAspectRatio(aspectNum, aspectDenum); - } - - if (bytesPerLine) - *bytesPerLine = ((size.width() * bitsPerPixel / 8) + 3) & ~3; - - return format; - } - - return QVideoSurfaceFormat(); -} - - -GstFlowReturn QVideoSurfaceGstSink::buffer_alloc( - GstBaseSink *base, guint64 offset, guint size, GstCaps *caps, GstBuffer **buffer) -{ - VO_SINK(base); - - Q_UNUSED(offset); - Q_UNUSED(size); - - if (!buffer) - return GST_FLOW_ERROR; - - *buffer = NULL; - - if (!sink->delegate->pool()) - return GST_FLOW_OK; - - QMutexLocker poolLock(sink->delegate->poolMutex()); - QAbstractGstBufferPool *pool = sink->delegate->pool(); - - if (!pool) - return GST_FLOW_OK; - - if (sink->lastRequestedCaps && gst_caps_is_equal(sink->lastRequestedCaps, caps)) { - //qDebug() << "reusing last caps"; - *buffer = GST_BUFFER(pool->takeBuffer(*sink->lastSurfaceFormat, sink->lastBufferCaps)); - return GST_FLOW_OK; - } - - if (sink->delegate->supportedPixelFormats(pool->handleType()).isEmpty()) { - //qDebug() << "sink doesn't support native pool buffers, skip buffers allocation"; - return GST_FLOW_OK; - } - - GstCaps *intersection = gst_caps_intersect(get_caps(GST_BASE_SINK(sink)), caps); - - if (gst_caps_is_empty (intersection)) { - gst_caps_unref(intersection); - return GST_FLOW_NOT_NEGOTIATED; - } - - poolLock.unlock(); - - if (sink->delegate->isActive()) { - //if format was changed, restart the surface - QVideoSurfaceFormat format = formatForCaps(intersection); - QVideoSurfaceFormat surfaceFormat = sink->delegate->surfaceFormat(); - - if (format.pixelFormat() != surfaceFormat.pixelFormat() || - format.frameSize() != surfaceFormat.frameSize()) { -#ifdef DEBUG_VIDEO_SURFACE_SINK - qDebug() << "new format requested, restart video surface"; -#endif - sink->delegate->stop(); - } - } - - if (!sink->delegate->isActive()) { - int bytesPerLine = 0; - QVideoSurfaceFormat format = formatForCaps(intersection, &bytesPerLine); - - if (!sink->delegate->start(format, bytesPerLine)) { - qWarning() << "failed to start video surface"; - return GST_FLOW_NOT_NEGOTIATED; - } - } - - poolLock.relock(); - pool = sink->delegate->pool(); - - QVideoSurfaceFormat surfaceFormat = sink->delegate->surfaceFormat(); - - if (!pool->isFormatSupported(surfaceFormat)) { - //qDebug() << "sink doesn't support native pool format, skip custom buffers allocation"; - return GST_FLOW_OK; - } - - if (sink->lastRequestedCaps) - gst_caps_unref(sink->lastRequestedCaps); - sink->lastRequestedCaps = caps; - gst_caps_ref(sink->lastRequestedCaps); - - if (sink->lastBufferCaps) - gst_caps_unref(sink->lastBufferCaps); - sink->lastBufferCaps = intersection; - gst_caps_ref(sink->lastBufferCaps); - - *sink->lastSurfaceFormat = surfaceFormat; - - *buffer = GST_BUFFER(pool->takeBuffer(surfaceFormat, intersection)); - - return GST_FLOW_OK; -} - -gboolean QVideoSurfaceGstSink::start(GstBaseSink *base) -{ - Q_UNUSED(base); - - return TRUE; -} - -gboolean QVideoSurfaceGstSink::stop(GstBaseSink *base) -{ - Q_UNUSED(base); - - return TRUE; -} - -gboolean QVideoSurfaceGstSink::unlock(GstBaseSink *base) -{ - Q_UNUSED(base); - - return TRUE; -} - -gboolean QVideoSurfaceGstSink::event(GstBaseSink *base, GstEvent *event) -{ - Q_UNUSED(base); - Q_UNUSED(event); - - return TRUE; -} - -GstFlowReturn QVideoSurfaceGstSink::preroll(GstBaseSink *base, GstBuffer *buffer) -{ - VO_SINK(base); - return sink->delegate->render(buffer); -} - -GstFlowReturn QVideoSurfaceGstSink::render(GstBaseSink *base, GstBuffer *buffer) -{ - VO_SINK(base); - return sink->delegate->render(buffer); -} - diff --git a/src/plugins/gstreamer/qvideosurfacegstsink.h b/src/plugins/gstreamer/qvideosurfacegstsink.h deleted file mode 100644 index 4110579e5..000000000 --- a/src/plugins/gstreamer/qvideosurfacegstsink.h +++ /dev/null @@ -1,163 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** 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$ -** -****************************************************************************/ - -#ifndef VIDEOSURFACEGSTSINK_H -#define VIDEOSURFACEGSTSINK_H - -#include <gst/video/gstvideosink.h> - -#include <QtCore/qlist.h> -#include <QtCore/qmutex.h> -#include <QtCore/qqueue.h> -#include <QtCore/qpointer.h> -#include <QtCore/qwaitcondition.h> -#include <qvideosurfaceformat.h> -#include <qvideoframe.h> -#include <qabstractvideobuffer.h> - -#include "qabstractgstbufferpool.h" - -QT_BEGIN_NAMESPACE -class QAbstractVideoSurface; -QT_END_NAMESPACE - -#if defined(Q_WS_X11) && !defined(QT_NO_XVIDEO) -class QGstXvImageBuffer; -class QGstXvImageBufferPool; -#endif - -class QVideoSurfaceGstDelegate : public QObject -{ - Q_OBJECT -public: - QVideoSurfaceGstDelegate(QAbstractVideoSurface *surface); - ~QVideoSurfaceGstDelegate(); - - QList<QVideoFrame::PixelFormat> supportedPixelFormats( - QAbstractVideoBuffer::HandleType handleType = QAbstractVideoBuffer::NoHandle) const; - - QVideoSurfaceFormat surfaceFormat() const; - - bool start(const QVideoSurfaceFormat &format, int bytesPerLine); - void stop(); - - bool isActive(); - - QAbstractGstBufferPool *pool() { return m_pool; } - QMutex *poolMutex() { return &m_poolMutex; } - - GstFlowReturn render(GstBuffer *buffer); - -private slots: - void queuedStart(); - void queuedStop(); - void queuedRender(); - - void updateSupportedFormats(); - -private: - QPointer<QAbstractVideoSurface> m_surface; - QList<QVideoFrame::PixelFormat> m_supportedPixelFormats; - //pixel formats of buffers pool native type - QList<QVideoFrame::PixelFormat> m_supportedPoolPixelFormats; - QAbstractGstBufferPool *m_pool; - QList<QAbstractGstBufferPool *> m_pools; - QMutex m_poolMutex; - QMutex m_mutex; - QWaitCondition m_setupCondition; - QWaitCondition m_renderCondition; - QVideoSurfaceFormat m_format; - QVideoFrame m_frame; - GstFlowReturn m_renderReturn; - int m_bytesPerLine; - bool m_started; - bool m_startCanceled; -}; - -class QVideoSurfaceGstSink -{ -public: - GstVideoSink parent; - - static QVideoSurfaceGstSink *createSink(QAbstractVideoSurface *surface); - static QVideoSurfaceFormat formatForCaps(GstCaps *caps, int *bytesPerLine = 0); - -private: - static GType get_type(); - static void class_init(gpointer g_class, gpointer class_data); - static void base_init(gpointer g_class); - static void instance_init(GTypeInstance *instance, gpointer g_class); - - static void finalize(GObject *object); - - static GstStateChangeReturn change_state(GstElement *element, GstStateChange transition); - - static GstCaps *get_caps(GstBaseSink *sink); - static gboolean set_caps(GstBaseSink *sink, GstCaps *caps); - - static GstFlowReturn buffer_alloc( - GstBaseSink *sink, guint64 offset, guint size, GstCaps *caps, GstBuffer **buffer); - - static gboolean start(GstBaseSink *sink); - static gboolean stop(GstBaseSink *sink); - - static gboolean unlock(GstBaseSink *sink); - - static gboolean event(GstBaseSink *sink, GstEvent *event); - static GstFlowReturn preroll(GstBaseSink *sink, GstBuffer *buffer); - static GstFlowReturn render(GstBaseSink *sink, GstBuffer *buffer); - -private: - QVideoSurfaceGstDelegate *delegate; - - GstCaps *lastRequestedCaps; - GstCaps *lastBufferCaps; - QVideoSurfaceFormat *lastSurfaceFormat; -}; - - -class QVideoSurfaceGstSinkClass -{ -public: - GstVideoSinkClass parent_class; -}; - -#endif |