[pulseaudio-discuss] [PATCH 1/2] alsa: Allow sample spec override in mappings
Arun Raghavan
arun.raghavan at collabora.co.uk
Wed Aug 7 10:56:51 PDT 2013
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 | 1 +
src/modules/alsa/alsa-mixer.h | 1 +
src/modules/alsa/alsa-sink.c | 11 +++++++++++
src/modules/alsa/alsa-source.c | 11 +++++++++++
4 files changed, 24 insertions(+)
diff --git a/src/modules/alsa/alsa-mixer.c b/src/modules/alsa/alsa-mixer.c
index fe5b7b1..07c0e5d 100644
--- a/src/modules/alsa/alsa-mixer.c
+++ b/src/modules/alsa/alsa-mixer.c
@@ -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();
diff --git a/src/modules/alsa/alsa-mixer.h b/src/modules/alsa/alsa-mixer.h
index 432e4de..995a34b 100644
--- a/src/modules/alsa/alsa-mixer.h
+++ b/src/modules/alsa/alsa-mixer.h
@@ -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;
diff --git a/src/modules/alsa/alsa-sink.c b/src/modules/alsa/alsa-sink.c
index f910d19..261536a 100644
--- a/src/modules/alsa/alsa-sink.c
+++ b/src/modules/alsa/alsa-sink.c
@@ -2035,6 +2035,17 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca
goto fail;
}
+ /* 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));
+ }
+
alternate_sample_rate = m->core->alternate_sample_rate;
if (pa_modargs_get_alternate_sample_rate(ma, &alternate_sample_rate) < 0) {
pa_log("Failed to parse alternate sample rate");
diff --git a/src/modules/alsa/alsa-source.c b/src/modules/alsa/alsa-source.c
index faf8965..4660c6a 100644
--- a/src/modules/alsa/alsa-source.c
+++ b/src/modules/alsa/alsa-source.c
@@ -1745,6 +1745,17 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p
goto fail;
}
+ /* 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));
+ }
+
alternate_sample_rate = m->core->alternate_sample_rate;
if (pa_modargs_get_alternate_sample_rate(ma, &alternate_sample_rate) < 0) {
pa_log("Failed to parse alternate sample rate");
--
1.8.2.1
More information about the pulseaudio-discuss
mailing list