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)
|
if(LASP_HAS_PORTAUDIO)
|
||||||
message("Building with Portaudio backend")
|
message("Building with Portaudio backend")
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
|
set(PA_USE_ALSA FALSE CACHE BOOL "Build PortAudio with ALSA backend")
|
||||||
else()
|
else()
|
||||||
# Unix
|
# Unix
|
||||||
set(PA_USE_ALSA TRUE CACHE BOOL "Build PortAudio with ALSA backend")
|
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_USE_PULSEAUDIO FALSE CACHE BOOL "Build PortAudio with PulseAudio backend")
|
||||||
set(PA_BUILD_SHARED_LIBS FALSE CACHE BOOL "Build static library")
|
set(PA_BUILD_SHARED_LIBS FALSE CACHE BOOL "Build static library")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_subdirectory(third_party/portaudio)
|
add_subdirectory(third_party/portaudio)
|
||||||
include_directories(third_party/portaudio/include)
|
include_directories(third_party/portaudio/include)
|
||||||
link_directories(third_party/portaudio)
|
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()
|
endif()
|
||||||
|
@ -75,7 +75,7 @@ StreamMgr::StreamMgr()
|
|||||||
{
|
{
|
||||||
DEBUGTRACE_ENTER;
|
DEBUGTRACE_ENTER;
|
||||||
// Trigger a scan for the available devices, in the background.
|
// Trigger a scan for the available devices, in the background.
|
||||||
rescanDAQDevices(false);
|
rescanDAQDevices(true);
|
||||||
}
|
}
|
||||||
#if LASP_DEBUG == 1
|
#if LASP_DEBUG == 1
|
||||||
void StreamMgr::checkRightThread() const {
|
void StreamMgr::checkRightThread() const {
|
||||||
@ -107,13 +107,44 @@ void StreamMgr::rescanDAQDevices(bool background,
|
|||||||
_pool.push_task(&StreamMgr::rescanDAQDevices_impl, this, callback);
|
_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) {
|
void StreamMgr::rescanDAQDevices_impl(std::function<void()> callback) {
|
||||||
DEBUGTRACE_ENTER;
|
DEBUGTRACE_ENTER;
|
||||||
|
assert(!_inputStream && !_outputStream);
|
||||||
Lck lck(_mtx);
|
Lck lck(_mtx);
|
||||||
_devices = DeviceInfo::getDeviceInfo();
|
// Alsa spits out annoying messages that are not useful
|
||||||
|
{
|
||||||
|
MuteErrHandler guard;
|
||||||
|
|
||||||
|
_devices = DeviceInfo::getDeviceInfo();
|
||||||
|
}
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
_scanningDevices = false;
|
_scanningDevices = false;
|
||||||
}
|
}
|
||||||
void StreamMgr::inCallback(const DaqData &data) {
|
void StreamMgr::inCallback(const DaqData &data) {
|
||||||
|
@ -93,6 +93,7 @@ void fillPortAudioDeviceInfo(DeviceInfoList &devinfolist) {
|
|||||||
d.api = portaudioALSAApi;
|
d.api = portaudioALSAApi;
|
||||||
break;
|
break;
|
||||||
case paASIO:
|
case paASIO:
|
||||||
|
hasDuplexMode = true;
|
||||||
d.api = portaudioASIOApi;
|
d.api = portaudioASIOApi;
|
||||||
break;
|
break;
|
||||||
case paDirectSound:
|
case paDirectSound:
|
||||||
|
Loading…
Reference in New Issue
Block a user