[alsa-devel] Signaling user-space through kcontrol
Hi Mark,
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()? What is the ALSA library API to intercept the event? Is there an sample user-space code which gets kcontrol event?
Thanks Patrick
On Tue, 2011-09-27 at 23:14 -0700, Patrick Lai wrote:
Hi Mark,
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()? What is the ALSA library API to intercept the event? Is there an sample user-space code which gets kcontrol event?
What events do you have in mind?
On 9/27/2011 11:15 PM, Vinod Koul wrote:
On Tue, 2011-09-27 at 23:14 -0700, Patrick Lai wrote:
Hi Mark,
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()? What is the ALSA library API to intercept the event? Is there an sample user-space code which gets kcontrol event?
What events do you have in mind?
Main one is detection of short circuiting headphone For this case, there is no need for extra payload. In case of there is need to pass back some payload, I presume user-space application can simply call the get function upon receiving notification.
Thanks Patrick
On Tue, 2011-09-27 at 23:47 -0700, Patrick Lai wrote:
On 9/27/2011 11:15 PM, Vinod Koul wrote:
On Tue, 2011-09-27 at 23:14 -0700, Patrick Lai wrote:
Hi Mark,
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()? What is the ALSA library API to intercept the event? Is there an sample user-space code which gets kcontrol event?
What events do you have in mind?
Main one is detection of short circuiting headphone For this case, there is no need for extra payload. In case of there is need to pass back some payload, I presume user-space application can simply call the get function upon receiving notification.
And what would userspace do with that information? Apart from logging this, is there anything useful we can do with such info
On 9/28/2011 12:03 AM, Vinod Koul wrote:
Main one is detection of short circuiting headphone For this case, there is no need for extra payload. In case of there is need to pass back some payload, I presume user-space application can simply call the get function upon receiving notification.
And what would userspace do with that information? Apart from logging this, is there anything useful we can do with such info
Well, it's up to user-space application to decide. I suppose application would not allow audio route to headphone/headset at this point.
Thanks Patrick
On Wed, Sep 28, 2011 at 12:26:43AM -0700, Patrick Lai wrote:
On 9/28/2011 12:03 AM, Vinod Koul wrote:
Main one is detection of short circuiting headphone For this case, there is no need for extra payload. In case of there is need to pass back some payload, I presume user-space application can simply call the get function upon receiving notification.
And what would userspace do with that information? Apart from logging this, is there anything useful we can do with such info
Well, it's up to user-space application to decide. I suppose application would not allow audio route to headphone/headset at this point.
Something like that specific example should probably be reported via the snd_jack accessory detection infrastructure which can then offer a consistent interface between all sound cards with minimal work on the part of the individual driver. There will doubtless be other examples though.
Something like that specific example should probably be reported via the snd_jack accessory detection infrastructure which can then offer a consistent interface between all sound cards with minimal work on the part of the individual driver. There will doubtless be other examples though.
Agree that should go through consistent interface but not exactly sure if going through input device interface is appropriate though. Isn't the same reasoning why it has been decided to create ALSA specific API for headset detection?
On Wed, Sep 28, 2011 at 09:27:31AM -0700, Patrick Lai wrote:
Agree that should go through consistent interface but not exactly sure if going through input device interface is appropriate though. Isn't the same reasoning why it has been decided to create ALSA specific API for headset detection?
That's why I said use the jack API not the input API, if you're open coding an input interface for jacks in ALSA you're doing something wrong. Just use the jack API and let it worry about how to tell the rest of the system about what's going on - a driver shouldn't have to worry about the details.
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
participants (5)
-
Clemens Ladisch
-
Mark Brown
-
Patrick Lai
-
Sebastian H.
-
Vinod Koul