[pulseaudio-commits] [SCM] PulseAudio Sound Server branch, master, updated. v0.9.15-test2-21-ga571565

Lennart Poettering gitmailer-noreply at 0pointer.de
Sun Feb 15 11:35:09 PST 2009


This is an automated email from the git hooks/post-receive script. It was
generated because of a push to the "PulseAudio Sound Server" repository.

The master branch has been updated
      from  023998e3c84c3158ab9f02e26949dbcd3e048886 (commit)

- Log -----------------------------------------------------------------
a571565... don't open the alsa devices in hw:xxx mode
6790c03... unify ALSA mixer initialization
-----------------------------------------------------------------------

Summary of changes:
 src/modules/alsa/alsa-sink.c   |   38 +------------------
 src/modules/alsa/alsa-source.c |   38 +------------------
 src/modules/alsa/alsa-util.c   |   80 ++++++++++++++++++++++++++++++++++++++++
 src/modules/alsa/alsa-util.h   |    1 +
 src/modules/module-detect.c    |    2 +-
 5 files changed, 84 insertions(+), 75 deletions(-)

-----------------------------------------------------------------------

commit 6790c03f91708540da284c80d0cb72cacf41c83d
Author: Lennart Poettering <lennart at poettering.net>
Date:   Sat Feb 14 00:21:36 2009 +0100

    unify ALSA mixer initialization

diff --git a/src/modules/alsa/alsa-sink.c b/src/modules/alsa/alsa-sink.c
index c56614c..1474cfe 100644
--- a/src/modules/alsa/alsa-sink.c
+++ b/src/modules/alsa/alsa-sink.c
@@ -1386,43 +1386,7 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca
     /* ALSA might tweak the sample spec, so recalculate the frame size */
     frame_size = pa_frame_size(&ss);
 
-    if ((err = snd_mixer_open(&u->mixer_handle, 0)) < 0)
-        pa_log_warn("Error opening mixer: %s", snd_strerror(err));
-    else {
-        pa_bool_t found = FALSE;
-
-        if (pa_alsa_prepare_mixer(u->mixer_handle, u->device_name) >= 0)
-            found = TRUE;
-        else {
-            snd_pcm_info_t *info;
-
-            snd_pcm_info_alloca(&info);
-
-            if (snd_pcm_info(u->pcm_handle, info) >= 0) {
-                char *md;
-                int card_idx;
-
-                if ((card_idx = snd_pcm_info_get_card(info)) >= 0) {
-
-                    md = pa_sprintf_malloc("hw:%i", card_idx);
-
-                    if (strcmp(u->device_name, md))
-                        if (pa_alsa_prepare_mixer(u->mixer_handle, md) >= 0)
-                            found = TRUE;
-                    pa_xfree(md);
-                }
-            }
-        }
-
-        if (found)
-            if (!(u->mixer_elem = pa_alsa_find_elem(u->mixer_handle, "Master", "PCM", TRUE)))
-                found = FALSE;
-
-        if (!found) {
-            snd_mixer_close(u->mixer_handle);
-            u->mixer_handle = NULL;
-        }
-    }
+    pa_alsa_find_mixer_and_elem(u->pcm_handle, &u->mixer_handle, &u->mixer_elem);
 
     pa_sink_new_data_init(&data);
     data.driver = driver;
diff --git a/src/modules/alsa/alsa-source.c b/src/modules/alsa/alsa-source.c
index 2b42d3f..192645d 100644
--- a/src/modules/alsa/alsa-source.c
+++ b/src/modules/alsa/alsa-source.c
@@ -1211,43 +1211,7 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p
     /* ALSA might tweak the sample spec, so recalculate the frame size */
     frame_size = pa_frame_size(&ss);
 
-    if ((err = snd_mixer_open(&u->mixer_handle, 0)) < 0)
-        pa_log("Error opening mixer: %s", snd_strerror(err));
-    else {
-        pa_bool_t found = FALSE;
-
-        if (pa_alsa_prepare_mixer(u->mixer_handle, u->device_name) >= 0)
-            found = TRUE;
-        else {
-            snd_pcm_info_t* info;
-
-            snd_pcm_info_alloca(&info);
-
-            if (snd_pcm_info(u->pcm_handle, info) >= 0) {
-                char *md;
-                int card_idx;
-
-                if ((card_idx = snd_pcm_info_get_card(info)) >= 0) {
-
-                    md = pa_sprintf_malloc("hw:%i", card_idx);
-
-                    if (strcmp(u->device_name, md))
-                        if (pa_alsa_prepare_mixer(u->mixer_handle, md) >= 0)
-                            found = TRUE;
-                    pa_xfree(md);
-                }
-            }
-        }
-
-        if (found)
-            if (!(u->mixer_elem = pa_alsa_find_elem(u->mixer_handle, "Capture", "Mic", FALSE)))
-                found = FALSE;
-
-        if (!found) {
-            snd_mixer_close(u->mixer_handle);
-            u->mixer_handle = NULL;
-        }
-    }
+    pa_alsa_find_mixer_and_elem(u->pcm_handle, &u->mixer_handle, &u->mixer_elem);
 
     pa_source_new_data_init(&data);
     data.driver = driver;
diff --git a/src/modules/alsa/alsa-util.c b/src/modules/alsa/alsa-util.c
index 5236d02..d7caa0f 100644
--- a/src/modules/alsa/alsa-util.c
+++ b/src/modules/alsa/alsa-util.c
@@ -1057,6 +1057,86 @@ success:
     return elem;
 }
 
+
+int pa_alsa_find_mixer_and_elem(
+        snd_pcm_t *pcm,
+        snd_mixer_t **_m,
+        snd_mixer_elem_t **_e) {
+
+    int err;
+    snd_mixer_t *m;
+    snd_mixer_elem_t *e;
+    pa_bool_t found = FALSE;
+    const char *dev;
+
+    pa_assert(pcm);
+    pa_assert(_m);
+    pa_assert(_e);
+
+    if ((err = snd_mixer_open(&m, 0)) < 0) {
+        pa_log("Error opening mixer: %s", snd_strerror(err));
+        return -1;
+    }
+
+    /* First, try by name */
+    if ((dev = snd_pcm_name(pcm)))
+        if (pa_alsa_prepare_mixer(m, dev) >= 0)
+            found = TRUE;
+
+    /* Then, try by card index */
+    if (!found) {
+        snd_pcm_info_t* info;
+        snd_pcm_info_alloca(&info);
+
+        if (snd_pcm_info(pcm, info) >= 0) {
+            char *md;
+            int card_idx;
+
+            if ((card_idx = snd_pcm_info_get_card(info)) >= 0) {
+
+                md = pa_sprintf_malloc("hw:%i", card_idx);
+
+                if (!dev || !pa_streq(dev, md))
+                    if (pa_alsa_prepare_mixer(m, md) >= 0)
+                        found = TRUE;
+
+                pa_xfree(md);
+            }
+        }
+    }
+
+    if (!found) {
+        snd_mixer_close(m);
+        return -1;
+    }
+
+    switch (snd_pcm_stream(pcm)) {
+
+        case SND_PCM_STREAM_PLAYBACK:
+            e = pa_alsa_find_elem(m, "Master", "PCM", TRUE);
+            break;
+
+        case SND_PCM_STREAM_CAPTURE:
+            e = pa_alsa_find_elem(m, "Capture", "Mic", FALSE);
+            break;
+
+        default:
+            pa_assert_not_reached();
+    }
+
+    if (!e) {
+        snd_mixer_close(m);
+        return -1;
+    }
+
+    pa_assert(e && m);
+
+    *_m = m;
+    *_e = e;
+
+    return 0;
+}
+
 static const snd_mixer_selem_channel_id_t alsa_channel_ids[PA_CHANNEL_POSITION_MAX] = {
     [PA_CHANNEL_POSITION_MONO] = SND_MIXER_SCHN_MONO, /* The ALSA name is just an alias! */
 
diff --git a/src/modules/alsa/alsa-util.h b/src/modules/alsa/alsa-util.h
index 8a20934..8b08339 100644
--- a/src/modules/alsa/alsa-util.h
+++ b/src/modules/alsa/alsa-util.h
@@ -54,6 +54,7 @@ int pa_alsa_set_sw_params(snd_pcm_t *pcm, snd_pcm_uframes_t avail_min);
 
 int pa_alsa_prepare_mixer(snd_mixer_t *mixer, const char *dev);
 snd_mixer_elem_t *pa_alsa_find_elem(snd_mixer_t *mixer, const char *name, const char *fallback, pa_bool_t playback);
+int pa_alsa_find_mixer_and_elem(snd_pcm_t *pcm, snd_mixer_t **_m, snd_mixer_elem_t **_e);
 
 typedef struct pa_alsa_profile_info {
     pa_channel_map map;

commit a571565f86a34d4ce4f16669c021be92494e132d
Author: Lennart Poettering <lennart at poettering.net>
Date:   Sun Feb 15 20:34:38 2009 +0100

    don't open the alsa devices in hw:xxx mode

diff --git a/src/modules/module-detect.c b/src/modules/module-detect.c
index 9ed262d..773e1d8 100644
--- a/src/modules/module-detect.c
+++ b/src/modules/module-detect.c
@@ -100,7 +100,7 @@ static int detect_alsa(pa_core *c, int just_one) {
         if (subdevice != 0)
             continue;
 
-        pa_snprintf(args, sizeof(args), "device=hw:%u", device);
+        pa_snprintf(args, sizeof(args), "device_id=%u", device);
         if (!pa_module_load(c, is_sink ? "module-alsa-sink" : "module-alsa-source", args))
             continue;
 

-- 
hooks/post-receive
PulseAudio Sound Server



More information about the pulseaudio-commits mailing list