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
Index: pjmedia/src/pjmedia-audiodev/alsa_dev.c
===================================================================
--- pjmedia/src/pjmedia-audiodev/alsa_dev.c (revision 6048)
+++ pjmedia/src/pjmedia-audiodev/alsa_dev.c (working copy)
@@ -689,6 +689,7 @@
tmp_period_size = stream->pb_frames;
snd_pcm_hw_params_set_period_size_near (stream->pb_pcm, params,
&tmp_period_size, NULL);
+ stream->pb_frames = tmp_period_size > stream->pb_frames ? tmp_period_size : stream->pb_frames;
TRACE_((THIS_FILE, "open_playback: period size set to: %d",
tmp_period_size));
@@ -807,6 +808,7 @@
tmp_period_size = stream->ca_frames;
snd_pcm_hw_params_set_period_size_near (stream->ca_pcm, params,
&tmp_period_size, NULL);
+ stream->ca_frames = tmp_period_size > stream->ca_frames ? tmp_period_size : stream->ca_frames;
TRACE_((THIS_FILE, "open_capture: period size set to: %d",
tmp_period_size));
_______________________________________________
Visit our blog: http://blog.pjsip.org
pjsip mailing list
pjsip@xxxxxxxxxxxxxxx
http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org