[pulseaudio-discuss] [PATCH v2 2/3] modargs: Adding pa_modargs_get_value_volume()

Flavio Ceolin flavio.ceolin at profusion.mobi
Thu Nov 29 05:04:12 PST 2012


This function gets a pa_volume_t from a string.
---
 src/pulsecore/modargs.c | 14 ++++++++++++++
 src/pulsecore/modargs.h |  4 ++++
 2 files changed, 18 insertions(+)

diff --git a/src/pulsecore/modargs.c b/src/pulsecore/modargs.c
index af9fabf..e86ffa5 100644
--- a/src/pulsecore/modargs.c
+++ b/src/pulsecore/modargs.c
@@ -350,6 +350,20 @@ int pa_modargs_get_value_double(pa_modargs *ma, const char *key, double *value)
     return 0;
 }
 
+int pa_modargs_get_value_volume(pa_modargs *ma, const char *key, pa_volume_t *value) {
+    const char *v;
+
+    pa_assert(value);
+
+    if (!(v = pa_modargs_get_value(ma, key, NULL)))
+        return 0;
+
+    if (pa_parse_volume(v, value) < 0)
+        return -1;
+
+    return 0;
+}
+
 int pa_modargs_get_sample_spec(pa_modargs *ma, pa_sample_spec *rss) {
     const char *format;
     uint32_t channels;
diff --git a/src/pulsecore/modargs.h b/src/pulsecore/modargs.h
index 5da9cf1..c1345ea 100644
--- a/src/pulsecore/modargs.h
+++ b/src/pulsecore/modargs.h
@@ -26,6 +26,7 @@
 #include <pulse/sample.h>
 #include <pulse/channelmap.h>
 #include <pulse/proplist.h>
+#include <pulse/volume.h>
 #include <pulsecore/macro.h>
 
 typedef struct pa_modargs pa_modargs;
@@ -48,6 +49,9 @@ int pa_modargs_get_value_boolean(pa_modargs *ma, const char *key, pa_bool_t *val
 /* Return a module argument as double value in *value */
 int pa_modargs_get_value_double(pa_modargs *ma, const char *key, double *value);
 
+/* Return a module argument as pa_volume_t value in *value */
+int pa_modargs_get_value_volume(pa_modargs *ma, const char *key, pa_volume_t *value);
+
 /* Return sample spec data from the three arguments "rate", "format" and "channels" */
 int pa_modargs_get_sample_spec(pa_modargs *ma, pa_sample_spec *ss);
 
-- 
1.7.11.7



More information about the pulseaudio-discuss mailing list