Add spa/utils/endian.h

This provides access to GNU C library-style endian and byteswap functions.

Windows doesn't provide pre-processor defines for endianness, but
all current Windows architectures (X32, X64, ARM) are little-endian.
This commit is contained in:
David Coles 2024-06-25 16:32:13 -07:00 committed by Wim Taymans
parent a97e8b6d1f
commit 5d7624001d
10 changed files with 35 additions and 30 deletions

View file

@ -5,9 +5,6 @@
#define __USE_GNU #define __USE_GNU
#include <limits.h> #include <limits.h>
#if !defined(__FreeBSD__) && !defined(__MidnightBSD__)
#include <byteswap.h>
#endif
#include <sys/shm.h> #include <sys/shm.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
@ -20,6 +17,7 @@
#include <spa/debug/types.h> #include <spa/debug/types.h>
#include <spa/param/props.h> #include <spa/param/props.h>
#include <spa/utils/atomic.h> #include <spa/utils/atomic.h>
#include <spa/utils/endian.h>
#include <spa/utils/result.h> #include <spa/utils/result.h>
#include <spa/utils/string.h> #include <spa/utils/string.h>
#include <spa/utils/json.h> #include <spa/utils/json.h>

View file

@ -9,9 +9,7 @@
extern "C" { extern "C" {
#endif #endif
#if !defined(__FreeBSD__) && !defined(__MidnightBSD__) #include <spa/utils/endian.h>
#include <endian.h>
#endif
/** /**
* \addtogroup spa_param * \addtogroup spa_param

View file

@ -11,9 +11,7 @@ extern "C" {
#include <stdint.h> #include <stdint.h>
#if !defined(__FreeBSD__) && !defined(__MidnightBSD__) #include <spa/utils/endian.h>
#include <endian.h>
#endif
/** /**
* \addtogroup spa_param * \addtogroup spa_param

View file

@ -0,0 +1,26 @@
/* Spa */
/* SPDX-FileCopyrightText: Copyright © 2019 Wim Taymans */
/* SPDX-License-Identifier: MIT */
#ifndef SPA_ENDIAN_H
#define SPA_ENDIAN_H
#if defined(__FreeBSD__) || defined(__MidnightBSD__)
#include <sys/endian.h>
#define bswap_16 bswap16
#define bswap_32 bswap32
#define bswap_64 bswap64
#elif defined(_MSC_VER) && defined(_WIN32)
#include <stdlib.h>
#define __LITTLE_ENDIAN 1234
#define __BIG_ENDIAN 4321
#define __BYTE_ORDER __LITTLE_ENDIAN
#define bswap_16 _byteswap_ushort
#define bswap_32 _byteswap_ulong
#define bswap_64 _byteswap_uint64
#else
#include <endian.h>
#include <byteswap.h>
#endif
#endif /* SPA_ENDIAN_H */

View file

@ -3,16 +3,9 @@
/* SPDX-License-Identifier: MIT */ /* SPDX-License-Identifier: MIT */
#include <math.h> #include <math.h>
#if defined(__FreeBSD__) || defined(__MidnightBSD__)
#include <sys/endian.h>
#define bswap_16 bswap16
#define bswap_32 bswap32
#define bswap_64 bswap64
#else
#include <byteswap.h>
#endif
#include <spa/utils/defs.h> #include <spa/utils/defs.h>
#include <spa/utils/endian.h>
#include <spa/utils/string.h> #include <spa/utils/string.h>
#define f32_round(a) lrintf(a) #define f32_round(a) lrintf(a)

View file

@ -7,12 +7,10 @@
#include <stddef.h> #include <stddef.h>
#include <errno.h> #include <errno.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#if __BYTE_ORDER != __LITTLE_ENDIAN
#include <byteswap.h>
#endif
#include <spa/param/audio/format.h> #include <spa/param/audio/format.h>
#include <spa/param/audio/format-utils.h> #include <spa/param/audio/format-utils.h>
#include <spa/utils/endian.h>
#include <sbc/sbc.h> #include <sbc/sbc.h>

View file

@ -7,12 +7,10 @@
#include <stddef.h> #include <stddef.h>
#include <errno.h> #include <errno.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#if __BYTE_ORDER != __LITTLE_ENDIAN
#include <byteswap.h>
#endif
#include <spa/param/audio/format.h> #include <spa/param/audio/format.h>
#include <spa/param/audio/format-utils.h> #include <spa/param/audio/format-utils.h>
#include <spa/utils/endian.h>
#ifdef HAVE_LC3PLUS_H #ifdef HAVE_LC3PLUS_H
#include <lc3plus.h> #include <lc3plus.h>

View file

@ -8,15 +8,13 @@
#include <stddef.h> #include <stddef.h>
#include <errno.h> #include <errno.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#if __BYTE_ORDER != __LITTLE_ENDIAN
#include <byteswap.h>
#endif
#include <spa/debug/types.h> #include <spa/debug/types.h>
#include <spa/param/audio/type-info.h> #include <spa/param/audio/type-info.h>
#include <spa/param/audio/raw.h> #include <spa/param/audio/raw.h>
#include <spa/utils/string.h> #include <spa/utils/string.h>
#include <spa/utils/dict.h> #include <spa/utils/dict.h>
#include <spa/utils/endian.h>
#include <spa/param/audio/format.h> #include <spa/param/audio/format.h>
#include <spa/param/audio/format-utils.h> #include <spa/param/audio/format-utils.h>

View file

@ -8,13 +8,11 @@
#include <stddef.h> #include <stddef.h>
#include <errno.h> #include <errno.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#if __BYTE_ORDER != __LITTLE_ENDIAN
#include <byteswap.h>
#endif
#include <spa/debug/types.h> #include <spa/debug/types.h>
#include <spa/param/audio/type-info.h> #include <spa/param/audio/type-info.h>
#include <spa/param/audio/raw.h> #include <spa/param/audio/raw.h>
#include <spa/utils/endian.h>
#include <spa/utils/string.h> #include <spa/utils/string.h>
#include <spa/utils/dict.h> #include <spa/utils/dict.h>
#include <spa/param/audio/format.h> #include <spa/param/audio/format.h>

View file

@ -1,5 +1,5 @@
#include <byteswap.h> #include <spa/utils/endian.h>
#ifdef HAVE_OPUS_CUSTOM #ifdef HAVE_OPUS_CUSTOM
#include <opus/opus.h> #include <opus/opus.h>