Commit 5e6fe57e authored by Val Doroshchuk's avatar Val Doroshchuk

readFrame

parent c924cdc8
...@@ -59,17 +59,18 @@ void AppSrc::imageReady() ...@@ -59,17 +59,18 @@ void AppSrc::imageReady()
m_grabResult.reset(); m_grabResult.reset();
} }
QVideoFrame AppSrc::readFrame() const bool AppSrc::readFrame(QVideoFrame &frame) const
{ {
if (!m_frame.isValid() && m_streamer->item()) { if (!m_frame.isValid() && m_streamer->item()) {
m_grabResult = qobject_cast<QQuickItem*>(m_streamer->item())->grabToImage(); m_grabResult = qobject_cast<QQuickItem*>(m_streamer->item())->grabToImage();
connect(m_grabResult.data(), &QQuickItemGrabResult::ready, this, &AppSrc::imageReady); connect(m_grabResult.data(), &QQuickItemGrabResult::ready, this, &AppSrc::imageReady);
return false;
} }
auto frame = m_frame; frame = m_frame;
m_frame = QVideoFrame(); m_frame = QVideoFrame();
return frame; return true;
} }
Streamer::Streamer(QObject *parent) Streamer::Streamer(QObject *parent)
......
...@@ -70,7 +70,7 @@ public: ...@@ -70,7 +70,7 @@ public:
} }
protected: protected:
QVideoFrame readFrame() const override; bool readFrame(QVideoFrame &frame) const override;
private Q_SLOTS: private Q_SLOTS:
void imageReady(); void imageReady();
......
...@@ -122,9 +122,10 @@ void QGstreamerAppSrc::stopFeed() ...@@ -122,9 +122,10 @@ void QGstreamerAppSrc::stopFeed()
d->timerId = 0; d->timerId = 0;
} }
QVideoFrame QGstreamerAppSrc::readFrame() const bool QGstreamerAppSrc::readFrame(QVideoFrame &frame) const
{ {
return QVideoFrame(); Q_UNUSED(frame);
return false;
} }
void QGstreamerAppSrc::timerEvent(QTimerEvent *event) void QGstreamerAppSrc::timerEvent(QTimerEvent *event)
...@@ -134,8 +135,8 @@ void QGstreamerAppSrc::timerEvent(QTimerEvent *event) ...@@ -134,8 +135,8 @@ void QGstreamerAppSrc::timerEvent(QTimerEvent *event)
if (event->timerId() != d->timerId) if (event->timerId() != d->timerId)
return; return;
QVideoFrame frame = readFrame(); QVideoFrame frame;
if (!frame.isValid() || (d->size != frame.size() && !d->restart(frame))) if (!readFrame(frame) || !frame.isValid() || (d->size != frame.size() && !d->restart(frame)))
return; return;
if (!frame.map(QAbstractVideoBuffer::ReadOnly)) if (!frame.map(QAbstractVideoBuffer::ReadOnly))
......
...@@ -54,7 +54,7 @@ public: ...@@ -54,7 +54,7 @@ public:
~QGstreamerAppSrc(); ~QGstreamerAppSrc();
protected: protected:
virtual QVideoFrame readFrame() const; virtual bool readFrame(QVideoFrame &frame) const;
private Q_SLOTS: private Q_SLOTS:
void startFeed(); void startFeed();
......
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