#endif
#include <sys/types.h>
-#include <limits.h>
#include <asoundlib.h>
+#include <math.h>
#ifdef HAVE_VALGRIND_MEMCHECK_H
#include <valgrind/memcheck.h>
#endif
+#include <pulse/mainloop-api.h>
#include <pulse/sample.h>
-#include <pulse/xmalloc.h>
#include <pulse/timeval.h>
#include <pulse/util.h>
-#include <pulse/i18n.h>
+#include <pulse/volume.h>
+#include <pulse/xmalloc.h>
#include <pulse/utf8.h>
+#include <pulsecore/i18n.h>
#include <pulsecore/log.h>
#include <pulsecore/macro.h>
#include <pulsecore/core-util.h>
-#include <pulsecore/atomic.h>
-#include <pulsecore/core-error.h>
-#include <pulsecore/once.h>
-#include <pulsecore/thread.h>
#include <pulsecore/conf-parser.h>
#include <pulsecore/strbuf.h>
void *userdata;
};
-static void io_cb(pa_mainloop_api*a, pa_io_event* e, int fd, pa_io_event_flags_t events, void *userdata) {
+static void io_cb(pa_mainloop_api *a, pa_io_event *e, int fd, pa_io_event_flags_t events, void *userdata) {
struct pa_alsa_fdlist *fdl = userdata;
int err;
snd_mixer_handle_events(fdl->mixer);
}
-static void defer_cb(pa_mainloop_api*a, pa_defer_event* e, void *userdata) {
+static void defer_cb(pa_mainloop_api *a, pa_defer_event *e, void *userdata) {
struct pa_alsa_fdlist *fdl = userdata;
unsigned num_fds, i;
int err, n;
pa_xfree(fdl);
}
-int pa_alsa_fdlist_set_mixer(struct pa_alsa_fdlist *fdl, snd_mixer_t *mixer_handle, pa_mainloop_api* m) {
+int pa_alsa_fdlist_set_mixer(struct pa_alsa_fdlist *fdl, snd_mixer_t *mixer_handle, pa_mainloop_api *m) {
pa_assert(fdl);
pa_assert(mixer_handle);
pa_assert(m);
struct pollfd *p;
unsigned n_fds;
unsigned short revents = 0;
- int err;
+ int err, ret = 0;
pd = pa_rtpoll_item_get_userdata(i);
pa_assert_fp(pd);
if ((err = snd_mixer_poll_descriptors_revents(pd->mixer, p, n_fds, &revents)) < 0) {
pa_log_error("Unable to get poll revent: %s", pa_alsa_strerror(err));
- pa_rtpoll_item_free(i);
- return -1;
+ ret = -1;
+ goto fail;
}
if (revents) {
- snd_mixer_handle_events(pd->mixer);
- pa_rtpoll_item_free(i);
- pa_alsa_set_mixer_rtpoll(pd, pd->mixer, pd->rtpoll);
+ if (revents & (POLLNVAL | POLLERR)) {
+ pa_log_debug("Device disconnected, stopping poll on mixer");
+ goto fail;
+ } else if (revents & POLLERR) {
+ /* This shouldn't happen. */
+ pa_log_error("Got a POLLERR (revents = %04x), stopping poll on mixer", revents);
+ goto fail;
+ }
+
+ err = snd_mixer_handle_events(pd->mixer);
+
+ if (PA_LIKELY(err >= 0)) {
+ pa_rtpoll_item_free(i);
+ pa_alsa_set_mixer_rtpoll(pd, pd->mixer, pd->rtpoll);
+ } else {
+ pa_log_error("Error handling mixer event: %s", pa_alsa_strerror(err));
+ ret = -1;
+ goto fail;
+ }
}
- return 0;
+ return ret;
+
+fail:
+ pa_rtpoll_item_free(i);
+
+ pd->poll_item = NULL;
+ pd->rtpoll = NULL;
+ pd->mixer = NULL;
+
+ return ret;
}
int pa_alsa_set_mixer_rtpoll(struct pa_alsa_mixer_pdata *pd, snd_mixer_t *mixer, pa_rtpoll *rtp) {
}
void pa_alsa_path_set_free(pa_alsa_path_set *ps) {
- pa_alsa_path *p;
pa_assert(ps);
- while ((p = ps->paths)) {
- PA_LLIST_REMOVE(pa_alsa_path, ps->paths, p);
- pa_alsa_path_free(p);
- }
+ if (ps->paths)
+ pa_hashmap_free(ps->paths, NULL, NULL);
pa_xfree(ps);
}
return i + db_fix->min_step;
}
-static int element_set_volume(pa_alsa_element *e, snd_mixer_t *m, const pa_channel_map *cm, pa_cvolume *v, pa_bool_t write_to_hw) {
+/* Alsa lib documentation says for snd_mixer_selem_set_playback_dB() direction argument,
+ * that "-1 = accurate or first below, 0 = accurate, 1 = accurate or first above".
+ * But even with accurate nearest dB volume step is not selected, so that is why we need
+ * this function. Returns 0 and nearest selectable volume in *value_dB on success or
+ * negative error code if fails. */
+static int element_get_nearest_alsa_dB(snd_mixer_elem_t *me, snd_mixer_selem_channel_id_t c, pa_alsa_direction_t d, long *value_dB) {
+
+ long alsa_val;
+ long value_high;
+ long value_low;
+ int r = -1;
+
+ pa_assert(me);
+ pa_assert(value_dB);
+
+ if (d == PA_ALSA_DIRECTION_OUTPUT) {
+ if ((r = snd_mixer_selem_ask_playback_dB_vol(me, *value_dB, +1, &alsa_val)) >= 0)
+ r = snd_mixer_selem_ask_playback_vol_dB(me, alsa_val, &value_high);
+
+ if (r < 0)
+ return r;
+
+ if (value_high == *value_dB)
+ return r;
+
+ if ((r = snd_mixer_selem_ask_playback_dB_vol(me, *value_dB, -1, &alsa_val)) >= 0)
+ r = snd_mixer_selem_ask_playback_vol_dB(me, alsa_val, &value_low);
+ } else {
+ if ((r = snd_mixer_selem_ask_capture_dB_vol(me, *value_dB, +1, &alsa_val)) >= 0)
+ r = snd_mixer_selem_ask_capture_vol_dB(me, alsa_val, &value_high);
+
+ if (r < 0)
+ return r;
+
+ if (value_high == *value_dB)
+ return r;
+
+ if ((r = snd_mixer_selem_ask_capture_dB_vol(me, *value_dB, -1, &alsa_val)) >= 0)
+ r = snd_mixer_selem_ask_capture_vol_dB(me, alsa_val, &value_low);
+ }
+
+ if (r < 0)
+ return r;
+
+ if (labs(value_high - *value_dB) < labs(value_low - *value_dB))
+ *value_dB = value_high;
+ else
+ *value_dB = value_low;
+
+ return r;
+}
+
+static int element_set_volume(pa_alsa_element *e, snd_mixer_t *m, const pa_channel_map *cm, pa_cvolume *v, pa_bool_t deferred_volume, pa_bool_t write_to_hw) {
snd_mixer_selem_id_t *sid;
pa_cvolume rv;
if (e->has_dB) {
long value = to_alsa_dB(f);
- int rounding = value > 0 ? -1 : +1;
+ int rounding;
+
+ if (e->volume_limit >= 0 && value > (e->max_dB * 100))
+ value = e->max_dB * 100;
if (e->direction == PA_ALSA_DIRECTION_OUTPUT) {
/* If we call set_playback_volume() without checking first
* if the channel is available, ALSA behaves very
* strangely and doesn't fail the call */
if (snd_mixer_selem_has_playback_channel(me, c)) {
+ rounding = +1;
if (e->db_fix) {
if (write_to_hw)
r = snd_mixer_selem_set_playback_volume(me, c, decibel_fix_get_step(e->db_fix, &value, rounding));
} else {
if (write_to_hw) {
- if ((r = snd_mixer_selem_set_playback_dB(me, c, value, rounding)) >= 0)
- r = snd_mixer_selem_get_playback_dB(me, c, &value);
+ if (deferred_volume) {
+ if ((r = element_get_nearest_alsa_dB(me, c, PA_ALSA_DIRECTION_OUTPUT, &value)) >= 0)
+ r = snd_mixer_selem_set_playback_dB(me, c, value, 0);
+ } else {
+ if ((r = snd_mixer_selem_set_playback_dB(me, c, value, rounding)) >= 0)
+ r = snd_mixer_selem_get_playback_dB(me, c, &value);
+ }
} else {
long alsa_val;
if ((r = snd_mixer_selem_ask_playback_dB_vol(me, value, rounding, &alsa_val)) >= 0)
r = -1;
} else {
if (snd_mixer_selem_has_capture_channel(me, c)) {
+ rounding = -1;
if (e->db_fix) {
if (write_to_hw)
r = snd_mixer_selem_set_capture_volume(me, c, decibel_fix_get_step(e->db_fix, &value, rounding));
} else {
if (write_to_hw) {
- if ((r = snd_mixer_selem_set_capture_dB(me, c, value, rounding)) >= 0)
- r = snd_mixer_selem_get_capture_dB(me, c, &value);
+ if (deferred_volume) {
+ if ((r = element_get_nearest_alsa_dB(me, c, PA_ALSA_DIRECTION_INPUT, &value)) >= 0)
+ r = snd_mixer_selem_set_capture_dB(me, c, value, 0);
+ } else {
+ if ((r = snd_mixer_selem_set_capture_dB(me, c, value, rounding)) >= 0)
+ r = snd_mixer_selem_get_capture_dB(me, c, &value);
+ }
} else {
long alsa_val;
if ((r = snd_mixer_selem_ask_capture_dB_vol(me, value, rounding, &alsa_val)) >= 0)
return 0;
}
-int pa_alsa_path_set_volume(pa_alsa_path *p, snd_mixer_t *m, const pa_channel_map *cm, pa_cvolume *v, pa_bool_t write_to_hw) {
+int pa_alsa_path_set_volume(pa_alsa_path *p, snd_mixer_t *m, const pa_channel_map *cm, pa_cvolume *v, pa_bool_t deferred_volume, pa_bool_t write_to_hw) {
pa_alsa_element *e;
pa_cvolume rv;
pa_assert(!p->has_dB || e->has_dB);
ev = rv;
- if (element_set_volume(e, m, cm, &ev, write_to_hw) < 0)
+ if (element_set_volume(e, m, cm, &ev, deferred_volume, write_to_hw) < 0)
return -1;
if (!p->has_dB) {
return 0;
}
-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;
+/* Depending on whether e->volume_use is _OFF, _ZERO or _CONSTANT, this
+ * function sets all channels of the volume element to e->min_volume, 0 dB or
+ * e->constant_volume. */
+static int element_set_constant_volume(pa_alsa_element *e, snd_mixer_t *m) {
+ snd_mixer_elem_t *me = NULL;
+ snd_mixer_selem_id_t *sid = NULL;
+ int r = 0;
+ long volume = -1;
+ pa_bool_t volume_set = FALSE;
pa_assert(m);
pa_assert(e);
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);
+ switch (e->volume_use) {
+ case PA_ALSA_VOLUME_OFF:
+ volume = e->min_volume;
+ volume_set = TRUE;
+ break;
- if (r < 0)
- pa_log_warn("Failed to set volume to muted of %s: %s", e->alsa_name, pa_alsa_strerror(errno));
+ case PA_ALSA_VOLUME_ZERO:
+ if (e->db_fix) {
+ long dB = 0;
- return r;
-}
-
-/* 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;
+ volume = decibel_fix_get_step(e->db_fix, &dB, (e->direction == PA_ALSA_DIRECTION_OUTPUT ? +1 : -1));
+ volume_set = TRUE;
+ }
+ break;
- pa_assert(m);
- pa_assert(e);
+ case PA_ALSA_VOLUME_CONSTANT:
+ volume = e->constant_volume;
+ volume_set = TRUE;
+ break;
- 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;
+ default:
+ pa_assert_not_reached();
}
- if (e->direction == PA_ALSA_DIRECTION_OUTPUT)
- if (e->db_fix) {
- long value = 0;
+ if (volume_set) {
+ if (e->direction == PA_ALSA_DIRECTION_OUTPUT)
+ r = snd_mixer_selem_set_playback_volume_all(me, volume);
+ else
+ r = snd_mixer_selem_set_capture_volume_all(me, volume);
+ } else {
+ pa_assert(e->volume_use == PA_ALSA_VOLUME_ZERO);
+ pa_assert(!e->db_fix);
- r = snd_mixer_selem_set_playback_volume_all(me, decibel_fix_get_step(e->db_fix, &value, +1));
- } else
+ if (e->direction == PA_ALSA_DIRECTION_OUTPUT)
r = snd_mixer_selem_set_playback_dB_all(me, 0, +1);
- else
- if (e->db_fix) {
- long value = 0;
-
- r = snd_mixer_selem_set_capture_volume_all(me, decibel_fix_get_step(e->db_fix, &value, +1));
- } else
- r = snd_mixer_selem_set_capture_dB_all(me, 0, +1);
+ else
+ r = snd_mixer_selem_set_capture_dB_all(me, 0, -1);
+ }
if (r < 0)
- pa_log_warn("Failed to set volume to 0dB of %s: %s", e->alsa_name, pa_alsa_strerror(errno));
+ pa_log_warn("Failed to set volume of %s: %s", e->alsa_name, pa_alsa_strerror(errno));
return r;
}
switch (e->volume_use) {
case PA_ALSA_VOLUME_OFF:
- r = element_mute_volume(e, m);
- break;
-
case PA_ALSA_VOLUME_ZERO:
- r = element_zero_volume(e, m);
+ case PA_ALSA_VOLUME_CONSTANT:
+ r = element_set_constant_volume(e, m);
break;
case PA_ALSA_VOLUME_MERGE:
if (e->required_any != PA_ALSA_REQUIRED_IGNORE) {
switch (e->required_any) {
- case PA_ALSA_REQUIRED_VOLUME:
- e->path->req_any_present |= (e->volume_use != PA_ALSA_VOLUME_IGNORE);
- break;
- case PA_ALSA_REQUIRED_SWITCH:
- e->path->req_any_present |= (e->switch_use != PA_ALSA_SWITCH_IGNORE);
- break;
- case PA_ALSA_REQUIRED_ENUMERATION:
- e->path->req_any_present |= (e->enumeration_use != PA_ALSA_ENUMERATION_IGNORE);
- break;
- case PA_ALSA_REQUIRED_ANY:
- e->path->req_any_present |=
- (e->volume_use != PA_ALSA_VOLUME_IGNORE) ||
- (e->switch_use != PA_ALSA_SWITCH_IGNORE) ||
- (e->enumeration_use != PA_ALSA_ENUMERATION_IGNORE);
- break;
+ case PA_ALSA_REQUIRED_VOLUME:
+ e->path->req_any_present |= (e->volume_use != PA_ALSA_VOLUME_IGNORE);
+ break;
+ case PA_ALSA_REQUIRED_SWITCH:
+ e->path->req_any_present |= (e->switch_use != PA_ALSA_SWITCH_IGNORE);
+ break;
+ case PA_ALSA_REQUIRED_ENUMERATION:
+ e->path->req_any_present |= (e->enumeration_use != PA_ALSA_ENUMERATION_IGNORE);
+ break;
+ case PA_ALSA_REQUIRED_ANY:
+ e->path->req_any_present |=
+ (e->volume_use != PA_ALSA_VOLUME_IGNORE) ||
+ (e->switch_use != PA_ALSA_SWITCH_IGNORE) ||
+ (e->enumeration_use != PA_ALSA_ENUMERATION_IGNORE);
+ break;
+ default:
+ pa_assert_not_reached();
}
}
pa_assert(m);
pa_assert(e);
+ pa_assert(e->path);
SELEM_INIT(sid, e->alsa_name);
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 if (e->volume_use == PA_ALSA_VOLUME_CONSTANT &&
+ (e->min_volume > e->constant_volume || e->max_volume < e->constant_volume)) {
+ pa_log_warn("Constant volume %li configured for element %s, but the available range is from %li to %li.",
+ e->constant_volume, e->alsa_name, e->min_volume, e->max_volume);
+ e->volume_use = PA_ALSA_VOLUME_IGNORE;
+
} else {
pa_bool_t is_mono;
pa_channel_position_t p;
else
e->has_dB = snd_mixer_selem_get_capture_dB_range(me, &min_dB, &max_dB) >= 0;
+ /* Check that the kernel driver returns consistent limits with
+ * both _get_*_dB_range() and _ask_*_vol_dB(). */
+ if (e->has_dB && !e->db_fix) {
+ long min_dB_checked = 0;
+ long max_dB_checked = 0;
+
+ if (e->direction == PA_ALSA_DIRECTION_OUTPUT)
+ r = snd_mixer_selem_ask_playback_vol_dB(me, e->min_volume, &min_dB_checked);
+ else
+ r = snd_mixer_selem_ask_capture_vol_dB(me, e->min_volume, &min_dB_checked);
+
+ if (r < 0) {
+ pa_log_warn("Failed to query the dB value for %s at volume level %li", e->alsa_name, e->min_volume);
+ return -1;
+ }
+
+ if (e->direction == PA_ALSA_DIRECTION_OUTPUT)
+ r = snd_mixer_selem_ask_playback_vol_dB(me, e->max_volume, &max_dB_checked);
+ else
+ r = snd_mixer_selem_ask_capture_vol_dB(me, e->max_volume, &max_dB_checked);
+
+ if (r < 0) {
+ pa_log_warn("Failed to query the dB value for %s at volume level %li", e->alsa_name, e->max_volume);
+ return -1;
+ }
+
+ if (min_dB != min_dB_checked || max_dB != max_dB_checked) {
+ pa_log_warn("Your kernel driver is broken: the reported dB range for %s (from %0.2f dB to %0.2f dB) "
+ "doesn't match the dB values at minimum and maximum volume levels: %0.2f dB at level %li, "
+ "%0.2f dB at level %li.",
+ e->alsa_name,
+ min_dB / 100.0, max_dB / 100.0,
+ min_dB_checked / 100.0, e->min_volume, max_dB_checked / 100.0, e->max_volume);
+ return -1;
+ }
+ }
+
if (e->has_dB) {
#ifdef HAVE_VALGRIND_MEMCHECK_H
VALGRIND_MAKE_MEM_DEFINED(&min_dB, sizeof(min_dB));
}
}
+ if (e->volume_limit >= 0) {
+ if (e->volume_limit <= e->min_volume || e->volume_limit > e->max_volume)
+ pa_log_warn("Volume limit for element %s of path %s is invalid: %li isn't within the valid range "
+ "%li-%li. The volume limit is ignored.",
+ e->alsa_name, e->path->name, e->volume_limit, e->min_volume + 1, e->max_volume);
+
+ else {
+ e->max_volume = e->volume_limit;
+
+ if (e->has_dB) {
+ if (e->db_fix) {
+ e->db_fix->max_step = e->max_volume;
+ e->max_dB = ((double) e->db_fix->db_values[e->db_fix->max_step - e->db_fix->min_step]) / 100.0;
+
+ } else {
+ if (e->direction == PA_ALSA_DIRECTION_OUTPUT)
+ r = snd_mixer_selem_ask_playback_vol_dB(me, e->max_volume, &max_dB);
+ else
+ r = snd_mixer_selem_ask_capture_vol_dB(me, e->max_volume, &max_dB);
+
+ if (r < 0) {
+ pa_log_warn("Failed to get dB value of %s: %s", e->alsa_name, pa_alsa_strerror(r));
+ e->has_dB = FALSE;
+ } else
+ e->max_dB = ((double) max_dB) / 100.0;
+ }
+ }
+ }
+ }
+
if (e->direction == PA_ALSA_DIRECTION_OUTPUT)
is_mono = snd_mixer_selem_is_playback_mono(me) > 0;
else
e->n_channels = 1;
if (!e->override_map) {
- for (p = PA_CHANNEL_POSITION_FRONT_LEFT; p < PA_CHANNEL_POSITION_MAX; p++)
+ for (p = PA_CHANNEL_POSITION_FRONT_LEFT; p < PA_CHANNEL_POSITION_MAX; p++) {
+ if (alsa_channel_ids[p] == SND_MIXER_SCHN_UNKNOWN)
+ continue;
+
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;
}
return -1;
}
+ if (e->n_channels > 2) {
+ /* FIXME: In some places code like this is used:
+ *
+ * e->masks[alsa_channel_ids[p]][e->n_channels-1]
+ *
+ * The definition of e->masks is
+ *
+ * pa_channel_position_mask_t masks[SND_MIXER_SCHN_LAST][2];
+ *
+ * Since the array size is fixed at 2, we obviously
+ * don't support elements with more than two
+ * channels... */
+ pa_log_warn("Volume element %s has %u channels. That's too much! I can't handle that!", e->alsa_name, e->n_channels);
+ return -1;
+ }
+
if (!e->override_map) {
for (p = PA_CHANNEL_POSITION_FRONT_LEFT; p < PA_CHANNEL_POSITION_MAX; p++) {
pa_bool_t has_channel;
}
e->merged_mask = 0;
- for (p = PA_CHANNEL_POSITION_FRONT_LEFT; p < PA_CHANNEL_POSITION_MAX; p++)
+ for (p = PA_CHANNEL_POSITION_FRONT_LEFT; p < PA_CHANNEL_POSITION_MAX; p++) {
+ if (alsa_channel_ids[p] == SND_MIXER_SCHN_UNKNOWN)
+ continue;
+
e->merged_mask |= e->masks[alsa_channel_ids[p]][e->n_channels-1];
+ }
}
}
}
e->path = p;
e->alsa_name = pa_xstrdup(section);
e->direction = p->direction;
+ e->volume_limit = -1;
PA_LLIST_INSERT_AFTER(pa_alsa_element, p->elements, p->last_element, e);
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;
+ uint32_t constant;
+
+ if (pa_atou(rvalue, &constant) >= 0) {
+ e->volume_use = PA_ALSA_VOLUME_CONSTANT;
+ e->constant_volume = constant;
+ } else {
+ pa_log("[%s:%u] Volume invalid of '%s'", filename, line, section);
+ return -1;
+ }
}
return 0;
return 0;
}
+static int element_parse_volume_limit(
+ const char *filename,
+ unsigned line,
+ const char *section,
+ const char *lvalue,
+ const char *rvalue,
+ void *data,
+ void *userdata) {
+
+ pa_alsa_path *p = userdata;
+ pa_alsa_element *e;
+ long volume_limit;
+
+ if (!(e = element_get(p, section, TRUE))) {
+ pa_log("[%s:%u] volume-limit makes no sense in '%s'", filename, line, section);
+ return -1;
+ }
+
+ if (pa_atol(rvalue, &volume_limit) < 0 || volume_limit < 0) {
+ pa_log("[%s:%u] Invalid value for volume-limit", filename, line);
+ return -1;
+ }
+
+ e->volume_limit = volume_limit;
+ return 0;
+}
+
static pa_channel_position_mask_t parse_mask(const char *m) {
pa_channel_position_mask_t v;
{ "input", N_("Input") },
{ "input-docking", N_("Docking Station Input") },
{ "input-docking-microphone", N_("Docking Station Microphone") },
- { "input-docking-linein", N_("Docking Station Line-In") },
- { "input-linein", N_("Line-In") },
+ { "input-docking-linein", N_("Docking Station Line In") },
+ { "input-linein", N_("Line In") },
{ "input-microphone", N_("Microphone") },
{ "input-microphone-front", N_("Front Microphone") },
{ "input-microphone-rear", N_("Rear Microphone") },
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-microphone", N_("Microphone") },
{ "analog-input-microphone-front", N_("Front Microphone") },
{ "analog-input-microphone-rear", N_("Rear Microphone") },
- { "analog-input-microphone-dock", N_("Docking Station Microphone") },
+ { "analog-input-microphone-dock", N_("Dock Microphone") },
{ "analog-input-microphone-internal", N_("Internal Microphone") },
- { "analog-input-linein", N_("Analog Line-In") },
- { "analog-input-radio", N_("Analog Radio") },
- { "analog-input-video", N_("Analog Video") },
+ { "analog-input-linein", N_("Line In") },
+ { "analog-input-radio", N_("Radio") },
+ { "analog-input-video", N_("Video") },
{ "analog-output", N_("Analog Output") },
- { "analog-output-headphones", N_("Analog Headphones") },
- { "analog-output-lfe-on-mono", N_("Analog Output (LFE)") },
+ { "analog-output-headphones", N_("Headphones") },
+ { "analog-output-lfe-on-mono", N_("LFE on Separate Mono Output") },
+ { "analog-output-lineout", N_("Line Out") },
{ "analog-output-mono", N_("Analog Mono Output") },
- { "analog-output-speaker", N_("Analog Speakers") },
- { "iec958-stereo-output", N_("Digital Output (IEC958)") },
- { "iec958-passthrough-output", N_("Digital Passthrough (IEC958)") }
+ { "analog-output-speaker", N_("Speakers") },
+ { "hdmi-output", N_("HDMI / DisplayPort") },
+ { "iec958-stereo-output", N_("Digital Output (S/PDIF)") },
+ { "iec958-passthrough-output", N_("Digital Passthrough (S/PDIF)") }
};
pa_alsa_element *e;
return 0;
}
-pa_alsa_path* pa_alsa_path_new(const char *fname, pa_alsa_direction_t direction) {
+static const char *get_default_paths_dir(void) {
+ if (pa_run_from_build_tree())
+ return PA_BUILDDIR "/modules/alsa/mixer/paths/";
+ else
+ return PA_ALSA_PATHS_DIR;
+}
+
+pa_alsa_path* pa_alsa_path_new(const char *paths_dir, const char *fname, pa_alsa_direction_t direction) {
pa_alsa_path *p;
char *fn;
int r;
{ "required-absent", element_parse_required, NULL, NULL },
{ "direction", element_parse_direction, NULL, NULL },
{ "direction-try-other", element_parse_direction_try_other, NULL, NULL },
+ { "volume-limit", element_parse_volume_limit, NULL, NULL },
{ NULL, NULL, NULL, NULL }
};
items[1].data = &p->description;
items[2].data = &p->name;
- fn = pa_maybe_prefix_path(fname,
-#if defined(__linux__) && !defined(__OPTIMIZE__)
- pa_run_from_build_tree() ? PA_BUILDDIR "/modules/alsa/mixer/paths/" :
-#endif
- PA_ALSA_PATHS_DIR);
+ if (!paths_dir)
+ paths_dir = get_default_paths_dir();
+
+ fn = pa_maybe_prefix_path(fname, paths_dir);
r = pa_config_parse(fn, NULL, items, p);
pa_xfree(fn);
return NULL;
}
-pa_alsa_path* pa_alsa_path_synthesize(const char*element, pa_alsa_direction_t direction) {
+pa_alsa_path *pa_alsa_path_synthesize(const char *element, pa_alsa_direction_t direction) {
pa_alsa_path *p;
pa_alsa_element *e;
e->path = p;
e->alsa_name = pa_xstrdup(element);
e->direction = direction;
+ e->volume_limit = -1;
e->switch_use = PA_ALSA_SWITCH_MUTE;
e->volume_use = PA_ALSA_VOLUME_MERGE;
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->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)
+ ? pa_sprintf_malloc("%s / %s", template->description, o->description)
: (template->description[0]
? pa_xstrdup(template->description)
: pa_xstrdup(o->description));
pa_alsa_element *e;
double min_dB[PA_CHANNEL_POSITION_MAX], max_dB[PA_CHANNEL_POSITION_MAX];
pa_channel_position_t t;
+ pa_channel_position_mask_t path_volume_channels = 0;
pa_assert(p);
pa_assert(m);
if (p->probed)
- return 0;
+ return p->supported ? 0 : -1;
+ p->probed = TRUE;
pa_zero(min_dB);
pa_zero(max_dB);
if (PA_CHANNEL_POSITION_MASK(t) & e->merged_mask) {
min_dB[t] = e->min_dB;
max_dB[t] = e->max_dB;
+ path_volume_channels |= PA_CHANNEL_POSITION_MASK(t);
}
p->has_dB = TRUE;
if (PA_CHANNEL_POSITION_MASK(t) & e->merged_mask) {
min_dB[t] += e->min_dB;
max_dB[t] += e->max_dB;
+ path_volume_channels |= PA_CHANNEL_POSITION_MASK(t);
}
} else {
/* Hmm, there's another element before us
path_create_settings(p);
p->supported = TRUE;
- p->probed = TRUE;
p->min_dB = INFINITY;
p->max_dB = -INFINITY;
for (t = 0; t < PA_CHANNEL_POSITION_MAX; t++) {
- if (p->min_dB > min_dB[t])
- p->min_dB = min_dB[t];
+ if (path_volume_channels & PA_CHANNEL_POSITION_MASK(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];
+ if (p->max_dB < max_dB[t])
+ p->max_dB = max_dB[t];
+ }
}
return 0;
pa_alsa_option *o;
pa_assert(e);
- pa_log_debug("Element %s, direction=%i, switch=%i, volume=%i, enumeration=%i, required=%i, required_any=%i, required_absent=%i, mask=0x%llx, n_channels=%u, override_map=%s",
+ pa_log_debug("Element %s, direction=%i, switch=%i, volume=%i, volume_limit=%li, enumeration=%i, required=%i, required_any=%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->volume_limit,
e->enumeration_use,
e->required,
e->required_any,
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;
+ void *state;
pa_assert(ps);
pa_assert(m);
pa_assert(cb);
- PA_LLIST_FOREACH(p, ps->paths)
+ PA_HASHMAP_FOREACH(p, ps->paths, state)
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 *pa_alsa_path_set_new(pa_alsa_mapping *m, pa_alsa_direction_t direction, const char *paths_dir) {
pa_alsa_path_set *ps;
char **pn = NULL, **en = NULL, **ie;
pa_alsa_decibel_fix *db_fix;
- void *state;
+ void *state, *state2;
+ pa_hashmap *cache;
pa_assert(m);
pa_assert(m->profile_set);
ps = pa_xnew0(pa_alsa_path_set, 1);
ps->direction = direction;
+ ps->paths = pa_hashmap_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func);
- if (direction == PA_ALSA_DIRECTION_OUTPUT)
+ if (direction == PA_ALSA_DIRECTION_OUTPUT) {
pn = m->output_path_names;
- else if (direction == PA_ALSA_DIRECTION_INPUT)
+ cache = m->profile_set->output_paths;
+ }
+ else if (direction == PA_ALSA_DIRECTION_INPUT) {
pn = m->input_path_names;
+ cache = m->profile_set->input_paths;
+ }
if (pn) {
char **in;
for (in = pn; *in; in++) {
- pa_alsa_path *p;
+ pa_alsa_path *p = NULL;
pa_bool_t duplicate = FALSE;
- char **kn, *fn;
+ char **kn;
- for (kn = pn; kn != in; kn++)
+ 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;
- PA_LLIST_INSERT_AFTER(pa_alsa_path, ps->paths, ps->last_path, p);
- ps->last_path = p;
+ p = pa_hashmap_get(cache, *in);
+ if (!p) {
+ char *fn = pa_sprintf_malloc("%s.conf", *in);
+ p = pa_alsa_path_new(paths_dir, fn, direction);
+ pa_xfree(fn);
+ if (p)
+ pa_hashmap_put(cache, *in, p);
}
+ pa_assert(pa_hashmap_get(cache, *in) == p);
+ if (p)
+ pa_hashmap_put(ps->paths, p, p);
- pa_xfree(fn);
}
goto finish;
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++) {
e->alsa_name = pa_xstrdup(*je);
e->direction = direction;
e->required_absent = PA_ALSA_REQUIRED_ANY;
+ e->volume_limit = -1;
PA_LLIST_INSERT_AFTER(pa_alsa_element, p->elements, p->last_element, e);
p->last_element = e;
}
- PA_LLIST_INSERT_AFTER(pa_alsa_path, ps->paths, ps->last_path, p);
- ps->last_path = p;
+ pa_hashmap_put(ps->paths, *ie, p);
}
finish:
PA_HASHMAP_FOREACH(db_fix, m->profile_set->decibel_fixes, state) {
pa_alsa_path *p;
- PA_LLIST_FOREACH(p, ps->paths) {
+ PA_HASHMAP_FOREACH(p, ps->paths, state2) {
pa_alsa_element *e;
PA_LLIST_FOREACH(e, p->elements) {
void pa_alsa_path_set_dump(pa_alsa_path_set *ps) {
pa_alsa_path *p;
+ void *state;
pa_assert(ps);
- pa_log_debug("Path Set %p, direction=%i, probed=%s",
+ pa_log_debug("Path Set %p, direction=%i",
(void*) ps,
- ps->direction,
- pa_yes_no(ps->probed));
+ ps->direction);
- PA_LLIST_FOREACH(p, ps->paths)
+ PA_HASHMAP_FOREACH(p, ps->paths, state)
pa_alsa_path_dump(p);
}
-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);
- /* 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. */
+static pa_bool_t options_have_option(pa_alsa_option *options, const char *alsa_name) {
+ pa_alsa_option *o;
+
+ pa_assert(options);
+ pa_assert(alsa_name);
+
+ PA_LLIST_FOREACH(o, options) {
+ if (pa_streq(o->alsa_name, alsa_name))
+ return TRUE;
+ }
+ return FALSE;
+}
- PA_LLIST_FOREACH(p, ps->paths) {
- pa_assert(p->probed);
+static pa_bool_t enumeration_is_subset(pa_alsa_option *a_options, pa_alsa_option *b_options) {
+ pa_alsa_option *oa, *ob;
- if (!p->has_volume)
- has_volume = FALSE;
- else if (!p->has_dB)
- has_dB = FALSE;
+ if (!a_options) return TRUE;
+ if (!b_options) return FALSE;
- if (!p->has_mute)
- has_mute = FALSE;
+ /* If there is an option A offers that B does not, then A is not a subset of B. */
+ PA_LLIST_FOREACH(oa, a_options) {
+ pa_bool_t found = FALSE;
+ PA_LLIST_FOREACH(ob, b_options) {
+ if (pa_streq(oa->alsa_name, ob->alsa_name)) {
+ found = TRUE;
+ break;
+ }
+ }
+ if (!found)
+ return FALSE;
}
+ return TRUE;
+}
+
+/**
+ * Compares two elements to see if a is a subset of b
+ */
+static pa_bool_t element_is_subset(pa_alsa_element *a, pa_alsa_element *b, snd_mixer_t *m) {
+ pa_assert(a);
+ pa_assert(b);
+ pa_assert(m);
+
+ /* General rules:
+ * Every state is a subset of itself (with caveats for volume_limits and options)
+ * IGNORE is a subset of every other state */
- if (!has_volume || !has_dB || !has_mute) {
+ /* Check the volume_use */
+ if (a->volume_use != PA_ALSA_VOLUME_IGNORE) {
- 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.");
+ /* "Constant" is subset of "Constant" only when their constant values are equal */
+ if (a->volume_use == PA_ALSA_VOLUME_CONSTANT && b->volume_use == PA_ALSA_VOLUME_CONSTANT && a->constant_volume != b->constant_volume)
+ return FALSE;
- if (!has_mute)
- pa_log_debug("Some paths of the device lack hardware mute control, disabling hardware control altogether.");
+ /* Different volume uses when b is not "Merge" means we are definitely not a subset */
+ if (a->volume_use != b->volume_use && b->volume_use != PA_ALSA_VOLUME_MERGE)
+ return FALSE;
- PA_LLIST_FOREACH(p, ps->paths) {
- if (!has_volume)
- p->has_volume = FALSE;
- else if (!has_dB)
- p->has_dB = FALSE;
+ /* "Constant" is a subset of "Merge", if there is not a "volume-limit" in "Merge" below the actual constant.
+ * "Zero" and "Off" are just special cases of "Constant" when comparing to "Merge"
+ * "Merge" with a "volume-limit" is a subset of "Merge" without a "volume-limit" or with a higher "volume-limit" */
+ if (b->volume_use == PA_ALSA_VOLUME_MERGE && b->volume_limit >= 0) {
+ long a_limit;
- if (!has_mute)
- p->has_mute = FALSE;
+ if (a->volume_use == PA_ALSA_VOLUME_CONSTANT)
+ a_limit = a->constant_volume;
+ else if (a->volume_use == PA_ALSA_VOLUME_ZERO) {
+ long dB = 0;
+
+ if (a->db_fix) {
+ int rounding = (a->direction == PA_ALSA_DIRECTION_OUTPUT ? +1 : -1);
+ a_limit = decibel_fix_get_step(a->db_fix, &dB, rounding);
+ } else {
+ snd_mixer_selem_id_t *sid;
+ snd_mixer_elem_t *me;
+
+ SELEM_INIT(sid, a->alsa_name);
+ if (!(me = snd_mixer_find_selem(m, sid))) {
+ pa_log_warn("Element %s seems to have disappeared.", a->alsa_name);
+ return FALSE;
+ }
+
+ if (a->direction == PA_ALSA_DIRECTION_OUTPUT) {
+ if (snd_mixer_selem_ask_playback_dB_vol(me, dB, +1, &a_limit) < 0)
+ return FALSE;
+ } else {
+ if (snd_mixer_selem_ask_capture_dB_vol(me, dB, -1, &a_limit) < 0)
+ return FALSE;
+ }
+ }
+ } else if (a->volume_use == PA_ALSA_VOLUME_OFF)
+ a_limit = a->min_volume;
+ else if (a->volume_use == PA_ALSA_VOLUME_MERGE)
+ a_limit = a->volume_limit;
+ else
+ /* This should never be reached */
+ pa_assert(FALSE);
+
+ if (a_limit > b->volume_limit)
+ return FALSE;
}
}
+
+ if (a->switch_use != PA_ALSA_SWITCH_IGNORE) {
+ /* "On" is a subset of "Mute".
+ * "Off" is a subset of "Mute".
+ * "On" is a subset of "Select", if there is an "Option:On" in B.
+ * "Off" is a subset of "Select", if there is an "Option:Off" in B.
+ * "Select" is a subset of "Select", if they have the same options (is this always true?). */
+
+ if (a->switch_use != b->switch_use) {
+
+ if (a->switch_use == PA_ALSA_SWITCH_SELECT || a->switch_use == PA_ALSA_SWITCH_MUTE
+ || b->switch_use == PA_ALSA_SWITCH_OFF || b->switch_use == PA_ALSA_SWITCH_ON)
+ return FALSE;
+
+ if (b->switch_use == PA_ALSA_SWITCH_SELECT) {
+ if (a->switch_use == PA_ALSA_SWITCH_ON) {
+ if (!options_have_option(b->options, "on"))
+ return FALSE;
+ } else if (a->switch_use == PA_ALSA_SWITCH_OFF) {
+ if (!options_have_option(b->options, "off"))
+ return FALSE;
+ }
+ }
+ } else if (a->switch_use == PA_ALSA_SWITCH_SELECT) {
+ if (!enumeration_is_subset(a->options, b->options))
+ return FALSE;
+ }
+ }
+
+ if (a->enumeration_use != PA_ALSA_ENUMERATION_IGNORE) {
+ if (b->enumeration_use == PA_ALSA_ENUMERATION_IGNORE)
+ return FALSE;
+ if (!enumeration_is_subset(a->options, b->options))
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static void path_set_condense(pa_alsa_path_set *ps, snd_mixer_t *m) {
+ pa_alsa_path *p;
+ void *state;
+
+ pa_assert(ps);
+ pa_assert(m);
+
+ /* If we only have one path, then don't bother */
+ if (pa_hashmap_size(ps->paths) < 2)
+ return;
+
+ PA_HASHMAP_FOREACH(p, ps->paths, state) {
+ pa_alsa_path *p2;
+ void *state2;
+
+ PA_HASHMAP_FOREACH(p2, ps->paths, state2) {
+ pa_alsa_element *ea, *eb;
+ pa_bool_t is_subset = TRUE;
+
+ if (p == p2)
+ continue;
+
+ /* Compare the elements of each set... */
+ pa_assert_se(ea = p->elements);
+ pa_assert_se(eb = p2->elements);
+
+ while (is_subset) {
+ if (pa_streq(ea->alsa_name, eb->alsa_name)) {
+ if (element_is_subset(ea, eb, m)) {
+ ea = ea->next;
+ eb = eb->next;
+ if ((ea && !eb) || (!ea && eb))
+ is_subset = FALSE;
+ else if (!ea && !eb)
+ break;
+ } else
+ is_subset = FALSE;
+
+ } else
+ is_subset = FALSE;
+ }
+
+ if (is_subset) {
+ pa_log_debug("Removing path '%s' as it is a subset of '%s'.", p->name, p2->name);
+ pa_hashmap_remove(ps->paths, p);
+ break;
+ }
+ }
+ }
+}
+
+static pa_alsa_path* path_set_find_path_by_name(pa_alsa_path_set *ps, const char* name, pa_alsa_path *ignore)
+{
+ pa_alsa_path* p;
+ void *state;
+
+ PA_HASHMAP_FOREACH(p, ps->paths, state)
+ if (p != ignore && pa_streq(p->name, name))
+ return p;
+ return NULL;
}
static void path_set_make_paths_unique(pa_alsa_path_set *ps) {
pa_alsa_path *p, *q;
+ void *state, *state2;
- PA_LLIST_FOREACH(p, ps->paths) {
+ PA_HASHMAP_FOREACH(p, ps->paths, state) {
unsigned i;
char *m;
- for (q = p->next; q; q = q->next)
- if (pa_streq(q->name, p->name))
- break;
+ q = path_set_find_path_by_name(ps, p->name, p);
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) {
+ i = 1;
+ PA_HASHMAP_FOREACH(q, ps->paths, state2) {
char *nn, *nd;
if (!pa_streq(q->name, 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;
-
- pa_assert(ps);
-
- if (ps->probed)
- return;
-
- 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);
- path_set_make_paths_unique(ps);
- ps->probed = TRUE;
-}
-
static void mapping_free(pa_alsa_mapping *m) {
pa_assert(m);
pa_xstrfreev(m->output_path_names);
pa_xstrfreev(m->input_element);
pa_xstrfreev(m->output_element);
+ if (m->input_path_set)
+ pa_alsa_path_set_free(m->input_path_set);
+ if (m->output_path_set)
+ pa_alsa_path_set_free(m->output_path_set);
pa_assert(!m->input_pcm);
pa_assert(!m->output_pcm);
void pa_alsa_profile_set_free(pa_alsa_profile_set *ps) {
pa_assert(ps);
+ if (ps->input_paths) {
+ pa_alsa_path *p;
+
+ while ((p = pa_hashmap_steal_first(ps->input_paths)))
+ pa_alsa_path_free(p);
+
+ pa_hashmap_free(ps->input_paths, NULL, NULL);
+ }
+
+ if (ps->output_paths) {
+ pa_alsa_path *p;
+
+ while ((p = pa_hashmap_steal_first(ps->output_paths)))
+ pa_alsa_path_free(p);
+
+ pa_hashmap_free(ps->output_paths, NULL, NULL);
+ }
+
if (ps->profiles) {
pa_alsa_profile *p;
return -1;
}
+static void mapping_paths_probe(pa_alsa_mapping *m, pa_alsa_profile *profile,
+ pa_alsa_direction_t direction) {
+
+ pa_alsa_path *p;
+ void *state;
+ snd_pcm_t *pcm_handle;
+ pa_alsa_path_set *ps;
+ snd_mixer_t *mixer_handle;
+
+ if (direction == PA_ALSA_DIRECTION_OUTPUT) {
+ if (m->output_path_set)
+ return; /* Already probed */
+ m->output_path_set = ps = pa_alsa_path_set_new(m, direction, NULL); /* FIXME: Handle paths_dir */
+ pcm_handle = m->output_pcm;
+ } else {
+ if (m->input_path_set)
+ return; /* Already probed */
+ m->input_path_set = ps = pa_alsa_path_set_new(m, direction, NULL); /* FIXME: Handle paths_dir */
+ pcm_handle = m->input_pcm;
+ }
+
+ if (!ps)
+ return; /* No paths */
+
+ pa_assert(pcm_handle);
+
+ mixer_handle = pa_alsa_open_mixer_for_pcm(pcm_handle, NULL);
+ if (!mixer_handle) {
+ /* Cannot open mixer, remove all entries */
+ while (pa_hashmap_steal_first(ps->paths));
+ return;
+ }
+
+
+ PA_HASHMAP_FOREACH(p, ps->paths, state) {
+ if (pa_alsa_path_probe(p, mixer_handle, m->profile_set->ignore_dB) < 0) {
+ pa_hashmap_remove(ps->paths, p);
+ }
+ }
+
+ path_set_condense(ps, mixer_handle);
+ path_set_make_paths_unique(ps);
+
+ if (mixer_handle)
+ snd_mixer_close(mixer_handle);
+
+ pa_log_debug("Available mixer paths (after tidying):");
+ pa_alsa_path_set_dump(ps);
+}
+
static int mapping_verify(pa_alsa_mapping *m, const pa_channel_map *bonus) {
static const struct description_map well_known_descriptions[] = {
{ "iec958-passthrough", N_("Digital Passthrough (IEC958)") },
{ "iec958-ac3-surround-40", N_("Digital Surround 4.0 (IEC958/AC3)") },
{ "iec958-ac3-surround-51", N_("Digital Surround 5.1 (IEC958/AC3)") },
- { "hdmi-stereo", N_("Digital Stereo (HDMI)") }
+ { "hdmi-stereo", N_("Digital Stereo (HDMI)") },
+ { "hdmi-surround-51", N_("Digital Surround 5.1 (HDMI)") }
};
pa_assert(m);
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);
+ pa_log("Profile '%s' refers to nonexistent mapping '%s'.", p->name, *name);
return -1;
}
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);
+ pa_log("Profile '%s' refers to nonexistent mapping '%s'.", p->name, *name);
return -1;
}
if (db_fix->db_values) {
pa_strbuf *buf;
- long i;
- long max_i = db_fix->max_step - db_fix->min_step;
+ unsigned long i, nsteps;
- buf = pa_strbuf_new();
- pa_strbuf_printf(buf, "[%li]:%0.2f", db_fix->min_step, db_fix->db_values[0] / 100.0);
+ pa_assert(db_fix->min_step <= db_fix->max_step);
+ nsteps = db_fix->max_step - db_fix->min_step + 1;
- for (i = 1; i <= max_i; ++i)
- pa_strbuf_printf(buf, " [%li]:%0.2f", i + db_fix->min_step, db_fix->db_values[i] / 100.0);
+ buf = pa_strbuf_new();
+ for (i = 0; i < nsteps; ++i)
+ pa_strbuf_printf(buf, "[%li]:%0.2f ", i + db_fix->min_step, db_fix->db_values[i] / 100.0);
db_values = pa_strbuf_tostring_free(buf);
}
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);
ps->decibel_fixes = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
+ ps->input_paths = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
+ ps->output_paths = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
items[0].data = &ps->auto_profiles;
fname = "default.conf";
fn = pa_maybe_prefix_path(fname,
-#if defined(__linux__) && !defined(__OPTIMIZE__)
pa_run_from_build_tree() ? PA_BUILDDIR "/modules/alsa/mixer/profile-sets/" :
-#endif
PA_ALSA_PROFILE_SETS_DIR);
r = pa_config_parse(fn, NULL, items, ps);
return NULL;
}
+static void profile_finalize_probing(pa_alsa_profile *to_be_finalized, pa_alsa_profile *next) {
+ pa_alsa_mapping *m;
+ uint32_t idx;
+
+ if (!to_be_finalized)
+ return;
+
+ if (to_be_finalized->output_mappings)
+ PA_IDXSET_FOREACH(m, to_be_finalized->output_mappings, idx) {
+
+ if (!m->output_pcm)
+ continue;
+
+ if (to_be_finalized->supported)
+ m->supported++;
+
+ /* If this mapping is also in the next profile, we won't close the
+ * pcm handle here, because it would get immediately reopened
+ * anyway. */
+ if (next && next->output_mappings && pa_idxset_get_by_data(next->output_mappings, m, NULL))
+ continue;
+
+ snd_pcm_close(m->output_pcm);
+ m->output_pcm = NULL;
+ }
+
+ if (to_be_finalized->input_mappings)
+ PA_IDXSET_FOREACH(m, to_be_finalized->input_mappings, idx) {
+
+ if (!m->input_pcm)
+ continue;
+
+ if (to_be_finalized->supported)
+ m->supported++;
+
+ /* If this mapping is also in the next profile, we won't close the
+ * pcm handle here, because it would get immediately reopened
+ * anyway. */
+ if (next && next->input_mappings && pa_idxset_get_by_data(next->input_mappings, m, NULL))
+ continue;
+
+ snd_pcm_close(m->input_pcm);
+ m->input_pcm = NULL;
+ }
+}
+
+static snd_pcm_t* mapping_open_pcm(pa_alsa_mapping *m,
+ const pa_sample_spec *ss,
+ const char *dev_id,
+ int mode,
+ unsigned default_n_fragments,
+ unsigned default_fragment_size_msec) {
+
+ pa_sample_spec try_ss = *ss;
+ pa_channel_map try_map = m->channel_map;
+ snd_pcm_uframes_t try_period_size, try_buffer_size;
+
+ try_ss.channels = try_map.channels;
+
+ try_period_size =
+ pa_usec_to_bytes(default_fragment_size_msec * PA_USEC_PER_MSEC, &try_ss) /
+ pa_frame_size(&try_ss);
+ try_buffer_size = default_n_fragments * try_period_size;
+
+ return pa_alsa_open_by_template(
+ m->device_strings, dev_id, NULL, &try_ss,
+ &try_map, mode, &try_period_size,
+ &try_buffer_size, 0, NULL, NULL, TRUE);
+}
+
void pa_alsa_profile_set_probe(
pa_alsa_profile_set *ps,
const char *dev_id,
return;
PA_HASHMAP_FOREACH(p, ps->profiles, state) {
- pa_sample_spec try_ss;
- pa_channel_map try_map;
- snd_pcm_uframes_t try_period_size, try_buffer_size;
uint32_t idx;
- /* Is this already marked that it is supported? (i.e. from the config file) */
- if (p->supported)
- continue;
-
- pa_log_debug("Looking at profile %s", p->name);
+ /* Skip if this is already marked that it is supported (i.e. from the config file) */
+ if (!p->supported) {
- /* Close PCMs from the last iteration we don't need anymore */
- if (last && last->output_mappings)
- PA_IDXSET_FOREACH(m, last->output_mappings, idx) {
+ pa_log_debug("Looking at profile %s", p->name);
+ profile_finalize_probing(last, p);
+ p->supported = TRUE;
- if (!m->output_pcm)
- break;
+ /* Check if we can open all new ones */
+ if (p->output_mappings)
+ PA_IDXSET_FOREACH(m, p->output_mappings, idx) {
- if (last->supported)
- m->supported++;
+ if (m->output_pcm)
+ continue;
- if (!p->output_mappings || !pa_idxset_get_by_data(p->output_mappings, m, NULL)) {
- snd_pcm_close(m->output_pcm);
- m->output_pcm = NULL;
+ pa_log_debug("Checking for playback on %s (%s)", m->description, m->name);
+ if (!(m->output_pcm = mapping_open_pcm(m, ss, dev_id,
+ SND_PCM_STREAM_PLAYBACK,
+ default_n_fragments,
+ default_fragment_size_msec))) {
+ p->supported = FALSE;
+ break;
+ }
}
- }
- if (last && last->input_mappings)
- PA_IDXSET_FOREACH(m, last->input_mappings, idx) {
-
- if (!m->input_pcm)
- break;
+ if (p->input_mappings && p->supported)
+ PA_IDXSET_FOREACH(m, p->input_mappings, idx) {
- if (last->supported)
- m->supported++;
+ if (m->input_pcm)
+ continue;
- if (!p->input_mappings || !pa_idxset_get_by_data(p->input_mappings, m, NULL)) {
- snd_pcm_close(m->input_pcm);
- m->input_pcm = NULL;
+ pa_log_debug("Checking for recording on %s (%s)", m->description, m->name);
+ if (!(m->input_pcm = mapping_open_pcm(m, ss, dev_id,
+ SND_PCM_STREAM_CAPTURE,
+ default_n_fragments,
+ default_fragment_size_msec))) {
+ p->supported = FALSE;
+ break;
+ }
}
- }
- p->supported = TRUE;
+ last = p;
- /* Check if we can open all new ones */
- if (p->output_mappings)
- PA_IDXSET_FOREACH(m, p->output_mappings, idx) {
+ if (!p->supported)
+ continue;
+ }
- if (m->output_pcm)
- continue;
+ pa_log_debug("Profile %s supported.", p->name);
- pa_log_debug("Checking for playback on %s (%s)", m->description, m->name);
- try_map = m->channel_map;
- try_ss = *ss;
- try_ss.channels = try_map.channels;
-
- try_period_size =
- pa_usec_to_bytes(default_fragment_size_msec * PA_USEC_PER_MSEC, &try_ss) /
- pa_frame_size(&try_ss);
- try_buffer_size = default_n_fragments * try_period_size;
-
- if (!(m ->output_pcm = pa_alsa_open_by_template(
- m->device_strings,
- dev_id,
- NULL,
- &try_ss, &try_map,
- SND_PCM_STREAM_PLAYBACK,
- &try_period_size, &try_buffer_size, 0, NULL, NULL,
- TRUE))) {
- p->supported = FALSE;
- break;
- }
- }
-
- if (p->input_mappings && p->supported)
- PA_IDXSET_FOREACH(m, p->input_mappings, idx) {
+ if (p->output_mappings)
+ PA_IDXSET_FOREACH(m, p->output_mappings, idx)
+ if (m->output_pcm)
+ mapping_paths_probe(m, p, PA_ALSA_DIRECTION_OUTPUT);
+ if (p->input_mappings)
+ 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_map = m->channel_map;
- try_ss = *ss;
- try_ss.channels = try_map.channels;
-
- try_period_size =
- pa_usec_to_bytes(default_fragment_size_msec*PA_USEC_PER_MSEC, &try_ss) /
- pa_frame_size(&try_ss);
- try_buffer_size = default_n_fragments * try_period_size;
-
- if (!(m ->input_pcm = pa_alsa_open_by_template(
- m->device_strings,
- dev_id,
- NULL,
- &try_ss, &try_map,
- SND_PCM_STREAM_CAPTURE,
- &try_period_size, &try_buffer_size, 0, NULL, NULL,
- TRUE))) {
- p->supported = FALSE;
- break;
- }
- }
-
- last = p;
-
- if (p->supported)
- pa_log_debug("Profile %s supported.", p->name);
+ mapping_paths_probe(m, p, PA_ALSA_DIRECTION_INPUT);
}
/* 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;
- }
- }
+ profile_finalize_probing(last, NULL);
PA_HASHMAP_FOREACH(p, ps->profiles, state)
if (!p->supported) {
pa_alsa_decibel_fix_dump(db_fix);
}
-void pa_alsa_add_ports(pa_hashmap **p, pa_alsa_path_set *ps) {
- pa_alsa_path *path;
+static pa_device_port* device_port_alsa_init(pa_hashmap *ports,
+ const char* name,
+ const char* description,
+ pa_alsa_path *path,
+ pa_alsa_setting *setting,
+ pa_card_profile *cp,
+ pa_hashmap *extra,
+ pa_core *core) {
- pa_assert(p);
- pa_assert(!*p);
- pa_assert(ps);
+ pa_device_port * p = pa_hashmap_get(ports, name);
+ if (!p) {
+ pa_alsa_port_data *data;
- /* if there is no path, we don't want a port list */
- if (!ps->paths)
- return;
+ p = pa_device_port_new(core, name, description, sizeof(pa_alsa_port_data));
+ pa_assert(p);
+ pa_hashmap_put(ports, name, p);
+ p->profiles = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
- if (!ps->paths->next){
- pa_alsa_setting *s;
+ data = PA_DEVICE_PORT_DATA(p);
+ data->path = path;
+ data->setting = setting;
+ }
- /* 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;
+ p->is_input |= path->direction == PA_ALSA_DIRECTION_ANY || path->direction == PA_ALSA_DIRECTION_INPUT;
+ p->is_output |= path->direction == PA_ALSA_DIRECTION_ANY || path->direction == PA_ALSA_DIRECTION_OUTPUT;
- /* 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);
+ if (cp)
+ pa_hashmap_put(p->profiles, cp->name, cp);
- PA_LLIST_FOREACH(s, ps->paths->settings) {
- pa_device_port *port;
- pa_alsa_port_data *data;
+ if (extra) {
+ pa_hashmap_put(extra, name, p);
+ pa_device_port_ref(p);
+ }
- port = pa_device_port_new(s->name, s->description, sizeof(pa_alsa_port_data));
- port->priority = s->priority;
+ return p;
+}
- data = PA_DEVICE_PORT_DATA(port);
- data->path = ps->paths;
- data->setting = s;
+void pa_alsa_path_set_add_ports(
+ pa_alsa_path_set *ps,
+ pa_card_profile *cp,
+ pa_hashmap *ports,
+ pa_hashmap *extra,
+ pa_core *core) {
- pa_hashmap_put(*p, port->name, port);
- }
+ pa_alsa_path *path;
+ void *state;
- } else {
+ pa_assert(ports);
- /* 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);
+ if (!ps)
+ return;
- PA_LLIST_FOREACH(path, ps->paths) {
+ PA_HASHMAP_FOREACH(path, ps->paths, state) {
+ if (!path->settings || !path->settings->next) {
+ /* If there is no or just one setting we only need a
+ * single entry */
+ pa_device_port *port = device_port_alsa_init(ports, path->name,
+ path->description, path, path->settings, cp, extra, core);
+ port->priority = path->priority * 100;
- if (!path->settings || !path->settings->next) {
+ } else {
+ pa_alsa_setting *s;
+ PA_LLIST_FOREACH(s, path->settings) {
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));
- port->priority = path->priority * 100;
+ char *n, *d;
+ n = pa_sprintf_malloc("%s;%s", path->name, s->name);
- 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);
+ if (s->description[0])
+ d = pa_sprintf_malloc("%s / %s", path->description, s->description);
+ else
+ d = pa_xstrdup(path->description);
- if (s->description[0])
- d = pa_sprintf_malloc(_("%s / %s"), path->description, s->description);
- else
- d = pa_xstrdup(path->description);
+ port = device_port_alsa_init(ports, n, d, path, s, cp, extra, core);
+ port->priority = path->priority * 100 + s->priority;
- 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);
+ }
+ }
+ }
+}
- pa_xfree(n);
- pa_xfree(d);
+void pa_alsa_add_ports(pa_hashmap **p, pa_alsa_path_set *ps, pa_card *card) {
- data = PA_DEVICE_PORT_DATA(port);
- data->path = path;
- data->setting = s;
+ pa_assert(p);
+ pa_assert(!*p);
+ pa_assert(ps);
- pa_hashmap_put(*p, port->name, port);
- }
- }
- }
+ if (ps->paths && pa_hashmap_size(ps->paths) > 0) {
+ pa_assert(card);
+ *p = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
+ pa_alsa_path_set_add_ports(ps, NULL, card->ports, *p, card->core);
}
- pa_log_debug("Added %u ports", pa_hashmap_size(*p));
+ pa_log_debug("Added %u ports", *p ? pa_hashmap_size(*p) : 0);
}