]> code.delx.au - pulseaudio/commitdiff
Let's have just one endian conversion macro suite.
authorPierre Ossman <ossman@cendio.se>
Fri, 3 Feb 2006 14:39:39 +0000 (14:39 +0000)
committerPierre Ossman <ossman@cendio.se>
Fri, 3 Feb 2006 14:39:39 +0000 (14:39 +0000)
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@475 fefdeb5f-60dc-0310-8127-8f9354f1896f

polyp/endianmacros.h
polyp/esound.h
polyp/protocol-esound.c

index 91489cd32f04b6692e9eff6182c2c48544521a73..3ab1826a542ad44e60bb7a1e8f2eaaaa244bbe3d 100644 (file)
@@ -33,6 +33,9 @@
 #define INT32_SWAP(x) ( (int32_t) ( ((uint32_t) x >> 24) | ((uint32_t) x << 24) | (((uint32_t) x & 0xFF00) << 8) | ((((uint32_t) x) >> 8) & 0xFF00) ) )
 #define UINT32_SWAP(x) ( (uint32_t) ( ((uint32_t) x >> 24) | ((uint32_t) x << 24) | (((uint32_t) x & 0xFF00) << 8) | ((((uint32_t) x) >> 8) & 0xFF00) ) )
 
+#define MAYBE_INT32_SWAP(c,x) ((c) ? INT32_SWAP(x) : x)
+#define MAYBE_UINT32_SWAP(c,x) ((c) ? UINT32_SWAP(x) : x)
+
 #ifdef WORDS_BIGENDIAN
  #define INT16_FROM_LE(x) INT16_SWAP(x)
  #define INT16_FROM_BE(x) ((int16_t)(x))
index 5dc2583b18c52e7322e5a28388763cf84f862448..9c507ef9c8e334fabee1314adf483b1042c7e333 100644 (file)
@@ -200,14 +200,10 @@ enum esd_client_state {
 };
 typedef int esd_client_state_t;
 
-/* switch endian order for cross platform playing */
-#define swap_endian_32(x) ((x >> 24) | ((x >> 8) & 0xFF00) | (((x & 0xFF00) << 8)) | (x << 24))
-#define maybe_swap_endian_32(c,x) ((c) ? swap_endian_32(x) : x)
-
 /* the endian key is transferred in binary, if it's read into int, */
 /* and matches ESD_ENDIAN_KEY (ENDN), then the endianness of the */
 /* server and the client match; if it's SWAP_ENDIAN_KEY, swap data */
-#define ESD_SWAP_ENDIAN_KEY ((uint32_t) swap_endian_32(ESD_ENDIAN_KEY))
+#define ESD_SWAP_ENDIAN_KEY (UINT32_SWAP(ESD_ENDIAN_KEY))
 
 
 #endif
index 40b0be28f92e8bef21325c580acdbdd851f81927..6f004e1689cd75875a5202451294c18e09083f93 100644 (file)
@@ -46,6 +46,7 @@
 #include "xmalloc.h"
 #include "log.h"
 #include "util.h"
+#include "endianmacros.h"
 
 /* Don't accept more connection than this */
 #define MAX_CONNECTIONS 10
@@ -301,8 +302,8 @@ static int esd_proto_stream_play(struct connection *c, PA_GCC_UNUSED esd_proto_t
     size_t l;
     assert(c && length == (sizeof(int)*2+ESD_NAME_MAX));
     
-    format = maybe_swap_endian_32(c->swap_byte_order, *(const int*)data);
-    rate = maybe_swap_endian_32(c->swap_byte_order, *((const int*)data + 1));
+    format = MAYBE_INT32_SWAP(c->swap_byte_order, *(const int*)data);
+    rate = MAYBE_INT32_SWAP(c->swap_byte_order, *((const int*)data + 1));
 
     ss.rate = rate;
     format_esd2native(format, c->swap_byte_order, &ss);
@@ -357,8 +358,8 @@ static int esd_proto_stream_record(struct connection *c, esd_proto_t request, co
     size_t l;
     assert(c && length == (sizeof(int)*2+ESD_NAME_MAX));
     
-    format = maybe_swap_endian_32(c->swap_byte_order, *(const int*)data);
-    rate = maybe_swap_endian_32(c->swap_byte_order, *((const int*)data + 1));
+    format = MAYBE_INT32_SWAP(c->swap_byte_order, *(const int*)data);
+    rate = MAYBE_INT32_SWAP(c->swap_byte_order, *((const int*)data + 1));
 
     ss.rate = rate;
     format_esd2native(format, c->swap_byte_order, &ss);
@@ -433,7 +434,7 @@ static int esd_proto_get_latency(struct connection *c, PA_GCC_UNUSED esd_proto_t
     
     lag = connection_write(c, sizeof(int));
     assert(lag);
-    *lag = c->swap_byte_order ? swap_endian_32(latency) : latency;
+    *lag = MAYBE_INT32_SWAP(c->swap_byte_order, latency);
     return 0;
 }
 
@@ -451,8 +452,8 @@ static int esd_proto_server_info(struct connection *c, PA_GCC_UNUSED esd_proto_t
     response = connection_write(c, sizeof(int)*3);
     assert(response);
     *(response++) = 0;
-    *(response++) = maybe_swap_endian_32(c->swap_byte_order, rate);
-    *(response++) = maybe_swap_endian_32(c->swap_byte_order, format);
+    *(response++) = MAYBE_INT32_SWAP(c->swap_byte_order, rate);
+    *(response++) = MAYBE_INT32_SWAP(c->swap_byte_order, format);
     return 0;
 }
 
@@ -489,7 +490,7 @@ static int esd_proto_all_info(struct connection *c, esd_proto_t request, const v
         }
         
         /* id */
-        *((int*) response) = maybe_swap_endian_32(c->swap_byte_order, (int) (conn->index+1));
+        *((int*) response) = MAYBE_INT32_SWAP(c->swap_byte_order, (int) (conn->index+1));
         response += sizeof(int);
 
         /* name */
@@ -498,19 +499,19 @@ static int esd_proto_all_info(struct connection *c, esd_proto_t request, const v
         response += ESD_NAME_MAX;
 
         /* rate */
-        *((int*) response) = maybe_swap_endian_32(c->swap_byte_order,  rate);
+        *((int*) response) = MAYBE_INT32_SWAP(c->swap_byte_order,  rate);
         response += sizeof(int);
 
         /* left */
-        *((int*) response) = maybe_swap_endian_32(c->swap_byte_order,  lvolume);
+        *((int*) response) = MAYBE_INT32_SWAP(c->swap_byte_order,  lvolume);
         response += sizeof(int);
 
         /*right*/
-        *((int*) response) = maybe_swap_endian_32(c->swap_byte_order,  rvolume);
+        *((int*) response) = MAYBE_INT32_SWAP(c->swap_byte_order,  rvolume);
         response += sizeof(int);
 
         /*format*/
-        *((int*) response) = maybe_swap_endian_32(c->swap_byte_order, format);
+        *((int*) response) = MAYBE_INT32_SWAP(c->swap_byte_order, format);
         response += sizeof(int);
 
         t-= k;
@@ -529,7 +530,7 @@ static int esd_proto_all_info(struct connection *c, esd_proto_t request, const v
             assert(t >= s*2);
             
             /* id */
-            *((int*) response) = maybe_swap_endian_32(c->swap_byte_order, (int) (ce->index+1));
+            *((int*) response) = MAYBE_INT32_SWAP(c->swap_byte_order, (int) (ce->index+1));
             response += sizeof(int);
             
             /* name */
@@ -540,23 +541,23 @@ static int esd_proto_all_info(struct connection *c, esd_proto_t request, const v
             response += ESD_NAME_MAX;
             
             /* rate */
-            *((int*) response) = maybe_swap_endian_32(c->swap_byte_order, ce->sample_spec.rate);
+            *((int*) response) = MAYBE_INT32_SWAP(c->swap_byte_order, ce->sample_spec.rate);
             response += sizeof(int);
             
             /* left */
-            *((int*) response) = maybe_swap_endian_32(c->swap_byte_order, (ce->volume.values[0]*ESD_VOLUME_BASE)/PA_VOLUME_NORM);
+            *((int*) response) = MAYBE_INT32_SWAP(c->swap_byte_order, (ce->volume.values[0]*ESD_VOLUME_BASE)/PA_VOLUME_NORM);
             response += sizeof(int);
             
             /*right*/
-            *((int*) response) = maybe_swap_endian_32(c->swap_byte_order, (ce->volume.values[0]*ESD_VOLUME_BASE)/PA_VOLUME_NORM);
+            *((int*) response) = MAYBE_INT32_SWAP(c->swap_byte_order, (ce->volume.values[0]*ESD_VOLUME_BASE)/PA_VOLUME_NORM);
             response += sizeof(int);
             
             /*format*/
-            *((int*) response) = maybe_swap_endian_32(c->swap_byte_order, format_native2esd(&ce->sample_spec));
+            *((int*) response) = MAYBE_INT32_SWAP(c->swap_byte_order, format_native2esd(&ce->sample_spec));
             response += sizeof(int);
 
             /*length*/
-            *((int*) response) = maybe_swap_endian_32(c->swap_byte_order, (int) ce->memchunk.length);
+            *((int*) response) = MAYBE_INT32_SWAP(c->swap_byte_order, (int) ce->memchunk.length);
             response += sizeof(int);
 
             t -= s;
@@ -576,10 +577,10 @@ static int esd_proto_stream_pan(struct connection *c, PA_GCC_UNUSED esd_proto_t
     struct connection *conn;
     assert(c && data && length == sizeof(int)*3);
     
-    idx = (uint32_t) maybe_swap_endian_32(c->swap_byte_order, *(const int*)data)-1;
-    lvolume = (uint32_t) maybe_swap_endian_32(c->swap_byte_order, *((const int*)data + 1));
+    idx = MAYBE_UINT32_SWAP(c->swap_byte_order, *(const int*)data)-1;
+    lvolume = MAYBE_UINT32_SWAP(c->swap_byte_order, *((const int*)data + 1));
     lvolume = (lvolume*PA_VOLUME_NORM)/ESD_VOLUME_BASE;
-    rvolume = (uint32_t) maybe_swap_endian_32(c->swap_byte_order, *((const int*)data + 2));
+    rvolume = MAYBE_UINT32_SWAP(c->swap_byte_order, *((const int*)data + 2));
     rvolume = (rvolume*PA_VOLUME_NORM)/ESD_VOLUME_BASE;
 
     ok = connection_write(c, sizeof(int));
@@ -606,13 +607,13 @@ static int esd_proto_sample_cache(struct connection *c, PA_GCC_UNUSED esd_proto_
     char name[ESD_NAME_MAX+sizeof(SCACHE_PREFIX)-1];
     assert(c && data && length == (ESD_NAME_MAX+3*sizeof(int)));
 
-    format = maybe_swap_endian_32(c->swap_byte_order, *(const int*)data);
-    rate = maybe_swap_endian_32(c->swap_byte_order, *((const int*)data + 1));
+    format = MAYBE_INT32_SWAP(c->swap_byte_order, *(const int*)data);
+    rate = MAYBE_INT32_SWAP(c->swap_byte_order, *((const int*)data + 1));
     
     ss.rate = rate;
     format_esd2native(format, c->swap_byte_order, &ss);
 
-    sc_length = (size_t) maybe_swap_endian_32(c->swap_byte_order, (*((const int*)data + 2)));
+    sc_length = (size_t) MAYBE_INT32_SWAP(c->swap_byte_order, (*((const int*)data + 2)));
 
     if (sc_length >= MAX_CACHE_SAMPLE_SIZE)
         return -1;
@@ -668,7 +669,7 @@ static int esd_proto_sample_free_or_play(struct connection *c, esd_proto_t reque
     uint32_t idx;
     assert(c && data && length == sizeof(int));
 
-    idx = (uint32_t) maybe_swap_endian_32(c->swap_byte_order, *(const int*)data)-1;
+    idx = (uint32_t) MAYBE_INT32_SWAP(c->swap_byte_order, *(const int*)data)-1;
 
     ok = connection_write(c, sizeof(int));
     assert(ok);
@@ -729,8 +730,7 @@ static int do_read(struct connection *c) {
         if ((c->read_data_length+= r) >= sizeof(c->request)) {
             struct proto_handler *handler;
             
-            if (c->swap_byte_order)
-                c->request = swap_endian_32(c->request);
+            c->request = MAYBE_INT32_SWAP(c->swap_byte_order, c->request);
 
             if (c->request < ESD_PROTO_CONNECT || c->request > ESD_PROTO_MAX) {
                 pa_log(__FILE__": recieved invalid request.\n");