Skip to contentSkip to conversation

crash with assertion (?)

DISCUSSION IOhannes m zmoelnig 3 participants 10 messages Sep 7, 2010 – Sep 10, 2010

lore
Share & tools
lore
#0 lore raw

hi all,

(just in case: sorry for double posting, i first sent from a non-subscribed address)

this might have been discussed already ages ago, but i didn't find much on the web, and i'm a bit confused why it happens, so:

i'm developing/bugfixing an application using (well, obviously) alsa, and i get crashes with assertions.

my setup:
- nvidia CK804 onboard soundcard (this soundcard seems to only be able to run at 48kHz)
- debian squeeze/sid (libasound2 1.0.23-1)

what i'm trying to do:
i'm requesting my "plughw" device with 44100Hz
the request is done with something like:
rate=44100;
err = snd_pcm_hw_params_set_rate_min(handle, params, &rate, 0);
[...]
err = snd_pcm_hw_params(handle, params);

what happens:
in the snd_pcm_hw_params(), my program exits with:
"interval_inline.h:52: snd_interval_single: Assertion `!snd_interval_empty(i)' failed."

sidenotes:
if i use the "hw" device, i get away with the wrong samplerate (no crash, though the requested samplerate does not take effect)

now i understand, that my soundcard does not accept 44100Hz. what i don't understand is, that alsa-lib crashes with an assertion error. i expect snd_pcm_hw_params() return an error!=0 if it fails to do what it is asked to do.
imho, a library should _never ever_ crash the application.

is this a bug?
in alsa-lib? in the debian-packages?

fgmasdr
IOhannes

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

#1 lore raw
Quoted 5 lines · IOhannes m zmoelnig

hi all,

is this a bug?
in alsa-lib? in the debian-packages?

it seems like debian compiles the package without explicitely adding the "--without-debug" configure-flag, does resulting in assert()ions that exist the application.

i will file a bug-report with debian, so they can fix this.

in the meantime: why is it the default to compile with asserts?

fgamdf
IOhannes

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

#2 lore raw
Quoted 8 lines · IOhannes m zmoelnig

it seems like debian compiles the package without explicitely adding the "--without-debug" configure-flag, does resulting in assert()ions that exist the application.

i will file a bug-report with debian, so they can fix this.

in the meantime: why is it the default to compile with asserts?

but obviously the assertion is there for a reason (so i guess i would get crashes even if the assertion was not there, since the assert() only protects from a NULL-pointer dereferencing)

which brings the bug back to alsa-lib....

fgamsdr
IOhannes

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

#3 lore raw
In reply to IOhannes m zmoelnig
Quoted 4 lines · IOhannes m zmoelnig

i'm requesting my "plughw" device with 44100Hz
the request is done with something like:
rate=44100;
err = snd_pcm_hw_params_set_rate_min(handle, params, &rate, 0);

This requests a sample rate of at least 44100 Hz.

Quoted 7 lines

[...]
err = snd_pcm_hw_params(handle, params);

what happens:
in the snd_pcm_hw_params(), my program exits with:
"interval_inline.h:52: snd_interval_single: Assertion `!snd_interval_empty(i)' failed."

You called snd_pcm_hw_params with an invalid params structure. I'd guess that snd_pcm_hw_params_set_rate_min (or some other snd_pcm_hw_params_set_*) returned an error.

Regards,
Clemens

#4 lore raw
Quoted 7 lines · Clemens Ladisch
Quoted 4 lines · IOhannes m zmoelnig

i'm requesting my "plughw" device with 44100Hz
the request is done with something like:
rate=44100;
err = snd_pcm_hw_params_set_rate_min(handle, params, &rate, 0);

This requests a sample rate of at least 44100 Hz.

yes. this is good enough for me.
(it shouldn't crash though)

Quoted 4 lines
Quoted 4 lines

[...]
err = snd_pcm_hw_params(handle, params);

Quoted 8 lines
Quoted 4 lines

what happens:
in the snd_pcm_hw_params(), my program exits with:
"interval_inline.h:52: snd_interval_single: Assertion `!snd_interval_empty(i)' failed."

You called snd_pcm_hw_params with an invalid params structure. I'd guess that snd_pcm_hw_params_set_rate_min (or some other snd_pcm_hw_params_set_*) returned an error.

i wish you were right.
however, it seems like i am blindfolded.

i noticed however, that i need to set both the rate (i use snd_pcm_hw_params_set_rate_min()) and the period size (i use snd_pcm_hw_params_set_period_size_near()), in order to make it crash.

attached is an example code that triggers the crash. please someone shed some light...

gmasdr
IOhannes

PS: that's how i use the sample program:

$ gcc -o alsatest alsatest.c $(pkg-config --cflags --libs alsa)
$ ./alsatest
trying to open 'hw:0' as CAPTURE
configuring device succeeded
CAPTURE configured
trying to open 'hw:0' as PLAYBACK
configuring device succeeded
PLAYBACK configured
trying to open 'plughw:0' as CAPTURE
configuring device succeeded
CAPTURE configured
trying to open 'plughw:0' as PLAYBACK
alsatest: interval_inline.h:55: snd_interval_single: Assertion
`!snd_interval_empty(i)' failed.
Aborted

so it seems to work fine with "hw:0" but not with "plughw:0".

you can specify the device to be opened on the cmdline:

$ ./alsatest hw:2

#include <stdio.h>
#include <alsa/asoundlib.h>

#define ENABLE_SETPARAMS_RATE 1
#define ENABLE_SETPARAMS_PERIOD 2

/* neither set_rate_min() nor set_period_size_near() is ok (but trivial) */ //#define ENABLE_SETPARAMS 0

/* only set_rate_min() is ok */
//#define ENABLE_SETPARAMS ENABLE_SETPARAMS_RATE

/* only set_period_size_near() is ok as well */ //#define ENABLE_SETPARAMS ENABLE_SETPARAMS_PERIOD

/* both set_rate_min() and set_period_size_near() -> CRASH */ #define ENABLE_SETPARAMS ENABLE_SETPARAMS_RATE | ENABLE_SETPARAMS_PERIOD

int pcm_configure(snd_pcm_t *pcm) {
unsigned int rate=44100;
snd_pcm_uframes_t uframes = 64;

snd_pcm_hw_params_t* hw_params;
int err;

  snd_pcm_hw_params_alloca(&hw_params);
  err = snd_pcm_hw_params_any(pcm, hw_params);
  if(err<0){fprintf(stderr, "snd_pcm_hw_params_any failed: %s\n",  snd_strerror(err));return err;}

#if ENABLE_SETPARAMS & 1
err = snd_pcm_hw_params_set_rate_min(pcm, hw_params, &rate, 0); if(err<0){fprintf(stderr, "snd_pcm_hw_params_set_rate_min failed: %s\n", snd_strerror(err));return err;}
#endif

#if ENABLE_SETPARAMS & 2
err = snd_pcm_hw_params_set_period_size_near(pcm, hw_params, &uframes, 0); if(err<0){fprintf(stderr, "snd_pcm_hw_params_set_period_size failed: %s\n", snd_strerror(err));return err;}
#endif

  err = snd_pcm_hw_params(pcm, hw_params);
  if(err<0){fprintf(stderr, "snd_pcm_hw_params failed: %s\n",  snd_strerror(err));return err;}

printf("configuring device succeeded\n");
return 0;
}

void pcm_open(char*name) {
int err=0;
snd_pcm_t *pcmIn=0, *pcmOut=0;

  printf("trying to open '%s' as CAPTURE\n", name);
  err = snd_pcm_open(&pcmIn, name, SND_PCM_STREAM_CAPTURE, SND_PCM_NONBLOCK);
  if(err<0){fprintf(stderr, "snd_pcm_open(CAPTURE) failed: %s\n",  snd_strerror(err));goto closeit;}
  err=snd_pcm_nonblock(pcmIn, 1);
  if(err<0){fprintf(stderr, "snd_pcm_nonblock failed: %s\n",  snd_strerror(err));goto closeit;}
  pcm_configure(pcmIn);
  fprintf(stderr, "CAPTURE configured\n");

  printf("trying to open '%s' as PLAYBACK\n", name);
  err = snd_pcm_open(&pcmOut, name, SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK);
  if(err<0){fprintf(stderr, "snd_pcm_open(PLAYBACK) failed: %s\n",  snd_strerror(err));goto closeit;}
  err=snd_pcm_nonblock(pcmOut, 1);
  if(err<0){fprintf(stderr, "snd_pcm_nonblock failed: %s\n",  snd_strerror(err));goto closeit;}
  pcm_configure(pcmOut);
  fprintf(stderr, "PLAYBACK configured\n");

closeit:
if(pcmIn)snd_pcm_close(pcmIn);
if(pcmOut)snd_pcm_close(pcmOut);
}

int main(int argc, char**argv) {
int i=0;

  if(argc>1) {
    for(i=1; i<argc; i++) {
      pcm_open(argv[i]);
    }
  } else {
      pcm_open("hw:0");
      pcm_open("plughw:0");

}
fprintf(stderr, "bye bye\n");
return 0;
}

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

#5 lore raw

2010/9/8 IOhannes m zmoelnig <[email protected]>

Quoted 7 lines · Clemens Ladisch
Quoted 6 lines
Quoted 4 lines · IOhannes m zmoelnig

i'm requesting my "plughw" device with 44100Hz
the request is done with something like:
rate=44100;
err = snd_pcm_hw_params_set_rate_min(handle, params, &rate, 0);

Quoted 6 lines
Quoted 1 line

This requests a sample rate of at least 44100 Hz.

yes. this is good enough for me.
(it shouldn't crash though)

http://www.alsa-project.org/alsa-doc/alsa-lib/group___p_c_m___h_w___params.htm

Restrict a configuration space with a minimum rate.

val approximate minimum rate ( on return filled with actul minimum ) dir sub unit direction (on return filled with actual direction)

Return 0 otherwise a negative error code if configuration space would become empty

what is the minimum rate returned by snd_pcm_hw_params_get_rate_min() when using hw:0,0 ?

Quoted 44 lines
Quoted 4 lines
Quoted 4 lines

[...]
err = snd_pcm_hw_params(handle, params);

Quoted 8 lines
Quoted 4 lines

what happens:
in the snd_pcm_hw_params(), my program exits with:
"interval_inline.h:52: snd_interval_single: Assertion `!snd_interval_empty(i)' failed."

You called snd_pcm_hw_params with an invalid params structure. I'd guess that snd_pcm_hw_params_set_rate_min (or some other snd_pcm_hw_params_set_*) returned an error.

i wish you were right.
however, it seems like i am blindfolded.

i noticed however, that i need to set both the rate (i use snd_pcm_hw_params_set_rate_min()) and the period size (i use snd_pcm_hw_params_set_period_size_near()), in order to make it crash.

attached is an example code that triggers the crash. please someone shed some light...

gmasdr
IOhannes

PS: that's how i use the sample program:

$ gcc -o alsatest alsatest.c $(pkg-config --cflags --libs alsa)
$ ./alsatest
trying to open 'hw:0' as CAPTURE
configuring device succeeded
CAPTURE configured
trying to open 'hw:0' as PLAYBACK
configuring device succeeded
PLAYBACK configured
trying to open 'plughw:0' as CAPTURE
configuring device succeeded
CAPTURE configured
trying to open 'plughw:0' as PLAYBACK
alsatest: interval_inline.h:55: snd_interval_single: Assertion
`!snd_interval_empty(i)' failed.
Aborted
Quoted 6 lines

so it seems to work fine with "hw:0" but not with "plughw:0".

you can specify the device to be opened on the cmdline:

$ ./alsatest hw:2

To debug , you will need to enable RULES_DEBUG In pcm_params.c

add snd_pcm_dump() after snd_pcm_hw_params in your program

export LIBASOUND_DEBUG=1

and post the output of your program

#6 lore raw
Quoted 1 line · Raymond Yau

http://www.alsa-project.org/alsa-doc/alsa-lib/group___p_c_m___h_w___params.htm

l

Quoted 2 lines

what is the minimum rate returned by snd_pcm_hw_params_get_rate_min() when using hw:0,0 ?

for hw:0,0 it is 48000, direction=0
for plughw:0,0 i get 4000(sic!), direction=0

Quoted 8 lines

To debug , you will need to enable RULES_DEBUG In pcm_params.c

add snd_pcm_dump() after snd_pcm_hw_params in your program

export LIBASOUND_DEBUG=1

and post the output of your program

ok, i tried that.
there's of course the little problem with havind snd_pcm_dump() after snd_pcm_hw_params(), since the latter crashes...
so i added it before i start configuring the device as well. here's the pseudocode:
<snip>
open(PLAYBACK);
dump();
nonblock(1); get_rate(); set_rate(44100); set_period(64); dump();
close();
open(CAPTURE);
dump();
nonblock(1); get_rate(); set_rate(44100); set_period(64); /* CRASH */ dump();
close();
</snip>

i prefixed all the printout of my application with "JMZ", so you can easily filter it out.

fgmasdr
IOhannes

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

#7 lore raw

2010/9/9 IOhannes m zmoelnig <[email protected]>

Quoted 6 lines · Raymond Yau
Quoted 2 lines

http://www.alsa-project.org/alsa-doc/alsa-lib/group___p_c_m___h_w___params.htm
l

Quoted 7 lines
Quoted 1 line

what is the minimum rate returned by snd_pcm_hw_params_get_rate_min()

when

Quoted 1 line

using hw:0,0 ?

for hw:0,0 it is 48000, direction=0
for plughw:0,0 i get 4000(sic!), direction=0

Are there any reason which you need to use snd_pcm_hw_params_set_rate_min() instead of snd_pcm_hw_params_set_rate_near() ?

set_rate_min( 44100) only restrict a configuration space with a minimum rate and this is not sufficient for alsa-lib to refine the parameters of snd_pcm_hw_params() to unique value when the device is plughw and your sound card only support 48000Hz and 96000Hz

Yes, I can reprodued the assertion with a patched intel8x0 driver inside virtualbox
since there is no error when using the emulated ac97 controller and codec which support 8000Hz<->48000Hz

There is no error when change to use set_rate_near instead of set_rate_min

Quoted 28 lines
Quoted 9 lines

To debug , you will need to enable RULES_DEBUG In pcm_params.c

add snd_pcm_dump() after snd_pcm_hw_params in your program

export LIBASOUND_DEBUG=1

and post the output of your program

ok, i tried that.
there's of course the little problem with havind snd_pcm_dump() after snd_pcm_hw_params(), since the latter crashes...
so i added it before i start configuring the device as well. here's the pseudocode:
<snip>
open(PLAYBACK);
dump();
nonblock(1); get_rate(); set_rate(44100); set_period(64); dump();
close();
open(CAPTURE);
dump();
nonblock(1); get_rate(); set_rate(44100); set_period(64); /* CRASH */ dump();
close();
</snip>

Quoted 8 lines

i prefixed all the printout of my application with "JMZ", so you can easily filter it out.

fgmasdr
IOhannes

schange 'plughw:0,0' (slave)

ACCESS:  MMAP_INTERLEAVED RW_INTERLEAVED
FORMAT:  S16_LE
SUBFORMAT:  STD
SAMPLE_BITS: 16
FRAME_BITS: [32 128]
CHANNELS: [2 8]
RATE: [48000 96000]
PERIOD_TIME: (20 341334)
PERIOD_SIZE: [2 16384]
PERIOD_BYTES: [32 131072]
PERIODS: [1 1024]
BUFFER_TIME: (20 341334)
BUFFER_SIZE: [2 16384]
BUFFER_BYTES: [32 65536]
TICK_TIME: ALL
ALSA ERROR hw_params: set (RATE)
           value = 44100 : Invalid argument
ACCESS:  MMAP_INTERLEAVED RW_INTERLEAVED
FORMAT:  S16_LE
SUBFORMAT:  STD
SAMPLE_BITS: 16
FRAME_BITS: [32 128]
CHANNELS: [2 8]
RATE: [48000 96000]
PERIOD_TIME: (20 341334)
PERIOD_SIZE: [2 16384]
PERIOD_BYTES: [32 131072]
PERIODS: [1 1024]
BUFFER_TIME: (20 341334)
BUFFER_SIZE: [2 16384]
BUFFER_BYTES: [32 65536]
TICK_TIME: ALL
ALSA ERROR hw_params: set (RATE)
           value = 88200 : Invalid argument
ACCESS:  MMAP_INTERLEAVED RW_INTERLEAVED
FORMAT:  S16_LE
SUBFORMAT:  STD
SAMPLE_BITS: 16
FRAME_BITS: [32 128]
CHANNELS: [2 8]
RATE: [48000 96000]
PERIOD_TIME: (20 341334)
PERIOD_SIZE: [2 16384]
PERIOD_BYTES: [32 131072]
PERIODS: [1 1024]
BUFFER_TIME: (20 341334)
BUFFER_SIZE: [2 16384]
BUFFER_BYTES: [32 65536]
TICK_TIME: ALL
srefine 'plughw:0,0' (client)
ACCESS:  MMAP_INTERLEAVED
FORMAT:  S8
SUBFORMAT:  STD
SAMPLE_BITS: 8
FRAME_BITS: 8
CHANNELS: 1
RATE: [44100 44100]
PERIOD_TIME: (83 1452)
PERIOD_SIZE: 64
PERIOD_BYTES: 64
PERIODS: (0 4113)
BUFFER_TIME: (3 5968186)
BUFFER_SIZE: [3 263197]
BUFFER_BYTES: [3 263197]
TICK_TIME: ALL
srefine 'plughw:0,0' (slave)
ACCESS:  MMAP_INTERLEAVED RW_INTERLEAVED
FORMAT:  S16_LE
SUBFORMAT:  STD
SAMPLE_BITS: 16
FRAME_BITS: 32
CHANNELS: 2
RATE: 48000
PERIOD_TIME: (166 1452)
PERIOD_SIZE: [8 16384]
PERIOD_BYTES: [32 65536]
PERIODS: [1 1024]
BUFFER_TIME: (166 341334)
BUFFER_SIZE: [8 16384]
BUFFER_BYTES: [32 65536]
TICK_TIME: ALL

cchange 'plughw:0,0'

The assertion occur becacuse RATE=44100 -> NONE

Rule 5 (0xb7773aa0): FRAME_BITS=8 -> 8 BUFFER_BYTES=[3 263197] BUFFER_SIZE=[7 15052]
Rule 7 (0xb7773aa0): RATE=44100 -> NONE PERIOD_SIZE=64 PERIOD_TIME=(166 1438)

alsatest: interval_inline.h:52: snd_interval_single: Assertion `!snd_interval_empty(i)' failed.

#8 lore raw
Quoted 4 lines · Raymond Yau

Yes, I can reprodued the assertion with a patched intel8x0 driver inside virtualbox
since there is no error when using the emulated ac97 controller and codec which support 8000Hz<->48000Hz

How exactly did you patch it?

Quoted 5 lines

Rule 7 (0xb7773aa0): RATE=44100 -> NONE PERIOD_SIZE=64 PERIOD_TIME=(166 1438)

alsatest: interval_inline.h:52: snd_interval_single: Assertion `!snd_interval_empty(i)' failed.

This looks like a definite bug.

Regards,
Clemens

#9 lore raw

2010/9/10 Clemens Ladisch <[email protected]>

Quoted 8 lines
Quoted 4 lines · Raymond Yau

Yes, I can reprodued the assertion with a patched intel8x0 driver inside virtualbox
since there is no error when using the emulated ac97 controller and codec which support 8000Hz<->48000Hz

How exactly did you patch it?

based on his log and his card seem support rate 48000 and 96000 only

SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000

the assertion also occur with snd-dummy model=ac97 with the above change in rate constraint on Fedora 13

may need the output of alsa-info.sh to find out his ac97 codec and snd_pcm_dump to find out the resampler