From 2a966ae9a73bda77bf110f6cd1ec6f9c1bb2266b Mon Sep 17 00:00:00 2001
From: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
Date: Tue, 1 Mar 2011 13:09:56 -0500
Subject: [PATCH] [#5267] Autodetect celt version (0.9.1, 0.7.1)

---
 sflphone-common/configure.ac                   | 11 ++++++-----
 sflphone-common/src/audio/codecs/Makefile.am   | 14 +++++++++++---
 sflphone-common/src/audio/codecs/celtcodec.cpp | 11 +++++++----
 3 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/sflphone-common/configure.ac b/sflphone-common/configure.ac
index aa9b8fdea1..2a0663abfe 100644
--- a/sflphone-common/configure.ac
+++ b/sflphone-common/configure.ac
@@ -389,16 +389,17 @@ AC_ARG_WITH([celt],
 AS_IF([test "x$with_celt" != xno],
 	PKG_CHECK_MODULES(CELT, celt >= 0.9.1, 
 		[
-			BUILD_CELT=91 ; with_celt=yes
+			with_celt_91=yes; AC_MSG_NOTICE([Using celt 0.9.1]); AC_SUBST(BUILD_CELT_91)
     	], 
     	[
-			PKG_CHECK_MODULES(CELT, celt >= 0.7.1,,AC_MSG_FAILURE([libcelt link test failed.   You may use --without-celt to compile without celt codec support.])) 
-        	BUILD_CELT=71; with_celt=yes;
+			PKG_CHECK_MODULES(CELT, celt >= 0.7.1, [with_celt_71=yes; AC_MSG_NOTICE([Using celt 0.7.1]); AC_SUBST(BUILD_CELT_71)], AC_MSG_FAILURE([libcelt link test failed.   You may use --without-celt to compile without celt codec support.])) 
     	])
 )
 
-AC_SUBST(BUILD_CELT)
-AM_CONDITIONAL(BUILD_CELT, test "x$with_celt" = "xyes" )
+# AC_SUBST(BUILD_CELT)
+# AM_CONDITIONAL(BUILD_CELT, test "x$with_celt" = "xyes" )
+AM_CONDITIONAL(BUILD_CELT_91, test "x$with_celt_91" = "xyes" )
+AM_CONDITIONAL(BUILD_CELT_71, test "x$with_celt_71" = "xyes" )
 
 
 dnl Check for IAX
diff --git a/sflphone-common/src/audio/codecs/Makefile.am b/sflphone-common/src/audio/codecs/Makefile.am
index 4b712fc460..37df13bcab 100644
--- a/sflphone-common/src/audio/codecs/Makefile.am
+++ b/sflphone-common/src/audio/codecs/Makefile.am
@@ -40,15 +40,23 @@ libcodec_speex_ub_so_LDFLAGS = --shared -lc -lspeex $(SPEEX_NIMP)
 INSTALL_SPEEX_UB_RULE = install-libcodec_speex_ub_so
 endif
 
-if BUILD_CELT
+if BUILD_CELT_91
 CELT_LIB = libcodec_celt.so
 libcodec_celt_so_SOURCES = celtcodec.cpp
-libcodec_celt_so_CFLAGS = -fPIC -g -Wall -D$(BUILD_CELT)
-libcodec_celt_so_CXXFLAGS = -fPIC -g -Wall
+libcodec_celt_so_CFLAGS = -fPIC -g -Wall -DBUILD_CELT_91
+libcodec_celt_so_CXXFLAGS = -fPIC -g -Wall -DBUILD_CELT_91
 libcodec_celt_so_LDFLAGS = --shared -lc -lcelt0 $(CELT_NIMP)
 INSTALL_CELT_RULE = install-libcodec_celt_so
 endif
 
+if BUILD_CELT_71
+CELT_LIB = libcodec_celt.so
+libcodec_celt_so_SOURCES = celtcodec.cpp
+libcodec_celt_so_CFLAGS = -fPIC -g -Wall -DBUILD_CELT_71
+libcodec_celt_so_CXXFLAGS = -fPIC -g -Wall -DBUILD_CELT_71
+libcodec_celt_so_LDFLAGS = --shared -lc -lcelt0 $(CELT_NIMP)
+INSTALL_CELT_RULE = install-libcodec_celt_so
+endif
 
 noinst_PROGRAMS = libcodec_ulaw.so libcodec_alaw.so libcodec_g722.so $(GSM_LIB) $(SPEEX_NB_LIB) $(SPEEX_WB_LIB) $(SPEEX_UB_LIB) $(CELT_LIB)
 
diff --git a/sflphone-common/src/audio/codecs/celtcodec.cpp b/sflphone-common/src/audio/codecs/celtcodec.cpp
index 9b6fe17e28..92ac63c092 100644
--- a/sflphone-common/src/audio/codecs/celtcodec.cpp
+++ b/sflphone-common/src/audio/codecs/celtcodec.cpp
@@ -126,10 +126,12 @@ class Celt : public AudioCodec
         }
 
         virtual int codecDecode (short *dst, unsigned char *src, unsigned int size) {
+#ifdef BUILD_CELT_91 // == 91
             int err = 0;
-#if BUILD_CELT == 91
             err = celt_decode (_dec, src, size, (celt_int16*) dst, size);
-#else
+#endif
+#ifdef BUILD_CELT_71
+            int err = 0;
             err = celt_decode (_dec, src, size, (celt_int16*) dst);
 #endif
             return _frameSize * sizeof (celt_int16);
@@ -137,9 +139,10 @@ class Celt : public AudioCodec
 
         virtual int codecEncode (unsigned char *dst, short *src, unsigned int size) {
             int len = 0;
-#if BUILD_CELT == 91 
+#ifdef BUILD_CELT_91// == 91
             len = celt_encode (_enc, (celt_int16*) src, size, dst, 40);
-#else
+#endif
+#ifdef BUILD_CELT_71
             len = celt_encode (_enc, (celt_int16*) src, (celt_int16 *) src, dst, 40);
 #endif
             // returns the number of bytes writen
-- 
GitLab