[PATCH] alsa_dev ignores period size return by ALSA

AW
Andreas Wehrmann
Thu, Aug 1, 2019 7:51 AM

Hey folks,

we have recently come across a problem with the ALSA backend in pjmedia.
We've got a special setup with fixed sound parameters in our ALSA config
and found that alsa_dev ignores the period size returned by the calls
to snd_pcm_hw_params_set_period_size_near().
alsa_dev simply assumes that it always gets the period size it requests
which was not the case in our environment
and lead to random crashes of our application because the buffer
that is allocated later on was wrongly sized.

Best regards,
Andreas Wehrmann

Hey folks, we have recently come across a problem with the ALSA backend in pjmedia. We've got a special setup with fixed sound parameters in our ALSA config and found that alsa_dev ignores the period size returned by the calls to snd_pcm_hw_params_set_period_size_near(). alsa_dev simply assumes that it always gets the period size it requests which was not the case in our environment and lead to random crashes of our application because the buffer that is allocated later on was wrongly sized. Best regards, Andreas Wehrmann
AW
Andreas Wehrmann
Thu, Aug 1, 2019 1:21 PM

On 01.08.19 09:51, Andreas Wehrmann wrote:

Hey folks,

we have recently come across a problem with the ALSA backend in pjmedia.
We've got a special setup with fixed sound parameters in our ALSA config
and found that alsa_dev ignores the period size returned by the calls
to snd_pcm_hw_params_set_period_size_near().
alsa_dev simply assumes that it always gets the period size it requests
which was not the case in our environment
and lead to random crashes of our application because the buffer
that is allocated later on was wrongly sized.

Best regards,
Andreas Wehrmann

Hold on! I found another issue:
The problem with the case above was that a small period was requested
but ALSA returned a bigger one
which lead to a segfault because the buffer allocated later was too small.
I now ran into a case where a smaller period size than requested is
returned but ALSA actually delivers the size requested...

The patch attached always uses the bigger size to make sure the buffer
is big enough.

Regards

On 01.08.19 09:51, Andreas Wehrmann wrote: > Hey folks, > > we have recently come across a problem with the ALSA backend in pjmedia. > We've got a special setup with fixed sound parameters in our ALSA config > and found that alsa_dev ignores the period size returned by the calls > to snd_pcm_hw_params_set_period_size_near(). > alsa_dev simply assumes that it always gets the period size it requests > which was not the case in our environment > and lead to random crashes of our application because the buffer > that is allocated later on was wrongly sized. > > Best regards, > Andreas Wehrmann Hold on! I found another issue: The problem with the case above was that a small period was requested but ALSA returned a bigger one which lead to a segfault because the buffer allocated later was too small. I now ran into a case where a smaller period size than requested is returned but ALSA actually delivers the size requested... The patch attached always uses the bigger size to make sure the buffer is big enough. Regards
RS
Riza Sulistyo
Wed, Aug 28, 2019 3:13 PM

Hi Andreas,

Thanks for the patch, it is committed on
https://trac.pjsip.org/repos/ticket/2223#ticket.

Best Regards,

Riza

On Thu, Aug 1, 2019 at 8:22 PM Andreas Wehrmann a.wehrmann@yandex.com
wrote:

On 01.08.19 09:51, Andreas Wehrmann wrote:

Hey folks,

we have recently come across a problem with the ALSA backend in pjmedia.
We've got a special setup with fixed sound parameters in our ALSA config
and found that alsa_dev ignores the period size returned by the calls
to snd_pcm_hw_params_set_period_size_near().
alsa_dev simply assumes that it always gets the period size it requests
which was not the case in our environment
and lead to random crashes of our application because the buffer
that is allocated later on was wrongly sized.

Best regards,
Andreas Wehrmann

Hold on! I found another issue:
The problem with the case above was that a small period was requested
but ALSA returned a bigger one
which lead to a segfault because the buffer allocated later was too small.
I now ran into a case where a smaller period size than requested is
returned but ALSA actually delivers the size requested...

The patch attached always uses the bigger size to make sure the buffer
is big enough.

Regards


Visit our blog: http://blog.pjsip.org

pjsip mailing list
pjsip@lists.pjsip.org
http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org

Hi Andreas, Thanks for the patch, it is committed on https://trac.pjsip.org/repos/ticket/2223#ticket. Best Regards, Riza On Thu, Aug 1, 2019 at 8:22 PM Andreas Wehrmann <a.wehrmann@yandex.com> wrote: > > On 01.08.19 09:51, Andreas Wehrmann wrote: > > Hey folks, > > > > we have recently come across a problem with the ALSA backend in pjmedia. > > We've got a special setup with fixed sound parameters in our ALSA config > > and found that alsa_dev ignores the period size returned by the calls > > to snd_pcm_hw_params_set_period_size_near(). > > alsa_dev simply assumes that it always gets the period size it requests > > which was not the case in our environment > > and lead to random crashes of our application because the buffer > > that is allocated later on was wrongly sized. > > > > Best regards, > > Andreas Wehrmann > > Hold on! I found another issue: > The problem with the case above was that a small period was requested > but ALSA returned a bigger one > which lead to a segfault because the buffer allocated later was too small. > I now ran into a case where a smaller period size than requested is > returned but ALSA actually delivers the size requested... > > The patch attached always uses the bigger size to make sure the buffer > is big enough. > > Regards > _______________________________________________ > Visit our blog: http://blog.pjsip.org > > pjsip mailing list > pjsip@lists.pjsip.org > http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org >