intreadwrite.h

Go to the documentation of this file.
00001 /*
00002  * This file is part of FFmpeg.
00003  *
00004  * FFmpeg is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2.1 of the License, or (at your option) any later version.
00008  *
00009  * FFmpeg is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with FFmpeg; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00017  */
00018 
00019 #ifndef FFMPEG_INTREADWRITE_H
00020 #define FFMPEG_INTREADWRITE_H
00021 
00022 #include <stdint.h>
00023 #include "config.h"
00024 #include "bswap.h"
00025 
00026 #ifdef __GNUC__
00027 
00028 struct unaligned_64 { uint64_t l; } __attribute__((packed));
00029 struct unaligned_32 { uint32_t l; } __attribute__((packed));
00030 struct unaligned_16 { uint16_t l; } __attribute__((packed));
00031 
00032 #define AV_RN16(a) (((const struct unaligned_16 *) (a))->l)
00033 #define AV_RN32(a) (((const struct unaligned_32 *) (a))->l)
00034 #define AV_RN64(a) (((const struct unaligned_64 *) (a))->l)
00035 
00036 #define AV_WN16(a, b) (((struct unaligned_16 *) (a))->l) = (b)
00037 #define AV_WN32(a, b) (((struct unaligned_32 *) (a))->l) = (b)
00038 #define AV_WN64(a, b) (((struct unaligned_64 *) (a))->l) = (b)
00039 
00040 #elif defined(__DECC)
00041 
00042 #define AV_RN16(a) (*((const __unaligned uint16_t*)(a)))
00043 #define AV_RN32(a) (*((const __unaligned uint32_t*)(a)))
00044 #define AV_RN64(a) (*((const __unaligned uint64_t*)(a)))
00045 
00046 #define AV_WN16(a, b) *((__unaligned uint16_t*)(a)) = (b)
00047 #define AV_WN32(a, b) *((__unaligned uint32_t*)(a)) = (b)
00048 #define AV_WN64(a, b) *((__unaligned uint64_t*)(a)) = (b)
00049 
00050 #else
00051 
00052 #define AV_RN16(a) (*((const uint16_t*)(a)))
00053 #define AV_RN32(a) (*((const uint32_t*)(a)))
00054 #define AV_RN64(a) (*((const uint64_t*)(a)))
00055 
00056 #define AV_WN16(a, b) *((uint16_t*)(a)) = (b)
00057 #define AV_WN32(a, b) *((uint32_t*)(a)) = (b)
00058 #define AV_WN64(a, b) *((uint64_t*)(a)) = (b)
00059 
00060 #endif /* !__GNUC__ */
00061 
00062 /* endian macros */
00063 #define AV_RB8(x)     (((const uint8_t*)(x))[0])
00064 #define AV_WB8(p, d)  do { ((uint8_t*)(p))[0] = (d); } while(0)
00065 
00066 #define AV_RL8(x)     AV_RB8(x)
00067 #define AV_WL8(p, d)  AV_WB8(p, d)
00068 
00069 #ifdef HAVE_FAST_UNALIGNED
00070 # ifdef WORDS_BIGENDIAN
00071 #  define AV_RB16(x)    AV_RN16(x)
00072 #  define AV_WB16(p, d) AV_WN16(p, d)
00073 
00074 #  define AV_RL16(x)    bswap_16(AV_RN16(x))
00075 #  define AV_WL16(p, d) AV_WN16(p, bswap_16(d))
00076 
00077 #  define AV_RB32(x)    AV_RN32(x)
00078 #  define AV_WB32(p, d) AV_WN32(p, d)
00079 
00080 #  define AV_RL32(x)    bswap_32(AV_RN32(x))
00081 #  define AV_WL32(p, d) AV_WN32(p, bswap_32(d))
00082 
00083 #  define AV_RB64(x)    AV_RN64(x)
00084 #  define AV_WB64(p, d) AV_WN64(p, d)
00085 
00086 #  define AV_RL64(x)    bswap_64(AV_RN64(x))
00087 #  define AV_WL64(p, d) AV_WN64(p, bswap_64(d))
00088 # else /* WORDS_BIGENDIAN */
00089 #  define AV_RB16(x)    bswap_16(AV_RN16(x))
00090 #  define AV_WB16(p, d) AV_WN16(p, bswap_16(d))
00091 
00092 #  define AV_RL16(x)    AV_RN16(x)
00093 #  define AV_WL16(p, d) AV_WN16(p, d)
00094 
00095 #  define AV_RB32(x)    bswap_32(AV_RN32(x))
00096 #  define AV_WB32(p, d) AV_WN32(p, bswap_32(d))
00097 
00098 #  define AV_RL32(x)    AV_RN32(x)
00099 #  define AV_WL32(p, d) AV_WN32(p, d)
00100 
00101 #  define AV_RB64(x)    bswap_64(AV_RN64(x))
00102 #  define AV_WB64(p, d) AV_WN64(p, bswap_64(d))
00103 
00104 #  define AV_RL64(x)    AV_RN64(x)
00105 #  define AV_WL64(p, d) AV_WN64(p, d)
00106 # endif
00107 #else /* HAVE_FAST_UNALIGNED */
00108 #define AV_RB16(x)  ((((const uint8_t*)(x))[0] << 8) | ((const uint8_t*)(x))[1])
00109 #define AV_WB16(p, d) do { \
00110                     ((uint8_t*)(p))[1] = (d); \
00111                     ((uint8_t*)(p))[0] = (d)>>8; } while(0)
00112 
00113 #define AV_RL16(x)  ((((const uint8_t*)(x))[1] << 8) | \
00114                       ((const uint8_t*)(x))[0])
00115 #define AV_WL16(p, d) do { \
00116                     ((uint8_t*)(p))[0] = (d); \
00117                     ((uint8_t*)(p))[1] = (d)>>8; } while(0)
00118 
00119 #define AV_RB32(x)  ((((const uint8_t*)(x))[0] << 24) | \
00120                      (((const uint8_t*)(x))[1] << 16) | \
00121                      (((const uint8_t*)(x))[2] <<  8) | \
00122                       ((const uint8_t*)(x))[3])
00123 #define AV_WB32(p, d) do { \
00124                     ((uint8_t*)(p))[3] = (d); \
00125                     ((uint8_t*)(p))[2] = (d)>>8; \
00126                     ((uint8_t*)(p))[1] = (d)>>16; \
00127                     ((uint8_t*)(p))[0] = (d)>>24; } while(0)
00128 
00129 #define AV_RL32(x) ((((const uint8_t*)(x))[3] << 24) | \
00130                     (((const uint8_t*)(x))[2] << 16) | \
00131                     (((const uint8_t*)(x))[1] <<  8) | \
00132                      ((const uint8_t*)(x))[0])
00133 #define AV_WL32(p, d) do { \
00134                     ((uint8_t*)(p))[0] = (d); \
00135                     ((uint8_t*)(p))[1] = (d)>>8; \
00136                     ((uint8_t*)(p))[2] = (d)>>16; \
00137                     ((uint8_t*)(p))[3] = (d)>>24; } while(0)
00138 
00139 #define AV_RB64(x)  (((uint64_t)((const uint8_t*)(x))[0] << 56) | \
00140                      ((uint64_t)((const uint8_t*)(x))[1] << 48) | \
00141                      ((uint64_t)((const uint8_t*)(x))[2] << 40) | \
00142                      ((uint64_t)((const uint8_t*)(x))[3] << 32) | \
00143                      ((uint64_t)((const uint8_t*)(x))[4] << 24) | \
00144                      ((uint64_t)((const uint8_t*)(x))[5] << 16) | \
00145                      ((uint64_t)((const uint8_t*)(x))[6] <<  8) | \
00146                       (uint64_t)((const uint8_t*)(x))[7])
00147 #define AV_WB64(p, d) do { \
00148                     ((uint8_t*)(p))[7] = (d);     \
00149                     ((uint8_t*)(p))[6] = (d)>>8;  \
00150                     ((uint8_t*)(p))[5] = (d)>>16; \
00151                     ((uint8_t*)(p))[4] = (d)>>24; \
00152                     ((uint8_t*)(p))[3] = (d)>>32; \
00153                     ((uint8_t*)(p))[2] = (d)>>40; \
00154                     ((uint8_t*)(p))[1] = (d)>>48; \
00155                     ((uint8_t*)(p))[0] = (d)>>56; } while(0)
00156 
00157 #define AV_RL64(x)  (((uint64_t)((const uint8_t*)(x))[7] << 56) | \
00158                      ((uint64_t)((const uint8_t*)(x))[6] << 48) | \
00159                      ((uint64_t)((const uint8_t*)(x))[5] << 40) | \
00160                      ((uint64_t)((const uint8_t*)(x))[4] << 32) | \
00161                      ((uint64_t)((const uint8_t*)(x))[3] << 24) | \
00162                      ((uint64_t)((const uint8_t*)(x))[2] << 16) | \
00163                      ((uint64_t)((const uint8_t*)(x))[1] <<  8) | \
00164                       (uint64_t)((const uint8_t*)(x))[0])
00165 #define AV_WL64(p, d) do { \
00166                     ((uint8_t*)(p))[0] = (d);     \
00167                     ((uint8_t*)(p))[1] = (d)>>8;  \
00168                     ((uint8_t*)(p))[2] = (d)>>16; \
00169                     ((uint8_t*)(p))[3] = (d)>>24; \
00170                     ((uint8_t*)(p))[4] = (d)>>32; \
00171                     ((uint8_t*)(p))[5] = (d)>>40; \
00172                     ((uint8_t*)(p))[6] = (d)>>48; \
00173                     ((uint8_t*)(p))[7] = (d)>>56; } while(0)
00174 #endif  /* HAVE_FAST_UNALIGNED */
00175 
00176 #define AV_RB24(x)  ((((const uint8_t*)(x))[0] << 16) | \
00177                      (((const uint8_t*)(x))[1] <<  8) | \
00178                       ((const uint8_t*)(x))[2])
00179 #define AV_WB24(p, d) do { \
00180                     ((uint8_t*)(p))[2] = (d); \
00181                     ((uint8_t*)(p))[1] = (d)>>8; \
00182                     ((uint8_t*)(p))[0] = (d)>>16; } while(0)
00183 
00184 #define AV_RL24(x)  ((((const uint8_t*)(x))[2] << 16) | \
00185                      (((const uint8_t*)(x))[1] <<  8) | \
00186                       ((const uint8_t*)(x))[0])
00187 #define AV_WL24(p, d) do { \
00188                     ((uint8_t*)(p))[0] = (d); \
00189                     ((uint8_t*)(p))[1] = (d)>>8; \
00190                     ((uint8_t*)(p))[2] = (d)>>16; } while(0)
00191 
00192 #endif /* FFMPEG_INTREADWRITE_H */

Generated on Thu Nov 20 06:44:44 2008 for libextractor by  doxygen 1.5.1