diff options
-rw-r--r-- | Makefile | 8 | ||||
-rw-r--r-- | libavcodec/Makefile | 15 | ||||
-rw-r--r-- | libavcodec/avcodec.h | 45 | ||||
-rw-r--r-- | libavcodec/i386/fdct_mmx.c | 2 | ||||
-rw-r--r-- | libavcodec/i386/idct_mmx.c | 2 | ||||
-rw-r--r-- | libavcodec/utils.c | 119 | ||||
-rw-r--r-- | libavformat/Makefile | 2 | ||||
-rw-r--r-- | libavutil/Makefile | 92 | ||||
-rw-r--r-- | libavutil/avutil.h | 34 | ||||
-rw-r--r-- | libavutil/bswap.h (renamed from libavcodec/bswap.h) | 0 | ||||
-rw-r--r-- | libavutil/common.h (renamed from libavcodec/common.h) | 0 | ||||
-rw-r--r-- | libavutil/integer.c (renamed from libavcodec/integer.c) | 0 | ||||
-rw-r--r-- | libavutil/integer.h (renamed from libavcodec/integer.h) | 0 | ||||
-rw-r--r-- | libavutil/intfloat_readwrite.c | 54 | ||||
-rw-r--r-- | libavutil/intfloat_readwrite.h | 11 | ||||
-rw-r--r-- | libavutil/mathematics.c | 84 | ||||
-rw-r--r-- | libavutil/mathematics.h | 31 | ||||
-rw-r--r-- | libavutil/rational.c (renamed from libavcodec/rational.c) | 35 | ||||
-rw-r--r-- | libavutil/rational.h (renamed from libavcodec/rational.h) | 8 | ||||
-rw-r--r-- | vhook/Makefile | 2 |
20 files changed, 369 insertions, 175 deletions
@@ -6,7 +6,7 @@ include config.mak VPATH=$(SRC_PATH) -CFLAGS=$(OPTFLAGS) -I. -I$(SRC_PATH) -I$(SRC_PATH)/libavcodec -I$(SRC_PATH)/libavformat -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE +CFLAGS=$(OPTFLAGS) -I. -I$(SRC_PATH) -I$(SRC_PATH)/libavutil -I$(SRC_PATH)/libavcodec -I$(SRC_PATH)/libavformat -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE LDFLAGS+= -g ifeq ($(TARGET_GPROF),yes) @@ -91,11 +91,12 @@ endif OBJS = ffmpeg.o ffserver.o cmdutils.o $(FFPLAY_O) SRCS = $(OBJS:.o=.c) $(ASM_OBJS:.o=.s) -FFLIBS = -L./libavformat -lavformat$(BUILDSUF) -L./libavcodec -lavcodec$(BUILDSUF) +FFLIBS = -L./libavformat -lavformat$(BUILDSUF) -L./libavcodec -lavcodec$(BUILDSUF) -L./libavutil -lavutil$(BUILDSUF) all: lib $(PROG) $(PROGTEST) $(VHOOK) $(QTFASTSTART) $(DOC) lib: + $(MAKE) -C libavutil all $(MAKE) -C libavcodec all $(MAKE) -C libavformat all @@ -140,6 +141,7 @@ documentation: .PHONY: install install: all install-man $(INSTALLVHOOK) + $(MAKE) -C libavutil install $(MAKE) -C libavcodec install $(MAKE) -C libavformat install install -d "$(bindir)" @@ -162,6 +164,7 @@ install-vhook: $(MAKE) -C vhook install installlib: + $(MAKE) -C libavutil installlib $(MAKE) -C libavcodec installlib $(MAKE) -C libavformat installlib @@ -182,6 +185,7 @@ endif @for i in $(DEP_LIBS) ; do if $(TEST) $$i -nt .libs ; then touch .libs; fi ; done clean: $(CLEANVHOOK) + $(MAKE) -C libavutil clean $(MAKE) -C libavcodec clean $(MAKE) -C libavformat clean $(MAKE) -C tests clean diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 086c28b..05d2955 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -7,7 +7,7 @@ include ../config.mak VPATH=$(SRC_PATH)/libavcodec # NOTE: -I.. is needed to include config.h -CFLAGS=$(OPTFLAGS) -DHAVE_AV_CONFIG_H -I.. -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE $(AMR_CFLAGS) +CFLAGS=$(OPTFLAGS) -DHAVE_AV_CONFIG_H -I.. -I$(SRC_PATH)/libavutil -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE $(AMR_CFLAGS) OBJS= bitstream.o utils.o mem.o allcodecs.o \ mpegvideo.o jrevdct.o jfdctfst.o jfdctint.o\ @@ -16,8 +16,8 @@ OBJS= bitstream.o utils.o mem.o allcodecs.o \ mpeg12.o mpegaudiodec.o pcm.o simple_idct.o \ ratecontrol.o adpcm.o eval.o error_resilience.o \ fft.o mdct.o raw.o golomb.o cabac.o\ - dpcm.o adx.o rational.o faandct.o parser.o g726.o \ - vp3dsp.o integer.o h264idct.o rangecoder.o pnm.o h263.o msmpeg4.o h263dec.o dvdsub.o dvbsub.o dvbsubdec.o + dpcm.o adx.o faandct.o parser.o g726.o \ + vp3dsp.o h264idct.o rangecoder.o pnm.o h263.o msmpeg4.o h263dec.o dvdsub.o dvbsub.o dvbsubdec.o ifeq ($(CONFIG_AASC_DECODER),yes) OBJS+= aasc.o @@ -234,6 +234,8 @@ OBJS+= liba52/bit_allocate.o liba52/bitstream.o liba52/downmix.o \ endif endif +EXTRALIBS += -L$(SRC_PATH)/libavutil -lavutil$(BUILDSUF) + # currently using libdts for dts decoding ifeq ($(CONFIG_DTS),yes) OBJS+= dtsdec.o @@ -375,6 +377,7 @@ SRCS := $(OBJS:.o=.c) $(ASM_OBJS:.o=.S) OBJS := $(OBJS) $(ASM_OBJS) LIB= $(LIBPREF)avcodec$(LIBSUF) +LIBAVUTIL= $(SRC_PATH)/libavutil/$(LIBPREF)avutil$(LIBSUF) ifeq ($(BUILD_SHARED),yes) SLIB= $(SLIBPREF)avcodec$(SLIBSUF) endif @@ -446,7 +449,7 @@ cleanamrwbfloat: # api example program apiexample: apiexample.c $(LIB) - $(CC) $(CFLAGS) -o $@ $< $(LIB) $(EXTRALIBS) -lm + $(CC) $(CFLAGS) -o $@ $< $(LIB) $(LIBAVUTIL) $(EXTRALIBS) -lm # cpuid test cpuid_test: i386/cputest.c @@ -464,7 +467,7 @@ motion-test: motion_test.o $(LIB) $(CC) -o $@ $^ -lm fft-test: fft-test.o $(LIB) - $(CC) -o $@ $^ -lm + $(CC) -o $@ $^ $(LIBAVUTIL) -lm ifeq ($(BUILD_SHARED),yes) install: all install-headers @@ -489,8 +492,6 @@ installlib: all install-headers install-headers: mkdir -p "$(prefix)/include/ffmpeg" install -m 644 $(SRC_PATH)/libavcodec/avcodec.h \ - $(SRC_PATH)/libavcodec/common.h \ - $(SRC_PATH)/libavcodec/rational.h \ "$(prefix)/include/ffmpeg" install -d $(libdir)/pkgconfig install -m 644 ../libavcodec.pc $(libdir)/pkgconfig diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index bccfe67..d3ed1a7 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -11,8 +11,7 @@ extern "C" { #endif -#include "common.h" -#include "rational.h" +#include "avutil.h" #include <sys/types.h> /* size_t */ //FIXME the following 2 really dont belong in here @@ -22,8 +21,8 @@ extern "C" { #define AV_STRINGIFY(s) AV_TOSTRING(s) #define AV_TOSTRING(s) #s -#define LIBAVCODEC_VERSION_INT ((49<<16)+(0<<8)+0) -#define LIBAVCODEC_VERSION 49.0.0 +#define LIBAVCODEC_VERSION_INT ((49<<16)+(0<<8)+1) +#define LIBAVCODEC_VERSION 49.0.1 #define LIBAVCODEC_BUILD LIBAVCODEC_VERSION_INT #define LIBAVCODEC_IDENT "Lavc" AV_STRINGIFY(LIBAVCODEC_VERSION) @@ -279,14 +278,6 @@ enum Motion_Est_ID { ME_X1 }; -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 -}; - enum AVDiscard{ //we leave some space between them for extensions (drop some keyframes for intra only or drop just some bidir frames) AVDISCARD_NONE =-16, ///< discard nothing @@ -2308,36 +2299,6 @@ void avcodec_default_free_buffers(AVCodecContext *s); */ char av_get_pict_type_char(int pict_type); -/** - * 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); - -/** - * 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); - -double av_int2dbl(int64_t v); -float av_int2flt(int32_t v); -int64_t av_dbl2int(double d); -int32_t av_flt2int(float d); - /* frame parsing */ typedef struct AVCodecParserContext { diff --git a/libavcodec/i386/fdct_mmx.c b/libavcodec/i386/fdct_mmx.c index aacbe57..6a13090 100644 --- a/libavcodec/i386/fdct_mmx.c +++ b/libavcodec/i386/fdct_mmx.c @@ -13,7 +13,7 @@ * a page about fdct at http://www.geocities.com/ssavekar/dct.htm * Skal's fdct at http://skal.planet-d.net/coding/dct.html */ -#include "../common.h" +#include "common.h" #include "../dsputil.h" #include "mmx.h" diff --git a/libavcodec/i386/idct_mmx.c b/libavcodec/i386/idct_mmx.c index d9586ef..355feac 100644 --- a/libavcodec/i386/idct_mmx.c +++ b/libavcodec/i386/idct_mmx.c @@ -22,7 +22,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "../common.h" +#include "common.h" #include "../dsputil.h" #include "mmx.h" diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 2d3aded..1b2cd21 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -31,24 +31,6 @@ #include <stdarg.h> #include <limits.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 -}; - const uint8_t ff_reverse[256]={ 0x00,0x80,0x40,0xC0,0x20,0xA0,0x60,0xE0,0x10,0x90,0x50,0xD0,0x30,0xB0,0x70,0xF0, 0x08,0x88,0x48,0xC8,0x28,0xA8,0x68,0xE8,0x18,0x98,0x58,0xD8,0x38,0xB8,0x78,0xF8, @@ -938,107 +920,6 @@ char av_get_pict_type_char(int pict_type){ } } -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; -} - -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); -} - -int64_t ff_gcd(int64_t a, int64_t b){ - if(b) return ff_gcd(b, a%b); - else return a; -} - -double av_int2dbl(int64_t v){ - if(v+v > 0xFFELLU<<52) - return 0.0/0.0; - return ldexp(((v&(1LL<<52)-1) + (1LL<<52)) * (v>>63|1), (v>>52&0x7FF)-1075); -} - -float av_int2flt(int32_t v){ - if(v+v > 0xFF000000U) - return 0.0/0.0; - return ldexp(((v&0x7FFFFF) + (1<<23)) * (v>>31|1), (v>>23&0xFF)-150); -} - -int64_t av_dbl2int(double d){ - int e; - if ( !d) return 0; - else if(d-d) return 0x7FF0000000000000LL + ((int64_t)(d<0)<<63) + (d!=d); - d= frexp(d, &e); - return (int64_t)(d<0)<<63 | (e+1022LL)<<52 | (int64_t)((fabs(d)-0.5)*(1LL<<53)); -} - -int32_t av_flt2int(float d){ - int e; - if ( !d) return 0; - else if(d-d) return 0x7F800000 + ((d<0)<<31) + (d!=d); - d= frexp(d, &e); - return (d<0)<<31 | (e+126)<<23 | (int64_t)((fabs(d)-0.5)*(1<<24)); -} - /* av_log API */ static int av_log_level = AV_LOG_INFO; diff --git a/libavformat/Makefile b/libavformat/Makefile index 5f74b3c..80c2f87 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -6,7 +6,7 @@ include ../config.mak VPATH=$(SRC_PATH)/libavformat -CFLAGS=$(OPTFLAGS) -I.. -I$(SRC_PATH) -I$(SRC_PATH)/libavcodec -DHAVE_AV_CONFIG_H -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE +CFLAGS=$(OPTFLAGS) -I.. -I$(SRC_PATH) -I$(SRC_PATH)/libavutil -I$(SRC_PATH)/libavcodec -DHAVE_AV_CONFIG_H -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE OBJS= utils.o cutils.o os_support.o allformats.o PPOBJS= diff --git a/libavutil/Makefile b/libavutil/Makefile new file mode 100644 index 0000000..1dd01c9 --- /dev/null +++ b/libavutil/Makefile @@ -0,0 +1,92 @@ +# +# libavutil Makefile +# +include ../config.mak + +VPATH=$(SRC_PATH)/libavutil + +# NOTE: -I.. is needed to include config.h +CFLAGS=$(OPTFLAGS) -DHAVE_AV_CONFIG_H -I.. -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE + +OBJS= mathematics.o \ + integer.o \ + rational.o \ + intfloat_readwrite.o \ + + +ifeq ($(TARGET_ARCH_SPARC64),yes) +CFLAGS+= -mcpu=ultrasparc -mtune=ultrasparc +endif + +SRCS := $(OBJS:.o=.c) + +LIB= $(LIBPREF)avutil$(LIBSUF) +ifeq ($(BUILD_SHARED),yes) +SLIB= $(SLIBPREF)avutil$(SLIBSUF) +endif + +all: $(LIB) $(SLIB) + +$(LIB): $(OBJS) + rm -f $@ + $(AR) rc $@ $(OBJS) + $(RANLIB) $@ + +$(SLIB): $(OBJS) +ifeq ($(CONFIG_WIN32),yes) + $(CC) $(SHFLAGS) -Wl,--output-def,$(@:.dll=.def) -o $@ $(OBJS) $(EXTRALIBS) $(AMREXTRALIBS) + -lib /machine:i386 /def:$(@:.dll=.def) +else + $(CC) $(SHFLAGS) -o $@ $(OBJS) $(EXTRALIBS) $(AMREXTRALIBS) $(LDFLAGS) +endif + +%.o: %.c + $(CC) $(CFLAGS) $(LIBOBJFLAGS) -c -o $@ $< + +depend: $(SRCS) + $(CC) -MM $(CFLAGS) $^ 1>.depend + +dep: depend + +clean: + rm -f *.o *.d *~ .depend $(LIB) $(SLIB) *.so + +distclean: clean + rm -f Makefile.bak .depend + + +ifeq ($(BUILD_SHARED),yes) +install: all install-headers +ifeq ($(CONFIG_WIN32),yes) + install $(INSTALLSTRIP) -m 755 $(SLIB) "$(prefix)" +else + install -d $(libdir) + install $(INSTALLSTRIP) -m 755 $(SLIB) $(libdir)/libavutil-$(VERSION).so + ln -sf libavutil-$(VERSION).so $(libdir)/libavutil.so + $(LDCONFIG) || true +endif +else +install: +endif + +installlib: all install-headers + install -m 644 $(LIB) "$(libdir)" + +install-headers: + mkdir -p "$(prefix)/include/ffmpeg" + install -m 644 $(SRC_PATH)/libavutil/avutil.h \ + $(SRC_PATH)/libavutil/common.h \ + $(SRC_PATH)/libavutil/mathematics.h \ + $(SRC_PATH)/libavutil/integer.h \ + $(SRC_PATH)/libavutil/rational.h \ + $(SRC_PATH)/libavutil/intfloat_readwrite.h \ + "$(prefix)/include/ffmpeg" +# install -d $(libdir)/pkgconfig +# install -m 644 ../libavutil.pc $(libdir)/pkgconfig + +# +# include dependency files if they exist +# +ifneq ($(wildcard .depend),) +include .depend +endif diff --git a/libavutil/avutil.h b/libavutil/avutil.h new file mode 100644 index 0000000..b9f930a --- /dev/null +++ b/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/libavcodec/bswap.h b/libavutil/bswap.h index 50fd571..50fd571 100644 --- a/libavcodec/bswap.h +++ b/libavutil/bswap.h diff --git a/libavcodec/common.h b/libavutil/common.h index 7d5edb4..7d5edb4 100644 --- a/libavcodec/common.h +++ b/libavutil/common.h diff --git a/libavcodec/integer.c b/libavutil/integer.c index 38a826f..38a826f 100644 --- a/libavcodec/integer.c +++ b/libavutil/integer.c diff --git a/libavcodec/integer.h b/libavutil/integer.h index ef1b2a0..ef1b2a0 100644 --- a/libavcodec/integer.h +++ b/libavutil/integer.h diff --git a/libavutil/intfloat_readwrite.c b/libavutil/intfloat_readwrite.c new file mode 100644 index 0000000..cf4d495 --- /dev/null +++ b/libavutil/intfloat_readwrite.c @@ -0,0 +1,54 @@ +/* + * portable IEEE float/double read/write functions + * + * 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 intfloat_readwrite.c + * Portable IEEE float/double read/write functions. + */ + +#include "common.h" + +double av_int2dbl(int64_t v){ + if(v+v > 0xFFELLU<<52) + return 0.0/0.0; + return ldexp(((v&(1LL<<52)-1) + (1LL<<52)) * (v>>63|1), (v>>52&0x7FF)-1075); +} + +float av_int2flt(int32_t v){ + if(v+v > 0xFF000000U) + return 0.0/0.0; + return ldexp(((v&0x7FFFFF) + (1<<23)) * (v>>31|1), (v>>23&0xFF)-150); +} + +int64_t av_dbl2int(double d){ + int e; + if ( !d) return 0; + else if(d-d) return 0x7FF0000000000000LL + ((int64_t)(d<0)<<63) + (d!=d); + d= frexp(d, &e); + return (int64_t)(d<0)<<63 | (e+1022LL)<<52 | (int64_t)((fabs(d)-0.5)*(1LL<<53)); +} + +int32_t av_flt2int(float d){ + int e; + if ( !d) return 0; + else if(d-d) return 0x7F800000 + ((d<0)<<31) + (d!=d); + d= frexp(d, &e); + return (d<0)<<31 | (e+126)<<23 | (int64_t)((fabs(d)-0.5)*(1<<24)); +} diff --git a/libavutil/intfloat_readwrite.h b/libavutil/intfloat_readwrite.h new file mode 100644 index 0000000..22f40bb --- /dev/null +++ b/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/libavutil/mathematics.c b/libavutil/mathematics.c new file mode 100644 index 0000000..aa3fd74 --- /dev/null +++ b/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/libavutil/mathematics.h b/libavutil/mathematics.h new file mode 100644 index 0000000..0cf726c --- /dev/null +++ b/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/libavcodec/rational.c b/libavutil/rational.c index 7ccad9e..1044999 100644 --- a/libavcodec/rational.c +++ b/libavutil/rational.c @@ -28,9 +28,42 @@ #include <limits.h> #include "common.h" -#include "avcodec.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. */ diff --git a/libavcodec/rational.h b/libavutil/rational.h index fcda759..e4bfe5f 100644 --- a/libavcodec/rational.h +++ b/libavutil/rational.h @@ -52,6 +52,14 @@ 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); diff --git a/vhook/Makefile b/vhook/Makefile index aedd8d1..cc001f5 100644 --- a/vhook/Makefile +++ b/vhook/Makefile @@ -2,7 +2,7 @@ include ../config.mak VPATH=$(SRC_PATH)/vhook -CFLAGS=-fPIC $(SHCFLAGS) -I.. -I$(SRC_PATH) -I$(SRC_PATH)/libavformat -I$(SRC_PATH)/libavcodec -DHAVE_AV_CONFIG_H +CFLAGS=-fPIC $(SHCFLAGS) -I.. -I$(SRC_PATH) -I$(SRC_PATH)/libavformat -I$(SRC_PATH)/libavcodec -I$(SRC_PATH)/libavutil -DHAVE_AV_CONFIG_H ifeq ($(CONFIG_DARWIN),yes) SHFLAGS+=-flat_namespace -undefined suppress |