[pulseaudio-discuss] [PATCH] alsa: remove double calls of snd_pcm_prepare()

Takashi Sakamoto o-takashi at sakamocchi.jp
Fri Dec 30 03:05:20 UTC 2016


In alsa-lib, snd_pcm_hw_params() internally calls snd_pcm_prepare(), thus
user space applications have no need to call snd_pcm_prepare() after calls
of snd_pcm_hw_params(). An explicit calls of snd_pcm_prepare() is expected
in a case to recover PCM substreams.

Current implementation of PulseAudio modules for ALSA playbacking/capturing
results in double calls of snd_pcm_prepare(). The second call for hw plugin
of alsa-lib executes ioctl(2) with SNDRV_PCM_IOCTL_PREPARE command in state
of SNDRV_PCM_STATE_PREPARED for the PCM substream. This has no effects to
the PCM substream as long as corresponding drivers are implemented
correctly.

This commit removes the second call for the reason.

Signed-off-by: Takashi Sakamoto <o-takashi at sakamocchi.jp>
---
 src/modules/alsa/alsa-util.c | 5 -----
 src/tests/alsa-time-test.c   | 3 ---
 2 files changed, 8 deletions(-)

diff --git a/src/modules/alsa/alsa-util.c b/src/modules/alsa/alsa-util.c
index dfb2aa7..63d370f 100644
--- a/src/modules/alsa/alsa-util.c
+++ b/src/modules/alsa/alsa-util.c
@@ -410,11 +410,6 @@ success:
     if (ss->format != _ss.format)
         pa_log_info("Device %s doesn't support sample format %s, changed to %s.", snd_pcm_name(pcm_handle), pa_sample_format_to_string(ss->format), pa_sample_format_to_string(_ss.format));
 
-    if ((ret = snd_pcm_prepare(pcm_handle)) < 0) {
-        pa_log_info("snd_pcm_prepare() failed: %s", pa_alsa_strerror(ret));
-        goto finish;
-    }
-
     if ((ret = snd_pcm_hw_params_current(pcm_handle, hwparams)) < 0) {
         pa_log_info("snd_pcm_hw_params_current() failed: %s", pa_alsa_strerror(ret));
         goto finish;
diff --git a/src/tests/alsa-time-test.c b/src/tests/alsa-time-test.c
index a877cb8..dff95bb 100644
--- a/src/tests/alsa-time-test.c
+++ b/src/tests/alsa-time-test.c
@@ -132,9 +132,6 @@ int main(int argc, char *argv[]) {
     r = snd_pcm_sw_params(pcm, swparams);
     assert(r == 0);
 
-    r = snd_pcm_prepare(pcm);
-    assert(r == 0);
-
     r = snd_pcm_sw_params_current(pcm, swparams);
     assert(r == 0);
 
-- 
2.9.3



More information about the pulseaudio-discuss mailing list