[alsa-devel] "Resource temporarily unavailable" while reading although poll returns POLLIN event

Raymond Yau superquad.vortex2 at gmail.com
Thu Apr 22 04:41:50 CEST 2010


2010/4/21 Stefan Schoenleitner <dev.c0debabe at gmail.com>

> Hi,
>
> I wrote a small application that opens both streams (i.e. capture and
> playback)
> of a PCM in non blocking (i.e. SND_PCM_NONBLOCK) mode.
>
> During device configuration I also set up the minimum number of
> frames to consider a PCM ready:
>
>
> ---------------------------------------------------------------------------------
> // when to consider the device to be ready for the next data transfer
> operation
> if ((ret=snd_pcm_sw_params_set_avail_min(handle, swparams,
> pcm_period_size))<0)
> {
>        fprintf(stderr, "could not set avail_min: %s\n", snd_strerror(ret));
>        return NULL;
> }
>
> ---------------------------------------------------------------------------------
>
> As you can see it is set to the number of frames one period contains.
>
> In other words, each time there are at least that many frames available for
> reading
> on the capture device, we should get a POLLIN event when using poll().
> On the other side we should get a POLLOUT event if that many frames can be
> written
> to the playback device.
>
>
> Then, later in my application, I use poll() on the fds of the PCM devices.
> As, according to the ALSA reference, poll events can be "mangeled", I use
> snd_pcm_poll_descriptors_revents() to "demangle" the events:
>
>
> ---------------------------------------------------------------------------------
> if ((ret=snd_pcm_poll_descriptors_revents(device_handle, &poll_fds[i], 1,
> &revents))<0)
> {
>        fprintf(stderr, "could not snd_pcm_poll_descriptors_revents: %s\n",
> snd_strerror(ret));
>        exit(EXIT_FAILURE);
> }
>
> ---------------------------------------------------------------------------------
>
>
>
> After that, each time there was a POLLIN event, I am reading exactly one
> period from the
> capture PCM.
> On the other side, if there was a POLLOUT event, I am writing exactly one
> period to the
> playback PCM.
>
>
> While this works for a small number of periods (which is not always the
> same), I always end up
> with a "Resource temporarily unavailable" error when trying to read one
> period from the capture PCM:
>
>
> ---------------------------------------------------------------------------------
> demangled poll: POLLIN  on capture device
> could not read from capture device: Resource temporarily unavailable
>
> ---------------------------------------------------------------------------------
>
>
> Since a POLLIN event only occurs after at least a full period is available
> for
> reading (as set up by snd_pcm_sw_params_set_avail_min() above)
> and I only read after a POLLIN event occured on the capture device fd,
> I really do not understand why I get the above error.
>
> So why does the above happen ?
> What am I doing wrong ?
>
> If it helps, I pasted the source code here so that you can view it nicely:
> http://pastebin.com/fCicqctq
>
> cheers,
> stefan
>

which sound card are you using ?

The program did not run on my two sound card since you are using 160 frames
and mono

are you using "pulse" device for testing since only pulse device return the
error messages "could not read from capture device: Resource temporarily
unavailable" ?


More information about the Alsa-devel mailing list