Commit 51203914 authored by Val Doroshchuk's avatar Val Doroshchuk

VideoSink

parent 8e77ff6b
......@@ -213,16 +213,43 @@ static GstElement *parseDesc(const QString &name)
void QGstreamerMediaPlayerPrivate::updatePipeline()
{
Q_Q(QGstreamerMediaPlayer);
if (pendingPipelineDesc.isEmpty() || !session->renderer() || !session->renderer()->isReady())
return;
GstElement *pipeline = parseDesc(pendingPipelineDesc);
if (!pipeline)
auto renderer = session->renderer();
if (!renderer || !renderer->isReady())
return;
pipelineDesc = pendingPipelineDesc;
session->setPipeline(pipeline);
emit q->pipelineChanged();
if (!pendingVideoSinkDesc.isEmpty()) {
GstElement *videoSink = parseDesc(pendingVideoSinkDesc);
if (videoSink) {
videoSinkDesc = pendingVideoSinkDesc;
pendingVideoSinkDesc.clear();
renderer->setVideoSink(videoSink);
emit q->videoSinkChanged();
}
}
if (!pendingPipelineDesc.isEmpty()) {
GstElement *pipeline = parseDesc(pendingPipelineDesc);
if (pipeline) {
pipelineDesc = pendingPipelineDesc;
pendingPipelineDesc.clear();
session->setPipeline(pipeline);
emit q->pipelineChanged();
auto it = gst_bin_iterate_sinks(GST_BIN(pipeline));
GValue data = { 0, 0 };
while (gst_iterator_next (it, &data) == GST_ITERATOR_OK) {
auto child = (GstElement*) g_value_get_object(&data);
if (QLatin1String(GST_OBJECT_NAME(child)) == QLatin1String("qtvideosink")) {
renderer->setVideoSink(child);
break;
}
}
gst_iterator_free(it);
}
}
}
QGstreamerMediaPlayer::QGstreamerMediaPlayer(QMediaObject *media, QObject *parent)
......@@ -302,7 +329,6 @@ void QGstreamerMediaPlayer::setMediaObject(QMediaObject *src)
// In case if these values've been applied
// before mediaObject is available.
setVideoSink(d->pendingVideoSinkDesc);
setShowText(d->pendingShowText);
setTextUri(d->pendingTextUri);
setTextFont(d->pendingTextFont);
......@@ -340,13 +366,7 @@ void QGstreamerMediaPlayer::setVideoSink(const QString &desc)
if (!d->session || d->videoSinkDesc == desc)
return;
GstElement *videoSink = parseDesc(desc);
if (!videoSink)
return;
d->videoSinkDesc = desc;
d->session->setVideoSink(videoSink);
emit videoSinkChanged();
d->updatePipeline();
}
bool QGstreamerMediaPlayer::showText() const
......@@ -515,7 +535,7 @@ bool QGstreamerMediaPlayer::set(const QString &elementName, const QVariantMap& m
GstElement *element = nullptr;
if (elementName == QLatin1String("videoSink"))
element = d->session ? d->session->videoSink() : nullptr;
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());
......
......@@ -71,13 +71,13 @@ struct Surface : QAbstractVideoSurface
QList<QVideoFrame::PixelFormat> supportedPixelFormats(
QAbstractVideoBuffer::HandleType) const override
{
return QList<QVideoFrame::PixelFormat>() << QVideoFrame::Format_RGB32;
return QList<QVideoFrame::PixelFormat>() << QVideoFrame::Format_ARGB32;
}
bool isFormatSupported(const QVideoSurfaceFormat &) const override { return false; }
bool start(const QVideoSurfaceFormat &) override { return false; }
bool isFormatSupported(const QVideoSurfaceFormat &) const override { return true; }
bool start(const QVideoSurfaceFormat &) override { return true; }
void stop() override { }
bool present(const QVideoFrame &) override { return false; }
bool present(const QVideoFrame &) override { return true; }
};
void tst_QGstreamerMediaPlayer::init()
......@@ -85,6 +85,8 @@ void tst_QGstreamerMediaPlayer::init()
mediaPlayer = new QMediaPlayer;
mediaPlayer->setMedia(QUrl("qrc:/testdata/colors.mp4"));
control = new QGstreamerMediaPlayer(mediaPlayer);
Surface *s = new Surface(mediaPlayer);
mediaPlayer->setVideoOutput(s);
}
void tst_QGstreamerMediaPlayer::cleanup()
......@@ -105,8 +107,6 @@ void tst_QGstreamerMediaPlayer::testVideoSink()
void tst_QGstreamerMediaPlayer::testPipeline()
{
Surface *s = new Surface(mediaPlayer);
mediaPlayer->setVideoOutput(s);
QSignalSpy spy(control, &QGstreamerMediaPlayer::pipelineChanged);
QVERIFY(control->pipeline().isEmpty());
......@@ -160,8 +160,8 @@ void tst_QGstreamerMediaPlayer::testAudioStreams()
QSignalSpy spy(control, &QGstreamerMediaPlayer::audioStreamsCountChanged);
QCOMPARE(control->audioStreamsCount(), 0);
QTRY_COMPARE(control->audioStreamsCount(), 1);
QVERIFY(spy.count() > 0);
QTRY_VERIFY(spy.count() > 0);
QCOMPARE(control->audioStreamsCount(), 1);
}
void tst_QGstreamerMediaPlayer::testVideoStreams()
......@@ -169,8 +169,8 @@ void tst_QGstreamerMediaPlayer::testVideoStreams()
QSignalSpy spy(control, &QGstreamerMediaPlayer::videoStreamsCountChanged);
QCOMPARE(control->videoStreamsCount(), 0);
QTRY_COMPARE(control->videoStreamsCount(), 1);
QVERIFY(spy.count() > 0);
QTRY_VERIFY(spy.count() > 0);
QCOMPARE(control->videoStreamsCount(), 1);
}
void tst_QGstreamerMediaPlayer::testTextStreams()
......@@ -178,8 +178,8 @@ void tst_QGstreamerMediaPlayer::testTextStreams()
QSignalSpy spy(control, &QGstreamerMediaPlayer::textStreamsCountChanged);
QCOMPARE(control->textStreamsCount(), 0);
QTRY_COMPARE(control->textStreamsCount(), 2);
QVERIFY(spy.count() > 0);
QTRY_VERIFY(spy.count() > 0);
QCOMPARE(control->textStreamsCount(), 2);
}
void tst_QGstreamerMediaPlayer::testSetTextStream()
......
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