[rtmpdump] r277 - in trunk: amf.c bytes.h

hyc subversion at mplayerhq.hu
Mon Mar 1 05:30:35 CET 2010


Author: hyc
Date: Mon Mar  1 05:30:34 2010
New Revision: 277

Log:
Cleanup more endian cruft

Modified:
   trunk/amf.c
   trunk/bytes.h

Modified: trunk/amf.c
==============================================================================
--- trunk/amf.c	Sat Feb 27 22:48:51 2010	(r276)
+++ trunk/amf.c	Mon Mar  1 05:30:34 2010	(r277)
@@ -70,13 +70,11 @@ AMF_DecodeString(const char *data, AVal 
 double
 AMF_DecodeNumber(const char *data)
 {
+  double dVal;
 #if __FLOAT_WORD_ORDER == __BYTE_ORDER
 #if __BYTE_ORDER == __BIG_ENDIAN
-  double dVal;
   memcpy(&dVal, data, 8);
-  return dVal;
 #elif __BYTE_ORDER == __LITTLE_ENDIAN
-  double dVal;
   unsigned char *ci, *co;
   ci = (unsigned char *) data;
   co = (unsigned char *) &dVal;
@@ -88,26 +86,35 @@ AMF_DecodeNumber(const char *data)
   co[5] = ci[2];
   co[6] = ci[1];
   co[7] = ci[0];
-  return dVal;
 #endif
 #else
 #if __BYTE_ORDER == __LITTLE_ENDIAN	// __FLOAT_WORD_ORER == __BIG_ENDIAN
-  uint32_t in1 = *((uint32_t *) data);
-  uint32_t in2 = *((uint32_t *) (data + 4));
-
-  in1 = __bswap_32(in1);
-  in2 = __bswap_32(in2);
-
-  uint64_t res = ((uint64_t) in2 << 32) | (uint64_t) in1;
-  return *((double *) &res);
+  unsigned char *ci, *co;
+  ci = (unsigned char *) data;
+  co = (unsigned char *) &dVal;
+  co[0] = ci[3];
+  co[1] = ci[2];
+  co[2] = ci[1];
+  co[3] = ci[0];
+  co[4] = ci[7];
+  co[5] = ci[6];
+  co[6] = ci[5];
+  co[7] = ci[4];
 #else // __BYTE_ORDER == __BIG_ENDIAN && __FLOAT_WORD_ORER == __LITTLE_ENDIAN
-  uint32_t in1 = *((uint32_t *) data);
-  uint32_t in2 = *((uint32_t *) (data + 4));
-
-  uint64_t res = ((uint64_t) in1 << 32) | (uint64_t) in2;
-  return *((double *) &res);
+  unsigned char *ci, *co;
+  ci = (unsigned char *) data;
+  co = (unsigned char *) &dVal;
+  co[0] = ci[4];
+  co[1] = ci[5];
+  co[2] = ci[6];
+  co[3] = ci[7];
+  co[4] = ci[0];
+  co[5] = ci[1];
+  co[6] = ci[2];
+  co[7] = ci[3];
 #endif
 #endif
+  return dVal;
 }
 
 bool

Modified: trunk/bytes.h
==============================================================================
--- trunk/bytes.h	Sat Feb 27 22:48:51 2010	(r276)
+++ trunk/bytes.h	Mon Mar  1 05:30:34 2010	(r277)
@@ -35,33 +35,24 @@
 
 typedef unsigned char uint8_t;
 
-#elif (defined(__FreeBSD__) && __FreeBSD_version >= 470000) || defined(__OpenBSD__) || defined(__NetBSD__) // *BSD
-#include <sys/endian.h>
-#define __BIG_ENDIAN    BIG_ENDIAN
-#define __LITTLE_ENDIAN LITTLE_ENDIAN
-#define __BYTE_ORDER    BYTE_ORDER
+#else /* !WIN32 */
 
-#elif (defined(BSD) && (BSD >= 199103)) || defined(__APPLE__) // more BSD
-#include <machine/endian.h>
-#define __BIG_ENDIAN	BIG_ENDIAN
-#define __LITTLE_ENDIAN	LITTLE_ENDIAN
-#define __BYTE_ORDER	BYTE_ORDER
+#include <sys/param.h>
 
-#elif defined(__linux__) //|| defined (__BEOS__) // Linux, BeOS
-#include <endian.h>
-#include <byteswap.h>
+#if defined(BYTE_ORDER) && !defined(__BYTE_ORDER)
+#define __BYTE_ORDER    BYTE_ORDER
+#endif
 
-//typedef __uint64_t uint64_t;
-//typedef __uint32_t uint32_t;
+#if defined(BIG_ENDIAN) && !defined(__BIG_ENDIAN)
+#define __BIG_ENDIAN	BIG_ENDIAN
 #endif
 
-// define missing byte swap macros
-#ifndef __bswap_32
-#define __bswap_32(x) \
-     ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >>  8) |               \
-     (((x) & 0x0000ff00) <<  8) | (((x) & 0x000000ff) << 24))
+#if defined(LITTLE_ENDIAN) && !defined(__LITTLE_ENDIAN)
+#define __LITTLE_ENDIAN	LITTLE_ENDIAN
 #endif
 
+#endif /* !WIN32 */
+
 // define default endianness
 #ifndef __LITTLE_ENDIAN
 #define __LITTLE_ENDIAN	1234


More information about the rtmpdump mailing list