]> code.delx.au - pulseaudio/blobdiff - polyp/modargs.c
Make the whole stuff LGPL only
[pulseaudio] / polyp / modargs.c
index 87d99ad2838639b65fa85dc269e472a54ec51dd9..01a694cf8d1fa128e7af570c2c132442d3ac15e8 100644 (file)
@@ -4,7 +4,7 @@
   This file is part of polypaudio.
  
   polypaudio is free software; you can redistribute it and/or modify
-  it under the terms of the GNU General Public License as published
+  it under the terms of the GNU Lesser General Public License as published
   by the Free Software Foundation; either version 2 of the License,
   or (at your option) any later version.
  
@@ -13,7 +13,7 @@
   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 General Public License
+  You should have received a copy of the GNU Lesser General Public License
   along with polypaudio; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
   USA.
@@ -36,6 +36,7 @@
 #include "sink.h"
 #include "source.h"
 #include "xmalloc.h"
+#include "util.h"
 
 struct pa_modargs;
 
@@ -207,6 +208,44 @@ int pa_modargs_get_value_u32(struct pa_modargs *ma, const char *key, uint32_t *v
     return 0;
 }
 
+int pa_modargs_get_value_s32(struct pa_modargs *ma, const char *key, int32_t *value) {
+    const char *v;
+    char *e;
+    signed long l;
+    assert(ma && key && value);
+
+    if (!(v = pa_modargs_get_value(ma, key, NULL)))
+        return 0;
+
+    if (!*v)
+        return -1;
+    
+    l = strtol(v, &e, 0);
+    if (*e)
+        return -1;
+
+    *value = (int32_t) l;
+    return 0;
+}
+
+int pa_modargs_get_value_boolean(struct pa_modargs *ma, const char *key, int *value) {
+    const char *v;
+    int r;
+    assert(ma && key && value);
+
+    if (!(v = pa_modargs_get_value(ma, key, NULL)))
+        return 0;
+
+    if (!*v)
+        return -1;
+
+    if ((r = pa_parse_boolean(v)) < 0)
+        return -1;
+
+    *value = r;
+    return 0;
+}
+
 int pa_modargs_get_sample_spec(struct pa_modargs *ma, struct pa_sample_spec *rss) {
     const char *format;
     uint32_t channels;
@@ -224,28 +263,9 @@ int pa_modargs_get_sample_spec(struct pa_modargs *ma, struct pa_sample_spec *rss
         return -1;
     ss.channels = (uint8_t) channels;
 
-    if ((format = pa_modargs_get_value(ma, "format", NULL))) {
-        if (strcmp(format, "s16le") == 0)
-            ss.format = PA_SAMPLE_S16LE;
-        else if (strcmp(format, "s16be") == 0)
-            ss.format = PA_SAMPLE_S16BE;
-        else if (strcmp(format, "s16ne") == 0 || strcmp(format, "s16") == 0 || strcmp(format, "16") == 0)
-            ss.format = PA_SAMPLE_S16NE;
-        else if (strcmp(format, "u8") == 0 || strcmp(format, "8") == 0)
-            ss.format = PA_SAMPLE_U8;
-        else if (strcmp(format, "float32") == 0 || strcmp(format, "float32ne") == 0)
-            ss.format = PA_SAMPLE_FLOAT32;
-        else if (strcmp(format, "float32le") == 0)
-            ss.format = PA_SAMPLE_FLOAT32LE;
-        else if (strcmp(format, "float32be") == 0)
-            ss.format = PA_SAMPLE_FLOAT32BE;
-        else if (strcmp(format, "ulaw") == 0)
-            ss.format = PA_SAMPLE_ULAW;
-        else if (strcmp(format, "alaw") == 0)
-            ss.format = PA_SAMPLE_ALAW;
-        else
+    if ((format = pa_modargs_get_value(ma, "format", NULL)))
+        if ((ss.format = pa_parse_sample_format(format)) < 0)
             return -1;
-    }
 
     if (!pa_sample_spec_valid(&ss))
         return -1;