diff --git a/configure.ac b/configure.ac index 62b9789867d907d3813e59e258c31de4cf0984b8..9b1ca925fec844c25b75e4c2eb2d2f9585ebab73 100644 --- a/configure.ac +++ b/configure.ac @@ -317,6 +317,29 @@ AC_DEFINE([HAVE_SPEEX], test "x$with_speex" = "xyes", [Define if you have libspe AM_CONDITIONAL(BUILD_SPEEX, test "x$with_speex" = "xyes" ) AM_CONDITIONAL(ENABLE_SPEEXDSP, test $HAVE_SPEEXDSP = yes) + +# check for libgsm1 (doesn't use pkg-config) +dnl Check for libgsm +AC_ARG_WITH([celt], + [AS_HELP_STRING([--without-celt], + [disable support for celt codec])], + [], + [with_celt=yes]) + +LIBCELT= +AS_IF([test "x$with_celt" != xno], + [AC_CHECK_HEADER([celt/celt.h], , AC_MSG_FAILURE([Unable to find the libcelt headers. You may use --without-celt to compile without celt codec support.]))] + [AC_CHECK_LIB([celt], [celt_decode], + [], + [AC_MSG_FAILURE( + [libcelt link test failed. You may use --without-celt to compile without celt codec support.])] + ) + ] + ) + +AC_DEFINE([HAVE_CELT], test "x$with_celt" = "xyes", [Define if you have libcelt]) +AM_CONDITIONAL(BUILD_CELT, test "x$with_celt" = "xyes" ) + dnl Check for ilbc support AC_ARG_WITH([ilbc], [AS_HELP_STRING([--without-ilbc], diff --git a/src/audio/codecs/Makefile.am b/src/audio/codecs/Makefile.am index 0644c65bbc7560f18f72621fce7a8dc31c74100f..45c1084ca2ba3a01da09d85f49201ba4dbd4efcc 100644 --- a/src/audio/codecs/Makefile.am +++ b/src/audio/codecs/Makefile.am @@ -31,6 +31,15 @@ libcodec_speex_wb_so_LDFLAGS = --shared -lc -lspeex $(SPEEX_NIMP) INSTALL_SPEEX_WB_RULE = install-libcodec_speex_wb_so endif +if BUILD_CELT +CELT_LIB = libcodec_celt.so +libcodec_celt_so_SOURCES = celtcodec.cpp +libcodec_celt_so_CFLAGS = -fPIC -g -Wall +libcodec_celt_so_CXXFLAGS = -fPIC -g -Wall +libcodec_celt_so_LDFLAGS = --shared -lc -lcelt $(CELT_NIMP) +INSTALL_CELT_RULE = install-libcodec_celt_so +endif + if BUILD_ILBC ILBC_LIB = libcodec_ilbc.so libcodec_ilbc_so_SOURCES = ilbc.cpp @@ -41,7 +50,7 @@ INSTALL_ILBC_RULE = install-libcodec_ilbc_so SUBDIRS = ilbc endif -noinst_PROGRAMS = libcodec_ulaw.so libcodec_alaw.so $(GSM_LIB) $(SPEEX_NB_LIB) $(SPEEX_WB_LIB) $(ILBC_LIB) +noinst_PROGRAMS = libcodec_ulaw.so libcodec_alaw.so $(GSM_LIB) $(SPEEX_NB_LIB) $(SPEEX_WB_LIB) $(CELT_LIB) $(ILBC_LIB) noinst_HEADERS = audiocodec.h @@ -57,8 +66,8 @@ libcodec_alaw_so_LDFLAGS = --shared -lc -install-exec-local: install-libcodec_ulaw_so install-libcodec_alaw_so $(INSTALL_GSM_RULE) $(INSTALL_SPEEX_NB_RULE) $(INSTALL_SPEEX_WB_RULE) $(INSTALL_ILBC_RULE) -uninstall-local: uninstall-libcodec_ulaw_so uninstall-libcodec_alaw_so uninstall-libcodec_gsm_so uninstall-libcodec_speex_nb_so uninstall-libcodec_speex_wb_so +install-exec-local: install-libcodec_ulaw_so install-libcodec_alaw_so $(INSTALL_GSM_RULE) $(INSTALL_SPEEX_NB_RULE) $(INSTALL_SPEEX_WB_RULE) $(INSTALL_CELT_RULE) $(INSTALL_ILBC_RULE) +uninstall-local: uninstall-libcodec_ulaw_so uninstall-libcodec_alaw_so uninstall-libcodec_gsm_so uninstall-libcodec_speex_nb_so uninstall-libcodec_speex_wb_so uninstall-libcodec_celt_so install-libcodec_ulaw_so: libcodec_ulaw.so mkdir -p $(sflcodecdir) @@ -71,6 +80,8 @@ install-libcodec_speex_nb_so: libcodec_speex_nb.so $(INSTALL_PROGRAM) libcodec_speex_nb.so $(sflcodecdir) install-libcodec_speex_wb_so: libcodec_speex_wb.so $(INSTALL_PROGRAM) libcodec_speex_wb.so $(sflcodecdir) +install-libcodec_celt_so: libcodec_celt.so + $(INSTALL_PROGRAM) libcodec_celt.so $(sflcodecdir) install-libcodec_ilbc_so: libcodec_ilbc.so $(INSTALL_PROGRAM) libcodec_ilbc.so $(sflcodecdir) @@ -85,6 +96,8 @@ uninstall-libcodec_speex_nb_so: rm -f $(sflcodecdir)/libcodec_speex_nb.so uninstall-libcodec_speex_wb_so: rm -f $(sflcodecdir)/libcodec_speex_wb.so +uninstall-libcodec_celt_so: + rm -f $(sflcodecdir)/libcodec_celt.so rm -rf $(sflcodecdir) uninstall-libcodec_ilbc_so: rm -f $(sflcodecdir)/libcodec_ilbc.so diff --git a/src/audio/codecs/celtcodec.cpp b/src/audio/codecs/celtcodec.cpp new file mode 100644 index 0000000000000000000000000000000000000000..31347cfb9ccc9584e18c68bf3a557ed4cb4d2666 --- /dev/null +++ b/src/audio/codecs/celtcodec.cpp @@ -0,0 +1,112 @@ +/* + * Copyright (C) 2007-2009 Savoir-Faire Linux inc. + * Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com> + * Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include "audiocodec.h" +#include <cstdio> +#include <celt/celt.h> + + +class Celt : public AudioCodec{ + public: + Celt(int payload=0) + : AudioCodec(payload, "celt"), + _celt_frame_size(512) + { + _clockRate = 44100; + _channel = 1; + _bitrate = 0; + _bandwidth = 0; + initCelt(); + } + + Celt( const Celt& ); + Celt& operator=(const Celt&); + + void initCelt() { + printf("init celt"); + + mode = celt_mode_create(_clockRate, _channel, _celt_frame_size, NULL); + // celt_mode_info(mode, CELT_GET_LOOKAHEAD, &skip); + + if (mode == NULL) + { + printf("failed to create a mode\n"); + } + + // bytes_per_packet = 1024; + // if (bytes_per_packet < 0 || bytes_per_packet > MAX_PACKET) + // { + // printf ("bytes per packet must be between 0 and %d\n"); + // } + + // celt_mode_info(mode, CELT_GET_FRAME_SIZE, &frame_size); + // celt_mode_info(mode, CELT_GET_NB_CHANNELS, &_channel); + + enc = celt_encoder_create(mode); + dec = celt_decoder_create(mode); + + } + + ~Celt() + { + terminateCelt(); + } + + void terminateCelt() { + + celt_encoder_destroy(enc); + celt_decoder_destroy(dec); + } + + virtual int codecDecode (short *dst, unsigned char *src, unsigned int size) + { + int len = 0; + len = celt_decode(dec, src, size, (celt_int16_t*)dst); + return len; + } + + virtual int codecEncode (unsigned char *dst, short *src, unsigned int size) + { + int len = 0; + len = celt_encode(enc, (celt_int16_t *)src, NULL, dst, size); + return len; + } + + private: + + CELTMode *mode; + + CELTEncoder *enc; + CELTDecoder *dec; + + celt_int32_t _celt_frame_size; + celt_int32_t skip; + +}; + +// the class factories +extern "C" AudioCodec* create() { + return new Celt(115); +} + +extern "C" void destroy(AudioCodec* a) { + delete a; +} +