[pulseaudio-commits] [SCM] PulseAudio Sound Server branch, alsa-mixer, updated. v0.9.15-190-g9252569
Lennart Poettering
gitmailer-noreply at 0pointer.de
Tue Jun 16 17:50:48 PDT 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 alsa-mixer branch has been updated
from 5627b68a7e44cd3e8795b5ce4233f9060d4b2d23 (commit)
- Log -----------------------------------------------------------------
9252569 commit it away
00d0159 save it away
09279c2 svae it for now
c71c537 save it for now
-----------------------------------------------------------------------
Summary of changes:
src/Makefile.am | 4 +-
src/daemon/main.c | 5 +
src/map-file | 2 +
src/modules/alsa/alsa-mixer.c | 2513 +++++++++++++++-----
src/modules/alsa/alsa-mixer.h | 176 ++-
src/modules/alsa/alsa-sink.c | 474 ++--
src/modules/alsa/alsa-sink.h | 3 +-
src/modules/alsa/alsa-source.c | 476 ++--
src/modules/alsa/alsa-source.h | 2 +-
src/modules/alsa/alsa-util.c | 501 ++---
src/modules/alsa/alsa-util.h | 95 +-
src/modules/alsa/mixer/paths/analog-input-aux.conf | 32 +
...nalog-output-mono.conf => analog-input-fm.conf} | 43 +-
...g-output-mono.conf => analog-input-linein.conf} | 32 +-
...output-mono.conf => analog-input-mic-line.conf} | 43 +-
src/modules/alsa/mixer/paths/analog-input-mic.conf | 39 +-
.../alsa/mixer/paths/analog-input-mic.conf.common | 41 +
...-output-mono.conf => analog-input-tvtuner.conf} | 43 +-
.../alsa/mixer/paths/analog-input-video.conf | 31 +
src/modules/alsa/mixer/paths/analog-input.conf | 35 +-
.../alsa/mixer/paths/analog-input.conf.common | 171 +-
.../alsa/mixer/paths/analog-output-headphones.conf | 22 +-
.../mixer/paths/analog-output-lfe-on-mono.conf | 26 +-
.../alsa/mixer/paths/analog-output-mono.conf | 22 +-
src/modules/alsa/mixer/paths/analog-output.conf | 22 +-
.../alsa/mixer/paths/analog-output.conf.common | 20 +-
.../mixer/{profiles => profile-sets}/default.conf | 32 +-
src/modules/alsa/module-alsa-card.c | 261 ++-
src/modules/bluetooth/module-bluetooth-device.c | 8 +-
src/modules/bluetooth/module-bluetooth-proximity.c | 4 +-
src/modules/module-ladspa-sink.c | 23 +-
src/modules/module-lirc.c | 10 +-
src/modules/module-mmkbd-evdev.c | 6 +-
src/modules/module-tunnel.c | 4 +-
src/modules/udev-util.c | 40 +-
src/modules/udev-util.h | 3 +-
src/pulse/version.h.in | 4 +-
src/pulse/volume.c | 36 +-
src/pulse/volume.h | 12 +-
src/pulsecore/card.c | 45 +-
src/pulsecore/cli-command.c | 78 +-
src/pulsecore/cli-text.c | 36 +-
src/pulsecore/conf-parser.c | 20 +
src/pulsecore/core-util.c | 2 +-
src/pulsecore/hashmap.c | 42 +
src/pulsecore/hashmap.h | 13 +-
src/pulsecore/idxset.c | 14 +
src/pulsecore/idxset.h | 3 +
src/pulsecore/protocol-native.c | 8 +-
src/pulsecore/sample-util.h | 2 +-
src/pulsecore/sink-input.c | 10 +-
src/pulsecore/sink.c | 144 +-
src/pulsecore/sink.h | 16 +-
src/pulsecore/source.c | 121 +-
src/pulsecore/source.h | 32 +-
55 files changed, 3830 insertions(+), 2072 deletions(-)
create mode 100644 src/modules/alsa/mixer/paths/analog-input-aux.conf
copy src/modules/alsa/mixer/paths/{analog-output-mono.conf => analog-input-fm.conf} (55%)
copy src/modules/alsa/mixer/paths/{analog-output-mono.conf => analog-input-linein.conf} (55%)
copy src/modules/alsa/mixer/paths/{analog-output-mono.conf => analog-input-mic-line.conf} (55%)
create mode 100644 src/modules/alsa/mixer/paths/analog-input-mic.conf.common
copy src/modules/alsa/mixer/paths/{analog-output-mono.conf => analog-input-tvtuner.conf} (55%)
create mode 100644 src/modules/alsa/mixer/paths/analog-input-video.conf
rename src/modules/alsa/mixer/{profiles => profile-sets}/default.conf (73%)
-----------------------------------------------------------------------
commit c71c5372472bcbb3f35f17f5874ae035fdb95fa4
Author: Lennart Poettering <lennart at poettering.net>
Date: Thu Jun 11 22:21:26 2009 +0200
save it for now
diff --git a/src/modules/alsa/alsa-mixer.c b/src/modules/alsa/alsa-mixer.c
index efdb02a..f6cd6b5 100644
--- a/src/modules/alsa/alsa-mixer.c
+++ b/src/modules/alsa/alsa-mixer.c
@@ -43,6 +43,7 @@
#include <pulsecore/once.h>
#include <pulsecore/thread.h>
#include <pulsecore/conf-parser.h>
+#include <pulsecore/strbuf.h>
#include "alsa-mixer.h"
#include "alsa-util.h"
@@ -248,7 +249,7 @@ int pa_alsa_prepare_mixer(snd_mixer_t *mixer, const char *dev) {
pa_log_info("Successfully attached to mixer '%s'", dev);
PA_DEBUG_TRAP;
- ps = pa_alsa_profile_set_new(NULL, PA_ALSA_PLAYBACK);
+ ps = pa_alsa_profile_set_new(NULL);
if (ps)
pa_alsa_profile_set_free(ps);
@@ -580,6 +581,17 @@ int pa_alsa_calc_mixer_map(snd_mixer_elem_t *elem, const pa_channel_map *channel
return 0;
}
+static void setting_free(pa_alsa_setting *s) {
+ pa_assert(s);
+
+ if (s->options)
+ pa_idxset_free(s->options, NULL, NULL);
+
+ pa_xfree(s->name);
+ pa_xfree(s->description);
+ pa_xfree(s);
+}
+
static void option_free(pa_alsa_option *o) {
pa_assert(o);
@@ -602,8 +614,10 @@ static void element_free(pa_alsa_element *e) {
pa_xfree(e);
}
-static void path_free(pa_alsa_path *p) {
+void pa_alsa_path_free(pa_alsa_path *p) {
pa_alsa_element *e;
+ pa_alsa_setting *s;
+
pa_assert(p);
while ((e = p->elements)) {
@@ -611,34 +625,23 @@ static void path_free(pa_alsa_path *p) {
element_free(e);
}
- pa_xfree(p->name);
- pa_xfree(p->description);
- pa_xfree(p);
-}
-
-static void profile_free(pa_alsa_profile *p) {
- pa_alsa_path *path;
- pa_assert(p);
-
- while ((path = p->paths)) {
- PA_LLIST_REMOVE(pa_alsa_path, p->paths, path);
- path_free(path);
+ while ((s = p->settings)) {
+ PA_LLIST_REMOVE(pa_alsa_setting, p->settings, s);
+ setting_free(s);
}
pa_xfree(p->name);
pa_xfree(p->description);
- pa_xstrfreev(p->device_strings);
- pa_xstrfreev(p->path_names);
pa_xfree(p);
}
-void pa_alsa_profile_set_free(pa_alsa_profile_set *ps) {
- pa_alsa_profile *p;
+void pa_alsa_path_set_free(pa_alsa_path_set *ps) {
+ pa_alsa_path *p;
pa_assert(ps);
- while ((p = ps->profiles)) {
- PA_LLIST_REMOVE(pa_alsa_profile, ps->profiles, p);
- profile_free(p);
+ while ((p = ps->paths)) {
+ PA_LLIST_REMOVE(pa_alsa_path, ps->paths, p);
+ pa_alsa_path_free(p);
}
pa_xfree(ps);
@@ -653,12 +656,10 @@ static pa_volume_t from_alsa_dB(long v) {
}
static long to_alsa_volume(pa_volume_t v, long min, long max) {
- long value;
+ long w;
- value = (long) round(((double) v * (double) (max - min)) / PA_VOLUME_NORM) + min;
- value = PA_CLAMP_UNLIKELY(value, min, max);
-
- return value;
+ w = (long) round(((double) v * (double) (max - min)) / PA_VOLUME_NORM) + min;
+ return PA_CLAMP_UNLIKELY(w, min, max);
}
static pa_volume_t from_alsa_volume(long v, long min, long max) {
@@ -672,7 +673,7 @@ static pa_volume_t from_alsa_volume(long v, long min, long max) {
snd_mixer_selem_id_set_index((sid), 0); \
} while(FALSE)
-static int element_get_volume(snd_mixer_t *m, pa_alsa_element *e, const pa_channel_map *cm, pa_cvolume *v) {
+static int element_get_volume(pa_alsa_element *e, snd_mixer_t *m, const pa_channel_map *cm, pa_cvolume *v) {
snd_mixer_selem_id_t *sid;
snd_mixer_elem_t *me;
snd_mixer_selem_channel_id_t c;
@@ -710,19 +711,17 @@ static int element_get_volume(snd_mixer_t *m, pa_alsa_element *e, const pa_chann
f = from_alsa_dB(value);
} else {
- long value = 0, min = 0, max = 0;
+ long value = 0;
if (e->direction == PA_ALSA_PLAYBACK) {
- if ((r = snd_mixer_selem_get_playback_volume(me, c, &value)) >= 0)
- r = snd_mixer_selem_get_playback_volume_range(me, &min, &max);
+ r = snd_mixer_selem_get_playback_volume(me, c, &value);
} else
- if ((r = snd_mixer_selem_get_capture_volume(me, c, &value)) >= 0)
- r = snd_mixer_selem_get_capture_volume_range(me, &min, &max);
+ r = snd_mixer_selem_get_capture_volume(me, c, &value);
if (r < 0)
continue;
- f = from_alsa_volume(value, min, max);
+ f = from_alsa_volume(value, e->min_volume, e->max_volume);
}
for (k = 0; k < cm->channels; k++)
@@ -740,7 +739,7 @@ static int element_get_volume(snd_mixer_t *m, pa_alsa_element *e, const pa_chann
return 0;
}
-int pa_alsa_path_get_volume(snd_mixer_t *m, pa_alsa_path *p, const pa_channel_map *cm, pa_cvolume *v) {
+int pa_alsa_path_get_volume(pa_alsa_path *p, snd_mixer_t *m, const pa_channel_map *cm, pa_cvolume *v) {
pa_alsa_element *e;
pa_assert(m);
@@ -759,10 +758,9 @@ int pa_alsa_path_get_volume(snd_mixer_t *m, pa_alsa_path *p, const pa_channel_ma
if (e->volume_use != PA_ALSA_VOLUME_MERGE)
continue;
- if (p->has_dB && !e->has_dB)
- continue;
+ pa_assert(!p->has_dB || e->has_dB);
- if (element_get_volume(m, e, cm, &ev) < 0)
+ if (element_get_volume(e, m, cm, &ev) < 0)
return -1;
/* If we have no dB information all we can do is take the first element and leave */
@@ -777,7 +775,7 @@ int pa_alsa_path_get_volume(snd_mixer_t *m, pa_alsa_path *p, const pa_channel_ma
return 0;
}
-static int element_get_switch(snd_mixer_t *m, pa_alsa_element *e, pa_bool_t *b) {
+static int element_get_switch(pa_alsa_element *e, snd_mixer_t *m, pa_bool_t *b) {
snd_mixer_selem_id_t *sid;
snd_mixer_elem_t *me;
snd_mixer_selem_channel_id_t c;
@@ -804,18 +802,17 @@ static int element_get_switch(snd_mixer_t *m, pa_alsa_element *e, pa_bool_t *b)
if (r < 0)
continue;
- if (value) {
- *b = TRUE;
+ if (!value) {
+ *b = FALSE;
return 0;
}
-
}
- *b = FALSE;
+ *b = TRUE;
return 0;
}
-int pa_alsa_path_get_mute(snd_mixer_t *m, pa_alsa_path *p, pa_bool_t *muted) {
+int pa_alsa_path_get_mute(pa_alsa_path *p, snd_mixer_t *m, pa_bool_t *muted) {
pa_alsa_element *e;
pa_assert(m);
@@ -831,7 +828,7 @@ int pa_alsa_path_get_mute(snd_mixer_t *m, pa_alsa_path *p, pa_bool_t *muted) {
if (e->switch_use != PA_ALSA_SWITCH_MUTE)
continue;
- if (element_get_switch(m, e, &b) < 0)
+ if (element_get_switch(e, m, &b) < 0)
return -1;
if (!b) {
@@ -844,7 +841,7 @@ int pa_alsa_path_get_mute(snd_mixer_t *m, pa_alsa_path *p, pa_bool_t *muted) {
return 0;
}
-static int element_set_volume(snd_mixer_t *m, pa_alsa_element *e, const pa_channel_map *cm, pa_cvolume *v) {
+static int element_set_volume(pa_alsa_element *e, snd_mixer_t *m, const pa_channel_map *cm, pa_cvolume *v) {
snd_mixer_selem_id_t *sid;
pa_cvolume rv;
snd_mixer_elem_t *me;
@@ -890,17 +887,9 @@ static int element_set_volume(snd_mixer_t *m, pa_alsa_element *e, const pa_chann
f = from_alsa_dB(value);
} else {
- long value, min = 0, max = 0;
-
- if (e->direction == PA_ALSA_PLAYBACK)
- r = snd_mixer_selem_get_playback_volume_range(me, &min, &max);
- else
- r = snd_mixer_selem_get_capture_volume_range(me, &min, &max);
+ long value;
- if (r < 0)
- continue;
-
- value = to_alsa_volume(f, min, max);
+ value = to_alsa_volume(f, e->min_volume, e->max_volume);
if (e->direction == PA_ALSA_PLAYBACK) {
if ((r = snd_mixer_selem_set_playback_volume(me, c, value)) >= 0)
@@ -913,7 +902,7 @@ static int element_set_volume(snd_mixer_t *m, pa_alsa_element *e, const pa_chann
if (r < 0)
continue;
- f = from_alsa_volume(value, min, max);
+ f = from_alsa_volume(value, e->min_volume, e->max_volume);
}
for (k = 0; k < cm->channels; k++)
@@ -932,7 +921,7 @@ static int element_set_volume(snd_mixer_t *m, pa_alsa_element *e, const pa_chann
return 0;
}
-int pa_alsa_path_set_volume(snd_mixer_t *m, pa_alsa_path *p, const pa_channel_map *cm, pa_cvolume *v) {
+int pa_alsa_path_set_volume(pa_alsa_path *p, snd_mixer_t *m, const pa_channel_map *cm, pa_cvolume *v) {
pa_alsa_element *e;
pa_cvolume rv;
@@ -954,11 +943,10 @@ int pa_alsa_path_set_volume(snd_mixer_t *m, pa_alsa_path *p, const pa_channel_ma
if (e->volume_use != PA_ALSA_VOLUME_MERGE)
continue;
- if (p->has_dB && !e->has_dB)
- continue;
+ pa_assert(!p->has_dB || e->has_dB);
ev = rv;
- if (element_set_volume(m, e, cm, &ev) < 0)
+ if (element_set_volume(e, m, cm, &ev) < 0)
return -1;
if (!p->has_dB) {
@@ -973,7 +961,7 @@ int pa_alsa_path_set_volume(snd_mixer_t *m, pa_alsa_path *p, const pa_channel_ma
return 0;
}
-static int element_set_switch(snd_mixer_t *m, pa_alsa_element *e, pa_bool_t b) {
+static int element_set_switch(pa_alsa_element *e, snd_mixer_t *m, pa_bool_t b) {
snd_mixer_elem_t *me;
snd_mixer_selem_id_t *sid;
int r;
@@ -997,7 +985,7 @@ static int element_set_switch(snd_mixer_t *m, pa_alsa_element *e, pa_bool_t b) {
return 0;
}
-int pa_alsa_path_set_mute(snd_mixer_t *m, pa_alsa_path *p, pa_bool_t muted) {
+int pa_alsa_path_set_mute(pa_alsa_path *p, snd_mixer_t *m, pa_bool_t muted) {
pa_alsa_element *e;
pa_assert(m);
@@ -1011,15 +999,14 @@ int pa_alsa_path_set_mute(snd_mixer_t *m, pa_alsa_path *p, pa_bool_t muted) {
if (e->switch_use != PA_ALSA_SWITCH_MUTE)
continue;
- if (element_set_switch(m, e, !muted) < 0)
+ if (element_set_switch(e, m, !muted) < 0)
return -1;
}
return 0;
}
-static int element_mute_volume(snd_mixer_t *m, pa_alsa_element *e) {
- long min, max;
+static int element_mute_volume(pa_alsa_element *e, snd_mixer_t *m) {
snd_mixer_elem_t *me;
snd_mixer_selem_id_t *sid;
int r;
@@ -1031,17 +1018,36 @@ static int element_mute_volume(snd_mixer_t *m, pa_alsa_element *e) {
if (!(me = snd_mixer_find_selem(m, sid)))
return -1;
- if (e->direction == PA_ALSA_PLAYBACK) {
- if ((r = snd_mixer_selem_get_playback_volume_range(me, &min, &max)) >= 0)
- r = snd_mixer_selem_set_playback_volume_all(me, min);
- } else
- if ((r = snd_mixer_selem_get_capture_volume_range(me, &min, &max)) >= 0)
- r = snd_mixer_selem_set_capture_volume_all(me, min);
+ if (e->direction == PA_ALSA_PLAYBACK)
+ r = snd_mixer_selem_set_playback_volume_all(me, e->min_volume);
+ else
+ r = snd_mixer_selem_set_capture_volume_all(me, e->min_volume);
return r;
}
-int pa_alsa_path_select(snd_mixer_t *m, pa_alsa_path *p) {
+/* The volume to 0dB */
+static int element_zero_volume(pa_alsa_element *e, snd_mixer_t *m) {
+ snd_mixer_elem_t *me;
+ snd_mixer_selem_id_t *sid;
+ int r;
+
+ pa_assert(m);
+ pa_assert(e);
+
+ SELEM_INIT(sid, e->alsa_name);
+ if (!(me = snd_mixer_find_selem(m, sid)))
+ return -1;
+
+ if (e->direction == PA_ALSA_PLAYBACK)
+ r = snd_mixer_selem_set_playback_dB_all(me, 0, +1);
+ else
+ r = snd_mixer_selem_set_capture_dB_all(me, 0, +1);
+
+ return r;
+}
+
+int pa_alsa_path_select(pa_alsa_path *p, snd_mixer_t *m) {
pa_alsa_element *e;
int r;
@@ -1053,11 +1059,11 @@ int pa_alsa_path_select(snd_mixer_t *m, pa_alsa_path *p) {
switch (e->switch_use) {
case PA_ALSA_SWITCH_MUTE:
case PA_ALSA_SWITCH_OFF:
- r = element_set_switch(m, e, FALSE);
+ r = element_set_switch(e, m, FALSE);
break;
case PA_ALSA_SWITCH_ON:
- r = element_set_switch(m, e, TRUE);
+ r = element_set_switch(e, m, TRUE);
break;
case PA_ALSA_SWITCH_IGNORE:
@@ -1072,7 +1078,11 @@ int pa_alsa_path_select(snd_mixer_t *m, pa_alsa_path *p) {
switch (e->volume_use) {
case PA_ALSA_VOLUME_OFF:
case PA_ALSA_VOLUME_MERGE:
- r = element_mute_volume(m, e);
+ r = element_mute_volume(e, m);
+ break;
+
+ case PA_ALSA_VOLUME_ZERO:
+ r = element_zero_volume(e, m);
break;
case PA_ALSA_VOLUME_IGNORE:
@@ -1087,29 +1097,6 @@ int pa_alsa_path_select(snd_mixer_t *m, pa_alsa_path *p) {
return 0;
}
-pa_alsa_element* pa_alsa_path_iterate_options(pa_alsa_path *p, pa_alsa_element *last) {
- pa_alsa_element *e;
- pa_assert(p);
-
-
- PA_LLIST_FOREACH(e, last ? last->next : p->elements)
- if (e->expose_options)
- return e;
-
- return NULL;
-}
-
-pa_alsa_option* pa_alsa_element_iterate_options(pa_alsa_element *e, pa_alsa_option *last) {
- pa_alsa_option *o;
- pa_assert(e);
-
- PA_LLIST_FOREACH(o, last ? last->next : e->options)
- if (o->expose)
- return o;
-
- return NULL;
-}
-
static int check_required(pa_alsa_element *e, snd_mixer_elem_t *me) {
pa_bool_t has_switch;
pa_bool_t has_enumeration;
@@ -1159,7 +1146,7 @@ static int check_required(pa_alsa_element *e, snd_mixer_elem_t *me) {
return 0;
}
-static int element_probe(snd_mixer_t *m, pa_alsa_element *e) {
+static int element_probe(pa_alsa_element *e, snd_mixer_t *m) {
snd_mixer_selem_id_t *sid;
snd_mixer_elem_t *me;
@@ -1227,6 +1214,7 @@ static int element_probe(snd_mixer_t *m, pa_alsa_element *e) {
if (e->volume_use != PA_ALSA_VOLUME_IGNORE) {
long min_dB = 0, max_dB = 0;
pa_channel_position_t p;
+ pa_bool_t is_mono;
e->direction_try_other = FALSE;
@@ -1240,10 +1228,20 @@ static int element_probe(snd_mixer_t *m, pa_alsa_element *e) {
e->max_dB = ((double) max_dB) / 100.0;
}
- if (snd_mixer_selem_get_playback_dB_range(me, &e->min_volume, &e->max_volume) < 0)
- return -1;
+ if (e->direction == PA_ALSA_PLAYBACK) {
+ if (snd_mixer_selem_get_playback_volume_range(me, &e->min_volume, &e->max_volume) < 0)
+ return -1;
+ } else {
+ if (snd_mixer_selem_get_capture_volume_range(me, &e->min_volume, &e->max_volume) < 0)
+ return -1;
+ }
- if (snd_mixer_selem_is_playback_mono(me)) {
+ if (e->direction == PA_ALSA_PLAYBACK)
+ is_mono = snd_mixer_selem_is_playback_mono(me) > 0;
+ else
+ is_mono = snd_mixer_selem_is_capture_mono(me) > 0;
+
+ if (is_mono) {
e->n_channels = 1;
if (!e->override_map)
@@ -1290,9 +1288,11 @@ static pa_alsa_element* element_get(pa_alsa_path *p, const char *section) {
pa_assert(p);
pa_assert(section);
- if (pa_streq(section, "Path"))
+ if (!pa_startswith(section, "Element "))
return NULL;
+ section += 8;
+
/* This is not an element section, but an enum section? */
if (strchr(section, ':'))
return NULL;
@@ -1307,7 +1307,7 @@ static pa_alsa_element* element_get(pa_alsa_path *p, const char *section) {
e = pa_xnew0(pa_alsa_element, 1);
e->path = p;
e->alsa_name = pa_xstrdup(section);
- e->direction = p->profile->profile_set->direction;
+ e->direction = p->direction;
PA_LLIST_PREPEND(pa_alsa_element, p->elements, e);
@@ -1322,6 +1322,11 @@ static pa_alsa_option* option_get(pa_alsa_path *p, const char *section) {
pa_alsa_option *o;
pa_alsa_element *e;
+ if (!pa_startswith(section, "Option "))
+ return NULL;
+
+ section += 7;
+
/* This is not an enum section, but an element section? */
if (!(on = strrchr(section, ':')))
return NULL;
@@ -1354,7 +1359,7 @@ finish:
return o;
}
-static int path_parse_switch(
+static int element_parse_switch(
const char *filename,
unsigned line,
const char *section,
@@ -1391,7 +1396,7 @@ static int path_parse_switch(
return 0;
}
-static int path_parse_volume(
+static int element_parse_volume(
const char *filename,
unsigned line,
const char *section,
@@ -1416,6 +1421,8 @@ static int path_parse_volume(
e->volume_use = PA_ALSA_VOLUME_MERGE;
else if (pa_streq(rvalue, "off"))
e->volume_use = PA_ALSA_VOLUME_OFF;
+ else if (pa_streq(rvalue, "zero"))
+ e->volume_use = PA_ALSA_VOLUME_ZERO;
else {
pa_log("[%s:%u] Volume invalid of '%s'", filename, line, section);
return -1;
@@ -1424,7 +1431,7 @@ static int path_parse_volume(
return 0;
}
-static int path_parse_enumeration(
+static int element_parse_enumeration(
const char *filename,
unsigned line,
const char *section,
@@ -1455,7 +1462,7 @@ static int path_parse_enumeration(
return 0;
}
-static int path_parse_priority(
+static int option_parse_priority(
const char *filename,
unsigned line,
const char *section,
@@ -1484,7 +1491,7 @@ static int path_parse_priority(
return 0;
}
-static int path_parse_name(
+static int option_parse_name(
const char *filename,
unsigned line,
const char *section,
@@ -1509,7 +1516,7 @@ static int path_parse_name(
return 0;
}
-static int path_parse_required(
+static int element_parse_required(
const char *filename,
unsigned line,
const char *section,
@@ -1552,7 +1559,7 @@ static int path_parse_required(
return 0;
}
-static int path_parse_direction(
+static int element_parse_direction(
const char *filename,
unsigned line,
const char *section,
@@ -1583,7 +1590,7 @@ static int path_parse_direction(
return 0;
}
-static int path_parse_direction_try_other(
+static int element_parse_direction_try_other(
const char *filename,
unsigned line,
const char *section,
@@ -1638,7 +1645,7 @@ static pa_channel_position_mask_t parse_mask(const char *m) {
return 0;
}
-static int path_parse_override_map(
+static int element_parse_override_map(
const char *filename,
unsigned line,
const char *section,
@@ -1686,131 +1693,377 @@ static int path_parse_override_map(
return 0;
}
-static int path_probe(snd_mixer_t *m, pa_alsa_profile *p, const char *path_name) {
+static int element_verify(pa_alsa_element *e) {
+ pa_assert(e);
+
+ if ((e->required != PA_ALSA_REQUIRED_IGNORE && e->required == e->required_absent) ||
+ (e->required_absent == PA_ALSA_REQUIRED_ANY && e->required != PA_ALSA_REQUIRED_IGNORE)) {
+ pa_log("Element %s cannot be required and absent at the same time.", e->alsa_name);
+ return -1;
+ }
+
+ return 0;
+}
+
+pa_alsa_path* pa_alsa_path_new(const char *fname, pa_alsa_direction_t direction) {
pa_alsa_element *e;
- pa_alsa_path *path;
+ pa_alsa_path *p;
char *fn;
int r;
pa_config_item items[] = {
- { "priority", pa_config_parse_unsigned, NULL, "Path" },
- { "description", pa_config_parse_string, NULL, "Path" },
- { "priority", path_parse_priority, NULL, NULL },
- { "name", path_parse_name, NULL, NULL },
- { "switch", path_parse_switch, NULL, NULL },
- { "volume", path_parse_volume, NULL, NULL },
- { "enumeration", path_parse_enumeration, NULL, NULL },
- { "override-map.1", path_parse_override_map, NULL, NULL },
- { "override-map.2", path_parse_override_map, NULL, NULL },
- /* Later on we might add override-map.3 and so on here */
- { "required", path_parse_required, NULL, NULL },
- { "required-absent", path_parse_required, NULL, NULL },
- { "direction", path_parse_direction, NULL, NULL },
- { "direction-try-other", path_parse_direction_try_other, NULL, NULL },
+ /* [General] */
+ { "priority", pa_config_parse_unsigned, NULL, "General" },
+ { "description", pa_config_parse_string, NULL, "General" },
+
+ /* [Option ...] */
+ { "priority", option_parse_priority, NULL, NULL },
+ { "name", option_parse_name, NULL, NULL },
+
+ /* [Element ...] */
+ { "switch", element_parse_switch, NULL, NULL },
+ { "volume", element_parse_volume, NULL, NULL },
+ { "enumeration", element_parse_enumeration, NULL, NULL },
+ { "override-map.1", element_parse_override_map, NULL, NULL },
+ { "override-map.2", element_parse_override_map, NULL, NULL },
+ /* ... later on we might add override-map.3 and so on here ... */
+ { "required", element_parse_required, NULL, NULL },
+ { "required-absent", element_parse_required, NULL, NULL },
+ { "direction", element_parse_direction, NULL, NULL },
+ { "direction-try-other", element_parse_direction_try_other, NULL, NULL },
{ NULL, NULL, NULL, NULL }
};
- pa_assert(m);
- pa_assert(p);
- pa_assert(path_name);
+ pa_assert(fname);
- path = pa_xnew0(pa_alsa_path, 1);
- path->profile = p;
- path->name = pa_xstrdup(path_name);
+ p = pa_xnew0(pa_alsa_path, 1);
+ p->name = pa_xstrdup(fname);
+ p->direction = direction;
- items[0].data = &path->priority;
- items[1].data = &path->description;
+ items[0].data = &p->priority;
+ items[1].data = &p->description;
- fn = pa_maybe_prefix_path(path_name, PA_ALSA_PATHS_PATH);
- r = pa_config_parse(fn, NULL, items, path);
+ fn = pa_maybe_prefix_path(fname, PA_ALSA_PATHS_PATH);
+ r = pa_config_parse(fn, NULL, items, p);
pa_xfree(fn);
if (r < 0)
goto fail;
- PA_LLIST_FOREACH(e, path->elements) {
- if (element_probe(m, e) < 0)
+ PA_LLIST_FOREACH(e, p->elements)
+ if (element_verify(e) < 0)
goto fail;
+ return p;
+
+fail:
+ pa_alsa_path_free(p);
+ return NULL;
+}
+
+pa_alsa_path* pa_alsa_path_synthesize(const char*element, pa_alsa_direction_t direction) {
+ pa_alsa_path *p;
+ pa_alsa_element *e;
+
+ pa_assert(element);
+
+ p = pa_xnew0(pa_alsa_path, 1);
+ p->name = pa_xstrdup(element);
+ p->direction = direction;
+
+ e = pa_xnew0(pa_alsa_element, 1);
+ e->path = p;
+ e->alsa_name = pa_xstrdup(element);
+ e->direction = direction;
+
+ e->switch_use = PA_ALSA_SWITCH_MUTE;
+ e->volume_use = PA_ALSA_VOLUME_MERGE;
+
+ PA_LLIST_PREPEND(pa_alsa_element, p->elements, e);
+ return p;
+}
+
+int pa_alsa_path_probe(pa_alsa_path *p, snd_mixer_t *m) {
+ pa_alsa_element *e;
+
+ pa_assert(p);
+ pa_assert(m);
+
+ if (p->probed)
+ return 0;
+
+ PA_LLIST_FOREACH(e, p->elements) {
+ if (element_probe(e, m) < 0) {
+ p->supported = FALSE;
+ return -1;
+ }
+
if (e->volume_use == PA_ALSA_VOLUME_MERGE) {
- if (!path->has_volume) {
- path->min_volume = e->min_volume;
- path->max_volume = e->max_volume;
+ if (!p->has_volume) {
+ p->min_volume = e->min_volume;
+ p->max_volume = e->max_volume;
}
if (e->has_dB) {
- if (!path->has_volume) {
- path->min_dB = e->min_dB;
- path->max_dB = e->max_dB;
- path->has_dB = TRUE;
- } else if (path->has_volume && path->has_dB) {
- path->min_dB += e->min_dB;
- path->max_dB += e->max_dB;
+ if (!p->has_volume) {
+ p->min_dB = e->min_dB;
+ p->max_dB = e->max_dB;
+ p->has_dB = TRUE;
+ } else {
+
+ if (p->has_dB) {
+ p->min_dB += e->min_dB;
+ p->max_dB += e->max_dB;
+ } else
+ /* Hmm, there's another element before us
+ * which cannot do dB volumes, so we we need
+ * to 'neutralize' this slider */
+ e->volume_use = PA_ALSA_VOLUME_ZERO;
}
- }
+ } else if (p->has_volume)
+ /* We can't use this volume, so let's ignore it */
+ e->volume_use = PA_ALSA_VOLUME_IGNORE;
- path->has_volume = TRUE;
+ p->has_volume = TRUE;
}
if (e->switch_use == PA_ALSA_SWITCH_MUTE)
- path->has_mute = TRUE;
+ p->has_mute = TRUE;
}
- PA_LLIST_PREPEND(pa_alsa_path, p->paths, path);
+ p->supported = TRUE;
+ p->probed = TRUE;
return 0;
+}
-fail:
- path_free(path);
- return -1;
+static pa_bool_t element_drop_unsupported(pa_alsa_element *e) {
+ pa_alsa_option *o, *n;
+
+ pa_assert(e);
+
+ for (o = e->options; o; o = n) {
+ n = o->next;
+
+ if (o->alsa_idx < 0) {
+ PA_LLIST_REMOVE(pa_alsa_option, e->options, o);
+ option_free(o);
+ }
+ }
+
+ return
+ e->switch_use != PA_ALSA_SWITCH_IGNORE ||
+ e->volume_use != PA_ALSA_VOLUME_IGNORE ||
+ e->enumeration_use != PA_ALSA_ENUMERATION_IGNORE;
}
-int pa_alsa_profile_probe_paths(snd_mixer_t *m, pa_alsa_profile *p) {
- char **t;
+pa_bool_t pa_alsa_path_drop_unsupported(pa_alsa_path *p) {
+ pa_alsa_element *e, *n;
+
pa_assert(p);
- if (p->probed)
- return 0;
+ for (e = p->elements; e; e = n) {
+ n = e->next;
- if (!p->path_names)
- return 0;
+ if (!element_drop_unsupported(e)) {
+ PA_LLIST_REMOVE(pa_alsa_element, p->elements, e);
+ element_free(e);
+ }
+ }
- for (t = p->path_names; *t; t++)
- if (path_probe(m, p, *t) < 0)
- return -1;
+ return !!p->elements;
+}
- return 0;
+pa_alsa_path_set *pa_alsa_path_set_new(pa_alsa_mapping *m, pa_alsa_direction_t direction) {
+ pa_alsa_path_set *ps;
+ char **pn = NULL, **en = NULL, **ie;
+ pa_assert(m);
+
+ ps = pa_xnew0(pa_alsa_path_set, 1);
+ ps->direction = direction;
+
+ if (direction == PA_ALSA_PLAYBACK)
+ pn = m->output_path_names;
+ else if (direction == PA_ALSA_CAPTURE)
+ pn = m->input_path_names;
+
+ if (pn) {
+
+ for (; *pn; pn++) {
+ pa_alsa_path *p;
+
+ if ((p = pa_alsa_path_new(*pn, direction))) {
+ p->path_set = ps;
+ PA_LLIST_PREPEND(pa_alsa_path, ps->paths, p);
+ }
+ }
+
+ return ps;
+ }
+
+ if (direction == PA_ALSA_PLAYBACK)
+ en = m->output_element;
+ else if (direction == PA_ALSA_CAPTURE)
+ en = m->input_element;
+
+ if (!en) {
+ pa_alsa_path_set_free(ps);
+ return NULL;
+ }
+
+ for (ie = en; *ie; ie++) {
+ char **je;
+ pa_alsa_path *p;
+
+ p = pa_alsa_path_synthesize(*ie, direction);
+ p->path_set = ps;
+
+ /* Mark all other passed elements for require-absent */
+ for (je = en; *je; je++) {
+ pa_alsa_element *e;
+ e = pa_xnew0(pa_alsa_element, 1);
+ e->path = p;
+ e->alsa_name = pa_xstrdup(*je);
+ e->direction = direction;
+ e->required_absent = PA_ALSA_REQUIRED_ANY;
+
+ PA_LLIST_PREPEND(pa_alsa_element, p->elements, e);
+ }
+
+ PA_LLIST_PREPEND(pa_alsa_path, ps->paths, p);
+ }
+
+ return ps;
}
-static pa_alsa_profile *profile_get(pa_alsa_profile_set *ps, const char *name) {
- pa_alsa_profile *p;
+void pa_alsa_path_set_probe(pa_alsa_path_set *ps, snd_mixer_t *m) {
+ pa_alsa_path *p;
+
+ pa_assert(ps);
+
+ PA_LLIST_FOREACH(p, ps->paths)
+ pa_alsa_path_probe(p, m);
+}
+
+void pa_alsa_path_set_drop_unsupported(pa_alsa_path_set *ps) {
+ pa_alsa_path *p, *n;
+ pa_assert(ps);
+
+ for (p = ps->paths; p; p = n) {
+ n = p->next;
+
+ if (p->supported &&
+ pa_alsa_path_drop_unsupported(p))
+ continue;
+
+ PA_LLIST_REMOVE(pa_alsa_path, ps->paths, p);
+ pa_alsa_path_free(p);
+ }
+}
+
+static void mapping_free(pa_alsa_mapping *m) {
+ pa_assert(m);
+
+ pa_xfree(m->name);
+ pa_xfree(m->description);
+
+ pa_xstrfreev(m->device_strings);
+ pa_xstrfreev(m->input_path_names);
+ pa_xstrfreev(m->output_path_names);
+ pa_xstrfreev(m->input_element);
+ pa_xstrfreev(m->output_element);
+
+ pa_assert(!m->input_pcm);
+ pa_assert(!m->output_pcm);
+
+ pa_xfree(m);
+}
+
+static void profile_free(pa_alsa_profile *p) {
+ pa_assert(p);
+
+ pa_xfree(p->name);
+ pa_xfree(p->description);
+
+ pa_xstrfreev(p->input_mapping_names);
+ pa_xstrfreev(p->output_mapping_names);
+
+ if (p->input_mappings)
+ pa_idxset_free(p->input_mappings, NULL, NULL);
+
+ if (p->output_mappings)
+ pa_idxset_free(p->output_mappings, NULL, NULL);
+
+ pa_xfree(p);
+}
+
+void pa_alsa_profile_set_free(pa_alsa_profile_set *ps) {
+ pa_assert(ps);
+
+ if (ps->profiles) {
+ pa_alsa_profile *p;
+
+ while ((p = pa_hashmap_steal_first(ps->profiles)))
+ profile_free(p);
+
+ pa_hashmap_free(ps->profiles, NULL, NULL);
+ }
+
+ if (ps->mappings) {
+ pa_alsa_mapping *m;
+
+ while ((m = pa_hashmap_steal_first(ps->mappings)))
+ mapping_free(m);
+
+ pa_hashmap_free(ps->mappings, NULL, NULL);
+ }
+
+ pa_xfree(ps);
+}
+
+static pa_alsa_mapping *mapping_get(pa_alsa_profile_set *ps, const char *name) {
+ pa_alsa_mapping *m;
if (!pa_startswith(name, "Mapping "))
return NULL;
name += 8;
- if (ps->parse_cache && pa_streq(ps->parse_cache->name, name))
- return ps->parse_cache;
+ if ((m = pa_hashmap_get(ps->mappings, name)))
+ return m;
- PA_LLIST_FOREACH(p, ps->profiles)
- if (pa_streq(p->name, name))
- goto finish;
+ m = pa_xnew0(pa_alsa_mapping, 1);
+ m->profile_set = ps;
+ m->name = pa_xstrdup(name);
+ pa_channel_map_init(&m->channel_map);
+
+ pa_hashmap_put(ps->mappings, m->name, m);
+
+ return m;
+}
+
+static pa_alsa_profile *profile_get(pa_alsa_profile_set *ps, const char *name) {
+ pa_alsa_profile *p;
+
+ if (!pa_startswith(name, "Profile "))
+ return NULL;
+
+ name += 8;
+
+ if ((p = pa_hashmap_get(ps->profiles, name)))
+ return p;
p = pa_xnew0(pa_alsa_profile, 1);
p->profile_set = ps;
p->name = pa_xstrdup(name);
- pa_channel_map_init(&p->channel_map);
- PA_LLIST_PREPEND(pa_alsa_profile, ps->profiles, p);
+ pa_hashmap_put(ps->profiles, p->name, p);
-finish:
- ps->parse_cache = p;
return p;
}
-static int profile_set_parse_device_strings(
+static int mapping_parse_device_strings(
const char *filename,
unsigned line,
const char *section,
@@ -1820,14 +2073,17 @@ static int profile_set_parse_device_strings(
void *userdata) {
pa_alsa_profile_set *ps = userdata;
- pa_alsa_profile *p;
+ pa_alsa_mapping *m;
pa_assert(ps);
- p = profile_get(ps, section);
- pa_xstrfreev(p->device_strings);
+ if (!(m = mapping_get(ps, section))) {
+ pa_log("[%s:%u] %s invalid in section %s", filename, line, lvalue, section);
+ return -1;
+ }
- if (!(p->device_strings = pa_split_spaces_strv(rvalue))) {
+ pa_xstrfreev(m->device_strings);
+ if (!(m->device_strings = pa_split_spaces_strv(rvalue))) {
pa_log("[%s:%u] Device string list empty of '%s'", filename, line, section);
return -1;
}
@@ -1835,7 +2091,7 @@ static int profile_set_parse_device_strings(
return 0;
}
-static int profile_set_parse_description(
+static int mapping_parse_channel_map(
const char *filename,
unsigned line,
const char *section,
@@ -1845,18 +2101,24 @@ static int profile_set_parse_description(
void *userdata) {
pa_alsa_profile_set *ps = userdata;
- pa_alsa_profile *p;
+ pa_alsa_mapping *m;
pa_assert(ps);
- p = profile_get(ps, section);
- pa_xfree(p->description);
- p->description = pa_xstrdup(rvalue);
+ if (!(m = mapping_get(ps, section))) {
+ pa_log("[%s:%u] %s invalid in section %s", filename, line, lvalue, section);
+ return -1;
+ }
+
+ if (!(pa_channel_map_parse(&m->channel_map, rvalue))) {
+ pa_log("[%s:%u] Channel map invalid of '%s'", filename, line, section);
+ return -1;
+ }
return 0;
}
-static int profile_set_parse_channel_map(
+static int mapping_parse_paths(
const char *filename,
unsigned line,
const char *section,
@@ -1866,21 +2128,27 @@ static int profile_set_parse_channel_map(
void *userdata) {
pa_alsa_profile_set *ps = userdata;
- pa_alsa_profile *p;
+ pa_alsa_mapping *m;
pa_assert(ps);
- p = profile_get(ps, section);
-
- if (!(pa_channel_map_parse(&p->channel_map, rvalue))) {
- pa_log("[%s:%u] Channel map invalid of '%s'", filename, line, section);
+ if (!(m = mapping_get(ps, section))) {
+ pa_log("[%s:%u] %s invalid in section %s", filename, line, lvalue, section);
return -1;
}
+ if (pa_streq(lvalue, "paths-input")) {
+ pa_xstrfreev(m->input_path_names);
+ m->input_path_names = pa_split_spaces_strv(rvalue);
+ } else {
+ pa_xstrfreev(m->output_path_names);
+ m->output_path_names = pa_split_spaces_strv(rvalue);
+ }
+
return 0;
}
-static int profile_set_parse_paths(
+static int mapping_parse_element(
const char *filename,
unsigned line,
const char *section,
@@ -1890,24 +2158,56 @@ static int profile_set_parse_paths(
void *userdata) {
pa_alsa_profile_set *ps = userdata;
- pa_alsa_profile *p;
+ pa_alsa_mapping *m;
pa_assert(ps);
- p = profile_get(ps, section);
+ if (!(m = mapping_get(ps, section))) {
+ pa_log("[%s:%u] %s invalid in section %s", filename, line, lvalue, section);
+ return -1;
+ }
- if (pa_streq(lvalue, "paths-input") && ps->direction != PA_ALSA_CAPTURE)
- return 0;
+ if (pa_streq(lvalue, "element-input")) {
+ pa_xstrfreev(m->input_element);
+ m->input_element = pa_split_spaces_strv(rvalue);
+ } else {
+ pa_xstrfreev(m->output_element);
+ m->output_element = pa_split_spaces_strv(rvalue);
+ }
- if (pa_streq(lvalue, "paths-output") && ps->direction != PA_ALSA_PLAYBACK)
- return 0;
+ return 0;
+}
+
+static int mapping_parse_description(
+ const char *filename,
+ unsigned line,
+ const char *section,
+ const char *lvalue,
+ const char *rvalue,
+ void *data,
+ void *userdata) {
+
+ pa_alsa_profile_set *ps = userdata;
+ pa_alsa_profile *p;
+ pa_alsa_mapping *m;
+
+ pa_assert(ps);
+
+ if ((m = mapping_get(ps, section))) {
+ pa_xstrdup(m->description);
+ m->description = pa_xstrdup(rvalue);
+ } else if ((p = profile_get(ps, section))) {
+ pa_xfree(p->description);
+ p->description = pa_xstrdup(rvalue);
+ } else {
+ pa_log("[%s:%u] Section name %s invalid.", filename, line, section);
+ return -1;
+ }
- pa_xstrfreev(p->path_names);
- p->path_names = pa_split_spaces_strv(rvalue);
return 0;
}
-static int profile_set_parse_priority(
+static int mapping_parse_priority(
const char *filename,
unsigned line,
const char *section,
@@ -1918,34 +2218,85 @@ static int profile_set_parse_priority(
pa_alsa_profile_set *ps = userdata;
pa_alsa_profile *p;
+ pa_alsa_mapping *m;
uint32_t prio;
pa_assert(ps);
- p = profile_get(ps, section);
-
if (pa_atou(rvalue, &prio) < 0) {
pa_log("[%s:%u] Priority invalid of '%s'", filename, line, section);
return -1;
}
- p->priority = prio;
+ if ((m = mapping_get(ps, section)))
+ m->priority = prio;
+ else if ((p = profile_get(ps, section)))
+ p->priority = prio;
+ else {
+ pa_log("[%s:%u] Section name %s invalid.", filename, line, section);
+ return -1;
+ }
+
return 0;
}
-static int profile_verify(pa_alsa_profile *p) {
- pa_assert(p);
+static int profile_parse_mappings(
+ const char *filename,
+ unsigned line,
+ const char *section,
+ const char *lvalue,
+ const char *rvalue,
+ void *data,
+ void *userdata) {
+
+ pa_alsa_profile_set *ps = userdata;
+ pa_alsa_profile *p;
+
+ pa_assert(ps);
- if (!pa_channel_map_valid(&p->channel_map)) {
- pa_log("Profile %s is missing channel map.", p->name);
+ if (!(p = profile_get(ps, section))) {
+ pa_log("[%s:%u] %s invalid in section %s", filename, line, lvalue, section);
return -1;
}
- if (!p->device_strings) {
- pa_log("Profile %s is missing device strings.", p->name);
+ if (pa_streq(lvalue, "input-mappings")) {
+ pa_xstrfreev(p->input_mapping_names);
+ p->input_mapping_names = pa_split_spaces_strv(rvalue);
+ } else {
+ pa_xstrfreev(p->output_mapping_names);
+ p->output_mapping_names = pa_split_spaces_strv(rvalue);
+ }
+
+ return 0;
+}
+
+static int profile_parse_skip_probe(
+ const char *filename,
+ unsigned line,
+ const char *section,
+ const char *lvalue,
+ const char *rvalue,
+ void *data,
+ void *userdata) {
+
+ pa_alsa_profile_set *ps = userdata;
+ pa_alsa_profile *p;
+ int b;
+
+ pa_assert(ps);
+
+ if (!(p = profile_get(ps, section))) {
+ pa_log("[%s:%u] %s invalid in section %s", filename, line, lvalue, section);
return -1;
}
+ if ((b = pa_parse_boolean(rvalue)) < 0) {
+ pa_log("[%s:%u] Skip probe invalid of '%s'", filename, line, section);
+ return -1;
+ }
+
+ p->supported = b;
+
return 0;
}
@@ -1964,11 +2315,7 @@ static const char *lookup_description(const char *name, const struct description
return NULL;
}
-pa_alsa_profile_set* pa_alsa_profile_set_new(const char *fname, pa_alsa_direction_t direction) {
- pa_alsa_profile_set *ps;
- pa_alsa_profile *p;
- char *fn;
- int r;
+static int mapping_verify(pa_alsa_mapping *m) {
static const struct description_map well_known_descriptions[] = {
{ "analog-mono", N_("Analog Mono") },
@@ -1991,18 +2338,220 @@ pa_alsa_profile_set* pa_alsa_profile_set_new(const char *fname, pa_alsa_directio
{ "hdmi-stereo", N_("Digital Stereo (HDMI)") }
};
- static const pa_config_item items[] = {
- { "device-strings", profile_set_parse_device_strings, NULL, NULL },
- { "description", profile_set_parse_description, NULL, NULL },
- { "channel-map", profile_set_parse_channel_map, NULL, NULL },
- { "paths-input", profile_set_parse_paths, NULL, NULL },
- { "paths-output", profile_set_parse_paths, NULL, NULL },
- { "priority", profile_set_parse_priority, NULL, NULL },
+ pa_assert(m);
+
+ if (!pa_channel_map_valid(&m->channel_map)) {
+ pa_log("Mapping %s is missing channel map.", m->name);
+ return -1;
+ }
+
+ if (!m->device_strings) {
+ pa_log("Mapping %s is missing device strings.", m->name);
+ return -1;
+ }
+
+ if ((m->input_path_names && m->input_element) ||
+ (m->output_path_names && m->output_element)) {
+ pa_log("Mapping %s must have either mixer path or mixer elment, not both.", m->name);
+ return -1;
+ }
+
+ if (!m->description)
+ m->description = pa_xstrdup(lookup_description(m->name,
+ well_known_descriptions,
+ PA_ELEMENTSOF(well_known_descriptions)));
+
+ if (!m->description)
+ m->description = pa_xstrdup(m->name);
+
+ return 0;
+}
+
+static void profile_set_add_auto_pair(
+ pa_alsa_profile_set *ps,
+ pa_alsa_mapping *m,
+ pa_alsa_mapping *n) {
+
+ char *name;
+ pa_alsa_profile *p;
+
+ pa_assert(ps);
+ pa_assert(m || n);
+
+ if (m && n)
+ name = pa_sprintf_malloc("output:%s+input:%s", m->name, n->name);
+ else if (m)
+ name = pa_xstrdup(m->name);
+ else
+ name = pa_xstrdup(n->name);
+
+ if ((p = pa_hashmap_get(ps->profiles, name))) {
+ pa_xfree(name);
+ return;
+ }
+
+ p = pa_xnew0(pa_alsa_profile, 1);
+ p->profile_set = ps;
+ p->name = name;
+
+ if (m) {
+ p->output_mappings = pa_idxset_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
+ pa_idxset_put(p->output_mappings, m, NULL);
+ p->priority += m->priority * 100;
+ }
+
+ if (n) {
+ p->input_mappings = pa_idxset_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func);
+ pa_idxset_put(p->input_mappings, n, NULL);
+ p->priority += m->priority;
+ }
+
+ pa_hashmap_put(ps->profiles, p->name, p);
+}
+
+static void profile_set_add_auto(pa_alsa_profile_set *ps) {
+ pa_alsa_mapping *m, *n;
+ void *m_state, *n_state;
+
+ pa_assert(ps);
+
+ PA_HASHMAP_FOREACH(m, ps->mappings, m_state) {
+ PA_HASHMAP_FOREACH(n, ps->mappings, n_state)
+ profile_set_add_auto_pair(ps, m, n);
+
+ profile_set_add_auto_pair(ps, m, NULL);
+ }
+
+ PA_HASHMAP_FOREACH(n, ps->mappings, n_state)
+ profile_set_add_auto_pair(ps, NULL, n);
+}
+
+static int profile_verify(pa_alsa_profile *p) {
+
+ static const struct description_map well_known_descriptions[] = {
+ { "output:analog-mono+input:analog-mono", N_("Analog Mono Duplex") },
+ { "output:analog-stereo+input:analog-stereo", N_("Analog Stereo Duplex") },
+ };
+
+ pa_assert(p);
+
+ /* Replace the output mapping names by the actual mappings */
+ if (p->output_mapping_names) {
+ char **name;
+
+ pa_assert(!p->output_mappings);
+ p->output_mappings = pa_idxset_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func);
+
+ for (name = p->output_mapping_names; *name; name++) {
+ pa_alsa_mapping *m;
+
+ if (!(m = pa_hashmap_get(p->profile_set->mappings, *name))) {
+ pa_log("Profile '%s' refers to unexistant mapping '%s'.", p->name, *name);
+ return -1;
+ }
+
+ pa_idxset_put(p->output_mappings, m, NULL);
+ }
+
+ pa_xstrfreev(p->output_mapping_names);
+ p->output_mapping_names = NULL;
+ }
+
+ /* Replace the input mapping names by the actual mappings */
+ if (p->input_mapping_names) {
+ char **name;
+
+ pa_assert(!p->input_mappings);
+ p->input_mappings = pa_idxset_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func);
+
+ for (name = p->input_mapping_names; *name; name++) {
+ pa_alsa_mapping *m;
+
+ if (!(m = pa_hashmap_get(p->profile_set->mappings, *name))) {
+ pa_log("Profile '%s' refers to unexistant mapping '%s'.", p->name, *name);
+ return -1;
+ }
+
+ pa_idxset_put(p->input_mappings, m, NULL);
+ }
+
+ pa_xstrfreev(p->input_mapping_names);
+ p->input_mapping_names = NULL;
+ }
+
+ if (!p->input_mappings && !p->output_mappings) {
+ pa_log("Profile '%s' lacks mappings.", p->name);
+ return -1;
+ }
+
+ if (!p->description)
+ p->description = pa_xstrdup(lookup_description(p->name,
+ well_known_descriptions,
+ PA_ELEMENTSOF(well_known_descriptions)));
+
+ if (!p->description) {
+ pa_strbuf *sb;
+ uint32_t idx;
+ pa_alsa_mapping *m;
+
+ sb = pa_strbuf_new();
+
+ PA_IDXSET_FOREACH(m, p->output_mappings, idx) {
+ if (!pa_strbuf_isempty(sb))
+ pa_strbuf_puts(sb, " + ");
+
+ pa_strbuf_printf(sb, "%s Output", m->description);
+ }
+
+ PA_IDXSET_FOREACH(m, p->output_mappings, idx) {
+ if (!pa_strbuf_isempty(sb))
+ pa_strbuf_puts(sb, " + ");
+
+ pa_strbuf_printf(sb, "%s Input", m->description);
+ }
+
+ p->description = pa_strbuf_tostring_free(sb);
+ }
+
+ return 0;
+}
+
+pa_alsa_profile_set* pa_alsa_profile_set_new(const char *fname) {
+ pa_alsa_profile_set *ps;
+ pa_alsa_profile *p;
+ pa_alsa_mapping *m;
+ char *fn;
+ int r;
+ void *state;
+
+ static pa_config_item items[] = {
+ /* [General] */
+ { "auto-profiles", pa_config_parse_bool, NULL, "General" },
+
+ /* [Mapping ...] */
+ { "device-strings", mapping_parse_device_strings, NULL, NULL },
+ { "channel-map", mapping_parse_channel_map, NULL, NULL },
+ { "paths-input", mapping_parse_paths, NULL, NULL },
+ { "paths-output", mapping_parse_paths, NULL, NULL },
+ { "element-input", mapping_parse_element, NULL, NULL },
+ { "element-output", mapping_parse_element, NULL, NULL },
+
+ /* Shared by [Mapping ...] and [Profile ...] */
+ { "description", mapping_parse_description, NULL, NULL },
+ { "priority", mapping_parse_priority, NULL, NULL },
+
+ /* [Profile ...] */
+ { "input-mappings", profile_parse_mappings, NULL, NULL },
+ { "output-mappings", profile_parse_mappings, NULL, NULL },
+ { "skip-probe", profile_parse_skip_probe, NULL, NULL },
{ NULL, NULL, NULL, NULL }
};
ps = pa_xnew0(pa_alsa_profile_set, 1);
- ps->direction = direction;
+ ps->mappings = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
+ ps->profiles = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
+
+ items[0].data = &ps->auto_profiles;
if (!fname)
fname = "default.conf";
@@ -2014,16 +2563,16 @@ pa_alsa_profile_set* pa_alsa_profile_set_new(const char *fname, pa_alsa_directio
if (r < 0)
goto fail;
- PA_LLIST_FOREACH(p, ps->profiles) {
- if (profile_verify(p) < 0)
+ PA_HASHMAP_FOREACH(m, ps->mappings, state)
+ if (mapping_verify(m) < 0)
goto fail;
- if (!p->description)
- p->description = pa_xstrdup(lookup_description(p->name, well_known_descriptions, PA_ELEMENTSOF(well_known_descriptions)));
+ if (ps->auto_profiles)
+ profile_set_add_auto(ps);
- if (!p->description)
- p->description = pa_xstrdup(p->name);
- }
+ PA_HASHMAP_FOREACH(p, ps->profiles, state)
+ if (profile_verify(p) < 0)
+ goto fail;
return ps;
@@ -2031,3 +2580,201 @@ fail:
pa_alsa_profile_set_free(ps);
return NULL;
}
+
+static snd_pcm_t *open_by_device_string_strv(
+ char **prefix,
+ const char *dev_id,
+ char **dev,
+ pa_sample_spec *ss,
+ pa_channel_map* map,
+ int mode,
+ uint32_t *nfrags,
+ snd_pcm_uframes_t *period_size,
+ snd_pcm_uframes_t tsched_size,
+ pa_bool_t *use_mmap,
+ pa_bool_t *use_tsched,
+ pa_bool_t require_exact_channel_number) {
+
+ snd_pcm_t *pcm_handle;
+ char **i;
+
+ for (i = prefix; *i; i++) {
+ char *d;
+
+ d = pa_sprintf_malloc("%s:%s", *prefix, dev_id);
+
+ pcm_handle = pa_alsa_open_by_device_string(
+ d,
+ dev,
+ ss,
+ map,
+ mode,
+ nfrags,
+ period_size,
+ tsched_size,
+ use_mmap,
+ use_tsched,
+ require_exact_channel_number);
+ pa_xfree(d);
+
+ if (pcm_handle)
+ return pcm_handle;
+ }
+
+ return NULL;
+}
+
+void pa_alsa_profile_set_probe(pa_alsa_profile_set *ps, const char *dev_id, const pa_sample_spec *ss) {
+ void *state;
+ pa_alsa_profile *p, *last = NULL;
+ pa_alsa_mapping *m;
+
+ pa_assert(ps);
+ pa_assert(dev_id);
+ pa_assert(ss);
+
+ if (ps->probed)
+ return;
+
+ PA_HASHMAP_FOREACH(p, ps->profiles, state) {
+ pa_sample_spec try_ss;
+ pa_channel_map try_map;
+ uint32_t idx;
+
+ /* Is this already marked that it is supported? (i.e. from the config file) */
+ if (p->supported)
+ continue;
+
+ /* Close PCMs from the last iteration we don't need anymore */
+ if (last && last->output_mappings)
+ PA_IDXSET_FOREACH(m, last->output_mappings, idx) {
+
+ if (!m->output_pcm)
+ break;
+
+ if (last->supported)
+ m->supported++;
+
+ if (!p->output_mappings || !pa_idxset_get_by_data(p->output_mappings, m, NULL)) {
+ snd_pcm_close(m->output_pcm);
+ m->output_pcm = NULL;
+ }
+ }
+
+ if (last && last->input_mappings)
+ PA_IDXSET_FOREACH(m, last->input_mappings, idx) {
+
+ if (!m->input_pcm)
+ break;
+
+ if (last->supported)
+ m->supported++;
+
+ if (!p->input_mappings || !pa_idxset_get_by_data(p->input_mappings, m, NULL)) {
+ snd_pcm_close(m->input_pcm);
+ m->input_pcm = NULL;
+ }
+ }
+
+ p->supported = TRUE;
+
+ /* Check if we can open all new ones */
+ if (p->output_mappings)
+ PA_IDXSET_FOREACH(m, p->output_mappings, idx) {
+
+ if (m->output_pcm)
+ continue;
+
+ pa_log_debug("Checking for playback on %s (%s)", m->description, m->name);
+ try_ss = *ss;
+ try_map = m->channel_map;
+
+ if (!(m ->output_pcm = open_by_device_string_strv(
+ m->device_strings,
+ dev_id,
+ NULL,
+ &try_ss, &try_map,
+ SND_PCM_STREAM_PLAYBACK,
+ NULL, NULL, 0, NULL, NULL,
+ TRUE))) {
+ p->supported = FALSE;
+ break;
+ }
+ }
+
+ if (p->input_mappings && p->supported)
+ PA_IDXSET_FOREACH(m, p->input_mappings, idx) {
+
+ if (m->input_pcm)
+ continue;
+
+ pa_log_debug("Checking for recording on %s (%s)", m->description, m->name);
+ try_ss = *ss;
+ try_map = m->channel_map;
+
+ if (!(m ->input_pcm = open_by_device_string_strv(
+ m->device_strings,
+ dev_id,
+ NULL,
+ &try_ss, &try_map,
+ SND_PCM_STREAM_CAPTURE,
+ NULL, NULL, 0, NULL, NULL,
+ TRUE))) {
+ p->supported = FALSE;
+ break;
+ }
+ }
+
+ last = p;
+ }
+
+ /* Clean up */
+ if (last) {
+ uint32_t idx;
+
+ if (last->output_mappings)
+ PA_IDXSET_FOREACH(m, last->output_mappings, idx)
+ if (m->output_pcm) {
+
+ if (last->supported)
+ m->supported++;
+
+ snd_pcm_close(m->output_pcm);
+ m->output_pcm = NULL;
+ }
+
+ if (last->input_mappings)
+ PA_IDXSET_FOREACH(m, last->input_mappings, idx)
+ if (m->input_pcm) {
+
+ if (last->supported)
+ m->supported++;
+
+ snd_pcm_close(m->input_pcm);
+ m->input_pcm = NULL;
+ }
+ }
+
+ ps->probed = TRUE;
+}
+
+void pa_alsa_profile_set_drop_unsupported(pa_alsa_profile_set *ps) {
+ pa_alsa_profile *p;
+ pa_alsa_mapping *m;
+ void *state;
+
+ pa_assert(ps);
+ pa_assert(ps->probed);
+
+ PA_HASHMAP_FOREACH(p, ps->profiles, state)
+ if (!p->supported) {
+ pa_hashmap_remove(ps->profiles, p->name);
+ profile_free(p);
+ }
+
+ PA_HASHMAP_FOREACH(m, ps->mappings, state)
+ if (m->supported <= 0) {
+ pa_hashmap_remove(ps->mappings, m);
+ mapping_free(m);
+ }
+}
diff --git a/src/modules/alsa/alsa-mixer.h b/src/modules/alsa/alsa-mixer.h
index 240afd6..c4cbc36 100644
--- a/src/modules/alsa/alsa-mixer.h
+++ b/src/modules/alsa/alsa-mixer.h
@@ -38,9 +38,12 @@
#include <pulsecore/log.h>
typedef struct pa_alsa_fdlist pa_alsa_fdlist;
+typedef struct pa_alsa_setting pa_alsa_setting;
typedef struct pa_alsa_option pa_alsa_option;
typedef struct pa_alsa_element pa_alsa_element;
typedef struct pa_alsa_path pa_alsa_path;
+typedef struct pa_alsa_path_set pa_alsa_path_set;
+typedef struct pa_alsa_mapping pa_alsa_mapping;
typedef struct pa_alsa_profile pa_alsa_profile;
typedef struct pa_alsa_profile_set pa_alsa_profile_set;
@@ -48,16 +51,17 @@ typedef struct pa_alsa_profile_set pa_alsa_profile_set;
typedef enum pa_alsa_switch_use {
PA_ALSA_SWITCH_IGNORE,
- PA_ALSA_SWITCH_MUTE,
- PA_ALSA_SWITCH_OFF,
- PA_ALSA_SWITCH_ON,
- PA_ALSA_SWITCH_SELECT
+ PA_ALSA_SWITCH_MUTE, /* make this switch follow mute status */
+ PA_ALSA_SWITCH_OFF, /* set this switch to 'off' unconditionally */
+ PA_ALSA_SWITCH_ON, /* set this switch to 'on' unconditionally */
+ PA_ALSA_SWITCH_SELECT /* allow the user to select switch status through a setting */
} pa_alsa_switch_use_t;
typedef enum pa_alsa_volume_use {
PA_ALSA_VOLUME_IGNORE,
- PA_ALSA_VOLUME_MERGE,
- PA_ALSA_VOLUME_OFF
+ PA_ALSA_VOLUME_MERGE, /* merge this volume slider into the global volume slider */
+ PA_ALSA_VOLUME_OFF, /* set this volume to minimal unconditionally */
+ PA_ALSA_VOLUME_ZERO /* set this volume to 0dB unconditionally */
} pa_alsa_volume_use_t;
typedef enum pa_alsa_enumeration_use {
@@ -78,20 +82,38 @@ typedef enum pa_alsa_direction {
PA_ALSA_CAPTURE
} pa_alsa_direction_t;
+/* A setting combines a couple of options into a single entity that
+ * may be selected. Only one setting can be active at the same
+ * time. */
+struct pa_alsa_setting {
+ pa_alsa_path *path;
+ PA_LLIST_FIELDS(pa_alsa_setting);
+
+ pa_idxset *options;
+
+ char *name;
+ char *description;
+ unsigned priority;
+};
+
+/* An option belongs to an element and refers to one enumeration item
+ * of the element is an enumeration item, or a switch status if the
+ * element is a switch item. */
struct pa_alsa_option {
pa_alsa_element *element;
PA_LLIST_FIELDS(pa_alsa_option);
char *alsa_name;
- unsigned alsa_idx;
+ int alsa_idx;
char *name;
char *description;
unsigned priority;
-
- pa_bool_t expose:1;
};
+/* And element wraps one specific ALSA element. A series of elements *
+make up a path (see below). If the element is an enumeration or switch
+* element it may includes a list of options. */
struct pa_alsa_element {
pa_alsa_path *path;
PA_LLIST_FIELDS(pa_alsa_element);
@@ -106,7 +128,6 @@ struct pa_alsa_element {
pa_alsa_required_t required;
pa_alsa_required_t required_absent;
- pa_bool_t expose_options:1;
pa_bool_t override_map:1;
pa_bool_t direction_try_other:1;
@@ -120,14 +141,21 @@ struct pa_alsa_element {
PA_LLIST_HEAD(pa_alsa_option, options);
};
+/* A path wraps a series of elements into a single entity which can be
+ * used to control it as if it had a single volume slider, a single
+ * mute switch and a single list of selectable options. */
struct pa_alsa_path {
- pa_alsa_profile *profile;
+ pa_alsa_path_set *path_set;
PA_LLIST_FIELDS(pa_alsa_path);
+ pa_alsa_direction_t direction;
+
char *name;
char *description;
unsigned priority;
+ pa_bool_t probed:1;
+ pa_bool_t supported:1;
pa_bool_t has_mute:1;
pa_bool_t has_volume:1;
pa_bool_t has_dB:1;
@@ -141,54 +169,92 @@ struct pa_alsa_path {
pa_alsa_option *option_parse_cache;
PA_LLIST_HEAD(pa_alsa_element, elements);
+ PA_LLIST_HEAD(pa_alsa_setting, settings);
};
-struct pa_alsa_profile {
+/* A path set is simply a set of paths that are applicable to a
+ * device */
+struct pa_alsa_path_set {
+ PA_LLIST_HEAD(pa_alsa_path, paths);
+ pa_alsa_direction_t direction;
+};
+
+int pa_alsa_path_get_volume(pa_alsa_path *p, snd_mixer_t *m, const pa_channel_map *cm, pa_cvolume *v);
+int pa_alsa_path_get_mute(pa_alsa_path *path, snd_mixer_t *m, pa_bool_t *muted);
+
+int pa_alsa_path_set_volume(pa_alsa_path *path, snd_mixer_t *m, const pa_channel_map *cm, pa_cvolume *v);
+int pa_alsa_path_set_mute(pa_alsa_path *path, snd_mixer_t *m, pa_bool_t muted);
+
+int pa_alsa_path_select(pa_alsa_path *p, snd_mixer_t *m);
+
+int pa_alsa_setting_select(pa_alsa_setting *s, snd_mixer_t *m);
+
+pa_alsa_path *pa_alsa_path_new(const char *fname, pa_alsa_direction_t direction);
+pa_alsa_path *pa_alsa_path_synthesize(const char *element, pa_alsa_direction_t direction);
+int pa_alsa_path_probe(pa_alsa_path *p, snd_mixer_t *m);
+pa_bool_t pa_alsa_path_drop_unsupported(pa_alsa_path *p);
+void pa_alsa_path_free(pa_alsa_path *p);
+
+pa_alsa_path_set *pa_alsa_path_set_new(pa_alsa_mapping *m, pa_alsa_direction_t direction);
+void pa_alsa_path_set_probe(pa_alsa_path_set *s, snd_mixer_t *m);
+void pa_alsa_path_set_drop_unsupported(pa_alsa_path_set *s);
+void pa_alsa_path_set_free(pa_alsa_path_set *s);
+
+struct pa_alsa_mapping {
pa_alsa_profile_set *profile_set;
- PA_LLIST_FIELDS(pa_alsa_profile);
char *name;
char *description;
unsigned priority;
+
pa_channel_map channel_map;
+
char **device_strings;
- char **path_names;
- pa_bool_t probed:1;
+ char **input_path_names;
+ char **output_path_names;
+ char **input_element; /* list of fallbacks */
+ char **output_element;
- PA_LLIST_HEAD(pa_alsa_path, paths);
-};
+ unsigned supported;
-struct pa_alsa_profile_set {
- pa_alsa_direction_t direction;
+ /* Temporarily used during probing */
+ snd_pcm_t *input_pcm;
+ snd_pcm_t *output_pcm;
+};
- /* This is used during parsing only, as a shortcut so that we
- * don't have to iterate the list all the time */
- pa_alsa_profile *parse_cache;
+struct pa_alsa_profile {
+ pa_alsa_profile_set *profile_set;
- PA_LLIST_HEAD(pa_alsa_profile, profiles);
-};
+ char *name;
+ char *description;
+ unsigned priority;
-int pa_alsa_path_get_volume(snd_mixer_t *m, pa_alsa_path *p, const pa_channel_map *cm, pa_cvolume *v);
-int pa_alsa_path_get_mute(snd_mixer_t *m, pa_alsa_path *path, pa_bool_t *muted);
+ pa_bool_t supported:1;
-int pa_alsa_path_set_volume(snd_mixer_t *m, pa_alsa_path *path, const pa_channel_map *cm, pa_cvolume *v);
-int pa_alsa_path_set_mute(snd_mixer_t *m, pa_alsa_path *path, pa_bool_t muted);
+ char **input_mapping_names;
+ char **output_mapping_names;
-int pa_alsa_path_select(snd_mixer_t *m, pa_alsa_path *p);
+ pa_idxset *input_mappings;
+ pa_idxset *output_mappings;
+};
-pa_alsa_element* pa_alsa_path_iterate_options(pa_alsa_path *path, pa_alsa_element *last);
-pa_alsa_option* pa_alsa_element_iterate_options(pa_alsa_element *e, pa_alsa_option *last);
+struct pa_alsa_profile_set {
+ pa_hashmap *mappings;
+ pa_hashmap *profiles;
-int pa_alsa_profile_probe_paths(snd_mixer_t *m, pa_alsa_profile *p);
+ pa_bool_t auto_profiles;
+ pa_bool_t probed:1;
+};
-pa_alsa_profile_set* pa_alsa_profile_set_new(const char *fname, pa_alsa_direction_t direction);
+pa_alsa_profile_set* pa_alsa_profile_set_new(const char *fname);
+void pa_alsa_profile_set_probe(pa_alsa_profile_set *ps, const char *dev_id, const pa_sample_spec *ss);
+void pa_alsa_profile_set_drop_unsupported(pa_alsa_profile_set *ps);
void pa_alsa_profile_set_free(pa_alsa_profile_set *s);
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, char **ctl_device, snd_mixer_t **_m, snd_mixer_elem_t **_e, const char *control_name, const pa_alsa_profile_info*profile);
-
int pa_alsa_calc_mixer_map(snd_mixer_elem_t *elem, const pa_channel_map *channel_map, snd_mixer_selem_channel_id_t mixer_map[], pa_bool_t playback);
pa_alsa_fdlist *pa_alsa_fdlist_new(void);
diff --git a/src/modules/alsa/mixer/paths/analog-input-mic.conf b/src/modules/alsa/mixer/paths/analog-input-mic.conf
index ff38342..f81470f 100644
--- a/src/modules/alsa/mixer/paths/analog-input-mic.conf
+++ b/src/modules/alsa/mixer/paths/analog-input-mic.conf
@@ -4,14 +4,14 @@
[Path]
priority = 100
-[Capture]
+[Element Capture]
required-absent = volume
switch = mute
volume = ignore
override-map.1 = all
override-map.2 = all-left,all-right
-[Mic]
+[Element Mic]
switch = mute
volume = merge
override-map.1 = all
diff --git a/src/modules/alsa/mixer/paths/analog-input.conf b/src/modules/alsa/mixer/paths/analog-input.conf
index a3bc35d..d09a14e 100644
--- a/src/modules/alsa/mixer/paths/analog-input.conf
+++ b/src/modules/alsa/mixer/paths/analog-input.conf
@@ -4,20 +4,20 @@
[Path]
priority = 100
-[Capture]
+[Element Capture]
required = volume
switch = mute
volume = merge
override-map.1 = all
override-map.2 = all-left,all-right
-[Mic]
+[Element Mic]
switch = select
volume = ignore
override-map.1 = all
override-map.2 = all-left,all-right
-[Mic:on]
+[Option Mic:on]
name = input-microphone
priority = 20
diff --git a/src/modules/alsa/mixer/paths/analog-input.conf.common b/src/modules/alsa/mixer/paths/analog-input.conf.common
index d2842e5..a094f6d 100644
--- a/src/modules/alsa/mixer/paths/analog-input.conf.common
+++ b/src/modules/alsa/mixer/paths/analog-input.conf.common
@@ -122,181 +122,181 @@ name = input-radio
[Option Capture Source:Mic/Line]
name = input
-[Capture Source:Line/Mic]
+[Option Capture Source:Line/Mic]
name = input
-[Capture Source:Mic]
+[Option Capture Source:Mic]
name = input-microphone
-[Capture Source:Microphone]
+[Option Capture Source:Microphone]
name = input-microphone
-[Capture Source:Int Mic]
+[Option Capture Source:Int Mic]
name = input-microphone-internal
-[Capture Source:Int DMic]
+[Option Capture Source:Int DMic]
name = input-microphone-internal
-[Capture Source:Internal Mic]
+[Option Capture Source:Internal Mic]
name = input-microphone-internal
-[Capture Source:iMic]
+[Option Capture Source:iMic]
name = input-microphone-internal
-[Capture Source:i-Mic]
+[Option Capture Source:i-Mic]
name = input-microphone-internal
-[Capture Source:Internal Microphone]
+[Option Capture Source:Internal Microphone]
name = input-microphone-internal
-[Capture Source:Front Mic]
+[Option Capture Source:Front Mic]
name = input-microphone
-[Capture Source:Front Microphone]
+[Option Capture Source:Front Microphone]
name = input-microphone
-[Capture Source:Rear Mic]
+[Option Capture Source:Rear Mic]
name = input-microphone
-[Capture Source:Mic1]
+[Option Capture Source:Mic1]
name = input-microphone
-[Capture Source:Mic2]
+[Option Capture Source:Mic2]
name = input-microphone
-[Capture Source:D-Mic]
+[Option Capture Source:D-Mic]
name = input-microphone
-[Capture Source:IntMic]
+[Option Capture Source:IntMic]
name = input-microphone-internal
-[Capture Source:ExtMic]
+[Option Capture Source:ExtMic]
name = input-microphone-external
-[Capture Source:Ext Mic]
+[Option Capture Source:Ext Mic]
name = input-microphone-external
-[Capture Source:E-Mic]
+[Option Capture Source:E-Mic]
name = input-microphone-external
-[Capture Source:e-Mic]
+[Option Capture Source:e-Mic]
name = input-microphone-external
-[Capture Source:LineIn]
+[Option Capture Source:LineIn]
name = input-linein
-[Capture Source:Analog]
+[Option Capture Source:Analog]
name = input
-[Capture Source:Line]
+[Option Capture Source:Line]
name = input-linein
-[Capture Source:Line-In]
+[Option Capture Source:Line-In]
name = input-linein
-[Capture Source:Line In]
+[Option Capture Source:Line In]
name = input-linein
-[Capture Source:Video]
+[Option Capture Source:Video]
name = input-video
-[Capture Source:Aux]
+[Option Capture Source:Aux]
name = input
-[Capture Source:Aux0]
+[Option Capture Source:Aux0]
name = input
-[Capture Source:Aux1]
+[Option Capture Source:Aux1]
name = input
-[Capture Source:Aux2]
+[Option Capture Source:Aux2]
name = input
-[Capture Source:Aux3]
+[Option Capture Source:Aux3]
name = input
-[Capture Source:AUX IN]
+[Option Capture Source:AUX IN]
name = input
-[Capture Source:Aux In]
+[Option Capture Source:Aux In]
name = input
-[Capture Source:AOUT]
+[Option Capture Source:AOUT]
name = input
-[Capture Source:AUX]
+[Option Capture Source:AUX]
name = input
-[Capture Source:Cam Mic]
+[Option Capture Source:Cam Mic]
name = input-microphone
-[Capture Source:Digital Mic]
+[Option Capture Source:Digital Mic]
name = input-microphone
-[Capture Source:Digital Mic 1]
+[Option Capture Source:Digital Mic 1]
name = input-microphone
-[Capture Source:Digital Mic 2]
+[Option Capture Source:Digital Mic 2]
name = input-microphone
-[Capture Source:Analog Inputs]
+[Option Capture Source:Analog Inputs]
name = input
-[Capture Source:Unknown1]
+[Option Capture Source:Unknown1]
name = input
-[Capture Source:Unknown2]
+[Option Capture Source:Unknown2]
name = input
-[Capture Source:Docking-Station]
+[Option Capture Source:Docking-Station]
name = input-docking
-[Capture Source:Dock Mic]
+[Option Capture Source:Dock Mic]
name = input-docking-microphone
;;; Various Boosts
-[Mic Boost (+20dB)]
+[Element Mic Boost (+20dB)]
switch = select
-[Mic Boost (+20dB):on]
+[Option Mic Boost (+20dB):on]
name = capture-boost-on
-[Mic Boost (+20dB):off]
+[Option Mic Boost (+20dB):off]
name = capture-boost-off
-[Capture Boost]
+[Option Capture Boost]
switch = select
-[Capture Boost:on]
+[Option Capture Boost:on]
name = capture-boost-on
-[Capture Boost:off]
+[Option Capture Boost:off]
name = capture-boost-off
-[Mic Boost]
+[Element Mic Boost]
switch = select
-[Mic Boost:on]
+[Option Mic Boost:on]
name = capture-boost-on
-[Mic Boost:off]
+[Option Mic Boost:off]
name = capture-boost-off
-[Front Mic Boost]
+[Element Front Mic Boost]
switch = select
-[Front Mic Boost:on]
+[Option Front Mic Boost:on]
name = capture-boost-on
-[Front Mic Boost:off]
+[Option Front Mic Boost:off]
name = capture-boost-off
-[Auto Gain Control]
+[Element Auto Gain Control]
switch = select
-[Auto Gain Control:on]
+[Option Auto Gain Control:on]
name = capture-agc-on
-[Auto Gain Control:off]
+[Option Auto Gain Control:off]
name = capture-agc-on
diff --git a/src/modules/alsa/mixer/paths/analog-output-headphones.conf b/src/modules/alsa/mixer/paths/analog-output-headphones.conf
index e520273..6559d16 100644
--- a/src/modules/alsa/mixer/paths/analog-output-headphones.conf
+++ b/src/modules/alsa/mixer/paths/analog-output-headphones.conf
@@ -3,50 +3,50 @@
[Path]
priority = 90
-[Hardware Master]
+[Element Hardware Master]
switch = mute
volume = merge
override-map.1 = all
override-map.2 = all-left,all-right
-[Master]
+[Element Master]
switch = mute
volume = merge
override-map.1 = all
override-map.2 = all-left,all-right
-[Master Mono]
+[Element Master Mono]
switch = off
volume = off
-[Headphone]
+[Element Headphone]
required = any
switch = mute
volume = merge
override-map.1 = all
override-map.2 = all-left,all-right
-[Front]
+[Element Front]
switch = off
volume = off
-[Rear]
+[Element Rear]
switch = off
volume = off
-[Sourround]
+[Element Sourround]
switch = off
volume = off
-[Side]
+[Element Side]
switch = off
volume = off
-[Center]
+[Element Center]
switch = off
volume = off
-[LFE]
+[Element LFE]
switch = off
volume = off
diff --git a/src/modules/alsa/mixer/paths/analog-output-lfe-on-mono.conf b/src/modules/alsa/mixer/paths/analog-output-lfe-on-mono.conf
index 65756e5..afc19e3 100644
--- a/src/modules/alsa/mixer/paths/analog-output-lfe-on-mono.conf
+++ b/src/modules/alsa/mixer/paths/analog-output-lfe-on-mono.conf
@@ -4,50 +4,50 @@
[Path]
priority = 40
-[Hardware Master]
+[Element Hardware Master]
switch = mute
volume = merge
override-map.1 = all
override-map.2 = all-left,all-right
-[Master]
+[Element Master]
switch = mute
volume = merge
override-map.1 = all-no-lfe
override-map.2 = all-left-no-lfe,all-right-no-lfe
-[Master Mono]
+[Element Master Mono]
required = any
switch = mute
volume = merge
override-map.1 = lfe
override-map.2 = lfe,lfe
-[Headphone]
+[Element Headphone]
switch = off
volume = off
-[Front]
+[Element Front]
switch = off
volume = off
-[Rear]
+[Element Rear]
switch = off
volume = off
-[Sourround]
+[Element Sourround]
switch = off
volume = off
-[Side]
+[Element Side]
switch = off
volume = off
-[Center]
+[Element Center]
switch = off
volume = off
-[LFE]
+[Element LFE]
switch = off
volume = off
diff --git a/src/modules/alsa/mixer/paths/analog-output-mono.conf b/src/modules/alsa/mixer/paths/analog-output-mono.conf
index 8fe144b..88af602 100644
--- a/src/modules/alsa/mixer/paths/analog-output-mono.conf
+++ b/src/modules/alsa/mixer/paths/analog-output-mono.conf
@@ -3,48 +3,48 @@
[Path]
priority = 50
-[Hardware Master]
+[Element Hardware Master]
switch = mute
volume = merge
override-map.1 = all
override-map.2 = all-left,all-right
-[Master]
+[Element Master]
switch = off
volume = off
-[Master Mono]
+[Element Master Mono]
required = any
switch = mute
volume = merge
override-map.1 = all
override-map.2 = all-left,all-right
-[Headphone]
+[Element Headphone]
switch = off
volume = off
-[Front]
+[Element Front]
switch = off
volume = off
-[Rear]
+[Element Rear]
switch = off
volume = off
-[Sourround]
+[Element Sourround]
switch = off
volume = off
-[Side]
+[Element Side]
switch = off
volume = off
-[Center]
+[Element Center]
switch = off
volume = off
-[LFE]
+[Element LFE]
switch = off
volume = off
diff --git a/src/modules/alsa/mixer/paths/analog-output.conf b/src/modules/alsa/mixer/paths/analog-output.conf
index 2017a93..d7fa91d 100644
--- a/src/modules/alsa/mixer/paths/analog-output.conf
+++ b/src/modules/alsa/mixer/paths/analog-output.conf
@@ -3,57 +3,57 @@
[Path]
priority = 100
-[Hardware Master]
+[Element Hardware Master]
switch = mute
volume = merge
override-map.1 = all
override-map.2 = all-left,all-right
-[Master]
+[Element Master]
switch = mute
volume = merge
override-map.1 = all
override-map.2 = all-left,all-right
-[Master Mono]
+[Element Master Mono]
switch = off
volume = off
-[Headphone]
+[Element Headphone]
switch = off
volume = off
-[Front]
+[Element Front]
switch = mute
volume = merge
override-map.1 = all-front
override-map.2 = front-left,front-right
-[Rear]
+[Element Rear]
switch = mute
volume = merge
override-map.1 = all-rear
override-map.2 = rear-left,rear-right
-[Sourround]
+[Element Sourround]
switch = mute
volume = merge
override-map.1 = all-rear
override-map.2 = rear-left,rear-right
-[Side]
+[Element Side]
switch = mute
volume = merge
override-map.1 = all-side
override-map.2 = side-left,side-right
-[Center]
+[Element Center]
switch = mute
volume = merge
override-map.1 = all-center
override-map.2 = all-center,all-center
-[LFE]
+[Element LFE]
switch = mute
volume = merge
override-map.1 = lfe
diff --git a/src/modules/alsa/mixer/paths/analog-output.conf.common b/src/modules/alsa/mixer/paths/analog-output.conf.common
index d05bfb5..c6fb36a 100644
--- a/src/modules/alsa/mixer/paths/analog-output.conf.common
+++ b/src/modules/alsa/mixer/paths/analog-output.conf.common
@@ -1,19 +1,19 @@
# Common part of all paths
-# [Path]
+# [General]
# priority = ...
# description = ...
#
-# [Element:Option]
+# [Option ...:...]
# name = ...
# priority = ...
#
-# [Element]
+# [Element ...]
# required = ignore | switch | volume | enumeration | any
# required-absent = ignore | switch | volume
#
# switch = ignore | mute | off | on | select
-# volume = ignore | merge | off
+# volume = ignore | merge | off | zero
# enumeration = ignore | select
#
# direction = playback | capture
@@ -22,19 +22,19 @@
# override-map.1 = ...
# override-map.2 = ...
-[PCM]
+[Element PCM]
switch = mute
volume = merge
override-map.1 = all
override-map.2 = all-left,all-right
-[External Amplifier]
+[Element External Amplifier]
switch = select
-[External Amplifier:on]
+[Option External Amplifier:on]
name = amplifier-on
priority = 0
-[External Amplifier:off]
+[Option External Amplifier:off]
name = amplifier-off
priority = 10
diff --git a/src/modules/alsa/mixer/profiles/default.conf b/src/modules/alsa/mixer/profiles/default.conf
index c25c4d7..dc378bb 100644
--- a/src/modules/alsa/mixer/profiles/default.conf
+++ b/src/modules/alsa/mixer/profiles/default.conf
@@ -1,17 +1,24 @@
# Profile definitions for PulseAudio's ALSA backend
-
+#
# [Mapping id]
# device-strings = ...
# channel-map = ...
# description = ...
# paths-input = ...
# paths-output = ...
+# element-input = ...
+# element-output = ...
# priority = ...
#
# [Profile id]
# input-mappings = ...
# output-mappings = ...
# description = ...
+# priority = ...
+# skip-probe = yes | no
+
+[General]
+auto-profiles = yes
[Mapping analog-mono]
device-strings = hw
diff --git a/src/modules/module-ladspa-sink.c b/src/modules/module-ladspa-sink.c
index 15af74a..21f4a8f 100644
--- a/src/modules/module-ladspa-sink.c
+++ b/src/modules/module-ladspa-sink.c
@@ -27,6 +27,7 @@
#endif
#include <pulse/xmalloc.h>
+#include <pulse/i18n.h>
#include <pulsecore/core-error.h>
#include <pulsecore/namereg.h>
@@ -45,20 +46,20 @@
#include "ladspa.h"
PA_MODULE_AUTHOR("Lennart Poettering");
-PA_MODULE_DESCRIPTION("Virtual LADSPA sink");
+PA_MODULE_DESCRIPTION(_("Virtual LADSPA sink"));
PA_MODULE_VERSION(PACKAGE_VERSION);
PA_MODULE_LOAD_ONCE(FALSE);
PA_MODULE_USAGE(
- "sink_name=<name for the sink> "
- "sink_properties=<properties for the sink> "
- "master=<name of sink to remap> "
- "format=<sample format> "
- "rate=<sample rate> "
- "channels=<number of channels> "
- "channel_map=<channel map> "
- "plugin=<ladspa plugin name> "
- "label=<ladspa plugin label> "
- "control=<comma seperated list of input control values>");
+ _("sink_name=<name for the sink> "
+ "sink_properties=<properties for the sink> "
+ "master=<name of sink to filter> "
+ "format=<sample format> "
+ "rate=<sample rate> "
+ "channels=<number of channels> "
+ "channel_map=<channel map> "
+ "plugin=<ladspa plugin name> "
+ "label=<ladspa plugin label> "
+ "control=<comma seperated list of input control values>"));
#define MEMBLOCKQ_MAXLENGTH (16*1024*1024)
diff --git a/src/pulsecore/conf-parser.c b/src/pulsecore/conf-parser.c
index 2bc9e8c..dfe327b 100644
--- a/src/pulsecore/conf-parser.c
+++ b/src/pulsecore/conf-parser.c
@@ -112,6 +112,9 @@ static int parse_line(const char *filename, unsigned line, char **section, const
if (!*b)
return 0;
+ if (pa_startswith(b, ".include "))
+ return pa_config_parse(strip(b+9), NULL, t, userdata);
+
if (*b == '[') {
size_t k;
commit 09279c269b9bffde70ddbd2ba140fd123b6cd064
Author: Lennart Poettering <lennart at poettering.net>
Date: Fri Jun 12 03:28:02 2009 +0200
svae it for now
diff --git a/src/modules/alsa/alsa-mixer.c b/src/modules/alsa/alsa-mixer.c
index f6cd6b5..a30fdc2 100644
--- a/src/modules/alsa/alsa-mixer.c
+++ b/src/modules/alsa/alsa-mixer.c
@@ -48,6 +48,21 @@
#include "alsa-mixer.h"
#include "alsa-util.h"
+struct description_map {
+ const char *name;
+ const char *description;
+};
+
+static const char *lookup_description(const char *name, const struct description_map dm[], unsigned n) {
+ unsigned i;
+
+ for (i = 0; i < n; i++)
+ if (pa_streq(dm[i].name, name))
+ return dm[i].description;
+
+ return NULL;
+}
+
struct pa_alsa_fdlist {
unsigned num_fds;
struct pollfd *fds;
@@ -248,11 +263,30 @@ int pa_alsa_prepare_mixer(snd_mixer_t *mixer, const char *dev) {
pa_log_info("Successfully attached to mixer '%s'", dev);
- PA_DEBUG_TRAP;
ps = pa_alsa_profile_set_new(NULL);
- if (ps)
+ if (ps) {
+ pa_sample_spec ss;
+ pa_alsa_path_set *paths;
+
+ ss.channels = 2;
+ ss.rate = 44100;
+ ss.format = PA_SAMPLE_S16NE;
+ pa_alsa_profile_set_probe(ps, "Audio", &ss);
+ pa_alsa_profile_set_drop_unsupported(ps);
+ pa_alsa_profile_set_dump(ps);
+
+ if ((paths = pa_alsa_path_set_new(pa_hashmap_first(ps->mappings), PA_ALSA_DIRECTION_OUTPUT))) {
+ pa_alsa_path_set_dump(paths);
+ pa_alsa_path_set_probe(paths, mixer);
+ pa_alsa_path_set_drop_unsupported(paths);
+ pa_alsa_path_set_dump(paths);
+ pa_alsa_path_set_free(paths);
+
+ }
+
pa_alsa_profile_set_free(ps);
+ }
return 0;
}
@@ -700,7 +734,7 @@ static int element_get_volume(pa_alsa_element *e, snd_mixer_t *m, const pa_chann
if (e->has_dB) {
long value = 0;
- if (e->direction == PA_ALSA_PLAYBACK)
+ if (e->direction == PA_ALSA_DIRECTION_OUTPUT)
r = snd_mixer_selem_get_playback_dB(me, c, &value);
else
r = snd_mixer_selem_get_capture_dB(me, c, &value);
@@ -713,7 +747,7 @@ static int element_get_volume(pa_alsa_element *e, snd_mixer_t *m, const pa_chann
} else {
long value = 0;
- if (e->direction == PA_ALSA_PLAYBACK) {
+ if (e->direction == PA_ALSA_DIRECTION_OUTPUT) {
r = snd_mixer_selem_get_playback_volume(me, c, &value);
} else
r = snd_mixer_selem_get_capture_volume(me, c, &value);
@@ -725,11 +759,11 @@ static int element_get_volume(pa_alsa_element *e, snd_mixer_t *m, const pa_chann
}
for (k = 0; k < cm->channels; k++)
- if (e->masks[c][e->n_channels] & PA_CHANNEL_POSITION_MASK(cm->map[k]))
+ if (e->masks[c][e->n_channels-1] & PA_CHANNEL_POSITION_MASK(cm->map[k]))
if (v->values[k] < f)
v->values[k] = f;
- mask |= e->masks[c][e->n_channels];
+ mask |= e->masks[c][e->n_channels-1];
}
for (k = 0; k < cm->channels; k++)
@@ -794,7 +828,7 @@ static int element_get_switch(pa_alsa_element *e, snd_mixer_t *m, pa_bool_t *b)
int r;
int value = 0;
- if (e->direction == PA_ALSA_PLAYBACK)
+ if (e->direction == PA_ALSA_DIRECTION_OUTPUT)
r = snd_mixer_selem_get_playback_switch(me, c, &value);
else
r = snd_mixer_selem_get_capture_switch(me, c, &value);
@@ -866,14 +900,14 @@ static int element_set_volume(pa_alsa_element *e, snd_mixer_t *m, const pa_chann
pa_volume_t f = PA_VOLUME_MUTED;
for (k = 0; k < cm->channels; k++)
- if (e->masks[c][e->n_channels] & PA_CHANNEL_POSITION_MASK(cm->map[k]))
+ if (e->masks[c][e->n_channels-1] & PA_CHANNEL_POSITION_MASK(cm->map[k]))
if (v->values[k] > f)
f = v->values[k];
if (e->has_dB) {
long value = to_alsa_dB(f);
- if (e->direction == PA_ALSA_PLAYBACK) {
+ if (e->direction == PA_ALSA_DIRECTION_OUTPUT) {
if ((r = snd_mixer_selem_set_playback_dB(me, c, value, +1)) >= 0)
r = snd_mixer_selem_get_playback_dB(me, c, &value);
} else {
@@ -891,7 +925,7 @@ static int element_set_volume(pa_alsa_element *e, snd_mixer_t *m, const pa_chann
value = to_alsa_volume(f, e->min_volume, e->max_volume);
- if (e->direction == PA_ALSA_PLAYBACK) {
+ if (e->direction == PA_ALSA_DIRECTION_OUTPUT) {
if ((r = snd_mixer_selem_set_playback_volume(me, c, value)) >= 0)
r = snd_mixer_selem_get_playback_volume(me, c, &value);
} else {
@@ -906,11 +940,11 @@ static int element_set_volume(pa_alsa_element *e, snd_mixer_t *m, const pa_chann
}
for (k = 0; k < cm->channels; k++)
- if (e->masks[c][e->n_channels] & PA_CHANNEL_POSITION_MASK(cm->map[k]))
+ if (e->masks[c][e->n_channels-1] & PA_CHANNEL_POSITION_MASK(cm->map[k]))
if (rv.values[k] < f)
rv.values[k] = f;
- mask |= e->masks[c][e->n_channels];
+ mask |= e->masks[c][e->n_channels-1];
}
for (k = 0; k < cm->channels; k++)
@@ -974,7 +1008,7 @@ static int element_set_switch(pa_alsa_element *e, snd_mixer_t *m, pa_bool_t b) {
if (!(me = snd_mixer_find_selem(m, sid)))
return -1;
- if (e->direction == PA_ALSA_PLAYBACK)
+ if (e->direction == PA_ALSA_DIRECTION_OUTPUT)
r = snd_mixer_selem_set_playback_switch_all(me, b);
else
r = snd_mixer_selem_set_capture_switch_all(me, b);
@@ -1018,7 +1052,7 @@ static int element_mute_volume(pa_alsa_element *e, snd_mixer_t *m) {
if (!(me = snd_mixer_find_selem(m, sid)))
return -1;
- if (e->direction == PA_ALSA_PLAYBACK)
+ if (e->direction == PA_ALSA_DIRECTION_OUTPUT)
r = snd_mixer_selem_set_playback_volume_all(me, e->min_volume);
else
r = snd_mixer_selem_set_capture_volume_all(me, e->min_volume);
@@ -1039,7 +1073,7 @@ static int element_zero_volume(pa_alsa_element *e, snd_mixer_t *m) {
if (!(me = snd_mixer_find_selem(m, sid)))
return -1;
- if (e->direction == PA_ALSA_PLAYBACK)
+ if (e->direction == PA_ALSA_DIRECTION_OUTPUT)
r = snd_mixer_selem_set_playback_dB_all(me, 0, +1);
else
r = snd_mixer_selem_set_capture_dB_all(me, 0, +1);
@@ -1105,7 +1139,7 @@ static int check_required(pa_alsa_element *e, snd_mixer_elem_t *me) {
pa_assert(e);
pa_assert(me);
- if (e->direction == PA_ALSA_PLAYBACK) {
+ if (e->direction == PA_ALSA_DIRECTION_OUTPUT) {
has_switch =
snd_mixer_selem_has_playback_switch(me) ||
(e->direction_try_other && snd_mixer_selem_has_capture_switch(me));
@@ -1115,7 +1149,7 @@ static int check_required(pa_alsa_element *e, snd_mixer_elem_t *me) {
(e->direction_try_other && snd_mixer_selem_has_playback_switch(me));
}
- if (e->direction == PA_ALSA_PLAYBACK) {
+ if (e->direction == PA_ALSA_DIRECTION_OUTPUT) {
has_volume =
snd_mixer_selem_has_playback_volume(me) ||
(e->direction_try_other && snd_mixer_selem_has_capture_volume(me));
@@ -1168,11 +1202,11 @@ static int element_probe(pa_alsa_element *e, snd_mixer_t *m) {
}
if (e->switch_use != PA_ALSA_SWITCH_IGNORE) {
- if (e->direction == PA_ALSA_PLAYBACK) {
+ if (e->direction == PA_ALSA_DIRECTION_OUTPUT) {
if (!snd_mixer_selem_has_playback_switch(me)) {
if (e->direction_try_other && snd_mixer_selem_has_capture_switch(me))
- e->direction = PA_ALSA_CAPTURE;
+ e->direction = PA_ALSA_DIRECTION_INPUT;
else
e->switch_use = PA_ALSA_SWITCH_IGNORE;
}
@@ -1181,7 +1215,7 @@ static int element_probe(pa_alsa_element *e, snd_mixer_t *m) {
if (!snd_mixer_selem_has_capture_switch(me)) {
if (e->direction_try_other && snd_mixer_selem_has_playback_switch(me))
- e->direction = PA_ALSA_PLAYBACK;
+ e->direction = PA_ALSA_DIRECTION_OUTPUT;
else
e->switch_use = PA_ALSA_SWITCH_IGNORE;
}
@@ -1192,11 +1226,12 @@ static int element_probe(pa_alsa_element *e, snd_mixer_t *m) {
}
if (e->volume_use != PA_ALSA_VOLUME_IGNORE) {
- if (e->direction == PA_ALSA_PLAYBACK) {
+
+ if (e->direction == PA_ALSA_DIRECTION_OUTPUT) {
if (!snd_mixer_selem_has_playback_volume(me)) {
if (e->direction_try_other && snd_mixer_selem_has_capture_volume(me))
- e->direction = PA_ALSA_CAPTURE;
+ e->direction = PA_ALSA_DIRECTION_INPUT;
else
e->volume_use = PA_ALSA_VOLUME_IGNORE;
}
@@ -1205,7 +1240,7 @@ static int element_probe(pa_alsa_element *e, snd_mixer_t *m) {
if (!snd_mixer_selem_has_capture_volume(me)) {
if (e->direction_try_other && snd_mixer_selem_has_playback_volume(me))
- e->direction = PA_ALSA_PLAYBACK;
+ e->direction = PA_ALSA_DIRECTION_OUTPUT;
else
e->volume_use = PA_ALSA_VOLUME_IGNORE;
}
@@ -1215,10 +1250,9 @@ static int element_probe(pa_alsa_element *e, snd_mixer_t *m) {
long min_dB = 0, max_dB = 0;
pa_channel_position_t p;
pa_bool_t is_mono;
-
e->direction_try_other = FALSE;
- if (e->direction == PA_ALSA_PLAYBACK)
+ if (e->direction == PA_ALSA_DIRECTION_OUTPUT)
e->has_dB = snd_mixer_selem_get_playback_dB_range(me, &min_dB, &max_dB) >= 0;
else
e->has_dB = snd_mixer_selem_get_capture_dB_range(me, &min_dB, &max_dB) >= 0;
@@ -1228,7 +1262,7 @@ static int element_probe(pa_alsa_element *e, snd_mixer_t *m) {
e->max_dB = ((double) max_dB) / 100.0;
}
- if (e->direction == PA_ALSA_PLAYBACK) {
+ if (e->direction == PA_ALSA_DIRECTION_OUTPUT) {
if (snd_mixer_selem_get_playback_volume_range(me, &e->min_volume, &e->max_volume) < 0)
return -1;
} else {
@@ -1236,7 +1270,7 @@ static int element_probe(pa_alsa_element *e, snd_mixer_t *m) {
return -1;
}
- if (e->direction == PA_ALSA_PLAYBACK)
+ if (e->direction == PA_ALSA_DIRECTION_OUTPUT)
is_mono = snd_mixer_selem_is_playback_mono(me) > 0;
else
is_mono = snd_mixer_selem_is_capture_mono(me) > 0;
@@ -1244,34 +1278,50 @@ static int element_probe(pa_alsa_element *e, snd_mixer_t *m) {
if (is_mono) {
e->n_channels = 1;
- if (!e->override_map)
- e->masks[SND_MIXER_SCHN_MONO][e->n_channels] = PA_CHANNEL_POSITION_MASK_ALL;
+ if (!e->override_map) {
+ for (p = PA_CHANNEL_POSITION_FRONT_LEFT; p < PA_CHANNEL_POSITION_MAX; p++)
+ e->masks[alsa_channel_ids[p]][e->n_channels-1] = 0;
+ e->masks[SND_MIXER_SCHN_MONO][e->n_channels-1] = PA_CHANNEL_POSITION_MASK_ALL;
+ }
+
+ e->merged_mask = e->masks[SND_MIXER_SCHN_MONO][e->n_channels-1];
} else {
e->n_channels = 0;
- for (p = PA_CHANNEL_POSITION_FRONT_LEFT; p < PA_CHANNEL_POSITION_MAX; p++)
- if (alsa_channel_ids[p] != SND_MIXER_SCHN_UNKNOWN) {
- if (e->direction == PA_ALSA_PLAYBACK)
- e->n_channels += snd_mixer_selem_has_playback_channel(me, alsa_channel_ids[p]) > 0;
- else
- e->n_channels += snd_mixer_selem_has_capture_channel(me, alsa_channel_ids[p]) > 0;
- }
+ for (p = PA_CHANNEL_POSITION_FRONT_LEFT; p < PA_CHANNEL_POSITION_MAX; p++) {
+
+ if (alsa_channel_ids[p] == SND_MIXER_SCHN_UNKNOWN)
+ continue;
+
+ if (e->direction == PA_ALSA_DIRECTION_OUTPUT)
+ e->n_channels += snd_mixer_selem_has_playback_channel(me, alsa_channel_ids[p]) > 0;
+ else
+ e->n_channels += snd_mixer_selem_has_capture_channel(me, alsa_channel_ids[p]) > 0;
+ }
- if (e->n_channels <= 0)
+ if (e->n_channels <= 0) {
+ pa_log_warn("Volume element with no channels?");
return -1;
+ }
if (!e->override_map) {
- for (p = PA_CHANNEL_POSITION_FRONT_LEFT; p < PA_CHANNEL_POSITION_MAX; p++)
- if (alsa_channel_ids[p] != SND_MIXER_SCHN_UNKNOWN) {
- pa_bool_t has_channel;
+ for (p = PA_CHANNEL_POSITION_FRONT_LEFT; p < PA_CHANNEL_POSITION_MAX; p++) {
+ pa_bool_t has_channel;
- if (e->direction == PA_ALSA_PLAYBACK)
- has_channel = snd_mixer_selem_has_playback_channel(me, alsa_channel_ids[p]) > 0;
- else
- has_channel = snd_mixer_selem_has_capture_channel(me, alsa_channel_ids[p]) > 0;
+ if (alsa_channel_ids[p] == SND_MIXER_SCHN_UNKNOWN)
+ continue;
- e->masks[alsa_channel_ids[p]][e->n_channels] = has_channel ? PA_CHANNEL_POSITION_MASK(p) : 0;
- }
+ if (e->direction == PA_ALSA_DIRECTION_OUTPUT)
+ has_channel = snd_mixer_selem_has_playback_channel(me, alsa_channel_ids[p]) > 0;
+ else
+ has_channel = snd_mixer_selem_has_capture_channel(me, alsa_channel_ids[p]) > 0;
+
+ e->masks[alsa_channel_ids[p]][e->n_channels-1] = has_channel ? PA_CHANNEL_POSITION_MASK(p) : 0;
+ }
}
+
+ e->merged_mask = 0;
+ for (p = PA_CHANNEL_POSITION_FRONT_LEFT; p < PA_CHANNEL_POSITION_MAX; p++)
+ e->merged_mask |= e->masks[alsa_channel_ids[p]][e->n_channels-1];
}
}
}
@@ -1282,16 +1332,18 @@ static int element_probe(pa_alsa_element *e, snd_mixer_t *m) {
return 0;
}
-static pa_alsa_element* element_get(pa_alsa_path *p, const char *section) {
+static pa_alsa_element* element_get(pa_alsa_path *p, const char *section, pa_bool_t prefixed) {
pa_alsa_element *e;
pa_assert(p);
pa_assert(section);
- if (!pa_startswith(section, "Element "))
- return NULL;
+ if (prefixed) {
+ if (!pa_startswith(section, "Element "))
+ return NULL;
- section += 8;
+ section += 8;
+ }
/* This is not an element section, but an enum section? */
if (strchr(section, ':'))
@@ -1328,7 +1380,7 @@ static pa_alsa_option* option_get(pa_alsa_path *p, const char *section) {
section += 7;
/* This is not an enum section, but an element section? */
- if (!(on = strrchr(section, ':')))
+ if (!(on = strchr(section, ':')))
return NULL;
en = pa_xstrndup(section, on - section);
@@ -1341,7 +1393,7 @@ static pa_alsa_option* option_get(pa_alsa_path *p, const char *section) {
return p->option_parse_cache;
}
- pa_assert_se(e = element_get(p, en));
+ pa_assert_se(e = element_get(p, en, FALSE));
pa_xfree(en);
PA_LLIST_FOREACH(o, e->options)
@@ -1350,7 +1402,7 @@ static pa_alsa_option* option_get(pa_alsa_path *p, const char *section) {
o = pa_xnew0(pa_alsa_option, 1);
o->element = e;
- e->alsa_name = pa_xstrdup(on);
+ o->alsa_name = pa_xstrdup(on);
PA_LLIST_PREPEND(pa_alsa_option, e->options, o);
@@ -1373,7 +1425,7 @@ static int element_parse_switch(
pa_assert(p);
- if (!(e = element_get(p, section))) {
+ if (!(e = element_get(p, section, TRUE))) {
pa_log("[%s:%u] Switch makes no sense in '%s'", filename, line, section);
return -1;
}
@@ -1410,7 +1462,7 @@ static int element_parse_volume(
pa_assert(p);
- if (!(e = element_get(p, section))) {
+ if (!(e = element_get(p, section, TRUE))) {
pa_log("[%s:%u] Volume makes no sense in '%s'", filename, line, section);
return -1;
}
@@ -1445,7 +1497,7 @@ static int element_parse_enumeration(
pa_assert(p);
- if (!(e = element_get(p, section))) {
+ if (!(e = element_get(p, section, TRUE))) {
pa_log("[%s:%u] Enumeration makes no sense in '%s'", filename, line, section);
return -1;
}
@@ -1511,7 +1563,7 @@ static int option_parse_name(
}
pa_xfree(o->name);
- p->name = pa_xstrdup(rvalue);
+ o->name = pa_xstrdup(rvalue);
return 0;
}
@@ -1531,20 +1583,20 @@ static int element_parse_required(
pa_assert(p);
- if (!(e = element_get(p, section))) {
+ if (!(e = element_get(p, section, TRUE))) {
pa_log("[%s:%u] Required makes no sense in '%s'", filename, line, section);
return -1;
}
if (pa_streq(rvalue, "ignore"))
req = PA_ALSA_REQUIRED_IGNORE;
- else if (pa_streq(lvalue, "switch"))
+ else if (pa_streq(rvalue, "switch"))
req = PA_ALSA_REQUIRED_SWITCH;
- else if (pa_streq(lvalue, "volume"))
+ else if (pa_streq(rvalue, "volume"))
req = PA_ALSA_REQUIRED_VOLUME;
- else if (pa_streq(lvalue, "enumeration"))
+ else if (pa_streq(rvalue, "enumeration"))
req = PA_ALSA_REQUIRED_ENUMERATION;
- else if (pa_streq(lvalue, "any"))
+ else if (pa_streq(rvalue, "any"))
req = PA_ALSA_REQUIRED_ANY;
else {
pa_log("[%s:%u] Required invalid of '%s'", filename, line, section);
@@ -1573,15 +1625,15 @@ static int element_parse_direction(
pa_assert(p);
- if (!(e = element_get(p, section))) {
+ if (!(e = element_get(p, section, TRUE))) {
pa_log("[%s:%u] Direction makes no sense in '%s'", filename, line, section);
return -1;
}
if (pa_streq(rvalue, "playback"))
- e->direction = PA_ALSA_PLAYBACK;
+ e->direction = PA_ALSA_DIRECTION_OUTPUT;
else if (pa_streq(rvalue, "capture"))
- e->direction = PA_ALSA_CAPTURE;
+ e->direction = PA_ALSA_DIRECTION_INPUT;
else {
pa_log("[%s:%u] Direction invalid of '%s'", filename, line, section);
return -1;
@@ -1603,7 +1655,7 @@ static int element_parse_direction_try_other(
pa_alsa_element *e;
int yes;
- if (!(e = element_get(p, section))) {
+ if (!(e = element_get(p, section, TRUE))) {
pa_log("[%s:%u] Direction makes no sense in '%s'", filename, line, section);
return -1;
}
@@ -1618,31 +1670,36 @@ static int element_parse_direction_try_other(
}
static pa_channel_position_mask_t parse_mask(const char *m) {
+ pa_channel_position_mask_t v;
if (pa_streq(m, "all-left"))
- return PA_CHANNEL_POSITION_MASK_LEFT;
+ v = PA_CHANNEL_POSITION_MASK_LEFT;
else if (pa_streq(m, "all-right"))
- return PA_CHANNEL_POSITION_MASK_RIGHT;
+ v = PA_CHANNEL_POSITION_MASK_RIGHT;
else if (pa_streq(m, "all-center"))
- return PA_CHANNEL_POSITION_MASK_CENTER;
+ v = PA_CHANNEL_POSITION_MASK_CENTER;
else if (pa_streq(m, "all-front"))
- return PA_CHANNEL_POSITION_MASK_FRONT;
+ v = PA_CHANNEL_POSITION_MASK_FRONT;
else if (pa_streq(m, "all-rear"))
- return PA_CHANNEL_POSITION_MASK_REAR;
+ v = PA_CHANNEL_POSITION_MASK_REAR;
else if (pa_streq(m, "all-side"))
- return PA_CHANNEL_POSITION_MASK_SIDE_OR_TOP_CENTER;
+ v = PA_CHANNEL_POSITION_MASK_SIDE_OR_TOP_CENTER;
else if (pa_streq(m, "all-top"))
- return PA_CHANNEL_POSITION_MASK_TOP;
+ v = PA_CHANNEL_POSITION_MASK_TOP;
+ else if (pa_streq(m, "all-no-lfe"))
+ v = PA_CHANNEL_POSITION_MASK_ALL ^ PA_CHANNEL_POSITION_MASK(PA_CHANNEL_POSITION_LFE);
else if (pa_streq(m, "all"))
- return PA_CHANNEL_POSITION_MASK_ALL;
+ v = PA_CHANNEL_POSITION_MASK_ALL;
else {
pa_channel_position_t p;
- if ((p = pa_channel_position_from_string(m)) != PA_CHANNEL_POSITION_INVALID)
- return PA_CHANNEL_POSITION_MASK(p);
+ if ((p = pa_channel_position_from_string(m)) == PA_CHANNEL_POSITION_INVALID)
+ return 0;
+
+ v = PA_CHANNEL_POSITION_MASK(p);
}
- return 0;
+ return v;
}
static int element_parse_override_map(
@@ -1660,7 +1717,7 @@ static int element_parse_override_map(
unsigned i = 0;
char *n;
- if (!(e = element_get(p, section))) {
+ if (!(e = element_get(p, section, TRUE))) {
pa_log("[%s:%u] Override map makes no sense in '%s'", filename, line, section);
return -1;
}
@@ -1672,8 +1729,8 @@ static int element_parse_override_map(
m = 0;
else {
if ((m = parse_mask(n)) == 0) {
- pa_log("[%s:%u] Override map invalid in '%s'", filename, line, section);
- pa_xfree(p);
+ pa_log("[%s:%u] Override map '%s' invalid in '%s'", filename, line, n, section);
+ pa_xfree(n);
return -1;
}
}
@@ -1693,7 +1750,49 @@ static int element_parse_override_map(
return 0;
}
+static int option_verify(pa_alsa_option *o) {
+ static const struct description_map well_known_descriptions[] = {
+ { "input", N_("Input") },
+ { "input-docking", N_("Docking Station Input") },
+ { "input-docking-microphone", N_("Docking Station Microphone Input") },
+ { "input-linein", N_("Line-In Input") },
+ { "input-microphone", N_("Microphone Input") },
+ { "input-microphone-external", N_("External Microphone Input") },
+ { "input-microphone-internal", N_("Internal Microphone Input") },
+ { "input-radio", N_("Radio Input") },
+ { "input-video", N_("Video Input") },
+ { "output-amplifier-on", N_("Amplifier") },
+ { "input-agc-on", N_("Automatic Gain Control") },
+ { "input-boost-on", N_("Boost") }
+ };
+
+ pa_assert(o);
+
+ if (!o->name) {
+ pa_log("No name set for option %s", o->alsa_name);
+ return -1;
+ }
+
+ if (o->element->enumeration_use != PA_ALSA_ENUMERATION_SELECT &&
+ o->element->switch_use != PA_ALSA_SWITCH_SELECT) {
+ pa_log("Element %s of option %s not set for select.", o->element->alsa_name, o->name);
+ return -1;
+ }
+
+ if (!o->description)
+ o->description = pa_xstrdup(lookup_description(o->name,
+ well_known_descriptions,
+ PA_ELEMENTSOF(well_known_descriptions)));
+
+ if (!o->description)
+ o->description = pa_xstrdup(o->name);
+
+ return 0;
+}
+
static int element_verify(pa_alsa_element *e) {
+ pa_alsa_option *o;
+
pa_assert(e);
if ((e->required != PA_ALSA_REQUIRED_IGNORE && e->required == e->required_absent) ||
@@ -1702,19 +1801,52 @@ static int element_verify(pa_alsa_element *e) {
return -1;
}
+ PA_LLIST_FOREACH(o, e->options)
+ if (option_verify(o) < 0)
+ return -1;
+
return 0;
}
-pa_alsa_path* pa_alsa_path_new(const char *fname, pa_alsa_direction_t direction) {
+static int path_verify(pa_alsa_path *p) {
+ static const struct description_map well_known_descriptions[] = {
+ { "analog-input", N_("Analog Input") },
+ { "analog-output", N_("Analog Output") },
+ { "analog-output-headphones", N_("Analog Headphones") },
+ { "analog-output-lfe-on-mono", N_("Analog Output (LFE)") },
+ { "analog-output-mono", N_("Analog Output (Mono)") }
+ };
+
pa_alsa_element *e;
+
+ pa_assert(p);
+
+ PA_LLIST_FOREACH(e, p->elements)
+ if (element_verify(e) < 0)
+ return -1;
+
+ if (!p->description)
+ p->description = pa_xstrdup(lookup_description(p->name,
+ well_known_descriptions,
+ PA_ELEMENTSOF(well_known_descriptions)));
+
+ if (!p->description)
+ p->description = pa_xstrdup(p->name);
+
+ return 0;
+}
+
+pa_alsa_path* pa_alsa_path_new(const char *fname, pa_alsa_direction_t direction) {
pa_alsa_path *p;
char *fn;
int r;
+ const char *n;
pa_config_item items[] = {
/* [General] */
{ "priority", pa_config_parse_unsigned, NULL, "General" },
{ "description", pa_config_parse_string, NULL, "General" },
+ { "name", pa_config_parse_string, NULL, "General" },
/* [Option ...] */
{ "priority", option_parse_priority, NULL, NULL },
@@ -1737,11 +1869,13 @@ pa_alsa_path* pa_alsa_path_new(const char *fname, pa_alsa_direction_t direction)
pa_assert(fname);
p = pa_xnew0(pa_alsa_path, 1);
- p->name = pa_xstrdup(fname);
+ n = pa_path_get_filename(fname);
+ p->name = pa_xstrndup(n, strcspn(n, "."));
p->direction = direction;
items[0].data = &p->priority;
items[1].data = &p->description;
+ items[2].data = &p->name;
fn = pa_maybe_prefix_path(fname, PA_ALSA_PATHS_PATH);
r = pa_config_parse(fn, NULL, items, p);
@@ -1750,9 +1884,8 @@ pa_alsa_path* pa_alsa_path_new(const char *fname, pa_alsa_direction_t direction)
if (r < 0)
goto fail;
- PA_LLIST_FOREACH(e, p->elements)
- if (element_verify(e) < 0)
- goto fail;
+ if (path_verify(p) < 0)
+ goto fail;
return p;
@@ -1785,6 +1918,8 @@ pa_alsa_path* pa_alsa_path_synthesize(const char*element, pa_alsa_direction_t di
int pa_alsa_path_probe(pa_alsa_path *p, snd_mixer_t *m) {
pa_alsa_element *e;
+ double min_dB[PA_CHANNEL_POSITION_MAX], max_dB[PA_CHANNEL_POSITION_MAX];
+ pa_channel_position_t t;
pa_assert(p);
pa_assert(m);
@@ -1792,9 +1927,15 @@ int pa_alsa_path_probe(pa_alsa_path *p, snd_mixer_t *m) {
if (p->probed)
return 0;
+ pa_zero(min_dB);
+ pa_zero(max_dB);
+
+ pa_log("Probing %s", p->name);
+
PA_LLIST_FOREACH(e, p->elements) {
if (element_probe(e, m) < 0) {
p->supported = FALSE;
+ pa_log("%s probe failed.", e->alsa_name);
return -1;
}
@@ -1807,14 +1948,21 @@ int pa_alsa_path_probe(pa_alsa_path *p, snd_mixer_t *m) {
if (e->has_dB) {
if (!p->has_volume) {
- p->min_dB = e->min_dB;
- p->max_dB = e->max_dB;
+ for (t = 0; t < PA_CHANNEL_POSITION_MAX; t++)
+ if (PA_CHANNEL_POSITION_MASK(t) & e->merged_mask) {
+ min_dB[t] = e->min_dB;
+ max_dB[t] = e->max_dB;
+ }
+
p->has_dB = TRUE;
} else {
if (p->has_dB) {
- p->min_dB += e->min_dB;
- p->max_dB += e->max_dB;
+ for (t = 0; t < PA_CHANNEL_POSITION_MAX; t++)
+ if (PA_CHANNEL_POSITION_MASK(t) & e->merged_mask) {
+ min_dB[t] += e->min_dB;
+ max_dB[t] += e->max_dB;
+ }
} else
/* Hmm, there's another element before us
* which cannot do dB volumes, so we we need
@@ -1835,6 +1983,16 @@ int pa_alsa_path_probe(pa_alsa_path *p, snd_mixer_t *m) {
p->supported = TRUE;
p->probed = TRUE;
+ p->min_dB = p->max_dB = 0.0;
+
+ for (t = 0; t < PA_CHANNEL_POSITION_MAX; t++) {
+ if (p->min_dB > min_dB[t])
+ p->min_dB = min_dB[t];
+
+ if (p->max_dB < max_dB[t])
+ p->max_dB = max_dB[t];
+ }
+
return 0;
}
@@ -1875,36 +2033,110 @@ pa_bool_t pa_alsa_path_drop_unsupported(pa_alsa_path *p) {
return !!p->elements;
}
+void pa_alsa_setting_dump(pa_alsa_setting *s) {
+ pa_assert(s);
+
+ pa_log_debug("Setting %s (%s) priority=%u",
+ s->name,
+ pa_strnull(s->description),
+ s->priority);
+}
+
+void pa_alsa_option_dump(pa_alsa_option *o) {
+ pa_assert(o);
+
+ pa_log_debug("Option %s (%s/%s) index=%i, priority=%u",
+ o->alsa_name,
+ pa_strnull(o->name),
+ pa_strnull(o->description),
+ o->alsa_idx,
+ o->priority);
+}
+
+void pa_alsa_element_dump(pa_alsa_element *e) {
+ pa_alsa_option *o;
+ pa_assert(e);
+
+ pa_log_debug("Element %s, direction=%i, switch=%i, volume=%i, enumeration=%i, required=%i, required_absent=%i, mask=0x%llx, n_channels=%u, override_map=%s",
+ e->alsa_name,
+ e->direction,
+ e->switch_use,
+ e->volume_use,
+ e->enumeration_use,
+ e->required,
+ e->required_absent,
+ (long long unsigned) e->merged_mask,
+ e->n_channels,
+ pa_yes_no(e->override_map));
+
+ PA_LLIST_FOREACH(o, e->options)
+ pa_alsa_option_dump(o);
+}
+
+void pa_alsa_path_dump(pa_alsa_path *p) {
+ pa_alsa_element *e;
+ pa_alsa_setting *s;
+ pa_assert(p);
+
+ pa_log_debug("Path %s (%s), direction=%i, priority=%u, probed=%s, supported=%s, has_mute=%s, has_volume=%s, "
+ "has_dB=%s, min_volume=%li, max_volume=%li, min_dB=%g, max_dB=%g",
+ p->name,
+ pa_strnull(p->description),
+ p->direction,
+ p->priority,
+ pa_yes_no(p->probed),
+ pa_yes_no(p->supported),
+ pa_yes_no(p->has_mute),
+ pa_yes_no(p->has_volume),
+ pa_yes_no(p->has_dB),
+ p->min_volume, p->max_volume,
+ p->min_dB, p->max_dB);
+
+ PA_LLIST_FOREACH(e, p->elements)
+ pa_alsa_element_dump(e);
+
+ PA_LLIST_FOREACH(s, p->settings)
+ pa_alsa_setting_dump(s);
+}
+
pa_alsa_path_set *pa_alsa_path_set_new(pa_alsa_mapping *m, pa_alsa_direction_t direction) {
pa_alsa_path_set *ps;
char **pn = NULL, **en = NULL, **ie;
+
pa_assert(m);
+ pa_assert(direction == PA_ALSA_DIRECTION_OUTPUT || direction == PA_ALSA_DIRECTION_INPUT);
+
+ if (m->direction != PA_ALSA_DIRECTION_ANY && m->direction != direction)
+ return NULL;
ps = pa_xnew0(pa_alsa_path_set, 1);
ps->direction = direction;
- if (direction == PA_ALSA_PLAYBACK)
+ if (direction == PA_ALSA_DIRECTION_OUTPUT)
pn = m->output_path_names;
- else if (direction == PA_ALSA_CAPTURE)
+ else if (direction == PA_ALSA_DIRECTION_INPUT)
pn = m->input_path_names;
if (pn) {
for (; *pn; pn++) {
pa_alsa_path *p;
+ char *fn = pa_sprintf_malloc("%s.conf", *pn);
- if ((p = pa_alsa_path_new(*pn, direction))) {
+ if ((p = pa_alsa_path_new(fn, direction))) {
p->path_set = ps;
PA_LLIST_PREPEND(pa_alsa_path, ps->paths, p);
}
+
+ pa_xfree(fn);
}
return ps;
}
- if (direction == PA_ALSA_PLAYBACK)
+ if (direction == PA_ALSA_DIRECTION_OUTPUT)
en = m->output_element;
- else if (direction == PA_ALSA_CAPTURE)
+ else if (direction == PA_ALSA_DIRECTION_INPUT)
en = m->input_element;
if (!en) {
@@ -1942,8 +2174,13 @@ void pa_alsa_path_set_probe(pa_alsa_path_set *ps, snd_mixer_t *m) {
pa_assert(ps);
+ if (ps->probed)
+ return;
+
PA_LLIST_FOREACH(p, ps->paths)
pa_alsa_path_probe(p, m);
+
+ ps->probed = TRUE;
}
void pa_alsa_path_set_drop_unsupported(pa_alsa_path_set *ps) {
@@ -1962,6 +2199,19 @@ void pa_alsa_path_set_drop_unsupported(pa_alsa_path_set *ps) {
}
}
+void pa_alsa_path_set_dump(pa_alsa_path_set *ps) {
+ pa_alsa_path *p;
+ pa_assert(ps);
+
+ pa_log_debug("Path Set %p, direction=%i, probed=%s",
+ (void*) ps,
+ ps->direction,
+ pa_yes_no(ps->probed));
+
+ PA_LLIST_FOREACH(p, ps->paths)
+ pa_alsa_path_dump(p);
+}
+
static void mapping_free(pa_alsa_mapping *m) {
pa_assert(m);
@@ -2178,6 +2428,39 @@ static int mapping_parse_element(
return 0;
}
+static int mapping_parse_direction(
+ const char *filename,
+ unsigned line,
+ const char *section,
+ const char *lvalue,
+ const char *rvalue,
+ void *data,
+ void *userdata) {
+
+ pa_alsa_profile_set *ps = userdata;
+ pa_alsa_mapping *m;
+
+ pa_assert(ps);
+
+ if (!(m = mapping_get(ps, section))) {
+ pa_log("[%s:%u] Section name %s invalid.", filename, line, section);
+ return -1;
+ }
+
+ if (pa_streq(rvalue, "input"))
+ m->direction = PA_ALSA_DIRECTION_INPUT;
+ else if (pa_streq(rvalue, "output"))
+ m->direction = PA_ALSA_DIRECTION_OUTPUT;
+ else if (pa_streq(rvalue, "any"))
+ m->direction = PA_ALSA_DIRECTION_ANY;
+ else {
+ pa_log("[%s:%u] Direction %s invalid.", filename, line, rvalue);
+ return -1;
+ }
+
+ return 0;
+}
+
static int mapping_parse_description(
const char *filename,
unsigned line,
@@ -2300,21 +2583,6 @@ static int profile_parse_skip_probe(
return 0;
}
-struct description_map {
- const char *name;
- const char *description;
-};
-
-static const char *lookup_description(const char *name, const struct description_map dm[], unsigned n) {
- unsigned i;
-
- for (i = 0; i < n; i++)
- if (pa_streq(dm[i].name, name))
- return dm[i].description;
-
- return NULL;
-}
-
static int mapping_verify(pa_alsa_mapping *m) {
static const struct description_map well_known_descriptions[] = {
@@ -2367,10 +2635,24 @@ static int mapping_verify(pa_alsa_mapping *m) {
return 0;
}
+void pa_alsa_mapping_dump(pa_alsa_mapping *m) {
+ char cm[PA_CHANNEL_MAP_SNPRINT_MAX];
+
+ pa_assert(m);
+
+ pa_log_debug("Mapping %s (%s), priority=%u, channel_map=%s, supported=%s, direction=%i",
+ m->name,
+ pa_strnull(m->description),
+ m->priority,
+ pa_channel_map_snprint(cm, sizeof(cm), &m->channel_map),
+ pa_yes_no(m->supported),
+ m->direction);
+}
+
static void profile_set_add_auto_pair(
pa_alsa_profile_set *ps,
- pa_alsa_mapping *m,
- pa_alsa_mapping *n) {
+ pa_alsa_mapping *m, /* output */
+ pa_alsa_mapping *n /* input */) {
char *name;
pa_alsa_profile *p;
@@ -2378,12 +2660,18 @@ static void profile_set_add_auto_pair(
pa_assert(ps);
pa_assert(m || n);
+ if (m && m->direction == PA_ALSA_DIRECTION_INPUT)
+ return;
+
+ if (n && n->direction == PA_ALSA_DIRECTION_OUTPUT)
+ return;
+
if (m && n)
name = pa_sprintf_malloc("output:%s+input:%s", m->name, n->name);
else if (m)
- name = pa_xstrdup(m->name);
+ name = pa_sprintf_malloc("output:%s", m->name);
else
- name = pa_xstrdup(n->name);
+ name = pa_sprintf_malloc("input:%s", n->name);
if ((p = pa_hashmap_get(ps->profiles, name))) {
pa_xfree(name);
@@ -2395,7 +2683,7 @@ static void profile_set_add_auto_pair(
p->name = name;
if (m) {
- p->output_mappings = pa_idxset_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
+ p->output_mappings = pa_idxset_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func);
pa_idxset_put(p->output_mappings, m, NULL);
p->priority += m->priority * 100;
}
@@ -2403,7 +2691,7 @@ static void profile_set_add_auto_pair(
if (n) {
p->input_mappings = pa_idxset_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func);
pa_idxset_put(p->input_mappings, n, NULL);
- p->priority += m->priority;
+ p->priority += n->priority;
}
pa_hashmap_put(ps->profiles, p->name, p);
@@ -2416,10 +2704,10 @@ static void profile_set_add_auto(pa_alsa_profile_set *ps) {
pa_assert(ps);
PA_HASHMAP_FOREACH(m, ps->mappings, m_state) {
+ profile_set_add_auto_pair(ps, m, NULL);
+
PA_HASHMAP_FOREACH(n, ps->mappings, n_state)
profile_set_add_auto_pair(ps, m, n);
-
- profile_set_add_auto_pair(ps, m, NULL);
}
PA_HASHMAP_FOREACH(n, ps->mappings, n_state)
@@ -2445,7 +2733,7 @@ static int profile_verify(pa_alsa_profile *p) {
for (name = p->output_mapping_names; *name; name++) {
pa_alsa_mapping *m;
- if (!(m = pa_hashmap_get(p->profile_set->mappings, *name))) {
+ if (!(m = pa_hashmap_get(p->profile_set->mappings, *name)) || m->direction == PA_ALSA_DIRECTION_INPUT) {
pa_log("Profile '%s' refers to unexistant mapping '%s'.", p->name, *name);
return -1;
}
@@ -2467,7 +2755,7 @@ static int profile_verify(pa_alsa_profile *p) {
for (name = p->input_mapping_names; *name; name++) {
pa_alsa_mapping *m;
- if (!(m = pa_hashmap_get(p->profile_set->mappings, *name))) {
+ if (!(m = pa_hashmap_get(p->profile_set->mappings, *name)) || m->direction == PA_ALSA_DIRECTION_OUTPUT) {
pa_log("Profile '%s' refers to unexistant mapping '%s'.", p->name, *name);
return -1;
}
@@ -2496,19 +2784,21 @@ static int profile_verify(pa_alsa_profile *p) {
sb = pa_strbuf_new();
- PA_IDXSET_FOREACH(m, p->output_mappings, idx) {
- if (!pa_strbuf_isempty(sb))
- pa_strbuf_puts(sb, " + ");
+ if (p->output_mappings)
+ PA_IDXSET_FOREACH(m, p->output_mappings, idx) {
+ if (!pa_strbuf_isempty(sb))
+ pa_strbuf_puts(sb, " + ");
- pa_strbuf_printf(sb, "%s Output", m->description);
- }
+ pa_strbuf_printf(sb, "%s Output", m->description);
+ }
- PA_IDXSET_FOREACH(m, p->output_mappings, idx) {
- if (!pa_strbuf_isempty(sb))
- pa_strbuf_puts(sb, " + ");
+ if (p->input_mappings)
+ PA_IDXSET_FOREACH(m, p->input_mappings, idx) {
+ if (!pa_strbuf_isempty(sb))
+ pa_strbuf_puts(sb, " + ");
- pa_strbuf_printf(sb, "%s Input", m->description);
- }
+ pa_strbuf_printf(sb, "%s Input", m->description);
+ }
p->description = pa_strbuf_tostring_free(sb);
}
@@ -2516,6 +2806,28 @@ static int profile_verify(pa_alsa_profile *p) {
return 0;
}
+void pa_alsa_profile_dump(pa_alsa_profile *p) {
+ uint32_t idx;
+ pa_alsa_mapping *m;
+ pa_assert(p);
+
+ pa_log_debug("Profile %s (%s), priority=%u, supported=%s n_input_mappings=%u, n_output_mappings=%u",
+ p->name,
+ pa_strnull(p->description),
+ p->priority,
+ pa_yes_no(p->supported),
+ p->input_mappings ? pa_idxset_size(p->input_mappings) : 0,
+ p->output_mappings ? pa_idxset_size(p->output_mappings) : 0);
+
+ if (p->input_mappings)
+ PA_IDXSET_FOREACH(m, p->input_mappings, idx)
+ pa_log_debug("Input %s", m->name);
+
+ if (p->output_mappings)
+ PA_IDXSET_FOREACH(m, p->output_mappings, idx)
+ pa_log_debug("Output %s", m->name);
+}
+
pa_alsa_profile_set* pa_alsa_profile_set_new(const char *fname) {
pa_alsa_profile_set *ps;
pa_alsa_profile *p;
@@ -2535,6 +2847,7 @@ pa_alsa_profile_set* pa_alsa_profile_set_new(const char *fname) {
{ "paths-output", mapping_parse_paths, NULL, NULL },
{ "element-input", mapping_parse_element, NULL, NULL },
{ "element-output", mapping_parse_element, NULL, NULL },
+ { "direction", mapping_parse_direction, NULL, NULL },
/* Shared by [Mapping ...] and [Profile ...] */
{ "description", mapping_parse_description, NULL, NULL },
@@ -2645,6 +2958,8 @@ void pa_alsa_profile_set_probe(pa_alsa_profile_set *ps, const char *dev_id, cons
if (p->supported)
continue;
+ pa_log_debug("Looking at profile %s", p->name);
+
/* Close PCMs from the last iteration we don't need anymore */
if (last && last->output_mappings)
PA_IDXSET_FOREACH(m, last->output_mappings, idx) {
@@ -2726,6 +3041,9 @@ void pa_alsa_profile_set_probe(pa_alsa_profile_set *ps, const char *dev_id, cons
}
last = p;
+
+ if (p->supported)
+ pa_log_debug("Profile %s supported.", p->name);
}
/* Clean up */
@@ -2774,7 +3092,29 @@ void pa_alsa_profile_set_drop_unsupported(pa_alsa_profile_set *ps) {
PA_HASHMAP_FOREACH(m, ps->mappings, state)
if (m->supported <= 0) {
- pa_hashmap_remove(ps->mappings, m);
+ pa_hashmap_remove(ps->mappings, m->name);
mapping_free(m);
}
}
+
+void pa_alsa_profile_set_dump(pa_alsa_profile_set *ps) {
+ pa_alsa_profile *p;
+ pa_alsa_mapping *m;
+ void *state;
+
+ pa_assert(ps);
+
+ pa_log_debug("Profile set %p, auto_profiles=%s, probed=%s, n_mappings=%u, n_profiles=%u",
+ (void*)
+ ps,
+ pa_yes_no(ps->auto_profiles),
+ pa_yes_no(ps->probed),
+ pa_hashmap_size(ps->mappings),
+ pa_hashmap_size(ps->profiles));
+
+ PA_HASHMAP_FOREACH(m, ps->mappings, state)
+ pa_alsa_mapping_dump(m);
+
+ PA_HASHMAP_FOREACH(p, ps->profiles, state)
+ pa_alsa_profile_dump(p);
+}
diff --git a/src/modules/alsa/alsa-mixer.h b/src/modules/alsa/alsa-mixer.h
index c4cbc36..836e901 100644
--- a/src/modules/alsa/alsa-mixer.h
+++ b/src/modules/alsa/alsa-mixer.h
@@ -78,8 +78,9 @@ typedef enum pa_alsa_required {
} pa_alsa_required_t;
typedef enum pa_alsa_direction {
- PA_ALSA_PLAYBACK,
- PA_ALSA_CAPTURE
+ PA_ALSA_DIRECTION_ANY,
+ PA_ALSA_DIRECTION_OUTPUT,
+ PA_ALSA_DIRECTION_INPUT
} pa_alsa_direction_t;
/* A setting combines a couple of options into a single entity that
@@ -138,6 +139,8 @@ struct pa_alsa_element {
pa_channel_position_mask_t masks[SND_MIXER_SCHN_LAST][2];
unsigned n_channels;
+ pa_channel_position_mask_t merged_mask;
+
PA_LLIST_HEAD(pa_alsa_option, options);
};
@@ -177,27 +180,32 @@ struct pa_alsa_path {
struct pa_alsa_path_set {
PA_LLIST_HEAD(pa_alsa_path, paths);
pa_alsa_direction_t direction;
+ pa_bool_t probed:1;
};
-int pa_alsa_path_get_volume(pa_alsa_path *p, snd_mixer_t *m, const pa_channel_map *cm, pa_cvolume *v);
-int pa_alsa_path_get_mute(pa_alsa_path *path, snd_mixer_t *m, pa_bool_t *muted);
+int pa_alsa_setting_select(pa_alsa_setting *s, snd_mixer_t *m);
+void pa_alsa_setting_dump(pa_alsa_setting *s);
-int pa_alsa_path_set_volume(pa_alsa_path *path, snd_mixer_t *m, const pa_channel_map *cm, pa_cvolume *v);
-int pa_alsa_path_set_mute(pa_alsa_path *path, snd_mixer_t *m, pa_bool_t muted);
+void pa_alsa_option_dump(pa_alsa_option *o);
-int pa_alsa_path_select(pa_alsa_path *p, snd_mixer_t *m);
-
-int pa_alsa_setting_select(pa_alsa_setting *s, snd_mixer_t *m);
+void pa_alsa_element_dump(pa_alsa_element *e);
pa_alsa_path *pa_alsa_path_new(const char *fname, pa_alsa_direction_t direction);
pa_alsa_path *pa_alsa_path_synthesize(const char *element, pa_alsa_direction_t direction);
int pa_alsa_path_probe(pa_alsa_path *p, snd_mixer_t *m);
pa_bool_t pa_alsa_path_drop_unsupported(pa_alsa_path *p);
+void pa_alsa_path_dump(pa_alsa_path *p);
+int pa_alsa_path_get_volume(pa_alsa_path *p, snd_mixer_t *m, const pa_channel_map *cm, pa_cvolume *v);
+int pa_alsa_path_get_mute(pa_alsa_path *path, snd_mixer_t *m, pa_bool_t *muted);
+int pa_alsa_path_set_volume(pa_alsa_path *path, snd_mixer_t *m, const pa_channel_map *cm, pa_cvolume *v);
+int pa_alsa_path_set_mute(pa_alsa_path *path, snd_mixer_t *m, pa_bool_t muted);
+int pa_alsa_path_select(pa_alsa_path *p, snd_mixer_t *m);
void pa_alsa_path_free(pa_alsa_path *p);
pa_alsa_path_set *pa_alsa_path_set_new(pa_alsa_mapping *m, pa_alsa_direction_t direction);
void pa_alsa_path_set_probe(pa_alsa_path_set *s, snd_mixer_t *m);
void pa_alsa_path_set_drop_unsupported(pa_alsa_path_set *s);
+void pa_alsa_path_set_dump(pa_alsa_path_set *s);
void pa_alsa_path_set_free(pa_alsa_path_set *s);
struct pa_alsa_mapping {
@@ -206,6 +214,7 @@ struct pa_alsa_mapping {
char *name;
char *description;
unsigned priority;
+ pa_alsa_direction_t direction;
pa_channel_map channel_map;
@@ -247,10 +256,14 @@ struct pa_alsa_profile_set {
pa_bool_t probed:1;
};
+void pa_alsa_mapping_dump(pa_alsa_mapping *m);
+void pa_alsa_profile_dump(pa_alsa_profile *p);
+
pa_alsa_profile_set* pa_alsa_profile_set_new(const char *fname);
void pa_alsa_profile_set_probe(pa_alsa_profile_set *ps, const char *dev_id, const pa_sample_spec *ss);
void pa_alsa_profile_set_drop_unsupported(pa_alsa_profile_set *ps);
void pa_alsa_profile_set_free(pa_alsa_profile_set *s);
+void pa_alsa_profile_set_dump(pa_alsa_profile_set *s);
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);
diff --git a/src/modules/alsa/mixer/paths/analog-input-mic.conf b/src/modules/alsa/mixer/paths/analog-input-mic.conf
index f81470f..9d40695 100644
--- a/src/modules/alsa/mixer/paths/analog-input-mic.conf
+++ b/src/modules/alsa/mixer/paths/analog-input-mic.conf
@@ -1,8 +1,9 @@
# For devices, where no 'Capture' slider exists an 'Mic' most likely
# controls input ADC volume (and not the input feedback volume)
-[Path]
+[General]
priority = 100
+name = analog-input
[Element Capture]
required-absent = volume
diff --git a/src/modules/alsa/mixer/paths/analog-input.conf b/src/modules/alsa/mixer/paths/analog-input.conf
index d09a14e..b96af1d 100644
--- a/src/modules/alsa/mixer/paths/analog-input.conf
+++ b/src/modules/alsa/mixer/paths/analog-input.conf
@@ -1,7 +1,7 @@
# For normal devices, where a 'Capture' slider exists. This path will
# not apply if we lack a 'Capture' Slider
-[Path]
+[General]
priority = 100
[Element Capture]
diff --git a/src/modules/alsa/mixer/paths/analog-input.conf.common b/src/modules/alsa/mixer/paths/analog-input.conf.common
index a094f6d..e353cc7 100644
--- a/src/modules/alsa/mixer/paths/analog-input.conf.common
+++ b/src/modules/alsa/mixer/paths/analog-input.conf.common
@@ -260,43 +260,43 @@ name = input-docking-microphone
switch = select
[Option Mic Boost (+20dB):on]
-name = capture-boost-on
+name = input-boost-on
[Option Mic Boost (+20dB):off]
-name = capture-boost-off
+name = input-boost-off
[Option Capture Boost]
switch = select
[Option Capture Boost:on]
-name = capture-boost-on
+name = input-boost-on
[Option Capture Boost:off]
-name = capture-boost-off
+name = input-boost-off
[Element Mic Boost]
switch = select
[Option Mic Boost:on]
-name = capture-boost-on
+name = input-boost-on
[Option Mic Boost:off]
-name = capture-boost-off
+name = input-boost-off
[Element Front Mic Boost]
switch = select
[Option Front Mic Boost:on]
-name = capture-boost-on
+name = input-boost-on
[Option Front Mic Boost:off]
-name = capture-boost-off
+name = input-boost-off
[Element Auto Gain Control]
switch = select
[Option Auto Gain Control:on]
-name = capture-agc-on
+name = input-agc-on
[Option Auto Gain Control:off]
-name = capture-agc-on
+name = input-agc-off
diff --git a/src/modules/alsa/mixer/paths/analog-output-headphones.conf b/src/modules/alsa/mixer/paths/analog-output-headphones.conf
index 6559d16..1a172d4 100644
--- a/src/modules/alsa/mixer/paths/analog-output-headphones.conf
+++ b/src/modules/alsa/mixer/paths/analog-output-headphones.conf
@@ -1,6 +1,6 @@
# Path for mixers that have a Headphone slider
-[Path]
+[General]
priority = 90
[Element Hardware Master]
diff --git a/src/modules/alsa/mixer/paths/analog-output-lfe-on-mono.conf b/src/modules/alsa/mixer/paths/analog-output-lfe-on-mono.conf
index afc19e3..6703176 100644
--- a/src/modules/alsa/mixer/paths/analog-output-lfe-on-mono.conf
+++ b/src/modules/alsa/mixer/paths/analog-output-lfe-on-mono.conf
@@ -1,7 +1,7 @@
# Intended for usage in laptops that have a seperate LFE speaker
# connected to the Master mono connector
-[Path]
+[General]
priority = 40
[Element Hardware Master]
@@ -14,7 +14,7 @@ override-map.2 = all-left,all-right
switch = mute
volume = merge
override-map.1 = all-no-lfe
-override-map.2 = all-left-no-lfe,all-right-no-lfe
+override-map.2 = all-left,all-right
[Element Master Mono]
required = any
@@ -51,4 +51,4 @@ volume = off
switch = off
volume = off
-.include analog-output-common.path
+.include analog-output.conf.common
diff --git a/src/modules/alsa/mixer/paths/analog-output-mono.conf b/src/modules/alsa/mixer/paths/analog-output-mono.conf
index 88af602..a23d9b7 100644
--- a/src/modules/alsa/mixer/paths/analog-output-mono.conf
+++ b/src/modules/alsa/mixer/paths/analog-output-mono.conf
@@ -1,6 +1,6 @@
# Intended for usage on boards that have a seperate Mono output plug.
-[Path]
+[General]
priority = 50
[Element Hardware Master]
diff --git a/src/modules/alsa/mixer/paths/analog-output.conf b/src/modules/alsa/mixer/paths/analog-output.conf
index d7fa91d..e869920 100644
--- a/src/modules/alsa/mixer/paths/analog-output.conf
+++ b/src/modules/alsa/mixer/paths/analog-output.conf
@@ -1,6 +1,6 @@
# Intended for the 'default' output
-[Path]
+[General]
priority = 100
[Element Hardware Master]
diff --git a/src/modules/alsa/mixer/paths/analog-output.conf.common b/src/modules/alsa/mixer/paths/analog-output.conf.common
index c6fb36a..c38eccd 100644
--- a/src/modules/alsa/mixer/paths/analog-output.conf.common
+++ b/src/modules/alsa/mixer/paths/analog-output.conf.common
@@ -32,9 +32,9 @@ override-map.2 = all-left,all-right
switch = select
[Option External Amplifier:on]
-name = amplifier-on
+name = output-amplifier-on
priority = 0
[Option External Amplifier:off]
-name = amplifier-off
+name = output-amplifier-off
priority = 10
diff --git a/src/modules/alsa/mixer/profiles/default.conf b/src/modules/alsa/mixer/profiles/default.conf
index dc378bb..fc2c192 100644
--- a/src/modules/alsa/mixer/profiles/default.conf
+++ b/src/modules/alsa/mixer/profiles/default.conf
@@ -9,13 +9,14 @@
# element-input = ...
# element-output = ...
# priority = ...
+# direction = any | input | output
#
# [Profile id]
# input-mappings = ...
# output-mappings = ...
# description = ...
# priority = ...
-# skip-probe = yes | no
+# skip-probe = no | yes
[General]
auto-profiles = yes
@@ -40,6 +41,7 @@ channel-map = front-left,front-right,rear-left,rear-right
paths-output = analog-output analog-output-lfe-on-mono
paths-input = analog-input
priority = 7
+direction = output
[Mapping analog-surround-41]
device-strings = surround41
@@ -47,6 +49,7 @@ channel-map = front-left,front-right,rear-left,rear-right,lfe
paths-output = analog-output analog-output-lfe-on-mono
paths-input = analog-input
priority = 8
+direction = output
[Mapping analog-surround-50]
device-strings = surround50
@@ -54,6 +57,7 @@ channel-map = front-left,front-right,rear-left,rear-right,front-center
paths-output = analog-output analog-output-lfe-on-mono
paths-input = analog-input
priority = 7
+direction = output
[Mapping analog-surround-51]
device-strings = surround51
@@ -61,6 +65,7 @@ channel-map = front-left,front-right,rear-left,rear-right,front-center,lfe
paths-output = analog-output analog-output-lfe-on-mono
paths-input = analog-input
priority = 8
+direction = output
[Mapping analog-surround-71]
device-strings = surround71
@@ -69,6 +74,7 @@ description = Analog Surround 7.1
paths-output = analog-output analog-output-lfe-on-mono
paths-input = analog-input
priority = 7
+direction = output
[Mapping iec958-stereo]
device-strings = iec958
@@ -84,13 +90,21 @@ priority = 1
device-strings = a52
channel-map = front-left,front-right,rear-left,rear-right
priority = 2
+direction = output
[Mapping iec958-ac3-surround-51]
device-strings = a52
channel-map = front-left,front-right,rear-left,rear-right,front-center,lfe
priority = 3
+direction = output
[Mapping hdmi-stereo]
device-strings = hdmi
channel-map = left,right
priority = 4
+direction = output
+
+[Profile output:analog-stereo+output:iec958-stereo+input:analog-stereo]
+description = Foobar
+output-mappings = analog-stereo iec958-stereo
+input-mappings = analog-stereo
diff --git a/src/pulsecore/conf-parser.c b/src/pulsecore/conf-parser.c
index dfe327b..a427c6c 100644
--- a/src/pulsecore/conf-parser.c
+++ b/src/pulsecore/conf-parser.c
@@ -112,8 +112,24 @@ static int parse_line(const char *filename, unsigned line, char **section, const
if (!*b)
return 0;
- if (pa_startswith(b, ".include "))
- return pa_config_parse(strip(b+9), NULL, t, userdata);
+ if (pa_startswith(b, ".include ")) {
+ char *path, *fn;
+ int r;
+
+ fn = strip(b+9);
+ if (!pa_is_path_absolute(fn)) {
+ const char *k;
+ if ((k = strrchr(filename, '/'))) {
+ char *dir = pa_xstrndup(filename, k-filename);
+ fn = path = pa_sprintf_malloc("%s" PA_PATH_SEP "%s", dir, fn);
+ pa_xfree(dir);
+ }
+ }
+
+ r = pa_config_parse(fn, NULL, t, userdata);
+ pa_xfree(path);
+ return r;
+ }
if (*b == '[') {
size_t k;
diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c
index b2faf95..a71ba0b 100644
--- a/src/pulsecore/core-util.c
+++ b/src/pulsecore/core-util.c
@@ -2742,7 +2742,7 @@ void pa_xfreev(void**a) {
for (p = a; *p; p++)
pa_xfree(*p);
- pa_xfree(p);
+ pa_xfree(a);
}
char **pa_split_spaces_strv(const char *s) {
diff --git a/src/pulsecore/sample-util.h b/src/pulsecore/sample-util.h
index 3119af3..6a306c1 100644
--- a/src/pulsecore/sample-util.h
+++ b/src/pulsecore/sample-util.h
@@ -142,6 +142,6 @@ void pa_memchunk_sine(pa_memchunk *c, pa_mempool *pool, unsigned rate, unsigned
| PA_CHANNEL_POSITION_MASK(PA_CHANNEL_POSITION_TOP_REAR_CENTER))
#define PA_CHANNEL_POSITION_MASK_ALL \
- ((pa_channel_position_mask_t) -1) \
+ ((pa_channel_position_mask_t) (PA_CHANNEL_POSITION_MASK(PA_CHANNEL_POSITION_MAX)-1))
#endif
commit 00d015980b7de3adf2a5f7898ef334b17ba1962b
Author: Lennart Poettering <lennart at poettering.net>
Date: Mon Jun 15 20:01:19 2009 +0200
save it away
diff --git a/src/Makefile.am b/src/Makefile.am
index eeaca85..2f5d9d8 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -74,8 +74,8 @@ AM_CFLAGS = \
-DAO_REQUIRE_CAS \
-DPULSE_LOCALEDIR=\"$(pulselocaledir)\" \
-DPA_MACHINE_ID=\"$(localstatedir)/lib/dbus/machine-id\" \
- -DPA_ALSA_PATHS_PATH=\"/home/lennart/projects/pulseaudio/src/modules/alsa/mixer/paths\" \
- -DPA_ALSA_PROFILES_PATH=\"/home/lennart/projects/pulseaudio/src/modules/alsa/mixer/profiles\"
+ -DPA_ALSA_PATHS_DIR=\"/home/lennart/projects/pulseaudio/src/modules/alsa/mixer/paths\" \
+ -DPA_ALSA_PROFILE_SETS_DIR=\"/home/lennart/projects/pulseaudio/src/modules/alsa/mixer/profile-sets\"
AM_LIBADD = $(PTHREAD_LIBS) $(INTLLIBS)
AM_LDADD = $(PTHREAD_LIBS) $(INTLLIBS)
diff --git a/src/daemon/main.c b/src/daemon/main.c
index 58f8d66..8058e12 100644
--- a/src/daemon/main.c
+++ b/src/daemon/main.c
@@ -930,6 +930,11 @@ int main(int argc, char *argv[]) {
pa_log_info(_("Running in system mode: %s"), pa_yes_no(pa_in_system_mode()));
+ if (pa_in_system_mode())
+ pa_log_warn(_("OK, so you are running PA in system mode. Please note that you most likely shouldn't be doing that.\n"
+ "If you do it nonetheless then it's your own fault if things don't work as expected.\n"
+ "Please read http://pulseaudio.org/wiki/WhatIsWrongWithSystemMode for an explanation why system mode is usually a bad idea."));
+
if (conf->use_pid_file) {
int z;
diff --git a/src/map-file b/src/map-file
index ba8b5c3..6f8946c 100644
--- a/src/map-file
+++ b/src/map-file
@@ -265,7 +265,9 @@ pa_stream_writable_size;
pa_stream_write;
pa_strerror;
pa_sw_cvolume_divide;
+pa_sw_cvolume_divide_scalar;
pa_sw_cvolume_multiply;
+pa_sw_cvolume_multiply_scalar;
pa_sw_cvolume_snprint_dB;
pa_sw_volume_divide;
pa_sw_volume_from_dB;
diff --git a/src/modules/alsa/alsa-mixer.c b/src/modules/alsa/alsa-mixer.c
index a30fdc2..02e1fcc 100644
--- a/src/modules/alsa/alsa-mixer.c
+++ b/src/modules/alsa/alsa-mixer.c
@@ -28,6 +28,10 @@
#include <limits.h>
#include <asoundlib.h>
+#ifdef HAVE_VALGRIND_MEMCHECK_H
+#include <valgrind/memcheck.h>
+#endif
+
#include <pulse/sample.h>
#include <pulse/xmalloc.h>
#include <pulse/timeval.h>
@@ -239,9 +243,8 @@ int pa_alsa_fdlist_set_mixer(struct pa_alsa_fdlist *fdl, snd_mixer_t *mixer_hand
return 0;
}
-int pa_alsa_prepare_mixer(snd_mixer_t *mixer, const char *dev) {
+static int prepare_mixer(snd_mixer_t *mixer, const char *dev) {
int err;
- pa_alsa_profile_set *ps;
pa_assert(mixer);
pa_assert(dev);
@@ -262,237 +265,58 @@ int pa_alsa_prepare_mixer(snd_mixer_t *mixer, const char *dev) {
}
pa_log_info("Successfully attached to mixer '%s'", dev);
-
- ps = pa_alsa_profile_set_new(NULL);
-
- if (ps) {
- pa_sample_spec ss;
- pa_alsa_path_set *paths;
-
- ss.channels = 2;
- ss.rate = 44100;
- ss.format = PA_SAMPLE_S16NE;
- pa_alsa_profile_set_probe(ps, "Audio", &ss);
- pa_alsa_profile_set_drop_unsupported(ps);
- pa_alsa_profile_set_dump(ps);
-
- if ((paths = pa_alsa_path_set_new(pa_hashmap_first(ps->mappings), PA_ALSA_DIRECTION_OUTPUT))) {
- pa_alsa_path_set_dump(paths);
- pa_alsa_path_set_probe(paths, mixer);
- pa_alsa_path_set_drop_unsupported(paths);
- pa_alsa_path_set_dump(paths);
- pa_alsa_path_set_free(paths);
-
- }
-
- pa_alsa_profile_set_free(ps);
- }
-
return 0;
}
-static pa_bool_t elem_has_volume(snd_mixer_elem_t *elem, pa_bool_t playback) {
- pa_assert(elem);
-
- if (playback && snd_mixer_selem_has_playback_volume(elem))
- return TRUE;
-
- if (!playback && snd_mixer_selem_has_capture_volume(elem))
- return TRUE;
-
- return FALSE;
-}
-
-static pa_bool_t elem_has_switch(snd_mixer_elem_t *elem, pa_bool_t playback) {
- pa_assert(elem);
-
- if (playback && snd_mixer_selem_has_playback_switch(elem))
- return TRUE;
-
- if (!playback && snd_mixer_selem_has_capture_switch(elem))
- return TRUE;
-
- return FALSE;
-}
-
-snd_mixer_elem_t *pa_alsa_find_elem(snd_mixer_t *mixer, const char *name, const char *fallback, pa_bool_t playback) {
- snd_mixer_elem_t *elem = NULL, *fallback_elem = NULL;
- snd_mixer_selem_id_t *sid = NULL;
-
- snd_mixer_selem_id_alloca(&sid);
-
- pa_assert(mixer);
- pa_assert(name);
-
- snd_mixer_selem_id_set_name(sid, name);
- snd_mixer_selem_id_set_index(sid, 0);
-
- if ((elem = snd_mixer_find_selem(mixer, sid))) {
-
- if (elem_has_volume(elem, playback) &&
- elem_has_switch(elem, playback))
- goto success;
-
- if (!elem_has_volume(elem, playback) &&
- !elem_has_switch(elem, playback))
- elem = NULL;
- }
-
- pa_log_info("Cannot find mixer control \"%s\" or mixer control is no combination of switch/volume.", snd_mixer_selem_id_get_name(sid));
-
- if (fallback) {
- snd_mixer_selem_id_set_name(sid, fallback);
- snd_mixer_selem_id_set_index(sid, 0);
-
- if ((fallback_elem = snd_mixer_find_selem(mixer, sid))) {
-
- if (elem_has_volume(fallback_elem, playback) &&
- elem_has_switch(fallback_elem, playback)) {
- elem = fallback_elem;
- goto success;
- }
-
- if (!elem_has_volume(fallback_elem, playback) &&
- !elem_has_switch(fallback_elem, playback))
- fallback_elem = NULL;
- }
-
- pa_log_info("Cannot find fallback mixer control \"%s\" or mixer control is no combination of switch/volume.", snd_mixer_selem_id_get_name(sid));
- }
-
- if (elem && fallback_elem) {
-
- /* Hmm, so we have both elements, but neither has both mute
- * and volume. Let's prefer the one with the volume */
-
- if (elem_has_volume(elem, playback))
- goto success;
-
- if (elem_has_volume(fallback_elem, playback)) {
- elem = fallback_elem;
- goto success;
- }
- }
-
- if (!elem && fallback_elem)
- elem = fallback_elem;
-
-success:
-
- if (elem)
- pa_log_info("Using mixer control \"%s\".", snd_mixer_selem_id_get_name(sid));
-
- return elem;
-}
-
-int pa_alsa_find_mixer_and_elem(
- snd_pcm_t *pcm,
- char **ctl_device,
- snd_mixer_t **_m,
- snd_mixer_elem_t **_e,
- const char *control_name,
- const pa_alsa_profile_info *profile) {
-
+snd_mixer_t *pa_alsa_open_mixer_for_pcm(snd_pcm_t *pcm, char **ctl_device) {
int err;
snd_mixer_t *m;
- snd_mixer_elem_t *e;
- pa_bool_t found = FALSE;
const char *dev;
+ snd_pcm_info_t* info;
+ snd_pcm_info_alloca(&info);
pa_assert(pcm);
- pa_assert(_m);
- pa_assert(_e);
-
- if (control_name && *control_name == 0) {
- pa_log_debug("Hardware mixer usage disabled because empty control name passed");
- return -1;
- }
if ((err = snd_mixer_open(&m, 0)) < 0) {
pa_log("Error opening mixer: %s", pa_alsa_strerror(err));
- return -1;
+ return NULL;
}
/* First, try by name */
if ((dev = snd_pcm_name(pcm)))
- if (pa_alsa_prepare_mixer(m, dev) >= 0) {
- found = TRUE;
-
+ if (prepare_mixer(m, dev) >= 0) {
if (ctl_device)
*ctl_device = pa_xstrdup(dev);
+
+ return m;
}
/* 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 (snd_pcm_info(pcm, info) >= 0) {
- char *md;
- int card_idx;
+ if ((card_idx = snd_pcm_info_get_card(info)) >= 0) {
- if ((card_idx = snd_pcm_info_get_card(info)) >= 0) {
+ md = pa_sprintf_malloc("hw:%i", card_idx);
- md = pa_sprintf_malloc("hw:%i", card_idx);
+ if (!dev || !pa_streq(dev, md))
+ if (prepare_mixer(m, md) >= 0) {
- if (!dev || !pa_streq(dev, md))
- if (pa_alsa_prepare_mixer(m, md) >= 0) {
- found = TRUE;
+ if (ctl_device)
+ *ctl_device = md;
+ else
+ pa_xfree(md);
- if (ctl_device) {
- *ctl_device = md;
- md = NULL;
- }
- }
+ return m;
+ }
- pa_xfree(md);
- }
+ pa_xfree(md);
}
}
- if (!found) {
- snd_mixer_close(m);
- return -1;
- }
-
- switch (snd_pcm_stream(pcm)) {
-
- case SND_PCM_STREAM_PLAYBACK:
- if (control_name)
- e = pa_alsa_find_elem(m, control_name, NULL, TRUE);
- else if (profile)
- e = pa_alsa_find_elem(m, profile->playback_control_name, profile->playback_control_fallback, TRUE);
- else
- e = pa_alsa_find_elem(m, "Master", "PCM", TRUE);
- break;
-
- case SND_PCM_STREAM_CAPTURE:
- if (control_name)
- e = pa_alsa_find_elem(m, control_name, NULL, FALSE);
- else if (profile)
- e = pa_alsa_find_elem(m, profile->record_control_name, profile->record_control_fallback, FALSE);
- else
- e = pa_alsa_find_elem(m, "Capture", "Mic", FALSE);
- break;
-
- default:
- pa_assert_not_reached();
- }
-
- if (!e) {
- if (ctl_device)
- pa_xfree(*ctl_device);
-
- snd_mixer_close(m);
- return -1;
- }
-
- pa_assert(e && m);
-
- *_m = m;
- *_e = e;
-
- return 0;
+ snd_mixer_close(m);
+ return NULL;
}
static const snd_mixer_selem_channel_id_t alsa_channel_ids[PA_CHANNEL_POSITION_MAX] = {
@@ -558,63 +382,6 @@ static const snd_mixer_selem_channel_id_t alsa_channel_ids[PA_CHANNEL_POSITION_M
[PA_CHANNEL_POSITION_TOP_REAR_RIGHT] = SND_MIXER_SCHN_UNKNOWN
};
-
-int pa_alsa_calc_mixer_map(snd_mixer_elem_t *elem, const pa_channel_map *channel_map, snd_mixer_selem_channel_id_t mixer_map[], pa_bool_t playback) {
- unsigned i;
- pa_bool_t alsa_channel_used[SND_MIXER_SCHN_LAST];
- pa_bool_t mono_used = FALSE;
-
- pa_assert(elem);
- pa_assert(channel_map);
- pa_assert(mixer_map);
-
- memset(&alsa_channel_used, 0, sizeof(alsa_channel_used));
-
- if (channel_map->channels > 1 &&
- ((playback && snd_mixer_selem_has_playback_volume_joined(elem)) ||
- (!playback && snd_mixer_selem_has_capture_volume_joined(elem)))) {
- pa_log_info("ALSA device lacks independant volume controls for each channel.");
- return -1;
- }
-
- for (i = 0; i < channel_map->channels; i++) {
- snd_mixer_selem_channel_id_t id;
- pa_bool_t is_mono;
-
- is_mono = channel_map->map[i] == PA_CHANNEL_POSITION_MONO;
- id = alsa_channel_ids[channel_map->map[i]];
-
- if (!is_mono && id == SND_MIXER_SCHN_UNKNOWN) {
- pa_log_info("Configured channel map contains channel '%s' that is unknown to the ALSA mixer.", pa_channel_position_to_string(channel_map->map[i]));
- return -1;
- }
-
- if ((is_mono && mono_used) || (!is_mono && alsa_channel_used[id])) {
- pa_log_info("Channel map has duplicate channel '%s', falling back to software volume control.", pa_channel_position_to_string(channel_map->map[i]));
- return -1;
- }
-
- if ((playback && (!snd_mixer_selem_has_playback_channel(elem, id) || (is_mono && !snd_mixer_selem_is_playback_mono(elem)))) ||
- (!playback && (!snd_mixer_selem_has_capture_channel(elem, id) || (is_mono && !snd_mixer_selem_is_capture_mono(elem))))) {
-
- pa_log_info("ALSA device lacks separate volumes control for channel '%s'", pa_channel_position_to_string(channel_map->map[i]));
- return -1;
- }
-
- if (is_mono) {
- mixer_map[i] = SND_MIXER_SCHN_MONO;
- mono_used = TRUE;
- } else {
- mixer_map[i] = id;
- alsa_channel_used[id] = TRUE;
- }
- }
-
- pa_log_info("All %u channels can be mapped to mixer channels.", channel_map->channels);
-
- return 0;
-}
-
static void setting_free(pa_alsa_setting *s) {
pa_assert(s);
@@ -681,6 +448,10 @@ void pa_alsa_path_set_free(pa_alsa_path_set *ps) {
pa_xfree(ps);
}
+int pa_alsa_setting_select(pa_alsa_setting *s, snd_mixer_t *m) {
+ return 0;
+}
+
static long to_alsa_dB(pa_volume_t v) {
return (long) (pa_sw_volume_to_dB(v) * 100.0);
}
@@ -720,8 +491,10 @@ static int element_get_volume(pa_alsa_element *e, snd_mixer_t *m, const pa_chann
pa_assert(v);
SELEM_INIT(sid, e->alsa_name);
- if (!(me = snd_mixer_find_selem(m, sid)))
+ if (!(me = snd_mixer_find_selem(m, sid))) {
+ pa_log_warn("Element %s seems to have disappeared.", e->alsa_name);
return -1;
+ }
pa_cvolume_mute(v, cm->channels);
@@ -742,6 +515,10 @@ static int element_get_volume(pa_alsa_element *e, snd_mixer_t *m, const pa_chann
if (r < 0)
continue;
+#ifdef HAVE_VALGRIND_MEMCHECK_H
+ VALGRIND_MAKE_MEM_DEFINED(&value, sizeof(value));
+#endif
+
f = from_alsa_dB(value);
} else {
@@ -819,8 +596,10 @@ static int element_get_switch(pa_alsa_element *e, snd_mixer_t *m, pa_bool_t *b)
pa_assert(b);
SELEM_INIT(sid, e->alsa_name);
- if (!(me = snd_mixer_find_selem(m, sid)))
+ if (!(me = snd_mixer_find_selem(m, sid))) {
+ pa_log_warn("Element %s seems to have disappeared.", e->alsa_name);
return -1;
+ }
/* We return muted if at least one channel is muted */
@@ -890,8 +669,10 @@ static int element_set_volume(pa_alsa_element *e, snd_mixer_t *m, const pa_chann
pa_assert(pa_cvolume_compatible_with_channel_map(v, cm));
SELEM_INIT(sid, e->alsa_name);
- if (!(me = snd_mixer_find_selem(m, sid)))
+ if (!(me = snd_mixer_find_selem(m, sid))) {
+ pa_log_warn("Element %s seems to have disappeared.", e->alsa_name);
return -1;
+ }
pa_cvolume_mute(&rv, cm->channels);
@@ -918,6 +699,10 @@ static int element_set_volume(pa_alsa_element *e, snd_mixer_t *m, const pa_chann
if (r < 0)
continue;
+#ifdef HAVE_VALGRIND_MEMCHECK_H
+ VALGRIND_MAKE_MEM_DEFINED(&value, sizeof(value));
+#endif
+
f = from_alsa_dB(value);
} else {
@@ -1005,8 +790,10 @@ static int element_set_switch(pa_alsa_element *e, snd_mixer_t *m, pa_bool_t b) {
pa_assert(b);
SELEM_INIT(sid, e->alsa_name);
- if (!(me = snd_mixer_find_selem(m, sid)))
+ if (!(me = snd_mixer_find_selem(m, sid))) {
+ pa_log_warn("Element %s seems to have disappeared.", e->alsa_name);
return -1;
+ }
if (e->direction == PA_ALSA_DIRECTION_OUTPUT)
r = snd_mixer_selem_set_playback_switch_all(me, b);
@@ -1014,9 +801,9 @@ static int element_set_switch(pa_alsa_element *e, snd_mixer_t *m, pa_bool_t b) {
r = snd_mixer_selem_set_capture_switch_all(me, b);
if (r < 0)
- return -1;
+ pa_log_warn("Faile to set switch of %s: %s", e->alsa_name, pa_alsa_strerror(errno));
- return 0;
+ return r;
}
int pa_alsa_path_set_mute(pa_alsa_path *p, snd_mixer_t *m, pa_bool_t muted) {
@@ -1049,14 +836,19 @@ static int element_mute_volume(pa_alsa_element *e, snd_mixer_t *m) {
pa_assert(e);
SELEM_INIT(sid, e->alsa_name);
- if (!(me = snd_mixer_find_selem(m, sid)))
+ if (!(me = snd_mixer_find_selem(m, sid))) {
+ pa_log_warn("Element %s seems to have disappeared.", e->alsa_name);
return -1;
+ }
if (e->direction == PA_ALSA_DIRECTION_OUTPUT)
r = snd_mixer_selem_set_playback_volume_all(me, e->min_volume);
else
r = snd_mixer_selem_set_capture_volume_all(me, e->min_volume);
+ if (r < 0)
+ pa_log_warn("Faile to set volume to muted of %s: %s", e->alsa_name, pa_alsa_strerror(errno));
+
return r;
}
@@ -1070,14 +862,19 @@ static int element_zero_volume(pa_alsa_element *e, snd_mixer_t *m) {
pa_assert(e);
SELEM_INIT(sid, e->alsa_name);
- if (!(me = snd_mixer_find_selem(m, sid)))
+ if (!(me = snd_mixer_find_selem(m, sid))) {
+ pa_log_warn("Element %s seems to have disappeared.", e->alsa_name);
return -1;
+ }
if (e->direction == PA_ALSA_DIRECTION_OUTPUT)
r = snd_mixer_selem_set_playback_dB_all(me, 0, +1);
else
r = snd_mixer_selem_set_capture_dB_all(me, 0, +1);
+ if (r < 0)
+ pa_log_warn("Faile to set volume to 0dB of %s: %s", e->alsa_name, pa_alsa_strerror(errno));
+
return r;
}
@@ -1088,6 +885,9 @@ int pa_alsa_path_select(pa_alsa_path *p, snd_mixer_t *m) {
pa_assert(m);
pa_assert(p);
+ pa_log_debug("Activating path %s", p->name);
+ pa_alsa_path_dump(p);
+
PA_LLIST_FOREACH(e, p->elements) {
switch (e->switch_use) {
@@ -1248,8 +1048,8 @@ static int element_probe(pa_alsa_element *e, snd_mixer_t *m) {
if (e->volume_use != PA_ALSA_VOLUME_IGNORE) {
long min_dB = 0, max_dB = 0;
- pa_channel_position_t p;
- pa_bool_t is_mono;
+ int r;
+
e->direction_try_other = FALSE;
if (e->direction == PA_ALSA_DIRECTION_OUTPUT)
@@ -1258,70 +1058,92 @@ static int element_probe(pa_alsa_element *e, snd_mixer_t *m) {
e->has_dB = snd_mixer_selem_get_capture_dB_range(me, &min_dB, &max_dB) >= 0;
if (e->has_dB) {
+#ifdef HAVE_VALGRIND_MEMCHECK_H
+ VALGRIND_MAKE_MEM_DEFINED(&min_dB, sizeof(min_dB));
+ VALGRIND_MAKE_MEM_DEFINED(&max_dB, sizeof(max_dB));
+#endif
+
e->min_dB = ((double) min_dB) / 100.0;
e->max_dB = ((double) max_dB) / 100.0;
- }
- if (e->direction == PA_ALSA_DIRECTION_OUTPUT) {
- if (snd_mixer_selem_get_playback_volume_range(me, &e->min_volume, &e->max_volume) < 0)
- return -1;
- } else {
- if (snd_mixer_selem_get_capture_volume_range(me, &e->min_volume, &e->max_volume) < 0)
- return -1;
+ if (min_dB >= max_dB) {
+ pa_log_warn("Your kernel driver is broken: it reports a volume range from %0.2f dB to %0.2f dB which makes no sense.", e->min_dB, e->max_dB);
+ e->has_dB = FALSE;
+ }
}
if (e->direction == PA_ALSA_DIRECTION_OUTPUT)
- is_mono = snd_mixer_selem_is_playback_mono(me) > 0;
+ r = snd_mixer_selem_get_playback_volume_range(me, &e->min_volume, &e->max_volume);
else
- is_mono = snd_mixer_selem_is_capture_mono(me) > 0;
+ r = snd_mixer_selem_get_capture_volume_range(me, &e->min_volume, &e->max_volume);
- if (is_mono) {
- e->n_channels = 1;
+ if (r < 0) {
+ pa_log_warn("Failed to get volume range of %s: %s", e->alsa_name, pa_alsa_strerror(r));
+ return -1;
+ }
- if (!e->override_map) {
- for (p = PA_CHANNEL_POSITION_FRONT_LEFT; p < PA_CHANNEL_POSITION_MAX; p++)
- e->masks[alsa_channel_ids[p]][e->n_channels-1] = 0;
- e->masks[SND_MIXER_SCHN_MONO][e->n_channels-1] = PA_CHANNEL_POSITION_MASK_ALL;
- }
- e->merged_mask = e->masks[SND_MIXER_SCHN_MONO][e->n_channels-1];
+ if (e->min_volume >= e->max_volume) {
+ pa_log_warn("Your kernel driver is broken: it reports a volume range from %li to %li which makes no sense.", e->min_volume, e->max_volume);
+ e->volume_use = PA_ALSA_VOLUME_IGNORE;
+
} else {
- e->n_channels = 0;
- for (p = PA_CHANNEL_POSITION_FRONT_LEFT; p < PA_CHANNEL_POSITION_MAX; p++) {
+ pa_bool_t is_mono;
+ pa_channel_position_t p;
- if (alsa_channel_ids[p] == SND_MIXER_SCHN_UNKNOWN)
- continue;
+ if (e->direction == PA_ALSA_DIRECTION_OUTPUT)
+ is_mono = snd_mixer_selem_is_playback_mono(me) > 0;
+ else
+ is_mono = snd_mixer_selem_is_capture_mono(me) > 0;
- if (e->direction == PA_ALSA_DIRECTION_OUTPUT)
- e->n_channels += snd_mixer_selem_has_playback_channel(me, alsa_channel_ids[p]) > 0;
- else
- e->n_channels += snd_mixer_selem_has_capture_channel(me, alsa_channel_ids[p]) > 0;
- }
+ if (is_mono) {
+ e->n_channels = 1;
- if (e->n_channels <= 0) {
- pa_log_warn("Volume element with no channels?");
- return -1;
- }
+ if (!e->override_map) {
+ for (p = PA_CHANNEL_POSITION_FRONT_LEFT; p < PA_CHANNEL_POSITION_MAX; p++)
+ e->masks[alsa_channel_ids[p]][e->n_channels-1] = 0;
+ e->masks[SND_MIXER_SCHN_MONO][e->n_channels-1] = PA_CHANNEL_POSITION_MASK_ALL;
+ }
- if (!e->override_map) {
+ e->merged_mask = e->masks[SND_MIXER_SCHN_MONO][e->n_channels-1];
+ } else {
+ e->n_channels = 0;
for (p = PA_CHANNEL_POSITION_FRONT_LEFT; p < PA_CHANNEL_POSITION_MAX; p++) {
- pa_bool_t has_channel;
if (alsa_channel_ids[p] == SND_MIXER_SCHN_UNKNOWN)
continue;
if (e->direction == PA_ALSA_DIRECTION_OUTPUT)
- has_channel = snd_mixer_selem_has_playback_channel(me, alsa_channel_ids[p]) > 0;
+ e->n_channels += snd_mixer_selem_has_playback_channel(me, alsa_channel_ids[p]) > 0;
else
- has_channel = snd_mixer_selem_has_capture_channel(me, alsa_channel_ids[p]) > 0;
+ e->n_channels += snd_mixer_selem_has_capture_channel(me, alsa_channel_ids[p]) > 0;
+ }
- e->masks[alsa_channel_ids[p]][e->n_channels-1] = has_channel ? PA_CHANNEL_POSITION_MASK(p) : 0;
+ if (e->n_channels <= 0) {
+ pa_log_warn("Volume element %s with no channels?", e->alsa_name);
+ return -1;
}
- }
- e->merged_mask = 0;
- for (p = PA_CHANNEL_POSITION_FRONT_LEFT; p < PA_CHANNEL_POSITION_MAX; p++)
- e->merged_mask |= e->masks[alsa_channel_ids[p]][e->n_channels-1];
+ if (!e->override_map) {
+ for (p = PA_CHANNEL_POSITION_FRONT_LEFT; p < PA_CHANNEL_POSITION_MAX; p++) {
+ pa_bool_t has_channel;
+
+ if (alsa_channel_ids[p] == SND_MIXER_SCHN_UNKNOWN)
+ continue;
+
+ if (e->direction == PA_ALSA_DIRECTION_OUTPUT)
+ has_channel = snd_mixer_selem_has_playback_channel(me, alsa_channel_ids[p]) > 0;
+ else
+ has_channel = snd_mixer_selem_has_capture_channel(me, alsa_channel_ids[p]) > 0;
+
+ e->masks[alsa_channel_ids[p]][e->n_channels-1] = has_channel ? PA_CHANNEL_POSITION_MASK(p) : 0;
+ }
+ }
+
+ e->merged_mask = 0;
+ for (p = PA_CHANNEL_POSITION_FRONT_LEFT; p < PA_CHANNEL_POSITION_MAX; p++)
+ e->merged_mask |= e->masks[alsa_channel_ids[p]][e->n_channels-1];
+ }
}
}
}
@@ -1877,7 +1699,7 @@ pa_alsa_path* pa_alsa_path_new(const char *fname, pa_alsa_direction_t direction)
items[1].data = &p->description;
items[2].data = &p->name;
- fn = pa_maybe_prefix_path(fname, PA_ALSA_PATHS_PATH);
+ fn = pa_maybe_prefix_path(fname, PA_ALSA_PATHS_DIR);
r = pa_config_parse(fn, NULL, items, p);
pa_xfree(fn);
@@ -1916,7 +1738,42 @@ pa_alsa_path* pa_alsa_path_synthesize(const char*element, pa_alsa_direction_t di
return p;
}
-int pa_alsa_path_probe(pa_alsa_path *p, snd_mixer_t *m) {
+static pa_bool_t element_drop_unsupported(pa_alsa_element *e) {
+ pa_alsa_option *o, *n;
+
+ pa_assert(e);
+
+ for (o = e->options; o; o = n) {
+ n = o->next;
+
+ if (o->alsa_idx < 0) {
+ PA_LLIST_REMOVE(pa_alsa_option, e->options, o);
+ option_free(o);
+ }
+ }
+
+ return
+ e->switch_use != PA_ALSA_SWITCH_IGNORE ||
+ e->volume_use != PA_ALSA_VOLUME_IGNORE ||
+ e->enumeration_use != PA_ALSA_ENUMERATION_IGNORE;
+}
+
+static void path_drop_unsupported(pa_alsa_path *p) {
+ pa_alsa_element *e, *n;
+
+ pa_assert(p);
+
+ for (e = p->elements; e; e = n) {
+ n = e->next;
+
+ if (!element_drop_unsupported(e)) {
+ PA_LLIST_REMOVE(pa_alsa_element, p->elements, e);
+ element_free(e);
+ }
+ }
+}
+
+int pa_alsa_path_probe(pa_alsa_path *p, snd_mixer_t *m, pa_bool_t ignore_dB) {
pa_alsa_element *e;
double min_dB[PA_CHANNEL_POSITION_MAX], max_dB[PA_CHANNEL_POSITION_MAX];
pa_channel_position_t t;
@@ -1939,6 +1796,9 @@ int pa_alsa_path_probe(pa_alsa_path *p, snd_mixer_t *m) {
return -1;
}
+ if (ignore_dB)
+ e->has_dB = FALSE;
+
if (e->volume_use == PA_ALSA_VOLUME_MERGE) {
if (!p->has_volume) {
@@ -1980,6 +1840,8 @@ int pa_alsa_path_probe(pa_alsa_path *p, snd_mixer_t *m) {
p->has_mute = TRUE;
}
+ path_drop_unsupported(p);
+
p->supported = TRUE;
p->probed = TRUE;
@@ -1996,43 +1858,6 @@ int pa_alsa_path_probe(pa_alsa_path *p, snd_mixer_t *m) {
return 0;
}
-static pa_bool_t element_drop_unsupported(pa_alsa_element *e) {
- pa_alsa_option *o, *n;
-
- pa_assert(e);
-
- for (o = e->options; o; o = n) {
- n = o->next;
-
- if (o->alsa_idx < 0) {
- PA_LLIST_REMOVE(pa_alsa_option, e->options, o);
- option_free(o);
- }
- }
-
- return
- e->switch_use != PA_ALSA_SWITCH_IGNORE ||
- e->volume_use != PA_ALSA_VOLUME_IGNORE ||
- e->enumeration_use != PA_ALSA_ENUMERATION_IGNORE;
-}
-
-pa_bool_t pa_alsa_path_drop_unsupported(pa_alsa_path *p) {
- pa_alsa_element *e, *n;
-
- pa_assert(p);
-
- for (e = p->elements; e; e = n) {
- n = e->next;
-
- if (!element_drop_unsupported(e)) {
- PA_LLIST_REMOVE(pa_alsa_element, p->elements, e);
- element_free(e);
- }
- }
-
- return !!p->elements;
-}
-
void pa_alsa_setting_dump(pa_alsa_setting *s) {
pa_assert(s);
@@ -2099,6 +1924,46 @@ void pa_alsa_path_dump(pa_alsa_path *p) {
pa_alsa_setting_dump(s);
}
+static void element_set_callback(pa_alsa_element *e, snd_mixer_t *m, snd_mixer_elem_callback_t cb, void *userdata) {
+ snd_mixer_selem_id_t *sid;
+ snd_mixer_elem_t *me;
+
+ pa_assert(e);
+ pa_assert(m);
+ pa_assert(cb);
+
+ SELEM_INIT(sid, e->alsa_name);
+ if (!(me = snd_mixer_find_selem(m, sid))) {
+ pa_log_warn("Element %s seems to have disappeared.", e->alsa_name);
+ return;
+ }
+
+ snd_mixer_elem_set_callback(me, cb);
+ snd_mixer_elem_set_callback_private(me, userdata);
+}
+
+void pa_alsa_path_set_callback(pa_alsa_path *p, snd_mixer_t *m, snd_mixer_elem_callback_t cb, void *userdata) {
+ pa_alsa_element *e;
+
+ pa_assert(p);
+ pa_assert(m);
+ pa_assert(cb);
+
+ PA_LLIST_FOREACH(e, p->elements)
+ element_set_callback(e, m, cb, userdata);
+}
+
+void pa_alsa_path_set_set_callback(pa_alsa_path_set *ps, snd_mixer_t *m, snd_mixer_elem_callback_t cb, void *userdata) {
+ pa_alsa_path *p;
+
+ pa_assert(ps);
+ pa_assert(m);
+ pa_assert(cb);
+
+ PA_LLIST_FOREACH(p, ps->paths)
+ pa_alsa_path_set_callback(p, m, cb, userdata);
+}
+
pa_alsa_path_set *pa_alsa_path_set_new(pa_alsa_mapping *m, pa_alsa_direction_t direction) {
pa_alsa_path_set *ps;
char **pn = NULL, **en = NULL, **ie;
@@ -2118,10 +1983,23 @@ pa_alsa_path_set *pa_alsa_path_set_new(pa_alsa_mapping *m, pa_alsa_direction_t d
pn = m->input_path_names;
if (pn) {
+ char **in;
- for (; *pn; pn++) {
+ for (in = pn; *in; in++) {
pa_alsa_path *p;
- char *fn = pa_sprintf_malloc("%s.conf", *pn);
+ pa_bool_t duplicate = FALSE;
+ char **kn, *fn;
+
+ for (kn = pn; kn != in; kn++)
+ if (pa_streq(*kn, *in)) {
+ duplicate = TRUE;
+ break;
+ }
+
+ if (duplicate)
+ continue;
+
+ fn = pa_sprintf_malloc("%s.conf", *in);
if ((p = pa_alsa_path_new(fn, direction))) {
p->path_set = ps;
@@ -2169,47 +2047,81 @@ pa_alsa_path_set *pa_alsa_path_set_new(pa_alsa_mapping *m, pa_alsa_direction_t d
return ps;
}
-void pa_alsa_path_set_probe(pa_alsa_path_set *ps, snd_mixer_t *m) {
+void pa_alsa_path_set_dump(pa_alsa_path_set *ps) {
pa_alsa_path *p;
-
pa_assert(ps);
- if (ps->probed)
- return;
+ pa_log_debug("Path Set %p, direction=%i, probed=%s",
+ (void*) ps,
+ ps->direction,
+ pa_yes_no(ps->probed));
PA_LLIST_FOREACH(p, ps->paths)
- pa_alsa_path_probe(p, m);
-
- ps->probed = TRUE;
+ pa_alsa_path_dump(p);
}
-void pa_alsa_path_set_drop_unsupported(pa_alsa_path_set *ps) {
- pa_alsa_path *p, *n;
+static void path_set_unify(pa_alsa_path_set *ps) {
+ pa_alsa_path *p;
+ pa_bool_t has_dB = TRUE, has_volume = TRUE, has_mute = TRUE;
pa_assert(ps);
- for (p = ps->paths; p; p = n) {
- n = p->next;
+ /* We have issues dealing with paths that vary too wildly. That
+ * means for now we have to have all paths support volume/mute/dB
+ * or none. */
- if (p->supported &&
- pa_alsa_path_drop_unsupported(p))
- continue;
+ PA_LLIST_FOREACH(p, ps->paths) {
+ pa_assert(p->probed);
- PA_LLIST_REMOVE(pa_alsa_path, ps->paths, p);
- pa_alsa_path_free(p);
+ if (!p->has_volume)
+ has_volume = FALSE;
+ else if (!p->has_dB)
+ has_dB = FALSE;
+
+ if (!p->has_mute)
+ has_mute = FALSE;
+ }
+
+ if (!has_volume || !has_dB || !has_mute) {
+
+ if (!has_volume)
+ pa_log_debug("Some paths of the device lack hardware volume control, disabling hardware control altogether.");
+ else if (!has_dB)
+ pa_log_debug("Some paths of the device lack dB information, disabling dB logic altogether.");
+
+ if (!has_mute)
+ pa_log_debug("Some paths of the device lack hardware mute control, disabling hardware control altogether.");
+
+ PA_LLIST_FOREACH(p, ps->paths) {
+ if (!has_volume)
+ p->has_volume = FALSE;
+ else if (!has_dB)
+ p->has_dB = FALSE;
+
+ if (!has_mute)
+ p->has_mute = FALSE;
+ }
}
}
-void pa_alsa_path_set_dump(pa_alsa_path_set *ps) {
- pa_alsa_path *p;
+void pa_alsa_path_set_probe(pa_alsa_path_set *ps, snd_mixer_t *m, pa_bool_t ignore_dB) {
+ pa_alsa_path *p, *n;
+
pa_assert(ps);
- pa_log_debug("Path Set %p, direction=%i, probed=%s",
- (void*) ps,
- ps->direction,
- pa_yes_no(ps->probed));
+ if (ps->probed)
+ return;
- PA_LLIST_FOREACH(p, ps->paths)
- pa_alsa_path_dump(p);
+ for (p = ps->paths; p; p = n) {
+ n = p->next;
+
+ if (pa_alsa_path_probe(p, m, ignore_dB) < 0) {
+ PA_LLIST_REMOVE(pa_alsa_path, ps->paths, p);
+ pa_alsa_path_free(p);
+ }
+ }
+
+ path_set_unify(ps);
+ ps->probed = TRUE;
}
static void mapping_free(pa_alsa_mapping *m) {
@@ -2583,7 +2495,7 @@ static int profile_parse_skip_probe(
return 0;
}
-static int mapping_verify(pa_alsa_mapping *m) {
+static int mapping_verify(pa_alsa_mapping *m, const pa_channel_map *bonus) {
static const struct description_map well_known_descriptions[] = {
{ "analog-mono", N_("Analog Mono") },
@@ -2632,6 +2544,13 @@ static int mapping_verify(pa_alsa_mapping *m) {
if (!m->description)
m->description = pa_xstrdup(m->name);
+ if (bonus) {
+ if (pa_channel_map_equal(&m->channel_map, bonus))
+ m->priority += 5000;
+ else if (m->channel_map.channels == bonus->channels)
+ m->priority += 4000;
+ }
+
return 0;
}
@@ -2719,6 +2638,7 @@ static int profile_verify(pa_alsa_profile *p) {
static const struct description_map well_known_descriptions[] = {
{ "output:analog-mono+input:analog-mono", N_("Analog Mono Duplex") },
{ "output:analog-stereo+input:analog-stereo", N_("Analog Stereo Duplex") },
+ { "off", N_("Off") }
};
pa_assert(p);
@@ -2732,6 +2652,17 @@ static int profile_verify(pa_alsa_profile *p) {
for (name = p->output_mapping_names; *name; name++) {
pa_alsa_mapping *m;
+ char **in;
+ pa_bool_t duplicate = FALSE;
+
+ for (in = p->output_mapping_names; *in; in++)
+ if (pa_streq(*name, *in)) {
+ duplicate = TRUE;
+ break;
+ }
+
+ if (duplicate)
+ continue;
if (!(m = pa_hashmap_get(p->profile_set->mappings, *name)) || m->direction == PA_ALSA_DIRECTION_INPUT) {
pa_log("Profile '%s' refers to unexistant mapping '%s'.", p->name, *name);
@@ -2754,6 +2685,17 @@ static int profile_verify(pa_alsa_profile *p) {
for (name = p->input_mapping_names; *name; name++) {
pa_alsa_mapping *m;
+ char **in;
+ pa_bool_t duplicate = FALSE;
+
+ for (in = p->input_mapping_names; *in; in++)
+ if (pa_streq(*name, *in)) {
+ duplicate = TRUE;
+ break;
+ }
+
+ if (duplicate)
+ continue;
if (!(m = pa_hashmap_get(p->profile_set->mappings, *name)) || m->direction == PA_ALSA_DIRECTION_OUTPUT) {
pa_log("Profile '%s' refers to unexistant mapping '%s'.", p->name, *name);
@@ -2828,7 +2770,7 @@ void pa_alsa_profile_dump(pa_alsa_profile *p) {
pa_log_debug("Output %s", m->name);
}
-pa_alsa_profile_set* pa_alsa_profile_set_new(const char *fname) {
+pa_alsa_profile_set* pa_alsa_profile_set_new(const char *fname, const pa_channel_map *bonus) {
pa_alsa_profile_set *ps;
pa_alsa_profile *p;
pa_alsa_mapping *m;
@@ -2869,7 +2811,7 @@ pa_alsa_profile_set* pa_alsa_profile_set_new(const char *fname) {
if (!fname)
fname = "default.conf";
- fn = pa_maybe_prefix_path(fname, PA_ALSA_PROFILES_PATH);
+ fn = pa_maybe_prefix_path(fname, PA_ALSA_PROFILE_SETS_DIR);
r = pa_config_parse(fn, NULL, items, ps);
pa_xfree(fn);
@@ -2877,7 +2819,7 @@ pa_alsa_profile_set* pa_alsa_profile_set_new(const char *fname) {
goto fail;
PA_HASHMAP_FOREACH(m, ps->mappings, state)
- if (mapping_verify(m) < 0)
+ if (mapping_verify(m, bonus) < 0)
goto fail;
if (ps->auto_profiles)
@@ -2894,49 +2836,6 @@ fail:
return NULL;
}
-static snd_pcm_t *open_by_device_string_strv(
- char **prefix,
- const char *dev_id,
- char **dev,
- pa_sample_spec *ss,
- pa_channel_map* map,
- int mode,
- uint32_t *nfrags,
- snd_pcm_uframes_t *period_size,
- snd_pcm_uframes_t tsched_size,
- pa_bool_t *use_mmap,
- pa_bool_t *use_tsched,
- pa_bool_t require_exact_channel_number) {
-
- snd_pcm_t *pcm_handle;
- char **i;
-
- for (i = prefix; *i; i++) {
- char *d;
-
- d = pa_sprintf_malloc("%s:%s", *prefix, dev_id);
-
- pcm_handle = pa_alsa_open_by_device_string(
- d,
- dev,
- ss,
- map,
- mode,
- nfrags,
- period_size,
- tsched_size,
- use_mmap,
- use_tsched,
- require_exact_channel_number);
- pa_xfree(d);
-
- if (pcm_handle)
- return pcm_handle;
- }
-
- return NULL;
-}
-
void pa_alsa_profile_set_probe(pa_alsa_profile_set *ps, const char *dev_id, const pa_sample_spec *ss) {
void *state;
pa_alsa_profile *p, *last = NULL;
@@ -3004,7 +2903,7 @@ void pa_alsa_profile_set_probe(pa_alsa_profile_set *ps, const char *dev_id, cons
try_ss = *ss;
try_map = m->channel_map;
- if (!(m ->output_pcm = open_by_device_string_strv(
+ if (!(m ->output_pcm = pa_alsa_open_by_device_string_strv(
m->device_strings,
dev_id,
NULL,
@@ -3027,7 +2926,7 @@ void pa_alsa_profile_set_probe(pa_alsa_profile_set *ps, const char *dev_id, cons
try_ss = *ss;
try_map = m->channel_map;
- if (!(m ->input_pcm = open_by_device_string_strv(
+ if (!(m ->input_pcm = pa_alsa_open_by_device_string_strv(
m->device_strings,
dev_id,
NULL,
@@ -3073,17 +2972,6 @@ void pa_alsa_profile_set_probe(pa_alsa_profile_set *ps, const char *dev_id, cons
}
}
- ps->probed = TRUE;
-}
-
-void pa_alsa_profile_set_drop_unsupported(pa_alsa_profile_set *ps) {
- pa_alsa_profile *p;
- pa_alsa_mapping *m;
- void *state;
-
- pa_assert(ps);
- pa_assert(ps->probed);
-
PA_HASHMAP_FOREACH(p, ps->profiles, state)
if (!p->supported) {
pa_hashmap_remove(ps->profiles, p->name);
@@ -3095,6 +2983,8 @@ void pa_alsa_profile_set_drop_unsupported(pa_alsa_profile_set *ps) {
pa_hashmap_remove(ps->mappings, m->name);
mapping_free(m);
}
+
+ ps->probed = TRUE;
}
void pa_alsa_profile_set_dump(pa_alsa_profile_set *ps) {
@@ -3118,3 +3008,89 @@ void pa_alsa_profile_set_dump(pa_alsa_profile_set *ps) {
PA_HASHMAP_FOREACH(p, ps->profiles, state)
pa_alsa_profile_dump(p);
}
+
+void pa_alsa_add_ports(pa_hashmap **p, pa_alsa_path_set *ps) {
+ pa_alsa_path *path;
+
+ pa_assert(p);
+ pa_assert(!*p);
+ pa_assert(ps);
+
+ /* if there is no path, we don't want a port list */
+ if (!ps->paths)
+ return;
+
+ if (!ps->paths->next){
+ pa_alsa_setting *s;
+
+ /* If there is only one path, but no or only one setting, then
+ * we want a port list either */
+ if (!ps->paths->settings || !ps->paths->settings->next)
+ return;
+
+ /* Ok, there is only one path, however with multiple settings,
+ * so let's create a port for each setting */
+ *p = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
+
+ PA_LLIST_FOREACH(s, ps->paths->settings) {
+ pa_device_port *port;
+ pa_alsa_port_data *data;
+
+ port = pa_device_port_new(s->name, s->description, sizeof(pa_alsa_port_data));
+
+ data = PA_DEVICE_PORT_DATA(port);
+ data->path = ps->paths;
+ data->setting = s;
+
+ pa_hashmap_put(*p, port->name, port);
+ }
+
+ } else {
+
+ /* We have multiple paths, so let's create a port for each
+ * one, and each of each settings */
+ *p = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
+
+ PA_LLIST_FOREACH(path, ps->paths) {
+
+ if (!path->settings || !path->settings->next) {
+ pa_device_port *port;
+ pa_alsa_port_data *data;
+
+ /* If there is no or just one setting we only need a
+ * single entry */
+
+ port = pa_device_port_new(path->name, path->description, sizeof(pa_alsa_port_data));
+ data = PA_DEVICE_PORT_DATA(port);
+ data->path = path;
+ data->setting = path->settings;
+
+ pa_hashmap_put(*p, port->name, port);
+ } else {
+ pa_alsa_setting *s;
+
+ PA_LLIST_FOREACH(s, path->settings) {
+ pa_device_port *port;
+ pa_alsa_port_data *data;
+ char *n, *d;
+
+ n = pa_sprintf_malloc("%s;%s", path->name, s->name);
+ d = pa_sprintf_malloc(_("%s, %s"), path->description, s->description);
+
+ port = pa_device_port_new(n, d, sizeof(pa_alsa_port_data));
+
+ pa_xfree(n);
+ pa_xfree(d);
+
+ data = PA_DEVICE_PORT_DATA(port);
+ data->path = path;
+ data->setting = s;
+
+ pa_hashmap_put(*p, port->name, port);
+ }
+ }
+ }
+ }
+
+ pa_log_debug("Added %u ports", pa_hashmap_size(*p));
+}
diff --git a/src/modules/alsa/alsa-mixer.h b/src/modules/alsa/alsa-mixer.h
index 836e901..f6b1c35 100644
--- a/src/modules/alsa/alsa-mixer.h
+++ b/src/modules/alsa/alsa-mixer.h
@@ -46,6 +46,7 @@ typedef struct pa_alsa_path_set pa_alsa_path_set;
typedef struct pa_alsa_mapping pa_alsa_mapping;
typedef struct pa_alsa_profile pa_alsa_profile;
typedef struct pa_alsa_profile_set pa_alsa_profile_set;
+typedef struct pa_alsa_port_data pa_alsa_port_data;
#include "alsa-util.h"
@@ -192,20 +193,20 @@ void pa_alsa_element_dump(pa_alsa_element *e);
pa_alsa_path *pa_alsa_path_new(const char *fname, pa_alsa_direction_t direction);
pa_alsa_path *pa_alsa_path_synthesize(const char *element, pa_alsa_direction_t direction);
-int pa_alsa_path_probe(pa_alsa_path *p, snd_mixer_t *m);
-pa_bool_t pa_alsa_path_drop_unsupported(pa_alsa_path *p);
+int pa_alsa_path_probe(pa_alsa_path *p, snd_mixer_t *m, pa_bool_t ignore_dB);
void pa_alsa_path_dump(pa_alsa_path *p);
int pa_alsa_path_get_volume(pa_alsa_path *p, snd_mixer_t *m, const pa_channel_map *cm, pa_cvolume *v);
int pa_alsa_path_get_mute(pa_alsa_path *path, snd_mixer_t *m, pa_bool_t *muted);
int pa_alsa_path_set_volume(pa_alsa_path *path, snd_mixer_t *m, const pa_channel_map *cm, pa_cvolume *v);
int pa_alsa_path_set_mute(pa_alsa_path *path, snd_mixer_t *m, pa_bool_t muted);
int pa_alsa_path_select(pa_alsa_path *p, snd_mixer_t *m);
+void pa_alsa_path_set_callback(pa_alsa_path *p, snd_mixer_t *m, snd_mixer_elem_callback_t cb, void *userdata);
void pa_alsa_path_free(pa_alsa_path *p);
pa_alsa_path_set *pa_alsa_path_set_new(pa_alsa_mapping *m, pa_alsa_direction_t direction);
-void pa_alsa_path_set_probe(pa_alsa_path_set *s, snd_mixer_t *m);
-void pa_alsa_path_set_drop_unsupported(pa_alsa_path_set *s);
+void pa_alsa_path_set_probe(pa_alsa_path_set *s, snd_mixer_t *m, pa_bool_t ignore_dB);
void pa_alsa_path_set_dump(pa_alsa_path_set *s);
+void pa_alsa_path_set_set_callback(pa_alsa_path_set *ps, snd_mixer_t *m, snd_mixer_elem_callback_t cb, void *userdata);
void pa_alsa_path_set_free(pa_alsa_path_set *s);
struct pa_alsa_mapping {
@@ -230,6 +231,9 @@ struct pa_alsa_mapping {
/* Temporarily used during probing */
snd_pcm_t *input_pcm;
snd_pcm_t *output_pcm;
+
+ pa_sink *sink;
+ pa_source *source;
};
struct pa_alsa_profile {
@@ -259,19 +263,25 @@ struct pa_alsa_profile_set {
void pa_alsa_mapping_dump(pa_alsa_mapping *m);
void pa_alsa_profile_dump(pa_alsa_profile *p);
-pa_alsa_profile_set* pa_alsa_profile_set_new(const char *fname);
+pa_alsa_profile_set* pa_alsa_profile_set_new(const char *fname, const pa_channel_map *bonus);
void pa_alsa_profile_set_probe(pa_alsa_profile_set *ps, const char *dev_id, const pa_sample_spec *ss);
-void pa_alsa_profile_set_drop_unsupported(pa_alsa_profile_set *ps);
void pa_alsa_profile_set_free(pa_alsa_profile_set *s);
void pa_alsa_profile_set_dump(pa_alsa_profile_set *s);
-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, char **ctl_device, snd_mixer_t **_m, snd_mixer_elem_t **_e, const char *control_name, const pa_alsa_profile_info*profile);
-int pa_alsa_calc_mixer_map(snd_mixer_elem_t *elem, const pa_channel_map *channel_map, snd_mixer_selem_channel_id_t mixer_map[], pa_bool_t playback);
+snd_mixer_t *pa_alsa_open_mixer_for_pcm(snd_pcm_t *pcm, char **ctl_device);
pa_alsa_fdlist *pa_alsa_fdlist_new(void);
void pa_alsa_fdlist_free(pa_alsa_fdlist *fdl);
int pa_alsa_fdlist_set_mixer(pa_alsa_fdlist *fdl, snd_mixer_t *mixer_handle, pa_mainloop_api* m);
+/* Data structure for inclusion in pa_device_port for alsa
+ * sinks/sources. This contains nothing that needs to be freed
+ * individually */
+struct pa_alsa_port_data {
+ pa_alsa_path *path;
+ pa_alsa_setting *setting;
+};
+
+void pa_alsa_add_ports(pa_hashmap **p, pa_alsa_path_set *ps);
+
#endif
diff --git a/src/modules/alsa/alsa-sink.c b/src/modules/alsa/alsa-sink.c
index 59a5ca7..d7e5be8 100644
--- a/src/modules/alsa/alsa-sink.c
+++ b/src/modules/alsa/alsa-sink.c
@@ -80,11 +80,9 @@ struct userdata {
pa_alsa_fdlist *mixer_fdl;
snd_mixer_t *mixer_handle;
- snd_mixer_elem_t *mixer_elem;
- long hw_volume_max, hw_volume_min;
- long hw_dB_max, hw_dB_min;
- pa_bool_t hw_dB_supported:1;
- pa_bool_t mixer_seperate_channels:1;
+ pa_alsa_path_set *mixer_path_set;
+ pa_alsa_path *mixer_path;
+
pa_cvolume hardware_volume;
size_t
@@ -100,7 +98,8 @@ struct userdata {
unsigned nfragments;
pa_memchunk memchunk;
- char *device_name;
+ char *device_name; /* name of the PCM device */
+ char *control_device; /* name of the control device */
pa_bool_t use_mmap:1, use_tsched:1;
@@ -991,191 +990,58 @@ static int mixer_callback(snd_mixer_elem_t *elem, unsigned int mask) {
return 0;
}
-static pa_volume_t from_alsa_volume(struct userdata *u, long alsa_vol) {
-
- return (pa_volume_t) round(((double) (alsa_vol - u->hw_volume_min) * PA_VOLUME_NORM) /
- (double) (u->hw_volume_max - u->hw_volume_min));
-}
-
-static long to_alsa_volume(struct userdata *u, pa_volume_t vol) {
- long alsa_vol;
-
- alsa_vol = (long) round(((double) vol * (double) (u->hw_volume_max - u->hw_volume_min))
- / PA_VOLUME_NORM) + u->hw_volume_min;
-
- return PA_CLAMP_UNLIKELY(alsa_vol, u->hw_volume_min, u->hw_volume_max);
-}
-
static void sink_get_volume_cb(pa_sink *s) {
struct userdata *u = s->userdata;
- int err;
- unsigned i;
pa_cvolume r;
char t[PA_CVOLUME_SNPRINT_MAX];
pa_assert(u);
- pa_assert(u->mixer_elem);
-
- if (u->mixer_seperate_channels) {
-
- r.channels = s->sample_spec.channels;
-
- for (i = 0; i < s->sample_spec.channels; i++) {
- long alsa_vol;
-
- if (u->hw_dB_supported) {
-
- if ((err = snd_mixer_selem_get_playback_dB(u->mixer_elem, u->mixer_map[i], &alsa_vol)) < 0)
- goto fail;
-
-#ifdef HAVE_VALGRIND_MEMCHECK_H
- VALGRIND_MAKE_MEM_DEFINED(&alsa_vol, sizeof(alsa_vol));
-#endif
-
- r.values[i] = pa_sw_volume_from_dB((double) (alsa_vol - u->hw_dB_max) / 100.0);
- } else {
-
- if ((err = snd_mixer_selem_get_playback_volume(u->mixer_elem, u->mixer_map[i], &alsa_vol)) < 0)
- goto fail;
-
- r.values[i] = from_alsa_volume(u, alsa_vol);
- }
- }
-
- } else {
- long alsa_vol;
-
- if (u->hw_dB_supported) {
-
- if ((err = snd_mixer_selem_get_playback_dB(u->mixer_elem, SND_MIXER_SCHN_MONO, &alsa_vol)) < 0)
- goto fail;
-
-#ifdef HAVE_VALGRIND_MEMCHECK_H
- VALGRIND_MAKE_MEM_DEFINED(&alsa_vol, sizeof(alsa_vol));
-#endif
-
- pa_cvolume_set(&r, s->sample_spec.channels, pa_sw_volume_from_dB((double) (alsa_vol - u->hw_dB_max) / 100.0));
-
- } else {
+ pa_assert(u->mixer_path);
+ pa_assert(u->mixer_handle);
- if ((err = snd_mixer_selem_get_playback_volume(u->mixer_elem, SND_MIXER_SCHN_MONO, &alsa_vol)) < 0)
- goto fail;
+ if (pa_alsa_path_get_volume(u->mixer_path, u->mixer_handle, &s->channel_map, &r) < 0)
+ return;
- pa_cvolume_set(&r, s->sample_spec.channels, from_alsa_volume(u, alsa_vol));
- }
- }
+ /* Shift down by the base volume, so that 0dB becomes maximum volume */
+ pa_sw_cvolume_divide_scalar(&r, &r, s->base_volume);
pa_log_debug("Read hardware volume: %s", pa_cvolume_snprint(t, sizeof(t), &r));
- if (!pa_cvolume_equal(&u->hardware_volume, &r)) {
+ if (pa_cvolume_equal(&u->hardware_volume, &r))
+ return;
- s->virtual_volume = u->hardware_volume = r;
+ s->virtual_volume = u->hardware_volume = r;
- if (u->hw_dB_supported) {
- pa_cvolume reset;
+ if (u->mixer_path->has_dB) {
+ pa_cvolume reset;
- /* Hmm, so the hardware volume changed, let's reset our software volume */
- pa_cvolume_reset(&reset, s->sample_spec.channels);
- pa_sink_set_soft_volume(s, &reset);
- }
+ /* Hmm, so the hardware volume changed, let's reset our software volume */
+ pa_cvolume_reset(&reset, s->sample_spec.channels);
+ pa_sink_set_soft_volume(s, &reset);
}
-
- return;
-
-fail:
- pa_log_error("Unable to read volume: %s", pa_alsa_strerror(err));
}
static void sink_set_volume_cb(pa_sink *s) {
struct userdata *u = s->userdata;
- int err;
- unsigned i;
pa_cvolume r;
+ char t[PA_CVOLUME_SNPRINT_MAX];
pa_assert(u);
- pa_assert(u->mixer_elem);
-
- if (u->mixer_seperate_channels) {
-
- r.channels = s->sample_spec.channels;
-
- for (i = 0; i < s->sample_spec.channels; i++) {
- long alsa_vol;
- pa_volume_t vol;
-
- vol = s->virtual_volume.values[i];
-
- if (u->hw_dB_supported) {
-
- alsa_vol = (long) (pa_sw_volume_to_dB(vol) * 100);
- alsa_vol += u->hw_dB_max;
- alsa_vol = PA_CLAMP_UNLIKELY(alsa_vol, u->hw_dB_min, u->hw_dB_max);
-
- if ((err = snd_mixer_selem_set_playback_dB(u->mixer_elem, u->mixer_map[i], alsa_vol, 1)) < 0)
- goto fail;
-
- if ((err = snd_mixer_selem_get_playback_dB(u->mixer_elem, u->mixer_map[i], &alsa_vol)) < 0)
- goto fail;
-
-#ifdef HAVE_VALGRIND_MEMCHECK_H
- VALGRIND_MAKE_MEM_DEFINED(&alsa_vol, sizeof(alsa_vol));
-#endif
-
- r.values[i] = pa_sw_volume_from_dB((double) (alsa_vol - u->hw_dB_max) / 100.0);
-
- } else {
- alsa_vol = to_alsa_volume(u, vol);
-
- if ((err = snd_mixer_selem_set_playback_volume(u->mixer_elem, u->mixer_map[i], alsa_vol)) < 0)
- goto fail;
-
- if ((err = snd_mixer_selem_get_playback_volume(u->mixer_elem, u->mixer_map[i], &alsa_vol)) < 0)
- goto fail;
-
- r.values[i] = from_alsa_volume(u, alsa_vol);
- }
- }
-
- } else {
- pa_volume_t vol;
- long alsa_vol;
-
- vol = pa_cvolume_max(&s->virtual_volume);
-
- if (u->hw_dB_supported) {
- alsa_vol = (long) (pa_sw_volume_to_dB(vol) * 100);
- alsa_vol += u->hw_dB_max;
- alsa_vol = PA_CLAMP_UNLIKELY(alsa_vol, u->hw_dB_min, u->hw_dB_max);
-
- if ((err = snd_mixer_selem_set_playback_dB_all(u->mixer_elem, alsa_vol, 1)) < 0)
- goto fail;
-
- if ((err = snd_mixer_selem_get_playback_dB(u->mixer_elem, SND_MIXER_SCHN_MONO, &alsa_vol)) < 0)
- goto fail;
-
-#ifdef HAVE_VALGRIND_MEMCHECK_H
- VALGRIND_MAKE_MEM_DEFINED(&alsa_vol, sizeof(alsa_vol));
-#endif
-
- pa_cvolume_set(&r, s->sample_spec.channels, pa_sw_volume_from_dB((double) (alsa_vol - u->hw_dB_max) / 100.0));
-
- } else {
- alsa_vol = to_alsa_volume(u, vol);
+ pa_assert(u->mixer_path);
+ pa_assert(u->mixer_handle);
- if ((err = snd_mixer_selem_set_playback_volume_all(u->mixer_elem, alsa_vol)) < 0)
- goto fail;
+ /* Shift up by the base volume */
+ pa_sw_cvolume_multiply_scalar(&r, &s->virtual_volume, s->base_volume);
- if ((err = snd_mixer_selem_get_playback_volume(u->mixer_elem, SND_MIXER_SCHN_MONO, &alsa_vol)) < 0)
- goto fail;
+ if (pa_alsa_path_set_volume(u->mixer_path, u->mixer_handle, &s->channel_map, &r) < 0)
+ return;
- pa_cvolume_set(&r, s->sample_spec.channels, from_alsa_volume(u, alsa_vol));
- }
- }
+ /* Shift down by the base volume, so that 0dB becomes maximum volume */
+ pa_sw_cvolume_divide_scalar(&r, &r, s->base_volume);
u->hardware_volume = r;
- if (u->hw_dB_supported) {
- char t[PA_CVOLUME_SNPRINT_MAX];
+ if (u->mixer_path->has_dB) {
/* Match exactly what the user requested by software */
pa_sw_cvolume_divide(&s->soft_volume, &s->virtual_volume, &u->hardware_volume);
@@ -1184,45 +1050,75 @@ static void sink_set_volume_cb(pa_sink *s) {
pa_log_debug("Got hardware volume: %s", pa_cvolume_snprint(t, sizeof(t), &u->hardware_volume));
pa_log_debug("Calculated software volume: %s", pa_cvolume_snprint(t, sizeof(t), &s->soft_volume));
- } else
+ } else {
+ pa_log_debug("Wrote hardware volume: %s", pa_cvolume_snprint(t, sizeof(t), &r));
/* We can't match exactly what the user requested, hence let's
* at least tell the user about it */
s->virtual_volume = r;
-
- return;
-
-fail:
- pa_log_error("Unable to set volume: %s", pa_alsa_strerror(err));
+ }
}
static void sink_get_mute_cb(pa_sink *s) {
struct userdata *u = s->userdata;
- int err, sw = 0;
+ pa_bool_t b;
pa_assert(u);
- pa_assert(u->mixer_elem);
+ pa_assert(u->mixer_path);
+ pa_assert(u->mixer_handle);
- if ((err = snd_mixer_selem_get_playback_switch(u->mixer_elem, 0, &sw)) < 0) {
- pa_log_error("Unable to get switch: %s", pa_alsa_strerror(err));
+ if (pa_alsa_path_get_mute(u->mixer_path, u->mixer_handle, &b) < 0)
return;
- }
- s->muted = !sw;
+ s->muted = b;
}
static void sink_set_mute_cb(pa_sink *s) {
struct userdata *u = s->userdata;
- int err;
pa_assert(u);
- pa_assert(u->mixer_elem);
+ pa_assert(u->mixer_path);
+ pa_assert(u->mixer_handle);
- if ((err = snd_mixer_selem_set_playback_switch_all(u->mixer_elem, !s->muted)) < 0) {
- pa_log_error("Unable to set switch: %s", pa_alsa_strerror(err));
- return;
+ pa_alsa_path_set_mute(u->mixer_path, u->mixer_handle, s->muted);
+}
+
+static int sink_set_port_cb(pa_sink *s, pa_device_port *p) {
+ struct userdata *u = s->userdata;
+ pa_alsa_port_data *data;
+
+ pa_assert(u);
+ pa_assert(p);
+ pa_assert(u->mixer_handle);
+
+ data = PA_DEVICE_PORT_DATA(p);
+
+ pa_assert_se(u->mixer_path = data->path);
+ pa_alsa_path_select(u->mixer_path, u->mixer_handle);
+
+ if (u->mixer_path->has_volume && u->mixer_path->has_dB) {
+ s->base_volume = pa_sw_volume_from_dB(-u->mixer_path->max_dB);
+ s->n_volume_steps = PA_VOLUME_NORM+1;
+
+ if (u->mixer_path->max_dB > 0.0)
+ pa_log_info("Fixing base volume to %0.2f dB", pa_sw_volume_to_dB(s->base_volume));
+ else
+ pa_log_info("No particular base volume set, fixing to 0 dB");
+ } else {
+ s->base_volume = PA_VOLUME_NORM;
+ s->n_volume_steps = u->mixer_path->max_volume - u->mixer_path->min_volume + 1;
}
+
+ if (data->setting)
+ pa_alsa_setting_select(data->setting, u->mixer_handle);
+
+ if (s->set_mute)
+ s->set_mute(s);
+ if (s->set_volume)
+ s->set_volume(s);
+
+ return 0;
}
static void sink_update_requested_latency_cb(pa_sink *s) {
@@ -1465,77 +1361,118 @@ static void set_sink_name(pa_sink_new_data *data, pa_modargs *ma, const char *de
pa_xfree(t);
}
+static void find_mixer(struct userdata *u, pa_alsa_mapping *mapping, const char *element, pa_bool_t ignore_dB) {
+
+ if (!mapping && !element)
+ return;
+
+ if (!(u->mixer_handle = pa_alsa_open_mixer_for_pcm(u->pcm_handle, &u->control_device))) {
+ pa_log_info("Failed to find a working mixer device.");
+ return;
+ }
+
+ if (element) {
+
+ if (!(u->mixer_path = pa_alsa_path_synthesize(element, PA_ALSA_DIRECTION_OUTPUT)))
+ goto fail;
+
+ if (pa_alsa_path_probe(u->mixer_path, u->mixer_handle, ignore_dB) < 0)
+ goto fail;
+
+ } else {
+
+ if (!(u->mixer_path_set = pa_alsa_path_set_new(mapping, PA_ALSA_DIRECTION_OUTPUT)))
+ goto fail;
+
+ pa_alsa_path_set_probe(u->mixer_path_set, u->mixer_handle, ignore_dB);
+ }
+
+ return;
+
+fail:
+
+ if (u->mixer_path_set) {
+ pa_alsa_path_set_free(u->mixer_path_set);
+ u->mixer_path_set = NULL;
+ } else if (u->mixer_path) {
+ pa_alsa_path_free(u->mixer_path);
+ u->mixer_path = NULL;
+ }
+
+ if (u->mixer_handle) {
+ snd_mixer_close(u->mixer_handle);
+ u->mixer_handle = NULL;
+ }
+}
+
static int setup_mixer(struct userdata *u, pa_bool_t ignore_dB) {
pa_assert(u);
if (!u->mixer_handle)
return 0;
- pa_assert(u->mixer_elem);
+ if (u->sink->active_port) {
+ pa_alsa_port_data *data;
- if (snd_mixer_selem_has_playback_volume(u->mixer_elem)) {
- pa_bool_t suitable = FALSE;
+ /* We have a list of supported paths, so let's activate the
+ * one that has been chosen as active */
- if (snd_mixer_selem_get_playback_volume_range(u->mixer_elem, &u->hw_volume_min, &u->hw_volume_max) < 0)
- pa_log_info("Failed to get volume range. Falling back to software volume control.");
- else if (u->hw_volume_min >= u->hw_volume_max)
- pa_log_warn("Your kernel driver is broken: it reports a volume range from %li to %li which makes no sense.", u->hw_volume_min, u->hw_volume_max);
- else {
- pa_log_info("Volume ranges from %li to %li.", u->hw_volume_min, u->hw_volume_max);
- suitable = TRUE;
- }
+ data = PA_DEVICE_PORT_DATA(u->sink->active_port);
+ u->mixer_path = data->path;
- if (suitable) {
- if (ignore_dB || snd_mixer_selem_get_playback_dB_range(u->mixer_elem, &u->hw_dB_min, &u->hw_dB_max) < 0)
- pa_log_info("Mixer doesn't support dB information or data is ignored.");
- else {
-#ifdef HAVE_VALGRIND_MEMCHECK_H
- VALGRIND_MAKE_MEM_DEFINED(&u->hw_dB_min, sizeof(u->hw_dB_min));
- VALGRIND_MAKE_MEM_DEFINED(&u->hw_dB_max, sizeof(u->hw_dB_max));
-#endif
+ pa_alsa_path_select(data->path, u->mixer_handle);
- if (u->hw_dB_min >= u->hw_dB_max)
- pa_log_warn("Your kernel driver is broken: it reports a volume range from %0.2f dB to %0.2f dB which makes no sense.", (double) u->hw_dB_min/100.0, (double) u->hw_dB_max/100.0);
- else {
- pa_log_info("Volume ranges from %0.2f dB to %0.2f dB.", (double) u->hw_dB_min/100.0, (double) u->hw_dB_max/100.0);
- u->hw_dB_supported = TRUE;
-
- if (u->hw_dB_max > 0) {
- u->sink->base_volume = pa_sw_volume_from_dB(- (double) u->hw_dB_max/100.0);
- pa_log_info("Fixing base volume to %0.2f dB", pa_sw_volume_to_dB(u->sink->base_volume));
- } else
- pa_log_info("No particular base volume set, fixing to 0 dB");
- }
- }
+ if (data->setting)
+ pa_alsa_setting_select(data->setting, u->mixer_handle);
- if (!u->hw_dB_supported &&
- u->hw_volume_max - u->hw_volume_min < 3) {
+ } else if (u->mixer_path) {
- pa_log_info("Device doesn't do dB volume and has less than 4 volume levels. Falling back to software volume control.");
- suitable = FALSE;
- }
- }
+ /* Hmm, we have only a single path, then let's activate it */
- if (suitable) {
- u->mixer_seperate_channels = pa_alsa_calc_mixer_map(u->mixer_elem, &u->sink->channel_map, u->mixer_map, TRUE) >= 0;
+ pa_alsa_path_select(u->mixer_path, u->mixer_handle);
- u->sink->get_volume = sink_get_volume_cb;
- u->sink->set_volume = sink_set_volume_cb;
- u->sink->flags |= PA_SINK_HW_VOLUME_CTRL | (u->hw_dB_supported ? PA_SINK_DECIBEL_VOLUME : 0);
- pa_log_info("Using hardware volume control. Hardware dB scale %s.", u->hw_dB_supported ? "supported" : "not supported");
+ if (u->mixer_path->settings)
+ pa_alsa_setting_select(u->mixer_path->settings, u->mixer_handle);
- if (!u->hw_dB_supported)
- u->sink->n_volume_steps = u->hw_volume_max - u->hw_volume_min + 1;
- } else
- pa_log_info("Using software volume control.");
+ } else
+ return 0;
+
+ if (!u->mixer_path->has_volume)
+ pa_log_info("Driver does not support hardware volume control, falling back to software volume control.");
+ else {
+
+ if (u->mixer_path->has_dB) {
+ pa_log_info("Hardware volume ranges from %0.2f dB to %0.2f dB.", u->mixer_path->min_dB, u->mixer_path->max_dB);
+
+ u->sink->base_volume = pa_sw_volume_from_dB(-u->mixer_path->max_dB);
+ u->sink->n_volume_steps = PA_VOLUME_NORM+1;
+
+ if (u->mixer_path->max_dB > 0.0)
+ pa_log_info("Fixing base volume to %0.2f dB", pa_sw_volume_to_dB(u->sink->base_volume));
+ else
+ pa_log_info("No particular base volume set, fixing to 0 dB");
+
+ } else {
+ pa_log_info("Hardware volume ranges from %li to %li.", u->mixer_path->min_volume, u->mixer_path->max_volume);
+ u->sink->base_volume = PA_VOLUME_NORM;
+ u->sink->n_volume_steps = u->mixer_path->max_volume - u->mixer_path->min_volume + 1;
+ }
+
+ u->sink->get_volume = sink_get_volume_cb;
+ u->sink->set_volume = sink_set_volume_cb;
+
+ u->sink->flags |= PA_SINK_HW_VOLUME_CTRL | (u->mixer_path->has_dB ? PA_SINK_DECIBEL_VOLUME : 0);
+ pa_log_info("Using hardware volume control. Hardware dB scale %s.", u->mixer_path->has_dB ? "supported" : "not supported");
}
- if (snd_mixer_selem_has_playback_switch(u->mixer_elem)) {
+ if (!u->mixer_path->has_mute) {
+ pa_log_info("Driver does not support hardware mute control, falling back to software mute control.");
+ } else {
u->sink->get_mute = sink_get_mute_cb;
u->sink->set_mute = sink_set_mute_cb;
u->sink->flags |= PA_SINK_HW_MUTE_CTRL;
- } else
- pa_log_info("Using software mute control.");
+ pa_log_info("Using hardware mute control.");
+ }
u->mixer_fdl = pa_alsa_fdlist_new();
@@ -1544,13 +1481,15 @@ static int setup_mixer(struct userdata *u, pa_bool_t ignore_dB) {
return -1;
}
- snd_mixer_elem_set_callback(u->mixer_elem, mixer_callback);
- snd_mixer_elem_set_callback_private(u->mixer_elem, u);
+ if (u->mixer_path_set)
+ pa_alsa_path_set_set_callback(u->mixer_path_set, u->mixer_handle, mixer_callback, u);
+ else
+ pa_alsa_path_set_callback(u->mixer_path, u->mixer_handle, mixer_callback, u);
return 0;
}
-pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_card *card, const pa_alsa_profile_info *profile) {
+pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_card *card, pa_alsa_mapping *mapping) {
struct userdata *u = NULL;
const char *dev_id = NULL;
@@ -1561,7 +1500,7 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca
size_t frame_size;
pa_bool_t use_mmap = TRUE, b, use_tsched = TRUE, d, ignore_dB = FALSE;
pa_sink_new_data data;
- char *control_device = NULL;
+ pa_alsa_profile_set *profile_set = NULL;
pa_assert(m);
pa_assert(ma);
@@ -1646,32 +1585,35 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca
b = use_mmap;
d = use_tsched;
- if (profile) {
+ if (mapping) {
if (!(dev_id = pa_modargs_get_value(ma, "device_id", NULL))) {
pa_log("device_id= not set");
goto fail;
}
- if (!(u->pcm_handle = pa_alsa_open_by_device_id_profile(
+ if (!(u->pcm_handle = pa_alsa_open_by_device_id_mapping(
dev_id,
&u->device_name,
&ss, &map,
SND_PCM_STREAM_PLAYBACK,
&nfrags, &period_frames, tsched_frames,
- &b, &d, profile)))
+ &b, &d, mapping)))
goto fail;
} else if ((dev_id = pa_modargs_get_value(ma, "device_id", NULL))) {
+ if (!(profile_set = pa_alsa_profile_set_new(NULL, &map)))
+ goto fail;
+
if (!(u->pcm_handle = pa_alsa_open_by_device_id_auto(
dev_id,
&u->device_name,
&ss, &map,
SND_PCM_STREAM_PLAYBACK,
&nfrags, &period_frames, tsched_frames,
- &b, &d, &profile)))
+ &b, &d, profile_set, &mapping)))
goto fail;
@@ -1685,7 +1627,6 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca
&nfrags, &period_frames, tsched_frames,
&b, &d, FALSE)))
goto fail;
-
}
pa_assert(u->device_name);
@@ -1696,8 +1637,8 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca
goto fail;
}
- if (profile)
- pa_log_info("Selected configuration '%s' (%s).", profile->description, profile->name);
+ if (mapping)
+ pa_log_info("Selected mapping '%s' (%s).", mapping->description, mapping->name);
if (use_mmap && !b) {
pa_log_info("Device doesn't support mmap(), falling back to UNIX read/write mode.");
@@ -1723,7 +1664,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);
- pa_alsa_find_mixer_and_elem(u->pcm_handle, &control_device, &u->mixer_handle, &u->mixer_elem, pa_modargs_get_value(ma, "control", NULL), profile);
+ find_mixer(u, mapping, pa_modargs_get_value(ma, "control", NULL), ignore_dB);
pa_sink_new_data_init(&data);
data.driver = driver;
@@ -1733,23 +1674,21 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca
pa_sink_new_data_set_sample_spec(&data, &ss);
pa_sink_new_data_set_channel_map(&data, &map);
- pa_alsa_init_proplist_pcm(m->core, data.proplist, u->pcm_handle, u->mixer_elem);
+ pa_alsa_init_proplist_pcm(m->core, data.proplist, u->pcm_handle);
pa_proplist_sets(data.proplist, PA_PROP_DEVICE_STRING, u->device_name);
pa_proplist_setf(data.proplist, PA_PROP_DEVICE_BUFFERING_BUFFER_SIZE, "%lu", (unsigned long) (period_frames * frame_size * nfrags));
pa_proplist_setf(data.proplist, PA_PROP_DEVICE_BUFFERING_FRAGMENT_SIZE, "%lu", (unsigned long) (period_frames * frame_size));
pa_proplist_sets(data.proplist, PA_PROP_DEVICE_ACCESS_MODE, u->use_tsched ? "mmap+timer" : (u->use_mmap ? "mmap" : "serial"));
- if (profile) {
- pa_proplist_sets(data.proplist, PA_PROP_DEVICE_PROFILE_NAME, profile->name);
- pa_proplist_sets(data.proplist, PA_PROP_DEVICE_PROFILE_DESCRIPTION, profile->description);
+ if (mapping) {
+ pa_proplist_sets(data.proplist, PA_PROP_DEVICE_PROFILE_NAME, mapping->name);
+ pa_proplist_sets(data.proplist, PA_PROP_DEVICE_PROFILE_DESCRIPTION, mapping->description);
}
pa_alsa_init_description(data.proplist);
- if (control_device) {
- pa_alsa_init_proplist_ctl(data.proplist, control_device);
- pa_xfree(control_device);
- }
+ if (u->control_device)
+ pa_alsa_init_proplist_ctl(data.proplist, u->control_device);
if (pa_modargs_get_proplist(ma, "sink_properties", data.proplist, PA_UPDATE_REPLACE) < 0) {
pa_log("Invalid properties");
@@ -1757,6 +1696,9 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca
goto fail;
}
+ if (u->mixer_path_set)
+ pa_alsa_add_ports(&data.ports, u->mixer_path_set);
+
u->sink = pa_sink_new(m->core, &data, PA_SINK_HARDWARE|PA_SINK_LATENCY|(u->use_tsched ? PA_SINK_DYNAMIC_LATENCY : 0));
pa_sink_new_data_done(&data);
@@ -1768,6 +1710,7 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca
u->sink->parent.process_msg = sink_process_msg;
u->sink->update_requested_latency = sink_update_requested_latency_cb;
u->sink->set_state = sink_set_state_cb;
+ u->sink->set_port = sink_set_port_cb;
u->sink->userdata = u;
pa_sink_set_asyncmsgq(u->sink, u->thread_mq.inq);
@@ -1836,6 +1779,9 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca
pa_sink_put(u->sink);
+ if (profile_set)
+ pa_alsa_profile_set_free(profile_set);
+
return u->sink;
fail:
@@ -1843,6 +1789,9 @@ fail:
if (u)
userdata_free(u);
+ if (profile_set)
+ pa_alsa_profile_set_free(profile_set);
+
return NULL;
}
@@ -1871,17 +1820,22 @@ static void userdata_free(struct userdata *u) {
if (u->rtpoll)
pa_rtpoll_free(u->rtpoll);
+ if (u->pcm_handle) {
+ snd_pcm_drop(u->pcm_handle);
+ snd_pcm_close(u->pcm_handle);
+ }
+
if (u->mixer_fdl)
pa_alsa_fdlist_free(u->mixer_fdl);
+ if (u->mixer_path_set)
+ pa_alsa_path_set_free(u->mixer_path_set);
+ else if (u->mixer_path)
+ pa_alsa_path_free(u->mixer_path);
+
if (u->mixer_handle)
snd_mixer_close(u->mixer_handle);
- if (u->pcm_handle) {
- snd_pcm_drop(u->pcm_handle);
- snd_pcm_close(u->pcm_handle);
- }
-
if (u->smoother)
pa_smoother_free(u->smoother);
@@ -1889,6 +1843,7 @@ static void userdata_free(struct userdata *u) {
monitor_done(u);
pa_xfree(u->device_name);
+ pa_xfree(u->control_device);
pa_xfree(u);
}
diff --git a/src/modules/alsa/alsa-sink.h b/src/modules/alsa/alsa-sink.h
index bbf6423..b9a4ac2 100644
--- a/src/modules/alsa/alsa-sink.h
+++ b/src/modules/alsa/alsa-sink.h
@@ -28,8 +28,9 @@
#include <pulsecore/sink.h>
#include "alsa-util.h"
+#include "alsa-mixer.h"
-pa_sink* pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_card *card, const pa_alsa_profile_info *profile);
+pa_sink* pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_card *card, pa_alsa_mapping *mapping);
void pa_alsa_sink_free(pa_sink *s);
diff --git a/src/modules/alsa/alsa-source.c b/src/modules/alsa/alsa-source.c
index c176309..c15748b 100644
--- a/src/modules/alsa/alsa-source.c
+++ b/src/modules/alsa/alsa-source.c
@@ -28,10 +28,6 @@
#include <asoundlib.h>
-#ifdef HAVE_VALGRIND_MEMCHECK_H
-#include <valgrind/memcheck.h>
-#endif
-
#include <pulse/xmalloc.h>
#include <pulse/util.h>
#include <pulse/timeval.h>
@@ -81,11 +77,8 @@ struct userdata {
pa_alsa_fdlist *mixer_fdl;
snd_mixer_t *mixer_handle;
- snd_mixer_elem_t *mixer_elem;
- long hw_volume_max, hw_volume_min;
- long hw_dB_max, hw_dB_min;
- pa_bool_t hw_dB_supported:1;
- pa_bool_t mixer_seperate_channels:1;
+ pa_alsa_path_set *mixer_path_set;
+ pa_alsa_path *mixer_path;
pa_cvolume hardware_volume;
@@ -102,6 +95,7 @@ struct userdata {
unsigned nfragments;
char *device_name;
+ char *control_device;
pa_bool_t use_mmap:1, use_tsched:1;
@@ -949,239 +943,135 @@ static int mixer_callback(snd_mixer_elem_t *elem, unsigned int mask) {
return 0;
}
-static pa_volume_t from_alsa_volume(struct userdata *u, long alsa_vol) {
-
- return (pa_volume_t) round(((double) (alsa_vol - u->hw_volume_min) * PA_VOLUME_NORM) /
- (double) (u->hw_volume_max - u->hw_volume_min));
-}
-
-static long to_alsa_volume(struct userdata *u, pa_volume_t vol) {
- long alsa_vol;
-
- alsa_vol = (long) round(((double) vol * (double) (u->hw_volume_max - u->hw_volume_min))
- / PA_VOLUME_NORM) + u->hw_volume_min;
-
- return PA_CLAMP_UNLIKELY(alsa_vol, u->hw_volume_min, u->hw_volume_max);
-}
-
static void source_get_volume_cb(pa_source *s) {
struct userdata *u = s->userdata;
- int err;
- unsigned i;
pa_cvolume r;
char t[PA_CVOLUME_SNPRINT_MAX];
pa_assert(u);
- pa_assert(u->mixer_elem);
-
- if (u->mixer_seperate_channels) {
-
- r.channels = s->sample_spec.channels;
-
- for (i = 0; i < s->sample_spec.channels; i++) {
- long alsa_vol;
-
- if (u->hw_dB_supported) {
-
- if ((err = snd_mixer_selem_get_capture_dB(u->mixer_elem, u->mixer_map[i], &alsa_vol)) < 0)
- goto fail;
-
-#ifdef HAVE_VALGRIND_MEMCHECK_H
- VALGRIND_MAKE_MEM_DEFINED(&alsa_vol, sizeof(alsa_vol));
-#endif
-
- r.values[i] = pa_sw_volume_from_dB((double) (alsa_vol - u->hw_dB_max) / 100.0);
- } else {
-
- if ((err = snd_mixer_selem_get_capture_volume(u->mixer_elem, u->mixer_map[i], &alsa_vol)) < 0)
- goto fail;
-
- r.values[i] = from_alsa_volume(u, alsa_vol);
- }
- }
-
- } else {
- long alsa_vol;
-
- if (u->hw_dB_supported) {
-
- if ((err = snd_mixer_selem_get_capture_dB(u->mixer_elem, SND_MIXER_SCHN_MONO, &alsa_vol)) < 0)
- goto fail;
-
-#ifdef HAVE_VALGRIND_MEMCHECK_H
- VALGRIND_MAKE_MEM_DEFINED(&alsa_vol, sizeof(alsa_vol));
-#endif
-
- pa_cvolume_set(&r, s->sample_spec.channels, pa_sw_volume_from_dB((double) (alsa_vol - u->hw_dB_max) / 100.0));
-
- } else {
+ pa_assert(u->mixer_path);
+ pa_assert(u->mixer_handle);
- if ((err = snd_mixer_selem_get_capture_volume(u->mixer_elem, SND_MIXER_SCHN_MONO, &alsa_vol)) < 0)
- goto fail;
+ if (pa_alsa_path_get_volume(u->mixer_path, u->mixer_handle, &s->channel_map, &r) < 0)
+ return;
- pa_cvolume_set(&r, s->sample_spec.channels, from_alsa_volume(u, alsa_vol));
- }
- }
+ /* Shift down by the base volume, so that 0dB becomes maximum volume */
+ pa_sw_cvolume_divide_scalar(&r, &r, s->base_volume);
pa_log_debug("Read hardware volume: %s", pa_cvolume_snprint(t, sizeof(t), &r));
- if (!pa_cvolume_equal(&u->hardware_volume, &r)) {
+ if (pa_cvolume_equal(&u->hardware_volume, &r))
+ return;
- s->virtual_volume = u->hardware_volume = r;
+ s->virtual_volume = u->hardware_volume = r;
- if (u->hw_dB_supported) {
- pa_cvolume reset;
+ if (u->mixer_path->has_dB) {
+ pa_cvolume reset;
- /* Hmm, so the hardware volume changed, let's reset our software volume */
- pa_cvolume_reset(&reset, s->sample_spec.channels);
- pa_source_set_soft_volume(s, &reset);
- }
+ /* Hmm, so the hardware volume changed, let's reset our software volume */
+ pa_cvolume_reset(&reset, s->sample_spec.channels);
+ pa_source_set_soft_volume(s, &reset);
}
-
- return;
-
-fail:
- pa_log_error("Unable to read volume: %s", pa_alsa_strerror(err));
}
static void source_set_volume_cb(pa_source *s) {
struct userdata *u = s->userdata;
- int err;
- unsigned i;
pa_cvolume r;
+ char t[PA_CVOLUME_SNPRINT_MAX];
pa_assert(u);
- pa_assert(u->mixer_elem);
-
- if (u->mixer_seperate_channels) {
-
- r.channels = s->sample_spec.channels;
-
- for (i = 0; i < s->sample_spec.channels; i++) {
- long alsa_vol;
- pa_volume_t vol;
-
- vol = s->virtual_volume.values[i];
-
- if (u->hw_dB_supported) {
-
- alsa_vol = (long) (pa_sw_volume_to_dB(vol) * 100);
- alsa_vol += u->hw_dB_max;
- alsa_vol = PA_CLAMP_UNLIKELY(alsa_vol, u->hw_dB_min, u->hw_dB_max);
-
- if ((err = snd_mixer_selem_set_capture_dB(u->mixer_elem, u->mixer_map[i], alsa_vol, 1)) < 0)
- goto fail;
-
- if ((err = snd_mixer_selem_get_capture_dB(u->mixer_elem, u->mixer_map[i], &alsa_vol)) < 0)
- goto fail;
-
-#ifdef HAVE_VALGRIND_MEMCHECK_H
- VALGRIND_MAKE_MEM_DEFINED(&alsa_vol, sizeof(alsa_vol));
-#endif
-
- r.values[i] = pa_sw_volume_from_dB((double) (alsa_vol - u->hw_dB_max) / 100.0);
-
- } else {
- alsa_vol = to_alsa_volume(u, vol);
-
- if ((err = snd_mixer_selem_set_capture_volume(u->mixer_elem, u->mixer_map[i], alsa_vol)) < 0)
- goto fail;
-
- if ((err = snd_mixer_selem_get_capture_volume(u->mixer_elem, u->mixer_map[i], &alsa_vol)) < 0)
- goto fail;
-
- r.values[i] = from_alsa_volume(u, alsa_vol);
- }
- }
-
- } else {
- pa_volume_t vol;
- long alsa_vol;
-
- vol = pa_cvolume_max(&s->virtual_volume);
-
- if (u->hw_dB_supported) {
- alsa_vol = (long) (pa_sw_volume_to_dB(vol) * 100);
- alsa_vol += u->hw_dB_max;
- alsa_vol = PA_CLAMP_UNLIKELY(alsa_vol, u->hw_dB_min, u->hw_dB_max);
-
- if ((err = snd_mixer_selem_set_capture_dB_all(u->mixer_elem, alsa_vol, 1)) < 0)
- goto fail;
-
- if ((err = snd_mixer_selem_get_capture_dB(u->mixer_elem, SND_MIXER_SCHN_MONO, &alsa_vol)) < 0)
- goto fail;
-
-#ifdef HAVE_VALGRIND_MEMCHECK_H
- VALGRIND_MAKE_MEM_DEFINED(&alsa_vol, sizeof(alsa_vol));
-#endif
-
- pa_cvolume_set(&r, s->sample_spec.channels, pa_sw_volume_from_dB((double) (alsa_vol - u->hw_dB_max) / 100.0));
-
- } else {
- alsa_vol = to_alsa_volume(u, vol);
+ pa_assert(u->mixer_path);
+ pa_assert(u->mixer_handle);
- if ((err = snd_mixer_selem_set_capture_volume_all(u->mixer_elem, alsa_vol)) < 0)
- goto fail;
+ /* Shift up by the base volume */
+ pa_sw_cvolume_multiply_scalar(&r, &s->virtual_volume, s->base_volume);
- if ((err = snd_mixer_selem_get_capture_volume(u->mixer_elem, SND_MIXER_SCHN_MONO, &alsa_vol)) < 0)
- goto fail;
+ if (pa_alsa_path_set_volume(u->mixer_path, u->mixer_handle, &s->channel_map, &r) < 0)
+ return;
- pa_cvolume_set(&r, s->sample_spec.channels, from_alsa_volume(u, alsa_vol));
- }
- }
+ /* Shift down by the base volume, so that 0dB becomes maximum volume */
+ pa_sw_cvolume_divide_scalar(&r, &r, s->base_volume);
u->hardware_volume = r;
- if (u->hw_dB_supported) {
- char t[PA_CVOLUME_SNPRINT_MAX];
+ if (u->mixer_path->has_dB) {
/* Match exactly what the user requested by software */
-
pa_sw_cvolume_divide(&s->soft_volume, &s->virtual_volume, &u->hardware_volume);
pa_log_debug("Requested volume: %s", pa_cvolume_snprint(t, sizeof(t), &s->virtual_volume));
pa_log_debug("Got hardware volume: %s", pa_cvolume_snprint(t, sizeof(t), &u->hardware_volume));
pa_log_debug("Calculated software volume: %s", pa_cvolume_snprint(t, sizeof(t), &s->soft_volume));
- } else
+ } else {
+ pa_log_debug("Wrote hardware volume: %s", pa_cvolume_snprint(t, sizeof(t), &r));
/* We can't match exactly what the user requested, hence let's
* at least tell the user about it */
s->virtual_volume = r;
-
- return;
-
-fail:
- pa_log_error("Unable to set volume: %s", pa_alsa_strerror(err));
+ }
}
static void source_get_mute_cb(pa_source *s) {
struct userdata *u = s->userdata;
- int err, sw = 0;
+ pa_bool_t b;
pa_assert(u);
- pa_assert(u->mixer_elem);
+ pa_assert(u->mixer_path);
+ pa_assert(u->mixer_handle);
- if ((err = snd_mixer_selem_get_capture_switch(u->mixer_elem, 0, &sw)) < 0) {
- pa_log_error("Unable to get switch: %s", pa_alsa_strerror(err));
+ if (pa_alsa_path_get_mute(u->mixer_path, u->mixer_handle, &b) < 0)
return;
- }
- s->muted = !sw;
+ s->muted = b;
}
static void source_set_mute_cb(pa_source *s) {
struct userdata *u = s->userdata;
- int err;
pa_assert(u);
- pa_assert(u->mixer_elem);
+ pa_assert(u->mixer_path);
+ pa_assert(u->mixer_handle);
- if ((err = snd_mixer_selem_set_capture_switch_all(u->mixer_elem, !s->muted)) < 0) {
- pa_log_error("Unable to set switch: %s", pa_alsa_strerror(err));
- return;
+ pa_alsa_path_set_mute(u->mixer_path, u->mixer_handle, s->muted);
+}
+
+static int source_set_port_cb(pa_source *s, pa_device_port *p) {
+ struct userdata *u = s->userdata;
+ pa_alsa_port_data *data;
+
+ pa_assert(u);
+ pa_assert(p);
+ pa_assert(u->mixer_handle);
+
+ data = PA_DEVICE_PORT_DATA(p);
+
+ pa_assert_se(u->mixer_path = data->path);
+ pa_alsa_path_select(u->mixer_path, u->mixer_handle);
+
+ if (u->mixer_path->has_volume && u->mixer_path->has_dB) {
+ s->base_volume = pa_sw_volume_from_dB(-u->mixer_path->max_dB);
+ s->n_volume_steps = PA_VOLUME_NORM+1;
+
+ if (u->mixer_path->max_dB > 0.0)
+ pa_log_info("Fixing base volume to %0.2f dB", pa_sw_volume_to_dB(s->base_volume));
+ else
+ pa_log_info("No particular base volume set, fixing to 0 dB");
+ } else {
+ s->base_volume = PA_VOLUME_NORM;
+ s->n_volume_steps = u->mixer_path->max_volume - u->mixer_path->min_volume + 1;
}
+
+ if (data->setting)
+ pa_alsa_setting_select(data->setting, u->mixer_handle);
+
+ if (s->set_mute)
+ s->set_mute(s);
+ if (s->set_volume)
+ s->set_volume(s);
+
+ return 0;
}
static void source_update_requested_latency_cb(pa_source *s) {
@@ -1323,77 +1213,118 @@ static void set_source_name(pa_source_new_data *data, pa_modargs *ma, const char
pa_xfree(t);
}
+static void find_mixer(struct userdata *u, pa_alsa_mapping *mapping, const char *element, pa_bool_t ignore_dB) {
+
+ if (!mapping && !element)
+ return;
+
+ if (!(u->mixer_handle = pa_alsa_open_mixer_for_pcm(u->pcm_handle, &u->control_device))) {
+ pa_log_info("Failed to find a working mixer device.");
+ return;
+ }
+
+ if (element) {
+
+ if (!(u->mixer_path = pa_alsa_path_synthesize(element, PA_ALSA_DIRECTION_OUTPUT)))
+ goto fail;
+
+ if (pa_alsa_path_probe(u->mixer_path, u->mixer_handle, ignore_dB) < 0)
+ goto fail;
+
+ } else {
+
+ if (!(u->mixer_path_set = pa_alsa_path_set_new(mapping, PA_ALSA_DIRECTION_OUTPUT)))
+ goto fail;
+
+ pa_alsa_path_set_probe(u->mixer_path_set, u->mixer_handle, ignore_dB);
+ }
+
+ return;
+
+fail:
+
+ if (u->mixer_path_set) {
+ pa_alsa_path_set_free(u->mixer_path_set);
+ u->mixer_path_set = NULL;
+ } else if (u->mixer_path) {
+ pa_alsa_path_free(u->mixer_path);
+ u->mixer_path = NULL;
+ }
+
+ if (u->mixer_handle) {
+ snd_mixer_close(u->mixer_handle);
+ u->mixer_handle = NULL;
+ }
+}
+
static int setup_mixer(struct userdata *u, pa_bool_t ignore_dB) {
pa_assert(u);
if (!u->mixer_handle)
return 0;
- pa_assert(u->mixer_elem);
+ if (u->source->active_port) {
+ pa_alsa_port_data *data;
- if (snd_mixer_selem_has_capture_volume(u->mixer_elem)) {
- pa_bool_t suitable = FALSE;
+ /* We have a list of supported paths, so let's activate the
+ * one that has been chosen as active */
- if (snd_mixer_selem_get_capture_volume_range(u->mixer_elem, &u->hw_volume_min, &u->hw_volume_max) < 0)
- pa_log_info("Failed to get volume range. Falling back to software volume control.");
- else if (u->hw_volume_min >= u->hw_volume_max)
- pa_log_warn("Your kernel driver is broken: it reports a volume range from %li to %li which makes no sense.", u->hw_volume_min, u->hw_volume_max);
- else {
- pa_log_info("Volume ranges from %li to %li.", u->hw_volume_min, u->hw_volume_max);
- suitable = TRUE;
- }
+ data = PA_DEVICE_PORT_DATA(u->source->active_port);
+ u->mixer_path = data->path;
- if (suitable) {
- if (ignore_dB || snd_mixer_selem_get_capture_dB_range(u->mixer_elem, &u->hw_dB_min, &u->hw_dB_max) < 0)
- pa_log_info("Mixer doesn't support dB information or data is ignored.");
- else {
-#ifdef HAVE_VALGRIND_MEMCHECK_H
- VALGRIND_MAKE_MEM_DEFINED(&u->hw_dB_min, sizeof(u->hw_dB_min));
- VALGRIND_MAKE_MEM_DEFINED(&u->hw_dB_max, sizeof(u->hw_dB_max));
-#endif
+ pa_alsa_path_select(data->path, u->mixer_handle);
- if (u->hw_dB_min >= u->hw_dB_max)
- pa_log_warn("Your kernel driver is broken: it reports a volume range from %0.2f dB to %0.2f dB which makes no sense.", (double) u->hw_dB_min/100.0, (double) u->hw_dB_max/100.0);
- else {
- pa_log_info("Volume ranges from %0.2f dB to %0.2f dB.", (double) u->hw_dB_min/100.0, (double) u->hw_dB_max/100.0);
- u->hw_dB_supported = TRUE;
-
- if (u->hw_dB_max > 0) {
- u->source->base_volume = pa_sw_volume_from_dB(- (double) u->hw_dB_max/100.0);
- pa_log_info("Fixing base volume to %0.2f dB", pa_sw_volume_to_dB(u->source->base_volume));
- } else
- pa_log_info("No particular base volume set, fixing to 0 dB");
- }
- }
+ if (data->setting)
+ pa_alsa_setting_select(data->setting, u->mixer_handle);
- if (!u->hw_dB_supported &&
- u->hw_volume_max - u->hw_volume_min < 3) {
+ } else if (u->mixer_path) {
- pa_log_info("Device has less than 4 volume levels. Falling back to software volume control.");
- suitable = FALSE;
- }
- }
+ /* Hmm, we have only a single path, then let's activate it */
- if (suitable) {
- u->mixer_seperate_channels = pa_alsa_calc_mixer_map(u->mixer_elem, &u->source->channel_map, u->mixer_map, FALSE) >= 0;
+ pa_alsa_path_select(u->mixer_path, u->mixer_handle);
- u->source->get_volume = source_get_volume_cb;
- u->source->set_volume = source_set_volume_cb;
- u->source->flags |= PA_SOURCE_HW_VOLUME_CTRL | (u->hw_dB_supported ? PA_SOURCE_DECIBEL_VOLUME : 0);
- pa_log_info("Using hardware volume control. Hardware dB scale %s.", u->hw_dB_supported ? "supported" : "not supported");
+ if (u->mixer_path->settings)
+ pa_alsa_setting_select(u->mixer_path->settings, u->mixer_handle);
- if (!u->hw_dB_supported)
- u->source->n_volume_steps = u->hw_volume_max - u->hw_volume_min + 1;
- } else
- pa_log_info("Using software volume control.");
+ } else
+ return 0;
+
+ if (!u->mixer_path->has_volume)
+ pa_log_info("Driver does not support hardware volume control, falling back to software volume control.");
+ else {
+
+ if (u->mixer_path->has_dB) {
+ pa_log_info("Hardware volume ranges from %0.2f dB to %0.2f dB.", u->mixer_path->min_dB, u->mixer_path->max_dB);
+
+ u->source->base_volume = pa_sw_volume_from_dB(-u->mixer_path->max_dB);
+ u->source->n_volume_steps = PA_VOLUME_NORM+1;
+
+ if (u->mixer_path->max_dB > 0.0)
+ pa_log_info("Fixing base volume to %0.2f dB", pa_sw_volume_to_dB(u->source->base_volume));
+ else
+ pa_log_info("No particular base volume set, fixing to 0 dB");
+
+ } else {
+ pa_log_info("Hardware volume ranges from %li to %li.", u->mixer_path->min_volume, u->mixer_path->max_volume);
+ u->source->base_volume = PA_VOLUME_NORM;
+ u->source->n_volume_steps = u->mixer_path->max_volume - u->mixer_path->min_volume + 1;
+ }
+
+ u->source->get_volume = source_get_volume_cb;
+ u->source->set_volume = source_set_volume_cb;
+
+ u->source->flags |= PA_SOURCE_HW_VOLUME_CTRL | (u->mixer_path->has_dB ? PA_SOURCE_DECIBEL_VOLUME : 0);
+ pa_log_info("Using hardware volume control. Hardware dB scale %s.", u->mixer_path->has_dB ? "supported" : "not supported");
}
- if (snd_mixer_selem_has_capture_switch(u->mixer_elem)) {
+ if (!u->mixer_path->has_mute) {
+ pa_log_info("Driver does not support hardware mute control, falling back to software mute control.");
+ } else {
u->source->get_mute = source_get_mute_cb;
u->source->set_mute = source_set_mute_cb;
u->source->flags |= PA_SOURCE_HW_MUTE_CTRL;
- } else
- pa_log_info("Using software mute control.");
+ pa_log_info("Using hardware mute control.");
+ }
u->mixer_fdl = pa_alsa_fdlist_new();
@@ -1402,13 +1333,15 @@ static int setup_mixer(struct userdata *u, pa_bool_t ignore_dB) {
return -1;
}
- snd_mixer_elem_set_callback(u->mixer_elem, mixer_callback);
- snd_mixer_elem_set_callback_private(u->mixer_elem, u);
+ if (u->mixer_path_set)
+ pa_alsa_path_set_set_callback(u->mixer_path_set, u->mixer_handle, mixer_callback, u);
+ else
+ pa_alsa_path_set_callback(u->mixer_path, u->mixer_handle, mixer_callback, u);
return 0;
}
-pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, pa_card *card, const pa_alsa_profile_info *profile) {
+pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, pa_card *card, pa_alsa_mapping *mapping) {
struct userdata *u = NULL;
const char *dev_id = NULL;
@@ -1419,7 +1352,7 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p
size_t frame_size;
pa_bool_t use_mmap = TRUE, b, use_tsched = TRUE, d, ignore_dB = FALSE;
pa_source_new_data data;
- char *control_device = NULL;
+ pa_alsa_profile_set *profile_set = NULL;
pa_assert(m);
pa_assert(ma);
@@ -1480,7 +1413,6 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p
u->use_tsched = use_tsched;
u->rtpoll = pa_rtpoll_new();
pa_thread_mq_init(&u->thread_mq, m->core->mainloop, u->rtpoll);
- u->alsa_rtpoll_item = NULL;
u->smoother = pa_smoother_new(
DEFAULT_TSCHED_WATERMARK_USEC*2,
@@ -1504,31 +1436,34 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p
b = use_mmap;
d = use_tsched;
- if (profile) {
+ if (mapping) {
if (!(dev_id = pa_modargs_get_value(ma, "device_id", NULL))) {
pa_log("device_id= not set");
goto fail;
}
- if (!(u->pcm_handle = pa_alsa_open_by_device_id_profile(
+ if (!(u->pcm_handle = pa_alsa_open_by_device_id_mapping(
dev_id,
&u->device_name,
&ss, &map,
SND_PCM_STREAM_CAPTURE,
&nfrags, &period_frames, tsched_frames,
- &b, &d, profile)))
+ &b, &d, mapping)))
goto fail;
} else if ((dev_id = pa_modargs_get_value(ma, "device_id", NULL))) {
+ if (!(profile_set = pa_alsa_profile_set_new(NULL, &map)))
+ goto fail;
+
if (!(u->pcm_handle = pa_alsa_open_by_device_id_auto(
dev_id,
&u->device_name,
&ss, &map,
SND_PCM_STREAM_CAPTURE,
&nfrags, &period_frames, tsched_frames,
- &b, &d, &profile)))
+ &b, &d, profile_set, &mapping)))
goto fail;
} else {
@@ -1551,8 +1486,8 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p
goto fail;
}
- if (profile)
- pa_log_info("Selected configuration '%s' (%s).", profile->description, profile->name);
+ if (mapping)
+ pa_log_info("Selected mapping '%s' (%s).", mapping->description, mapping->name);
if (use_mmap && !b) {
pa_log_info("Device doesn't support mmap(), falling back to UNIX read/write mode.");
@@ -1578,7 +1513,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);
- pa_alsa_find_mixer_and_elem(u->pcm_handle, &control_device, &u->mixer_handle, &u->mixer_elem, pa_modargs_get_value(ma, "control", NULL), profile);
+ find_mixer(u, mapping, pa_modargs_get_value(ma, "control", NULL), ignore_dB);
pa_source_new_data_init(&data);
data.driver = driver;
@@ -1588,23 +1523,21 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p
pa_source_new_data_set_sample_spec(&data, &ss);
pa_source_new_data_set_channel_map(&data, &map);
- pa_alsa_init_proplist_pcm(m->core, data.proplist, u->pcm_handle, u->mixer_elem);
+ pa_alsa_init_proplist_pcm(m->core, data.proplist, u->pcm_handle);
pa_proplist_sets(data.proplist, PA_PROP_DEVICE_STRING, u->device_name);
pa_proplist_setf(data.proplist, PA_PROP_DEVICE_BUFFERING_BUFFER_SIZE, "%lu", (unsigned long) (period_frames * frame_size * nfrags));
pa_proplist_setf(data.proplist, PA_PROP_DEVICE_BUFFERING_FRAGMENT_SIZE, "%lu", (unsigned long) (period_frames * frame_size));
pa_proplist_sets(data.proplist, PA_PROP_DEVICE_ACCESS_MODE, u->use_tsched ? "mmap+timer" : (u->use_mmap ? "mmap" : "serial"));
- if (profile) {
- pa_proplist_sets(data.proplist, PA_PROP_DEVICE_PROFILE_NAME, profile->name);
- pa_proplist_sets(data.proplist, PA_PROP_DEVICE_PROFILE_DESCRIPTION, profile->description);
+ if (mapping) {
+ pa_proplist_sets(data.proplist, PA_PROP_DEVICE_PROFILE_NAME, mapping->name);
+ pa_proplist_sets(data.proplist, PA_PROP_DEVICE_PROFILE_DESCRIPTION, mapping->description);
}
pa_alsa_init_description(data.proplist);
- if (control_device) {
- pa_alsa_init_proplist_ctl(data.proplist, control_device);
- pa_xfree(control_device);
- }
+ if (u->control_device)
+ pa_alsa_init_proplist_ctl(data.proplist, u->control_device);
if (pa_modargs_get_proplist(ma, "source_properties", data.proplist, PA_UPDATE_REPLACE) < 0) {
pa_log("Invalid properties");
@@ -1612,6 +1545,9 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p
goto fail;
}
+ if (u->mixer_path_set)
+ pa_alsa_add_ports(&data.ports, u->mixer_path_set);
+
u->source = pa_source_new(m->core, &data, PA_SOURCE_HARDWARE|PA_SOURCE_LATENCY|(u->use_tsched ? PA_SOURCE_DYNAMIC_LATENCY : 0));
pa_source_new_data_done(&data);
@@ -1623,6 +1559,7 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p
u->source->parent.process_msg = source_process_msg;
u->source->update_requested_latency = source_update_requested_latency_cb;
u->source->set_state = source_set_state_cb;
+ u->source->set_port = source_set_port_cb;
u->source->userdata = u;
pa_source_set_asyncmsgq(u->source, u->thread_mq.inq);
@@ -1687,6 +1624,9 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p
pa_source_put(u->source);
+ if (profile_set)
+ pa_alsa_profile_set_free(profile_set);
+
return u->source;
fail:
@@ -1694,6 +1634,9 @@ fail:
if (u)
userdata_free(u);
+ if (profile_set)
+ pa_alsa_profile_set_free(profile_set);
+
return NULL;
}
@@ -1719,17 +1662,22 @@ static void userdata_free(struct userdata *u) {
if (u->rtpoll)
pa_rtpoll_free(u->rtpoll);
+ if (u->pcm_handle) {
+ snd_pcm_drop(u->pcm_handle);
+ snd_pcm_close(u->pcm_handle);
+ }
+
if (u->mixer_fdl)
pa_alsa_fdlist_free(u->mixer_fdl);
+ if (u->mixer_path_set)
+ pa_alsa_path_set_free(u->mixer_path_set);
+ else if (u->mixer_path)
+ pa_alsa_path_free(u->mixer_path);
+
if (u->mixer_handle)
snd_mixer_close(u->mixer_handle);
- if (u->pcm_handle) {
- snd_pcm_drop(u->pcm_handle);
- snd_pcm_close(u->pcm_handle);
- }
-
if (u->smoother)
pa_smoother_free(u->smoother);
@@ -1737,6 +1685,7 @@ static void userdata_free(struct userdata *u) {
monitor_done(u);
pa_xfree(u->device_name);
+ pa_xfree(u->control_device);
pa_xfree(u);
}
diff --git a/src/modules/alsa/alsa-source.h b/src/modules/alsa/alsa-source.h
index 9cbb0e1..5d9409e 100644
--- a/src/modules/alsa/alsa-source.h
+++ b/src/modules/alsa/alsa-source.h
@@ -29,7 +29,7 @@
#include "alsa-util.h"
-pa_source* pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, pa_card *card, const pa_alsa_profile_info *profile);
+pa_source* pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, pa_card *card, pa_alsa_mapping *mapping);
void pa_alsa_source_free(pa_source *s);
diff --git a/src/modules/alsa/alsa-util.c b/src/modules/alsa/alsa-util.c
index 79ffff1..865daff 100644
--- a/src/modules/alsa/alsa-util.c
+++ b/src/modules/alsa/alsa-util.c
@@ -86,11 +86,11 @@ static int set_format(snd_pcm_t *pcm_handle, snd_pcm_hw_params_t *hwparams, pa_s
PA_SAMPLE_S16RE,
PA_SAMPLE_ALAW,
PA_SAMPLE_ULAW,
- PA_SAMPLE_U8,
- PA_SAMPLE_INVALID
+ PA_SAMPLE_U8
};
- int i, ret;
+ unsigned i;
+ int ret;
pa_assert(pcm_handle);
pa_assert(f);
@@ -134,7 +134,7 @@ static int set_format(snd_pcm_t *pcm_handle, snd_pcm_hw_params_t *hwparams, pa_s
try_auto:
- for (i = 0; try_order[i] != PA_SAMPLE_INVALID; i++) {
+ for (i = 0; i < PA_ELEMENTSOF(try_order); i++) {
*f = try_order[i];
if ((ret = snd_pcm_hw_params_set_format(pcm_handle, hwparams, format_trans[*f])) >= 0)
@@ -240,10 +240,12 @@ int pa_alsa_set_hw_params(
tsched_size = (snd_pcm_uframes_t) (((uint64_t) tsched_size * r) / ss->rate);
if (_use_tsched) {
- snd_pcm_uframes_t buffer_size;
+ snd_pcm_uframes_t buffer_size = 0;
- pa_assert_se(snd_pcm_hw_params_get_buffer_size_max(hwparams, &buffer_size) == 0);
- pa_log_debug("Maximum hw buffer size is %u ms", (unsigned) buffer_size * 1000 / r);
+ if ((ret = snd_pcm_hw_params_get_buffer_size_max(hwparams, &buffer_size)) < 0)
+ pa_log_warn("snd_pcm_hw_params_get_buffer_size_max() failed: %s", pa_alsa_strerror(ret));
+ else
+ pa_log_debug("Maximum hw buffer size is %u ms", (unsigned) buffer_size * 1000 / r);
_period_size = tsched_size;
_periods = 1;
@@ -289,12 +291,16 @@ int pa_alsa_set_hw_params(
if (ss->format != f)
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(f));
- if ((ret = snd_pcm_prepare(pcm_handle)) < 0)
+ 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_get_period_size(hwparams, &_period_size, &dir)) < 0 ||
- (ret = snd_pcm_hw_params_get_periods(hwparams, &_periods, &dir)) < 0)
+ (ret = snd_pcm_hw_params_get_periods(hwparams, &_periods, &dir)) < 0) {
+ pa_log_info("snd_pcm_hw_params_get_period{s|_size}() failed: %s", pa_alsa_strerror(ret));
goto finish;
+ }
/* If the sample rate deviates too much, we need to resample */
if (r < ss->rate*.95 || r > ss->rate*1.05)
@@ -378,167 +384,6 @@ int pa_alsa_set_sw_params(snd_pcm_t *pcm, snd_pcm_uframes_t avail_min) {
return 0;
}
-static const struct pa_alsa_profile_info device_table[] = {
- {{ 1, { PA_CHANNEL_POSITION_MONO }},
- "hw", NULL,
- N_("Analog Mono"),
- "analog-mono",
- 1,
- "Master", "PCM",
- "Capture", "Mic" },
-
- {{ 2, { PA_CHANNEL_POSITION_LEFT, PA_CHANNEL_POSITION_RIGHT }},
- "front", "hw",
- N_("Analog Stereo"),
- "analog-stereo",
- 10,
- "Master", "PCM",
- "Capture", "Mic" },
-
- {{ 2, { PA_CHANNEL_POSITION_LEFT, PA_CHANNEL_POSITION_RIGHT }},
- "iec958", NULL,
- N_("Digital Stereo (IEC958)"),
- "iec958-stereo",
- 5,
- "IEC958", NULL,
- "IEC958 In", NULL },
-
- {{ 2, { PA_CHANNEL_POSITION_LEFT, PA_CHANNEL_POSITION_RIGHT }},
- "hdmi", NULL,
- N_("Digital Stereo (HDMI)"),
- "hdmi-stereo",
- 4,
- "IEC958", NULL,
- "IEC958 In", NULL },
-
- {{ 4, { PA_CHANNEL_POSITION_FRONT_LEFT, PA_CHANNEL_POSITION_FRONT_RIGHT,
- PA_CHANNEL_POSITION_REAR_LEFT, PA_CHANNEL_POSITION_REAR_RIGHT }},
- "surround40", NULL,
- N_("Analog Surround 4.0"),
- "analog-surround-40",
- 7,
- "Master", "PCM",
- "Capture", "Mic" },
-
- {{ 4, { PA_CHANNEL_POSITION_FRONT_LEFT, PA_CHANNEL_POSITION_FRONT_RIGHT,
- PA_CHANNEL_POSITION_REAR_LEFT, PA_CHANNEL_POSITION_REAR_RIGHT }},
- "a52", NULL,
- N_("Digital Surround 4.0 (IEC958/AC3)"),
- "iec958-ac3-surround-40",
- 2,
- "Master", "PCM",
- "Capture", "Mic" },
-
- {{ 5, { PA_CHANNEL_POSITION_FRONT_LEFT, PA_CHANNEL_POSITION_FRONT_RIGHT,
- PA_CHANNEL_POSITION_REAR_LEFT, PA_CHANNEL_POSITION_REAR_RIGHT,
- PA_CHANNEL_POSITION_LFE }},
- "surround41", NULL,
- N_("Analog Surround 4.1"),
- "analog-surround-41",
- 7,
- "Master", "PCM",
- "Capture", "Mic" },
-
- {{ 5, { PA_CHANNEL_POSITION_FRONT_LEFT, PA_CHANNEL_POSITION_FRONT_RIGHT,
- PA_CHANNEL_POSITION_REAR_LEFT, PA_CHANNEL_POSITION_REAR_RIGHT,
- PA_CHANNEL_POSITION_CENTER }},
- "surround50", NULL,
- N_("Analog Surround 5.0"),
- "analog-surround-50",
- 7,
- "Master", "PCM",
- "Capture", "Mic" },
-
- {{ 6, { PA_CHANNEL_POSITION_FRONT_LEFT, PA_CHANNEL_POSITION_FRONT_RIGHT,
- PA_CHANNEL_POSITION_REAR_LEFT, PA_CHANNEL_POSITION_REAR_RIGHT,
- PA_CHANNEL_POSITION_CENTER, PA_CHANNEL_POSITION_LFE }},
- "surround51", NULL,
- N_("Analog Surround 5.1"),
- "analog-surround-51",
- 8,
- "Master", "PCM",
- "Capture", "Mic" },
-
- {{ 6, { PA_CHANNEL_POSITION_FRONT_LEFT, PA_CHANNEL_POSITION_FRONT_RIGHT,
- PA_CHANNEL_POSITION_REAR_LEFT, PA_CHANNEL_POSITION_REAR_RIGHT,
- PA_CHANNEL_POSITION_FRONT_CENTER, PA_CHANNEL_POSITION_LFE}},
- "a52", NULL,
- N_("Digital Surround 5.1 (IEC958/AC3)"),
- "iec958-ac3-surround-51",
- 3,
- "IEC958", NULL,
- "IEC958 In", NULL },
-
- {{ 8, { PA_CHANNEL_POSITION_FRONT_LEFT, PA_CHANNEL_POSITION_FRONT_RIGHT,
- PA_CHANNEL_POSITION_REAR_LEFT, PA_CHANNEL_POSITION_REAR_RIGHT,
- PA_CHANNEL_POSITION_CENTER, PA_CHANNEL_POSITION_LFE,
- PA_CHANNEL_POSITION_SIDE_LEFT, PA_CHANNEL_POSITION_SIDE_RIGHT }},
- "surround71", NULL,
- N_("Analog Surround 7.1"),
- "analog-surround-71",
- 7,
- "Master", "PCM",
- "Capture", "Mic" },
-
- {{ 0, { 0 }}, NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL }
-};
-
-static snd_pcm_t *open_by_device_string_with_fallback(
- const char *prefix,
- const char *prefix_fallback,
- const char *dev_id,
- char **dev,
- pa_sample_spec *ss,
- pa_channel_map* map,
- int mode,
- uint32_t *nfrags,
- snd_pcm_uframes_t *period_size,
- snd_pcm_uframes_t tsched_size,
- pa_bool_t *use_mmap,
- pa_bool_t *use_tsched,
- pa_bool_t require_exact_channel_number) {
-
- snd_pcm_t *pcm_handle;
- char *d;
-
- d = pa_sprintf_malloc("%s:%s", prefix, dev_id);
-
- pcm_handle = pa_alsa_open_by_device_string(
- d,
- dev,
- ss,
- map,
- mode,
- nfrags,
- period_size,
- tsched_size,
- use_mmap,
- use_tsched,
- require_exact_channel_number);
- pa_xfree(d);
-
- if (!pcm_handle && prefix_fallback) {
-
- d = pa_sprintf_malloc("%s:%s", prefix_fallback, dev_id);
-
- pcm_handle = pa_alsa_open_by_device_string(
- d,
- dev,
- ss,
- map,
- mode,
- nfrags,
- period_size,
- tsched_size,
- use_mmap,
- use_tsched,
- require_exact_channel_number);
- pa_xfree(d);
- }
-
- return pcm_handle;
-}
-
snd_pcm_t *pa_alsa_open_by_device_id_auto(
const char *dev_id,
char **dev,
@@ -550,12 +395,13 @@ snd_pcm_t *pa_alsa_open_by_device_id_auto(
snd_pcm_uframes_t tsched_size,
pa_bool_t *use_mmap,
pa_bool_t *use_tsched,
- const pa_alsa_profile_info **profile) {
+ pa_alsa_profile_set *ps,
+ pa_alsa_mapping **mapping) {
- int i;
- int direction = 1;
char *d;
snd_pcm_t *pcm_handle;
+ void *state;
+ pa_alsa_mapping *m;
pa_assert(dev_id);
pa_assert(dev);
@@ -563,113 +409,82 @@ snd_pcm_t *pa_alsa_open_by_device_id_auto(
pa_assert(map);
pa_assert(nfrags);
pa_assert(period_size);
+ pa_assert(ps);
/* First we try to find a device string with a superset of the
- * requested channel map and open it without the plug: prefix. We
- * iterate through our device table from top to bottom and take
- * the first that matches. If we didn't find a working device that
- * way, we iterate backwards, and check all devices that do not
- * provide a superset of the requested channel map.*/
-
- i = 0;
- for (;;) {
-
- if ((direction > 0) == pa_channel_map_superset(&device_table[i].map, map)) {
- pa_sample_spec try_ss;
-
- pa_log_debug("Checking for %s (%s)", device_table[i].name, device_table[i].alsa_name);
-
- try_ss.channels = device_table[i].map.channels;
- try_ss.rate = ss->rate;
- try_ss.format = ss->format;
+ * requested channel map. We iterate through our device table from
+ * top to bottom and take the first that matches. If we didn't
+ * find a working device that way, we iterate backwards, and check
+ * all devices that do not provide a superset of the requested
+ * channel map.*/
- pcm_handle = open_by_device_string_with_fallback(
- device_table[i].alsa_name,
- device_table[i].alsa_name_fallback,
- dev_id,
- dev,
- &try_ss,
- map,
- mode,
- nfrags,
- period_size,
- tsched_size,
- use_mmap,
- use_tsched,
- TRUE);
+ PA_HASHMAP_FOREACH(m, ps->mappings, state) {
+ if (!pa_channel_map_superset(&m->channel_map, map))
+ continue;
- if (pcm_handle) {
+ pa_log_debug("Checking for superset %s (%s)", m->name, m->device_strings[0]);
- *ss = try_ss;
- *map = device_table[i].map;
- pa_assert(map->channels == ss->channels);
-
- if (profile)
- *profile = &device_table[i];
-
- return pcm_handle;
- }
+ pcm_handle = pa_alsa_open_by_device_id_mapping(
+ dev_id,
+ dev,
+ ss,
+ map,
+ mode,
+ nfrags,
+ period_size,
+ tsched_size,
+ use_mmap,
+ use_tsched,
+ m);
- }
+ if (pcm_handle) {
+ if (mapping)
+ *mapping = m;
- if (direction > 0) {
- if (!device_table[i+1].alsa_name) {
- /* OK, so we are at the end of our list. Let's turn
- * back. */
- direction = -1;
- } else {
- /* We are not at the end of the list, so let's simply
- * try the next entry */
- i++;
- }
+ return pcm_handle;
}
+ }
- if (direction < 0) {
-
- if (device_table[i+1].alsa_name &&
- device_table[i].map.channels == device_table[i+1].map.channels) {
-
- /* OK, the next entry has the same number of channels,
- * let's try it */
- i++;
+ PA_HASHMAP_FOREACH_BACKWARDS(m, ps->mappings, state) {
+ if (pa_channel_map_superset(&m->channel_map, map))
+ continue;
- } else {
- /* Hmm, so the next entry does not have the same
- * number of channels, so let's go backwards until we
- * find the next entry with a different number of
- * channels */
+ pa_log_debug("Checking for subset %s (%s)", m->name, m->device_strings[0]);
- for (i--; i >= 0; i--)
- if (device_table[i].map.channels != device_table[i+1].map.channels)
- break;
+ pcm_handle = pa_alsa_open_by_device_id_mapping(
+ dev_id,
+ dev,
+ ss,
+ map,
+ mode,
+ nfrags,
+ period_size,
+ tsched_size,
+ use_mmap,
+ use_tsched,
+ m);
- /* Hmm, there is no entry with a different number of
- * entries, then we're done */
- if (i < 0)
- break;
+ if (pcm_handle) {
+ if (mapping)
+ *mapping = m;
- /* OK, now lets find go back as long as we have the same number of channels */
- for (; i > 0; i--)
- if (device_table[i].map.channels != device_table[i-1].map.channels)
- break;
- }
+ return pcm_handle;
}
}
- /* OK, we didn't find any good device, so let's try the raw plughw: stuff */
-
+ /* OK, we didn't find any good device, so let's try the raw hw: stuff */
d = pa_sprintf_malloc("hw:%s", dev_id);
pa_log_debug("Trying %s as last resort...", d);
pcm_handle = pa_alsa_open_by_device_string(d, dev, ss, map, mode, nfrags, period_size, tsched_size, use_mmap, use_tsched, FALSE);
pa_xfree(d);
- if (pcm_handle && profile)
- *profile = NULL;
+ if (pcm_handle && mapping)
+ *mapping = NULL;
return pcm_handle;
}
-snd_pcm_t *pa_alsa_open_by_device_id_profile(
+snd_pcm_t *pa_alsa_open_by_device_id_mapping(
const char *dev_id,
char **dev,
pa_sample_spec *ss,
@@ -680,10 +495,11 @@ snd_pcm_t *pa_alsa_open_by_device_id_profile(
snd_pcm_uframes_t tsched_size,
pa_bool_t *use_mmap,
pa_bool_t *use_tsched,
- const pa_alsa_profile_info *profile) {
+ pa_alsa_mapping *m) {
snd_pcm_t *pcm_handle;
pa_sample_spec try_ss;
+ pa_channel_map try_map;
pa_assert(dev_id);
pa_assert(dev);
@@ -691,19 +507,19 @@ snd_pcm_t *pa_alsa_open_by_device_id_profile(
pa_assert(map);
pa_assert(nfrags);
pa_assert(period_size);
- pa_assert(profile);
+ pa_assert(m);
- try_ss.channels = profile->map.channels;
+ try_ss.channels = m->channel_map.channels;
try_ss.rate = ss->rate;
try_ss.format = ss->format;
+ try_map = m->channel_map;
- pcm_handle = open_by_device_string_with_fallback(
- profile->alsa_name,
- profile->alsa_name_fallback,
+ pcm_handle = pa_alsa_open_by_device_string_strv(
+ m->device_strings,
dev_id,
dev,
&try_ss,
- map,
+ &try_map,
mode,
nfrags,
period_size,
@@ -716,7 +532,7 @@ snd_pcm_t *pa_alsa_open_by_device_id_profile(
return NULL;
*ss = try_ss;
- *map = profile->map;
+ *map = try_map;
pa_assert(map->channels == ss->channels);
return pcm_handle;
@@ -749,14 +565,8 @@ snd_pcm_t *pa_alsa_open_by_device_string(
for (;;) {
pa_log_debug("Trying %s %s SND_PCM_NO_AUTO_FORMAT ...", d, reformat ? "without" : "with");
- /* We don't pass SND_PCM_NONBLOCK here, since alsa-lib <=
- * 1.0.17a would then ignore the SND_PCM_NO_xxx flags. Instead
- * we enable nonblock mode afterwards via
- * snd_pcm_nonblock(). Also see
- * http://mailman.alsa-project.org/pipermail/alsa-devel/2008-August/010258.html */
-
if ((err = snd_pcm_open(&pcm_handle, d, mode,
- /*SND_PCM_NONBLOCK|*/
+ SND_PCM_NONBLOCK|
SND_PCM_NO_AUTO_RESAMPLE|
SND_PCM_NO_AUTO_CHANNELS|
(reformat ? 0 : SND_PCM_NO_AUTO_FORMAT))) < 0) {
@@ -776,7 +586,6 @@ snd_pcm_t *pa_alsa_open_by_device_string(
}
/* Hmm, some hw is very exotic, so we retry with plug, if without it didn't work */
-
if (!pa_startswith(d, "plug:") && !pa_startswith(d, "plughw:")) {
char *t;
@@ -813,90 +622,48 @@ fail:
return NULL;
}
-int pa_alsa_probe_profiles(
+snd_pcm_t *pa_alsa_open_by_device_string_strv(
+ char **prefix,
const char *dev_id,
- const pa_sample_spec *ss,
- void (*cb)(const pa_alsa_profile_info *sink, const pa_alsa_profile_info *source, void *userdata),
- void *userdata) {
-
- const pa_alsa_profile_info *i;
-
- pa_assert(dev_id);
- pa_assert(ss);
- pa_assert(cb);
-
- /* We try each combination of playback/capture. We also try to
- * open only for capture resp. only for sink. Don't get confused
- * by the trailing entry in device_table we use for this! */
-
- for (i = device_table; i < device_table + PA_ELEMENTSOF(device_table); i++) {
- const pa_alsa_profile_info *j;
- snd_pcm_t *pcm_i = NULL;
-
- if (i->alsa_name) {
- pa_sample_spec try_ss;
- pa_channel_map try_map;
-
- pa_log_debug("Checking for playback on %s (%s)", i->name, i->alsa_name);
-
- try_ss = *ss;
- try_ss.channels = i->map.channels;
- try_map = i->map;
-
- pcm_i = open_by_device_string_with_fallback(
- i->alsa_name,
- i->alsa_name_fallback,
- dev_id,
- NULL,
- &try_ss, &try_map,
- SND_PCM_STREAM_PLAYBACK,
- NULL, NULL, 0, NULL, NULL,
- TRUE);
-
- if (!pcm_i)
- continue;
- }
-
- for (j = device_table; j < device_table + PA_ELEMENTSOF(device_table); j++) {
- snd_pcm_t *pcm_j = NULL;
-
- if (j->alsa_name) {
- pa_sample_spec try_ss;
- pa_channel_map try_map;
-
- pa_log_debug("Checking for capture on %s (%s)", j->name, j->alsa_name);
+ char **dev,
+ pa_sample_spec *ss,
+ pa_channel_map* map,
+ int mode,
+ uint32_t *nfrags,
+ snd_pcm_uframes_t *period_size,
+ snd_pcm_uframes_t tsched_size,
+ pa_bool_t *use_mmap,
+ pa_bool_t *use_tsched,
+ pa_bool_t require_exact_channel_number) {
- try_ss = *ss;
- try_ss.channels = j->map.channels;
- try_map = j->map;
+ snd_pcm_t *pcm_handle;
+ char **i;
- pcm_j = open_by_device_string_with_fallback(
- j->alsa_name,
- j->alsa_name_fallback,
- dev_id,
- NULL,
- &try_ss, &try_map,
- SND_PCM_STREAM_CAPTURE,
- NULL, NULL, 0, NULL, NULL,
- TRUE);
+ for (i = prefix; *i; i++) {
+ char *d;
- if (!pcm_j)
- continue;
- }
+ d = pa_sprintf_malloc("%s:%s", *prefix, dev_id);
- if (pcm_j)
- snd_pcm_close(pcm_j);
+ pcm_handle = pa_alsa_open_by_device_string(
+ d,
+ dev,
+ ss,
+ map,
+ mode,
+ nfrags,
+ period_size,
+ tsched_size,
+ use_mmap,
+ use_tsched,
+ require_exact_channel_number);
- if (i->alsa_name || j->alsa_name)
- cb(i->alsa_name ? i : NULL,
- j->alsa_name ? j : NULL, userdata);
- }
+ pa_xfree(d);
- if (pcm_i)
- snd_pcm_close(pcm_i);
+ if (pcm_handle)
+ return pcm_handle;
}
- return TRUE;
+ return NULL;
}
void pa_alsa_dump(pa_log_level_t level, snd_pcm_t *pcm) {
@@ -922,24 +689,33 @@ void pa_alsa_dump_status(snd_pcm_t *pcm) {
int err;
snd_output_t *out;
snd_pcm_status_t *status;
+ char *s = NULL;
pa_assert(pcm);
snd_pcm_status_alloca(&status);
- pa_assert_se(snd_output_buffer_open(&out) == 0);
+ if ((err = snd_output_buffer_open(&out)) < 0) {
+ pa_log_debug("snd_output_buffer_open() failed: %s", pa_cstrerror(err));
+ return;
+ }
- pa_assert_se(snd_pcm_status(pcm, status) == 0);
+ if ((err = snd_pcm_status(pcm, status)) < 0) {
+ pa_log_debug("snd_pcm_status() failed: %s", pa_cstrerror(err));
+ goto finish;
+ }
- if ((err = snd_pcm_status_dump(status, out)) < 0)
+ if ((err = snd_pcm_status_dump(status, out)) < 0) {
pa_log_debug("snd_pcm_dump(): %s", pa_alsa_strerror(err));
- else {
- char *s = NULL;
- snd_output_buffer_string(out, &s);
- pa_log_debug("snd_pcm_dump():\n%s", pa_strnull(s));
+ goto finish;
}
- pa_assert_se(snd_output_close(out) == 0);
+ snd_output_buffer_string(out, &s);
+ pa_log_debug("snd_pcm_dump():\n%s", pa_strnull(s));
+
+finish:
+
+ snd_output_close(out);
}
static void alsa_error_handler(const char *file, int line, const char *function, int err, const char *fmt,...) {
@@ -1019,7 +795,7 @@ void pa_alsa_init_proplist_card(pa_core *c, pa_proplist *p, int card) {
}
#ifdef HAVE_UDEV
- pa_udev_get_info(c, p, card);
+ pa_udev_get_info(card, p);
#endif
#ifdef HAVE_HAL
@@ -1056,16 +832,15 @@ void pa_alsa_init_proplist_pcm_info(pa_core *c, pa_proplist *p, snd_pcm_info_t *
pa_proplist_sets(p, PA_PROP_DEVICE_API, "alsa");
- class = snd_pcm_info_get_class(pcm_info);
- if (class <= SND_PCM_CLASS_LAST) {
+ if ((class = snd_pcm_info_get_class(pcm_info)) <= SND_PCM_CLASS_LAST) {
if (class_table[class])
pa_proplist_sets(p, PA_PROP_DEVICE_CLASS, class_table[class]);
if (alsa_class_table[class])
pa_proplist_sets(p, "alsa.class", alsa_class_table[class]);
}
- subclass = snd_pcm_info_get_subclass(pcm_info);
- if (subclass <= SND_PCM_SUBCLASS_LAST)
+
+ if ((subclass = snd_pcm_info_get_subclass(pcm_info)) <= SND_PCM_SUBCLASS_LAST)
if (alsa_subclass_table[subclass])
pa_proplist_sets(p, "alsa.subclass", alsa_subclass_table[subclass]);
@@ -1085,7 +860,7 @@ void pa_alsa_init_proplist_pcm_info(pa_core *c, pa_proplist *p, snd_pcm_info_t *
pa_alsa_init_proplist_card(c, p, card);
}
-void pa_alsa_init_proplist_pcm(pa_core *c, pa_proplist *p, snd_pcm_t *pcm, snd_mixer_elem_t *elem) {
+void pa_alsa_init_proplist_pcm(pa_core *c, pa_proplist *p, snd_pcm_t *pcm) {
snd_pcm_hw_params_t *hwparams;
snd_pcm_info_t *info;
int bits, err;
@@ -1101,9 +876,6 @@ void pa_alsa_init_proplist_pcm(pa_core *c, pa_proplist *p, snd_pcm_t *pcm, snd_m
pa_proplist_setf(p, "alsa.resolution_bits", "%i", bits);
}
- if (elem)
- pa_proplist_sets(p, "alsa.mixer_element", snd_mixer_selem_get_name(elem));
-
if ((err = snd_pcm_info(pcm, info)) < 0)
pa_log_warn("Error fetching PCM info: %s", pa_alsa_strerror(err));
else
diff --git a/src/modules/alsa/alsa-util.h b/src/modules/alsa/alsa-util.h
index 0e196af..4993f45 100644
--- a/src/modules/alsa/alsa-util.h
+++ b/src/modules/alsa/alsa-util.h
@@ -37,82 +37,79 @@
#include <pulsecore/core.h>
#include <pulsecore/log.h>
-typedef struct pa_alsa_profile_info pa_alsa_profile_info;
-
#include "alsa-mixer.h"
int pa_alsa_set_hw_params(
snd_pcm_t *pcm_handle,
- pa_sample_spec *ss,
- uint32_t *periods,
- snd_pcm_uframes_t *period_size,
+ pa_sample_spec *ss, /* modified at return */
+ uint32_t *periods, /* modified at return */
+ snd_pcm_uframes_t *period_size, /* modified at return */
snd_pcm_uframes_t tsched_size,
- pa_bool_t *use_mmap,
- pa_bool_t *use_tsched,
+ pa_bool_t *use_mmap, /* modified at return */
+ pa_bool_t *use_tsched, /* modified at return */
pa_bool_t require_exact_channel_number);
int pa_alsa_set_sw_params(
snd_pcm_t *pcm,
snd_pcm_uframes_t avail_min);
-struct pa_alsa_profile_info {
- pa_channel_map map;
- const char *alsa_name;
- const char *alsa_name_fallback;
- const char *description; /* internationalized */
- const char *name;
- unsigned priority;
- const char *playback_control_name, *playback_control_fallback;
- const char *record_control_name, *record_control_fallback;
-};
-
-/* Picks a working profile based on the specified ss/map */
+/* Picks a working mapping from the profile set based on the specified ss/map */
snd_pcm_t *pa_alsa_open_by_device_id_auto(
const char *dev_id,
- char **dev,
- pa_sample_spec *ss,
- pa_channel_map* map,
+ char **dev, /* modified at return */
+ pa_sample_spec *ss, /* modified at return */
+ pa_channel_map* map, /* modified at return */
int mode,
- uint32_t *nfrags,
- snd_pcm_uframes_t *period_size,
+ uint32_t *nfrags, /* modified at return */
+ snd_pcm_uframes_t *period_size, /* modified at return */
snd_pcm_uframes_t tsched_size,
- pa_bool_t *use_mmap,
- pa_bool_t *use_tsched,
- const pa_alsa_profile_info **profile);
+ pa_bool_t *use_mmap, /* modified at return */
+ pa_bool_t *use_tsched, /* modified at return */
+ pa_alsa_profile_set *ps,
+ pa_alsa_mapping **mapping); /* modified at return */
-/* Uses the specified profile */
-snd_pcm_t *pa_alsa_open_by_device_id_profile(
+/* Uses the specified mapping */
+snd_pcm_t *pa_alsa_open_by_device_id_mapping(
const char *dev_id,
- char **dev,
- pa_sample_spec *ss,
- pa_channel_map* map,
+ char **dev, /* modified at return */
+ pa_sample_spec *ss, /* modified at return */
+ pa_channel_map* map, /* modified at return */
int mode,
- uint32_t *nfrags,
- snd_pcm_uframes_t *period_size,
+ uint32_t *nfrags, /* modified at return */
+ snd_pcm_uframes_t *period_size, /* modified at return */
snd_pcm_uframes_t tsched_size,
- pa_bool_t *use_mmap,
- pa_bool_t *use_tsched,
- const pa_alsa_profile_info *profile);
+ pa_bool_t *use_mmap, /* modified at return */
+ pa_bool_t *use_tsched, /* modified at return */
+ pa_alsa_mapping *mapping);
/* Opens the explicit ALSA device */
snd_pcm_t *pa_alsa_open_by_device_string(
const char *device,
- char **dev,
- pa_sample_spec *ss,
- pa_channel_map* map,
+ char **dev, /* modified at return */
+ pa_sample_spec *ss, /* modified at return */
+ pa_channel_map* map, /* modified at return */
int mode,
- uint32_t *nfrags,
- snd_pcm_uframes_t *period_size,
+ uint32_t *nfrags, /* modified at return */
+ snd_pcm_uframes_t *period_size, /* modified at return */
snd_pcm_uframes_t tsched_size,
- pa_bool_t *use_mmap,
- pa_bool_t *use_tsched,
+ pa_bool_t *use_mmap, /* modified at return */
+ pa_bool_t *use_tsched, /* modified at return */
pa_bool_t require_exact_channel_number);
-int pa_alsa_probe_profiles(
+/* Opens the explicit ALSA device with a fallback list */
+snd_pcm_t *pa_alsa_open_by_device_string_strv(
+ char **device,
const char *dev_id,
- const pa_sample_spec *ss,
- void (*cb)(const pa_alsa_profile_info *sink, const pa_alsa_profile_info *source, void *userdata),
- void *userdata);
+ char **dev, /* modified at return */
+ pa_sample_spec *ss, /* modified at return */
+ pa_channel_map* map, /* modified at return */
+ int mode,
+ uint32_t *nfrags, /* modified at return */
+ snd_pcm_uframes_t *period_size, /* modified at return */
+ snd_pcm_uframes_t tsched_size,
+ pa_bool_t *use_mmap, /* modified at return */
+ pa_bool_t *use_tsched, /* modified at return */
+ pa_bool_t require_exact_channel_number);
void pa_alsa_dump(pa_log_level_t level, snd_pcm_t *pcm);
void pa_alsa_dump_status(snd_pcm_t *pcm);
@@ -122,7 +119,7 @@ void pa_alsa_redirect_errors_dec(void);
void pa_alsa_init_proplist_pcm_info(pa_core *c, pa_proplist *p, snd_pcm_info_t *pcm_info);
void pa_alsa_init_proplist_card(pa_core *c, pa_proplist *p, int card);
-void pa_alsa_init_proplist_pcm(pa_core *c, pa_proplist *p, snd_pcm_t *pcm, snd_mixer_elem_t *elem);
+void pa_alsa_init_proplist_pcm(pa_core *c, pa_proplist *p, snd_pcm_t *pcm);
void pa_alsa_init_proplist_ctl(pa_proplist *p, const char *name);
pa_bool_t pa_alsa_init_description(pa_proplist *p);
diff --git a/src/modules/alsa/module-alsa-card.c b/src/modules/alsa/module-alsa-card.c
index ad52f5e..ca2c07f 100644
--- a/src/modules/alsa/module-alsa-card.c
+++ b/src/modules/alsa/module-alsa-card.c
@@ -32,6 +32,10 @@
#include <modules/reserve-wrap.h>
+#ifdef HAVE_UDEV
+#include <modules/udev-util.h>
+#endif
+
#include "alsa-util.h"
#include "alsa-sink.h"
#include "alsa-source.h"
@@ -92,81 +96,53 @@ struct userdata {
char *device_id;
pa_card *card;
- pa_sink *sink;
- pa_source *source;
pa_modargs *modargs;
- pa_hashmap *profiles;
+ pa_alsa_profile_set *profile_set;
};
struct profile_data {
- const pa_alsa_profile_info *sink_profile, *source_profile;
+ pa_alsa_profile *profile;
};
-static void enumerate_cb(
- const pa_alsa_profile_info *sink,
- const pa_alsa_profile_info *source,
- void *userdata) {
-
- struct userdata *u = userdata;
- char *t, *n;
- pa_card_profile *p;
- struct profile_data *d;
- unsigned bonus = 0;
-
- if (sink && source) {
- n = pa_sprintf_malloc("output-%s+input-%s", sink->name, source->name);
- t = pa_sprintf_malloc(_("Output %s + Input %s"), sink->description, _(source->description));
- } else if (sink) {
- n = pa_sprintf_malloc("output-%s", sink->name);
- t = pa_sprintf_malloc(_("Output %s"), _(sink->description));
- } else {
- pa_assert(source);
- n = pa_sprintf_malloc("input-%s", source->name);
- t = pa_sprintf_malloc(_("Input %s"), _(source->description));
- }
-
- if (sink) {
- if (pa_channel_map_equal(&sink->map, &u->core->default_channel_map))
- bonus += 50000;
- else if (sink->map.channels == u->core->default_channel_map.channels)
- bonus += 40000;
- }
-
- if (source) {
- if (pa_channel_map_equal(&source->map, &u->core->default_channel_map))
- bonus += 30000;
- else if (source->map.channels == u->core->default_channel_map.channels)
- bonus += 20000;
- }
+static void add_profiles(struct userdata *u, pa_hashmap *h) {
+ pa_alsa_profile *ap;
+ void *state;
- pa_log_info("Found profile '%s'", t);
+ pa_assert(u);
+ pa_assert(h);
- p = pa_card_profile_new(n, t, sizeof(struct profile_data));
+ PA_HASHMAP_FOREACH(ap, u->profile_set->profiles, state) {
+ struct profile_data *d;
+ pa_card_profile *cp;
+ pa_alsa_mapping *m;
+ uint32_t idx;
- pa_xfree(t);
- pa_xfree(n);
+ cp = pa_card_profile_new(ap->name, ap->description, sizeof(struct profile_data));
+ cp->priority = ap->priority;
- p->priority =
- (sink ? sink->priority : 0) * 100 +
- (source ? source->priority : 0) +
- bonus;
+ if (ap->output_mappings) {
+ cp->n_sinks = pa_idxset_size(ap->output_mappings);
- p->n_sinks = !!sink;
- p->n_sources = !!source;
+ PA_IDXSET_FOREACH(m, ap->output_mappings, idx)
+ if (m->channel_map.channels > cp->max_sink_channels)
+ cp->max_sink_channels = m->channel_map.channels;
+ }
- if (sink)
- p->max_sink_channels = sink->map.channels;
- if (source)
- p->max_source_channels = source->map.channels;
+ if (ap->input_mappings) {
+ cp->n_sources = pa_idxset_size(ap->input_mappings);
- d = PA_CARD_PROFILE_DATA(p);
+ PA_IDXSET_FOREACH(m, ap->input_mappings, idx)
+ if (m->channel_map.channels > cp->max_source_channels)
+ cp->max_source_channels = m->channel_map.channels;
+ }
- d->sink_profile = sink;
- d->source_profile = source;
+ d = PA_CARD_PROFILE_DATA(cp);
+ d->profile = ap;
- pa_hashmap_put(u->profiles, p->name, p);
+ pa_hashmap_put(h, cp->name, cp);
+ }
}
static void add_disabled_profile(pa_hashmap *profiles) {
@@ -176,7 +152,7 @@ static void add_disabled_profile(pa_hashmap *profiles) {
p = pa_card_profile_new("off", _("Off"), sizeof(struct profile_data));
d = PA_CARD_PROFILE_DATA(p);
- d->sink_profile = d->source_profile = NULL;
+ d->profile = NULL;
pa_hashmap_put(profiles, p->name, p);
}
@@ -184,6 +160,9 @@ static void add_disabled_profile(pa_hashmap *profiles) {
static int card_set_profile(pa_card *c, pa_card_profile *new_profile) {
struct userdata *u;
struct profile_data *nd, *od;
+ uint32_t idx;
+ pa_alsa_mapping *am;
+ pa_queue *sink_inputs = NULL, *source_outputs = NULL;
pa_assert(c);
pa_assert(new_profile);
@@ -192,67 +171,83 @@ static int card_set_profile(pa_card *c, pa_card_profile *new_profile) {
nd = PA_CARD_PROFILE_DATA(new_profile);
od = PA_CARD_PROFILE_DATA(c->active_profile);
- if (od->sink_profile != nd->sink_profile) {
- pa_queue *inputs = NULL;
+ if (od->profile && od->profile->output_mappings)
+ PA_IDXSET_FOREACH(am, od->profile->output_mappings, idx) {
+ if (!am->sink)
+ continue;
- if (u->sink) {
- if (nd->sink_profile)
- inputs = pa_sink_move_all_start(u->sink);
+ if (nd->profile &&
+ nd->profile->output_mappings &&
+ pa_idxset_get_by_data(nd->profile->output_mappings, am, NULL))
+ continue;
- pa_alsa_sink_free(u->sink);
- u->sink = NULL;
+ sink_inputs = pa_sink_move_all_start(am->sink, sink_inputs);
+ pa_alsa_sink_free(am->sink);
+ am->sink = NULL;
}
- if (nd->sink_profile) {
- u->sink = pa_alsa_sink_new(c->module, u->modargs, __FILE__, c, nd->sink_profile);
+ if (od->profile && od->profile->input_mappings)
+ PA_IDXSET_FOREACH(am, od->profile->input_mappings, idx) {
+ if (!am->source)
+ continue;
- if (inputs) {
- if (u->sink)
- pa_sink_move_all_finish(u->sink, inputs, FALSE);
- else
- pa_sink_move_all_fail(inputs);
- }
+ if (nd->profile &&
+ nd->profile->input_mappings &&
+ pa_idxset_get_by_data(nd->profile->input_mappings, am, NULL))
+ continue;
+
+ source_outputs = pa_source_move_all_start(am->source, source_outputs);
+ pa_alsa_source_free(am->source);
+ am->source = NULL;
}
- }
- if (od->source_profile != nd->source_profile) {
- pa_queue *outputs = NULL;
+ if (nd->profile && nd->profile->output_mappings)
+ PA_IDXSET_FOREACH(am, nd->profile->output_mappings, idx) {
- if (u->source) {
- if (nd->source_profile)
- outputs = pa_source_move_all_start(u->source);
+ if (!am->sink)
+ am->sink = pa_alsa_sink_new(c->module, u->modargs, __FILE__, c, am);
- pa_alsa_source_free(u->source);
- u->source = NULL;
+ if (sink_inputs && am->sink) {
+ pa_sink_move_all_finish(am->sink, sink_inputs, FALSE);
+ sink_inputs = NULL;
+ }
}
- if (nd->source_profile) {
- u->source = pa_alsa_source_new(c->module, u->modargs, __FILE__, c, nd->source_profile);
+ if (nd->profile && nd->profile->input_mappings)
+ PA_IDXSET_FOREACH(am, nd->profile->input_mappings, idx) {
+
+ if (!am->source)
+ am->source = pa_alsa_source_new(c->module, u->modargs, __FILE__, c, am);
- if (outputs) {
- if (u->source)
- pa_source_move_all_finish(u->source, outputs, FALSE);
- else
- pa_source_move_all_fail(outputs);
+ if (source_outputs && am->source) {
+ pa_source_move_all_finish(am->source, source_outputs, FALSE);
+ source_outputs = NULL;
}
}
- }
+
+ if (sink_inputs)
+ pa_sink_move_all_fail(sink_inputs);
+
+ if (source_outputs)
+ pa_source_move_all_fail(source_outputs);
return 0;
}
static void init_profile(struct userdata *u) {
+ uint32_t idx;
+ pa_alsa_mapping *am;
struct profile_data *d;
pa_assert(u);
d = PA_CARD_PROFILE_DATA(u->card->active_profile);
- if (d->sink_profile)
- u->sink = pa_alsa_sink_new(u->module, u->modargs, __FILE__, u->card, d->sink_profile);
+ PA_IDXSET_FOREACH(am, d->profile->output_mappings, idx)
+ am->sink = pa_alsa_sink_new(u->module, u->modargs, __FILE__, u->card, am);
- if (d->source_profile)
- u->source = pa_alsa_source_new(u->module, u->modargs, __FILE__, u->card, d->source_profile);
+ PA_IDXSET_FOREACH(am, d->profile->input_mappings, idx)
+ am->source = pa_alsa_source_new(u->module, u->modargs, __FILE__, u->card, am);
}
static void set_card_name(pa_card_new_data *data, pa_modargs *ma, const char *device_id) {
@@ -286,9 +281,9 @@ int pa__init(pa_module *m) {
pa_modargs *ma;
int alsa_card_index;
struct userdata *u;
- char rname[32];
pa_reserve_wrapper *reserve = NULL;
const char *description;
+ char *fn = NULL;
pa_alsa_redirect_errors_inc();
snd_config_update_free_global();
@@ -304,9 +299,6 @@ int pa__init(pa_module *m) {
u->core = m->core;
u->module = m;
u->device_id = pa_xstrdup(pa_modargs_get_value(ma, "device_id", DEFAULT_DEVICE_ID));
- u->card = NULL;
- u->sink = NULL;
- u->source = NULL;
u->modargs = ma;
if ((alsa_card_index = snd_card_get_index(u->device_id)) < 0) {
@@ -314,16 +306,34 @@ int pa__init(pa_module *m) {
goto fail;
}
- pa_snprintf(rname, sizeof(rname), "Audio%i", alsa_card_index);
+ if (!pa_in_system_mode()) {
+ char *rname;
+
+ if ((rname = pa_alsa_get_reserve_name(u->device_id))) {
+ reserve = pa_reserve_wrapper_get(m->core, rname);
+ pa_xfree(rname);
+
+ if (!reserve)
+ goto fail;
+ }
+ }
+
+#ifdef HAVE_UDEV
+ fn = pa_udev_get_property(alsa_card_index, "PULSE_PROFILE_SET");
+#endif
+
+ u->profile_set = pa_alsa_profile_set_new(fn, &u->core->default_channel_map);
+ pa_xfree(fn);
- if (!pa_in_system_mode())
- if (!(reserve = pa_reserve_wrapper_get(m->core, rname)))
- goto fail;
+ if (!u->profile_set)
+ goto fail;
pa_card_new_data_init(&data);
data.driver = __FILE__;
data.module = m;
+
pa_alsa_init_proplist_card(m->core, data.proplist, alsa_card_index);
+
pa_proplist_sets(data.proplist, PA_PROP_DEVICE_STRING, u->device_id);
pa_alsa_init_description(data.proplist);
set_card_name(&data, ma, u->device_id);
@@ -332,11 +342,8 @@ int pa__init(pa_module *m) {
if ((description = pa_proplist_gets(data.proplist, PA_PROP_DEVICE_DESCRIPTION)))
pa_reserve_wrapper_set_application_device_name(reserve, description);
- u->profiles = data.profiles = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
- if (pa_alsa_probe_profiles(u->device_id, &m->core->default_sample_spec, enumerate_cb, u) < 0) {
- pa_card_new_data_done(&data);
- goto fail;
- }
+ data.profiles = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
+ add_profiles(u, data.profiles);
if (pa_hashmap_isempty(data.profiles)) {
pa_log("Failed to find a working profile.");
@@ -379,13 +386,22 @@ fail:
int pa__get_n_used(pa_module *m) {
struct userdata *u;
+ int n = 0;
+ uint32_t idx;
+ pa_sink *sink;
+ pa_source *source;
pa_assert(m);
pa_assert_se(u = m->userdata);
+ pa_assert(u->card);
+
+ PA_IDXSET_FOREACH(sink, u->card->sinks, idx)
+ n += pa_sink_linked_by(sink);
- return
- (u->sink ? pa_sink_linked_by(u->sink) : 0) +
- (u->source ? pa_source_linked_by(u->source) : 0);
+ PA_IDXSET_FOREACH(source, u->card->sources, idx)
+ n += pa_source_linked_by(source);
+
+ return n;
}
void pa__done(pa_module*m) {
@@ -396,11 +412,19 @@ void pa__done(pa_module*m) {
if (!(u = m->userdata))
goto finish;
- if (u->sink)
- pa_alsa_sink_free(u->sink);
+ if (u->card && u->card->sinks) {
+ pa_sink *s;
+
+ while ((s = pa_idxset_steal_first(u->card->sinks, NULL)))
+ pa_alsa_sink_free(s);
+ }
+
+ if (u->card && u->card->sources) {
+ pa_source *s;
- if (u->source)
- pa_alsa_source_free(u->source);
+ while ((s = pa_idxset_steal_first(u->card->sources, NULL)))
+ pa_alsa_source_free(s);
+ }
if (u->card)
pa_card_free(u->card);
@@ -408,6 +432,9 @@ void pa__done(pa_module*m) {
if (u->modargs)
pa_modargs_free(u->modargs);
+ if (u->profile_set)
+ pa_alsa_profile_set_free(u->profile_set);
+
pa_xfree(u->device_id);
pa_xfree(u);
diff --git a/src/modules/bluetooth/module-bluetooth-device.c b/src/modules/bluetooth/module-bluetooth-device.c
index 40093cf..9fec4ed 100644
--- a/src/modules/bluetooth/module-bluetooth-device.c
+++ b/src/modules/bluetooth/module-bluetooth-device.c
@@ -1443,12 +1443,12 @@ static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *m, void *us
if (u->sink && dbus_message_is_signal(m, "org.bluez.Headset", "SpeakerGainChanged")) {
pa_cvolume_set(&v, u->sample_spec.channels, (pa_volume_t) (gain * PA_VOLUME_NORM / 15));
- pa_sink_volume_changed(u->sink, &v);
+ pa_sink_volume_changed(u->sink, &v, TRUE);
} else if (u->source && dbus_message_is_signal(m, "org.bluez.Headset", "MicrophoneGainChanged")) {
pa_cvolume_set(&v, u->sample_spec.channels, (pa_volume_t) (gain * PA_VOLUME_NORM / 15));
- pa_source_volume_changed(u->source, &v);
+ pa_source_volume_changed(u->source, &v, TRUE);
}
}
}
@@ -1938,7 +1938,7 @@ static int card_set_profile(pa_card *c, pa_card_profile *new_profile) {
}
if (u->sink) {
- inputs = pa_sink_move_all_start(u->sink);
+ inputs = pa_sink_move_all_start(u->sink, NULL);
#ifdef NOKIA
if (!USE_SCO_OVER_PCM(u))
#endif
@@ -1946,7 +1946,7 @@ static int card_set_profile(pa_card *c, pa_card_profile *new_profile) {
}
if (u->source) {
- outputs = pa_source_move_all_start(u->source);
+ outputs = pa_source_move_all_start(u->source, NULL);
#ifdef NOKIA
if (!USE_SCO_OVER_PCM(u))
#endif
diff --git a/src/modules/bluetooth/module-bluetooth-proximity.c b/src/modules/bluetooth/module-bluetooth-proximity.c
index 9993c8d..c4cfd73 100644
--- a/src/modules/bluetooth/module-bluetooth-proximity.c
+++ b/src/modules/bluetooth/module-bluetooth-proximity.c
@@ -109,7 +109,7 @@ static void update_volume(struct userdata *u) {
}
pa_log_info("Found %u BT devices, unmuting.", u->n_found);
- pa_sink_set_mute(s, FALSE);
+ pa_sink_set_mute(s, FALSE, FALSE);
} else if (!u->muted && (u->n_found+u->n_unknown) <= 0) {
pa_sink *s;
@@ -122,7 +122,7 @@ static void update_volume(struct userdata *u) {
}
pa_log_info("No BT devices found, muting.");
- pa_sink_set_mute(s, TRUE);
+ pa_sink_set_mute(s, TRUE, FALSE);
} else
pa_log_info("%u devices now active, %u with unknown state.", u->n_found, u->n_unknown);
diff --git a/src/modules/module-lirc.c b/src/modules/module-lirc.c
index 83f7f28..06efeb8 100644
--- a/src/modules/module-lirc.c
+++ b/src/modules/module-lirc.c
@@ -133,7 +133,7 @@ static void io_callback(pa_mainloop_api *io, pa_io_event *e, int fd, pa_io_event
cv.values[i] = PA_VOLUME_MAX;
}
- pa_sink_set_volume(s, &cv, TRUE, TRUE, TRUE);
+ pa_sink_set_volume(s, &cv, TRUE, TRUE, TRUE, TRUE);
break;
case DOWN:
@@ -144,20 +144,20 @@ static void io_callback(pa_mainloop_api *io, pa_io_event *e, int fd, pa_io_event
cv.values[i] = PA_VOLUME_MUTED;
}
- pa_sink_set_volume(s, &cv, TRUE, TRUE, TRUE);
+ pa_sink_set_volume(s, &cv, TRUE, TRUE, TRUE, TRUE);
break;
case MUTE:
- pa_sink_set_mute(s, TRUE);
+ pa_sink_set_mute(s, TRUE, TRUE);
break;
case RESET:
- pa_sink_set_mute(s, FALSE);
+ pa_sink_set_mute(s, FALSE, TRUE);
break;
case MUTE_TOGGLE:
- pa_sink_set_mute(s, !pa_sink_get_mute(s, FALSE));
+ pa_sink_set_mute(s, !pa_sink_get_mute(s, FALSE), TRUE);
break;
case INVALID:
diff --git a/src/modules/module-mmkbd-evdev.c b/src/modules/module-mmkbd-evdev.c
index d8b9c79..b30fae5 100644
--- a/src/modules/module-mmkbd-evdev.c
+++ b/src/modules/module-mmkbd-evdev.c
@@ -115,7 +115,7 @@ static void io_callback(pa_mainloop_api *io, pa_io_event *e, int fd, pa_io_event
cv.values[i] = PA_VOLUME_MAX;
}
- pa_sink_set_volume(s, &cv, TRUE, TRUE, TRUE);
+ pa_sink_set_volume(s, &cv, TRUE, TRUE, TRUE, TRUE);
break;
case DOWN:
@@ -126,12 +126,12 @@ static void io_callback(pa_mainloop_api *io, pa_io_event *e, int fd, pa_io_event
cv.values[i] = PA_VOLUME_MUTED;
}
- pa_sink_set_volume(s, &cv, TRUE, TRUE, TRUE);
+ pa_sink_set_volume(s, &cv, TRUE, TRUE, TRUE, TRUE);
break;
case MUTE_TOGGLE:
- pa_sink_set_mute(s, !pa_sink_get_mute(s, FALSE));
+ pa_sink_set_mute(s, !pa_sink_get_mute(s, FALSE), TRUE);
break;
case INVALID:
diff --git a/src/modules/module-tunnel.c b/src/modules/module-tunnel.c
index bea1dd4..c493d9b 100644
--- a/src/modules/module-tunnel.c
+++ b/src/modules/module-tunnel.c
@@ -1157,10 +1157,10 @@ static void sink_input_info_cb(pa_pdispatch *pd, uint32_t command, uint32_t tag
pa_cvolume_equal(&volume, &u->sink->virtual_volume))
return;
- pa_sink_volume_changed(u->sink, &volume);
+ pa_sink_volume_changed(u->sink, &volume, FALSE);
if (u->version >= 11)
- pa_sink_mute_changed(u->sink, mute);
+ pa_sink_mute_changed(u->sink, mute, FALSE);
return;
diff --git a/src/modules/udev-util.c b/src/modules/udev-util.c
index de8f5f2..cc82446 100644
--- a/src/modules/udev-util.c
+++ b/src/modules/udev-util.c
@@ -58,7 +58,7 @@ static int read_id(struct udev_device *d, const char *n) {
return u;
}
-int pa_udev_get_info(pa_core *core, pa_proplist *p, int card_idx) {
+int pa_udev_get_info(int card_idx, pa_proplist *p) {
int r = -1;
struct udev *udev;
struct udev_device *card = NULL;
@@ -66,7 +66,6 @@ int pa_udev_get_info(pa_core *core, pa_proplist *p, int card_idx) {
const char *v;
int id;
- pa_assert(core);
pa_assert(p);
pa_assert(card_idx >= 0);
@@ -153,3 +152,40 @@ finish:
return r;
}
+
+char* pa_udev_get_property(int card_idx, const char *name) {
+ struct udev *udev;
+ struct udev_device *card = NULL;
+ char *t, *r = NULL;
+ const char *v;
+
+ pa_assert(card_idx >= 0);
+ pa_assert(name);
+
+ if (!(udev = udev_new())) {
+ pa_log_error("Failed to allocate udev context.");
+ goto finish;
+ }
+
+ t = pa_sprintf_malloc("%s/class/sound/card%i", udev_get_sys_path(udev), card_idx);
+ card = udev_device_new_from_syspath(udev, t);
+ pa_xfree(t);
+
+ if (!card) {
+ pa_log_error("Failed to get card object.");
+ goto finish;
+ }
+
+ if ((v = udev_device_get_property_value(card, name)) && *v)
+ r = pa_xstrdup(v);
+
+finish:
+
+ if (card)
+ udev_device_unref(card);
+
+ if (udev)
+ udev_unref(udev);
+
+ return r;
+}
diff --git a/src/modules/udev-util.h b/src/modules/udev-util.h
index 5120abd..8523bc4 100644
--- a/src/modules/udev-util.h
+++ b/src/modules/udev-util.h
@@ -25,6 +25,7 @@
#include <pulsecore/core.h>
-int pa_udev_get_info(pa_core *core, pa_proplist *p, int card);
+int pa_udev_get_info(int card_idx, pa_proplist *p);
+char* pa_udev_get_property(int card_idx, const char *name);
#endif
diff --git a/src/pulse/version.h.in b/src/pulse/version.h.in
index 3143e98..c2c1f20 100644
--- a/src/pulse/version.h.in
+++ b/src/pulse/version.h.in
@@ -64,8 +64,8 @@ const char* pa_get_library_version(void);
* newer than the specified. \since 0.9.16 */
#define PA_CHECK_VERSION(major,minor,micro) \
((PA_MAJOR > (major)) || \
- (PA_MAJOR == (major) && CA_MINOR > (minor)) || \
- (PA_MAJOR == (major) && CA_MINOR == (minor) && CA_MICRO >= (micro)))
+ (PA_MAJOR == (major) && PA_MINOR > (minor)) || \
+ (PA_MAJOR == (major) && PA_MINOR == (minor) && PA_MICRO >= (micro)))
PA_C_DECL_END
diff --git a/src/pulse/volume.c b/src/pulse/volume.c
index 308c121..42cde5b 100644
--- a/src/pulse/volume.c
+++ b/src/pulse/volume.c
@@ -346,7 +346,7 @@ pa_cvolume *pa_sw_cvolume_multiply(pa_cvolume *dest, const pa_cvolume *a, const
pa_return_val_if_fail(pa_cvolume_valid(a), NULL);
pa_return_val_if_fail(pa_cvolume_valid(b), NULL);
- for (i = 0; i < a->channels && i < b->channels && i < PA_CHANNELS_MAX; i++)
+ for (i = 0; i < a->channels && i < b->channels; i++)
dest->values[i] = pa_sw_volume_multiply(a->values[i], b->values[i]);
dest->channels = (uint8_t) i;
@@ -354,6 +354,22 @@ pa_cvolume *pa_sw_cvolume_multiply(pa_cvolume *dest, const pa_cvolume *a, const
return dest;
}
+pa_cvolume *pa_sw_cvolume_multiply_scalar(pa_cvolume *dest, const pa_cvolume *a, pa_volume_t b) {
+ unsigned i;
+
+ pa_assert(dest);
+ pa_assert(a);
+
+ pa_return_val_if_fail(pa_cvolume_valid(a), NULL);
+
+ for (i = 0; i < a->channels; i++)
+ dest->values[i] = pa_sw_volume_multiply(a->values[i], b);
+
+ dest->channels = (uint8_t) i;
+
+ return dest;
+}
+
pa_cvolume *pa_sw_cvolume_divide(pa_cvolume *dest, const pa_cvolume *a, const pa_cvolume *b) {
unsigned i;
@@ -364,7 +380,7 @@ pa_cvolume *pa_sw_cvolume_divide(pa_cvolume *dest, const pa_cvolume *a, const pa
pa_return_val_if_fail(pa_cvolume_valid(a), NULL);
pa_return_val_if_fail(pa_cvolume_valid(b), NULL);
- for (i = 0; i < a->channels && i < b->channels && i < PA_CHANNELS_MAX; i++)
+ for (i = 0; i < a->channels && i < b->channels; i++)
dest->values[i] = pa_sw_volume_divide(a->values[i], b->values[i]);
dest->channels = (uint8_t) i;
@@ -372,6 +388,22 @@ pa_cvolume *pa_sw_cvolume_divide(pa_cvolume *dest, const pa_cvolume *a, const pa
return dest;
}
+pa_cvolume *pa_sw_cvolume_divide_scalar(pa_cvolume *dest, const pa_cvolume *a, pa_volume_t b) {
+ unsigned i;
+
+ pa_assert(dest);
+ pa_assert(a);
+
+ pa_return_val_if_fail(pa_cvolume_valid(a), NULL);
+
+ for (i = 0; i < a->channels; i++)
+ dest->values[i] = pa_sw_volume_divide(a->values[i], b);
+
+ dest->channels = (uint8_t) i;
+
+ return dest;
+}
+
int pa_cvolume_valid(const pa_cvolume *v) {
unsigned c;
diff --git a/src/pulse/volume.h b/src/pulse/volume.h
index c07fd99..05b7ebb 100644
--- a/src/pulse/volume.h
+++ b/src/pulse/volume.h
@@ -216,16 +216,26 @@ pa_volume_t pa_sw_volume_multiply(pa_volume_t a, pa_volume_t b) PA_GCC_CONST;
* *dest. This is only valid for software volumes! */
pa_cvolume *pa_sw_cvolume_multiply(pa_cvolume *dest, const pa_cvolume *a, const pa_cvolume *b);
+/** Multiply a per-channel volume with a scalar volume and return the
+ * result in *dest. This is only valid for software volumes! \since
+ * 0.9.16 */
+pa_cvolume *pa_sw_cvolume_multiply_scalar(pa_cvolume *dest, const pa_cvolume *a, pa_volume_t b);
+
/** Divide two volume specifications, return the result. This uses
* PA_VOLUME_NORM as neutral element of division. This is only valid
* for software volumes! If a division by zero is tried the result
* will be 0. \since 0.9.13 */
pa_volume_t pa_sw_volume_divide(pa_volume_t a, pa_volume_t b) PA_GCC_CONST;
-/** Multiply to per-channel volumes and return the result in
+/** Divide two per-channel volumes and return the result in
* *dest. This is only valid for software volumes! \since 0.9.13 */
pa_cvolume *pa_sw_cvolume_divide(pa_cvolume *dest, const pa_cvolume *a, const pa_cvolume *b);
+/** Divide a per-channel volume by a scalar volume and return the
+ * result in *dest. This is only valid for software volumes! \since
+ * 0.9.16 */
+pa_cvolume *pa_sw_cvolume_divide_scalar(pa_cvolume *dest, const pa_cvolume *a, pa_volume_t b);
+
/** Convert a decibel value to a volume (amplitude, not power). This is only valid for software volumes! */
pa_volume_t pa_sw_volume_from_dB(double f) PA_GCC_CONST;
diff --git a/src/pulsecore/card.c b/src/pulsecore/card.c
index 9c16ef2..2f0a3af 100644
--- a/src/pulsecore/card.c
+++ b/src/pulsecore/card.c
@@ -148,15 +148,12 @@ pa_card *pa_card_new(pa_core *core, pa_card_new_data *data) {
c->save_profile = data->save_profile;
if (!c->active_profile && c->profiles) {
- void *state = NULL;
+ void *state;
pa_card_profile *p;
- while ((p = pa_hashmap_iterate(c->profiles, &state, NULL))) {
- if (!c->active_profile ||
- p->priority > c->active_profile->priority)
-
+ PA_HASHMAP_FOREACH(p, c->profiles, state)
+ if (!c->active_profile || p->priority > c->active_profile->priority)
c->active_profile = p;
- }
}
c->userdata = NULL;
@@ -177,7 +174,6 @@ pa_card *pa_card_new(pa_core *core, pa_card_new_data *data) {
void pa_card_free(pa_card *c) {
pa_core *core;
- pa_card_profile *profile;
pa_assert(c);
pa_assert(c->core);
@@ -200,8 +196,10 @@ void pa_card_free(pa_card *c) {
pa_idxset_free(c->sources, NULL, NULL);
if (c->profiles) {
- while ((profile = pa_hashmap_steal_first(c->profiles)))
- pa_card_profile_free(profile);
+ pa_card_profile *p;
+
+ while ((p = pa_hashmap_steal_first(c->profiles)))
+ pa_card_profile_free(p);
pa_hashmap_free(c->profiles, NULL, NULL);
}
@@ -214,26 +212,27 @@ void pa_card_free(pa_card *c) {
int pa_card_set_profile(pa_card *c, const char *name, pa_bool_t save) {
pa_card_profile *profile;
+ int r;
pa_assert(c);
if (!c->set_profile) {
- pa_log_warn("set_profile() operation not implemented for card %u \"%s\"", c->index, c->name);
- return -1;
+ pa_log_debug("set_profile() operation not implemented for card %u \"%s\"", c->index, c->name);
+ return -PA_ERR_NOTIMPLEMENTED;
}
if (!c->profiles)
- return -1;
+ return -PA_ERR_NOENTITY;
if (!(profile = pa_hashmap_get(c->profiles, name)))
- return -1;
+ return -PA_ERR_NOENTITY;
if (c->active_profile == profile) {
c->save_profile = c->save_profile || save;
return 0;
}
- if (c->set_profile(c, profile) < 0)
- return -1;
+ if ((r = c->set_profile(c, profile)) < 0)
+ return r;
pa_subscription_post(c->core, PA_SUBSCRIPTION_EVENT_CARD|PA_SUBSCRIPTION_EVENT_CHANGE, c->index);
@@ -254,11 +253,19 @@ int pa_card_suspend(pa_card *c, pa_bool_t suspend, pa_suspend_cause_t cause) {
pa_assert(c);
pa_assert(cause != 0);
- for (sink = pa_idxset_first(c->sinks, &idx); sink; sink = pa_idxset_next(c->sinks, &idx))
- ret -= pa_sink_suspend(sink, suspend, cause) < 0;
+ for (sink = pa_idxset_first(c->sinks, &idx); sink; sink = pa_idxset_next(c->sinks, &idx)) {
+ int r;
- for (source = pa_idxset_first(c->sources, &idx); source; source = pa_idxset_next(c->sources, &idx))
- ret -= pa_source_suspend(source, suspend, cause) < 0;
+ if ((r = pa_sink_suspend(sink, suspend, cause)) < 0)
+ ret = r;
+ }
+
+ for (source = pa_idxset_first(c->sources, &idx); source; source = pa_idxset_next(c->sources, &idx)) {
+ int r;
+
+ if ((r = pa_source_suspend(source, suspend, cause)) < 0)
+ ret = r;
+ }
return ret;
}
diff --git a/src/pulsecore/cli-command.c b/src/pulsecore/cli-command.c
index 644de96..e2c3c06 100644
--- a/src/pulsecore/cli-command.c
+++ b/src/pulsecore/cli-command.c
@@ -125,6 +125,8 @@ static int pa_cli_command_update_source_proplist(pa_core *c, pa_tokenizer *t, pa
static int pa_cli_command_update_sink_input_proplist(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail);
static int pa_cli_command_update_source_output_proplist(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail);
static int pa_cli_command_card_profile(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail);
+static int pa_cli_command_sink_port(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail);
+static int pa_cli_command_source_port(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail);
/* A method table for all available commands */
@@ -176,10 +178,12 @@ static const struct command commands[] = {
{ "suspend-source", pa_cli_command_suspend_source, "Suspend source (args: index|name, bool)", 3},
{ "suspend", pa_cli_command_suspend, "Suspend all sinks and all sources (args: bool)", 2},
{ "set-card-profile", pa_cli_command_card_profile, "Change the profile of a card (args: index, name)", 3},
+ { "set-sink-port", pa_cli_command_sink_port, "Change the port of a sink (args: index, name)", 3},
+ { "set-source-port", pa_cli_command_source_port, "Change the port of a source (args: index, name)", 3},
{ "set-log-level", pa_cli_command_log_level, "Change the log level (args: numeric level)", 2},
{ "set-log-meta", pa_cli_command_log_meta, "Show source code location in log messages (args: bool)", 2},
{ "set-log-time", pa_cli_command_log_time, "Show timestamps in log messages (args: bool)", 2},
- { "set-log-backtrace", pa_cli_command_log_backtrace, "Show bakctrace in log messages (args: frames)", 2},
+ { "set-log-backtrace", pa_cli_command_log_backtrace, "Show backtrace in log messages (args: frames)", 2},
{ NULL, NULL, NULL, 0 }
};
@@ -526,7 +530,7 @@ static int pa_cli_command_sink_volume(pa_core *c, pa_tokenizer *t, pa_strbuf *bu
}
pa_cvolume_set(&cvolume, sink->sample_spec.channels, volume);
- pa_sink_set_volume(sink, &cvolume, TRUE, TRUE, TRUE);
+ pa_sink_set_volume(sink, &cvolume, TRUE, TRUE, TRUE, TRUE);
return 0;
}
@@ -604,7 +608,7 @@ static int pa_cli_command_source_volume(pa_core *c, pa_tokenizer *t, pa_strbuf *
}
pa_cvolume_set(&cvolume, source->sample_spec.channels, volume);
- pa_source_set_volume(source, &cvolume);
+ pa_source_set_volume(source, &cvolume, TRUE);
return 0;
}
@@ -638,7 +642,7 @@ static int pa_cli_command_sink_mute(pa_core *c, pa_tokenizer *t, pa_strbuf *buf,
return -1;
}
- pa_sink_set_mute(sink, mute);
+ pa_sink_set_mute(sink, mute, TRUE);
return 0;
}
@@ -672,7 +676,7 @@ static int pa_cli_command_source_mute(pa_core *c, pa_tokenizer *t, pa_strbuf *bu
return -1;
}
- pa_source_set_mute(source, mute);
+ pa_source_set_mute(source, mute, TRUE);
return 0;
}
@@ -1476,6 +1480,70 @@ static int pa_cli_command_card_profile(pa_core *c, pa_tokenizer *t, pa_strbuf *b
return 0;
}
+static int pa_cli_command_sink_port(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail) {
+ const char *n, *p;
+ pa_sink *sink;
+
+ pa_core_assert_ref(c);
+ pa_assert(t);
+ pa_assert(buf);
+ pa_assert(fail);
+
+ if (!(n = pa_tokenizer_get(t, 1))) {
+ pa_strbuf_puts(buf, "You need to specify a sink either by its name or its index.\n");
+ return -1;
+ }
+
+ if (!(p = pa_tokenizer_get(t, 2))) {
+ pa_strbuf_puts(buf, "You need to specify a profile by its name.\n");
+ return -1;
+ }
+
+ if (!(sink = pa_namereg_get(c, n, PA_NAMEREG_SINK))) {
+ pa_strbuf_puts(buf, "No sink found by this name or index.\n");
+ return -1;
+ }
+
+ if (pa_sink_set_port(sink, p, TRUE) < 0) {
+ pa_strbuf_printf(buf, "Failed to set sink port to '%s'.\n", p);
+ return -1;
+ }
+
+ return 0;
+}
+
+static int pa_cli_command_source_port(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail) {
+ const char *n, *p;
+ pa_source *source;
+
+ pa_core_assert_ref(c);
+ pa_assert(t);
+ pa_assert(buf);
+ pa_assert(fail);
+
+ if (!(n = pa_tokenizer_get(t, 1))) {
+ pa_strbuf_puts(buf, "You need to specify a source either by its name or its index.\n");
+ return -1;
+ }
+
+ if (!(p = pa_tokenizer_get(t, 2))) {
+ pa_strbuf_puts(buf, "You need to specify a profile by its name.\n");
+ return -1;
+ }
+
+ if (!(source = pa_namereg_get(c, n, PA_NAMEREG_SOURCE))) {
+ pa_strbuf_puts(buf, "No source found by this name or index.\n");
+ return -1;
+ }
+
+ if (pa_source_set_port(source, p, TRUE) < 0) {
+ pa_strbuf_printf(buf, "Failed to set source port to '%s'.\n", p);
+ return -1;
+ }
+
+ return 0;
+}
+
static int pa_cli_command_dump(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail) {
pa_module *m;
pa_sink *sink;
diff --git a/src/pulsecore/cli-text.c b/src/pulsecore/cli-text.c
index bc863f0..9395513 100644
--- a/src/pulsecore/cli-text.c
+++ b/src/pulsecore/cli-text.c
@@ -139,11 +139,10 @@ char *pa_card_list_to_string(pa_core *c) {
if (card->profiles) {
pa_card_profile *p;
- void *state = NULL;
+ void *state;
pa_strbuf_puts(s, "\tprofiles:\n");
-
- while ((p = pa_hashmap_iterate(card->profiles, &state, NULL)))
+ PA_HASHMAP_FOREACH(p, card->profiles, state)
pa_strbuf_printf(s, "\t\t%s: %s (priority %u)\n", p->name, p->description, p->priority);
}
@@ -307,6 +306,22 @@ char *pa_sink_list_to_string(pa_core *c) {
t = pa_proplist_to_string_sep(sink->proplist, "\n\t\t");
pa_strbuf_printf(s, "\tproperties:\n\t\t%s\n", t);
pa_xfree(t);
+
+ if (sink->ports) {
+ pa_device_port *p;
+ void *state;
+
+ pa_strbuf_puts(s, "\tports:\n");
+ PA_HASHMAP_FOREACH(p, sink->ports, state)
+ pa_strbuf_printf(s, "\t\t%s: %s (priority %u)\n", p->name, p->description, p->priority);
+ }
+
+
+ if (sink->active_port)
+ pa_strbuf_printf(
+ s,
+ "\tactive port: <%s>\n",
+ sink->active_port->name);
}
return pa_strbuf_tostring_free(s);
@@ -412,6 +427,21 @@ char *pa_source_list_to_string(pa_core *c) {
t = pa_proplist_to_string_sep(source->proplist, "\n\t\t");
pa_strbuf_printf(s, "\tproperties:\n\t\t%s\n", t);
pa_xfree(t);
+
+ if (source->ports) {
+ pa_device_port *p;
+ void *state;
+
+ pa_strbuf_puts(s, "\tports:\n");
+ PA_HASHMAP_FOREACH(p, source->ports, state)
+ pa_strbuf_printf(s, "\t\t%s: %s (priority %u)\n", p->name, p->description, p->priority);
+ }
+
+ if (source->active_port)
+ pa_strbuf_printf(
+ s,
+ "\tactive port: <%s>\n",
+ source->active_port->name);
}
return pa_strbuf_tostring_free(s);
diff --git a/src/pulsecore/conf-parser.c b/src/pulsecore/conf-parser.c
index a427c6c..2dc9a22 100644
--- a/src/pulsecore/conf-parser.c
+++ b/src/pulsecore/conf-parser.c
@@ -170,6 +170,7 @@ int pa_config_parse(const char *filename, FILE *f, const pa_config_item *t, void
if (!f && !(f = fopen(filename, "r"))) {
if (errno == ENOENT) {
+ pa_log_debug("Failed to open configuration file '%s': %s", filename, pa_cstrerror(errno));
r = 0;
goto finish;
}
diff --git a/src/pulsecore/hashmap.c b/src/pulsecore/hashmap.c
index e957c5b..1fac97e 100644
--- a/src/pulsecore/hashmap.c
+++ b/src/pulsecore/hashmap.c
@@ -237,6 +237,39 @@ at_end:
return NULL;
}
+void *pa_hashmap_iterate_backwards(pa_hashmap *h, void **state, const void **key) {
+ struct hashmap_entry *e;
+
+ pa_assert(h);
+ pa_assert(state);
+
+ if (*state == (void*) -1)
+ goto at_beginning;
+
+ if (!*state && !h->iterate_list_tail)
+ goto at_beginning;
+
+ e = *state ? *state : h->iterate_list_tail;
+
+ if (e->iterate_previous)
+ *state = e->iterate_previous;
+ else
+ *state = (void*) -1;
+
+ if (key)
+ *key = e->key;
+
+ return e->value;
+
+at_beginning:
+ *state = (void *) -1;
+
+ if (key)
+ *key = NULL;
+
+ return NULL;
+}
+
void* pa_hashmap_first(pa_hashmap *h) {
pa_assert(h);
@@ -246,6 +279,15 @@ void* pa_hashmap_first(pa_hashmap *h) {
return h->iterate_list_head->value;
}
+void* pa_hashmap_last(pa_hashmap *h) {
+ pa_assert(h);
+
+ if (!h->iterate_list_tail)
+ return NULL;
+
+ return h->iterate_list_tail->value;
+}
+
void* pa_hashmap_steal_first(pa_hashmap *h) {
void *data;
diff --git a/src/pulsecore/hashmap.h b/src/pulsecore/hashmap.h
index 828e244..ac2092a 100644
--- a/src/pulsecore/hashmap.h
+++ b/src/pulsecore/hashmap.h
@@ -26,7 +26,8 @@
/* Simple Implementation of a hash table. Memory management is the
* user's job. It's a good idea to have the key pointer point to a
- * string in the value data. */
+ * string in the value data. The insertion order is preserved when
+ * iterating. */
typedef struct pa_hashmap pa_hashmap;
@@ -59,14 +60,24 @@ pa_bool_t pa_hashmap_isempty(pa_hashmap *h);
returned. */
void *pa_hashmap_iterate(pa_hashmap *h, void **state, const void**key);
+/* Same as pa_hashmap_iterate() but goes backwards */
+void *pa_hashmap_iterate_backwards(pa_hashmap *h, void **state, const void**key);
+
/* Remove the oldest entry in the hashmap and return it */
void *pa_hashmap_steal_first(pa_hashmap *h);
/* Return the oldest entry in the hashmap */
void* pa_hashmap_first(pa_hashmap *h);
+/* Return the newest entry in the hashmap */
+void* pa_hashmap_last(pa_hashmap *h);
+
/* A macro to ease iteration through all entries */
#define PA_HASHMAP_FOREACH(e, h, state) \
for ((state) = NULL, (e) = pa_hashmap_iterate((h), &(state), NULL); (e); (e) = pa_hashmap_iterate((h), &(state), NULL))
+/* A macro to ease iteration through all entries, backwards */
+#define PA_HASHMAP_FOREACH_BACKWARDS(e, h, state) \
+ for ((state) = NULL, (e) = pa_hashmap_iterate_backwards((h), &(state), NULL); (e); (e) = pa_hashmap_iterate_backwards((h), &(state), NULL))
+
#endif
diff --git a/src/pulsecore/protocol-native.c b/src/pulsecore/protocol-native.c
index e9e2d60..b27346b 100644
--- a/src/pulsecore/protocol-native.c
+++ b/src/pulsecore/protocol-native.c
@@ -3328,9 +3328,9 @@ static void command_set_volume(
CHECK_VALIDITY(c->pstream, si || sink || source, tag, PA_ERR_NOENTITY);
if (sink)
- pa_sink_set_volume(sink, &volume, TRUE, TRUE, TRUE);
+ pa_sink_set_volume(sink, &volume, TRUE, TRUE, TRUE, TRUE);
else if (source)
- pa_source_set_volume(source, &volume);
+ pa_source_set_volume(source, &volume, TRUE);
else if (si)
pa_sink_input_set_volume(si, &volume, TRUE, TRUE);
@@ -3400,9 +3400,9 @@ static void command_set_mute(
CHECK_VALIDITY(c->pstream, si || sink || source, tag, PA_ERR_NOENTITY);
if (sink)
- pa_sink_set_mute(sink, mute);
+ pa_sink_set_mute(sink, mute, TRUE);
else if (source)
- pa_source_set_mute(source, mute);
+ pa_source_set_mute(source, mute, TRUE);
else if (si)
pa_sink_input_set_mute(si, mute, TRUE);
diff --git a/src/pulsecore/sink-input.c b/src/pulsecore/sink-input.c
index 0d05b00..a5f9635 100644
--- a/src/pulsecore/sink-input.c
+++ b/src/pulsecore/sink-input.c
@@ -442,7 +442,7 @@ void pa_sink_input_unlink(pa_sink_input *i) {
if (i->sink->flags & PA_SINK_FLAT_VOLUME) {
pa_cvolume new_volume;
pa_sink_update_flat_volume(i->sink, &new_volume);
- pa_sink_set_volume(i->sink, &new_volume, FALSE, FALSE, FALSE);
+ pa_sink_set_volume(i->sink, &new_volume, FALSE, FALSE, FALSE, FALSE);
}
if (i->sink->asyncmsgq)
@@ -520,7 +520,7 @@ void pa_sink_input_put(pa_sink_input *i) {
if (i->sink->flags & PA_SINK_FLAT_VOLUME) {
pa_cvolume new_volume;
pa_sink_update_flat_volume(i->sink, &new_volume);
- pa_sink_set_volume(i->sink, &new_volume, FALSE, FALSE, FALSE);
+ pa_sink_set_volume(i->sink, &new_volume, FALSE, FALSE, FALSE, FALSE);
} else
pa_sink_input_set_relative_volume(i, &i->virtual_volume);
@@ -900,7 +900,7 @@ void pa_sink_input_set_volume(pa_sink_input *i, const pa_cvolume *volume, pa_boo
* volumes and update the flat volume of the sink */
pa_sink_update_flat_volume(i->sink, &new_volume);
- pa_sink_set_volume(i->sink, &new_volume, FALSE, TRUE, FALSE);
+ pa_sink_set_volume(i->sink, &new_volume, FALSE, TRUE, FALSE, FALSE);
} else {
@@ -1159,7 +1159,7 @@ int pa_sink_input_start_move(pa_sink_input *i) {
/* We might need to update the sink's volume if we are in flat
* volume mode. */
pa_sink_update_flat_volume(i->sink, &new_volume);
- pa_sink_set_volume(i->sink, &new_volume, FALSE, FALSE, FALSE);
+ pa_sink_set_volume(i->sink, &new_volume, FALSE, FALSE, FALSE, FALSE);
}
pa_assert_se(pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i->sink), PA_SINK_MESSAGE_START_MOVE, i, 0, NULL) == 0);
@@ -1252,7 +1252,7 @@ int pa_sink_input_finish_move(pa_sink_input *i, pa_sink *dest, pa_bool_t save) {
/* We might need to update the sink's volume if we are in flat volume mode. */
pa_sink_update_flat_volume(i->sink, &new_volume);
- pa_sink_set_volume(i->sink, &new_volume, FALSE, FALSE, FALSE);
+ pa_sink_set_volume(i->sink, &new_volume, FALSE, FALSE, FALSE, FALSE);
}
pa_assert_se(pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i->sink), PA_SINK_MESSAGE_FINISH_MOVE, i, 0, NULL) == 0);
diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c
index 1da094a..4779229 100644
--- a/src/pulsecore/sink.c
+++ b/src/pulsecore/sink.c
@@ -100,11 +100,51 @@ void pa_sink_new_data_set_muted(pa_sink_new_data *data, pa_bool_t mute) {
data->muted = !!mute;
}
+void pa_sink_new_data_set_port(pa_sink_new_data *data, const char *port) {
+ pa_assert(data);
+
+ pa_xfree(data->active_port);
+ data->active_port = pa_xstrdup(port);
+}
+
void pa_sink_new_data_done(pa_sink_new_data *data) {
pa_assert(data);
- pa_xfree(data->name);
pa_proplist_free(data->proplist);
+
+ if (data->ports) {
+ pa_device_port *p;
+
+ while ((p = pa_hashmap_steal_first(data->ports)))
+ pa_device_port_free(p);
+
+ pa_hashmap_free(data->ports, NULL, NULL);
+ }
+
+ pa_xfree(data->name);
+ pa_xfree(data->active_port);
+}
+
+pa_device_port *pa_device_port_new(const char *name, const char *description, size_t extra) {
+ pa_device_port *p;
+
+ pa_assert(name);
+
+ p = pa_xmalloc(PA_ALIGN(sizeof(pa_device_port)) + extra);
+ p->name = pa_xstrdup(name);
+ p->description = pa_xstrdup(description);
+
+ p->priority = 0;
+
+ return p;
+}
+
+void pa_device_port_free(pa_device_port *p) {
+ pa_assert(p);
+
+ pa_xfree(p->name);
+ pa_xfree(p->description);
+ pa_xfree(p);
}
/* Called from main context */
@@ -118,6 +158,7 @@ static void reset_callbacks(pa_sink *s) {
s->set_mute = NULL;
s->request_rewind = NULL;
s->update_requested_latency = NULL;
+ s->set_port = NULL;
}
/* Called from main context */
@@ -152,6 +193,8 @@ pa_sink* pa_sink_new(
return NULL;
}
+ /* FIXME, need to free s here on failure */
+
pa_return_null_if_fail(!data->driver || pa_utf8_valid(data->driver));
pa_return_null_if_fail(data->name && pa_utf8_valid(data->name) && data->name[0]);
@@ -219,6 +262,30 @@ pa_sink* pa_sink_new(
s->asyncmsgq = NULL;
s->rtpoll = NULL;
+ /* As a minor optimization we just steal the list instead of
+ * copying it here */
+ s->ports = data->ports;
+ data->ports = NULL;
+
+ s->active_port = NULL;
+ s->save_port = FALSE;
+
+ if (data->active_port && s->ports)
+ if ((s->active_port = pa_hashmap_get(s->ports, data->active_port)))
+ s->save_port = data->save_port;
+
+ if (!s->active_port && s->ports) {
+ void *state;
+ pa_device_port *p;
+
+ PA_HASHMAP_FOREACH(p, s->ports, state)
+ if (!s->active_port || p->priority > s->active_port->priority)
+ s->active_port = p;
+ }
+
+ s->save_volume = data->save_volume;
+ s->save_muted = data->save_muted;
+
pa_silence_memchunk_get(
&core->silence_cache,
core->mempool,
@@ -467,6 +534,15 @@ static void sink_free(pa_object *o) {
if (s->proplist)
pa_proplist_free(s->proplist);
+ if (s->ports) {
+ pa_device_port *p;
+
+ while ((p = pa_hashmap_steal_first(s->ports)))
+ pa_device_port_free(p);
+
+ pa_hashmap_free(s->ports, NULL, NULL);
+ }
+
pa_xfree(s);
}
@@ -485,6 +561,7 @@ void pa_sink_set_rtpoll(pa_sink *s, pa_rtpoll *p) {
pa_sink_assert_ref(s);
s->rtpoll = p;
+
if (s->monitor_source)
pa_source_set_rtpoll(s->monitor_source, p);
}
@@ -526,15 +603,15 @@ int pa_sink_suspend(pa_sink *s, pa_bool_t suspend, pa_suspend_cause_t cause) {
}
/* Called from main context */
-pa_queue *pa_sink_move_all_start(pa_sink *s) {
- pa_queue *q;
+pa_queue *pa_sink_move_all_start(pa_sink *s, pa_queue *q) {
pa_sink_input *i, *n;
uint32_t idx;
pa_sink_assert_ref(s);
pa_assert(PA_SINK_IS_LINKED(s->state));
- q = pa_queue_new();
+ if (!q)
+ q = pa_queue_new();
for (i = PA_SINK_INPUT(pa_idxset_first(s->inputs, &idx)); i; i = n) {
n = PA_SINK_INPUT(pa_idxset_next(s->inputs, &idx));
@@ -1237,7 +1314,7 @@ void pa_sink_propagate_flat_volume(pa_sink *s) {
}
/* Called from main thread */
-void pa_sink_set_volume(pa_sink *s, const pa_cvolume *volume, pa_bool_t propagate, pa_bool_t sendmsg, pa_bool_t become_reference) {
+void pa_sink_set_volume(pa_sink *s, const pa_cvolume *volume, pa_bool_t propagate, pa_bool_t sendmsg, pa_bool_t become_reference, pa_bool_t save) {
pa_bool_t virtual_volume_changed;
pa_sink_assert_ref(s);
@@ -1248,6 +1325,7 @@ void pa_sink_set_volume(pa_sink *s, const pa_cvolume *volume, pa_bool_t propagat
virtual_volume_changed = !pa_cvolume_equal(volume, &s->virtual_volume);
s->virtual_volume = *volume;
+ s->save_volume = (!virtual_volume_changed && s->save_volume) || save;
if (become_reference)
s->reference_volume = s->virtual_volume;
@@ -1318,15 +1396,17 @@ const pa_cvolume *pa_sink_get_volume(pa_sink *s, pa_bool_t force_refresh, pa_boo
}
/* Called from main thread */
-void pa_sink_volume_changed(pa_sink *s, const pa_cvolume *new_volume) {
+void pa_sink_volume_changed(pa_sink *s, const pa_cvolume *new_volume, pa_bool_t save) {
pa_sink_assert_ref(s);
/* The sink implementor may call this if the volume changed to make sure everyone is notified */
-
- if (pa_cvolume_equal(&s->virtual_volume, new_volume))
+ if (pa_cvolume_equal(&s->virtual_volume, new_volume)) {
+ s->save_volume = s->save_volume || save;
return;
+ }
s->reference_volume = s->virtual_volume = *new_volume;
+ s->save_volume = save;
if (s->flags & PA_SINK_FLAT_VOLUME)
pa_sink_propagate_flat_volume(s);
@@ -1335,7 +1415,7 @@ void pa_sink_volume_changed(pa_sink *s, const pa_cvolume *new_volume) {
}
/* Called from main thread */
-void pa_sink_set_mute(pa_sink *s, pa_bool_t mute) {
+void pa_sink_set_mute(pa_sink *s, pa_bool_t mute, pa_bool_t save) {
pa_bool_t old_muted;
pa_sink_assert_ref(s);
@@ -1343,6 +1423,7 @@ void pa_sink_set_mute(pa_sink *s, pa_bool_t mute) {
old_muted = s->muted;
s->muted = mute;
+ s->save_muted = (old_muted == s->muted && s->save_muted) || save;
if (s->set_mute)
s->set_mute(s);
@@ -1378,15 +1459,19 @@ pa_bool_t pa_sink_get_mute(pa_sink *s, pa_bool_t force_refresh) {
}
/* Called from main thread */
-void pa_sink_mute_changed(pa_sink *s, pa_bool_t new_muted) {
+void pa_sink_mute_changed(pa_sink *s, pa_bool_t new_muted, pa_bool_t save) {
pa_sink_assert_ref(s);
/* The sink implementor may call this if the volume changed to make sure everyone is notified */
- if (s->muted == new_muted)
+ if (s->muted == new_muted) {
+ s->save_muted = s->save_muted || save;
return;
+ }
s->muted = new_muted;
+ s->save_muted = save;
+
pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SINK|PA_SUBSCRIPTION_EVENT_CHANGE, s->index);
}
@@ -1484,7 +1569,7 @@ unsigned pa_sink_check_suspend(pa_sink *s) {
ret = 0;
- for (i = PA_SINK_INPUT(pa_idxset_first(s->inputs, &idx)); i; i = PA_SINK_INPUT(pa_idxset_next(s->inputs, &idx))) {
+ PA_IDXSET_FOREACH(i, s->inputs, idx) {
pa_sink_input_state_t st;
st = pa_sink_input_get_state(i);
@@ -2195,6 +2280,41 @@ size_t pa_sink_get_max_request(pa_sink *s) {
}
/* Called from main context */
+int pa_sink_set_port(pa_sink *s, const char *name, pa_bool_t save) {
+ pa_device_port *port;
+
+ pa_assert(s);
+
+ if (!s->set_port) {
+ pa_log_debug("set_port() operation not implemented for sink %u \"%s\"", s->index, s->name);
+ return -PA_ERR_NOTIMPLEMENTED;
+ }
+
+ if (!s->ports)
+ return -PA_ERR_NOENTITY;
+
+ if (!(port = pa_hashmap_get(s->ports, name)))
+ return -PA_ERR_NOENTITY;
+
+ if (s->active_port == port) {
+ s->save_port = s->save_port || save;
+ return 0;
+ }
+
+ if ((s->set_port(s, port)) < 0)
+ return -PA_ERR_NOENTITY;
+
+ pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SINK|PA_SUBSCRIPTION_EVENT_CHANGE, s->index);
+
+ pa_log_info("Changed port of sink %u \"%s\" to %s", s->index, s->name, port->name);
+
+ s->active_port = port;
+ s->save_port = save;
+
+ return 0;
+}
+
+/* Called from main context */
pa_bool_t pa_device_init_icon(pa_proplist *p, pa_bool_t is_sink) {
const char *ff, *c, *t = NULL, *s = "", *profile, *bus;
diff --git a/src/pulsecore/sink.h b/src/pulsecore/sink.h
index 4e1bf52..d16fcc0 100644
--- a/src/pulsecore/sink.h
+++ b/src/pulsecore/sink.h
@@ -59,6 +59,8 @@ struct pa_device_port {
/* .. followed by some implementation specific data */
};
+#define PA_DEVICE_PORT_DATA(d) ((void*) ((uint8_t*) d + PA_ALIGN(sizeof(pa_device_port))))
+
struct pa_sink {
pa_msgobject parent;
@@ -95,6 +97,8 @@ struct pa_sink {
pa_bool_t refresh_volume:1;
pa_bool_t refresh_muted:1;
pa_bool_t save_port:1;
+ pa_bool_t save_volume:1;
+ pa_bool_t save_muted:1;
pa_asyncmsgq *asyncmsgq;
pa_rtpoll *rtpoll;
@@ -227,6 +231,8 @@ typedef struct pa_sink_new_data {
pa_bool_t namereg_fail:1;
pa_bool_t save_port:1;
+ pa_bool_t save_volume:1;
+ pa_bool_t save_muted:1;
} pa_sink_new_data;
pa_sink_new_data* pa_sink_new_data_init(pa_sink_new_data *data);
@@ -261,8 +267,8 @@ void pa_sink_detach(pa_sink *s);
void pa_sink_attach(pa_sink *s);
void pa_sink_set_soft_volume(pa_sink *s, const pa_cvolume *volume);
-void pa_sink_volume_changed(pa_sink *s, const pa_cvolume *new_volume);
-void pa_sink_mute_changed(pa_sink *s, pa_bool_t new_muted);
+void pa_sink_volume_changed(pa_sink *s, const pa_cvolume *new_volume, pa_bool_t save);
+void pa_sink_mute_changed(pa_sink *s, pa_bool_t new_muted, pa_bool_t save);
pa_bool_t pa_device_init_description(pa_proplist *p);
pa_bool_t pa_device_init_icon(pa_proplist *p, pa_bool_t is_sink);
@@ -285,10 +291,10 @@ int pa_sink_suspend_all(pa_core *c, pa_bool_t suspend, pa_suspend_cause_t cause)
void pa_sink_update_flat_volume(pa_sink *s, pa_cvolume *new_volume);
void pa_sink_propagate_flat_volume(pa_sink *s);
-void pa_sink_set_volume(pa_sink *sink, const pa_cvolume *volume, pa_bool_t propagate, pa_bool_t sendmsg, pa_bool_t become_reference);
+void pa_sink_set_volume(pa_sink *sink, const pa_cvolume *volume, pa_bool_t propagate, pa_bool_t sendmsg, pa_bool_t become_reference, pa_bool_t save);
const pa_cvolume *pa_sink_get_volume(pa_sink *sink, pa_bool_t force_refresh, pa_bool_t reference);
-void pa_sink_set_mute(pa_sink *sink, pa_bool_t mute);
+void pa_sink_set_mute(pa_sink *sink, pa_bool_t mute, pa_bool_t save);
pa_bool_t pa_sink_get_mute(pa_sink *sink, pa_bool_t force_refresh);
pa_bool_t pa_sink_update_proplist(pa_sink *s, pa_update_mode_t mode, pa_proplist *p);
@@ -301,7 +307,7 @@ unsigned pa_sink_check_suspend(pa_sink *s); /* Returns how many streams are acti
#define pa_sink_get_state(s) ((s)->state)
/* Moves all inputs away, and stores them in pa_queue */
-pa_queue *pa_sink_move_all_start(pa_sink *s);
+pa_queue *pa_sink_move_all_start(pa_sink *s, pa_queue *q);
void pa_sink_move_all_finish(pa_sink *s, pa_queue *q, pa_bool_t save);
void pa_sink_move_all_fail(pa_queue *q);
diff --git a/src/pulsecore/source.c b/src/pulsecore/source.c
index d35c852..1e43116 100644
--- a/src/pulsecore/source.c
+++ b/src/pulsecore/source.c
@@ -93,11 +93,29 @@ void pa_source_new_data_set_muted(pa_source_new_data *data, pa_bool_t mute) {
data->muted = !!mute;
}
+void pa_source_new_data_set_port(pa_source_new_data *data, const char *port) {
+ pa_assert(data);
+
+ pa_xfree(data->active_port);
+ data->active_port = pa_xstrdup(port);
+}
+
void pa_source_new_data_done(pa_source_new_data *data) {
pa_assert(data);
- pa_xfree(data->name);
pa_proplist_free(data->proplist);
+
+ if (data->ports) {
+ pa_device_port *p;
+
+ while ((p = pa_hashmap_steal_first(data->ports)))
+ pa_device_port_free(p);
+
+ pa_hashmap_free(data->ports, NULL, NULL);
+ }
+
+ pa_xfree(data->name);
+ pa_xfree(data->active_port);
}
/* Called from main context */
@@ -110,6 +128,7 @@ static void reset_callbacks(pa_source *s) {
s->get_mute = NULL;
s->set_mute = NULL;
s->update_requested_latency = NULL;
+ s->set_port = NULL;
}
/* Called from main context */
@@ -142,6 +161,8 @@ pa_source* pa_source_new(
return NULL;
}
+ /* FIXME, need to free s here on failure */
+
pa_return_null_if_fail(!data->driver || pa_utf8_valid(data->driver));
pa_return_null_if_fail(data->name && pa_utf8_valid(data->name) && data->name[0]);
@@ -210,6 +231,30 @@ pa_source* pa_source_new(
s->asyncmsgq = NULL;
s->rtpoll = NULL;
+ /* As a minor optimization we just steal the list instead of
+ * copying it here */
+ s->ports = data->ports;
+ data->ports = NULL;
+
+ s->active_port = NULL;
+ s->save_port = FALSE;
+
+ if (data->active_port && s->ports)
+ if ((s->active_port = pa_hashmap_get(s->ports, data->active_port)))
+ s->save_port = data->save_port;
+
+ if (!s->active_port && s->ports) {
+ void *state;
+ pa_device_port *p;
+
+ PA_HASHMAP_FOREACH(p, s->ports, state)
+ if (!s->active_port || p->priority > s->active_port->priority)
+ s->active_port = p;
+ }
+
+ s->save_volume = data->save_volume;
+ s->save_muted = data->save_muted;
+
pa_silence_memchunk_get(
&core->silence_cache,
core->mempool,
@@ -400,6 +445,15 @@ static void source_free(pa_object *o) {
if (s->proplist)
pa_proplist_free(s->proplist);
+ if (s->ports) {
+ pa_device_port *p;
+
+ while ((p = pa_hashmap_steal_first(s->ports)))
+ pa_device_port_free(p);
+
+ pa_hashmap_free(s->ports, NULL, NULL);
+ }
+
pa_xfree(s);
}
@@ -472,15 +526,15 @@ int pa_source_sync_suspend(pa_source *s) {
}
/* Called from main context */
-pa_queue *pa_source_move_all_start(pa_source *s) {
- pa_queue *q;
+pa_queue *pa_source_move_all_start(pa_source *s, pa_queue *q) {
pa_source_output *o, *n;
uint32_t idx;
pa_source_assert_ref(s);
pa_assert(PA_SOURCE_IS_LINKED(s->state));
- q = pa_queue_new();
+ if (!q)
+ q = pa_queue_new();
for (o = PA_SOURCE_OUTPUT(pa_idxset_first(s->outputs, &idx)); o; o = n) {
n = PA_SOURCE_OUTPUT(pa_idxset_next(s->outputs, &idx));
@@ -667,7 +721,7 @@ pa_usec_t pa_source_get_latency_within_thread(pa_source *s) {
}
/* Called from main thread */
-void pa_source_set_volume(pa_source *s, const pa_cvolume *volume) {
+void pa_source_set_volume(pa_source *s, const pa_cvolume *volume, pa_bool_t save) {
pa_cvolume old_virtual_volume;
pa_bool_t virtual_volume_changed;
@@ -680,6 +734,7 @@ void pa_source_set_volume(pa_source *s, const pa_cvolume *volume) {
old_virtual_volume = s->virtual_volume;
s->virtual_volume = *volume;
virtual_volume_changed = !pa_cvolume_equal(&old_virtual_volume, &s->virtual_volume);
+ s->save_volume = (!virtual_volume_changed && s->save_volume) || save;
if (s->set_volume) {
pa_cvolume_reset(&s->soft_volume, s->sample_spec.channels);
@@ -725,20 +780,24 @@ const pa_cvolume *pa_source_get_volume(pa_source *s, pa_bool_t force_refresh) {
}
/* Called from main thread */
-void pa_source_volume_changed(pa_source *s, const pa_cvolume *new_volume) {
+void pa_source_volume_changed(pa_source *s, const pa_cvolume *new_volume, pa_bool_t save) {
pa_source_assert_ref(s);
/* The source implementor may call this if the volume changed to make sure everyone is notified */
- if (pa_cvolume_equal(&s->virtual_volume, new_volume))
+ if (pa_cvolume_equal(&s->virtual_volume, new_volume)) {
+ s->save_volume = s->save_volume || save;
return;
+ }
s->virtual_volume = *new_volume;
+ s->save_volume = save;
+
pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SOURCE|PA_SUBSCRIPTION_EVENT_CHANGE, s->index);
}
/* Called from main thread */
-void pa_source_set_mute(pa_source *s, pa_bool_t mute) {
+void pa_source_set_mute(pa_source *s, pa_bool_t mute, pa_bool_t save) {
pa_bool_t old_muted;
pa_source_assert_ref(s);
@@ -746,6 +805,7 @@ void pa_source_set_mute(pa_source *s, pa_bool_t mute) {
old_muted = s->muted;
s->muted = mute;
+ s->save_muted = (old_muted == s->muted && s->save_muted) || save;
if (s->set_mute)
s->set_mute(s);
@@ -781,15 +841,19 @@ pa_bool_t pa_source_get_mute(pa_source *s, pa_bool_t force_refresh) {
}
/* Called from main thread */
-void pa_source_mute_changed(pa_source *s, pa_bool_t new_muted) {
+void pa_source_mute_changed(pa_source *s, pa_bool_t new_muted, pa_bool_t save) {
pa_source_assert_ref(s);
/* The source implementor may call this if the mute state changed to make sure everyone is notified */
- if (s->muted == new_muted)
+ if (s->muted == new_muted) {
+ s->save_muted = s->save_muted || save;
return;
+ }
s->muted = new_muted;
+ s->save_muted = save;
+
pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SOURCE|PA_SUBSCRIPTION_EVENT_CHANGE, s->index);
}
@@ -866,7 +930,7 @@ unsigned pa_source_check_suspend(pa_source *s) {
ret = 0;
- for (o = PA_SOURCE_OUTPUT(pa_idxset_first(s->outputs, &idx)); o; o = PA_SOURCE_OUTPUT(pa_idxset_next(s->outputs, &idx))) {
+ PA_IDXSET_FOREACH(o, s->outputs, idx) {
pa_source_output_state_t st;
st = pa_source_output_get_state(o);
@@ -1323,3 +1387,38 @@ size_t pa_source_get_max_rewind(pa_source *s) {
return r;
}
+
+/* Called from main context */
+int pa_source_set_port(pa_source *s, const char *name, pa_bool_t save) {
+ pa_device_port *port;
+
+ pa_assert(s);
+
+ if (!s->set_port) {
+ pa_log_debug("set_port() operation not implemented for sink %u \"%s\"", s->index, s->name);
+ return -PA_ERR_NOTIMPLEMENTED;
+ }
+
+ if (!s->ports)
+ return -PA_ERR_NOENTITY;
+
+ if (!(port = pa_hashmap_get(s->ports, name)))
+ return -PA_ERR_NOENTITY;
+
+ if (s->active_port == port) {
+ s->save_port = s->save_port || save;
+ return 0;
+ }
+
+ if ((s->set_port(s, port)) < 0)
+ return -PA_ERR_NOENTITY;
+
+ pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SOURCE|PA_SUBSCRIPTION_EVENT_CHANGE, s->index);
+
+ pa_log_info("Changed port of source %u \"%s\" to %s", s->index, s->name, port->name);
+
+ s->active_port = port;
+ s->save_port = save;
+
+ return 0;
+}
diff --git a/src/pulsecore/source.h b/src/pulsecore/source.h
index 1fbed70..7e9fd8b 100644
--- a/src/pulsecore/source.h
+++ b/src/pulsecore/source.h
@@ -56,6 +56,7 @@ struct pa_source {
uint32_t index;
pa_core *core;
+
pa_source_state_t state;
pa_source_flags_t flags;
pa_suspend_cause_t suspend_cause;
@@ -83,6 +84,10 @@ struct pa_source {
pa_bool_t refresh_volume:1;
pa_bool_t refresh_muted:1;
+ pa_bool_t save_port:1;
+ pa_bool_t save_volume:1;
+ pa_bool_t save_muted:1;
+
pa_asyncmsgq *asyncmsgq;
pa_rtpoll *rtpoll;
@@ -90,6 +95,9 @@ struct pa_source {
pa_usec_t fixed_latency; /* for sources with PA_SOURCE_DYNAMIC_LATENCY this is 0 */
+ pa_hashmap *ports;
+ pa_device_port *active_port;
+
/* Called when the main loop requests a state change. Called from
* main loop context. If returns -1 the state change will be
* inhibited */
@@ -121,6 +129,10 @@ struct pa_source {
* thread context. */
void (*update_requested_latency)(pa_source *s); /* dito */
+ /* Called whenever the port shall be changed. Called from main
+ * thread. */
+ int (*set_port)(pa_source *s, pa_device_port *port); /*dito */
+
/* Contains copies of the above data so that the real-time worker
* thread can work without access locking */
struct {
@@ -174,6 +186,9 @@ typedef struct pa_source_new_data {
pa_module *module;
pa_card *card;
+ pa_hashmap *ports;
+ char *active_port;
+
pa_sample_spec sample_spec;
pa_channel_map channel_map;
pa_cvolume volume;
@@ -185,6 +200,10 @@ typedef struct pa_source_new_data {
pa_bool_t channel_map_is_set:1;
pa_bool_t namereg_fail:1;
+
+ pa_bool_t save_port:1;
+ pa_bool_t save_volume:1;
+ pa_bool_t save_muted:1;
} pa_source_new_data;
pa_source_new_data* pa_source_new_data_init(pa_source_new_data *data);
@@ -193,6 +212,7 @@ void pa_source_new_data_set_sample_spec(pa_source_new_data *data, const pa_sampl
void pa_source_new_data_set_channel_map(pa_source_new_data *data, const pa_channel_map *map);
void pa_source_new_data_set_volume(pa_source_new_data *data, const pa_cvolume *volume);
void pa_source_new_data_set_muted(pa_source_new_data *data, pa_bool_t mute);
+void pa_source_new_data_set_port(pa_source_new_data *data, const char *port);
void pa_source_new_data_done(pa_source_new_data *data);
/*** To be called exclusively by the source driver, from main context */
@@ -217,8 +237,8 @@ void pa_source_detach(pa_source *s);
void pa_source_attach(pa_source *s);
void pa_source_set_soft_volume(pa_source *s, const pa_cvolume *volume);
-void pa_source_volume_changed(pa_source *s, const pa_cvolume *new_volume);
-void pa_source_mute_changed(pa_source *s, pa_bool_t new_muted);
+void pa_source_volume_changed(pa_source *s, const pa_cvolume *new_volume, pa_bool_t save);
+void pa_source_mute_changed(pa_source *s, pa_bool_t new_muted, pa_bool_t save);
int pa_source_sync_suspend(pa_source *s);
@@ -235,20 +255,22 @@ int pa_source_update_status(pa_source*s);
int pa_source_suspend(pa_source *s, pa_bool_t suspend, pa_suspend_cause_t cause);
int pa_source_suspend_all(pa_core *c, pa_bool_t suspend, pa_suspend_cause_t cause);
-void pa_source_set_volume(pa_source *source, const pa_cvolume *volume);
+void pa_source_set_volume(pa_source *source, const pa_cvolume *volume, pa_bool_t save);
const pa_cvolume *pa_source_get_volume(pa_source *source, pa_bool_t force_refresh);
-void pa_source_set_mute(pa_source *source, pa_bool_t mute);
+void pa_source_set_mute(pa_source *source, pa_bool_t mute, pa_bool_t save);
pa_bool_t pa_source_get_mute(pa_source *source, pa_bool_t force_refresh);
pa_bool_t pa_source_update_proplist(pa_source *s, pa_update_mode_t mode, pa_proplist *p);
+int pa_source_set_port(pa_source *s, const char *name, pa_bool_t save);
+
unsigned pa_source_linked_by(pa_source *s); /* Number of connected streams */
unsigned pa_source_used_by(pa_source *s); /* Number of connected streams that are not corked */
unsigned pa_source_check_suspend(pa_source *s); /* Returns how many streams are active that don't allow suspensions */
#define pa_source_get_state(s) ((pa_source_state_t) (s)->state)
/* Moves all inputs away, and stores them in pa_queue */
-pa_queue *pa_source_move_all_start(pa_source *s);
+pa_queue *pa_source_move_all_start(pa_source *s, pa_queue *q);
void pa_source_move_all_finish(pa_source *s, pa_queue *q, pa_bool_t save);
void pa_source_move_all_fail(pa_queue *q);
commit 92525698dfbcf003b98a327ddd531e8b026756dd
Author: Lennart Poettering <lennart at poettering.net>
Date: Wed Jun 17 02:50:50 2009 +0200
commit it away
diff --git a/src/modules/alsa/alsa-mixer.c b/src/modules/alsa/alsa-mixer.c
index 02e1fcc..5387516 100644
--- a/src/modules/alsa/alsa-mixer.c
+++ b/src/modules/alsa/alsa-mixer.c
@@ -448,10 +448,6 @@ void pa_alsa_path_set_free(pa_alsa_path_set *ps) {
pa_xfree(ps);
}
-int pa_alsa_setting_select(pa_alsa_setting *s, snd_mixer_t *m) {
- return 0;
-}
-
static long to_alsa_dB(pa_volume_t v) {
return (long) (pa_sw_volume_to_dB(v) * 100.0);
}
@@ -507,10 +503,17 @@ static int element_get_volume(pa_alsa_element *e, snd_mixer_t *m, const pa_chann
if (e->has_dB) {
long value = 0;
- if (e->direction == PA_ALSA_DIRECTION_OUTPUT)
- r = snd_mixer_selem_get_playback_dB(me, c, &value);
- else
- r = snd_mixer_selem_get_capture_dB(me, c, &value);
+ if (e->direction == PA_ALSA_DIRECTION_OUTPUT) {
+ if (snd_mixer_selem_has_playback_channel(me, c))
+ r = snd_mixer_selem_get_playback_dB(me, c, &value);
+ else
+ r = -1;
+ } else {
+ if (snd_mixer_selem_has_capture_channel(me, c))
+ r = snd_mixer_selem_get_capture_dB(me, c, &value);
+ else
+ r = -1;
+ }
if (r < 0)
continue;
@@ -525,9 +528,16 @@ static int element_get_volume(pa_alsa_element *e, snd_mixer_t *m, const pa_chann
long value = 0;
if (e->direction == PA_ALSA_DIRECTION_OUTPUT) {
- r = snd_mixer_selem_get_playback_volume(me, c, &value);
- } else
- r = snd_mixer_selem_get_capture_volume(me, c, &value);
+ if (snd_mixer_selem_has_playback_channel(me, c))
+ r = snd_mixer_selem_get_playback_volume(me, c, &value);
+ else
+ r = -1;
+ } else {
+ if (snd_mixer_selem_has_capture_channel(me, c))
+ r = snd_mixer_selem_get_capture_volume(me, c, &value);
+ else
+ r = -1;
+ }
if (r < 0)
continue;
@@ -607,10 +617,17 @@ static int element_get_switch(pa_alsa_element *e, snd_mixer_t *m, pa_bool_t *b)
int r;
int value = 0;
- if (e->direction == PA_ALSA_DIRECTION_OUTPUT)
- r = snd_mixer_selem_get_playback_switch(me, c, &value);
- else
- r = snd_mixer_selem_get_capture_switch(me, c, &value);
+ if (e->direction == PA_ALSA_DIRECTION_OUTPUT) {
+ if (snd_mixer_selem_has_playback_channel(me, c))
+ r = snd_mixer_selem_get_playback_switch(me, c, &value);
+ else
+ r = -1;
+ } else {
+ if (snd_mixer_selem_has_capture_channel(me, c))
+ r = snd_mixer_selem_get_capture_switch(me, c, &value);
+ else
+ r = -1;
+ }
if (r < 0)
continue;
@@ -689,11 +706,20 @@ static int element_set_volume(pa_alsa_element *e, snd_mixer_t *m, const pa_chann
long value = to_alsa_dB(f);
if (e->direction == PA_ALSA_DIRECTION_OUTPUT) {
- if ((r = snd_mixer_selem_set_playback_dB(me, c, value, +1)) >= 0)
- r = snd_mixer_selem_get_playback_dB(me, c, &value);
+ /* If we call set_play_volume() without checking first
+ * if the channel is available, ALSA behaves ver
+ * strangely and doesn't fail the call */
+ if (snd_mixer_selem_has_playback_channel(me, c)) {
+ if ((r = snd_mixer_selem_set_playback_dB(me, c, value, +1)) >= 0)
+ r = snd_mixer_selem_get_playback_dB(me, c, &value);
+ } else
+ r = -1;
} else {
- if ((r = snd_mixer_selem_set_capture_dB(me, c, value, +1)) >= 0)
- r = snd_mixer_selem_get_capture_dB(me, c, &value);
+ if (snd_mixer_selem_has_capture_channel(me, c)) {
+ if ((r = snd_mixer_selem_set_capture_dB(me, c, value, +1)) >= 0)
+ r = snd_mixer_selem_get_capture_dB(me, c, &value);
+ } else
+ r = -1;
}
if (r < 0)
@@ -711,11 +737,17 @@ static int element_set_volume(pa_alsa_element *e, snd_mixer_t *m, const pa_chann
value = to_alsa_volume(f, e->min_volume, e->max_volume);
if (e->direction == PA_ALSA_DIRECTION_OUTPUT) {
- if ((r = snd_mixer_selem_set_playback_volume(me, c, value)) >= 0)
- r = snd_mixer_selem_get_playback_volume(me, c, &value);
+ if (snd_mixer_selem_has_playback_channel(me, c)) {
+ if ((r = snd_mixer_selem_set_playback_volume(me, c, value)) >= 0)
+ r = snd_mixer_selem_get_playback_volume(me, c, &value);
+ } else
+ r = -1;
} else {
- if ((r = snd_mixer_selem_set_capture_volume(me, c, value)) >= 0)
- r = snd_mixer_selem_get_capture_volume(me, c, &value);
+ if (snd_mixer_selem_has_capture_channel(me, c)) {
+ if ((r = snd_mixer_selem_set_capture_volume(me, c, value)) >= 0)
+ r = snd_mixer_selem_get_capture_volume(me, c, &value);
+ } else
+ r = -1;
}
if (r < 0)
@@ -787,7 +819,6 @@ static int element_set_switch(pa_alsa_element *e, snd_mixer_t *m, pa_bool_t b) {
pa_assert(m);
pa_assert(e);
- pa_assert(b);
SELEM_INIT(sid, e->alsa_name);
if (!(me = snd_mixer_find_selem(m, sid))) {
@@ -801,7 +832,7 @@ static int element_set_switch(pa_alsa_element *e, snd_mixer_t *m, pa_bool_t b) {
r = snd_mixer_selem_set_capture_switch_all(me, b);
if (r < 0)
- pa_log_warn("Faile to set switch of %s: %s", e->alsa_name, pa_alsa_strerror(errno));
+ pa_log_warn("Failed to set switch of %s: %s", e->alsa_name, pa_alsa_strerror(errno));
return r;
}
@@ -1146,11 +1177,43 @@ static int element_probe(pa_alsa_element *e, snd_mixer_t *m) {
}
}
}
+
}
if (check_required(e, me) < 0)
return -1;
+ if (e->switch_use == PA_ALSA_SWITCH_SELECT) {
+ pa_alsa_option *o;
+
+ PA_LLIST_FOREACH(o, e->options)
+ o->alsa_idx = pa_streq(o->alsa_name, "on") ? 1 : 0;
+ } else if (e->enumeration_use == PA_ALSA_ENUMERATION_SELECT) {
+ int n;
+ pa_alsa_option *o;
+
+ if ((n = snd_mixer_selem_get_enum_items(me)) < 0) {
+ pa_log("snd_mixer_selem_get_enum_items() failed: %s", pa_alsa_strerror(n));
+ return -1;
+ }
+
+ PA_LLIST_FOREACH(o, e->options) {
+ int i;
+
+ for (i = 0; i < n; i++) {
+ char buf[128];
+
+ if (snd_mixer_selem_get_enum_item_name(me, i, sizeof(buf), buf) < 0)
+ continue;
+
+ if (!pa_streq(buf, o->alsa_name))
+ continue;
+
+ o->alsa_idx = i;
+ }
+ }
+ }
+
return 0;
}
@@ -1171,8 +1234,8 @@ static pa_alsa_element* element_get(pa_alsa_path *p, const char *section, pa_boo
if (strchr(section, ':'))
return NULL;
- if (p->element_parse_cache && pa_streq(p->element_parse_cache->alsa_name, section))
- return p->element_parse_cache;
+ if (p->last_element && pa_streq(p->last_element->alsa_name, section))
+ return p->last_element;
PA_LLIST_FOREACH(e, p->elements)
if (pa_streq(e->alsa_name, section))
@@ -1183,10 +1246,10 @@ static pa_alsa_element* element_get(pa_alsa_path *p, const char *section, pa_boo
e->alsa_name = pa_xstrdup(section);
e->direction = p->direction;
- PA_LLIST_PREPEND(pa_alsa_element, p->elements, e);
+ PA_LLIST_INSERT_AFTER(pa_alsa_element, p->elements, p->last_element, e);
finish:
- p->element_parse_cache = e;
+ p->last_element = e;
return e;
}
@@ -1208,11 +1271,11 @@ static pa_alsa_option* option_get(pa_alsa_path *p, const char *section) {
en = pa_xstrndup(section, on - section);
on++;
- if (p->option_parse_cache &&
- pa_streq(p->option_parse_cache->element->alsa_name, en) &&
- pa_streq(p->option_parse_cache->alsa_name, on)) {
+ if (p->last_option &&
+ pa_streq(p->last_option->element->alsa_name, en) &&
+ pa_streq(p->last_option->alsa_name, on)) {
pa_xfree(en);
- return p->option_parse_cache;
+ return p->last_option;
}
pa_assert_se(e = element_get(p, en, FALSE));
@@ -1225,11 +1288,15 @@ static pa_alsa_option* option_get(pa_alsa_path *p, const char *section) {
o = pa_xnew0(pa_alsa_option, 1);
o->element = e;
o->alsa_name = pa_xstrdup(on);
+ o->alsa_idx = -1;
- PA_LLIST_PREPEND(pa_alsa_option, e->options, o);
+ if (p->last_option && p->last_option->element == e)
+ PA_LLIST_INSERT_AFTER(pa_alsa_option, e->options, p->last_option, o);
+ else
+ PA_LLIST_PREPEND(pa_alsa_option, e->options, o);
finish:
- p->option_parse_cache = o;
+ p->last_option = o;
return o;
}
@@ -1572,20 +1639,70 @@ static int element_parse_override_map(
return 0;
}
+static int element_set_option(pa_alsa_element *e, snd_mixer_t *m, int alsa_idx) {
+ snd_mixer_selem_id_t *sid;
+ snd_mixer_elem_t *me;
+ int r;
+
+ pa_assert(e);
+ pa_assert(m);
+
+ SELEM_INIT(sid, e->alsa_name);
+ if (!(me = snd_mixer_find_selem(m, sid))) {
+ pa_log_warn("Element %s seems to have disappeared.", e->alsa_name);
+ return -1;
+ }
+
+ if (e->switch_use == PA_ALSA_SWITCH_SELECT) {
+
+ if (e->direction == PA_ALSA_DIRECTION_OUTPUT)
+ r = snd_mixer_selem_set_playback_switch_all(me, alsa_idx);
+ else
+ r = snd_mixer_selem_set_capture_switch_all(me, alsa_idx);
+
+ if (r < 0)
+ pa_log_warn("Faile to set switch of %s: %s", e->alsa_name, pa_alsa_strerror(errno));
+
+ } else {
+ pa_assert(e->enumeration_use == PA_ALSA_ENUMERATION_SELECT);
+
+ if ((r = snd_mixer_selem_set_enum_item(me, 0, alsa_idx)) < 0)
+ pa_log_warn("Faile to set enumeration of %s: %s", e->alsa_name, pa_alsa_strerror(errno));
+ }
+
+ return r;
+}
+
+int pa_alsa_setting_select(pa_alsa_setting *s, snd_mixer_t *m) {
+ pa_alsa_option *o;
+ uint32_t idx;
+
+ pa_assert(s);
+ pa_assert(m);
+
+ PA_IDXSET_FOREACH(o, s->options, idx)
+ element_set_option(o->element, m, o->alsa_idx);
+
+ return 0;
+}
+
static int option_verify(pa_alsa_option *o) {
static const struct description_map well_known_descriptions[] = {
{ "input", N_("Input") },
{ "input-docking", N_("Docking Station Input") },
- { "input-docking-microphone", N_("Docking Station Microphone Input") },
- { "input-linein", N_("Line-In Input") },
- { "input-microphone", N_("Microphone Input") },
- { "input-microphone-external", N_("External Microphone Input") },
- { "input-microphone-internal", N_("Internal Microphone Input") },
- { "input-radio", N_("Radio Input") },
- { "input-video", N_("Video Input") },
- { "output-amplifier-on", N_("Amplifier") },
+ { "input-docking-microphone", N_("Docking Station Microphone") },
+ { "input-linein", N_("Line-In") },
+ { "input-microphone", N_("Microphone") },
+ { "input-microphone-external", N_("External Microphone") },
+ { "input-microphone-internal", N_("Internal Microphone") },
+ { "input-radio", N_("Radio") },
+ { "input-video", N_("Video") },
{ "input-agc-on", N_("Automatic Gain Control") },
- { "input-boost-on", N_("Boost") }
+ { "input-agc-off", "" },
+ { "input-boost-on", N_("Boost") },
+ { "input-boost-off", "" },
+ { "output-amplifier-on", N_("Amplifier") },
+ { "output-amplifier-off", "" }
};
pa_assert(o);
@@ -1601,11 +1718,17 @@ static int option_verify(pa_alsa_option *o) {
return -1;
}
+ if (o->element->switch_use == PA_ALSA_SWITCH_SELECT &&
+ !pa_streq(o->alsa_name, "on") &&
+ !pa_streq(o->alsa_name, "off")) {
+ pa_log("Switch %s options need be named off or on ", o->element->alsa_name);
+ return -1;
+ }
+
if (!o->description)
o->description = pa_xstrdup(lookup_description(o->name,
well_known_descriptions,
PA_ELEMENTSOF(well_known_descriptions)));
-
if (!o->description)
o->description = pa_xstrdup(o->name);
@@ -1623,6 +1746,11 @@ static int element_verify(pa_alsa_element *e) {
return -1;
}
+ if (e->switch_use == PA_ALSA_SWITCH_SELECT && e->enumeration_use == PA_ALSA_ENUMERATION_SELECT) {
+ pa_log("Element %s cannot set select for both switch and enumeration.", e->alsa_name);
+ return -1;
+ }
+
PA_LLIST_FOREACH(o, e->options)
if (option_verify(o) < 0)
return -1;
@@ -1633,10 +1761,14 @@ static int element_verify(pa_alsa_element *e) {
static int path_verify(pa_alsa_path *p) {
static const struct description_map well_known_descriptions[] = {
{ "analog-input", N_("Analog Input") },
+ { "analog-input-microphone", N_("Analog Microphone") },
+ { "analog-input-linein", N_("Analog Line-In") },
+ { "analog-input-radio", N_("Analog Radio") },
+ { "analog-input-video", N_("Analog Video") },
{ "analog-output", N_("Analog Output") },
{ "analog-output-headphones", N_("Analog Headphones") },
{ "analog-output-lfe-on-mono", N_("Analog Output (LFE)") },
- { "analog-output-mono", N_("Analog Output (Mono)") }
+ { "analog-output-mono", N_("Analog Mono Output") }
};
pa_alsa_element *e;
@@ -1773,6 +1905,103 @@ static void path_drop_unsupported(pa_alsa_path *p) {
}
}
+static void path_make_options_unique(pa_alsa_path *p) {
+ pa_alsa_element *e;
+ pa_alsa_option *o, *u;
+
+ PA_LLIST_FOREACH(e, p->elements) {
+ PA_LLIST_FOREACH(o, e->options) {
+ unsigned i;
+ char *m;
+
+ for (u = o->next; u; u = u->next)
+ if (pa_streq(u->name, o->name))
+ break;
+
+ if (!u)
+ continue;
+
+ m = pa_xstrdup(o->name);
+
+ /* OK, this name is not unique, hence let's rename */
+ for (i = 1, u = o; u; u = u->next) {
+ char *nn, *nd;
+
+ if (!pa_streq(u->name, m))
+ continue;
+
+ nn = pa_sprintf_malloc("%s-%u", m, i);
+ pa_xfree(u->name);
+ u->name = nn;
+
+ nd = pa_sprintf_malloc("%s %u", u->description, i);
+ pa_xfree(u->description);
+ u->description = nd;
+
+ i++;
+ }
+
+ pa_xfree(m);
+ }
+ }
+}
+
+static pa_bool_t element_create_settings(pa_alsa_element *e, pa_alsa_setting *template) {
+ pa_alsa_option *o;
+
+ for (; e; e = e->next)
+ if (e->switch_use == PA_ALSA_SWITCH_SELECT ||
+ e->enumeration_use == PA_ALSA_ENUMERATION_SELECT)
+ break;
+
+ if (!e)
+ return FALSE;
+
+ for (o = e->options; o; o = o->next) {
+ pa_alsa_setting *s;
+
+ if (template) {
+ s = pa_xnewdup(pa_alsa_setting, template, 1);
+ s->options = pa_idxset_copy(template->options);
+ s->name = pa_sprintf_malloc(_("%s+%s"), template->name, o->name);
+ s->description =
+ (template->description[0] && o->description[0])
+ ? pa_sprintf_malloc(_("%s / %s"), template->description, o->description)
+ : (template->description[0]
+ ? pa_xstrdup(template->description)
+ : pa_xstrdup(o->description));
+
+ s->priority = PA_MAX(template->priority, o->priority);
+ } else {
+ s = pa_xnew0(pa_alsa_setting, 1);
+ s->options = pa_idxset_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func);
+ s->name = pa_xstrdup(o->name);
+ s->description = pa_xstrdup(o->description);
+ s->priority = o->priority;
+ }
+
+ pa_idxset_put(s->options, o, NULL);
+
+ if (element_create_settings(e->next, s))
+ /* This is not a leaf, so let's get rid of it */
+ setting_free(s);
+ else {
+ /* This is a leaf, so let's add it */
+ PA_LLIST_INSERT_AFTER(pa_alsa_setting, e->path->settings, e->path->last_setting, s);
+
+ e->path->last_setting = s;
+ }
+ }
+
+ return TRUE;
+}
+
+static void path_create_settings(pa_alsa_path *p) {
+ pa_assert(p);
+
+ element_create_settings(p->elements, NULL);
+}
+
int pa_alsa_path_probe(pa_alsa_path *p, snd_mixer_t *m, pa_bool_t ignore_dB) {
pa_alsa_element *e;
double min_dB[PA_CHANNEL_POSITION_MAX], max_dB[PA_CHANNEL_POSITION_MAX];
@@ -1787,12 +2016,12 @@ int pa_alsa_path_probe(pa_alsa_path *p, snd_mixer_t *m, pa_bool_t ignore_dB) {
pa_zero(min_dB);
pa_zero(max_dB);
- pa_log("Probing %s", p->name);
+ pa_log_debug("Probing path '%s'", p->name);
PA_LLIST_FOREACH(e, p->elements) {
if (element_probe(e, m) < 0) {
p->supported = FALSE;
- pa_log("%s probe failed.", e->alsa_name);
+ pa_log_debug("Probe of element '%s' failed.", e->alsa_name);
return -1;
}
@@ -1841,11 +2070,14 @@ int pa_alsa_path_probe(pa_alsa_path *p, snd_mixer_t *m, pa_bool_t ignore_dB) {
}
path_drop_unsupported(p);
+ path_make_options_unique(p);
+ path_create_settings(p);
p->supported = TRUE;
p->probed = TRUE;
- p->min_dB = p->max_dB = 0.0;
+ p->min_dB = INFINITY;
+ p->max_dB = -INFINITY;
for (t = 0; t < PA_CHANNEL_POSITION_MAX; t++) {
if (p->min_dB > min_dB[t])
@@ -2003,7 +2235,8 @@ pa_alsa_path_set *pa_alsa_path_set_new(pa_alsa_mapping *m, pa_alsa_direction_t d
if ((p = pa_alsa_path_new(fn, direction))) {
p->path_set = ps;
- PA_LLIST_PREPEND(pa_alsa_path, ps->paths, p);
+ PA_LLIST_INSERT_AFTER(pa_alsa_path, ps->paths, ps->last_path, p);
+ ps->last_path = p;
}
pa_xfree(fn);
@@ -2038,10 +2271,12 @@ pa_alsa_path_set *pa_alsa_path_set_new(pa_alsa_mapping *m, pa_alsa_direction_t d
e->direction = direction;
e->required_absent = PA_ALSA_REQUIRED_ANY;
- PA_LLIST_PREPEND(pa_alsa_element, p->elements, e);
+ PA_LLIST_INSERT_AFTER(pa_alsa_element, p->elements, p->last_element, e);
+ p->last_element = e;
}
- PA_LLIST_PREPEND(pa_alsa_path, ps->paths, p);
+ PA_LLIST_INSERT_AFTER(pa_alsa_path, ps->paths, ps->last_path, p);
+ ps->last_path = p;
}
return ps;
@@ -2103,6 +2338,44 @@ static void path_set_unify(pa_alsa_path_set *ps) {
}
}
+static void path_set_make_paths_unique(pa_alsa_path_set *ps) {
+ pa_alsa_path *p, *q;
+
+ PA_LLIST_FOREACH(p, ps->paths) {
+ unsigned i;
+ char *m;
+
+ for (q = p->next; q; q = q->next)
+ if (pa_streq(q->name, p->name))
+ break;
+
+ if (!q)
+ continue;
+
+ m = pa_xstrdup(p->name);
+
+ /* OK, this name is not unique, hence let's rename */
+ for (i = 1, q = p; q; q = q->next) {
+ char *nn, *nd;
+
+ if (!pa_streq(q->name, m))
+ continue;
+
+ nn = pa_sprintf_malloc("%s-%u", m, i);
+ pa_xfree(q->name);
+ q->name = nn;
+
+ nd = pa_sprintf_malloc("%s %u", q->description, i);
+ pa_xfree(q->description);
+ q->description = nd;
+
+ i++;
+ }
+
+ pa_xfree(m);
+ }
+}
+
void pa_alsa_path_set_probe(pa_alsa_path_set *ps, snd_mixer_t *m, pa_bool_t ignore_dB) {
pa_alsa_path *p, *n;
@@ -2121,6 +2394,7 @@ void pa_alsa_path_set_probe(pa_alsa_path_set *ps, snd_mixer_t *m, pa_bool_t igno
}
path_set_unify(ps);
+ path_set_make_paths_unique(ps);
ps->probed = TRUE;
}
@@ -2638,6 +2912,7 @@ static int profile_verify(pa_alsa_profile *p) {
static const struct description_map well_known_descriptions[] = {
{ "output:analog-mono+input:analog-mono", N_("Analog Mono Duplex") },
{ "output:analog-stereo+input:analog-stereo", N_("Analog Stereo Duplex") },
+ { "output:iec958-stereo", N_("Digital Stereo Duplex (IEC958)") },
{ "off", N_("Off") }
};
@@ -2900,8 +3175,9 @@ void pa_alsa_profile_set_probe(pa_alsa_profile_set *ps, const char *dev_id, cons
continue;
pa_log_debug("Checking for playback on %s (%s)", m->description, m->name);
- try_ss = *ss;
try_map = m->channel_map;
+ try_ss = *ss;
+ try_ss.channels = try_map.channels;
if (!(m ->output_pcm = pa_alsa_open_by_device_string_strv(
m->device_strings,
@@ -2923,8 +3199,9 @@ void pa_alsa_profile_set_probe(pa_alsa_profile_set *ps, const char *dev_id, cons
continue;
pa_log_debug("Checking for recording on %s (%s)", m->description, m->name);
- try_ss = *ss;
try_map = m->channel_map;
+ try_ss = *ss;
+ try_ss.channels = try_map.channels;
if (!(m ->input_pcm = pa_alsa_open_by_device_string_strv(
m->device_strings,
@@ -3037,6 +3314,7 @@ void pa_alsa_add_ports(pa_hashmap **p, pa_alsa_path_set *ps) {
pa_alsa_port_data *data;
port = pa_device_port_new(s->name, s->description, sizeof(pa_alsa_port_data));
+ port->priority = s->priority;
data = PA_DEVICE_PORT_DATA(port);
data->path = ps->paths;
@@ -3061,6 +3339,9 @@ void pa_alsa_add_ports(pa_hashmap **p, pa_alsa_path_set *ps) {
* single entry */
port = pa_device_port_new(path->name, path->description, sizeof(pa_alsa_port_data));
+ port->priority = path->priority * 100;
+
+
data = PA_DEVICE_PORT_DATA(port);
data->path = path;
data->setting = path->settings;
@@ -3075,9 +3356,14 @@ void pa_alsa_add_ports(pa_hashmap **p, pa_alsa_path_set *ps) {
char *n, *d;
n = pa_sprintf_malloc("%s;%s", path->name, s->name);
- d = pa_sprintf_malloc(_("%s, %s"), path->description, s->description);
+
+ if (s->description[0])
+ d = pa_sprintf_malloc(_("%s / %s"), path->description, s->description);
+ else
+ d = pa_xstrdup(path->description);
port = pa_device_port_new(n, d, sizeof(pa_alsa_port_data));
+ port->priority = path->priority * 100 + s->priority;
pa_xfree(n);
pa_xfree(d);
diff --git a/src/modules/alsa/alsa-mixer.h b/src/modules/alsa/alsa-mixer.h
index f6b1c35..7678818 100644
--- a/src/modules/alsa/alsa-mixer.h
+++ b/src/modules/alsa/alsa-mixer.h
@@ -169,8 +169,9 @@ struct pa_alsa_path {
/* This is used during parsing only, as a shortcut so that we
* don't have to iterate the list all the time */
- pa_alsa_element *element_parse_cache;
- pa_alsa_option *option_parse_cache;
+ pa_alsa_element *last_element;
+ pa_alsa_option *last_option;
+ pa_alsa_setting *last_setting;
PA_LLIST_HEAD(pa_alsa_element, elements);
PA_LLIST_HEAD(pa_alsa_setting, settings);
@@ -182,6 +183,10 @@ struct pa_alsa_path_set {
PA_LLIST_HEAD(pa_alsa_path, paths);
pa_alsa_direction_t direction;
pa_bool_t probed:1;
+
+ /* This is used during parsing only, as a shortcut so that we
+ * don't have to iterate the list all the time */
+ pa_alsa_path *last_path;
};
int pa_alsa_setting_select(pa_alsa_setting *s, snd_mixer_t *m);
diff --git a/src/modules/alsa/alsa-sink.c b/src/modules/alsa/alsa-sink.c
index d7e5be8..2226bc6 100644
--- a/src/modules/alsa/alsa-sink.c
+++ b/src/modules/alsa/alsa-sink.c
@@ -1003,7 +1003,7 @@ static void sink_get_volume_cb(pa_sink *s) {
return;
/* Shift down by the base volume, so that 0dB becomes maximum volume */
- pa_sw_cvolume_divide_scalar(&r, &r, s->base_volume);
+ pa_sw_cvolume_multiply_scalar(&r, &r, s->base_volume);
pa_log_debug("Read hardware volume: %s", pa_cvolume_snprint(t, sizeof(t), &r));
@@ -1031,13 +1031,13 @@ static void sink_set_volume_cb(pa_sink *s) {
pa_assert(u->mixer_handle);
/* Shift up by the base volume */
- pa_sw_cvolume_multiply_scalar(&r, &s->virtual_volume, s->base_volume);
+ pa_sw_cvolume_divide_scalar(&r, &s->virtual_volume, s->base_volume);
if (pa_alsa_path_set_volume(u->mixer_path, u->mixer_handle, &s->channel_map, &r) < 0)
return;
/* Shift down by the base volume, so that 0dB becomes maximum volume */
- pa_sw_cvolume_divide_scalar(&r, &r, s->base_volume);
+ pa_sw_cvolume_multiply_scalar(&r, &r, s->base_volume);
u->hardware_volume = r;
@@ -1379,12 +1379,17 @@ static void find_mixer(struct userdata *u, pa_alsa_mapping *mapping, const char
if (pa_alsa_path_probe(u->mixer_path, u->mixer_handle, ignore_dB) < 0)
goto fail;
+ pa_log_debug("Probed mixer path %s:", u->mixer_path->name);
+ pa_alsa_path_dump(u->mixer_path);
} else {
if (!(u->mixer_path_set = pa_alsa_path_set_new(mapping, PA_ALSA_DIRECTION_OUTPUT)))
goto fail;
pa_alsa_path_set_probe(u->mixer_path_set, u->mixer_handle, ignore_dB);
+
+ pa_log_debug("Probed mixer paths:");
+ pa_alsa_path_set_dump(u->mixer_path_set);
}
return;
@@ -1425,17 +1430,21 @@ static int setup_mixer(struct userdata *u, pa_bool_t ignore_dB) {
if (data->setting)
pa_alsa_setting_select(data->setting, u->mixer_handle);
- } else if (u->mixer_path) {
+ } else {
- /* Hmm, we have only a single path, then let's activate it */
+ if (!u->mixer_path && u->mixer_path_set)
+ u->mixer_path = u->mixer_path_set->paths;
- pa_alsa_path_select(u->mixer_path, u->mixer_handle);
+ if (u->mixer_path) {
+ /* Hmm, we have only a single path, then let's activate it */
- if (u->mixer_path->settings)
- pa_alsa_setting_select(u->mixer_path->settings, u->mixer_handle);
+ pa_alsa_path_select(u->mixer_path, u->mixer_handle);
- } else
- return 0;
+ if (u->mixer_path->settings)
+ pa_alsa_setting_select(u->mixer_path->settings, u->mixer_handle);
+ } else
+ return 0;
+ }
if (!u->mixer_path->has_volume)
pa_log_info("Driver does not support hardware volume control, falling back to software volume control.");
diff --git a/src/modules/alsa/alsa-source.c b/src/modules/alsa/alsa-source.c
index c15748b..f2e4e23 100644
--- a/src/modules/alsa/alsa-source.c
+++ b/src/modules/alsa/alsa-source.c
@@ -956,7 +956,7 @@ static void source_get_volume_cb(pa_source *s) {
return;
/* Shift down by the base volume, so that 0dB becomes maximum volume */
- pa_sw_cvolume_divide_scalar(&r, &r, s->base_volume);
+ pa_sw_cvolume_multiply_scalar(&r, &r, s->base_volume);
pa_log_debug("Read hardware volume: %s", pa_cvolume_snprint(t, sizeof(t), &r));
@@ -984,13 +984,13 @@ static void source_set_volume_cb(pa_source *s) {
pa_assert(u->mixer_handle);
/* Shift up by the base volume */
- pa_sw_cvolume_multiply_scalar(&r, &s->virtual_volume, s->base_volume);
+ pa_sw_cvolume_divide_scalar(&r, &s->virtual_volume, s->base_volume);
if (pa_alsa_path_set_volume(u->mixer_path, u->mixer_handle, &s->channel_map, &r) < 0)
return;
/* Shift down by the base volume, so that 0dB becomes maximum volume */
- pa_sw_cvolume_divide_scalar(&r, &r, s->base_volume);
+ pa_sw_cvolume_multiply_scalar(&r, &r, s->base_volume);
u->hardware_volume = r;
@@ -1225,18 +1225,23 @@ static void find_mixer(struct userdata *u, pa_alsa_mapping *mapping, const char
if (element) {
- if (!(u->mixer_path = pa_alsa_path_synthesize(element, PA_ALSA_DIRECTION_OUTPUT)))
+ if (!(u->mixer_path = pa_alsa_path_synthesize(element, PA_ALSA_DIRECTION_INPUT)))
goto fail;
if (pa_alsa_path_probe(u->mixer_path, u->mixer_handle, ignore_dB) < 0)
goto fail;
+ pa_log_debug("Probed mixer path %s:", u->mixer_path->name);
+ pa_alsa_path_dump(u->mixer_path);
} else {
- if (!(u->mixer_path_set = pa_alsa_path_set_new(mapping, PA_ALSA_DIRECTION_OUTPUT)))
+ if (!(u->mixer_path_set = pa_alsa_path_set_new(mapping, PA_ALSA_DIRECTION_INPUT)))
goto fail;
pa_alsa_path_set_probe(u->mixer_path_set, u->mixer_handle, ignore_dB);
+
+ pa_log_debug("Probed mixer paths:");
+ pa_alsa_path_set_dump(u->mixer_path_set);
}
return;
@@ -1277,17 +1282,21 @@ static int setup_mixer(struct userdata *u, pa_bool_t ignore_dB) {
if (data->setting)
pa_alsa_setting_select(data->setting, u->mixer_handle);
- } else if (u->mixer_path) {
+ } else {
- /* Hmm, we have only a single path, then let's activate it */
+ if (!u->mixer_path && u->mixer_path_set)
+ u->mixer_path = u->mixer_path_set->paths;
- pa_alsa_path_select(u->mixer_path, u->mixer_handle);
+ if (u->mixer_path) {
+ /* Hmm, we have only a single path, then let's activate it */
- if (u->mixer_path->settings)
- pa_alsa_setting_select(u->mixer_path->settings, u->mixer_handle);
+ pa_alsa_path_select(u->mixer_path, u->mixer_handle);
- } else
- return 0;
+ if (u->mixer_path->settings)
+ pa_alsa_setting_select(u->mixer_path->settings, u->mixer_handle);
+ } else
+ return 0;
+ }
if (!u->mixer_path->has_volume)
pa_log_info("Driver does not support hardware volume control, falling back to software volume control.");
diff --git a/src/modules/alsa/alsa-util.c b/src/modules/alsa/alsa-util.c
index 865daff..d117ccd 100644
--- a/src/modules/alsa/alsa-util.c
+++ b/src/modules/alsa/alsa-util.c
@@ -218,12 +218,12 @@ int pa_alsa_set_hw_params(
if (require_exact_channel_number) {
if ((ret = snd_pcm_hw_params_set_channels(pcm_handle, hwparams, c)) < 0) {
- pa_log_debug("snd_pcm_hw_params_set_channels() failed: %s", pa_alsa_strerror(ret));
+ pa_log_debug("snd_pcm_hw_params_set_channels(%u) failed: %s", c, pa_alsa_strerror(ret));
goto finish;
}
} else {
if ((ret = snd_pcm_hw_params_set_channels_near(pcm_handle, hwparams, &c)) < 0) {
- pa_log_debug("snd_pcm_hw_params_set_channels_near() failed: %s", pa_alsa_strerror(ret));
+ pa_log_debug("snd_pcm_hw_params_set_channels_near(%u) failed: %s", c, pa_alsa_strerror(ret));
goto finish;
}
}
@@ -642,7 +642,7 @@ snd_pcm_t *pa_alsa_open_by_device_string_strv(
for (i = prefix; *i; i++) {
char *d;
- d = pa_sprintf_malloc("%s:%s", *prefix, dev_id);
+ d = pa_sprintf_malloc("%s:%s", *i, dev_id);
pcm_handle = pa_alsa_open_by_device_string(
d,
@@ -839,7 +839,6 @@ void pa_alsa_init_proplist_pcm_info(pa_core *c, pa_proplist *p, snd_pcm_info_t *
pa_proplist_sets(p, "alsa.class", alsa_class_table[class]);
}
-
if ((subclass = snd_pcm_info_get_subclass(pcm_info)) <= SND_PCM_SUBCLASS_LAST)
if (alsa_subclass_table[subclass])
pa_proplist_sets(p, "alsa.subclass", alsa_subclass_table[subclass]);
diff --git a/src/modules/alsa/mixer/paths/analog-input-mic.conf b/src/modules/alsa/mixer/paths/analog-input-aux.conf
similarity index 54%
copy from src/modules/alsa/mixer/paths/analog-input-mic.conf
copy to src/modules/alsa/mixer/paths/analog-input-aux.conf
index 9d40695..8f48056 100644
--- a/src/modules/alsa/mixer/paths/analog-input-mic.conf
+++ b/src/modules/alsa/mixer/paths/analog-input-aux.conf
@@ -1,21 +1,32 @@
-# For devices, where no 'Capture' slider exists an 'Mic' most likely
-# controls input ADC volume (and not the input feedback volume)
+# For devices, where we have an Aux element
[General]
-priority = 100
+priority = 90
name = analog-input
[Element Capture]
-required-absent = volume
switch = mute
-volume = ignore
+volume = merge
override-map.1 = all
override-map.2 = all-left,all-right
[Element Mic]
+switch = off
+volume = off
+
+[Element Line]
+switch = off
+volume = off
+
+[Element Aux]
+required = any
switch = mute
volume = merge
override-map.1 = all
override-map.2 = all-left,all-right
+[Element Video]
+switch = off
+volume = off
+
.include analog-input.conf.common
diff --git a/src/modules/alsa/mixer/paths/analog-input-fm.conf b/src/modules/alsa/mixer/paths/analog-input-fm.conf
new file mode 100644
index 0000000..0f78f39
--- /dev/null
+++ b/src/modules/alsa/mixer/paths/analog-input-fm.conf
@@ -0,0 +1,44 @@
+# For devices where we have an FM element
+
+[General]
+priority = 70
+name = analog-input-radio
+
+[Element Capture]
+switch = mute
+volume = merge
+override-map.1 = all
+override-map.2 = all-left,all-right
+
+[Element Mic]
+switch = off
+volume = off
+
+[Element Line]
+switch = off
+volume = off
+
+[Element Aux]
+switch = off
+volume = off
+
+[Element Video]
+switch = off
+volume = off
+
+[Element Mic/Line]
+switch = off
+volume = off
+
+[Element TV Tuner]
+switch = off
+volume = off
+
+[Element FM]
+required = any
+switch = mute
+volume = merge
+override-map.1 = all
+override-map.2 = all-left,all-right
+
+.include analog-input.conf.common
diff --git a/src/modules/alsa/mixer/paths/analog-input-linein.conf b/src/modules/alsa/mixer/paths/analog-input-linein.conf
new file mode 100644
index 0000000..b6ba738
--- /dev/null
+++ b/src/modules/alsa/mixer/paths/analog-input-linein.conf
@@ -0,0 +1,43 @@
+# For devices, where we have a Line element
+
+[General]
+priority = 90
+
+[Element Capture]
+switch = mute
+volume = merge
+override-map.1 = all
+override-map.2 = all-left,all-right
+
+[Element Mic]
+switch = off
+volume = off
+
+[Element Line]
+required = any
+switch = mute
+volume = merge
+override-map.1 = all
+override-map.2 = all-left,all-right
+
+[Element Aux]
+switch = off
+volume = off
+
+[Element Video]
+switch = off
+volume = off
+
+[Element Mic/Line]
+switch = off
+volume = off
+
+[Element TV Tuner]
+switch = off
+volume = off
+
+[Element FM]
+switch = off
+volume = off
+
+.include analog-input.conf.common
diff --git a/src/modules/alsa/mixer/paths/analog-input-mic-line.conf b/src/modules/alsa/mixer/paths/analog-input-mic-line.conf
new file mode 100644
index 0000000..7d4addf
--- /dev/null
+++ b/src/modules/alsa/mixer/paths/analog-input-mic-line.conf
@@ -0,0 +1,44 @@
+# For devices where we have a Mic/Lineb element
+
+[General]
+priority = 90
+name = analog-input
+
+[Element Capture]
+switch = mute
+volume = merge
+override-map.1 = all
+override-map.2 = all-left,all-right
+
+[Element Mic]
+switch = off
+volume = off
+
+[Element Line]
+switch = off
+volume = off
+
+[Element Aux]
+switch = off
+volume = off
+
+[Element Video]
+switch = off
+volume = off
+
+[Element Mic/Line]
+required = any
+switch = mute
+volume = merge
+override-map.1 = all
+override-map.2 = all-left,all-right
+
+[Element TV Tuner]
+switch = off
+volume = off
+
+[Element FM]
+switch = off
+volume = off
+
+.include analog-input.conf.common
diff --git a/src/modules/alsa/mixer/paths/analog-input-mic.conf b/src/modules/alsa/mixer/paths/analog-input-mic.conf
index 9d40695..004cd24 100644
--- a/src/modules/alsa/mixer/paths/analog-input-mic.conf
+++ b/src/modules/alsa/mixer/paths/analog-input-mic.conf
@@ -1,21 +1,45 @@
-# For devices, where no 'Capture' slider exists an 'Mic' most likely
-# controls input ADC volume (and not the input feedback volume)
+# For devices where we have a Mic element
[General]
priority = 100
-name = analog-input
+name = analog-input-microphone
[Element Capture]
-required-absent = volume
switch = mute
-volume = ignore
+volume = merge
override-map.1 = all
override-map.2 = all-left,all-right
[Element Mic]
+required = any
switch = mute
volume = merge
override-map.1 = all
override-map.2 = all-left,all-right
+[Element Line]
+switch = off
+volume = off
+
+[Element Aux]
+switch = off
+volume = off
+
+[Element Video]
+switch = off
+volume = off
+
+[Element Mic/Line]
+switch = off
+volume = off
+
+[Element TV Tuner]
+switch = off
+volume = off
+
+[Element FM]
+switch = off
+volume = off
+
.include analog-input.conf.common
+.include analog-input-mic.conf.common
diff --git a/src/modules/alsa/mixer/paths/analog-input-mic.conf.common b/src/modules/alsa/mixer/paths/analog-input-mic.conf.common
new file mode 100644
index 0000000..d67ee4e
--- /dev/null
+++ b/src/modules/alsa/mixer/paths/analog-input-mic.conf.common
@@ -0,0 +1,41 @@
+;;; 'Mic Select'
+
+[Element Mic Select]
+enumeration = select
+
+[Option Mic Select:Mic1]
+name = input-microphone
+priority = 20
+
+[Option Mic Select:Mic2]
+name = input-microphone
+priority = 19
+
+;;; Various Boosts
+
+[Element Mic Boost (+20dB)]
+switch = select
+
+[Option Mic Boost (+20dB):on]
+name = input-boost-on
+
+[Option Mic Boost (+20dB):off]
+name = input-boost-off
+
+[Element Mic Boost]
+switch = select
+
+[Option Mic Boost:on]
+name = input-boost-on
+
+[Option Mic Boost:off]
+name = input-boost-off
+
+[Element Front Mic Boost]
+switch = select
+
+[Option Front Mic Boost:on]
+name = input-boost-on
+
+[Option Front Mic Boost:off]
+name = input-boost-off
diff --git a/src/modules/alsa/mixer/paths/analog-input-tvtuner.conf b/src/modules/alsa/mixer/paths/analog-input-tvtuner.conf
new file mode 100644
index 0000000..ea0a0b7
--- /dev/null
+++ b/src/modules/alsa/mixer/paths/analog-input-tvtuner.conf
@@ -0,0 +1,44 @@
+# For devices, where we have a TV Tuner element
+
+[General]
+priority = 70
+name = analog-input-video
+
+[Element Capture]
+switch = mute
+volume = merge
+override-map.1 = all
+override-map.2 = all-left,all-right
+
+[Element Mic]
+switch = off
+volume = off
+
+[Element Line]
+switch = off
+volume = off
+
+[Element Aux]
+switch = off
+volume = off
+
+[Element Video]
+switch = off
+volume = off
+
+[Element Mic/Line]
+switch = off
+volume = off
+
+[Element TV Tuner]
+required = any
+switch = mute
+volume = merge
+override-map.1 = all
+override-map.2 = all-left,all-right
+
+[Element FM]
+switch = off
+volume = off
+
+.include analog-input.conf.common
diff --git a/src/modules/alsa/mixer/paths/analog-input-mic.conf b/src/modules/alsa/mixer/paths/analog-input-video.conf
similarity index 52%
copy from src/modules/alsa/mixer/paths/analog-input-mic.conf
copy to src/modules/alsa/mixer/paths/analog-input-video.conf
index 9d40695..27acc25 100644
--- a/src/modules/alsa/mixer/paths/analog-input-mic.conf
+++ b/src/modules/alsa/mixer/paths/analog-input-video.conf
@@ -1,18 +1,28 @@
-# For devices, where no 'Capture' slider exists an 'Mic' most likely
-# controls input ADC volume (and not the input feedback volume)
+# For devices, where we have a Video element
[General]
-priority = 100
-name = analog-input
+priority = 70
[Element Capture]
-required-absent = volume
switch = mute
-volume = ignore
+volume = merge
override-map.1 = all
override-map.2 = all-left,all-right
[Element Mic]
+switch = off
+volume = off
+
+[Element Line]
+switch = off
+volume = off
+
+[Element Aux]
+switch = off
+volume = off
+
+[Element Video]
+required = any
switch = mute
volume = merge
override-map.1 = all
diff --git a/src/modules/alsa/mixer/paths/analog-input.conf b/src/modules/alsa/mixer/paths/analog-input.conf
index b96af1d..b221bb4 100644
--- a/src/modules/alsa/mixer/paths/analog-input.conf
+++ b/src/modules/alsa/mixer/paths/analog-input.conf
@@ -1,5 +1,4 @@
-# For normal devices, where a 'Capture' slider exists. This path will
-# not apply if we lack a 'Capture' Slider
+# A fallback for devices that lack seperate Mic/Line/Aux/Video elements
[General]
priority = 100
@@ -12,13 +11,25 @@ override-map.1 = all
override-map.2 = all-left,all-right
[Element Mic]
-switch = select
-volume = ignore
-override-map.1 = all
-override-map.2 = all-left,all-right
+required-absent = any
+
+[Element Line]
+required-absent = any
+
+[Element Aux]
+required-absent = any
+
+[Element Video]
+required-absent = any
+
+[Element Mic/Line]
+required-absent = any
+
+[Element TV Tuner]
+required-absent = any
-[Option Mic:on]
-name = input-microphone
-priority = 20
+[Element FM]
+required-absent = any
.include analog-input.conf.common
+.include analog-input-mic.conf.common
diff --git a/src/modules/alsa/mixer/paths/analog-input.conf.common b/src/modules/alsa/mixer/paths/analog-input.conf.common
index e353cc7..d34afd0 100644
--- a/src/modules/alsa/mixer/paths/analog-input.conf.common
+++ b/src/modules/alsa/mixer/paths/analog-input.conf.common
@@ -26,29 +26,6 @@
# PC Speaker
#
-;;; Non-Enumeration Elements
-
-[Element Line]
-switch = select
-
-[Option Line:on]
-name = input-linein
-priority = 18
-
-[Element Aux]
-switch = select
-
-[Option Aux:on]
-name = input
-priority = 16
-
-[Element Video]
-switch = select
-
-[Option Video:on]
-name = input-video
-priority = 14
-
;;; 'Input Source Select'
[Element Input Source Select]
@@ -95,19 +72,6 @@ priority = 18
name = input-linein
priority = 18
-;;; 'Mic Select'
-
-[Element Mic Select]
-enumeration = select
-
-[Option Mic Select:Mic1]
-name = input-microphone
-priority = 20
-
-[Option Mic Select:Mic2]
-name = input-microphone
-priority = 19
-
;;; ' Capture Source'
[Element Capture Source]
@@ -256,16 +220,7 @@ name = input-docking-microphone
;;; Various Boosts
-[Element Mic Boost (+20dB)]
-switch = select
-
-[Option Mic Boost (+20dB):on]
-name = input-boost-on
-
-[Option Mic Boost (+20dB):off]
-name = input-boost-off
-
-[Option Capture Boost]
+[Element Capture Boost]
switch = select
[Option Capture Boost:on]
@@ -274,24 +229,6 @@ name = input-boost-on
[Option Capture Boost:off]
name = input-boost-off
-[Element Mic Boost]
-switch = select
-
-[Option Mic Boost:on]
-name = input-boost-on
-
-[Option Mic Boost:off]
-name = input-boost-off
-
-[Element Front Mic Boost]
-switch = select
-
-[Option Front Mic Boost:on]
-name = input-boost-on
-
-[Option Front Mic Boost:off]
-name = input-boost-off
-
[Element Auto Gain Control]
switch = select
diff --git a/src/modules/alsa/mixer/paths/analog-output.conf b/src/modules/alsa/mixer/paths/analog-output.conf
index e869920..15e703c 100644
--- a/src/modules/alsa/mixer/paths/analog-output.conf
+++ b/src/modules/alsa/mixer/paths/analog-output.conf
@@ -35,7 +35,7 @@ volume = merge
override-map.1 = all-rear
override-map.2 = rear-left,rear-right
-[Element Sourround]
+[Element Surround]
switch = mute
volume = merge
override-map.1 = all-rear
diff --git a/src/modules/alsa/mixer/profiles/default.conf b/src/modules/alsa/mixer/profile-sets/default.conf
similarity index 83%
rename from src/modules/alsa/mixer/profiles/default.conf
rename to src/modules/alsa/mixer/profile-sets/default.conf
index fc2c192..bced10a 100644
--- a/src/modules/alsa/mixer/profiles/default.conf
+++ b/src/modules/alsa/mixer/profile-sets/default.conf
@@ -25,21 +25,20 @@ auto-profiles = yes
device-strings = hw
channel-map = mono
paths-output = analog-output analog-output-headphones analog-output-mono analog-output-lfe-on-mono
-paths-input = analog-input analog-input-mic
+paths-input = analog-input analog-input-mic analog-input-linein analog-input-aux analog-input-video analog-input-tvtuner analog-input-fm analog-input-mic-line
priority = 1
[Mapping analog-stereo]
device-strings = front hw
channel-map = left,right
paths-output = analog-output analog-output-headphones analog-output-mono analog-output-lfe-on-mono
-paths-input = analog-input analog-input-mic
+paths-input = analog-input analog-input-mic analog-input-linein analog-input-aux analog-input-video analog-input-tvtuner analog-input-fm analog-input-mic-line
priority = 10
[Mapping analog-surround-40]
device-strings = surround40
channel-map = front-left,front-right,rear-left,rear-right
paths-output = analog-output analog-output-lfe-on-mono
-paths-input = analog-input
priority = 7
direction = output
@@ -47,7 +46,6 @@ direction = output
device-strings = surround41
channel-map = front-left,front-right,rear-left,rear-right,lfe
paths-output = analog-output analog-output-lfe-on-mono
-paths-input = analog-input
priority = 8
direction = output
@@ -55,7 +53,6 @@ direction = output
device-strings = surround50
channel-map = front-left,front-right,rear-left,rear-right,front-center
paths-output = analog-output analog-output-lfe-on-mono
-paths-input = analog-input
priority = 7
direction = output
@@ -63,7 +60,6 @@ direction = output
device-strings = surround51
channel-map = front-left,front-right,rear-left,rear-right,front-center,lfe
paths-output = analog-output analog-output-lfe-on-mono
-paths-input = analog-input
priority = 8
direction = output
@@ -72,7 +68,6 @@ device-strings = surround71
channel-map = front-left,front-right,rear-left,rear-right,front-center,lfe,side-left,side-right
description = Analog Surround 7.1
paths-output = analog-output analog-output-lfe-on-mono
-paths-input = analog-input
priority = 7
direction = output
@@ -104,7 +99,7 @@ channel-map = left,right
priority = 4
direction = output
-[Profile output:analog-stereo+output:iec958-stereo+input:analog-stereo]
-description = Foobar
-output-mappings = analog-stereo iec958-stereo
-input-mappings = analog-stereo
+#[Profile output:analog-stereo+output:iec958-stereo+input:analog-stereo]
+#description = Foobar
+#output-mappings = analog-stereo iec958-stereo
+#input-mappings = analog-stereo
diff --git a/src/modules/alsa/module-alsa-card.c b/src/modules/alsa/module-alsa-card.c
index ca2c07f..e8a7f20 100644
--- a/src/modules/alsa/module-alsa-card.c
+++ b/src/modules/alsa/module-alsa-card.c
@@ -243,11 +243,13 @@ static void init_profile(struct userdata *u) {
d = PA_CARD_PROFILE_DATA(u->card->active_profile);
- PA_IDXSET_FOREACH(am, d->profile->output_mappings, idx)
- am->sink = pa_alsa_sink_new(u->module, u->modargs, __FILE__, u->card, am);
+ if (d->profile && d->profile->output_mappings)
+ PA_IDXSET_FOREACH(am, d->profile->output_mappings, idx)
+ am->sink = pa_alsa_sink_new(u->module, u->modargs, __FILE__, u->card, am);
- PA_IDXSET_FOREACH(am, d->profile->input_mappings, idx)
- am->source = pa_alsa_source_new(u->module, u->modargs, __FILE__, u->card, am);
+ if (d->profile && d->profile->input_mappings)
+ PA_IDXSET_FOREACH(am, d->profile->input_mappings, idx)
+ am->source = pa_alsa_source_new(u->module, u->modargs, __FILE__, u->card, am);
}
static void set_card_name(pa_card_new_data *data, pa_modargs *ma, const char *device_id) {
@@ -295,7 +297,7 @@ int pa__init(pa_module *m) {
goto fail;
}
- m->userdata = u = pa_xnew(struct userdata, 1);
+ m->userdata = u = pa_xnew0(struct userdata, 1);
u->core = m->core;
u->module = m;
u->device_id = pa_xstrdup(pa_modargs_get_value(ma, "device_id", DEFAULT_DEVICE_ID));
@@ -328,6 +330,8 @@ int pa__init(pa_module *m) {
if (!u->profile_set)
goto fail;
+ pa_alsa_profile_set_probe(u->profile_set, u->device_id, &m->core->default_sample_spec);
+
pa_card_new_data_init(&data);
data.driver = __FILE__;
data.module = m;
diff --git a/src/pulsecore/idxset.c b/src/pulsecore/idxset.c
index 352ac97..408011f 100644
--- a/src/pulsecore/idxset.c
+++ b/src/pulsecore/idxset.c
@@ -453,3 +453,17 @@ pa_bool_t pa_idxset_isempty(pa_idxset *s) {
return s->n_entries == 0;
}
+
+pa_idxset *pa_idxset_copy(pa_idxset *s) {
+ pa_idxset *copy;
+ struct idxset_entry *i;
+
+ pa_assert(s);
+
+ copy = pa_idxset_new(s->hash_func, s->compare_func);
+
+ for (i = s->iterate_list_head; i; i = i->iterate_next)
+ pa_idxset_put(copy, i->data, NULL);
+
+ return copy;
+}
diff --git a/src/pulsecore/idxset.h b/src/pulsecore/idxset.h
index a6179fc..d1e68c5 100644
--- a/src/pulsecore/idxset.h
+++ b/src/pulsecore/idxset.h
@@ -103,6 +103,9 @@ unsigned pa_idxset_size(pa_idxset*s);
/* Return TRUE of the idxset is empty */
pa_bool_t pa_idxset_isempty(pa_idxset *s);
+/* Duplicate the idxset. This will not copy the actual indexes */
+pa_idxset *pa_idxset_copy(pa_idxset *s);
+
/* A macro to ease iteration through all entries */
#define PA_IDXSET_FOREACH(e, s, idx) \
for ((e) = pa_idxset_first((s), &(idx)); (e); (e) = pa_idxset_next((s), &(idx)))
--
hooks/post-receive
PulseAudio Sound Server
More information about the pulseaudio-commits
mailing list