]> code.delx.au - pulseaudio/blobdiff - src/pulsecore/tagstruct.c
echo-cancel: Add alternative echo-cancellation implementation
[pulseaudio] / src / pulsecore / tagstruct.c
index fb412a4a23db9b05b912ecc88884dce370184813..330b7596884b00483fb9c18a58a0fe0ba27cdff9 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id$ */
-
 /***
   This file is part of PulseAudio.
 
@@ -156,7 +154,7 @@ 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);
@@ -167,7 +165,7 @@ void pa_tagstruct_put_boolean(pa_tagstruct*t, pa_bool_t 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,7 @@ void pa_tagstruct_put_channel_map(pa_tagstruct *t, const pa_channel_map *map) {
     unsigned i;
 
     pa_assert(t);
-    extend(t, 2 + map->channels);
+    extend(t, 2 + (size_t) map->channels);
 
     t->data[t->length++] = PA_TAG_CHANNEL_MAP;
     t->data[t->length++] = map->channels;
@@ -256,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);
@@ -437,9 +446,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 +534,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,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;
 
@@ -665,8 +693,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();
@@ -739,8 +772,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();