diff options
author | Benny Prijono <bennylp@teluu.com> | 2011-10-14 04:15:15 +0000 |
---|---|---|
committer | Benny Prijono <bennylp@teluu.com> | 2011-10-14 04:15:15 +0000 |
commit | de1679edb534fafe595aa0dbcfd41086c4d51277 (patch) | |
tree | 30eeab4eb7bc03d6a8037202b12acef71ff82180 | |
parent | d3f073e11620f76da99dd660356c3094c13cd810 (diff) |
Committing re #1388: Support for OpenCORE AMR-NB codec (thank you Dan Arrhenius for the contribution!)
git-svn-id: http://svn.pjsip.org/repos/pjproject/branches/1.x@3816 74dad513-b988-da41-8d7b-12977e46ad98
-rwxr-xr-x | aconfigure | 86 | ||||
-rw-r--r-- | aconfigure.ac | 28 | ||||
-rw-r--r-- | pjmedia/build/os-auto.mak.in | 7 | ||||
-rw-r--r-- | pjmedia/include/pjmedia-codec.h | 1 | ||||
-rw-r--r-- | pjmedia/include/pjmedia-codec/config.h | 7 | ||||
-rw-r--r-- | pjmedia/include/pjmedia-codec/config_auto.h.in | 5 | ||||
-rw-r--r-- | pjmedia/include/pjmedia-codec/opencore_amrnb.h | 89 | ||||
-rw-r--r-- | pjmedia/src/pjmedia-codec/opencore_amrnb.c | 814 | ||||
-rw-r--r-- | pjmedia/src/test/mips_test.c | 40 | ||||
-rw-r--r-- | pjsip-apps/src/samples/encdec.c | 3 | ||||
-rw-r--r-- | pjsip-apps/src/samples/jbsim.c | 3 | ||||
-rw-r--r-- | pjsip-apps/src/samples/pcaputil.c | 4 | ||||
-rw-r--r-- | pjsip-apps/src/samples/pjsip-perf.c | 3 | ||||
-rw-r--r-- | pjsip-apps/src/samples/streamutil.c | 5 | ||||
-rw-r--r-- | pjsip/src/pjsua-lib/pjsua_media.c | 14 |
15 files changed, 1109 insertions, 0 deletions
@@ -596,6 +596,9 @@ ac_main_obj ac_host ac_linux_poll ac_cross_compile +opencore_amrnb_present +opencore_amrnb_h_present +ac_no_opencore_amrnb libcrypto_present libssl_present openssl_h_present @@ -721,6 +724,7 @@ with_ipp with_ipp_samples with_ipp_arch enable_ssl +enable_opencore_amrnb ' ac_precious_vars='build_alias host_alias @@ -1374,6 +1378,10 @@ Optional Features: --with-ipp-samples options --disable-ssl Exclude SSL support the build (default: autodetect) + --disable-opencore-amrnb + Exclude OpenCORE AMR-NB support from the build + (default: autodetect) + Optional Packages: --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] @@ -6259,6 +6267,84 @@ fi +# Check whether --enable-opencore_amrnb was given. +if test "${enable_opencore_amrnb+set}" = set; then : + enableval=$enable_opencore_amrnb; + if test "$enable_opencore_amrnb" = "no"; then + ac_no_opencore_amrnb=1 + $as_echo "#define PJMEDIA_HAS_OPENCORE_AMRNB_CODEC 0" >>confdefs.h + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: Checking if OpenCORE AMR-NB support is disabled... yes" >&5 +$as_echo "Checking if OpenCORE AMR-NB support is disabled... yes" >&6; } + fi + +else + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: checking for OpenCORE AMR-NB installations.." >&5 +$as_echo "checking for OpenCORE AMR-NB installations.." >&6; } + + + ac_fn_c_check_header_mongrel "$LINENO" "opencore-amrnb/interf_enc.h" "ac_cv_header_opencore_amrnb_interf_enc_h" "$ac_includes_default" +if test "x$ac_cv_header_opencore_amrnb_interf_enc_h" = x""yes; then : + opencore_amrnb_h_present=1 +fi + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Encoder_Interface_init in -lopencore-amrnb" >&5 +$as_echo_n "checking for Encoder_Interface_init in -lopencore-amrnb... " >&6; } +if test "${ac_cv_lib_opencore_amrnb_Encoder_Interface_init+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lopencore-amrnb $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char Encoder_Interface_init (); +int +main () +{ +return Encoder_Interface_init (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_opencore_amrnb_Encoder_Interface_init=yes +else + ac_cv_lib_opencore_amrnb_Encoder_Interface_init=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_opencore_amrnb_Encoder_Interface_init" >&5 +$as_echo "$ac_cv_lib_opencore_amrnb_Encoder_Interface_init" >&6; } +if test "x$ac_cv_lib_opencore_amrnb_Encoder_Interface_init" = x""yes; then : + opencore_amrnb_present=1 && LIBS="$LIBS -lopencore-amrnb" +fi + + if test "x$opencore_amrnb_h_present" = "x1" -a "x$opencore_amrnb_present" = "x1"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: OpenCORE AMR-NB library found, AMR-NB support enabled" >&5 +$as_echo "OpenCORE AMR-NB library found, AMR-NB support enabled" >&6; } + $as_echo "#define PJMEDIA_HAS_OPENCORE_AMRNB_CODEC 1" >>confdefs.h + + else + ac_no_opencore_amrnb=1 + $as_echo "#define PJMEDIA_HAS_OPENCORE_AMRNB_CODEC 0" >>confdefs.h + + fi + +fi + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if select() needs correct nfds" >&5 diff --git a/aconfigure.ac b/aconfigure.ac index 2efb3a18..c9848253 100644 --- a/aconfigure.ac +++ b/aconfigure.ac @@ -997,6 +997,34 @@ AC_ARG_ENABLE(ssl, fi ]) +dnl # Include opencore-amrnb support +AC_SUBST(ac_no_opencore_amrnb) +AC_ARG_ENABLE(opencore_amrnb, + AC_HELP_STRING([--disable-opencore-amrnb], + [Exclude OpenCORE AMR-NB support from the build (default: autodetect)]) + , + [ + if test "$enable_opencore_amrnb" = "no"; then + [ac_no_opencore_amrnb=1] + AC_DEFINE(PJMEDIA_HAS_OPENCORE_AMRNB_CODEC,0) + AC_MSG_RESULT([Checking if OpenCORE AMR-NB support is disabled... yes]) + fi + ], + [ + AC_MSG_RESULT([checking for OpenCORE AMR-NB installations..]) + AC_SUBST(opencore_amrnb_h_present) + AC_SUBST(opencore_amrnb_present) + AC_CHECK_HEADER(opencore-amrnb/interf_enc.h,[opencore_amrnb_h_present=1]) + AC_CHECK_LIB(opencore-amrnb,Encoder_Interface_init,[opencore_amrnb_present=1 && LIBS="$LIBS -lopencore-amrnb"]) + if test "x$opencore_amrnb_h_present" = "x1" -a "x$opencore_amrnb_present" = "x1"; then + AC_MSG_RESULT([OpenCORE AMR-NB library found, AMR-NB support enabled]) + AC_DEFINE(PJMEDIA_HAS_OPENCORE_AMRNB_CODEC,1) + else + [ac_no_opencore_amrnb=1] + AC_DEFINE(PJMEDIA_HAS_OPENCORE_AMRNB_CODEC,0) + fi + ]) + dnl ########################################## dnl # diff --git a/pjmedia/build/os-auto.mak.in b/pjmedia/build/os-auto.mak.in index a329f76c..145f1d5d 100644 --- a/pjmedia/build/os-auto.mak.in +++ b/pjmedia/build/os-auto.mak.in @@ -29,6 +29,7 @@ AC_NO_SPEEX_CODEC=@ac_no_speex_codec@ AC_NO_ILBC_CODEC=@ac_no_ilbc_codec@ AC_NO_G722_CODEC=@ac_no_g722_codec@ AC_NO_G7221_CODEC=@ac_no_g7221_codec@ +AC_NO_OPENCORE_AMRNB=@ac_no_opencore_amrnb@ export CODEC_OBJS= @@ -81,6 +82,12 @@ export CODEC_OBJS += g7221.o export G7221_CFLAGS += -I$(THIRD_PARTY) endif +ifeq ($(AC_NO_OPENCORE_AMRNB),1) +export CFLAGS += -DPJMEDIA_HAS_OPENCORE_AMRNB_CODEC=0 +else +export CODEC_OBJS += opencore_amrnb.o +endif + # # PortAudio diff --git a/pjmedia/include/pjmedia-codec.h b/pjmedia/include/pjmedia-codec.h index 7ff72257..b010ef44 100644 --- a/pjmedia/include/pjmedia-codec.h +++ b/pjmedia/include/pjmedia-codec.h @@ -33,6 +33,7 @@ #include <pjmedia-codec/g7221.h> #include <pjmedia-codec/ipp_codecs.h> #include <pjmedia-codec/passthrough.h> +#include <pjmedia-codec/opencore_amrnb.h> #endif /* __PJMEDIA_CODEC_PJMEDIA_CODEC_H__ */ diff --git a/pjmedia/include/pjmedia-codec/config.h b/pjmedia/include/pjmedia-codec/config.h index 693fb106..40fa3779 100644 --- a/pjmedia/include/pjmedia-codec/config.h +++ b/pjmedia/include/pjmedia-codec/config.h @@ -313,6 +313,13 @@ #endif /** + * OpenCORE AMR-NB codec is enabled by default. + */ +#ifndef PJMEDIA_HAS_OPENCORE_AMRNB_CODEC +# define PJMEDIA_HAS_OPENCORE_AMRNB_CODEC 0 +#endif + +/** * Default G.722.1 codec encoder and decoder level adjustment. * If the value is non-zero, then PCM input samples to the encoder will * be shifted right by this value, and similarly PCM output samples from diff --git a/pjmedia/include/pjmedia-codec/config_auto.h.in b/pjmedia/include/pjmedia-codec/config_auto.h.in index 9c2a9af2..c469d795 100644 --- a/pjmedia/include/pjmedia-codec/config_auto.h.in +++ b/pjmedia/include/pjmedia-codec/config_auto.h.in @@ -69,6 +69,11 @@ #undef PJMEDIA_HAS_G7221_CODEC #endif +/* OpenCORE AMR-NB codec */ +#ifndef PJMEDIA_HAS_OPENCORE_AMRNB_CODEC +#undef PJMEDIA_HAS_OPENCORE_AMRNB_CODEC +#endif + #endif /* __PJMEDIA_CODEC_CONFIG_AUTO_H_ */ diff --git a/pjmedia/include/pjmedia-codec/opencore_amrnb.h b/pjmedia/include/pjmedia-codec/opencore_amrnb.h new file mode 100644 index 00000000..3e618e46 --- /dev/null +++ b/pjmedia/include/pjmedia-codec/opencore_amrnb.h @@ -0,0 +1,89 @@ +/* $Id$ */ +/* + * Copyright (C) 2011 Teluu Inc. (http://www.teluu.com) + * Copyright (C) 2011 Dan Arrhenius <dan@keystream.se> + * + * 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 2 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#ifndef __PJMEDIA_CODEC_OPENCORE_AMRNB_H__ +#define __PJMEDIA_CODEC_OPENCORE_AMRNB_H__ + +#include <pjmedia-codec/types.h> + +/** + * @defgroup PJMED_OC_AMRNB OpenCORE AMR-NB Codec + * @ingroup PJMEDIA_CODEC_CODECS + * @brief AMRCodec wrapper for OpenCORE AMR-NB codec + * @{ + */ + +PJ_BEGIN_DECL + +/** + * Settings. Use #pjmedia_codec_opencore_amrnb_set_config() to + * activate. + */ +typedef struct pjmedia_codec_amrnb_config +{ + /** + * Control whether to use octent align. + */ + pj_bool_t octet_align; + + /** + * Set the bitrate. + */ + unsigned bitrate; + +} pjmedia_codec_amrnb_config; + + +/** + * Initialize and register AMR-NB codec factory to pjmedia endpoint. + * + * @param endpt The pjmedia endpoint. + * + * @return PJ_SUCCESS on success. + */ +PJ_DECL(pj_status_t) pjmedia_codec_opencore_amrnb_init(pjmedia_endpt* endpt); + +/** + * Unregister AMR-NB codec factory from pjmedia endpoint and deinitialize + * the OpenCORE codec library. + * + * @return PJ_SUCCESS on success. + */ +PJ_DECL(pj_status_t) pjmedia_codec_opencore_amrnb_deinit(void); + + +/** + * Set AMR-NB parameters. + * + * @param cfg The settings; + * + * @return PJ_SUCCESS on success. + */ +PJ_DECL(pj_status_t) pjmedia_codec_opencore_amrnb_set_config( + const pjmedia_codec_amrnb_config* cfg); + +PJ_END_DECL + + +/** + * @} + */ + +#endif /* __PJMEDIA_CODEC_OPENCORE_AMRNB_H__ */ + diff --git a/pjmedia/src/pjmedia-codec/opencore_amrnb.c b/pjmedia/src/pjmedia-codec/opencore_amrnb.c new file mode 100644 index 00000000..ea10d83b --- /dev/null +++ b/pjmedia/src/pjmedia-codec/opencore_amrnb.c @@ -0,0 +1,814 @@ +/* $Id */ +/* + * Copyright (C) 2011 Teluu Inc. (http://www.teluu.com) + * Copyright (C) 2011 Dan Arrhenius <dan@keystream.se> + * + * 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 2 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * AMR-NB codec implementation with OpenCORE AMRNB library + */ +#include <pjmedia-codec/g722.h> +#include <pjmedia/codec.h> +#include <pjmedia/errno.h> +#include <pjmedia/endpoint.h> +#include <pjmedia/plc.h> +#include <pjmedia/port.h> +#include <pjmedia/silencedet.h> +#include <pj/assert.h> +#include <pj/log.h> +#include <pj/pool.h> +#include <pj/string.h> +#include <pj/os.h> +#include <pj/math.h> + +#if defined(PJMEDIA_HAS_OPENCORE_AMRNB_CODEC) && \ + (PJMEDIA_HAS_OPENCORE_AMRNB_CODEC != 0) + +#include <opencore-amrnb/interf_enc.h> +#include <opencore-amrnb/interf_dec.h> +#include <pjmedia-codec/amr_helper.h> +#include <pjmedia-codec/opencore_amrnb.h> + +#define THIS_FILE "opencore_amrnb.c" + +/* Tracing */ +#define PJ_TRACE 0 + +#if PJ_TRACE +# define TRACE_(expr) PJ_LOG(4,expr) +#else +# define TRACE_(expr) +#endif + +/* Use PJMEDIA PLC */ +#define USE_PJMEDIA_PLC 1 + + + +/* Prototypes for AMR-NB factory */ +static pj_status_t amr_test_alloc(pjmedia_codec_factory *factory, + const pjmedia_codec_info *id ); +static pj_status_t amr_default_attr(pjmedia_codec_factory *factory, + const pjmedia_codec_info *id, + pjmedia_codec_param *attr ); +static pj_status_t amr_enum_codecs(pjmedia_codec_factory *factory, + unsigned *count, + pjmedia_codec_info codecs[]); +static pj_status_t amr_alloc_codec(pjmedia_codec_factory *factory, + const pjmedia_codec_info *id, + pjmedia_codec **p_codec); +static pj_status_t amr_dealloc_codec(pjmedia_codec_factory *factory, + pjmedia_codec *codec ); + +/* Prototypes for AMR-NB implementation. */ +static pj_status_t amr_codec_init(pjmedia_codec *codec, + pj_pool_t *pool ); +static pj_status_t amr_codec_open(pjmedia_codec *codec, + pjmedia_codec_param *attr ); +static pj_status_t amr_codec_close(pjmedia_codec *codec ); +static pj_status_t amr_codec_modify(pjmedia_codec *codec, + const pjmedia_codec_param *attr ); +static pj_status_t amr_codec_parse(pjmedia_codec *codec, + void *pkt, + pj_size_t pkt_size, + const pj_timestamp *ts, + unsigned *frame_cnt, + pjmedia_frame frames[]); +static pj_status_t amr_codec_encode(pjmedia_codec *codec, + const struct pjmedia_frame *input, + unsigned output_buf_len, + struct pjmedia_frame *output); +static pj_status_t amr_codec_decode(pjmedia_codec *codec, + const struct pjmedia_frame *input, + unsigned output_buf_len, + struct pjmedia_frame *output); +static pj_status_t amr_codec_recover(pjmedia_codec *codec, + unsigned output_buf_len, + struct pjmedia_frame *output); + + + +/* Definition for AMR-NB codec operations. */ +static pjmedia_codec_op amr_op = +{ + &amr_codec_init, + &amr_codec_open, + &amr_codec_close, + &amr_codec_modify, + &amr_codec_parse, + &amr_codec_encode, + &amr_codec_decode, + &amr_codec_recover +}; + +/* Definition for AMR-NB codec factory operations. */ +static pjmedia_codec_factory_op amr_factory_op = +{ + &amr_test_alloc, + &amr_default_attr, + &amr_enum_codecs, + &amr_alloc_codec, + &amr_dealloc_codec +}; + + +/* AMR-NB factory */ +static struct amr_codec_factory +{ + pjmedia_codec_factory base; + pjmedia_endpt *endpt; + pj_pool_t *pool; +} amr_codec_factory; + + +/* AMR-NB codec private data. */ +struct amr_data +{ + pj_pool_t *pool; + void *encoder; + void *decoder; + pj_bool_t plc_enabled; + pj_bool_t vad_enabled; + int enc_mode; + pjmedia_codec_amr_pack_setting enc_setting; + pjmedia_codec_amr_pack_setting dec_setting; +#if USE_PJMEDIA_PLC + pjmedia_plc *plc; +#endif + pj_timestamp last_tx; +}; + +static pjmedia_codec_amrnb_config def_config = +{ + PJ_FALSE, /* octet align */ + 5900 /* bitrate */ +}; + + + +/* + * Initialize and register AMR-NB codec factory to pjmedia endpoint. + */ +PJ_DEF(pj_status_t) pjmedia_codec_opencore_amrnb_init( pjmedia_endpt *endpt ) +{ + pjmedia_codec_mgr *codec_mgr; + pj_status_t status; + + if (amr_codec_factory.pool != NULL) + return PJ_SUCCESS; + + /* Create AMR-NB codec factory. */ + amr_codec_factory.base.op = &amr_factory_op; + amr_codec_factory.base.factory_data = NULL; + amr_codec_factory.endpt = endpt; + + amr_codec_factory.pool = pjmedia_endpt_create_pool(endpt, "amrnb", 1000, + 1000); + if (!amr_codec_factory.pool) + return PJ_ENOMEM; + + /* Get the codec manager. */ + codec_mgr = pjmedia_endpt_get_codec_mgr(endpt); + if (!codec_mgr) { + status = PJ_EINVALIDOP; + goto on_error; + } + + /* Register codec factory to endpoint. */ + status = pjmedia_codec_mgr_register_factory(codec_mgr, + &amr_codec_factory.base); + if (status != PJ_SUCCESS) + goto on_error; + + /* Done. */ + return PJ_SUCCESS; + +on_error: + pj_pool_release(amr_codec_factory.pool); + amr_codec_factory.pool = NULL; + return status; +} + + +/* + * Unregister AMR-NB codec factory from pjmedia endpoint and deinitialize + * the AMR-NB codec library. + */ +PJ_DEF(pj_status_t) pjmedia_codec_opencore_amrnb_deinit(void) +{ + pjmedia_codec_mgr *codec_mgr; + pj_status_t status; + + if (amr_codec_factory.pool == NULL) + return PJ_SUCCESS; + + /* Get the codec manager. */ + codec_mgr = pjmedia_endpt_get_codec_mgr(amr_codec_factory.endpt); + if (!codec_mgr) { + pj_pool_release(amr_codec_factory.pool); + amr_codec_factory.pool = NULL; + return PJ_EINVALIDOP; + } + + /* Unregister AMR-NB codec factory. */ + status = pjmedia_codec_mgr_unregister_factory(codec_mgr, + &amr_codec_factory.base); + + /* Destroy pool. */ + pj_pool_release(amr_codec_factory.pool); + amr_codec_factory.pool = NULL; + + return status; +} + + +PJ_DEF(pj_status_t) pjmedia_codec_opencore_amrnb_set_config( + const pjmedia_codec_amrnb_config *config) +{ + unsigned nbitrates; + + + def_config = *config; + + /* Normalize bitrate. */ + nbitrates = PJ_ARRAY_SIZE(pjmedia_codec_amrnb_bitrates); + if (def_config.bitrate < pjmedia_codec_amrnb_bitrates[0]) + def_config.bitrate = pjmedia_codec_amrnb_bitrates[0]; + else if (def_config.bitrate > pjmedia_codec_amrnb_bitrates[nbitrates-1]) + def_config.bitrate = pjmedia_codec_amrnb_bitrates[nbitrates-1]; + else + { + unsigned i; + + for (i = 0; i < nbitrates; ++i) { + if (def_config.bitrate <= pjmedia_codec_amrnb_bitrates[i]) + break; + } + def_config.bitrate = pjmedia_codec_amrnb_bitrates[i]; + } + + return PJ_SUCCESS; +} + +/* + * Check if factory can allocate the specified codec. + */ +static pj_status_t amr_test_alloc( pjmedia_codec_factory *factory, + const pjmedia_codec_info *info ) +{ + PJ_UNUSED_ARG(factory); + + /* Check payload type. */ + if (info->pt != PJMEDIA_RTP_PT_AMR) + return PJMEDIA_CODEC_EUNSUP; + + /* Ignore the rest, since it's static payload type. */ + + return PJ_SUCCESS; +} + +/* + * Generate default attribute. + */ +static pj_status_t amr_default_attr( pjmedia_codec_factory *factory, + const pjmedia_codec_info *id, + pjmedia_codec_param *attr ) +{ + PJ_UNUSED_ARG(factory); + PJ_UNUSED_ARG(id); + + pj_bzero(attr, sizeof(pjmedia_codec_param)); + attr->info.clock_rate = 8000; + attr->info.channel_cnt = 1; + attr->info.avg_bps = def_config.bitrate; + attr->info.max_bps = pjmedia_codec_amrnb_bitrates[7]; + attr->info.pcm_bits_per_sample = 16; + attr->info.frm_ptime = 20; + attr->info.pt = PJMEDIA_RTP_PT_AMR; + + attr->setting.frm_per_pkt = 4; + attr->setting.vad = 1; + attr->setting.plc = 1; + + if (def_config.octet_align) { + attr->setting.dec_fmtp.cnt = 1; + attr->setting.dec_fmtp.param[0].name = pj_str("octet-align"); + attr->setting.dec_fmtp.param[0].val = pj_str("1"); + } + + /* Default all other flag bits disabled. */ + + return PJ_SUCCESS; +} + + +/* + * Enum codecs supported by this factory (i.e. only AMR-NB!). + */ +static pj_status_t amr_enum_codecs( pjmedia_codec_factory *factory, + unsigned *count, + pjmedia_codec_info codecs[]) +{ + PJ_UNUSED_ARG(factory); + PJ_ASSERT_RETURN(codecs && *count > 0, PJ_EINVAL); + + pj_bzero(&codecs[0], sizeof(pjmedia_codec_info)); + codecs[0].encoding_name = pj_str("AMR"); + codecs[0].pt = PJMEDIA_RTP_PT_AMR; + codecs[0].type = PJMEDIA_TYPE_AUDIO; + codecs[0].clock_rate = 8000; + codecs[0].channel_cnt = 1; + + *count = 1; + + return PJ_SUCCESS; +} + + +/* + * Allocate a new AMR-NB codec instance. + */ +static pj_status_t amr_alloc_codec( pjmedia_codec_factory *factory, + const pjmedia_codec_info *id, + pjmedia_codec **p_codec) +{ + pj_pool_t *pool; + pjmedia_codec *codec; + struct amr_data *amr_data; + pj_status_t status; + + PJ_ASSERT_RETURN(factory && id && p_codec, PJ_EINVAL); + PJ_ASSERT_RETURN(factory == &amr_codec_factory.base, PJ_EINVAL); + + pool = pjmedia_endpt_create_pool(amr_codec_factory.endpt, "amrnb-inst", + 512, 512); + + codec = PJ_POOL_ZALLOC_T(pool, pjmedia_codec); + PJ_ASSERT_RETURN(codec != NULL, PJ_ENOMEM); + codec->op = &amr_op; + codec->factory = factory; + + amr_data = PJ_POOL_ZALLOC_T(pool, struct amr_data); + codec->codec_data = amr_data; + amr_data->pool = pool; + +#if USE_PJMEDIA_PLC + /* Create PLC */ + status = pjmedia_plc_create(pool, 8000, 160, 0, &amr_data->plc); + if (status != PJ_SUCCESS) { + return status; + } +#else + PJ_UNUSED_ARG(status); +#endif + *p_codec = codec; + return PJ_SUCCESS; +} + + +/* + * Free codec. + */ +static pj_status_t amr_dealloc_codec( pjmedia_codec_factory *factory, + pjmedia_codec *codec ) +{ + struct amr_data *amr_data; + + PJ_ASSERT_RETURN(factory && codec, PJ_EINVAL); + PJ_ASSERT_RETURN(factory == &amr_codec_factory.base, PJ_EINVAL); + + amr_data = (struct amr_data*) codec->codec_data; + + /* Close codec, if it's not closed. */ + amr_codec_close(codec); + + pj_pool_release(amr_data->pool); + amr_data = NULL; + + return PJ_SUCCESS; +} + +/* + * Init codec. + */ +static pj_status_t amr_codec_init( pjmedia_codec *codec, + pj_pool_t *pool ) +{ + PJ_UNUSED_ARG(codec); + PJ_UNUSED_ARG(pool); + return PJ_SUCCESS; +} + + +/* + * Open codec. + */ +static pj_status_t amr_codec_open( pjmedia_codec *codec, + pjmedia_codec_param *attr ) +{ + struct amr_data *amr_data = (struct amr_data*) codec->codec_data; + pjmedia_codec_amr_pack_setting *setting; + unsigned i; + pj_uint8_t octet_align = 0; + pj_int8_t enc_mode; + const pj_str_t STR_FMTP_OCTET_ALIGN = {"octet-align", 11}; + + PJ_ASSERT_RETURN(codec && attr, PJ_EINVAL); + PJ_ASSERT_RETURN(amr_data != NULL, PJ_EINVALIDOP); + + enc_mode = pjmedia_codec_amr_get_mode(attr->info.avg_bps); + pj_assert(enc_mode >= 0 && enc_mode <= 7); + + /* Check octet-align */ + for (i = 0; i < attr->setting.dec_fmtp.cnt; ++i) { + if (pj_stricmp(&attr->setting.dec_fmtp.param[i].name, + &STR_FMTP_OCTET_ALIGN) == 0) + { + octet_align = (pj_uint8_t) + (pj_strtoul(&attr->setting.dec_fmtp.param[i].val)); + break; + } + } + + /* Check mode-set */ + for (i = 0; i < attr->setting.enc_fmtp.cnt; ++i) { + const pj_str_t STR_FMTP_MODE_SET = {"mode-set", 8}; + + if (pj_stricmp(&attr->setting.enc_fmtp.param[i].name, + &STR_FMTP_MODE_SET) == 0) + { + const char *p; + pj_size_t l; + pj_int8_t diff = 99; + + /* Encoding mode is chosen based on local default mode setting: + * - if local default mode is included in the mode-set, use it + * - otherwise, find the closest mode to local default mode; + * if there are two closest modes, prefer to use the higher + * one, e.g: local default mode is 4, the mode-set param + * contains '2,3,5,6', then 5 will be chosen. + */ + p = pj_strbuf(&attr->setting.enc_fmtp.param[i].val); + l = pj_strlen(&attr->setting.enc_fmtp.param[i].val); + while (l--) { + if (*p>='0' && *p<='7') { + pj_int8_t tmp = *p - '0' - enc_mode; + + if (PJ_ABS(diff) > PJ_ABS(tmp) || + (PJ_ABS(diff) == PJ_ABS(tmp) && tmp > diff)) + { + diff = tmp; + if (diff == 0) break; + } + } + ++p; + } + PJ_ASSERT_RETURN(diff != 99, PJMEDIA_CODEC_EFAILED); + + enc_mode = enc_mode + diff; + + break; + } + } + + amr_data->vad_enabled = (attr->setting.vad != 0); + amr_data->plc_enabled = (attr->setting.plc != 0); + amr_data->enc_mode = enc_mode; + + amr_data->encoder = Encoder_Interface_init(amr_data->vad_enabled); + if (amr_data->encoder == NULL) { + TRACE_((THIS_FILE, "Encoder_Interface_init() failed")); + amr_codec_close(codec); + return PJMEDIA_CODEC_EFAILED; + } + setting = &amr_data->enc_setting; + pj_bzero(setting, sizeof(pjmedia_codec_amr_pack_setting)); + setting->amr_nb = 1; + setting->reorder = 0; + setting->octet_aligned = octet_align; + setting->cmr = 15; + + amr_data->decoder = Decoder_Interface_init(); + if (amr_data->decoder == NULL) { + TRACE_((THIS_FILE, "Decoder_Interface_init() failed")); + amr_codec_close(codec); + return PJMEDIA_CODEC_EFAILED; + } + setting = &amr_data->dec_setting; + pj_bzero(setting, sizeof(pjmedia_codec_amr_pack_setting)); + setting->amr_nb = 1; + setting->reorder = 0; + setting->octet_aligned = octet_align; + + TRACE_((THIS_FILE, "AMR-NB codec allocated: vad=%d, plc=%d, bitrate=%d", + amr_data->vad_enabled, amr_data->plc_enabled, + pjmedia_codec_amrnb_bitrates[amr_data->enc_mode])); + return PJ_SUCCESS; +} + + +/* + * Close codec. + */ +static pj_status_t amr_codec_close( pjmedia_codec *codec ) +{ + struct amr_data *amr_data; + + PJ_ASSERT_RETURN(codec, PJ_EINVAL); + + amr_data = (struct amr_data*) codec->codec_data; + PJ_ASSERT_RETURN(amr_data != NULL, PJ_EINVALIDOP); + + if (amr_data->encoder) { + Encoder_Interface_exit(amr_data->encoder); + amr_data->encoder = NULL; + } + + if (amr_data->decoder) { + Decoder_Interface_exit(amr_data->decoder); + amr_data->decoder = NULL; + } + + TRACE_((THIS_FILE, "AMR-NB codec closed")); + return PJ_SUCCESS; +} + + +/* + * Modify codec settings. + */ +static pj_status_t amr_codec_modify( pjmedia_codec *codec, + const pjmedia_codec_param *attr ) +{ + struct amr_data *amr_data = (struct amr_data*) codec->codec_data; + pj_bool_t prev_vad_state; + + pj_assert(amr_data != NULL); + pj_assert(amr_data->encoder != NULL && amr_data->decoder != NULL); + + prev_vad_state = amr_data->vad_enabled; + amr_data->vad_enabled = (attr->setting.vad != 0); + amr_data->plc_enabled = (attr->setting.plc != 0); + + if (prev_vad_state != amr_data->vad_enabled) { + /* Reinit AMR encoder to update VAD setting */ + TRACE_((THIS_FILE, "Reiniting AMR encoder to update VAD setting.")); + Encoder_Interface_exit(amr_data->encoder); + amr_data->encoder = Encoder_Interface_init(amr_data->vad_enabled); + if (amr_data->encoder == NULL) { + TRACE_((THIS_FILE, "Encoder_Interface_init() failed")); + amr_codec_close(codec); + return PJMEDIA_CODEC_EFAILED; + } + } + + TRACE_((THIS_FILE, "AMR-NB codec modified: vad=%d, plc=%d", + amr_data->vad_enabled, amr_data->plc_enabled)); + return PJ_SUCCESS; +} + + +/* + * Get frames in the packet. + */ +static pj_status_t amr_codec_parse( pjmedia_codec *codec, + void *pkt, + pj_size_t pkt_size, + const pj_timestamp *ts, + unsigned *frame_cnt, + pjmedia_frame frames[]) +{ + struct amr_data *amr_data = (struct amr_data*) codec->codec_data; + pj_uint8_t cmr; + pj_status_t status; + + status = pjmedia_codec_amr_parse(pkt, pkt_size, ts, &amr_data->dec_setting, + frames, frame_cnt, &cmr); + if (status != PJ_SUCCESS) + return status; + + /* Check for Change Mode Request. */ + if (cmr <= 7 && amr_data->enc_mode != cmr) { + amr_data->enc_mode = cmr; + TRACE_((THIS_FILE, "AMR-NB encoder switched mode to %d (%dbps)", + amr_data->enc_mode, + pjmedia_codec_amrnb_bitrates[amr_data->enc_mode])); + } + + return PJ_SUCCESS; +} + + +/* + * Encode frame. + */ +static pj_status_t amr_codec_encode( pjmedia_codec *codec, + const struct pjmedia_frame *input, + unsigned output_buf_len, + struct pjmedia_frame *output) +{ + struct amr_data *amr_data = (struct amr_data*) codec->codec_data; + unsigned char *bitstream; + pj_int16_t *speech; + unsigned nsamples, samples_per_frame; + enum {MAX_FRAMES_PER_PACKET = 16}; + pjmedia_frame frames[MAX_FRAMES_PER_PACKET]; + pj_uint8_t *p; + unsigned i, out_size = 0, nframes = 0; + pj_size_t payload_len; + unsigned dtx_cnt, sid_cnt; + pj_status_t status; + int size; + + pj_assert(amr_data != NULL); + PJ_ASSERT_RETURN(input && output, PJ_EINVAL); + + nsamples = input->size >> 1; + samples_per_frame = 160; + PJ_ASSERT_RETURN(nsamples % samples_per_frame == 0, + PJMEDIA_CODEC_EPCMFRMINLEN); + + nframes = nsamples / samples_per_frame; + PJ_ASSERT_RETURN(nframes <= MAX_FRAMES_PER_PACKET, + PJMEDIA_CODEC_EFRMTOOSHORT); + + /* Encode the frames */ + speech = (pj_int16_t*)input->buf; + bitstream = (unsigned char*)output->buf; + while (nsamples >= samples_per_frame) { + size = Encoder_Interface_Encode (amr_data->encoder, amr_data->enc_mode, + speech, bitstream, 0); + if (size == 0) { + output->size = 0; + output->buf = NULL; + output->type = PJMEDIA_FRAME_TYPE_NONE; + TRACE_((THIS_FILE, "AMR-NB encode() failed")); + return PJMEDIA_CODEC_EFAILED; + } + nsamples -= 160; + speech += samples_per_frame; + bitstream += size; + out_size += size; + TRACE_((THIS_FILE, "AMR-NB encode(): mode=%d, size=%d", + amr_data->enc_mode, out_size)); + } + + /* Pack payload */ + p = (pj_uint8_t*)output->buf + output_buf_len - out_size; + pj_memmove(p, output->buf, out_size); + dtx_cnt = sid_cnt = 0; + for (i = 0; i < nframes; ++i) { + pjmedia_codec_amr_bit_info *info = (pjmedia_codec_amr_bit_info*) + &frames[i].bit_info; + info->frame_type = (pj_uint8_t)((*p >> 3) & 0x0F); + info->good_quality = (pj_uint8_t)((*p >> 2) & 0x01); + info->mode = (pj_int8_t)amr_data->enc_mode; + info->start_bit = 0; + frames[i].buf = p + 1; + frames[i].size = (info->frame_type <= 8)? + pjmedia_codec_amrnb_framelen[info->frame_type] : 0; + p += frames[i].size + 1; + + /* Count the number of SID and DTX frames */ + if (info->frame_type == 15) /* DTX*/ + ++dtx_cnt; + else if (info->frame_type == 8) /* SID */ + ++sid_cnt; + } + + /* VA generates DTX frames as DTX+SID frames switching quickly and it + * seems that the SID frames occur too often (assuming the purpose is + * only for keeping NAT alive?). So let's modify the behavior a bit. + * Only an SID frame will be sent every PJMEDIA_CODEC_MAX_SILENCE_PERIOD + * milliseconds. + */ + if (sid_cnt + dtx_cnt == nframes) { + pj_int32_t dtx_duration; + + dtx_duration = pj_timestamp_diff32(&amr_data->last_tx, + &input->timestamp); + if (PJMEDIA_CODEC_MAX_SILENCE_PERIOD == -1 || + dtx_duration < PJMEDIA_CODEC_MAX_SILENCE_PERIOD*8000/1000) + { + output->size = 0; + output->type = PJMEDIA_FRAME_TYPE_NONE; + output->timestamp = input->timestamp; + return PJ_SUCCESS; + } + } + + payload_len = output_buf_len; + + status = pjmedia_codec_amr_pack(frames, nframes, &amr_data->enc_setting, + output->buf, &payload_len); + if (status != PJ_SUCCESS) { + output->size = 0; + output->buf = NULL; + output->type = PJMEDIA_FRAME_TYPE_NONE; + TRACE_((THIS_FILE, "Failed to pack AMR payload, status=%d", status)); + return status; + } + + output->size = payload_len; + output->type = PJMEDIA_FRAME_TYPE_AUDIO; + output->timestamp = input->timestamp; + + amr_data->last_tx = input->timestamp; + + return PJ_SUCCESS; +} + + +/* + * Decode frame. + */ +static pj_status_t amr_codec_decode( pjmedia_codec *codec, + const struct pjmedia_frame *input, + unsigned output_buf_len, + struct pjmedia_frame *output) +{ + struct amr_data *amr_data = (struct amr_data*) codec->codec_data; + pjmedia_frame input_; + pjmedia_codec_amr_bit_info *info; + /* VA AMR-NB decoding buffer: AMR-NB max frame size + 1 byte header. */ + unsigned char bitstream[32]; + + pj_assert(amr_data != NULL); + PJ_ASSERT_RETURN(input && output, PJ_EINVAL); + + if (output_buf_len < 320) + return PJMEDIA_CODEC_EPCMTOOSHORT; + + input_.buf = &bitstream[1]; + input_.size = 31; /* AMR-NB max frame size */ + pjmedia_codec_amr_predecode(input, &amr_data->dec_setting, &input_); + info = (pjmedia_codec_amr_bit_info*)&input_.bit_info; + + /* VA AMRNB decoder requires frame info in the first byte. */ + bitstream[0] = (info->frame_type << 3) | (info->good_quality << 2); + + TRACE_((THIS_FILE, "AMR-NB decode(): mode=%d, ft=%d, size=%d", + info->mode, info->frame_type, input_.size)); + + /* Decode */ + Decoder_Interface_Decode(amr_data->decoder, bitstream, + (pj_int16_t*)output->buf, 0); + + output->size = 320; + output->type = PJMEDIA_FRAME_TYPE_AUDIO; + output->timestamp = input->timestamp; + +#if USE_PJMEDIA_PLC + if (amr_data->plc_enabled) + pjmedia_plc_save(amr_data->plc, (pj_int16_t*)output->buf); +#endif + + return PJ_SUCCESS; +} + + +/* + * Recover lost frame. + */ +#if USE_PJMEDIA_PLC +/* + * Recover lost frame. + */ +static pj_status_t amr_codec_recover( pjmedia_codec *codec, + unsigned output_buf_len, + struct pjmedia_frame *output) +{ + struct amr_data *amr_data = codec->codec_data; + + TRACE_((THIS_FILE, "amr_codec_recover")); + + PJ_ASSERT_RETURN(amr_data->plc_enabled, PJ_EINVALIDOP); + + PJ_ASSERT_RETURN(output_buf_len >= 320, PJMEDIA_CODEC_EPCMTOOSHORT); + + pjmedia_plc_generate(amr_data->plc, (pj_int16_t*)output->buf); + + output->size = 320; + output->type = PJMEDIA_FRAME_TYPE_AUDIO; + + return PJ_SUCCESS; +} +#endif + + + +#endif diff --git a/pjmedia/src/test/mips_test.c b/pjmedia/src/test/mips_test.c index d5ece9c7..1493b082 100644 --- a/pjmedia/src/test/mips_test.c +++ b/pjmedia/src/test/mips_test.c @@ -916,6 +916,23 @@ static pjmedia_port* g7221c_encode_decode(pj_pool_t *pool, } #endif /* PJMEDIA_HAS_G7221_CODEC */ +#if PJMEDIA_HAS_OPENCORE_AMRNB_CODEC +/* AMR-NB benchmark benchmark */ +static pjmedia_port* amr_encode_decode(pj_pool_t *pool, + unsigned clock_rate, + unsigned channel_count, + unsigned samples_per_frame, + unsigned flags, + struct test_entry *te) +{ + return codec_encode_decode(pool, "AMR/8000", + &pjmedia_codec_opencore_amrnb_init, + &pjmedia_codec_opencore_amrnb_deinit, + clock_rate, channel_count, + samples_per_frame, flags, te); +} +#endif /* PJMEDIA_HAS_OPENCORE_AMRNB_CODEC */ + #if defined(PJMEDIA_HAS_L16_CODEC) && PJMEDIA_HAS_L16_CODEC!=0 static pj_status_t init_l16_default(pjmedia_endpt *endpt) { @@ -1974,6 +1991,23 @@ static pjmedia_port* create_stream_g7221c( pj_pool_t *pool, } #endif /* PJMEDIA_HAS_G7221_CODEC */ +/* AMR-NB stream */ +#if PJMEDIA_HAS_OPENCORE_AMRNB_CODEC +static pjmedia_port* create_stream_amr( pj_pool_t *pool, + unsigned clock_rate, + unsigned channel_count, + unsigned samples_per_frame, + unsigned flags, + struct test_entry *te) +{ + return create_stream(pool, "AMR/8000", &pjmedia_codec_opencore_amrnb_init, + &pjmedia_codec_opencore_amrnb_deinit, + PJ_FALSE, PJ_FALSE, PJ_FALSE, + clock_rate, channel_count, + samples_per_frame, flags, te); +} +#endif /* PJMEDIA_HAS_OPENCORE_AMRNB_CODEC */ + /***************************************************************************/ /* Delay buffer */ enum {DELAY_BUF_MAX_DELAY = 80}; @@ -2364,6 +2398,9 @@ int mips_test(void) { "codec encode/decode - G.722.1", OP_PUT, K16, &g7221_encode_decode}, { "codec encode/decode - G.722.1c", OP_PUT, K32, &g7221c_encode_decode}, #endif +#if PJMEDIA_HAS_OPENCORE_AMRNB_CODEC + { "codec encode/decode - AMR-NB", OP_PUT, K8, &amr_encode_decode}, +#endif #if PJMEDIA_HAS_L16_CODEC { "codec encode/decode - L16/8000/1", OP_PUT, K8, &l16_8_encode_decode}, { "codec encode/decode - L16/16000/1", OP_PUT, K16, &l16_16_encode_decode}, @@ -2389,6 +2426,9 @@ int mips_test(void) { "stream TX/RX - G.722.1", OP_PUT_GET, K16, &create_stream_g7221}, { "stream TX/RX - G.722.1c", OP_PUT_GET, K32, &create_stream_g7221c}, #endif +#if PJMEDIA_HAS_OPENCORE_AMRNB_CODEC + { "stream TX/RX - AMR-NB", OP_PUT_GET, K8, &create_stream_amr}, +#endif }; unsigned i, c, k[3] = {K8, K16, K32}, clock_rates[3] = {8000, 16000, 32000}; diff --git a/pjsip-apps/src/samples/encdec.c b/pjsip-apps/src/samples/encdec.c index 0d38ce88..f6693679 100644 --- a/pjsip-apps/src/samples/encdec.c +++ b/pjsip-apps/src/samples/encdec.c @@ -253,6 +253,9 @@ int main(int argc, char *argv[]) #if PJMEDIA_HAS_G722_CODEC CHECK( pjmedia_codec_g722_init(mept) ); #endif +#if PJMEDIA_HAS_OPENCORE_AMRNB_CODEC + CHECK( pjmedia_codec_opencore_amrnb_init(mept) ); +#endif pj_gettimeofday(&t0); status = enc_dec_test(argv[1], argv[2], argv[3]); diff --git a/pjsip-apps/src/samples/jbsim.c b/pjsip-apps/src/samples/jbsim.c index e023dd55..65d57a8c 100644 --- a/pjsip-apps/src/samples/jbsim.c +++ b/pjsip-apps/src/samples/jbsim.c @@ -494,6 +494,9 @@ static pj_status_t test_init(void) #if defined(PJMEDIA_HAS_INTEL_IPP) && PJMEDIA_HAS_INTEL_IPP != 0 pjmedia_codec_ipp_init(g_app.endpt); #endif +#if defined(PJMEDIA_HAS_OPENCORE_AMRNB_CODEC) && (PJMEDIA_HAS_OPENCORE_AMRNB_CODEC != 0) + pjmedia_codec_opencore_amrnb_init(g_app.endpt); +#endif #if defined(PJMEDIA_HAS_L16_CODEC) && PJMEDIA_HAS_L16_CODEC != 0 pjmedia_codec_l16_init(g_app.endpt, 0); #endif diff --git a/pjsip-apps/src/samples/pcaputil.c b/pjsip-apps/src/samples/pcaputil.c index 01c87129..ff4403d3 100644 --- a/pjsip-apps/src/samples/pcaputil.c +++ b/pjsip-apps/src/samples/pcaputil.c @@ -305,6 +305,10 @@ static void pcap2wav(const pj_str_t *codec, T( pjmedia_codec_l16_init(app.mept, 0) ); #endif /* PJMEDIA_HAS_L16_CODEC */ +#if PJMEDIA_HAS_OPENCORE_AMRNB_CODEC + T( pjmedia_codec_opencore_amrnb_init(app.mept) ); +#endif /* PJMEDIA_HAS_L16_CODEC */ + #if PJMEDIA_HAS_INTEL_IPP T( pjmedia_codec_ipp_init(app.mept) ); #endif diff --git a/pjsip-apps/src/samples/pjsip-perf.c b/pjsip-apps/src/samples/pjsip-perf.c index 9c8fec3a..851f79da 100644 --- a/pjsip-apps/src/samples/pjsip-perf.c +++ b/pjsip-apps/src/samples/pjsip-perf.c @@ -940,6 +940,9 @@ static pj_status_t init_media() #if defined(PJMEDIA_HAS_G722_CODEC) && PJMEDIA_HAS_G722_CODEC!=0 pjmedia_codec_g722_init(app.med_endpt); #endif +#if defined(PJMEDIA_HAS_OPENCORE_AMRNB_CODEC) && PJMEDIA_HAS_OPENCORE_AMRNB_CODEC!=0 + pjmedia_codec_opencore_amrnb_init(app.med_endpt); +#endif /* Init dummy socket addresses */ app.skinfo_cnt = 0; diff --git a/pjsip-apps/src/samples/streamutil.c b/pjsip-apps/src/samples/streamutil.c index 7237b7b8..1a449352 100644 --- a/pjsip-apps/src/samples/streamutil.c +++ b/pjsip-apps/src/samples/streamutil.c @@ -125,6 +125,11 @@ static pj_status_t init_codecs(pjmedia_endpt *med_endpt) PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); #endif +#if defined(PJMEDIA_HAS_OPENCORE_AMRNB_CODEC) && PJMEDIA_HAS_OPENCORE_AMRNB_CODEC!=0 + status = pjmedia_codec_opencore_amrnb_init(med_endpt); + PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); +#endif + #if defined(PJMEDIA_HAS_L16_CODEC) && PJMEDIA_HAS_L16_CODEC!=0 status = pjmedia_codec_l16_init(med_endpt, 0); PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); diff --git a/pjsip/src/pjsua-lib/pjsua_media.c b/pjsip/src/pjsua-lib/pjsua_media.c index bf121e78..e939dba9 100644 --- a/pjsip/src/pjsua-lib/pjsua_media.c +++ b/pjsip/src/pjsua-lib/pjsua_media.c @@ -274,6 +274,16 @@ pj_status_t pjsua_media_subsys_init(const pjsua_media_config *cfg) #endif /* PJMEDIA_HAS_L16_CODEC */ +#if PJMEDIA_HAS_OPENCORE_AMRNB_CODEC + /* Register OpenCORE AMR-NB codec */ + status = pjmedia_codec_opencore_amrnb_init(pjsua_var.med_endpt); + if (status != PJ_SUCCESS) { + pjsua_perror(THIS_FILE, "Error initializing OpenCORE AMR-NB codec", + status); + return status; + } +#endif /* PJMEDIA_HAS_OPENCORE_AMRNB_CODEC */ + /* Save additional conference bridge parameters for future * reference. @@ -729,6 +739,10 @@ pj_status_t pjsua_media_subsys_destroy(void) pjmedia_codec_l16_deinit(); # endif /* PJMEDIA_HAS_L16_CODEC */ +# if PJMEDIA_HAS_OPENCORE_AMRNB_CODEC + pjmedia_codec_opencore_amrnb_deinit(); +# endif /* PJMEDIA_HAS_OPENCORE_AMRNB_CODEC */ + pjmedia_endpt_destroy(pjsua_var.med_endpt); pjsua_var.med_endpt = NULL; |