[polypaudio-commits] r475 - in /trunk/polyp: endianmacros.h esound.h protocol-esound.c

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Fri Feb 3 06:39:40 PST 2006


Author: ossman
Date: Fri Feb  3 15:39:39 2006
New Revision: 475

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=475&root=polypaudio&view=rev
Log:
Let's have just one endian conversion macro suite.

Modified:
    trunk/polyp/endianmacros.h
    trunk/polyp/esound.h
    trunk/polyp/protocol-esound.c

Modified: trunk/polyp/endianmacros.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/polyp/endianmacros.h?rev=475&root=polypaudio&r1=474&r2=475&view=diff
==============================================================================
--- trunk/polyp/endianmacros.h (original)
+++ trunk/polyp/endianmacros.h Fri Feb  3 15:39:39 2006
@@ -32,6 +32,9 @@
 #define UINT16_SWAP(x) ( (uint16_t) ( ((uint16_t) x >> 8) | ((uint16_t) x << 8) ) )
 #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)

Modified: trunk/polyp/esound.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/polyp/esound.h?rev=475&root=polypaudio&r1=474&r2=475&view=diff
==============================================================================
--- trunk/polyp/esound.h (original)
+++ trunk/polyp/esound.h Fri Feb  3 15:39:39 2006
@@ -200,14 +200,10 @@
 };
 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

Modified: trunk/polyp/protocol-esound.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/polyp/protocol-esound.c?rev=475&root=polypaudio&r1=474&r2=475&view=diff
==============================================================================
--- trunk/polyp/protocol-esound.c (original)
+++ trunk/polyp/protocol-esound.c Fri Feb  3 15:39:39 2006
@@ -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 @@
     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 @@
     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 @@
     
     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 @@
     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 @@
         }
         
         /* 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 @@
         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 @@
             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 @@
             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 @@
     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 @@
     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 @@
     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 @@
         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");




More information about the pulseaudio-commits mailing list