Patrick Lai wrote:
The codec I am working on, beside headset detection, also have other type of events to be propagated to user space. Per our discussion at IPC, there is way to signal user-space through kcontrol. Is it through calling snd_ctl_notify()?
Yes.
What is the ALSA library API to intercept the event?
snd_ctl_open() and snd_ctl_subscribe(), then snd_ctl_read() in a loop. To integrate this into a poll()-based event loop, use the snd_ctl_poll_descriptors*() functions.
Do you want to write a specific tool that does nothing but waiting for these events, or will this be integrated into another program?
Is there an sample user-space code which gets kcontrol event?
Not really. There is alsamixer, but it uses a different API (the snd_mixer* functions implement an abstracation on top of the snd_ctl* stuff). In the main loop (alsa-utils/alsamixer/mainloop.c), the snd_mixer_poll_descriptors* functions work similar to the snd_ctl* functions, but the snd_mixer_handle_events() function then reads the event(s) from the ctl device and calls callback functions, in this case elem_callback() and mixer_callback() in mixer_widget.c.
Regards, Clemens