mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Throttle the emission of callback-updates for high number of LEDs or big images
This commit is contained in:
parent
2e4942adc6
commit
6310cf922a
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
// stl includes
|
// stl includes
|
||||||
#include <list>
|
#include <list>
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
// QT includes
|
// QT includes
|
||||||
#include <QString>
|
#include <QString>
|
||||||
@ -604,4 +605,14 @@ private:
|
|||||||
/// Boblight instance
|
/// Boblight instance
|
||||||
BoblightServer* _boblightServer;
|
BoblightServer* _boblightServer;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
QElapsedTimer _imageTimer; // Timer for controlling image emission frequency
|
||||||
|
QElapsedTimer _rawLedDataTimer; // Timer for controlling rawLedColors emission frequency
|
||||||
|
QElapsedTimer _ledDeviceDataTimer; // Timer for controlling LedDevice data emission frequency
|
||||||
|
qint64 _lastImageEmission; // Last timestamp of image signal emission
|
||||||
|
qint64 _lastRawLedDataEmission; // Last timestamp of rawLedColors signal emission
|
||||||
|
qint64 _lastLedDeviceDataEmission; // Last timestamp of ledDeviceData signal emission
|
||||||
|
std::chrono::milliseconds _imageEmissionInterval;
|
||||||
|
std::chrono::milliseconds _rawLedDataEmissionInterval;
|
||||||
|
std::chrono::milliseconds _ledDeviceDataEmissionInterval;
|
||||||
};
|
};
|
||||||
|
@ -49,6 +49,13 @@
|
|||||||
#include <boblightserver/BoblightServer.h>
|
#include <boblightserver/BoblightServer.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Constants
|
||||||
|
namespace {
|
||||||
|
constexpr std::chrono::milliseconds DEFAULT_MAX_IMAGE_EMISSION_INTERVAL{ 40 }; // 25 Hz
|
||||||
|
constexpr std::chrono::milliseconds DEFAULT_MAX_RAW_LED_DATA_EMISSION_INTERVAL{ 25 }; // 40 Hz
|
||||||
|
constexpr std::chrono::milliseconds DEFAULT_MAX_LED_DEVICE_DATA_EMISSION_INTERVAL{ 5 }; // 200 Hz
|
||||||
|
} //End of constants
|
||||||
|
|
||||||
Hyperion::Hyperion(quint8 instance)
|
Hyperion::Hyperion(quint8 instance)
|
||||||
: QObject()
|
: QObject()
|
||||||
, _instIndex(instance)
|
, _instIndex(instance)
|
||||||
@ -75,6 +82,12 @@ Hyperion::Hyperion(quint8 instance)
|
|||||||
#if defined(ENABLE_BOBLIGHT_SERVER)
|
#if defined(ENABLE_BOBLIGHT_SERVER)
|
||||||
, _boblightServer(nullptr)
|
, _boblightServer(nullptr)
|
||||||
#endif
|
#endif
|
||||||
|
, _lastImageEmission(0)
|
||||||
|
, _lastRawLedDataEmission(0)
|
||||||
|
, _lastLedDeviceDataEmission(0)
|
||||||
|
, _imageEmissionInterval(DEFAULT_MAX_IMAGE_EMISSION_INTERVAL)
|
||||||
|
, _rawLedDataEmissionInterval(DEFAULT_MAX_RAW_LED_DATA_EMISSION_INTERVAL)
|
||||||
|
, _ledDeviceDataEmissionInterval(DEFAULT_MAX_LED_DEVICE_DATA_EMISSION_INTERVAL)
|
||||||
{
|
{
|
||||||
qRegisterMetaType<ComponentList>("ComponentList");
|
qRegisterMetaType<ComponentList>("ComponentList");
|
||||||
|
|
||||||
@ -109,6 +122,8 @@ void Hyperion::start()
|
|||||||
// handle hwLedCount
|
// handle hwLedCount
|
||||||
_hwLedCount = getSetting(settings::DEVICE).object()["hardwareLedCount"].toInt(getLedCount());
|
_hwLedCount = getSetting(settings::DEVICE).object()["hardwareLedCount"].toInt(getLedCount());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Initialize colororder vector
|
// Initialize colororder vector
|
||||||
for (const Led& led : _ledString.leds())
|
for (const Led& led : _ledString.leds())
|
||||||
{
|
{
|
||||||
@ -180,6 +195,15 @@ void Hyperion::start()
|
|||||||
connect(GlobalSignals::getInstance(), &GlobalSignals::setGlobalColor, this, &Hyperion::setColor);
|
connect(GlobalSignals::getInstance(), &GlobalSignals::setGlobalColor, this, &Hyperion::setColor);
|
||||||
connect(GlobalSignals::getInstance(), &GlobalSignals::setGlobalImage, this, &Hyperion::setInputImage);
|
connect(GlobalSignals::getInstance(), &GlobalSignals::setGlobalImage, this, &Hyperion::setInputImage);
|
||||||
|
|
||||||
|
// Limit LED data emission, if high rumber of LEDs configured
|
||||||
|
_rawLedDataEmissionInterval = (_ledString.leds().size() > 1000) ? 2 * DEFAULT_MAX_RAW_LED_DATA_EMISSION_INTERVAL : DEFAULT_MAX_RAW_LED_DATA_EMISSION_INTERVAL;
|
||||||
|
_ledDeviceDataEmissionInterval = (_hwLedCount > 1000) ? 2 * DEFAULT_MAX_LED_DEVICE_DATA_EMISSION_INTERVAL : DEFAULT_MAX_LED_DEVICE_DATA_EMISSION_INTERVAL;
|
||||||
|
|
||||||
|
// Set up timers to throttle specific signals
|
||||||
|
_imageTimer.start(); // Start the elapsed timer for image signal throttling
|
||||||
|
_rawLedDataTimer.start(); // Start the elapsed timer for rawLedColors throttling
|
||||||
|
_ledDeviceDataTimer.start(); // Start the elapsed timer for LED-Device data throttling
|
||||||
|
|
||||||
// if there is no startup / background effect and no sending capture interface we probably want to push once BLACK (as PrioMuxer won't emit a priority change)
|
// if there is no startup / background effect and no sending capture interface we probably want to push once BLACK (as PrioMuxer won't emit a priority change)
|
||||||
update();
|
update();
|
||||||
|
|
||||||
@ -267,6 +291,7 @@ void Hyperion::handleSettingsUpdate(settings::type type, const QJsonDocument& co
|
|||||||
std::vector<ColorRgb> color(_ledString.leds().size(), ColorRgb{0,0,0});
|
std::vector<ColorRgb> color(_ledString.leds().size(), ColorRgb{0,0,0});
|
||||||
_ledBuffer = color;
|
_ledBuffer = color;
|
||||||
|
|
||||||
|
|
||||||
_ledStringColorOrder.clear();
|
_ledStringColorOrder.clear();
|
||||||
for (const Led& led : _ledString.leds())
|
for (const Led& led : _ledString.leds())
|
||||||
{
|
{
|
||||||
@ -276,6 +301,10 @@ void Hyperion::handleSettingsUpdate(settings::type type, const QJsonDocument& co
|
|||||||
// handle hwLedCount update
|
// handle hwLedCount update
|
||||||
_hwLedCount = getSetting(settings::DEVICE).object()["hardwareLedCount"].toInt(getLedCount());
|
_hwLedCount = getSetting(settings::DEVICE).object()["hardwareLedCount"].toInt(getLedCount());
|
||||||
|
|
||||||
|
// Limit LED data emission, if high rumber of LEDs configured
|
||||||
|
_rawLedDataEmissionInterval = (_ledString.leds().size() > 1000) ? 2 * DEFAULT_MAX_RAW_LED_DATA_EMISSION_INTERVAL : DEFAULT_MAX_RAW_LED_DATA_EMISSION_INTERVAL;
|
||||||
|
_ledDeviceDataEmissionInterval = (_hwLedCount > 1000) ? 2 * DEFAULT_MAX_LED_DEVICE_DATA_EMISSION_INTERVAL : DEFAULT_MAX_LED_DEVICE_DATA_EMISSION_INTERVAL;
|
||||||
|
|
||||||
// change in leds are also reflected in adjustment
|
// change in leds are also reflected in adjustment
|
||||||
delete _raw2ledAdjustment;
|
delete _raw2ledAdjustment;
|
||||||
_raw2ledAdjustment = hyperion::createLedColorsAdjustment(static_cast<int>(_ledString.leds().size()), getSetting(settings::COLOR).object());
|
_raw2ledAdjustment = hyperion::createLedColorsAdjustment(static_cast<int>(_ledString.leds().size()), getSetting(settings::COLOR).object());
|
||||||
@ -672,7 +701,14 @@ void Hyperion::update()
|
|||||||
Image<ColorRgb> image = priorityInfo.image;
|
Image<ColorRgb> image = priorityInfo.image;
|
||||||
if (image.width() > 1 || image.height() > 1)
|
if (image.width() > 1 || image.height() > 1)
|
||||||
{
|
{
|
||||||
emit currentImage(image);
|
_imageEmissionInterval = (image.width() > 1280) ? 2 * DEFAULT_MAX_IMAGE_EMISSION_INTERVAL : DEFAULT_MAX_IMAGE_EMISSION_INTERVAL;
|
||||||
|
// Throttle the emission of currentImage(image) signal
|
||||||
|
qint64 elapsedImageEmissionTime = _imageTimer.elapsed();
|
||||||
|
if (elapsedImageEmissionTime - _lastImageEmission >= _imageEmissionInterval.count())
|
||||||
|
{
|
||||||
|
_lastImageEmission = elapsedImageEmissionTime;
|
||||||
|
emit currentImage(image); // Emit the image signal at the controlled rate
|
||||||
|
}
|
||||||
_ledBuffer = _imageProcessor->process(image);
|
_ledBuffer = _imageProcessor->process(image);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -692,9 +728,15 @@ void Hyperion::update()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// emit rawLedColors before transform
|
// Throttle the emission of rawLedColors(_ledBuffer) signal
|
||||||
emit rawLedColors(_ledBuffer);
|
qint64 elapsedRawLedDataEmissionTime = _rawLedDataTimer.elapsed();
|
||||||
|
if (elapsedRawLedDataEmissionTime - _lastRawLedDataEmission >= _rawLedDataEmissionInterval.count())
|
||||||
|
{
|
||||||
|
_lastRawLedDataEmission = elapsedRawLedDataEmissionTime;
|
||||||
|
emit rawLedColors(_ledBuffer); // Emit the rawLedColors signal at the controlled rate
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start transformations
|
||||||
_raw2ledAdjustment->applyAdjustment(_ledBuffer);
|
_raw2ledAdjustment->applyAdjustment(_ledBuffer);
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@ -740,7 +782,13 @@ void Hyperion::update()
|
|||||||
// Smoothing is disabled
|
// Smoothing is disabled
|
||||||
if (! _deviceSmooth->enabled())
|
if (! _deviceSmooth->enabled())
|
||||||
{
|
{
|
||||||
emit ledDeviceData(_ledBuffer);
|
// Throttle the emission of LED-Device data signal
|
||||||
|
qint64 elapsedLedDeviceDataEmissionTime = _ledDeviceDataTimer.elapsed();
|
||||||
|
if (elapsedLedDeviceDataEmissionTime - _lastLedDeviceDataEmission >= _ledDeviceDataEmissionInterval.count())
|
||||||
|
{
|
||||||
|
_lastLedDeviceDataEmission = elapsedLedDeviceDataEmissionTime;
|
||||||
|
emit ledDeviceData(_ledBuffer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user