Silence warnings from portaudio ALSA backend during device enumeration. Do device enumeration on background thread
This commit is contained in:
parent
1765042d20
commit
d50dd35745
@ -2,6 +2,7 @@
|
||||
if(LASP_HAS_PORTAUDIO)
|
||||
message("Building with Portaudio backend")
|
||||
if(WIN32)
|
||||
set(PA_USE_ALSA FALSE CACHE BOOL "Build PortAudio with ALSA backend")
|
||||
else()
|
||||
# Unix
|
||||
set(PA_USE_ALSA TRUE CACHE BOOL "Build PortAudio with ALSA backend")
|
||||
@ -9,7 +10,15 @@ if(LASP_HAS_PORTAUDIO)
|
||||
set(PA_USE_PULSEAUDIO FALSE CACHE BOOL "Build PortAudio with PulseAudio backend")
|
||||
set(PA_BUILD_SHARED_LIBS FALSE CACHE BOOL "Build static library")
|
||||
endif()
|
||||
|
||||
add_subdirectory(third_party/portaudio)
|
||||
include_directories(third_party/portaudio/include)
|
||||
link_directories(third_party/portaudio)
|
||||
|
||||
if(PA_USE_ALSA)
|
||||
add_definitions(-DLASP_HAS_PA_ALSA=1)
|
||||
else()
|
||||
add_definitions(-DLASP_HAS_PA_ALSA=0)
|
||||
endif()
|
||||
|
||||
endif()
|
||||
|
@ -75,7 +75,7 @@ StreamMgr::StreamMgr()
|
||||
{
|
||||
DEBUGTRACE_ENTER;
|
||||
// Trigger a scan for the available devices, in the background.
|
||||
rescanDAQDevices(false);
|
||||
rescanDAQDevices(true);
|
||||
}
|
||||
#if LASP_DEBUG == 1
|
||||
void StreamMgr::checkRightThread() const {
|
||||
@ -107,13 +107,44 @@ 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();
|
||||
}
|
||||
if (callback) {
|
||||
callback();
|
||||
}
|
||||
|
||||
_scanningDevices = false;
|
||||
}
|
||||
void StreamMgr::inCallback(const DaqData &data) {
|
||||
|
@ -93,6 +93,7 @@ void fillPortAudioDeviceInfo(DeviceInfoList &devinfolist) {
|
||||
d.api = portaudioALSAApi;
|
||||
break;
|
||||
case paASIO:
|
||||
hasDuplexMode = true;
|
||||
d.api = portaudioASIOApi;
|
||||
break;
|
||||
case paDirectSound:
|
||||
|
Loading…
Reference in New Issue
Block a user