[Ffmpeg-devel] [PATCH] libavutil - splitting parts from libavcodec

Alexander Strasser eclipse7
Sun Jul 24 11:36:42 CEST 2005


Alexander Strasser wrote:
>   i moved some of the generic utility code of libavcodec
> to a lib of its own: libavutil.
> 
>   The idea is to have the generally useful stuff in an
> independent directory/library for making it conviniently
> usable from other projects. It IMHO also improves FFmpeg
> project's internal structure/layout.
> 
>   I did no functional changes to the code. I did only
> code moving, buildsystem changes and exporting of
> functions through avutil.h .

  I was unnecessary incompatible because of a misconception
i had about the dynamic linkage of libavformat.

  Also removed a cosmetical change that slipped through.

  Corrected patch attached.

  Alex (beastd)
-------------- next part --------------
Index: Makefile
===================================================================
RCS file: /cvsroot/ffmpeg/ffmpeg/Makefile,v
retrieving revision 1.81
diff -u -r1.81 Makefile
--- Makefile	8 May 2005 15:04:59 -0000	1.81
+++ Makefile	24 Jul 2005 09:33:19 -0000
@@ -6,7 +6,7 @@
 
 VPATH=$(SRC_PATH)
 
-CFLAGS=$(OPTFLAGS) -I. -I$(SRC_PATH) -I$(SRC_PATH)/libavcodec -I$(SRC_PATH)/libavformat -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE
+CFLAGS=$(OPTFLAGS) -I. -I$(SRC_PATH) -I$(SRC_PATH)/libavutil -I$(SRC_PATH)/libavcodec -I$(SRC_PATH)/libavformat -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE
 LDFLAGS+= -g 
 
 ifeq ($(TARGET_GPROF),yes)
@@ -91,11 +91,12 @@
 
 OBJS = ffmpeg.o ffserver.o cmdutils.o $(FFPLAY_O)
 SRCS = $(OBJS:.o=.c) $(ASM_OBJS:.o=.s)
-FFLIBS = -L./libavformat -lavformat$(BUILDSUF) -L./libavcodec -lavcodec$(BUILDSUF)
+FFLIBS = -L./libavformat -lavformat$(BUILDSUF) -L./libavcodec -lavcodec$(BUILDSUF) -L./libavutil -lavutil$(BUILDSUF)
 
 all: lib $(PROG) $(PROGTEST) $(VHOOK) $(QTFASTSTART) $(DOC)
 
 lib:
+	$(MAKE) -C libavutil all
 	$(MAKE) -C libavcodec all
 	$(MAKE) -C libavformat all
 
@@ -162,6 +163,7 @@
 	$(MAKE) -C vhook install
 
 installlib:
+	$(MAKE) -C libavutil installlib
 	$(MAKE) -C libavcodec installlib
 	$(MAKE) -C libavformat installlib
 
@@ -182,6 +184,7 @@
 	@for i in $(DEP_LIBS) ; do if $(TEST) $$i -nt .libs ; then touch .libs; fi ; done
 
 clean: $(CLEANVHOOK)
+	$(MAKE) -C libavutil clean
 	$(MAKE) -C libavcodec clean
 	$(MAKE) -C libavformat clean
 	$(MAKE) -C tests clean
Index: libavcodec/Makefile
===================================================================
RCS file: /cvsroot/ffmpeg/ffmpeg/libavcodec/Makefile,v
retrieving revision 1.196
diff -u -r1.196 Makefile
--- libavcodec/Makefile	17 Jul 2005 00:28:11 -0000	1.196
+++ libavcodec/Makefile	24 Jul 2005 09:33:19 -0000
@@ -7,7 +7,7 @@
 VPATH=$(SRC_PATH)/libavcodec
 
 # NOTE: -I.. is needed to include config.h
-CFLAGS=$(OPTFLAGS) -DHAVE_AV_CONFIG_H -I.. -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE $(AMR_CFLAGS)
+CFLAGS=$(OPTFLAGS) -DHAVE_AV_CONFIG_H -I.. -I$(SRC_PATH)/libavutil -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE $(AMR_CFLAGS)
 
 OBJS= bitstream.o utils.o mem.o allcodecs.o \
       mpegvideo.o jrevdct.o jfdctfst.o jfdctint.o\
@@ -16,8 +16,8 @@
       mpeg12.o mpegaudiodec.o pcm.o simple_idct.o \
       ratecontrol.o adpcm.o eval.o error_resilience.o \
       fft.o mdct.o raw.o golomb.o cabac.o\
-      dpcm.o adx.o rational.o faandct.o parser.o g726.o \
-      vp3dsp.o integer.o h264idct.o rangecoder.o pnm.o h263.o msmpeg4.o h263dec.o dvdsub.o dvbsub.o dvbsubdec.o
+      dpcm.o adx.o faandct.o parser.o g726.o \
+      vp3dsp.o h264idct.o rangecoder.o pnm.o h263.o msmpeg4.o h263dec.o dvdsub.o dvbsub.o dvbsubdec.o
 
 ifeq ($(CONFIG_AASC_DECODER),yes)
     OBJS+= aasc.o
@@ -234,6 +234,8 @@
 endif
 endif
 
+EXTRALIBS += -L$(SRC_PATH)/libavutil -lavutil$(BUILDSUF)
+
 # currently using libdts for dts decoding
 ifeq ($(CONFIG_DTS),yes)
 OBJS+= dtsdec.o
@@ -375,6 +377,7 @@
 OBJS := $(OBJS) $(ASM_OBJS)
 
 LIB= $(LIBPREF)avcodec$(LIBSUF)
+LIBAVUTIL= $(SRC_PATH)/libavutil/$(LIBPREF)avutil$(LIBSUF)
 ifeq ($(BUILD_SHARED),yes)
 SLIB= $(SLIBPREF)avcodec$(SLIBSUF)
 endif
@@ -446,7 +449,7 @@
 
 # api example program
 apiexample: apiexample.c $(LIB)
-	$(CC) $(CFLAGS) -o $@ $< $(LIB) $(EXTRALIBS) -lm
+	$(CC) $(CFLAGS) -o $@ $< $(LIB) $(LIBAVUTIL) $(EXTRALIBS) -lm
 
 # cpuid test
 cpuid_test: i386/cputest.c
@@ -464,7 +467,7 @@
 	$(CC) -o $@ $^ -lm
 
 fft-test: fft-test.o $(LIB)
-	$(CC) -o $@ $^ -lm
+	$(CC) -o $@ $^ $(LIBAVUTIL) -lm
 
 ifeq ($(BUILD_SHARED),yes)
 install: all install-headers
@@ -489,8 +492,6 @@
 install-headers:
 	mkdir -p "$(prefix)/include/ffmpeg"
 	install -m 644 $(SRC_PATH)/libavcodec/avcodec.h \
-	               $(SRC_PATH)/libavcodec/common.h \
-	               $(SRC_PATH)/libavcodec/rational.h \
                 "$(prefix)/include/ffmpeg"
 	install -d $(libdir)/pkgconfig
 	install -m 644 ../libavcodec.pc $(libdir)/pkgconfig
Index: libavcodec/avcodec.h
===================================================================
RCS file: /cvsroot/ffmpeg/ffmpeg/libavcodec/avcodec.h,v
retrieving revision 1.410
diff -u -r1.410 avcodec.h
--- libavcodec/avcodec.h	19 Jul 2005 14:25:23 -0000	1.410
+++ libavcodec/avcodec.h	24 Jul 2005 09:33:20 -0000
@@ -11,12 +11,9 @@
 extern "C" {
 #endif
 
-#include "common.h"
-#include "rational.h"
+#include "avutil.h"
 #include <sys/types.h> /* size_t */
 
-#define FFMPEG_VERSION_INT     0x000409
-#define FFMPEG_VERSION         "CVS"
 #define LIBAVCODEC_BUILD       4759
 
 
@@ -2308,14 +2305,6 @@
 char av_get_pict_type_char(int pict_type);
 
 /**
- * reduce a fraction.
- * this is usefull for framerate calculations
- * @param max the maximum allowed for dst_nom & dst_den
- * @return 1 if exact, 0 otherwise
- */
-int av_reduce(int *dst_nom, int *dst_den, int64_t nom, int64_t den, int64_t max);
-
-/**
  * rescale a 64bit integer with rounding to nearest.
  * a simple a*b/c isn't possible as it can overflow
  */
@@ -2332,11 +2321,6 @@
  */
 int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq);
 
-double av_int2dbl(int64_t v);
-float av_int2flt(int32_t v);
-int64_t av_dbl2int(double d);
-int32_t av_flt2int(float d);
-
 
 /* frame parsing */
 typedef struct AVCodecParserContext {
Index: libavcodec/utils.c
===================================================================
RCS file: /cvsroot/ffmpeg/ffmpeg/libavcodec/utils.c,v
retrieving revision 1.145
diff -u -r1.145 utils.c
--- libavcodec/utils.c	19 Jul 2005 13:29:13 -0000	1.145
+++ libavcodec/utils.c	24 Jul 2005 09:33:21 -0000
@@ -38,17 +38,6 @@
         9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11
 };
 
-const uint8_t ff_log2_tab[256]={
-        0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
-        5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
-        6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
-        6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
-        7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
-        7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
-        7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
-        7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
-};
-
 const uint8_t ff_reverse[256]={
 0x00,0x80,0x40,0xC0,0x20,0xA0,0x60,0xE0,0x10,0x90,0x50,0xD0,0x30,0xB0,0x70,0xF0,
 0x08,0x88,0x48,0xC8,0x28,0xA8,0x68,0xE8,0x18,0x98,0x58,0xD8,0x38,0xB8,0x78,0xF8,
@@ -919,39 +908,6 @@
     }
 }
 
-int av_reduce(int *dst_nom, int *dst_den, int64_t nom, int64_t den, int64_t max){
-    AVRational a0={0,1}, a1={1,0};
-    int sign= (nom<0) ^ (den<0);
-    int64_t gcd= ff_gcd(ABS(nom), ABS(den));
-
-    nom = ABS(nom)/gcd;
-    den = ABS(den)/gcd;
-    if(nom<=max && den<=max){
-        a1= (AVRational){nom, den};
-        den=0;
-    }
-    
-    while(den){
-        int64_t x       = nom / den;
-        int64_t next_den= nom - den*x;
-        int64_t a2n= x*a1.num + a0.num;
-        int64_t a2d= x*a1.den + a0.den;
-
-        if(a2n > max || a2d > max) break;
-
-        a0= a1;
-        a1= (AVRational){a2n, a2d};
-        nom= den;
-        den= next_den;
-    }
-    assert(ff_gcd(a1.num, a1.den) == 1);
-    
-    *dst_nom = sign ? -a1.num : a1.num;
-    *dst_den = a1.den;
-    
-    return den==0;
-}
-
 int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding rnd){
     AVInteger ai;
     int64_t r=0;
@@ -987,39 +943,6 @@
     return av_rescale_rnd(a, b, c, AV_ROUND_NEAR_INF);
 }
 
-int64_t ff_gcd(int64_t a, int64_t b){
-    if(b) return ff_gcd(b, a%b);
-    else  return a;
-}
-
-double av_int2dbl(int64_t v){
-    if(v+v > 0xFFELLU<<52)
-        return 0.0/0.0;
-    return ldexp(((v&(1LL<<52)-1) + (1LL<<52)) * (v>>63|1), (v>>52&0x7FF)-1075);
-}
-
-float av_int2flt(int32_t v){
-    if(v+v > 0xFF000000U)
-        return 0.0/0.0;
-    return ldexp(((v&0x7FFFFF) + (1<<23)) * (v>>31|1), (v>>23&0xFF)-150);
-}
-
-int64_t av_dbl2int(double d){
-    int e;
-    if     ( !d) return 0;
-    else if(d-d) return 0x7FF0000000000000LL + ((int64_t)(d<0)<<63) + (d!=d);
-    d= frexp(d, &e);
-    return (int64_t)(d<0)<<63 | (e+1022LL)<<52 | (int64_t)((fabs(d)-0.5)*(1LL<<53));
-}
-
-int32_t av_flt2int(float d){
-    int e;
-    if     ( !d) return 0;
-    else if(d-d) return 0x7F800000 + ((d<0)<<31) + (d!=d);
-    d= frexp(d, &e);
-    return (d<0)<<31 | (e+126)<<23 | (int64_t)((fabs(d)-0.5)*(1<<24));
-}
-
 /* av_log API */
 
 static int av_log_level = AV_LOG_INFO;
Index: libavcodec/i386/fdct_mmx.c
===================================================================
RCS file: /cvsroot/ffmpeg/ffmpeg/libavcodec/i386/fdct_mmx.c,v
retrieving revision 1.16
diff -u -r1.16 fdct_mmx.c
--- libavcodec/i386/fdct_mmx.c	11 Oct 2004 02:19:29 -0000	1.16
+++ libavcodec/i386/fdct_mmx.c	24 Jul 2005 09:33:21 -0000
@@ -13,7 +13,7 @@
  * a page about fdct at http://www.geocities.com/ssavekar/dct.htm
  * Skal's fdct at http://skal.planet-d.net/coding/dct.html
  */
-#include "../common.h"
+#include "common.h"
 #include "../dsputil.h"
 #include "mmx.h"
 
Index: libavcodec/i386/idct_mmx.c
===================================================================
RCS file: /cvsroot/ffmpeg/ffmpeg/libavcodec/i386/idct_mmx.c,v
retrieving revision 1.12
diff -u -r1.12 idct_mmx.c
--- libavcodec/i386/idct_mmx.c	2 Jun 2005 20:45:35 -0000	1.12
+++ libavcodec/i386/idct_mmx.c	24 Jul 2005 09:33:22 -0000
@@ -22,7 +22,7 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#include "../common.h"
+#include "common.h"
 #include "../dsputil.h"
 
 #include "mmx.h"
Index: libavformat/Makefile
===================================================================
RCS file: /cvsroot/ffmpeg/ffmpeg/libavformat/Makefile,v
retrieving revision 1.95
diff -u -r1.95 Makefile
--- libavformat/Makefile	15 Jul 2005 12:50:00 -0000	1.95
+++ libavformat/Makefile	24 Jul 2005 09:33:22 -0000
@@ -6,7 +6,7 @@
 
 VPATH=$(SRC_PATH)/libavformat
 
-CFLAGS=$(OPTFLAGS) -I.. -I$(SRC_PATH) -I$(SRC_PATH)/libavcodec -DHAVE_AV_CONFIG_H -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE
+CFLAGS=$(OPTFLAGS) -I.. -I$(SRC_PATH) -I$(SRC_PATH)/libavutil -I$(SRC_PATH)/libavcodec -DHAVE_AV_CONFIG_H -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE
 
 OBJS= utils.o cutils.o os_support.o allformats.o
 PPOBJS=
Index: vhook/Makefile
===================================================================
RCS file: /cvsroot/ffmpeg/ffmpeg/vhook/Makefile,v
retrieving revision 1.21
diff -u -r1.21 Makefile
--- vhook/Makefile	11 Jul 2005 00:15:37 -0000	1.21
+++ vhook/Makefile	24 Jul 2005 09:33:22 -0000
@@ -2,7 +2,7 @@
 
 VPATH=$(SRC_PATH)/vhook
 
-CFLAGS=-fPIC $(SHCFLAGS) -I.. -I$(SRC_PATH) -I$(SRC_PATH)/libavformat -I$(SRC_PATH)/libavcodec -DHAVE_AV_CONFIG_H
+CFLAGS=-fPIC $(SHCFLAGS) -I.. -I$(SRC_PATH) -I$(SRC_PATH)/libavformat -I$(SRC_PATH)/libavcodec -I$(SRC_PATH)/libavutil -DHAVE_AV_CONFIG_H
 
 ifeq ($(CONFIG_DARWIN),yes)
 SHFLAGS+=-flat_namespace -undefined suppress



More information about the ffmpeg-devel mailing list