summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2008-12-24 00:46:02 +0100
committerLennart Poettering <lennart@poettering.net>2008-12-24 00:46:02 +0100
commit3e3c103ed9e9e4782c12380c3735ab9aaf2611c8 (patch)
tree862b47626a7948a1ee1fef34cda01f9cd1f70900
parent6342053b34ab2f8addd2ed74cd965ec794ee50d4 (diff)
Add APIs to pass pa_volume_t fields in a tagstruct
-rw-r--r--src/pulsecore/tagstruct.c38
-rw-r--r--src/pulsecore/tagstruct.h6
2 files changed, 42 insertions, 2 deletions
diff --git a/src/pulsecore/tagstruct.c b/src/pulsecore/tagstruct.c
index 62a30144..330b7596 100644
--- a/src/pulsecore/tagstruct.c
+++ b/src/pulsecore/tagstruct.c
@@ -254,6 +254,17 @@ void pa_tagstruct_put_cvolume(pa_tagstruct *t, const pa_cvolume *cvolume) {
}
}
+void pa_tagstruct_put_volume(pa_tagstruct *t, pa_volume_t vol) {
+ uint32_t u;
+ pa_assert(t);
+
+ extend(t, 5);
+ t->data[t->length] = PA_TAG_VOLUME;
+ u = htonl((uint32_t) vol);
+ memcpy(t->data+t->length+1, &u, 4);
+ t->length += 5;
+}
+
void pa_tagstruct_put_proplist(pa_tagstruct *t, pa_proplist *p) {
void *state = NULL;
pa_assert(t);
@@ -555,6 +566,25 @@ int pa_tagstruct_get_cvolume(pa_tagstruct *t, pa_cvolume *cvolume) {
return 0;
}
+int pa_tagstruct_get_volume(pa_tagstruct*t, pa_volume_t *vol) {
+ uint32_t u;
+
+ pa_assert(t);
+ pa_assert(vol);
+
+ if (t->rindex+5 > t->length)
+ return -1;
+
+ if (t->data[t->rindex] != PA_TAG_VOLUME)
+ return -1;
+
+ memcpy(&u, t->data+t->rindex+1, 4);
+ *vol = (pa_volume_t) ntohl(u);
+
+ t->rindex += 5;
+ return 0;
+}
+
int pa_tagstruct_get_proplist(pa_tagstruct *t, pa_proplist *p) {
size_t saved_rindex;
@@ -663,6 +693,10 @@ void pa_tagstruct_put(pa_tagstruct *t, ...) {
pa_tagstruct_put_cvolume(t, va_arg(va, pa_cvolume *));
break;
+ case PA_TAG_VOLUME:
+ pa_tagstruct_put_volume(t, va_arg(va, pa_volume_t));
+ break;
+
case PA_TAG_PROPLIST:
pa_tagstruct_put_proplist(t, va_arg(va, pa_proplist *));
break;
@@ -738,6 +772,10 @@ int pa_tagstruct_get(pa_tagstruct *t, ...) {
ret = pa_tagstruct_get_cvolume(t, va_arg(va, pa_cvolume *));
break;
+ case PA_TAG_VOLUME:
+ ret = pa_tagstruct_get_volume(t, va_arg(va, pa_volume_t *));
+ break;
+
case PA_TAG_PROPLIST:
ret = pa_tagstruct_get_proplist(t, va_arg(va, pa_proplist *));
break;
diff --git a/src/pulsecore/tagstruct.h b/src/pulsecore/tagstruct.h
index e7d07054..19288eeb 100644
--- a/src/pulsecore/tagstruct.h
+++ b/src/pulsecore/tagstruct.h
@@ -54,7 +54,8 @@ enum {
PA_TAG_USEC = 'U' /* 64bit unsigned */,
PA_TAG_CHANNEL_MAP = 'm',
PA_TAG_CVOLUME = 'v',
- PA_TAG_PROPLIST = 'P'
+ PA_TAG_PROPLIST = 'P',
+ PA_TAG_VOLUME = 'V'
};
pa_tagstruct *pa_tagstruct_new(const uint8_t* data, size_t length);
@@ -79,6 +80,7 @@ void pa_tagstruct_put_usec(pa_tagstruct*t, pa_usec_t u);
void pa_tagstruct_put_channel_map(pa_tagstruct *t, const pa_channel_map *map);
void pa_tagstruct_put_cvolume(pa_tagstruct *t, const pa_cvolume *cvolume);
void pa_tagstruct_put_proplist(pa_tagstruct *t, pa_proplist *p);
+void pa_tagstruct_put_volume(pa_tagstruct *t, pa_volume_t volume);
int pa_tagstruct_get(pa_tagstruct *t, ...);
@@ -95,6 +97,6 @@ int pa_tagstruct_get_usec(pa_tagstruct*t, pa_usec_t *u);
int pa_tagstruct_get_channel_map(pa_tagstruct *t, pa_channel_map *map);
int pa_tagstruct_get_cvolume(pa_tagstruct *t, pa_cvolume *v);
int pa_tagstruct_get_proplist(pa_tagstruct *t, pa_proplist *p);
-
+int pa_tagstruct_get_volume(pa_tagstruct *t, pa_volume_t *v);
#endif