Throttle frames sent to color scopes so that we only cause minimum slowdown in playback

parent 76f839cb
......@@ -64,13 +64,15 @@ Q_OBJECT public:
private:
Kdenlive::MonitorId m_id;
signals:
/** @brief The renderer refreshed the current frame. */
void frameUpdated(const QImage &);
/** @brief This signal contains the audio of the current frame. */
void audioSamplesSignal(const audioShortVector&,int,int,int);
/** @brief Scopes are ready to receive a new frame. */
void scopesClear();
};
class AbstractMonitor : public QWidget
......
......@@ -55,7 +55,6 @@ typedef GLenum (*ClientWaitSync_fp) (GLsync sync, GLbitfield flags, GLuint64 tim
static ClientWaitSync_fp ClientWaitSync = 0;
#endif
using namespace Mlt;
GLWidget::GLWidget(int id, QObject *parent)
......@@ -67,6 +66,7 @@ GLWidget::GLWidget(int id, QObject *parent)
, m_consumer(0)
, m_producer(0)
, m_initSem(0)
, m_analyseSem(1)
, m_isInitialized(false)
, m_threadStartEvent(0)
, m_threadStopEvent(0)
......@@ -377,6 +377,11 @@ void GLWidget::clear()
update();
}
void GLWidget::releaseAnalyse()
{
m_analyseSem.release();
}
void GLWidget::paintGL()
{
QOpenGLFunctions* f = openglContext()->functions();
......@@ -471,7 +476,7 @@ void GLWidget::paintGL()
f->glDrawArrays(GL_TRIANGLE_STRIP, 0, vertices.size());
check_error(f);
if (sendFrameForAnalysis) {
if (sendFrameForAnalysis && m_analyseSem.tryAcquire(1)) {
// Render RGB frame for analysis
int fullWidth = m_monitorProfile->width();
int fullHeight = m_monitorProfile->height();
......
......@@ -109,6 +109,7 @@ public slots:
void slotSwitchAudioOverlay(bool enable);
void slotZoomScene(double value);
void initializeGL();
void releaseAnalyse();
signals:
void frameDisplayed(const SharedFrame& frame);
......@@ -143,6 +144,7 @@ private:
Mlt::Consumer* m_consumer;
Mlt::Producer* m_producer;
QSemaphore m_initSem;
QSemaphore m_analyseSem;
bool m_isInitialized;
Mlt::Event* m_threadStartEvent;
Mlt::Event* m_threadStopEvent;
......
......@@ -281,7 +281,8 @@ Monitor::Monitor(Kdenlive::MonitorId id, MonitorManager *manager, QWidget *paren
connect(render, SIGNAL(durationChanged(int,int)), this, SLOT(adjustRulerSize(int,int)));
connect(render, SIGNAL(rendererStopped(int)), this, SLOT(rendererStopped(int)));
connect(m_glMonitor, SIGNAL(analyseFrame(QImage)), render, SLOT(emitFrameUpdated(QImage)));
connect(render, &AbstractRender::scopesClear, m_glMonitor, &GLWidget::releaseAnalyse, Qt::DirectConnection);
connect(m_glMonitor, SIGNAL(analyseFrame(QImage)), render, SIGNAL(frameUpdated(QImage)));
connect(m_glMonitor, SIGNAL(audioSamplesSignal(const audioShortVector&,int,int,int)), render, SIGNAL(audioSamplesSignal(const audioShortVector&,int,int,int)));
if (id != Kdenlive::ClipMonitor) {
......
......@@ -961,11 +961,6 @@ bool Render::checkFrameNumber(int pos)
return true;
}
void Render::emitFrameUpdated(QImage img)
{
emit frameUpdated(img);
}
void Render::slotCheckSeeking()
{
if (requestedSeekPosition != SEEK_INACTIVE) {
......
......@@ -361,7 +361,6 @@ public slots:
void seekToFrame(int pos);
/** @brief Starts a timer to query for a refresh. */
void doRefresh();
void emitFrameUpdated(QImage img);
/** @brief Save a part of current timeline to an xml file. */
void saveZone(QPoint zone);
......
......@@ -103,6 +103,7 @@ bool ScopeManager::addScope(AbstractGfxScopeWidget *colorScope, QDockWidget *col
connect(colorScope, SIGNAL(requestAutoRefresh(bool)), this, SLOT(slotCheckActiveScopes()));
connect(colorScope, SIGNAL(signalFrameRequest(QString)), this, SLOT(slotRequestFrame(QString)));
connect(colorScope, SIGNAL(signalScopeRenderingFinished(uint, uint)), this, SLOT(slotScopeReady()));
if (colorScopeWidget != NULL) {
connect(colorScopeWidget, SIGNAL(visibilityChanged(bool)), this, SLOT(slotCheckActiveScopes()));
connect(colorScopeWidget, SIGNAL(visibilityChanged(bool)), m_signalMapper, SLOT(map()));
......@@ -155,8 +156,13 @@ void ScopeManager::slotDistributeFrame(const QImage &image)
}
}
}
//checkActiveColourScopes();
}
checkActiveColourScopes();
void ScopeManager::slotScopeReady()
{
if (m_lastConnectedRenderer)
m_lastConnectedRenderer->scopesClear();
}
......
......@@ -129,6 +129,7 @@ private slots:
Allows a scope to explicitly request a new frame, even if the scope's autoRefresh is disabled.
*/
void slotRequestFrame(const QString &widgetName);
void slotScopeReady();
};
#endif // SCOPEMANAGER_H
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