mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
acdf733936
* Creating Audio Grabber Creating Audio Grabber Creating Audio Grabber. Successfully began capturing audio in windows. Starting to implement a hard-coded UV Visualizer. Got Windows DirectSound Implementation working. Hardcoded basic VU Meter. Begin working on linux audio grabber implementation. Finished Linux Draft Implementation. Minor Mods to windows implementation. Windows: - Free memory used by device id. - Prevent starting audio if the grabber is disabled - More debug logging Linux: - Prevent starting audio if the grabber is disabled Added strings to english Removed "custom" from device selection Made hard-coded visualizer values configurable. wrote values to imageData with BGR priority to enable configurable values to be set in RGB format. created logic to support "Automatic" to enable the API to select the default device. Add language key for audio in "Remote Control" section. Removed audio configuration for number of channels. This was causing an error with some devices. Fixed logic to update capture while its active. Optimizing code . UI Tweaks Destructuring. Fixed build error on linux. Custom Effects - Clean-ups and Enhancements (#1163) * Cleanup EffectFileHandler * Support Custom Effect Schemas and align EffectFileHandler * Change back to colon prefix for system effects * WebSockets - Fix error in handling fragmented frames * Correct missing colon updates * Update json with image file location for custom gif effects * Image effect deletion - considere full filename is stored in JSON * Correct selection lists indentions Creating Audio Grabber Creating Audio Grabber Creating Audio Grabber. Successfully began capturing audio in windows. Starting to implement a hard-coded UV Visualizer. Got Windows DirectSound Implementation working. Hardcoded basic VU Meter. Begin working on linux audio grabber implementation. Finished Linux Draft Implementation. Minor Mods to windows implementation. Windows: - Free memory used by device id. - Prevent starting audio if the grabber is disabled - More debug logging Linux: - Prevent starting audio if the grabber is disabled Added strings to english Removed "custom" from device selection Made hard-coded visualizer values configurable. wrote values to imageData with BGR priority to enable configurable values to be set in RGB format. created logic to support "Automatic" to enable the API to select the default device. Add language key for audio in "Remote Control" section. Removed audio configuration for number of channels. This was causing an error with some devices. Fixed logic to update capture while its active. Optimizing code . UI Tweaks Destructuring. Fixed build error on linux. Commented setVideoMode from AudioGrabber. Linux Threading changes. Implementing new API Continuing to implement audio into new APIs Fixed Audio Grabber for DirectSound on Windows Fixed UI for Audio Grabber Configuration Default AUDIO to off unless specified. fixed missing #ifdef for audio grabber. Added logic to calculate a dynamic multiplier from the signal input. Updating linux api for discovering devices. Fixed HTML/JS issues with view. Fixed NPE in Windows. Disabled setting thread priority in linux. updated the schema options check to pass through hidden states and commented the change. Updated grabber start conditions Updated Audio grabber to instantiate similar to video grabber Updated windows grabber to set "started" flag to false when shutting down. Removed "tryStart" to prevent enabling audio capture unnecessarily. Fixing instance audio grabber device configuration Added configurable resolution Reduced tolerance to 5% Fixed issue where grabber failed for additional instances when "start" was called multiple times. Fixed resolution calculation Change averaging algorithm to prevent overflowing the sum. Updated logic to stop audio grabber when disabled. Fix integer casting and rounding. Restart grabber on configuration change. Fix missing include/grabber/AudioGrabber. Disable tolerance. Added configurable tolerance. Fixed tolerance algorithm. reset multiplier on configuration change. Line Endings Proposed change and questions/request to fix implementing more of LordGrey's suggestions. Fix mode for snd_pcm_open. Latest ALSA uses SND_PCM_NONBLOCK instead of SND_PCM_OPEN_NONBLOCK defaulted multiplier to 0 "auto" defaulted tolerance to 20% changed 100 to 100.0 for pixel value percentage calculation to fix value from being 0. missed a 100 as a double so precision isn't lost during math operation. Fix Windows grabber and further cleanups Enable Audio grabbing in standard build Remove empty methods Fix audio capture priority setting Remove unused code Clean-up default config Allow additional json-editor attributes Allow multiple effects and resetting to defaults Correct default values Allow to build for Qt < 5.14 Update CodeQL build dependency Update build dependencies Remove effect1 placeholder * Renamed uvMeter to VU Meter (Volume Unit) - Fixed issues flagged by code scanning bot. * Moved stop call into destructor of implementing class. * Removed commented linux audio channel configuration logic. --------- Co-authored-by: Michael Rochelle <michael@j2inn.com>
311 lines
7.3 KiB
C++
311 lines
7.3 KiB
C++
// Hyperion includes
|
|
#include <hyperion/GrabberWrapper.h>
|
|
#include <hyperion/Grabber.h>
|
|
#include <HyperionConfig.h>
|
|
|
|
// utils includes
|
|
#include <utils/GlobalSignals.h>
|
|
|
|
// qt
|
|
#include <QTimer>
|
|
|
|
GrabberWrapper* GrabberWrapper::instance = nullptr;
|
|
const int GrabberWrapper::DEFAULT_RATE_HZ = 25;
|
|
const int GrabberWrapper::DEFAULT_MIN_GRAB_RATE_HZ = 1;
|
|
const int GrabberWrapper::DEFAULT_MAX_GRAB_RATE_HZ = 30;
|
|
const int GrabberWrapper::DEFAULT_PIXELDECIMATION = 8;
|
|
|
|
/// Map of Hyperion instances with grabber name that requested screen capture
|
|
QMap<int, QString> GrabberWrapper::GRABBER_SYS_CLIENTS = QMap<int, QString>();
|
|
QMap<int, QString> GrabberWrapper::GRABBER_V4L_CLIENTS = QMap<int, QString>();
|
|
QMap<int, QString> GrabberWrapper::GRABBER_AUDIO_CLIENTS = QMap<int, QString>();
|
|
bool GrabberWrapper::GLOBAL_GRABBER_SYS_ENABLE = false;
|
|
bool GrabberWrapper::GLOBAL_GRABBER_V4L_ENABLE = false;
|
|
bool GrabberWrapper::GLOBAL_GRABBER_AUDIO_ENABLE = false;
|
|
|
|
GrabberWrapper::GrabberWrapper(const QString& grabberName, Grabber * ggrabber, int updateRate_Hz)
|
|
: _grabberName(grabberName)
|
|
, _log(Logger::getInstance(grabberName.toUpper()))
|
|
, _timer(new QTimer(this))
|
|
, _updateInterval_ms(1000/updateRate_Hz)
|
|
, _ggrabber(ggrabber)
|
|
, _image(0,0)
|
|
{
|
|
GrabberWrapper::instance = this;
|
|
|
|
// Configure the timer to generate events every n milliseconds
|
|
_timer->setTimerType(Qt::PreciseTimer);
|
|
_timer->setInterval(_updateInterval_ms);
|
|
|
|
connect(_timer, &QTimer::timeout, this, &GrabberWrapper::action);
|
|
|
|
// connect the image forwarding
|
|
if (_grabberName.startsWith("V4L"))
|
|
connect(this, &GrabberWrapper::systemImage, GlobalSignals::getInstance(), &GlobalSignals::setV4lImage);
|
|
else if (_grabberName.startsWith("Audio"))
|
|
connect(this, &GrabberWrapper::systemImage, GlobalSignals::getInstance(), &GlobalSignals::setAudioImage);
|
|
else
|
|
connect(this, &GrabberWrapper::systemImage, GlobalSignals::getInstance(), &GlobalSignals::setSystemImage);
|
|
|
|
// listen for source requests
|
|
connect(GlobalSignals::getInstance(), &GlobalSignals::requestSource, this, &GrabberWrapper::handleSourceRequest);
|
|
}
|
|
|
|
GrabberWrapper::~GrabberWrapper()
|
|
{
|
|
GrabberWrapper::instance = nullptr;
|
|
}
|
|
|
|
bool GrabberWrapper::start()
|
|
{
|
|
bool rc = false;
|
|
if ( open() )
|
|
{
|
|
if (!_timer->isActive())
|
|
{
|
|
// Start the timer with the pre configured interval
|
|
Debug(_log,"Grabber start()");
|
|
_timer->start();
|
|
}
|
|
|
|
rc = _timer->isActive();
|
|
}
|
|
return rc;
|
|
}
|
|
|
|
void GrabberWrapper::stop()
|
|
{
|
|
if (_timer->isActive())
|
|
{
|
|
// Stop the timer, effectively stopping the process
|
|
Debug(_log,"Grabber stop()");
|
|
_timer->stop();
|
|
}
|
|
}
|
|
|
|
bool GrabberWrapper::isActive() const
|
|
{
|
|
return _timer->isActive();
|
|
}
|
|
|
|
QStringList GrabberWrapper::getActive(int inst, GrabberTypeFilter type) const
|
|
{
|
|
QStringList result = QStringList();
|
|
|
|
if (type == GrabberTypeFilter::SCREEN || type == GrabberTypeFilter::ALL)
|
|
{
|
|
if (GRABBER_SYS_CLIENTS.contains(inst))
|
|
result << GRABBER_SYS_CLIENTS.value(inst);
|
|
}
|
|
|
|
if (type == GrabberTypeFilter::VIDEO || type == GrabberTypeFilter::ALL)
|
|
{
|
|
if (GRABBER_V4L_CLIENTS.contains(inst))
|
|
result << GRABBER_V4L_CLIENTS.value(inst);
|
|
}
|
|
|
|
if (type == GrabberTypeFilter::AUDIO || type == GrabberTypeFilter::ALL)
|
|
{
|
|
if (GRABBER_AUDIO_CLIENTS.contains(inst))
|
|
result << GRABBER_AUDIO_CLIENTS.value(inst);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
QStringList GrabberWrapper::availableGrabbers(GrabberTypeFilter type)
|
|
{
|
|
QStringList grabbers;
|
|
|
|
if (type == GrabberTypeFilter::SCREEN || type == GrabberTypeFilter::ALL)
|
|
{
|
|
#ifdef ENABLE_DISPMANX
|
|
grabbers << "dispmanx";
|
|
#endif
|
|
|
|
#ifdef ENABLE_FB
|
|
grabbers << "framebuffer";
|
|
#endif
|
|
|
|
#ifdef ENABLE_AMLOGIC
|
|
grabbers << "amlogic";
|
|
#endif
|
|
|
|
#ifdef ENABLE_OSX
|
|
grabbers << "osx";
|
|
#endif
|
|
|
|
#ifdef ENABLE_X11
|
|
grabbers << "x11";
|
|
#endif
|
|
|
|
#ifdef ENABLE_XCB
|
|
grabbers << "xcb";
|
|
#endif
|
|
|
|
#ifdef ENABLE_QT
|
|
grabbers << "qt";
|
|
#endif
|
|
|
|
#ifdef ENABLE_DX
|
|
grabbers << "dx";
|
|
#endif
|
|
}
|
|
|
|
if (type == GrabberTypeFilter::VIDEO || type == GrabberTypeFilter::ALL)
|
|
{
|
|
#if defined(ENABLE_V4L2) || defined(ENABLE_MF)
|
|
grabbers << "v4l2";
|
|
#endif
|
|
}
|
|
|
|
if (type == GrabberTypeFilter::AUDIO || type == GrabberTypeFilter::ALL)
|
|
{
|
|
#ifdef ENABLE_AUDIO
|
|
grabbers << "audio";
|
|
#endif
|
|
}
|
|
|
|
return grabbers;
|
|
}
|
|
|
|
void GrabberWrapper::setVideoMode(VideoMode mode)
|
|
{
|
|
if (_ggrabber != nullptr)
|
|
{
|
|
Info(_log,"setVideoMode");
|
|
_ggrabber->setVideoMode(mode);
|
|
}
|
|
}
|
|
|
|
void GrabberWrapper::setFlipMode(const QString& flipMode)
|
|
{
|
|
_ggrabber->setFlipMode(parseFlipMode(flipMode));
|
|
}
|
|
|
|
void GrabberWrapper::setCropping(int cropLeft, int cropRight, int cropTop, int cropBottom)
|
|
{
|
|
_ggrabber->setCropping(cropLeft, cropRight, cropTop, cropBottom);
|
|
}
|
|
|
|
void GrabberWrapper::updateTimer(int interval)
|
|
{
|
|
if(_updateInterval_ms != interval)
|
|
{
|
|
_updateInterval_ms = interval;
|
|
|
|
const bool& timerWasActive = _timer->isActive();
|
|
_timer->stop();
|
|
_timer->setInterval(_updateInterval_ms);
|
|
|
|
if(timerWasActive)
|
|
_timer->start();
|
|
}
|
|
}
|
|
|
|
void GrabberWrapper::handleSettingsUpdate(settings::type type, const QJsonDocument& config)
|
|
{
|
|
if (type == settings::SYSTEMCAPTURE &&
|
|
!_grabberName.startsWith("V4L") &&
|
|
!_grabberName.startsWith("Audio"))
|
|
{
|
|
// extract settings
|
|
const QJsonObject& obj = config.object();
|
|
|
|
// save current state
|
|
bool isEnabled = getSysGrabberState();
|
|
|
|
// set global grabber state
|
|
setSysGrabberState(obj["enable"].toBool(false));
|
|
|
|
if (getSysGrabberState())
|
|
{
|
|
// width/height
|
|
_ggrabber->setWidthHeight(obj["width"].toInt(96), obj["height"].toInt(96));
|
|
|
|
// display index for MAC
|
|
_ggrabber->setDisplayIndex(obj["input"].toInt(0));
|
|
|
|
// pixel decimation for x11
|
|
_ggrabber->setPixelDecimation(obj["pixelDecimation"].toInt(DEFAULT_PIXELDECIMATION));
|
|
|
|
// crop for system capture
|
|
_ggrabber->setCropping(
|
|
obj["cropLeft"].toInt(0),
|
|
obj["cropRight"].toInt(0),
|
|
obj["cropTop"].toInt(0),
|
|
obj["cropBottom"].toInt(0));
|
|
|
|
_ggrabber->setFramerate(obj["fps"].toInt(DEFAULT_RATE_HZ));
|
|
// eval new update time
|
|
updateTimer(_ggrabber->getUpdateInterval());
|
|
|
|
// start if current state is not true
|
|
if (!isEnabled)
|
|
{
|
|
start();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
stop();
|
|
}
|
|
}
|
|
}
|
|
|
|
void GrabberWrapper::handleSourceRequest(hyperion::Components component, int hyperionInd, bool listen)
|
|
{
|
|
if (component == hyperion::Components::COMP_GRABBER &&
|
|
!_grabberName.startsWith("V4L") &&
|
|
!_grabberName.startsWith("Audio"))
|
|
{
|
|
if (listen)
|
|
GRABBER_SYS_CLIENTS.insert(hyperionInd, _grabberName);
|
|
else
|
|
GRABBER_SYS_CLIENTS.remove(hyperionInd);
|
|
|
|
if (GRABBER_SYS_CLIENTS.empty() || !getSysGrabberState())
|
|
stop();
|
|
else
|
|
start();
|
|
}
|
|
else if (component == hyperion::Components::COMP_V4L &&
|
|
_grabberName.startsWith("V4L"))
|
|
{
|
|
if (listen)
|
|
GRABBER_V4L_CLIENTS.insert(hyperionInd, _grabberName);
|
|
else
|
|
GRABBER_V4L_CLIENTS.remove(hyperionInd);
|
|
|
|
if (GRABBER_V4L_CLIENTS.empty() || !getV4lGrabberState())
|
|
stop();
|
|
else
|
|
start();
|
|
}
|
|
else if (component == hyperion::Components::COMP_AUDIO &&
|
|
_grabberName.startsWith("Audio"))
|
|
{
|
|
if (listen)
|
|
GRABBER_AUDIO_CLIENTS.insert(hyperionInd, _grabberName);
|
|
else
|
|
GRABBER_AUDIO_CLIENTS.remove(hyperionInd);
|
|
|
|
if (GRABBER_AUDIO_CLIENTS.empty())
|
|
stop();
|
|
else
|
|
start();
|
|
}
|
|
}
|
|
|
|
void GrabberWrapper::tryStart()
|
|
{
|
|
// verify start condition
|
|
if (!_grabberName.startsWith("V4L") &&
|
|
!_grabberName.startsWith("Audio") &&
|
|
!GRABBER_SYS_CLIENTS.empty() &&
|
|
getSysGrabberState())
|
|
{
|
|
start();
|
|
}
|
|
}
|