00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef FFMPEG_INTREADWRITE_H
00020 #define FFMPEG_INTREADWRITE_H
00021
00022 #include <stdint.h>
00023 #include "bswap.h"
00024
00025 #ifdef __GNUC__
00026
00027 struct unaligned_64 { uint64_t l; } __attribute__((packed));
00028 struct unaligned_32 { uint32_t l; } __attribute__((packed));
00029 struct unaligned_16 { uint16_t l; } __attribute__((packed));
00030
00031 #define AV_RN16(a) (((const struct unaligned_16 *) (a))->l)
00032 #define AV_RN32(a) (((const struct unaligned_32 *) (a))->l)
00033 #define AV_RN64(a) (((const struct unaligned_64 *) (a))->l)
00034
00035 #define AV_WN16(a, b) (((struct unaligned_16 *) (a))->l) = (b)
00036 #define AV_WN32(a, b) (((struct unaligned_32 *) (a))->l) = (b)
00037 #define AV_WN64(a, b) (((struct unaligned_64 *) (a))->l) = (b)
00038
00039 #else
00040
00041 #define AV_RN16(a) (*((const uint16_t*)(a)))
00042 #define AV_RN32(a) (*((const uint32_t*)(a)))
00043 #define AV_RN64(a) (*((const uint64_t*)(a)))
00044
00045 #define AV_WN16(a, b) *((uint16_t*)(a)) = (b)
00046 #define AV_WN32(a, b) *((uint32_t*)(a)) = (b)
00047 #define AV_WN64(a, b) *((uint64_t*)(a)) = (b)
00048
00049 #endif
00050
00051
00052 #define AV_RB8(x) (((const uint8_t*)(x))[0])
00053 #define AV_WB8(p, d) do { ((uint8_t*)(p))[0] = (d); } while(0)
00054
00055 #define AV_RL8(x) AV_RB8(x)
00056 #define AV_WL8(p, d) AV_WB8(p, d)
00057
00058 #ifdef HAVE_FAST_UNALIGNED
00059 # ifdef WORDS_BIGENDIAN
00060 # define AV_RB16(x) AV_RN16(x)
00061 # define AV_WB16(p, d) AV_WN16(p, d)
00062
00063 # define AV_RL16(x) bswap_16(AV_RN16(x))
00064 # define AV_WL16(p, d) AV_WN16(p, bswap_16(d))
00065 # else
00066 # define AV_RB16(x) bswap_16(AV_RN16(x))
00067 # define AV_WB16(p, d) AV_WN16(p, bswap_16(d))
00068
00069 # define AV_RL16(x) AV_RN16(x)
00070 # define AV_WL16(p, d) AV_WN16(p, d)
00071 # endif
00072 #else
00073 #define AV_RB16(x) ((((const uint8_t*)(x))[0] << 8) | ((const uint8_t*)(x))[1])
00074 #define AV_WB16(p, d) do { \
00075 ((uint8_t*)(p))[1] = (d); \
00076 ((uint8_t*)(p))[0] = (d)>>8; } while(0)
00077
00078 #define AV_RL16(x) ((((const uint8_t*)(x))[1] << 8) | \
00079 ((const uint8_t*)(x))[0])
00080 #define AV_WL16(p, d) do { \
00081 ((uint8_t*)(p))[0] = (d); \
00082 ((uint8_t*)(p))[1] = (d)>>8; } while(0)
00083 #endif
00084
00085 #define AV_RB24(x) ((((const uint8_t*)(x))[0] << 16) | \
00086 (((const uint8_t*)(x))[1] << 8) | \
00087 ((const uint8_t*)(x))[2])
00088 #define AV_WB24(p, d) do { \
00089 ((uint8_t*)(p))[2] = (d); \
00090 ((uint8_t*)(p))[1] = (d)>>8; \
00091 ((uint8_t*)(p))[0] = (d)>>16; } while(0)
00092
00093 #define AV_RL24(x) ((((const uint8_t*)(x))[2] << 16) | \
00094 (((const uint8_t*)(x))[1] << 8) | \
00095 ((const uint8_t*)(x))[0])
00096 #define AV_WL24(p, d) do { \
00097 ((uint8_t*)(p))[0] = (d); \
00098 ((uint8_t*)(p))[1] = (d)>>8; \
00099 ((uint8_t*)(p))[2] = (d)>>16; } while(0)
00100
00101 #ifdef HAVE_FAST_UNALIGNED
00102 # ifdef WORDS_BIGENDIAN
00103 # define AV_RB32(x) AV_RN32(x)
00104 # define AV_WB32(p, d) AV_WN32(p, d)
00105
00106 # define AV_RL32(x) bswap_32(AV_RN32(x))
00107 # define AV_WL32(p, d) AV_WN32(p, bswap_32(d))
00108 # else
00109 # define AV_RB32(x) bswap_32(AV_RN32(x))
00110 # define AV_WB32(p, d) AV_WN32(p, bswap_32(d))
00111
00112 # define AV_RL32(x) AV_RN32(x)
00113 # define AV_WL32(p, d) AV_WN32(p, d)
00114 # endif
00115 #else
00116 #define AV_RB32(x) ((((const uint8_t*)(x))[0] << 24) | \
00117 (((const uint8_t*)(x))[1] << 16) | \
00118 (((const uint8_t*)(x))[2] << 8) | \
00119 ((const uint8_t*)(x))[3])
00120 #define AV_WB32(p, d) do { \
00121 ((uint8_t*)(p))[3] = (d); \
00122 ((uint8_t*)(p))[2] = (d)>>8; \
00123 ((uint8_t*)(p))[1] = (d)>>16; \
00124 ((uint8_t*)(p))[0] = (d)>>24; } while(0)
00125
00126 #define AV_RL32(x) ((((const uint8_t*)(x))[3] << 24) | \
00127 (((const uint8_t*)(x))[2] << 16) | \
00128 (((const uint8_t*)(x))[1] << 8) | \
00129 ((const uint8_t*)(x))[0])
00130 #define AV_WL32(p, d) do { \
00131 ((uint8_t*)(p))[0] = (d); \
00132 ((uint8_t*)(p))[1] = (d)>>8; \
00133 ((uint8_t*)(p))[2] = (d)>>16; \
00134 ((uint8_t*)(p))[3] = (d)>>24; } while(0)
00135 #endif
00136
00137 #ifdef HAVE_FAST_UNALIGNED
00138 # ifdef WORDS_BIGENDIAN
00139 # define AV_RB64(x) AV_RN64(x)
00140 # define AV_WB64(p, d) AV_WN64(p, d)
00141
00142 # define AV_RL64(x) bswap_64(AV_RN64(x))
00143 # define AV_WL64(p, d) AV_WN64(p, bswap_64(d))
00144 # else
00145 # define AV_RB64(x) bswap_64(AV_RN64(x))
00146 # define AV_WB64(p, d) AV_WN64(p, bswap_64(d))
00147
00148 # define AV_RL64(x) AV_RN64(x)
00149 # define AV_WL64(p, d) AV_WN64(p, d)
00150 # endif
00151 #else
00152 #define AV_RB64(x) (((uint64_t)((const uint8_t*)(x))[0] << 56) | \
00153 ((uint64_t)((const uint8_t*)(x))[1] << 48) | \
00154 ((uint64_t)((const uint8_t*)(x))[2] << 40) | \
00155 ((uint64_t)((const uint8_t*)(x))[3] << 32) | \
00156 ((uint64_t)((const uint8_t*)(x))[4] << 24) | \
00157 ((uint64_t)((const uint8_t*)(x))[5] << 16) | \
00158 ((uint64_t)((const uint8_t*)(x))[6] << 8) | \
00159 (uint64_t)((const uint8_t*)(x))[7])
00160 #define AV_WB64(p, d) do { \
00161 ((uint8_t*)(p))[7] = (d); \
00162 ((uint8_t*)(p))[6] = (d)>>8; \
00163 ((uint8_t*)(p))[5] = (d)>>16; \
00164 ((uint8_t*)(p))[4] = (d)>>24; \
00165 ((uint8_t*)(p))[3] = (d)>>32; \
00166 ((uint8_t*)(p))[2] = (d)>>40; \
00167 ((uint8_t*)(p))[1] = (d)>>48; \
00168 ((uint8_t*)(p))[0] = (d)>>56; } while(0)
00169
00170 #define AV_RL64(x) (((uint64_t)((const uint8_t*)(x))[7] << 56) | \
00171 ((uint64_t)((const uint8_t*)(x))[6] << 48) | \
00172 ((uint64_t)((const uint8_t*)(x))[5] << 40) | \
00173 ((uint64_t)((const uint8_t*)(x))[4] << 32) | \
00174 ((uint64_t)((const uint8_t*)(x))[3] << 24) | \
00175 ((uint64_t)((const uint8_t*)(x))[2] << 16) | \
00176 ((uint64_t)((const uint8_t*)(x))[1] << 8) | \
00177 (uint64_t)((const uint8_t*)(x))[0])
00178 #define AV_WL64(p, d) do { \
00179 ((uint8_t*)(p))[0] = (d); \
00180 ((uint8_t*)(p))[1] = (d)>>8; \
00181 ((uint8_t*)(p))[2] = (d)>>16; \
00182 ((uint8_t*)(p))[3] = (d)>>24; \
00183 ((uint8_t*)(p))[4] = (d)>>32; \
00184 ((uint8_t*)(p))[5] = (d)>>40; \
00185 ((uint8_t*)(p))[6] = (d)>>48; \
00186 ((uint8_t*)(p))[7] = (d)>>56; } while(0)
00187 #endif
00188
00189 #endif