]> code.delx.au - pulseaudio/commitdiff
core-format: Add pa_format_info_get_channel_map()
authorTanu Kaskinen <tanu.kaskinen@linux.intel.com>
Mon, 25 Nov 2013 12:59:44 +0000 (14:59 +0200)
committerTanu Kaskinen <tanu.kaskinen@linux.intel.com>
Wed, 8 Jan 2014 19:26:39 +0000 (21:26 +0200)
src/pulse/format.c
src/pulsecore/core-format.c
src/pulsecore/core-format.h

index 424df0e696228d2f1d18b3c63f917fbe512edcb0..4f4b3425da97e4bed19132e01af5486ee3aa8598 100644 (file)
@@ -218,7 +218,6 @@ pa_format_info* pa_format_info_from_sample_spec(pa_sample_spec *ss, pa_channel_m
 
 /* For PCM streams */
 int pa_format_info_to_sample_spec(pa_format_info *f, pa_sample_spec *ss, pa_channel_map *map) {
-    char *m = NULL;
     int ret = -PA_ERR_INVALID;
 
     pa_assert(f);
@@ -233,21 +232,12 @@ int pa_format_info_to_sample_spec(pa_format_info *f, pa_sample_spec *ss, pa_chan
         goto out;
     if (pa_format_info_get_channels(f, &ss->channels) < 0)
         goto out;
-
-    if (map) {
-        pa_channel_map_init(map);
-
-        if (pa_format_info_get_prop_string(f, PA_PROP_FORMAT_CHANNEL_MAP, &m) == 0)
-            if (pa_channel_map_parse(map, m) == NULL)
-                goto out;
-    }
+    if (map && pa_format_info_get_channel_map(f, map) < 0)
+        goto out;
 
     ret = 0;
 
 out:
-    if (m)
-        pa_xfree(m);
-
     return ret;
 }
 
index c2457199cb89f3f8725d249a4e89e61bc3aa5d56..799b2dae5b3f2e2b6f7b6bd51950224b1604b04f 100644 (file)
@@ -95,6 +95,28 @@ int pa_format_info_get_channels(pa_format_info *f, uint8_t *channels) {
     return 0;
 }
 
+int pa_format_info_get_channel_map(pa_format_info *f, pa_channel_map *map) {
+    int r;
+    char *map_str;
+
+    pa_assert(f);
+    pa_assert(map);
+
+    r = pa_format_info_get_prop_string(f, PA_PROP_FORMAT_CHANNEL_MAP, &map_str);
+    if (r < 0)
+        return r;
+
+    map = pa_channel_map_parse(map, map_str);
+    pa_xfree(map_str);
+
+    if (!map) {
+        pa_log_debug("Failed to parse channel map.");
+        return -PA_ERR_INVALID;
+    }
+
+    return 0;
+}
+
 int pa_format_info_to_sample_spec_fake(pa_format_info *f, pa_sample_spec *ss, pa_channel_map *map) {
     int rate;
 
index 06fb51f30aec3cfdcc11f33c06cd51fe85e12006..086cbed841e53936d965831e231567bea6b48395 100644 (file)
@@ -37,6 +37,11 @@ int pa_format_info_get_rate(pa_format_info *f, uint32_t *rate);
  * -PA_ERR_NOENTITY. */
 int pa_format_info_get_channels(pa_format_info *f, uint8_t *channels);
 
+/* Gets the channel map stored in the format info. Returns a negative error
+ * code on failure. If the channel map property is not set at all, returns
+ * -PA_ERR_NOENTITY. */
+int pa_format_info_get_channel_map(pa_format_info *f, pa_channel_map *map);
+
 /* For compressed formats. Converts the format info into a sample spec and a
  * channel map that an ALSA device can use as its configuration parameters when
  * playing back the compressed data. That is, the returned sample spec doesn't