Commit 25a526ae authored by Val Doroshchuk's avatar Val Doroshchuk

test

parent 6573ce3c
......@@ -77,7 +77,6 @@ protected:
QPointer<QObject> source;
QPointer<QMediaObject> mediaObject;
QGstreamerPlayerSession *session = nullptr;
GstElement *playbin = nullptr;
QString pipelineDesc;
QString pendingPipelineDesc;
......@@ -140,6 +139,7 @@ void QGstreamerMediaPlayerPrivate::streamsChanged()
{
Q_Q(QGstreamerMediaPlayer);
GstElement *playbin = session ? session->playbin() : nullptr;
if (!playbin)
return;
......@@ -213,18 +213,9 @@ static GstElement *parseDesc(const QString &name)
void QGstreamerMediaPlayerPrivate::updatePipeline()
{
Q_Q(QGstreamerMediaPlayer);
if (pendingPipelineDesc.isEmpty() || !session->renderer())
if (pendingPipelineDesc.isEmpty() || !session->renderer() || !session->renderer()->isReady())
return;
auto videoRenderer = static_cast<QGstreamerVideoRenderer *>(session->renderer());
// Check if the renderer provides a surface.
if (videoRenderer) {
if (!videoRenderer->isReady())
return;
QGstVideoRendererSink::setSurface(videoRenderer->surface());
}
QString p = pendingPipelineDesc;
pendingPipelineDesc.clear();
GstElement *pipeline = parseDesc(p);
......@@ -233,7 +224,6 @@ void QGstreamerMediaPlayerPrivate::updatePipeline()
pipelineDesc = p;
session->setPipeline(pipeline);
playbin = nullptr;
emit q->pipelineChanged();
}
......@@ -305,12 +295,10 @@ void QGstreamerMediaPlayer::setMediaObject(QMediaObject *src)
if (!d->session)
return;
d->playbin = d->session->playbin();
connect(d->session, &QGstreamerPlayerSession::streamsChanged,
d, &QGstreamerMediaPlayerPrivate::streamsChanged);
// Create pipeline when surface is ready.
// Create pipeline when renderer is ready.
connect(d->session, &QGstreamerPlayerSession::rendererChanged,
d, &QGstreamerMediaPlayerPrivate::updatePipeline);
......@@ -351,7 +339,7 @@ void QGstreamerMediaPlayer::setVideoSink(const QString &desc)
Q_D(QGstreamerMediaPlayer);
d->pendingVideoSinkDesc = desc;
if (!d->playbin || d->videoSinkDesc == desc)
if (!d->session || d->videoSinkDesc == desc)
return;
GstElement *videoSink = parseDesc(desc);
......@@ -373,19 +361,20 @@ void QGstreamerMediaPlayer::setShowText(bool show)
Q_D(QGstreamerMediaPlayer);
d->pendingShowText = show;
if (!d->playbin || d->showText == show)
GstElement *playbin = d->session ? d->session->playbin() : nullptr;
if (!playbin || d->showText == show)
return;
d->showText = show;
int flags = 0;
g_object_get(G_OBJECT(d->playbin), "flags", &flags, NULL);
g_object_get(G_OBJECT(playbin), "flags", &flags, NULL);
if (show)
flags |= GST_PLAY_FLAG_TEXT;
else
flags &= ~GST_PLAY_FLAG_TEXT;
g_object_set(G_OBJECT(d->playbin), "flags", flags, NULL);
g_object_set(G_OBJECT(playbin), "flags", flags, NULL);
emit showTextChanged();
}
......@@ -399,13 +388,14 @@ void QGstreamerMediaPlayer::setTextUri(const QUrl &uri)
Q_D(QGstreamerMediaPlayer);
d->pendingTextUri = uri;
if (!d->playbin || d->textUri == uri)
GstElement *playbin = d->session ? d->session->playbin() : nullptr;
if (!playbin || d->textUri == uri)
return;
d->textUri = uri;
setShowText(true);
g_object_set(G_OBJECT(d->playbin), "suburi", uri.toEncoded().constData(), NULL);
g_object_set(G_OBJECT(playbin), "suburi", uri.toEncoded().constData(), NULL);
emit textUriChanged();
}
......@@ -419,11 +409,12 @@ void QGstreamerMediaPlayer::setTextFont(const QString &str)
Q_D(QGstreamerMediaPlayer);
d->pendingTextFont = str;
if (!d->playbin || d->textFont == str)
GstElement *playbin = d->session ? d->session->playbin() : nullptr;
if (!playbin || d->textFont == str)
return;
d->textFont = str;
g_object_set(G_OBJECT(d->playbin), "subtitle-font-desc", str.toUtf8().constData(), NULL);
g_object_set(G_OBJECT(playbin), "subtitle-font-desc", str.toUtf8().constData(), NULL);
emit textFontChanged();
}
......@@ -442,11 +433,12 @@ void QGstreamerMediaPlayer::setAudioStream(int i)
Q_D(QGstreamerMediaPlayer);
d->pendingAudioStream = i;
if (!d->playbin || d->audioStream == i)
GstElement *playbin = d->session ? d->session->playbin() : nullptr;
if (!playbin || d->audioStream == i)
return;
d->audioStream = i;
g_object_set(G_OBJECT(d->playbin), "current-audio", i, NULL);
g_object_set(G_OBJECT(playbin), "current-audio", i, NULL);
emit audioStreamChanged();
}
......@@ -470,11 +462,12 @@ void QGstreamerMediaPlayer::setVideoStream(int i)
Q_D(QGstreamerMediaPlayer);
d->pendingVideoStream = i;
if (!d->playbin || d->videoStream == i)
GstElement *playbin = d->session ? d->session->playbin() : nullptr;
if (!playbin || d->videoStream == i)
return;
d->videoStream = i;
g_object_set(G_OBJECT(d->playbin), "current-video", i, NULL);
g_object_set(G_OBJECT(playbin), "current-video", i, NULL);
emit videoStreamChanged();
}
......@@ -498,11 +491,12 @@ void QGstreamerMediaPlayer::setTextStream(int i)
Q_D(QGstreamerMediaPlayer);
d->pendingTextStream = i;
if (!d->playbin || d->textStream == i)
GstElement *playbin = d->session ? d->session->playbin() : nullptr;
if (!playbin || d->textStream == i)
return;
d->textStream = i;
g_object_set(G_OBJECT(d->playbin), "current-text", i, NULL);
g_object_set(G_OBJECT(playbin), "current-text", i, NULL);
emit textStreamChanged();
}
......@@ -524,15 +518,15 @@ void QGstreamerMediaPlayer::set(const QString &elementName, const QVariantMap& m
GstElement *element = nullptr;
if (elementName == QLatin1String("videoSink"))
element = d->session ? d->session->videoSink() : nullptr;
else if (d->playbin)
element = gst_bin_get_by_name(GST_BIN(d->playbin), elementName.toLatin1().constData());
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;
if (d->playbin) {
if (d->session->pipeline()) {
qWarning() << "Available elements:";
qDebug() << " " << "videoSink";
GstIterator *children = gst_bin_iterate_recurse(GST_BIN(d->playbin));
GstIterator *children = gst_bin_iterate_recurse(GST_BIN(d->session->pipeline()));
gst_iterator_foreach(children, [](const GValue *item, gpointer) {
GstElement *element = GST_ELEMENT(g_value_get_object(item));
qDebug() << " " << GST_ELEMENT_NAME(element);
......
......@@ -54,9 +54,11 @@ private slots:
void testSetTextStream();
void testTextStreamProperties();
void testTextUriStreamProperties();
void testSetProperty();
private:
QMediaPlayer *mediaPlayer = nullptr;
QGstreamerMediaPlayer *control = nullptr;
};
struct Surface : QAbstractVideoSurface
......@@ -82,6 +84,7 @@ void tst_QGstreamerMediaPlayer::init()
{
mediaPlayer = new QMediaPlayer;
mediaPlayer->setMedia(QUrl("qrc:/testdata/colors.mp4"));
control = new QGstreamerMediaPlayer(mediaPlayer);
}
void tst_QGstreamerMediaPlayer::cleanup()
......@@ -91,145 +94,141 @@ void tst_QGstreamerMediaPlayer::cleanup()
void tst_QGstreamerMediaPlayer::testVideoSink()
{
QGstreamerMediaPlayer player(mediaPlayer);
QSignalSpy spy(&player, &QGstreamerMediaPlayer::videoSinkChanged);
QSignalSpy spy(control, &QGstreamerMediaPlayer::videoSinkChanged);
QVERIFY(player.videoSink().isEmpty());
QVERIFY(control->videoSink().isEmpty());
QString sink = "xvimagesink hue=100";
player.setVideoSink(sink);
control->setVideoSink(sink);
QTRY_COMPARE(spy.count(), 1);
QCOMPARE(sink, player.videoSink());
QCOMPARE(sink, control->videoSink());
}
void tst_QGstreamerMediaPlayer::testPipeline()
{
Surface *s = new Surface(mediaPlayer);
mediaPlayer->setVideoOutput(s);
QGstreamerMediaPlayer player(mediaPlayer);
QSignalSpy spy(&player, &QGstreamerMediaPlayer::pipelineChanged);
QSignalSpy spy(control, &QGstreamerMediaPlayer::pipelineChanged);
QVERIFY(player.pipeline().isEmpty());
QVERIFY(control->pipeline().isEmpty());
QString p = "videotestsrc ! autovideosink";
player.setPipeline(p);
control->setPipeline(p);
QTRY_COMPARE(spy.count(), 1);
QCOMPARE(p, player.pipeline());
QCOMPARE(p, control->pipeline());
}
void tst_QGstreamerMediaPlayer::testShowText()
{
QGstreamerMediaPlayer player(mediaPlayer);
QSignalSpy spy(&player, &QGstreamerMediaPlayer::showTextChanged);
QSignalSpy spy(control, &QGstreamerMediaPlayer::showTextChanged);
QVERIFY(!player.showText());
player.setShowText(true);
QVERIFY(player.showText());
QVERIFY(!control->showText());
control->setShowText(true);
QVERIFY(control->showText());
QCOMPARE(spy.count(), 1);
player.setShowText(true);
QVERIFY(player.showText());
control->setShowText(true);
QVERIFY(control->showText());
QCOMPARE(spy.count(), 1);
player.setShowText(false);
QVERIFY(!player.showText());
control->setShowText(false);
QVERIFY(!control->showText());
QCOMPARE(spy.count(), 2);
}
void tst_QGstreamerMediaPlayer::testTextUri()
{
QGstreamerMediaPlayer player(mediaPlayer);
QSignalSpy spy(&player, &QGstreamerMediaPlayer::textUriChanged);
QSignalSpy spy(control, &QGstreamerMediaPlayer::textUriChanged);
QCOMPARE(player.textUri(), QUrl());
QCOMPARE(control->textUri(), QUrl());
QUrl text("text.srt");
player.setTextUri(text);
QVERIFY(player.showText());
QCOMPARE(player.textUri(), text);
control->setTextUri(text);
QVERIFY(control->showText());
QCOMPARE(control->textUri(), text);
QCOMPARE(spy.count(), 1);
}
void tst_QGstreamerMediaPlayer::testTextFont()
{
QGstreamerMediaPlayer player(mediaPlayer);
QSignalSpy spy(&player, &QGstreamerMediaPlayer::textFontChanged);
QSignalSpy spy(control, &QGstreamerMediaPlayer::textFontChanged);
QCOMPARE(player.textFont(), QString());
QCOMPARE(control->textFont(), QString());
QString font = "Sans, 18";
player.setTextFont(font);
QCOMPARE(player.textFont(), font);
control->setTextFont(font);
QCOMPARE(control->textFont(), font);
QCOMPARE(spy.count(), 1);
}
void tst_QGstreamerMediaPlayer::testAudioStreams()
{
QGstreamerMediaPlayer player(mediaPlayer);
QSignalSpy spy(&player, &QGstreamerMediaPlayer::audioStreamsCountChanged);
QSignalSpy spy(control, &QGstreamerMediaPlayer::audioStreamsCountChanged);
QCOMPARE(player.audioStreamsCount(), 0);
QTRY_COMPARE(player.audioStreamsCount(), 1);
QCOMPARE(control->audioStreamsCount(), 0);
QTRY_COMPARE(control->audioStreamsCount(), 1);
QVERIFY(spy.count() > 0);
}
void tst_QGstreamerMediaPlayer::testVideoStreams()
{
QGstreamerMediaPlayer player(mediaPlayer);
QSignalSpy spy(&player, &QGstreamerMediaPlayer::videoStreamsCountChanged);
QSignalSpy spy(control, &QGstreamerMediaPlayer::videoStreamsCountChanged);
QCOMPARE(player.videoStreamsCount(), 0);
QTRY_COMPARE(player.videoStreamsCount(), 1);
QCOMPARE(control->videoStreamsCount(), 0);
QTRY_COMPARE(control->videoStreamsCount(), 1);
QVERIFY(spy.count() > 0);
}
void tst_QGstreamerMediaPlayer::testTextStreams()
{
QGstreamerMediaPlayer player(mediaPlayer);
QSignalSpy spy(&player, &QGstreamerMediaPlayer::textStreamsCountChanged);
QSignalSpy spy(control, &QGstreamerMediaPlayer::textStreamsCountChanged);
QCOMPARE(player.textStreamsCount(), 0);
QTRY_COMPARE(player.textStreamsCount(), 2);
QCOMPARE(control->textStreamsCount(), 0);
QTRY_COMPARE(control->textStreamsCount(), 2);
QVERIFY(spy.count() > 0);
}
void tst_QGstreamerMediaPlayer::testSetTextStream()
{
QGstreamerMediaPlayer player(mediaPlayer);
QSignalSpy spy(&player, &QGstreamerMediaPlayer::textStreamChanged);
QSignalSpy spy(control, &QGstreamerMediaPlayer::textStreamChanged);
QCOMPARE(player.textStream(), -1);
QTRY_COMPARE(player.textStreamsCount(), 2);
player.setTextStream(0);
QCOMPARE(control->textStream(), -1);
QTRY_COMPARE(control->textStreamsCount(), 2);
control->setTextStream(0);
QCOMPARE(spy.count(), 1);
QCOMPARE(player.textStream(), 0);
player.setTextStream(1);
QCOMPARE(control->textStream(), 0);
control->setTextStream(1);
QCOMPARE(spy.count(), 2);
QTRY_COMPARE(player.textStream(), 1);
QTRY_COMPARE(control->textStream(), 1);
}
void tst_QGstreamerMediaPlayer::testTextStreamProperties()
{
QGstreamerMediaPlayer player(mediaPlayer);
QSignalSpy spy(&player, &QGstreamerMediaPlayer::textStreamPropertiesChanged);
QCOMPARE(player.textStreamsCount(), 0);
QTRY_COMPARE(player.textStreamsCount(), 2);
QTRY_COMPARE(player.textStreamProperties(0).size(), 1);
QCOMPARE(player.textStreamProperties(0)["Language"], QVariant("en"));
QCOMPARE(player.textStreamProperties(1).size(), 1);
QCOMPARE(player.textStreamProperties(1)["Language"], QVariant("no"));
QSignalSpy spy(control, &QGstreamerMediaPlayer::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"));
}
void tst_QGstreamerMediaPlayer::testTextUriStreamProperties()
{
QGstreamerMediaPlayer player(mediaPlayer);
QSignalSpy spy(&player, &QGstreamerMediaPlayer::textStreamPropertiesChanged);
QSignalSpy spy(control, &QGstreamerMediaPlayer::textStreamPropertiesChanged);
mediaPlayer->setMedia(QUrl());
player.setTextUri(QUrl::fromLocalFile(QFINDTESTDATA("testdata/text.srt")));
control->setTextUri(QUrl::fromLocalFile(QFINDTESTDATA("testdata/text.srt")));
mediaPlayer->setMedia(QUrl::fromLocalFile(QFINDTESTDATA("testdata/colors.mp4")));
QTRY_COMPARE(player.textStreamsCount(), 3);
QCOMPARE(player.textStreamProperties(0).size(), 0);
QTRY_COMPARE(player.textStreamProperties(1).size(), 1);
QCOMPARE(player.textStreamProperties(1)["Language"], QVariant("en"));
QTRY_COMPARE(player.textStreamProperties(2).size(), 1);
QCOMPARE(player.textStreamProperties(2)["Language"], QVariant("no"));
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"));
}
void tst_QGstreamerMediaPlayer::testSetProperty()
{
QVariantMap m;
m["name"] = "new_name";
control->set("source", m);
}
QTEST_GUILESS_MAIN(tst_QGstreamerMediaPlayer)
......
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