Commit 02361a35 authored by Val Doroshchuk's avatar Val Doroshchuk

tmp example

parent 95d7b0e2
......@@ -51,6 +51,25 @@
#include "streamer.h"
#include <QQuickItemGrabResult>
void AppSrc::imageReady()
{
m_frame = m_grabResult->image();
m_grabResult.reset();
}
QVideoFrame AppSrc::readFrame() const
{
if (!m_frame.isValid() && m_streamer->item()) {
m_grabResult = qobject_cast<QQuickItem*>(m_streamer->item())->grabToImage();
connect(m_grabResult.data(), &QQuickItemGrabResult::ready, this, &AppSrc::imageReady);
}
auto frame = m_frame;
m_frame = QVideoFrame();
return frame;
}
Streamer::Streamer(QObject *parent)
: QGstreamerPipeline(parent)
{
......@@ -65,10 +84,11 @@ QObject *Streamer::item() const
void Streamer::setItem(QObject *src)
{
if (src == m_item)
auto item = qobject_cast<QQuickItem*>(src);
if (m_item == item)
return;
m_item = qobject_cast<QQuickItem*>(src);
m_item = item;
emit itemChanged();
}
......@@ -85,17 +105,3 @@ void Streamer::onPipelineChanged()
m_appsrc.reset(new AppSrc(this, appsrc));
}
QVideoFrame AppSrc::readFrame() const
{
if (!m_frame.isValid() && m_streamer->item()) {
auto result = qobject_cast<QQuickItem*>(m_streamer->item())->grabToImage();
connect(result.data(), &QQuickItemGrabResult::ready, result.data(), [this, result](){
m_frame = result->image();
});
}
auto frame = m_frame;
m_frame = QVideoFrame();
return frame;
}
......@@ -72,8 +72,12 @@ public:
protected:
QVideoFrame readFrame() const override;
private Q_SLOTS:
void imageReady();
private:
Streamer *m_streamer = nullptr;
mutable QSharedPointer<QQuickItemGrabResult> m_grabResult;
mutable QVideoFrame m_frame;
};
......
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