Commit 27582bd0 authored by Val Doroshchuk's avatar Val Doroshchuk

Remove qml gstreamer media player and add video sink prop

parent 8ef21f1f
......@@ -57,9 +57,14 @@ public:
void setMediaObject(QMediaObject *src);
public Q_SLOTS:
void updateMediaObject();
QPointer<QObject> source;
QPointer<QMediaObject> mediaObject;
QPointer<QGstreamerPlayerSession> session;
QString videoSink;
bool showText = false;
QUrl textUri;
QString textFont;
......@@ -67,56 +72,12 @@ public:
QGstreamerMediaPlayer *q_ptr = nullptr;
};
void QGstreamerMediaPlayerPrivate::setMediaObject(QMediaObject *src)
void QGstreamerMediaPlayerPrivate::updateMediaObject()
{
Q_Q(QGstreamerMediaPlayer);
if (mediaObject == src)
return;
mediaObject.clear();
auto service = src ? src->service() : nullptr;
if (!service)
return;
auto control = qobject_cast<QGstreamerPlayerControl *>(service->requestControl(QMediaPlayerControl_iid));
session = control ? control->session() : nullptr;
if (!session)
return;
connect(session, &QGstreamerPlayerSession::showTextChanged,
q, &QGstreamerMediaPlayer::showTextChanged);
connect(session, &QGstreamerPlayerSession::textUriChanged,
q, &QGstreamerMediaPlayer::textUriChanged);
connect(session, &QGstreamerPlayerSession::textFontChanged,
q, &QGstreamerMediaPlayer::textFontChanged);
connect(session, &QGstreamerPlayerSession::audioStreamsCountChanged,
q, &QGstreamerMediaPlayer::audioStreamsCountChanged);
connect(session, &QGstreamerPlayerSession::audioStreamChanged,
q, &QGstreamerMediaPlayer::audioStreamChanged);
connect(session, &QGstreamerPlayerSession::audioStreamPropertiesChanged,
q, &QGstreamerMediaPlayer::audioStreamPropertiesChanged);
connect(session, &QGstreamerPlayerSession::videoStreamsCountChanged,
q, &QGstreamerMediaPlayer::videoStreamsCountChanged);
connect(session, &QGstreamerPlayerSession::videoStreamChanged,
q, &QGstreamerMediaPlayer::videoStreamChanged);
connect(session, &QGstreamerPlayerSession::videoStreamPropertiesChanged,
q, &QGstreamerMediaPlayer::videoStreamPropertiesChanged);
connect(session, &QGstreamerPlayerSession::textStreamsCountChanged,
q, &QGstreamerMediaPlayer::textStreamsCountChanged);
connect(session, &QGstreamerPlayerSession::textStreamChanged,
q, &QGstreamerMediaPlayer::textStreamChanged);
connect(session, &QGstreamerPlayerSession::textStreamPropertiesChanged,
q, &QGstreamerMediaPlayer::textStreamPropertiesChanged);
connect(session, &QGstreamerPlayerSession::streamsChanged,
q, &QGstreamerMediaPlayer::streamsChanged);
mediaObject = src;
emit q->mediaObjectChanged();
QMediaObject *obj = qobject_cast<QMediaObject*>(source->property("mediaObject").value<QObject*>());
q->setMediaObject(obj);
}
QGstreamerMediaPlayer::QGstreamerMediaPlayer(QMediaObject *player, QObject *parent)
......@@ -138,14 +99,125 @@ QGstreamerMediaPlayer::~QGstreamerMediaPlayer()
d->session.clear();
}
QObject *QGstreamerMediaPlayer::mediaObject() const
QObject *QGstreamerMediaPlayer::source() const
{
return d_func()->source.data();
}
void QGstreamerMediaPlayer::setSource(QObject *src)
{
Q_D(QGstreamerMediaPlayer);
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 *QGstreamerMediaPlayer::mediaObject() const
{
return d_func()->mediaObject.data();
}
void QGstreamerMediaPlayer::setMediaObject(QObject *source)
void QGstreamerMediaPlayer::setMediaObject(QMediaObject *src)
{
Q_D(QGstreamerMediaPlayer);
if (d->mediaObject == src)
return;
d->mediaObject.clear();
auto service = src ? src->service() : nullptr;
if (!service)
return;
auto control = qobject_cast<QGstreamerPlayerControl *>(service->requestControl(QMediaPlayerControl_iid));
d->session = control ? control->session() : nullptr;
if (!d->session)
return;
connect(d->session, &QGstreamerPlayerSession::videoSinkChanged,
this, &QGstreamerMediaPlayer::videoSinkChanged);
connect(d->session, &QGstreamerPlayerSession::showTextChanged,
this, &QGstreamerMediaPlayer::showTextChanged);
connect(d->session, &QGstreamerPlayerSession::textUriChanged,
this, &QGstreamerMediaPlayer::textUriChanged);
connect(d->session, &QGstreamerPlayerSession::textFontChanged,
this, &QGstreamerMediaPlayer::textFontChanged);
connect(d->session, &QGstreamerPlayerSession::audioStreamsCountChanged,
this, &QGstreamerMediaPlayer::audioStreamsCountChanged);
connect(d->session, &QGstreamerPlayerSession::audioStreamChanged,
this, &QGstreamerMediaPlayer::audioStreamChanged);
connect(d->session, &QGstreamerPlayerSession::audioStreamPropertiesChanged,
this, &QGstreamerMediaPlayer::audioStreamPropertiesChanged);
connect(d->session, &QGstreamerPlayerSession::videoStreamsCountChanged,
this, &QGstreamerMediaPlayer::videoStreamsCountChanged);
connect(d->session, &QGstreamerPlayerSession::videoStreamChanged,
this, &QGstreamerMediaPlayer::videoStreamChanged);
connect(d->session, &QGstreamerPlayerSession::videoStreamPropertiesChanged,
this, &QGstreamerMediaPlayer::videoStreamPropertiesChanged);
connect(d->session, &QGstreamerPlayerSession::textStreamsCountChanged,
this, &QGstreamerMediaPlayer::textStreamsCountChanged);
connect(d->session, &QGstreamerPlayerSession::textStreamChanged,
this, &QGstreamerMediaPlayer::textStreamChanged);
connect(d->session, &QGstreamerPlayerSession::textStreamPropertiesChanged,
this, &QGstreamerMediaPlayer::textStreamPropertiesChanged);
connect(d->session, &QGstreamerPlayerSession::streamsChanged,
this, &QGstreamerMediaPlayer::streamsChanged);
d->mediaObject = src;
emit mediaObjectChanged();
// In case if these values've been applied
// before mediaObject is available.
qDebug()<<__FUNCTION__<<"d->showText"<<d->showText;
setVideoSink(d->videoSink);
setShowText(d->showText);
setTextUri(d->textUri);
setTextFont(d->textFont);
}
QString QGstreamerMediaPlayer::videoSink() const
{
Q_D(const QGstreamerMediaPlayer);
return d->session ? d->session->videoSink() : d->videoSink;
}
void QGstreamerMediaPlayer::setVideoSink(const QString &name)
{
d_func()->setMediaObject(qobject_cast<QMediaObject *>(source));
Q_D(QGstreamerMediaPlayer);
d->videoSink = name;
if (d->session)
d->session->setVideoSink(name);
}
bool QGstreamerMediaPlayer::showText() const
......@@ -176,7 +248,7 @@ void QGstreamerMediaPlayer::setTextUri(const QUrl &url)
Q_D(QGstreamerMediaPlayer);
d->textUri = url;
setShowText(true);
setShowText(!url.isEmpty());
if (d->session)
d->session->setTextUri(url);
}
......
......@@ -50,7 +50,9 @@ class QGstreamerMediaPlayerPrivate;
class Q_MULTIMEDIA_EXPORT QGstreamerMediaPlayer : public QObject
{
Q_OBJECT
Q_PROPERTY(QObject* mediaObject READ mediaObject NOTIFY mediaObjectChanged SCRIPTABLE false DESIGNABLE false)
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 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)
......@@ -66,8 +68,14 @@ public:
QGstreamerMediaPlayer(QObject *parent = nullptr);
~QGstreamerMediaPlayer();
QObject *mediaObject() const;
void setMediaObject(QObject *source);
QObject *source() const;
void setSource(QObject *source);
QMediaObject *mediaObject() const;
void setMediaObject(QMediaObject *source);
QString videoSink() const;
void setVideoSink(const QString &name);
bool showText() const;
void setShowText(bool show);
......@@ -94,7 +102,10 @@ public:
Q_INVOKABLE QVariantMap textStreamProperties(int i);
Q_SIGNALS:
void sourceChanged();
void mediaObjectChanged();
void videoSinkChanged();
void showTextChanged();
void textUriChanged();
void textFontChanged();
......
......@@ -42,7 +42,7 @@
#include <QtQml/qqmlengine.h>
#include <QtQml/qqmlcomponent.h>
#include "qqmlgstreamermediaplayer_p.h"
#include "qgstreamermediaplayer.h"
QT_BEGIN_NAMESPACE
......@@ -57,7 +57,7 @@ public:
{
Q_ASSERT(QLatin1String(uri) == QLatin1String("QtGstreamerExtras"));
qmlRegisterType<QQmlGstreamerMediaPlayer>(uri, 5, 12, "GstreamerMediaPlayer");
qmlRegisterType<QGstreamerMediaPlayer>(uri, 5, 12, "GstreamerMediaPlayer");
}
};
......
......@@ -2,14 +2,10 @@ CXX_MODULE = gstreamerextras
TARGET = declarative_gstreamer
TARGETPATH = QtGstreamerExtras
QT += gstreamerextras qtmultimediaquicktools-private
HEADERS += \
qqmlgstreamermediaplayer_p.h
QT += gstreamerextras qtmultimediaquicktools-private multimedia-private
SOURCES += \
gstreamerextras.cpp \
qqmlgstreamermediaplayer.cpp
gstreamerextras.cpp
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
......
/****************************************************************************
**
** 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 <QtQml/qqmlinfo.h>
#include "qqmlgstreamermediaplayer_p.h"
#include "qmediaservice.h"
#include <private/qgstreamerplayersession_p.h>
#include <QtQml/qqmlengine.h>
QT_BEGIN_NAMESPACE
QQmlGstreamerMediaPlayer::QQmlGstreamerMediaPlayer(QObject *parent)
: QGstreamerMediaPlayer(parent)
{
}
QQmlGstreamerMediaPlayer::~QQmlGstreamerMediaPlayer()
{
m_source.clear();
}
QObject *QQmlGstreamerMediaPlayer::source() const
{
return m_source.data();
}
void QQmlGstreamerMediaPlayer::setSource(QObject *source)
{
if (m_source == source)
return;
if (m_source)
disconnect(m_source.data(), 0, this, SLOT(_q_updateMediaObject()));
m_source = source;
if (m_source) {
const QMetaObject *metaObject = m_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(m_source.data(), method.methodIndex(),
this, this->metaObject()->indexOfSlot("_q_updateMediaObject()"),
Qt::DirectConnection, 0);
}
}
}
_q_updateMediaObject();
emit sourceChanged();
}
void QQmlGstreamerMediaPlayer::_q_updateMediaObject()
{
QMediaObject *mediaObject = m_source
? qobject_cast<QMediaObject *>(m_source->property("mediaObject").value<QObject *>())
: nullptr;
if (m_mediaObject == mediaObject)
return;
m_mediaObject = mediaObject;
}
void QQmlGstreamerMediaPlayer::classBegin()
{
}
void QQmlGstreamerMediaPlayer::componentComplete()
{
if (!m_mediaObject)
return;
// In case if these values've been applied
// before mediaObject is available.
bool show = showText();
QUrl uri = textUri();
QString font = textFont();
setMediaObject(m_mediaObject);
setShowText(show);
setTextUri(uri);
setTextFont(font);
}
QT_END_NAMESPACE
#include "moc_qqmlgstreamermediaplayer_p.cpp"
/****************************************************************************
**
** 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 QQMLGSTREAMERMEDIAPLAYER_P_H
#define QQMLGSTREAMERMEDIAPLAYER_P_H
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists for the convenience
// of other Qt classes. This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//
#include <private/qtmultimediaquickdefs_p.h>
#include <QGstreamerMediaPlayer>
#include <QtQuick/qquickitem.h>
#include <QtCore/qpointer.h>
#include <QUrl>
#include <QString>
QT_BEGIN_NAMESPACE
class QMediaObject;
class QQmlGstreamerMediaPlayer : public QGstreamerMediaPlayer, public QQmlParserStatus
{
Q_OBJECT
Q_DISABLE_COPY(QQmlGstreamerMediaPlayer)
Q_PROPERTY(QObject* source READ source WRITE setSource NOTIFY sourceChanged)
Q_INTERFACES(QQmlParserStatus)
public:
QQmlGstreamerMediaPlayer(QObject *parent = nullptr);
~QQmlGstreamerMediaPlayer();
void classBegin() override;
void componentComplete() override;
QObject *source() const;
void setSource(QObject *source);
Q_SIGNALS:
void sourceChanged();
private Q_SLOTS:
void _q_updateMediaObject();
private:
QPointer<QObject> m_source;
QPointer<QMediaObject> m_mediaObject;
};
QT_END_NAMESPACE
QML_DECLARE_TYPE(QT_PREPEND_NAMESPACE(QQmlGstreamerMediaPlayer))
#endif // QQMLGSTREAMERMEDIAPLAYER_P_H
CONFIG += testcase
TARGET = tst_qgstreamermediaplayer
QT += network gstreamer-private multimedia-private testlib
QT += network gstreamerextras-private multimedia-private testlib
SOURCES += tst_qgstreamermediaplayer.cpp
RESOURCES += testdata.qrc
\ No newline at end of file
......@@ -42,6 +42,7 @@ public slots:
void cleanup();
private slots:
void testVideoSink();
void testShowText();
void testTextUri();
void testTextFont();
......@@ -68,6 +69,18 @@ void tst_QGstreamerMediaPlayer::cleanup()
delete mediaPlayer;
}
void tst_QGstreamerMediaPlayer::testVideoSink()
{
QGstreamerMediaPlayer player(mediaPlayer);
QSignalSpy spy(&player, &QGstreamerMediaPlayer::videoSinkChanged);
QVERIFY(player.videoSink().isEmpty());
QString sink = "xvimagesink hue=100";
player.setVideoSink(sink);
QCOMPARE(sink, player.videoSink());
QCOMPARE(spy.count(), 1);
}
void tst_QGstreamerMediaPlayer::testShowText()
{
QGstreamerMediaPlayer player(mediaPlayer);
......
......@@ -53,6 +53,13 @@ Item {
id: control
source: player
textUri: srcText
videoSink: "xvimagesink pixel-aspect-ratio=\"1/2\""
}
SignalSpy {
id: spyVideoSink
target: control
signalName: "videoSinkChanged"
}
SignalSpy {
......@@ -114,6 +121,11 @@ Item {
compare(control.source, player)
}
function test_videoSink() {
compare(spyVideoSink.count, 1);
compare(control.videoSink, "xvimagesink pixel-aspect-ratio=\"1/2\"")
}
function test_showText() {
spyShowText.clear()
verify(control.showText)
......
......@@ -3,7 +3,7 @@ TARGET=tst_qml
CONFIG += qmltestcase
SOURCES += tst_qml.cpp
importFiles.files = playercontrol
importFiles.files = player
importFiles.path = .
DEPLOYMENT += importFiles
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