Skip to contentSkip to conversation

Asterisk 1.4.17 and alsa 1.0.19 dmix plugin problem.

DISCUSSION Nicola Mfb 2 participants 6 messages Apr 20, 2009 – Apr 21, 2009

lore
Share & tools
lore

Nicola Mfb

author
#0 lore raw

Hi!
I'm sorry if this is an old issue but I did not found help in archives/alsaweb/google and I'm new to alsa, so this report is what I guessed reading sources and compiling test apps for about 2 days, and the following assumptions may be completely wrong.

Asterisk has an alsa channel that works fine when using plughw:0,0 both for read and for writing, but if use plug:dmix/plug:dsnoop or default with a dmix/dsnoop wrapper in /etc/asound.conf it does not emit any sound. It uses select on poll fd descriptor to know if the pcm is ready to be sent output samples.
The select will never return as it seems the dmix plugin is not able to signal when is ready.
I noted that using snd_pcm_wait works well but cannot be used in asterisk as it needs to select on two fd.
I guess that snd_pcm_wait with dmix check the shared memory and not the fd descriptor.
So should poll/select be avoided completely in applications (as they does not know if the default pcm is a dmix) and asterisk alsa channel be rewritten or is there a workaround?

Best Regards

Nicola

#1 lore raw
Quoted 6 lines · Nicola Mfb

Hi!
I'm sorry if this is an old issue but I did not found help in archives/alsaweb/google and I'm new to alsa, so this report is what I guessed reading sources and compiling test apps for about 2 days, and the following assumptions may be completely wrong.

Quoted 14 lines

Asterisk has an alsa channel that works fine when using plughw:0,0 both for read and for writing, but if use plug:dmix/plug:dsnoop or default with a dmix/dsnoop wrapper in /etc/asound.conf it does not emit any sound. It uses select on poll fd descriptor to know if the pcm is ready to be sent output samples.
The select will never return as it seems the dmix plugin is not able to signal when is ready.
I noted that using snd_pcm_wait works well but cannot be used in asterisk as it needs to select on two fd.
I guess that snd_pcm_wait with dmix check the shared memory and not the fd descriptor.
So should poll/select be avoided completely in applications (as they does not know if the default pcm is a dmix) and asterisk alsa channel be rewritten or is there a workaround?

Asterisk does not use snd_pcm_poll_descriptors_revents to translate events returned from poll to correct poll event. Also, only file descriptor number from snd_pcm_poll_descriptors() - asterisk should handle correctly returned poll events as well.

See chan_alsa.c - readdev / writedev variables and sound_thread().

Jaroslav

-----
Jaroslav Kysela <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project, Red Hat, Inc.

author
#2 lore raw

2009/4/20 Jaroslav Kysela <[email protected]>:

Quoted 1 line · Nicola Mfb

[...]

Quoted 8 lines

Asterisk does not use snd_pcm_poll_descriptors_revents to translate events returned from poll to correct poll event. Also, only file descriptor number from snd_pcm_poll_descriptors() - asterisk should handle correctly returned poll events as well.

See chan_alsa.c - readdev / writedev variables and sound_thread().

                                       Jaroslav

Hi Jaroslav!
thanks for quick reply and hints!
I finally understand the inverted POLLIN/POLLOUT in dmix. As a quick check I added writedev to fds set and it worked, now I'll able to write a patch using poll and demangling revents...
First level documentation on www.alsa-project.org says that you may use select or poll as you need, should be this corrected?

Thank you again!

Nicola

#3 lore raw
Quoted 12 lines · Nicola Mfb

2009/4/20 Jaroslav Kysela <[email protected]>:

Quoted 1 line · Nicola Mfb

[...]

Quoted 8 lines

Asterisk does not use snd_pcm_poll_descriptors_revents to translate events returned from poll to correct poll event. Also, only file descriptor number from snd_pcm_poll_descriptors() - asterisk should handle correctly returned poll events as well.

See chan_alsa.c - readdev / writedev variables and sound_thread().

                                       Jaroslav

Quoted 7 lines

Hi Jaroslav!
thanks for quick reply and hints!
I finally understand the inverted POLLIN/POLLOUT in dmix. As a quick check I added writedev to fds set and it worked, now I'll able to write a patch using poll and demangling revents...
First level documentation on www.alsa-project.org says that you may use select or poll as you need, should be this corrected?

Could you point me where is documentation unclear exactly?

Thanks,
Jaroslav

-----
Jaroslav Kysela <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project, Red Hat, Inc.

_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

author
#4 lore raw

2009/4/21 Jaroslav Kysela <[email protected]>:

Quoted 5 lines · Nicola Mfb
Quoted 4 lines

2009/4/20 Jaroslav Kysela <[email protected]>:

Quoted 2 lines · Nicola Mfb

[...]

Quoted 4 lines
Quoted 2 lines

First level documentation on www.alsa-project.org says that you may use select or poll as you need, should be this corrected?

Could you point me where is documentation unclear exactly?

For example at:
http://www.alsa-project.org/alsa-doc/alsa-lib/pcm.html
in "event waiting routines" you see "snd_pcm_poll_descriptors can be used to get a file descriptor to poll or select on".

And at: http://www.alsa-project.org/alsa-doc/alsa-lib/group___p_c_m.html#gfc99365835bb429cac8c994fa56a42d7
the sentence "You can use output from this function as arguments for
the select() syscall, too." may be confusing. At first look reader may
suppose that bogus results affects only poll.

Regards

Nicola

#5 lore raw
Quoted 17 lines · Nicola Mfb

2009/4/21 Jaroslav Kysela <[email protected]>:

Quoted 5 lines · Nicola Mfb
Quoted 4 lines

2009/4/20 Jaroslav Kysela <[email protected]>:

Quoted 2 lines · Nicola Mfb

[...]

Quoted 4 lines
Quoted 2 lines

First level documentation on www.alsa-project.org says that you may use select or poll as you need, should be this corrected?

Could you point me where is documentation unclear exactly?

For example at:
http://www.alsa-project.org/alsa-doc/alsa-lib/pcm.html
in "event waiting routines" you see "snd_pcm_poll_descriptors can be used to get a file descriptor to poll or select on".

Quoted 4 lines

And at: http://www.alsa-project.org/alsa-doc/alsa-lib/group___p_c_m.html#gfc99365835bb429cac8c994fa56a42d7
the sentence "You can use output from this function as arguments for
the select() syscall, too." may be confusing. At first look reader may
suppose that bogus results affects only poll.

I added more notes about events mangling there. Thanks.

Jaroslav

-----
Jaroslav Kysela <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project, Red Hat, Inc.