diff options
-rw-r--r-- | src/libffmpeg/libavutil/Makefile.am | 12 | ||||
-rw-r--r-- | src/libffmpeg/libavutil/avutil.h | 56 | ||||
-rw-r--r-- | src/libffmpeg/libavutil/bswap.h | 48 | ||||
-rw-r--r-- | src/libffmpeg/libavutil/common.h | 422 | ||||
-rw-r--r-- | src/libffmpeg/libavutil/integer.c | 32 | ||||
-rw-r--r-- | src/libffmpeg/libavutil/integer.h | 8 | ||||
-rw-r--r-- | src/libffmpeg/libavutil/intfloat_readwrite.h | 8 | ||||
-rw-r--r-- | src/libffmpeg/libavutil/mathematics.c | 77 | ||||
-rw-r--r-- | src/libffmpeg/libavutil/rational.c | 21 | ||||
-rw-r--r-- | src/libffmpeg/libavutil/rational.h | 4 |
10 files changed, 285 insertions, 403 deletions
diff --git a/src/libffmpeg/libavutil/Makefile.am b/src/libffmpeg/libavutil/Makefile.am index fca5a2d49..f4aeee569 100644 --- a/src/libffmpeg/libavutil/Makefile.am +++ b/src/libffmpeg/libavutil/Makefile.am @@ -7,17 +7,27 @@ ASFLAGS = noinst_LTLIBRARIES = libavutil.la libavutil_la_SOURCES = \ + adler32.c \ + crc.c \ integer.c \ + lls.c \ + log.c \ mathematics.c \ + md5.c \ rational.c libavutil_la_LDFLAGS = -avoid-version -module noinst_HEADERS = \ + adler32.h \ avutil.h \ bswap.h \ common.h \ + crc.h \ integer.h \ intfloat_readwrite.h \ - mathematics.h \ + lls.h \ + log.h \ + mathematics.c \ + md5.h \ rational.h diff --git a/src/libffmpeg/libavutil/avutil.h b/src/libffmpeg/libavutil/avutil.h index b9f930a56..6f66fbb07 100644 --- a/src/libffmpeg/libavutil/avutil.h +++ b/src/libffmpeg/libavutil/avutil.h @@ -11,14 +11,14 @@ extern "C" { #endif -#define AV_STRINGIFY(s) AV_TOSTRING(s) +#define AV_STRINGIFY(s) AV_TOSTRING(s) #define AV_TOSTRING(s) #s -#define LIBAVUTIL_VERSION_INT ((49<<16)+(0<<8)+0) -#define LIBAVUTIL_VERSION 49.0.0 -#define LIBAVUTIL_BUILD LIBAVUTIL_VERSION_INT +#define LIBAVUTIL_VERSION_INT ((49<<16)+(0<<8)+0) +#define LIBAVUTIL_VERSION 49.0.0 +#define LIBAVUTIL_BUILD LIBAVUTIL_VERSION_INT -#define LIBAVUTIL_IDENT "Lavu" AV_STRINGIFY(LIBAVUTIL_VERSION) +#define LIBAVUTIL_IDENT "Lavu" AV_STRINGIFY(LIBAVUTIL_VERSION) #include "common.h" @@ -26,6 +26,52 @@ extern "C" { #include "rational.h" #include "integer.h" #include "intfloat_readwrite.h" +#include "log.h" + +/** + * Pixel format. Notes: + * + * PIX_FMT_RGBA32 is handled in an endian-specific manner. A RGBA + * color is put together as: + * (A << 24) | (R << 16) | (G << 8) | B + * This is stored as BGRA on little endian CPU architectures and ARGB on + * big endian CPUs. + * + * When the pixel format is palettized RGB (PIX_FMT_PAL8), the palettized + * image data is stored in AVFrame.data[0]. The palette is transported in + * AVFrame.data[1] and, is 1024 bytes long (256 4-byte entries) and is + * formatted the same as in PIX_FMT_RGBA32 described above (i.e., it is + * also endian-specific). Note also that the individual RGB palette + * components stored in AVFrame.data[1] should be in the range 0..255. + * This is important as many custom PAL8 video codecs that were designed + * to run on the IBM VGA graphics adapter use 6-bit palette components. + */ +enum PixelFormat { + PIX_FMT_NONE= -1, + PIX_FMT_YUV420P, ///< Planar YUV 4:2:0 (1 Cr & Cb sample per 2x2 Y samples) + PIX_FMT_YUV422, ///< Packed pixel, Y0 Cb Y1 Cr + PIX_FMT_RGB24, ///< Packed pixel, 3 bytes per pixel, RGBRGB... + PIX_FMT_BGR24, ///< Packed pixel, 3 bytes per pixel, BGRBGR... + PIX_FMT_YUV422P, ///< Planar YUV 4:2:2 (1 Cr & Cb sample per 2x1 Y samples) + PIX_FMT_YUV444P, ///< Planar YUV 4:4:4 (1 Cr & Cb sample per 1x1 Y samples) + PIX_FMT_RGBA32, ///< Packed pixel, 4 bytes per pixel, BGRABGRA..., stored in cpu endianness + PIX_FMT_YUV410P, ///< Planar YUV 4:1:0 (1 Cr & Cb sample per 4x4 Y samples) + PIX_FMT_YUV411P, ///< Planar YUV 4:1:1 (1 Cr & Cb sample per 4x1 Y samples) + PIX_FMT_RGB565, ///< always stored in cpu endianness + PIX_FMT_RGB555, ///< always stored in cpu endianness, most significant bit to 1 + PIX_FMT_GRAY8, + PIX_FMT_MONOWHITE, ///< 0 is white + PIX_FMT_MONOBLACK, ///< 0 is black + PIX_FMT_PAL8, ///< 8 bit with RGBA palette + PIX_FMT_YUVJ420P, ///< Planar YUV 4:2:0 full scale (jpeg) + PIX_FMT_YUVJ422P, ///< Planar YUV 4:2:2 full scale (jpeg) + PIX_FMT_YUVJ444P, ///< Planar YUV 4:4:4 full scale (jpeg) + PIX_FMT_XVMC_MPEG2_MC,///< XVideo Motion Acceleration via common packet passing(xvmc_render.h) + PIX_FMT_XVMC_MPEG2_IDCT, + PIX_FMT_UYVY422, ///< Packed pixel, Cb Y0 Cr Y1 + PIX_FMT_UYVY411, ///< Packed pixel, Cb Y0 Y1 Cr Y2 Y3 + PIX_FMT_NB, +}; #ifdef __cplusplus } diff --git a/src/libffmpeg/libavutil/bswap.h b/src/libffmpeg/libavutil/bswap.h index 50fd57178..25d418c69 100644 --- a/src/libffmpeg/libavutil/bswap.h +++ b/src/libffmpeg/libavutil/bswap.h @@ -19,22 +19,22 @@ #if defined(ARCH_X86) || defined(ARCH_X86_64) static always_inline uint16_t bswap_16(uint16_t x) { - __asm("rorw $8, %0" : - LEGACY_REGS (x) : + __asm("rorw $8, %0" : + LEGACY_REGS (x) : "0" (x)); return x; } static always_inline uint32_t bswap_32(uint32_t x) { -#if __CPU__ > 386 - __asm("bswap %0": +#if __CPU__ != 386 + __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; @@ -43,12 +43,12 @@ static always_inline uint32_t bswap_32(uint32_t x) static inline uint64_t bswap_64(uint64_t x) { #ifdef ARCH_X86_64 - __asm("bswap %0": - "=r" (x) : + __asm("bswap %0": + "=r" (x) : "0" (x)); return x; #else - union { + union { uint64_t ll; struct { uint32_t l,h; @@ -63,22 +63,22 @@ static inline uint64_t bswap_64(uint64_t x) #elif defined(ARCH_SH4) static always_inline uint16_t bswap_16(uint16_t x) { - __asm__("swap.b %0,%0":"=r"(x):"0"(x)); - return x; + __asm__("swap.b %0,%0":"=r"(x):"0"(x)); + return x; } static 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; + __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 { + union { uint64_t ll; struct { uint32_t l,h; @@ -119,9 +119,9 @@ static inline uint64_t bswap_64(uint64_t x) x= ((x<<16)&0xFFFF0000FFFF0000ULL) | ((x>>16)&0x0000FFFF0000FFFFULL); return (x>>32) | (x<<32); #else - union { + union { uint64_t ll; - uint32_t l[2]; + uint32_t l[2]; } w, r; w.ll = x; r.l[0] = bswap_32 (w.l[1]); @@ -129,9 +129,9 @@ static inline uint64_t bswap_64(uint64_t x) return r.ll; #endif } -#endif /* !ARCH_X86 */ +#endif /* !ARCH_X86 */ -#endif /* !HAVE_BYTESWAP_H */ +#endif /* !HAVE_BYTESWAP_H */ // be2me ... BigEndian to MachineEndian // le2me ... LittleEndian to MachineEndian diff --git a/src/libffmpeg/libavutil/common.h b/src/libffmpeg/libavutil/common.h index fffd2ff01..b26c821f8 100644 --- a/src/libffmpeg/libavutil/common.h +++ b/src/libffmpeg/libavutil/common.h @@ -1,29 +1,15 @@ /** * @file common.h - * common internal api header. + * common internal and external api header. */ #ifndef COMMON_H #define COMMON_H -/* xine: disable DEBUG for ffmpeg (too noisy) */ -#ifdef DEBUG -#undef DEBUG -#define DISABLE_INLINE -#endif - -#if defined(WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__) -# define CONFIG_WIN32 -#endif - #ifndef M_PI #define M_PI 3.14159265358979323846 #endif -#if ( defined(__PIC__) || defined(__pic__) ) && ! defined(PIC) -# define PIC -#endif - #ifdef HAVE_AV_CONFIG_H /* only include the following when compiling package */ # include "config.h" @@ -39,31 +25,6 @@ # include "berrno.h" # endif # include <math.h> - -# ifndef ENODATA -# define ENODATA 61 -# endif - -#include <stddef.h> -#ifndef offsetof -# define offsetof(T,F) ((unsigned int)((char *)&((T *)0)->F)) -#endif - -#define AVOPTION_CODEC_BOOL(name, help, field) \ - { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_BOOL } -#define AVOPTION_CODEC_DOUBLE(name, help, field, minv, maxv, defval) \ - { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_DOUBLE, minv, maxv, defval } -#define AVOPTION_CODEC_FLAG(name, help, field, flag, defval) \ - { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_FLAG, flag, 0, defval } -#define AVOPTION_CODEC_INT(name, help, field, minv, maxv, defval) \ - { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_INT, minv, maxv, defval } -#define AVOPTION_CODEC_STRING(name, help, field, str, val) \ - { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_STRING, .defval = val, .defstr = str } -#define AVOPTION_CODEC_RCOVERRIDE(name, help, field) \ - { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_RCOVERRIDE, .defval = 0, .defstr = NULL } -#define AVOPTION_SUB(ptr) { .name = NULL, .help = (const char*)ptr } -#define AVOPTION_END() AVOPTION_SUB(NULL) - #endif /* HAVE_AV_CONFIG_H */ /* Suppress restrict if it was not defined in config.h. */ @@ -104,16 +65,34 @@ typedef unsigned char uint8_t; typedef unsigned short uint16_t; typedef unsigned int uint32_t; - -# ifdef CONFIG_WIN32 - typedef signed __int64 int64_t; - typedef unsigned __int64 uint64_t; -# else /* other OS */ - typedef signed long long int64_t; - typedef unsigned long long uint64_t; -# endif /* other OS */ + typedef signed long long int64_t; + typedef unsigned long long uint64_t; #endif /* EMULATE_INTTYPES */ +#ifndef PRId64 +#define PRId64 "lld" +#endif + +#ifndef PRIu64 +#define PRIu64 "llu" +#endif + +#ifndef PRIx64 +#define PRIx64 "llx" +#endif + +#ifndef PRId32 +#define PRId32 "d" +#endif + +#ifndef PRIdFAST16 +#define PRIdFAST16 PRId32 +#endif + +#ifndef PRIdFAST32 +#define PRIdFAST32 PRId32 +#endif + #ifndef INT16_MIN #define INT16_MIN (-0x7fff-1) #endif @@ -122,6 +101,18 @@ #define INT16_MAX 0x7fff #endif +#ifndef INT32_MIN +#define INT32_MIN (-0x7fffffff-1) +#endif + +#ifndef INT32_MAX +#define INT32_MAX 0x7fffffff +#endif + +#ifndef UINT32_MAX +#define UINT32_MAX 0xffffffff +#endif + #ifndef INT64_MIN #define INT64_MIN (-0x7fffffffffffffffLL-1) #endif @@ -152,125 +143,22 @@ typedef uint64_t uint_fast64_t; # endif #endif -#if defined(CONFIG_OS2) || defined(CONFIG_SUNOS) -static inline float floorf(float f) { - return floor(f); -} -#endif - -#ifdef CONFIG_WIN32 - -/* windows */ - -# if !defined(__MINGW32__) && !defined(__CYGWIN__) -# define int64_t_C(c) (c ## i64) -# define uint64_t_C(c) (c ## i64) - -# ifdef HAVE_AV_CONFIG_H -# define inline __inline -# endif - -# else -# define int64_t_C(c) (c ## LL) -# define uint64_t_C(c) (c ## ULL) -# endif /* __MINGW32__ */ - -# ifdef HAVE_AV_CONFIG_H -# ifdef _DEBUG -# define DEBUG -# endif - -# define snprintf _snprintf -# define vsnprintf _vsnprintf -# endif - -/* CONFIG_WIN32 end */ -#elif defined (CONFIG_OS2) -/* OS/2 EMX */ - #ifndef int64_t_C #define int64_t_C(c) (c ## LL) #define uint64_t_C(c) (c ## ULL) #endif -#ifdef HAVE_AV_CONFIG_H - -#if 0 -#ifdef USE_FASTMEMCPY - #define memcpy(to, from, len) xine_fast_memcpy(to, from, len) -#endif -#endif - -#include <float.h> - -#endif /* HAVE_AV_CONFIG_H */ - -/* CONFIG_OS2 end */ +#if defined(__MINGW32__) && !defined(BUILD_AVUTIL) && defined(BUILD_SHARED_AV) +# define FF_IMPORT_ATTR __declspec(dllimport) #else - -/* unix */ - -#ifndef int64_t_C -#define int64_t_C(c) (c ## LL) -#define uint64_t_C(c) (c ## ULL) +# define FF_IMPORT_ATTR #endif -#ifdef HAVE_AV_CONFIG_H - -#if 0 -# ifdef USE_FASTMEMCPY -# define memcpy(to, from, len) xine_fast_memcpy(to, from, len) -# endif -# endif /* HAVE_AV_CONFIG_H */ -#endif - -#endif /* !CONFIG_WIN32 && !CONFIG_OS2 */ #ifdef HAVE_AV_CONFIG_H - -# include "bswap.h" - -// Use rip-relative addressing if compiling PIC code on x86-64. -# if defined(__MINGW32__) || defined(__CYGWIN__) || \ - defined(__OS2__) || (defined (__OpenBSD__) && !defined(__ELF__)) -# if defined(ARCH_X86_64) && defined(PIC) -# define MANGLE(a) "_" #a"(%%rip)" -# else -# define MANGLE(a) "_" #a -# endif -# else -# if defined(ARCH_X86_64) && defined(PIC) -# define MANGLE(a) #a"(%%rip)" -# else -# define MANGLE(a) #a -# endif -# endif - -/* debug stuff */ - -# ifndef DEBUG -# ifndef NDEBUG -# define NDEBUG -# endif -# endif -# include <assert.h> - -/* dprintf macros */ -# if defined(CONFIG_WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__) - -inline void dprintf(const char* fmt,...) {} - -# else - -# ifdef DEBUG -# define dprintf(fmt,...) av_log(NULL, AV_LOG_DEBUG, fmt, __VA_ARGS__) -# else -# define dprintf(fmt,...) -# endif - -# endif /* !CONFIG_WIN32 */ - -# define av_abort() do { av_log(NULL, AV_LOG_ERROR, "Abort at %s:%d\n", __FILE__, __LINE__); abort(); } while (0) +/* only include the following when compiling package */ +# include "internal.h" +#endif //rounded divison & shift #define RSHIFT(a,b) ((a) > 0 ? ((a) + ((1<<(b))>>1))>>(b) : ((a) + ((1<<(b))>>1)-1)>>(b)) @@ -281,51 +169,8 @@ inline void dprintf(const char* fmt,...) {} #define FFMAX(a,b) ((a) > (b) ? (a) : (b)) #define FFMIN(a,b) ((a) > (b) ? (b) : (a)) -extern const uint32_t inverse[256]; - -#if defined(ARCH_X86) || defined(ARCH_X86_64) -# define FASTDIV(a,b) \ - ({\ - int ret,dmy;\ - asm volatile(\ - "mull %3"\ - :"=d"(ret),"=a"(dmy)\ - :"1"(a),"g"(inverse[b])\ - );\ - ret;\ - }) -#elif defined(CONFIG_FASTDIV) -# define FASTDIV(a,b) ((uint32_t)((((uint64_t)a)*inverse[b])>>32)) -#else -# define FASTDIV(a,b) ((a)/(b)) -#endif - -/* define it to include statistics code (useful only for optimizing - codec efficiency */ -//#define STATS - -#ifdef STATS - -enum { - ST_UNKNOWN, - ST_DC, - ST_INTRA_AC, - ST_INTER_AC, - ST_INTRA_MB, - ST_INTER_MB, - ST_MV, - ST_NB, -}; - -extern int st_current_index; -extern unsigned int st_bit_counts[ST_NB]; -extern unsigned int st_out_bit_counts[ST_NB]; - -void print_stats(void); -#endif - /* misc math functions */ -extern const uint8_t ff_log2_tab[256]; +extern FF_IMPORT_ATTR const uint8_t ff_log2_tab[256]; static inline int av_log2(unsigned int v) { @@ -386,50 +231,41 @@ static inline int mid_pred(int a, int b, int c) #endif } +/** + * clip a signed integer value into the amin-amax range + * @param a value to clip + * @param amin minimum value of the clip range + * @param amax maximum value of the clip range + * @return cliped value + */ static inline int clip(int a, int amin, int amax) { - if (a < amin) - return amin; - else if (a > amax) - return amax; - else - return a; + if (a < amin) return amin; + else if (a > amax) return amax; + else return a; } -static inline int clip_uint8(int a) +/** + * clip a signed integer value into the 0-255 range + * @param a value to clip + * @return cliped value + */ +static inline uint8_t clip_uint8(int a) { if (a&(~255)) return (-a)>>31; else return a; } /* math */ -extern const uint8_t ff_sqrt_tab[128]; - int64_t ff_gcd(int64_t a, int64_t b); -static inline int ff_sqrt(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; - } - } - return ret; -} - /** * converts fourcc string to int */ static inline int ff_get_fourcc(const char *s){ +#ifdef HAVE_AV_CONFIG_H assert( strlen(s)==4 ); +#endif return (s[0]) + (s[1]<<8) + (s[2]<<16) + (s[3]<<24); } @@ -438,58 +274,39 @@ static inline int ff_get_fourcc(const char *s){ #define MKBETAG(a,b,c,d) (d | (c << 8) | (b << 16) | (a << 24)) -#if defined(ARCH_X86) || defined(ARCH_X86_64) -#define MASK_ABS(mask, level)\ - asm volatile(\ - "cdq \n\t"\ - "xorl %1, %0 \n\t"\ - "subl %1, %0 \n\t"\ - : "+a" (level), "=&d" (mask)\ - ); -#else -#define MASK_ABS(mask, level)\ - mask= level>>31;\ - level= (level^mask)-mask; -#endif - - -#if __CPU__ >= 686 && !defined(RUNTIME_CPUDETECT) -#define COPY3_IF_LT(x,y,a,b,c,d)\ -asm volatile (\ - "cmpl %0, %3 \n\t"\ - "cmovl %3, %0 \n\t"\ - "cmovl %4, %1 \n\t"\ - "cmovl %5, %2 \n\t"\ - : "+r" (x), "+r" (a), "+r" (c)\ - : "r" (y), "r" (b), "r" (d)\ -); -#else -#define COPY3_IF_LT(x,y,a,b,c,d)\ -if((y)<(x)){\ - (x)=(y);\ - (a)=(b);\ - (c)=(d);\ -} -#endif +#define GET_UTF8(val, GET_BYTE, ERROR)\ + val= GET_BYTE;\ + {\ + int ones= 7 - av_log2(val ^ 255);\ + if(ones==1)\ + ERROR\ + val&= 127>>ones;\ + while(--ones > 0){\ + int tmp= GET_BYTE - 128;\ + if(tmp>>6)\ + ERROR\ + val= (val<<6) + tmp;\ + }\ + } #if defined(ARCH_X86) || defined(ARCH_X86_64) || defined(ARCH_POWERPC) #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) 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; } #else //FIXME check ppc64 static inline uint64_t read_time(void) @@ -528,69 +345,18 @@ tend= read_time();\ }else\ tskip_count++;\ if(256*256*256*64%(tcount+tskip_count)==0){\ - av_log(NULL, AV_LOG_DEBUG, "%Ld dezicycles in %s, %d runs, %d skips\n", tsum*10/tcount, id, tcount, tskip_count);\ + 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 START_TIMER #define STOP_TIMER(id) {} #endif -/* avoid usage of various functions */ -#define malloc please_use_av_malloc -#define free please_use_av_free -#define realloc please_use_av_realloc -#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 sprintf -#define sprintf sprintf_is_forbidden_due_to_security_issues_use_snprintf -#undef strcat -#define strcat strcat_is_forbidden_due_to_security_issues_use_pstrcat -#if !(defined(LIBAVFORMAT_BUILD) || defined(_FRAMEHOOK_H)) -//#define printf please_use_av_log -//#define fprintf please_use_av_log -#endif - -#define CHECKED_ALLOCZ(p, size)\ -{\ - p= av_mallocz(size);\ - if(p==NULL && (size)!=0){\ - perror("malloc");\ - goto fail;\ - }\ -} - -#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 always_inline long int lrintf(float x) -{ -#ifdef CONFIG_WIN32 -# ifdef ARCH_X86 - 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 */ -#else - return (int)(rint(x)); -#endif /* CONFIG_WIN32 */ -} -#else -#ifndef _ISOC9X_SOURCE -#define _ISOC9X_SOURCE -#endif -#include <math.h> -#endif /* HAVE_LRINTF */ - -#endif /* HAVE_AV_CONFIG_H */ +/* memory */ +void *av_malloc(unsigned int size); +void *av_realloc(void *ptr, unsigned int size); +void av_free(void *ptr); /* xine: inline causes trouble for debug compiling */ #ifdef DISABLE_INLINE diff --git a/src/libffmpeg/libavutil/integer.c b/src/libffmpeg/libavutil/integer.c index 38a826f86..98c3df35d 100644 --- a/src/libffmpeg/libavutil/integer.c +++ b/src/libffmpeg/libavutil/integer.c @@ -14,10 +14,10 @@ * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ - + /** * @file integer.c * arbitrary precision integers. @@ -29,7 +29,7 @@ AVInteger av_add_i(AVInteger a, AVInteger b){ int i, carry=0; - + for(i=0; i<AV_INTEGER_SIZE; i++){ carry= (carry>>16) + a.v[i] + b.v[i]; a.v[i]= carry; @@ -39,7 +39,7 @@ AVInteger av_add_i(AVInteger a, AVInteger b){ AVInteger av_sub_i(AVInteger a, AVInteger b){ int i, carry=0; - + for(i=0; i<AV_INTEGER_SIZE; i++){ carry= (carry>>16) + a.v[i] - b.v[i]; a.v[i]= carry; @@ -66,12 +66,12 @@ AVInteger av_mul_i(AVInteger a, AVInteger b){ int i, j; int na= (av_log2_i(a)+16) >> 4; int nb= (av_log2_i(b)+16) >> 4; - + memset(&out, 0, sizeof(out)); - + for(i=0; i<na; i++){ unsigned int carry=0; - + if(a.v[i]) for(j=i; j<AV_INTEGER_SIZE && j-i<=nb; j++){ carry= (carry>>16) + out.v[j] + a.v[i]*b.v[j-i]; @@ -86,10 +86,10 @@ AVInteger av_mul_i(AVInteger a, AVInteger b){ * returns 0 if a==b, 1 if a>b and -1 if a<b. */ int av_cmp_i(AVInteger a, AVInteger b){ - int i; + int i; int v= (int16_t)a.v[AV_INTEGER_SIZE-1] - (int16_t)b.v[AV_INTEGER_SIZE-1]; if(v) return (v>>16)|1; - + for(i=AV_INTEGER_SIZE-2; i>=0; i--){ int v= a.v[i] - b.v[i]; if(v) return (v>>16)|1; @@ -123,13 +123,13 @@ AVInteger av_mod_i(AVInteger *quot, AVInteger a, AVInteger b){ int i= av_log2_i(a) - av_log2_i(b); AVInteger quot_temp; if(!quot) quot = "_temp; - + assert((int16_t)a[AV_INTEGER_SIZE-1] >= 0 && (int16_t)b[AV_INTEGER_SIZE-1] >= 0); assert(av_log2(b)>=0); - + if(i > 0) b= av_shr_i(b, -i); - + memset(quot, 0, sizeof(AVInteger)); while(i-- >= 0){ @@ -158,7 +158,7 @@ AVInteger av_div_i(AVInteger a, AVInteger b){ AVInteger av_int2i(int64_t a){ AVInteger out; int i; - + for(i=0; i<AV_INTEGER_SIZE; i++){ out.v[i]= a; a>>=16; @@ -168,13 +168,13 @@ AVInteger av_int2i(int64_t a){ /** * converts the given AVInteger to an int64_t. - * if the AVInteger is too large to fit into an int64_t, + * if the AVInteger is too large to fit into an int64_t, * then only the least significant 64bit will be used */ int64_t av_i2int(AVInteger a){ int i; int64_t out=(int8_t)a.v[AV_INTEGER_SIZE-1]; - + for(i= AV_INTEGER_SIZE-2; i>=0; i--){ out = (out<<16) + a.v[i]; } @@ -203,7 +203,7 @@ main(){ for(b=3; b<256*256*256; b+=27118){ AVInteger ai= av_int2i(a); AVInteger bi= av_int2i(b); - + assert(av_i2int(ai) == a); assert(av_i2int(bi) == b); assert(av_i2int(av_add_i(ai,bi)) == a+b); diff --git a/src/libffmpeg/libavutil/integer.h b/src/libffmpeg/libavutil/integer.h index ef1b2a089..523752912 100644 --- a/src/libffmpeg/libavutil/integer.h +++ b/src/libffmpeg/libavutil/integer.h @@ -14,23 +14,23 @@ * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ - + /** * @file integer.h * arbitrary precision integers * @author Michael Niedermayer <michaelni@gmx.at> */ - + #ifndef INTEGER_H #define INTEGER_H #define AV_INTEGER_SIZE 8 typedef struct AVInteger{ - uint16_t v[AV_INTEGER_SIZE]; + uint16_t v[AV_INTEGER_SIZE]; } AVInteger; AVInteger av_add_i(AVInteger a, AVInteger b); diff --git a/src/libffmpeg/libavutil/intfloat_readwrite.h b/src/libffmpeg/libavutil/intfloat_readwrite.h index 22f40bb66..33e4c636c 100644 --- a/src/libffmpeg/libavutil/intfloat_readwrite.h +++ b/src/libffmpeg/libavutil/intfloat_readwrite.h @@ -3,9 +3,17 @@ #include "common.h" +/* IEEE 80 bits extended float */ +typedef struct AVExtFloat { + uint8_t exponent[2]; + uint8_t mantissa[8]; +} AVExtFloat; + double av_int2dbl(int64_t v); float av_int2flt(int32_t v); +double av_ext2dbl(const AVExtFloat ext); int64_t av_dbl2int(double d); int32_t av_flt2int(float d); +AVExtFloat av_dbl2ext(double d); #endif /* INTFLOAT_READWRITE_H */ diff --git a/src/libffmpeg/libavutil/mathematics.c b/src/libffmpeg/libavutil/mathematics.c index aa3fd74e0..951324e99 100644 --- a/src/libffmpeg/libavutil/mathematics.c +++ b/src/libffmpeg/libavutil/mathematics.c @@ -13,16 +13,15 @@ * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ - + /** * @file mathematics.c * Miscellaneous math routines and tables. */ #include "common.h" -#include "integer.h" #include "mathematics.h" const uint8_t ff_sqrt_tab[128]={ @@ -49,14 +48,13 @@ int64_t ff_gcd(int64_t a, int64_t b){ } int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding rnd){ - AVInteger ai; int64_t r=0; assert(c > 0); assert(b >=0); assert(rnd >=0 && rnd<=5 && rnd!=4); - - if(a<0 && a != INT64_MIN) return -av_rescale_rnd(-a, b, c, rnd ^ ((rnd>>1)&1)); - + + if(a<0 && a != INT64_MIN) return -av_rescale_rnd(-a, b, c, rnd ^ ((rnd>>1)&1)); + if(rnd==AV_ROUND_NEAR_INF) r= c/2; else if(rnd&1) r= c-1; @@ -65,12 +63,40 @@ int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding rnd){ return (a * b + r)/c; else return a/c*b + (a%c*b + r)/c; + }else{ +#if 1 + uint64_t a0= a&0xFFFFFFFF; + uint64_t a1= a>>32; + uint64_t b0= b&0xFFFFFFFF; + uint64_t b1= b>>32; + uint64_t t1= a0*b1 + a1*b0; + uint64_t t1a= t1<<32; + int i; + + a0 = a0*b0 + t1a; + a1 = a1*b1 + (t1>>32) + (a0<t1a); + a0 += r; + a1 += a0<r; + + for(i=63; i>=0; i--){ +// int o= a1 & 0x8000000000000000ULL; + a1+= a1 + ((a0>>i)&1); + t1+=t1; + if(/*o || */c <= a1){ + a1 -= c; + t1++; + } + } + return t1; + } +#else + AVInteger ai; + ai= av_mul_i(av_int2i(a), av_int2i(b)); + ai= av_add_i(ai, av_int2i(r)); + + return av_i2int(av_div_i(ai, av_int2i(c))); } - - ai= av_mul_i(av_int2i(a), av_int2i(b)); - ai= av_add_i(ai, av_int2i(r)); - - return av_i2int(av_div_i(ai, av_int2i(c))); +#endif } int64_t av_rescale(int64_t a, int64_t b, int64_t c){ @@ -82,3 +108,30 @@ 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 +#include "integer.h" +#undef printf +main(){ + int64_t a,b,c,d,e; + + for(a=7; a<(1LL<<62); a+=a/3+1){ + for(b=3; b<(1LL<<62); b+=b/4+1){ + for(c=9; c<(1LL<<62); c+=(c*2)/5+3){ + int64_t r= c/2; + AVInteger ai; + ai= av_mul_i(av_int2i(a), av_int2i(b)); + ai= av_add_i(ai, av_int2i(r)); + + d= av_i2int(av_div_i(ai, av_int2i(c))); + + e= av_rescale(a,b,c); + + if((double)a * (double)b / (double)c > (1LL<<63)) + continue; + + if(d!=e) printf("%Ld*%Ld/%Ld= %Ld=%Ld\n", a, b, c, d, e); + } + } + } +} +#endif diff --git a/src/libffmpeg/libavutil/rational.c b/src/libffmpeg/libavutil/rational.c index 104499929..4a7b0edf7 100644 --- a/src/libffmpeg/libavutil/rational.c +++ b/src/libffmpeg/libavutil/rational.c @@ -14,10 +14,10 @@ * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ - + /** * @file rational.c * Rational numbers @@ -26,7 +26,7 @@ //#include <math.h> #include <limits.h> - + #include "common.h" #include "mathematics.h" #include "rational.h" @@ -42,7 +42,7 @@ int av_reduce(int *dst_nom, int *dst_den, int64_t nom, int64_t den, int64_t max) a1= (AVRational){nom, den}; den=0; } - + while(den){ int64_t x = nom / den; int64_t next_den= nom - den*x; @@ -57,10 +57,10 @@ int av_reduce(int *dst_nom, int *dst_den, int64_t nom, int64_t den, int64_t max) den= next_den; } assert(ff_gcd(a1.num, a1.den) == 1); - + *dst_nom = sign ? -a1.num : a1.num; *dst_den = a1.den; - + return den==0; } @@ -76,8 +76,7 @@ AVRational av_mul_q(AVRational b, AVRational c){ * returns b/c. */ AVRational av_div_q(AVRational b, AVRational c){ - av_reduce(&b.num, &b.den, b.num * (int64_t)c.den, b.den * (int64_t)c.num, INT_MAX); - return b; + return av_mul_q(b, (AVRational){c.den, c.num}); } /** @@ -92,8 +91,7 @@ AVRational av_add_q(AVRational b, AVRational c){ * returns b-c. */ AVRational av_sub_q(AVRational b, AVRational c){ - av_reduce(&b.num, &b.den, b.num * (int64_t)c.den - c.num * (int64_t)b.den, b.den * (int64_t)c.den, INT_MAX); - return b; + return av_add_q(b, (AVRational){-c.num, c.den}); } /** @@ -102,7 +100,8 @@ AVRational av_sub_q(AVRational b, AVRational c){ */ AVRational av_d2q(double d, int max){ AVRational a; - int exponent= FFMAX( (int)(log(ABS(d) + 1e-20)/log(2)), 0); +#define LOG2 0.69314718055994530941723212145817656807550013436025 + int exponent= FFMAX( (int)(log(fabs(d) + 1e-20)/LOG2), 0); int64_t den= 1LL << (61 - exponent); av_reduce(&a.num, &a.den, (int64_t)(d * den + 0.5), den, max); diff --git a/src/libffmpeg/libavutil/rational.h b/src/libffmpeg/libavutil/rational.h index e4bfe5f7a..0fbe0d29d 100644 --- a/src/libffmpeg/libavutil/rational.h +++ b/src/libffmpeg/libavutil/rational.h @@ -14,10 +14,10 @@ * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ - + /** * @file rational.h * Rational numbers. |