summaryrefslogtreecommitdiff
path: root/src/libffmpeg/libavutil
diff options
context:
space:
mode:
Diffstat (limited to 'src/libffmpeg/libavutil')
-rw-r--r--src/libffmpeg/libavutil/avutil.h34
-rw-r--r--src/libffmpeg/libavutil/bswap.h155
-rw-r--r--src/libffmpeg/libavutil/common.h588
-rw-r--r--src/libffmpeg/libavutil/integer.h47
-rw-r--r--src/libffmpeg/libavutil/intfloat_readwrite.h11
-rw-r--r--src/libffmpeg/libavutil/mathematics.c84
-rw-r--r--src/libffmpeg/libavutil/mathematics.h31
-rw-r--r--src/libffmpeg/libavutil/rational.c110
-rw-r--r--src/libffmpeg/libavutil/rational.h69
9 files changed, 1129 insertions, 0 deletions
diff --git a/src/libffmpeg/libavutil/avutil.h b/src/libffmpeg/libavutil/avutil.h
new file mode 100644
index 000000000..b9f930a56
--- /dev/null
+++ b/src/libffmpeg/libavutil/avutil.h
@@ -0,0 +1,34 @@
+#ifndef AVUTIL_H
+#define AVUTIL_H
+
+/**
+ * @file avutil.h
+ * external api header.
+ */
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#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_IDENT "Lavu" AV_STRINGIFY(LIBAVUTIL_VERSION)
+
+
+#include "common.h"
+#include "mathematics.h"
+#include "rational.h"
+#include "integer.h"
+#include "intfloat_readwrite.h"
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* AVUTIL_H */
diff --git a/src/libffmpeg/libavutil/bswap.h b/src/libffmpeg/libavutil/bswap.h
new file mode 100644
index 000000000..50fd57178
--- /dev/null
+++ b/src/libffmpeg/libavutil/bswap.h
@@ -0,0 +1,155 @@
+/**
+ * @file bswap.h
+ * byte swap.
+ */
+
+#ifndef __BSWAP_H__
+#define __BSWAP_H__
+
+#ifdef HAVE_BYTESWAP_H
+#include <byteswap.h>
+#else
+
+#ifdef ARCH_X86_64
+# define LEGACY_REGS "=Q"
+#else
+# define LEGACY_REGS "=q"
+#endif
+
+#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) :
+ "0" (x));
+ return x;
+}
+
+static always_inline uint32_t bswap_32(uint32_t x)
+{
+#if __CPU__ > 386
+ __asm("bswap %0":
+ "=r" (x) :
+#else
+ __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
+}
+
+#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;
+}
+
+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;
+}
+
+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 always_inline uint16_t bswap_16(uint16_t x){
+ return (x>>8) | (x<<8);
+}
+
+#ifdef ARCH_ARM
+static always_inline uint32_t bswap_32(uint32_t x){
+ 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;
+}
+#else
+static always_inline uint32_t bswap_32(uint32_t x){
+ x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);
+ return (x>>16) | (x<<16);
+}
+#endif
+
+static inline uint64_t bswap_64(uint64_t x)
+{
+#if 0
+ x= ((x<< 8)&0xFF00FF00FF00FF00ULL) | ((x>> 8)&0x00FF00FF00FF00FFULL);
+ x= ((x<<16)&0xFFFF0000FFFF0000ULL) | ((x>>16)&0x0000FFFF0000FFFFULL);
+ return (x>>32) | (x<<32);
+#else
+ union {
+ uint64_t ll;
+ uint32_t l[2];
+ } w, r;
+ w.ll = x;
+ r.l[0] = bswap_32 (w.l[1]);
+ r.l[1] = bswap_32 (w.l[0]);
+ return r.ll;
+#endif
+}
+#endif /* !ARCH_X86 */
+
+#endif /* !HAVE_BYTESWAP_H */
+
+// be2me ... BigEndian to MachineEndian
+// le2me ... LittleEndian to MachineEndian
+
+#ifdef WORDS_BIGENDIAN
+#define be2me_16(x) (x)
+#define be2me_32(x) (x)
+#define be2me_64(x) (x)
+#define le2me_16(x) bswap_16(x)
+#define le2me_32(x) bswap_32(x)
+#define le2me_64(x) bswap_64(x)
+#else
+#define be2me_16(x) bswap_16(x)
+#define be2me_32(x) bswap_32(x)
+#define be2me_64(x) bswap_64(x)
+#define le2me_16(x) (x)
+#define le2me_32(x) (x)
+#define le2me_64(x) (x)
+#endif
+
+#endif /* __BSWAP_H__ */
diff --git a/src/libffmpeg/libavutil/common.h b/src/libffmpeg/libavutil/common.h
new file mode 100644
index 000000000..4bf8cacbe
--- /dev/null
+++ b/src/libffmpeg/libavutil/common.h
@@ -0,0 +1,588 @@
+/**
+ * @file common.h
+ * common internal api header.
+ */
+
+#ifndef COMMON_H
+#define COMMON_H
+
+/* xine: disable DEBUG for ffmpeg (too noisy) */
+#ifdef DEBUG
+#undef DEBUG
+#endif
+
+#if defined(WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__)
+# define CONFIG_WIN32
+#endif
+
+#ifndef M_PI
+#define M_PI 3.14159265358979323846
+#endif
+
+#ifdef HAVE_AV_CONFIG_H
+/* only include the following when compiling package */
+# include "config.h"
+
+# include <stdlib.h>
+# include <stdio.h>
+# include <string.h>
+# include <ctype.h>
+# include <limits.h>
+# ifndef __BEOS__
+# include <errno.h>
+# else
+# 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. */
+#ifndef restrict
+# define restrict
+#endif
+
+#ifndef always_inline
+#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
+# define always_inline __attribute__((always_inline)) inline
+#else
+# define always_inline inline
+#endif
+#endif
+
+#ifndef attribute_used
+#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
+# define attribute_used __attribute__((used))
+#else
+# define attribute_used
+#endif
+#endif
+
+#ifndef attribute_unused
+#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
+# define attribute_unused __attribute__((unused))
+#else
+# define attribute_unused
+#endif
+#endif
+
+#ifndef EMULATE_INTTYPES
+# include <inttypes.h>
+#else
+ typedef signed char int8_t;
+ typedef signed short int16_t;
+ typedef signed int int32_t;
+ 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 */
+#endif /* EMULATE_INTTYPES */
+
+#ifndef INT16_MIN
+#define INT16_MIN (-0x7fff-1)
+#endif
+
+#ifndef INT16_MAX
+#define INT16_MAX 0x7fff
+#endif
+
+#ifndef INT64_MIN
+#define INT64_MIN (-0x7fffffffffffffffLL-1)
+#endif
+
+#ifndef INT64_MAX
+#define INT64_MAX int64_t_C(9223372036854775807)
+#endif
+
+#ifndef UINT64_MAX
+#define UINT64_MAX uint64_t_C(0xFFFFFFFFFFFFFFFF)
+#endif
+
+#ifdef EMULATE_FAST_INT
+typedef signed char int_fast8_t;
+typedef signed int int_fast16_t;
+typedef signed int int_fast32_t;
+typedef unsigned char uint_fast8_t;
+typedef unsigned int uint_fast16_t;
+typedef unsigned int uint_fast32_t;
+typedef uint64_t uint_fast64_t;
+#endif
+
+#ifndef INT_BIT
+# if INT_MAX != 2147483647
+# define INT_BIT 64
+# else
+# define INT_BIT 32
+# 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 */
+#else
+
+/* unix */
+
+#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 /* 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)
+
+//rounded divison & shift
+#define RSHIFT(a,b) ((a) > 0 ? ((a) + ((1<<(b))>>1))>>(b) : ((a) + ((1<<(b))>>1)-1)>>(b))
+/* assume b>0 */
+#define ROUNDED_DIV(a,b) (((a)>0 ? (a) + ((b)>>1) : (a) - ((b)>>1))/(b))
+#define ABS(a) ((a) >= 0 ? (a) : (-(a)))
+
+#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];
+
+static inline int av_log2(unsigned int v)
+{
+ int n;
+
+ n = 0;
+ if (v & 0xffff0000) {
+ v >>= 16;
+ n += 16;
+ }
+ if (v & 0xff00) {
+ v >>= 8;
+ n += 8;
+ }
+ n += ff_log2_tab[v];
+
+ return n;
+}
+
+static inline int av_log2_16bit(unsigned int v)
+{
+ int n;
+
+ n = 0;
+ if (v & 0xff00) {
+ v >>= 8;
+ n += 8;
+ }
+ n += ff_log2_tab[v];
+
+ return n;
+}
+
+/* median of 3 */
+static inline int mid_pred(int a, int b, int c)
+{
+#if 0
+ int t= (a-b)&((a-b)>>31);
+ a-=t;
+ b+=t;
+ b-= (b-c)&((b-c)>>31);
+ b+= (a-b)&((a-b)>>31);
+
+ return b;
+#else
+ if(a>b){
+ if(c>b){
+ if(c>a) b=a;
+ else b=c;
+ }
+ }else{
+ if(b>c){
+ if(c>a) b=c;
+ else b=a;
+ }
+ }
+ return b;
+#endif
+}
+
+static inline int clip(int a, int amin, int amax)
+{
+ if (a < amin)
+ return amin;
+ else if (a > amax)
+ return amax;
+ else
+ return a;
+}
+
+static inline int 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){
+ assert( strlen(s)==4 );
+
+ return (s[0]) + (s[1]<<8) + (s[2]<<16) + (s[3]<<24);
+}
+
+#define MKTAG(a,b,c,d) (a | (b << 8) | (c << 16) | (d << 24))
+#define MKBETAG(a,b,c,d) (d | (c << 8) | (b << 16) | (a << 24))
+
+
+#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
+
+#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);
+}
+#elif defined(ARCH_X86)
+static inline long long read_time(void)
+{
+ long long l;
+ asm volatile( "rdtsc\n\t"
+ : "=A" (l)
+ );
+ return l;
+}
+#else //FIXME check ppc64
+static inline uint64_t read_time(void)
+{
+ uint32_t tbu, tbl, temp;
+
+ /* from section 2.2.1 of the 32-bit PowerPC PEM */
+ __asm__ __volatile__(
+ "1:\n"
+ "mftbu %2\n"
+ "mftb %0\n"
+ "mftbu %1\n"
+ "cmpw %2,%1\n"
+ "bne 1b\n"
+ : "=r"(tbl), "=r"(tbu), "=r"(temp)
+ :
+ : "cc");
+
+ return (((uint64_t)tbu)<<32) | (uint64_t)tbl;
+}
+#endif
+
+#define START_TIMER \
+uint64_t tend;\
+uint64_t tstart= read_time();\
+
+#define STOP_TIMER(id) \
+tend= read_time();\
+{\
+ static uint64_t tsum=0;\
+ static int tcount=0;\
+ static int tskip_count=0;\
+ if(tcount<2 || tend - tstart < 8*tsum/tcount){\
+ tsum+= tend - tstart;\
+ tcount++;\
+ }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);\
+ }\
+}
+#else
+#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
+#define sprintf sprintf_is_forbidden_due_to_security_issues_use_snprintf
+#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 */
+
+#endif /* COMMON_H */
diff --git a/src/libffmpeg/libavutil/integer.h b/src/libffmpeg/libavutil/integer.h
new file mode 100644
index 000000000..ef1b2a089
--- /dev/null
+++ b/src/libffmpeg/libavutil/integer.h
@@ -0,0 +1,47 @@
+/*
+ * arbitrary precision integers
+ * Copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This library 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 of the License, or (at your option) any later version.
+ *
+ * This library 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 this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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];
+} AVInteger;
+
+AVInteger av_add_i(AVInteger a, AVInteger b);
+AVInteger av_sub_i(AVInteger a, AVInteger b);
+int av_log2_i(AVInteger a);
+AVInteger av_mul_i(AVInteger a, AVInteger b);
+int av_cmp_i(AVInteger a, AVInteger b);
+AVInteger av_shr_i(AVInteger a, int s);
+AVInteger av_mod_i(AVInteger *quot, AVInteger a, AVInteger b);
+AVInteger av_div_i(AVInteger a, AVInteger b);
+AVInteger av_int2i(int64_t a);
+int64_t av_i2int(AVInteger a);
+
+#endif // INTEGER_H
diff --git a/src/libffmpeg/libavutil/intfloat_readwrite.h b/src/libffmpeg/libavutil/intfloat_readwrite.h
new file mode 100644
index 000000000..22f40bb66
--- /dev/null
+++ b/src/libffmpeg/libavutil/intfloat_readwrite.h
@@ -0,0 +1,11 @@
+#ifndef INTFLOAT_READWRITE_H
+#define INTFLOAT_READWRITE_H
+
+#include "common.h"
+
+double av_int2dbl(int64_t v);
+float av_int2flt(int32_t v);
+int64_t av_dbl2int(double d);
+int32_t av_flt2int(float d);
+
+#endif /* INTFLOAT_READWRITE_H */
diff --git a/src/libffmpeg/libavutil/mathematics.c b/src/libffmpeg/libavutil/mathematics.c
new file mode 100644
index 000000000..aa3fd74e0
--- /dev/null
+++ b/src/libffmpeg/libavutil/mathematics.c
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 2005 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This library 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 of the License, or (at your option) any later version.
+ *
+ * This library 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 this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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]={
+ 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_log2_tab[256]={
+ 0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
+ 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+ 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
+ 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,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,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,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,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,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
+};
+
+int64_t ff_gcd(int64_t a, int64_t b){
+ if(b) return ff_gcd(b, a%b);
+ else return a;
+}
+
+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(rnd==AV_ROUND_NEAR_INF) r= c/2;
+ else if(rnd&1) r= c-1;
+
+ if(b<=INT_MAX && c<=INT_MAX){
+ if(a<=INT_MAX)
+ return (a * b + r)/c;
+ else
+ return a/c*b + (a%c*b + r)/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)));
+}
+
+int64_t av_rescale(int64_t a, int64_t b, int64_t c){
+ return av_rescale_rnd(a, b, c, AV_ROUND_NEAR_INF);
+}
+
+int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq){
+ int64_t b= bq.num * (int64_t)cq.den;
+ int64_t c= cq.num * (int64_t)bq.den;
+ return av_rescale_rnd(a, b, c, AV_ROUND_NEAR_INF);
+}
diff --git a/src/libffmpeg/libavutil/mathematics.h b/src/libffmpeg/libavutil/mathematics.h
new file mode 100644
index 000000000..0cf726cbe
--- /dev/null
+++ b/src/libffmpeg/libavutil/mathematics.h
@@ -0,0 +1,31 @@
+#ifndef MATHEMATICS_H
+#define MATHEMATICS_H
+
+#include "rational.h"
+
+enum AVRounding {
+ AV_ROUND_ZERO = 0, ///< round toward zero
+ AV_ROUND_INF = 1, ///< round away from zero
+ AV_ROUND_DOWN = 2, ///< round toward -infinity
+ AV_ROUND_UP = 3, ///< round toward +infinity
+ AV_ROUND_NEAR_INF = 5, ///< round to nearest and halfway cases away from zero
+};
+
+/**
+ * rescale a 64bit integer with rounding to nearest.
+ * a simple a*b/c isn't possible as it can overflow
+ */
+int64_t av_rescale(int64_t a, int64_t b, int64_t c);
+
+/**
+ * rescale a 64bit integer with specified rounding.
+ * a simple a*b/c isn't possible as it can overflow
+ */
+int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding);
+
+/**
+ * rescale a 64bit integer by 2 rational numbers.
+ */
+int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq);
+
+#endif /* MATHEMATICS_H */
diff --git a/src/libffmpeg/libavutil/rational.c b/src/libffmpeg/libavutil/rational.c
new file mode 100644
index 000000000..104499929
--- /dev/null
+++ b/src/libffmpeg/libavutil/rational.c
@@ -0,0 +1,110 @@
+/*
+ * Rational numbers
+ * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This library 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 of the License, or (at your option) any later version.
+ *
+ * This library 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 this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+/**
+ * @file rational.c
+ * Rational numbers
+ * @author Michael Niedermayer <michaelni@gmx.at>
+ */
+
+//#include <math.h>
+#include <limits.h>
+
+#include "common.h"
+#include "mathematics.h"
+#include "rational.h"
+
+int av_reduce(int *dst_nom, int *dst_den, int64_t nom, int64_t den, int64_t max){
+ AVRational a0={0,1}, a1={1,0};
+ int sign= (nom<0) ^ (den<0);
+ int64_t gcd= ff_gcd(ABS(nom), ABS(den));
+
+ nom = ABS(nom)/gcd;
+ den = ABS(den)/gcd;
+ if(nom<=max && den<=max){
+ a1= (AVRational){nom, den};
+ den=0;
+ }
+
+ while(den){
+ int64_t x = nom / den;
+ int64_t next_den= nom - den*x;
+ int64_t a2n= x*a1.num + a0.num;
+ int64_t a2d= x*a1.den + a0.den;
+
+ if(a2n > max || a2d > max) break;
+
+ a0= a1;
+ a1= (AVRational){a2n, a2d};
+ nom= den;
+ 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;
+}
+
+/**
+ * returns b*c.
+ */
+AVRational av_mul_q(AVRational b, AVRational c){
+ av_reduce(&b.num, &b.den, b.num * (int64_t)c.num, b.den * (int64_t)c.den, INT_MAX);
+ return b;
+}
+
+/**
+ * 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;
+}
+
+/**
+ * returns b+c.
+ */
+AVRational av_add_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;
+}
+
+/**
+ * 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;
+}
+
+/**
+ * Converts a double precission floating point number to a AVRational.
+ * @param max the maximum allowed numerator and denominator
+ */
+AVRational av_d2q(double d, int max){
+ AVRational a;
+ int exponent= FFMAX( (int)(log(ABS(d) + 1e-20)/log(2)), 0);
+ int64_t den= 1LL << (61 - exponent);
+ av_reduce(&a.num, &a.den, (int64_t)(d * den + 0.5), den, max);
+
+ return a;
+}
diff --git a/src/libffmpeg/libavutil/rational.h b/src/libffmpeg/libavutil/rational.h
new file mode 100644
index 000000000..e4bfe5f7a
--- /dev/null
+++ b/src/libffmpeg/libavutil/rational.h
@@ -0,0 +1,69 @@
+/*
+ * Rational numbers
+ * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This library 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 of the License, or (at your option) any later version.
+ *
+ * This library 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 this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+/**
+ * @file rational.h
+ * Rational numbers.
+ * @author Michael Niedermayer <michaelni@gmx.at>
+ */
+
+#ifndef RATIONAL_H
+#define RATIONAL_H
+
+/**
+ * Rational number num/den.
+ */
+typedef struct AVRational{
+ int num; ///< numerator
+ int den; ///< denominator
+} AVRational;
+
+/**
+ * returns 0 if a==b, 1 if a>b and -1 if a<b.
+ */
+static inline int av_cmp_q(AVRational a, AVRational b){
+ const int64_t tmp= a.num * (int64_t)b.den - b.num * (int64_t)a.den;
+
+ if(tmp) return (tmp>>63)|1;
+ else return 0;
+}
+
+/**
+ * converts the given AVRational to a double.
+ */
+static inline double av_q2d(AVRational a){
+ return a.num / (double) a.den;
+}
+
+/**
+ * reduce a fraction.
+ * this is usefull for framerate calculations
+ * @param max the maximum allowed for dst_nom & dst_den
+ * @return 1 if exact, 0 otherwise
+ */
+int av_reduce(int *dst_nom, int *dst_den, int64_t nom, int64_t den, int64_t max);
+
+AVRational av_mul_q(AVRational b, AVRational c);
+AVRational av_div_q(AVRational b, AVRational c);
+AVRational av_add_q(AVRational b, AVRational c);
+AVRational av_sub_q(AVRational b, AVRational c);
+AVRational av_d2q(double d, int max);
+
+#endif // RATIONAL_H