Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Silence alsa errors #284

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions soundio/soundio.h
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,14 @@ struct SoundIo {
/// Optional: JACK error callback.
/// See SoundIo::jack_info_callback
void (*jack_error_callback)(const char *msg);


/// Optional: ALSA error callback.
/// By default, libsoundio sets this to an empty function in order to
/// silence stderr messages from ALSA. You may override the behavior by
/// setting this to `NULL` to reinstate ALSAs default behaviour of printing
/// to stderr.
void(* alsa_error_callback) (const char *file, int line, const char *function, int err, const char *fmt,...);
};

/// The size of this struct is not part of the API or ABI.
Expand Down
2 changes: 2 additions & 0 deletions src/alsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -1867,6 +1867,8 @@ int soundio_alsa_init(struct SoundIoPrivate *si) {
struct SoundIoAlsa *sia = &si->backend_data.alsa;
int err;

snd_lib_error_set_handler(si->pub.alsa_error_callback);

sia->notify_fd = -1;
sia->notify_wd = -1;
SOUNDIO_ATOMIC_FLAG_TEST_AND_SET(sia->abort_flag);
Expand Down
9 changes: 6 additions & 3 deletions src/soundio.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@ void soundio_destroy(struct SoundIo *soundio) {
}

static void do_nothing_cb(struct SoundIo *soundio) { }
static void default_msg_callback(const char *msg) { }
static void default_jack_msg_callback(const char *msg) { }
static void snd_lib_error_default(const char *file, int line, const char *function, int err, const char *fmt, ...)
{ }

static void default_backend_disconnect_cb(struct SoundIo *soundio, int err) {
soundio_panic("libsoundio: backend disconnected: %s", soundio_strerror(err));
Expand Down Expand Up @@ -199,8 +201,9 @@ struct SoundIo *soundio_create(void) {
soundio->on_events_signal = do_nothing_cb;
soundio->app_name = "SoundIo";
soundio->emit_rtprio_warning = default_emit_rtprio_warning;
soundio->jack_info_callback = default_msg_callback;
soundio->jack_error_callback = default_msg_callback;
soundio->jack_info_callback = default_jack_msg_callback;
soundio->jack_error_callback = default_jack_msg_callback;
soundio->alsa_error_callback = snd_lib_error_default;
return soundio;
}

Expand Down