Refactor/Create APT/DNF Repository (#1648)

This commit is contained in:
Paulchen-Panther
2023-11-16 21:05:56 +01:00
committed by GitHub
parent c9518db597
commit 91270966f9
165 changed files with 1918 additions and 2924 deletions

View File

@@ -0,0 +1,196 @@
#ifndef AUDIOGRABBER_H
#define AUDIOGRABBER_H
#include <QObject>
#include <QColor>
#include <cmath>
// Hyperion-utils includes
#include <utils/ColorRgb.h>
#include <hyperion/Grabber.h>
#include <utils/Logger.h>
///
/// Base Audio Grabber Class
///
/// This class is extended by the windows audio grabber to provied DirectX9 access to the audio devices
/// This class is extended by the linux audio grabber to provide ALSA access to the audio devices
///
/// @brief The DirectX9 capture implementation
///
class AudioGrabber : public Grabber
{
Q_OBJECT
public:
///
/// Device properties
///
/// this structure holds the name, id, and inputs of the enumerated audio devices.
///
struct DeviceProperties
{
QString name = QString();
QString id = QString();
QMultiMap<QString, int> inputs = QMultiMap<QString, int>();
};
AudioGrabber();
~AudioGrabber() override;
///
/// Start audio capturing session
///
/// @returns true if successful
virtual bool start();
///
/// Stop audio capturing session
///
virtual void stop();
///
/// Restart the audio capturing session
///
void restart();
Logger* getLog();
///
/// Set Device
///
/// configures the audio device used by the grabber
///
/// @param[in] device identifier of audio device
void setDevice(const QString& device);
///
/// Set Configuration
///
/// sets the audio grabber's configuration parameters
///
/// @param[in] config object of configuration parameters
void setConfiguration(const QJsonObject& config);
///
/// Reset Multiplier
///
/// resets the calcualted audio multiplier so that it is recalculated
/// currently the multiplier is only reduced based on loudness.
///
/// TODO: also calculate a low signal and reset the multiplier
///
void resetMultiplier();
///
/// Discover
///
/// discovers audio devices in the system
///
/// @param[in] params discover parameters
/// @return array of audio devices
virtual QJsonArray discover(const QJsonObject& params);
signals:
void newFrame(const Image<ColorRgb>& image);
protected:
///
/// Process Audio Frame
///
/// this functions takes in an audio buffer and emits a visual representation of the audio data
///
/// @param[in] buffer The audio buffer to process
/// @param[in] length The length of audio data in the buffer
void processAudioFrame(int16_t* buffer, int length);
///
/// Audio device id / properties map
///
/// properties include information such as name, inputs, and etc...
///
QMap<QString, AudioGrabber::DeviceProperties> _deviceProperties;
///
/// Current device
///
QString _device;
///
/// Hot Color
///
/// the color of the leds when the signal is high or hot
///
QColor _hotColor;
///
/// Warn value
///
/// The maximum value of the warning color. above this threshold the signal is considered hot
///
int _warnValue;
///
/// Warn color
///
/// the color of the leds when the signal is in between the safe and warn value threshold
///
QColor _warnColor;
///
/// Save value
///
/// The maximum value of the safe color. above this threshold the signal enteres the warn zone.
/// below the signal is in the safe zone.
///
int _safeValue;
///
/// Safe color
///
/// the color of the leds when the signal is below the safe threshold
///
QColor _safeColor;
///
/// Multiplier
///
/// this value is used to multiply the input signal value. Some inputs may have a very low signal
/// and the multiplier is used to get the desired visualization.
///
/// When the multiplier is configured to 0, the multiplier is automatically configured based off of the average
/// signal amplitude and tolernace.
///
double _multiplier;
///
/// Tolerance
///
/// The tolerance is used to calculate what percentage of the top end part of the signal to ignore when
/// calculating the multiplier. This enables the effect to reach the hot zone with an auto configured multiplier
///
int _tolerance;
///
/// Dynamic Multiplier
///
/// This is the current value of the automatically configured multiplier.
///
double _dynamicMultiplier;
///
/// Started
///
/// true if the capturing session has started.
///
bool _started;
private:
///
/// @brief free the _screen pointer
///
void freeResources();
};
#endif // AUDIOGRABBER_H

View File

@@ -0,0 +1,86 @@
#ifndef AUDIOGRABBERLINUX_H
#define AUDIOGRABBERLINUX_H
#include <pthread.h>
#include <sched.h>
#include <alsa/asoundlib.h>
// Hyperion-utils includes
#include <grabber/audio/AudioGrabber.h>
///
/// @brief The Linux Audio capture implementation
///
class AudioGrabberLinux : public AudioGrabber
{
public:
AudioGrabberLinux();
~AudioGrabberLinux() override;
///
/// Process audio buffer
///
void processAudioBuffer(snd_pcm_sframes_t frames);
///
/// Is Running Flag
///
std::atomic<bool> _isRunning;
///
/// Current capture device
///
snd_pcm_t * _captureDevice;
public slots:
///
/// Start audio capturing session
///
/// @returns true if successful
bool start() override;
///
/// Stop audio capturing session
///
void stop() override;
///
/// Discovery audio devices
///
QJsonArray discover(const QJsonObject& params) override;
private:
///
/// Refresh audio devices
///
void refreshDevices();
///
/// Configure current audio capture interface
///
bool configureCaptureInterface();
///
/// Get device name from path
///
QString getDeviceName(const QString& devicePath) const;
///
/// Current sample rate
///
unsigned int _sampleRate;
///
/// Audio capture thread
///
pthread_t _audioThread;
///
/// ALSA device configuration parameters
///
snd_pcm_hw_params_t * _captureDeviceConfig;
};
#endif // AUDIOGRABBERLINUX_H

View File

@@ -0,0 +1,81 @@
#ifndef AUDIOGRABBERWINDOWS_H
#define AUDIOGRABBERWINDOWS_H
// Hyperion-utils includes
#include <grabber/audio/AudioGrabber.h>
#include <DSound.h>
///
/// @brief The Windows Audio capture implementation
///
class AudioGrabberWindows : public AudioGrabber
{
public:
AudioGrabberWindows();
~AudioGrabberWindows() override;
public slots:
bool start() override;
void stop() override;
QJsonArray discover(const QJsonObject& params) override;
private:
void refreshDevices();
bool configureCaptureInterface();
QString getDeviceName(const QString& devicePath) const;
void processAudioBuffer();
LPDIRECTSOUNDCAPTURE8 recordingDevice;
LPDIRECTSOUNDCAPTUREBUFFER8 recordingBuffer;
HANDLE audioThread;
DWORD bufferCapturePosition;
DWORD bufferCaptureSize;
DWORD notificationSize;
static DWORD WINAPI AudioThreadRunner(LPVOID param);
HANDLE notificationEvent;
std::atomic<bool> isRunning{ false };
static BOOL CALLBACK DirectSoundEnumProcessor(LPGUID deviceIdGuid, LPCWSTR deviceDescStr,
LPCWSTR deviceModelStr, LPVOID context)
{
// Skip undefined audio devices
if (deviceIdGuid == NULL)
return TRUE;
QMap<QString, AudioGrabber::DeviceProperties>* devices = (QMap<QString, AudioGrabber::DeviceProperties>*)context;
AudioGrabber::DeviceProperties device;
// Process Device Information
QString deviceName = QString::fromWCharArray(deviceDescStr);
// Process Device ID
LPOLESTR deviceIdStr;
HRESULT res = StringFromCLSID(*deviceIdGuid, &deviceIdStr);
if (FAILED(res))
{
Error(Logger::getInstance("AUDIOGRABBER"), "Failed to get CLSID-string for %s with error: 0x%08x: %s", QSTRING_CSTR(deviceName), res, std::system_category().message(res).c_str());
return FALSE;
}
QString deviceId = QString::fromWCharArray(deviceIdStr);
CoTaskMemFree(deviceIdStr);
Debug(Logger::getInstance("AUDIOGRABBER"), "Found Audio Device: %s", QSTRING_CSTR(deviceName));
device.id = deviceId;
device.name = deviceName;
devices->insert(deviceId, device);
return TRUE;
}
};
#endif // AUDIOGRABBERWINDOWS_H

View File

@@ -0,0 +1,69 @@
#pragma once
#include <hyperion/GrabberWrapper.h>
#ifdef WIN32
#include <grabber/audio/AudioGrabberWindows.h>
#endif
#ifdef __linux__
#include <grabber/audio/AudioGrabberLinux.h>
#endif
///
/// Audio Grabber wrapper
///
class AudioWrapper : public GrabberWrapper
{
public:
// The AudioWrapper has no params...
///
/// Constructs the Audio grabber with a specified grab size and update rate.
///
/// @param[in] device Audio Device Identifier
/// @param[in] updateRate_Hz The audio grab rate [Hz]
///
AudioWrapper();
///
/// Destructor of this Audio grabber. Releases any claimed resources.
///
~AudioWrapper() override;
///
/// Settings update handler
///
void handleSettingsUpdate(settings::type type, const QJsonDocument& config) override;
public slots:
///
/// Performs a single frame grab and computes the led-colors
///
void action() override;
///
/// Start audio capturing session
///
/// @returns true if successful
bool start() override;
///
/// Stop audio capturing session
///
void stop() override;
private:
void newFrame(const Image<ColorRgb>& image);
/// The actual grabber
#ifdef WIN32
AudioGrabberWindows _grabber;
#endif
#ifdef __linux__
AudioGrabberLinux _grabber;
#endif
};