From 838a0f7cc13961775897bd05db44868c0702ab47 Mon Sep 17 00:00:00 2001 From: "J.A. de Jong - Redu-Sone B.V., ASCEE V.O.F" Date: Wed, 26 Jun 2024 12:17:43 +0200 Subject: [PATCH] Silence portaudio alsa errors when querying device info AND when starting stream. Do not know whether this solves the problem of its verbosity, but at least the code is where it belongs --- cpp_src/device/lasp_streammgr.cpp | 25 ---------------- .../device/portaudio/lasp_portaudiodaq.cpp | 29 +++++++++++++++++++ 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/cpp_src/device/lasp_streammgr.cpp b/cpp_src/device/lasp_streammgr.cpp index 526e0c8..3b328c7 100644 --- a/cpp_src/device/lasp_streammgr.cpp +++ b/cpp_src/device/lasp_streammgr.cpp @@ -107,37 +107,12 @@ void StreamMgr::rescanDAQDevices(bool background, _pool.push_task(&StreamMgr::rescanDAQDevices_impl, this, callback); } } -#if LASP_HAS_PORTAUDIO && LASP_HAS_PA_ALSA -#include -void empty_handler(const char *file, int line, const char *function, int err, - const char *fmt, ...) {} - -// Temporarily set the ALSA eror handler to something that does nothing, to -// prevent ALSA from spitting out all kinds of misconfiguration errors. -class MuteErrHandler { - private: - snd_lib_error_handler_t _default_handler; - - public: - explicit MuteErrHandler() { - _default_handler = snd_lib_error; - snd_lib_error_set_handler(empty_handler); - } - - ~MuteErrHandler() { snd_lib_error_set_handler(_default_handler); } -}; -#else -// Does nothin in case of no ALSA -class MuteErrHandler {}; -#endif - void StreamMgr::rescanDAQDevices_impl(std::function callback) { DEBUGTRACE_ENTER; assert(!_inputStream && !_outputStream); Lck lck(_mtx); // Alsa spits out annoying messages that are not useful { - MuteErrHandler guard; _devices = DeviceInfo::getDeviceInfo(); } diff --git a/cpp_src/device/portaudio/lasp_portaudiodaq.cpp b/cpp_src/device/portaudio/lasp_portaudiodaq.cpp index 05e7cc7..e22c461 100644 --- a/cpp_src/device/portaudio/lasp_portaudiodaq.cpp +++ b/cpp_src/device/portaudio/lasp_portaudiodaq.cpp @@ -16,6 +16,33 @@ using std::endl; using std::string; using std::to_string; +#if LASP_HAS_PA_ALSA +#include +void empty_handler(const char *file, int line, const char *function, int err, + const char *fmt, ...) { + + // cerr << "Test empty error handler...\n"; + } + +// Temporarily set the ALSA eror handler to something that does nothing, to +// prevent ALSA from spitting out all kinds of misconfiguration errors. +class MuteErrHandler { + private: + snd_lib_error_handler_t _default_handler; + + public: + explicit MuteErrHandler() { + _default_handler = snd_lib_error; + snd_lib_error_set_handler(empty_handler); + } + + ~MuteErrHandler() { snd_lib_error_set_handler(_default_handler); } +}; +#else +// Does nothin in case of no ALSA +class MuteErrHandler {}; +#endif + inline void throwIfError(PaError e) { DEBUGTRACE_ENTER; if (e != paNoError) { @@ -44,6 +71,7 @@ class OurPaDeviceInfo : public DeviceInfo { void fillPortAudioDeviceInfo(DeviceInfoList &devinfolist) { DEBUGTRACE_ENTER; bool shouldPaTerminate = false; + MuteErrHandler guard; try { PaError err = Pa_Initialize(); /// PortAudio says that Pa_Terminate() should not be called whenever there @@ -348,6 +376,7 @@ PortAudioDaq::PortAudioDaq(const OurPaDeviceInfo &devinfo_gen, void PortAudioDaq::start(InDaqCallback inCallback, OutDaqCallback outCallback) { DEBUGTRACE_ENTER; assert(_stream); + MuteErrHandler guard; if (Pa_IsStreamActive(_stream)) { throw rte("Stream is already running");