Skip to contentSkip to conversation

problems using select() on alsa pcm.

DISCUSSION James Courtier-Dutton 6 participants 13 messages Mar 25, 2004

lore
Share & tools
lore
#0 lore raw

open pcm, and get a handle.

snd_pcm_poll_descriptors(handle, &pfd, err);

Get a poll file scriptor in pfd.

select(nfds, rfds, wfds, efds, tvp);

Is it possible to use this call with alsa ?
It seems that the select functions as expected with the descriptor so that we can do a snd_pcm_writei().

It seems that the select does not function so that we can do a snd_pcm_readi().

Are there any documents describing how one can get the read (rfds) working?

Cheers
James

-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click

#1 lore raw
Quoted 9 lines

open pcm, and get a handle.

snd_pcm_poll_descriptors(handle, &pfd, err);

Get a poll file scriptor in pfd.

select(nfds, rfds, wfds, efds, tvp);

Is it possible to use this call with alsa ?

select is generally deprecated in linux (linus says so!). but you can use the same pfds in select as in poll (select is implemented in the kernel using the poll code). the problem is interpreting the results you get back (as noted recently for the dmix plugin).

-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click

#12 lore raw
In reply to James Courtier-Dutton
Quoted 9 lines · James Courtier-Dutton

open pcm, and get a handle.

snd_pcm_poll_descriptors(handle, &pfd, err);

Get a poll file scriptor in pfd.

select(nfds, rfds, wfds, efds, tvp);

Is it possible to use this call with alsa ?

Yes, snd_pcm_poll_descriptors() gives you all hints. See to alsa-oss/alsa/alsa-oss.c - select() wrapper, but man select and man poll will help you also.

Jaroslav

-----
Jaroslav Kysela <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project, SuSE Labs

-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click

#2 lore raw
In reply to Paul Davis
Quoted 6 lines · Paul Davis
Quoted 6 lines

open pcm, and get a handle.

snd_pcm_poll_descriptors(handle, &pfd, err);

Get a poll file scriptor in pfd.

Quoted 8 lines
Quoted 3 lines

select(nfds, rfds, wfds, efds, tvp);

Is it possible to use this call with alsa ?

select is generally deprecated in linux (linus says so!). but you can use the same pfds in select as in poll (select is implemented in the kernel using the poll code). the problem is interpreting the results you get back (as noted recently for the dmix plugin).

Nope, the application must give results back to pfd array and call snd_pcm_poll_descriptors_revents() function. In this way, everything will work as expected.

Jaroslav

-----
Jaroslav Kysela <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project, SuSE Labs

-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click

#7 lore raw
In reply to Paul Davis
Quoted 6 lines
Quoted 6 lines

open pcm, and get a handle.

snd_pcm_poll_descriptors(handle, &pfd, err);

Get a poll file scriptor in pfd.

Quoted 8 lines
Quoted 3 lines

select(nfds, rfds, wfds, efds, tvp);

Is it possible to use this call with alsa ?

select is generally deprecated in linux (linus says so!). but you can use the same pfds in select as in poll (select is implemented in the kernel using the poll code). the problem is interpreting the results you get back (as noted recently for the dmix plugin).

select and pselect do allow for a more accurate timeout specification. Why is select deprecated?

--ms

-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click

#8 lore raw
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines

open pcm, and get a handle.

snd_pcm_poll_descriptors(handle, &pfd, err);

Get a poll file scriptor in pfd.

select(nfds, rfds, wfds, efds, tvp);

Is it possible to use this call with alsa ?

Quoted 7 lines
Quoted 4 lines

select is generally deprecated in linux (linus says so!). but you can use the same pfds in select as in poll (select is implemented in the kernel using the poll code). the problem is interpreting the results you get back (as noted recently for the dmix plugin).

select and pselect do allow for a more accurate timeout specification. Why is select deprecated?

well, one reason might be gleaned from the man page for select_tut:

[ ... ]

mode at all (see ioctl(2)). It is easy to introduce subtle errors that will remove the advantage of using select, hence I will present a list of essentials to watch for when using the select call.

1. You should always try use select without a timeout. Your program
should have nothing to do if there is no data available. Code that depends on timeouts is not usually portable and difficult to debug.

of course, for main event loops in things like glib, this can't ever really be true, but it is a rather salient point for most callers of select().

i think the main reason for its "deprecation" (which is very mild, given that its an official POSIX call) is that its semantics are not quite as clear as poll(2). its even possible that i've missed a retraction from linus about this.

--p

-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click

#9 lore raw
In reply to Martijn Sipkema

At Thu, 25 Mar 2004 11:25:56 +0100,

Quoted 9 lines · Martijn Sipkema
Quoted 9 lines
Quoted 9 lines

open pcm, and get a handle.

snd_pcm_poll_descriptors(handle, &pfd, err);

Get a poll file scriptor in pfd.

select(nfds, rfds, wfds, efds, tvp);

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

Is it possible to use this call with alsa ?

select is generally deprecated in linux (linus says so!). but you can use the same pfds in select as in poll (select is implemented in the kernel using the poll code). the problem is interpreting the results you get back (as noted recently for the dmix plugin).

select and pselect do allow for a more accurate timeout specification.

from the spec, yes. but nsec resolution would be never implemented :)

Quoted 1 line

Why is select deprecated?

because select is just a wrapper of poll in fact (on linux)?

Takashi

-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click

#10 lore raw
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines

open pcm, and get a handle.

snd_pcm_poll_descriptors(handle, &pfd, err);

Get a poll file scriptor in pfd.

select(nfds, rfds, wfds, efds, tvp);

Is it possible to use this call with alsa ?

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

select is generally deprecated in linux (linus says so!). but you can use the same pfds in select as in poll (select is implemented in the kernel using the poll code). the problem is interpreting the results you get back (as noted recently for the dmix plugin).

select and pselect do allow for a more accurate timeout specification.

from the spec, yes. but nsec resolution would be never implemented :)

Not nsec resolution perhaps, but a higher than msec resolution might be useful in some cases. The fact that select was updated in the POSIX specs to support a timespec timeout (pselect) and poll only supports msec timeout might indicate that pselect is better suited for realtime use. Not to mention that pselect supports at least a 31 day timeout and that it can set the signal mask...

--ms

-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click

#3 lore raw
In reply to Jaroslav Kysela
Quoted 8 lines
Quoted 4 lines

select is generally deprecated in linux (linus says so!). but you can use the same pfds in select as in poll (select is implemented in the kernel using the poll code). the problem is interpreting the results you get back (as noted recently for the dmix plugin).

Nope, the application must give results back to pfd array and call snd_pcm_poll_descriptors_revents() function. In this way, everything will work as expected.

i thought that the flags set by select(2) were different than those set by poll(2) ??

-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click

#4 lore raw
Quoted 11 lines · Paul Davis
Quoted 8 lines
Quoted 4 lines

select is generally deprecated in linux (linus says so!). but you can use the same pfds in select as in poll (select is implemented in the kernel using the poll code). the problem is interpreting the results you get back (as noted recently for the dmix plugin).

Nope, the application must give results back to pfd array and call snd_pcm_poll_descriptors_revents() function. In this way, everything will work as expected.

i thought that the flags set by select(2) were different than those set by poll(2) ??

Yes, but the results are similar. So you have to do:

snd_pcm_poll_descriptors(pfds)
pfds->events -> FD_SET(x, y)
select()
FD_ISSET(x, y) -> pfds->revents
revents = snd_pcm_poll_descriptors_revents(pfds)
if (revents & POLLOUT)
playback_event();
if (revents & POLLIN)
capture_event();

Jaroslav

-----
Jaroslav Kysela <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project, SuSE Labs

-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click

#5 lore raw
In reply to Jaroslav Kysela
Quoted 19 lines · Jaroslav Kysela
Quoted 6 lines · Paul Davis
Quoted 6 lines

open pcm, and get a handle.

snd_pcm_poll_descriptors(handle, &pfd, err);

Get a poll file scriptor in pfd.

Quoted 8 lines
Quoted 3 lines

select(nfds, rfds, wfds, efds, tvp);

Is it possible to use this call with alsa ?

select is generally deprecated in linux (linus says so!). but you can use the same pfds in select as in poll (select is implemented in the kernel using the poll code). the problem is interpreting the results you get back (as noted recently for the dmix plugin).

Quoted 5 lines

Nope, the application must give results back to pfd array and call snd_pcm_poll_descriptors_revents() function. In this way, everything will work as expected.

Jaroslav

So which of the following is needed: -

snd_pcm_poll_descriptors(handle, &pfd, err);
select(nfds, rfds, wfds, efds, tvp); snd_pcm_poll_descriptors_revents() <- decode the results of the select.

or
snd_pcm_poll_descriptors(handle, &pfd, err); snd_pcm_poll_descriptors_revents() <- rearrange the pfd so that select works as expected. select(nfds, rfds, wfds, efds, tvp);

Cheers
James

-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click

#6 lore raw
Quoted 24 lines · James Courtier-Dutton
Quoted 23 lines · Jaroslav Kysela
Quoted 6 lines · Paul Davis
Quoted 6 lines

open pcm, and get a handle.

snd_pcm_poll_descriptors(handle, &pfd, err);

Get a poll file scriptor in pfd.

Quoted 8 lines
Quoted 3 lines

select(nfds, rfds, wfds, efds, tvp);

Is it possible to use this call with alsa ?

select is generally deprecated in linux (linus says so!). but you can use the same pfds in select as in poll (select is implemented in the kernel using the poll code). the problem is interpreting the results you get back (as noted recently for the dmix plugin).

Nope, the application must give results back to pfd array and call snd_pcm_poll_descriptors_revents() function. In this way, everything will work as expected.

Quoted 6 lines
Quoted 1 line

Jaroslav

So which of the following is needed: -

snd_pcm_poll_descriptors(handle, &pfd, err);
select(nfds, rfds, wfds, efds, tvp); snd_pcm_poll_descriptors_revents() <- decode the results of the select.

This one. The *revents() function mangles the returned ->revents back to the useful meaning for applications.

Quoted 5 lines

or
snd_pcm_poll_descriptors(handle, &pfd, err); snd_pcm_poll_descriptors_revents() <- rearrange the pfd so that select works as expected.
select(nfds, rfds, wfds, efds, tvp);

That's wrong.

Jaroslav

-----
Jaroslav Kysela <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project, SuSE Labs

-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click

#11 lore raw
In reply to Takashi Iwai
Quoted 3 lines · Takashi Iwai
Quoted 1 line

Why is select deprecated?

because select is just a wrapper of poll in fact (on linux)?

So? There are a few other operating systems out there, and select() is very portable.

(select isn't deprecated; it's simply not Linus's API to deprecate. :)

Signature · 8 lines
Glenn Maynard


-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click