aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSylvain Munaut <tnt@246tNt.com>2010-11-11 13:51:31 +0100
committerSylvain Munaut <tnt@246tNt.com>2010-11-11 20:26:41 +0100
commitdc5b38b99196f3e4e027dc8f0d8d21e8a0a7aa0c (patch)
tree4806ad344f2108bc7d29f2bf926fe32815b44e5b
parent24b761218f2db05f8e758640e3f7817410c43212 (diff)
codec/fr: Add support for encoding/decoding using libgsm
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
-rw-r--r--configure.ac11
-rw-r--r--src/Makefile.am2
-rw-r--r--src/codec_fr.c59
3 files changed, 71 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac
index c09b27f..43e13ba 100644
--- a/configure.ac
+++ b/configure.ac
@@ -20,8 +20,19 @@ AC_CONFIG_FILES([
AC_PROG_CC
# Checks for libraries.
+ # libosmocore (codec module)
PKG_CHECK_MODULES(LIBOSMOCODEC, libosmocodec >= 0.1.25)
+ # libgsm for FR decoding
+found_libgsm=yes
+AC_CHECK_HEADERS(gsm/gsm.h, ,
+ [AC_CHECK_HEADERS(gsm.h, ,found_libgsm=no)])
+ AC_CHECK_LIB(gsm, gsm_create, LIBGSM_LIBS="-lgsm", found_libgsm=no)
+if test "$found_libgsm" = yes; then
+ AC_DEFINE(HAVE_LIBGSM, 1, [Define to 1 if libgsm is available])
+fi
+AC_SUBST(LIBGSM_LIBS)
+
# Checks for header files.
AC_CHECK_HEADERS([stdint.h stdlib.h string.h unistd.h])
diff --git a/src/Makefile.am b/src/Makefile.am
index fa72df0..dc37076 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,6 +1,6 @@
INCLUDES = $(all_includes) -I$(top_srcdir)/include -I$(top_builddir)
AM_CFLAGS=-Wall $(LIBOSMOCODEC_CFLAGS)
-AM_LDFLAGS=$(LIBOSMOCODEC_LIBS)
+AM_LDFLAGS=$(LIBOSMOCODEC_LIBS) ${LIBGSM_LIBS}
bin_PROGRAMS = gapk
gapk_SOURCES = main.c \
diff --git a/src/codec_fr.c b/src/codec_fr.c
index 6f11269..3b1bb7c 100644
--- a/src/codec_fr.c
+++ b/src/codec_fr.c
@@ -19,9 +19,68 @@
#include <gapk/codecs.h>
+#include "config.h"
+
+
+#ifdef HAVE_LIBGSM
+
+/* Find header */
+#ifdef HAVE_GSM_H
+# include <gsm.h>
+#elif HAVE_GSM_GSM_H
+# include <gsm/gsm.h>
+#else
+# error "Can't find gsm.h header anywhere ..."
+#endif
+
+#include <string.h>
+
+
+static void *
+codec_fr_init(void)
+{
+ return (void *)gsm_create();
+}
+
+static void
+codec_fr_exit(void *state)
+{
+ gsm_destroy( (gsm)state );
+}
+
+static int
+codec_fr_encode(void *state, uint8_t *cod, const uint8_t *pcm)
+{
+ gsm gh = (gsm)state;
+ uint8_t pcm_b[2*160]; /* local copy as libgsm src isn't const ! */
+ memcpy(pcm_b, pcm, 2*160);
+ gsm_encode(gh, (gsm_signal*)pcm, (gsm_byte*)cod);
+ return 0;
+}
+
+static int
+codec_fr_decode(void *state, uint8_t *pcm, const uint8_t *cod)
+{
+ gsm gh = (gsm)state;
+ uint8_t cod_b[33]; /* local copy as libgsm src isn't const ! */
+ memcpy(cod_b, cod, 33);
+ return gsm_decode(gh, (gsm_byte*)cod_b, (gsm_signal*)pcm);
+}
+
+#endif /* HAVE_LIBGSM */
+
+
const struct codec_desc codec_fr_desc = {
.type = CODEC_FR,
.name = "fr",
.description = "GSM 06.10 Full Rate codec (classic gsm codec)",
.canon_frame_len = 33,
+#ifdef HAVE_LIBGSM
+ .codec_enc_format_type = FMT_GSM,
+ .codec_dec_format_type = FMT_GSM,
+ .codec_init = codec_fr_init,
+ .codec_exit = codec_fr_exit,
+ .codec_encode = codec_fr_encode,
+ .codec_decode = codec_fr_decode,
+#endif
};