summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/map-file1
-rw-r--r--src/pulse/channelmap.c48
-rw-r--r--src/pulse/channelmap.h3
3 files changed, 30 insertions, 22 deletions
diff --git a/src/map-file b/src/map-file
index 08fb827d..6f8946c6 100644
--- a/src/map-file
+++ b/src/map-file
@@ -28,6 +28,7 @@ pa_channel_map_superset;
pa_channel_map_to_name;
pa_channel_map_to_pretty_name;
pa_channel_map_valid;
+pa_channel_position_from_string;
pa_channel_position_to_pretty_string;
pa_channel_position_to_string;
pa_context_add_autoload;
diff --git a/src/pulse/channelmap.c b/src/pulse/channelmap.c
index 4654a9ad..f663f176 100644
--- a/src/pulse/channelmap.c
+++ b/src/pulse/channelmap.c
@@ -491,6 +491,27 @@ char* pa_channel_map_snprint(char *s, size_t l, const pa_channel_map *map) {
return s;
}
+pa_channel_position_t pa_channel_position_from_string(const char *p) {
+ pa_channel_position_t i;
+ pa_assert(p);
+
+ /* Some special aliases */
+ if (pa_streq(p, "left"))
+ return PA_CHANNEL_POSITION_LEFT;
+ else if (pa_streq(p, "right"))
+ return PA_CHANNEL_POSITION_RIGHT;
+ else if (pa_streq(p, "center"))
+ return PA_CHANNEL_POSITION_CENTER;
+ else if (pa_streq(p, "subwoofer"))
+ return PA_CHANNEL_POSITION_SUBWOOFER;
+
+ for (i = 0; i < PA_CHANNEL_POSITION_MAX; i++)
+ if (pa_streq(p, table[i]))
+ return i;
+
+ return PA_CHANNEL_POSITION_INVALID;
+}
+
pa_channel_map *pa_channel_map_parse(pa_channel_map *rmap, const char *s) {
const char *state;
pa_channel_map map;
@@ -559,36 +580,19 @@ pa_channel_map *pa_channel_map_parse(pa_channel_map *rmap, const char *s) {
map.channels = 0;
while ((p = pa_split(s, ",", &state))) {
+ pa_channel_position_t f;
if (map.channels >= PA_CHANNELS_MAX) {
pa_xfree(p);
return NULL;
}
- /* Some special aliases */
- if (pa_streq(p, "left"))
- map.map[map.channels++] = PA_CHANNEL_POSITION_LEFT;
- else if (pa_streq(p, "right"))
- map.map[map.channels++] = PA_CHANNEL_POSITION_RIGHT;
- else if (pa_streq(p, "center"))
- map.map[map.channels++] = PA_CHANNEL_POSITION_CENTER;
- else if (pa_streq(p, "subwoofer"))
- map.map[map.channels++] = PA_CHANNEL_POSITION_SUBWOOFER;
- else {
- pa_channel_position_t i;
-
- for (i = 0; i < PA_CHANNEL_POSITION_MAX; i++)
- if (strcmp(p, table[i]) == 0) {
- map.map[map.channels++] = i;
- break;
- }
-
- if (i >= PA_CHANNEL_POSITION_MAX) {
- pa_xfree(p);
- return NULL;
- }
+ if ((f = pa_channel_position_from_string(p)) == PA_CHANNEL_POSITION_INVALID) {
+ pa_xfree(p);
+ return NULL;
}
+ map.map[map.channels++] = f;
pa_xfree(p);
}
diff --git a/src/pulse/channelmap.h b/src/pulse/channelmap.h
index 2aaead01..d0474262 100644
--- a/src/pulse/channelmap.h
+++ b/src/pulse/channelmap.h
@@ -282,6 +282,9 @@ pa_channel_map* pa_channel_map_init_extend(pa_channel_map *m, unsigned channels,
/** Return a text label for the specified channel position */
const char* pa_channel_position_to_string(pa_channel_position_t pos) PA_GCC_PURE;
+/* The inverse of pa_channel_position_to_string(). \since 0.9.16 */
+pa_channel_position_t pa_channel_position_from_string(const char *s) PA_GCC_PURE;
+
/** Return a human readable text label for the specified channel position. \since 0.9.7 */
const char* pa_channel_position_to_pretty_string(pa_channel_position_t pos);