]> code.delx.au - pulseaudio/commitdiff
alsa: Allow sample spec override in mappings
authorArun Raghavan <arun.raghavan@collabora.co.uk>
Wed, 7 Aug 2013 12:56:26 +0000 (18:26 +0530)
committerArun Raghavan <arun.raghavan@collabora.co.uk>
Tue, 17 Sep 2013 13:01:03 +0000 (18:31 +0530)
This allows mappings to override some or all of the sample_spec used to
open the ALSA device. The intention, to start with, is to use this for
devices in UCM that need to be opened at a specific rate (like modem
devices). This can be extended to allow overrides in profile-sets as
well.

src/modules/alsa/alsa-mixer.c
src/modules/alsa/alsa-mixer.h
src/modules/alsa/alsa-sink.c
src/modules/alsa/alsa-source.c

index 8c95b1c896321e7e66692f26872cf490f2f26615..71dfa7975af0b1708183fdf71589d5b6595a83e9 100644 (file)
@@ -3368,6 +3368,7 @@ pa_alsa_mapping *pa_alsa_mapping_get(pa_alsa_profile_set *ps, const char *name)
     m = pa_xnew0(pa_alsa_mapping, 1);
     m->profile_set = ps;
     m->name = pa_xstrdup(name);
+    pa_sample_spec_init(&m->sample_spec);
     pa_channel_map_init(&m->channel_map);
     m->proplist = pa_proplist_new();
 
index 432e4de78fd7baa3a8ea8d87898eb854f16ac8ef..995a34ba068ec9f17837defa6b1ee6535eaa9f68 100644 (file)
@@ -251,6 +251,7 @@ struct pa_alsa_mapping {
     /* These are copied over to the resultant sink/source */
     pa_proplist *proplist;
 
+    pa_sample_spec sample_spec;
     pa_channel_map channel_map;
 
     char **device_strings;
index 6e6064655c0bed601b5a1ab72fc99f8a101257c2..d3d5b19a39c2c5e8ad2011eee3d0470f9a05f203 100644 (file)
@@ -2030,6 +2030,19 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca
 
     ss = m->core->default_sample_spec;
     map = m->core->default_channel_map;
+
+    /* Pick sample spec overrides from the mapping, if any */
+    if (mapping->sample_spec.format != PA_SAMPLE_INVALID)
+        ss.format = mapping->sample_spec.format;
+    if (mapping->sample_spec.rate != 0)
+        ss.rate = mapping->sample_spec.rate;
+    if (mapping->sample_spec.channels != 0) {
+        ss.channels = mapping->sample_spec.channels;
+        if (pa_channel_map_valid(&mapping->channel_map))
+            pa_assert(pa_channel_map_compatible(&mapping->channel_map, &ss));
+    }
+
+    /* Override with modargs if provided */
     if (pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map, PA_CHANNEL_MAP_ALSA) < 0) {
         pa_log("Failed to parse sample specification and channel map");
         goto fail;
index 78125b1de5fc1707615ecf4df96e1c6c0a6869d1..8416ba8ae5b50b1c95992f5751b10d6edadf843b 100644 (file)
@@ -1740,6 +1740,19 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p
 
     ss = m->core->default_sample_spec;
     map = m->core->default_channel_map;
+
+    /* Pick sample spec overrides from the mapping, if any */
+    if (mapping->sample_spec.format != PA_SAMPLE_INVALID)
+        ss.format = mapping->sample_spec.format;
+    if (mapping->sample_spec.rate != 0)
+        ss.rate = mapping->sample_spec.rate;
+    if (mapping->sample_spec.channels != 0) {
+        ss.channels = mapping->sample_spec.channels;
+        if (pa_channel_map_valid(&mapping->channel_map))
+            pa_assert(pa_channel_map_compatible(&mapping->channel_map, &ss));
+    }
+
+    /* Override with modargs if provided */
     if (pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map, PA_CHANNEL_MAP_ALSA) < 0) {
         pa_log("Failed to parse sample specification and channel map");
         goto fail;