libplatform/endian.h Source File
MP4v2 Home
Documentation
API Reference
libplatform
endian.h
1
#ifndef MP4V2_PLATFORM_ENDIAN_H
2
#define MP4V2_PLATFORM_ENDIAN_H
3
5
6
#define MP4V2_BYTESWAP_16(x) \
7
mp4v2::platform::uint16_t( ((mp4v2::platform::uint16_t(x) & 0xff00U) >> 8) \
8
| ((mp4v2::platform::uint16_t(x) & 0x00ffU) << 8) )
9
10
#define MP4V2_BYTESWAP_32(x) \
11
mp4v2::platform::uint32_t( ((mp4v2::platform::uint32_t(x) & 0xff000000U) >> 24) \
12
| ((mp4v2::platform::uint32_t(x) & 0x00ff0000U) >> 8) \
13
| ((mp4v2::platform::uint32_t(x) & 0x0000ff00U) << 8) \
14
| ((mp4v2::platform::uint32_t(x) & 0x000000ffU) << 24) )
15
16
#define MP4V2_BYTESWAP_64(x) \
17
mp4v2::platform::uint64_t( ((mp4v2::platform::uint64_t(x) & 0xff00000000000000ULL) >> 56) \
18
| ((mp4v2::platform::uint64_t(x) & 0x00ff000000000000ULL) >> 40) \
19
| ((mp4v2::platform::uint64_t(x) & 0x0000ff0000000000ULL) >> 24) \
20
| ((mp4v2::platform::uint64_t(x) & 0x000000ff00000000ULL) >> 8) \
21
| ((mp4v2::platform::uint64_t(x) & 0x00000000ff000000ULL) << 8) \
22
| ((mp4v2::platform::uint64_t(x) & 0x0000000000ff0000ULL) << 24) \
23
| ((mp4v2::platform::uint64_t(x) & 0x000000000000ff00ULL) << 40) \
24
| ((mp4v2::platform::uint64_t(x) & 0x00000000000000ffULL) << 56) )
25
27
28
#if defined( __BIG_ENDIAN__ )
29
# define MP4V2_HTONS(x) (x)
30
# define MP4V2_HTONL(x) (x)
31
# define MP4V2_NTOHS(x) (x)
32
# define MP4V2_NTOHL(x) (x)
33
#else
34
# define MP4V2_HTONS(x) MP4V2_BYTESWAP_16(x)
35
# define MP4V2_HTONL(x) MP4V2_BYTESWAP_32(x)
36
# define MP4V2_NTOHS(x) MP4V2_BYTESWAP_16(x)
37
# define MP4V2_NTOHL(x) MP4V2_BYTESWAP_32(x)
38
#endif
39
41
42
#endif // MP4V2_PLATFORM_ENDIAN_H