135 lines
5.0 KiB
Diff
135 lines
5.0 KiB
Diff
|
From d7dbd0cbe3191661c02ac89d108b36c79474de3c Mon Sep 17 00:00:00 2001
|
||
|
From: Jaroslav Kysela <perex@perex.cz>
|
||
|
Date: Sun, 8 Dec 2019 23:17:32 +0100
|
||
|
Subject: [PATCH] alsa-mixer: improve check for the empty path set for
|
||
|
sink/source
|
||
|
|
||
|
The unused mixer instances are created without this code.
|
||
|
|
||
|
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
|
||
|
---
|
||
|
src/modules/alsa/alsa-mixer.c | 6 ++++++
|
||
|
src/modules/alsa/alsa-mixer.h | 1 +
|
||
|
src/modules/alsa/alsa-sink.c | 19 +++++++++++++------
|
||
|
src/modules/alsa/alsa-source.c | 9 ++++++---
|
||
|
4 files changed, 26 insertions(+), 9 deletions(-)
|
||
|
|
||
|
diff --git a/src/modules/alsa/alsa-mixer.c b/src/modules/alsa/alsa-mixer.c
|
||
|
index a3c998b654e9..d184aec7aee7 100644
|
||
|
--- a/src/modules/alsa/alsa-mixer.c
|
||
|
+++ b/src/modules/alsa/alsa-mixer.c
|
||
|
@@ -741,6 +741,12 @@ void pa_alsa_path_set_free(pa_alsa_path_set *ps) {
|
||
|
pa_xfree(ps);
|
||
|
}
|
||
|
|
||
|
+int pa_alsa_path_set_is_empty(pa_alsa_path_set *ps) {
|
||
|
+ if (ps && !pa_hashmap_isempty(ps->paths))
|
||
|
+ return 0;
|
||
|
+ return 1;
|
||
|
+}
|
||
|
+
|
||
|
static long to_alsa_dB(pa_volume_t v) {
|
||
|
return lround(pa_sw_volume_to_dB(v) * 100.0);
|
||
|
}
|
||
|
diff --git a/src/modules/alsa/alsa-mixer.h b/src/modules/alsa/alsa-mixer.h
|
||
|
index d740a78c8dce..df739cc2e0f3 100644
|
||
|
--- a/src/modules/alsa/alsa-mixer.h
|
||
|
+++ b/src/modules/alsa/alsa-mixer.h
|
||
|
@@ -272,6 +272,7 @@ pa_alsa_path_set *pa_alsa_path_set_new(pa_alsa_mapping *m, pa_alsa_direction_t d
|
||
|
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);
|
||
|
+int pa_alsa_path_set_is_empty(pa_alsa_path_set *s);
|
||
|
|
||
|
struct pa_alsa_mapping {
|
||
|
pa_alsa_profile_set *profile_set;
|
||
|
diff --git a/src/modules/alsa/alsa-sink.c b/src/modules/alsa/alsa-sink.c
|
||
|
index 363b4be2fa25..042d4dfd9c89 100644
|
||
|
--- a/src/modules/alsa/alsa-sink.c
|
||
|
+++ b/src/modules/alsa/alsa-sink.c
|
||
|
@@ -1651,7 +1651,6 @@ static int sink_set_port_ucm_cb(pa_sink *s, pa_device_port *p) {
|
||
|
|
||
|
pa_assert(u);
|
||
|
pa_assert(p);
|
||
|
- pa_assert(u->mixer_handle);
|
||
|
pa_assert(u->ucm_context);
|
||
|
|
||
|
data = PA_DEVICE_PORT_DATA(p);
|
||
|
@@ -2089,6 +2088,9 @@ static void find_mixer(struct userdata *u, pa_alsa_mapping *mapping, const char
|
||
|
if (!mapping && !element)
|
||
|
return;
|
||
|
|
||
|
+ if (!element && mapping && pa_alsa_path_set_is_empty(mapping->output_path_set))
|
||
|
+ return;
|
||
|
+
|
||
|
u->mixers = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func,
|
||
|
NULL, (pa_free_cb_t) pa_alsa_mixer_free);
|
||
|
|
||
|
@@ -2113,8 +2115,9 @@ static void find_mixer(struct userdata *u, pa_alsa_mapping *mapping, const char
|
||
|
|
||
|
pa_log_debug("Probed mixer path %s:", u->mixer_path->name);
|
||
|
pa_alsa_path_dump(u->mixer_path);
|
||
|
- } else if (!(u->mixer_path_set = mapping->output_path_set))
|
||
|
- goto fail;
|
||
|
+ } else {
|
||
|
+ u->mixer_path_set = mapping->output_path_set;
|
||
|
+ }
|
||
|
|
||
|
return;
|
||
|
|
||
|
@@ -2559,10 +2562,14 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca
|
||
|
goto fail;
|
||
|
}
|
||
|
|
||
|
- if (u->ucm_context)
|
||
|
+ if (u->ucm_context) {
|
||
|
pa_alsa_ucm_add_ports(&data.ports, data.proplist, u->ucm_context, true, card, u->pcm_handle, ignore_dB);
|
||
|
- else if (u->mixer_path_set)
|
||
|
- pa_alsa_add_ports(&data, u->mixer_path_set, card);
|
||
|
+ find_mixer(u, mapping, pa_modargs_get_value(ma, "control", NULL), ignore_dB);
|
||
|
+ } else {
|
||
|
+ find_mixer(u, mapping, pa_modargs_get_value(ma, "control", NULL), ignore_dB);
|
||
|
+ if (u->mixer_path_set)
|
||
|
+ pa_alsa_add_ports(&data, u->mixer_path_set, card);
|
||
|
+ }
|
||
|
|
||
|
u->sink = pa_sink_new(m->core, &data, PA_SINK_HARDWARE | PA_SINK_LATENCY | (u->use_tsched ? PA_SINK_DYNAMIC_LATENCY : 0) |
|
||
|
(set_formats ? PA_SINK_SET_FORMATS : 0));
|
||
|
diff --git a/src/modules/alsa/alsa-source.c b/src/modules/alsa/alsa-source.c
|
||
|
index b46e845cc5a7..104de4e266dd 100644
|
||
|
--- a/src/modules/alsa/alsa-source.c
|
||
|
+++ b/src/modules/alsa/alsa-source.c
|
||
|
@@ -1522,7 +1522,6 @@ static int source_set_port_ucm_cb(pa_source *s, pa_device_port *p) {
|
||
|
|
||
|
pa_assert(u);
|
||
|
pa_assert(p);
|
||
|
- pa_assert(u->mixer_handle);
|
||
|
pa_assert(u->ucm_context);
|
||
|
|
||
|
data = PA_DEVICE_PORT_DATA(p);
|
||
|
@@ -1795,6 +1794,9 @@ static void find_mixer(struct userdata *u, pa_alsa_mapping *mapping, const char
|
||
|
if (!mapping && !element)
|
||
|
return;
|
||
|
|
||
|
+ if (!element && mapping && pa_alsa_path_set_is_empty(mapping->input_path_set))
|
||
|
+ return;
|
||
|
+
|
||
|
u->mixers = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func,
|
||
|
NULL, (pa_free_cb_t) pa_alsa_mixer_free);
|
||
|
|
||
|
@@ -1819,8 +1821,9 @@ static void find_mixer(struct userdata *u, pa_alsa_mapping *mapping, const char
|
||
|
|
||
|
pa_log_debug("Probed mixer path %s:", u->mixer_path->name);
|
||
|
pa_alsa_path_dump(u->mixer_path);
|
||
|
- } else if (!(u->mixer_path_set = mapping->input_path_set))
|
||
|
- goto fail;
|
||
|
+ } else {
|
||
|
+ u->mixer_path_set = mapping->input_path_set;
|
||
|
+ }
|
||
|
|
||
|
return;
|
||
|
|
||
|
--
|
||
|
2.16.4
|
||
|
|