The new module argument can be used to provide a custom directory for loading alsa path configuration files. This is useful for testing: no need to be root to create test configuration files. --- src/modules/alsa/alsa-mixer.c | 20 ++++++++++++++------ src/modules/alsa/alsa-mixer.h | 4 ++-- src/modules/alsa/alsa-sink.c | 6 +++++- src/modules/alsa/alsa-source.c | 6 +++++- src/modules/alsa/module-alsa-card.c | 5 ++++- 5 files changed, 30 insertions(+), 11 deletions(-) diff --git a/src/modules/alsa/alsa-mixer.c b/src/modules/alsa/alsa-mixer.c index 8e34456..cbc4776 100644 --- a/src/modules/alsa/alsa-mixer.c +++ b/src/modules/alsa/alsa-mixer.c @@ -2313,7 +2313,14 @@ static int path_verify(pa_alsa_path *p) { 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; @@ -2356,9 +2363,10 @@ 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_run_from_build_tree() ? PA_BUILDDIR "/modules/alsa/mixer/paths/" : - 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); @@ -2743,7 +2751,7 @@ void pa_alsa_path_set_set_callback(pa_alsa_path_set *ps, snd_mixer_t *m, snd_mix 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; @@ -2784,7 +2792,7 @@ pa_alsa_path_set *pa_alsa_path_set_new(pa_alsa_mapping *m, pa_alsa_direction_t d fn = pa_sprintf_malloc("%s.conf", *in); - if ((p = pa_alsa_path_new(fn, direction))) { + if ((p = pa_alsa_path_new(paths_dir, fn, direction))) { p->path_set = ps; PA_LLIST_INSERT_AFTER(pa_alsa_path, ps->paths, ps->last_path, p); ps->last_path = p; diff --git a/src/modules/alsa/alsa-mixer.h b/src/modules/alsa/alsa-mixer.h index d92d3e9..9a96838 100644 --- a/src/modules/alsa/alsa-mixer.h +++ b/src/modules/alsa/alsa-mixer.h @@ -208,7 +208,7 @@ void pa_alsa_option_dump(pa_alsa_option *o); 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_new(const char *paths_dir, 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 ignore_dB); void pa_alsa_path_dump(pa_alsa_path *p); @@ -220,7 +220,7 @@ 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); +pa_alsa_path_set *pa_alsa_path_set_new(pa_alsa_mapping *m, pa_alsa_direction_t direction, const char *paths_dir); 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); diff --git a/src/modules/alsa/alsa-sink.c b/src/modules/alsa/alsa-sink.c index eec38d8..0c15b46 100644 --- a/src/modules/alsa/alsa-sink.c +++ b/src/modules/alsa/alsa-sink.c @@ -100,6 +100,7 @@ struct userdata { snd_pcm_t *pcm_handle; + char *paths_dir; pa_alsa_fdlist *mixer_fdl; pa_alsa_mixer_pdata *mixer_pd; snd_mixer_t *mixer_handle; @@ -1791,7 +1792,7 @@ static void find_mixer(struct userdata *u, pa_alsa_mapping *mapping, const char 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_OUTPUT, u->paths_dir))) goto fail; pa_alsa_path_set_probe(u->mixer_path_set, u->mixer_handle, ignore_dB); @@ -1998,6 +1999,8 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca ma, "device_id", pa_modargs_get_value(ma, "device", DEFAULT_DEVICE)); + u->paths_dir = pa_xstrdup(pa_modargs_get_value(ma, "paths_dir", NULL)); + if (reserve_init(u, dev_id) < 0) goto fail; @@ -2325,6 +2328,7 @@ static void userdata_free(struct userdata *u) { pa_xfree(u->device_name); pa_xfree(u->control_device); + pa_xfree(u->paths_dir); pa_xfree(u); } diff --git a/src/modules/alsa/alsa-source.c b/src/modules/alsa/alsa-source.c index 1dd63f0..969793c 100644 --- a/src/modules/alsa/alsa-source.c +++ b/src/modules/alsa/alsa-source.c @@ -90,6 +90,7 @@ struct userdata { snd_pcm_t *pcm_handle; + char *paths_dir; pa_alsa_fdlist *mixer_fdl; pa_alsa_mixer_pdata *mixer_pd; snd_mixer_t *mixer_handle; @@ -1515,7 +1516,7 @@ static void find_mixer(struct userdata *u, pa_alsa_mapping *mapping, const char pa_alsa_path_dump(u->mixer_path); } else { - if (!(u->mixer_path_set = pa_alsa_path_set_new(mapping, PA_ALSA_DIRECTION_INPUT))) + if (!(u->mixer_path_set = pa_alsa_path_set_new(mapping, PA_ALSA_DIRECTION_INPUT, u->paths_dir))) goto fail; pa_alsa_path_set_probe(u->mixer_path_set, u->mixer_handle, ignore_dB); @@ -1714,6 +1715,8 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p ma, "device_id", pa_modargs_get_value(ma, "device", DEFAULT_DEVICE)); + u->paths_dir = pa_xstrdup(pa_modargs_get_value(ma, "paths_dir", NULL)); + if (reserve_init(u, dev_id) < 0) goto fail; @@ -2008,6 +2011,7 @@ static void userdata_free(struct userdata *u) { pa_xfree(u->device_name); pa_xfree(u->control_device); + pa_xfree(u->paths_dir); pa_xfree(u); } diff --git a/src/modules/alsa/module-alsa-card.c b/src/modules/alsa/module-alsa-card.c index 8b19d42..2681129 100644 --- a/src/modules/alsa/module-alsa-card.c +++ b/src/modules/alsa/module-alsa-card.c @@ -66,7 +66,9 @@ PA_MODULE_USAGE( "profile=<profile name> " "ignore_dB=<ignore dB information from the device?> " "sync_volume=<syncronize sw and hw voluchanges in IO-thread?> " - "profile_set=<profile set configuration file> "); + "profile_set=<profile set configuration file> " + "paths_dir=<directory containing the path configuration files> " +); static const char* const valid_modargs[] = { "name", @@ -90,6 +92,7 @@ static const char* const valid_modargs[] = { "ignore_dB", "sync_volume", "profile_set", + "paths_dir", NULL }; -- 1.7.5.4