[pulseaudio-commits] 2 commits - src/modules

Arun Raghavan arun at kemper.freedesktop.org
Tue Sep 17 06:03:36 PDT 2013


 src/modules/alsa/alsa-mixer.c  |    1 +
 src/modules/alsa/alsa-mixer.h  |    1 +
 src/modules/alsa/alsa-sink.c   |   13 +++++++++++++
 src/modules/alsa/alsa-source.c |   13 +++++++++++++
 src/modules/alsa/alsa-ucm.c    |   29 +++++++++++++++++++++++++++--
 src/modules/alsa/alsa-ucm.h    |    9 +++++++++
 6 files changed, 64 insertions(+), 2 deletions(-)

New commits:
commit 4d638b5ffd2d482223f74a42622fb063b45a390c
Author: Arun Raghavan <arun.raghavan at collabora.co.uk>
Date:   Wed Aug 7 22:56:58 2013 +0530

    alsa-ucm: Use playback/capture rate specification from UCM
    
    Add new PlaybackRate/CaptureRate values for UCM that can be used to
    specify custom rates for devices. This value can either be set on the
    verb, which makes it apply to all devices, or on the device to override
    the verb setting.

diff --git a/src/modules/alsa/alsa-ucm.c b/src/modules/alsa/alsa-ucm.c
index 7f6b9f1..9eb6412 100644
--- a/src/modules/alsa/alsa-ucm.c
+++ b/src/modules/alsa/alsa-ucm.c
@@ -84,10 +84,12 @@ static struct ucm_items item[] = {
     {"PlaybackVolume", PA_ALSA_PROP_UCM_PLAYBACK_VOLUME},
     {"PlaybackSwitch", PA_ALSA_PROP_UCM_PLAYBACK_SWITCH},
     {"PlaybackPriority", PA_ALSA_PROP_UCM_PLAYBACK_PRIORITY},
+    {"PlaybackRate", PA_ALSA_PROP_UCM_PLAYBACK_RATE},
     {"PlaybackChannels", PA_ALSA_PROP_UCM_PLAYBACK_CHANNELS},
     {"CaptureVolume", PA_ALSA_PROP_UCM_CAPTURE_VOLUME},
     {"CaptureSwitch", PA_ALSA_PROP_UCM_CAPTURE_SWITCH},
     {"CapturePriority", PA_ALSA_PROP_UCM_CAPTURE_PRIORITY},
+    {"CaptureRate", PA_ALSA_PROP_UCM_CAPTURE_RATE},
     {"CaptureChannels", PA_ALSA_PROP_UCM_CAPTURE_CHANNELS},
     {"TQ", PA_ALSA_PROP_UCM_QOS},
     {NULL, NULL},
@@ -256,8 +258,18 @@ static int ucm_get_device_property(
         device->capture_channels = 2;
     }
 
-    /* get priority of device */
+    /* get rate and priority of device */
     if (device->playback_channels) { /* sink device */
+        /* get rate */
+        if ((value = pa_proplist_gets(device->proplist, PA_ALSA_PROP_UCM_PLAYBACK_RATE)) ||
+            (value = pa_proplist_gets(verb->proplist, PA_ALSA_PROP_UCM_PLAYBACK_RATE))) {
+            if (pa_atou(value, &ui) == 0 && ui < PA_RATE_MAX) {
+                pa_log_debug("UCM playback device %s rate %d", device_name, ui);
+                device->playback_rate = ui;
+            } else
+                pa_log_debug("UCM playback device %s has bad rate %s", device_name, value);
+        }
+
         value = pa_proplist_gets(device->proplist, PA_ALSA_PROP_UCM_PLAYBACK_PRIORITY);
         if (value) {
             /* get priority from ucm config */
@@ -269,6 +281,16 @@ static int ucm_get_device_property(
     }
 
     if (device->capture_channels) { /* source device */
+        /* get rate */
+        if ((value = pa_proplist_gets(device->proplist, PA_ALSA_PROP_UCM_CAPTURE_RATE)) ||
+            (value = pa_proplist_gets(verb->proplist, PA_ALSA_PROP_UCM_CAPTURE_RATE))) {
+            if (pa_atou(value, &ui) == 0 && ui < PA_RATE_MAX) {
+                pa_log_debug("UCM capture device %s rate %d", device_name, ui);
+                device->capture_rate = ui;
+            } else
+                pa_log_debug("UCM capture device %s has bad rate %s", device_name, value);
+        }
+
         value = pa_proplist_gets(device->proplist, PA_ALSA_PROP_UCM_CAPTURE_PRIORITY);
         if (value) {
             /* get priority from ucm config */
@@ -1111,7 +1133,7 @@ static int ucm_create_mapping_direction(
 
     pa_alsa_mapping *m;
     char *mapping_name;
-    unsigned priority, channels;
+    unsigned priority, rate, channels;
 
     mapping_name = pa_sprintf_malloc("Mapping %s: %s: %s", verb_name, device_str, is_sink ? "sink" : "source");
 
@@ -1125,6 +1147,7 @@ static int ucm_create_mapping_direction(
     pa_xfree(mapping_name);
 
     priority = is_sink ? device->playback_priority : device->capture_priority;
+    rate = is_sink ? device->playback_rate : device->capture_rate;
     channels = is_sink ? device->playback_channels : device->capture_channels;
 
     if (!m->ucm_context.ucm_devices) {   /* new mapping */
@@ -1137,6 +1160,8 @@ static int ucm_create_mapping_direction(
         m->direction = is_sink ? PA_ALSA_DIRECTION_OUTPUT : PA_ALSA_DIRECTION_INPUT;
 
         ucm_add_mapping(p, m);
+        if (rate)
+            m->sample_spec.rate = rate;
         pa_channel_map_init_extend(&m->channel_map, channels, PA_CHANNEL_MAP_ALSA);
     }
 
diff --git a/src/modules/alsa/alsa-ucm.h b/src/modules/alsa/alsa-ucm.h
index c31e5b1..2fae6c4 100644
--- a/src/modules/alsa/alsa-ucm.h
+++ b/src/modules/alsa/alsa-ucm.h
@@ -56,6 +56,9 @@ typedef void snd_use_case_mgr_t;
 /** For devices: Playback priority */
 #define PA_ALSA_PROP_UCM_PLAYBACK_PRIORITY          "alsa.ucm.playback.priority"
 
+/** For devices: Playback rate */
+#define PA_ALSA_PROP_UCM_PLAYBACK_RATE              "alsa.ucm.playback.rate"
+
 /** For devices: Playback channels */
 #define PA_ALSA_PROP_UCM_PLAYBACK_CHANNELS          "alsa.ucm.playback.channels"
 
@@ -71,6 +74,9 @@ typedef void snd_use_case_mgr_t;
 /** For devices: Capture priority */
 #define PA_ALSA_PROP_UCM_CAPTURE_PRIORITY           "alsa.ucm.capture.priority"
 
+/** For devices: Capture rate */
+#define PA_ALSA_PROP_UCM_CAPTURE_RATE               "alsa.ucm.capture.rate"
+
 /** For devices: Capture channels */
 #define PA_ALSA_PROP_UCM_CAPTURE_CHANNELS           "alsa.ucm.capture.channels"
 
@@ -123,6 +129,9 @@ struct pa_alsa_ucm_device {
     unsigned playback_priority;
     unsigned capture_priority;
 
+    unsigned playback_rate;
+    unsigned capture_rate;
+
     unsigned playback_channels;
     unsigned capture_channels;
 

commit 6a6ee8fd22356f70ee70fa6a92d450d6018a34fe
Author: Arun Raghavan <arun.raghavan at collabora.co.uk>
Date:   Wed Aug 7 18:26:26 2013 +0530

    alsa: Allow sample spec override in mappings
    
    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.

diff --git a/src/modules/alsa/alsa-mixer.c b/src/modules/alsa/alsa-mixer.c
index 8c95b1c..71dfa79 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 6e60646..d3d5b19 100644
--- a/src/modules/alsa/alsa-sink.c
+++ b/src/modules/alsa/alsa-sink.c
@@ -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;
diff --git a/src/modules/alsa/alsa-source.c b/src/modules/alsa/alsa-source.c
index 78125b1..8416ba8 100644
--- a/src/modules/alsa/alsa-source.c
+++ b/src/modules/alsa/alsa-source.c
@@ -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;



More information about the pulseaudio-commits mailing list