[polypaudio-commits] r799 - in /trunk/src/polyp: channelmap.c channelmap.h
svnmailer-noreply at 0pointer.de
svnmailer-noreply at 0pointer.de
Wed Apr 26 07:33:46 PDT 2006
Author: lennart
Date: Wed Apr 26 16:33:45 2006
New Revision: 799
URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=799&root=polypaudio&view=rev
Log:
* add new function pa_channel_map_parse()
* increase PA_CHANNEL_MAP_SNPRINT_MAX
* add "top" channel positions
Modified:
trunk/src/polyp/channelmap.c
trunk/src/polyp/channelmap.h
Modified: trunk/src/polyp/channelmap.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/polyp/channelmap.c?rev=799&root=polypaudio&r1=798&r2=799&view=diff
==============================================================================
--- trunk/src/polyp/channelmap.c (original)
+++ trunk/src/polyp/channelmap.c Wed Apr 26 16:33:45 2006
@@ -28,7 +28,56 @@
#include <stdio.h>
#include <string.h>
+#include <polypcore/util.h>
+#include <polypcore/xmalloc.h>
#include "channelmap.h"
+
+const char *const table[] = {
+ [PA_CHANNEL_POSITION_MONO] = "mono",
+
+ [PA_CHANNEL_POSITION_FRONT_CENTER] = "front-center",
+ [PA_CHANNEL_POSITION_FRONT_LEFT] = "front-left",
+ [PA_CHANNEL_POSITION_FRONT_RIGHT] = "front-right",
+
+ [PA_CHANNEL_POSITION_REAR_CENTER] = "rear-center",
+ [PA_CHANNEL_POSITION_REAR_LEFT] = "rear-left",
+ [PA_CHANNEL_POSITION_REAR_RIGHT] = "rear-right",
+
+ [PA_CHANNEL_POSITION_LFE] = "lfe",
+
+ [PA_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER] = "front-left-of-center",
+ [PA_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER] = "front-right-of-center",
+
+ [PA_CHANNEL_POSITION_SIDE_LEFT] = "side-left",
+ [PA_CHANNEL_POSITION_SIDE_RIGHT] = "side-right",
+
+ [PA_CHANNEL_POSITION_AUX0] = "aux0",
+ [PA_CHANNEL_POSITION_AUX1] = "aux1",
+ [PA_CHANNEL_POSITION_AUX2] = "aux2",
+ [PA_CHANNEL_POSITION_AUX3] = "aux3",
+ [PA_CHANNEL_POSITION_AUX4] = "aux4",
+ [PA_CHANNEL_POSITION_AUX5] = "aux5",
+ [PA_CHANNEL_POSITION_AUX6] = "aux6",
+ [PA_CHANNEL_POSITION_AUX7] = "aux7",
+ [PA_CHANNEL_POSITION_AUX8] = "aux8",
+ [PA_CHANNEL_POSITION_AUX9] = "aux9",
+ [PA_CHANNEL_POSITION_AUX10] = "aux10",
+ [PA_CHANNEL_POSITION_AUX11] = "aux11",
+ [PA_CHANNEL_POSITION_AUX12] = "aux12",
+ [PA_CHANNEL_POSITION_AUX13] = "aux13",
+ [PA_CHANNEL_POSITION_AUX14] = "aux14",
+ [PA_CHANNEL_POSITION_AUX15] = "aux15",
+
+ [PA_CHANNEL_POSITION_TOP_CENTER] = "top-center",
+
+ [PA_CHANNEL_POSITION_TOP_FRONT_LEFT] = "top-front-left",
+ [PA_CHANNEL_POSITION_TOP_FRONT_RIGHT] = "top-front-right",
+ [PA_CHANNEL_POSITION_TOP_FRONT_CENTER] = "top-front-center",
+
+ [PA_CHANNEL_POSITION_TOP_REAR_LEFT] = "top-rear-left",
+ [PA_CHANNEL_POSITION_TOP_REAR_RIGHT] = "top-rear-right",
+ [PA_CHANNEL_POSITION_TOP_REAR_CENTER] = "top-rear-center"
+};
pa_channel_map* pa_channel_map_init(pa_channel_map *m) {
unsigned c;
@@ -117,40 +166,8 @@
}
}
+
const char* pa_channel_position_to_string(pa_channel_position_t pos) {
-
- const char *const table[] = {
- [PA_CHANNEL_POSITION_MONO] = "mono",
-
- [PA_CHANNEL_POSITION_FRONT_CENTER] = "front-center",
- [PA_CHANNEL_POSITION_FRONT_LEFT] = "front-left",
- [PA_CHANNEL_POSITION_FRONT_RIGHT] = "front-right",
-
- [PA_CHANNEL_POSITION_REAR_CENTER] = "rear-center",
- [PA_CHANNEL_POSITION_REAR_LEFT] = "rear-left",
- [PA_CHANNEL_POSITION_REAR_RIGHT] = "rear-right",
-
- [PA_CHANNEL_POSITION_LFE] = "lfe",
-
- [PA_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER] = "front-left-of-center",
- [PA_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER] = "front-right-of-center",
-
- [PA_CHANNEL_POSITION_SIDE_LEFT] = "side-left",
- [PA_CHANNEL_POSITION_SIDE_RIGHT] = "side-right",
-
- [PA_CHANNEL_POSITION_AUX1] = "aux1",
- [PA_CHANNEL_POSITION_AUX2] = "aux2",
- [PA_CHANNEL_POSITION_AUX3] = "aux3",
- [PA_CHANNEL_POSITION_AUX4] = "aux4",
- [PA_CHANNEL_POSITION_AUX5] = "aux5",
- [PA_CHANNEL_POSITION_AUX6] = "aux6",
- [PA_CHANNEL_POSITION_AUX7] = "aux7",
- [PA_CHANNEL_POSITION_AUX8] = "aux8",
- [PA_CHANNEL_POSITION_AUX9] = "aux9",
- [PA_CHANNEL_POSITION_AUX10] = "aux10",
- [PA_CHANNEL_POSITION_AUX11] = "aux11",
- [PA_CHANNEL_POSITION_AUX12] = "aux12"
- };
if (pos < 0 || pos >= PA_CHANNEL_POSITION_MAX)
return NULL;
@@ -186,9 +203,8 @@
*(e = s) = 0;
for (channel = 0; channel < map->channels && l > 1; channel++) {
- l -= snprintf(e, l, "%s%u:%s",
- first ? "" : " ",
- channel,
+ l -= snprintf(e, l, "%s%s",
+ first ? "" : ",",
pa_channel_position_to_string(map->map[channel]));
e = strchr(e, 0);
@@ -197,6 +213,61 @@
return s;
}
+
+pa_channel_map *pa_channel_map_parse(pa_channel_map *map, const char *s) {
+ const char *state;
+ char *p;
+
+ assert(map);
+ assert(s);
+
+ memset(map, 0, sizeof(pa_channel_map));
+
+ if (strcmp(s, "stereo") == 0) {
+ map->channels = 2;
+ map->map[0] = PA_CHANNEL_POSITION_LEFT;
+ map->map[1] = PA_CHANNEL_POSITION_RIGHT;
+ return map;
+ }
+
+ state = NULL;
+ map->channels = 0;
+
+ while ((p = pa_split(s, ",", &state))) {
+
+ /* Some special aliases */
+ if (strcmp(p, "left") == 0)
+ map->map[map->channels++] = PA_CHANNEL_POSITION_LEFT;
+ else if (strcmp(p, "right") == 0)
+ map->map[map->channels++] = PA_CHANNEL_POSITION_RIGHT;
+ else if (strcmp(p, "center") == 0)
+ map->map[map->channels++] = PA_CHANNEL_POSITION_CENTER;
+ else if (strcmp(p, "subwoofer") == 0)
+ 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;
+ }
+ }
+
+ pa_xfree(p);
+ }
+
+ if (!map->channels)
+ return NULL;
+
+ return map;
+}
+
int pa_channel_map_valid(const pa_channel_map *map) {
unsigned c;
@@ -212,3 +283,4 @@
return 1;
}
+
Modified: trunk/src/polyp/channelmap.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/polyp/channelmap.h?rev=799&root=polypaudio&r1=798&r2=799&view=diff
==============================================================================
--- trunk/src/polyp/channelmap.h (original)
+++ trunk/src/polyp/channelmap.h Wed Apr 26 16:33:45 2006
@@ -107,6 +107,16 @@
PA_CHANNEL_POSITION_AUX14,
PA_CHANNEL_POSITION_AUX15,
+ PA_CHANNEL_POSITION_TOP_CENTER,
+
+ PA_CHANNEL_POSITION_TOP_FRONT_LEFT,
+ PA_CHANNEL_POSITION_TOP_FRONT_RIGHT,
+ PA_CHANNEL_POSITION_TOP_FRONT_CENTER,
+
+ PA_CHANNEL_POSITION_TOP_REAR_LEFT,
+ PA_CHANNEL_POSITION_TOP_REAR_RIGHT,
+ PA_CHANNEL_POSITION_TOP_REAR_CENTER,
+
PA_CHANNEL_POSITION_MAX
} pa_channel_position_t;
@@ -134,10 +144,13 @@
const char* pa_channel_position_to_string(pa_channel_position_t pos);
/** The maximum length of strings returned by pa_channel_map_snprint() */
-#define PA_CHANNEL_MAP_SNPRINT_MAX 64
+#define PA_CHANNEL_MAP_SNPRINT_MAX 336
/** Make a humand readable string from the specified channel map */
char* pa_channel_map_snprint(char *s, size_t l, const pa_channel_map *map);
+
+/** Parse a channel position list into a channel map structure. \since 0.8.1 */
+pa_channel_map *pa_channel_map_parse(pa_channel_map *map, const char *s);
/** Compare two channel maps. Return 1 if both match. */
int pa_channel_map_equal(const pa_channel_map *a, const pa_channel_map *b);
More information about the pulseaudio-commits
mailing list