Skip to content

Commit

Permalink
Introducing configurable render interval for qml streamer (#215)
Browse files Browse the repository at this point in the history
  • Loading branch information
ppodhajski authored Aug 6, 2019
1 parent a2374b8 commit ac6e742
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 14 deletions.
12 changes: 8 additions & 4 deletions deflect/qt/OffscreenQuickView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,13 @@ void OffscreenQuickView::_requestRender()
{
killTimer(_stopRenderingDelayTimer);
_stopRenderingDelayTimer = 0;

if (_renderTimer == 0)
_renderTimer = startTimer(5, Qt::PreciseTimer);
_renderTimer = startTimer(int(_renderInterval), Qt::PreciseTimer);
}

void OffscreenQuickView::setRenderInterval(uint interval)
{
_renderInterval = interval;
}

void OffscreenQuickView::_initRenderer()
Expand Down Expand Up @@ -244,5 +248,5 @@ void OffscreenQuickView::_afterRender()
// The fbo can be safely assumed to be valid when this function executes.
emit afterRender(_quickRenderer->fbo()->toImage());
}
}
}
} // namespace qt
} // namespace deflect
11 changes: 9 additions & 2 deletions deflect/qt/OffscreenQuickView.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ class OffscreenQuickView : public QQuickWindow
/** @return the root qml context. */
QQmlContext* getRootContext() const;

/**
* Set a value used to calculate intenal render timer.
* @param interval interval to set.
*/
void setRenderInterval(uint interval);

signals:
/**
* Notify that the scene has just finished rendering.
Expand All @@ -123,6 +129,7 @@ class OffscreenQuickView : public QQuickWindow
std::promise<bool> _loadPromise;

int _renderTimer = 0;
uint _renderInterval = 16;
int _stopRenderingDelayTimer = 0;

void timerEvent(QTimerEvent* e) final;
Expand All @@ -133,7 +140,7 @@ class OffscreenQuickView : public QQuickWindow
void _render();
void _afterRender();
};
}
}
} // namespace qt
} // namespace deflect

#endif
12 changes: 8 additions & 4 deletions deflect/qt/QmlStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ QmlStreamer::QmlStreamer(const QString& qmlFile, const std::string& streamHost,
connect(_impl.get(), &Impl::streamClosed, this, &QmlStreamer::streamClosed);
}

QmlStreamer::~QmlStreamer()
{
}
QmlStreamer::~QmlStreamer() {}

void QmlStreamer::useAsyncSend(const bool async)
{
Expand All @@ -76,5 +74,11 @@ bool QmlStreamer::sendData(const QByteArray data)
{
return _impl->getStream()->sendData(data.constData(), data.size());
}

void QmlStreamer::setRenderInterval(uint interval)
{
_impl->setRenderInterval(interval);
}
}

} // namespace qt
} // namespace deflect
11 changes: 9 additions & 2 deletions deflect/qt/QmlStreamer.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ class DEFLECT_API QmlStreamer : public QObject
*/
bool sendData(QByteArray data);

/**
* Set a value used to calculate intenal render timer
* needed in OffscreenQuickView
* @param interval interval to set.
*/
void setRenderInterval(uint interval);

signals:
/** Emitted when the stream has been closed. */
void streamClosed();
Expand All @@ -118,7 +125,7 @@ class DEFLECT_API QmlStreamer : public QObject
class Impl;
std::unique_ptr<Impl> _impl;
};
}
}
} // namespace qt
} // namespace deflect

#endif
5 changes: 5 additions & 0 deletions deflect/qt/QmlStreamerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ void QmlStreamer::Impl::_send(QKeyEvent& keyEvent_)
}
}

void QmlStreamer::Impl::setRenderInterval(unsigned int interval)
{
_quickView->setRenderInterval(interval);
}

bool QmlStreamer::Impl::_sendToWebengineviewItems(QKeyEvent& keyEvent_)
{
// Special handling for WebEngineView in offscreen Qml windows.
Expand Down
7 changes: 5 additions & 2 deletions deflect/qt/QmlStreamerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ class QmlStreamer::Impl : public QObject
QQuickItem* getRootItem() { return _quickView->getRootItem(); }
QQmlEngine* getQmlEngine() { return _quickView->getEngine(); }
Stream* getStream() { return _stream.get(); }

void setRenderInterval(unsigned int interval);

signals:
void streamClosed();

Expand Down Expand Up @@ -134,7 +137,7 @@ private slots:
AppNapSuspender _napSuspender;
#endif
};
}
}
} // namespace qt
} // namespace deflect

#endif

0 comments on commit ac6e742

Please sign in to comment.