Skip to contentSkip to conversation

Signaling user-space through kcontrol

DISCUSSION Patrick Lai 5 participants 10 messages Sep 28, 2011

lore
Share & tools
lore
#0 lore raw

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

Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
#1 lore raw
Quoted 8 lines · Patrick Lai

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?

Signature · 1 line
~Vinod
#2 lore raw
Quoted 11 lines · Vinod Koul
Quoted 8 lines · Patrick Lai

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

Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
#3 lore raw
Quoted 10 lines · Patrick Lai
Quoted 9 lines · Vinod Koul
Quoted 8 lines · Patrick Lai

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?

Quoted 6 lines
Quoted 2 lines

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

Signature · 1 line
~Vinod
#4 lore raw
Quoted 7 lines · Vinod Koul
Quoted 4 lines

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

Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
#8 lore raw
In reply to Patrick Lai
Quoted 4 lines · Patrick Lai

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.

Quoted 1 line

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?

Quoted 1 line

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

#9 lore raw
In reply to Patrick Lai
Quoted 2 lines

Is there an sample user-space code which gets kcontrol event?

QasMixer supports snd_hctl_* controls beside snd_mixer_selem_* controls. (select the element mixer view)
AFAIK snd_hctl_* is only thin wrapper over snd_ctl_*.

Sebastian

#5 lore raw
In reply to Patrick Lai
Quoted 7 lines · Patrick Lai
Quoted 4 lines · Vinod Koul
Quoted 4 lines

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.

Quoted 6 lines
Quoted 2 lines

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.

#6 lore raw
Quoted 5 lines

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?

Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
#7 lore raw
Quoted 4 lines · Patrick Lai

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.