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
This commit is contained in:
parent
bf5d006aef
commit
838a0f7cc1
@ -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 <alsa/asoundlib.h>
|
||||
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<void()> callback) {
|
||||
DEBUGTRACE_ENTER;
|
||||
assert(!_inputStream && !_outputStream);
|
||||
Lck lck(_mtx);
|
||||
// Alsa spits out annoying messages that are not useful
|
||||
{
|
||||
MuteErrHandler guard;
|
||||
|
||||
_devices = DeviceInfo::getDeviceInfo();
|
||||
}
|
||||
|
@ -16,6 +16,33 @@ using std::endl;
|
||||
using std::string;
|
||||
using std::to_string;
|
||||
|
||||
#if LASP_HAS_PA_ALSA
|
||||
#include <alsa/asoundlib.h>
|
||||
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");
|
||||
|
Loading…
Reference in New Issue
Block a user