[lkml]   [2006]   [Jan]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: [OT] ALSA userspace API complexity
Alistair John Strachan <> wrote:
> On Tuesday 03 January 2006 23:10, Tomasz K?oczko wrote:
> 2) ALSA API is to complicated: most applications opens single sound
> stream.

> FUD and nonsense. I've written many DSP applications and very often I can
> recycle the same code for use in them.

It's not FUD and it's very true. I've written ALSA support for many
programs and I still can't remember the tricks that are needed to get
even basic things working.

Just look at error handling of libao-0.8.6 for a great example how
complicated it is to write code for ALSA. The following code is directly
from the source:

/* try to write the entire buffer at once */
err = internal->writei(internal->pcm_handle, ptr, len);

/* it's possible that no data was transferred */
if (err == -EAGAIN) {

if (err < 0) {
/* this might be an error, or an exception */
err = alsa_error_recovery(internal, err);
if (err < 0) {
fprintf(stderr,"ALSA write error: %s\n",
return 0;

/* abandon the rest of the buffer */

alsa_error_recovery() expands to 30 lines of more logic. This is pretty
insane considering that libao _only_ writes data to device and does
nothing else. If ALSA was done properly, the main loop would simply be:

err = internal->writei(internal->pcm_handle, ptr, len);

/* it's possible that no data was transferred */
if (err == -EAGAIN || err == -EINTR) {

if (err < 0) {
/* BAD BAD */

When I originally ran into this signal handling brain damage of ALSA, I
had to actually look into other programs how they handle signals because
ALSA documentation is so bad. The core problem is of course the broken
API, not the bad documentation.

A small note, libao can not handle EINTR properly. A patch has been
submitted already.

I've long ago stopped using ALSA API because it is broken. But if you
wanted to make ALSA usable by real people you might considering adding 3
functions (there are ~300 already so not much loss):

err = alsa_simple_pcm_open(nchannels, sampleformat, samplingrate, frames_in_period /* 0 for automated default */ );
err = alsa_simple_writei(); /* handless signal brokeness automagically */

Basically ogg123/mpg123 like applications would only need 3 alsa calls.
Now everyone reimplementing their own buggy versions of simple mechanisms.

Heikki Orsila Barbie's law: "Math is hard, let's go shopping!"
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at

 \ /
  Last update: 2006-01-05 15:04    [W:0.076 / U:8.580 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site