From 3ee45ab7bed6447f09aaf1a24f5d35f212cd8b14 Mon Sep 17 00:00:00 2001 From: Mohamed Tarek Date: Fri, 14 Aug 2009 15:26:04 +0000 Subject: Use the bytestream reading functions form librm and drop bytestream.h and libavutil/ git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22309 a1c6a512-1295-4272-9138-f99709370657 --- apps/codecs/libatrac/atrac3.c | 39 ++-- apps/codecs/libatrac/bytestream.h | 70 ------- apps/codecs/libatrac/libavutil/avutil.h | 63 ------ apps/codecs/libatrac/libavutil/bswap.h | 99 --------- apps/codecs/libatrac/libavutil/common.h | 279 -------------------------- apps/codecs/libatrac/libavutil/intreadwrite.h | 192 ------------------ 6 files changed, 26 insertions(+), 716 deletions(-) delete mode 100644 apps/codecs/libatrac/bytestream.h delete mode 100644 apps/codecs/libatrac/libavutil/avutil.h delete mode 100644 apps/codecs/libatrac/libavutil/bswap.h delete mode 100644 apps/codecs/libatrac/libavutil/common.h delete mode 100644 apps/codecs/libatrac/libavutil/intreadwrite.h (limited to 'apps/codecs/libatrac') diff --git a/apps/codecs/libatrac/atrac3.c b/apps/codecs/libatrac/atrac3.c index 26bffd42d4..9e61db1686 100644 --- a/apps/codecs/libatrac/atrac3.c +++ b/apps/codecs/libatrac/atrac3.c @@ -36,7 +36,6 @@ #include #include -#include "bytestream.h" #include "atrac3.h" #include "atrac3data.h" #include "atrac3data_fixed.h" @@ -48,6 +47,20 @@ #define AVERROR(...) -1 +/* FFMAX/MIN/SWAP and av_clip were taken from libavutil/common.h */ +#define FFMAX(a,b) ((a) > (b) ? (a) : (b)) +#define FFMIN(a,b) ((a) > (b) ? (b) : (a)) +#define FFSWAP(type,a,b) do{type SWAP_tmp= b; b= a; a= SWAP_tmp;}while(0) + +/** + * Clips a signed integer value into the -32768,32767 range. + */ +static inline int16_t av_clip_int16(int a) +{ + if ((a+32768) & ~65535) return (a>>31) ^ 32767; + else return a; +} + static int32_t qmf_window[48]; static VLC spectral_coeff_tab[7]; static channel_unit channel_units[2]; @@ -169,7 +182,7 @@ static int decode_bytes(const uint8_t* inbuffer, uint8_t* out, int bytes){ } -static av_cold void init_atrac3_transforms(ATRAC3Context *q) { +static void init_atrac3_transforms(ATRAC3Context *q) { int32_t s; int i; @@ -830,7 +843,7 @@ int atrac3_decode_frame(RMContext *rmctx, ATRAC3Context *q, int atrac3_decode_init(ATRAC3Context *q, RMContext *rmctx) { int i; - const uint8_t *edata_ptr = rmctx->codec_extradata; + uint8_t *edata_ptr = rmctx->codec_extradata; static VLC_TYPE atrac3_vlc_table[4096][2]; static int vlcs_initialized = 0; @@ -844,12 +857,12 @@ int atrac3_decode_init(ATRAC3Context *q, RMContext *rmctx) /* Take care of the codec-specific extradata. */ if (rmctx->extradata_size == 14) { /* Parse the extradata, WAV format */ - DEBUGF("[0-1] %d\n",bytestream_get_le16(&edata_ptr)); //Unknown value always 1 - q->samples_per_channel = bytestream_get_le32(&edata_ptr); - q->codingMode = bytestream_get_le16(&edata_ptr); - DEBUGF("[8-9] %d\n",bytestream_get_le16(&edata_ptr)); //Dupe of coding mode - q->frame_factor = bytestream_get_le16(&edata_ptr); //Unknown always 1 - DEBUGF("[12-13] %d\n",bytestream_get_le16(&edata_ptr)); //Unknown always 0 + DEBUGF("[0-1] %d\n",rm_get_uint16le(&edata_ptr[0])); //Unknown value always 1 + q->samples_per_channel = rm_get_uint32le(&edata_ptr[2]); + q->codingMode = rm_get_uint16le(&edata_ptr[6]); + DEBUGF("[8-9] %d\n",rm_get_uint16le(&edata_ptr[8])); //Dupe of coding mode + q->frame_factor = rm_get_uint16le(&edata_ptr[10]); //Unknown always 1 + DEBUGF("[12-13] %d\n",rm_get_uint16le(&edata_ptr[12])); //Unknown always 0 /* setup */ q->samples_per_frame = 1024 * q->channels; @@ -869,10 +882,10 @@ int atrac3_decode_init(ATRAC3Context *q, RMContext *rmctx) } else if (rmctx->extradata_size == 10) { /* Parse the extradata, RM format. */ - q->atrac3version = bytestream_get_be32(&edata_ptr); - q->samples_per_frame = bytestream_get_be16(&edata_ptr); - q->delay = bytestream_get_be16(&edata_ptr); - q->codingMode = bytestream_get_be16(&edata_ptr); + q->atrac3version = rm_get_uint32be(&edata_ptr[0]); + q->samples_per_frame = rm_get_uint16be(&edata_ptr[4]); + q->delay = rm_get_uint16be(&edata_ptr[6]); + q->codingMode = rm_get_uint16be(&edata_ptr[8]); q->samples_per_channel = q->samples_per_frame / q->channels; q->scrambled_stream = 1; diff --git a/apps/codecs/libatrac/bytestream.h b/apps/codecs/libatrac/bytestream.h deleted file mode 100644 index cc4f7a62c7..0000000000 --- a/apps/codecs/libatrac/bytestream.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Bytestream functions - * copyright (c) 2006 Baptiste Coudurier - * - * This file is part of FFmpeg. - * - * FFmpeg is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * FFmpeg is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef AVCODEC_BYTESTREAM_H -#define AVCODEC_BYTESTREAM_H - -#include -#include "libavutil/intreadwrite.h" - -#define DEF_T(type, name, bytes, read, write) \ -static av_always_inline type bytestream_get_ ## name(const uint8_t **b){\ - (*b) += bytes;\ - return read(*b - bytes);\ -}\ -static av_always_inline void bytestream_put_ ##name(uint8_t **b, const type value){\ - write(*b, value);\ - (*b) += bytes;\ -} - -#define DEF(name, bytes, read, write) \ - DEF_T(unsigned int, name, bytes, read, write) -#define DEF64(name, bytes, read, write) \ - DEF_T(uint64_t, name, bytes, read, write) - -DEF64(le64, 8, AV_RL64, AV_WL64) -DEF (le32, 4, AV_RL32, AV_WL32) -DEF (le24, 3, AV_RL24, AV_WL24) -DEF (le16, 2, AV_RL16, AV_WL16) -DEF64(be64, 8, AV_RB64, AV_WB64) -DEF (be32, 4, AV_RB32, AV_WB32) -DEF (be24, 3, AV_RB24, AV_WB24) -DEF (be16, 2, AV_RB16, AV_WB16) -DEF (byte, 1, AV_RB8 , AV_WB8 ) - -#undef DEF -#undef DEF64 -#undef DEF_T - -static av_always_inline unsigned int bytestream_get_buffer(const uint8_t **b, uint8_t *dst, unsigned int size) -{ - memcpy(dst, *b, size); - (*b) += size; - return size; -} - -static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size) -{ - memcpy(*b, src, size); - (*b) += size; -} - -#endif /* AVCODEC_BYTESTREAM_H */ diff --git a/apps/codecs/libatrac/libavutil/avutil.h b/apps/codecs/libatrac/libavutil/avutil.h deleted file mode 100644 index c07e44d660..0000000000 --- a/apps/codecs/libatrac/libavutil/avutil.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * copyright (c) 2006 Michael Niedermayer - * - * This file is part of FFmpeg. - * - * FFmpeg is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * FFmpeg is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef AVUTIL_AVUTIL_H -#define AVUTIL_AVUTIL_H - -/** - * @file libavutil/avutil.h - * external API header - */ - - -#define AV_STRINGIFY(s) AV_TOSTRING(s) -#define AV_TOSTRING(s) #s - -#define AV_VERSION_INT(a, b, c) (a<<16 | b<<8 | c) -#define AV_VERSION_DOT(a, b, c) a ##.## b ##.## c -#define AV_VERSION(a, b, c) AV_VERSION_DOT(a, b, c) - -#define LIBAVUTIL_VERSION_MAJOR 50 -#define LIBAVUTIL_VERSION_MINOR 0 -#define LIBAVUTIL_VERSION_MICRO 0 - -#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ - LIBAVUTIL_VERSION_MINOR, \ - LIBAVUTIL_VERSION_MICRO) -#define LIBAVUTIL_VERSION AV_VERSION(LIBAVUTIL_VERSION_MAJOR, \ - LIBAVUTIL_VERSION_MINOR, \ - LIBAVUTIL_VERSION_MICRO) -#define LIBAVUTIL_BUILD LIBAVUTIL_VERSION_INT - -#define LIBAVUTIL_IDENT "Lavu" AV_STRINGIFY(LIBAVUTIL_VERSION) - -/** - * Returns the LIBAVUTIL_VERSION_INT constant. - */ -unsigned avutil_version(void); - -#include "common.h" -//#include "mathematics.h" -//#include "rational.h" -//#include "intfloat_readwrite.h" -#include "log.h" -//#include "pixfmt.h" - -#endif /* AVUTIL_AVUTIL_H */ diff --git a/apps/codecs/libatrac/libavutil/bswap.h b/apps/codecs/libatrac/libavutil/bswap.h deleted file mode 100644 index 9175cb24a5..0000000000 --- a/apps/codecs/libatrac/libavutil/bswap.h +++ /dev/null @@ -1,99 +0,0 @@ -/* - * copyright (c) 2006 Michael Niedermayer - * - * This file is part of FFmpeg. - * - * FFmpeg is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * FFmpeg is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/** - * @file libavutil/bswap.h - * byte swapping routines - */ - -#ifndef AVUTIL_BSWAP_H -#define AVUTIL_BSWAP_H - -#include -//#include "ffmpeg_config.h" -#include "common.h" - -#if ARCH_ARM -# include "arm/bswap.h" -#elif ARCH_BFIN -# include "bfin/bswap.h" -#elif ARCH_SH4 -# include "sh4/bswap.h" -#elif ARCH_X86 -# include "x86/bswap.h" -#endif - -#ifndef bswap_16 -static av_always_inline av_const uint16_t bswap_16(uint16_t x) -{ - x= (x>>8) | (x<<8); - return x; -} -#endif - -#ifndef bswap_32 -static av_always_inline av_const uint32_t bswap_32(uint32_t x) -{ - x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF); - x= (x>>16) | (x<<16); - return x; -} -#endif - -#ifndef bswap_64 -static inline uint64_t av_const bswap_64(uint64_t x) -{ -#if 0 - x= ((x<< 8)&0xFF00FF00FF00FF00ULL) | ((x>> 8)&0x00FF00FF00FF00FFULL); - x= ((x<<16)&0xFFFF0000FFFF0000ULL) | ((x>>16)&0x0000FFFF0000FFFFULL); - return (x>>32) | (x<<32); -#else - union { - uint64_t ll; - uint32_t l[2]; - } w, r; - w.ll = x; - r.l[0] = bswap_32 (w.l[1]); - r.l[1] = bswap_32 (w.l[0]); - return r.ll; -#endif -} -#endif - -// be2me ... big-endian to machine-endian -// le2me ... little-endian to machine-endian - -#ifdef WORDS_BIGENDIAN -#define be2me_16(x) (x) -#define be2me_32(x) (x) -#define be2me_64(x) (x) -#define le2me_16(x) bswap_16(x) -#define le2me_32(x) bswap_32(x) -#define le2me_64(x) bswap_64(x) -#else -#define be2me_16(x) bswap_16(x) -#define be2me_32(x) bswap_32(x) -#define be2me_64(x) bswap_64(x) -#define le2me_16(x) (x) -#define le2me_32(x) (x) -#define le2me_64(x) (x) -#endif - -#endif /* AVUTIL_BSWAP_H */ diff --git a/apps/codecs/libatrac/libavutil/common.h b/apps/codecs/libatrac/libavutil/common.h deleted file mode 100644 index e369b43da7..0000000000 --- a/apps/codecs/libatrac/libavutil/common.h +++ /dev/null @@ -1,279 +0,0 @@ -/* - * copyright (c) 2006 Michael Niedermayer - * - * This file is part of FFmpeg. - * - * FFmpeg is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * FFmpeg is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/** - * @file libavutil/common.h - * common internal and external API header - */ - -#ifndef AVUTIL_COMMON_H -#define AVUTIL_COMMON_H - -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef __GNUC__ -# define AV_GCC_VERSION_AT_LEAST(x,y) (__GNUC__ > x || __GNUC__ == x && __GNUC_MINOR__ >= y) -#else -# define AV_GCC_VERSION_AT_LEAST(x,y) 0 -#endif - -#ifndef av_always_inline -#if AV_GCC_VERSION_AT_LEAST(3,1) -# define av_always_inline __attribute__((always_inline)) inline -#else -# define av_always_inline inline -#endif -#endif - -#ifndef av_noinline -#if AV_GCC_VERSION_AT_LEAST(3,1) -# define av_noinline __attribute__((noinline)) -#else -# define av_noinline -#endif -#endif - -#ifndef av_pure -#if AV_GCC_VERSION_AT_LEAST(3,1) -# define av_pure __attribute__((pure)) -#else -# define av_pure -#endif -#endif - -#ifndef av_const -#if AV_GCC_VERSION_AT_LEAST(2,6) -# define av_const __attribute__((const)) -#else -# define av_const -#endif -#endif - -#ifndef av_cold -#if (!defined(__ICC) || __ICC > 1100) && AV_GCC_VERSION_AT_LEAST(4,3) -# define av_cold __attribute__((cold)) -#else -# define av_cold -#endif -#endif - -#ifndef av_flatten -#if AV_GCC_VERSION_AT_LEAST(4,1) -# define av_flatten __attribute__((flatten)) -#else -# define av_flatten -#endif -#endif - -#ifndef attribute_deprecated -#if AV_GCC_VERSION_AT_LEAST(3,1) -# define attribute_deprecated __attribute__((deprecated)) -#else -# define attribute_deprecated -#endif -#endif - -#ifndef av_unused -#if defined(__GNUC__) -# define av_unused __attribute__((unused)) -#else -# define av_unused -#endif -#endif - -#ifndef av_uninit -#if defined(__GNUC__) && !defined(__ICC) -# define av_uninit(x) x=x -#else -# define av_uninit(x) x -#endif -#endif - -//rounded division & shift -#define RSHIFT(a,b) ((a) > 0 ? ((a) + ((1<<(b))>>1))>>(b) : ((a) + ((1<<(b))>>1)-1)>>(b)) -/* assume b>0 */ -#define ROUNDED_DIV(a,b) (((a)>0 ? (a) + ((b)>>1) : (a) - ((b)>>1))/(b)) -#define FFABS(a) ((a) >= 0 ? (a) : (-(a))) -#define FFSIGN(a) ((a) > 0 ? 1 : -1) - -#define FFMAX(a,b) ((a) > (b) ? (a) : (b)) -#define FFMAX3(a,b,c) FFMAX(FFMAX(a,b),c) -#define FFMIN(a,b) ((a) > (b) ? (b) : (a)) -#define FFMIN3(a,b,c) FFMIN(FFMIN(a,b),c) - -#define FFSWAP(type,a,b) do{type SWAP_tmp= b; b= a; a= SWAP_tmp;}while(0) -#define FF_ARRAY_ELEMS(a) (sizeof(a) / sizeof((a)[0])) - -/* misc math functions */ -extern const uint8_t ff_log2_tab[256]; - -static inline av_const int av_log2(unsigned int v) -{ - int n = 0; - if (v & 0xffff0000) { - v >>= 16; - n += 16; - } - if (v & 0xff00) { - v >>= 8; - n += 8; - } - n += ff_log2_tab[v]; - - return n; -} - -static inline av_const int av_log2_16bit(unsigned int v) -{ - int n = 0; - if (v & 0xff00) { - v >>= 8; - n += 8; - } - n += ff_log2_tab[v]; - - return n; -} - -/** - * Clips a signed integer value into the amin-amax range. - * @param a value to clip - * @param amin minimum value of the clip range - * @param amax maximum value of the clip range - * @return clipped value - */ -static inline av_const int av_clip(int a, int amin, int amax) -{ - if (a < amin) return amin; - else if (a > amax) return amax; - else return a; -} - -/** - * Clips a signed integer value into the 0-255 range. - * @param a value to clip - * @return clipped value - */ -static inline av_const uint8_t av_clip_uint8(int a) -{ - if (a&(~255)) return (-a)>>31; - else return a; -} - -/** - * Clips a signed integer value into the -32768,32767 range. - * @param a value to clip - * @return clipped value - */ -static inline av_const int16_t av_clip_int16(int a) -{ - if ((a+32768) & ~65535) return (a>>31) ^ 32767; - else return a; -} - -/** - * Clips a float value into the amin-amax range. - * @param a value to clip - * @param amin minimum value of the clip range - * @param amax maximum value of the clip range - * @return clipped value - */ -static inline av_const float av_clipf(float a, float amin, float amax) -{ - if (a < amin) return amin; - else if (a > amax) return amax; - else return a; -} - -#define MKTAG(a,b,c,d) (a | (b << 8) | (c << 16) | (d << 24)) -#define MKBETAG(a,b,c,d) (d | (c << 8) | (b << 16) | (a << 24)) - -/*! - * \def GET_UTF8(val, GET_BYTE, ERROR) - * Converts a UTF-8 character (up to 4 bytes long) to its 32-bit UCS-4 encoded form - * \param val is the output and should be of type uint32_t. It holds the converted - * UCS-4 character and should be a left value. - * \param GET_BYTE gets UTF-8 encoded bytes from any proper source. It can be - * a function or a statement whose return value or evaluated value is of type - * uint8_t. It will be executed up to 4 times for values in the valid UTF-8 range, - * and up to 7 times in the general case. - * \param ERROR action that should be taken when an invalid UTF-8 byte is returned - * from GET_BYTE. It should be a statement that jumps out of the macro, - * like exit(), goto, return, break, or continue. - */ -#define GET_UTF8(val, GET_BYTE, ERROR)\ - val= GET_BYTE;\ - {\ - int ones= 7 - av_log2(val ^ 255);\ - if(ones==1)\ - ERROR\ - val&= 127>>ones;\ - while(--ones > 0){\ - int tmp= GET_BYTE - 128;\ - if(tmp>>6)\ - ERROR\ - val= (val<<6) + tmp;\ - }\ - } - -/*! - * \def PUT_UTF8(val, tmp, PUT_BYTE) - * Converts a 32-bit Unicode character to its UTF-8 encoded form (up to 4 bytes long). - * \param val is an input-only argument and should be of type uint32_t. It holds - * a UCS-4 encoded Unicode character that is to be converted to UTF-8. If - * val is given as a function it is executed only once. - * \param tmp is a temporary variable and should be of type uint8_t. It - * represents an intermediate value during conversion that is to be - * output by PUT_BYTE. - * \param PUT_BYTE writes the converted UTF-8 bytes to any proper destination. - * It could be a function or a statement, and uses tmp as the input byte. - * For example, PUT_BYTE could be "*output++ = tmp;" PUT_BYTE will be - * executed up to 4 times for values in the valid UTF-8 range and up to - * 7 times in the general case, depending on the length of the converted - * Unicode character. - */ -#define PUT_UTF8(val, tmp, PUT_BYTE)\ - {\ - int bytes, shift;\ - uint32_t in = val;\ - if (in < 0x80) {\ - tmp = in;\ - PUT_BYTE\ - } else {\ - bytes = (av_log2(in) + 4) / 5;\ - shift = (bytes - 1) * 6;\ - tmp = (256 - (256 >> bytes)) | (in >> shift);\ - PUT_BYTE\ - while (shift >= 6) {\ - shift -= 6;\ - tmp = 0x80 | ((in >> shift) & 0x3f);\ - PUT_BYTE\ - }\ - }\ - } - -#endif /* AVUTIL_COMMON_H */ diff --git a/apps/codecs/libatrac/libavutil/intreadwrite.h b/apps/codecs/libatrac/libavutil/intreadwrite.h deleted file mode 100644 index d27a50061e..0000000000 --- a/apps/codecs/libatrac/libavutil/intreadwrite.h +++ /dev/null @@ -1,192 +0,0 @@ -/* - * This file is part of FFmpeg. - * - * FFmpeg is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * FFmpeg is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef AVUTIL_INTREADWRITE_H -#define AVUTIL_INTREADWRITE_H - -#include -//#include "ffmpeg_config.h" -#include "bswap.h" - -#ifdef __GNUC__ - -struct unaligned_64 { uint64_t l; } __attribute__((packed)); -struct unaligned_32 { uint32_t l; } __attribute__((packed)); -struct unaligned_16 { uint16_t l; } __attribute__((packed)); - -#define AV_RN16(a) (((const struct unaligned_16 *) (a))->l) -#define AV_RN32(a) (((const struct unaligned_32 *) (a))->l) -#define AV_RN64(a) (((const struct unaligned_64 *) (a))->l) - -#define AV_WN16(a, b) (((struct unaligned_16 *) (a))->l) = (b) -#define AV_WN32(a, b) (((struct unaligned_32 *) (a))->l) = (b) -#define AV_WN64(a, b) (((struct unaligned_64 *) (a))->l) = (b) - -#elif defined(__DECC) - -#define AV_RN16(a) (*((const __unaligned uint16_t*)(a))) -#define AV_RN32(a) (*((const __unaligned uint32_t*)(a))) -#define AV_RN64(a) (*((const __unaligned uint64_t*)(a))) - -#define AV_WN16(a, b) *((__unaligned uint16_t*)(a)) = (b) -#define AV_WN32(a, b) *((__unaligned uint32_t*)(a)) = (b) -#define AV_WN64(a, b) *((__unaligned uint64_t*)(a)) = (b) - -#else - -#define AV_RN16(a) (*((const uint16_t*)(a))) -#define AV_RN32(a) (*((const uint32_t*)(a))) -#define AV_RN64(a) (*((const uint64_t*)(a))) - -#define AV_WN16(a, b) *((uint16_t*)(a)) = (b) -#define AV_WN32(a, b) *((uint32_t*)(a)) = (b) -#define AV_WN64(a, b) *((uint64_t*)(a)) = (b) - -#endif /* !__GNUC__ */ - -/* endian macros */ -#define AV_RB8(x) (((const uint8_t*)(x))[0]) -#define AV_WB8(p, d) do { ((uint8_t*)(p))[0] = (d); } while(0) - -#define AV_RL8(x) AV_RB8(x) -#define AV_WL8(p, d) AV_WB8(p, d) - -#if HAVE_FAST_UNALIGNED -# ifdef WORDS_BIGENDIAN -# define AV_RB16(x) AV_RN16(x) -# define AV_WB16(p, d) AV_WN16(p, d) - -# define AV_RL16(x) bswap_16(AV_RN16(x)) -# define AV_WL16(p, d) AV_WN16(p, bswap_16(d)) - -# define AV_RB32(x) AV_RN32(x) -# define AV_WB32(p, d) AV_WN32(p, d) - -# define AV_RL32(x) bswap_32(AV_RN32(x)) -# define AV_WL32(p, d) AV_WN32(p, bswap_32(d)) - -# define AV_RB64(x) AV_RN64(x) -# define AV_WB64(p, d) AV_WN64(p, d) - -# define AV_RL64(x) bswap_64(AV_RN64(x)) -# define AV_WL64(p, d) AV_WN64(p, bswap_64(d)) -# else /* WORDS_BIGENDIAN */ -# define AV_RB16(x) bswap_16(AV_RN16(x)) -# define AV_WB16(p, d) AV_WN16(p, bswap_16(d)) - -# define AV_RL16(x) AV_RN16(x) -# define AV_WL16(p, d) AV_WN16(p, d) - -# define AV_RB32(x) bswap_32(AV_RN32(x)) -# define AV_WB32(p, d) AV_WN32(p, bswap_32(d)) - -# define AV_RL32(x) AV_RN32(x) -# define AV_WL32(p, d) AV_WN32(p, d) - -# define AV_RB64(x) bswap_64(AV_RN64(x)) -# define AV_WB64(p, d) AV_WN64(p, bswap_64(d)) - -# define AV_RL64(x) AV_RN64(x) -# define AV_WL64(p, d) AV_WN64(p, d) -# endif -#else /* HAVE_FAST_UNALIGNED */ -#define AV_RB16(x) ((((const uint8_t*)(x))[0] << 8) | ((const uint8_t*)(x))[1]) -#define AV_WB16(p, d) do { \ - ((uint8_t*)(p))[1] = (d); \ - ((uint8_t*)(p))[0] = (d)>>8; } while(0) - -#define AV_RL16(x) ((((const uint8_t*)(x))[1] << 8) | \ - ((const uint8_t*)(x))[0]) -#define AV_WL16(p, d) do { \ - ((uint8_t*)(p))[0] = (d); \ - ((uint8_t*)(p))[1] = (d)>>8; } while(0) - -#define AV_RB32(x) ((((const uint8_t*)(x))[0] << 24) | \ - (((const uint8_t*)(x))[1] << 16) | \ - (((const uint8_t*)(x))[2] << 8) | \ - ((const uint8_t*)(x))[3]) -#define AV_WB32(p, d) do { \ - ((uint8_t*)(p))[3] = (d); \ - ((uint8_t*)(p))[2] = (d)>>8; \ - ((uint8_t*)(p))[1] = (d)>>16; \ - ((uint8_t*)(p))[0] = (d)>>24; } while(0) - -#define AV_RL32(x) ((((const uint8_t*)(x))[3] << 24) | \ - (((const uint8_t*)(x))[2] << 16) | \ - (((const uint8_t*)(x))[1] << 8) | \ - ((const uint8_t*)(x))[0]) -#define AV_WL32(p, d) do { \ - ((uint8_t*)(p))[0] = (d); \ - ((uint8_t*)(p))[1] = (d)>>8; \ - ((uint8_t*)(p))[2] = (d)>>16; \ - ((uint8_t*)(p))[3] = (d)>>24; } while(0) - -#define AV_RB64(x) (((uint64_t)((const uint8_t*)(x))[0] << 56) | \ - ((uint64_t)((const uint8_t*)(x))[1] << 48) | \ - ((uint64_t)((const uint8_t*)(x))[2] << 40) | \ - ((uint64_t)((const uint8_t*)(x))[3] << 32) | \ - ((uint64_t)((const uint8_t*)(x))[4] << 24) | \ - ((uint64_t)((const uint8_t*)(x))[5] << 16) | \ - ((uint64_t)((const uint8_t*)(x))[6] << 8) | \ - (uint64_t)((const uint8_t*)(x))[7]) -#define AV_WB64(p, d) do { \ - ((uint8_t*)(p))[7] = (d); \ - ((uint8_t*)(p))[6] = (d)>>8; \ - ((uint8_t*)(p))[5] = (d)>>16; \ - ((uint8_t*)(p))[4] = (d)>>24; \ - ((uint8_t*)(p))[3] = (d)>>32; \ - ((uint8_t*)(p))[2] = (d)>>40; \ - ((uint8_t*)(p))[1] = (d)>>48; \ - ((uint8_t*)(p))[0] = (d)>>56; } while(0) - -#define AV_RL64(x) (((uint64_t)((const uint8_t*)(x))[7] << 56) | \ - ((uint64_t)((const uint8_t*)(x))[6] << 48) | \ - ((uint64_t)((const uint8_t*)(x))[5] << 40) | \ - ((uint64_t)((const uint8_t*)(x))[4] << 32) | \ - ((uint64_t)((const uint8_t*)(x))[3] << 24) | \ - ((uint64_t)((const uint8_t*)(x))[2] << 16) | \ - ((uint64_t)((const uint8_t*)(x))[1] << 8) | \ - (uint64_t)((const uint8_t*)(x))[0]) -#define AV_WL64(p, d) do { \ - ((uint8_t*)(p))[0] = (d); \ - ((uint8_t*)(p))[1] = (d)>>8; \ - ((uint8_t*)(p))[2] = (d)>>16; \ - ((uint8_t*)(p))[3] = (d)>>24; \ - ((uint8_t*)(p))[4] = (d)>>32; \ - ((uint8_t*)(p))[5] = (d)>>40; \ - ((uint8_t*)(p))[6] = (d)>>48; \ - ((uint8_t*)(p))[7] = (d)>>56; } while(0) -#endif /* HAVE_FAST_UNALIGNED */ - -#define AV_RB24(x) ((((const uint8_t*)(x))[0] << 16) | \ - (((const uint8_t*)(x))[1] << 8) | \ - ((const uint8_t*)(x))[2]) -#define AV_WB24(p, d) do { \ - ((uint8_t*)(p))[2] = (d); \ - ((uint8_t*)(p))[1] = (d)>>8; \ - ((uint8_t*)(p))[0] = (d)>>16; } while(0) - -#define AV_RL24(x) ((((const uint8_t*)(x))[2] << 16) | \ - (((const uint8_t*)(x))[1] << 8) | \ - ((const uint8_t*)(x))[0]) -#define AV_WL24(p, d) do { \ - ((uint8_t*)(p))[0] = (d); \ - ((uint8_t*)(p))[1] = (d)>>8; \ - ((uint8_t*)(p))[2] = (d)>>16; } while(0) - -#endif /* AVUTIL_INTREADWRITE_H */ -- cgit v1.2.3