diff options
Diffstat (limited to 'src/modules/alsa/module-alsa-card.c')
-rw-r--r-- | src/modules/alsa/module-alsa-card.c | 52 |
1 files changed, 46 insertions, 6 deletions
diff --git a/src/modules/alsa/module-alsa-card.c b/src/modules/alsa/module-alsa-card.c index e517ddcc..fc6b886b 100644 --- a/src/modules/alsa/module-alsa-card.c +++ b/src/modules/alsa/module-alsa-card.c @@ -30,6 +30,8 @@ #include <pulsecore/modargs.h> #include <pulsecore/queue.h> +#include <modules/reserve-wrap.h> + #include "alsa-util.h" #include "alsa-sink.h" #include "alsa-source.h" @@ -88,6 +90,8 @@ struct userdata { pa_source *source; pa_modargs *modargs; + + pa_hashmap *profiles; }; struct profile_data { @@ -99,10 +103,11 @@ static void enumerate_cb( const pa_alsa_profile_info *source, void *userdata) { - pa_hashmap *profiles = (pa_hashmap *) 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); @@ -116,6 +121,20 @@ static void enumerate_cb( 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; + } + pa_log_info("Found output profile '%s'", t); p = pa_card_profile_new(n, t, sizeof(struct profile_data)); @@ -123,7 +142,11 @@ static void enumerate_cb( pa_xfree(t); pa_xfree(n); - p->priority = (sink ? sink->priority : 0)*100 + (source ? source->priority : 0); + p->priority = + (sink ? sink->priority : 0) * 100 + + (source ? source->priority : 0) + + bonus; + p->n_sinks = !!sink; p->n_sources = !!source; @@ -137,7 +160,7 @@ static void enumerate_cb( d->sink_profile = sink; d->source_profile = source; - pa_hashmap_put(profiles, p->name, p); + pa_hashmap_put(u->profiles, p->name, p); } static void add_disabled_profile(pa_hashmap *profiles) { @@ -252,11 +275,14 @@ static void set_card_name(pa_card_new_data *data, pa_modargs *ma, const char *de pa_xfree(t); } -int pa__init(pa_module*m) { +int pa__init(pa_module *m) { pa_card_new_data data; pa_modargs *ma; int alsa_card_index; struct userdata *u; + char rname[32]; + pa_reserve_wrapper *reserve = NULL; + const char *description; pa_alsa_redirect_errors_inc(); snd_config_update_free_global(); @@ -282,6 +308,11 @@ int pa__init(pa_module*m) { goto fail; } + pa_snprintf(rname, sizeof(rname), "Audio%i", alsa_card_index); + + if (!(reserve = pa_reserve_wrapper_get(m->core, rname))) + goto fail; + pa_card_new_data_init(&data); data.driver = __FILE__; data.module = m; @@ -289,8 +320,12 @@ int pa__init(pa_module*m) { pa_proplist_sets(data.proplist, PA_PROP_DEVICE_STRING, u->device_id); set_card_name(&data, ma, u->device_id); - 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, data.profiles) < 0) { + if (reserve) + 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; } @@ -314,11 +349,16 @@ int pa__init(pa_module*m) { init_profile(u); + pa_reserve_wrapper_unref(reserve); + return 0; fail: + if (reserve) + pa_reserve_wrapper_unref(reserve); pa__done(m); + return -1; } |