mirror of
https://github.com/mpv-player/mpv
synced 2024-12-22 06:42:03 +00:00
1a1e631ccd
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.
32 lines
697 B
C
32 lines
697 B
C
#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
|