Commit 24638fbb authored by Val Doroshchuk's avatar Val Doroshchuk

Reverted to GstreamerMediaPlayer

parent 4d56161c
......@@ -2,18 +2,9 @@ TARGET = QtGstreamerExtras
QT += multimediagsttools-private
CONFIG += simd optimize_full
PUBLIC_HEADERS += \
qgstreamerpipeline.h \
qgstreamerplaybin.h
include(playback/playback.pri)
PRIVATE_HEADERS += \
qgstreamerpipeline_p.h
SOURCES += \
qgstreamerpipeline.cpp \
qgstreamerplaybin.cpp
CONFIG += simd optimize_full
HEADERS += $$PUBLIC_HEADERS $$PRIVATE_HEADERS
......
INCLUDEPATH += playback
PUBLIC_HEADERS += \
playback/qgstreamermediaplayer.h
SOURCES += \
playback/qgstreamermediaplayer.cpp
......@@ -37,18 +37,25 @@
**
****************************************************************************/
#ifndef QGSTREAMERPLAYBIN_H
#define QGSTREAMERPLAYBIN_H
#ifndef QGSTREAMERMEDIAPLAYER_H
#define QGSTREAMERMEDIAPLAYER_H
#include "qgstreamerpipeline.h"
#include <QObject>
#include <QVariantMap>
#include <QtMultimedia/qtmultimediaglobal.h>
#include <QUrl>
QT_BEGIN_NAMESPACE
class QGstreamerPlaybinPrivate;
class Q_MULTIMEDIA_EXPORT QGstreamerPlaybin : public QGstreamerPipeline
class QMediaObject;
class QGstreamerMediaPlayerPrivate;
class Q_MULTIMEDIA_EXPORT QGstreamerMediaPlayer : public QObject
{
Q_OBJECT
Q_PROPERTY(QObject* source READ source WRITE setSource NOTIFY sourceChanged)
Q_PROPERTY(QMediaObject* mediaObject READ mediaObject NOTIFY mediaObjectChanged SCRIPTABLE false DESIGNABLE false)
Q_PROPERTY(QString pipeline READ pipeline WRITE setPipeline NOTIFY pipelineChanged)
Q_PROPERTY(QString videoSink READ videoSink WRITE setVideoSink NOTIFY videoSinkChanged)
Q_PROPERTY(bool showText READ showText WRITE setShowText NOTIFY showTextChanged)
Q_PROPERTY(QUrl textUri READ textUri WRITE setTextUri NOTIFY textUriChanged)
Q_PROPERTY(QString textFont READ textFont WRITE setTextFont NOTIFY textFontChanged)
......@@ -60,8 +67,20 @@ class Q_MULTIMEDIA_EXPORT QGstreamerPlaybin : public QGstreamerPipeline
Q_PROPERTY(int textStream READ textStream WRITE setTextStream NOTIFY textStreamChanged)
public:
QGstreamerPlaybin(QMediaObject *player, QObject *parent = nullptr);
QGstreamerPlaybin(QObject *parent = nullptr);
QGstreamerMediaPlayer(QMediaObject *player, QObject *parent = nullptr);
QGstreamerMediaPlayer(QObject *parent = nullptr);
QObject *source() const;
void setSource(QObject *source);
QMediaObject *mediaObject() const;
void setMediaObject(QMediaObject *source);
QString pipeline() const;
void setPipeline(const QString &name);
QString videoSink() const;
void setVideoSink(const QString &name);
bool showText() const;
void setShowText(bool show);
......@@ -87,7 +106,13 @@ public:
void setTextStream(int i);
Q_INVOKABLE QVariantMap textStreamProperties(int i);
Q_INVOKABLE void set(const QString &elementName, const QVariantMap& map);
Q_SIGNALS:
void sourceChanged();
void mediaObjectChanged();
void pipelineChanged();
void videoSinkChanged();
void showTextChanged();
void textUriChanged();
void textFontChanged();
......@@ -105,10 +130,12 @@ Q_SIGNALS:
void textStreamPropertiesChanged();
private:
Q_DISABLE_COPY(QGstreamerPlaybin)
Q_DECLARE_PRIVATE(QGstreamerPlaybin)
Q_DISABLE_COPY(QGstreamerMediaPlayer)
Q_DECLARE_PRIVATE(QGstreamerMediaPlayer)
QGstreamerMediaPlayerPrivate *d_ptr = nullptr;
};
QT_END_NAMESPACE
#endif // QGSTREAMERPLAYBIN_H
#endif // QGSTREAMERMEDIAPLAYER_H
/****************************************************************************
**
** Copyright (C) 2018 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or (at your option) the GNU General
** Public license version 3 or any later version approved by the KDE Free
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qgstreamerpipeline_p.h"
#include <private/qgstvideorenderersink_p.h>
#include <QMediaObject>
#include <QtCore/qmetaobject.h>
#include <QDebug>
QT_BEGIN_NAMESPACE
QGstreamerPipelinePrivate::QGstreamerPipelinePrivate(QGstreamerPipeline *parent)
: q_ptr(parent)
{
}
QGstreamerPipelinePrivate::~QGstreamerPipelinePrivate()
{
if (pipeline)
gst_object_unref(GST_OBJECT(pipeline));
}
void QGstreamerPipelinePrivate::updateMediaObject()
{
Q_Q(QGstreamerPipeline);
QMediaObject *obj = qobject_cast<QMediaObject*>(source->property("mediaObject").value<QObject*>());
q->setMediaObject(obj);
}
static GstElement *parseDesc(const QString &name)
{
GError *error = NULL;
GstElement *element = gst_parse_launch(name.toLatin1().constData(), &error);
if (error) {
g_printerr("ERROR: %s: %s\n", name.toLatin1().constData(), GST_STR_NULL(error->message));
g_clear_error(&error);
}
return element;
}
void QGstreamerPipelinePrivate::updatePipeline()
{
Q_Q(QGstreamerPipeline);
if (!renderer || !renderer->isReady())
return;
if (!pendingPipelineDesc.isEmpty()) {
QGstVideoRendererSink::setSurface(renderer->surface());
pipeline = parseDesc(pendingPipelineDesc);
if (pipeline) {
pipelineDesc = pendingPipelineDesc;
pendingPipelineDesc.clear();
emit q->pipelineChanged();
}
} else if (!pendingVideoSinkDesc.isEmpty()) {
GstElement *videoSink = parseDesc(pendingVideoSinkDesc);
if (videoSink) {
videoSinkDesc = pendingVideoSinkDesc;
pendingVideoSinkDesc.clear();
renderer->setVideoSink(videoSink);
emit q->videoSinkChanged();
}
}
}
QGstreamerPipeline::QGstreamerPipeline(QGstreamerPipelinePrivate *d, QObject *parent)
: QObject(parent)
, d_ptr(d)
{
}
QGstreamerPipeline::~QGstreamerPipeline()
{
delete d_ptr;
}
QObject *QGstreamerPipeline::source() const
{
return d_func()->source.data();
}
void QGstreamerPipeline::setSource(QObject *src)
{
Q_D(QGstreamerPipeline);
if (d->source == src)
return;
if (d->source)
disconnect(d->source.data(), 0, d, SLOT(updateMediaObject()));
d->source = src;
if (d->source) {
const QMetaObject *metaObject = d->source->metaObject();
int mediaObjectPropertyIndex = metaObject->indexOfProperty("mediaObject");
if (mediaObjectPropertyIndex != -1) {
const QMetaProperty mediaObjectProperty = metaObject->property(mediaObjectPropertyIndex);
if (mediaObjectProperty.hasNotifySignal()) {
QMetaMethod method = mediaObjectProperty.notifySignal();
QMetaObject::connect(d->source.data(), method.methodIndex(),
d, d->metaObject()->indexOfSlot("updateMediaObject()"),
Qt::DirectConnection, 0);
}
}
}
d->updateMediaObject();
emit sourceChanged();
}
QMediaObject *QGstreamerPipeline::mediaObject() const
{
return d_func()->mediaObject.data();
}
void QGstreamerPipeline::setMediaObject(QMediaObject *src)
{
Q_D(QGstreamerPipeline);
if (d->mediaObject == src)
return;
d->mediaObject = src;
emit mediaObjectChanged();
}
QString QGstreamerPipeline::pipeline() const
{
return d_func()->pipelineDesc;
}
void QGstreamerPipeline::setPipeline(const QString &desc)
{
Q_D(QGstreamerPipeline);
d->pendingPipelineDesc = desc;
if (d->pipelineDesc == desc)
return;
d->updatePipeline();
}
QString QGstreamerPipeline::videoSink() const
{
return d_func()->videoSinkDesc;
}
void QGstreamerPipeline::setVideoSink(const QString &desc)
{
Q_D(QGstreamerPipeline);
d->pendingVideoSinkDesc = desc;
if (d->videoSinkDesc == desc)
return;
d->updatePipeline();
}
template <class T>
static void setGstProperty(GstElement *element, const QString &name, T v)
{
g_object_set(G_OBJECT(element), name.toLatin1().constData(), v, NULL);
}
void QGstreamerPipeline::set(const QString &elementName, const QVariantMap& map)
{
Q_D(QGstreamerPipeline);
GstElement *element = nullptr;
if (elementName == QLatin1String("videoSink"))
element = d->renderer ? d->renderer->videoSink() : nullptr;
else if (d->pipeline)
element = gst_bin_get_by_name(GST_BIN(d->pipeline), elementName.toLatin1().constData());
if (!element) {
qWarning() << "Could not find element by name:" << elementName;
if (d->pipeline) {
qWarning() << "Available elements:";
qDebug() << " " << "videoSink";
GstIterator *children = gst_bin_iterate_recurse(GST_BIN(d->pipeline));
gst_iterator_foreach(children, [](const GValue *item, gpointer) {
GstElement *element = GST_ELEMENT(g_value_get_object(item));
qDebug() << " " << GST_ELEMENT_NAME(element);
}, nullptr);
gst_iterator_free(children);
} else {
qWarning() << "No pipeline available";
}
return;
}
for (auto it = map.begin(); it != map.end(); ++it) {
QString name = it.key();
QVariant value = it.value();
switch (value.type()) {
case QMetaType::Int:
setGstProperty(element, name, value.toInt());
break;
case QMetaType::Bool:
setGstProperty(element, name, value.toBool());
break;
case QMetaType::Double:
setGstProperty(element, name, value.toDouble());
break;
case QMetaType::QString:
setGstProperty(element, name, value.toString().toUtf8().constData());
break;
default:
break;
}
}
}
#include "moc_qgstreamerpipeline_p.cpp"
QT_END_NAMESPACE
/****************************************************************************
**
** Copyright (C) 2018 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or (at your option) the GNU General
** Public license version 3 or any later version approved by the KDE Free
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QGSTREAMERPIPELINE_H
#define QGSTREAMERPIPELINE_H
#include <QObject>
#include <QVariantMap>
#include <QtMultimedia/qtmultimediaglobal.h>
QT_BEGIN_NAMESPACE
class QMediaObject;
class QGstreamerPipelinePrivate;
class Q_MULTIMEDIA_EXPORT QGstreamerPipeline : public QObject
{
Q_OBJECT
Q_PROPERTY(QObject* source READ source WRITE setSource NOTIFY sourceChanged)
Q_PROPERTY(QMediaObject* mediaObject READ mediaObject NOTIFY mediaObjectChanged SCRIPTABLE false DESIGNABLE false)
Q_PROPERTY(QString pipeline READ pipeline WRITE setPipeline NOTIFY pipelineChanged)
Q_PROPERTY(QString videoSink READ videoSink WRITE setVideoSink NOTIFY videoSinkChanged)
public:
~QGstreamerPipeline();
QObject *source() const;
void setSource(QObject *source);
QMediaObject *mediaObject() const;
void setMediaObject(QMediaObject *source);
QString pipeline() const;
void setPipeline(const QString &name);
QString videoSink() const;
void setVideoSink(const QString &name);
Q_INVOKABLE void set(const QString &elementName, const QVariantMap& map);
Q_SIGNALS:
void sourceChanged();
void mediaObjectChanged();
void pipelineChanged();
void videoSinkChanged();
protected:
QGstreamerPipeline(QGstreamerPipelinePrivate *d, QObject *parent = nullptr);
QGstreamerPipelinePrivate *d_ptr = nullptr;
private:
Q_DISABLE_COPY(QGstreamerPipeline)
Q_DECLARE_PRIVATE(QGstreamerPipeline)
};
QT_END_NAMESPACE
#endif // QGSTREAMERPIPELINE_H
/****************************************************************************
**
** Copyright (C) 2018 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or (at your option) the GNU General
** Public license version 3 or any later version approved by the KDE Free
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QGSTREAMERPIPELINE_P_H
#define QGSTREAMERPIPELINE_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 "qgstreamerpipeline.h"
#include <private/qgstreamervideorenderer_p.h>
#include <QPointer>
#include <gst/gst.h>
class QMediaService;
class QGstreamerVideoRendererInterface;
class QGstreamerPipelinePrivate : public QObject
{
Q_DECLARE_PUBLIC(QGstreamerPipeline)
Q_OBJECT
public:
QGstreamerPipelinePrivate(QGstreamerPipeline *pipeline);
~QGstreamerPipelinePrivate();
public Q_SLOTS:
void updateMediaObject();
protected:
void updatePipeline();
QPointer<QObject> source;
QPointer<QMediaObject> mediaObject;
QGstreamerVideoRenderer *renderer = nullptr;
QString pipelineDesc;
QString pendingPipelineDesc;
GstElement *pipeline = nullptr;
QString videoSinkDesc;
QString pendingVideoSinkDesc;
QGstreamerPipeline *q_ptr = nullptr;
};
QT_END_NAMESPACE
#endif
......@@ -42,7 +42,7 @@
#include <QtQml/qqmlengine.h>
#include <QtQml/qqmlcomponent.h>
#include "qgstreamerplaybin.h"
#include "qgstreamermediaplayer.h"
#include "qtransparentrectangle_p.h"
QT_BEGIN_NAMESPACE
......@@ -58,7 +58,7 @@ public:
{
Q_ASSERT(QLatin1String(uri) == QLatin1String("QtGstreamerExtras"));
qmlRegisterType<QGstreamerPlaybin>(uri, 5, 12, "GstreamerPlaybin");
qmlRegisterType<QGstreamerMediaPlayer>(uri, 5, 12, "GstreamerMediaPlayer");
qmlRegisterType<QTransparentRectangle>(uri, 5, 12, "TransparentRectangle");
}
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment