X-Git-Url: https://code.delx.au/pulseaudio/blobdiff_plain/e1c1a782b65e5e207b72e88f3ae04720a743c7e8..e11b699d45fa3dca2cde8a976cbf25490f5501a4:/src/pulsecore/tagstruct.c diff --git a/src/pulsecore/tagstruct.c b/src/pulsecore/tagstruct.c index fb412a4a..e51fcf28 100644 --- a/src/pulsecore/tagstruct.c +++ b/src/pulsecore/tagstruct.c @@ -1,5 +1,3 @@ -/* $Id$ */ - /*** This file is part of PulseAudio. @@ -37,7 +35,7 @@ #include -#include +#include #include #include "tagstruct.h" @@ -49,7 +47,7 @@ struct pa_tagstruct { size_t length, allocated; size_t rindex; - pa_bool_t dynamic; + bool dynamic; }; pa_tagstruct *pa_tagstruct_new(const uint8_t* data, size_t length) { @@ -156,18 +154,18 @@ void pa_tagstruct_put_arbitrary(pa_tagstruct *t, const void *p, size_t length) { extend(t, 5+length); t->data[t->length] = PA_TAG_ARBITRARY; - tmp = htonl(length); + tmp = htonl((uint32_t) length); memcpy(t->data+t->length+1, &tmp, 4); if (length) memcpy(t->data+t->length+5, p, length); t->length += 5+length; } -void pa_tagstruct_put_boolean(pa_tagstruct*t, pa_bool_t b) { +void pa_tagstruct_put_boolean(pa_tagstruct*t, bool b) { pa_assert(t); extend(t, 1); - t->data[t->length] = b ? PA_TAG_BOOLEAN_TRUE : PA_TAG_BOOLEAN_FALSE; + t->data[t->length] = (uint8_t) (b ? PA_TAG_BOOLEAN_TRUE : PA_TAG_BOOLEAN_FALSE); t->length += 1; } @@ -177,9 +175,9 @@ void pa_tagstruct_put_timeval(pa_tagstruct*t, const struct timeval *tv) { extend(t, 9); t->data[t->length] = PA_TAG_TIMEVAL; - tmp = htonl(tv->tv_sec); + tmp = htonl((uint32_t) tv->tv_sec); memcpy(t->data+t->length+1, &tmp, 4); - tmp = htonl(tv->tv_usec); + tmp = htonl((uint32_t) tv->tv_usec); memcpy(t->data+t->length+5, &tmp, 4); t->length += 9; } @@ -230,7 +228,8 @@ void pa_tagstruct_put_channel_map(pa_tagstruct *t, const pa_channel_map *map) { unsigned i; pa_assert(t); - extend(t, 2 + map->channels); + pa_assert(map); + extend(t, 2 + (size_t) map->channels); t->data[t->length++] = PA_TAG_CHANNEL_MAP; t->data[t->length++] = map->channels; @@ -244,6 +243,7 @@ void pa_tagstruct_put_cvolume(pa_tagstruct *t, const pa_cvolume *cvolume) { pa_volume_t vol; pa_assert(t); + pa_assert(cvolume); extend(t, 2 + cvolume->channels * sizeof(pa_volume_t)); t->data[t->length++] = PA_TAG_CVOLUME; @@ -256,6 +256,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); @@ -282,6 +293,17 @@ void pa_tagstruct_put_proplist(pa_tagstruct *t, pa_proplist *p) { pa_tagstruct_puts(t, NULL); } +void pa_tagstruct_put_format_info(pa_tagstruct *t, pa_format_info *f) { + pa_assert(t); + pa_assert(f); + + extend(t, 1); + + t->data[t->length++] = PA_TAG_FORMAT_INFO; + pa_tagstruct_putu8(t, (uint8_t) f->encoding); + pa_tagstruct_put_proplist(t, f->plist); +} + int pa_tagstruct_gets(pa_tagstruct*t, const char **s) { int error = 0; size_t n; @@ -407,7 +429,7 @@ const uint8_t* pa_tagstruct_data(pa_tagstruct*t, size_t *l) { return t->data; } -int pa_tagstruct_get_boolean(pa_tagstruct*t, pa_bool_t *b) { +int pa_tagstruct_get_boolean(pa_tagstruct*t, bool *b) { pa_assert(t); pa_assert(b); @@ -415,9 +437,9 @@ int pa_tagstruct_get_boolean(pa_tagstruct*t, pa_bool_t *b) { return -1; if (t->data[t->rindex] == PA_TAG_BOOLEAN_TRUE) - *b = TRUE; + *b = true; else if (t->data[t->rindex] == PA_TAG_BOOLEAN_FALSE) - *b = FALSE; + *b = false; else return -1; @@ -437,9 +459,9 @@ int pa_tagstruct_get_timeval(pa_tagstruct*t, struct timeval *tv) { return -1; memcpy(&tv->tv_sec, t->data+t->rindex+1, 4); - tv->tv_sec = ntohl(tv->tv_sec); + tv->tv_sec = (time_t) ntohl((uint32_t) tv->tv_sec); memcpy(&tv->tv_usec, t->data+t->rindex+5, 4); - tv->tv_usec = ntohl(tv->tv_usec); + tv->tv_usec = (suseconds_t) ntohl((uint32_t) tv->tv_usec); t->rindex += 9; return 0; } @@ -525,7 +547,7 @@ int pa_tagstruct_get_channel_map(pa_tagstruct *t, pa_channel_map *map) { for (i = 0; i < map->channels; i ++) map->map[i] = (int8_t) t->data[t->rindex + 2 + i]; - t->rindex += 2 + map->channels; + t->rindex += 2 + (size_t) map->channels; return 0; } @@ -557,11 +579,29 @@ 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; pa_assert(t); - pa_assert(p); if (t->rindex+1 > t->length) return -1; @@ -583,6 +623,9 @@ int pa_tagstruct_get_proplist(pa_tagstruct *t, pa_proplist *p) { if (!k) break; + if (!pa_proplist_key_valid(k)) + goto fail; + if (pa_tagstruct_getu32(t, &length) < 0) goto fail; @@ -592,8 +635,8 @@ int pa_tagstruct_get_proplist(pa_tagstruct *t, pa_proplist *p) { if (pa_tagstruct_get_arbitrary(t, &d, length) < 0) goto fail; - if (pa_proplist_set(p, k, d, length) < 0) - goto fail; + if (p) + pa_assert_se(pa_proplist_set(p, k, d, length) >= 0); } return 0; @@ -603,6 +646,37 @@ fail: return -1; } +int pa_tagstruct_get_format_info(pa_tagstruct *t, pa_format_info *f) { + size_t saved_rindex; + uint8_t encoding; + + pa_assert(t); + pa_assert(f); + + if (t->rindex+1 > t->length) + return -1; + + if (t->data[t->rindex] != PA_TAG_FORMAT_INFO) + return -1; + + saved_rindex = t->rindex; + t->rindex++; + + if (pa_tagstruct_getu8(t, &encoding) < 0) + goto fail; + + f->encoding = encoding; + + if (pa_tagstruct_get_proplist(t, f->plist) < 0) + goto fail; + + return 0; + +fail: + t->rindex = saved_rindex; + return -1; +} + void pa_tagstruct_put(pa_tagstruct *t, ...) { va_list va; pa_assert(t); @@ -665,8 +739,13 @@ 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; default: pa_assert_not_reached(); @@ -720,7 +799,7 @@ int pa_tagstruct_get(pa_tagstruct *t, ...) { case PA_TAG_BOOLEAN_TRUE: case PA_TAG_BOOLEAN_FALSE: - ret = pa_tagstruct_get_boolean(t, va_arg(va, pa_bool_t*)); + ret = pa_tagstruct_get_boolean(t, va_arg(va, bool*)); break; case PA_TAG_TIMEVAL: @@ -739,8 +818,13 @@ 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; default: pa_assert_not_reached();