From 3e3c103ed9e9e4782c12380c3735ab9aaf2611c8 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 24 Dec 2008 00:46:02 +0100 Subject: Add APIs to pass pa_volume_t fields in a tagstruct --- src/pulsecore/tagstruct.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'src/pulsecore/tagstruct.c') 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; -- cgit