UI: Prevent thread stalls with fader/volume widgets
When the OBS signal is triggered for these widgets, the invokeMethod could cause the thread to stall, which could make it wait much longer than necessary to output audio data. When that happens, it causes audio monitoring to get backed up and get unnecessarily delayed, as well as cause general audio buffering in libobs to increase unnecessarily. A simple fix both in terms of preventing that stall and improving UI performance is to not call invokeMethod to update the widget each time, and then instead have those widgets update themselves via a timer at a specific interval.
This commit is contained in:
@@ -2,8 +2,13 @@
|
||||
|
||||
#include <obs.hpp>
|
||||
#include <QWidget>
|
||||
#include <QSharedPointer>
|
||||
#include <QTimer>
|
||||
#include <QMutex>
|
||||
#include <QList>
|
||||
|
||||
class QPushButton;
|
||||
class VolumeMeterTimer;
|
||||
|
||||
class VolumeMeter : public QWidget
|
||||
{
|
||||
@@ -14,12 +19,23 @@ class VolumeMeter : public QWidget
|
||||
Q_PROPERTY(QColor peakHoldColor READ getPeakHoldColor WRITE setPeakHoldColor DESIGNABLE true)
|
||||
|
||||
private:
|
||||
float mag, peak, peakHold;
|
||||
static QWeakPointer<VolumeMeterTimer> updateTimer;
|
||||
QSharedPointer<VolumeMeterTimer> updateTimerRef;
|
||||
float curMag = 0.0f, curPeak = 0.0f, curPeakHold = 0.0f;
|
||||
|
||||
inline void calcLevels();
|
||||
|
||||
QMutex dataMutex;
|
||||
float mag = 0.0f, peak = 0.0f, peakHold = 0.0f;
|
||||
float multiple = 0.0f;
|
||||
uint64_t lastUpdateTime = 0;
|
||||
|
||||
QColor bkColor, magColor, peakColor, peakHoldColor;
|
||||
QTimer *resetTimer;
|
||||
|
||||
public:
|
||||
explicit VolumeMeter(QWidget *parent = 0);
|
||||
~VolumeMeter();
|
||||
|
||||
void setLevels(float nmag, float npeak, float npeakHold);
|
||||
QColor getBkColor() const;
|
||||
void setBkColor(QColor c);
|
||||
@@ -32,8 +48,20 @@ public:
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event);
|
||||
private slots:
|
||||
void resetState();
|
||||
};
|
||||
|
||||
class VolumeMeterTimer : public QTimer {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
inline VolumeMeterTimer() : QTimer() {}
|
||||
|
||||
void AddVolControl(VolumeMeter *meter);
|
||||
void RemoveVolControl(VolumeMeter *meter);
|
||||
|
||||
protected:
|
||||
virtual void timerEvent(QTimerEvent *event) override;
|
||||
QList<VolumeMeter*> volumeMeters;
|
||||
};
|
||||
|
||||
class QLabel;
|
||||
|
Reference in New Issue
Block a user