[MPlayer-dev-eng] [PATCH] float endianness fixes

Reimar Döffinger Reimar.Doeffinger at stud.uni-karlsruhe.de
Tue Jul 12 20:29:22 CEST 2005


Hi,
I think I finally understood those float endianness issues. For all
platforms that we support I think float endianness == int endianness,
what had me irritated was that the stream_read_qword function in ebml.c
already does a big endian -> host endian conversion!
So attached is a patch that hopefully fixes the remaining issues. Can
somebody please test thoroughly?

Greetings,
Reimar Döffinger
-------------- next part --------------
Index: bswap.h
===================================================================
RCS file: /cvsroot/mplayer/main/bswap.h,v
retrieving revision 1.5
diff -u -r1.5 bswap.h
--- bswap.h	21 Oct 2004 11:55:19 -0000	1.5
+++ bswap.h	12 Jul 2005 18:23:36 -0000
@@ -117,6 +117,37 @@
 
 #endif	/* !HAVE_BYTESWAP_H */
 
+static float inline bswap_flt(float x) {
+  union {uint32_t i; float f;} u;
+  u.f = x;
+  u.i = bswap_32(u.i);
+  return u.f;
+}
+
+static double inline bswap_dbl(double x) {
+  union {uint64_t i; double d;} u;
+  u.d = x;
+  u.i = bswap_64(u.i);
+  return u.d;
+}
+
+static long double inline bswap_ldbl(long double x) {
+  union {char d[10]; long double ld;} uin;
+  union {char d[10]; long double ld;} uout;
+  uin.ld = x;
+  uout.d[0] = uin.d[9];
+  uout.d[1] = uin.d[8];
+  uout.d[2] = uin.d[7];
+  uout.d[3] = uin.d[6];
+  uout.d[4] = uin.d[5];
+  uout.d[5] = uin.d[4];
+  uout.d[6] = uin.d[3];
+  uout.d[7] = uin.d[2];
+  uout.d[8] = uin.d[1];
+  uout.d[9] = uin.d[0];
+  return uout.ld;
+}
+
 // be2me ... BigEndian to MachineEndian
 // le2me ... LittleEndian to MachineEndian
 
@@ -127,6 +158,12 @@
 #define le2me_16(x) bswap_16(x)
 #define le2me_32(x) bswap_32(x)
 #define le2me_64(x) bswap_64(x)
+#define be2me_flt(x) (x)
+#define be2me_dbl(x) (x)
+#define be2me_ldbl(x) (x)
+#define le2me_flt(x) bswap_flt(x)
+#define le2me_dbl(x) bswap_dbl(x)
+#define le2me_ldbl(x) bswap_ldbl(x)
 #else
 #define be2me_16(x) bswap_16(x)
 #define be2me_32(x) bswap_32(x)
@@ -134,6 +171,12 @@
 #define le2me_16(x) (x)
 #define le2me_32(x) (x)
 #define le2me_64(x) (x)
+#define be2me_flt(x) bswap_flt(x)
+#define be2me_dbl(x) bswap_dbl(x)
+#define be2me_ldbl(x) bswap_ldbl(x)
+#define le2me_flt(x) (x)
+#define le2me_dbl(x) (x)
+#define le2me_ldbl(x) (x)
 #endif
 
 #endif /* __BSWAP_H__ */
Index: libmpdemux/ebml.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/ebml.c,v
retrieving revision 1.5
diff -u -r1.5 ebml.c
--- libmpdemux/ebml.c	10 Jul 2005 18:31:13 -0000	1.5
+++ libmpdemux/ebml.c	12 Jul 2005 18:23:50 -0000
@@ -12,6 +12,7 @@
 
 #include "stream.h"
 #include "ebml.h"
+#include "bswap.h"
 
 
 /*
@@ -194,7 +195,7 @@
         union {uint8_t data[10]; long double ld;} u;
         if (stream_read (s, u.data, 10) != 10)
           return EBML_FLOAT_INVALID;
-        value = u.ld;
+        value = be2me_ldbl(u.ld);
         break;
       }
 
Index: libmpdemux/nuppelvideo.h
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/nuppelvideo.h,v
retrieving revision 1.3
diff -u -r1.3 nuppelvideo.h
--- libmpdemux/nuppelvideo.h	25 May 2005 11:48:58 -0000	1.3
+++ libmpdemux/nuppelvideo.h	12 Jul 2005 18:23:50 -0000
@@ -92,12 +92,13 @@
     unsigned char *buffer_offset;
 } audbuffertyp;
 
-#ifdef WORDS_BIGENDIAN
 #define le2me_rtfileheader(h) {					\
     (h)->width = le2me_32((h)->width);				\
     (h)->height = le2me_32((h)->height);			\
     (h)->desiredwidth = le2me_32((h)->desiredwidth);		\
     (h)->desiredheight = le2me_32((h)->desiredheight);		\
+    (h)->aspect = le2me_dbl((h)->aspect);			\
+    (h)->fps = le2me_dbl((h)->fps);				\
     (h)->videoblocks = le2me_32((h)->videoblocks);		\
     (h)->audioblocks = le2me_32((h)->audioblocks);		\
     (h)->textsblocks = le2me_32((h)->textsblocks);		\
@@ -107,8 +108,4 @@
     (h)->timecode = le2me_32((h)->timecode);			\
     (h)->packetlength = le2me_32((h)->packetlength);		\
   }
-#else
-#define le2me_rtfileheader(h) /**/
-#define le2me_rtframeheader(h) /**/
-#endif
 


More information about the MPlayer-dev-eng mailing list