Commit 70ede91b authored by Val Doroshchuk's avatar Val Doroshchuk

test

parent ed44454c
......@@ -68,16 +68,14 @@ public:
{
}
void updatePipeline();
public Q_SLOTS:
void updateMediaObject();
void streamsChanged();
void updatePipeline();
protected:
QPointer<QObject> source;
QPointer<QMediaObject> mediaObject;
QGstreamerVideoRendererInterface *renderer = nullptr;
QGstreamerPlayerSession *session = nullptr;
GstElement *playbin = nullptr;
......@@ -215,21 +213,25 @@ static GstElement *parseDesc(const QString &name)
void QGstreamerMediaPlayerPrivate::updatePipeline()
{
Q_Q(QGstreamerMediaPlayer);
if (!renderer || !renderer->isReady())
if (pendingPipelineDesc.isEmpty()
|| !session->renderer()
|| !session->renderer()->isReady()) {
return;
if (!pendingPipelineDesc.isEmpty()) {
auto videoRenderer = static_cast<QGstreamerVideoRenderer *>(renderer);
if (videoRenderer)
QGstVideoRendererSink::setSurface(videoRenderer->surface());
GstElement *pipeline = parseDesc(pendingPipelineDesc);
if (pipeline) {
pipelineDesc = pendingPipelineDesc;
pendingPipelineDesc.clear();
session->setPipeline(pipeline);
emit q->pipelineChanged();
}
}
auto videoRenderer = static_cast<QGstreamerVideoRenderer *>(session->renderer());
if (videoRenderer)
QGstVideoRendererSink::setSurface(videoRenderer->surface());
QString p = pendingPipelineDesc;
pendingPipelineDesc.clear();
GstElement *pipeline = parseDesc(p);
if (!pipeline)
return;
pipelineDesc = p;
session->setPipeline(pipeline);
emit q->pipelineChanged();
}
QGstreamerMediaPlayer::QGstreamerMediaPlayer(QMediaObject *media, QObject *parent)
......@@ -305,12 +307,9 @@ void QGstreamerMediaPlayer::setMediaObject(QMediaObject *src)
connect(d->session, &QGstreamerPlayerSession::streamsChanged,
d, &QGstreamerMediaPlayerPrivate::streamsChanged);
// Create pipeline when surface is ready.
connect(d->session, &QGstreamerPlayerSession::rendererChanged,
[d](QGstreamerVideoRendererInterface *r) {
d->renderer = r;
// Set pipeline when surface is ready.
d->updatePipeline();
});
d, &QGstreamerMediaPlayerPrivate::updatePipeline);
// In case if these values've been applied
// before mediaObject is available.
......@@ -333,7 +332,7 @@ void QGstreamerMediaPlayer::setPipeline(const QString &desc)
Q_D(QGstreamerMediaPlayer);
d->pendingPipelineDesc = desc;
if (d->pipelineDesc == desc)
if (!d->session || d->pipelineDesc == desc)
return;
d->updatePipeline();
......@@ -353,11 +352,12 @@ void QGstreamerMediaPlayer::setVideoSink(const QString &desc)
return;
GstElement *videoSink = parseDesc(desc);
if (videoSink) {
d->videoSinkDesc = desc;
d->session->setVideoSink(videoSink);
emit videoSinkChanged();
}
if (!videoSink)
return;
d->videoSinkDesc = desc;
d->session->setVideoSink(videoSink);
emit videoSinkChanged();
}
bool QGstreamerMediaPlayer::showText() const
......
......@@ -30,6 +30,7 @@
#include <QMediaPlayer>
#include <QGstreamerMediaPlayer>
#include <QAbstractVideoSurface>
QT_USE_NAMESPACE
......@@ -42,6 +43,7 @@ public slots:
void cleanup();
private slots:
void testPipeline();
void testVideoSink();
void testShowText();
void testTextUri();
......@@ -57,6 +59,24 @@ private:
QMediaPlayer *mediaPlayer = nullptr;
};
struct Surface : QAbstractVideoSurface
{
Surface(QObject *parent = nullptr)
: QAbstractVideoSurface(parent)
{
}
QList<QVideoFrame::PixelFormat> supportedPixelFormats(
QAbstractVideoBuffer::HandleType) const override
{
return QList<QVideoFrame::PixelFormat>() << QVideoFrame::Format_RGB32;
}
bool isFormatSupported(const QVideoSurfaceFormat &) const override { return false; }
bool start(const QVideoSurfaceFormat &) override { return false; }
void stop() override { }
bool present(const QVideoFrame &) override { return false; }
};
void tst_QGstreamerMediaPlayer::init()
{
......@@ -77,8 +97,22 @@ void tst_QGstreamerMediaPlayer::testVideoSink()
QVERIFY(player.videoSink().isEmpty());
QString sink = "xvimagesink hue=100";
player.setVideoSink(sink);
QTRY_COMPARE(spy.count(), 1);
QCOMPARE(sink, player.videoSink());
QCOMPARE(spy.count(), 1);
}
void tst_QGstreamerMediaPlayer::testPipeline()
{
Surface *s = new Surface(mediaPlayer);
mediaPlayer->setVideoOutput(s);
QGstreamerMediaPlayer player(mediaPlayer);
QSignalSpy spy(&player, &QGstreamerMediaPlayer::pipelineChanged);
QVERIFY(player.pipeline().isEmpty());
QString p = "videotestsrc ! autovideosink";
player.setPipeline(p);
QTRY_COMPARE(spy.count(), 1);
QCOMPARE(p, player.pipeline());
}
void tst_QGstreamerMediaPlayer::testShowText()
......
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