mirror of https://gerrit.osmocom.org/gapk
codec/fr: Add support for encoding/decoding using libgsm
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
This commit is contained in:
parent
24b761218f
commit
dc5b38b991
11
configure.ac
11
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])
|
||||
|
||||
|
|
|
@ -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 \
|
||||
|
|
|
@ -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
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue