• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

libavutil/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 AVUTIL_INTREADWRITE_H
00020 #define AVUTIL_INTREADWRITE_H
00021 
00022 #include <stdint.h>
00023 #include "config.h"
00024 #include "bswap.h"
00025 
00026 /*
00027  * Arch-specific headers can provide any combination of
00028  * AV_[RW][BLN](16|32|64) macros.  Preprocessor symbols must be
00029  * defined, even if these are implemented as inline functions.
00030  */
00031 
00032 #if   ARCH_ARM
00033 #   include "arm/intreadwrite.h"
00034 #endif
00035 
00036 /*
00037  * Define AV_[RW]N helper macros to simplify definitions not provided
00038  * by per-arch headers.
00039  */
00040 
00041 #if   defined(__GNUC__)
00042 
00043 struct unaligned_64 { uint64_t l; } __attribute__((packed));
00044 struct unaligned_32 { uint32_t l; } __attribute__((packed));
00045 struct unaligned_16 { uint16_t l; } __attribute__((packed));
00046 
00047 #   define AV_RN(s, p) (((const struct unaligned_##s *) (p))->l)
00048 #   define AV_WN(s, p, v) (((struct unaligned_##s *) (p))->l) = (v)
00049 
00050 #elif defined(__DECC)
00051 
00052 #   define AV_RN(s, p) (*((const __unaligned uint##s##_t*)(p)))
00053 #   define AV_WN(s, p, v) *((__unaligned uint##s##_t*)(p)) = (v)
00054 
00055 #elif HAVE_FAST_UNALIGNED
00056 
00057 #   define AV_RN(s, p) (*((const uint##s##_t*)(p)))
00058 #   define AV_WN(s, p, v) *((uint##s##_t*)(p)) = (v)
00059 
00060 #else
00061 
00062 #ifndef AV_RB16
00063 #define AV_RB16(x)  ((((const uint8_t*)(x))[0] << 8) | \
00064                       ((const uint8_t*)(x))[1])
00065 #endif
00066 #ifndef AV_WB16
00067 #define AV_WB16(p, d) do { \
00068                     ((uint8_t*)(p))[1] = (d); \
00069                     ((uint8_t*)(p))[0] = (d)>>8; } while(0)
00070 #endif
00071 
00072 #ifndef AV_RL16
00073 #define AV_RL16(x)  ((((const uint8_t*)(x))[1] << 8) | \
00074                       ((const uint8_t*)(x))[0])
00075 #endif
00076 #ifndef AV_WL16
00077 #define AV_WL16(p, d) do { \
00078                     ((uint8_t*)(p))[0] = (d); \
00079                     ((uint8_t*)(p))[1] = (d)>>8; } while(0)
00080 #endif
00081 
00082 #ifndef AV_RB32
00083 #define AV_RB32(x)  ((((const uint8_t*)(x))[0] << 24) | \
00084                      (((const uint8_t*)(x))[1] << 16) | \
00085                      (((const uint8_t*)(x))[2] <<  8) | \
00086                       ((const uint8_t*)(x))[3])
00087 #endif
00088 #ifndef AV_WB32
00089 #define AV_WB32(p, d) do { \
00090                     ((uint8_t*)(p))[3] = (d); \
00091                     ((uint8_t*)(p))[2] = (d)>>8; \
00092                     ((uint8_t*)(p))[1] = (d)>>16; \
00093                     ((uint8_t*)(p))[0] = (d)>>24; } while(0)
00094 #endif
00095 
00096 #ifndef AV_RL32
00097 #define AV_RL32(x) ((((const uint8_t*)(x))[3] << 24) | \
00098                     (((const uint8_t*)(x))[2] << 16) | \
00099                     (((const uint8_t*)(x))[1] <<  8) | \
00100                      ((const uint8_t*)(x))[0])
00101 #endif
00102 #ifndef AV_WL32
00103 #define AV_WL32(p, d) do { \
00104                     ((uint8_t*)(p))[0] = (d); \
00105                     ((uint8_t*)(p))[1] = (d)>>8; \
00106                     ((uint8_t*)(p))[2] = (d)>>16; \
00107                     ((uint8_t*)(p))[3] = (d)>>24; } while(0)
00108 #endif
00109 
00110 #ifndef AV_RB64
00111 #define AV_RB64(x)  (((uint64_t)((const uint8_t*)(x))[0] << 56) | \
00112                      ((uint64_t)((const uint8_t*)(x))[1] << 48) | \
00113                      ((uint64_t)((const uint8_t*)(x))[2] << 40) | \
00114                      ((uint64_t)((const uint8_t*)(x))[3] << 32) | \
00115                      ((uint64_t)((const uint8_t*)(x))[4] << 24) | \
00116                      ((uint64_t)((const uint8_t*)(x))[5] << 16) | \
00117                      ((uint64_t)((const uint8_t*)(x))[6] <<  8) | \
00118                       (uint64_t)((const uint8_t*)(x))[7])
00119 #endif
00120 #ifndef AV_WB64
00121 #define AV_WB64(p, d) do { \
00122                     ((uint8_t*)(p))[7] = (d);     \
00123                     ((uint8_t*)(p))[6] = (d)>>8;  \
00124                     ((uint8_t*)(p))[5] = (d)>>16; \
00125                     ((uint8_t*)(p))[4] = (d)>>24; \
00126                     ((uint8_t*)(p))[3] = (d)>>32; \
00127                     ((uint8_t*)(p))[2] = (d)>>40; \
00128                     ((uint8_t*)(p))[1] = (d)>>48; \
00129                     ((uint8_t*)(p))[0] = (d)>>56; } while(0)
00130 #endif
00131 
00132 #ifndef AV_RL64
00133 #define AV_RL64(x)  (((uint64_t)((const uint8_t*)(x))[7] << 56) | \
00134                      ((uint64_t)((const uint8_t*)(x))[6] << 48) | \
00135                      ((uint64_t)((const uint8_t*)(x))[5] << 40) | \
00136                      ((uint64_t)((const uint8_t*)(x))[4] << 32) | \
00137                      ((uint64_t)((const uint8_t*)(x))[3] << 24) | \
00138                      ((uint64_t)((const uint8_t*)(x))[2] << 16) | \
00139                      ((uint64_t)((const uint8_t*)(x))[1] <<  8) | \
00140                       (uint64_t)((const uint8_t*)(x))[0])
00141 #endif
00142 #ifndef AV_WL64
00143 #define AV_WL64(p, d) do { \
00144                     ((uint8_t*)(p))[0] = (d);     \
00145                     ((uint8_t*)(p))[1] = (d)>>8;  \
00146                     ((uint8_t*)(p))[2] = (d)>>16; \
00147                     ((uint8_t*)(p))[3] = (d)>>24; \
00148                     ((uint8_t*)(p))[4] = (d)>>32; \
00149                     ((uint8_t*)(p))[5] = (d)>>40; \
00150                     ((uint8_t*)(p))[6] = (d)>>48; \
00151                     ((uint8_t*)(p))[7] = (d)>>56; } while(0)
00152 #endif
00153 
00154 #ifdef WORDS_BIGENDIAN
00155 #   define AV_RN(s, p)    AV_RB##s(p)
00156 #   define AV_WN(s, p, v) AV_WB##s(p, v)
00157 #else
00158 #   define AV_RN(s, p)    AV_RL##s(p)
00159 #   define AV_WN(s, p, v) AV_WL##s(p, v)
00160 #endif
00161 
00162 #endif /* HAVE_FAST_UNALIGNED */
00163 
00164 #ifndef AV_RN16
00165 #   define AV_RN16(p) AV_RN(16, p)
00166 #endif
00167 
00168 #ifndef AV_RN32
00169 #   define AV_RN32(p) AV_RN(32, p)
00170 #endif
00171 
00172 #ifndef AV_RN64
00173 #   define AV_RN64(p) AV_RN(64, p)
00174 #endif
00175 
00176 #ifndef AV_WN16
00177 #   define AV_WN16(p, v) AV_WN(16, p, v)
00178 #endif
00179 
00180 #ifndef AV_WN32
00181 #   define AV_WN32(p, v) AV_WN(32, p, v)
00182 #endif
00183 
00184 #ifndef AV_WN64
00185 #   define AV_WN64(p, v) AV_WN(64, p, v)
00186 #endif
00187 
00188 #ifdef WORDS_BIGENDIAN
00189 #   define AV_RB(s, p)    AV_RN(s, p)
00190 #   define AV_WB(s, p, v) AV_WN(s, p, v)
00191 #   define AV_RL(s, p)    bswap_##s(AV_RN(s, p))
00192 #   define AV_WL(s, p, v) AV_WN(s, p, bswap_##s(v))
00193 #else
00194 #   define AV_RB(s, p)    bswap_##s(AV_RN(s, p))
00195 #   define AV_WB(s, p, v) AV_WN(s, p, bswap_##s(v))
00196 #   define AV_RL(s, p)    AV_RN(s, p)
00197 #   define AV_WL(s, p, v) AV_WN(s, p, v)
00198 #endif
00199 
00200 #define AV_RB8(x)     (((const uint8_t*)(x))[0])
00201 #define AV_WB8(p, d)  do { ((uint8_t*)(p))[0] = (d); } while(0)
00202 
00203 #define AV_RL8(x)     AV_RB8(x)
00204 #define AV_WL8(p, d)  AV_WB8(p, d)
00205 
00206 #ifndef AV_RB16
00207 #   define AV_RB16(p)    AV_RB(16, p)
00208 #endif
00209 #ifndef AV_WB16
00210 #   define AV_WB16(p, v) AV_WB(16, p, v)
00211 #endif
00212 
00213 #ifndef AV_RL16
00214 #   define AV_RL16(p)    AV_RL(16, p)
00215 #endif
00216 #ifndef AV_WL16
00217 #   define AV_WL16(p, v) AV_WL(16, p, v)
00218 #endif
00219 
00220 #ifndef AV_RB32
00221 #   define AV_RB32(p)    AV_RB(32, p)
00222 #endif
00223 #ifndef AV_WB32
00224 #   define AV_WB32(p, v) AV_WB(32, p, v)
00225 #endif
00226 
00227 #ifndef AV_RL32
00228 #   define AV_RL32(p)    AV_RL(32, p)
00229 #endif
00230 #ifndef AV_WL32
00231 #   define AV_WL32(p, v) AV_WL(32, p, v)
00232 #endif
00233 
00234 #ifndef AV_RB64
00235 #   define AV_RB64(p)    AV_RB(64, p)
00236 #endif
00237 #ifndef AV_WB64
00238 #   define AV_WB64(p, v) AV_WB(64, p, v)
00239 #endif
00240 
00241 #ifndef AV_RL64
00242 #   define AV_RL64(p)    AV_RL(64, p)
00243 #endif
00244 #ifndef AV_WL64
00245 #   define AV_WL64(p, v) AV_WL(64, p, v)
00246 #endif
00247 
00248 #define AV_RB24(x)  ((((const uint8_t*)(x))[0] << 16) | \
00249                      (((const uint8_t*)(x))[1] <<  8) | \
00250                       ((const uint8_t*)(x))[2])
00251 #define AV_WB24(p, d) do { \
00252                     ((uint8_t*)(p))[2] = (d); \
00253                     ((uint8_t*)(p))[1] = (d)>>8; \
00254                     ((uint8_t*)(p))[0] = (d)>>16; } while(0)
00255 
00256 #define AV_RL24(x)  ((((const uint8_t*)(x))[2] << 16) | \
00257                      (((const uint8_t*)(x))[1] <<  8) | \
00258                       ((const uint8_t*)(x))[0])
00259 #define AV_WL24(p, d) do { \
00260                     ((uint8_t*)(p))[0] = (d); \
00261                     ((uint8_t*)(p))[1] = (d)>>8; \
00262                     ((uint8_t*)(p))[2] = (d)>>16; } while(0)
00263 
00264 #endif /* AVUTIL_INTREADWRITE_H */

Generated on Tue Nov 4 2014 12:59:24 for ffmpeg by  doxygen 1.7.1