Originally committed as revision 4489 to svn://svn.ffmpeg.org/ffmpeg/trunk
| ... | ... |
@@ -6,7 +6,7 @@ include config.mak |
| 6 | 6 |
|
| 7 | 7 |
VPATH=$(SRC_PATH) |
| 8 | 8 |
|
| 9 |
-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 |
|
| 9 |
+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 |
|
| 10 | 10 |
LDFLAGS+= -g |
| 11 | 11 |
|
| 12 | 12 |
ifeq ($(TARGET_GPROF),yes) |
| ... | ... |
@@ -91,11 +91,12 @@ endif |
| 91 | 91 |
|
| 92 | 92 |
OBJS = ffmpeg.o ffserver.o cmdutils.o $(FFPLAY_O) |
| 93 | 93 |
SRCS = $(OBJS:.o=.c) $(ASM_OBJS:.o=.s) |
| 94 |
-FFLIBS = -L./libavformat -lavformat$(BUILDSUF) -L./libavcodec -lavcodec$(BUILDSUF) |
|
| 94 |
+FFLIBS = -L./libavformat -lavformat$(BUILDSUF) -L./libavcodec -lavcodec$(BUILDSUF) -L./libavutil -lavutil$(BUILDSUF) |
|
| 95 | 95 |
|
| 96 | 96 |
all: lib $(PROG) $(PROGTEST) $(VHOOK) $(QTFASTSTART) $(DOC) |
| 97 | 97 |
|
| 98 | 98 |
lib: |
| 99 |
+ $(MAKE) -C libavutil all |
|
| 99 | 100 |
$(MAKE) -C libavcodec all |
| 100 | 101 |
$(MAKE) -C libavformat all |
| 101 | 102 |
|
| ... | ... |
@@ -140,6 +141,7 @@ documentation: |
| 140 | 140 |
.PHONY: install |
| 141 | 141 |
|
| 142 | 142 |
install: all install-man $(INSTALLVHOOK) |
| 143 |
+ $(MAKE) -C libavutil install |
|
| 143 | 144 |
$(MAKE) -C libavcodec install |
| 144 | 145 |
$(MAKE) -C libavformat install |
| 145 | 146 |
install -d "$(bindir)" |
| ... | ... |
@@ -162,6 +164,7 @@ install-vhook: |
| 162 | 162 |
$(MAKE) -C vhook install |
| 163 | 163 |
|
| 164 | 164 |
installlib: |
| 165 |
+ $(MAKE) -C libavutil installlib |
|
| 165 | 166 |
$(MAKE) -C libavcodec installlib |
| 166 | 167 |
$(MAKE) -C libavformat installlib |
| 167 | 168 |
|
| ... | ... |
@@ -182,6 +185,7 @@ endif |
| 182 | 182 |
@for i in $(DEP_LIBS) ; do if $(TEST) $$i -nt .libs ; then touch .libs; fi ; done |
| 183 | 183 |
|
| 184 | 184 |
clean: $(CLEANVHOOK) |
| 185 |
+ $(MAKE) -C libavutil clean |
|
| 185 | 186 |
$(MAKE) -C libavcodec clean |
| 186 | 187 |
$(MAKE) -C libavformat clean |
| 187 | 188 |
$(MAKE) -C tests clean |
| ... | ... |
@@ -7,7 +7,7 @@ include ../config.mak |
| 7 | 7 |
VPATH=$(SRC_PATH)/libavcodec |
| 8 | 8 |
|
| 9 | 9 |
# NOTE: -I.. is needed to include config.h |
| 10 |
-CFLAGS=$(OPTFLAGS) -DHAVE_AV_CONFIG_H -I.. -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE $(AMR_CFLAGS) |
|
| 10 |
+CFLAGS=$(OPTFLAGS) -DHAVE_AV_CONFIG_H -I.. -I$(SRC_PATH)/libavutil -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE $(AMR_CFLAGS) |
|
| 11 | 11 |
|
| 12 | 12 |
OBJS= bitstream.o utils.o mem.o allcodecs.o \ |
| 13 | 13 |
mpegvideo.o jrevdct.o jfdctfst.o jfdctint.o\ |
| ... | ... |
@@ -16,8 +16,8 @@ OBJS= bitstream.o utils.o mem.o allcodecs.o \ |
| 16 | 16 |
mpeg12.o mpegaudiodec.o pcm.o simple_idct.o \ |
| 17 | 17 |
ratecontrol.o adpcm.o eval.o error_resilience.o \ |
| 18 | 18 |
fft.o mdct.o raw.o golomb.o cabac.o\ |
| 19 |
- dpcm.o adx.o rational.o faandct.o parser.o g726.o \ |
|
| 20 |
- vp3dsp.o integer.o h264idct.o rangecoder.o pnm.o h263.o msmpeg4.o h263dec.o dvdsub.o dvbsub.o dvbsubdec.o |
|
| 19 |
+ dpcm.o adx.o faandct.o parser.o g726.o \ |
|
| 20 |
+ vp3dsp.o h264idct.o rangecoder.o pnm.o h263.o msmpeg4.o h263dec.o dvdsub.o dvbsub.o dvbsubdec.o |
|
| 21 | 21 |
|
| 22 | 22 |
ifeq ($(CONFIG_AASC_DECODER),yes) |
| 23 | 23 |
OBJS+= aasc.o |
| ... | ... |
@@ -234,6 +234,8 @@ OBJS+= liba52/bit_allocate.o liba52/bitstream.o liba52/downmix.o \ |
| 234 | 234 |
endif |
| 235 | 235 |
endif |
| 236 | 236 |
|
| 237 |
+EXTRALIBS += -L$(SRC_PATH)/libavutil -lavutil$(BUILDSUF) |
|
| 238 |
+ |
|
| 237 | 239 |
# currently using libdts for dts decoding |
| 238 | 240 |
ifeq ($(CONFIG_DTS),yes) |
| 239 | 241 |
OBJS+= dtsdec.o |
| ... | ... |
@@ -375,6 +377,7 @@ SRCS := $(OBJS:.o=.c) $(ASM_OBJS:.o=.S) |
| 375 | 375 |
OBJS := $(OBJS) $(ASM_OBJS) |
| 376 | 376 |
|
| 377 | 377 |
LIB= $(LIBPREF)avcodec$(LIBSUF) |
| 378 |
+LIBAVUTIL= $(SRC_PATH)/libavutil/$(LIBPREF)avutil$(LIBSUF) |
|
| 378 | 379 |
ifeq ($(BUILD_SHARED),yes) |
| 379 | 380 |
SLIB= $(SLIBPREF)avcodec$(SLIBSUF) |
| 380 | 381 |
endif |
| ... | ... |
@@ -446,7 +449,7 @@ cleanamrwbfloat: |
| 446 | 446 |
|
| 447 | 447 |
# api example program |
| 448 | 448 |
apiexample: apiexample.c $(LIB) |
| 449 |
- $(CC) $(CFLAGS) -o $@ $< $(LIB) $(EXTRALIBS) -lm |
|
| 449 |
+ $(CC) $(CFLAGS) -o $@ $< $(LIB) $(LIBAVUTIL) $(EXTRALIBS) -lm |
|
| 450 | 450 |
|
| 451 | 451 |
# cpuid test |
| 452 | 452 |
cpuid_test: i386/cputest.c |
| ... | ... |
@@ -464,7 +467,7 @@ motion-test: motion_test.o $(LIB) |
| 464 | 464 |
$(CC) -o $@ $^ -lm |
| 465 | 465 |
|
| 466 | 466 |
fft-test: fft-test.o $(LIB) |
| 467 |
- $(CC) -o $@ $^ -lm |
|
| 467 |
+ $(CC) -o $@ $^ $(LIBAVUTIL) -lm |
|
| 468 | 468 |
|
| 469 | 469 |
ifeq ($(BUILD_SHARED),yes) |
| 470 | 470 |
install: all install-headers |
| ... | ... |
@@ -489,8 +492,6 @@ installlib: all install-headers |
| 489 | 489 |
install-headers: |
| 490 | 490 |
mkdir -p "$(prefix)/include/ffmpeg" |
| 491 | 491 |
install -m 644 $(SRC_PATH)/libavcodec/avcodec.h \ |
| 492 |
- $(SRC_PATH)/libavcodec/common.h \ |
|
| 493 |
- $(SRC_PATH)/libavcodec/rational.h \ |
|
| 494 | 492 |
"$(prefix)/include/ffmpeg" |
| 495 | 493 |
install -d $(libdir)/pkgconfig |
| 496 | 494 |
install -m 644 ../libavcodec.pc $(libdir)/pkgconfig |
| ... | ... |
@@ -11,8 +11,7 @@ |
| 11 | 11 |
extern "C" {
|
| 12 | 12 |
#endif |
| 13 | 13 |
|
| 14 |
-#include "common.h" |
|
| 15 |
-#include "rational.h" |
|
| 14 |
+#include "avutil.h" |
|
| 16 | 15 |
#include <sys/types.h> /* size_t */ |
| 17 | 16 |
|
| 18 | 17 |
//FIXME the following 2 really dont belong in here |
| ... | ... |
@@ -22,8 +21,8 @@ extern "C" {
|
| 22 | 22 |
#define AV_STRINGIFY(s) AV_TOSTRING(s) |
| 23 | 23 |
#define AV_TOSTRING(s) #s |
| 24 | 24 |
|
| 25 |
-#define LIBAVCODEC_VERSION_INT ((49<<16)+(0<<8)+0) |
|
| 26 |
-#define LIBAVCODEC_VERSION 49.0.0 |
|
| 25 |
+#define LIBAVCODEC_VERSION_INT ((49<<16)+(0<<8)+1) |
|
| 26 |
+#define LIBAVCODEC_VERSION 49.0.1 |
|
| 27 | 27 |
#define LIBAVCODEC_BUILD LIBAVCODEC_VERSION_INT |
| 28 | 28 |
|
| 29 | 29 |
#define LIBAVCODEC_IDENT "Lavc" AV_STRINGIFY(LIBAVCODEC_VERSION) |
| ... | ... |
@@ -279,14 +278,6 @@ enum Motion_Est_ID {
|
| 279 | 279 |
ME_X1 |
| 280 | 280 |
}; |
| 281 | 281 |
|
| 282 |
-enum AVRounding {
|
|
| 283 |
- AV_ROUND_ZERO = 0, ///< round toward zero |
|
| 284 |
- AV_ROUND_INF = 1, ///< round away from zero |
|
| 285 |
- AV_ROUND_DOWN = 2, ///< round toward -infinity |
|
| 286 |
- AV_ROUND_UP = 3, ///< round toward +infinity |
|
| 287 |
- AV_ROUND_NEAR_INF = 5, ///< round to nearest and halfway cases away from zero |
|
| 288 |
-}; |
|
| 289 |
- |
|
| 290 | 282 |
enum AVDiscard{
|
| 291 | 283 |
//we leave some space between them for extensions (drop some keyframes for intra only or drop just some bidir frames) |
| 292 | 284 |
AVDISCARD_NONE =-16, ///< discard nothing |
| ... | ... |
@@ -2308,36 +2299,6 @@ void avcodec_default_free_buffers(AVCodecContext *s); |
| 2308 | 2308 |
*/ |
| 2309 | 2309 |
char av_get_pict_type_char(int pict_type); |
| 2310 | 2310 |
|
| 2311 |
-/** |
|
| 2312 |
- * reduce a fraction. |
|
| 2313 |
- * this is usefull for framerate calculations |
|
| 2314 |
- * @param max the maximum allowed for dst_nom & dst_den |
|
| 2315 |
- * @return 1 if exact, 0 otherwise |
|
| 2316 |
- */ |
|
| 2317 |
-int av_reduce(int *dst_nom, int *dst_den, int64_t nom, int64_t den, int64_t max); |
|
| 2318 |
- |
|
| 2319 |
-/** |
|
| 2320 |
- * rescale a 64bit integer with rounding to nearest. |
|
| 2321 |
- * a simple a*b/c isn't possible as it can overflow |
|
| 2322 |
- */ |
|
| 2323 |
-int64_t av_rescale(int64_t a, int64_t b, int64_t c); |
|
| 2324 |
- |
|
| 2325 |
-/** |
|
| 2326 |
- * rescale a 64bit integer with specified rounding. |
|
| 2327 |
- * a simple a*b/c isn't possible as it can overflow |
|
| 2328 |
- */ |
|
| 2329 |
-int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding); |
|
| 2330 |
- |
|
| 2331 |
-/** |
|
| 2332 |
- * rescale a 64bit integer by 2 rational numbers. |
|
| 2333 |
- */ |
|
| 2334 |
-int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq); |
|
| 2335 |
- |
|
| 2336 |
-double av_int2dbl(int64_t v); |
|
| 2337 |
-float av_int2flt(int32_t v); |
|
| 2338 |
-int64_t av_dbl2int(double d); |
|
| 2339 |
-int32_t av_flt2int(float d); |
|
| 2340 |
- |
|
| 2341 | 2311 |
|
| 2342 | 2312 |
/* frame parsing */ |
| 2343 | 2313 |
typedef struct AVCodecParserContext {
|
| 2344 | 2314 |
deleted file mode 100644 |
| ... | ... |
@@ -1,155 +0,0 @@ |
| 1 |
-/** |
|
| 2 |
- * @file bswap.h |
|
| 3 |
- * byte swap. |
|
| 4 |
- */ |
|
| 5 |
- |
|
| 6 |
-#ifndef __BSWAP_H__ |
|
| 7 |
-#define __BSWAP_H__ |
|
| 8 |
- |
|
| 9 |
-#ifdef HAVE_BYTESWAP_H |
|
| 10 |
-#include <byteswap.h> |
|
| 11 |
-#else |
|
| 12 |
- |
|
| 13 |
-#ifdef ARCH_X86_64 |
|
| 14 |
-# define LEGACY_REGS "=Q" |
|
| 15 |
-#else |
|
| 16 |
-# define LEGACY_REGS "=q" |
|
| 17 |
-#endif |
|
| 18 |
- |
|
| 19 |
-#if defined(ARCH_X86) || defined(ARCH_X86_64) |
|
| 20 |
-static always_inline uint16_t bswap_16(uint16_t x) |
|
| 21 |
-{
|
|
| 22 |
- __asm("rorw $8, %0" :
|
|
| 23 |
- LEGACY_REGS (x) : |
|
| 24 |
- "0" (x)); |
|
| 25 |
- return x; |
|
| 26 |
-} |
|
| 27 |
- |
|
| 28 |
-static always_inline uint32_t bswap_32(uint32_t x) |
|
| 29 |
-{
|
|
| 30 |
-#if __CPU__ > 386 |
|
| 31 |
- __asm("bswap %0":
|
|
| 32 |
- "=r" (x) : |
|
| 33 |
-#else |
|
| 34 |
- __asm("xchgb %b0,%h0\n"
|
|
| 35 |
- " rorl $16,%0\n" |
|
| 36 |
- " xchgb %b0,%h0": |
|
| 37 |
- LEGACY_REGS (x) : |
|
| 38 |
-#endif |
|
| 39 |
- "0" (x)); |
|
| 40 |
- return x; |
|
| 41 |
-} |
|
| 42 |
- |
|
| 43 |
-static inline uint64_t bswap_64(uint64_t x) |
|
| 44 |
-{
|
|
| 45 |
-#ifdef ARCH_X86_64 |
|
| 46 |
- __asm("bswap %0":
|
|
| 47 |
- "=r" (x) : |
|
| 48 |
- "0" (x)); |
|
| 49 |
- return x; |
|
| 50 |
-#else |
|
| 51 |
- union {
|
|
| 52 |
- uint64_t ll; |
|
| 53 |
- struct {
|
|
| 54 |
- uint32_t l,h; |
|
| 55 |
- } l; |
|
| 56 |
- } r; |
|
| 57 |
- r.l.l = bswap_32 (x); |
|
| 58 |
- r.l.h = bswap_32 (x>>32); |
|
| 59 |
- return r.ll; |
|
| 60 |
-#endif |
|
| 61 |
-} |
|
| 62 |
- |
|
| 63 |
-#elif defined(ARCH_SH4) |
|
| 64 |
- |
|
| 65 |
-static always_inline uint16_t bswap_16(uint16_t x) {
|
|
| 66 |
- __asm__("swap.b %0,%0":"=r"(x):"0"(x));
|
|
| 67 |
- return x; |
|
| 68 |
-} |
|
| 69 |
- |
|
| 70 |
-static always_inline uint32_t bswap_32(uint32_t x) {
|
|
| 71 |
- __asm__( |
|
| 72 |
- "swap.b %0,%0\n" |
|
| 73 |
- "swap.w %0,%0\n" |
|
| 74 |
- "swap.b %0,%0\n" |
|
| 75 |
- :"=r"(x):"0"(x)); |
|
| 76 |
- return x; |
|
| 77 |
-} |
|
| 78 |
- |
|
| 79 |
-static inline uint64_t bswap_64(uint64_t x) |
|
| 80 |
-{
|
|
| 81 |
- union {
|
|
| 82 |
- uint64_t ll; |
|
| 83 |
- struct {
|
|
| 84 |
- uint32_t l,h; |
|
| 85 |
- } l; |
|
| 86 |
- } r; |
|
| 87 |
- r.l.l = bswap_32 (x); |
|
| 88 |
- r.l.h = bswap_32 (x>>32); |
|
| 89 |
- return r.ll; |
|
| 90 |
-} |
|
| 91 |
-#else |
|
| 92 |
- |
|
| 93 |
-static always_inline uint16_t bswap_16(uint16_t x){
|
|
| 94 |
- return (x>>8) | (x<<8); |
|
| 95 |
-} |
|
| 96 |
- |
|
| 97 |
-#ifdef ARCH_ARM |
|
| 98 |
-static always_inline uint32_t bswap_32(uint32_t x){
|
|
| 99 |
- uint32_t t; |
|
| 100 |
- __asm__ ( |
|
| 101 |
- "eor %1, %0, %0, ror #16 \n\t" |
|
| 102 |
- "bic %1, %1, #0xFF0000 \n\t" |
|
| 103 |
- "mov %0, %0, ror #8 \n\t" |
|
| 104 |
- "eor %0, %0, %1, lsr #8 \n\t" |
|
| 105 |
- : "+r"(x), "+r"(t)); |
|
| 106 |
- return x; |
|
| 107 |
-} |
|
| 108 |
-#else |
|
| 109 |
-static always_inline uint32_t bswap_32(uint32_t x){
|
|
| 110 |
- x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF); |
|
| 111 |
- return (x>>16) | (x<<16); |
|
| 112 |
-} |
|
| 113 |
-#endif |
|
| 114 |
- |
|
| 115 |
-static inline uint64_t bswap_64(uint64_t x) |
|
| 116 |
-{
|
|
| 117 |
-#if 0 |
|
| 118 |
- x= ((x<< 8)&0xFF00FF00FF00FF00ULL) | ((x>> 8)&0x00FF00FF00FF00FFULL); |
|
| 119 |
- x= ((x<<16)&0xFFFF0000FFFF0000ULL) | ((x>>16)&0x0000FFFF0000FFFFULL); |
|
| 120 |
- return (x>>32) | (x<<32); |
|
| 121 |
-#else |
|
| 122 |
- union {
|
|
| 123 |
- uint64_t ll; |
|
| 124 |
- uint32_t l[2]; |
|
| 125 |
- } w, r; |
|
| 126 |
- w.ll = x; |
|
| 127 |
- r.l[0] = bswap_32 (w.l[1]); |
|
| 128 |
- r.l[1] = bswap_32 (w.l[0]); |
|
| 129 |
- return r.ll; |
|
| 130 |
-#endif |
|
| 131 |
-} |
|
| 132 |
-#endif /* !ARCH_X86 */ |
|
| 133 |
- |
|
| 134 |
-#endif /* !HAVE_BYTESWAP_H */ |
|
| 135 |
- |
|
| 136 |
-// be2me ... BigEndian to MachineEndian |
|
| 137 |
-// le2me ... LittleEndian to MachineEndian |
|
| 138 |
- |
|
| 139 |
-#ifdef WORDS_BIGENDIAN |
|
| 140 |
-#define be2me_16(x) (x) |
|
| 141 |
-#define be2me_32(x) (x) |
|
| 142 |
-#define be2me_64(x) (x) |
|
| 143 |
-#define le2me_16(x) bswap_16(x) |
|
| 144 |
-#define le2me_32(x) bswap_32(x) |
|
| 145 |
-#define le2me_64(x) bswap_64(x) |
|
| 146 |
-#else |
|
| 147 |
-#define be2me_16(x) bswap_16(x) |
|
| 148 |
-#define be2me_32(x) bswap_32(x) |
|
| 149 |
-#define be2me_64(x) bswap_64(x) |
|
| 150 |
-#define le2me_16(x) (x) |
|
| 151 |
-#define le2me_32(x) (x) |
|
| 152 |
-#define le2me_64(x) (x) |
|
| 153 |
-#endif |
|
| 154 |
- |
|
| 155 |
-#endif /* __BSWAP_H__ */ |
| 156 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,548 +0,0 @@ |
| 1 |
-/** |
|
| 2 |
- * @file common.h |
|
| 3 |
- * common internal api header. |
|
| 4 |
- */ |
|
| 5 |
- |
|
| 6 |
-#ifndef COMMON_H |
|
| 7 |
-#define COMMON_H |
|
| 8 |
- |
|
| 9 |
-#if defined(WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__) |
|
| 10 |
-# define CONFIG_WIN32 |
|
| 11 |
-#endif |
|
| 12 |
- |
|
| 13 |
-#ifndef M_PI |
|
| 14 |
-#define M_PI 3.14159265358979323846 |
|
| 15 |
-#endif |
|
| 16 |
- |
|
| 17 |
-#ifdef HAVE_AV_CONFIG_H |
|
| 18 |
-/* only include the following when compiling package */ |
|
| 19 |
-# include "config.h" |
|
| 20 |
- |
|
| 21 |
-# include <stdlib.h> |
|
| 22 |
-# include <stdio.h> |
|
| 23 |
-# include <string.h> |
|
| 24 |
-# include <ctype.h> |
|
| 25 |
-# include <limits.h> |
|
| 26 |
-# ifndef __BEOS__ |
|
| 27 |
-# include <errno.h> |
|
| 28 |
-# else |
|
| 29 |
-# include "berrno.h" |
|
| 30 |
-# endif |
|
| 31 |
-# include <math.h> |
|
| 32 |
- |
|
| 33 |
-# ifndef ENODATA |
|
| 34 |
-# define ENODATA 61 |
|
| 35 |
-# endif |
|
| 36 |
- |
|
| 37 |
-#include <stddef.h> |
|
| 38 |
-#ifndef offsetof |
|
| 39 |
-# define offsetof(T,F) ((unsigned int)((char *)&((T *)0)->F)) |
|
| 40 |
-#endif |
|
| 41 |
- |
|
| 42 |
-#define AVOPTION_CODEC_BOOL(name, help, field) \ |
|
| 43 |
- { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_BOOL }
|
|
| 44 |
-#define AVOPTION_CODEC_DOUBLE(name, help, field, minv, maxv, defval) \ |
|
| 45 |
- { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_DOUBLE, minv, maxv, defval }
|
|
| 46 |
-#define AVOPTION_CODEC_FLAG(name, help, field, flag, defval) \ |
|
| 47 |
- { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_FLAG, flag, 0, defval }
|
|
| 48 |
-#define AVOPTION_CODEC_INT(name, help, field, minv, maxv, defval) \ |
|
| 49 |
- { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_INT, minv, maxv, defval }
|
|
| 50 |
-#define AVOPTION_CODEC_STRING(name, help, field, str, val) \ |
|
| 51 |
- { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_STRING, .defval = val, .defstr = str }
|
|
| 52 |
-#define AVOPTION_CODEC_RCOVERRIDE(name, help, field) \ |
|
| 53 |
- { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_RCOVERRIDE, .defval = 0, .defstr = NULL }
|
|
| 54 |
-#define AVOPTION_SUB(ptr) { .name = NULL, .help = (const char*)ptr }
|
|
| 55 |
-#define AVOPTION_END() AVOPTION_SUB(NULL) |
|
| 56 |
- |
|
| 57 |
-#endif /* HAVE_AV_CONFIG_H */ |
|
| 58 |
- |
|
| 59 |
-/* Suppress restrict if it was not defined in config.h. */ |
|
| 60 |
-#ifndef restrict |
|
| 61 |
-# define restrict |
|
| 62 |
-#endif |
|
| 63 |
- |
|
| 64 |
-#ifndef always_inline |
|
| 65 |
-#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0) |
|
| 66 |
-# define always_inline __attribute__((always_inline)) inline |
|
| 67 |
-#else |
|
| 68 |
-# define always_inline inline |
|
| 69 |
-#endif |
|
| 70 |
-#endif |
|
| 71 |
- |
|
| 72 |
-#ifndef attribute_used |
|
| 73 |
-#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0) |
|
| 74 |
-# define attribute_used __attribute__((used)) |
|
| 75 |
-#else |
|
| 76 |
-# define attribute_used |
|
| 77 |
-#endif |
|
| 78 |
-#endif |
|
| 79 |
- |
|
| 80 |
-#ifndef attribute_unused |
|
| 81 |
-#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0) |
|
| 82 |
-# define attribute_unused __attribute__((unused)) |
|
| 83 |
-#else |
|
| 84 |
-# define attribute_unused |
|
| 85 |
-#endif |
|
| 86 |
-#endif |
|
| 87 |
- |
|
| 88 |
-#ifndef EMULATE_INTTYPES |
|
| 89 |
-# include <inttypes.h> |
|
| 90 |
-#else |
|
| 91 |
- typedef signed char int8_t; |
|
| 92 |
- typedef signed short int16_t; |
|
| 93 |
- typedef signed int int32_t; |
|
| 94 |
- typedef unsigned char uint8_t; |
|
| 95 |
- typedef unsigned short uint16_t; |
|
| 96 |
- typedef unsigned int uint32_t; |
|
| 97 |
- |
|
| 98 |
-# ifdef CONFIG_WIN32 |
|
| 99 |
- typedef signed __int64 int64_t; |
|
| 100 |
- typedef unsigned __int64 uint64_t; |
|
| 101 |
-# else /* other OS */ |
|
| 102 |
- typedef signed long long int64_t; |
|
| 103 |
- typedef unsigned long long uint64_t; |
|
| 104 |
-# endif /* other OS */ |
|
| 105 |
-#endif /* HAVE_INTTYPES_H */ |
|
| 106 |
- |
|
| 107 |
-#ifndef INT16_MIN |
|
| 108 |
-#define INT16_MIN (-0x7fff-1) |
|
| 109 |
-#endif |
|
| 110 |
- |
|
| 111 |
-#ifndef INT16_MAX |
|
| 112 |
-#define INT16_MAX 0x7fff |
|
| 113 |
-#endif |
|
| 114 |
- |
|
| 115 |
-#ifndef INT64_MIN |
|
| 116 |
-#define INT64_MIN (-0x7fffffffffffffffLL-1) |
|
| 117 |
-#endif |
|
| 118 |
- |
|
| 119 |
-#ifndef INT64_MAX |
|
| 120 |
-#define INT64_MAX int64_t_C(9223372036854775807) |
|
| 121 |
-#endif |
|
| 122 |
- |
|
| 123 |
-#ifndef UINT64_MAX |
|
| 124 |
-#define UINT64_MAX uint64_t_C(0xFFFFFFFFFFFFFFFF) |
|
| 125 |
-#endif |
|
| 126 |
- |
|
| 127 |
-#ifdef EMULATE_FAST_INT |
|
| 128 |
-typedef signed char int_fast8_t; |
|
| 129 |
-typedef signed int int_fast16_t; |
|
| 130 |
-typedef signed int int_fast32_t; |
|
| 131 |
-typedef unsigned char uint_fast8_t; |
|
| 132 |
-typedef unsigned int uint_fast16_t; |
|
| 133 |
-typedef unsigned int uint_fast32_t; |
|
| 134 |
-typedef uint64_t uint_fast64_t; |
|
| 135 |
-#endif |
|
| 136 |
- |
|
| 137 |
-#ifndef INT_BIT |
|
| 138 |
-# if INT_MAX != 2147483647 |
|
| 139 |
-# define INT_BIT 64 |
|
| 140 |
-# else |
|
| 141 |
-# define INT_BIT 32 |
|
| 142 |
-# endif |
|
| 143 |
-#endif |
|
| 144 |
- |
|
| 145 |
-#if defined(CONFIG_OS2) || defined(CONFIG_SUNOS) |
|
| 146 |
-static inline float floorf(float f) {
|
|
| 147 |
- return floor(f); |
|
| 148 |
-} |
|
| 149 |
-#endif |
|
| 150 |
- |
|
| 151 |
-#ifdef CONFIG_WIN32 |
|
| 152 |
- |
|
| 153 |
-/* windows */ |
|
| 154 |
- |
|
| 155 |
-# if !defined(__MINGW32__) && !defined(__CYGWIN__) |
|
| 156 |
-# define int64_t_C(c) (c ## i64) |
|
| 157 |
-# define uint64_t_C(c) (c ## i64) |
|
| 158 |
- |
|
| 159 |
-# ifdef HAVE_AV_CONFIG_H |
|
| 160 |
-# define inline __inline |
|
| 161 |
-# endif |
|
| 162 |
- |
|
| 163 |
-# else |
|
| 164 |
-# define int64_t_C(c) (c ## LL) |
|
| 165 |
-# define uint64_t_C(c) (c ## ULL) |
|
| 166 |
-# endif /* __MINGW32__ */ |
|
| 167 |
- |
|
| 168 |
-# ifdef HAVE_AV_CONFIG_H |
|
| 169 |
-# ifdef _DEBUG |
|
| 170 |
-# define DEBUG |
|
| 171 |
-# endif |
|
| 172 |
- |
|
| 173 |
-# define snprintf _snprintf |
|
| 174 |
-# define vsnprintf _vsnprintf |
|
| 175 |
-# endif |
|
| 176 |
- |
|
| 177 |
-/* CONFIG_WIN32 end */ |
|
| 178 |
-#elif defined (CONFIG_OS2) |
|
| 179 |
-/* OS/2 EMX */ |
|
| 180 |
- |
|
| 181 |
-#ifndef int64_t_C |
|
| 182 |
-#define int64_t_C(c) (c ## LL) |
|
| 183 |
-#define uint64_t_C(c) (c ## ULL) |
|
| 184 |
-#endif |
|
| 185 |
- |
|
| 186 |
-#ifdef HAVE_AV_CONFIG_H |
|
| 187 |
- |
|
| 188 |
-#ifdef USE_FASTMEMCPY |
|
| 189 |
-#include "fastmemcpy.h" |
|
| 190 |
-#endif |
|
| 191 |
- |
|
| 192 |
-#include <float.h> |
|
| 193 |
- |
|
| 194 |
-#endif /* HAVE_AV_CONFIG_H */ |
|
| 195 |
- |
|
| 196 |
-/* CONFIG_OS2 end */ |
|
| 197 |
-#else |
|
| 198 |
- |
|
| 199 |
-/* unix */ |
|
| 200 |
- |
|
| 201 |
-#ifndef int64_t_C |
|
| 202 |
-#define int64_t_C(c) (c ## LL) |
|
| 203 |
-#define uint64_t_C(c) (c ## ULL) |
|
| 204 |
-#endif |
|
| 205 |
- |
|
| 206 |
-#ifdef HAVE_AV_CONFIG_H |
|
| 207 |
- |
|
| 208 |
-# ifdef USE_FASTMEMCPY |
|
| 209 |
-# include "fastmemcpy.h" |
|
| 210 |
-# endif |
|
| 211 |
-# endif /* HAVE_AV_CONFIG_H */ |
|
| 212 |
- |
|
| 213 |
-#endif /* !CONFIG_WIN32 && !CONFIG_OS2 */ |
|
| 214 |
- |
|
| 215 |
-#ifdef HAVE_AV_CONFIG_H |
|
| 216 |
- |
|
| 217 |
-# include "bswap.h" |
|
| 218 |
- |
|
| 219 |
-// Use rip-relative addressing if compiling PIC code on x86-64. |
|
| 220 |
-# if defined(__MINGW32__) || defined(__CYGWIN__) || \ |
|
| 221 |
- defined(__OS2__) || (defined (__OpenBSD__) && !defined(__ELF__)) |
|
| 222 |
-# if defined(ARCH_X86_64) && defined(PIC) |
|
| 223 |
-# define MANGLE(a) "_" #a"(%%rip)" |
|
| 224 |
-# else |
|
| 225 |
-# define MANGLE(a) "_" #a |
|
| 226 |
-# endif |
|
| 227 |
-# else |
|
| 228 |
-# if defined(ARCH_X86_64) && defined(PIC) |
|
| 229 |
-# define MANGLE(a) #a"(%%rip)" |
|
| 230 |
-# else |
|
| 231 |
-# define MANGLE(a) #a |
|
| 232 |
-# endif |
|
| 233 |
-# endif |
|
| 234 |
- |
|
| 235 |
-/* debug stuff */ |
|
| 236 |
- |
|
| 237 |
-# ifndef DEBUG |
|
| 238 |
-# define NDEBUG |
|
| 239 |
-# endif |
|
| 240 |
-# include <assert.h> |
|
| 241 |
- |
|
| 242 |
-/* dprintf macros */ |
|
| 243 |
-# if defined(CONFIG_WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__) |
|
| 244 |
- |
|
| 245 |
-inline void dprintf(const char* fmt,...) {}
|
|
| 246 |
- |
|
| 247 |
-# else |
|
| 248 |
- |
|
| 249 |
-# ifdef DEBUG |
|
| 250 |
-# define dprintf(fmt,...) av_log(NULL, AV_LOG_DEBUG, fmt, __VA_ARGS__) |
|
| 251 |
-# else |
|
| 252 |
-# define dprintf(fmt,...) |
|
| 253 |
-# endif |
|
| 254 |
- |
|
| 255 |
-# endif /* !CONFIG_WIN32 */ |
|
| 256 |
- |
|
| 257 |
-# define av_abort() do { av_log(NULL, AV_LOG_ERROR, "Abort at %s:%d\n", __FILE__, __LINE__); abort(); } while (0)
|
|
| 258 |
- |
|
| 259 |
-//rounded divison & shift |
|
| 260 |
-#define RSHIFT(a,b) ((a) > 0 ? ((a) + ((1<<(b))>>1))>>(b) : ((a) + ((1<<(b))>>1)-1)>>(b)) |
|
| 261 |
-/* assume b>0 */ |
|
| 262 |
-#define ROUNDED_DIV(a,b) (((a)>0 ? (a) + ((b)>>1) : (a) - ((b)>>1))/(b)) |
|
| 263 |
-#define ABS(a) ((a) >= 0 ? (a) : (-(a))) |
|
| 264 |
- |
|
| 265 |
-#define FFMAX(a,b) ((a) > (b) ? (a) : (b)) |
|
| 266 |
-#define FFMIN(a,b) ((a) > (b) ? (b) : (a)) |
|
| 267 |
- |
|
| 268 |
-extern const uint32_t inverse[256]; |
|
| 269 |
- |
|
| 270 |
-#if defined(ARCH_X86) || defined(ARCH_X86_64) |
|
| 271 |
-# define FASTDIV(a,b) \ |
|
| 272 |
- ({\
|
|
| 273 |
- int ret,dmy;\ |
|
| 274 |
- asm volatile(\ |
|
| 275 |
- "mull %3"\ |
|
| 276 |
- :"=d"(ret),"=a"(dmy)\ |
|
| 277 |
- :"1"(a),"g"(inverse[b])\ |
|
| 278 |
- );\ |
|
| 279 |
- ret;\ |
|
| 280 |
- }) |
|
| 281 |
-#elif defined(CONFIG_FASTDIV) |
|
| 282 |
-# define FASTDIV(a,b) ((uint32_t)((((uint64_t)a)*inverse[b])>>32)) |
|
| 283 |
-#else |
|
| 284 |
-# define FASTDIV(a,b) ((a)/(b)) |
|
| 285 |
-#endif |
|
| 286 |
- |
|
| 287 |
-/* define it to include statistics code (useful only for optimizing |
|
| 288 |
- codec efficiency */ |
|
| 289 |
-//#define STATS |
|
| 290 |
- |
|
| 291 |
-#ifdef STATS |
|
| 292 |
- |
|
| 293 |
-enum {
|
|
| 294 |
- ST_UNKNOWN, |
|
| 295 |
- ST_DC, |
|
| 296 |
- ST_INTRA_AC, |
|
| 297 |
- ST_INTER_AC, |
|
| 298 |
- ST_INTRA_MB, |
|
| 299 |
- ST_INTER_MB, |
|
| 300 |
- ST_MV, |
|
| 301 |
- ST_NB, |
|
| 302 |
-}; |
|
| 303 |
- |
|
| 304 |
-extern int st_current_index; |
|
| 305 |
-extern unsigned int st_bit_counts[ST_NB]; |
|
| 306 |
-extern unsigned int st_out_bit_counts[ST_NB]; |
|
| 307 |
- |
|
| 308 |
-void print_stats(void); |
|
| 309 |
-#endif |
|
| 310 |
- |
|
| 311 |
-/* misc math functions */ |
|
| 312 |
-extern const uint8_t ff_log2_tab[256]; |
|
| 313 |
- |
|
| 314 |
-static inline int av_log2(unsigned int v) |
|
| 315 |
-{
|
|
| 316 |
- int n; |
|
| 317 |
- |
|
| 318 |
- n = 0; |
|
| 319 |
- if (v & 0xffff0000) {
|
|
| 320 |
- v >>= 16; |
|
| 321 |
- n += 16; |
|
| 322 |
- } |
|
| 323 |
- if (v & 0xff00) {
|
|
| 324 |
- v >>= 8; |
|
| 325 |
- n += 8; |
|
| 326 |
- } |
|
| 327 |
- n += ff_log2_tab[v]; |
|
| 328 |
- |
|
| 329 |
- return n; |
|
| 330 |
-} |
|
| 331 |
- |
|
| 332 |
-static inline int av_log2_16bit(unsigned int v) |
|
| 333 |
-{
|
|
| 334 |
- int n; |
|
| 335 |
- |
|
| 336 |
- n = 0; |
|
| 337 |
- if (v & 0xff00) {
|
|
| 338 |
- v >>= 8; |
|
| 339 |
- n += 8; |
|
| 340 |
- } |
|
| 341 |
- n += ff_log2_tab[v]; |
|
| 342 |
- |
|
| 343 |
- return n; |
|
| 344 |
-} |
|
| 345 |
- |
|
| 346 |
-/* median of 3 */ |
|
| 347 |
-static inline int mid_pred(int a, int b, int c) |
|
| 348 |
-{
|
|
| 349 |
-#if 0 |
|
| 350 |
- int t= (a-b)&((a-b)>>31); |
|
| 351 |
- a-=t; |
|
| 352 |
- b+=t; |
|
| 353 |
- b-= (b-c)&((b-c)>>31); |
|
| 354 |
- b+= (a-b)&((a-b)>>31); |
|
| 355 |
- |
|
| 356 |
- return b; |
|
| 357 |
-#else |
|
| 358 |
- if(a>b){
|
|
| 359 |
- if(c>b){
|
|
| 360 |
- if(c>a) b=a; |
|
| 361 |
- else b=c; |
|
| 362 |
- } |
|
| 363 |
- }else{
|
|
| 364 |
- if(b>c){
|
|
| 365 |
- if(c>a) b=c; |
|
| 366 |
- else b=a; |
|
| 367 |
- } |
|
| 368 |
- } |
|
| 369 |
- return b; |
|
| 370 |
-#endif |
|
| 371 |
-} |
|
| 372 |
- |
|
| 373 |
-static inline int clip(int a, int amin, int amax) |
|
| 374 |
-{
|
|
| 375 |
- if (a < amin) |
|
| 376 |
- return amin; |
|
| 377 |
- else if (a > amax) |
|
| 378 |
- return amax; |
|
| 379 |
- else |
|
| 380 |
- return a; |
|
| 381 |
-} |
|
| 382 |
- |
|
| 383 |
-static inline int clip_uint8(int a) |
|
| 384 |
-{
|
|
| 385 |
- if (a&(~255)) return (-a)>>31; |
|
| 386 |
- else return a; |
|
| 387 |
-} |
|
| 388 |
- |
|
| 389 |
-/* math */ |
|
| 390 |
-extern const uint8_t ff_sqrt_tab[128]; |
|
| 391 |
- |
|
| 392 |
-int64_t ff_gcd(int64_t a, int64_t b); |
|
| 393 |
- |
|
| 394 |
-static inline int ff_sqrt(int a) |
|
| 395 |
-{
|
|
| 396 |
- int ret=0; |
|
| 397 |
- int s; |
|
| 398 |
- int ret_sq=0; |
|
| 399 |
- |
|
| 400 |
- if(a<128) return ff_sqrt_tab[a]; |
|
| 401 |
- |
|
| 402 |
- for(s=15; s>=0; s--){
|
|
| 403 |
- int b= ret_sq + (1<<(s*2)) + (ret<<s)*2; |
|
| 404 |
- if(b<=a){
|
|
| 405 |
- ret_sq=b; |
|
| 406 |
- ret+= 1<<s; |
|
| 407 |
- } |
|
| 408 |
- } |
|
| 409 |
- return ret; |
|
| 410 |
-} |
|
| 411 |
- |
|
| 412 |
-/** |
|
| 413 |
- * converts fourcc string to int |
|
| 414 |
- */ |
|
| 415 |
-static inline int ff_get_fourcc(const char *s){
|
|
| 416 |
- assert( strlen(s)==4 ); |
|
| 417 |
- |
|
| 418 |
- return (s[0]) + (s[1]<<8) + (s[2]<<16) + (s[3]<<24); |
|
| 419 |
-} |
|
| 420 |
- |
|
| 421 |
-#define MKTAG(a,b,c,d) (a | (b << 8) | (c << 16) | (d << 24)) |
|
| 422 |
-#define MKBETAG(a,b,c,d) (d | (c << 8) | (b << 16) | (a << 24)) |
|
| 423 |
- |
|
| 424 |
- |
|
| 425 |
-#if defined(ARCH_X86) || defined(ARCH_X86_64) |
|
| 426 |
-#define MASK_ABS(mask, level)\ |
|
| 427 |
- asm volatile(\ |
|
| 428 |
- "cdq \n\t"\ |
|
| 429 |
- "xorl %1, %0 \n\t"\ |
|
| 430 |
- "subl %1, %0 \n\t"\ |
|
| 431 |
- : "+a" (level), "=&d" (mask)\ |
|
| 432 |
- ); |
|
| 433 |
-#else |
|
| 434 |
-#define MASK_ABS(mask, level)\ |
|
| 435 |
- mask= level>>31;\ |
|
| 436 |
- level= (level^mask)-mask; |
|
| 437 |
-#endif |
|
| 438 |
- |
|
| 439 |
- |
|
| 440 |
-#if __CPU__ >= 686 && !defined(RUNTIME_CPUDETECT) |
|
| 441 |
-#define COPY3_IF_LT(x,y,a,b,c,d)\ |
|
| 442 |
-asm volatile (\ |
|
| 443 |
- "cmpl %0, %3 \n\t"\ |
|
| 444 |
- "cmovl %3, %0 \n\t"\ |
|
| 445 |
- "cmovl %4, %1 \n\t"\ |
|
| 446 |
- "cmovl %5, %2 \n\t"\ |
|
| 447 |
- : "+r" (x), "+r" (a), "+r" (c)\ |
|
| 448 |
- : "r" (y), "r" (b), "r" (d)\ |
|
| 449 |
-); |
|
| 450 |
-#else |
|
| 451 |
-#define COPY3_IF_LT(x,y,a,b,c,d)\ |
|
| 452 |
-if((y)<(x)){\
|
|
| 453 |
- (x)=(y);\ |
|
| 454 |
- (a)=(b);\ |
|
| 455 |
- (c)=(d);\ |
|
| 456 |
-} |
|
| 457 |
-#endif |
|
| 458 |
- |
|
| 459 |
-#if defined(ARCH_X86) || defined(ARCH_X86_64) || defined(ARCH_POWERPC) |
|
| 460 |
-#if defined(ARCH_X86_64) |
|
| 461 |
-static inline uint64_t read_time(void) |
|
| 462 |
-{
|
|
| 463 |
- uint64_t a, d; |
|
| 464 |
- asm volatile( "rdtsc\n\t" |
|
| 465 |
- : "=a" (a), "=d" (d) |
|
| 466 |
- ); |
|
| 467 |
- return (d << 32) | (a & 0xffffffff); |
|
| 468 |
-} |
|
| 469 |
-#elif defined(ARCH_X86) |
|
| 470 |
-static inline long long read_time(void) |
|
| 471 |
-{
|
|
| 472 |
- long long l; |
|
| 473 |
- asm volatile( "rdtsc\n\t" |
|
| 474 |
- : "=A" (l) |
|
| 475 |
- ); |
|
| 476 |
- return l; |
|
| 477 |
-} |
|
| 478 |
-#else //FIXME check ppc64 |
|
| 479 |
-static inline uint64_t read_time(void) |
|
| 480 |
-{
|
|
| 481 |
- uint32_t tbu, tbl, temp; |
|
| 482 |
- |
|
| 483 |
- /* from section 2.2.1 of the 32-bit PowerPC PEM */ |
|
| 484 |
- __asm__ __volatile__( |
|
| 485 |
- "1:\n" |
|
| 486 |
- "mftbu %2\n" |
|
| 487 |
- "mftb %0\n" |
|
| 488 |
- "mftbu %1\n" |
|
| 489 |
- "cmpw %2,%1\n" |
|
| 490 |
- "bne 1b\n" |
|
| 491 |
- : "=r"(tbl), "=r"(tbu), "=r"(temp) |
|
| 492 |
- : |
|
| 493 |
- : "cc"); |
|
| 494 |
- |
|
| 495 |
- return (((uint64_t)tbu)<<32) | (uint64_t)tbl; |
|
| 496 |
-} |
|
| 497 |
-#endif |
|
| 498 |
- |
|
| 499 |
-#define START_TIMER \ |
|
| 500 |
-uint64_t tend;\ |
|
| 501 |
-uint64_t tstart= read_time();\ |
|
| 502 |
- |
|
| 503 |
-#define STOP_TIMER(id) \ |
|
| 504 |
-tend= read_time();\ |
|
| 505 |
-{\
|
|
| 506 |
- static uint64_t tsum=0;\ |
|
| 507 |
- static int tcount=0;\ |
|
| 508 |
- static int tskip_count=0;\ |
|
| 509 |
- if(tcount<2 || tend - tstart < 8*tsum/tcount){\
|
|
| 510 |
- tsum+= tend - tstart;\ |
|
| 511 |
- tcount++;\ |
|
| 512 |
- }else\ |
|
| 513 |
- tskip_count++;\ |
|
| 514 |
- if(256*256*256*64%(tcount+tskip_count)==0){\
|
|
| 515 |
- av_log(NULL, AV_LOG_DEBUG, "%Ld dezicycles in %s, %d runs, %d skips\n", tsum*10/tcount, id, tcount, tskip_count);\ |
|
| 516 |
- }\ |
|
| 517 |
-} |
|
| 518 |
-#else |
|
| 519 |
-#define START_TIMER |
|
| 520 |
-#define STOP_TIMER(id) {}
|
|
| 521 |
-#endif |
|
| 522 |
- |
|
| 523 |
-/* avoid usage of various functions */ |
|
| 524 |
-#define malloc please_use_av_malloc |
|
| 525 |
-#define free please_use_av_free |
|
| 526 |
-#define realloc please_use_av_realloc |
|
| 527 |
-#define time time_is_forbidden_due_to_security_issues |
|
| 528 |
-#define rand rand_is_forbidden_due_to_state_trashing |
|
| 529 |
-#define srand srand_is_forbidden_due_to_state_trashing |
|
| 530 |
-#define sprintf sprintf_is_forbidden_due_to_security_issues_use_snprintf |
|
| 531 |
-#define strcat strcat_is_forbidden_due_to_security_issues_use_pstrcat |
|
| 532 |
-#if !(defined(LIBAVFORMAT_BUILD) || defined(_FRAMEHOOK_H)) |
|
| 533 |
-#define printf please_use_av_log |
|
| 534 |
-#define fprintf please_use_av_log |
|
| 535 |
-#endif |
|
| 536 |
- |
|
| 537 |
-#define CHECKED_ALLOCZ(p, size)\ |
|
| 538 |
-{\
|
|
| 539 |
- p= av_mallocz(size);\ |
|
| 540 |
- if(p==NULL && (size)!=0){\
|
|
| 541 |
- perror("malloc");\
|
|
| 542 |
- goto fail;\ |
|
| 543 |
- }\ |
|
| 544 |
-} |
|
| 545 |
- |
|
| 546 |
-#endif /* HAVE_AV_CONFIG_H */ |
|
| 547 |
- |
|
| 548 |
-#endif /* COMMON_H */ |
| 29 | 29 |
deleted file mode 100644 |
| ... | ... |
@@ -1,221 +0,0 @@ |
| 1 |
-/* |
|
| 2 |
- * arbitrary precision integers |
|
| 3 |
- * Copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at> |
|
| 4 |
- * |
|
| 5 |
- * This library is free software; you can redistribute it and/or |
|
| 6 |
- * modify it under the terms of the GNU Lesser General Public |
|
| 7 |
- * License as published by the Free Software Foundation; either |
|
| 8 |
- * version 2 of the License, or (at your option) any later version. |
|
| 9 |
- * |
|
| 10 |
- * This library is distributed in the hope that it will be useful, |
|
| 11 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 12 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
| 13 |
- * Lesser General Public License for more details. |
|
| 14 |
- * |
|
| 15 |
- * You should have received a copy of the GNU Lesser General Public |
|
| 16 |
- * License along with this library; if not, write to the Free Software |
|
| 17 |
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
| 18 |
- * |
|
| 19 |
- */ |
|
| 20 |
- |
|
| 21 |
-/** |
|
| 22 |
- * @file integer.c |
|
| 23 |
- * arbitrary precision integers. |
|
| 24 |
- * @author Michael Niedermayer <michaelni@gmx.at> |
|
| 25 |
- */ |
|
| 26 |
- |
|
| 27 |
-#include "common.h" |
|
| 28 |
-#include "integer.h" |
|
| 29 |
- |
|
| 30 |
-AVInteger av_add_i(AVInteger a, AVInteger b){
|
|
| 31 |
- int i, carry=0; |
|
| 32 |
- |
|
| 33 |
- for(i=0; i<AV_INTEGER_SIZE; i++){
|
|
| 34 |
- carry= (carry>>16) + a.v[i] + b.v[i]; |
|
| 35 |
- a.v[i]= carry; |
|
| 36 |
- } |
|
| 37 |
- return a; |
|
| 38 |
-} |
|
| 39 |
- |
|
| 40 |
-AVInteger av_sub_i(AVInteger a, AVInteger b){
|
|
| 41 |
- int i, carry=0; |
|
| 42 |
- |
|
| 43 |
- for(i=0; i<AV_INTEGER_SIZE; i++){
|
|
| 44 |
- carry= (carry>>16) + a.v[i] - b.v[i]; |
|
| 45 |
- a.v[i]= carry; |
|
| 46 |
- } |
|
| 47 |
- return a; |
|
| 48 |
-} |
|
| 49 |
- |
|
| 50 |
-/** |
|
| 51 |
- * returns the rounded down value of the logarithm of base 2 of the given AVInteger. |
|
| 52 |
- * this is simply the index of the most significant bit which is 1. Or 0 of all bits are 0 |
|
| 53 |
- */ |
|
| 54 |
-int av_log2_i(AVInteger a){
|
|
| 55 |
- int i; |
|
| 56 |
- |
|
| 57 |
- for(i=AV_INTEGER_SIZE-1; i>=0; i--){
|
|
| 58 |
- if(a.v[i]) |
|
| 59 |
- return av_log2_16bit(a.v[i]) + 16*i; |
|
| 60 |
- } |
|
| 61 |
- return -1; |
|
| 62 |
-} |
|
| 63 |
- |
|
| 64 |
-AVInteger av_mul_i(AVInteger a, AVInteger b){
|
|
| 65 |
- AVInteger out; |
|
| 66 |
- int i, j; |
|
| 67 |
- int na= (av_log2_i(a)+16) >> 4; |
|
| 68 |
- int nb= (av_log2_i(b)+16) >> 4; |
|
| 69 |
- |
|
| 70 |
- memset(&out, 0, sizeof(out)); |
|
| 71 |
- |
|
| 72 |
- for(i=0; i<na; i++){
|
|
| 73 |
- unsigned int carry=0; |
|
| 74 |
- |
|
| 75 |
- if(a.v[i]) |
|
| 76 |
- for(j=i; j<AV_INTEGER_SIZE && j-i<=nb; j++){
|
|
| 77 |
- carry= (carry>>16) + out.v[j] + a.v[i]*b.v[j-i]; |
|
| 78 |
- out.v[j]= carry; |
|
| 79 |
- } |
|
| 80 |
- } |
|
| 81 |
- |
|
| 82 |
- return out; |
|
| 83 |
-} |
|
| 84 |
- |
|
| 85 |
-/** |
|
| 86 |
- * returns 0 if a==b, 1 if a>b and -1 if a<b. |
|
| 87 |
- */ |
|
| 88 |
-int av_cmp_i(AVInteger a, AVInteger b){
|
|
| 89 |
- int i; |
|
| 90 |
- int v= (int16_t)a.v[AV_INTEGER_SIZE-1] - (int16_t)b.v[AV_INTEGER_SIZE-1]; |
|
| 91 |
- if(v) return (v>>16)|1; |
|
| 92 |
- |
|
| 93 |
- for(i=AV_INTEGER_SIZE-2; i>=0; i--){
|
|
| 94 |
- int v= a.v[i] - b.v[i]; |
|
| 95 |
- if(v) return (v>>16)|1; |
|
| 96 |
- } |
|
| 97 |
- return 0; |
|
| 98 |
-} |
|
| 99 |
- |
|
| 100 |
-/** |
|
| 101 |
- * bitwise shift. |
|
| 102 |
- * @param s the number of bits by which the value should be shifted right, may be negative for shifting left |
|
| 103 |
- */ |
|
| 104 |
-AVInteger av_shr_i(AVInteger a, int s){
|
|
| 105 |
- AVInteger out; |
|
| 106 |
- int i; |
|
| 107 |
- |
|
| 108 |
- for(i=0; i<AV_INTEGER_SIZE; i++){
|
|
| 109 |
- int index= i + (s>>4); |
|
| 110 |
- unsigned int v=0; |
|
| 111 |
- if(index+1<AV_INTEGER_SIZE && index+1>=0) v = a.v[index+1]<<16; |
|
| 112 |
- if(index <AV_INTEGER_SIZE && index >=0) v+= a.v[index ]; |
|
| 113 |
- out.v[i]= v >> (s&15); |
|
| 114 |
- } |
|
| 115 |
- return out; |
|
| 116 |
-} |
|
| 117 |
- |
|
| 118 |
-/** |
|
| 119 |
- * returns a % b. |
|
| 120 |
- * @param quot a/b will be stored here |
|
| 121 |
- */ |
|
| 122 |
-AVInteger av_mod_i(AVInteger *quot, AVInteger a, AVInteger b){
|
|
| 123 |
- int i= av_log2_i(a) - av_log2_i(b); |
|
| 124 |
- AVInteger quot_temp; |
|
| 125 |
- if(!quot) quot = "_temp; |
|
| 126 |
- |
|
| 127 |
- assert((int16_t)a[AV_INTEGER_SIZE-1] >= 0 && (int16_t)b[AV_INTEGER_SIZE-1] >= 0); |
|
| 128 |
- assert(av_log2(b)>=0); |
|
| 129 |
- |
|
| 130 |
- if(i > 0) |
|
| 131 |
- b= av_shr_i(b, -i); |
|
| 132 |
- |
|
| 133 |
- memset(quot, 0, sizeof(AVInteger)); |
|
| 134 |
- |
|
| 135 |
- while(i-- >= 0){
|
|
| 136 |
- *quot= av_shr_i(*quot, -1); |
|
| 137 |
- if(av_cmp_i(a, b) >= 0){
|
|
| 138 |
- a= av_sub_i(a, b); |
|
| 139 |
- quot->v[0] += 1; |
|
| 140 |
- } |
|
| 141 |
- b= av_shr_i(b, 1); |
|
| 142 |
- } |
|
| 143 |
- return a; |
|
| 144 |
-} |
|
| 145 |
- |
|
| 146 |
-/** |
|
| 147 |
- * returns a/b. |
|
| 148 |
- */ |
|
| 149 |
-AVInteger av_div_i(AVInteger a, AVInteger b){
|
|
| 150 |
- AVInteger quot; |
|
| 151 |
- av_mod_i(", a, b); |
|
| 152 |
- return quot; |
|
| 153 |
-} |
|
| 154 |
- |
|
| 155 |
-/** |
|
| 156 |
- * converts the given int64_t to an AVInteger. |
|
| 157 |
- */ |
|
| 158 |
-AVInteger av_int2i(int64_t a){
|
|
| 159 |
- AVInteger out; |
|
| 160 |
- int i; |
|
| 161 |
- |
|
| 162 |
- for(i=0; i<AV_INTEGER_SIZE; i++){
|
|
| 163 |
- out.v[i]= a; |
|
| 164 |
- a>>=16; |
|
| 165 |
- } |
|
| 166 |
- return out; |
|
| 167 |
-} |
|
| 168 |
- |
|
| 169 |
-/** |
|
| 170 |
- * converts the given AVInteger to an int64_t. |
|
| 171 |
- * if the AVInteger is too large to fit into an int64_t, |
|
| 172 |
- * then only the least significant 64bit will be used |
|
| 173 |
- */ |
|
| 174 |
-int64_t av_i2int(AVInteger a){
|
|
| 175 |
- int i; |
|
| 176 |
- int64_t out=(int8_t)a.v[AV_INTEGER_SIZE-1]; |
|
| 177 |
- |
|
| 178 |
- for(i= AV_INTEGER_SIZE-2; i>=0; i--){
|
|
| 179 |
- out = (out<<16) + a.v[i]; |
|
| 180 |
- } |
|
| 181 |
- return out; |
|
| 182 |
-} |
|
| 183 |
- |
|
| 184 |
-#if 0 |
|
| 185 |
-#undef NDEBUG |
|
| 186 |
-#include <assert.h> |
|
| 187 |
- |
|
| 188 |
-const uint8_t ff_log2_tab[256]={
|
|
| 189 |
- 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, |
|
| 190 |
- 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, |
|
| 191 |
- 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, |
|
| 192 |
- 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, |
|
| 193 |
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, |
|
| 194 |
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, |
|
| 195 |
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, |
|
| 196 |
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7 |
|
| 197 |
-}; |
|
| 198 |
- |
|
| 199 |
-main(){
|
|
| 200 |
- int64_t a,b; |
|
| 201 |
- |
|
| 202 |
- for(a=7; a<256*256*256; a+=13215){
|
|
| 203 |
- for(b=3; b<256*256*256; b+=27118){
|
|
| 204 |
- AVInteger ai= av_int2i(a); |
|
| 205 |
- AVInteger bi= av_int2i(b); |
|
| 206 |
- |
|
| 207 |
- assert(av_i2int(ai) == a); |
|
| 208 |
- assert(av_i2int(bi) == b); |
|
| 209 |
- assert(av_i2int(av_add_i(ai,bi)) == a+b); |
|
| 210 |
- assert(av_i2int(av_sub_i(ai,bi)) == a-b); |
|
| 211 |
- assert(av_i2int(av_mul_i(ai,bi)) == a*b); |
|
| 212 |
- assert(av_i2int(av_shr_i(ai, 9)) == a>>9); |
|
| 213 |
- assert(av_i2int(av_shr_i(ai,-9)) == a<<9); |
|
| 214 |
- assert(av_i2int(av_shr_i(ai, 17)) == a>>17); |
|
| 215 |
- assert(av_i2int(av_shr_i(ai,-17)) == a<<17); |
|
| 216 |
- assert(av_log2_i(ai) == av_log2(a)); |
|
| 217 |
- assert(av_i2int(av_div_i(ai,bi)) == a/b); |
|
| 218 |
- } |
|
| 219 |
- } |
|
| 220 |
-} |
|
| 221 |
-#endif |
| 222 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,47 +0,0 @@ |
| 1 |
-/* |
|
| 2 |
- * arbitrary precision integers |
|
| 3 |
- * Copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at> |
|
| 4 |
- * |
|
| 5 |
- * This library is free software; you can redistribute it and/or |
|
| 6 |
- * modify it under the terms of the GNU Lesser General Public |
|
| 7 |
- * License as published by the Free Software Foundation; either |
|
| 8 |
- * version 2 of the License, or (at your option) any later version. |
|
| 9 |
- * |
|
| 10 |
- * This library is distributed in the hope that it will be useful, |
|
| 11 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 12 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
| 13 |
- * Lesser General Public License for more details. |
|
| 14 |
- * |
|
| 15 |
- * You should have received a copy of the GNU Lesser General Public |
|
| 16 |
- * License along with this library; if not, write to the Free Software |
|
| 17 |
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
| 18 |
- * |
|
| 19 |
- */ |
|
| 20 |
- |
|
| 21 |
-/** |
|
| 22 |
- * @file integer.h |
|
| 23 |
- * arbitrary precision integers |
|
| 24 |
- * @author Michael Niedermayer <michaelni@gmx.at> |
|
| 25 |
- */ |
|
| 26 |
- |
|
| 27 |
-#ifndef INTEGER_H |
|
| 28 |
-#define INTEGER_H |
|
| 29 |
- |
|
| 30 |
-#define AV_INTEGER_SIZE 8 |
|
| 31 |
- |
|
| 32 |
-typedef struct AVInteger{
|
|
| 33 |
- uint16_t v[AV_INTEGER_SIZE]; |
|
| 34 |
-} AVInteger; |
|
| 35 |
- |
|
| 36 |
-AVInteger av_add_i(AVInteger a, AVInteger b); |
|
| 37 |
-AVInteger av_sub_i(AVInteger a, AVInteger b); |
|
| 38 |
-int av_log2_i(AVInteger a); |
|
| 39 |
-AVInteger av_mul_i(AVInteger a, AVInteger b); |
|
| 40 |
-int av_cmp_i(AVInteger a, AVInteger b); |
|
| 41 |
-AVInteger av_shr_i(AVInteger a, int s); |
|
| 42 |
-AVInteger av_mod_i(AVInteger *quot, AVInteger a, AVInteger b); |
|
| 43 |
-AVInteger av_div_i(AVInteger a, AVInteger b); |
|
| 44 |
-AVInteger av_int2i(int64_t a); |
|
| 45 |
-int64_t av_i2int(AVInteger a); |
|
| 46 |
- |
|
| 47 |
-#endif // INTEGER_H |
| 48 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,77 +0,0 @@ |
| 1 |
-/* |
|
| 2 |
- * Rational numbers |
|
| 3 |
- * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at> |
|
| 4 |
- * |
|
| 5 |
- * This library is free software; you can redistribute it and/or |
|
| 6 |
- * modify it under the terms of the GNU Lesser General Public |
|
| 7 |
- * License as published by the Free Software Foundation; either |
|
| 8 |
- * version 2 of the License, or (at your option) any later version. |
|
| 9 |
- * |
|
| 10 |
- * This library is distributed in the hope that it will be useful, |
|
| 11 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 12 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
| 13 |
- * Lesser General Public License for more details. |
|
| 14 |
- * |
|
| 15 |
- * You should have received a copy of the GNU Lesser General Public |
|
| 16 |
- * License along with this library; if not, write to the Free Software |
|
| 17 |
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
| 18 |
- * |
|
| 19 |
- */ |
|
| 20 |
- |
|
| 21 |
-/** |
|
| 22 |
- * @file rational.c |
|
| 23 |
- * Rational numbers |
|
| 24 |
- * @author Michael Niedermayer <michaelni@gmx.at> |
|
| 25 |
- */ |
|
| 26 |
- |
|
| 27 |
-//#include <math.h> |
|
| 28 |
-#include <limits.h> |
|
| 29 |
- |
|
| 30 |
-#include "common.h" |
|
| 31 |
-#include "avcodec.h" |
|
| 32 |
-#include "rational.h" |
|
| 33 |
- |
|
| 34 |
-/** |
|
| 35 |
- * returns b*c. |
|
| 36 |
- */ |
|
| 37 |
-AVRational av_mul_q(AVRational b, AVRational c){
|
|
| 38 |
- av_reduce(&b.num, &b.den, b.num * (int64_t)c.num, b.den * (int64_t)c.den, INT_MAX); |
|
| 39 |
- return b; |
|
| 40 |
-} |
|
| 41 |
- |
|
| 42 |
-/** |
|
| 43 |
- * returns b/c. |
|
| 44 |
- */ |
|
| 45 |
-AVRational av_div_q(AVRational b, AVRational c){
|
|
| 46 |
- av_reduce(&b.num, &b.den, b.num * (int64_t)c.den, b.den * (int64_t)c.num, INT_MAX); |
|
| 47 |
- return b; |
|
| 48 |
-} |
|
| 49 |
- |
|
| 50 |
-/** |
|
| 51 |
- * returns b+c. |
|
| 52 |
- */ |
|
| 53 |
-AVRational av_add_q(AVRational b, AVRational c){
|
|
| 54 |
- 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); |
|
| 55 |
- return b; |
|
| 56 |
-} |
|
| 57 |
- |
|
| 58 |
-/** |
|
| 59 |
- * returns b-c. |
|
| 60 |
- */ |
|
| 61 |
-AVRational av_sub_q(AVRational b, AVRational c){
|
|
| 62 |
- 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); |
|
| 63 |
- return b; |
|
| 64 |
-} |
|
| 65 |
- |
|
| 66 |
-/** |
|
| 67 |
- * Converts a double precission floating point number to a AVRational. |
|
| 68 |
- * @param max the maximum allowed numerator and denominator |
|
| 69 |
- */ |
|
| 70 |
-AVRational av_d2q(double d, int max){
|
|
| 71 |
- AVRational a; |
|
| 72 |
- int exponent= FFMAX( (int)(log(ABS(d) + 1e-20)/log(2)), 0); |
|
| 73 |
- int64_t den= 1LL << (61 - exponent); |
|
| 74 |
- av_reduce(&a.num, &a.den, (int64_t)(d * den + 0.5), den, max); |
|
| 75 |
- |
|
| 76 |
- return a; |
|
| 77 |
-} |
| 78 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,61 +0,0 @@ |
| 1 |
-/* |
|
| 2 |
- * Rational numbers |
|
| 3 |
- * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at> |
|
| 4 |
- * |
|
| 5 |
- * This library is free software; you can redistribute it and/or |
|
| 6 |
- * modify it under the terms of the GNU Lesser General Public |
|
| 7 |
- * License as published by the Free Software Foundation; either |
|
| 8 |
- * version 2 of the License, or (at your option) any later version. |
|
| 9 |
- * |
|
| 10 |
- * This library is distributed in the hope that it will be useful, |
|
| 11 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 12 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
| 13 |
- * Lesser General Public License for more details. |
|
| 14 |
- * |
|
| 15 |
- * You should have received a copy of the GNU Lesser General Public |
|
| 16 |
- * License along with this library; if not, write to the Free Software |
|
| 17 |
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
| 18 |
- * |
|
| 19 |
- */ |
|
| 20 |
- |
|
| 21 |
-/** |
|
| 22 |
- * @file rational.h |
|
| 23 |
- * Rational numbers. |
|
| 24 |
- * @author Michael Niedermayer <michaelni@gmx.at> |
|
| 25 |
- */ |
|
| 26 |
- |
|
| 27 |
-#ifndef RATIONAL_H |
|
| 28 |
-#define RATIONAL_H |
|
| 29 |
- |
|
| 30 |
-/** |
|
| 31 |
- * Rational number num/den. |
|
| 32 |
- */ |
|
| 33 |
-typedef struct AVRational{
|
|
| 34 |
- int num; ///< numerator |
|
| 35 |
- int den; ///< denominator |
|
| 36 |
-} AVRational; |
|
| 37 |
- |
|
| 38 |
-/** |
|
| 39 |
- * returns 0 if a==b, 1 if a>b and -1 if a<b. |
|
| 40 |
- */ |
|
| 41 |
-static inline int av_cmp_q(AVRational a, AVRational b){
|
|
| 42 |
- const int64_t tmp= a.num * (int64_t)b.den - b.num * (int64_t)a.den; |
|
| 43 |
- |
|
| 44 |
- if(tmp) return (tmp>>63)|1; |
|
| 45 |
- else return 0; |
|
| 46 |
-} |
|
| 47 |
- |
|
| 48 |
-/** |
|
| 49 |
- * converts the given AVRational to a double. |
|
| 50 |
- */ |
|
| 51 |
-static inline double av_q2d(AVRational a){
|
|
| 52 |
- return a.num / (double) a.den; |
|
| 53 |
-} |
|
| 54 |
- |
|
| 55 |
-AVRational av_mul_q(AVRational b, AVRational c); |
|
| 56 |
-AVRational av_div_q(AVRational b, AVRational c); |
|
| 57 |
-AVRational av_add_q(AVRational b, AVRational c); |
|
| 58 |
-AVRational av_sub_q(AVRational b, AVRational c); |
|
| 59 |
-AVRational av_d2q(double d, int max); |
|
| 60 |
- |
|
| 61 |
-#endif // RATIONAL_H |
| ... | ... |
@@ -31,24 +31,6 @@ |
| 31 | 31 |
#include <stdarg.h> |
| 32 | 32 |
#include <limits.h> |
| 33 | 33 |
|
| 34 |
-const uint8_t ff_sqrt_tab[128]={
|
|
| 35 |
- 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, |
|
| 36 |
- 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, |
|
| 37 |
- 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, |
|
| 38 |
- 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 |
|
| 39 |
-}; |
|
| 40 |
- |
|
| 41 |
-const uint8_t ff_log2_tab[256]={
|
|
| 42 |
- 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, |
|
| 43 |
- 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, |
|
| 44 |
- 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, |
|
| 45 |
- 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, |
|
| 46 |
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, |
|
| 47 |
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, |
|
| 48 |
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, |
|
| 49 |
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7 |
|
| 50 |
-}; |
|
| 51 |
- |
|
| 52 | 34 |
const uint8_t ff_reverse[256]={
|
| 53 | 35 |
0x00,0x80,0x40,0xC0,0x20,0xA0,0x60,0xE0,0x10,0x90,0x50,0xD0,0x30,0xB0,0x70,0xF0, |
| 54 | 36 |
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){
|
| 938 | 938 |
} |
| 939 | 939 |
} |
| 940 | 940 |
|
| 941 |
-int av_reduce(int *dst_nom, int *dst_den, int64_t nom, int64_t den, int64_t max){
|
|
| 942 |
- AVRational a0={0,1}, a1={1,0};
|
|
| 943 |
- int sign= (nom<0) ^ (den<0); |
|
| 944 |
- int64_t gcd= ff_gcd(ABS(nom), ABS(den)); |
|
| 945 |
- |
|
| 946 |
- nom = ABS(nom)/gcd; |
|
| 947 |
- den = ABS(den)/gcd; |
|
| 948 |
- if(nom<=max && den<=max){
|
|
| 949 |
- a1= (AVRational){nom, den};
|
|
| 950 |
- den=0; |
|
| 951 |
- } |
|
| 952 |
- |
|
| 953 |
- while(den){
|
|
| 954 |
- int64_t x = nom / den; |
|
| 955 |
- int64_t next_den= nom - den*x; |
|
| 956 |
- int64_t a2n= x*a1.num + a0.num; |
|
| 957 |
- int64_t a2d= x*a1.den + a0.den; |
|
| 958 |
- |
|
| 959 |
- if(a2n > max || a2d > max) break; |
|
| 960 |
- |
|
| 961 |
- a0= a1; |
|
| 962 |
- a1= (AVRational){a2n, a2d};
|
|
| 963 |
- nom= den; |
|
| 964 |
- den= next_den; |
|
| 965 |
- } |
|
| 966 |
- assert(ff_gcd(a1.num, a1.den) == 1); |
|
| 967 |
- |
|
| 968 |
- *dst_nom = sign ? -a1.num : a1.num; |
|
| 969 |
- *dst_den = a1.den; |
|
| 970 |
- |
|
| 971 |
- return den==0; |
|
| 972 |
-} |
|
| 973 |
- |
|
| 974 |
-int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding rnd){
|
|
| 975 |
- AVInteger ai; |
|
| 976 |
- int64_t r=0; |
|
| 977 |
- assert(c > 0); |
|
| 978 |
- assert(b >=0); |
|
| 979 |
- assert(rnd >=0 && rnd<=5 && rnd!=4); |
|
| 980 |
- |
|
| 981 |
- if(a<0 && a != INT64_MIN) return -av_rescale_rnd(-a, b, c, rnd ^ ((rnd>>1)&1)); |
|
| 982 |
- |
|
| 983 |
- if(rnd==AV_ROUND_NEAR_INF) r= c/2; |
|
| 984 |
- else if(rnd&1) r= c-1; |
|
| 985 |
- |
|
| 986 |
- if(b<=INT_MAX && c<=INT_MAX){
|
|
| 987 |
- if(a<=INT_MAX) |
|
| 988 |
- return (a * b + r)/c; |
|
| 989 |
- else |
|
| 990 |
- return a/c*b + (a%c*b + r)/c; |
|
| 991 |
- } |
|
| 992 |
- |
|
| 993 |
- ai= av_mul_i(av_int2i(a), av_int2i(b)); |
|
| 994 |
- ai= av_add_i(ai, av_int2i(r)); |
|
| 995 |
- |
|
| 996 |
- return av_i2int(av_div_i(ai, av_int2i(c))); |
|
| 997 |
-} |
|
| 998 |
- |
|
| 999 |
-int64_t av_rescale(int64_t a, int64_t b, int64_t c){
|
|
| 1000 |
- return av_rescale_rnd(a, b, c, AV_ROUND_NEAR_INF); |
|
| 1001 |
-} |
|
| 1002 |
- |
|
| 1003 |
-int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq){
|
|
| 1004 |
- int64_t b= bq.num * (int64_t)cq.den; |
|
| 1005 |
- int64_t c= cq.num * (int64_t)bq.den; |
|
| 1006 |
- return av_rescale_rnd(a, b, c, AV_ROUND_NEAR_INF); |
|
| 1007 |
-} |
|
| 1008 |
- |
|
| 1009 |
-int64_t ff_gcd(int64_t a, int64_t b){
|
|
| 1010 |
- if(b) return ff_gcd(b, a%b); |
|
| 1011 |
- else return a; |
|
| 1012 |
-} |
|
| 1013 |
- |
|
| 1014 |
-double av_int2dbl(int64_t v){
|
|
| 1015 |
- if(v+v > 0xFFELLU<<52) |
|
| 1016 |
- return 0.0/0.0; |
|
| 1017 |
- return ldexp(((v&(1LL<<52)-1) + (1LL<<52)) * (v>>63|1), (v>>52&0x7FF)-1075); |
|
| 1018 |
-} |
|
| 1019 |
- |
|
| 1020 |
-float av_int2flt(int32_t v){
|
|
| 1021 |
- if(v+v > 0xFF000000U) |
|
| 1022 |
- return 0.0/0.0; |
|
| 1023 |
- return ldexp(((v&0x7FFFFF) + (1<<23)) * (v>>31|1), (v>>23&0xFF)-150); |
|
| 1024 |
-} |
|
| 1025 |
- |
|
| 1026 |
-int64_t av_dbl2int(double d){
|
|
| 1027 |
- int e; |
|
| 1028 |
- if ( !d) return 0; |
|
| 1029 |
- else if(d-d) return 0x7FF0000000000000LL + ((int64_t)(d<0)<<63) + (d!=d); |
|
| 1030 |
- d= frexp(d, &e); |
|
| 1031 |
- return (int64_t)(d<0)<<63 | (e+1022LL)<<52 | (int64_t)((fabs(d)-0.5)*(1LL<<53)); |
|
| 1032 |
-} |
|
| 1033 |
- |
|
| 1034 |
-int32_t av_flt2int(float d){
|
|
| 1035 |
- int e; |
|
| 1036 |
- if ( !d) return 0; |
|
| 1037 |
- else if(d-d) return 0x7F800000 + ((d<0)<<31) + (d!=d); |
|
| 1038 |
- d= frexp(d, &e); |
|
| 1039 |
- return (d<0)<<31 | (e+126)<<23 | (int64_t)((fabs(d)-0.5)*(1<<24)); |
|
| 1040 |
-} |
|
| 1041 |
- |
|
| 1042 | 941 |
/* av_log API */ |
| 1043 | 942 |
|
| 1044 | 943 |
static int av_log_level = AV_LOG_INFO; |
| ... | ... |
@@ -6,7 +6,7 @@ include ../config.mak |
| 6 | 6 |
|
| 7 | 7 |
VPATH=$(SRC_PATH)/libavformat |
| 8 | 8 |
|
| 9 |
-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 |
|
| 9 |
+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 |
|
| 10 | 10 |
|
| 11 | 11 |
OBJS= utils.o cutils.o os_support.o allformats.o |
| 12 | 12 |
PPOBJS= |
| 13 | 13 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,92 @@ |
| 0 |
+# |
|
| 1 |
+# libavutil Makefile |
|
| 2 |
+# |
|
| 3 |
+include ../config.mak |
|
| 4 |
+ |
|
| 5 |
+VPATH=$(SRC_PATH)/libavutil |
|
| 6 |
+ |
|
| 7 |
+# NOTE: -I.. is needed to include config.h |
|
| 8 |
+CFLAGS=$(OPTFLAGS) -DHAVE_AV_CONFIG_H -I.. -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE |
|
| 9 |
+ |
|
| 10 |
+OBJS= mathematics.o \ |
|
| 11 |
+ integer.o \ |
|
| 12 |
+ rational.o \ |
|
| 13 |
+ intfloat_readwrite.o \ |
|
| 14 |
+ |
|
| 15 |
+ |
|
| 16 |
+ifeq ($(TARGET_ARCH_SPARC64),yes) |
|
| 17 |
+CFLAGS+= -mcpu=ultrasparc -mtune=ultrasparc |
|
| 18 |
+endif |
|
| 19 |
+ |
|
| 20 |
+SRCS := $(OBJS:.o=.c) |
|
| 21 |
+ |
|
| 22 |
+LIB= $(LIBPREF)avutil$(LIBSUF) |
|
| 23 |
+ifeq ($(BUILD_SHARED),yes) |
|
| 24 |
+SLIB= $(SLIBPREF)avutil$(SLIBSUF) |
|
| 25 |
+endif |
|
| 26 |
+ |
|
| 27 |
+all: $(LIB) $(SLIB) |
|
| 28 |
+ |
|
| 29 |
+$(LIB): $(OBJS) |
|
| 30 |
+ rm -f $@ |
|
| 31 |
+ $(AR) rc $@ $(OBJS) |
|
| 32 |
+ $(RANLIB) $@ |
|
| 33 |
+ |
|
| 34 |
+$(SLIB): $(OBJS) |
|
| 35 |
+ifeq ($(CONFIG_WIN32),yes) |
|
| 36 |
+ $(CC) $(SHFLAGS) -Wl,--output-def,$(@:.dll=.def) -o $@ $(OBJS) $(EXTRALIBS) $(AMREXTRALIBS) |
|
| 37 |
+ -lib /machine:i386 /def:$(@:.dll=.def) |
|
| 38 |
+else |
|
| 39 |
+ $(CC) $(SHFLAGS) -o $@ $(OBJS) $(EXTRALIBS) $(AMREXTRALIBS) $(LDFLAGS) |
|
| 40 |
+endif |
|
| 41 |
+ |
|
| 42 |
+%.o: %.c |
|
| 43 |
+ $(CC) $(CFLAGS) $(LIBOBJFLAGS) -c -o $@ $< |
|
| 44 |
+ |
|
| 45 |
+depend: $(SRCS) |
|
| 46 |
+ $(CC) -MM $(CFLAGS) $^ 1>.depend |
|
| 47 |
+ |
|
| 48 |
+dep: depend |
|
| 49 |
+ |
|
| 50 |
+clean: |
|
| 51 |
+ rm -f *.o *.d *~ .depend $(LIB) $(SLIB) *.so |
|
| 52 |
+ |
|
| 53 |
+distclean: clean |
|
| 54 |
+ rm -f Makefile.bak .depend |
|
| 55 |
+ |
|
| 56 |
+ |
|
| 57 |
+ifeq ($(BUILD_SHARED),yes) |
|
| 58 |
+install: all install-headers |
|
| 59 |
+ifeq ($(CONFIG_WIN32),yes) |
|
| 60 |
+ install $(INSTALLSTRIP) -m 755 $(SLIB) "$(prefix)" |
|
| 61 |
+else |
|
| 62 |
+ install -d $(libdir) |
|
| 63 |
+ install $(INSTALLSTRIP) -m 755 $(SLIB) $(libdir)/libavutil-$(VERSION).so |
|
| 64 |
+ ln -sf libavutil-$(VERSION).so $(libdir)/libavutil.so |
|
| 65 |
+ $(LDCONFIG) || true |
|
| 66 |
+endif |
|
| 67 |
+else |
|
| 68 |
+install: |
|
| 69 |
+endif |
|
| 70 |
+ |
|
| 71 |
+installlib: all install-headers |
|
| 72 |
+ install -m 644 $(LIB) "$(libdir)" |
|
| 73 |
+ |
|
| 74 |
+install-headers: |
|
| 75 |
+ mkdir -p "$(prefix)/include/ffmpeg" |
|
| 76 |
+ install -m 644 $(SRC_PATH)/libavutil/avutil.h \ |
|
| 77 |
+ $(SRC_PATH)/libavutil/common.h \ |
|
| 78 |
+ $(SRC_PATH)/libavutil/mathematics.h \ |
|
| 79 |
+ $(SRC_PATH)/libavutil/integer.h \ |
|
| 80 |
+ $(SRC_PATH)/libavutil/rational.h \ |
|
| 81 |
+ $(SRC_PATH)/libavutil/intfloat_readwrite.h \ |
|
| 82 |
+ "$(prefix)/include/ffmpeg" |
|
| 83 |
+# install -d $(libdir)/pkgconfig |
|
| 84 |
+# install -m 644 ../libavutil.pc $(libdir)/pkgconfig |
|
| 85 |
+ |
|
| 86 |
+# |
|
| 87 |
+# include dependency files if they exist |
|
| 88 |
+# |
|
| 89 |
+ifneq ($(wildcard .depend),) |
|
| 90 |
+include .depend |
|
| 91 |
+endif |
| 0 | 92 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,34 @@ |
| 0 |
+#ifndef AVUTIL_H |
|
| 1 |
+#define AVUTIL_H |
|
| 2 |
+ |
|
| 3 |
+/** |
|
| 4 |
+ * @file avutil.h |
|
| 5 |
+ * external api header. |
|
| 6 |
+ */ |
|
| 7 |
+ |
|
| 8 |
+ |
|
| 9 |
+#ifdef __cplusplus |
|
| 10 |
+extern "C" {
|
|
| 11 |
+#endif |
|
| 12 |
+ |
|
| 13 |
+#define AV_STRINGIFY(s) AV_TOSTRING(s) |
|
| 14 |
+#define AV_TOSTRING(s) #s |
|
| 15 |
+ |
|
| 16 |
+#define LIBAVUTIL_VERSION_INT ((49<<16)+(0<<8)+0) |
|
| 17 |
+#define LIBAVUTIL_VERSION 49.0.0 |
|
| 18 |
+#define LIBAVUTIL_BUILD LIBAVUTIL_VERSION_INT |
|
| 19 |
+ |
|
| 20 |
+#define LIBAVUTIL_IDENT "Lavu" AV_STRINGIFY(LIBAVUTIL_VERSION) |
|
| 21 |
+ |
|
| 22 |
+ |
|
| 23 |
+#include "common.h" |
|
| 24 |
+#include "mathematics.h" |
|
| 25 |
+#include "rational.h" |
|
| 26 |
+#include "integer.h" |
|
| 27 |
+#include "intfloat_readwrite.h" |
|
| 28 |
+ |
|
| 29 |
+#ifdef __cplusplus |
|
| 30 |
+} |
|
| 31 |
+#endif |
|
| 32 |
+ |
|
| 33 |
+#endif /* AVUTIL_H */ |
| 0 | 34 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,155 @@ |
| 0 |
+/** |
|
| 1 |
+ * @file bswap.h |
|
| 2 |
+ * byte swap. |
|
| 3 |
+ */ |
|
| 4 |
+ |
|
| 5 |
+#ifndef __BSWAP_H__ |
|
| 6 |
+#define __BSWAP_H__ |
|
| 7 |
+ |
|
| 8 |
+#ifdef HAVE_BYTESWAP_H |
|
| 9 |
+#include <byteswap.h> |
|
| 10 |
+#else |
|
| 11 |
+ |
|
| 12 |
+#ifdef ARCH_X86_64 |
|
| 13 |
+# define LEGACY_REGS "=Q" |
|
| 14 |
+#else |
|
| 15 |
+# define LEGACY_REGS "=q" |
|
| 16 |
+#endif |
|
| 17 |
+ |
|
| 18 |
+#if defined(ARCH_X86) || defined(ARCH_X86_64) |
|
| 19 |
+static always_inline uint16_t bswap_16(uint16_t x) |
|
| 20 |
+{
|
|
| 21 |
+ __asm("rorw $8, %0" :
|
|
| 22 |
+ LEGACY_REGS (x) : |
|
| 23 |
+ "0" (x)); |
|
| 24 |
+ return x; |
|
| 25 |
+} |
|
| 26 |
+ |
|
| 27 |
+static always_inline uint32_t bswap_32(uint32_t x) |
|
| 28 |
+{
|
|
| 29 |
+#if __CPU__ > 386 |
|
| 30 |
+ __asm("bswap %0":
|
|
| 31 |
+ "=r" (x) : |
|
| 32 |
+#else |
|
| 33 |
+ __asm("xchgb %b0,%h0\n"
|
|
| 34 |
+ " rorl $16,%0\n" |
|
| 35 |
+ " xchgb %b0,%h0": |
|
| 36 |
+ LEGACY_REGS (x) : |
|
| 37 |
+#endif |
|
| 38 |
+ "0" (x)); |
|
| 39 |
+ return x; |
|
| 40 |
+} |
|
| 41 |
+ |
|
| 42 |
+static inline uint64_t bswap_64(uint64_t x) |
|
| 43 |
+{
|
|
| 44 |
+#ifdef ARCH_X86_64 |
|
| 45 |
+ __asm("bswap %0":
|
|
| 46 |
+ "=r" (x) : |
|
| 47 |
+ "0" (x)); |
|
| 48 |
+ return x; |
|
| 49 |
+#else |
|
| 50 |
+ union {
|
|
| 51 |
+ uint64_t ll; |
|
| 52 |
+ struct {
|
|
| 53 |
+ uint32_t l,h; |
|
| 54 |
+ } l; |
|
| 55 |
+ } r; |
|
| 56 |
+ r.l.l = bswap_32 (x); |
|
| 57 |
+ r.l.h = bswap_32 (x>>32); |
|
| 58 |
+ return r.ll; |
|
| 59 |
+#endif |
|
| 60 |
+} |
|
| 61 |
+ |
|
| 62 |
+#elif defined(ARCH_SH4) |
|
| 63 |
+ |
|
| 64 |
+static always_inline uint16_t bswap_16(uint16_t x) {
|
|
| 65 |
+ __asm__("swap.b %0,%0":"=r"(x):"0"(x));
|
|
| 66 |
+ return x; |
|
| 67 |
+} |
|
| 68 |
+ |
|
| 69 |
+static always_inline uint32_t bswap_32(uint32_t x) {
|
|
| 70 |
+ __asm__( |
|
| 71 |
+ "swap.b %0,%0\n" |
|
| 72 |
+ "swap.w %0,%0\n" |
|
| 73 |
+ "swap.b %0,%0\n" |
|
| 74 |
+ :"=r"(x):"0"(x)); |
|
| 75 |
+ return x; |
|
| 76 |
+} |
|
| 77 |
+ |
|
| 78 |
+static inline uint64_t bswap_64(uint64_t x) |
|
| 79 |
+{
|
|
| 80 |
+ union {
|
|
| 81 |
+ uint64_t ll; |
|
| 82 |
+ struct {
|
|
| 83 |
+ uint32_t l,h; |
|
| 84 |
+ } l; |
|
| 85 |
+ } r; |
|
| 86 |
+ r.l.l = bswap_32 (x); |
|
| 87 |
+ r.l.h = bswap_32 (x>>32); |
|
| 88 |
+ return r.ll; |
|
| 89 |
+} |
|
| 90 |
+#else |
|
| 91 |
+ |
|
| 92 |
+static always_inline uint16_t bswap_16(uint16_t x){
|
|
| 93 |
+ return (x>>8) | (x<<8); |
|
| 94 |
+} |
|
| 95 |
+ |
|
| 96 |
+#ifdef ARCH_ARM |
|
| 97 |
+static always_inline uint32_t bswap_32(uint32_t x){
|
|
| 98 |
+ uint32_t t; |
|
| 99 |
+ __asm__ ( |
|
| 100 |
+ "eor %1, %0, %0, ror #16 \n\t" |
|
| 101 |
+ "bic %1, %1, #0xFF0000 \n\t" |
|
| 102 |
+ "mov %0, %0, ror #8 \n\t" |
|
| 103 |
+ "eor %0, %0, %1, lsr #8 \n\t" |
|
| 104 |
+ : "+r"(x), "+r"(t)); |
|
| 105 |
+ return x; |
|
| 106 |
+} |
|
| 107 |
+#else |
|
| 108 |
+static always_inline uint32_t bswap_32(uint32_t x){
|
|
| 109 |
+ x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF); |
|
| 110 |
+ return (x>>16) | (x<<16); |
|
| 111 |
+} |
|
| 112 |
+#endif |
|
| 113 |
+ |
|
| 114 |
+static inline uint64_t bswap_64(uint64_t x) |
|
| 115 |
+{
|
|
| 116 |
+#if 0 |
|
| 117 |
+ x= ((x<< 8)&0xFF00FF00FF00FF00ULL) | ((x>> 8)&0x00FF00FF00FF00FFULL); |
|
| 118 |
+ x= ((x<<16)&0xFFFF0000FFFF0000ULL) | ((x>>16)&0x0000FFFF0000FFFFULL); |
|
| 119 |
+ return (x>>32) | (x<<32); |
|
| 120 |
+#else |
|
| 121 |
+ union {
|
|
| 122 |
+ uint64_t ll; |
|
| 123 |
+ uint32_t l[2]; |
|
| 124 |
+ } w, r; |
|
| 125 |
+ w.ll = x; |
|
| 126 |
+ r.l[0] = bswap_32 (w.l[1]); |
|
| 127 |
+ r.l[1] = bswap_32 (w.l[0]); |
|
| 128 |
+ return r.ll; |
|
| 129 |
+#endif |
|
| 130 |
+} |
|
| 131 |
+#endif /* !ARCH_X86 */ |
|
| 132 |
+ |
|
| 133 |
+#endif /* !HAVE_BYTESWAP_H */ |
|
| 134 |
+ |
|
| 135 |
+// be2me ... BigEndian to MachineEndian |
|
| 136 |
+// le2me ... LittleEndian to MachineEndian |
|
| 137 |
+ |
|
| 138 |
+#ifdef WORDS_BIGENDIAN |
|
| 139 |
+#define be2me_16(x) (x) |
|
| 140 |
+#define be2me_32(x) (x) |
|
| 141 |
+#define be2me_64(x) (x) |
|
| 142 |
+#define le2me_16(x) bswap_16(x) |
|
| 143 |
+#define le2me_32(x) bswap_32(x) |
|
| 144 |
+#define le2me_64(x) bswap_64(x) |
|
| 145 |
+#else |
|
| 146 |
+#define be2me_16(x) bswap_16(x) |
|
| 147 |
+#define be2me_32(x) bswap_32(x) |
|
| 148 |
+#define be2me_64(x) bswap_64(x) |
|
| 149 |
+#define le2me_16(x) (x) |
|
| 150 |
+#define le2me_32(x) (x) |
|
| 151 |
+#define le2me_64(x) (x) |
|
| 152 |
+#endif |
|
| 153 |
+ |
|
| 154 |
+#endif /* __BSWAP_H__ */ |
| 0 | 155 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,548 @@ |
| 0 |
+/** |
|
| 1 |
+ * @file common.h |
|
| 2 |
+ * common internal api header. |
|
| 3 |
+ */ |
|
| 4 |
+ |
|
| 5 |
+#ifndef COMMON_H |
|
| 6 |
+#define COMMON_H |
|
| 7 |
+ |
|
| 8 |
+#if defined(WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__) |
|
| 9 |
+# define CONFIG_WIN32 |
|
| 10 |
+#endif |
|
| 11 |
+ |
|
| 12 |
+#ifndef M_PI |
|
| 13 |
+#define M_PI 3.14159265358979323846 |
|
| 14 |
+#endif |
|
| 15 |
+ |
|
| 16 |
+#ifdef HAVE_AV_CONFIG_H |
|
| 17 |
+/* only include the following when compiling package */ |
|
| 18 |
+# include "config.h" |
|
| 19 |
+ |
|
| 20 |
+# include <stdlib.h> |
|
| 21 |
+# include <stdio.h> |
|
| 22 |
+# include <string.h> |
|
| 23 |
+# include <ctype.h> |
|
| 24 |
+# include <limits.h> |
|
| 25 |
+# ifndef __BEOS__ |
|
| 26 |
+# include <errno.h> |
|
| 27 |
+# else |
|
| 28 |
+# include "berrno.h" |
|
| 29 |
+# endif |
|
| 30 |
+# include <math.h> |
|
| 31 |
+ |
|
| 32 |
+# ifndef ENODATA |
|
| 33 |
+# define ENODATA 61 |
|
| 34 |
+# endif |
|
| 35 |
+ |
|
| 36 |
+#include <stddef.h> |
|
| 37 |
+#ifndef offsetof |
|
| 38 |
+# define offsetof(T,F) ((unsigned int)((char *)&((T *)0)->F)) |
|
| 39 |
+#endif |
|
| 40 |
+ |
|
| 41 |
+#define AVOPTION_CODEC_BOOL(name, help, field) \ |
|
| 42 |
+ { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_BOOL }
|
|
| 43 |
+#define AVOPTION_CODEC_DOUBLE(name, help, field, minv, maxv, defval) \ |
|
| 44 |
+ { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_DOUBLE, minv, maxv, defval }
|
|
| 45 |
+#define AVOPTION_CODEC_FLAG(name, help, field, flag, defval) \ |
|
| 46 |
+ { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_FLAG, flag, 0, defval }
|
|
| 47 |
+#define AVOPTION_CODEC_INT(name, help, field, minv, maxv, defval) \ |
|
| 48 |
+ { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_INT, minv, maxv, defval }
|
|
| 49 |
+#define AVOPTION_CODEC_STRING(name, help, field, str, val) \ |
|
| 50 |
+ { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_STRING, .defval = val, .defstr = str }
|
|
| 51 |
+#define AVOPTION_CODEC_RCOVERRIDE(name, help, field) \ |
|
| 52 |
+ { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_RCOVERRIDE, .defval = 0, .defstr = NULL }
|
|
| 53 |
+#define AVOPTION_SUB(ptr) { .name = NULL, .help = (const char*)ptr }
|
|
| 54 |
+#define AVOPTION_END() AVOPTION_SUB(NULL) |
|
| 55 |
+ |
|
| 56 |
+#endif /* HAVE_AV_CONFIG_H */ |
|
| 57 |
+ |
|
| 58 |
+/* Suppress restrict if it was not defined in config.h. */ |
|
| 59 |
+#ifndef restrict |
|
| 60 |
+# define restrict |
|
| 61 |
+#endif |
|
| 62 |
+ |
|
| 63 |
+#ifndef always_inline |
|
| 64 |
+#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0) |
|
| 65 |
+# define always_inline __attribute__((always_inline)) inline |
|
| 66 |
+#else |
|
| 67 |
+# define always_inline inline |
|
| 68 |
+#endif |
|
| 69 |
+#endif |
|
| 70 |
+ |
|
| 71 |
+#ifndef attribute_used |
|
| 72 |
+#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0) |
|
| 73 |
+# define attribute_used __attribute__((used)) |
|
| 74 |
+#else |
|
| 75 |
+# define attribute_used |
|
| 76 |
+#endif |
|
| 77 |
+#endif |
|
| 78 |
+ |
|
| 79 |
+#ifndef attribute_unused |
|
| 80 |
+#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0) |
|
| 81 |
+# define attribute_unused __attribute__((unused)) |
|
| 82 |
+#else |
|
| 83 |
+# define attribute_unused |
|
| 84 |
+#endif |
|
| 85 |
+#endif |
|
| 86 |
+ |
|
| 87 |
+#ifndef EMULATE_INTTYPES |
|
| 88 |
+# include <inttypes.h> |
|
| 89 |
+#else |
|
| 90 |
+ typedef signed char int8_t; |
|
| 91 |
+ typedef signed short int16_t; |
|
| 92 |
+ typedef signed int int32_t; |
|
| 93 |
+ typedef unsigned char uint8_t; |
|
| 94 |
+ typedef unsigned short uint16_t; |
|
| 95 |
+ typedef unsigned int uint32_t; |
|
| 96 |
+ |
|
| 97 |
+# ifdef CONFIG_WIN32 |
|
| 98 |
+ typedef signed __int64 int64_t; |
|
| 99 |
+ typedef unsigned __int64 uint64_t; |
|
| 100 |
+# else /* other OS */ |
|
| 101 |
+ typedef signed long long int64_t; |
|
| 102 |
+ typedef unsigned long long uint64_t; |
|
| 103 |
+# endif /* other OS */ |
|
| 104 |
+#endif /* HAVE_INTTYPES_H */ |
|
| 105 |
+ |
|
| 106 |
+#ifndef INT16_MIN |
|
| 107 |
+#define INT16_MIN (-0x7fff-1) |
|
| 108 |
+#endif |
|
| 109 |
+ |
|
| 110 |
+#ifndef INT16_MAX |
|
| 111 |
+#define INT16_MAX 0x7fff |
|
| 112 |
+#endif |
|
| 113 |
+ |
|
| 114 |
+#ifndef INT64_MIN |
|
| 115 |
+#define INT64_MIN (-0x7fffffffffffffffLL-1) |
|
| 116 |
+#endif |
|
| 117 |
+ |
|
| 118 |
+#ifndef INT64_MAX |
|
| 119 |
+#define INT64_MAX int64_t_C(9223372036854775807) |
|
| 120 |
+#endif |
|
| 121 |
+ |
|
| 122 |
+#ifndef UINT64_MAX |
|
| 123 |
+#define UINT64_MAX uint64_t_C(0xFFFFFFFFFFFFFFFF) |
|
| 124 |
+#endif |
|
| 125 |
+ |
|
| 126 |
+#ifdef EMULATE_FAST_INT |
|
| 127 |
+typedef signed char int_fast8_t; |
|
| 128 |
+typedef signed int int_fast16_t; |
|
| 129 |
+typedef signed int int_fast32_t; |
|
| 130 |
+typedef unsigned char uint_fast8_t; |
|
| 131 |
+typedef unsigned int uint_fast16_t; |
|
| 132 |
+typedef unsigned int uint_fast32_t; |
|
| 133 |
+typedef uint64_t uint_fast64_t; |
|
| 134 |
+#endif |
|
| 135 |
+ |
|
| 136 |
+#ifndef INT_BIT |
|
| 137 |
+# if INT_MAX != 2147483647 |
|
| 138 |
+# define INT_BIT 64 |
|
| 139 |
+# else |
|
| 140 |
+# define INT_BIT 32 |
|
| 141 |
+# endif |
|
| 142 |
+#endif |
|
| 143 |
+ |
|
| 144 |
+#if defined(CONFIG_OS2) || defined(CONFIG_SUNOS) |
|
| 145 |
+static inline float floorf(float f) {
|
|
| 146 |
+ return floor(f); |
|
| 147 |
+} |
|
| 148 |
+#endif |
|
| 149 |
+ |
|
| 150 |
+#ifdef CONFIG_WIN32 |
|
| 151 |
+ |
|
| 152 |
+/* windows */ |
|
| 153 |
+ |
|
| 154 |
+# if !defined(__MINGW32__) && !defined(__CYGWIN__) |
|
| 155 |
+# define int64_t_C(c) (c ## i64) |
|
| 156 |
+# define uint64_t_C(c) (c ## i64) |
|
| 157 |
+ |
|
| 158 |
+# ifdef HAVE_AV_CONFIG_H |
|
| 159 |
+# define inline __inline |
|
| 160 |
+# endif |
|
| 161 |
+ |
|
| 162 |
+# else |
|
| 163 |
+# define int64_t_C(c) (c ## LL) |
|
| 164 |
+# define uint64_t_C(c) (c ## ULL) |
|
| 165 |
+# endif /* __MINGW32__ */ |
|
| 166 |
+ |
|
| 167 |
+# ifdef HAVE_AV_CONFIG_H |
|
| 168 |
+# ifdef _DEBUG |
|
| 169 |
+# define DEBUG |
|
| 170 |
+# endif |
|
| 171 |
+ |
|
| 172 |
+# define snprintf _snprintf |
|
| 173 |
+# define vsnprintf _vsnprintf |
|
| 174 |
+# endif |
|
| 175 |
+ |
|
| 176 |
+/* CONFIG_WIN32 end */ |
|
| 177 |
+#elif defined (CONFIG_OS2) |
|
| 178 |
+/* OS/2 EMX */ |
|
| 179 |
+ |
|
| 180 |
+#ifndef int64_t_C |
|
| 181 |
+#define int64_t_C(c) (c ## LL) |
|
| 182 |
+#define uint64_t_C(c) (c ## ULL) |
|
| 183 |
+#endif |
|
| 184 |
+ |
|
| 185 |
+#ifdef HAVE_AV_CONFIG_H |
|
| 186 |
+ |
|
| 187 |
+#ifdef USE_FASTMEMCPY |
|
| 188 |
+#include "fastmemcpy.h" |
|
| 189 |
+#endif |
|
| 190 |
+ |
|
| 191 |
+#include <float.h> |
|
| 192 |
+ |
|
| 193 |
+#endif /* HAVE_AV_CONFIG_H */ |
|
| 194 |
+ |
|
| 195 |
+/* CONFIG_OS2 end */ |
|
| 196 |
+#else |
|
| 197 |
+ |
|
| 198 |
+/* unix */ |
|
| 199 |
+ |
|
| 200 |
+#ifndef int64_t_C |
|
| 201 |
+#define int64_t_C(c) (c ## LL) |
|
| 202 |
+#define uint64_t_C(c) (c ## ULL) |
|
| 203 |
+#endif |
|
| 204 |
+ |
|
| 205 |
+#ifdef HAVE_AV_CONFIG_H |
|
| 206 |
+ |
|
| 207 |
+# ifdef USE_FASTMEMCPY |
|
| 208 |
+# include "fastmemcpy.h" |
|
| 209 |
+# endif |
|
| 210 |
+# endif /* HAVE_AV_CONFIG_H */ |
|
| 211 |
+ |
|
| 212 |
+#endif /* !CONFIG_WIN32 && !CONFIG_OS2 */ |
|
| 213 |
+ |
|
| 214 |
+#ifdef HAVE_AV_CONFIG_H |
|
| 215 |
+ |
|
| 216 |
+# include "bswap.h" |
|
| 217 |
+ |
|
| 218 |
+// Use rip-relative addressing if compiling PIC code on x86-64. |
|
| 219 |
+# if defined(__MINGW32__) || defined(__CYGWIN__) || \ |
|
| 220 |
+ defined(__OS2__) || (defined (__OpenBSD__) && !defined(__ELF__)) |
|
| 221 |
+# if defined(ARCH_X86_64) && defined(PIC) |
|
| 222 |
+# define MANGLE(a) "_" #a"(%%rip)" |
|
| 223 |
+# else |
|
| 224 |
+# define MANGLE(a) "_" #a |
|
| 225 |
+# endif |
|
| 226 |
+# else |
|
| 227 |
+# if defined(ARCH_X86_64) && defined(PIC) |
|
| 228 |
+# define MANGLE(a) #a"(%%rip)" |
|
| 229 |
+# else |
|
| 230 |
+# define MANGLE(a) #a |
|
| 231 |
+# endif |
|
| 232 |
+# endif |
|
| 233 |
+ |
|
| 234 |
+/* debug stuff */ |
|
| 235 |
+ |
|
| 236 |
+# ifndef DEBUG |
|
| 237 |
+# define NDEBUG |
|
| 238 |
+# endif |
|
| 239 |
+# include <assert.h> |
|
| 240 |
+ |
|
| 241 |
+/* dprintf macros */ |
|
| 242 |
+# if defined(CONFIG_WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__) |
|
| 243 |
+ |
|
| 244 |
+inline void dprintf(const char* fmt,...) {}
|
|
| 245 |
+ |
|
| 246 |
+# else |
|
| 247 |
+ |
|
| 248 |
+# ifdef DEBUG |
|
| 249 |
+# define dprintf(fmt,...) av_log(NULL, AV_LOG_DEBUG, fmt, __VA_ARGS__) |
|
| 250 |
+# else |
|
| 251 |
+# define dprintf(fmt,...) |
|
| 252 |
+# endif |
|
| 253 |
+ |
|
| 254 |
+# endif /* !CONFIG_WIN32 */ |
|
| 255 |
+ |
|
| 256 |
+# define av_abort() do { av_log(NULL, AV_LOG_ERROR, "Abort at %s:%d\n", __FILE__, __LINE__); abort(); } while (0)
|
|
| 257 |
+ |
|
| 258 |
+//rounded divison & shift |
|
| 259 |
+#define RSHIFT(a,b) ((a) > 0 ? ((a) + ((1<<(b))>>1))>>(b) : ((a) + ((1<<(b))>>1)-1)>>(b)) |
|
| 260 |
+/* assume b>0 */ |
|
| 261 |
+#define ROUNDED_DIV(a,b) (((a)>0 ? (a) + ((b)>>1) : (a) - ((b)>>1))/(b)) |
|
| 262 |
+#define ABS(a) ((a) >= 0 ? (a) : (-(a))) |
|
| 263 |
+ |
|
| 264 |
+#define FFMAX(a,b) ((a) > (b) ? (a) : (b)) |
|
| 265 |
+#define FFMIN(a,b) ((a) > (b) ? (b) : (a)) |
|
| 266 |
+ |
|
| 267 |
+extern const uint32_t inverse[256]; |
|
| 268 |
+ |
|
| 269 |
+#if defined(ARCH_X86) || defined(ARCH_X86_64) |
|
| 270 |
+# define FASTDIV(a,b) \ |
|
| 271 |
+ ({\
|
|
| 272 |
+ int ret,dmy;\ |
|
| 273 |
+ asm volatile(\ |
|
| 274 |
+ "mull %3"\ |
|
| 275 |
+ :"=d"(ret),"=a"(dmy)\ |
|
| 276 |
+ :"1"(a),"g"(inverse[b])\ |
|
| 277 |
+ );\ |
|
| 278 |
+ ret;\ |
|
| 279 |
+ }) |
|
| 280 |
+#elif defined(CONFIG_FASTDIV) |
|
| 281 |
+# define FASTDIV(a,b) ((uint32_t)((((uint64_t)a)*inverse[b])>>32)) |
|
| 282 |
+#else |
|
| 283 |
+# define FASTDIV(a,b) ((a)/(b)) |
|
| 284 |
+#endif |
|
| 285 |
+ |
|
| 286 |
+/* define it to include statistics code (useful only for optimizing |
|
| 287 |
+ codec efficiency */ |
|
| 288 |
+//#define STATS |
|
| 289 |
+ |
|
| 290 |
+#ifdef STATS |
|
| 291 |
+ |
|
| 292 |
+enum {
|
|
| 293 |
+ ST_UNKNOWN, |
|
| 294 |
+ ST_DC, |
|
| 295 |
+ ST_INTRA_AC, |
|
| 296 |
+ ST_INTER_AC, |
|
| 297 |
+ ST_INTRA_MB, |
|
| 298 |
+ ST_INTER_MB, |
|
| 299 |
+ ST_MV, |
|
| 300 |
+ ST_NB, |
|
| 301 |
+}; |
|
| 302 |
+ |
|
| 303 |
+extern int st_current_index; |
|
| 304 |
+extern unsigned int st_bit_counts[ST_NB]; |
|
| 305 |
+extern unsigned int st_out_bit_counts[ST_NB]; |
|
| 306 |
+ |
|
| 307 |
+void print_stats(void); |
|
| 308 |
+#endif |
|
| 309 |
+ |
|
| 310 |
+/* misc math functions */ |
|
| 311 |
+extern const uint8_t ff_log2_tab[256]; |
|
| 312 |
+ |
|
| 313 |
+static inline int av_log2(unsigned int v) |
|
| 314 |
+{
|
|
| 315 |
+ int n; |
|
| 316 |
+ |
|
| 317 |
+ n = 0; |
|
| 318 |
+ if (v & 0xffff0000) {
|
|
| 319 |
+ v >>= 16; |
|
| 320 |
+ n += 16; |
|
| 321 |
+ } |
|
| 322 |
+ if (v & 0xff00) {
|
|
| 323 |
+ v >>= 8; |
|
| 324 |
+ n += 8; |
|
| 325 |
+ } |
|
| 326 |
+ n += ff_log2_tab[v]; |
|
| 327 |
+ |
|
| 328 |
+ return n; |
|
| 329 |
+} |
|
| 330 |
+ |
|
| 331 |
+static inline int av_log2_16bit(unsigned int v) |
|
| 332 |
+{
|
|
| 333 |
+ int n; |
|
| 334 |
+ |
|
| 335 |
+ n = 0; |
|
| 336 |
+ if (v & 0xff00) {
|
|
| 337 |
+ v >>= 8; |
|
| 338 |
+ n += 8; |
|
| 339 |
+ } |
|
| 340 |
+ n += ff_log2_tab[v]; |
|
| 341 |
+ |
|
| 342 |
+ return n; |
|
| 343 |
+} |
|
| 344 |
+ |
|
| 345 |
+/* median of 3 */ |
|
| 346 |
+static inline int mid_pred(int a, int b, int c) |
|
| 347 |
+{
|
|
| 348 |
+#if 0 |
|
| 349 |
+ int t= (a-b)&((a-b)>>31); |
|
| 350 |
+ a-=t; |
|
| 351 |
+ b+=t; |
|
| 352 |
+ b-= (b-c)&((b-c)>>31); |
|
| 353 |
+ b+= (a-b)&((a-b)>>31); |
|
| 354 |
+ |
|
| 355 |
+ return b; |
|
| 356 |
+#else |
|
| 357 |
+ if(a>b){
|
|
| 358 |
+ if(c>b){
|
|
| 359 |
+ if(c>a) b=a; |
|
| 360 |
+ else b=c; |
|
| 361 |
+ } |
|
| 362 |
+ }else{
|
|
| 363 |
+ if(b>c){
|
|
| 364 |
+ if(c>a) b=c; |
|
| 365 |
+ else b=a; |
|
| 366 |
+ } |
|
| 367 |
+ } |
|
| 368 |
+ return b; |
|
| 369 |
+#endif |
|
| 370 |
+} |
|
| 371 |
+ |
|
| 372 |
+static inline int clip(int a, int amin, int amax) |
|
| 373 |
+{
|
|
| 374 |
+ if (a < amin) |
|
| 375 |
+ return amin; |
|
| 376 |
+ else if (a > amax) |
|
| 377 |
+ return amax; |
|
| 378 |
+ else |
|
| 379 |
+ return a; |
|
| 380 |
+} |
|
| 381 |
+ |
|
| 382 |
+static inline int clip_uint8(int a) |
|
| 383 |
+{
|
|
| 384 |
+ if (a&(~255)) return (-a)>>31; |
|
| 385 |
+ else return a; |
|
| 386 |
+} |
|
| 387 |
+ |
|
| 388 |
+/* math */ |
|
| 389 |
+extern const uint8_t ff_sqrt_tab[128]; |
|
| 390 |
+ |
|
| 391 |
+int64_t ff_gcd(int64_t a, int64_t b); |
|
| 392 |
+ |
|
| 393 |
+static inline int ff_sqrt(int a) |
|
| 394 |
+{
|
|
| 395 |
+ int ret=0; |
|
| 396 |
+ int s; |
|
| 397 |
+ int ret_sq=0; |
|
| 398 |
+ |
|
| 399 |
+ if(a<128) return ff_sqrt_tab[a]; |
|
| 400 |
+ |
|
| 401 |
+ for(s=15; s>=0; s--){
|
|
| 402 |
+ int b= ret_sq + (1<<(s*2)) + (ret<<s)*2; |
|
| 403 |
+ if(b<=a){
|
|
| 404 |
+ ret_sq=b; |
|
| 405 |
+ ret+= 1<<s; |
|
| 406 |
+ } |
|
| 407 |
+ } |
|
| 408 |
+ return ret; |
|
| 409 |
+} |
|
| 410 |
+ |
|
| 411 |
+/** |
|
| 412 |
+ * converts fourcc string to int |
|
| 413 |
+ */ |
|
| 414 |
+static inline int ff_get_fourcc(const char *s){
|
|
| 415 |
+ assert( strlen(s)==4 ); |
|
| 416 |
+ |
|
| 417 |
+ return (s[0]) + (s[1]<<8) + (s[2]<<16) + (s[3]<<24); |
|
| 418 |
+} |
|
| 419 |
+ |
|
| 420 |
+#define MKTAG(a,b,c,d) (a | (b << 8) | (c << 16) | (d << 24)) |
|
| 421 |
+#define MKBETAG(a,b,c,d) (d | (c << 8) | (b << 16) | (a << 24)) |
|
| 422 |
+ |
|
| 423 |
+ |
|
| 424 |
+#if defined(ARCH_X86) || defined(ARCH_X86_64) |
|
| 425 |
+#define MASK_ABS(mask, level)\ |
|
| 426 |
+ asm volatile(\ |
|
| 427 |
+ "cdq \n\t"\ |
|
| 428 |
+ "xorl %1, %0 \n\t"\ |
|
| 429 |
+ "subl %1, %0 \n\t"\ |
|
| 430 |
+ : "+a" (level), "=&d" (mask)\ |
|
| 431 |
+ ); |
|
| 432 |
+#else |
|
| 433 |
+#define MASK_ABS(mask, level)\ |
|
| 434 |
+ mask= level>>31;\ |
|
| 435 |
+ level= (level^mask)-mask; |
|
| 436 |
+#endif |
|
| 437 |
+ |
|
| 438 |
+ |
|
| 439 |
+#if __CPU__ >= 686 && !defined(RUNTIME_CPUDETECT) |
|
| 440 |
+#define COPY3_IF_LT(x,y,a,b,c,d)\ |
|
| 441 |
+asm volatile (\ |
|
| 442 |
+ "cmpl %0, %3 \n\t"\ |
|
| 443 |
+ "cmovl %3, %0 \n\t"\ |
|
| 444 |
+ "cmovl %4, %1 \n\t"\ |
|
| 445 |
+ "cmovl %5, %2 \n\t"\ |
|
| 446 |
+ : "+r" (x), "+r" (a), "+r" (c)\ |
|
| 447 |
+ : "r" (y), "r" (b), "r" (d)\ |
|
| 448 |
+); |
|
| 449 |
+#else |
|
| 450 |
+#define COPY3_IF_LT(x,y,a,b,c,d)\ |
|
| 451 |
+if((y)<(x)){\
|
|
| 452 |
+ (x)=(y);\ |
|
| 453 |
+ (a)=(b);\ |
|
| 454 |
+ (c)=(d);\ |
|
| 455 |
+} |
|
| 456 |
+#endif |
|
| 457 |
+ |
|
| 458 |
+#if defined(ARCH_X86) || defined(ARCH_X86_64) || defined(ARCH_POWERPC) |
|
| 459 |
+#if defined(ARCH_X86_64) |
|
| 460 |
+static inline uint64_t read_time(void) |
|
| 461 |
+{
|
|
| 462 |
+ uint64_t a, d; |
|
| 463 |
+ asm volatile( "rdtsc\n\t" |
|
| 464 |
+ : "=a" (a), "=d" (d) |
|
| 465 |
+ ); |
|
| 466 |
+ return (d << 32) | (a & 0xffffffff); |
|
| 467 |
+} |
|
| 468 |
+#elif defined(ARCH_X86) |
|
| 469 |
+static inline long long read_time(void) |
|
| 470 |
+{
|
|
| 471 |
+ long long l; |
|
| 472 |
+ asm volatile( "rdtsc\n\t" |
|
| 473 |
+ : "=A" (l) |
|
| 474 |
+ ); |
|
| 475 |
+ return l; |
|
| 476 |
+} |
|
| 477 |
+#else //FIXME check ppc64 |
|
| 478 |
+static inline uint64_t read_time(void) |
|
| 479 |
+{
|
|
| 480 |
+ uint32_t tbu, tbl, temp; |
|
| 481 |
+ |
|
| 482 |
+ /* from section 2.2.1 of the 32-bit PowerPC PEM */ |
|
| 483 |
+ __asm__ __volatile__( |
|
| 484 |
+ "1:\n" |
|
| 485 |
+ "mftbu %2\n" |
|
| 486 |
+ "mftb %0\n" |
|
| 487 |
+ "mftbu %1\n" |
|
| 488 |
+ "cmpw %2,%1\n" |
|
| 489 |
+ "bne 1b\n" |
|
| 490 |
+ : "=r"(tbl), "=r"(tbu), "=r"(temp) |
|
| 491 |
+ : |
|
| 492 |
+ : "cc"); |
|
| 493 |
+ |
|
| 494 |
+ return (((uint64_t)tbu)<<32) | (uint64_t)tbl; |
|
| 495 |
+} |
|
| 496 |
+#endif |
|
| 497 |
+ |
|
| 498 |
+#define START_TIMER \ |
|
| 499 |
+uint64_t tend;\ |
|
| 500 |
+uint64_t tstart= read_time();\ |
|
| 501 |
+ |
|
| 502 |
+#define STOP_TIMER(id) \ |
|
| 503 |
+tend= read_time();\ |
|
| 504 |
+{\
|
|
| 505 |
+ static uint64_t tsum=0;\ |
|
| 506 |
+ static int tcount=0;\ |
|
| 507 |
+ static int tskip_count=0;\ |
|
| 508 |
+ if(tcount<2 || tend - tstart < 8*tsum/tcount){\
|
|
| 509 |
+ tsum+= tend - tstart;\ |
|
| 510 |
+ tcount++;\ |
|
| 511 |
+ }else\ |
|
| 512 |
+ tskip_count++;\ |
|
| 513 |
+ if(256*256*256*64%(tcount+tskip_count)==0){\
|
|
| 514 |
+ av_log(NULL, AV_LOG_DEBUG, "%Ld dezicycles in %s, %d runs, %d skips\n", tsum*10/tcount, id, tcount, tskip_count);\ |
|
| 515 |
+ }\ |
|
| 516 |
+} |
|
| 517 |
+#else |
|
| 518 |
+#define START_TIMER |
|
| 519 |
+#define STOP_TIMER(id) {}
|
|
| 520 |
+#endif |
|
| 521 |
+ |
|
| 522 |
+/* avoid usage of various functions */ |
|
| 523 |
+#define malloc please_use_av_malloc |
|
| 524 |
+#define free please_use_av_free |
|
| 525 |
+#define realloc please_use_av_realloc |
|
| 526 |
+#define time time_is_forbidden_due_to_security_issues |
|
| 527 |
+#define rand rand_is_forbidden_due_to_state_trashing |
|
| 528 |
+#define srand srand_is_forbidden_due_to_state_trashing |
|
| 529 |
+#define sprintf sprintf_is_forbidden_due_to_security_issues_use_snprintf |
|
| 530 |
+#define strcat strcat_is_forbidden_due_to_security_issues_use_pstrcat |
|
| 531 |
+#if !(defined(LIBAVFORMAT_BUILD) || defined(_FRAMEHOOK_H)) |
|
| 532 |
+#define printf please_use_av_log |
|
| 533 |
+#define fprintf please_use_av_log |
|
| 534 |
+#endif |
|
| 535 |
+ |
|
| 536 |
+#define CHECKED_ALLOCZ(p, size)\ |
|
| 537 |
+{\
|
|
| 538 |
+ p= av_mallocz(size);\ |
|
| 539 |
+ if(p==NULL && (size)!=0){\
|
|
| 540 |
+ perror("malloc");\
|
|
| 541 |
+ goto fail;\ |
|
| 542 |
+ }\ |
|
| 543 |
+} |
|
| 544 |
+ |
|
| 545 |
+#endif /* HAVE_AV_CONFIG_H */ |
|
| 546 |
+ |
|
| 547 |
+#endif /* COMMON_H */ |
| 0 | 548 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,221 @@ |
| 0 |
+/* |
|
| 1 |
+ * arbitrary precision integers |
|
| 2 |
+ * Copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at> |
|
| 3 |
+ * |
|
| 4 |
+ * This library is free software; you can redistribute it and/or |
|
| 5 |
+ * modify it under the terms of the GNU Lesser General Public |
|
| 6 |
+ * License as published by the Free Software Foundation; either |
|
| 7 |
+ * version 2 of the License, or (at your option) any later version. |
|
| 8 |
+ * |
|
| 9 |
+ * This library is distributed in the hope that it will be useful, |
|
| 10 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 11 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
| 12 |
+ * Lesser General Public License for more details. |
|
| 13 |
+ * |
|
| 14 |
+ * You should have received a copy of the GNU Lesser General Public |
|
| 15 |
+ * License along with this library; if not, write to the Free Software |
|
| 16 |
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
| 17 |
+ * |
|
| 18 |
+ */ |
|
| 19 |
+ |
|
| 20 |
+/** |
|
| 21 |
+ * @file integer.c |
|
| 22 |
+ * arbitrary precision integers. |
|
| 23 |
+ * @author Michael Niedermayer <michaelni@gmx.at> |
|
| 24 |
+ */ |
|
| 25 |
+ |
|
| 26 |
+#include "common.h" |
|
| 27 |
+#include "integer.h" |
|
| 28 |
+ |
|
| 29 |
+AVInteger av_add_i(AVInteger a, AVInteger b){
|
|
| 30 |
+ int i, carry=0; |
|
| 31 |
+ |
|
| 32 |
+ for(i=0; i<AV_INTEGER_SIZE; i++){
|
|
| 33 |
+ carry= (carry>>16) + a.v[i] + b.v[i]; |
|
| 34 |
+ a.v[i]= carry; |
|
| 35 |
+ } |
|
| 36 |
+ return a; |
|
| 37 |
+} |
|
| 38 |
+ |
|
| 39 |
+AVInteger av_sub_i(AVInteger a, AVInteger b){
|
|
| 40 |
+ int i, carry=0; |
|
| 41 |
+ |
|
| 42 |
+ for(i=0; i<AV_INTEGER_SIZE; i++){
|
|
| 43 |
+ carry= (carry>>16) + a.v[i] - b.v[i]; |
|
| 44 |
+ a.v[i]= carry; |
|
| 45 |
+ } |
|
| 46 |
+ return a; |
|
| 47 |
+} |
|
| 48 |
+ |
|
| 49 |
+/** |
|
| 50 |
+ * returns the rounded down value of the logarithm of base 2 of the given AVInteger. |
|
| 51 |
+ * this is simply the index of the most significant bit which is 1. Or 0 of all bits are 0 |
|
| 52 |
+ */ |
|
| 53 |
+int av_log2_i(AVInteger a){
|
|
| 54 |
+ int i; |
|
| 55 |
+ |
|
| 56 |
+ for(i=AV_INTEGER_SIZE-1; i>=0; i--){
|
|
| 57 |
+ if(a.v[i]) |
|
| 58 |
+ return av_log2_16bit(a.v[i]) + 16*i; |
|
| 59 |
+ } |
|
| 60 |
+ return -1; |
|
| 61 |
+} |
|
| 62 |
+ |
|
| 63 |
+AVInteger av_mul_i(AVInteger a, AVInteger b){
|
|
| 64 |
+ AVInteger out; |
|
| 65 |
+ int i, j; |
|
| 66 |
+ int na= (av_log2_i(a)+16) >> 4; |
|
| 67 |
+ int nb= (av_log2_i(b)+16) >> 4; |
|
| 68 |
+ |
|
| 69 |
+ memset(&out, 0, sizeof(out)); |
|
| 70 |
+ |
|
| 71 |
+ for(i=0; i<na; i++){
|
|
| 72 |
+ unsigned int carry=0; |
|
| 73 |
+ |
|
| 74 |
+ if(a.v[i]) |
|
| 75 |
+ for(j=i; j<AV_INTEGER_SIZE && j-i<=nb; j++){
|
|
| 76 |
+ carry= (carry>>16) + out.v[j] + a.v[i]*b.v[j-i]; |
|
| 77 |
+ out.v[j]= carry; |
|
| 78 |
+ } |
|
| 79 |
+ } |
|
| 80 |
+ |
|
| 81 |
+ return out; |
|
| 82 |
+} |
|
| 83 |
+ |
|
| 84 |
+/** |
|
| 85 |
+ * returns 0 if a==b, 1 if a>b and -1 if a<b. |
|
| 86 |
+ */ |
|
| 87 |
+int av_cmp_i(AVInteger a, AVInteger b){
|
|
| 88 |
+ int i; |
|
| 89 |
+ int v= (int16_t)a.v[AV_INTEGER_SIZE-1] - (int16_t)b.v[AV_INTEGER_SIZE-1]; |
|
| 90 |
+ if(v) return (v>>16)|1; |
|
| 91 |
+ |
|
| 92 |
+ for(i=AV_INTEGER_SIZE-2; i>=0; i--){
|
|
| 93 |
+ int v= a.v[i] - b.v[i]; |
|
| 94 |
+ if(v) return (v>>16)|1; |
|
| 95 |
+ } |
|
| 96 |
+ return 0; |
|
| 97 |
+} |
|
| 98 |
+ |
|
| 99 |
+/** |
|
| 100 |
+ * bitwise shift. |
|
| 101 |
+ * @param s the number of bits by which the value should be shifted right, may be negative for shifting left |
|
| 102 |
+ */ |
|
| 103 |
+AVInteger av_shr_i(AVInteger a, int s){
|
|
| 104 |
+ AVInteger out; |
|
| 105 |
+ int i; |
|
| 106 |
+ |
|
| 107 |
+ for(i=0; i<AV_INTEGER_SIZE; i++){
|
|
| 108 |
+ int index= i + (s>>4); |
|
| 109 |
+ unsigned int v=0; |
|
| 110 |
+ if(index+1<AV_INTEGER_SIZE && index+1>=0) v = a.v[index+1]<<16; |
|
| 111 |
+ if(index <AV_INTEGER_SIZE && index >=0) v+= a.v[index ]; |
|
| 112 |
+ out.v[i]= v >> (s&15); |
|
| 113 |
+ } |
|
| 114 |
+ return out; |
|
| 115 |
+} |
|
| 116 |
+ |
|
| 117 |
+/** |
|
| 118 |
+ * returns a % b. |
|
| 119 |
+ * @param quot a/b will be stored here |
|
| 120 |
+ */ |
|
| 121 |
+AVInteger av_mod_i(AVInteger *quot, AVInteger a, AVInteger b){
|
|
| 122 |
+ int i= av_log2_i(a) - av_log2_i(b); |
|
| 123 |
+ AVInteger quot_temp; |
|
| 124 |
+ if(!quot) quot = "_temp; |
|
| 125 |
+ |
|
| 126 |
+ assert((int16_t)a[AV_INTEGER_SIZE-1] >= 0 && (int16_t)b[AV_INTEGER_SIZE-1] >= 0); |
|
| 127 |
+ assert(av_log2(b)>=0); |
|
| 128 |
+ |
|
| 129 |
+ if(i > 0) |
|
| 130 |
+ b= av_shr_i(b, -i); |
|
| 131 |
+ |
|
| 132 |
+ memset(quot, 0, sizeof(AVInteger)); |
|
| 133 |
+ |
|
| 134 |
+ while(i-- >= 0){
|
|
| 135 |
+ *quot= av_shr_i(*quot, -1); |
|
| 136 |
+ if(av_cmp_i(a, b) >= 0){
|
|
| 137 |
+ a= av_sub_i(a, b); |
|
| 138 |
+ quot->v[0] += 1; |
|
| 139 |
+ } |
|
| 140 |
+ b= av_shr_i(b, 1); |
|
| 141 |
+ } |
|
| 142 |
+ return a; |
|
| 143 |
+} |
|
| 144 |
+ |
|
| 145 |
+/** |
|
| 146 |
+ * returns a/b. |
|
| 147 |
+ */ |
|
| 148 |
+AVInteger av_div_i(AVInteger a, AVInteger b){
|
|
| 149 |
+ AVInteger quot; |
|
| 150 |
+ av_mod_i(", a, b); |
|
| 151 |
+ return quot; |
|
| 152 |
+} |
|
| 153 |
+ |
|
| 154 |
+/** |
|
| 155 |
+ * converts the given int64_t to an AVInteger. |
|
| 156 |
+ */ |
|
| 157 |
+AVInteger av_int2i(int64_t a){
|
|
| 158 |
+ AVInteger out; |
|
| 159 |
+ int i; |
|
| 160 |
+ |
|
| 161 |
+ for(i=0; i<AV_INTEGER_SIZE; i++){
|
|
| 162 |
+ out.v[i]= a; |
|
| 163 |
+ a>>=16; |
|
| 164 |
+ } |
|
| 165 |
+ return out; |
|
| 166 |
+} |
|
| 167 |
+ |
|
| 168 |
+/** |
|
| 169 |
+ * converts the given AVInteger to an int64_t. |
|
| 170 |
+ * if the AVInteger is too large to fit into an int64_t, |
|
| 171 |
+ * then only the least significant 64bit will be used |
|
| 172 |
+ */ |
|
| 173 |
+int64_t av_i2int(AVInteger a){
|
|
| 174 |
+ int i; |
|
| 175 |
+ int64_t out=(int8_t)a.v[AV_INTEGER_SIZE-1]; |
|
| 176 |
+ |
|
| 177 |
+ for(i= AV_INTEGER_SIZE-2; i>=0; i--){
|
|
| 178 |
+ out = (out<<16) + a.v[i]; |
|
| 179 |
+ } |
|
| 180 |
+ return out; |
|
| 181 |
+} |
|
| 182 |
+ |
|
| 183 |
+#if 0 |
|
| 184 |
+#undef NDEBUG |
|
| 185 |
+#include <assert.h> |
|
| 186 |
+ |
|
| 187 |
+const uint8_t ff_log2_tab[256]={
|
|
| 188 |
+ 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, |
|
| 189 |
+ 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, |
|
| 190 |
+ 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, |
|
| 191 |
+ 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, |
|
| 192 |
+ 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, |
|
| 193 |
+ 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, |
|
| 194 |
+ 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, |
|
| 195 |
+ 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7 |
|
| 196 |
+}; |
|
| 197 |
+ |
|
| 198 |
+main(){
|
|
| 199 |
+ int64_t a,b; |
|
| 200 |
+ |
|
| 201 |
+ for(a=7; a<256*256*256; a+=13215){
|
|
| 202 |
+ for(b=3; b<256*256*256; b+=27118){
|
|
| 203 |
+ AVInteger ai= av_int2i(a); |
|
| 204 |
+ AVInteger bi= av_int2i(b); |
|
| 205 |
+ |
|
| 206 |
+ assert(av_i2int(ai) == a); |
|
| 207 |
+ assert(av_i2int(bi) == b); |
|
| 208 |
+ assert(av_i2int(av_add_i(ai,bi)) == a+b); |
|
| 209 |
+ assert(av_i2int(av_sub_i(ai,bi)) == a-b); |
|
| 210 |
+ assert(av_i2int(av_mul_i(ai,bi)) == a*b); |
|
| 211 |
+ assert(av_i2int(av_shr_i(ai, 9)) == a>>9); |
|
| 212 |
+ assert(av_i2int(av_shr_i(ai,-9)) == a<<9); |
|
| 213 |
+ assert(av_i2int(av_shr_i(ai, 17)) == a>>17); |
|
| 214 |
+ assert(av_i2int(av_shr_i(ai,-17)) == a<<17); |
|
| 215 |
+ assert(av_log2_i(ai) == av_log2(a)); |
|
| 216 |
+ assert(av_i2int(av_div_i(ai,bi)) == a/b); |
|
| 217 |
+ } |
|
| 218 |
+ } |
|
| 219 |
+} |
|
| 220 |
+#endif |
| 0 | 221 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,47 @@ |
| 0 |
+/* |
|
| 1 |
+ * arbitrary precision integers |
|
| 2 |
+ * Copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at> |
|
| 3 |
+ * |
|
| 4 |
+ * This library is free software; you can redistribute it and/or |
|
| 5 |
+ * modify it under the terms of the GNU Lesser General Public |
|
| 6 |
+ * License as published by the Free Software Foundation; either |
|
| 7 |
+ * version 2 of the License, or (at your option) any later version. |
|
| 8 |
+ * |
|
| 9 |
+ * This library is distributed in the hope that it will be useful, |
|
| 10 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 11 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
| 12 |
+ * Lesser General Public License for more details. |
|
| 13 |
+ * |
|
| 14 |
+ * You should have received a copy of the GNU Lesser General Public |
|
| 15 |
+ * License along with this library; if not, write to the Free Software |
|
| 16 |
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
| 17 |
+ * |
|
| 18 |
+ */ |
|
| 19 |
+ |
|
| 20 |
+/** |
|
| 21 |
+ * @file integer.h |
|
| 22 |
+ * arbitrary precision integers |
|
| 23 |
+ * @author Michael Niedermayer <michaelni@gmx.at> |
|
| 24 |
+ */ |
|
| 25 |
+ |
|
| 26 |
+#ifndef INTEGER_H |
|
| 27 |
+#define INTEGER_H |
|
| 28 |
+ |
|
| 29 |
+#define AV_INTEGER_SIZE 8 |
|
| 30 |
+ |
|
| 31 |
+typedef struct AVInteger{
|
|
| 32 |
+ uint16_t v[AV_INTEGER_SIZE]; |
|
| 33 |
+} AVInteger; |
|
| 34 |
+ |
|
| 35 |
+AVInteger av_add_i(AVInteger a, AVInteger b); |
|
| 36 |
+AVInteger av_sub_i(AVInteger a, AVInteger b); |
|
| 37 |
+int av_log2_i(AVInteger a); |
|
| 38 |
+AVInteger av_mul_i(AVInteger a, AVInteger b); |
|
| 39 |
+int av_cmp_i(AVInteger a, AVInteger b); |
|
| 40 |
+AVInteger av_shr_i(AVInteger a, int s); |
|
| 41 |
+AVInteger av_mod_i(AVInteger *quot, AVInteger a, AVInteger b); |
|
| 42 |
+AVInteger av_div_i(AVInteger a, AVInteger b); |
|
| 43 |
+AVInteger av_int2i(int64_t a); |
|
| 44 |
+int64_t av_i2int(AVInteger a); |
|
| 45 |
+ |
|
| 46 |
+#endif // INTEGER_H |
| 0 | 47 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,54 @@ |
| 0 |
+/* |
|
| 1 |
+ * portable IEEE float/double read/write functions |
|
| 2 |
+ * |
|
| 3 |
+ * Copyright (c) 2005 Michael Niedermayer <michaelni@gmx.at> |
|
| 4 |
+ * |
|
| 5 |
+ * This library is free software; you can redistribute it and/or |
|
| 6 |
+ * modify it under the terms of the GNU Lesser General Public |
|
| 7 |
+ * License as published by the Free Software Foundation; either |
|
| 8 |
+ * version 2 of the License, or (at your option) any later version. |
|
| 9 |
+ * |
|
| 10 |
+ * This library is distributed in the hope that it will be useful, |
|
| 11 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 12 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
| 13 |
+ * Lesser General Public License for more details. |
|
| 14 |
+ * |
|
| 15 |
+ * You should have received a copy of the GNU Lesser General Public |
|
| 16 |
+ * License along with this library; if not, write to the Free Software |
|
| 17 |
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
| 18 |
+ */ |
|
| 19 |
+ |
|
| 20 |
+/** |
|
| 21 |
+ * @file intfloat_readwrite.c |
|
| 22 |
+ * Portable IEEE float/double read/write functions. |
|
| 23 |
+ */ |
|
| 24 |
+ |
|
| 25 |
+#include "common.h" |
|
| 26 |
+ |
|
| 27 |
+double av_int2dbl(int64_t v){
|
|
| 28 |
+ if(v+v > 0xFFELLU<<52) |
|
| 29 |
+ return 0.0/0.0; |
|
| 30 |
+ return ldexp(((v&(1LL<<52)-1) + (1LL<<52)) * (v>>63|1), (v>>52&0x7FF)-1075); |
|
| 31 |
+} |
|
| 32 |
+ |
|
| 33 |
+float av_int2flt(int32_t v){
|
|
| 34 |
+ if(v+v > 0xFF000000U) |
|
| 35 |
+ return 0.0/0.0; |
|
| 36 |
+ return ldexp(((v&0x7FFFFF) + (1<<23)) * (v>>31|1), (v>>23&0xFF)-150); |
|
| 37 |
+} |
|
| 38 |
+ |
|
| 39 |
+int64_t av_dbl2int(double d){
|
|
| 40 |
+ int e; |
|
| 41 |
+ if ( !d) return 0; |
|
| 42 |
+ else if(d-d) return 0x7FF0000000000000LL + ((int64_t)(d<0)<<63) + (d!=d); |
|
| 43 |
+ d= frexp(d, &e); |
|
| 44 |
+ return (int64_t)(d<0)<<63 | (e+1022LL)<<52 | (int64_t)((fabs(d)-0.5)*(1LL<<53)); |
|
| 45 |
+} |
|
| 46 |
+ |
|
| 47 |
+int32_t av_flt2int(float d){
|
|
| 48 |
+ int e; |
|
| 49 |
+ if ( !d) return 0; |
|
| 50 |
+ else if(d-d) return 0x7F800000 + ((d<0)<<31) + (d!=d); |
|
| 51 |
+ d= frexp(d, &e); |
|
| 52 |
+ return (d<0)<<31 | (e+126)<<23 | (int64_t)((fabs(d)-0.5)*(1<<24)); |
|
| 53 |
+} |
| 0 | 54 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,11 @@ |
| 0 |
+#ifndef INTFLOAT_READWRITE_H |
|
| 1 |
+#define INTFLOAT_READWRITE_H |
|
| 2 |
+ |
|
| 3 |
+#include "common.h" |
|
| 4 |
+ |
|
| 5 |
+double av_int2dbl(int64_t v); |
|
| 6 |
+float av_int2flt(int32_t v); |
|
| 7 |
+int64_t av_dbl2int(double d); |
|
| 8 |
+int32_t av_flt2int(float d); |
|
| 9 |
+ |
|
| 10 |
+#endif /* INTFLOAT_READWRITE_H */ |
| 0 | 11 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,84 @@ |
| 0 |
+/* |
|
| 1 |
+ * Copyright (c) 2005 Michael Niedermayer <michaelni@gmx.at> |
|
| 2 |
+ * |
|
| 3 |
+ * This library is free software; you can redistribute it and/or |
|
| 4 |
+ * modify it under the terms of the GNU Lesser General Public |
|
| 5 |
+ * License as published by the Free Software Foundation; either |
|
| 6 |
+ * version 2 of the License, or (at your option) any later version. |
|
| 7 |
+ * |
|
| 8 |
+ * This library is distributed in the hope that it will be useful, |
|
| 9 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 10 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
| 11 |
+ * Lesser General Public License for more details. |
|
| 12 |
+ * |
|
| 13 |
+ * You should have received a copy of the GNU Lesser General Public |
|
| 14 |
+ * License along with this library; if not, write to the Free Software |
|
| 15 |
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
| 16 |
+ */ |
|
| 17 |
+ |
|
| 18 |
+/** |
|
| 19 |
+ * @file mathematics.c |
|
| 20 |
+ * Miscellaneous math routines and tables. |
|
| 21 |
+ */ |
|
| 22 |
+ |
|
| 23 |
+#include "common.h" |
|
| 24 |
+#include "integer.h" |
|
| 25 |
+#include "mathematics.h" |
|
| 26 |
+ |
|
| 27 |
+const uint8_t ff_sqrt_tab[128]={
|
|
| 28 |
+ 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, |
|
| 29 |
+ 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, |
|
| 30 |
+ 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, |
|
| 31 |
+ 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 |
|
| 32 |
+}; |
|
| 33 |
+ |
|
| 34 |
+const uint8_t ff_log2_tab[256]={
|
|
| 35 |
+ 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, |
|
| 36 |
+ 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, |
|
| 37 |
+ 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, |
|
| 38 |
+ 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, |
|
| 39 |
+ 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, |
|
| 40 |
+ 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, |
|
| 41 |
+ 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, |
|
| 42 |
+ 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7 |
|
| 43 |
+}; |
|
| 44 |
+ |
|
| 45 |
+int64_t ff_gcd(int64_t a, int64_t b){
|
|
| 46 |
+ if(b) return ff_gcd(b, a%b); |
|
| 47 |
+ else return a; |
|
| 48 |
+} |
|
| 49 |
+ |
|
| 50 |
+int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding rnd){
|
|
| 51 |
+ AVInteger ai; |
|
| 52 |
+ int64_t r=0; |
|
| 53 |
+ assert(c > 0); |
|
| 54 |
+ assert(b >=0); |
|
| 55 |
+ assert(rnd >=0 && rnd<=5 && rnd!=4); |
|
| 56 |
+ |
|
| 57 |
+ if(a<0 && a != INT64_MIN) return -av_rescale_rnd(-a, b, c, rnd ^ ((rnd>>1)&1)); |
|
| 58 |
+ |
|
| 59 |
+ if(rnd==AV_ROUND_NEAR_INF) r= c/2; |
|
| 60 |
+ else if(rnd&1) r= c-1; |
|
| 61 |
+ |
|
| 62 |
+ if(b<=INT_MAX && c<=INT_MAX){
|
|
| 63 |
+ if(a<=INT_MAX) |
|
| 64 |
+ return (a * b + r)/c; |
|
| 65 |
+ else |
|
| 66 |
+ return a/c*b + (a%c*b + r)/c; |
|
| 67 |
+ } |
|
| 68 |
+ |
|
| 69 |
+ ai= av_mul_i(av_int2i(a), av_int2i(b)); |
|
| 70 |
+ ai= av_add_i(ai, av_int2i(r)); |
|
| 71 |
+ |
|
| 72 |
+ return av_i2int(av_div_i(ai, av_int2i(c))); |
|
| 73 |
+} |
|
| 74 |
+ |
|
| 75 |
+int64_t av_rescale(int64_t a, int64_t b, int64_t c){
|
|
| 76 |
+ return av_rescale_rnd(a, b, c, AV_ROUND_NEAR_INF); |
|
| 77 |
+} |
|
| 78 |
+ |
|
| 79 |
+int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq){
|
|
| 80 |
+ int64_t b= bq.num * (int64_t)cq.den; |
|
| 81 |
+ int64_t c= cq.num * (int64_t)bq.den; |
|
| 82 |
+ return av_rescale_rnd(a, b, c, AV_ROUND_NEAR_INF); |
|
| 83 |
+} |
| 0 | 84 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,31 @@ |
| 0 |
+#ifndef MATHEMATICS_H |
|
| 1 |
+#define MATHEMATICS_H |
|
| 2 |
+ |
|
| 3 |
+#include "rational.h" |
|
| 4 |
+ |
|
| 5 |
+enum AVRounding {
|
|
| 6 |
+ AV_ROUND_ZERO = 0, ///< round toward zero |
|
| 7 |
+ AV_ROUND_INF = 1, ///< round away from zero |
|
| 8 |
+ AV_ROUND_DOWN = 2, ///< round toward -infinity |
|
| 9 |
+ AV_ROUND_UP = 3, ///< round toward +infinity |
|
| 10 |
+ AV_ROUND_NEAR_INF = 5, ///< round to nearest and halfway cases away from zero |
|
| 11 |
+}; |
|
| 12 |
+ |
|
| 13 |
+/** |
|
| 14 |
+ * rescale a 64bit integer with rounding to nearest. |
|
| 15 |
+ * a simple a*b/c isn't possible as it can overflow |
|
| 16 |
+ */ |
|
| 17 |
+int64_t av_rescale(int64_t a, int64_t b, int64_t c); |
|
| 18 |
+ |
|
| 19 |
+/** |
|
| 20 |
+ * rescale a 64bit integer with specified rounding. |
|
| 21 |
+ * a simple a*b/c isn't possible as it can overflow |
|
| 22 |
+ */ |
|
| 23 |
+int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding); |
|
| 24 |
+ |
|
| 25 |
+/** |
|
| 26 |
+ * rescale a 64bit integer by 2 rational numbers. |
|
| 27 |
+ */ |
|
| 28 |
+int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq); |
|
| 29 |
+ |
|
| 30 |
+#endif /* MATHEMATICS_H */ |
| 0 | 31 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,110 @@ |
| 0 |
+/* |
|
| 1 |
+ * Rational numbers |
|
| 2 |
+ * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at> |
|
| 3 |
+ * |
|
| 4 |
+ * This library is free software; you can redistribute it and/or |
|
| 5 |
+ * modify it under the terms of the GNU Lesser General Public |
|
| 6 |
+ * License as published by the Free Software Foundation; either |
|
| 7 |
+ * version 2 of the License, or (at your option) any later version. |
|
| 8 |
+ * |
|
| 9 |
+ * This library is distributed in the hope that it will be useful, |
|
| 10 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 11 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
| 12 |
+ * Lesser General Public License for more details. |
|
| 13 |
+ * |
|
| 14 |
+ * You should have received a copy of the GNU Lesser General Public |
|
| 15 |
+ * License along with this library; if not, write to the Free Software |
|
| 16 |
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
| 17 |
+ * |
|
| 18 |
+ */ |
|
| 19 |
+ |
|
| 20 |
+/** |
|
| 21 |
+ * @file rational.c |
|
| 22 |
+ * Rational numbers |
|
| 23 |
+ * @author Michael Niedermayer <michaelni@gmx.at> |
|
| 24 |
+ */ |
|
| 25 |
+ |
|
| 26 |
+//#include <math.h> |
|
| 27 |
+#include <limits.h> |
|
| 28 |
+ |
|
| 29 |
+#include "common.h" |
|
| 30 |
+#include "mathematics.h" |
|
| 31 |
+#include "rational.h" |
|
| 32 |
+ |
|
| 33 |
+int av_reduce(int *dst_nom, int *dst_den, int64_t nom, int64_t den, int64_t max){
|
|
| 34 |
+ AVRational a0={0,1}, a1={1,0};
|
|
| 35 |
+ int sign= (nom<0) ^ (den<0); |
|
| 36 |
+ int64_t gcd= ff_gcd(ABS(nom), ABS(den)); |
|
| 37 |
+ |
|
| 38 |
+ nom = ABS(nom)/gcd; |
|
| 39 |
+ den = ABS(den)/gcd; |
|
| 40 |
+ if(nom<=max && den<=max){
|
|
| 41 |
+ a1= (AVRational){nom, den};
|
|
| 42 |
+ den=0; |
|
| 43 |
+ } |
|
| 44 |
+ |
|
| 45 |
+ while(den){
|
|
| 46 |
+ int64_t x = nom / den; |
|
| 47 |
+ int64_t next_den= nom - den*x; |
|
| 48 |
+ int64_t a2n= x*a1.num + a0.num; |
|
| 49 |
+ int64_t a2d= x*a1.den + a0.den; |
|
| 50 |
+ |
|
| 51 |
+ if(a2n > max || a2d > max) break; |
|
| 52 |
+ |
|
| 53 |
+ a0= a1; |
|
| 54 |
+ a1= (AVRational){a2n, a2d};
|
|
| 55 |
+ nom= den; |
|
| 56 |
+ den= next_den; |
|
| 57 |
+ } |
|
| 58 |
+ assert(ff_gcd(a1.num, a1.den) == 1); |
|
| 59 |
+ |
|
| 60 |
+ *dst_nom = sign ? -a1.num : a1.num; |
|
| 61 |
+ *dst_den = a1.den; |
|
| 62 |
+ |
|
| 63 |
+ return den==0; |
|
| 64 |
+} |
|
| 65 |
+ |
|
| 66 |
+/** |
|
| 67 |
+ * returns b*c. |
|
| 68 |
+ */ |
|
| 69 |
+AVRational av_mul_q(AVRational b, AVRational c){
|
|
| 70 |
+ av_reduce(&b.num, &b.den, b.num * (int64_t)c.num, b.den * (int64_t)c.den, INT_MAX); |
|
| 71 |
+ return b; |
|
| 72 |
+} |
|
| 73 |
+ |
|
| 74 |
+/** |
|
| 75 |
+ * returns b/c. |
|
| 76 |
+ */ |
|
| 77 |
+AVRational av_div_q(AVRational b, AVRational c){
|
|
| 78 |
+ av_reduce(&b.num, &b.den, b.num * (int64_t)c.den, b.den * (int64_t)c.num, INT_MAX); |
|
| 79 |
+ return b; |
|
| 80 |
+} |
|
| 81 |
+ |
|
| 82 |
+/** |
|
| 83 |
+ * returns b+c. |
|
| 84 |
+ */ |
|
| 85 |
+AVRational av_add_q(AVRational b, AVRational c){
|
|
| 86 |
+ 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); |
|
| 87 |
+ return b; |
|
| 88 |
+} |
|
| 89 |
+ |
|
| 90 |
+/** |
|
| 91 |
+ * returns b-c. |
|
| 92 |
+ */ |
|
| 93 |
+AVRational av_sub_q(AVRational b, AVRational c){
|
|
| 94 |
+ 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); |
|
| 95 |
+ return b; |
|
| 96 |
+} |
|
| 97 |
+ |
|
| 98 |
+/** |
|
| 99 |
+ * Converts a double precission floating point number to a AVRational. |
|
| 100 |
+ * @param max the maximum allowed numerator and denominator |
|
| 101 |
+ */ |
|
| 102 |
+AVRational av_d2q(double d, int max){
|
|
| 103 |
+ AVRational a; |
|
| 104 |
+ int exponent= FFMAX( (int)(log(ABS(d) + 1e-20)/log(2)), 0); |
|
| 105 |
+ int64_t den= 1LL << (61 - exponent); |
|
| 106 |
+ av_reduce(&a.num, &a.den, (int64_t)(d * den + 0.5), den, max); |
|
| 107 |
+ |
|
| 108 |
+ return a; |
|
| 109 |
+} |
| 0 | 110 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,69 @@ |
| 0 |
+/* |
|
| 1 |
+ * Rational numbers |
|
| 2 |
+ * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at> |
|
| 3 |
+ * |
|
| 4 |
+ * This library is free software; you can redistribute it and/or |
|
| 5 |
+ * modify it under the terms of the GNU Lesser General Public |
|
| 6 |
+ * License as published by the Free Software Foundation; either |
|
| 7 |
+ * version 2 of the License, or (at your option) any later version. |
|
| 8 |
+ * |
|
| 9 |
+ * This library is distributed in the hope that it will be useful, |
|
| 10 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 11 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
| 12 |
+ * Lesser General Public License for more details. |
|
| 13 |
+ * |
|
| 14 |
+ * You should have received a copy of the GNU Lesser General Public |
|
| 15 |
+ * License along with this library; if not, write to the Free Software |
|
| 16 |
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
| 17 |
+ * |
|
| 18 |
+ */ |
|
| 19 |
+ |
|
| 20 |
+/** |
|
| 21 |
+ * @file rational.h |
|
| 22 |
+ * Rational numbers. |
|
| 23 |
+ * @author Michael Niedermayer <michaelni@gmx.at> |
|
| 24 |
+ */ |
|
| 25 |
+ |
|
| 26 |
+#ifndef RATIONAL_H |
|
| 27 |
+#define RATIONAL_H |
|
| 28 |
+ |
|
| 29 |
+/** |
|
| 30 |
+ * Rational number num/den. |
|
| 31 |
+ */ |
|
| 32 |
+typedef struct AVRational{
|
|
| 33 |
+ int num; ///< numerator |
|
| 34 |
+ int den; ///< denominator |
|
| 35 |
+} AVRational; |
|
| 36 |
+ |
|
| 37 |
+/** |
|
| 38 |
+ * returns 0 if a==b, 1 if a>b and -1 if a<b. |
|
| 39 |
+ */ |
|
| 40 |
+static inline int av_cmp_q(AVRational a, AVRational b){
|
|
| 41 |
+ const int64_t tmp= a.num * (int64_t)b.den - b.num * (int64_t)a.den; |
|
| 42 |
+ |
|
| 43 |
+ if(tmp) return (tmp>>63)|1; |
|
| 44 |
+ else return 0; |
|
| 45 |
+} |
|
| 46 |
+ |
|
| 47 |
+/** |
|
| 48 |
+ * converts the given AVRational to a double. |
|
| 49 |
+ */ |
|
| 50 |
+static inline double av_q2d(AVRational a){
|
|
| 51 |
+ return a.num / (double) a.den; |
|
| 52 |
+} |
|
| 53 |
+ |
|
| 54 |
+/** |
|
| 55 |
+ * reduce a fraction. |
|
| 56 |
+ * this is usefull for framerate calculations |
|
| 57 |
+ * @param max the maximum allowed for dst_nom & dst_den |
|
| 58 |
+ * @return 1 if exact, 0 otherwise |
|
| 59 |
+ */ |
|
| 60 |
+int av_reduce(int *dst_nom, int *dst_den, int64_t nom, int64_t den, int64_t max); |
|
| 61 |
+ |
|
| 62 |
+AVRational av_mul_q(AVRational b, AVRational c); |
|
| 63 |
+AVRational av_div_q(AVRational b, AVRational c); |
|
| 64 |
+AVRational av_add_q(AVRational b, AVRational c); |
|
| 65 |
+AVRational av_sub_q(AVRational b, AVRational c); |
|
| 66 |
+AVRational av_d2q(double d, int max); |
|
| 67 |
+ |
|
| 68 |
+#endif // RATIONAL_H |
| ... | ... |
@@ -2,7 +2,7 @@ include ../config.mak |
| 2 | 2 |
|
| 3 | 3 |
VPATH=$(SRC_PATH)/vhook |
| 4 | 4 |
|
| 5 |
-CFLAGS=-fPIC $(SHCFLAGS) -I.. -I$(SRC_PATH) -I$(SRC_PATH)/libavformat -I$(SRC_PATH)/libavcodec -DHAVE_AV_CONFIG_H |
|
| 5 |
+CFLAGS=-fPIC $(SHCFLAGS) -I.. -I$(SRC_PATH) -I$(SRC_PATH)/libavformat -I$(SRC_PATH)/libavcodec -I$(SRC_PATH)/libavutil -DHAVE_AV_CONFIG_H |
|
| 6 | 6 |
|
| 7 | 7 |
ifeq ($(CONFIG_DARWIN),yes) |
| 8 | 8 |
SHFLAGS+=-flat_namespace -undefined suppress |