Libav
|
00001 /* 00002 * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at> 00003 * 00004 * This file is part of FFmpeg. 00005 * 00006 * FFmpeg is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 * FFmpeg is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with FFmpeg; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00019 */ 00020 00026 #ifndef AVUTIL_BSWAP_H 00027 #define AVUTIL_BSWAP_H 00028 00029 #include <stdint.h> 00030 #include "config.h" 00031 #include "attributes.h" 00032 00033 #if ARCH_ARM 00034 # include "arm/bswap.h" 00035 #elif ARCH_AVR32 00036 # include "avr32/bswap.h" 00037 #elif ARCH_BFIN 00038 # include "bfin/bswap.h" 00039 #elif ARCH_SH4 00040 # include "sh4/bswap.h" 00041 #elif ARCH_X86 00042 # include "x86/bswap.h" 00043 #endif 00044 00045 #define AV_BSWAP16C(x) (((x) << 8 & 0xff00) | ((x) >> 8 & 0x00ff)) 00046 #define AV_BSWAP32C(x) (AV_BSWAP16C(x) << 16 | AV_BSWAP16C((x) >> 16)) 00047 #define AV_BSWAP64C(x) (AV_BSWAP32C(x) << 32 | AV_BSWAP32C((x) >> 32)) 00048 00049 #define AV_BSWAPC(s, x) AV_BSWAP##s##C(x) 00050 00051 #ifndef bswap_16 00052 static av_always_inline av_const uint16_t bswap_16(uint16_t x) 00053 { 00054 x= (x>>8) | (x<<8); 00055 return x; 00056 } 00057 #endif 00058 00059 #ifndef bswap_32 00060 static av_always_inline av_const uint32_t bswap_32(uint32_t x) 00061 { 00062 x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF); 00063 x= (x>>16) | (x<<16); 00064 return x; 00065 } 00066 #endif 00067 00068 #ifndef bswap_64 00069 static inline uint64_t av_const bswap_64(uint64_t x) 00070 { 00071 #if 0 00072 x= ((x<< 8)&0xFF00FF00FF00FF00ULL) | ((x>> 8)&0x00FF00FF00FF00FFULL); 00073 x= ((x<<16)&0xFFFF0000FFFF0000ULL) | ((x>>16)&0x0000FFFF0000FFFFULL); 00074 return (x>>32) | (x<<32); 00075 #else 00076 union { 00077 uint64_t ll; 00078 uint32_t l[2]; 00079 } w, r; 00080 w.ll = x; 00081 r.l[0] = bswap_32 (w.l[1]); 00082 r.l[1] = bswap_32 (w.l[0]); 00083 return r.ll; 00084 #endif 00085 } 00086 #endif 00087 00088 // be2me ... big-endian to machine-endian 00089 // le2me ... little-endian to machine-endian 00090 00091 #if HAVE_BIGENDIAN 00092 #define be2me_16(x) (x) 00093 #define be2me_32(x) (x) 00094 #define be2me_64(x) (x) 00095 #define le2me_16(x) bswap_16(x) 00096 #define le2me_32(x) bswap_32(x) 00097 #define le2me_64(x) bswap_64(x) 00098 #define AV_BE2MEC(s, x) (x) 00099 #define AV_LE2MEC(s, x) AV_BSWAPC(s, x) 00100 #else 00101 #define be2me_16(x) bswap_16(x) 00102 #define be2me_32(x) bswap_32(x) 00103 #define be2me_64(x) bswap_64(x) 00104 #define le2me_16(x) (x) 00105 #define le2me_32(x) (x) 00106 #define le2me_64(x) (x) 00107 #define AV_BE2MEC(s, x) AV_BSWAPC(s, x) 00108 #define AV_LE2MEC(s, x) (x) 00109 #endif 00110 00111 #define AV_BE2ME16C(x) AV_BE2MEC(16, x) 00112 #define AV_BE2ME32C(x) AV_BE2MEC(32, x) 00113 #define AV_BE2ME64C(x) AV_BE2MEC(64, x) 00114 #define AV_LE2ME16C(x) AV_LE2MEC(16, x) 00115 #define AV_LE2ME32C(x) AV_LE2MEC(32, x) 00116 #define AV_LE2ME64C(x) AV_LE2MEC(64, x) 00117 00118 #endif /* AVUTIL_BSWAP_H */