diff options
Diffstat (limited to 'contrib/ffmpeg/libavutil')
47 files changed, 1742 insertions, 544 deletions
diff --git a/contrib/ffmpeg/libavutil/Makefile b/contrib/ffmpeg/libavutil/Makefile index a760401ab..0cf55f50f 100644 --- a/contrib/ffmpeg/libavutil/Makefile +++ b/contrib/ffmpeg/libavutil/Makefile @@ -1,27 +1,51 @@ include ../config.mak -OBJS= mathematics.o \ - rational.o \ - intfloat_readwrite.o \ - crc.o \ - md5.o \ - lls.o \ - adler32.o \ - log.o \ - mem.o \ - fifo.o \ - tree.o \ - lzo.o \ - random.o \ - aes.o \ - base64.o \ +OBJS = adler32.o \ + aes.o \ + base64.o \ + crc.o \ + des.o \ + fifo.o \ + intfloat_readwrite.o \ + lls.o \ + log.o \ + lzo.o \ + mathematics.o \ + md5.o \ + mem.o \ + random.o \ + rational.o \ + rc4.o \ + sha1.o \ + string.o \ + tree.o \ -HEADERS = avutil.h common.h mathematics.h integer.h rational.h \ - intfloat_readwrite.h md5.h adler32.h log.h fifo.h lzo.h \ - random.h mem.h base64.h +HEADERS = adler32.h \ + avstring.h \ + avutil.h \ + base64.h \ + common.h \ + crc.h \ + fifo.h \ + intfloat_readwrite.h \ + log.h \ + lzo.h \ + mathematics.h \ + md5.h \ + mem.h \ + random.h \ + rational.h \ + sha1.h NAME=avutil LIBVERSION=$(LAVUVERSION) LIBMAJOR=$(LAVUMAJOR) +TESTS = $(addsuffix -test$(EXESUF), adler32 aes crc des lls md5 sha1 softfloat tree) + include ../common.mak + +lzo-test$(EXESUF): EXTRALIBS += -llzo2 + +clean:: + rm -f lzo-test$(EXESUF) diff --git a/contrib/ffmpeg/libavutil/adler32.c b/contrib/ffmpeg/libavutil/adler32.c index 50d57470b..148664e53 100644 --- a/contrib/ffmpeg/libavutil/adler32.c +++ b/contrib/ffmpeg/libavutil/adler32.c @@ -18,7 +18,6 @@ * 2. Altered source versions must be plainly marked as such, and must not be * misrepresented as being the original software. * 3. This notice may not be removed or altered from any source distribution. - * */ #include "common.h" @@ -55,7 +54,7 @@ unsigned long av_adler32_update(unsigned long adler, const uint8_t *buf, unsigne #include "log.h" #define LEN 7001 volatile int checksum; -int main(){ +int main(void){ int i; char data[LEN]; av_log_level = AV_LOG_DEBUG; @@ -67,5 +66,6 @@ int main(){ STOP_TIMER("adler") } av_log(NULL, AV_LOG_DEBUG, "%X == 50E6E508\n", checksum); + return 0; } #endif diff --git a/contrib/ffmpeg/libavutil/adler32.h b/contrib/ffmpeg/libavutil/adler32.h index f56d416fb..2e29e05b2 100644 --- a/contrib/ffmpeg/libavutil/adler32.h +++ b/contrib/ffmpeg/libavutil/adler32.h @@ -18,10 +18,12 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef ADLER32_H -#define ADLER32_H +#ifndef FFMPEG_ADLER32_H +#define FFMPEG_ADLER32_H + +#include <stdint.h> unsigned long av_adler32_update(unsigned long adler, const uint8_t *buf, unsigned int len); -#endif +#endif /* FFMPEG_ADLER32_H */ diff --git a/contrib/ffmpeg/libavutil/aes.c b/contrib/ffmpeg/libavutil/aes.c index 55ae0d4f3..5030dac48 100644 --- a/contrib/ffmpeg/libavutil/aes.c +++ b/contrib/ffmpeg/libavutil/aes.c @@ -1,6 +1,8 @@ /* * copyright (c) 2007 Michael Niedermayer <michaelni@gmx.at> * + * some optimization ideas from aes128.c by Reimar Doeffinger + * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or @@ -16,14 +18,14 @@ * 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 - * - * some optimization ideas from aes128.c by Reimar Doeffinger */ #include "common.h" #include "aes.h" typedef struct AVAES{ + // Note: round_key[16] is accessed in the init code, but this only + // overwrites state, which does not matter (see also r7471). uint8_t round_key[15][4][4]; uint8_t state[2][4][4]; int rounds; @@ -128,7 +130,7 @@ int av_aes_init(AVAES *a, const uint8_t *key, int key_bits, int decrypt) { uint8_t log8[256]; uint8_t alog8[512]; - if(!enc_multbl[4][1023]){ + if(!enc_multbl[0][sizeof(enc_multbl)/sizeof(enc_multbl[0][0])-1]){ j=1; for(i=0; i<255; i++){ alog8[i]= @@ -192,7 +194,9 @@ int av_aes_init(AVAES *a, const uint8_t *key, int key_bits, int decrypt) { #ifdef TEST #include "log.h" -int main(){ +#undef random + +int main(void){ int i,j; AVAES ae, ad, b; uint8_t rkey[2][16]= { diff --git a/contrib/ffmpeg/libavutil/aes.h b/contrib/ffmpeg/libavutil/aes.h index 34ba0a2fa..438ba170e 100644 --- a/contrib/ffmpeg/libavutil/aes.h +++ b/contrib/ffmpeg/libavutil/aes.h @@ -18,15 +18,17 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef AES_H -#define AES_H +#ifndef FFMPEG_AES_H +#define FFMPEG_AES_H + +#include <stdint.h> extern const int av_aes_size; struct AVAES; /** - * initalizes a AVAES context + * initializes an AVAES context * @param key_bits 128, 192 or 256 * @param decrypt 0 for encryption, 1 for decryption */ @@ -37,9 +39,9 @@ int av_aes_init(struct AVAES *a, const uint8_t *key, int key_bits, int decrypt); * @param count number of 16 byte blocks * @param dst destination array, can be equal to src * @param src source array, can be equal to dst - * @param iv initalization vector for CBC mode, if NULL then ECB will be used + * @param iv initialization vector for CBC mode, if NULL then ECB will be used * @param decrypt 0 for encryption, 1 for decryption */ void av_aes_crypt(struct AVAES *a, uint8_t *dst, uint8_t *src, int count, uint8_t *iv, int decrypt); -#endif /* AES_H */ +#endif /* FFMPEG_AES_H */ diff --git a/contrib/ffmpeg/libavutil/avstring.h b/contrib/ffmpeg/libavutil/avstring.h new file mode 100644 index 000000000..ecac9e623 --- /dev/null +++ b/contrib/ffmpeg/libavutil/avstring.h @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2007 Mans Rullgard + * + * 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 FFMPEG_AVSTRING_H +#define FFMPEG_AVSTRING_H + +#include <stddef.h> + +/** + * Return non-zero if pfx is a prefix of str. If it is, *ptr is set to + * the address of the first character in str after the prefix. + * + * @param str input string + * @param pfx prefix to test + * @param ptr updated after the prefix in str in there is a match + * @return non-zero if the prefix matches, zero otherwise + */ +int av_strstart(const char *str, const char *pfx, const char **ptr); + +/** + * Return non-zero if pfx is a prefix of str independent of case. If + * it is, *ptr is set to the address of the first character in str + * after the prefix. + * + * @param str input string + * @param pfx prefix to test + * @param ptr updated after the prefix in str in there is a match + * @return non-zero if the prefix matches, zero otherwise + */ +int av_stristart(const char *str, const char *pfx, const char **ptr); + +/** + * Copy the string src to dst, but no more than size - 1 bytes, and + * null terminate dst. + * + * This function is the same as BSD strlcpy(). + * + * @param dst destination buffer + * @param src source string + * @param size size of destination buffer + * @return the length of src + */ +size_t av_strlcpy(char *dst, const char *src, size_t size); + +/** + * Append the string src to the string dst, but to a total length of + * no more than size - 1 bytes, and null terminate dst. + * + * This function is similar to BSD strlcat(), but differs when + * size <= strlen(dst). + * + * @param dst destination buffer + * @param src source string + * @param size size of destination buffer + * @return the total length of src and dst + */ +size_t av_strlcat(char *dst, const char *src, size_t size); + +/** + * Append output to a string, according to a format. Never write out of + * the destination buffer, and and always put a terminating 0 within + * the buffer. + * @param dst destination buffer (string to which the output is + * appended) + * @param size total size of the destination buffer + * @param fmt printf-compatible format string, specifying how the + * following parameters are used + * @return the length of the string that would have been generated + * if enough space had been available + */ +size_t av_strlcatf(char *dst, size_t size, const char *fmt, ...); + +#endif /* FFMPEG_AVSTRING_H */ diff --git a/contrib/ffmpeg/libavutil/avutil.h b/contrib/ffmpeg/libavutil/avutil.h index 32bc40bfb..3d2bd4be2 100644 --- a/contrib/ffmpeg/libavutil/avutil.h +++ b/contrib/ffmpeg/libavutil/avutil.h @@ -18,8 +18,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef AVUTIL_H -#define AVUTIL_H +#ifndef FFMPEG_AVUTIL_H +#define FFMPEG_AVUTIL_H /** * @file avutil.h @@ -27,15 +27,23 @@ */ -#ifdef __cplusplus -extern "C" { -#endif - #define AV_STRINGIFY(s) AV_TOSTRING(s) #define AV_TOSTRING(s) #s -#define LIBAVUTIL_VERSION_INT ((49<<16)+(4<<8)+0) -#define LIBAVUTIL_VERSION 49.4.0 +#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 49 +#define LIBAVUTIL_VERSION_MINOR 6 +#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) @@ -44,7 +52,6 @@ extern "C" { #include "common.h" #include "mathematics.h" #include "rational.h" -#include "integer.h" #include "intfloat_readwrite.h" #include "log.h" @@ -80,8 +87,8 @@ enum PixelFormat { PIX_FMT_RGB565, ///< Packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), in cpu endianness PIX_FMT_RGB555, ///< Packed RGB 5:5:5, 16bpp, (msb)1A 5R 5G 5B(lsb), in cpu endianness most significant bit to 0 PIX_FMT_GRAY8, ///< Y , 8bpp - PIX_FMT_MONOWHITE, ///< Y , 1bpp, 1 is white - PIX_FMT_MONOBLACK, ///< Y , 1bpp, 0 is black + PIX_FMT_MONOWHITE, ///< Y , 1bpp, 0 is white, 1 is black + PIX_FMT_MONOBLACK, ///< Y , 1bpp, 0 is black, 1 is white PIX_FMT_PAL8, ///< 8 bit with PIX_FMT_RGB32 palette PIX_FMT_YUVJ420P, ///< Planar YUV 4:2:0, 12bpp, full scale (jpeg) PIX_FMT_YUVJ422P, ///< Planar YUV 4:2:2, 16bpp, full scale (jpeg) @@ -107,6 +114,9 @@ enum PixelFormat { PIX_FMT_GRAY16BE, ///< Y , 16bpp, big-endian PIX_FMT_GRAY16LE, ///< Y , 16bpp, little-endian + PIX_FMT_YUV440P, ///< Planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples) + PIX_FMT_YUVJ440P, ///< Planar YUV 4:4:0 full scale (jpeg) + PIX_FMT_YUVA420P, ///< Planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples) PIX_FMT_NB, ///< number of pixel formats, DO NOT USE THIS if you want to link with shared libav* because the number of formats might differ between versions }; @@ -130,8 +140,4 @@ enum PixelFormat { #define PIX_FMT_YUV422 PIX_FMT_YUYV422 #endif -#ifdef __cplusplus -} -#endif - -#endif /* AVUTIL_H */ +#endif /* FFMPEG_AVUTIL_H */ diff --git a/contrib/ffmpeg/libavutil/base64.c b/contrib/ffmpeg/libavutil/base64.c index bee800c82..8567c9924 100644 --- a/contrib/ffmpeg/libavutil/base64.c +++ b/contrib/ffmpeg/libavutil/base64.c @@ -29,7 +29,7 @@ #include "base64.h" /* ---------------- private code */ -static uint8_t map2[] = +static const uint8_t map2[] = { 0x3e, 0xff, 0xff, 0xff, 0x3f, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0xff, @@ -70,7 +70,7 @@ int av_base64_decode(uint8_t * out, const char *in, int out_length) * fixed edge cases and made it work from data (vs. strings) by ryan. *****************************************************************************/ -char *av_base64_encode(char * buf, int buf_len, uint8_t * src, int len) +char *av_base64_encode(char * buf, int buf_len, const uint8_t * src, int len) { static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; @@ -83,20 +83,18 @@ char *av_base64_encode(char * buf, int buf_len, uint8_t * src, int len) buf_len < len * 4 / 3 + 12) return NULL; ret = dst = buf; - if (len) { // special edge case, what should we really do here? - while (bytes_remaining) { - i_bits = (i_bits << 8) + *src++; - bytes_remaining--; - i_shift += 8; - - do { - *dst++ = b64[(i_bits << 6 >> i_shift) & 0x3f]; - i_shift -= 6; - } while (i_shift > 6 || (bytes_remaining == 0 && i_shift > 0)); - } - while ((dst - ret) & 3) - *dst++ = '='; + while (bytes_remaining) { + i_bits = (i_bits << 8) + *src++; + bytes_remaining--; + i_shift += 8; + + do { + *dst++ = b64[(i_bits << 6 >> i_shift) & 0x3f]; + i_shift -= 6; + } while (i_shift > 6 || (bytes_remaining == 0 && i_shift > 0)); } + while ((dst - ret) & 3) + *dst++ = '='; *dst = '\0'; return ret; diff --git a/contrib/ffmpeg/libavutil/base64.h b/contrib/ffmpeg/libavutil/base64.h index 3d905313c..e95e4ea3e 100644 --- a/contrib/ffmpeg/libavutil/base64.h +++ b/contrib/ffmpeg/libavutil/base64.h @@ -19,6 +19,11 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#ifndef FFMPEG_BASE64_H +#define FFMPEG_BASE64_H + +#include <stdint.h> + /** * decodes base64 * param order as strncpy() @@ -30,5 +35,6 @@ int av_base64_decode(uint8_t * out, const char *in, int out_length); * @param src data, not a string * @param buf output string */ -char *av_base64_encode(char * buf, int buf_len, uint8_t * src, int len); +char *av_base64_encode(char * buf, int buf_len, const uint8_t * src, int len); +#endif /* FFMPEG_BASE64_H */ diff --git a/contrib/ffmpeg/libavutil/bswap.h b/contrib/ffmpeg/libavutil/bswap.h index 03d613db2..ee75f88c3 100644 --- a/contrib/ffmpeg/libavutil/bswap.h +++ b/contrib/ffmpeg/libavutil/bswap.h @@ -23,8 +23,11 @@ * byte swap. */ -#ifndef __BSWAP_H__ -#define __BSWAP_H__ +#ifndef FFMPEG_BSWAP_H +#define FFMPEG_BSWAP_H + +#include <stdint.h> +#include "common.h" #ifdef HAVE_BYTESWAP_H #include <byteswap.h> @@ -36,101 +39,58 @@ # define LEGACY_REGS "=q" #endif -#if defined(ARCH_X86) static av_always_inline uint16_t bswap_16(uint16_t x) { - __asm("rorw $8, %0" : - LEGACY_REGS (x) : - "0" (x)); +#if defined(ARCH_X86) + __asm("rorw $8, %0" : + LEGACY_REGS (x) : + "0" (x)); +#elif defined(ARCH_SH4) + __asm__("swap.b %0,%0":"=r"(x):"0"(x)); +#else + x= (x>>8) | (x<<8); +#endif return x; } static av_always_inline uint32_t bswap_32(uint32_t x) { +#if defined(ARCH_X86) #if __CPU__ != 386 - __asm("bswap %0": - "=r" (x) : + __asm("bswap %0": + "=r" (x) : #else - __asm("xchgb %b0,%h0\n" - " rorl $16,%0\n" - " xchgb %b0,%h0": - LEGACY_REGS (x) : + __asm("xchgb %b0,%h0\n" + "rorl $16,%0 \n" + "xchgb %b0,%h0": + LEGACY_REGS (x) : #endif - "0" (x)); - return x; -} - -static inline uint64_t bswap_64(uint64_t x) -{ -#ifdef ARCH_X86_64 - __asm("bswap %0": - "=r" (x) : - "0" (x)); - return x; -#else - union { - uint64_t ll; - struct { - uint32_t l,h; - } l; - } r; - r.l.l = bswap_32 (x); - r.l.h = bswap_32 (x>>32); - return r.ll; -#endif -} - + "0" (x)); #elif defined(ARCH_SH4) - -static av_always_inline uint16_t bswap_16(uint16_t x) { - __asm__("swap.b %0,%0":"=r"(x):"0"(x)); - return x; -} - -static av_always_inline uint32_t bswap_32(uint32_t x) { - __asm__( - "swap.b %0,%0\n" - "swap.w %0,%0\n" - "swap.b %0,%0\n" - :"=r"(x):"0"(x)); - return x; -} - -static inline uint64_t bswap_64(uint64_t x) -{ - union { - uint64_t ll; - struct { - uint32_t l,h; - } l; - } r; - r.l.l = bswap_32 (x); - r.l.h = bswap_32 (x>>32); - return r.ll; -} -#else - -static av_always_inline uint16_t bswap_16(uint16_t x){ - return (x>>8) | (x<<8); -} - -#ifdef ARCH_ARM -static av_always_inline uint32_t bswap_32(uint32_t x){ + __asm__("swap.b %0,%0\n" + "swap.w %0,%0\n" + "swap.b %0,%0\n" + :"=r"(x):"0"(x)); +#elif defined(ARCH_ARM) uint32_t t; - __asm__ ( - "eor %1, %0, %0, ror #16 \n\t" - "bic %1, %1, #0xFF0000 \n\t" - "mov %0, %0, ror #8 \n\t" - "eor %0, %0, %1, lsr #8 \n\t" - : "+r"(x), "+r"(t)); - return x; -} + __asm__ ("eor %1, %0, %0, ror #16 \n\t" + "bic %1, %1, #0xFF0000 \n\t" + "mov %0, %0, ror #8 \n\t" + "eor %0, %0, %1, lsr #8 \n\t" + : "+r"(x), "+r"(t)); +#elif defined(ARCH_BFIN) + unsigned tmp; + asm("%1 = %0 >> 8 (V); \n\t" + "%0 = %0 << 8 (V); \n\t" + "%0 = %0 | %1; \n\t" + "%0 = PACK(%0.L, %0.H); \n\t" + : "+d"(x), "=&d"(tmp)); #else -static av_always_inline uint32_t bswap_32(uint32_t x){ x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF); - return (x>>16) | (x<<16); -} + x= (x>>16) | (x<<16); #endif + return x; +} static inline uint64_t bswap_64(uint64_t x) { @@ -138,6 +98,11 @@ static inline uint64_t bswap_64(uint64_t x) x= ((x<< 8)&0xFF00FF00FF00FF00ULL) | ((x>> 8)&0x00FF00FF00FF00FFULL); x= ((x<<16)&0xFFFF0000FFFF0000ULL) | ((x>>16)&0x0000FFFF0000FFFFULL); return (x>>32) | (x<<32); +#elif defined(ARCH_X86_64) + __asm("bswap %0": + "=r" (x) : + "0" (x)); + return x; #else union { uint64_t ll; @@ -149,7 +114,6 @@ static inline uint64_t bswap_64(uint64_t x) return r.ll; #endif } -#endif /* defined(ARCH_X86) */ #endif /* !HAVE_BYTESWAP_H */ @@ -172,4 +136,4 @@ static inline uint64_t bswap_64(uint64_t x) #define le2me_64(x) (x) #endif -#endif /* __BSWAP_H__ */ +#endif /* FFMPEG_BSWAP_H */ diff --git a/contrib/ffmpeg/libavutil/common.h b/contrib/ffmpeg/libavutil/common.h index 9ec5c7c78..ce017b090 100644 --- a/contrib/ffmpeg/libavutil/common.h +++ b/contrib/ffmpeg/libavutil/common.h @@ -23,8 +23,8 @@ * common internal and external api header. */ -#ifndef COMMON_H -#define COMMON_H +#ifndef FFMPEG_COMMON_H +#define FFMPEG_COMMON_H #include <inttypes.h> @@ -44,9 +44,15 @@ #ifndef av_always_inline #if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0) # define av_always_inline __attribute__((always_inline)) inline -# define av_noinline __attribute__((noinline)) #else # define av_always_inline inline +#endif +#endif + +#ifndef av_noinline +#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0) +# define av_noinline __attribute__((noinline)) +#else # define av_noinline #endif #endif @@ -63,6 +69,14 @@ #endif #endif +#ifndef av_unused +#if defined(__GNUC__) +# define av_unused __attribute__((unused)) +#else +# define av_unused +#endif +#endif + #include "mem.h" //rounded divison & shift @@ -82,9 +96,7 @@ extern const uint8_t ff_log2_tab[256]; static inline int av_log2(unsigned int v) { - int n; - - n = 0; + int n = 0; if (v & 0xffff0000) { v >>= 16; n += 16; @@ -100,9 +112,7 @@ static inline int av_log2(unsigned int v) static inline int av_log2_16bit(unsigned int v) { - int n; - - n = 0; + int n = 0; if (v & 0xff00) { v >>= 8; n += 8; @@ -162,7 +172,7 @@ static inline int mid_pred(int a, int b, int c) */ static inline int av_clip(int a, int amin, int amax) { - if (a < amin) return amin; + if (a < amin) return amin; else if (a > amax) return amax; else return a; } @@ -178,6 +188,17 @@ static inline uint8_t av_clip_uint8(int a) else return a; } +/** + * clip a signed integer value into the -32768,32767 range + * @param a value to clip + * @return clipped value + */ +static inline int16_t av_clip_int16(int a) +{ + if ((a+32768) & ~65535) return (a>>31) ^ 32767; + else return a; +} + /* math */ int64_t ff_gcd(int64_t a, int64_t b); @@ -197,14 +218,14 @@ static inline int ff_get_fourcc(const char *s){ /*! * \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 + * 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 + * 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, + * 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 + * \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. */ @@ -225,17 +246,17 @@ static inline int ff_get_fourcc(const char *s){ /*! * \def PUT_UTF8(val, tmp, PUT_BYTE) - * converts a 32-bit unicode character to its utf-8 encoded form (up to 4 bytes long). + * 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 ucs4 encoded unicode character that is to be converted to utf-8. If + * a ucs4 encoded unicode character that is to be converted to UTF-8. If * val is given as a function it's 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 * outputted by PUT_BYTE. - * \param PUT_BYTE writes the converted utf-8 bytes to any proper destination. + * \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 + * 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. */ @@ -259,24 +280,36 @@ static inline int ff_get_fourcc(const char *s){ }\ } -#if defined(ARCH_X86) || defined(ARCH_POWERPC) +#if defined(ARCH_X86) || defined(ARCH_POWERPC) || defined(ARCH_BFIN) +#define AV_READ_TIME read_time #if defined(ARCH_X86_64) static inline uint64_t read_time(void) { - uint64_t a, d; - asm volatile( "rdtsc\n\t" - : "=a" (a), "=d" (d) - ); - return (d << 32) | (a & 0xffffffff); + uint64_t a, d; + asm volatile("rdtsc\n\t" + : "=a" (a), "=d" (d)); + return (d << 32) | (a & 0xffffffff); } #elif defined(ARCH_X86_32) static inline long long read_time(void) { - long long l; - asm volatile( "rdtsc\n\t" - : "=A" (l) - ); - return l; + long long l; + asm volatile("rdtsc\n\t" + : "=A" (l)); + return l; +} +#elif ARCH_BFIN +static inline uint64_t read_time(void) +{ + union { + struct { + unsigned lo; + unsigned hi; + } p; + unsigned long long c; + } t; + asm volatile ("%0=cycles; %1=cycles2;" : "=d" (t.p.lo), "=d" (t.p.hi)); + return t.c; } #else //FIXME check ppc64 static inline uint64_t read_time(void) @@ -298,29 +331,34 @@ static inline uint64_t read_time(void) return (((uint64_t)tbu)<<32) | (uint64_t)tbl; } #endif +#elif defined(HAVE_GETHRTIME) +#define AV_READ_TIME gethrtime +#endif +#ifdef AV_READ_TIME #define START_TIMER \ uint64_t tend;\ -uint64_t tstart= read_time();\ +uint64_t tstart= AV_READ_TIME();\ #define STOP_TIMER(id) \ -tend= read_time();\ +tend= AV_READ_TIME();\ {\ - static uint64_t tsum=0;\ - static int tcount=0;\ - static int tskip_count=0;\ - if(tcount<2 || tend - tstart < FFMAX(8*tsum/tcount, 2000)){\ - tsum+= tend - tstart;\ - tcount++;\ - }else\ - tskip_count++;\ - if(((tcount+tskip_count)&(tcount+tskip_count-1))==0){\ - av_log(NULL, AV_LOG_DEBUG, "%"PRIu64" dezicycles in %s, %d runs, %d skips\n", tsum*10/tcount, id, tcount, tskip_count);\ - }\ + static uint64_t tsum=0;\ + static int tcount=0;\ + static int tskip_count=0;\ + if(tcount<2 || tend - tstart < FFMAX(8*tsum/tcount, 2000)){\ + tsum+= tend - tstart;\ + tcount++;\ + }else\ + tskip_count++;\ + if(((tcount+tskip_count)&(tcount+tskip_count-1))==0){\ + av_log(NULL, AV_LOG_DEBUG, "%"PRIu64" dezicycles in %s, %d runs, %d skips\n",\ + tsum*10/tcount, id, tcount, tskip_count);\ + }\ } #else #define START_TIMER #define STOP_TIMER(id) {} #endif -#endif /* COMMON_H */ +#endif /* FFMPEG_COMMON_H */ diff --git a/contrib/ffmpeg/libavutil/crc.c b/contrib/ffmpeg/libavutil/crc.c index 02fb860b8..743a64038 100644 --- a/contrib/ffmpeg/libavutil/crc.c +++ b/contrib/ffmpeg/libavutil/crc.c @@ -21,22 +21,36 @@ #include "common.h" #include "crc.h" -#if LIBAVUTIL_VERSION_INT < (50<<16) -AVCRC *av_crcEDB88320; -AVCRC *av_crc04C11DB7; -AVCRC *av_crc8005 ; -AVCRC *av_crc07 ; +#ifdef CONFIG_HARDCODED_TABLES +#include "crc_data.h" #else -AVCRC av_crcEDB88320[257]; -AVCRC av_crc04C11DB7[257]; -AVCRC av_crc8005 [257]; -AVCRC av_crc07 [257]; +static struct { + uint8_t le; + uint8_t bits; + uint32_t poly; +} av_crc_table_params[AV_CRC_MAX] = { + [AV_CRC_8_ATM] = { 0, 8, 0x07 }, + [AV_CRC_16_ANSI] = { 0, 16, 0x8005 }, + [AV_CRC_16_CCITT] = { 0, 16, 0x1021 }, + [AV_CRC_32_IEEE] = { 0, 32, 0x04C11DB7 }, + [AV_CRC_32_IEEE_LE] = { 1, 32, 0xEDB88320 }, +}; +static AVCRC av_crc_table[AV_CRC_MAX][257]; #endif /** * Inits a crc table. * @param ctx must be an array of sizeof(AVCRC)*257 or sizeof(AVCRC)*1024 * @param cts_size size of ctx in bytes + * @param le if 1, lowest bit represents coefficient for highest exponent + * of corresponding polynomial (both for poly and actual CRC). + * If 0, you must swap the crc parameter and the result of av_crc + * if you need the standard representation (can be simplified in + * most cases to e.g. bswap16): + * bswap_32(crc << (32-bits)) + * @param bits number of bits for the CRC + * @param poly generator polynomial without the x**bits coefficient, in the + * representation as specified by le * @return <0 on failure */ int av_crc_init(AVCRC *ctx, int le, int bits, uint32_t poly, int ctx_size){ @@ -70,13 +84,38 @@ int av_crc_init(AVCRC *ctx, int le, int bits, uint32_t poly, int ctx_size){ return 0; } +/** + * Get an initialized standard CRC table. + * @param crc_id ID of a standard CRC + * @return a pointer to the CRC table or NULL on failure + */ +const AVCRC *av_crc_get_table(AVCRCId crc_id){ +#ifndef CONFIG_HARDCODED_TABLES + if (!av_crc_table[crc_id][sizeof(av_crc_table[crc_id])/sizeof(av_crc_table[crc_id][0])-1]) + if (av_crc_init(av_crc_table[crc_id], + av_crc_table_params[crc_id].le, + av_crc_table_params[crc_id].bits, + av_crc_table_params[crc_id].poly, + sizeof(av_crc_table[crc_id])) < 0) + return NULL; +#endif + return av_crc_table[crc_id]; +} + +/** + * Calculate the CRC of a block + * @param crc CRC of previous blocks if any or initial value for CRC. + * @return CRC updated with the data from the given block + * + * @see av_crc_init() "le" parameter + */ uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length){ const uint8_t *end= buffer+length; #ifndef CONFIG_SMALL if(!ctx[256]) while(buffer<end-3){ - crc ^= le2me_32(*(uint32_t*)buffer); buffer+=4; + crc ^= le2me_32(*(const uint32_t*)buffer); buffer+=4; crc = ctx[3*256 + ( crc &0xFF)] ^ctx[2*256 + ((crc>>8 )&0xFF)] ^ctx[1*256 + ((crc>>16)&0xFF)] @@ -91,21 +130,22 @@ uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t le #ifdef TEST #undef printf -main(){ +int main(void){ uint8_t buf[1999]; int i; - int p[4][4]={{1, 32, 0xedb88320L, 0x3D5CDD04}, - {0, 32, 0x04c11db7L, 0xC0F5BAE0}, - {0, 16, 0x8005 , 0x1FBB }, - {0, 8, 0x07 , 0xE3 },}; - AVCRC ctx[1 ? 1024:257]; + int p[4][3]={{AV_CRC_32_IEEE_LE, 0xEDB88320, 0x3D5CDD04}, + {AV_CRC_32_IEEE , 0x04C11DB7, 0xC0F5BAE0}, + {AV_CRC_16_ANSI , 0x8005, 0x1FBB }, + {AV_CRC_8_ATM , 0x07, 0xE3 },}; + const AVCRC *ctx; for(i=0; i<sizeof(buf); i++) buf[i]= i+i*i; for(i=0; i<4; i++){ - av_crc_init(ctx, p[i][0], p[i][1], p[i][2], sizeof(ctx)); - printf("crc %08X =%X\n", p[i][2], av_crc(ctx, 0, buf, sizeof(buf))); + ctx = av_crc_get_table(p[i][0]); + printf("crc %08X =%X\n", p[i][1], av_crc(ctx, 0, buf, sizeof(buf))); } + return 0; } #endif diff --git a/contrib/ffmpeg/libavutil/crc.h b/contrib/ffmpeg/libavutil/crc.h index 1f6431992..28cb7c021 100644 --- a/contrib/ffmpeg/libavutil/crc.h +++ b/contrib/ffmpeg/libavutil/crc.h @@ -18,25 +18,26 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef CRC_H -#define CRC_H +#ifndef FFMPEG_CRC_H +#define FFMPEG_CRC_H + +#include <stdint.h> +#include <sys/types.h> typedef uint32_t AVCRC; -#if LIBAVUTIL_VERSION_INT < (50<<16) -extern AVCRC *av_crcEDB88320; -extern AVCRC *av_crc04C11DB7; -extern AVCRC *av_crc8005 ; -extern AVCRC *av_crc07 ; -#else -extern AVCRC av_crcEDB88320[]; -extern AVCRC av_crc04C11DB7[]; -extern AVCRC av_crc8005 []; -extern AVCRC av_crc07 []; -#endif +typedef enum { + AV_CRC_8_ATM, + AV_CRC_16_ANSI, + AV_CRC_16_CCITT, + AV_CRC_32_IEEE, + AV_CRC_32_IEEE_LE, /*< reversed bitorder version of AV_CRC_32_IEEE */ + AV_CRC_MAX, /*< not part of public API! don't use outside lavu */ +}AVCRCId; int av_crc_init(AVCRC *ctx, int le, int bits, uint32_t poly, int ctx_size); +const AVCRC *av_crc_get_table(AVCRCId crc_id); uint32_t av_crc(const AVCRC *ctx, uint32_t start_crc, const uint8_t *buffer, size_t length); -#endif /* CRC_H */ +#endif /* FFMPEG_CRC_H */ diff --git a/contrib/ffmpeg/libavutil/crc_data.h b/contrib/ffmpeg/libavutil/crc_data.h new file mode 100644 index 000000000..857678dd6 --- /dev/null +++ b/contrib/ffmpeg/libavutil/crc_data.h @@ -0,0 +1,213 @@ +/* + * copyright (c) 2008 Aurelien Jacobs <aurel@gnuage.org> + * + * 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 FFMPEG_CRC_DATA_H +#define FFMPEG_CRC_DATA_H + +#include "crc.h" + +static const AVCRC av_crc_table[AV_CRC_MAX][257] = { + [AV_CRC_8_ATM] = { + 0x00, 0x07, 0x0E, 0x09, 0x1C, 0x1B, 0x12, 0x15, 0x38, 0x3F, 0x36, 0x31, + 0x24, 0x23, 0x2A, 0x2D, 0x70, 0x77, 0x7E, 0x79, 0x6C, 0x6B, 0x62, 0x65, + 0x48, 0x4F, 0x46, 0x41, 0x54, 0x53, 0x5A, 0x5D, 0xE0, 0xE7, 0xEE, 0xE9, + 0xFC, 0xFB, 0xF2, 0xF5, 0xD8, 0xDF, 0xD6, 0xD1, 0xC4, 0xC3, 0xCA, 0xCD, + 0x90, 0x97, 0x9E, 0x99, 0x8C, 0x8B, 0x82, 0x85, 0xA8, 0xAF, 0xA6, 0xA1, + 0xB4, 0xB3, 0xBA, 0xBD, 0xC7, 0xC0, 0xC9, 0xCE, 0xDB, 0xDC, 0xD5, 0xD2, + 0xFF, 0xF8, 0xF1, 0xF6, 0xE3, 0xE4, 0xED, 0xEA, 0xB7, 0xB0, 0xB9, 0xBE, + 0xAB, 0xAC, 0xA5, 0xA2, 0x8F, 0x88, 0x81, 0x86, 0x93, 0x94, 0x9D, 0x9A, + 0x27, 0x20, 0x29, 0x2E, 0x3B, 0x3C, 0x35, 0x32, 0x1F, 0x18, 0x11, 0x16, + 0x03, 0x04, 0x0D, 0x0A, 0x57, 0x50, 0x59, 0x5E, 0x4B, 0x4C, 0x45, 0x42, + 0x6F, 0x68, 0x61, 0x66, 0x73, 0x74, 0x7D, 0x7A, 0x89, 0x8E, 0x87, 0x80, + 0x95, 0x92, 0x9B, 0x9C, 0xB1, 0xB6, 0xBF, 0xB8, 0xAD, 0xAA, 0xA3, 0xA4, + 0xF9, 0xFE, 0xF7, 0xF0, 0xE5, 0xE2, 0xEB, 0xEC, 0xC1, 0xC6, 0xCF, 0xC8, + 0xDD, 0xDA, 0xD3, 0xD4, 0x69, 0x6E, 0x67, 0x60, 0x75, 0x72, 0x7B, 0x7C, + 0x51, 0x56, 0x5F, 0x58, 0x4D, 0x4A, 0x43, 0x44, 0x19, 0x1E, 0x17, 0x10, + 0x05, 0x02, 0x0B, 0x0C, 0x21, 0x26, 0x2F, 0x28, 0x3D, 0x3A, 0x33, 0x34, + 0x4E, 0x49, 0x40, 0x47, 0x52, 0x55, 0x5C, 0x5B, 0x76, 0x71, 0x78, 0x7F, + 0x6A, 0x6D, 0x64, 0x63, 0x3E, 0x39, 0x30, 0x37, 0x22, 0x25, 0x2C, 0x2B, + 0x06, 0x01, 0x08, 0x0F, 0x1A, 0x1D, 0x14, 0x13, 0xAE, 0xA9, 0xA0, 0xA7, + 0xB2, 0xB5, 0xBC, 0xBB, 0x96, 0x91, 0x98, 0x9F, 0x8A, 0x8D, 0x84, 0x83, + 0xDE, 0xD9, 0xD0, 0xD7, 0xC2, 0xC5, 0xCC, 0xCB, 0xE6, 0xE1, 0xE8, 0xEF, + 0xFA, 0xFD, 0xF4, 0xF3, 0x01 + }, + [AV_CRC_16_ANSI] = { + 0x0000, 0x0580, 0x0F80, 0x0A00, 0x1B80, 0x1E00, 0x1400, 0x1180, + 0x3380, 0x3600, 0x3C00, 0x3980, 0x2800, 0x2D80, 0x2780, 0x2200, + 0x6380, 0x6600, 0x6C00, 0x6980, 0x7800, 0x7D80, 0x7780, 0x7200, + 0x5000, 0x5580, 0x5F80, 0x5A00, 0x4B80, 0x4E00, 0x4400, 0x4180, + 0xC380, 0xC600, 0xCC00, 0xC980, 0xD800, 0xDD80, 0xD780, 0xD200, + 0xF000, 0xF580, 0xFF80, 0xFA00, 0xEB80, 0xEE00, 0xE400, 0xE180, + 0xA000, 0xA580, 0xAF80, 0xAA00, 0xBB80, 0xBE00, 0xB400, 0xB180, + 0x9380, 0x9600, 0x9C00, 0x9980, 0x8800, 0x8D80, 0x8780, 0x8200, + 0x8381, 0x8601, 0x8C01, 0x8981, 0x9801, 0x9D81, 0x9781, 0x9201, + 0xB001, 0xB581, 0xBF81, 0xBA01, 0xAB81, 0xAE01, 0xA401, 0xA181, + 0xE001, 0xE581, 0xEF81, 0xEA01, 0xFB81, 0xFE01, 0xF401, 0xF181, + 0xD381, 0xD601, 0xDC01, 0xD981, 0xC801, 0xCD81, 0xC781, 0xC201, + 0x4001, 0x4581, 0x4F81, 0x4A01, 0x5B81, 0x5E01, 0x5401, 0x5181, + 0x7381, 0x7601, 0x7C01, 0x7981, 0x6801, 0x6D81, 0x6781, 0x6201, + 0x2381, 0x2601, 0x2C01, 0x2981, 0x3801, 0x3D81, 0x3781, 0x3201, + 0x1001, 0x1581, 0x1F81, 0x1A01, 0x0B81, 0x0E01, 0x0401, 0x0181, + 0x0383, 0x0603, 0x0C03, 0x0983, 0x1803, 0x1D83, 0x1783, 0x1203, + 0x3003, 0x3583, 0x3F83, 0x3A03, 0x2B83, 0x2E03, 0x2403, 0x2183, + 0x6003, 0x6583, 0x6F83, 0x6A03, 0x7B83, 0x7E03, 0x7403, 0x7183, + 0x5383, 0x5603, 0x5C03, 0x5983, 0x4803, 0x4D83, 0x4783, 0x4203, + 0xC003, 0xC583, 0xCF83, 0xCA03, 0xDB83, 0xDE03, 0xD403, 0xD183, + 0xF383, 0xF603, 0xFC03, 0xF983, 0xE803, 0xED83, 0xE783, 0xE203, + 0xA383, 0xA603, 0xAC03, 0xA983, 0xB803, 0xBD83, 0xB783, 0xB203, + 0x9003, 0x9583, 0x9F83, 0x9A03, 0x8B83, 0x8E03, 0x8403, 0x8183, + 0x8002, 0x8582, 0x8F82, 0x8A02, 0x9B82, 0x9E02, 0x9402, 0x9182, + 0xB382, 0xB602, 0xBC02, 0xB982, 0xA802, 0xAD82, 0xA782, 0xA202, + 0xE382, 0xE602, 0xEC02, 0xE982, 0xF802, 0xFD82, 0xF782, 0xF202, + 0xD002, 0xD582, 0xDF82, 0xDA02, 0xCB82, 0xCE02, 0xC402, 0xC182, + 0x4382, 0x4602, 0x4C02, 0x4982, 0x5802, 0x5D82, 0x5782, 0x5202, + 0x7002, 0x7582, 0x7F82, 0x7A02, 0x6B82, 0x6E02, 0x6402, 0x6182, + 0x2002, 0x2582, 0x2F82, 0x2A02, 0x3B82, 0x3E02, 0x3402, 0x3182, + 0x1382, 0x1602, 0x1C02, 0x1982, 0x0802, 0x0D82, 0x0782, 0x0202, + 0x0001 + }, + [AV_CRC_16_CCITT] = { + 0x0000, 0x2110, 0x4220, 0x6330, 0x8440, 0xA550, 0xC660, 0xE770, + 0x0881, 0x2991, 0x4AA1, 0x6BB1, 0x8CC1, 0xADD1, 0xCEE1, 0xEFF1, + 0x3112, 0x1002, 0x7332, 0x5222, 0xB552, 0x9442, 0xF772, 0xD662, + 0x3993, 0x1883, 0x7BB3, 0x5AA3, 0xBDD3, 0x9CC3, 0xFFF3, 0xDEE3, + 0x6224, 0x4334, 0x2004, 0x0114, 0xE664, 0xC774, 0xA444, 0x8554, + 0x6AA5, 0x4BB5, 0x2885, 0x0995, 0xEEE5, 0xCFF5, 0xACC5, 0x8DD5, + 0x5336, 0x7226, 0x1116, 0x3006, 0xD776, 0xF666, 0x9556, 0xB446, + 0x5BB7, 0x7AA7, 0x1997, 0x3887, 0xDFF7, 0xFEE7, 0x9DD7, 0xBCC7, + 0xC448, 0xE558, 0x8668, 0xA778, 0x4008, 0x6118, 0x0228, 0x2338, + 0xCCC9, 0xEDD9, 0x8EE9, 0xAFF9, 0x4889, 0x6999, 0x0AA9, 0x2BB9, + 0xF55A, 0xD44A, 0xB77A, 0x966A, 0x711A, 0x500A, 0x333A, 0x122A, + 0xFDDB, 0xDCCB, 0xBFFB, 0x9EEB, 0x799B, 0x588B, 0x3BBB, 0x1AAB, + 0xA66C, 0x877C, 0xE44C, 0xC55C, 0x222C, 0x033C, 0x600C, 0x411C, + 0xAEED, 0x8FFD, 0xECCD, 0xCDDD, 0x2AAD, 0x0BBD, 0x688D, 0x499D, + 0x977E, 0xB66E, 0xD55E, 0xF44E, 0x133E, 0x322E, 0x511E, 0x700E, + 0x9FFF, 0xBEEF, 0xDDDF, 0xFCCF, 0x1BBF, 0x3AAF, 0x599F, 0x788F, + 0x8891, 0xA981, 0xCAB1, 0xEBA1, 0x0CD1, 0x2DC1, 0x4EF1, 0x6FE1, + 0x8010, 0xA100, 0xC230, 0xE320, 0x0450, 0x2540, 0x4670, 0x6760, + 0xB983, 0x9893, 0xFBA3, 0xDAB3, 0x3DC3, 0x1CD3, 0x7FE3, 0x5EF3, + 0xB102, 0x9012, 0xF322, 0xD232, 0x3542, 0x1452, 0x7762, 0x5672, + 0xEAB5, 0xCBA5, 0xA895, 0x8985, 0x6EF5, 0x4FE5, 0x2CD5, 0x0DC5, + 0xE234, 0xC324, 0xA014, 0x8104, 0x6674, 0x4764, 0x2454, 0x0544, + 0xDBA7, 0xFAB7, 0x9987, 0xB897, 0x5FE7, 0x7EF7, 0x1DC7, 0x3CD7, + 0xD326, 0xF236, 0x9106, 0xB016, 0x5766, 0x7676, 0x1546, 0x3456, + 0x4CD9, 0x6DC9, 0x0EF9, 0x2FE9, 0xC899, 0xE989, 0x8AB9, 0xABA9, + 0x4458, 0x6548, 0x0678, 0x2768, 0xC018, 0xE108, 0x8238, 0xA328, + 0x7DCB, 0x5CDB, 0x3FEB, 0x1EFB, 0xF98B, 0xD89B, 0xBBAB, 0x9ABB, + 0x754A, 0x545A, 0x376A, 0x167A, 0xF10A, 0xD01A, 0xB32A, 0x923A, + 0x2EFD, 0x0FED, 0x6CDD, 0x4DCD, 0xAABD, 0x8BAD, 0xE89D, 0xC98D, + 0x267C, 0x076C, 0x645C, 0x454C, 0xA23C, 0x832C, 0xE01C, 0xC10C, + 0x1FEF, 0x3EFF, 0x5DCF, 0x7CDF, 0x9BAF, 0xBABF, 0xD98F, 0xF89F, + 0x176E, 0x367E, 0x554E, 0x745E, 0x932E, 0xB23E, 0xD10E, 0xF01E, + 0x0001 + }, + [AV_CRC_32_IEEE] = { + 0x00000000, 0xB71DC104, 0x6E3B8209, 0xD926430D, 0xDC760413, 0x6B6BC517, + 0xB24D861A, 0x0550471E, 0xB8ED0826, 0x0FF0C922, 0xD6D68A2F, 0x61CB4B2B, + 0x649B0C35, 0xD386CD31, 0x0AA08E3C, 0xBDBD4F38, 0x70DB114C, 0xC7C6D048, + 0x1EE09345, 0xA9FD5241, 0xACAD155F, 0x1BB0D45B, 0xC2969756, 0x758B5652, + 0xC836196A, 0x7F2BD86E, 0xA60D9B63, 0x11105A67, 0x14401D79, 0xA35DDC7D, + 0x7A7B9F70, 0xCD665E74, 0xE0B62398, 0x57ABE29C, 0x8E8DA191, 0x39906095, + 0x3CC0278B, 0x8BDDE68F, 0x52FBA582, 0xE5E66486, 0x585B2BBE, 0xEF46EABA, + 0x3660A9B7, 0x817D68B3, 0x842D2FAD, 0x3330EEA9, 0xEA16ADA4, 0x5D0B6CA0, + 0x906D32D4, 0x2770F3D0, 0xFE56B0DD, 0x494B71D9, 0x4C1B36C7, 0xFB06F7C3, + 0x2220B4CE, 0x953D75CA, 0x28803AF2, 0x9F9DFBF6, 0x46BBB8FB, 0xF1A679FF, + 0xF4F63EE1, 0x43EBFFE5, 0x9ACDBCE8, 0x2DD07DEC, 0x77708634, 0xC06D4730, + 0x194B043D, 0xAE56C539, 0xAB068227, 0x1C1B4323, 0xC53D002E, 0x7220C12A, + 0xCF9D8E12, 0x78804F16, 0xA1A60C1B, 0x16BBCD1F, 0x13EB8A01, 0xA4F64B05, + 0x7DD00808, 0xCACDC90C, 0x07AB9778, 0xB0B6567C, 0x69901571, 0xDE8DD475, + 0xDBDD936B, 0x6CC0526F, 0xB5E61162, 0x02FBD066, 0xBF469F5E, 0x085B5E5A, + 0xD17D1D57, 0x6660DC53, 0x63309B4D, 0xD42D5A49, 0x0D0B1944, 0xBA16D840, + 0x97C6A5AC, 0x20DB64A8, 0xF9FD27A5, 0x4EE0E6A1, 0x4BB0A1BF, 0xFCAD60BB, + 0x258B23B6, 0x9296E2B2, 0x2F2BAD8A, 0x98366C8E, 0x41102F83, 0xF60DEE87, + 0xF35DA999, 0x4440689D, 0x9D662B90, 0x2A7BEA94, 0xE71DB4E0, 0x500075E4, + 0x892636E9, 0x3E3BF7ED, 0x3B6BB0F3, 0x8C7671F7, 0x555032FA, 0xE24DF3FE, + 0x5FF0BCC6, 0xE8ED7DC2, 0x31CB3ECF, 0x86D6FFCB, 0x8386B8D5, 0x349B79D1, + 0xEDBD3ADC, 0x5AA0FBD8, 0xEEE00C69, 0x59FDCD6D, 0x80DB8E60, 0x37C64F64, + 0x3296087A, 0x858BC97E, 0x5CAD8A73, 0xEBB04B77, 0x560D044F, 0xE110C54B, + 0x38368646, 0x8F2B4742, 0x8A7B005C, 0x3D66C158, 0xE4408255, 0x535D4351, + 0x9E3B1D25, 0x2926DC21, 0xF0009F2C, 0x471D5E28, 0x424D1936, 0xF550D832, + 0x2C769B3F, 0x9B6B5A3B, 0x26D61503, 0x91CBD407, 0x48ED970A, 0xFFF0560E, + 0xFAA01110, 0x4DBDD014, 0x949B9319, 0x2386521D, 0x0E562FF1, 0xB94BEEF5, + 0x606DADF8, 0xD7706CFC, 0xD2202BE2, 0x653DEAE6, 0xBC1BA9EB, 0x0B0668EF, + 0xB6BB27D7, 0x01A6E6D3, 0xD880A5DE, 0x6F9D64DA, 0x6ACD23C4, 0xDDD0E2C0, + 0x04F6A1CD, 0xB3EB60C9, 0x7E8D3EBD, 0xC990FFB9, 0x10B6BCB4, 0xA7AB7DB0, + 0xA2FB3AAE, 0x15E6FBAA, 0xCCC0B8A7, 0x7BDD79A3, 0xC660369B, 0x717DF79F, + 0xA85BB492, 0x1F467596, 0x1A163288, 0xAD0BF38C, 0x742DB081, 0xC3307185, + 0x99908A5D, 0x2E8D4B59, 0xF7AB0854, 0x40B6C950, 0x45E68E4E, 0xF2FB4F4A, + 0x2BDD0C47, 0x9CC0CD43, 0x217D827B, 0x9660437F, 0x4F460072, 0xF85BC176, + 0xFD0B8668, 0x4A16476C, 0x93300461, 0x242DC565, 0xE94B9B11, 0x5E565A15, + 0x87701918, 0x306DD81C, 0x353D9F02, 0x82205E06, 0x5B061D0B, 0xEC1BDC0F, + 0x51A69337, 0xE6BB5233, 0x3F9D113E, 0x8880D03A, 0x8DD09724, 0x3ACD5620, + 0xE3EB152D, 0x54F6D429, 0x7926A9C5, 0xCE3B68C1, 0x171D2BCC, 0xA000EAC8, + 0xA550ADD6, 0x124D6CD2, 0xCB6B2FDF, 0x7C76EEDB, 0xC1CBA1E3, 0x76D660E7, + 0xAFF023EA, 0x18EDE2EE, 0x1DBDA5F0, 0xAAA064F4, 0x738627F9, 0xC49BE6FD, + 0x09FDB889, 0xBEE0798D, 0x67C63A80, 0xD0DBFB84, 0xD58BBC9A, 0x62967D9E, + 0xBBB03E93, 0x0CADFF97, 0xB110B0AF, 0x060D71AB, 0xDF2B32A6, 0x6836F3A2, + 0x6D66B4BC, 0xDA7B75B8, 0x035D36B5, 0xB440F7B1, 0x00000001 + }, + [AV_CRC_32_IEEE_LE] = { + 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, + 0xE963A535, 0x9E6495A3, 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, + 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, 0x1DB71064, 0x6AB020F2, + 0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, + 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9, + 0xFA0F3D63, 0x8D080DF5, 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, + 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B, 0x35B5A8FA, 0x42B2986C, + 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59, + 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, + 0xCFBA9599, 0xB8BDA50F, 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, + 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D, 0x76DC4190, 0x01DB7106, + 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433, + 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, + 0x91646C97, 0xE6635C01, 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, + 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457, 0x65B0D9C6, 0x12B7E950, + 0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65, + 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, + 0xA4D1C46D, 0xD3D6F4FB, 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, + 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9, 0x5005713C, 0x270241AA, + 0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F, + 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81, + 0xB7BD5C3B, 0xC0BA6CAD, 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, + 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683, 0xE3630B12, 0x94643B84, + 0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1, + 0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB, + 0x196C3671, 0x6E6B06E7, 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, + 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5, 0xD6D6A3E8, 0xA1D1937E, + 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B, + 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, + 0x316E8EEF, 0x4669BE79, 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, + 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F, 0xC5BA3BBE, 0xB2BD0B28, + 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D, + 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F, + 0x72076785, 0x05005713, 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, + 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21, 0x86D3D2D4, 0xF1D4E242, + 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777, + 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69, + 0x616BFFD3, 0x166CCF45, 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, + 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB, 0xAED16A4A, 0xD9D65ADC, + 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9, + 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693, + 0x54DE5729, 0x23D967BF, 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, + 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D, 0x00000001 + }, +}; + +#endif /* FFMPEG_CRC_DATA_H */ diff --git a/contrib/ffmpeg/libavutil/des.c b/contrib/ffmpeg/libavutil/des.c new file mode 100644 index 000000000..36f90ffaa --- /dev/null +++ b/contrib/ffmpeg/libavutil/des.c @@ -0,0 +1,330 @@ +/* + * DES encryption/decryption + * Copyright (c) 2007 Reimar Doeffinger + * + * 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 + */ +#include <inttypes.h> +#include "des.h" + +#define T(a, b, c, d, e, f, g, h) 64-a,64-b,64-c,64-d,64-e,64-f,64-g,64-h +static const uint8_t IP_shuffle[] = { + T(58, 50, 42, 34, 26, 18, 10, 2), + T(60, 52, 44, 36, 28, 20, 12, 4), + T(62, 54, 46, 38, 30, 22, 14, 6), + T(64, 56, 48, 40, 32, 24, 16, 8), + T(57, 49, 41, 33, 25, 17, 9, 1), + T(59, 51, 43, 35, 27, 19, 11, 3), + T(61, 53, 45, 37, 29, 21, 13, 5), + T(63, 55, 47, 39, 31, 23, 15, 7) +}; +#undef T + +#define T(a, b, c, d) 32-a,32-b,32-c,32-d +static const uint8_t P_shuffle[] = { + T(16, 7, 20, 21), + T(29, 12, 28, 17), + T( 1, 15, 23, 26), + T( 5, 18, 31, 10), + T( 2, 8, 24, 14), + T(32, 27, 3, 9), + T(19, 13, 30, 6), + T(22, 11, 4, 25) +}; +#undef T + +#define T(a, b, c, d, e, f, g) 64-a,64-b,64-c,64-d,64-e,64-f,64-g +static const uint8_t PC1_shuffle[] = { + T(57, 49, 41, 33, 25, 17, 9), + T( 1, 58, 50, 42, 34, 26, 18), + T(10, 2, 59, 51, 43, 35, 27), + T(19, 11, 3, 60, 52, 44, 36), + T(63, 55, 47, 39, 31, 23, 15), + T( 7, 62, 54, 46, 38, 30, 22), + T(14, 6, 61, 53, 45, 37, 29), + T(21, 13, 5, 28, 20, 12, 4) +}; +#undef T + +#define T(a, b, c, d, e, f) 56-a,56-b,56-c,56-d,56-e,56-f +static const uint8_t PC2_shuffle[] = { + T(14, 17, 11, 24, 1, 5), + T( 3, 28, 15, 6, 21, 10), + T(23, 19, 12, 4, 26, 8), + T(16, 7, 27, 20, 13, 2), + T(41, 52, 31, 37, 47, 55), + T(30, 40, 51, 45, 33, 48), + T(44, 49, 39, 56, 34, 53), + T(46, 42, 50, 36, 29, 32) +}; +#undef T + +#ifdef CONFIG_SMALL +static const uint8_t S_boxes[8][32] = { + { + 0x0e, 0xf4, 0x7d, 0x41, 0xe2, 0x2f, 0xdb, 0x18, 0xa3, 0x6a, 0xc6, 0xbc, 0x95, 0x59, 0x30, 0x87, + 0xf4, 0xc1, 0x8e, 0x28, 0x4d, 0x96, 0x12, 0x7b, 0x5f, 0xbc, 0x39, 0xe7, 0xa3, 0x0a, 0x65, 0xd0, + }, { + 0x3f, 0xd1, 0x48, 0x7e, 0xf6, 0x2b, 0x83, 0xe4, 0xc9, 0x07, 0x12, 0xad, 0x6c, 0x90, 0xb5, 0x5a, + 0xd0, 0x8e, 0xa7, 0x1b, 0x3a, 0xf4, 0x4d, 0x21, 0xb5, 0x68, 0x7c, 0xc6, 0x09, 0x53, 0xe2, 0x9f, + }, { + 0xda, 0x70, 0x09, 0x9e, 0x36, 0x43, 0x6f, 0xa5, 0x21, 0x8d, 0x5c, 0xe7, 0xcb, 0xb4, 0xf2, 0x18, + 0x1d, 0xa6, 0xd4, 0x09, 0x68, 0x9f, 0x83, 0x70, 0x4b, 0xf1, 0xe2, 0x3c, 0xb5, 0x5a, 0x2e, 0xc7, + }, { + 0xd7, 0x8d, 0xbe, 0x53, 0x60, 0xf6, 0x09, 0x3a, 0x41, 0x72, 0x28, 0xc5, 0x1b, 0xac, 0xe4, 0x9f, + 0x3a, 0xf6, 0x09, 0x60, 0xac, 0x1b, 0xd7, 0x8d, 0x9f, 0x41, 0x53, 0xbe, 0xc5, 0x72, 0x28, 0xe4, + }, { + 0xe2, 0xbc, 0x24, 0xc1, 0x47, 0x7a, 0xdb, 0x16, 0x58, 0x05, 0xf3, 0xaf, 0x3d, 0x90, 0x8e, 0x69, + 0xb4, 0x82, 0xc1, 0x7b, 0x1a, 0xed, 0x27, 0xd8, 0x6f, 0xf9, 0x0c, 0x95, 0xa6, 0x43, 0x50, 0x3e, + }, { + 0xac, 0xf1, 0x4a, 0x2f, 0x79, 0xc2, 0x96, 0x58, 0x60, 0x1d, 0xd3, 0xe4, 0x0e, 0xb7, 0x35, 0x8b, + 0x49, 0x3e, 0x2f, 0xc5, 0x92, 0x58, 0xfc, 0xa3, 0xb7, 0xe0, 0x14, 0x7a, 0x61, 0x0d, 0x8b, 0xd6, + }, { + 0xd4, 0x0b, 0xb2, 0x7e, 0x4f, 0x90, 0x18, 0xad, 0xe3, 0x3c, 0x59, 0xc7, 0x25, 0xfa, 0x86, 0x61, + 0x61, 0xb4, 0xdb, 0x8d, 0x1c, 0x43, 0xa7, 0x7e, 0x9a, 0x5f, 0x06, 0xf8, 0xe0, 0x25, 0x39, 0xc2, + }, { + 0x1d, 0xf2, 0xd8, 0x84, 0xa6, 0x3f, 0x7b, 0x41, 0xca, 0x59, 0x63, 0xbe, 0x05, 0xe0, 0x9c, 0x27, + 0x27, 0x1b, 0xe4, 0x71, 0x49, 0xac, 0x8e, 0xd2, 0xf0, 0xc6, 0x9a, 0x0d, 0x3f, 0x53, 0x65, 0xb8, + } +}; +#else +/** + * This table contains the results of applying both the S-box and P-shuffle. + * It can be regenerated by compiling this file with -DCONFIG_SMALL -DTEST -DGENTABLES + */ +static const uint32_t S_boxes_P_shuffle[8][64] = { + { + 0x00808200, 0x00000000, 0x00008000, 0x00808202, 0x00808002, 0x00008202, 0x00000002, 0x00008000, + 0x00000200, 0x00808200, 0x00808202, 0x00000200, 0x00800202, 0x00808002, 0x00800000, 0x00000002, + 0x00000202, 0x00800200, 0x00800200, 0x00008200, 0x00008200, 0x00808000, 0x00808000, 0x00800202, + 0x00008002, 0x00800002, 0x00800002, 0x00008002, 0x00000000, 0x00000202, 0x00008202, 0x00800000, + 0x00008000, 0x00808202, 0x00000002, 0x00808000, 0x00808200, 0x00800000, 0x00800000, 0x00000200, + 0x00808002, 0x00008000, 0x00008200, 0x00800002, 0x00000200, 0x00000002, 0x00800202, 0x00008202, + 0x00808202, 0x00008002, 0x00808000, 0x00800202, 0x00800002, 0x00000202, 0x00008202, 0x00808200, + 0x00000202, 0x00800200, 0x00800200, 0x00000000, 0x00008002, 0x00008200, 0x00000000, 0x00808002, + }, + { + 0x40084010, 0x40004000, 0x00004000, 0x00084010, 0x00080000, 0x00000010, 0x40080010, 0x40004010, + 0x40000010, 0x40084010, 0x40084000, 0x40000000, 0x40004000, 0x00080000, 0x00000010, 0x40080010, + 0x00084000, 0x00080010, 0x40004010, 0x00000000, 0x40000000, 0x00004000, 0x00084010, 0x40080000, + 0x00080010, 0x40000010, 0x00000000, 0x00084000, 0x00004010, 0x40084000, 0x40080000, 0x00004010, + 0x00000000, 0x00084010, 0x40080010, 0x00080000, 0x40004010, 0x40080000, 0x40084000, 0x00004000, + 0x40080000, 0x40004000, 0x00000010, 0x40084010, 0x00084010, 0x00000010, 0x00004000, 0x40000000, + 0x00004010, 0x40084000, 0x00080000, 0x40000010, 0x00080010, 0x40004010, 0x40000010, 0x00080010, + 0x00084000, 0x00000000, 0x40004000, 0x00004010, 0x40000000, 0x40080010, 0x40084010, 0x00084000, + }, + { + 0x00000104, 0x04010100, 0x00000000, 0x04010004, 0x04000100, 0x00000000, 0x00010104, 0x04000100, + 0x00010004, 0x04000004, 0x04000004, 0x00010000, 0x04010104, 0x00010004, 0x04010000, 0x00000104, + 0x04000000, 0x00000004, 0x04010100, 0x00000100, 0x00010100, 0x04010000, 0x04010004, 0x00010104, + 0x04000104, 0x00010100, 0x00010000, 0x04000104, 0x00000004, 0x04010104, 0x00000100, 0x04000000, + 0x04010100, 0x04000000, 0x00010004, 0x00000104, 0x00010000, 0x04010100, 0x04000100, 0x00000000, + 0x00000100, 0x00010004, 0x04010104, 0x04000100, 0x04000004, 0x00000100, 0x00000000, 0x04010004, + 0x04000104, 0x00010000, 0x04000000, 0x04010104, 0x00000004, 0x00010104, 0x00010100, 0x04000004, + 0x04010000, 0x04000104, 0x00000104, 0x04010000, 0x00010104, 0x00000004, 0x04010004, 0x00010100, + }, + { + 0x80401000, 0x80001040, 0x80001040, 0x00000040, 0x00401040, 0x80400040, 0x80400000, 0x80001000, + 0x00000000, 0x00401000, 0x00401000, 0x80401040, 0x80000040, 0x00000000, 0x00400040, 0x80400000, + 0x80000000, 0x00001000, 0x00400000, 0x80401000, 0x00000040, 0x00400000, 0x80001000, 0x00001040, + 0x80400040, 0x80000000, 0x00001040, 0x00400040, 0x00001000, 0x00401040, 0x80401040, 0x80000040, + 0x00400040, 0x80400000, 0x00401000, 0x80401040, 0x80000040, 0x00000000, 0x00000000, 0x00401000, + 0x00001040, 0x00400040, 0x80400040, 0x80000000, 0x80401000, 0x80001040, 0x80001040, 0x00000040, + 0x80401040, 0x80000040, 0x80000000, 0x00001000, 0x80400000, 0x80001000, 0x00401040, 0x80400040, + 0x80001000, 0x00001040, 0x00400000, 0x80401000, 0x00000040, 0x00400000, 0x00001000, 0x00401040, + }, + { + 0x00000080, 0x01040080, 0x01040000, 0x21000080, 0x00040000, 0x00000080, 0x20000000, 0x01040000, + 0x20040080, 0x00040000, 0x01000080, 0x20040080, 0x21000080, 0x21040000, 0x00040080, 0x20000000, + 0x01000000, 0x20040000, 0x20040000, 0x00000000, 0x20000080, 0x21040080, 0x21040080, 0x01000080, + 0x21040000, 0x20000080, 0x00000000, 0x21000000, 0x01040080, 0x01000000, 0x21000000, 0x00040080, + 0x00040000, 0x21000080, 0x00000080, 0x01000000, 0x20000000, 0x01040000, 0x21000080, 0x20040080, + 0x01000080, 0x20000000, 0x21040000, 0x01040080, 0x20040080, 0x00000080, 0x01000000, 0x21040000, + 0x21040080, 0x00040080, 0x21000000, 0x21040080, 0x01040000, 0x00000000, 0x20040000, 0x21000000, + 0x00040080, 0x01000080, 0x20000080, 0x00040000, 0x00000000, 0x20040000, 0x01040080, 0x20000080, + }, + { + 0x10000008, 0x10200000, 0x00002000, 0x10202008, 0x10200000, 0x00000008, 0x10202008, 0x00200000, + 0x10002000, 0x00202008, 0x00200000, 0x10000008, 0x00200008, 0x10002000, 0x10000000, 0x00002008, + 0x00000000, 0x00200008, 0x10002008, 0x00002000, 0x00202000, 0x10002008, 0x00000008, 0x10200008, + 0x10200008, 0x00000000, 0x00202008, 0x10202000, 0x00002008, 0x00202000, 0x10202000, 0x10000000, + 0x10002000, 0x00000008, 0x10200008, 0x00202000, 0x10202008, 0x00200000, 0x00002008, 0x10000008, + 0x00200000, 0x10002000, 0x10000000, 0x00002008, 0x10000008, 0x10202008, 0x00202000, 0x10200000, + 0x00202008, 0x10202000, 0x00000000, 0x10200008, 0x00000008, 0x00002000, 0x10200000, 0x00202008, + 0x00002000, 0x00200008, 0x10002008, 0x00000000, 0x10202000, 0x10000000, 0x00200008, 0x10002008, + }, + { + 0x00100000, 0x02100001, 0x02000401, 0x00000000, 0x00000400, 0x02000401, 0x00100401, 0x02100400, + 0x02100401, 0x00100000, 0x00000000, 0x02000001, 0x00000001, 0x02000000, 0x02100001, 0x00000401, + 0x02000400, 0x00100401, 0x00100001, 0x02000400, 0x02000001, 0x02100000, 0x02100400, 0x00100001, + 0x02100000, 0x00000400, 0x00000401, 0x02100401, 0x00100400, 0x00000001, 0x02000000, 0x00100400, + 0x02000000, 0x00100400, 0x00100000, 0x02000401, 0x02000401, 0x02100001, 0x02100001, 0x00000001, + 0x00100001, 0x02000000, 0x02000400, 0x00100000, 0x02100400, 0x00000401, 0x00100401, 0x02100400, + 0x00000401, 0x02000001, 0x02100401, 0x02100000, 0x00100400, 0x00000000, 0x00000001, 0x02100401, + 0x00000000, 0x00100401, 0x02100000, 0x00000400, 0x02000001, 0x02000400, 0x00000400, 0x00100001, + }, + { + 0x08000820, 0x00000800, 0x00020000, 0x08020820, 0x08000000, 0x08000820, 0x00000020, 0x08000000, + 0x00020020, 0x08020000, 0x08020820, 0x00020800, 0x08020800, 0x00020820, 0x00000800, 0x00000020, + 0x08020000, 0x08000020, 0x08000800, 0x00000820, 0x00020800, 0x00020020, 0x08020020, 0x08020800, + 0x00000820, 0x00000000, 0x00000000, 0x08020020, 0x08000020, 0x08000800, 0x00020820, 0x00020000, + 0x00020820, 0x00020000, 0x08020800, 0x00000800, 0x00000020, 0x08020020, 0x00000800, 0x00020820, + 0x08000800, 0x00000020, 0x08000020, 0x08020000, 0x08020020, 0x08000000, 0x00020000, 0x08000820, + 0x00000000, 0x08020820, 0x00020020, 0x08000020, 0x08020000, 0x08000800, 0x08000820, 0x00000000, + 0x08020820, 0x00020800, 0x00020800, 0x00000820, 0x00000820, 0x00020020, 0x08000000, 0x08020800, + }, +}; +#endif + +static uint64_t shuffle(uint64_t in, const uint8_t *shuffle, int shuffle_len) { + int i; + uint64_t res = 0; + for (i = 0; i < shuffle_len; i++) + res += res + ((in >> *shuffle++) & 1); + return res; +} + +static uint64_t shuffle_inv(uint64_t in, const uint8_t *shuffle, int shuffle_len) { + int i; + uint64_t res = 0; + shuffle += shuffle_len - 1; + for (i = 0; i < shuffle_len; i++) { + res |= (in & 1) << *shuffle--; + in >>= 1; + } + return res; +} + +static uint32_t f_func(uint32_t r, uint64_t k) { + int i; + uint32_t out = 0; + // rotate to get first part of E-shuffle in the lowest 6 bits + r = (r << 1) | (r >> 31); + // apply S-boxes, those compress the data again from 8 * 6 to 8 * 4 bits + for (i = 7; i >= 0; i--) { + uint8_t tmp = (r ^ k) & 0x3f; +#ifdef CONFIG_SMALL + uint8_t v = S_boxes[i][tmp >> 1]; + if (tmp & 1) v >>= 4; + out = (out >> 4) | (v << 28); +#else + out |= S_boxes_P_shuffle[i][tmp]; +#endif + // get next 6 bits of E-shuffle and round key k into the lowest bits + r = (r >> 4) | (r << 28); + k >>= 6; + } +#ifdef CONFIG_SMALL + out = shuffle(out, P_shuffle, sizeof(P_shuffle)); +#endif + return out; +} + +/** + * \brief rotate the two halves of the expanded 56 bit key each 1 bit left + * + * Note: the specification calls this "shift", so I kept it although + * it is confusing. + */ +static uint64_t key_shift_left(uint64_t CDn) { + uint64_t carries = (CDn >> 27) & 0x10000001; + CDn <<= 1; + CDn &= ~0x10000001; + CDn |= carries; + return CDn; +} + +uint64_t ff_des_encdec(uint64_t in, uint64_t key, int decrypt) { + int i; + uint64_t K[16]; + // discard parity bits from key and shuffle it into C and D parts + uint64_t CDn = shuffle(key, PC1_shuffle, sizeof(PC1_shuffle)); + // generate round keys + for (i = 0; i < 16; i++) { + CDn = key_shift_left(CDn); + if (i > 1 && i != 8 && i != 15) + CDn = key_shift_left(CDn); + K[i] = shuffle(CDn, PC2_shuffle, sizeof(PC2_shuffle)); + } + // used to apply round keys in reverse order for decryption + decrypt = decrypt ? 15 : 0; + // shuffle irrelevant to security but to ease hardware implementations + in = shuffle(in, IP_shuffle, sizeof(IP_shuffle)); + for (i = 0; i < 16; i++) { + uint32_t f_res; + f_res = f_func(in, K[decrypt ^ i]); + in = (in << 32) | (in >> 32); + in ^= f_res; + } + in = (in << 32) | (in >> 32); + // reverse shuffle used to ease hardware implementations + in = shuffle_inv(in, IP_shuffle, sizeof(IP_shuffle)); + return in; +} + +#ifdef TEST +#include <stdlib.h> +#include <stdio.h> +#include <sys/time.h> +static uint64_t rand64(void) { + uint64_t r = rand(); + r = (r << 32) | rand(); + return r; +} + +int main(void) { + int i, j; + struct timeval tv; + uint64_t key; + uint64_t data; + uint64_t ct; + gettimeofday(&tv, NULL); + srand(tv.tv_sec * 1000 * 1000 + tv.tv_usec); + key = 0x123456789abcdef0ULL; + data = 0xfedcba9876543210ULL; + if (ff_des_encdec(data, key, 0) != 0x4ab65b3d4b061518ULL) { + printf("Test 1 failed\n"); + return 1; + } + for (i = 0; i < 1000000; i++) { + key = rand64(); + data = rand64(); + ct = ff_des_encdec(data, key, 0); + if (ff_des_encdec(ct, key, 1) != data) { + printf("Test 2 failed\n"); + return 1; + } + } +#ifdef GENTABLES + printf("static const uint32_t S_boxes_P_shuffle[8][64] = {\n"); + for (i = 0; i < 8; i++) { + printf(" {"); + for (j = 0; j < 64; j++) { + uint32_t v = S_boxes[i][j >> 1]; + v = j & 1 ? v >> 4 : v & 0xf; + v <<= 28 - 4 * i; + v = shuffle(v, P_shuffle, sizeof(P_shuffle)); + printf((j & 7) == 0 ? "\n " : " "); + printf("0x%08X,", v); + } + printf("\n },\n"); + } + printf("};\n"); +#endif + return 0; +} +#endif diff --git a/contrib/ffmpeg/libavutil/des.h b/contrib/ffmpeg/libavutil/des.h new file mode 100644 index 000000000..70f89937c --- /dev/null +++ b/contrib/ffmpeg/libavutil/des.h @@ -0,0 +1,39 @@ +/* + * DES encryption/decryption + * Copyright (c) 2007 Reimar Doeffinger + * + * 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 FFMPEG_DES_H +#define FFMPEG_DES_H + +#include <stdint.h> + +/** + * \brief en- or decrypt an 64-bit block of data with DES + * \param in data to process. + * \param key key to use for en-/decryption. + * \param decrypt if 0 encrypt, else decrypt. + * \return processed data + * + * If your input data is in 8-bit blocks treat it as big-endian + * (use e.g. AV_RB64 and AV_WB64). + */ +uint64_t ff_des_encdec(uint64_t in, uint64_t key, int decrypt); + +#endif /* FFMPEG_DES_H */ diff --git a/contrib/ffmpeg/libavutil/fifo.h b/contrib/ffmpeg/libavutil/fifo.h index e1e85293d..817a8a6b6 100644 --- a/contrib/ffmpeg/libavutil/fifo.h +++ b/contrib/ffmpeg/libavutil/fifo.h @@ -21,8 +21,10 @@ * A very simple circular buffer FIFO implementation. */ -#ifndef FIFO_H -#define FIFO_H +#ifndef FFMPEG_FIFO_H +#define FFMPEG_FIFO_H + +#include <stdint.h> typedef struct AVFifoBuffer { uint8_t *buffer; @@ -97,4 +99,4 @@ static inline uint8_t av_fifo_peek(AVFifoBuffer *f, int offs) ptr -= f->end - f->buffer; return *ptr; } -#endif /* FIFO_H */ +#endif /* FFMPEG_FIFO_H */ diff --git a/contrib/ffmpeg/libavutil/integer.c b/contrib/ffmpeg/libavutil/integer.c index 3269a366a..a7ab5c97f 100644 --- a/contrib/ffmpeg/libavutil/integer.c +++ b/contrib/ffmpeg/libavutil/integer.c @@ -17,7 +17,6 @@ * 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 - * */ /** @@ -157,7 +156,7 @@ int64_t av_i2int(AVInteger a){ return out; } -#if 0 +#ifdef TEST #undef NDEBUG #include <assert.h> @@ -172,7 +171,7 @@ const uint8_t ff_log2_tab[256]={ 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7 }; -main(){ +int main(void){ int64_t a,b; for(a=7; a<256*256*256; a+=13215){ @@ -193,5 +192,6 @@ main(){ assert(av_i2int(av_div_i(ai,bi)) == a/b); } } + return 0; } #endif diff --git a/contrib/ffmpeg/libavutil/integer.h b/contrib/ffmpeg/libavutil/integer.h index 2a4d70316..f539125d1 100644 --- a/contrib/ffmpeg/libavutil/integer.h +++ b/contrib/ffmpeg/libavutil/integer.h @@ -17,7 +17,6 @@ * 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 - * */ /** @@ -26,8 +25,10 @@ * @author Michael Niedermayer <michaelni@gmx.at> */ -#ifndef INTEGER_H -#define INTEGER_H +#ifndef FFMPEG_INTEGER_H +#define FFMPEG_INTEGER_H + +#include <stdint.h> #define AV_INTEGER_SIZE 8 @@ -79,4 +80,4 @@ AVInteger av_int2i(int64_t a); */ int64_t av_i2int(AVInteger a); -#endif // INTEGER_H +#endif /* FFMPEG_INTEGER_H */ diff --git a/contrib/ffmpeg/libavutil/internal.h b/contrib/ffmpeg/libavutil/internal.h index eefbfa1e4..749a85c45 100644 --- a/contrib/ffmpeg/libavutil/internal.h +++ b/contrib/ffmpeg/libavutil/internal.h @@ -23,8 +23,24 @@ * common internal api header. */ -#ifndef INTERNAL_H -#define INTERNAL_H +#ifndef FFMPEG_INTERNAL_H +#define FFMPEG_INTERNAL_H + +#if !defined(DEBUG) && !defined(NDEBUG) +# define NDEBUG +#endif + +#include <stdint.h> +#include <stddef.h> +#include <assert.h> + +#ifndef attribute_align_arg +#if defined(__GNUC__) && (__GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__>1) +# define attribute_align_arg __attribute__((force_align_arg_pointer)) +#else +# define attribute_align_arg +#endif +#endif #ifndef attribute_used #if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0) @@ -34,12 +50,11 @@ #endif #endif -#ifndef attribute_unused -#if defined(__GNUC__) -# define attribute_unused __attribute__((unused)) +/* Use Apple-specific AltiVec syntax for vector declarations when necessary. */ +#ifdef __APPLE_CC__ +#define AVV(x...) (x) #else -# define attribute_unused -#endif +#define AVV(x...) {x} #endif #ifndef M_PI @@ -93,38 +108,17 @@ #include "intreadwrite.h" #include "bswap.h" -#include <stddef.h> #ifndef offsetof # define offsetof(T,F) ((unsigned int)((char *)&((T *)0)->F)) #endif -#ifdef __MINGW32__ -# ifdef _DEBUG -# define DEBUG -# endif - -# define snprintf _snprintf -# define vsnprintf _vsnprintf - -# ifdef CONFIG_WINCE -# define perror(a) -# define abort() -# endif - -/* __MINGW32__ end */ -#elif defined (CONFIG_OS2) -/* OS/2 EMX */ - -# include <float.h> - -#endif /* !__MINGW32__ && CONFIG_OS2 */ - #ifdef USE_FASTMEMCPY # include "libvo/fastmemcpy.h" +# define memcpy(a,b,c) fast_memcpy(a,b,c) #endif // Use rip-relative addressing if compiling PIC code on x86-64. -#if defined(__MINGW32__) || defined(__CYGWIN__) || \ +#if defined(__MINGW32__) || defined(__CYGWIN__) || defined(__DJGPP__) || \ defined(__OS2__) || (defined (__OpenBSD__) && !defined(__ELF__)) # if defined(ARCH_X86_64) && defined(PIC) # define MANGLE(a) "_" #a"(%%rip)" @@ -134,7 +128,7 @@ #else # if defined(ARCH_X86_64) && defined(PIC) # define MANGLE(a) #a"(%%rip)" -# elif defined(CONFIG_DARWIN) +# elif defined(__APPLE__) # define MANGLE(a) "_" #a # else # define MANGLE(a) #a @@ -143,11 +137,6 @@ /* debug stuff */ -#if !defined(DEBUG) && !defined(NDEBUG) -# define NDEBUG -#endif -#include <assert.h> - /* dprintf macros */ #ifdef DEBUG # define dprintf(pctx, ...) av_log(pctx, AV_LOG_DEBUG, __VA_ARGS__) @@ -189,30 +178,34 @@ extern const uint32_t ff_inverse[256]; # define FASTDIV(a,b) ((a)/(b)) #endif -extern const uint8_t ff_sqrt_tab[128]; +extern const uint8_t ff_sqrt_tab[256]; + +static inline int av_log2_16bit(unsigned int v); -static inline int ff_sqrt(int a) +static inline unsigned int ff_sqrt(unsigned int a) { - int ret=0; - int s; - int ret_sq=0; - - if(a<128) return ff_sqrt_tab[a]; - - for(s=15; s>=0; s--){ - int b= ret_sq + (1<<(s*2)) + (ret<<s)*2; - if(b<=a){ - ret_sq=b; - ret+= 1<<s; - } + unsigned int b; + + if(a<255) return (ff_sqrt_tab[a+1]-1)>>4; + else if(a<(1<<12)) b= ff_sqrt_tab[a>>4 ]>>2; +#ifndef CONFIG_SMALL + else if(a<(1<<14)) b= ff_sqrt_tab[a>>6 ]>>1; + else if(a<(1<<16)) b= ff_sqrt_tab[a>>8 ] ; +#endif + else{ + int s= av_log2_16bit(a>>16)>>1; + unsigned int c= a>>(s+2); + b= ff_sqrt_tab[c>>(s+8)]; + b= FASTDIV(c,b) + (b<<s); } - return ret; + + return b - (a<b*b); } #if defined(ARCH_X86) #define MASK_ABS(mask, level)\ asm volatile(\ - "cdq \n\t"\ + "cltd \n\t"\ "xorl %1, %0 \n\t"\ "subl %1, %0 \n\t"\ : "+a" (level), "=&d" (mask)\ @@ -230,7 +223,7 @@ asm volatile (\ "cmovl %3, %0 \n\t"\ "cmovl %4, %1 \n\t"\ "cmovl %5, %2 \n\t"\ - : "+r" (x), "+r" (a), "+r" (c)\ + : "+&r" (x), "+&r" (a), "+r" (c)\ : "r" (y), "r" (b), "r" (d)\ ); #else @@ -243,51 +236,79 @@ if((y)<(x)){\ #endif /* avoid usage of various functions */ +#undef malloc #define malloc please_use_av_malloc +#undef free #define free please_use_av_free +#undef realloc #define realloc please_use_av_realloc +#undef time #define time time_is_forbidden_due_to_security_issues -#define rand rand_is_forbidden_due_to_state_trashing -#define srand srand_is_forbidden_due_to_state_trashing +#undef rand +#define rand rand_is_forbidden_due_to_state_trashing_use_av_random +#undef srand +#define srand srand_is_forbidden_due_to_state_trashing_use_av_init_random +#undef random +#define random random_is_forbidden_due_to_state_trashing_use_av_random +#undef sprintf #define sprintf sprintf_is_forbidden_due_to_security_issues_use_snprintf -#define strcat strcat_is_forbidden_due_to_security_issues_use_pstrcat +#undef strcat +#define strcat strcat_is_forbidden_due_to_security_issues_use_av_strlcat +#undef exit #define exit exit_is_forbidden -#if !(defined(LIBAVFORMAT_BUILD) || defined(_FRAMEHOOK_H)) +#if !(defined(LIBAVFORMAT_BUILD) || defined(FFMPEG_FRAMEHOOK_H)) +#undef printf #define printf please_use_av_log +#undef fprintf #define fprintf please_use_av_log +#undef puts +#define puts please_use_av_log +#undef perror +#define perror please_use_av_log_instead_of_perror #endif #define CHECKED_ALLOCZ(p, size)\ {\ p= av_mallocz(size);\ if(p==NULL && (size)!=0){\ - perror("malloc");\ + av_log(NULL, AV_LOG_ERROR, "Cannot allocate memory.");\ goto fail;\ }\ } +#ifndef HAVE_LLRINT +static av_always_inline long long llrint(double x) +{ + return rint(x); +} +#endif /* HAVE_LLRINT */ + +#ifndef HAVE_LRINT +static av_always_inline long int lrint(double x) +{ + return rint(x); +} +#endif /* HAVE_LRINT */ + #ifndef HAVE_LRINTF -/* XXX: add ISOC specific test to avoid specific BSD testing. */ -/* better than nothing implementation. */ -/* btw, rintf() is existing on fbsd too -- alex */ static av_always_inline long int lrintf(float x) { -#ifdef __MINGW32__ -# ifdef ARCH_X86_32 - int32_t i; - asm volatile( - "fistpl %0\n\t" - : "=m" (i) : "t" (x) : "st" - ); - return i; -# else - /* XXX: incorrect, but make it compile */ - return (int)(x + (x < 0 ? -0.5 : 0.5)); -# endif /* ARCH_X86_32 */ -#else return (int)(rint(x)); -#endif /* __MINGW32__ */ } #endif /* HAVE_LRINTF */ -#endif /* INTERNAL_H */ +#ifndef HAVE_ROUND +static av_always_inline double round(double x) +{ + return (x > 0) ? floor(x + 0.5) : ceil(x - 0.5); +} +#endif /* HAVE_ROUND */ + +#ifndef HAVE_ROUNDF +static av_always_inline float roundf(float x) +{ + return (x > 0) ? floor(x + 0.5) : ceil(x - 0.5); +} +#endif /* HAVE_ROUNDF */ + +#endif /* FFMPEG_INTERNAL_H */ diff --git a/contrib/ffmpeg/libavutil/intfloat_readwrite.h b/contrib/ffmpeg/libavutil/intfloat_readwrite.h index c535b64c8..fe7fe3520 100644 --- a/contrib/ffmpeg/libavutil/intfloat_readwrite.h +++ b/contrib/ffmpeg/libavutil/intfloat_readwrite.h @@ -18,8 +18,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef INTFLOAT_READWRITE_H -#define INTFLOAT_READWRITE_H +#ifndef FFMPEG_INTFLOAT_READWRITE_H +#define FFMPEG_INTFLOAT_READWRITE_H #include "common.h" @@ -36,4 +36,4 @@ int64_t av_dbl2int(double d); int32_t av_flt2int(float d); AVExtFloat av_dbl2ext(double d); -#endif /* INTFLOAT_READWRITE_H */ +#endif /* FFMPEG_INTFLOAT_READWRITE_H */ diff --git a/contrib/ffmpeg/libavutil/intreadwrite.h b/contrib/ffmpeg/libavutil/intreadwrite.h index 7225f0b67..dd77104f2 100644 --- a/contrib/ffmpeg/libavutil/intreadwrite.h +++ b/contrib/ffmpeg/libavutil/intreadwrite.h @@ -16,8 +16,11 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef INTREADWRITE_H -#define INTREADWRITE_H +#ifndef FFMPEG_INTREADWRITE_H +#define FFMPEG_INTREADWRITE_H + +#include <stdint.h> +#include "bswap.h" #ifdef __GNUC__ @@ -25,75 +28,162 @@ 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 LD16(a) (((const struct unaligned_16 *) (a))->l) -#define LD32(a) (((const struct unaligned_32 *) (a))->l) -#define LD64(a) (((const struct unaligned_64 *) (a))->l) +#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 ST16(a, b) (((struct unaligned_16 *) (a))->l) = (b) -#define ST32(a, b) (((struct unaligned_32 *) (a))->l) = (b) +#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) #else /* __GNUC__ */ -#define LD16(a) (*((uint16_t*)(a))) -#define LD32(a) (*((uint32_t*)(a))) -#define LD64(a) (*((uint64_t*)(a))) +#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 ST16(a, b) *((uint16_t*)(a)) = (b) -#define ST32(a, b) *((uint32_t*)(a)) = (b) +#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) (((uint8_t*)(x))[0]) -#define AV_WB8(p, d) { ((uint8_t*)(p))[0] = (d); } +#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) -#define AV_RB16(x) ((((uint8_t*)(x))[0] << 8) | ((uint8_t*)(x))[1]) -#define AV_WB16(p, d) { \ +#ifdef 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)) +# 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) +# 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; } + ((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) +#endif -#define AV_RB24(x) ((((uint8_t*)(x))[0] << 16) | \ - (((uint8_t*)(x))[1] << 8) | \ - ((uint8_t*)(x))[2]) -#define AV_WB24(p, d) { \ +#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; } + ((uint8_t*)(p))[0] = (d)>>16; } while(0) -#define AV_RB32(x) ((((uint8_t*)(x))[0] << 24) | \ - (((uint8_t*)(x))[1] << 16) | \ - (((uint8_t*)(x))[2] << 8) | \ - ((uint8_t*)(x))[3]) -#define AV_WB32(p, d) { \ +#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) + +#ifdef HAVE_FAST_UNALIGNED +# ifdef WORDS_BIGENDIAN +# 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)) +# else /* WORDS_BIGENDIAN */ +# 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) +# endif +#else /* HAVE_FAST_UNALIGNED */ +#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; } - -#define AV_RL8(x) AV_RB8(x) -#define AV_WL8(p, d) AV_WB8(p, d) - -#define AV_RL16(x) ((((uint8_t*)(x))[1] << 8) | ((uint8_t*)(x))[0]) -#define AV_WL16(p, d) { \ - ((uint8_t*)(p))[0] = (d); \ - ((uint8_t*)(p))[1] = (d)>>8; } - -#define AV_RL24(x) ((((uint8_t*)(x))[2] << 16) | \ - (((uint8_t*)(x))[1] << 8) | \ - ((uint8_t*)(x))[0]) -#define AV_WL24(p, d) { \ - ((uint8_t*)(p))[0] = (d); \ - ((uint8_t*)(p))[1] = (d)>>8; \ - ((uint8_t*)(p))[2] = (d)>>16; } + ((uint8_t*)(p))[0] = (d)>>24; } while(0) -#define AV_RL32(x) ((((uint8_t*)(x))[3] << 24) | \ - (((uint8_t*)(x))[2] << 16) | \ - (((uint8_t*)(x))[1] << 8) | \ - ((uint8_t*)(x))[0]) -#define AV_WL32(p, d) { \ +#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; } - -#endif /* INTREADWRITE_H */ + ((uint8_t*)(p))[3] = (d)>>24; } while(0) +#endif + +#ifdef HAVE_FAST_UNALIGNED +# ifdef WORDS_BIGENDIAN +# 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_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_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 + +#endif /* FFMPEG_INTREADWRITE_H */ diff --git a/contrib/ffmpeg/libavutil/lls.c b/contrib/ffmpeg/libavutil/lls.c index aa9467dce..b9d2d8168 100644 --- a/contrib/ffmpeg/libavutil/lls.c +++ b/contrib/ffmpeg/libavutil/lls.c @@ -17,7 +17,7 @@ * * 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 St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /** @@ -53,8 +53,8 @@ void av_update_lls(LLSModel *m, double *var, double decay){ void av_solve_lls(LLSModel *m, double threshold, int min_order){ int i,j,k; - double (*factor)[MAX_VARS+1]= &m->covariance[1][0]; - double (*covar )[MAX_VARS+1]= &m->covariance[1][1]; + double (*factor)[MAX_VARS+1]= (void*)&m->covariance[1][0]; + double (*covar )[MAX_VARS+1]= (void*)&m->covariance[1][1]; double *covar_y = m->covariance[0]; int count= m->indep_count; @@ -113,7 +113,7 @@ double av_evaluate_lls(LLSModel *m, double *param, int order){ #include <stdlib.h> #include <stdio.h> -int main(){ +int main(void){ LLSModel m; int i, order; @@ -121,7 +121,7 @@ int main(){ for(i=0; i<100; i++){ double var[4]; - double eval, variance; + double eval; #if 0 var[1] = rand() / (double)RAND_MAX; var[2] = rand() / (double)RAND_MAX; diff --git a/contrib/ffmpeg/libavutil/lls.h b/contrib/ffmpeg/libavutil/lls.h index 59ad2e958..90b2332aa 100644 --- a/contrib/ffmpeg/libavutil/lls.h +++ b/contrib/ffmpeg/libavutil/lls.h @@ -17,11 +17,11 @@ * * 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 St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef LLS_H -#define LLS_H +#ifndef FFMPEG_LLS_H +#define FFMPEG_LLS_H #define MAX_VARS 32 @@ -42,4 +42,4 @@ void av_update_lls(LLSModel *m, double *param, double decay); void av_solve_lls(LLSModel *m, double threshold, int min_order); double av_evaluate_lls(LLSModel *m, double *param, int order); -#endif +#endif /* FFMPEG_LLS_H */ diff --git a/contrib/ffmpeg/libavutil/log.c b/contrib/ffmpeg/libavutil/log.c index 4fd503d0d..fed0ce80a 100644 --- a/contrib/ffmpeg/libavutil/log.c +++ b/contrib/ffmpeg/libavutil/log.c @@ -45,11 +45,7 @@ void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl) vfprintf(stderr, fmt, vl); } -#if LIBAVUTIL_VERSION_INT < (50<<16) static void (*av_log_callback)(void*, int, const char*, va_list) = av_log_default_callback; -#else -void (*av_vlog)(void*, int, const char*, va_list) = av_log_default_callback; -#endif void av_log(void* avcl, int level, const char *fmt, ...) { @@ -59,7 +55,6 @@ void av_log(void* avcl, int level, const char *fmt, ...) va_end(vl); } -#if LIBAVUTIL_VERSION_INT < (50<<16) void av_vlog(void* avcl, int level, const char *fmt, va_list vl) { av_log_callback(avcl, level, fmt, vl); @@ -79,4 +74,3 @@ void av_log_set_callback(void (*callback)(void*, int, const char*, va_list)) { av_log_callback = callback; } -#endif diff --git a/contrib/ffmpeg/libavutil/log.h b/contrib/ffmpeg/libavutil/log.h index fa88f5fb2..5d18197ef 100644 --- a/contrib/ffmpeg/libavutil/log.h +++ b/contrib/ffmpeg/libavutil/log.h @@ -18,8 +18,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef LOG_H -#define LOG_H +#ifndef FFMPEG_LOG_H +#define FFMPEG_LOG_H #include <stdarg.h> @@ -81,7 +81,10 @@ struct AVCLASS { */ #define AV_LOG_DEBUG 48 #endif + +#if LIBAVUTIL_VERSION_INT < (50<<16) extern int av_log_level; +#endif /** * Send the specified message to the log if the level is less than or equal to @@ -103,14 +106,10 @@ extern void av_log(void*, int level, const char *fmt, ...) __attribute__ ((__for extern void av_log(void*, int level, const char *fmt, ...); #endif -#if LIBAVUTIL_VERSION_INT < (50<<16) extern void av_vlog(void*, int level, const char *fmt, va_list); extern int av_log_get_level(void); extern void av_log_set_level(int); extern void av_log_set_callback(void (*)(void*, int, const char*, va_list)); extern void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl); -#else -extern void (*av_vlog)(void*, int, const char*, va_list); -#endif -#endif /* LOG_H */ +#endif /* FFMPEG_LOG_H */ diff --git a/contrib/ffmpeg/libavutil/lzo.c b/contrib/ffmpeg/libavutil/lzo.c index d3849a743..d5d11867f 100644 --- a/contrib/ffmpeg/libavutil/lzo.c +++ b/contrib/ffmpeg/libavutil/lzo.c @@ -29,7 +29,7 @@ //! define if we may read up to 8 bytes beyond the input buffer #define INBUF_PADDED 1 typedef struct LZOContext { - uint8_t *in, *in_end; + const uint8_t *in, *in_end; uint8_t *out_start, *out, *out_end; int error; } LZOContext; @@ -84,7 +84,7 @@ static inline int get_len(LZOContext *c, int x, int mask) { * \param cnt number of bytes to copy, must be >= 0 */ static inline void copy(LZOContext *c, int cnt) { - register uint8_t *src = c->in; + register const uint8_t *src = c->in; register uint8_t *dst = c->out; if (cnt > c->in_end - src) { cnt = FFMAX(c->in_end - src, 0); @@ -115,7 +115,7 @@ static inline void copy(LZOContext *c, int cnt) { * thus creating a repeating pattern with a period length of back. */ static inline void copy_backptr(LZOContext *c, int back, int cnt) { - register uint8_t *src = &c->out[-back]; + register const uint8_t *src = &c->out[-back]; register uint8_t *dst = c->out; if (src < c->out_start || src > dst) { c->error |= LZO_INVALID_BACKPTR; @@ -171,12 +171,12 @@ static inline void copy_backptr(LZOContext *c, int back, int cnt) { * make sure all buffers are appropriately padded, in must provide * LZO_INPUT_PADDING, out must provide LZO_OUTPUT_PADDING additional bytes */ -int lzo1x_decode(void *out, int *outlen, void *in, int *inlen) { +int lzo1x_decode(void *out, int *outlen, const void *in, int *inlen) { int state= 0; int x; LZOContext c; c.in = in; - c.in_end = (uint8_t *)in + *inlen; + c.in_end = (const uint8_t *)in + *inlen; c.out = c.out_start = out; c.out_end = (uint8_t *)out + * outlen; c.error = 0; diff --git a/contrib/ffmpeg/libavutil/lzo.h b/contrib/ffmpeg/libavutil/lzo.h index 5b3d98f40..e7795f771 100644 --- a/contrib/ffmpeg/libavutil/lzo.h +++ b/contrib/ffmpeg/libavutil/lzo.h @@ -19,8 +19,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef LZO_H -#define LZO_H +#ifndef FFMPEG_LZO_H +#define FFMPEG_LZO_H #define LZO_INPUT_DEPLETED 1 #define LZO_OUTPUT_FULL 2 @@ -30,6 +30,6 @@ #define LZO_INPUT_PADDING 8 #define LZO_OUTPUT_PADDING 12 -int lzo1x_decode(void *out, int *outlen, void *in, int *inlen); +int lzo1x_decode(void *out, int *outlen, const void *in, int *inlen); -#endif +#endif /* FFMPEG_LZO_H */ diff --git a/contrib/ffmpeg/libavutil/mathematics.c b/contrib/ffmpeg/libavutil/mathematics.c index 4be027d9d..ef93ba4a1 100644 --- a/contrib/ffmpeg/libavutil/mathematics.c +++ b/contrib/ffmpeg/libavutil/mathematics.c @@ -26,11 +26,15 @@ #include "common.h" #include "mathematics.h" -const uint8_t ff_sqrt_tab[128]={ - 0, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, - 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11 +const uint8_t ff_sqrt_tab[256]={ + 0, 16, 23, 28, 32, 36, 40, 43, 46, 48, 51, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 77, 79, 80, 82, 84, 85, 87, 88, 90, + 91, 92, 94, 95, 96, 98, 99,100,102,103,104,105,107,108,109,110,111,112,114,115,116,117,118,119,120,121,122,123,124,125,126,127, +128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,144,145,146,147,148,149,150,151,151,152,153,154,155,156,156, +157,158,159,160,160,161,162,163,164,164,165,166,167,168,168,169,170,171,171,172,173,174,174,175,176,176,177,178,179,179,180,181, +182,182,183,184,184,185,186,186,187,188,188,189,190,190,191,192,192,193,194,194,195,196,196,197,198,198,199,200,200,201,202,202, +203,204,204,205,205,206,207,207,208,208,209,210,210,211,212,212,213,213,214,215,215,216,216,217,218,218,219,219,220,220,221,222, +222,223,223,224,224,225,226,226,227,227,228,228,229,230,230,231,231,232,232,233,233,234,235,235,236,236,237,237,238,238,239,239, +240,240,241,242,242,243,243,244,244,245,245,246,246,247,247,248,248,249,249,250,250,251,251,252,252,253,253,254,254,255,255,255 }; const uint8_t ff_log2_tab[256]={ @@ -110,10 +114,11 @@ int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq){ int64_t c= cq.num * (int64_t)bq.den; return av_rescale_rnd(a, b, c, AV_ROUND_NEAR_INF); } -#if 0 + +#ifdef TEST #include "integer.h" #undef printf -main(){ +int main(void){ int64_t a,b,c,d,e; for(a=7; a<(1LL<<62); a+=a/3+1){ @@ -135,5 +140,6 @@ main(){ } } } + return 0; } #endif diff --git a/contrib/ffmpeg/libavutil/mathematics.h b/contrib/ffmpeg/libavutil/mathematics.h index 0b74b254b..a0c286249 100644 --- a/contrib/ffmpeg/libavutil/mathematics.h +++ b/contrib/ffmpeg/libavutil/mathematics.h @@ -18,8 +18,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef MATHEMATICS_H -#define MATHEMATICS_H +#ifndef FFMPEG_MATHEMATICS_H +#define FFMPEG_MATHEMATICS_H #include "rational.h" @@ -48,4 +48,4 @@ int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding); */ int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq); -#endif /* MATHEMATICS_H */ +#endif /* FFMPEG_MATHEMATICS_H */ diff --git a/contrib/ffmpeg/libavutil/md5.c b/contrib/ffmpeg/libavutil/md5.c index f71703124..ee39de131 100644 --- a/contrib/ffmpeg/libavutil/md5.c +++ b/contrib/ffmpeg/libavutil/md5.c @@ -2,6 +2,17 @@ * Copyright (C) 2006 Michael Niedermayer (michaelni@gmx.at) * Copyright (C) 2003-2005 by Christopher R. Hertel (crh@ubiqx.mn.org) * + * References: + * IETF RFC 1321: The MD5 Message-Digest Algorithm + * Ron Rivest. IETF, April, 1992 + * + * based on http://ubiqx.org/libcifs/source/Auth/MD5.c + * from Christopher R. Hertel (crh@ubiqx.mn.org) + * Simplified, cleaned and IMO redundant comments removed by michael. + * + * If you use gcc, then version 4.1 or later and -fomit-frame-pointer is + * strongly recommended. + * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or @@ -17,17 +28,6 @@ * 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 - * - * References: - * IETF RFC 1321: The MD5 Message-Digest Algorithm - * Ron Rivest. IETF, April, 1992 - * - * based on http://ubiqx.org/libcifs/source/Auth/MD5.c - * from Christopher R. Hertel (crh@ubiqx.mn.org) - * simplified, cleaned and IMO redundant comments removed by michael - * - * if you use gcc, then version 4.1 or later and -fomit-frame-pointer is - * strongly recommended */ #include "common.h" @@ -87,7 +87,7 @@ static const uint32_t T[64] = { // T[i]= fabs(sin(i+1)<<32) static void body(uint32_t ABCD[4], uint32_t X[16]){ int t; - int i attribute_unused; + int i av_unused; unsigned int a= ABCD[3]; unsigned int b= ABCD[2]; unsigned int c= ABCD[1]; @@ -147,7 +147,7 @@ void av_md5_final(AVMD5 *ctx, uint8_t *dst){ while((ctx->len & 63)<56) av_md5_update(ctx, "", 1); - av_md5_update(ctx, &finalcount, 8); + av_md5_update(ctx, (uint8_t*)&finalcount, 8); for(i=0; i<4; i++) ((uint32_t*)dst)[i]= le2me_32(ctx->ABCD[3-i]); @@ -164,7 +164,7 @@ void av_md5_sum(uint8_t *dst, const uint8_t *src, const int len){ #ifdef TEST #include <stdio.h> #undef printf -main(){ +int main(void){ uint64_t md5val; int i; uint8_t in[1000]; @@ -176,5 +176,7 @@ main(){ av_md5_sum( (uint8_t*)&md5val, in, 65); printf("%"PRId64"\n", md5val); for(i=0; i<1000; i++) in[i]= i % 127; av_md5_sum( (uint8_t*)&md5val, in, 999); printf("%"PRId64"\n", md5val); + + return 0; } #endif diff --git a/contrib/ffmpeg/libavutil/md5.h b/contrib/ffmpeg/libavutil/md5.h index 8d1b4b5fe..7d63df01b 100644 --- a/contrib/ffmpeg/libavutil/md5.h +++ b/contrib/ffmpeg/libavutil/md5.h @@ -18,8 +18,10 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef MD5_H -#define MD5_H +#ifndef FFMPEG_MD5_H +#define FFMPEG_MD5_H + +#include <stdint.h> extern const int av_md5_size; @@ -30,5 +32,5 @@ void av_md5_update(struct AVMD5 *ctx, const uint8_t *src, const int len); void av_md5_final(struct AVMD5 *ctx, uint8_t *dst); void av_md5_sum(uint8_t *dst, const uint8_t *src, const int len); -#endif /* MD5_H */ +#endif /* FFMPEG_MD5_H */ diff --git a/contrib/ffmpeg/libavutil/mem.c b/contrib/ffmpeg/libavutil/mem.c index a91ac4a07..244475968 100644 --- a/contrib/ffmpeg/libavutil/mem.c +++ b/contrib/ffmpeg/libavutil/mem.c @@ -55,7 +55,7 @@ void *av_malloc(unsigned int size) if(!ptr) return ptr; diff= ((-(long)ptr - 1)&15) + 1; - ptr += diff; + ptr = (char*)ptr + diff; ((char*)ptr)[-1]= diff; #elif defined (HAVE_MEMALIGN) ptr = memalign(16,size); @@ -105,7 +105,7 @@ void *av_realloc(void *ptr, unsigned int size) //FIXME this isn't aligned correctly, though it probably isn't needed if(!ptr) return av_malloc(size); diff= ((char*)ptr)[-1]; - return realloc(ptr - diff, size + diff) + diff; + return (char*)realloc((char*)ptr - diff, size + diff) + diff; #else return realloc(ptr, size); #endif @@ -116,7 +116,7 @@ void av_free(void *ptr) /* XXX: this test should not be needed on most libcs */ if (ptr) #ifdef CONFIG_MEMALIGN_HACK - free(ptr - ((char*)ptr)[-1]); + free((char*)ptr - ((char*)ptr)[-1]); #else free(ptr); #endif diff --git a/contrib/ffmpeg/libavutil/mem.h b/contrib/ffmpeg/libavutil/mem.h index 4ebdad8f5..7bf707001 100644 --- a/contrib/ffmpeg/libavutil/mem.h +++ b/contrib/ffmpeg/libavutil/mem.h @@ -23,43 +23,84 @@ * Memory handling functions. */ -#ifndef AV_MEM_H -#define AV_MEM_H +#ifndef FFMPEG_MEM_H +#define FFMPEG_MEM_H -#ifdef __GNUC__ - #define DECLARE_ALIGNED(n,t,v) t v __attribute__ ((aligned (n))) +#ifdef __ICC + #define DECLARE_ALIGNED(n,t,v) t v __attribute__ ((aligned (n))) + #define DECLARE_ASM_CONST(n,t,v) const t __attribute__ ((aligned (n))) v +#elif defined(__GNUC__) + #define DECLARE_ALIGNED(n,t,v) t v __attribute__ ((aligned (n))) + #define DECLARE_ASM_CONST(n,t,v) static const t v attribute_used __attribute__ ((aligned (n))) +#elif defined(_MSC_VER) + #define DECLARE_ALIGNED(n,t,v) __declspec(align(n)) t v + #define DECLARE_ASM_CONST(n,t,v) __declspec(align(n)) static const t v #else - #define DECLARE_ALIGNED(n,t,v) __declspec(align(n)) t v +// #warning No align and asm directives, this might fail. + #define DECLARE_ALIGNED(n,t,v) t v + #define DECLARE_ASM_CONST(n,t,v) static const t v #endif /** - * Memory allocation of size byte with alignment suitable for all - * memory accesses (including vectors if available on the - * CPU). av_malloc(0) must return a non NULL pointer. + * Allocate a block of \p size bytes with alignment suitable for all + * memory accesses (including vectors if available on the CPU). + * @param size Size in bytes for the memory block to be allocated. + * @return Pointer to the allocated block, NULL if it cannot allocate + * it. + * @see av_mallocz() */ void *av_malloc(unsigned int size); /** - * av_realloc semantics (same as glibc): if ptr is NULL and size > 0, - * identical to malloc(size). If size is zero, it is identical to - * free(ptr) and NULL is returned. + * Allocate or reallocate a block of memory. + * If \p ptr is NULL and \p size > 0, allocate a new block. If \p + * size is zero, free the memory block pointed by \p ptr. + * @param size Size in bytes for the memory block to be allocated or + * reallocated. + * @param ptr Pointer to a memory block already allocated with + * av_malloc(z)() or av_realloc() or NULL. + * @return Pointer to a newly reallocated block or NULL if it cannot + * reallocate or the function is used to free the memory block. + * @see av_fast_realloc() */ void *av_realloc(void *ptr, unsigned int size); /** - * Free memory which has been allocated with av_malloc(z)() or av_realloc(). - * NOTE: ptr = NULL is explicetly allowed - * Note2: it is recommended that you use av_freep() instead + * Free a memory block which has been allocated with av_malloc(z)() or + * av_realloc(). + * @param ptr Pointer to the memory block which should be freed. + * @note ptr = NULL is explicitly allowed. + * @note It is recommended that you use av_freep() instead. + * @see av_freep() */ void av_free(void *ptr); +/** + * Allocate a block of \p size bytes with alignment suitable for all + * memory accesses (including vectors if available on the CPU) and + * set to zeroes all the bytes of the block. + * @param size Size in bytes for the memory block to be allocated. + * @return Pointer to the allocated block, NULL if it cannot allocate + * it. + * @see av_malloc() + */ void *av_mallocz(unsigned int size); + +/** + * Duplicate the string \p s. + * @param s String to be duplicated. + * @return Pointer to a newly allocated string containing a + * copy of \p s or NULL if it cannot be allocated. + */ char *av_strdup(const char *s); /** - * Frees memory and sets the pointer to NULL. - * @param ptr pointer to the pointer which should be freed + * Free a memory block which has been allocated with av_malloc(z)() or + * av_realloc() and set to NULL the pointer to it. + * @param ptr Pointer to the pointer to the memory block which should + * be freed. + * @see av_free() */ void av_freep(void *ptr); -#endif /* AV_MEM_H */ +#endif /* FFMPEG_MEM_H */ diff --git a/contrib/ffmpeg/libavutil/random.h b/contrib/ffmpeg/libavutil/random.h index d9d08a5de..4d00d7e00 100644 --- a/contrib/ffmpeg/libavutil/random.h +++ b/contrib/ffmpeg/libavutil/random.h @@ -21,8 +21,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef AV_RANDOM_H -#define AV_RANDOM_H +#ifndef FFMPEG_RANDOM_H +#define FFMPEG_RANDOM_H #define AV_RANDOM_N 624 @@ -65,5 +65,5 @@ static inline double av_random_real1(AVRandomState *state) // only available if DEBUG is defined in the .c file void av_benchmark_random(void); -#endif // AV_RANDOM_H +#endif /* FFMPEG_RANDOM_H */ diff --git a/contrib/ffmpeg/libavutil/rational.c b/contrib/ffmpeg/libavutil/rational.c index ac0c9d371..96a4c5462 100644 --- a/contrib/ffmpeg/libavutil/rational.c +++ b/contrib/ffmpeg/libavutil/rational.c @@ -17,7 +17,6 @@ * 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 - * */ /** diff --git a/contrib/ffmpeg/libavutil/rational.h b/contrib/ffmpeg/libavutil/rational.h index 63c0b150f..f53f27861 100644 --- a/contrib/ffmpeg/libavutil/rational.h +++ b/contrib/ffmpeg/libavutil/rational.h @@ -17,7 +17,6 @@ * 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 - * */ /** @@ -26,8 +25,10 @@ * @author Michael Niedermayer <michaelni@gmx.at> */ -#ifndef RATIONAL_H -#define RATIONAL_H +#ifndef FFMPEG_RATIONAL_H +#define FFMPEG_RATIONAL_H + +#include <stdint.h> /** * Rational number num/den. @@ -99,7 +100,7 @@ AVRational av_add_q(AVRational b, AVRational c); * Subtracts one rational from another. * @param b first rational. * @param c second rational. - * returns b-c. + * @return b-c. */ AVRational av_sub_q(AVRational b, AVRational c); @@ -111,4 +112,4 @@ AVRational av_sub_q(AVRational b, AVRational c); */ AVRational av_d2q(double d, int max); -#endif // RATIONAL_H +#endif /* FFMPEG_RATIONAL_H */ diff --git a/contrib/ffmpeg/libavutil/rc4.c b/contrib/ffmpeg/libavutil/rc4.c new file mode 100644 index 000000000..0cf71a419 --- /dev/null +++ b/contrib/ffmpeg/libavutil/rc4.c @@ -0,0 +1,48 @@ +/* + * RC4 encryption/decryption/pseudo-random number generator + * Copyright (c) 2007 Reimar Doeffinger + * + * loosely based on LibTomCrypt by Tom St Denis + * + * 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 + */ +#include "common.h" +#include "rc4.h" + +void ff_rc4_enc(const uint8_t *key, int keylen, uint8_t *data, int datalen) { + int i, j; + uint8_t x, y; + uint8_t state[256]; + for (i = 0; i < 256; i++) + state[i] = i; + y = 0; + // j is i % keylen + for (j = 0, i = 0; i < 256; i++, j++) { + if (j == keylen) j = 0; + y += state[i] + key[j]; + FFSWAP(uint8_t, state[i], state[y]); + } + // state initialized, now do the real encryption + x = 1; y = state[1]; + while (datalen-- > 0) { + uint8_t sum = state[x] + state[y]; + FFSWAP(uint8_t, state[x], state[y]); + *data++ ^= state[sum]; + x++; + y += state[x]; + } +} diff --git a/contrib/ffmpeg/libavutil/rc4.h b/contrib/ffmpeg/libavutil/rc4.h new file mode 100644 index 000000000..e06e12e9e --- /dev/null +++ b/contrib/ffmpeg/libavutil/rc4.h @@ -0,0 +1,28 @@ +/* + * RC4 encryption/decryption/pseudo-random number generator + * + * 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 FFMPEG_RC4_H +#define FFMPEG_RC4_H + +#include <inttypes.h> + +void ff_rc4_enc(const uint8_t *key, int keylen, uint8_t *data, int datalen); + +#endif /* FFMPEG_RC4_H */ diff --git a/contrib/ffmpeg/libavutil/sha1.c b/contrib/ffmpeg/libavutil/sha1.c index 6c10791f4..61ad38de2 100644 --- a/contrib/ffmpeg/libavutil/sha1.c +++ b/contrib/ffmpeg/libavutil/sha1.c @@ -1,8 +1,26 @@ -// SHA-1 code Copyright 2007 Michael Nidermayer <michaelni@gmx.at> -// license LGPL -// based on public domain SHA-1 code by Steve Reid <steve@edmweb.com> +/* + * Copyright (C) 2007 Michael Niedermayer <michaelni@gmx.at> + * based on public domain SHA-1 code by Steve Reid <steve@edmweb.com> + * + * 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 + */ #include "common.h" +#include "bswap.h" #include "sha1.h" typedef struct AVSHA1 { @@ -11,10 +29,12 @@ typedef struct AVSHA1 { uint32_t state[5]; } AVSHA1; +const int av_sha1_size = sizeof(AVSHA1); + #define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits)))) /* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */ -#define blk0(i) (block[i] = be2me_32(((uint32_t*)buffer)[i])) +#define blk0(i) (block[i] = be2me_32(((const uint32_t*)buffer)[i])) #define blk(i) (block[i] = rol(block[i-3]^block[i-8]^block[i-14]^block[i-16],1)) #define R0(v,w,x,y,z,i) z+=((w&(x^y))^y) +blk0(i)+0x5A827999+rol(v,5);w=rol(w,30); @@ -25,7 +45,7 @@ typedef struct AVSHA1 { /* Hash a single 512-bit block. This is the core of the algorithm. */ -static void transform(uint32_t state[5], uint8_t buffer[64]){ +static void transform(uint32_t state[5], const uint8_t buffer[64]){ uint32_t block[80]; unsigned int i, a, b, c, d, e; @@ -85,7 +105,7 @@ void av_sha1_init(AVSHA1* ctx){ ctx->count = 0; } -void av_sha1_update(AVSHA1* ctx, uint8_t* data, unsigned int len){ +void av_sha1_update(AVSHA1* ctx, const uint8_t* data, unsigned int len){ unsigned int i, j; j = ctx->count & 63; @@ -120,7 +140,7 @@ void av_sha1_final(AVSHA1* ctx, uint8_t digest[20]){ while ((ctx->count & 63) != 56) { av_sha1_update(ctx, "", 1); } - av_sha1_update(ctx, &finalcount, 8); /* Should cause a transform() */ + av_sha1_update(ctx, (uint8_t *)&finalcount, 8); /* Should cause a transform() */ for(i=0; i<5; i++) ((uint32_t*)digest)[i]= be2me_32(ctx->state[i]); } @@ -131,7 +151,7 @@ void av_sha1_final(AVSHA1* ctx, uint8_t digest[20]){ #include <stdio.h> #undef printf -int main(){ +int main(void){ int i, k; AVSHA1 ctx; unsigned char digest[20]; diff --git a/contrib/ffmpeg/libavutil/sha1.h b/contrib/ffmpeg/libavutil/sha1.h index 8739cbde9..fc5bf0825 100644 --- a/contrib/ffmpeg/libavutil/sha1.h +++ b/contrib/ffmpeg/libavutil/sha1.h @@ -1,11 +1,34 @@ -#ifndef AV_SHA1_H -#define AV_SHA1_H +/* + * Copyright (C) 2007 Michael Niedermayer <michaelni@gmx.at> + * + * 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 FFMPEG_SHA1_H +#define FFMPEG_SHA1_H + +#include <stdint.h> extern const int av_sha1_size; struct AVSHA1; void av_sha1_init(struct AVSHA1* context); -void av_sha1_update(struct AVSHA1* context, uint8_t* data, unsigned int len); +void av_sha1_update(struct AVSHA1* context, const uint8_t* data, unsigned int len); void av_sha1_final(struct AVSHA1* context, uint8_t digest[20]); -#endif + +#endif /* FFMPEG_SHA1_H */ diff --git a/contrib/ffmpeg/libavutil/softfloat.c b/contrib/ffmpeg/libavutil/softfloat.c index f12fd17a0..a5757c270 100644 --- a/contrib/ffmpeg/libavutil/softfloat.c +++ b/contrib/ffmpeg/libavutil/softfloat.c @@ -27,7 +27,7 @@ #undef printf -int main(){ +int main(void){ SoftFloat one= av_int2sf(1, 0); SoftFloat sf1, sf2; double d1, d2; diff --git a/contrib/ffmpeg/libavutil/softfloat.h b/contrib/ffmpeg/libavutil/softfloat.h index 5bb2c1cbc..d1a1901ea 100644 --- a/contrib/ffmpeg/libavutil/softfloat.h +++ b/contrib/ffmpeg/libavutil/softfloat.h @@ -16,9 +16,13 @@ * 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 FFMPEG_SOFTFLOAT_H +#define FFMPEG_SOFTFLOAT_H + +#include <stdint.h> + #define MIN_EXP -126 #define MAX_EXP 126 #define ONE_BITS 29 @@ -120,3 +124,5 @@ static inline int av_sf2int(SoftFloat v, int frac_bits){ if(v.exp >= 0) return v.mant << v.exp ; else return v.mant >>(-v.exp); } + +#endif /* FFMPEG_SOFTFLOAT_H */ diff --git a/contrib/ffmpeg/libavutil/string.c b/contrib/ffmpeg/libavutil/string.c new file mode 100644 index 000000000..8ee2a6b12 --- /dev/null +++ b/contrib/ffmpeg/libavutil/string.c @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2000, 2001, 2002 Fabrice Bellard + * Copyright (c) 2007 Mans Rullgard + * + * 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 + */ + +#include <stdarg.h> +#include <stdio.h> +#include <string.h> +#include <ctype.h> +#include "avstring.h" + +int av_strstart(const char *str, const char *pfx, const char **ptr) +{ + while (*pfx && *pfx == *str) { + pfx++; + str++; + } + if (!*pfx && ptr) + *ptr = str; + return !*pfx; +} + +int av_stristart(const char *str, const char *pfx, const char **ptr) +{ + while (*pfx && toupper((unsigned)*pfx) == toupper((unsigned)*str)) { + pfx++; + str++; + } + if (!*pfx && ptr) + *ptr = str; + return !*pfx; +} + +size_t av_strlcpy(char *dst, const char *src, size_t size) +{ + size_t len = 0; + while (++len < size && *src) + *dst++ = *src++; + if (len <= size) + *dst = 0; + return len + strlen(src) - 1; +} + +size_t av_strlcat(char *dst, const char *src, size_t size) +{ + size_t len = strlen(dst); + if (size <= len + 1) + return len + strlen(src); + return len + av_strlcpy(dst + len, src, size - len); +} + +size_t av_strlcatf(char *dst, size_t size, const char *fmt, ...) +{ + int len = strlen(dst); + va_list vl; + + va_start(vl, fmt); + len += vsnprintf(dst + len, size > len ? size - len : 0, fmt, vl); + va_end(vl); + + return len; +} diff --git a/contrib/ffmpeg/libavutil/tree.c b/contrib/ffmpeg/libavutil/tree.c index c929e4819..cb442ff4b 100644 --- a/contrib/ffmpeg/libavutil/tree.c +++ b/contrib/ffmpeg/libavutil/tree.c @@ -28,58 +28,97 @@ typedef struct AVTreeNode{ int state; }AVTreeNode; +const int av_tree_node_size = sizeof(AVTreeNode); + void *av_tree_find(const AVTreeNode *t, void *key, int (*cmp)(void *key, const void *b), void *next[2]){ if(t){ - unsigned int v= cmp(t->elem, key); + unsigned int v= cmp(key, t->elem); if(v){ - if(next) next[(v>>31)^1]= t->elem; - return av_tree_find(t->child[v>>31], key, cmp, next); + if(next) next[v>>31]= t->elem; + return av_tree_find(t->child[(v>>31)^1], key, cmp, next); }else{ + if(next){ + av_tree_find(t->child[0], key, cmp, next); + av_tree_find(t->child[1], key, cmp, next); + } return t->elem; } } return NULL; } -void *av_tree_insert(AVTreeNode **tp, void *key, int (*cmp)(void *key, const void *b)){ +void *av_tree_insert(AVTreeNode **tp, void *key, int (*cmp)(void *key, const void *b), AVTreeNode **next){ AVTreeNode *t= *tp; if(t){ unsigned int v= cmp(t->elem, key); - if(v){ - int i= v>>31; + void *ret; + if(!v){ + if(*next) + return t->elem; + else if(t->child[0]||t->child[1]){ + int i= !t->child[0]; + void *next_elem[2]; + av_tree_find(t->child[i], key, cmp, next_elem); + key= t->elem= next_elem[i]; + v= -i; + }else{ + *next= t; + *tp=NULL; + return NULL; + } + } + ret= av_tree_insert(&t->child[v>>31], key, cmp, next); + if(!ret){ + int i= (v>>31) ^ !!*next; AVTreeNode **child= &t->child[i]; - void *ret= av_tree_insert(child, key, cmp); - if(!ret){ - t->state -= ((int)v>>31)|1; - if(!(t->state&1)){ - if(t->state){ - if((*child)->state*2 == t->state){ - *tp= *child; - *child= (*child)->child[i^1]; - (*tp)->child[i^1]= t; - t->state= 0; - }else{ - *tp= (*child)->child[i^1]; - (*child)->child[i^1]= (*tp)->child[i]; - (*tp)->child[i]= *child; - *child= (*tp)->child[i^1]; - (*tp)->child[i^1]= t; - - i= (*tp)->state > 0; - (*tp)->child[i ]->state= 0; - (*tp)->child[i^1]->state= -(*tp)->state; - } + t->state += 2*i - 1; + + if(!(t->state&1)){ + if(t->state){ + /* The following code is equivalent to + if((*child)->state*2 == -t->state) + rotate(child, i^1); + rotate(tp, i); + + with rotate(): + static void rotate(AVTreeNode **tp, int i){ + AVTreeNode *t= *tp; + + *tp= t->child[i]; + t->child[i]= t->child[i]->child[i^1]; + (*tp)->child[i^1]= t; + i= 4*t->state + 2*(*tp)->state + 12; + t ->state= ((0x614586 >> i) & 3)-1; + (*tp)->state= ((*tp)->state>>1) + ((0x400EEA >> i) & 3)-1; + } + but such a rotate function is both bigger and slower + */ + if((*child)->state*2 == -t->state){ + *tp= (*child)->child[i^1]; + (*child)->child[i^1]= (*tp)->child[i]; + (*tp)->child[i]= *child; + *child= (*tp)->child[i^1]; + (*tp)->child[i^1]= t; + + (*tp)->child[0]->state= -((*tp)->state>0); + (*tp)->child[1]->state= (*tp)->state<0 ; (*tp)->state=0; + }else{ + *tp= *child; + *child= (*child)->child[i^1]; + (*tp)->child[i^1]= t; + if((*tp)->state) t->state = 0; + else t->state>>= 1; + (*tp)->state= -t->state; } - return key; } } - return ret; - }else{ - return t->elem; + if(!(*tp)->state ^ !!*next) + return key; } + return ret; }else{ - *tp= av_mallocz(sizeof(AVTreeNode)); + *tp= *next; *next= NULL; (*tp)->elem= key; return NULL; } @@ -100,7 +139,7 @@ void av_tree_enumerate(AVTreeNode *t, void *opaque, int (*f)(void *opaque, void #endif #ifdef TEST - +#undef random static int check(AVTreeNode *t){ if(t){ int left= check(t->child[0]); @@ -132,19 +171,32 @@ int cmp(const void *a, const void *b){ return a-b; } -int main(){ - int i,j,k; - AVTreeNode *root= NULL; +int main(void){ + int i,k; + AVTreeNode *root= NULL, *node=NULL; for(i=0; i<10000; i++){ - int j= (random()%863294); + int j= (random()%86294); if(check(root) > 999){ av_log(NULL, AV_LOG_ERROR, "FATAL error %d\n", i); print(root, 0); return -1; } av_log(NULL, AV_LOG_ERROR, "inserting %4d\n", j); - av_tree_insert(&root, (void*)(j+1), cmp); + if(!node) + node= av_mallocz(av_tree_node_size); + av_tree_insert(&root, (void*)(j+1), cmp, &node); + + j= (random()%86294); + k= av_tree_find(root, (void*)(j+1), cmp, NULL); + if(k){ + AVTreeNode *node2=NULL; + av_log(NULL, AV_LOG_ERROR, "removing %4d\n", j); + av_tree_insert(&root, (void*)(j+1), cmp, &node2); + k= av_tree_find(root, (void*)(j+1), cmp, NULL); + if(k) + av_log(NULL, AV_LOG_ERROR, "removial failure %d\n", i); + } } return 0; } diff --git a/contrib/ffmpeg/libavutil/tree.h b/contrib/ffmpeg/libavutil/tree.h index be1735858..111ea81a0 100644 --- a/contrib/ffmpeg/libavutil/tree.h +++ b/contrib/ffmpeg/libavutil/tree.h @@ -21,13 +21,16 @@ /** * @file tree.h * A tree container. + * Insertion, Removial, Finding equal, largest which is smaller than and + * smallest which is larger than all have O(log n) worst case time. * @author Michael Niedermayer <michaelni@gmx.at> */ -#ifndef TREE_H -#define TREE_H +#ifndef FFMPEG_TREE_H +#define FFMPEG_TREE_H struct AVTreeNode; +extern const int av_tree_node_size; /** * Finds an element. @@ -41,18 +44,39 @@ struct AVTreeNode; void *av_tree_find(const struct AVTreeNode *root, void *key, int (*cmp)(void *key, const void *b), void *next[2]); /** - * Finds a element for which cmp(key, elem)==0, if no such element is found key - * is inserted into the tree. + * Inserts or removes an element. + * If *next is NULL then the element supplied will be removed, if no such + * element exists behavior is undefined. + * If *next is not NULL then the element supplied will be inserted, unless + * it already exists in the tree. * @param rootp A pointer to a pointer to the root node of the tree. Note that * the root node can change during insertions, this is required * to keep the tree balanced. + * @param next Used to allocate and free AVTreeNodes. For insertion the user + * must set it to an allocated and zeroed object of at least + * av_tree_node_size bytes size. av_tree_insert() will set it to + * NULL if it has been consumed. + * For deleting elements *next is set to NULL by the user and + * av_tree_node_size() will set it to the AVTreeNode which was + * used for the removed element. + * This allows the use of flat arrays, which have + * lower overhead compared to many malloced elements. + * You might want to define a function like: + * void *tree_insert(struct AVTreeNode **rootp, void *key, int (*cmp)(void *key, const void *b), AVTreeNode **next){ + * if(!*next) *next= av_mallocz(av_tree_node_size); + * return av_tree_insert(rootp, key, cmp, next); + * } + * void *tree_remove(struct AVTreeNode **rootp, void *key, int (*cmp)(void *key, const void *b, AVTreeNode **next)){ + * if(*next) av_freep(next); + * return av_tree_insert(rootp, key, cmp, next); + * } * * @return If no insertion happened, the found element. - * If an insertion happened, then either key or NULL will be returned. + * If an insertion or removial happened, then either key or NULL will be returned. * Which one it is depends on the tree state and the implementation. You * should make no assumptions that it's one or the other in the code. */ -void *av_tree_insert(struct AVTreeNode **rootp, void *key, int (*cmp)(void *key, const void *b)); +void *av_tree_insert(struct AVTreeNode **rootp, void *key, int (*cmp)(void *key, const void *b), struct AVTreeNode **next); void av_tree_destroy(struct AVTreeNode *t); -#endif /* TREE_H */ +#endif /* FFMPEG_TREE_H */ diff --git a/contrib/ffmpeg/libavutil/x86_cpu.h b/contrib/ffmpeg/libavutil/x86_cpu.h index 67d4cd9aa..5ab570405 100644 --- a/contrib/ffmpeg/libavutil/x86_cpu.h +++ b/contrib/ffmpeg/libavutil/x86_cpu.h @@ -18,47 +18,51 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef AVUTIL_X86CPU_H -#define AVUTIL_X86CPU_H +#ifndef FFMPEG_X86CPU_H +#define FFMPEG_X86CPU_H #ifdef ARCH_X86_64 -# define REG_a "rax" -# define REG_b "rbx" -# define REG_c "rcx" -# define REG_d "rdx" -# define REG_D "rdi" -# define REG_S "rsi" -# define PTR_SIZE "8" +# define REG_a "rax" +# define REG_b "rbx" +# define REG_c "rcx" +# define REG_d "rdx" +# define REG_D "rdi" +# define REG_S "rsi" +# define PTR_SIZE "8" -# define REG_SP "rsp" -# define REG_BP "rbp" -# define REGBP rbp -# define REGa rax -# define REGb rbx -# define REGc rcx -# define REGSP rsp +# define REG_SP "rsp" +# define REG_BP "rbp" +# define REGBP rbp +# define REGa rax +# define REGb rbx +# define REGc rcx +# define REGSP rsp #else -# define REG_a "eax" -# define REG_b "ebx" -# define REG_c "ecx" -# define REG_d "edx" -# define REG_D "edi" -# define REG_S "esi" -# define PTR_SIZE "4" +# define REG_a "eax" +# define REG_b "ebx" +# define REG_c "ecx" +# define REG_d "edx" +# define REG_D "edi" +# define REG_S "esi" +# define PTR_SIZE "4" -# define REG_SP "esp" -# define REG_BP "ebp" -# define REGBP ebp -# define REGa eax -# define REGb ebx -# define REGc ecx -# define REGSP esp +# define REG_SP "esp" +# define REG_BP "ebp" +# define REGBP ebp +# define REGa eax +# define REGb ebx +# define REGc ecx +# define REGSP esp #endif -#if defined(ARCH_X86_64) || (defined(ARCH_X86_32) && defined(CONFIG_EBX_AVAILABLE) && defined(CONFIG_EBP_AVAILABLE)) -# define CONFIG_7REGS 1 +#if defined(ARCH_X86_64) || (defined(ARCH_X86_32) && defined(HAVE_EBX_AVAILABLE) && defined(HAVE_EBP_AVAILABLE)) +# define HAVE_7REGS 1 #endif -#endif /* AVUTIL_X86CPU_H */ +#if defined(ARCH_X86_64) && defined(PIC) +# define BROKEN_RELOCATIONS 1 +#endif + +#endif /* FFMPEG_X86CPU_H */ |