[alsa-devel] standard read/write vs event waiting routines (poll) in ALSA

Diego Buffa diego.buffa at gmail.com
Thu Aug 1 11:04:17 CEST 2019


Hi Jaroslav,
many thanks for your answer, if I understand correctly pcmjob.c, you are
polling on capture, play and ctrl files (thread_job1).
So in this case it is clear the scope of the polling, sorry I just look at
https://www.alsa-project.org/alsa-doc/alsa-lib/_2test_2pcm_8c-example.html and
I was not understanding the advantage of using poll.

Regards,
d.

On Wed, Jul 31, 2019 at 7:03 PM Jaroslav Kysela <perex at perex.cz> wrote:

> Dne 31. 07. 19 v 18:05 Diego Buffa napsal(a):
> > Hi all,
> > I am trying to learn more about ALSA, I always used example found in the
> > howtos but now I would go further.
> >
> > I went though ALSA documentation (
> > https://www.alsa-project.org/alsa-doc/alsa-lib/pcm.html) and in the
> > specific the transfer methods.
> > Basically I don't understand the advantages of using poll instead of
> > traditional blocking read/write.
> >
> > Generally I know that using poll I can multiplex I/O on several files,
> but
> > in ALSA I cannot create the poll descriptor array as I want, as I must
> use
> > snd_pcm_poll_descriptors() which requires that the poll descriptor array
> > should have the size returned by snd_pcm_poll_descriptors_count().
> >
> > Am I supposed to realloc the poll array descriptor once I set it up with
> > ALSA, and add my own files? Should I then always check poll array
> > descriptor with snd_pcm_poll_descriptors_revents() before checking my own
> > files? And in this case it is safe to call
> > snd_pcm_poll_descriptors_revents() with a  poll array descriptor bigger
> > than the size returned by snd_pcm_poll_descriptors_count()?
> >
> > Many thanks in advance.
>
> All ALSA poll functions works only with the ALSA file descriptors.
> Basically,
> allocate your pollfd array as big as you like and get the file descriptors
> from ALSA to this array (using the returned count) and check those
> descriptors
> through ALSA (revents function). Look to alsa-utils/alsaloop/pcmjob.c for
> an
> example.
>
>                                                 Jaroslav
>
> --
> Jaroslav Kysela <perex at perex.cz>
> Linux Sound Maintainer; ALSA Project; Red Hat, Inc.
>


More information about the Alsa-devel mailing list