• 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 #include "common.h"
00026 
00027 typedef union {
00028     uint64_t u64;
00029     uint32_t u32[2];
00030     uint16_t u16[4];
00031     uint8_t  u8 [8];
00032     double   f64;
00033     float    f32[2];
00034 } av_alias av_alias64;
00035 
00036 typedef union {
00037     uint32_t u32;
00038     uint16_t u16[2];
00039     uint8_t  u8 [4];
00040     float    f32;
00041 } av_alias av_alias32;
00042 
00043 typedef union {
00044     uint16_t u16;
00045     uint8_t  u8 [2];
00046 } av_alias av_alias16;
00047 
00048 /*
00049  * Arch-specific headers can provide any combination of
00050  * AV_[RW][BLN](16|24|32|64) and AV_(COPY|SWAP|ZERO)(64|128) macros.
00051  * Preprocessor symbols must be defined, even if these are implemented
00052  * as inline functions.
00053  */
00054 
00055 #if   ARCH_ARM
00056 #   include "arm/intreadwrite.h"
00057 #elif ARCH_AVR32
00058 #   include "avr32/intreadwrite.h"
00059 #elif ARCH_MIPS
00060 #   include "mips/intreadwrite.h"
00061 #elif ARCH_PPC
00062 #   include "ppc/intreadwrite.h"
00063 #elif ARCH_TOMI
00064 #   include "tomi/intreadwrite.h"
00065 #elif ARCH_X86
00066 #   include "x86/intreadwrite.h"
00067 #endif
00068 
00069 /*
00070  * Map AV_RNXX <-> AV_R[BL]XX for all variants provided by per-arch headers.
00071  */
00072 
00073 #if HAVE_BIGENDIAN
00074 
00075 #   if    defined(AV_RN16) && !defined(AV_RB16)
00076 #       define AV_RB16(p) AV_RN16(p)
00077 #   elif !defined(AV_RN16) &&  defined(AV_RB16)
00078 #       define AV_RN16(p) AV_RB16(p)
00079 #   endif
00080 
00081 #   if    defined(AV_WN16) && !defined(AV_WB16)
00082 #       define AV_WB16(p, v) AV_WN16(p, v)
00083 #   elif !defined(AV_WN16) &&  defined(AV_WB16)
00084 #       define AV_WN16(p, v) AV_WB16(p, v)
00085 #   endif
00086 
00087 #   if    defined(AV_RN24) && !defined(AV_RB24)
00088 #       define AV_RB24(p) AV_RN24(p)
00089 #   elif !defined(AV_RN24) &&  defined(AV_RB24)
00090 #       define AV_RN24(p) AV_RB24(p)
00091 #   endif
00092 
00093 #   if    defined(AV_WN24) && !defined(AV_WB24)
00094 #       define AV_WB24(p, v) AV_WN24(p, v)
00095 #   elif !defined(AV_WN24) &&  defined(AV_WB24)
00096 #       define AV_WN24(p, v) AV_WB24(p, v)
00097 #   endif
00098 
00099 #   if    defined(AV_RN32) && !defined(AV_RB32)
00100 #       define AV_RB32(p) AV_RN32(p)
00101 #   elif !defined(AV_RN32) &&  defined(AV_RB32)
00102 #       define AV_RN32(p) AV_RB32(p)
00103 #   endif
00104 
00105 #   if    defined(AV_WN32) && !defined(AV_WB32)
00106 #       define AV_WB32(p, v) AV_WN32(p, v)
00107 #   elif !defined(AV_WN32) &&  defined(AV_WB32)
00108 #       define AV_WN32(p, v) AV_WB32(p, v)
00109 #   endif
00110 
00111 #   if    defined(AV_RN64) && !defined(AV_RB64)
00112 #       define AV_RB64(p) AV_RN64(p)
00113 #   elif !defined(AV_RN64) &&  defined(AV_RB64)
00114 #       define AV_RN64(p) AV_RB64(p)
00115 #   endif
00116 
00117 #   if    defined(AV_WN64) && !defined(AV_WB64)
00118 #       define AV_WB64(p, v) AV_WN64(p, v)
00119 #   elif !defined(AV_WN64) &&  defined(AV_WB64)
00120 #       define AV_WN64(p, v) AV_WB64(p, v)
00121 #   endif
00122 
00123 #else /* HAVE_BIGENDIAN */
00124 
00125 #   if    defined(AV_RN16) && !defined(AV_RL16)
00126 #       define AV_RL16(p) AV_RN16(p)
00127 #   elif !defined(AV_RN16) &&  defined(AV_RL16)
00128 #       define AV_RN16(p) AV_RL16(p)
00129 #   endif
00130 
00131 #   if    defined(AV_WN16) && !defined(AV_WL16)
00132 #       define AV_WL16(p, v) AV_WN16(p, v)
00133 #   elif !defined(AV_WN16) &&  defined(AV_WL16)
00134 #       define AV_WN16(p, v) AV_WL16(p, v)
00135 #   endif
00136 
00137 #   if    defined(AV_RN24) && !defined(AV_RL24)
00138 #       define AV_RL24(p) AV_RN24(p)
00139 #   elif !defined(AV_RN24) &&  defined(AV_RL24)
00140 #       define AV_RN24(p) AV_RL24(p)
00141 #   endif
00142 
00143 #   if    defined(AV_WN24) && !defined(AV_WL24)
00144 #       define AV_WL24(p, v) AV_WN24(p, v)
00145 #   elif !defined(AV_WN24) &&  defined(AV_WL24)
00146 #       define AV_WN24(p, v) AV_WL24(p, v)
00147 #   endif
00148 
00149 #   if    defined(AV_RN32) && !defined(AV_RL32)
00150 #       define AV_RL32(p) AV_RN32(p)
00151 #   elif !defined(AV_RN32) &&  defined(AV_RL32)
00152 #       define AV_RN32(p) AV_RL32(p)
00153 #   endif
00154 
00155 #   if    defined(AV_WN32) && !defined(AV_WL32)
00156 #       define AV_WL32(p, v) AV_WN32(p, v)
00157 #   elif !defined(AV_WN32) &&  defined(AV_WL32)
00158 #       define AV_WN32(p, v) AV_WL32(p, v)
00159 #   endif
00160 
00161 #   if    defined(AV_RN64) && !defined(AV_RL64)
00162 #       define AV_RL64(p) AV_RN64(p)
00163 #   elif !defined(AV_RN64) &&  defined(AV_RL64)
00164 #       define AV_RN64(p) AV_RL64(p)
00165 #   endif
00166 
00167 #   if    defined(AV_WN64) && !defined(AV_WL64)
00168 #       define AV_WL64(p, v) AV_WN64(p, v)
00169 #   elif !defined(AV_WN64) &&  defined(AV_WL64)
00170 #       define AV_WN64(p, v) AV_WL64(p, v)
00171 #   endif
00172 
00173 #endif /* !HAVE_BIGENDIAN */
00174 
00175 /*
00176  * Define AV_[RW]N helper macros to simplify definitions not provided
00177  * by per-arch headers.
00178  */
00179 
00180 #if   HAVE_ATTRIBUTE_PACKED
00181 
00182 union unaligned_64 { uint64_t l; } __attribute__((packed)) av_alias;
00183 union unaligned_32 { uint32_t l; } __attribute__((packed)) av_alias;
00184 union unaligned_16 { uint16_t l; } __attribute__((packed)) av_alias;
00185 
00186 #   define AV_RN(s, p) (((const union unaligned_##s *) (p))->l)
00187 #   define AV_WN(s, p, v) ((((union unaligned_##s *) (p))->l) = (v))
00188 
00189 #elif defined(__DECC)
00190 
00191 #   define AV_RN(s, p) (*((const __unaligned uint##s##_t*)(p)))
00192 #   define AV_WN(s, p, v) (*((__unaligned uint##s##_t*)(p)) = (v))
00193 
00194 #elif HAVE_FAST_UNALIGNED
00195 
00196 #   define AV_RN(s, p) (((const av_alias##s*)(p))->u##s)
00197 #   define AV_WN(s, p, v) (((av_alias##s*)(p))->u##s = (v))
00198 
00199 #else
00200 
00201 #ifndef AV_RB16
00202 #   define AV_RB16(x)                           \
00203     ((((const uint8_t*)(x))[0] << 8) |          \
00204       ((const uint8_t*)(x))[1])
00205 #endif
00206 #ifndef AV_WB16
00207 #   define AV_WB16(p, d) do {                   \
00208         ((uint8_t*)(p))[1] = (d);               \
00209         ((uint8_t*)(p))[0] = (d)>>8;            \
00210     } while(0)
00211 #endif
00212 
00213 #ifndef AV_RL16
00214 #   define AV_RL16(x)                           \
00215     ((((const uint8_t*)(x))[1] << 8) |          \
00216       ((const uint8_t*)(x))[0])
00217 #endif
00218 #ifndef AV_WL16
00219 #   define AV_WL16(p, d) do {                   \
00220         ((uint8_t*)(p))[0] = (d);               \
00221         ((uint8_t*)(p))[1] = (d)>>8;            \
00222     } while(0)
00223 #endif
00224 
00225 #ifndef AV_RB32
00226 #   define AV_RB32(x)                           \
00227     ((((const uint8_t*)(x))[0] << 24) |         \
00228      (((const uint8_t*)(x))[1] << 16) |         \
00229      (((const uint8_t*)(x))[2] <<  8) |         \
00230       ((const uint8_t*)(x))[3])
00231 #endif
00232 #ifndef AV_WB32
00233 #   define AV_WB32(p, d) do {                   \
00234         ((uint8_t*)(p))[3] = (d);               \
00235         ((uint8_t*)(p))[2] = (d)>>8;            \
00236         ((uint8_t*)(p))[1] = (d)>>16;           \
00237         ((uint8_t*)(p))[0] = (d)>>24;           \
00238     } while(0)
00239 #endif
00240 
00241 #ifndef AV_RL32
00242 #   define AV_RL32(x)                           \
00243     ((((const uint8_t*)(x))[3] << 24) |         \
00244      (((const uint8_t*)(x))[2] << 16) |         \
00245      (((const uint8_t*)(x))[1] <<  8) |         \
00246       ((const uint8_t*)(x))[0])
00247 #endif
00248 #ifndef AV_WL32
00249 #   define AV_WL32(p, d) do {                   \
00250         ((uint8_t*)(p))[0] = (d);               \
00251         ((uint8_t*)(p))[1] = (d)>>8;            \
00252         ((uint8_t*)(p))[2] = (d)>>16;           \
00253         ((uint8_t*)(p))[3] = (d)>>24;           \
00254     } while(0)
00255 #endif
00256 
00257 #ifndef AV_RB64
00258 #   define AV_RB64(x)                                   \
00259     (((uint64_t)((const uint8_t*)(x))[0] << 56) |       \
00260      ((uint64_t)((const uint8_t*)(x))[1] << 48) |       \
00261      ((uint64_t)((const uint8_t*)(x))[2] << 40) |       \
00262      ((uint64_t)((const uint8_t*)(x))[3] << 32) |       \
00263      ((uint64_t)((const uint8_t*)(x))[4] << 24) |       \
00264      ((uint64_t)((const uint8_t*)(x))[5] << 16) |       \
00265      ((uint64_t)((const uint8_t*)(x))[6] <<  8) |       \
00266       (uint64_t)((const uint8_t*)(x))[7])
00267 #endif
00268 #ifndef AV_WB64
00269 #   define AV_WB64(p, d) do {                   \
00270         ((uint8_t*)(p))[7] = (d);               \
00271         ((uint8_t*)(p))[6] = (d)>>8;            \
00272         ((uint8_t*)(p))[5] = (d)>>16;           \
00273         ((uint8_t*)(p))[4] = (d)>>24;           \
00274         ((uint8_t*)(p))[3] = (d)>>32;           \
00275         ((uint8_t*)(p))[2] = (d)>>40;           \
00276         ((uint8_t*)(p))[1] = (d)>>48;           \
00277         ((uint8_t*)(p))[0] = (d)>>56;           \
00278     } while(0)
00279 #endif
00280 
00281 #ifndef AV_RL64
00282 #   define AV_RL64(x)                                   \
00283     (((uint64_t)((const uint8_t*)(x))[7] << 56) |       \
00284      ((uint64_t)((const uint8_t*)(x))[6] << 48) |       \
00285      ((uint64_t)((const uint8_t*)(x))[5] << 40) |       \
00286      ((uint64_t)((const uint8_t*)(x))[4] << 32) |       \
00287      ((uint64_t)((const uint8_t*)(x))[3] << 24) |       \
00288      ((uint64_t)((const uint8_t*)(x))[2] << 16) |       \
00289      ((uint64_t)((const uint8_t*)(x))[1] <<  8) |       \
00290       (uint64_t)((const uint8_t*)(x))[0])
00291 #endif
00292 #ifndef AV_WL64
00293 #   define AV_WL64(p, d) do {                   \
00294         ((uint8_t*)(p))[0] = (d);               \
00295         ((uint8_t*)(p))[1] = (d)>>8;            \
00296         ((uint8_t*)(p))[2] = (d)>>16;           \
00297         ((uint8_t*)(p))[3] = (d)>>24;           \
00298         ((uint8_t*)(p))[4] = (d)>>32;           \
00299         ((uint8_t*)(p))[5] = (d)>>40;           \
00300         ((uint8_t*)(p))[6] = (d)>>48;           \
00301         ((uint8_t*)(p))[7] = (d)>>56;           \
00302     } while(0)
00303 #endif
00304 
00305 #if HAVE_BIGENDIAN
00306 #   define AV_RN(s, p)    AV_RB##s(p)
00307 #   define AV_WN(s, p, v) AV_WB##s(p, v)
00308 #else
00309 #   define AV_RN(s, p)    AV_RL##s(p)
00310 #   define AV_WN(s, p, v) AV_WL##s(p, v)
00311 #endif
00312 
00313 #endif /* HAVE_FAST_UNALIGNED */
00314 
00315 #ifndef AV_RN16
00316 #   define AV_RN16(p) AV_RN(16, p)
00317 #endif
00318 
00319 #ifndef AV_RN32
00320 #   define AV_RN32(p) AV_RN(32, p)
00321 #endif
00322 
00323 #ifndef AV_RN64
00324 #   define AV_RN64(p) AV_RN(64, p)
00325 #endif
00326 
00327 #ifndef AV_WN16
00328 #   define AV_WN16(p, v) AV_WN(16, p, v)
00329 #endif
00330 
00331 #ifndef AV_WN32
00332 #   define AV_WN32(p, v) AV_WN(32, p, v)
00333 #endif
00334 
00335 #ifndef AV_WN64
00336 #   define AV_WN64(p, v) AV_WN(64, p, v)
00337 #endif
00338 
00339 #if HAVE_BIGENDIAN
00340 #   define AV_RB(s, p)    AV_RN##s(p)
00341 #   define AV_WB(s, p, v) AV_WN##s(p, v)
00342 #   define AV_RL(s, p)    bswap_##s(AV_RN##s(p))
00343 #   define AV_WL(s, p, v) AV_WN##s(p, bswap_##s(v))
00344 #else
00345 #   define AV_RB(s, p)    bswap_##s(AV_RN##s(p))
00346 #   define AV_WB(s, p, v) AV_WN##s(p, bswap_##s(v))
00347 #   define AV_RL(s, p)    AV_RN##s(p)
00348 #   define AV_WL(s, p, v) AV_WN##s(p, v)
00349 #endif
00350 
00351 #define AV_RB8(x)     (((const uint8_t*)(x))[0])
00352 #define AV_WB8(p, d)  do { ((uint8_t*)(p))[0] = (d); } while(0)
00353 
00354 #define AV_RL8(x)     AV_RB8(x)
00355 #define AV_WL8(p, d)  AV_WB8(p, d)
00356 
00357 #ifndef AV_RB16
00358 #   define AV_RB16(p)    AV_RB(16, p)
00359 #endif
00360 #ifndef AV_WB16
00361 #   define AV_WB16(p, v) AV_WB(16, p, v)
00362 #endif
00363 
00364 #ifndef AV_RL16
00365 #   define AV_RL16(p)    AV_RL(16, p)
00366 #endif
00367 #ifndef AV_WL16
00368 #   define AV_WL16(p, v) AV_WL(16, p, v)
00369 #endif
00370 
00371 #ifndef AV_RB32
00372 #   define AV_RB32(p)    AV_RB(32, p)
00373 #endif
00374 #ifndef AV_WB32
00375 #   define AV_WB32(p, v) AV_WB(32, p, v)
00376 #endif
00377 
00378 #ifndef AV_RL32
00379 #   define AV_RL32(p)    AV_RL(32, p)
00380 #endif
00381 #ifndef AV_WL32
00382 #   define AV_WL32(p, v) AV_WL(32, p, v)
00383 #endif
00384 
00385 #ifndef AV_RB64
00386 #   define AV_RB64(p)    AV_RB(64, p)
00387 #endif
00388 #ifndef AV_WB64
00389 #   define AV_WB64(p, v) AV_WB(64, p, v)
00390 #endif
00391 
00392 #ifndef AV_RL64
00393 #   define AV_RL64(p)    AV_RL(64, p)
00394 #endif
00395 #ifndef AV_WL64
00396 #   define AV_WL64(p, v) AV_WL(64, p, v)
00397 #endif
00398 
00399 #ifndef AV_RB24
00400 #   define AV_RB24(x)                           \
00401     ((((const uint8_t*)(x))[0] << 16) |         \
00402      (((const uint8_t*)(x))[1] <<  8) |         \
00403       ((const uint8_t*)(x))[2])
00404 #endif
00405 #ifndef AV_WB24
00406 #   define AV_WB24(p, d) do {                   \
00407         ((uint8_t*)(p))[2] = (d);               \
00408         ((uint8_t*)(p))[1] = (d)>>8;            \
00409         ((uint8_t*)(p))[0] = (d)>>16;           \
00410     } while(0)
00411 #endif
00412 
00413 #ifndef AV_RL24
00414 #   define AV_RL24(x)                           \
00415     ((((const uint8_t*)(x))[2] << 16) |         \
00416      (((const uint8_t*)(x))[1] <<  8) |         \
00417       ((const uint8_t*)(x))[0])
00418 #endif
00419 #ifndef AV_WL24
00420 #   define AV_WL24(p, d) do {                   \
00421         ((uint8_t*)(p))[0] = (d);               \
00422         ((uint8_t*)(p))[1] = (d)>>8;            \
00423         ((uint8_t*)(p))[2] = (d)>>16;           \
00424     } while(0)
00425 #endif
00426 
00427 /*
00428  * The AV_[RW]NA macros access naturally aligned data
00429  * in a type-safe way.
00430  */
00431 
00432 #define AV_RNA(s, p)    (((const av_alias##s*)(p))->u##s)
00433 #define AV_WNA(s, p, v) (((av_alias##s*)(p))->u##s = (v))
00434 
00435 #ifndef AV_RN16A
00436 #   define AV_RN16A(p) AV_RNA(16, p)
00437 #endif
00438 
00439 #ifndef AV_RN32A
00440 #   define AV_RN32A(p) AV_RNA(32, p)
00441 #endif
00442 
00443 #ifndef AV_RN64A
00444 #   define AV_RN64A(p) AV_RNA(64, p)
00445 #endif
00446 
00447 #ifndef AV_WN16A
00448 #   define AV_WN16A(p, v) AV_WNA(16, p, v)
00449 #endif
00450 
00451 #ifndef AV_WN32A
00452 #   define AV_WN32A(p, v) AV_WNA(32, p, v)
00453 #endif
00454 
00455 #ifndef AV_WN64A
00456 #   define AV_WN64A(p, v) AV_WNA(64, p, v)
00457 #endif
00458 
00459 /* Parameters for AV_COPY*, AV_SWAP*, AV_ZERO* must be
00460  * naturally aligned. They may be implemented using MMX,
00461  * so emms_c() must be called before using any float code
00462  * afterwards.
00463  */
00464 
00465 #define AV_COPY(n, d, s) \
00466     (((av_alias##n*)(d))->u##n = ((const av_alias##n*)(s))->u##n)
00467 
00468 #ifndef AV_COPY16
00469 #   define AV_COPY16(d, s) AV_COPY(16, d, s)
00470 #endif
00471 
00472 #ifndef AV_COPY32
00473 #   define AV_COPY32(d, s) AV_COPY(32, d, s)
00474 #endif
00475 
00476 #ifndef AV_COPY64
00477 #   define AV_COPY64(d, s) AV_COPY(64, d, s)
00478 #endif
00479 
00480 #ifndef AV_COPY128
00481 #   define AV_COPY128(d, s)                    \
00482     do {                                       \
00483         AV_COPY64(d, s);                       \
00484         AV_COPY64((char*)(d)+8, (char*)(s)+8); \
00485     } while(0)
00486 #endif
00487 
00488 #define AV_SWAP(n, a, b) FFSWAP(av_alias##n, *(av_alias##n*)(a), *(av_alias##n*)(b))
00489 
00490 #ifndef AV_SWAP64
00491 #   define AV_SWAP64(a, b) AV_SWAP(64, a, b)
00492 #endif
00493 
00494 #define AV_ZERO(n, d) (((av_alias##n*)(d))->u##n = 0)
00495 
00496 #ifndef AV_ZERO16
00497 #   define AV_ZERO16(d) AV_ZERO(16, d)
00498 #endif
00499 
00500 #ifndef AV_ZERO32
00501 #   define AV_ZERO32(d) AV_ZERO(32, d)
00502 #endif
00503 
00504 #ifndef AV_ZERO64
00505 #   define AV_ZERO64(d) AV_ZERO(64, d)
00506 #endif
00507 
00508 #ifndef AV_ZERO128
00509 #   define AV_ZERO128(d)         \
00510     do {                         \
00511         AV_ZERO64(d);            \
00512         AV_ZERO64((char*)(d)+8); \
00513     } while(0)
00514 #endif
00515 
00516 #endif /* AVUTIL_INTREADWRITE_H */

Generated on Fri Sep 16 2011 17:17:51 for FFmpeg by  doxygen 1.7.1