diff --git a/configure.ac b/configure.ac index 43e13ba..39c2f76 100644 --- a/configure.ac +++ b/configure.ac @@ -23,6 +23,13 @@ AC_PROG_CC # libosmocore (codec module) PKG_CHECK_MODULES(LIBOSMOCODEC, libosmocodec >= 0.1.25) + # opencore-amrnb for AMR and EFR decoding +found_opencore_amrnb=yes +PKG_CHECK_MODULES(OPENCORE_AMRNB, opencore-amrnb >= 0.1.0, , found_libgsm=no) +if test "$found_opencore_amrnb" = yes; then + AC_DEFINE(HAVE_OPENCORE_AMRNB, 1, [Define to 1 if OpenCore AMR-NB library is available]) +fi + # libgsm for FR decoding found_libgsm=yes AC_CHECK_HEADERS(gsm/gsm.h, , diff --git a/src/Makefile.am b/src/Makefile.am index dc37076..dedb3f0 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) ${LIBGSM_LIBS} +AM_CFLAGS=-Wall $(LIBOSMOCODEC_CFLAGS) ${OPENCORE_AMRNB_CFLAGS} +AM_LDFLAGS=$(LIBOSMOCODEC_LIBS) ${OPENCORE_AMRNB_LIBS} ${LIBGSM_LIBS} bin_PROGRAMS = gapk gapk_SOURCES = main.c \ diff --git a/src/codec_efr.c b/src/codec_efr.c index 6c9b59e..ca5225c 100644 --- a/src/codec_efr.c +++ b/src/codec_efr.c @@ -19,9 +19,95 @@ #include +#include "config.h" + + +#ifdef HAVE_OPENCORE_AMRNB + +#include + +#include +#include + + +struct codec_efr_state { + void *encoder; + void *decoder; +}; + + +static void * +codec_efr_init(void) +{ + struct codec_efr_state *st; + + st = calloc(1, sizeof(*st)); + if (!st) + return NULL; + + st->encoder = Encoder_Interface_init(0); + st->decoder = Decoder_Interface_init(); + + return (void *)st; +} + +static void +codec_efr_exit(void *state) +{ + struct codec_efr_state *st = state; + + Decoder_Interface_exit(st->decoder); + Encoder_Interface_exit(st->encoder); + + return; +} + +static int +codec_efr_encode(void *state, uint8_t *cod, const uint8_t *pcm) +{ + struct codec_efr_state *st = state; + int rv; + + rv = Encoder_Interface_Encode( + st->encoder, + MR122, + (const short*) pcm, + (unsigned char*) cod, + 1 + ); + + return rv; +} + +static int +codec_efr_decode(void *state, uint8_t *pcm, const uint8_t *cod) +{ + struct codec_efr_state *st = state; + + Decoder_Interface_Decode( + st->decoder, + (const unsigned char*) cod, + (short *) pcm, + 0 + ); + + return 0; +} + +#endif /* HAVE_OPENCORE_AMRNB */ + + const struct codec_desc codec_efr_desc = { .type = CODEC_EFR, .name = "efr", .description = "GSM 06.60 Enhanced Full Rate codec", .canon_frame_len = 31, +#ifdef HAVE_OPENCORE_AMRNB + .codec_enc_format_type = FMT_AMR_EFR, + .codec_dec_format_type = FMT_AMR_EFR, + .codec_init = codec_efr_init, + .codec_exit = codec_efr_exit, + .codec_encode = codec_efr_encode, + .codec_decode = codec_efr_decode, +#endif };