summaryrefslogtreecommitdiffstats
path: root/osdep
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-07-10 00:49:01 +0200
committerwm4 <wm4@nowhere>2014-07-10 00:58:56 +0200
commit1a1e631ccd561afdea31e2fb2f4982b3fdc81432 (patch)
treeba93a1718d46bcd93d7f9707b1d839d24a554a57 /osdep
parent2e6a8f260ca169e2e1a5646eecfc322de6f77307 (diff)
downloadmpv-1a1e631ccd561afdea31e2fb2f4982b3fdc81432.tar.bz2
mpv-1a1e631ccd561afdea31e2fb2f4982b3fdc81432.tar.xz
build: deal with endian mess
There is no standard mechanism for detecting endianess. Doing it at compile time in a portable way is probably hard. Doing it properly with a configure check is probably hard too. Using the endian definitions in <sys/types.h> (usually includes <endian.h>, which is not available everywhere) works under circumstances, but the previous commit broke it on OSX. Ideally all code should be endian dependent, but that is not possible due to the dependencies (such as FFmpeg, some video output APIs, some audio output APIs). Create a header osdep/endian.h, which contains various fallbacks. Note that the last fallback uses libavutil; however, it's not clear whether AV_HAVE_BIGENDIAN is a public symbol, or whether including <libavutil/bswap.h> really makes it visible. And in fact we don't want to pollute the namespace with libavutil definitions either. Thus it's only the last fallback.
Diffstat (limited to 'osdep')
-rw-r--r--osdep/endian.h31
1 files changed, 31 insertions, 0 deletions
diff --git a/osdep/endian.h b/osdep/endian.h
new file mode 100644
index 0000000000..b600f1c281
--- /dev/null
+++ b/osdep/endian.h
@@ -0,0 +1,31 @@
+#ifndef MP_ENDIAN_H_
+#define MP_ENDIAN_H_
+
+#include <sys/types.h>
+
+#if !defined(BYTE_ORDER)
+
+#if defined(__BYTE_ORDER)
+#define BYTE_ORDER __BYTE_ORDER
+#define LITTLE_ENDIAN __LITTLE_ENDIAN
+#define BIG_ENDIAN __BIG_ENDIAN
+#elif defined(__DARWIN_BYTE_ORDER)
+#define BYTE_ORDER __DARWIN_BYTE_ORDER
+#define LITTLE_ENDIAN __DARWIN_LITTLE_ENDIAN
+#define BIG_ENDIAN __DARWIN_BIG_ENDIAN
+#else
+#include <libavutil/bswap.h>
+#if AV_HAVE_BIGENDIAN
+#define BYTE_ORDER 1234
+#define LITTLE_ENDIAN 4321
+#define BIG_ENDIAN 1234
+#else
+#define BYTE_ORDER 1234
+#define LITTLE_ENDIAN 1234
+#define BIG_ENDIAN 4321
+#endif
+#endif
+
+#endif /* !defined(BYTE_ORDER) */
+
+#endif