[pulseaudio-commits] 3 commits - src/modules src/pulsecore src/tests

Colin Guthrie colin at kemper.freedesktop.org
Fri Sep 9 11:51:44 PDT 2011


 src/modules/alsa/mixer/profile-sets/90-pulseaudio.rules |    1 
 src/modules/alsa/mixer/profile-sets/kinect-audio.conf   |   39 ++++++
 src/modules/raop/module-raop-discover.c                 |    8 -
 src/pulsecore/modargs.c                                 |  100 ++++++++++------
 src/tests/proplist-test.c                               |    2 
 5 files changed, 111 insertions(+), 39 deletions(-)

New commits:
commit 27343ed79a98e971c285b546ebb85495a334895b
Author: Colin Guthrie <colin at mageia.org>
Date:   Tue Sep 6 11:45:24 2011 +0100

    raop: Properly deal with the name coming from the device.
    
    We need to properly quote our proplist arguments passed to the module.

diff --git a/src/modules/raop/module-raop-discover.c b/src/modules/raop/module-raop-discover.c
index 1a7572c..4ebe5fc 100644
--- a/src/modules/raop/module-raop-discover.c
+++ b/src/modules/raop/module-raop-discover.c
@@ -156,7 +156,9 @@ static void resolver_cb(
             ++nicename;
             if (strlen(nicename) > 0) {
                 pa_log_debug("Found RAOP: %s", nicename);
-            }
+                nicename = pa_escape(nicename, "\"'");
+            } else
+                nicename = NULL;
         }
 
         for (l = txt; l; l = l->next) {
@@ -189,11 +191,11 @@ static void resolver_cb(
         if (nicename) {
             args = pa_sprintf_malloc("server=[%s]:%u "
                                      "sink_name=%s "
-                                     "sink_properties=device.description=\"%s\"",
+                                     "sink_properties='device.description=\"%s\"'",
                                      avahi_address_snprint(at, sizeof(at), a), port,
                                      vname,
                                      nicename);
-
+            pa_xfree(nicename);
         } else {
             args = pa_sprintf_malloc("server=[%s]:%u "
                                      "sink_name=%s",

commit 3542112888c0dd563eda37a8be498dd5883fcb0e
Author: Colin Guthrie <colin at mageia.org>
Date:   Tue Sep 6 11:35:33 2011 +0100

    modargs: Ensure modargs can be accessed in their raw form.
    
    When dealing with proplists passed as modargs, we need the unescaped form
    in order to properly deal with quotes (ticks + double quotes). As the previous
    code always called pa_unescape() before adding it into the modarg hashmap, this
    was impossible.
    
    This modification simply stores two proplists. If the unescaped value
    is different from the raw value, we also keep the raw form.
    
    When parsing proplist arguments, we use this raw form and do the unescaping
    ourselves when processing it.
    
    This changes the current behaviour which required you to double escape
    proplists arguments. This double escape mechanism did allow you to mix
    and match what types of quotes you used to delimit the individial
    proplist values, but it made the actual data much harder to pass in.
    
    This approach has the drawback that you cannot mix and match the quotes
    you use, but this is a very minor issue and IMO pales in comparison to
    the general clarity gained.
    
    See the discussion on the mailing list for more background:
     http://lists.freedesktop.org/archives/pulseaudio-discuss/2011-September/011220.html

diff --git a/src/pulsecore/modargs.c b/src/pulsecore/modargs.c
index 45ffba2..2211cba 100644
--- a/src/pulsecore/modargs.c
+++ b/src/pulsecore/modargs.c
@@ -36,18 +36,26 @@
 
 #include "modargs.h"
 
+struct pa_modargs {
+    pa_hashmap *raw;
+    pa_hashmap *unescaped;
+};
+
 struct entry {
     char *key, *value;
 };
 
-static int add_key_value(pa_hashmap *map, char *key, char *value, const char* const valid_keys[]) {
+static int add_key_value(pa_modargs *ma, char *key, char *value, const char* const valid_keys[]) {
     struct entry *e;
+    char *raw;
 
-    pa_assert(map);
+    pa_assert(ma);
+    pa_assert(ma->raw);
+    pa_assert(ma->unescaped);
     pa_assert(key);
     pa_assert(value);
 
-    if (pa_hashmap_get(map, key)) {
+    if (pa_hashmap_get(ma->unescaped, key)) {
         pa_xfree(key);
         pa_xfree(value);
         return -1;
@@ -66,10 +74,21 @@ static int add_key_value(pa_hashmap *map, char *key, char *value, const char* co
         }
     }
 
+    raw = pa_xstrdup(value);
+
     e = pa_xnew(struct entry, 1);
     e->key = key;
-    e->value = value;
-    pa_hashmap_put(map, key, e);
+    e->value = pa_unescape(value);
+    pa_hashmap_put(ma->unescaped, key, e);
+
+    if (pa_streq(raw, value))
+        pa_xfree(raw);
+    else {
+        e = pa_xnew(struct entry, 1);
+        e->key = pa_xstrdup(key);
+        e->value = raw;
+        pa_hashmap_put(ma->raw, key, e);
+    }
 
     return 0;
 }
@@ -89,12 +108,13 @@ pa_modargs *pa_modargs_new(const char *args, const char* const* valid_keys) {
 
     const char *p, *key = NULL, *value = NULL;
     size_t key_len = 0, value_len = 0;
-    pa_hashmap *map;
+    pa_modargs *ma = pa_xnew(pa_modargs, 1);
 
-    map = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
+    ma->raw = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
+    ma->unescaped = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
 
     if (!args)
-        return (pa_modargs*) map;
+        return ma;
 
     state = WHITESPACE;
 
@@ -130,7 +150,7 @@ pa_modargs *pa_modargs_new(const char *args, const char* const* valid_keys) {
                     value = p+1;
                     value_len = 0;
                 } else if (isspace(*p)) {
-                    if (add_key_value(map,
+                    if (add_key_value(ma,
                                       pa_xstrndup(key, key_len),
                                       pa_xstrdup(""),
                                       valid_keys) < 0)
@@ -149,9 +169,9 @@ pa_modargs *pa_modargs_new(const char *args, const char* const* valid_keys) {
 
             case VALUE_SIMPLE:
                 if (isspace(*p)) {
-                    if (add_key_value(map,
+                    if (add_key_value(ma,
                                       pa_xstrndup(key, key_len),
-                                      pa_unescape(pa_xstrndup(value, value_len)),
+                                      pa_xstrndup(value, value_len),
                                       valid_keys) < 0)
                         goto fail;
                     state = WHITESPACE;
@@ -169,9 +189,9 @@ pa_modargs *pa_modargs_new(const char *args, const char* const* valid_keys) {
 
             case VALUE_DOUBLE_QUOTES:
                 if (*p == '"') {
-                    if (add_key_value(map,
+                    if (add_key_value(ma,
                                       pa_xstrndup(key, key_len),
-                                      pa_unescape(pa_xstrndup(value, value_len)),
+                                      pa_xstrndup(value, value_len),
                                       valid_keys) < 0)
                         goto fail;
                     state = WHITESPACE;
@@ -189,9 +209,9 @@ pa_modargs *pa_modargs_new(const char *args, const char* const* valid_keys) {
 
             case VALUE_TICKS:
                 if (*p == '\'') {
-                    if (add_key_value(map,
+                    if (add_key_value(ma,
                                       pa_xstrndup(key, key_len),
-                                      pa_unescape(pa_xstrndup(value, value_len)),
+                                      pa_xstrndup(value, value_len),
                                       valid_keys) < 0)
                         goto fail;
                     state = WHITESPACE;
@@ -210,19 +230,19 @@ pa_modargs *pa_modargs_new(const char *args, const char* const* valid_keys) {
     }
 
     if (state == VALUE_START) {
-        if (add_key_value(map, pa_xstrndup(key, key_len), pa_xstrdup(""), valid_keys) < 0)
+        if (add_key_value(ma, pa_xstrndup(key, key_len), pa_xstrdup(""), valid_keys) < 0)
             goto fail;
     } else if (state == VALUE_SIMPLE) {
-        if (add_key_value(map, pa_xstrndup(key, key_len), pa_xstrdup(value), valid_keys) < 0)
+        if (add_key_value(ma, pa_xstrndup(key, key_len), pa_xstrdup(value), valid_keys) < 0)
             goto fail;
     } else if (state != WHITESPACE)
         goto fail;
 
-    return (pa_modargs*) map;
+    return ma;
 
 fail:
 
-    pa_modargs_free((pa_modargs*) map);
+    pa_modargs_free(ma);
 
     return NULL;
 }
@@ -237,25 +257,41 @@ static void free_func(void *p, void*userdata) {
 }
 
 void pa_modargs_free(pa_modargs*ma) {
-    pa_hashmap *map = (pa_hashmap*) ma;
-    pa_hashmap_free(map, free_func, NULL);
+    pa_assert(ma);
+
+    pa_hashmap_free(ma->raw, free_func, NULL);
+    pa_hashmap_free(ma->unescaped, free_func, NULL);
+    pa_xfree(ma);
 }
 
 const char *pa_modargs_get_value(pa_modargs *ma, const char *key, const char *def) {
-    pa_hashmap *map = (pa_hashmap*) ma;
     struct entry*e;
 
-    if (!(e = pa_hashmap_get(map, key)))
+    pa_assert(ma);
+    pa_assert(key);
+
+    if (!(e = pa_hashmap_get(ma->unescaped, key)))
         return def;
 
     return e->value;
 }
 
-int pa_modargs_get_value_u32(pa_modargs *ma, const char *key, uint32_t *value) {
-    const char *v;
+static const char *modargs_get_value_raw(pa_modargs *ma, const char *key, const char *def) {
+    struct entry*e;
 
     pa_assert(ma);
     pa_assert(key);
+
+    if (!(e = pa_hashmap_get(ma->raw, key)))
+        if (!(e = pa_hashmap_get(ma->unescaped, key)))
+            return def;
+
+    return e->value;
+}
+
+int pa_modargs_get_value_u32(pa_modargs *ma, const char *key, uint32_t *value) {
+    const char *v;
+
     pa_assert(value);
 
     if (!(v = pa_modargs_get_value(ma, key, NULL)))
@@ -270,8 +306,6 @@ int pa_modargs_get_value_u32(pa_modargs *ma, const char *key, uint32_t *value) {
 int pa_modargs_get_value_s32(pa_modargs *ma, const char *key, int32_t *value) {
     const char *v;
 
-    pa_assert(ma);
-    pa_assert(key);
     pa_assert(value);
 
     if (!(v = pa_modargs_get_value(ma, key, NULL)))
@@ -287,8 +321,6 @@ int pa_modargs_get_value_boolean(pa_modargs *ma, const char *key, pa_bool_t *val
     const char *v;
     int r;
 
-    pa_assert(ma);
-    pa_assert(key);
     pa_assert(value);
 
     if (!(v = pa_modargs_get_value(ma, key, NULL)))
@@ -309,7 +341,6 @@ int pa_modargs_get_sample_spec(pa_modargs *ma, pa_sample_spec *rss) {
     uint32_t channels;
     pa_sample_spec ss;
 
-    pa_assert(ma);
     pa_assert(rss);
 
     ss = *rss;
@@ -341,7 +372,6 @@ int pa_modargs_get_channel_map(pa_modargs *ma, const char *name, pa_channel_map
     pa_channel_map map;
     const char *cm;
 
-    pa_assert(ma);
     pa_assert(rmap);
 
     map = *rmap;
@@ -366,7 +396,6 @@ int pa_modargs_get_sample_spec_and_channel_map(
     pa_sample_spec ss;
     pa_channel_map map;
 
-    pa_assert(ma);
     pa_assert(rss);
     pa_assert(rmap);
 
@@ -400,7 +429,7 @@ int pa_modargs_get_proplist(pa_modargs *ma, const char *name, pa_proplist *p, pa
     pa_assert(name);
     pa_assert(p);
 
-    if (!(v = pa_modargs_get_value(ma, name, NULL)))
+    if (!(v = modargs_get_value_raw(ma, name, NULL)))
         return 0;
 
     if (!(n = pa_proplist_from_string(v)))
@@ -413,10 +442,11 @@ int pa_modargs_get_proplist(pa_modargs *ma, const char *name, pa_proplist *p, pa
 }
 
 const char *pa_modargs_iterate(pa_modargs *ma, void **state) {
-    pa_hashmap *map = (pa_hashmap*) ma;
     struct entry *e;
 
-    if (!(e = pa_hashmap_iterate(map, state, NULL)))
+    pa_assert(ma);
+
+    if (!(e = pa_hashmap_iterate(ma->unescaped, state, NULL)))
         return NULL;
 
     return e->key;
diff --git a/src/tests/proplist-test.c b/src/tests/proplist-test.c
index 27a0d3f..8b5a235 100644
--- a/src/tests/proplist-test.c
+++ b/src/tests/proplist-test.c
@@ -81,7 +81,7 @@ int main(int argc, char*argv[]) {
     printf("%s\n", v);
     pa_xfree(v);
 
-    pa_assert_se(ma = pa_modargs_new("foo='foobar=waldo foo2=\"lj\\\\\"dhflh\" foo3=\\'kjlskj\\\\\\'\\''", x));
+    pa_assert_se(ma = pa_modargs_new("foo='foobar=waldo foo2=\"lj\\\"dhflh\" foo3=\"kjlskj\\'\"'", x));
     pa_assert_se(a = pa_proplist_new());
 
     pa_assert_se(pa_modargs_get_proplist(ma, "foo", a, PA_UPDATE_REPLACE) >= 0);

commit e93b32744c1bafb33d5f3ee40b422bab2d017ae1
Author: Antonio Ospite <ospite at studenti.unina.it>
Date:   Fri Sep 9 12:05:29 2011 +0200

    alsa-mixer: Add support for the Microsoft Kinect Sensor device
    
    The Kinect shows up as a UAC device after the firmware has been loaded,
    but in order to be detected by pulseaudio a 4-channels input only
    mapping is needed. Provide a new profile for that and set it with a udev
    rule.
    
    fdo#39664

diff --git a/src/modules/alsa/mixer/profile-sets/90-pulseaudio.rules b/src/modules/alsa/mixer/profile-sets/90-pulseaudio.rules
index 0329340..65864f7 100644
--- a/src/modules/alsa/mixer/profile-sets/90-pulseaudio.rules
+++ b/src/modules/alsa/mixer/profile-sets/90-pulseaudio.rules
@@ -27,5 +27,6 @@ SUBSYSTEMS=="usb", ATTRS{idVendor}=="17cc", ATTRS{idProduct}=="4711", ENV{PULSE_
 SUBSYSTEMS=="usb", ATTRS{idVendor}=="17cc", ATTRS{idProduct}=="1011", ENV{PULSE_PROFILE_SET}="native-instruments-traktor-audio6.conf"
 SUBSYSTEMS=="usb", ATTRS{idVendor}=="17cc", ATTRS{idProduct}=="1021", ENV{PULSE_PROFILE_SET}="native-instruments-traktor-audio10.conf"
 SUBSYSTEMS=="usb", ATTRS{idVendor}=="0763", ATTRS{idProduct}=="2012", ENV{PULSE_PROFILE_SET}="maudio-fasttrack-pro.conf"
+SUBSYSTEMS=="usb", ATTRS{idVendor}=="045e", ATTRS{idProduct}=="02bb", ENV{PULSE_PROFILE_SET}="kinect-audio.conf"
 
 LABEL="pulseaudio_end"
diff --git a/src/modules/alsa/mixer/profile-sets/kinect-audio.conf b/src/modules/alsa/mixer/profile-sets/kinect-audio.conf
new file mode 100644
index 0000000..a66730a
--- /dev/null
+++ b/src/modules/alsa/mixer/profile-sets/kinect-audio.conf
@@ -0,0 +1,39 @@
+# This file is part of PulseAudio.
+#
+# PulseAudio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as
+# published by the Free Software Foundation; either version 2.1 of the
+# License, or (at your option) any later version.
+#
+# PulseAudio is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with PulseAudio; if not, write to the Free Software Foundation,
+# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+
+; Audio profile for the Microsoft Kinect Sensor device in UAC mode.
+;
+; Copyright (C) 2011  Antonio Ospite <ospite at studenti.unina.it>
+;
+; This device has an array of four microphones, and no playback capability.
+;
+; See default.conf for an explanation on the directives used here.
+
+[General]
+auto-profiles = no
+
+[Mapping input-4-channels]
+device-strings = hw:%f
+channel-map = front-left,front-right,rear-left,rear-right
+description = 4 Channels Input
+direction = input
+priority = 5
+
+[Profile input:mic-array]
+description = Microphone Array
+input-mappings = input-4-channels
+priority = 2
+skip-probe = yes



More information about the pulseaudio-commits mailing list