diff options
Diffstat (limited to 'src/gsttools')
28 files changed, 3121 insertions, 8 deletions
diff --git a/src/gsttools/gsttools.pro b/src/gsttools/gsttools.pro index ca111b3f2..b13479ce7 100644 --- a/src/gsttools/gsttools.pro +++ b/src/gsttools/gsttools.pro @@ -15,12 +15,6 @@ QMAKE_USE += gstreamer qtConfig(resourcepolicy): \ QMAKE_USE += libresourceqt5 -# Header files must go inside source directory of a module -# to be installed by syncqt. -INCLUDEPATH += ../multimedia/gsttools_headers/ -INCLUDEPATH += ../plugins/gstreamer/mediaplayer/ -VPATH += ../multimedia/gsttools_headers/ - PRIVATE_HEADERS += \ qgstreamerbushelper_p.h \ qgstreamermessage_p.h \ diff --git a/src/gsttools/gstvideoconnector_p.h b/src/gsttools/gstvideoconnector_p.h new file mode 100644 index 000000000..a38ca2e65 --- /dev/null +++ b/src/gsttools/gstvideoconnector_p.h @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGSTVIDEOCONNECTOR_H +#define QGSTVIDEOCONNECTOR_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/qgsttools_global_p.h> + +#include <gst/gst.h> + +G_BEGIN_DECLS + +#define GST_TYPE_VIDEO_CONNECTOR \ + (gst_video_connector_get_type()) +#define GST_VIDEO_CONNECTOR(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_VIDEO_CONNECTOR, GstVideoConnector)) +#define GST_VIDEO_CONNECTOR_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_VIDEO_CONNECTOR, GstVideoConnectorClass)) +#define GST_IS_VIDEO_CONNECTOR(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_VIDEO_CONNECTOR)) +#define GST_IS_VIDEO_CONNECTOR_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_VIDEO_CONNECTOR)) + +typedef struct _GstVideoConnector GstVideoConnector; +typedef struct _GstVideoConnectorClass GstVideoConnectorClass; + +struct Q_GSTTOOLS_EXPORT _GstVideoConnector { + GstElement element; + + GstPad *srcpad; + GstPad *sinkpad; + + gboolean relinked; + gboolean failedSignalEmited; + GstSegment segment; + GstBuffer *latest_buffer; +}; + +struct Q_GSTTOOLS_EXPORT _GstVideoConnectorClass { + GstElementClass parent_class; + + /* action signal to resend new segment */ + void (*resend_new_segment) (GstElement * element, gboolean emitFailedSignal); +}; + +GType Q_GSTTOOLS_EXPORT gst_video_connector_get_type (void); + +G_END_DECLS + +#endif + diff --git a/src/gsttools/qgstappsrc_p.h b/src/gsttools/qgstappsrc_p.h new file mode 100644 index 000000000..c7e87037d --- /dev/null +++ b/src/gsttools/qgstappsrc_p.h @@ -0,0 +1,121 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGSTAPPSRC_H +#define QGSTAPPSRC_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/qgsttools_global_p.h> +#include <QtCore/qobject.h> +#include <QtCore/qiodevice.h> + +#include <gst/gst.h> +#include <gst/app/gstappsrc.h> + +#if GST_VERSION_MAJOR < 1 +#include <gst/app/gstappbuffer.h> +#endif + +QT_BEGIN_NAMESPACE + +class Q_GSTTOOLS_EXPORT QGstAppSrc : public QObject +{ + Q_OBJECT +public: + QGstAppSrc(QObject *parent = 0); + ~QGstAppSrc(); + + bool setup(GstElement *); + + void setStream(QIODevice *); + QIODevice *stream() const; + + GstAppSrc *element(); + + qint64 queueSize() const { return m_maxBytes; } + + bool& enoughData() { return m_enoughData; } + bool& dataRequested() { return m_dataRequested; } + unsigned int& dataRequestSize() { return m_dataRequestSize; } + + bool isStreamValid() const + { + return m_stream != 0 && + m_stream->isOpen(); + } + +private slots: + void pushDataToAppSrc(); + bool doSeek(qint64); + void onDataReady(); + + void streamDestroyed(); +private: + static gboolean on_seek_data(GstAppSrc *element, guint64 arg0, gpointer userdata); + static void on_enough_data(GstAppSrc *element, gpointer userdata); + static void on_need_data(GstAppSrc *element, uint arg0, gpointer userdata); + static void destroy_notify(gpointer data); + + void sendEOS(); + + QIODevice *m_stream; + GstAppSrc *m_appSrc; + bool m_sequential; + GstAppStreamType m_streamType; + GstAppSrcCallbacks m_callbacks; + qint64 m_maxBytes; + unsigned int m_dataRequestSize; + bool m_dataRequested; + bool m_enoughData; + bool m_forceData; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/gsttools/qgstbufferpoolinterface_p.h b/src/gsttools/qgstbufferpoolinterface_p.h new file mode 100644 index 000000000..45e573262 --- /dev/null +++ b/src/gsttools/qgstbufferpoolinterface_p.h @@ -0,0 +1,117 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGSTBUFFERPOOLINTERFACE_P_H +#define QGSTBUFFERPOOLINTERFACE_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/qgsttools_global_p.h> +#include <qabstractvideobuffer.h> +#include <qvideosurfaceformat.h> +#include <QtCore/qobject.h> +#include <QtCore/qplugin.h> + +#include <gst/gst.h> + +QT_BEGIN_NAMESPACE + +const QLatin1String QGstBufferPoolPluginKey("bufferpool"); + +/*! + Abstract interface for video buffers allocation. +*/ +class Q_GSTTOOLS_EXPORT QGstBufferPoolInterface +{ +public: + virtual ~QGstBufferPoolInterface() {} + + virtual bool isFormatSupported(const QVideoSurfaceFormat &format) 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 GstBuffer. + Returns NULL if GstBuffer is not compatible with this buffer pool. + + This method is called from gstreamer video sink thread. + */ + virtual QAbstractVideoBuffer *prepareVideoBuffer(GstBuffer *buffer, int bytesPerLine) = 0; +}; + +#define QGstBufferPoolInterface_iid "org.qt-project.qt.gstbufferpool/5.0" +Q_DECLARE_INTERFACE(QGstBufferPoolInterface, QGstBufferPoolInterface_iid) + +class QGstBufferPoolPlugin : public QObject, public QGstBufferPoolInterface +{ + Q_OBJECT + Q_INTERFACES(QGstBufferPoolInterface) +public: + explicit QGstBufferPoolPlugin(QObject *parent = 0); + virtual ~QGstBufferPoolPlugin() {} + + bool isFormatSupported(const QVideoSurfaceFormat &format) const override = 0; + GstBuffer *takeBuffer(const QVideoSurfaceFormat &format, GstCaps *caps) override = 0; + void clear() override = 0; + + QAbstractVideoBuffer::HandleType handleType() const override = 0; + + /*! + Build an QAbstractVideoBuffer instance from compatible GstBuffer. + Returns NULL if GstBuffer is not compatible with this buffer pool. + + This method is called from gstreamer video sink thread. + */ + QAbstractVideoBuffer *prepareVideoBuffer(GstBuffer *buffer, int bytesPerLine) override = 0; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/gsttools/qgstcodecsinfo_p.h b/src/gsttools/qgstcodecsinfo_p.h new file mode 100644 index 000000000..33ab3de4b --- /dev/null +++ b/src/gsttools/qgstcodecsinfo_p.h @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGSTCODECSINFO_H +#define QGSTCODECSINFO_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/qgsttools_global_p.h> +#include <QtCore/qmap.h> +#include <QtCore/qstringlist.h> + +#include <gst/gst.h> + +QT_BEGIN_NAMESPACE + +class Q_GSTTOOLS_EXPORT QGstCodecsInfo +{ +public: + enum ElementType { AudioEncoder, VideoEncoder, Muxer }; + + struct CodecInfo { + QString description; + QByteArray elementName; + GstRank rank; + }; + + QGstCodecsInfo(ElementType elementType); + + QStringList supportedCodecs() const; + QString codecDescription(const QString &codec) const; + QByteArray codecElement(const QString &codec) const; + QStringList codecOptions(const QString &codec) const; + +private: + void updateCodecs(ElementType elementType); + GList *elementFactories(ElementType elementType) const; + + QStringList m_codecs; + QMap<QString, CodecInfo> m_codecInfo; +}; + +Q_DECLARE_TYPEINFO(QGstCodecsInfo::CodecInfo, Q_MOVABLE_TYPE); + +QT_END_NAMESPACE + +#endif diff --git a/src/gsttools/qgstreameraudioinputselector_p.h b/src/gsttools/qgstreameraudioinputselector_p.h new file mode 100644 index 000000000..0c193fda9 --- /dev/null +++ b/src/gsttools/qgstreameraudioinputselector_p.h @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGSTREAMERAUDIOINPUTSELECTOR_H +#define QGSTREAMERAUDIOINPUTSELECTOR_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/qgsttools_global_p.h> +#include <qaudioinputselectorcontrol.h> +#include <QtCore/qstringlist.h> + +QT_BEGIN_NAMESPACE + +class Q_GSTTOOLS_EXPORT QGstreamerAudioInputSelector : public QAudioInputSelectorControl +{ +Q_OBJECT +public: + QGstreamerAudioInputSelector(QObject *parent); + ~QGstreamerAudioInputSelector(); + + QList<QString> availableInputs() const override; + QString inputDescription(const QString &name) const override; + QString defaultInput() const override; + QString activeInput() const override; + +public Q_SLOTS: + void setActiveInput(const QString &name) override; + +private: + void update(); + void updateAlsaDevices(); + void updateOssDevices(); + void updatePulseDevices(); + + QString m_audioInput; + QList<QString> m_names; + QList<QString> m_descriptions; +}; + +QT_END_NAMESPACE + +#endif // QGSTREAMERAUDIOINPUTSELECTOR_H diff --git a/src/gsttools/qgstreameraudioprobecontrol_p.h b/src/gsttools/qgstreameraudioprobecontrol_p.h new file mode 100644 index 000000000..4fc5c7704 --- /dev/null +++ b/src/gsttools/qgstreameraudioprobecontrol_p.h @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGSTREAMERAUDIOPROBECONTROL_H +#define QGSTREAMERAUDIOPROBECONTROL_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/qgsttools_global_p.h> +#include <gst/gst.h> +#include <qmediaaudioprobecontrol.h> +#include <QtCore/qmutex.h> +#include <qaudiobuffer.h> +#include <qshareddata.h> + +#include <private/qgstreamerbufferprobe_p.h> + +QT_BEGIN_NAMESPACE + +class Q_GSTTOOLS_EXPORT QGstreamerAudioProbeControl + : public QMediaAudioProbeControl + , public QGstreamerBufferProbe + , public QSharedData +{ + Q_OBJECT +public: + explicit QGstreamerAudioProbeControl(QObject *parent); + virtual ~QGstreamerAudioProbeControl(); + +protected: + void probeCaps(GstCaps *caps) override; + bool probeBuffer(GstBuffer *buffer) override; + +private slots: + void bufferProbed(); + +private: + QAudioBuffer m_pendingBuffer; + QAudioFormat m_format; + QMutex m_bufferMutex; +}; + +QT_END_NAMESPACE + +#endif // QGSTREAMERAUDIOPROBECONTROL_H diff --git a/src/gsttools/qgstreamerbufferprobe_p.h b/src/gsttools/qgstreamerbufferprobe_p.h new file mode 100644 index 000000000..35644f934 --- /dev/null +++ b/src/gsttools/qgstreamerbufferprobe_p.h @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** 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 QGSTREAMERBUFFERPROBE_H +#define QGSTREAMERBUFFERPROBE_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/qgsttools_global_p.h> +#include <gst/gst.h> + +#include <QtCore/qglobal.h> + + +QT_BEGIN_NAMESPACE + +class Q_GSTTOOLS_EXPORT QGstreamerBufferProbe +{ +public: + enum Flags + { + ProbeCaps = 0x01, + ProbeBuffers = 0x02, + ProbeAll = ProbeCaps | ProbeBuffers + }; + + explicit QGstreamerBufferProbe(Flags flags = ProbeAll); + virtual ~QGstreamerBufferProbe(); + + void addProbeToPad(GstPad *pad, bool downstream = true); + void removeProbeFromPad(GstPad *pad); + +protected: + virtual void probeCaps(GstCaps *caps); + virtual bool probeBuffer(GstBuffer *buffer); + +private: +#if GST_CHECK_VERSION(1,0,0) + static GstPadProbeReturn capsProbe(GstPad *pad, GstPadProbeInfo *info, gpointer user_data); + static GstPadProbeReturn bufferProbe(GstPad *pad, GstPadProbeInfo *info, gpointer user_data); + int m_capsProbeId; +#else + static gboolean bufferProbe(GstElement *element, GstBuffer *buffer, gpointer user_data); + GstCaps *m_caps; +#endif + int m_bufferProbeId; + const Flags m_flags; +}; + +QT_END_NAMESPACE + +#endif // QGSTREAMERAUDIOPROBECONTROL_H diff --git a/src/gsttools/qgstreamerbushelper_p.h b/src/gsttools/qgstreamerbushelper_p.h new file mode 100644 index 000000000..c7d06faf8 --- /dev/null +++ b/src/gsttools/qgstreamerbushelper_p.h @@ -0,0 +1,104 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGSTREAMERBUSHELPER_P_H +#define QGSTREAMERBUSHELPER_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/qgsttools_global_p.h> +#include <QObject> + +#include "qgstreamermessage_p.h" + +#include <gst/gst.h> + +QT_BEGIN_NAMESPACE + +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 "org.qt-project.qt.gstreamersyncmessagefilter/5.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 "org.qt-project.qt.gstreamerbusmessagefilter/5.0" +Q_DECLARE_INTERFACE(QGstreamerBusMessageFilter, QGstreamerBusMessageFilter_iid) + + +class QGstreamerBusHelperPrivate; + +class Q_GSTTOOLS_EXPORT 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; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/gsttools/qgstreamermessage_p.h b/src/gsttools/qgstreamermessage_p.h new file mode 100644 index 000000000..2f9d1745c --- /dev/null +++ b/src/gsttools/qgstreamermessage_p.h @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGSTREAMERMESSAGE_P_H +#define QGSTREAMERMESSAGE_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/qgsttools_global_p.h> +#include <QMetaType> + +#include <gst/gst.h> + +QT_BEGIN_NAMESPACE + +// Required for QDoc workaround +class QString; + +class Q_GSTTOOLS_EXPORT QGstreamerMessage +{ +public: + QGstreamerMessage(); + QGstreamerMessage(GstMessage* message); + QGstreamerMessage(QGstreamerMessage const& m); + ~QGstreamerMessage(); + + GstMessage* rawMessage() const; + + QGstreamerMessage& operator=(QGstreamerMessage const& rhs); + +private: + GstMessage* m_message; +}; + +QT_END_NAMESPACE + +Q_DECLARE_METATYPE(QGstreamerMessage); + +#endif diff --git a/src/gsttools/qgstreamermirtexturerenderer_p.h b/src/gsttools/qgstreamermirtexturerenderer_p.h new file mode 100644 index 000000000..62150f7e1 --- /dev/null +++ b/src/gsttools/qgstreamermirtexturerenderer_p.h @@ -0,0 +1,119 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Canonical 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 QGSTREAMERMIRTEXTURERENDERER_H +#define QGSTREAMERMIRTEXTURERENDERER_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 <qmediaplayer.h> +#include <qvideorenderercontrol.h> +#include <private/qvideosurfacegstsink_p.h> +#include <qabstractvideosurface.h> + +#include "qgstreamervideorendererinterface_p.h" + +QT_BEGIN_NAMESPACE + +class QGstreamerMirTextureBuffer; +class QGstreamerPlayerSession; +class QGLContext; +class QOpenGLContext; +class QSurfaceFormat; + +class QGstreamerMirTextureRenderer : public QVideoRendererControl, public QGstreamerVideoRendererInterface +{ + Q_OBJECT + Q_INTERFACES(QGstreamerVideoRendererInterface) +public: + QGstreamerMirTextureRenderer(QObject *parent = 0, const QGstreamerPlayerSession *playerSession = 0); + virtual ~QGstreamerMirTextureRenderer(); + + QAbstractVideoSurface *surface() const; + void setSurface(QAbstractVideoSurface *surface); + + void setPlayerSession(const QGstreamerPlayerSession *playerSession); + + GstElement *videoSink(); + + void stopRenderer(); + bool isReady() const { return m_surface != 0; } + +signals: + void sinkChanged(); + void readyChanged(bool); + void nativeSizeChanged(); + +private slots: + void handleFormatChange(); + void updateNativeVideoSize(); + void handleFocusWindowChanged(QWindow *window); + void renderFrame(); + +private: + QWindow *createOffscreenWindow(const QSurfaceFormat &format); + static void handleFrameReady(gpointer userData); + static GstPadProbeReturn padBufferProbe(GstPad *pad, GstPadProbeInfo *info, gpointer userData); + + GstElement *m_videoSink; + QPointer<QAbstractVideoSurface> m_surface; + QPointer<QAbstractVideoSurface> m_glSurface; + QGLContext *m_context; + QOpenGLContext *m_glContext; + unsigned int m_textureId; + QWindow *m_offscreenSurface; + QGstreamerPlayerSession *m_playerSession; + QGstreamerMirTextureBuffer *m_textureBuffer; + QSize m_nativeSize; + + QMutex m_mutex; +}; + +QT_END_NAMESPACE + +#endif // QGSTREAMERMIRTEXTURERENDRER_H diff --git a/src/gsttools/qgstreamerplayercontrol_p.h b/src/gsttools/qgstreamerplayercontrol_p.h new file mode 100644 index 000000000..e2252ea52 --- /dev/null +++ b/src/gsttools/qgstreamerplayercontrol_p.h @@ -0,0 +1,145 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGSTREAMERPLAYERCONTROL_P_H +#define QGSTREAMERPLAYERCONTROL_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 <QtCore/qstack.h> +#include <qmediaplayercontrol.h> +#include <private/qgsttools_global_p.h> + +QT_BEGIN_NAMESPACE + +class QMediaPlayerResourceSetInterface; +class QGstreamerPlayerSession; +class Q_GSTTOOLS_EXPORT QGstreamerPlayerControl : public QMediaPlayerControl +{ + Q_OBJECT + +public: + QGstreamerPlayerControl(QGstreamerPlayerSession *session, QObject *parent = 0); + ~QGstreamerPlayerControl(); + + QGstreamerPlayerSession *session() { return m_session; } + + QMediaPlayer::State state() const override; + QMediaPlayer::MediaStatus mediaStatus() const override; + + qint64 position() const override; + qint64 duration() const override; + + int bufferStatus() const override; + + int volume() const override; + bool isMuted() const override; + + bool isAudioAvailable() const override; + bool isVideoAvailable() const override; + void setVideoOutput(QObject *output); + + bool isSeekable() const override; + QMediaTimeRange availablePlaybackRanges() const override; + + qreal playbackRate() const override; + void setPlaybackRate(qreal rate) override; + + QMediaContent media() const override; + const QIODevice *mediaStream() const override; + void setMedia(const QMediaContent&, QIODevice *) override; + + QMediaPlayerResourceSetInterface* resources() const; + +public Q_SLOTS: + void setPosition(qint64 pos) override; + + void play() override; + void pause() override; + void stop() override; + + void setVolume(int volume) override; + void setMuted(bool muted) override; + +private Q_SLOTS: + void updateSessionState(QMediaPlayer::State state); + void updateMediaStatus(); + void processEOS(); + void setBufferProgress(int progress); + + void handleInvalidMedia(); + + void handleResourcesGranted(); + void handleResourcesLost(); + void handleResourcesDenied(); + +private: + void playOrPause(QMediaPlayer::State state); + + void pushState(); + void popAndNotifyState(); + + QGstreamerPlayerSession *m_session; + QMediaPlayer::State m_userRequestedState; + QMediaPlayer::State m_currentState; + QMediaPlayer::MediaStatus m_mediaStatus; + QStack<QMediaPlayer::State> m_stateStack; + QStack<QMediaPlayer::MediaStatus> m_mediaStatusStack; + + int m_bufferProgress; + qint64 m_pendingSeekPosition; + bool m_setMediaPending; + QMediaContent m_currentResource; + QIODevice *m_stream; + + QMediaPlayerResourceSetInterface *m_resources; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/gsttools/qgstreamerplayersession_p.h b/src/gsttools/qgstreamerplayersession_p.h new file mode 100644 index 000000000..b613793c4 --- /dev/null +++ b/src/gsttools/qgstreamerplayersession_p.h @@ -0,0 +1,280 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGSTREAMERPLAYERSESSION_P_H +#define QGSTREAMERPLAYERSESSION_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 <QtMultimedia/private/qtmultimediaglobal_p.h> +#include <QObject> +#include <QtCore/qmutex.h> +#include <QtNetwork/qnetworkrequest.h> +#include <private/qgstreamerplayercontrol_p.h> +#include <private/qgstreamerbushelper_p.h> +#include <qmediaplayer.h> +#include <qmediastreamscontrol.h> +#include <qaudioformat.h> + +#if QT_CONFIG(gstreamer_app) +#include <private/qgstappsrc_p.h> +#endif + +#include <gst/gst.h> + +QT_BEGIN_NAMESPACE + +class QGstreamerBusHelper; +class QGstreamerMessage; + +class QGstreamerVideoRendererInterface; +class QGstreamerVideoProbeControl; +class QGstreamerAudioProbeControl; + +typedef enum { + GST_AUTOPLUG_SELECT_TRY, + GST_AUTOPLUG_SELECT_EXPOSE, + GST_AUTOPLUG_SELECT_SKIP +} GstAutoplugSelectResult; + +class Q_GSTTOOLS_EXPORT QGstreamerPlayerSession + : public QObject + , public QGstreamerBusMessageFilter +{ +Q_OBJECT +Q_INTERFACES(QGstreamerBusMessageFilter) + +public: + QGstreamerPlayerSession(QObject *parent); + virtual ~QGstreamerPlayerSession(); + + GstElement *playbin() const; + GstElement *pipeline() const { return m_pipeline; } + QGstreamerBusHelper *bus() const { return m_busHelper; } + + QNetworkRequest request() const; + + QMediaPlayer::State state() const { return m_state; } + QMediaPlayer::State pendingState() const { return m_pendingState; } + + qint64 duration() const; + qint64 position() const; + + int volume() const; + bool isMuted() const; + + bool isAudioAvailable() const; + + void setVideoRenderer(QObject *renderer); + QGstreamerVideoRendererInterface *renderer() const { return m_renderer; } + bool isVideoAvailable() const; + + bool isSeekable() const; + + qreal playbackRate() const; + void setPlaybackRate(qreal rate); + + QMediaTimeRange availablePlaybackRanges() const; + + QMap<QByteArray ,QVariant> tags() const { return m_tags; } + QMap<QString,QVariant> streamProperties(int streamNumber) const { return m_streamProperties[streamNumber]; } + int streamCount() const { return m_streamProperties.count(); } + QMediaStreamsControl::StreamType streamType(int streamNumber) { return m_streamTypes.value(streamNumber, QMediaStreamsControl::UnknownStream); } + + int activeStream(QMediaStreamsControl::StreamType streamType) const; + void setActiveStream(QMediaStreamsControl::StreamType streamType, int streamNumber); + + bool processBusMessage(const QGstreamerMessage &message) override; + +#if QT_CONFIG(gstreamer_app) + QGstAppSrc *appsrc() const { return m_appSrc; } + static void configureAppSrcElement(GObject*, GObject*, GParamSpec*,QGstreamerPlayerSession* _this); +#endif + + bool isLiveSource() const; + + void addProbe(QGstreamerVideoProbeControl* probe); + void removeProbe(QGstreamerVideoProbeControl* probe); + + void addProbe(QGstreamerAudioProbeControl* probe); + void removeProbe(QGstreamerAudioProbeControl* probe); + + void endOfMediaReset(); + +public slots: + void loadFromUri(const QNetworkRequest &url); + void loadFromStream(const QNetworkRequest &url, QIODevice *stream); + bool play(); + bool pause(); + void stop(); + + bool seek(qint64 pos); + + void setVolume(int volume); + void setMuted(bool muted); + + void showPrerollFrames(bool enabled); + +signals: + void durationChanged(qint64 duration); + void positionChanged(qint64 position); + void stateChanged(QMediaPlayer::State state); + void volumeChanged(int volume); + void mutedStateChanged(bool muted); + void audioAvailableChanged(bool audioAvailable); + void videoAvailableChanged(bool videoAvailable); + void bufferingProgressChanged(int percentFilled); + void playbackFinished(); + void tagsChanged(); + void streamsChanged(); + void seekableChanged(bool); + void error(int error, const QString &errorString); + void invalidMedia(); + void playbackRateChanged(qreal); + void rendererChanged(); + void pipelineChanged(); + +private slots: + void getStreamsInfo(); + void setSeekable(bool); + void finishVideoOutputChange(); + void updateVideoRenderer(); + void updateVideoResolutionTag(); + void updateVolume(); + void updateMuted(); + void updateDuration(); + +private: + static void playbinNotifySource(GObject *o, GParamSpec *p, gpointer d); + static void handleVolumeChange(GObject *o, GParamSpec *p, gpointer d); + static void handleMutedChange(GObject *o, GParamSpec *p, gpointer d); +#if !GST_CHECK_VERSION(1,0,0) + static void insertColorSpaceElement(GstElement *element, gpointer data); +#endif + static void handleElementAdded(GstBin *bin, GstElement *element, QGstreamerPlayerSession *session); + static void handleStreamsChange(GstBin *bin, gpointer user_data); + static GstAutoplugSelectResult handleAutoplugSelect(GstBin *bin, GstPad *pad, GstCaps *caps, GstElementFactory *factory, QGstreamerPlayerSession *session); + + void processInvalidMedia(QMediaPlayer::Error errorCode, const QString& errorString); + + void removeVideoBufferProbe(); + void addVideoBufferProbe(); + void removeAudioBufferProbe(); + void addAudioBufferProbe(); + void flushVideoProbes(); + void resumeVideoProbes(); + void setPipeline(GstElement *pipeline); + + QNetworkRequest m_request; + QMediaPlayer::State m_state; + QMediaPlayer::State m_pendingState; + QGstreamerBusHelper* m_busHelper; + GstElement *m_playbin = nullptr; // Can be null + GstElement *m_pipeline = nullptr; // Never null + + GstElement* m_videoSink; + + GstElement* m_videoOutputBin; + GstElement* m_videoIdentity; +#if !GST_CHECK_VERSION(1,0,0) + GstElement* m_colorSpace; + bool m_usingColorspaceElement; +#endif + GstElement* m_pendingVideoSink; + GstElement* m_nullVideoSink; + + GstElement* m_audioSink; + GstElement* m_volumeElement; + + GstBus* m_bus; + QObject *m_videoOutput; + QGstreamerVideoRendererInterface *m_renderer; + +#if QT_CONFIG(gstreamer_app) + QGstAppSrc *m_appSrc; +#endif + + QMap<QByteArray, QVariant> m_tags; + QList< QMap<QString,QVariant> > m_streamProperties; + QList<QMediaStreamsControl::StreamType> m_streamTypes; + QMap<QMediaStreamsControl::StreamType, int> m_playbin2StreamOffset; + + QGstreamerVideoProbeControl *m_videoProbe; + QGstreamerAudioProbeControl *m_audioProbe; + + int m_volume; + qreal m_playbackRate; + bool m_muted; + bool m_audioAvailable; + bool m_videoAvailable; + bool m_seekable; + + mutable qint64 m_lastPosition; + qint64 m_duration; + int m_durationQueries; + + bool m_displayPrerolledFrame; + + enum SourceType + { + UnknownSrc, + SoupHTTPSrc, + UDPSrc, + MMSSrc, + RTSPSrc, + }; + SourceType m_sourceType; + bool m_everPlayed; + bool m_isLiveSource; + + gulong pad_probe_id; +}; + +QT_END_NAMESPACE + +#endif // QGSTREAMERPLAYERSESSION_H diff --git a/src/gsttools/qgstreamervideoinputdevicecontrol_p.h b/src/gsttools/qgstreamervideoinputdevicecontrol_p.h new file mode 100644 index 000000000..b660cc7b3 --- /dev/null +++ b/src/gsttools/qgstreamervideoinputdevicecontrol_p.h @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGSTREAMERVIDEOINPUTDEVICECONTROL_H +#define QGSTREAMERVIDEOINPUTDEVICECONTROL_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/qgsttools_global_p.h> +#include <qvideodeviceselectorcontrol.h> +#include <QtCore/qstringlist.h> + +#include <gst/gst.h> +#include <qcamera.h> + +QT_BEGIN_NAMESPACE + +class Q_GSTTOOLS_EXPORT QGstreamerVideoInputDeviceControl : public QVideoDeviceSelectorControl +{ +Q_OBJECT +public: + QGstreamerVideoInputDeviceControl(QObject *parent); + QGstreamerVideoInputDeviceControl(GstElementFactory *factory, QObject *parent); + ~QGstreamerVideoInputDeviceControl(); + + int deviceCount() const override; + + QString deviceName(int index) const override; + QString deviceDescription(int index) const override; + + int defaultDevice() const override; + int selectedDevice() const override; + + static QString primaryCamera() { return tr("Main camera"); } + static QString secondaryCamera() { return tr("Front camera"); } + +public Q_SLOTS: + void setSelectedDevice(int index) override; + +private: + GstElementFactory *m_factory; + + int m_selectedDevice; +}; + +QT_END_NAMESPACE + +#endif // QGSTREAMERAUDIOINPUTDEVICECONTROL_H diff --git a/src/gsttools/qgstreamervideooverlay_p.h b/src/gsttools/qgstreamervideooverlay_p.h new file mode 100644 index 000000000..f2ca8a23b --- /dev/null +++ b/src/gsttools/qgstreamervideooverlay_p.h @@ -0,0 +1,127 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGSTREAMERVIDEOOVERLAY_P_H +#define QGSTREAMERVIDEOOVERLAY_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/qgstreamerbushelper_p.h> +#include <private/qgstreamerbufferprobe_p.h> +#include <QtGui/qwindowdefs.h> +#include <QtCore/qsize.h> + +QT_BEGIN_NAMESPACE + +class QGstreamerSinkProperties; +class QGstreamerVideoOverlay + : public QObject + , public QGstreamerSyncMessageFilter + , public QGstreamerBusMessageFilter + , private QGstreamerBufferProbe +{ + Q_OBJECT + Q_INTERFACES(QGstreamerSyncMessageFilter QGstreamerBusMessageFilter) +public: + explicit QGstreamerVideoOverlay(QObject *parent = 0, const QByteArray &elementName = QByteArray()); + virtual ~QGstreamerVideoOverlay(); + + GstElement *videoSink() const; + void setVideoSink(GstElement *); + QSize nativeVideoSize() const; + + void setWindowHandle(WId id); + void expose(); + void setRenderRectangle(const QRect &rect); + + bool isActive() const; + + Qt::AspectRatioMode aspectRatioMode() const; + void setAspectRatioMode(Qt::AspectRatioMode mode); + + int brightness() const; + void setBrightness(int brightness); + + int contrast() const; + void setContrast(int contrast); + + int hue() const; + void setHue(int hue); + + int saturation() const; + void setSaturation(int saturation); + + bool processSyncMessage(const QGstreamerMessage &message) override; + bool processBusMessage(const QGstreamerMessage &message) override; + +Q_SIGNALS: + void nativeVideoSizeChanged(); + void activeChanged(); + void brightnessChanged(int brightness); + void contrastChanged(int contrast); + void hueChanged(int hue); + void saturationChanged(int saturation); + +private: + void setWindowHandle_helper(WId id); + void updateIsActive(); + void probeCaps(GstCaps *caps) override; + static void showPrerollFrameChanged(GObject *, GParamSpec *, QGstreamerVideoOverlay *); + + GstElement *m_videoSink = nullptr; + QSize m_nativeVideoSize; + bool m_isActive = false; + + QGstreamerSinkProperties *m_sinkProperties = nullptr; + WId m_windowId = 0; +}; + +QT_END_NAMESPACE + +#endif // QGSTREAMERVIDEOOVERLAY_P_H + diff --git a/src/gsttools/qgstreamervideoprobecontrol_p.h b/src/gsttools/qgstreamervideoprobecontrol_p.h new file mode 100644 index 000000000..b15b6099c --- /dev/null +++ b/src/gsttools/qgstreamervideoprobecontrol_p.h @@ -0,0 +1,100 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGSTREAMERVIDEOPROBECONTROL_H +#define QGSTREAMERVIDEOPROBECONTROL_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/qgsttools_global_p.h> +#include <gst/gst.h> +#include <gst/video/video.h> +#include <qmediavideoprobecontrol.h> +#include <QtCore/qmutex.h> +#include <qvideoframe.h> +#include <qvideosurfaceformat.h> + +#include <private/qgstreamerbufferprobe_p.h> + +QT_BEGIN_NAMESPACE + +class Q_GSTTOOLS_EXPORT QGstreamerVideoProbeControl + : public QMediaVideoProbeControl + , public QGstreamerBufferProbe + , public QSharedData +{ + Q_OBJECT +public: + explicit QGstreamerVideoProbeControl(QObject *parent); + virtual ~QGstreamerVideoProbeControl(); + + void probeCaps(GstCaps *caps) override; + bool probeBuffer(GstBuffer *buffer) override; + + void startFlushing(); + void stopFlushing(); + +private slots: + void frameProbed(); + +private: + QVideoSurfaceFormat m_format; + QVideoFrame m_pendingFrame; + QMutex m_frameMutex; +#if GST_CHECK_VERSION(1,0,0) + GstVideoInfo m_videoInfo; +#else + int m_bytesPerLine; +#endif + bool m_flushing; + bool m_frameProbed; // true if at least one frame was probed +}; + +QT_END_NAMESPACE + +#endif // QGSTREAMERVIDEOPROBECONTROL_H diff --git a/src/gsttools/qgstreamervideorenderer_p.h b/src/gsttools/qgstreamervideorenderer_p.h new file mode 100644 index 000000000..d87bfcb8f --- /dev/null +++ b/src/gsttools/qgstreamervideorenderer_p.h @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGSTREAMERVIDEORENDERER_H +#define QGSTREAMERVIDEORENDERER_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/qgsttools_global_p.h> +#include <qvideorenderercontrol.h> +#include <private/qvideosurfacegstsink_p.h> +#include <qabstractvideosurface.h> + +#include "qgstreamervideorendererinterface_p.h" + +QT_BEGIN_NAMESPACE + +class Q_GSTTOOLS_EXPORT QGstreamerVideoRenderer : public QVideoRendererControl, public QGstreamerVideoRendererInterface +{ + Q_OBJECT + Q_INTERFACES(QGstreamerVideoRendererInterface) +public: + QGstreamerVideoRenderer(QObject *parent = 0); + virtual ~QGstreamerVideoRenderer(); + + QAbstractVideoSurface *surface() const override; + void setSurface(QAbstractVideoSurface *surface) override; + + GstElement *videoSink() override; + void setVideoSink(GstElement *) override; + + void stopRenderer() override; + bool isReady() const override { return m_surface != 0; } + +signals: + void sinkChanged(); + void readyChanged(bool); + +private slots: + void handleFormatChange(); + +private: + GstElement *m_videoSink = nullptr; + QPointer<QAbstractVideoSurface> m_surface; +}; + +QT_END_NAMESPACE + +#endif // QGSTREAMERVIDEORENDRER_H diff --git a/src/gsttools/qgstreamervideorendererinterface_p.h b/src/gsttools/qgstreamervideorendererinterface_p.h new file mode 100644 index 000000000..231c843db --- /dev/null +++ b/src/gsttools/qgstreamervideorendererinterface_p.h @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGSTREAMERVIDEOOUTPUTCONTROL_H +#define QGSTREAMERVIDEOOUTPUTCONTROL_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 <gst/gst.h> + +#include <QtCore/qobject.h> + +QT_BEGIN_NAMESPACE + +class QGstreamerVideoRendererInterface +{ +public: + virtual ~QGstreamerVideoRendererInterface(); + virtual GstElement *videoSink() = 0; + virtual void setVideoSink(GstElement *) {}; + + //stopRenderer() is called when the renderer element is stopped. + //it can be reimplemented when video renderer can't detect + //changes to NULL state but has to free video resources. + virtual void stopRenderer() {} + + //the video output is configured, usually after the first paint event + //(winId is known, + virtual bool isReady() const { return true; } + + //signals: + //void sinkChanged(); + //void readyChanged(bool); +}; + +#define QGstreamerVideoRendererInterface_iid "org.qt-project.qt.gstreamervideorenderer/5.0" +Q_DECLARE_INTERFACE(QGstreamerVideoRendererInterface, QGstreamerVideoRendererInterface_iid) +QT_END_NAMESPACE + +#endif diff --git a/src/gsttools/qgstreamervideowidget.cpp b/src/gsttools/qgstreamervideowidget.cpp index 633f39fa2..bb85e1eb7 100644 --- a/src/gsttools/qgstreamervideowidget.cpp +++ b/src/gsttools/qgstreamervideowidget.cpp @@ -53,7 +53,7 @@ public: { setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); QPalette palette; - palette.setColor(QPalette::Background, Qt::black); + palette.setColor(QPalette::Window, Qt::black); setPalette(palette); } @@ -80,7 +80,7 @@ public: void paint_helper() { QPainter painter(this); - painter.fillRect(rect(), palette().background()); + painter.fillRect(rect(), palette().window()); } protected: diff --git a/src/gsttools/qgstreamervideowidget_p.h b/src/gsttools/qgstreamervideowidget_p.h new file mode 100644 index 000000000..1ddb738df --- /dev/null +++ b/src/gsttools/qgstreamervideowidget_p.h @@ -0,0 +1,128 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGSTREAMERVIDEOWIDGET_H +#define QGSTREAMERVIDEOWIDGET_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/qgsttools_global_p.h> +#include <qvideowidgetcontrol.h> + +#include "qgstreamervideorendererinterface_p.h" +#include <private/qgstreamerbushelper_p.h> +#include <private/qgstreamervideooverlay_p.h> + +QT_BEGIN_NAMESPACE + +class Q_GSTTOOLS_EXPORT QGstreamerVideoWidget; + +class Q_GSTTOOLS_EXPORT QGstreamerVideoWidgetControl + : public QVideoWidgetControl + , public QGstreamerVideoRendererInterface + , public QGstreamerSyncMessageFilter + , public QGstreamerBusMessageFilter +{ + Q_OBJECT + Q_INTERFACES(QGstreamerVideoRendererInterface QGstreamerSyncMessageFilter QGstreamerBusMessageFilter) +public: + explicit QGstreamerVideoWidgetControl(QObject *parent = 0, const QByteArray &elementName = QByteArray()); + virtual ~QGstreamerVideoWidgetControl(); + + GstElement *videoSink() override; + void setVideoSink(GstElement *) override; + + QWidget *videoWidget() override; + + void stopRenderer() override; + + Qt::AspectRatioMode aspectRatioMode() const override; + void setAspectRatioMode(Qt::AspectRatioMode mode) override; + + bool isFullScreen() const override; + void setFullScreen(bool fullScreen) override; + + int brightness() const override; + void setBrightness(int brightness) override; + + int contrast() const override; + void setContrast(int contrast) override; + + int hue() const override; + void setHue(int hue) override; + + int saturation() const override; + void setSaturation(int saturation) override; + + bool eventFilter(QObject *object, QEvent *event) override; + +signals: + void sinkChanged(); + void readyChanged(bool); + +private Q_SLOTS: + void onOverlayActiveChanged(); + void onNativeVideoSizeChanged(); + +private: + void createVideoWidget(); + void updateWidgetAttributes(); + + bool processSyncMessage(const QGstreamerMessage &message) override; + bool processBusMessage(const QGstreamerMessage &message) override; + + QGstreamerVideoOverlay m_videoOverlay; + QGstreamerVideoWidget *m_widget; + bool m_stopped; + WId m_windowId; + bool m_fullScreen; +}; + +QT_END_NAMESPACE + +#endif // QGSTREAMERVIDEOWIDGET_H diff --git a/src/gsttools/qgstreamervideowindow_p.h b/src/gsttools/qgstreamervideowindow_p.h new file mode 100644 index 000000000..5f893f10e --- /dev/null +++ b/src/gsttools/qgstreamervideowindow_p.h @@ -0,0 +1,127 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGSTREAMERVIDEOWINDOW_H +#define QGSTREAMERVIDEOWINDOW_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/qgsttools_global_p.h> +#include <qvideowindowcontrol.h> + +#include "qgstreamervideorendererinterface_p.h" +#include <private/qgstreamerbushelper_p.h> +#include <private/qgstreamervideooverlay_p.h> +#include <QtGui/qcolor.h> + +QT_BEGIN_NAMESPACE +class QAbstractVideoSurface; + +class Q_GSTTOOLS_EXPORT QGstreamerVideoWindow : + public QVideoWindowControl, + public QGstreamerVideoRendererInterface, + public QGstreamerSyncMessageFilter, + public QGstreamerBusMessageFilter +{ + Q_OBJECT + Q_INTERFACES(QGstreamerVideoRendererInterface QGstreamerSyncMessageFilter QGstreamerBusMessageFilter) +public: + explicit QGstreamerVideoWindow(QObject *parent = 0, const QByteArray &elementName = QByteArray()); + ~QGstreamerVideoWindow(); + + WId winId() const override; + void setWinId(WId id) override; + + QRect displayRect() const override; + void setDisplayRect(const QRect &rect) override; + + bool isFullScreen() const override; + void setFullScreen(bool fullScreen) override; + + QSize nativeSize() const override; + + Qt::AspectRatioMode aspectRatioMode() const override; + void setAspectRatioMode(Qt::AspectRatioMode mode) override; + + void repaint() override; + + int brightness() const override; + void setBrightness(int brightness) override; + + int contrast() const override; + void setContrast(int contrast) override; + + int hue() const override; + void setHue(int hue) override; + + int saturation() const override; + void setSaturation(int saturation) override; + + QAbstractVideoSurface *surface() const; + + GstElement *videoSink() override; + + bool processSyncMessage(const QGstreamerMessage &message) override; + bool processBusMessage(const QGstreamerMessage &message) override; + bool isReady() const override { return m_windowId != 0; } + +signals: + void sinkChanged(); + void readyChanged(bool); + +private: + QGstreamerVideoOverlay m_videoOverlay; + WId m_windowId; + QRect m_displayRect; + bool m_fullScreen; + mutable QColor m_colorKey; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/gsttools/qgsttools_global_p.h b/src/gsttools/qgsttools_global_p.h new file mode 100644 index 000000000..babcd3aaf --- /dev/null +++ b/src/gsttools/qgsttools_global_p.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGSTTOOLS_GLOBAL_H +#define QGSTTOOLS_GLOBAL_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 <QtCore/qglobal.h> + +QT_BEGIN_NAMESPACE + +#ifndef QT_STATIC +# if defined(QT_BUILD_MULTIMEDIAGSTTOOLS_LIB) +# define Q_GSTTOOLS_EXPORT Q_DECL_EXPORT +# else +# define Q_GSTTOOLS_EXPORT Q_DECL_IMPORT +# endif +#else +# define Q_GSTTOOLS_EXPORT +#endif + +QT_END_NAMESPACE + +#endif // QGSTTOOLS_GLOBAL_H diff --git a/src/gsttools/qgstutils.cpp b/src/gsttools/qgstutils.cpp index 58dd6e5fe..06f277766 100644 --- a/src/gsttools/qgstutils.cpp +++ b/src/gsttools/qgstutils.cpp @@ -686,6 +686,67 @@ QVector<QGstUtils::CameraInfo> QGstUtils::enumerateCameras(GstElementFactory *fa camerasCacheAgeTimer.restart(); #endif // linux_v4l +#if GST_CHECK_VERSION(1,4,0) && (defined(Q_OS_WIN) || defined(Q_OS_MACOS)) + if (!devices.isEmpty()) + return devices; + +#if defined(Q_OS_WIN) + const char *propName = "device-path"; + auto deviceDesc = [](GValue *value) { + gchar *desc = g_value_dup_string(value); + const QString id = QLatin1String(desc); + g_free(desc); + return id; + }; +#elif defined(Q_OS_MACOS) + const char *propName = "device-index"; + auto deviceDesc = [](GValue *value) { + return QString::number(g_value_get_int(value)); + }; +#endif + + QGstUtils::initializeGst(); + GstDeviceMonitor *monitor = gst_device_monitor_new(); + auto caps = gst_caps_new_empty_simple("video/x-raw"); + gst_device_monitor_add_filter(monitor, "Video/Source", caps); + gst_caps_unref(caps); + + GList *devs = gst_device_monitor_get_devices(monitor); + while (devs) { + GstDevice *dev = reinterpret_cast<GstDevice*>(devs->data); + GstElement *element = gst_device_create_element(dev, nullptr); + if (element) { + gchar *name = gst_device_get_display_name(dev); + const QString deviceName = QLatin1String(name); + g_free(name); + GParamSpec *prop = g_object_class_find_property(G_OBJECT_GET_CLASS(element), propName); + if (prop) { + GValue value = G_VALUE_INIT; + g_value_init(&value, prop->value_type); + g_object_get_property(G_OBJECT(element), prop->name, &value); + const QString deviceId = deviceDesc(&value); + g_value_unset(&value); + + CameraInfo device = { + deviceId, + deviceName, + 0, + QCamera::UnspecifiedPosition, + QByteArray() + }; + + devices.append(device); + } + + gst_object_unref(element); + } + + gst_object_unref(dev); + devs = g_list_delete_link(devs, devs); + } + gst_object_unref(monitor); +#endif // GST_CHECK_VERSION(1,4,0) && (defined(Q_OS_WIN) || defined(Q_OS_MACOS)) + return devices; } @@ -1474,6 +1535,37 @@ QString QGstUtils::fileExtensionForMimeType(const QString &mimeType) return extension; } +#if GST_CHECK_VERSION(0,10,30) +QVariant QGstUtils::fromGStreamerOrientation(const QVariant &value) +{ + // Note gstreamer tokens either describe the counter clockwise rotation of the + // image or the clockwise transform to apply to correct the image. The orientation + // value returned is the clockwise rotation of the image. + const QString token = value.toString(); + if (token == QStringLiteral("rotate-90")) + return 270; + if (token == QStringLiteral("rotate-180")) + return 180; + if (token == QStringLiteral("rotate-270")) + return 90; + return 0; +} + +QVariant QGstUtils::toGStreamerOrientation(const QVariant &value) +{ + switch (value.toInt()) { + case 90: + return QStringLiteral("rotate-270"); + case 180: + return QStringLiteral("rotate-180"); + case 270: + return QStringLiteral("rotate-90"); + default: + return QStringLiteral("rotate-0"); + } +} +#endif + void qt_gst_object_ref_sink(gpointer object) { #if GST_CHECK_VERSION(0,10,24) diff --git a/src/gsttools/qgstutils_p.h b/src/gsttools/qgstutils_p.h new file mode 100644 index 000000000..387a2e27a --- /dev/null +++ b/src/gsttools/qgstutils_p.h @@ -0,0 +1,174 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGSTUTILS_P_H +#define QGSTUTILS_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/qgsttools_global_p.h> +#include <QtCore/qmap.h> +#include <QtCore/qset.h> +#include <QtCore/qvector.h> +#include <gst/gst.h> +#include <gst/video/video.h> +#include <qaudioformat.h> +#include <qcamera.h> +#include <qabstractvideobuffer.h> +#include <qvideoframe.h> +#include <QDebug> + +#if GST_CHECK_VERSION(1,0,0) +# define QT_GSTREAMER_PLAYBIN_ELEMENT_NAME "playbin" +# define QT_GSTREAMER_CAMERABIN_ELEMENT_NAME "camerabin" +# define QT_GSTREAMER_COLORCONVERSION_ELEMENT_NAME "videoconvert" +# define QT_GSTREAMER_RAW_AUDIO_MIME "audio/x-raw" +# define QT_GSTREAMER_VIDEOOVERLAY_INTERFACE_NAME "GstVideoOverlay" +#else +# define QT_GSTREAMER_PLAYBIN_ELEMENT_NAME "playbin2" +# define QT_GSTREAMER_CAMERABIN_ELEMENT_NAME "camerabin2" +# define QT_GSTREAMER_COLORCONVERSION_ELEMENT_NAME "ffmpegcolorspace" +# define QT_GSTREAMER_RAW_AUDIO_MIME "audio/x-raw-int" +# define QT_GSTREAMER_VIDEOOVERLAY_INTERFACE_NAME "GstXOverlay" +#endif + +QT_BEGIN_NAMESPACE + +class QSize; +class QVariant; +class QByteArray; +class QImage; +class QVideoSurfaceFormat; + +namespace QGstUtils { + struct Q_GSTTOOLS_EXPORT CameraInfo + { + QString name; + QString description; + int orientation; + QCamera::Position position; + QByteArray driver; + }; + + Q_GSTTOOLS_EXPORT QMap<QByteArray, QVariant> gstTagListToMap(const GstTagList *list); + + Q_GSTTOOLS_EXPORT QSize capsResolution(const GstCaps *caps); + Q_GSTTOOLS_EXPORT QSize capsCorrectedResolution(const GstCaps *caps); + Q_GSTTOOLS_EXPORT QAudioFormat audioFormatForCaps(const GstCaps *caps); +#if GST_CHECK_VERSION(1,0,0) + Q_GSTTOOLS_EXPORT QAudioFormat audioFormatForSample(GstSample *sample); +#else + Q_GSTTOOLS_EXPORT QAudioFormat audioFormatForBuffer(GstBuffer *buffer); +#endif + Q_GSTTOOLS_EXPORT GstCaps *capsForAudioFormat(const QAudioFormat &format); + Q_GSTTOOLS_EXPORT void initializeGst(); + Q_GSTTOOLS_EXPORT QMultimedia::SupportEstimate hasSupport(const QString &mimeType, + const QStringList &codecs, + const QSet<QString> &supportedMimeTypeSet); + + Q_GSTTOOLS_EXPORT QVector<CameraInfo> enumerateCameras(GstElementFactory *factory = 0); + Q_GSTTOOLS_EXPORT QList<QByteArray> cameraDevices(GstElementFactory * factory = 0); + Q_GSTTOOLS_EXPORT QString cameraDescription(const QString &device, GstElementFactory * factory = 0); + Q_GSTTOOLS_EXPORT QCamera::Position cameraPosition(const QString &device, GstElementFactory * factory = 0); + Q_GSTTOOLS_EXPORT int cameraOrientation(const QString &device, GstElementFactory * factory = 0); + Q_GSTTOOLS_EXPORT QByteArray cameraDriver(const QString &device, GstElementFactory * factory = 0); + + Q_GSTTOOLS_EXPORT QSet<QString> supportedMimeTypes(bool (*isValidFactory)(GstElementFactory *factory)); + +#if GST_CHECK_VERSION(1,0,0) + Q_GSTTOOLS_EXPORT QImage bufferToImage(GstBuffer *buffer, const GstVideoInfo &info); + Q_GSTTOOLS_EXPORT QVideoSurfaceFormat formatForCaps( + GstCaps *caps, + GstVideoInfo *info = 0, + QAbstractVideoBuffer::HandleType handleType = QAbstractVideoBuffer::NoHandle); +#else + Q_GSTTOOLS_EXPORT QImage bufferToImage(GstBuffer *buffer); + Q_GSTTOOLS_EXPORT QVideoSurfaceFormat formatForCaps( + GstCaps *caps, + int *bytesPerLine = 0, + QAbstractVideoBuffer::HandleType handleType = QAbstractVideoBuffer::NoHandle); +#endif + + Q_GSTTOOLS_EXPORT GstCaps *capsForFormats(const QList<QVideoFrame::PixelFormat> &formats); + void setFrameTimeStamps(QVideoFrame *frame, GstBuffer *buffer); + + Q_GSTTOOLS_EXPORT void setMetaData(GstElement *element, const QMap<QByteArray, QVariant> &data); + Q_GSTTOOLS_EXPORT void setMetaData(GstBin *bin, const QMap<QByteArray, QVariant> &data); + + Q_GSTTOOLS_EXPORT GstCaps *videoFilterCaps(); + + Q_GSTTOOLS_EXPORT QSize structureResolution(const GstStructure *s); + Q_GSTTOOLS_EXPORT QVideoFrame::PixelFormat structurePixelFormat(const GstStructure *s, int *bpp = 0); + Q_GSTTOOLS_EXPORT QSize structurePixelAspectRatio(const GstStructure *s); + Q_GSTTOOLS_EXPORT QPair<qreal, qreal> structureFrameRateRange(const GstStructure *s); + + Q_GSTTOOLS_EXPORT QString fileExtensionForMimeType(const QString &mimeType); + +#if GST_CHECK_VERSION(0,10,30) + Q_GSTTOOLS_EXPORT QVariant fromGStreamerOrientation(const QVariant &value); + Q_GSTTOOLS_EXPORT QVariant toGStreamerOrientation(const QVariant &value); +#endif +} + +Q_GSTTOOLS_EXPORT void qt_gst_object_ref_sink(gpointer object); +Q_GSTTOOLS_EXPORT GstCaps *qt_gst_pad_get_current_caps(GstPad *pad); +Q_GSTTOOLS_EXPORT GstCaps *qt_gst_pad_get_caps(GstPad *pad); +Q_GSTTOOLS_EXPORT GstStructure *qt_gst_structure_new_empty(const char *name); +Q_GSTTOOLS_EXPORT gboolean qt_gst_element_query_position(GstElement *element, GstFormat format, gint64 *cur); +Q_GSTTOOLS_EXPORT gboolean qt_gst_element_query_duration(GstElement *element, GstFormat format, gint64 *cur); +Q_GSTTOOLS_EXPORT GstCaps *qt_gst_caps_normalize(GstCaps *caps); +Q_GSTTOOLS_EXPORT const gchar *qt_gst_element_get_factory_name(GstElement *element); +Q_GSTTOOLS_EXPORT gboolean qt_gst_caps_can_intersect(const GstCaps * caps1, const GstCaps * caps2); +Q_GSTTOOLS_EXPORT GList *qt_gst_video_sinks(); +Q_GSTTOOLS_EXPORT void qt_gst_util_double_to_fraction(gdouble src, gint *dest_n, gint *dest_d); + +Q_GSTTOOLS_EXPORT QDebug operator <<(QDebug debug, GstCaps *caps); + +QT_END_NAMESPACE + +#endif diff --git a/src/gsttools/qgstvideobuffer_p.h b/src/gsttools/qgstvideobuffer_p.h new file mode 100644 index 000000000..6681070da --- /dev/null +++ b/src/gsttools/qgstvideobuffer_p.h @@ -0,0 +1,107 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGSTVIDEOBUFFER_P_H +#define QGSTVIDEOBUFFER_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/qgsttools_global_p.h> +#include <qabstractvideobuffer.h> +#include <QtCore/qvariant.h> + +#include <gst/gst.h> +#include <gst/video/video.h> + +QT_BEGIN_NAMESPACE + +#if GST_CHECK_VERSION(1,0,0) +class Q_GSTTOOLS_EXPORT QGstVideoBuffer : public QAbstractPlanarVideoBuffer +{ +public: + QGstVideoBuffer(GstBuffer *buffer, const GstVideoInfo &info); + QGstVideoBuffer(GstBuffer *buffer, const GstVideoInfo &info, + HandleType handleType, const QVariant &handle); +#else +class Q_GSTTOOLS_EXPORT QGstVideoBuffer : public QAbstractVideoBuffer +{ +public: + QGstVideoBuffer(GstBuffer *buffer, int bytesPerLine); + QGstVideoBuffer(GstBuffer *buffer, int bytesPerLine, + HandleType handleType, const QVariant &handle); +#endif + + ~QGstVideoBuffer(); + + GstBuffer *buffer() const { return m_buffer; } + MapMode mapMode() const override; + +#if GST_CHECK_VERSION(1,0,0) + int map(MapMode mode, int *numBytes, int bytesPerLine[4], uchar *data[4]) override; +#else + uchar *map(MapMode mode, int *numBytes, int *bytesPerLine) override; +#endif + + void unmap() override; + + QVariant handle() const override { return m_handle; } +private: +#if GST_CHECK_VERSION(1,0,0) + GstVideoInfo m_videoInfo; + GstVideoFrame m_frame; +#else + int m_bytesPerLine; +#endif + GstBuffer *m_buffer; + MapMode m_mode; + QVariant m_handle; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/gsttools/qgstvideorendererplugin_p.h b/src/gsttools/qgstvideorendererplugin_p.h new file mode 100644 index 000000000..df36dbe09 --- /dev/null +++ b/src/gsttools/qgstvideorendererplugin_p.h @@ -0,0 +1,110 @@ +/**************************************************************************** +** +** 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/qgsttools_global_p.h> +#include <qabstractvideobuffer.h> +#include <qvideosurfaceformat.h> +#include <QtCore/qobject.h> +#include <QtCore/qplugin.h> + +#include <gst/gst.h> + +QT_BEGIN_NAMESPACE + +class QAbstractVideoSurface; + +const QLatin1String QGstVideoRendererPluginKey("gstvideorenderer"); + +class Q_GSTTOOLS_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_GSTTOOLS_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_GSTTOOLS_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/gsttools/qgstvideorenderersink_p.h b/src/gsttools/qgstvideorenderersink_p.h new file mode 100644 index 000000000..d2417a7c9 --- /dev/null +++ b/src/gsttools/qgstvideorenderersink_p.h @@ -0,0 +1,185 @@ +/**************************************************************************** +** +** 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 QGSTVIDEORENDERERSINK_P_H +#define QGSTVIDEORENDERERSINK_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 <gst/video/gstvideosink.h> +#include <gst/video/video.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 "qgstvideorendererplugin_p.h" + +#include "qgstvideorendererplugin_p.h" + +QT_BEGIN_NAMESPACE +class QAbstractVideoSurface; + +class QGstDefaultVideoRenderer : public QGstVideoRenderer +{ +public: + QGstDefaultVideoRenderer(); + ~QGstDefaultVideoRenderer(); + + GstCaps *getCaps(QAbstractVideoSurface *surface) override; + bool start(QAbstractVideoSurface *surface, GstCaps *caps) override; + void stop(QAbstractVideoSurface *surface) override; + + bool proposeAllocation(GstQuery *query) override; + + bool present(QAbstractVideoSurface *surface, GstBuffer *buffer) override; + void flush(QAbstractVideoSurface *surface) override; + +private: + QVideoSurfaceFormat m_format; + GstVideoInfo m_videoInfo; + bool m_flushed; +}; + +class QVideoSurfaceGstDelegate : public QObject +{ + Q_OBJECT +public: + QVideoSurfaceGstDelegate(QAbstractVideoSurface *surface); + ~QVideoSurfaceGstDelegate(); + + GstCaps *caps(); + + bool start(GstCaps *caps); + void stop(); + void unlock(); + bool proposeAllocation(GstQuery *query); + + void flush(); + + GstFlowReturn render(GstBuffer *buffer); + + bool event(QEvent *event) override; + +private slots: + bool handleEvent(QMutexLocker *locker); + void updateSupportedFormats(); + +private: + void notify(); + bool waitForAsyncEvent(QMutexLocker *locker, QWaitCondition *condition, unsigned long time); + + QPointer<QAbstractVideoSurface> m_surface; + + QMutex m_mutex; + QWaitCondition m_setupCondition; + QWaitCondition m_renderCondition; + GstFlowReturn m_renderReturn; + QList<QGstVideoRenderer *> m_renderers; + QGstVideoRenderer *m_renderer; + QGstVideoRenderer *m_activeRenderer; + + GstCaps *m_surfaceCaps; + GstCaps *m_startCaps; + GstBuffer *m_renderBuffer; + + bool m_notified; + bool m_stop; + bool m_flush; +}; + +class Q_GSTTOOLS_EXPORT QGstVideoRendererSink +{ +public: + GstVideoSink parent; + + static QGstVideoRendererSink *createSink(QAbstractVideoSurface *surface); + static void setSurface(QAbstractVideoSurface *surface); + +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 void handleShowPrerollChange(GObject *o, GParamSpec *p, gpointer d); + + static GstStateChangeReturn change_state(GstElement *element, GstStateChange transition); + + static GstCaps *get_caps(GstBaseSink *sink, GstCaps *filter); + static gboolean set_caps(GstBaseSink *sink, GstCaps *caps); + + static gboolean propose_allocation(GstBaseSink *sink, GstQuery *query); + + static gboolean stop(GstBaseSink *sink); + + static gboolean unlock(GstBaseSink *sink); + + static GstFlowReturn show_frame(GstVideoSink *sink, GstBuffer *buffer); + +private: + QVideoSurfaceGstDelegate *delegate; +}; + + +class QGstVideoRendererSinkClass +{ +public: + GstVideoSinkClass parent_class; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/gsttools/qvideosurfacegstsink_p.h b/src/gsttools/qvideosurfacegstsink_p.h new file mode 100644 index 000000000..961cf91d2 --- /dev/null +++ b/src/gsttools/qvideosurfacegstsink_p.h @@ -0,0 +1,192 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef VIDEOSURFACEGSTSINK_P_H +#define VIDEOSURFACEGSTSINK_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 <gst/gst.h> + +#if GST_CHECK_VERSION(1,0,0) + +#include "qgstvideorenderersink_p.h" + +QT_BEGIN_NAMESPACE +typedef QGstVideoRendererSink QVideoSurfaceGstSink; +QT_END_NAMESPACE + +#else + +#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 "qgstbufferpoolinterface_p.h" + +QT_BEGIN_NAMESPACE +class QAbstractVideoSurface; + +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(); + + void unlock(); + + bool isActive(); + + QGstBufferPoolInterface *pool() { return m_pool; } + QMutex *poolMutex() { return &m_poolMutex; } + void clearPoolBuffers(); + + void flush(); + + GstFlowReturn render(GstBuffer *buffer); + +private slots: + void queuedStart(); + void queuedStop(); + void queuedFlush(); + 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; + QGstBufferPoolInterface *m_pool; + QList<QGstBufferPoolInterface *> 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 void setSurface(QAbstractVideoSurface *surface) { Q_UNUSED(surface); } + +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 void handleShowPrerollChange(GObject *o, GParamSpec *p, gpointer d); + + 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); + +#if GST_CHECK_VERSION(0, 10, 25) + static GstFlowReturn show_frame(GstVideoSink *sink, GstBuffer *buffer); +#else + static GstFlowReturn preroll(GstBaseSink *sink, GstBuffer *buffer); + static GstFlowReturn render(GstBaseSink *sink, GstBuffer *buffer); +#endif + +private: + QVideoSurfaceGstDelegate *delegate; + + GstCaps *lastRequestedCaps; + GstCaps *lastBufferCaps; + QVideoSurfaceFormat *lastSurfaceFormat; +}; + +class QVideoSurfaceGstSinkClass +{ +public: + GstVideoSinkClass parent_class; +}; + +QT_END_NAMESPACE + +#endif + +#endif |