00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00026 #ifndef AVUTIL_BSWAP_H
00027 #define AVUTIL_BSWAP_H
00028
00029 #include <stdint.h>
00030 #include "libavutil/avconfig.h"
00031 #include "attributes.h"
00032
00033 #ifdef HAVE_AV_CONFIG_H
00034
00035 #include "config.h"
00036
00037 #if ARCH_ARM
00038 # include "arm/bswap.h"
00039 #elif ARCH_AVR32
00040 # include "avr32/bswap.h"
00041 #elif ARCH_BFIN
00042 # include "bfin/bswap.h"
00043 #elif ARCH_SH4
00044 # include "sh4/bswap.h"
00045 #elif ARCH_X86
00046 # include "x86/bswap.h"
00047 #endif
00048
00049 #endif
00050
00051 #define AV_BSWAP16C(x) (((x) << 8 & 0xff00) | ((x) >> 8 & 0x00ff))
00052 #define AV_BSWAP32C(x) (AV_BSWAP16C(x) << 16 | AV_BSWAP16C((x) >> 16))
00053 #define AV_BSWAP64C(x) (AV_BSWAP32C(x) << 32 | AV_BSWAP32C((x) >> 32))
00054
00055 #define AV_BSWAPC(s, x) AV_BSWAP##s##C(x)
00056
00057 #ifndef av_bswap16
00058 static av_always_inline av_const uint16_t av_bswap16(uint16_t x)
00059 {
00060 x= (x>>8) | (x<<8);
00061 return x;
00062 }
00063 #endif
00064
00065 #ifndef av_bswap32
00066 static av_always_inline av_const uint32_t av_bswap32(uint32_t x)
00067 {
00068 return AV_BSWAP32C(x);
00069 }
00070 #endif
00071
00072 #ifndef av_bswap64
00073 static inline uint64_t av_const av_bswap64(uint64_t x)
00074 {
00075 return (uint64_t)av_bswap32(x) << 32 | av_bswap32(x >> 32);
00076 }
00077 #endif
00078
00079
00080
00081
00082 #if AV_HAVE_BIGENDIAN
00083 #define av_be2ne16(x) (x)
00084 #define av_be2ne32(x) (x)
00085 #define av_be2ne64(x) (x)
00086 #define av_le2ne16(x) av_bswap16(x)
00087 #define av_le2ne32(x) av_bswap32(x)
00088 #define av_le2ne64(x) av_bswap64(x)
00089 #define AV_BE2NEC(s, x) (x)
00090 #define AV_LE2NEC(s, x) AV_BSWAPC(s, x)
00091 #else
00092 #define av_be2ne16(x) av_bswap16(x)
00093 #define av_be2ne32(x) av_bswap32(x)
00094 #define av_be2ne64(x) av_bswap64(x)
00095 #define av_le2ne16(x) (x)
00096 #define av_le2ne32(x) (x)
00097 #define av_le2ne64(x) (x)
00098 #define AV_BE2NEC(s, x) AV_BSWAPC(s, x)
00099 #define AV_LE2NEC(s, x) (x)
00100 #endif
00101
00102 #define AV_BE2NE16C(x) AV_BE2NEC(16, x)
00103 #define AV_BE2NE32C(x) AV_BE2NEC(32, x)
00104 #define AV_BE2NE64C(x) AV_BE2NEC(64, x)
00105 #define AV_LE2NE16C(x) AV_LE2NEC(16, x)
00106 #define AV_LE2NE32C(x) AV_LE2NEC(32, x)
00107 #define AV_LE2NE64C(x) AV_LE2NEC(64, x)
00108
00109 #endif