Commit 1797a2f0 authored by Val Doroshchuk's avatar Val Doroshchuk

up

parent 184c72ca
/****************************************************************************
**
** Copyright (C) 2018 The Qt Company Ltd.
** Copyright (C) 2019 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt Toolkit.
......@@ -173,15 +173,17 @@ static void setGstProperty(GstElement *element, const QString &name, T v)
g_object_set(G_OBJECT(element), name.toLatin1().constData(), v, NULL);
}
bool QGstreamerPipeline::set(const QString &elementName, const QVariantMap& map)
bool QGstreamerPipeline::set(const QString &elementName, const QVariantMap &map)
{
Q_D(QGstreamerPipeline);
GstElement *element = nullptr;
if (elementName == QLatin1String("videoSink"))
element = (d->session && d->session->renderer()) ? d->session->renderer()->videoSink() : nullptr;
else if (d->session->pipeline())
element = gst_bin_get_by_name(GST_BIN(d->session->pipeline()), elementName.toLatin1().constData());
if (d->session) {
if (elementName == QLatin1String("videoSink"))
element = d->session->renderer() ? d->session->renderer()->videoSink() : nullptr;
else if (d->session->pipeline())
element = gst_bin_get_by_name(GST_BIN(d->session->pipeline()), elementName.toLatin1().constData());
}
if (!element) {
qWarning() << "Could not find element by name:" << elementName;
......@@ -226,8 +228,6 @@ bool QGstreamerPipeline::set(const QString &elementName, const QVariantMap& map)
return true;
}
#include "moc_qgstreamerpipeline.cpp"
QT_END_NAMESPACE
/****************************************************************************
**
** Copyright (C) 2018 The Qt Company Ltd.
** Copyright (C) 2019 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt Toolkit.
......@@ -94,4 +94,4 @@ private:
QT_END_NAMESPACE
#endif // QGSTREAMERPIPELINE_H
#endif
/****************************************************************************
**
** Copyright (C) 2018 The Qt Company Ltd.
** Copyright (C) 2019 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt Toolkit.
......@@ -82,4 +82,4 @@ protected:
QT_END_NAMESPACE
#endif // QGSTREAMERPIPELINE_P_H
#endif
/****************************************************************************
**
** Copyright (C) 2018 The Qt Company Ltd.
** Copyright (C) 2019 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt Toolkit.
......@@ -44,24 +44,12 @@
QT_BEGIN_NAMESPACE
typedef enum {
GST_PLAY_FLAG_VIDEO = 0x00000001,
GST_PLAY_FLAG_AUDIO = 0x00000002,
GST_PLAY_FLAG_TEXT = 0x00000004,
GST_PLAY_FLAG_VIS = 0x00000008,
GST_PLAY_FLAG_SOFT_VOLUME = 0x00000010,
GST_PLAY_FLAG_NATIVE_AUDIO = 0x00000020,
GST_PLAY_FLAG_NATIVE_VIDEO = 0x00000040,
GST_PLAY_FLAG_DOWNLOAD = 0x00000080,
GST_PLAY_FLAG_BUFFERING = 0x000000100
} GstPlayFlags;
class QGstreamerPlaybinPrivate : public QGstreamerPipelinePrivate
{
Q_DECLARE_PUBLIC(QGstreamerPlaybin)
public:
QGstreamerPlaybinPrivate(QGstreamerPlaybin *q)
QGstreamerPlaybinPrivate(QGstreamerPlaybin *q)
: QGstreamerPipelinePrivate(q)
{
}
......@@ -102,7 +90,12 @@ void QGstreamerPlaybinPrivate::mediaPlayerChanged()
return;
QObject::connect(session, &QGstreamerPlayerSession::streamsChanged,
q, [this]() { streamsChanged(); });
q, [this, q]() {
streamsChanged();
q->setAudioStream(pendingAudioStream);
q->setVideoStream(pendingVideoStream);
q->setTextStream(pendingTextStream);
});
QObject::connect(session, &QGstreamerPlayerSession::rendererChanged,
q, [this]() { updatePlaybin(); });
......@@ -350,7 +343,7 @@ void QGstreamerPlaybin::setAudioStream(int i)
d->pendingAudioStream = i;
GstElement *playbin = pipeline();
if (!playbin || d->audioStream == i)
if (!playbin || d->audioStream == i || i >= d->audioStreamsCount)
return;
d->audioStream = i;
......@@ -379,7 +372,7 @@ void QGstreamerPlaybin::setVideoStream(int i)
d->pendingVideoStream = i;
GstElement *playbin = pipeline();
if (!playbin || d->videoStream == i)
if (!playbin || d->videoStream == i || i >= d->videoStreamsCount)
return;
d->videoStream = i;
......@@ -408,7 +401,7 @@ void QGstreamerPlaybin::setTextStream(int i)
d->pendingTextStream = i;
GstElement *playbin = pipeline();
if (!playbin || d->textStream == i)
if (!playbin || d->textStream == i || i >= d->textStreamsCount)
return;
d->textStream = i;
......@@ -421,6 +414,4 @@ QVariantMap QGstreamerPlaybin::textStreamProperties(int i)
return d_func()->textStreamProperties[i];
}
#include "moc_qgstreamerplaybin.cpp"
QT_END_NAMESPACE
/****************************************************************************
**
** Copyright (C) 2018 The Qt Company Ltd.
** Copyright (C) 2019 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt Toolkit.
......@@ -40,7 +40,7 @@
#ifndef QGSTREAMERPLAYBIN_H
#define QGSTREAMERPLAYBIN_H
#include <QtGstreamerExtras/qgstreamerpipeline.h>
#include "qgstreamerpipeline_p.h"
#include <QVariantMap>
#include <QUrl>
......@@ -118,4 +118,4 @@ private:
QT_END_NAMESPACE
#endif // QGSTREAMERPLAYBIN_H
#endif
......@@ -53,14 +53,13 @@ class QQmlGstreamerExtrasModule : public QQmlExtensionPlugin
Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid)
public:
QQmlGstreamerExtrasModule(QObject *parent = 0) : QQmlExtensionPlugin(parent) { }
QQmlGstreamerExtrasModule(QObject *parent = nullptr) : QQmlExtensionPlugin(parent) { }
void registerTypes(const char *uri) override
{
Q_ASSERT(QLatin1String(uri) == QLatin1String("QtGstreamerExtras"));
qmlRegisterType<QGstreamerPipeline>(uri, 5, 12, "Pipeline");
qmlRegisterType<QGstreamerPlaybin>(uri, 5, 12, "Playbin");
qmlRegisterType<QTransparentRectangle>(uri, 5, 12, "TransparentRectangle");
qmlRegisterType<QGstreamerPipeline>(uri, 5, 12, "GstreamerPipeline");
qmlRegisterType<QGstreamerPlaybin>(uri, 5, 12, "GstreamerPlaybin");
}
};
......
......@@ -57,7 +57,7 @@ QT_BEGIN_NAMESPACE
class QTransparentRectangle : public QQuickRectangle
{
Q_OBJECT
Q_OBJECT
public:
QTransparentRectangle(QQuickItem *parent = nullptr);
......
/****************************************************************************
**
** Copyright (C) 2018 The Qt Company Ltd.
** Copyright (C) 2019 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
......@@ -72,7 +72,7 @@ void tst_QGstreamerPipeline::testMediaPlayer()
{
QMediaPlayer mediaPlayer;
QGstreamerPipeline p(&mediaPlayer);
QVERIFY(!p.source());
QCOMPARE(p.mediaPlayer(), &mediaPlayer);
}
......@@ -102,7 +102,7 @@ void tst_QGstreamerPipeline::testPipelineSurface()
QString pl = "videotestsrc ! xvimagesink name=qtvideosink";
p.setPipeline(pl);
mediaPlayer.play();
mediaPlayer.play();
QTRY_COMPARE(spy.count(), 1);
QCOMPARE(mediaPlayer.error(), QMediaPlayer::NoError);
......
/****************************************************************************
**
** Copyright (C) 2018 The Qt Company Ltd.
** Copyright (C) 2019 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
......@@ -54,8 +54,8 @@ private slots:
void testTextUriStreamProperties();
private:
QMediaPlayer *mediaPlayer = nullptr;
QGstreamerPlaybin *control = nullptr;
QMediaPlayer *m_mediaPlayer = nullptr;
QGstreamerPlaybin *m_gst = nullptr;
};
struct Surface : QAbstractVideoSurface
......@@ -79,135 +79,134 @@ struct Surface : QAbstractVideoSurface
void tst_QGstreamerPlaybin::init()
{
mediaPlayer = new QMediaPlayer;
mediaPlayer->setMedia(QUrl("qrc:/testdata/colors.mp4"));
control = new QGstreamerPlaybin(mediaPlayer);
Surface *s = new Surface(mediaPlayer);
mediaPlayer->setVideoOutput(s);
m_mediaPlayer = new QMediaPlayer;
m_mediaPlayer->setMedia(QUrl("qrc:/testdata/colors.mp4"));
m_gst = new QGstreamerPlaybin(m_mediaPlayer, m_mediaPlayer);
m_mediaPlayer->setVideoOutput(new Surface(m_mediaPlayer));
}
void tst_QGstreamerPlaybin::cleanup()
{
delete mediaPlayer;
delete m_mediaPlayer;
}
void tst_QGstreamerPlaybin::testVideoSink()
{
QSignalSpy spy(control, &QGstreamerPlaybin::videoSinkChanged);
QSignalSpy spy(m_gst, &QGstreamerPlaybin::videoSinkChanged);
QVERIFY(control->videoSink().isEmpty());
QVERIFY(m_gst->videoSink().isEmpty());
QString sink = "xvimagesink hue=100";
control->setVideoSink(sink);
m_gst->setVideoSink(sink);
QTRY_COMPARE(spy.count(), 1);
QCOMPARE(sink, control->videoSink());
QCOMPARE(sink, m_gst->videoSink());
}
void tst_QGstreamerPlaybin::testShowText()
{
QSignalSpy spy(control, &QGstreamerPlaybin::showTextChanged);
QSignalSpy spy(m_gst, &QGstreamerPlaybin::showTextChanged);
QVERIFY(!control->showText());
control->setShowText(true);
QVERIFY(control->showText());
QVERIFY(!m_gst->showText());
m_gst->setShowText(true);
QVERIFY(m_gst->showText());
QCOMPARE(spy.count(), 1);
control->setShowText(true);
QVERIFY(control->showText());
m_gst->setShowText(true);
QVERIFY(m_gst->showText());
QCOMPARE(spy.count(), 1);
control->setShowText(false);
QVERIFY(!control->showText());
m_gst->setShowText(false);
QVERIFY(!m_gst->showText());
QCOMPARE(spy.count(), 2);
}
void tst_QGstreamerPlaybin::testTextUri()
{
QSignalSpy spy(control, &QGstreamerPlaybin::textUriChanged);
QSignalSpy spy(m_gst, &QGstreamerPlaybin::textUriChanged);
QCOMPARE(control->textUri(), QUrl());
QCOMPARE(m_gst->textUri(), QUrl());
QUrl text("text.srt");
control->setTextUri(text);
QVERIFY(control->showText());
QCOMPARE(control->textUri(), text);
m_gst->setTextUri(text);
QVERIFY(m_gst->showText());
QCOMPARE(m_gst->textUri(), text);
QCOMPARE(spy.count(), 1);
}
void tst_QGstreamerPlaybin::testTextFont()
{
QSignalSpy spy(control, &QGstreamerPlaybin::textFontChanged);
QSignalSpy spy(m_gst, &QGstreamerPlaybin::textFontChanged);
QCOMPARE(control->textFont(), QString());
QCOMPARE(m_gst->textFont(), QString());
QString font = "Sans, 18";
control->setTextFont(font);
QCOMPARE(control->textFont(), font);
m_gst->setTextFont(font);
QCOMPARE(m_gst->textFont(), font);
QCOMPARE(spy.count(), 1);
}
void tst_QGstreamerPlaybin::testAudioStreams()
{
QSignalSpy spy(control, &QGstreamerPlaybin::audioStreamsCountChanged);
QSignalSpy spy(m_gst, &QGstreamerPlaybin::audioStreamsCountChanged);
QCOMPARE(control->audioStreamsCount(), 0);
QCOMPARE(m_gst->audioStreamsCount(), 0);
QTRY_VERIFY(spy.count() > 0);
QCOMPARE(control->audioStreamsCount(), 1);
QCOMPARE(m_gst->audioStreamsCount(), 1);
}
void tst_QGstreamerPlaybin::testVideoStreams()
{
QSignalSpy spy(control, &QGstreamerPlaybin::videoStreamsCountChanged);
QSignalSpy spy(m_gst, &QGstreamerPlaybin::videoStreamsCountChanged);
QCOMPARE(control->videoStreamsCount(), 0);
QCOMPARE(m_gst->videoStreamsCount(), 0);
QTRY_VERIFY(spy.count() > 0);
QCOMPARE(control->videoStreamsCount(), 1);
QCOMPARE(m_gst->videoStreamsCount(), 1);
}
void tst_QGstreamerPlaybin::testTextStreams()
{
QSignalSpy spy(control, &QGstreamerPlaybin::textStreamsCountChanged);
QSignalSpy spy(m_gst, &QGstreamerPlaybin::textStreamsCountChanged);
QCOMPARE(control->textStreamsCount(), 0);
QCOMPARE(m_gst->textStreamsCount(), 0);
QTRY_VERIFY(spy.count() > 0);
QCOMPARE(control->textStreamsCount(), 2);
QCOMPARE(m_gst->textStreamsCount(), 2);
}
void tst_QGstreamerPlaybin::testSetTextStream()
{
QSignalSpy spy(control, &QGstreamerPlaybin::textStreamChanged);
QSignalSpy spy(m_gst, &QGstreamerPlaybin::textStreamChanged);
QCOMPARE(control->textStream(), -1);
QTRY_COMPARE(control->textStreamsCount(), 2);
control->setTextStream(0);
QCOMPARE(m_gst->textStream(), -1);
QTRY_COMPARE(m_gst->textStreamsCount(), 2);
m_gst->setTextStream(0);
QCOMPARE(spy.count(), 1);
QCOMPARE(control->textStream(), 0);
control->setTextStream(1);
QCOMPARE(m_gst->textStream(), 0);
m_gst->setTextStream(1);
QCOMPARE(spy.count(), 2);
QTRY_COMPARE(control->textStream(), 1);
QTRY_COMPARE(m_gst->textStream(), 1);
}
void tst_QGstreamerPlaybin::testTextStreamProperties()
{
QSignalSpy spy(control, &QGstreamerPlaybin::textStreamPropertiesChanged);
QCOMPARE(control->textStreamsCount(), 0);
QTRY_COMPARE(control->textStreamsCount(), 2);
QTRY_COMPARE(control->textStreamProperties(0).size(), 1);
QCOMPARE(control->textStreamProperties(0)["Language"], QVariant("en"));
QCOMPARE(control->textStreamProperties(1).size(), 1);
QCOMPARE(control->textStreamProperties(1)["Language"], QVariant("no"));
QSignalSpy spy(m_gst, &QGstreamerPlaybin::textStreamPropertiesChanged);
QCOMPARE(m_gst->textStreamsCount(), 0);
QTRY_COMPARE(m_gst->textStreamsCount(), 2);
QTRY_COMPARE(m_gst->textStreamProperties(0).size(), 1);
QCOMPARE(m_gst->textStreamProperties(0)["Language"], QVariant("en"));
QCOMPARE(m_gst->textStreamProperties(1).size(), 1);
QCOMPARE(m_gst->textStreamProperties(1)["Language"], QVariant("no"));
}
void tst_QGstreamerPlaybin::testTextUriStreamProperties()
{
QSignalSpy spy(control, &QGstreamerPlaybin::textStreamPropertiesChanged);
mediaPlayer->setMedia(QUrl());
control->setTextUri(QUrl::fromLocalFile(QFINDTESTDATA("testdata/text.srt")));
mediaPlayer->setMedia(QUrl::fromLocalFile(QFINDTESTDATA("testdata/colors.mp4")));
QTRY_COMPARE(control->textStreamsCount(), 3);
QCOMPARE(control->textStreamProperties(0).size(), 0);
QTRY_COMPARE(control->textStreamProperties(1).size(), 1);
QCOMPARE(control->textStreamProperties(1)["Language"], QVariant("en"));
QTRY_COMPARE(control->textStreamProperties(2).size(), 1);
QCOMPARE(control->textStreamProperties(2)["Language"], QVariant("no"));
QSignalSpy spy(m_gst, &QGstreamerPlaybin::textStreamPropertiesChanged);
m_mediaPlayer->setMedia(QUrl());
m_gst->setTextUri(QUrl::fromLocalFile(QFINDTESTDATA("testdata/text.srt")));
m_mediaPlayer->setMedia(QUrl::fromLocalFile(QFINDTESTDATA("testdata/colors.mp4")));
QTRY_COMPARE(m_gst->textStreamsCount(), 3);
QCOMPARE(m_gst->textStreamProperties(0).size(), 0);
QTRY_COMPARE(m_gst->textStreamProperties(1).size(), 1);
QCOMPARE(m_gst->textStreamProperties(1)["Language"], QVariant("en"));
QTRY_COMPARE(m_gst->textStreamProperties(2).size(), 1);
QCOMPARE(m_gst->textStreamProperties(2)["Language"], QVariant("no"));
}
QTEST_GUILESS_MAIN(tst_QGstreamerPlaybin)
......
/****************************************************************************
**
** Copyright (C) 2018 The Qt Company Ltd.
** Copyright (C) 2019 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
......@@ -27,7 +27,7 @@
****************************************************************************/
import QtQuick 2.0
import QtMultimedia 5.0
import QtMultimedia 5.9
import QtGstreamerExtras 5.12
import QtTest 1.0
......@@ -45,7 +45,7 @@ Item {
loops: Audio.Infinite
}
Pipeline {
GstreamerPipeline {
id: control
source: player
}
......@@ -74,7 +74,7 @@ Item {
loops: Audio.Infinite
}
Pipeline {
GstreamerPipeline {
id: control2
source: player2
}
......@@ -85,8 +85,26 @@ Item {
signalName: "pipelineChanged"
}
MediaPlayer {
id: player3
autoPlay: false
loops: Audio.Infinite
}
GstreamerPipeline {
id: control3
source: player3
pipeline: "videotestsrc ! autovideosink"
}
SignalSpy {
id: spyPipeline3
target: control3
signalName: "pipelineChanged"
}
TestCase {
name: "GstreamerPipelineControl"
name: "Pipeline"
function initTestCase() {
compare(control.source, player);
......@@ -117,6 +135,9 @@ Item {
compare(spyPipeline2.count, 1);
compare(control2.pipeline, pp);
compare(player2.error, MediaPlayer.NoError);
compare(spyPipeline3.count, 1);
compare(control3.pipeline, pp);
compare(player3.error, MediaPlayer.NoError);
}
}
}
/****************************************************************************
**
** Copyright (C) 2018 The Qt Company Ltd.
** Copyright (C) 2019 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
......@@ -27,7 +27,7 @@
****************************************************************************/
import QtQuick 2.0
import QtMultimedia 5.0
import QtMultimedia 5.9
import QtGstreamerExtras 5.12
import QtTest 1.0
......@@ -49,7 +49,7 @@ Item {
source: srcMp4
}
Playbin {
GstreamerPlaybin {
id: control
source: player
textUri: srcText
......@@ -115,7 +115,7 @@ Item {
}
TestCase {
name: "GstreamerPlayerControl"
name: "Playbin"
function initTestCase() {
compare(control.source, player)
......
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