[pulseaudio-commits] [Git][pulseaudio/pulseaudio][master] 6 commits: alsa-ucm: parse correctly the device values

Arun Raghavan gitlab at gitlab.freedesktop.org
Wed Dec 18 07:34:42 UTC 2019



Arun Raghavan pushed to branch master at PulseAudio / pulseaudio


Commits:
4c64f73c by Jaroslav Kysela at 2019-12-18T07:29:11Z
alsa-ucm: parse correctly the device values

The UCM library is used to get the fallback values from the verbs
and the defaults section. There is no reason to duplicate this code
inside application.

Signed-off-by: Jaroslav Kysela <perex at perex.cz>

- - - - -
ef1df946 by Jaroslav Kysela at 2019-12-18T07:29:11Z
alsa-ucm: do not try to use UCM device name as jack name by default

Remove the implicit rule. It is perfectly ok to have the jack with
the same name for another I/O in the driver. Trust only the
value obtained from UCM.

Signed-off-by: Jaroslav Kysela <perex at perex.cz>

- - - - -
d8200ee8 by Jaroslav Kysela at 2019-12-18T07:29:11Z
alsa-util: do not try to guess the mixer name from the PCM name

This is just invalid. It results to an error in almost all cases.
The hw:<number> scheme is sufficient to get the right card mixer.

Signed-off-by: Jaroslav Kysela <perex at perex.cz>

- - - - -
ddd0fdb9 by Jaroslav Kysela at 2019-12-18T07:29:11Z
alsa-ucm: add control and mixer device items

Signed-off-by: Jaroslav Kysela <perex at perex.cz>

- - - - -
e438382a by Jaroslav Kysela at 2019-12-18T07:29:11Z
alsa-ucm: get the mixer names from ucm, don't guess

Signed-off-by: Jaroslav Kysela <perex at perex.cz>

- - - - -
dacfcbb0 by Jaroslav Kysela at 2019-12-18T07:29:11Z
alsa-ucm: use the proper mixer name for ucm pcm sink/source

Signed-off-by: Jaroslav Kysela <perex at perex.cz>

- - - - -


6 changed files:

- src/modules/alsa/alsa-mixer.h
- src/modules/alsa/alsa-sink.c
- src/modules/alsa/alsa-source.c
- src/modules/alsa/alsa-ucm.c
- src/modules/alsa/alsa-ucm.h
- src/modules/alsa/alsa-util.c


Changes:

=====================================
src/modules/alsa/alsa-mixer.h
=====================================
@@ -364,6 +364,7 @@ void pa_alsa_profile_set_free(pa_alsa_profile_set *s);
 void pa_alsa_profile_set_dump(pa_alsa_profile_set *s);
 void pa_alsa_profile_set_drop_unsupported(pa_alsa_profile_set *s);
 
+snd_mixer_t *pa_alsa_open_mixer_by_name(const char *dev);
 snd_mixer_t *pa_alsa_open_mixer_for_pcm(snd_pcm_t *pcm, char **ctl_device);
 
 pa_alsa_fdlist *pa_alsa_fdlist_new(void);


=====================================
src/modules/alsa/alsa-sink.c
=====================================
@@ -2083,11 +2083,18 @@ static void set_sink_name(pa_sink_new_data *data, pa_modargs *ma, const char *de
 }
 
 static void find_mixer(struct userdata *u, pa_alsa_mapping *mapping, const char *element, bool ignore_dB) {
+    const char *mdev;
 
     if (!mapping && !element)
         return;
 
-    if (!(u->mixer_handle = pa_alsa_open_mixer_for_pcm(u->pcm_handle, &u->control_device))) {
+    mdev = pa_proplist_gets(mapping->proplist, "alsa.mixer_device");
+    if (mdev) {
+        u->mixer_handle = pa_alsa_open_mixer_by_name(mdev);
+    } else {
+        u->mixer_handle = pa_alsa_open_mixer_for_pcm(u->pcm_handle, &u->control_device);
+    }
+    if (!mdev) {
         pa_log_info("Failed to find a working mixer device.");
         return;
     }


=====================================
src/modules/alsa/alsa-source.c
=====================================
@@ -1789,10 +1789,18 @@ static void set_source_name(pa_source_new_data *data, pa_modargs *ma, const char
 }
 
 static void find_mixer(struct userdata *u, pa_alsa_mapping *mapping, const char *element, bool ignore_dB) {
+    const char *mdev;
+
     if (!mapping && !element)
         return;
 
-    if (!(u->mixer_handle = pa_alsa_open_mixer_for_pcm(u->pcm_handle, &u->control_device))) {
+    mdev = pa_proplist_gets(mapping->proplist, "alsa.mixer_device");
+    if (mdev) {
+        u->mixer_handle = pa_alsa_open_mixer_by_name(mdev);
+    } else {
+        u->mixer_handle = pa_alsa_open_mixer_for_pcm(u->pcm_handle, &u->control_device);
+    }
+    if (!mdev) {
         pa_log_info("Failed to find a working mixer device.");
         return;
     }


=====================================
src/modules/alsa/alsa-ucm.c
=====================================
@@ -90,16 +90,20 @@ static void ucm_port_update_available(pa_alsa_ucm_port_data *port);
 static struct ucm_items item[] = {
     {"PlaybackPCM", PA_ALSA_PROP_UCM_SINK},
     {"CapturePCM", PA_ALSA_PROP_UCM_SOURCE},
+    {"PlaybackCTL", PA_ALSA_PROP_UCM_PLAYBACK_CTL_DEVICE},
     {"PlaybackVolume", PA_ALSA_PROP_UCM_PLAYBACK_VOLUME},
     {"PlaybackSwitch", PA_ALSA_PROP_UCM_PLAYBACK_SWITCH},
+    {"PlaybackMixer", PA_ALSA_PROP_UCM_PLAYBACK_MIXER_DEVICE},
     {"PlaybackMixerElem", PA_ALSA_PROP_UCM_PLAYBACK_MIXER_ELEM},
     {"PlaybackMasterElem", PA_ALSA_PROP_UCM_PLAYBACK_MASTER_ELEM},
     {"PlaybackMasterType", PA_ALSA_PROP_UCM_PLAYBACK_MASTER_TYPE},
     {"PlaybackPriority", PA_ALSA_PROP_UCM_PLAYBACK_PRIORITY},
     {"PlaybackRate", PA_ALSA_PROP_UCM_PLAYBACK_RATE},
     {"PlaybackChannels", PA_ALSA_PROP_UCM_PLAYBACK_CHANNELS},
+    {"CaptureCTL", PA_ALSA_PROP_UCM_CAPTURE_CTL_DEVICE},
     {"CaptureVolume", PA_ALSA_PROP_UCM_CAPTURE_VOLUME},
     {"CaptureSwitch", PA_ALSA_PROP_UCM_CAPTURE_SWITCH},
+    {"CaptureMixer", PA_ALSA_PROP_UCM_CAPTURE_MIXER_DEVICE},
     {"CaptureMixerElem", PA_ALSA_PROP_UCM_CAPTURE_MIXER_ELEM},
     {"CaptureMasterElem", PA_ALSA_PROP_UCM_CAPTURE_MASTER_ELEM},
     {"CaptureMasterType", PA_ALSA_PROP_UCM_CAPTURE_MASTER_TYPE},
@@ -107,6 +111,7 @@ static struct ucm_items item[] = {
     {"CaptureRate", PA_ALSA_PROP_UCM_CAPTURE_RATE},
     {"CaptureChannels", PA_ALSA_PROP_UCM_CAPTURE_CHANNELS},
     {"TQ", PA_ALSA_PROP_UCM_QOS},
+    {"JackCTL", PA_ALSA_PROP_UCM_JACK_DEVICE},
     {"JackControl", PA_ALSA_PROP_UCM_JACK_CONTROL},
     {"JackHWMute", PA_ALSA_PROP_UCM_JACK_HW_MUTE},
     {NULL, NULL},
@@ -141,30 +146,6 @@ static struct ucm_info dev_info[] = {
     {NULL, 0}
 };
 
-/* UCM profile properties - The verb data is store so it can be used to fill
- * the new profiles properties */
-static int ucm_get_property(pa_alsa_ucm_verb *verb, snd_use_case_mgr_t *uc_mgr, const char *verb_name) {
-    const char *value;
-    char *id;
-    int i;
-
-    for (i = 0; item[i].id; i++) {
-        int err;
-
-        id = pa_sprintf_malloc("=%s//%s", item[i].id, verb_name);
-        err = snd_use_case_get(uc_mgr, id, &value);
-        pa_xfree(id);
-        if (err < 0)
-            continue;
-
-        pa_log_debug("Got %s for verb %s: %s", item[i].id, verb_name, value);
-        pa_proplist_sets(verb->proplist, item[i].property, value);
-        free((void*)value);
-    }
-
-    return 0;
-};
-
 static int ucm_device_exists(pa_idxset *idxset, pa_alsa_ucm_device *dev) {
     pa_alsa_ucm_device *d;
     uint32_t idx;
@@ -308,6 +289,31 @@ static pa_alsa_ucm_volume *ucm_get_mixer_volume(
     return vol;
 }
 
+/* Get the ALSA mixer device for the UCM device */
+static const char *get_mixer_device(pa_alsa_ucm_device *dev, bool is_sink)
+{
+    const char *dev_name;
+    
+    if (is_sink) {
+        dev_name = pa_proplist_gets(dev->proplist, PA_ALSA_PROP_UCM_PLAYBACK_MIXER_DEVICE);
+        if (!dev_name)
+            dev_name = pa_proplist_gets(dev->proplist, PA_ALSA_PROP_UCM_PLAYBACK_CTL_DEVICE);
+    } else {
+        dev_name = pa_proplist_gets(dev->proplist, PA_ALSA_PROP_UCM_CAPTURE_MIXER_DEVICE);
+        if (!dev_name)
+            dev_name = pa_proplist_gets(dev->proplist, PA_ALSA_PROP_UCM_CAPTURE_CTL_DEVICE);
+    }
+    return dev_name;
+}
+
+/* Get the ALSA mixer device for the UCM jack */
+static const char *get_jack_mixer_device(pa_alsa_ucm_device *dev, bool is_sink) {
+    const char *dev_name = pa_proplist_gets(dev->proplist, PA_ALSA_PROP_UCM_JACK_DEVICE);
+    if (!dev_name)
+        return get_mixer_device(dev, is_sink);
+    return dev_name;
+}
+
 /* Create a property list for this ucm device */
 static int ucm_get_device_property(
         pa_alsa_ucm_device *device,
@@ -325,7 +331,7 @@ static int ucm_get_device_property(
     pa_alsa_ucm_volume *vol;
 
     for (i = 0; item[i].id; i++) {
-        id = pa_sprintf_malloc("=%s/%s", item[i].id, device_name);
+        id = pa_sprintf_malloc("%s/%s", item[i].id, device_name);
         err = snd_use_case_get(uc_mgr, id, &value);
         pa_xfree(id);
         if (err < 0)
@@ -347,14 +353,8 @@ static int ucm_get_device_property(
 
         /* get pcm */
         value = pa_proplist_gets(device->proplist, PA_ALSA_PROP_UCM_SINK);
-        if (!value) { /* take pcm from verb playback default */
-            value = pa_proplist_gets(verb->proplist, PA_ALSA_PROP_UCM_SINK);
-            if (value) {
-                pa_log_debug("UCM playback device %s fetch pcm from verb default %s", device_name, value);
-                pa_proplist_sets(device->proplist, PA_ALSA_PROP_UCM_SINK, value);
-            } else
-                pa_log("UCM playback device %s fetch pcm failed", device_name);
-        }
+        if (!value) /* take pcm from verb playback default */
+            pa_log("UCM playback device %s fetch pcm failed", device_name);
     }
 
     value = pa_proplist_gets(device->proplist, PA_ALSA_PROP_UCM_CAPTURE_CHANNELS);
@@ -367,14 +367,8 @@ static int ucm_get_device_property(
 
         /* get pcm */
         value = pa_proplist_gets(device->proplist, PA_ALSA_PROP_UCM_SOURCE);
-        if (!value) { /* take pcm from verb capture default */
-            value = pa_proplist_gets(verb->proplist, PA_ALSA_PROP_UCM_SOURCE);
-            if (value) {
-                pa_log_debug("UCM capture device %s fetch pcm from verb default %s", device_name, value);
-                pa_proplist_sets(device->proplist, PA_ALSA_PROP_UCM_SOURCE, value);
-            } else
-                pa_log("UCM capture device %s fetch pcm failed", device_name);
-        }
+        if (!value) /* take pcm from verb capture default */
+            pa_log("UCM capture device %s fetch pcm failed", device_name);
     }
 
     if (device->playback_channels == 0 && device->capture_channels == 0) {
@@ -387,8 +381,7 @@ static int ucm_get_device_property(
     /* get rate and priority of device */
     if (device->playback_channels) { /* sink device */
         /* get rate */
-        if ((value = pa_proplist_gets(device->proplist, PA_ALSA_PROP_UCM_PLAYBACK_RATE)) ||
-            (value = pa_proplist_gets(verb->proplist, PA_ALSA_PROP_UCM_PLAYBACK_RATE))) {
+        if ((value = pa_proplist_gets(device->proplist, PA_ALSA_PROP_UCM_PLAYBACK_RATE))) {
             if (pa_atou(value, &ui) == 0 && pa_sample_rate_valid(ui)) {
                 pa_log_debug("UCM playback device %s rate %d", device_name, ui);
                 device->playback_rate = ui;
@@ -417,8 +410,7 @@ static int ucm_get_device_property(
 
     if (device->capture_channels) { /* source device */
         /* get rate */
-        if ((value = pa_proplist_gets(device->proplist, PA_ALSA_PROP_UCM_CAPTURE_RATE)) ||
-            (value = pa_proplist_gets(verb->proplist, PA_ALSA_PROP_UCM_CAPTURE_RATE))) {
+        if ((value = pa_proplist_gets(device->proplist, PA_ALSA_PROP_UCM_CAPTURE_RATE))) {
             if (pa_atou(value, &ui) == 0 && pa_sample_rate_valid(ui)) {
                 pa_log_debug("UCM capture device %s rate %d", device_name, ui);
                 device->capture_rate = ui;
@@ -796,9 +788,6 @@ int pa_alsa_ucm_get_verb(snd_use_case_mgr_t *uc_mgr, const char *verb_name, cons
     if (err < 0)
         pa_log("No UCM modifiers for verb %s", verb_name);
 
-    /* Verb properties */
-    ucm_get_property(verb, uc_mgr, verb_name);
-
     PA_LLIST_FOREACH(d, verb->devices) {
         const char *dev_name = pa_proplist_gets(d->proplist, PA_ALSA_PROP_UCM_NAME);
 
@@ -831,22 +820,41 @@ static int pa_alsa_ucm_device_cmp(const void *a, const void *b) {
     return strcmp(pa_proplist_gets(d1->proplist, PA_ALSA_PROP_UCM_NAME), pa_proplist_gets(d2->proplist, PA_ALSA_PROP_UCM_NAME));
 }
 
-static void probe_volumes(pa_hashmap *hash, snd_pcm_t *pcm_handle, bool ignore_dB) {
+static void probe_volumes(pa_hashmap *hash, bool is_sink, snd_pcm_t *pcm_handle, bool ignore_dB) {
     pa_device_port *port;
     pa_alsa_path *path;
     pa_alsa_ucm_port_data *data;
-    snd_mixer_t *mixer_handle;
-    const char *profile;
+    pa_alsa_ucm_device *dev;
+    snd_mixer_t *mixer_handle = NULL;
+    const char *profile, *mdev_opened = NULL, *mdev, *mdev2;
     void *state, *state2;
-
-    if (!(mixer_handle = pa_alsa_open_mixer_for_pcm(pcm_handle, NULL))) {
-        pa_log_error("Failed to find a working mixer device.");
-        goto fail;
-    }
+    int idx;
 
     PA_HASHMAP_FOREACH(port, hash, state) {
         data = PA_DEVICE_PORT_DATA(port);
 
+        mdev = NULL;
+        PA_DYNARRAY_FOREACH(dev, data->devices, idx) {
+            mdev2 = get_mixer_device(dev, is_sink);
+            if (mdev && !pa_streq(mdev, mdev2)) {
+                pa_log_error("Two mixer device names found ('%s', '%s'), using s/w volume", mdev, mdev2);
+                goto fail;
+            }
+            mdev = mdev2;
+        }
+
+        if (!mdev_opened || !pa_streq(mdev_opened, mdev)) {
+            if (mixer_handle) {
+                snd_mixer_close(mixer_handle);
+                mdev_opened = NULL;
+            }
+            if (!(mixer_handle = pa_alsa_open_mixer_by_name(mdev))) {
+                pa_log_error("Failed to find a working mixer device (%s).", mdev);
+                goto fail;
+            }
+            mdev_opened = mdev;
+        }
+
         PA_HASHMAP_FOREACH_KV(profile, path, data->paths, state2) {
             if (pa_alsa_path_probe(path, NULL, mixer_handle, ignore_dB) < 0) {
                 pa_log_warn("Could not probe path: %s, using s/w volume", data->path->name);
@@ -859,7 +867,8 @@ static void probe_volumes(pa_hashmap *hash, snd_pcm_t *pcm_handle, bool ignore_d
         }
     }
 
-    snd_mixer_close(mixer_handle);
+    if (mixer_handle)
+        snd_mixer_close(mixer_handle);
 
     return;
 
@@ -1185,7 +1194,7 @@ void pa_alsa_ucm_add_ports(
     pa_alsa_ucm_add_ports_combination(*p, context, is_sink, card->ports, NULL, card->core);
 
     /* now set up volume paths if any */
-    probe_volumes(*p, pcm_handle, ignore_dB);
+    probe_volumes(*p, is_sink, pcm_handle, ignore_dB);
 
     /* then set property PA_PROP_DEVICE_INTENDED_ROLES */
     merged_roles = pa_xstrdup(pa_proplist_gets(proplist, PA_PROP_DEVICE_INTENDED_ROLES));
@@ -1330,7 +1339,8 @@ static void ucm_add_mapping(pa_alsa_profile *p, pa_alsa_mapping *m) {
 
 static void alsa_mapping_add_ucm_device(pa_alsa_mapping *m, pa_alsa_ucm_device *device) {
     char *cur_desc;
-    const char *new_desc;
+    const char *new_desc, *mdev;
+    bool is_sink = m->direction == PA_ALSA_DIRECTION_OUTPUT;
 
     pa_idxset_put(m->ucm_context.ucm_devices, device, NULL);
 
@@ -1346,10 +1356,14 @@ static void alsa_mapping_add_ucm_device(pa_alsa_mapping *m, pa_alsa_ucm_device *
     m->description = m->description ? m->description : pa_xstrdup("");
 
     /* save mapping to ucm device */
-    if (m->direction == PA_ALSA_DIRECTION_OUTPUT)
+    if (is_sink)
         device->playback_mapping = m;
     else
         device->capture_mapping = m;
+
+    mdev = get_mixer_device(device, is_sink);
+    if (mdev)
+        pa_proplist_sets(m->proplist, "alsa.mixer_device", mdev);
 }
 
 static void alsa_mapping_add_ucm_modifier(pa_alsa_mapping *m, pa_alsa_ucm_modifier *modifier) {
@@ -1563,9 +1577,8 @@ static pa_alsa_jack* ucm_get_jack(pa_alsa_ucm_config *ucm, pa_alsa_ucm_device *d
          * end, so drop the trailing " Jack". */
         name = pa_xstrndup(jack_control, strlen(jack_control) - 5);
     } else {
-        /* The jack control hasn't been explicitly configured - try a jack name
-         * that is the same as the device name. */
-        name = pa_xstrdup(device_name);
+        /* The jack control hasn't been explicitly configured, fail. */
+        return NULL;
     }
 
     PA_LLIST_FOREACH(j, ucm->jacks)
@@ -1644,7 +1657,8 @@ static int ucm_create_profile(
         ucm_create_mapping(ucm, ps, p, dev, verb_name, name, sink, source);
 
         jack = ucm_get_jack(ucm, dev);
-        device_set_jack(dev, jack);
+        if (jack)
+            device_set_jack(dev, jack);
 
         /* JackHWMute contains a list of device names. Each listed device must
          * be associated with the jack object that we just created. */
@@ -1752,26 +1766,43 @@ static void profile_finalize_probing(pa_alsa_profile *p) {
 }
 
 static void ucm_mapping_jack_probe(pa_alsa_mapping *m) {
-    snd_pcm_t *pcm_handle;
-    snd_mixer_t *mixer_handle;
+    snd_mixer_t *mixer_handle = NULL;
     pa_alsa_ucm_mapping_context *context = &m->ucm_context;
     pa_alsa_ucm_device *dev;
+    bool is_sink = m->direction == PA_ALSA_DIRECTION_OUTPUT;
+    const char *mdev_opened = NULL, *mdev;
     uint32_t idx;
 
-    pcm_handle = m->direction == PA_ALSA_DIRECTION_OUTPUT ? m->output_pcm : m->input_pcm;
-    mixer_handle = pa_alsa_open_mixer_for_pcm(pcm_handle, NULL);
-    if (!mixer_handle)
-        return;
-
     PA_IDXSET_FOREACH(dev, context->ucm_devices, idx) {
         bool has_control;
 
+        if (!dev->jack)
+            continue;
+
+        mdev = get_jack_mixer_device(dev, is_sink);
+        if (mdev == NULL) {
+            pa_log_error("Unable to determine mixer device for jack %s", dev->jack->name);
+            continue;
+        }
+
+        if (!mdev_opened || !pa_streq(mdev_opened, mdev)) {
+            if (mixer_handle) {
+                snd_mixer_close(mixer_handle);
+                mdev_opened = NULL;
+            }
+            mixer_handle = pa_alsa_open_mixer_by_name(mdev);
+            if (!mixer_handle)
+                continue;
+            mdev_opened = mdev;
+        }
+
         has_control = pa_alsa_mixer_find(mixer_handle, dev->jack->alsa_name, 0) != NULL;
         pa_alsa_jack_set_has_control(dev->jack, has_control);
         pa_log_info("UCM jack %s has_control=%d", dev->jack->name, dev->jack->has_control);
     }
 
-    snd_mixer_close(mixer_handle);
+    if (mixer_handle)
+        snd_mixer_close(mixer_handle);
 }
 
 static void ucm_probe_profile_set(pa_alsa_ucm_config *ucm, pa_alsa_profile_set *ps) {


=====================================
src/modules/alsa/alsa-ucm.h
=====================================
@@ -45,12 +45,18 @@ typedef void snd_use_case_mgr_t;
 /** For devices: Playback roles */
 #define PA_ALSA_PROP_UCM_PLAYBACK_ROLES             "alsa.ucm.playback.roles"
 
+/** For devices: Playback control device name  */
+#define PA_ALSA_PROP_UCM_PLAYBACK_CTL_DEVICE        "alsa.ucm.playback.ctldev"
+
 /** For devices: Playback control volume ID string. e.g PlaybackVolume */
 #define PA_ALSA_PROP_UCM_PLAYBACK_VOLUME            "alsa.ucm.playback.volume"
 
 /** For devices: Playback switch e.g PlaybackSwitch */
 #define PA_ALSA_PROP_UCM_PLAYBACK_SWITCH            "alsa.ucm.playback.switch"
 
+/** For devices: Playback mixer device name  */
+#define PA_ALSA_PROP_UCM_PLAYBACK_MIXER_DEVICE      "alsa.ucm.playback.mixer.device"
+
 /** For devices: Playback mixer identifier */
 #define PA_ALSA_PROP_UCM_PLAYBACK_MIXER_ELEM        "alsa.ucm.playback.mixer.element"
 
@@ -78,12 +84,18 @@ typedef void snd_use_case_mgr_t;
 /** For devices: Capture roles */
 #define PA_ALSA_PROP_UCM_CAPTURE_ROLES              "alsa.ucm.capture.roles"
 
+/** For devices: Capture control device name  */
+#define PA_ALSA_PROP_UCM_CAPTURE_CTL_DEVICE         "alsa.ucm.capture.ctldev"
+
 /** For devices: Capture controls volume ID string. e.g CaptureVolume */
 #define PA_ALSA_PROP_UCM_CAPTURE_VOLUME             "alsa.ucm.capture.volume"
 
 /** For devices: Capture switch e.g CaptureSwitch */
 #define PA_ALSA_PROP_UCM_CAPTURE_SWITCH             "alsa.ucm.capture.switch"
 
+/** For devices: Capture mixer device name  */
+#define PA_ALSA_PROP_UCM_CAPTURE_MIXER_DEVICE       "alsa.ucm.capture.mixer.device"
+
 /** For devices: Capture mixer identifier */
 #define PA_ALSA_PROP_UCM_CAPTURE_MIXER_ELEM         "alsa.ucm.capture.mixer.element"
 
@@ -114,6 +126,9 @@ typedef void snd_use_case_mgr_t;
 /** For devices: The modifier (if any) that this device corresponds to */
 #define PA_ALSA_PROP_UCM_MODIFIER "alsa.ucm.modifier"
 
+/* Corresponds to the "JackCTL" UCM value. */
+#define PA_ALSA_PROP_UCM_JACK_DEVICE		    "alsa.ucm.jack_device"
+
 /* Corresponds to the "JackControl" UCM value. */
 #define PA_ALSA_PROP_UCM_JACK_CONTROL               "alsa.ucm.jack_control"
 


=====================================
src/modules/alsa/alsa-util.c
=====================================
@@ -1740,30 +1740,31 @@ snd_mixer_t *pa_alsa_open_mixer(int alsa_card_index, char **ctl_device) {
     return NULL;
 }
 
-snd_mixer_t *pa_alsa_open_mixer_for_pcm(snd_pcm_t *pcm, char **ctl_device) {
+snd_mixer_t *pa_alsa_open_mixer_by_name(const char *dev) {
     int err;
     snd_mixer_t *m;
-    const char *dev;
-    snd_pcm_info_t* info;
-    snd_pcm_info_alloca(&info);
 
-    pa_assert(pcm);
+    pa_assert(dev);
 
     if ((err = snd_mixer_open(&m, 0)) < 0) {
         pa_log("Error opening mixer: %s", pa_alsa_strerror(err));
         return NULL;
     }
 
-    /* First, try by name */
-    if ((dev = snd_pcm_name(pcm)))
-        if (prepare_mixer(m, dev) >= 0) {
-            if (ctl_device)
-                *ctl_device = pa_xstrdup(dev);
+    if (prepare_mixer(m, dev) >= 0)
+        return m;
 
-            return m;
-        }
+    snd_mixer_close(m);
+    return NULL;
+}
+
+snd_mixer_t *pa_alsa_open_mixer_for_pcm(snd_pcm_t *pcm, char **ctl_device) {
+    snd_mixer_t *m;
+    snd_pcm_info_t* info;
+    snd_pcm_info_alloca(&info);
+
+    pa_assert(pcm);
 
-    /* Then, try by card index */
     if (snd_pcm_info(pcm, info) >= 0) {
         char *md;
         int card_idx;
@@ -1771,23 +1772,20 @@ snd_mixer_t *pa_alsa_open_mixer_for_pcm(snd_pcm_t *pcm, char **ctl_device) {
         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 (prepare_mixer(m, md) >= 0) {
-
-                    if (ctl_device)
-                        *ctl_device = md;
-                    else
-                        pa_xfree(md);
-
-                    return m;
-                }
+            m = pa_alsa_open_mixer_by_name(md);
+            if (m) {
+                if (ctl_device)
+                    *ctl_device = md;
+                else
+                    pa_xfree(md);
+
+                return m;
+            }
 
             pa_xfree(md);
         }
     }
 
-    snd_mixer_close(m);
     return NULL;
 }
 



View it on GitLab: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/compare/f62a49b8cf109c011a9818d2358beb6834e6ec25...dacfcbb09c9d91ca20dedfa449da37f0f7e3953f

-- 
View it on GitLab: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/compare/f62a49b8cf109c011a9818d2358beb6834e6ec25...dacfcbb09c9d91ca20dedfa449da37f0f7e3953f
You're receiving this email because of your account on gitlab.freedesktop.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/pulseaudio-commits/attachments/20191218/b22fbfff/attachment-0001.htm>


More information about the pulseaudio-commits mailing list