mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Various Cleanups (#1075)
* LedDevice - Address clang findings * Fix Windows Warnings * Ensure newInput is initialised * Clean-up unused elements for Plaform Capture * Fix initialization problem and spellings * Address clang findings and spelling corrections * LedDevice clean-ups * Cleanups * Align that getLedCount is int * Have "display" as default for Grabbers * Fix config during start-up for missing elements * Framegrabber Clean-up - Remove non supported grabbers from selection, filter valid options * Typo * Framegrabber.json - Fix property numbering * Preselect active Grabbertype * Sort Grabbernames * Align options with selected element * Fix deletion of pointer to incomplete type 'BonjourBrowserWrapper' * Address macOS compile warnings * Have default layout = 1 LED only to avoid errors as in #673 * Address lgtm findings * Address finding that params passed to LedDevice discovery were not considered * Cleanups after merging with latest master * Update Changelog * Address lgtm findings * Fix comment * Test Fix * Fix Python Warning * Handle Dummy Device assignment correctly * Address delete called on non-final 'commandline::Option' that has virtual functions but non-virtual destructor * Correct that QTimer.start accepts only int * Have Release Python GIL & reset threat state chnage downward compatible * Correct format specifier * LedDevice - add assertions * Readonly DB - Fix merge issue * Smoothing - Fix wrong defaults * LedDevice - correct assertion * Show smoothing config set# in debug and related values. * Suppress error on windows, if default file is "/dev/null" * CMAKE - Allow to define QT_BASE_DIR dynamically via environment-variable * Ignore Visual Studio specific files Co-authored-by: Paulchen Panther <16664240+Paulchen-Panther@users.noreply.github.com>
This commit is contained in:
@@ -22,7 +22,7 @@ const int64_t MS_PER_MICRO = 1000;
|
||||
|
||||
/// Clamps the rounded values to the byte-interval of [0, 255].
|
||||
ALWAYS_INLINE long clampRounded(const floatT x) {
|
||||
return std::min(255l, std::max(0l, std::lroundf(x)));
|
||||
return std::min(255L, std::max(0L, std::lroundf(x)));
|
||||
}
|
||||
|
||||
/// The number of bits that are used for shifting the fixed point values
|
||||
@@ -43,15 +43,16 @@ const char* SETTINGS_KEY_DECAY = "decay";
|
||||
using namespace hyperion;
|
||||
|
||||
const int64_t DEFAUL_SETTLINGTIME = 200; // settlingtime in ms
|
||||
const double DEFAUL_UPDATEFREQUENCY = 25; // updatefrequncy in hz
|
||||
const int64_t DEFAUL_UPDATEINTERVALL = static_cast<int64_t>(1000 / DEFAUL_UPDATEFREQUENCY); // updateintervall in ms
|
||||
const int DEFAUL_UPDATEFREQUENCY = 25; // updatefrequncy in hz
|
||||
|
||||
constexpr std::chrono::milliseconds DEFAUL_UPDATEINTERVALL{1000/ DEFAUL_UPDATEFREQUENCY};
|
||||
const unsigned DEFAUL_OUTPUTDEPLAY = 0; // outputdelay in ms
|
||||
|
||||
LinearColorSmoothing::LinearColorSmoothing(const QJsonDocument &config, Hyperion *hyperion)
|
||||
: QObject(hyperion)
|
||||
, _log(Logger::getInstance("SMOOTHING"))
|
||||
, _hyperion(hyperion)
|
||||
, _updateInterval(DEFAUL_UPDATEINTERVALL)
|
||||
, _updateInterval(DEFAUL_UPDATEINTERVALL.count())
|
||||
, _settlingTime(DEFAUL_SETTLINGTIME)
|
||||
, _timer(new QTimer(this))
|
||||
, _outputDelay(DEFAUL_OUTPUTDEPLAY)
|
||||
@@ -61,7 +62,7 @@ LinearColorSmoothing::LinearColorSmoothing(const QJsonDocument &config, Hyperion
|
||||
, _pause(false)
|
||||
, _currentConfigId(0)
|
||||
, _enabled(false)
|
||||
, tempValues(std::vector<uint64_t>(0, 0l))
|
||||
, tempValues(std::vector<uint64_t>(0, 0L))
|
||||
{
|
||||
// init cfg 0 (default)
|
||||
addConfig(DEFAUL_SETTLINGTIME, DEFAUL_UPDATEFREQUENCY, DEFAUL_OUTPUTDEPLAY);
|
||||
@@ -69,7 +70,7 @@ LinearColorSmoothing::LinearColorSmoothing(const QJsonDocument &config, Hyperion
|
||||
selectConfig(0, true);
|
||||
|
||||
// add pause on cfg 1
|
||||
SMOOTHING_CFG cfg = {SmoothingType::Linear, 0, 0, 0, 0, 0, false};
|
||||
SMOOTHING_CFG cfg = {SmoothingType::Linear, false, 0, 0, 0, 0, 0, false, 1};
|
||||
_cfgList.append(cfg);
|
||||
|
||||
// listen for comp changes
|
||||
@@ -77,7 +78,7 @@ LinearColorSmoothing::LinearColorSmoothing(const QJsonDocument &config, Hyperion
|
||||
// timer
|
||||
connect(_timer, &QTimer::timeout, this, &LinearColorSmoothing::updateLeds);
|
||||
|
||||
Info(_log, "LinearColorSmoothing sizeof floatT == %d", (sizeof(floatT)));
|
||||
//Debug(_log, "LinearColorSmoothing sizeof floatT == %d", (sizeof(floatT)));
|
||||
}
|
||||
|
||||
void LinearColorSmoothing::handleSettingsUpdate(settings::type type, const QJsonDocument &config)
|
||||
@@ -89,7 +90,9 @@ void LinearColorSmoothing::handleSettingsUpdate(settings::type type, const QJson
|
||||
|
||||
QJsonObject obj = config.object();
|
||||
if (enabled() != obj["enable"].toBool(true))
|
||||
{
|
||||
setEnable(obj["enable"].toBool(true));
|
||||
}
|
||||
|
||||
_continuousOutput = obj["continuousOutput"].toBool(true);
|
||||
|
||||
@@ -105,7 +108,7 @@ void LinearColorSmoothing::handleSettingsUpdate(settings::type type, const QJson
|
||||
|
||||
cfg.pause = false;
|
||||
cfg.settlingTime = static_cast<int64_t>(obj["time_ms"].toInt(DEFAUL_SETTLINGTIME));
|
||||
cfg.updateInterval = static_cast<int64_t>(1000.0 / obj["updateFrequency"].toDouble(DEFAUL_UPDATEFREQUENCY));
|
||||
cfg.updateInterval = static_cast<int>(1000.0 / obj["updateFrequency"].toDouble(DEFAUL_UPDATEFREQUENCY));
|
||||
cfg.outputRate = obj[SETTINGS_KEY_OUTPUT_RATE].toDouble(DEFAUL_UPDATEFREQUENCY);
|
||||
cfg.interpolationRate = obj[SETTINGS_KEY_INTERPOLATION_RATE].toDouble(DEFAUL_UPDATEFREQUENCY);
|
||||
cfg.outputDelay = static_cast<unsigned>(obj["updateDelay"].toInt(DEFAUL_OUTPUTDEPLAY));
|
||||
@@ -155,7 +158,7 @@ int LinearColorSmoothing::updateLedValues(const std::vector<ColorRgb> &ledValues
|
||||
int retval = 0;
|
||||
if (!_enabled)
|
||||
{
|
||||
return -1;
|
||||
retval = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -173,13 +176,13 @@ void LinearColorSmoothing::intitializeComponentVectors(const size_t ledCount)
|
||||
|
||||
const size_t len = 3 * ledCount;
|
||||
|
||||
meanValues = std::vector<floatT>(len, 0.0f);
|
||||
residualErrors = std::vector<floatT>(len, 0.0f);
|
||||
tempValues = std::vector<uint64_t>(len, 0l);
|
||||
meanValues = std::vector<floatT>(len, 0.0F);
|
||||
residualErrors = std::vector<floatT>(len, 0.0F);
|
||||
tempValues = std::vector<uint64_t>(len, 0L);
|
||||
}
|
||||
|
||||
// Zero the temp vector
|
||||
std::fill(tempValues.begin(), tempValues.end(), 0l);
|
||||
std::fill(tempValues.begin(), tempValues.end(), 0L);
|
||||
}
|
||||
|
||||
void LinearColorSmoothing::writeDirect()
|
||||
@@ -232,9 +235,9 @@ void LinearColorSmoothing::assembleAndDitherFrame()
|
||||
|
||||
// Update the colors
|
||||
ColorRgb &prev = _previousValues[i];
|
||||
prev.red = (uint8_t)ir;
|
||||
prev.green = (uint8_t)ig;
|
||||
prev.blue = (uint8_t)ib;
|
||||
prev.red = static_cast<uint8_t>(ir);
|
||||
prev.green = static_cast<uint8_t>(ig);
|
||||
prev.blue = static_cast<uint8_t>(ib);
|
||||
|
||||
// Determine the component errors
|
||||
residualErrors[3 * i + 0] = fr - ir;
|
||||
@@ -262,15 +265,15 @@ void LinearColorSmoothing::assembleFrame()
|
||||
|
||||
// Update the colors
|
||||
ColorRgb &prev = _previousValues[i];
|
||||
prev.red = (uint8_t)ir;
|
||||
prev.green = (uint8_t)ig;
|
||||
prev.blue = (uint8_t)ib;
|
||||
prev.red = static_cast<uint8_t>(ir);
|
||||
prev.green = static_cast<uint8_t>(ig);
|
||||
prev.blue = static_cast<uint8_t>(ib);
|
||||
}
|
||||
}
|
||||
|
||||
ALWAYS_INLINE void LinearColorSmoothing::aggregateComponents(const std::vector<ColorRgb>& colors, std::vector<uint64_t>& weighted, const floatT weight) {
|
||||
// Determine the integer-scale by converting the weight to fixed point
|
||||
const uint64_t scale = (1l<<FPShift) * static_cast<double>(weight);
|
||||
const uint64_t scale = (static_cast<uint64_t>(1L)<<FPShift) * static_cast<double>(weight);
|
||||
|
||||
const size_t N = colors.size();
|
||||
|
||||
@@ -309,7 +312,7 @@ void LinearColorSmoothing::interpolateFrame()
|
||||
const int64_t windowStart = now - (MS_PER_MICRO * _settlingTime);
|
||||
|
||||
/// The total weight of the frames that were included in our window; sum of the individual weights
|
||||
floatT fs = 0.0f;
|
||||
floatT fs = 0.0F;
|
||||
|
||||
// To calculate the mean component we iterate over all relevant frames;
|
||||
// from the most recent to the oldest frame that still clips our moving-average window given by time (now)
|
||||
@@ -331,7 +334,7 @@ void LinearColorSmoothing::interpolateFrame()
|
||||
}
|
||||
|
||||
/// The inverse scaling factor for the color components, clamped to (0, 1.0]; 1.0 for fs < 1, 1 : fs otherwise
|
||||
const floatT inv_fs = ((fs < 1.0f) ? 1.0f : 1.0f / fs) / (1 << SmallShiftBis);
|
||||
const floatT inv_fs = ((fs < 1.0F) ? 1.0F : 1.0F / fs) / (1 << SmallShiftBis);
|
||||
|
||||
// Normalize the mean component values for the window (fs)
|
||||
for (size_t i = 0; i < 3 * N; ++i)
|
||||
@@ -385,8 +388,8 @@ void LinearColorSmoothing::performDecay(const int64_t now) {
|
||||
if(_updateInterval <= 0 && !(interpolatePending || writePending)) {
|
||||
const int64_t nextActionExpected = std::min(interpolationTarget, writeTarget);
|
||||
const int64_t microsTillNextAction = nextActionExpected - now;
|
||||
const int64_t SLEEP_MAX_MICROS = 1000l; // We want to use usleep for up to 1ms
|
||||
const int64_t SLEEP_RES_MICROS = 100l; // Expected resolution is >= 100µs on stock linux
|
||||
const int64_t SLEEP_MAX_MICROS = 1000L; // We want to use usleep for up to 1ms
|
||||
const int64_t SLEEP_RES_MICROS = 100L; // Expected resolution is >= 100µs on stock linux
|
||||
|
||||
if(microsTillNextAction > SLEEP_RES_MICROS) {
|
||||
const int64_t wait = std::min(microsTillNextAction - SLEEP_RES_MICROS, SLEEP_MAX_MICROS);
|
||||
@@ -398,12 +401,12 @@ void LinearColorSmoothing::performDecay(const int64_t now) {
|
||||
// Write stats every 30 sec
|
||||
if ((now > (_renderedStatTime + 30 * 1000000)) && (_renderedCounter > _renderedStatCounter))
|
||||
{
|
||||
Info(_log, "decay - rendered frames [%d] (%f/s), interpolated frames [%d] (%f/s) in [%f ms]"
|
||||
Debug(_log, "decay - rendered frames [%d] (%f/s), interpolated frames [%d] (%f/s) in [%f ms]"
|
||||
, _renderedCounter - _renderedStatCounter
|
||||
, (1.0f * (_renderedCounter - _renderedStatCounter) / ((now - _renderedStatTime) / 1000000.0f))
|
||||
, (1.0F * (_renderedCounter - _renderedStatCounter) / ((now - _renderedStatTime) / 1000000.0F))
|
||||
, _interpolationCounter - _interpolationStatCounter
|
||||
, (1.0f * (_interpolationCounter - _interpolationStatCounter) / ((now - _renderedStatTime) / 1000000.0f))
|
||||
, (now - _renderedStatTime) / 1000.0f
|
||||
, (1.0F * (_interpolationCounter - _interpolationStatCounter) / ((now - _renderedStatTime) / 1000000.0F))
|
||||
, (now - _renderedStatTime) / 1000.0F
|
||||
);
|
||||
_renderedStatTime = now;
|
||||
_renderedStatCounter = _renderedCounter;
|
||||
@@ -413,7 +416,7 @@ void LinearColorSmoothing::performDecay(const int64_t now) {
|
||||
|
||||
void LinearColorSmoothing::performLinear(const int64_t now) {
|
||||
const int64_t deltaTime = _targetTime - now;
|
||||
const float k = 1.0f - 1.0f * deltaTime / (_targetTime - _previousWriteTime);
|
||||
const float k = 1.0F - 1.0F * deltaTime / (_targetTime - _previousWriteTime);
|
||||
const size_t N = _previousValues.size();
|
||||
|
||||
for (size_t i = 0; i < N; ++i)
|
||||
@@ -461,7 +464,7 @@ void LinearColorSmoothing::updateLeds()
|
||||
|
||||
void LinearColorSmoothing::rememberFrame(const std::vector<ColorRgb> &ledColors)
|
||||
{
|
||||
//Info(_log, "rememberFrame - before _frameQueue.size() [%d]", _frameQueue.size());
|
||||
//Debug(_log, "rememberFrame - before _frameQueue.size() [%d]", _frameQueue.size());
|
||||
|
||||
const int64_t now = micros();
|
||||
|
||||
@@ -478,7 +481,7 @@ void LinearColorSmoothing::rememberFrame(const std::vector<ColorRgb> &ledColors)
|
||||
|
||||
if (p > 0)
|
||||
{
|
||||
//Info(_log, "rememberFrame - erasing %d frames", p);
|
||||
//Debug(_log, "rememberFrame - erasing %d frames", p);
|
||||
_frameQueue.erase(_frameQueue.begin(), _frameQueue.begin() + p);
|
||||
}
|
||||
|
||||
@@ -486,7 +489,7 @@ void LinearColorSmoothing::rememberFrame(const std::vector<ColorRgb> &ledColors)
|
||||
const REMEMBERED_FRAME frame = REMEMBERED_FRAME(now, ledColors);
|
||||
_frameQueue.push_back(frame);
|
||||
|
||||
//Info(_log, "rememberFrame - after _frameQueue.size() [%d]", _frameQueue.size());
|
||||
//Debug(_log, "rememberFrame - after _frameQueue.size() [%d]", _frameQueue.size());
|
||||
}
|
||||
|
||||
|
||||
@@ -518,10 +521,12 @@ void LinearColorSmoothing::queueColors(const std::vector<ColorRgb> &ledColors)
|
||||
{
|
||||
// Push new colors in the delay-buffer
|
||||
if (_writeToLedsEnable)
|
||||
{
|
||||
_outputQueue.push_back(ledColors);
|
||||
}
|
||||
|
||||
// If the delay-buffer is filled pop the front and write to device
|
||||
if (_outputQueue.size() > 0)
|
||||
if (!_outputQueue.empty())
|
||||
{
|
||||
if (_outputQueue.size() > _outputDelay || !_writeToLedsEnable)
|
||||
{
|
||||
@@ -581,7 +586,7 @@ unsigned LinearColorSmoothing::addConfig(int settlingTime_ms, double ledUpdateFr
|
||||
SmoothingType::Linear,
|
||||
false,
|
||||
settlingTime_ms,
|
||||
int64_t(1000.0 / ledUpdateFrequency_hz),
|
||||
static_cast<int>(1000.0 / ledUpdateFrequency_hz),
|
||||
ledUpdateFrequency_hz,
|
||||
ledUpdateFrequency_hz,
|
||||
updateDelay,
|
||||
@@ -603,7 +608,7 @@ unsigned LinearColorSmoothing::updateConfig(unsigned cfgID, int settlingTime_ms,
|
||||
SmoothingType::Linear,
|
||||
false,
|
||||
settlingTime_ms,
|
||||
int64_t(1000.0 / ledUpdateFrequency_hz),
|
||||
static_cast<int>(1000.0 / ledUpdateFrequency_hz),
|
||||
ledUpdateFrequency_hz,
|
||||
ledUpdateFrequency_hz,
|
||||
updateDelay,
|
||||
@@ -630,7 +635,7 @@ bool LinearColorSmoothing::selectConfig(unsigned cfg, bool force)
|
||||
}
|
||||
|
||||
//Debug( _log, "selectConfig FORCED - _currentConfigId [%u], force [%d]", cfg, force);
|
||||
if (cfg < (unsigned)_cfgList.count())
|
||||
if (cfg < static_cast<uint>(_cfgList.count()) )
|
||||
{
|
||||
_smoothingType = _cfgList[cfg].smoothingType;
|
||||
_settlingTime = _cfgList[cfg].settlingTime;
|
||||
@@ -642,14 +647,14 @@ bool LinearColorSmoothing::selectConfig(unsigned cfg, bool force)
|
||||
_interpolationIntervalMicros = int64_t(1000000.0 / _interpolationRate);
|
||||
_dithering = _cfgList[cfg].dithering;
|
||||
_decay = _cfgList[cfg].decay;
|
||||
_invWindow = 1.0f / (MS_PER_MICRO * _settlingTime);
|
||||
_invWindow = 1.0F / (MS_PER_MICRO * _settlingTime);
|
||||
|
||||
// Set _weightFrame based on the given decay
|
||||
const float decay = _decay;
|
||||
const floatT inv_window = _invWindow;
|
||||
|
||||
// For decay != 1 use power-based approach for calculating the moving average values
|
||||
if(std::abs(decay - 1.0f) > std::numeric_limits<float>::epsilon()) {
|
||||
if(std::abs(decay - 1.0F) > std::numeric_limits<float>::epsilon()) {
|
||||
// Exponential Decay
|
||||
_weightFrame = [inv_window,decay](const int64_t fs, const int64_t fe, const int64_t ws) {
|
||||
const floatT s = (fs - ws) * inv_window;
|
||||
@@ -660,7 +665,7 @@ bool LinearColorSmoothing::selectConfig(unsigned cfg, bool force)
|
||||
} else {
|
||||
// For decay == 1 use linear interpolation of the moving average values
|
||||
// Linear Decay
|
||||
_weightFrame = [inv_window](const int64_t fs, const int64_t fe, const int64_t ws) {
|
||||
_weightFrame = [inv_window](const int64_t fs, const int64_t fe, const int64_t /*ws*/) {
|
||||
// Linear weighting = (end - start) * scale
|
||||
return static_cast<floatT>((fe - fs) * inv_window);
|
||||
};
|
||||
@@ -693,7 +698,7 @@ bool LinearColorSmoothing::selectConfig(unsigned cfg, bool force)
|
||||
// DebugIf( _pause, _log, "set smoothing cfg: %d, pause", _currentConfigId );
|
||||
|
||||
const float thalf = (1.0-std::pow(1.0/2, 1.0/_decay))*_settlingTime;
|
||||
Info( _log, "%s - Time: %d ms, outputRate %f Hz, interpolationRate: %f Hz, timer: %d ms, Dithering: %d, Decay: %f -> HalfTime: %f ms", _smoothingType == SmoothingType::Decay ? "decay" : "linear", _settlingTime, _outputRate, _interpolationRate, _updateInterval, _dithering ? 1 : 0, _decay, thalf);
|
||||
Debug( _log, "cfg [%d]: Type: %s - Time: %d ms, outputRate %f Hz, interpolationRate: %f Hz, timer: %d ms, Dithering: %d, Decay: %f -> HalfTime: %f ms", cfg, _smoothingType == SmoothingType::Decay ? "decay" : "linear", _settlingTime, _outputRate, _interpolationRate, _updateInterval, _dithering ? 1 : 0, _decay, thalf);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user