* #36737: switch back to svn repo, remove assert in sip_transaction.c
diff --git a/jni/pjproject-android/.svn/pristine/84/8404ee587fc7fab84089fc0b7148cd9203178469.svn-base b/jni/pjproject-android/.svn/pristine/84/8404ee587fc7fab84089fc0b7148cd9203178469.svn-base
new file mode 100644
index 0000000..875c821
--- /dev/null
+++ b/jni/pjproject-android/.svn/pristine/84/8404ee587fc7fab84089fc0b7148cd9203178469.svn-base
@@ -0,0 +1,465 @@
+/* $Id$ */
+/* 
+ * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
+ * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
+ *
+ * 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_CONFIG_H__
+#define __PJMEDIA_CODEC_CONFIG_H__
+
+/**
+ * @file config.h
+ * @brief PJMEDIA-CODEC compile time settings
+ */
+
+/**
+ * @defgroup pjmedia_codec_config PJMEDIA-CODEC Compile Time Settings
+ * @ingroup PJMEDIA_CODEC
+ * @brief Various compile time settings such as to enable/disable codecs
+ * @{
+ */
+
+#include <pjmedia/types.h>
+
+/*
+ * Include config_auto.h if autoconf is used (PJ_AUTOCONF is set)
+ */
+#if defined(PJ_AUTOCONF)
+#   include <pjmedia-codec/config_auto.h>
+#endif
+
+
+/**
+ * Unless specified otherwise, L16 codec is included by default.
+ */
+#ifndef PJMEDIA_HAS_L16_CODEC
+#   define PJMEDIA_HAS_L16_CODEC    1
+#endif
+
+
+/**
+ * Unless specified otherwise, GSM codec is included by default.
+ */
+#ifndef PJMEDIA_HAS_GSM_CODEC
+#   define PJMEDIA_HAS_GSM_CODEC    1
+#endif
+
+
+/**
+ * Unless specified otherwise, Speex codec is included by default.
+ */
+#ifndef PJMEDIA_HAS_SPEEX_CODEC
+#   define PJMEDIA_HAS_SPEEX_CODEC    1
+#endif
+
+/**
+ * Speex codec default complexity setting.
+ */
+#ifndef PJMEDIA_CODEC_SPEEX_DEFAULT_COMPLEXITY
+#   define PJMEDIA_CODEC_SPEEX_DEFAULT_COMPLEXITY   2
+#endif
+
+/**
+ * Speex codec default quality setting. Please note that pjsua-lib may override
+ * this setting via its codec quality setting (i.e PJSUA_DEFAULT_CODEC_QUALITY).
+ */
+#ifndef PJMEDIA_CODEC_SPEEX_DEFAULT_QUALITY
+#   define PJMEDIA_CODEC_SPEEX_DEFAULT_QUALITY	    8
+#endif
+
+
+/**
+ * Unless specified otherwise, iLBC codec is included by default.
+ */
+#ifndef PJMEDIA_HAS_ILBC_CODEC
+#   define PJMEDIA_HAS_ILBC_CODEC    1
+#endif
+
+
+/**
+ * Unless specified otherwise, G.722 codec is included by default.
+ */
+#ifndef PJMEDIA_HAS_G722_CODEC
+#   define PJMEDIA_HAS_G722_CODEC    1
+#endif
+
+
+/**
+ * Default G.722 codec encoder and decoder level adjustment. The G.722
+ * specifies that it uses 14 bit PCM for input and output, while PJMEDIA
+ * normally uses 16 bit PCM, so the conversion is done by applying
+ * 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 the decoder will be shifted left by this value.
+ *
+ * This can be changed at run-time after initialization by calling
+ * #pjmedia_codec_g722_set_pcm_shift().
+ *
+ * Default: 2.
+ */
+#ifndef PJMEDIA_G722_DEFAULT_PCM_SHIFT
+#   define PJMEDIA_G722_DEFAULT_PCM_SHIFT	    2
+#endif
+
+
+/**
+ * Specifies whether G.722 PCM shifting should be stopped when clipping
+ * detected in the decoder. Enabling this feature can be useful when
+ * talking to G.722 implementation that uses 16 bit PCM for G.722 input/
+ * output (for any reason it seems to work) and the PCM shifting causes
+ * audio clipping.
+ *
+ * See also #PJMEDIA_G722_DEFAULT_PCM_SHIFT.
+ *
+ * Default: enabled.
+ */
+#ifndef PJMEDIA_G722_STOP_PCM_SHIFT_ON_CLIPPING
+#   define PJMEDIA_G722_STOP_PCM_SHIFT_ON_CLIPPING  1
+#endif
+
+
+/**
+ * Enable the features provided by Intel IPP libraries, for example
+ * codecs such as G.729, G.723.1, G.726, G.728, G.722.1, and AMR.
+ *
+ * By default this is disabled. Please follow the instructions in
+ * http://trac.pjsip.org/repos/wiki/Intel_IPP_Codecs on how to setup
+ * Intel IPP with PJMEDIA.
+ */
+#ifndef PJMEDIA_HAS_INTEL_IPP
+#   define PJMEDIA_HAS_INTEL_IPP		0
+#endif
+
+
+/**
+ * Visual Studio only: when this option is set, the Intel IPP libraries
+ * will be automatically linked to application using pragma(comment)
+ * constructs. This is convenient, however it will only link with
+ * the stub libraries and the Intel IPP DLL's will be required when
+ * distributing the application.
+ *
+ * If application wants to link with the different types of the Intel IPP
+ * libraries (for example, the static libraries), it must set this option
+ * to zero and specify the Intel IPP libraries in the application's input
+ * library specification manually.
+ *
+ * Default 1.
+ */
+#ifndef PJMEDIA_AUTO_LINK_IPP_LIBS
+#   define PJMEDIA_AUTO_LINK_IPP_LIBS		1
+#endif
+
+
+/**
+ * Enable Intel IPP AMR codec. This also needs to be enabled when AMR WB
+ * codec is enabled. This option is only used when PJMEDIA_HAS_INTEL_IPP 
+ * is enabled.
+ *
+ * Default: 1
+ */
+#ifndef PJMEDIA_HAS_INTEL_IPP_CODEC_AMR
+#   define PJMEDIA_HAS_INTEL_IPP_CODEC_AMR	1
+#endif
+
+
+/**
+ * Enable Intel IPP AMR wideband codec. The PJMEDIA_HAS_INTEL_IPP_CODEC_AMR
+ * option must also be enabled to use this codec. This option is only used 
+ * when PJMEDIA_HAS_INTEL_IPP is enabled.
+ *
+ * Default: 1
+ */
+#ifndef PJMEDIA_HAS_INTEL_IPP_CODEC_AMRWB
+#   define PJMEDIA_HAS_INTEL_IPP_CODEC_AMRWB	1
+#endif
+
+
+/**
+ * Enable Intel IPP G.729 codec. This option is only used when
+ * PJMEDIA_HAS_INTEL_IPP is enabled.
+ *
+ * Default: 1
+ */
+#ifndef PJMEDIA_HAS_INTEL_IPP_CODEC_G729
+#   define PJMEDIA_HAS_INTEL_IPP_CODEC_G729	1
+#endif
+
+
+/**
+ * Enable Intel IPP G.723.1 codec. This option is only used when
+ * PJMEDIA_HAS_INTEL_IPP is enabled.
+ *
+ * Default: 1
+ */
+#ifndef PJMEDIA_HAS_INTEL_IPP_CODEC_G723_1
+#   define PJMEDIA_HAS_INTEL_IPP_CODEC_G723_1	1
+#endif
+
+
+/**
+ * Enable Intel IPP G.726 codec. This option is only used when
+ * PJMEDIA_HAS_INTEL_IPP is enabled.
+ *
+ * Default: 1
+ */
+#ifndef PJMEDIA_HAS_INTEL_IPP_CODEC_G726
+#   define PJMEDIA_HAS_INTEL_IPP_CODEC_G726	1
+#endif
+
+
+/**
+ * Enable Intel IPP G.728 codec. This option is only used when
+ * PJMEDIA_HAS_INTEL_IPP is enabled.
+ *
+ * Default: 1
+ */
+#ifndef PJMEDIA_HAS_INTEL_IPP_CODEC_G728
+#   define PJMEDIA_HAS_INTEL_IPP_CODEC_G728	1
+#endif
+
+
+/**
+ * Enable Intel IPP G.722.1 codec. This option is only used when
+ * PJMEDIA_HAS_INTEL_IPP is enabled.
+ *
+ * Default: 1
+ */
+#ifndef PJMEDIA_HAS_INTEL_IPP_CODEC_G722_1
+#   define PJMEDIA_HAS_INTEL_IPP_CODEC_G722_1	1
+#endif
+
+/**
+ * Enable Passthrough codecs.
+ *
+ * Default: 0
+ */
+#ifndef PJMEDIA_HAS_PASSTHROUGH_CODECS
+#   define PJMEDIA_HAS_PASSTHROUGH_CODECS	0
+#endif
+
+/**
+ * Enable AMR passthrough codec.
+ *
+ * Default: 1
+ */
+#ifndef PJMEDIA_HAS_PASSTHROUGH_CODEC_AMR
+#   define PJMEDIA_HAS_PASSTHROUGH_CODEC_AMR	1
+#endif
+
+/**
+ * Enable G.729 passthrough codec.
+ *
+ * Default: 1
+ */
+#ifndef PJMEDIA_HAS_PASSTHROUGH_CODEC_G729
+#   define PJMEDIA_HAS_PASSTHROUGH_CODEC_G729	1
+#endif
+
+/**
+ * Enable iLBC passthrough codec.
+ *
+ * Default: 1
+ */
+#ifndef PJMEDIA_HAS_PASSTHROUGH_CODEC_ILBC
+#   define PJMEDIA_HAS_PASSTHROUGH_CODEC_ILBC	1
+#endif
+
+/**
+ * Enable PCMU passthrough codec.
+ *
+ * Default: 1
+ */
+#ifndef PJMEDIA_HAS_PASSTHROUGH_CODEC_PCMU
+#   define PJMEDIA_HAS_PASSTHROUGH_CODEC_PCMU	1
+#endif
+
+/**
+ * Enable PCMA passthrough codec.
+ *
+ * Default: 1
+ */
+#ifndef PJMEDIA_HAS_PASSTHROUGH_CODEC_PCMA
+#   define PJMEDIA_HAS_PASSTHROUGH_CODEC_PCMA	1
+#endif
+
+/* If passthrough and PCMU/PCMA are enabled, disable the software
+ * G.711 codec
+ */
+#if PJMEDIA_HAS_PASSTHROUGH_CODECS && \
+    (PJMEDIA_HAS_PASSTHROUGH_CODEC_PCMU || PJMEDIA_HAS_PASSTHROUGH_CODEC_PCMA)
+#   undef PJMEDIA_HAS_G711_CODEC
+#   define PJMEDIA_HAS_G711_CODEC		0
+#endif
+
+
+/**
+ * G.722.1 codec is disabled by default.
+ */
+#ifndef PJMEDIA_HAS_G7221_CODEC
+#   define PJMEDIA_HAS_G7221_CODEC		0
+#endif
+
+/**
+ * Enable OpenCORE AMR-NB codec.
+ * See https://trac.pjsip.org/repos/ticket/1388 for some info.
+ *
+ * Default: 0
+ */
+#ifndef PJMEDIA_HAS_OPENCORE_AMRNB_CODEC
+#   define PJMEDIA_HAS_OPENCORE_AMRNB_CODEC	0
+#endif
+
+/**
+ * Enable OpenCORE AMR-WB codec.
+ * See https://trac.pjsip.org/repos/ticket/1608 for some info.
+ *
+ * Default: 0
+ */
+#ifndef PJMEDIA_HAS_OPENCORE_AMRWB_CODEC
+#   define PJMEDIA_HAS_OPENCORE_AMRWB_CODEC	0
+#endif
+
+/**
+ * Link with libopencore-amrXX via pragma comment on Visual Studio.
+ * This option only makes sense if PJMEDIA_HAS_OPENCORE_AMRNB/WB_CODEC
+ * is enabled.
+ *
+ * Default: 1
+ */
+#ifndef PJMEDIA_AUTO_LINK_OPENCORE_AMR_LIBS
+#  define PJMEDIA_AUTO_LINK_OPENCORE_AMR_LIBS	1
+#endif
+
+/**
+ * Link with libopencore-amrXX.a that has been produced with gcc.
+ * This option only makes sense if PJMEDIA_HAS_OPENCORE_AMRNB/WB_CODEC
+ * and PJMEDIA_AUTO_LINK_OPENCORE_AMR_LIBS are enabled.
+ *
+ * Default: 1
+ */
+#ifndef PJMEDIA_OPENCORE_AMR_BUILT_WITH_GCC
+#   define PJMEDIA_OPENCORE_AMR_BUILT_WITH_GCC	1
+#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
+ * the decoder will be shifted left by this value.
+ *
+ * This can be changed at run-time after initialization by calling
+ * #pjmedia_codec_g7221_set_pcm_shift().
+ */
+#ifndef PJMEDIA_G7221_DEFAULT_PCM_SHIFT
+#   define PJMEDIA_G7221_DEFAULT_PCM_SHIFT	1
+#endif
+
+
+/**
+ * Enabling both G.722.1 codec implementations, internal PJMEDIA and IPP,
+ * may cause problem in SDP, i.e: payload types duplications. So, let's 
+ * just trap such case here at compile time.
+ *
+ * Application can control which implementation to be used by manipulating
+ * PJMEDIA_HAS_G7221_CODEC and PJMEDIA_HAS_INTEL_IPP_CODEC_G722_1 in
+ * config_site.h.
+ */
+#if (PJMEDIA_HAS_G7221_CODEC != 0) && (PJMEDIA_HAS_INTEL_IPP != 0) && \
+    (PJMEDIA_HAS_INTEL_IPP_CODEC_G722_1 != 0)
+#   error Only one G.722.1 implementation can be enabled at the same time. \
+	  Please use PJMEDIA_HAS_G7221_CODEC and \
+	  PJMEDIA_HAS_INTEL_IPP_CODEC_G722_1 in your config_site.h \
+	  to control which implementation to be used.
+#endif
+
+
+/**
+ * Enable SILK codec.
+ *
+ * Default: 0
+ */
+#ifndef PJMEDIA_HAS_SILK_CODEC
+#   define PJMEDIA_HAS_SILK_CODEC		0
+#endif
+
+
+/**
+ * SILK codec default complexity setting, valid values are 0 (lowest), 1,
+ * and 2.
+ *
+ * Default: 2
+ */
+#ifndef PJMEDIA_CODEC_SILK_DEFAULT_COMPLEXITY
+#   define PJMEDIA_CODEC_SILK_DEFAULT_COMPLEXITY   2
+#endif
+
+/**
+ * SILK codec default quality setting, valid values are ranging from
+ * 0 (lowest) to 10. Please note that pjsua-lib may override this setting
+ * via its codec quality setting (i.e PJSUA_DEFAULT_CODEC_QUALITY).
+ *
+ * Default: 10
+ */
+#ifndef PJMEDIA_CODEC_SILK_DEFAULT_QUALITY
+#   define PJMEDIA_CODEC_SILK_DEFAULT_QUALITY	    10
+#endif
+
+
+/**
+ * Specify if FFMPEG codecs are available.
+ *
+ * Default: PJMEDIA_HAS_LIBAVCODEC
+ */
+#ifndef PJMEDIA_HAS_FFMPEG_CODEC
+#   define PJMEDIA_HAS_FFMPEG_CODEC		PJMEDIA_HAS_LIBAVCODEC
+#endif
+
+
+/**
+ * Specify if FFMPEG video codecs are available.
+ *
+ * Default: PJMEDIA_HAS_FFMPEG_CODEC
+ */
+#ifndef PJMEDIA_HAS_FFMPEG_VID_CODEC
+#   define PJMEDIA_HAS_FFMPEG_VID_CODEC		PJMEDIA_HAS_FFMPEG_CODEC
+#endif
+
+/**
+ * Enable FFMPEG H263+/H263-1998 codec.
+ *
+ * Default: 1
+ */
+#ifndef PJMEDIA_HAS_FFMPEG_CODEC_H263P
+#   define PJMEDIA_HAS_FFMPEG_CODEC_H263P	PJMEDIA_HAS_FFMPEG_VID_CODEC
+#endif
+
+/**
+ * Enable FFMPEG H264 codec (requires libx264).
+ *
+ * Default: 0
+ */
+#ifndef PJMEDIA_HAS_FFMPEG_CODEC_H264
+#   define PJMEDIA_HAS_FFMPEG_CODEC_H264	PJMEDIA_HAS_FFMPEG_VID_CODEC
+#endif
+
+/**
+ * @}
+ */
+
+
+
+#endif	/* __PJMEDIA_CODEC_CONFIG_H__ */
diff --git a/jni/pjproject-android/.svn/pristine/84/841b3b846b1e51269dfb01d1a3a3c27f382e9cce.svn-base b/jni/pjproject-android/.svn/pristine/84/841b3b846b1e51269dfb01d1a3a3c27f382e9cce.svn-base
new file mode 100644
index 0000000..8d77ffa
--- /dev/null
+++ b/jni/pjproject-android/.svn/pristine/84/841b3b846b1e51269dfb01d1a3a3c27f382e9cce.svn-base
@@ -0,0 +1,1577 @@
+AC_INIT(pjproject,2.x)
+
+host_orig="$host"
+
+AC_CANONICAL_BUILD
+AC_CANONICAL_HOST
+AC_CANONICAL_TARGET
+AC_CONFIG_HEADER([pjlib/include/pj/compat/os_auto.h
+		  pjlib/include/pj/compat/m_auto.h
+		  pjmedia/include/pjmedia/config_auto.h
+		  pjmedia/include/pjmedia-codec/config_auto.h
+		  pjsip/include/pjsip/sip_autoconf.h
+		 ])
+AC_CONFIG_FILES([build.mak 
+		 build/os-auto.mak 
+		 build/cc-auto.mak
+		 pjlib/build/os-auto.mak 
+		 pjlib-util/build/os-auto.mak 
+		 pjmedia/build/os-auto.mak
+		 pjsip/build/os-auto.mak
+		 third_party/build/os-auto.mak
+		 third_party/build/portaudio/os-auto.mak 
+		 ])
+
+
+dnl
+dnl Setup default CFLAGS
+dnl
+if test "$CFLAGS" = ""; then
+  CFLAGS="-O2"
+else
+  CFLAGS="$CFLAGS"
+fi
+
+CXXFLAGS="$CFLAGS $CXXFLAGS"
+
+dnl #
+dnl # Configure tools
+dnl #
+AC_PROG_CC
+AC_PROG_CXX
+AC_LANG_C
+
+AC_PROG_RANLIB
+AC_CHECK_TOOLS([AR], [ar gar], :)
+
+if test "$AR_FLAGS" = ""; then AR_FLAGS="rv"; fi
+AC_SUBST(AR_FLAGS)
+if test "$LD" = ""; then LD="$CC"; fi
+AC_SUBST(LD)
+if test "$LDOUT" = ""; then LDOUT="-o "; fi
+AC_SUBST(LDOUT)
+if test "$OBJEXT" = ""; then OBJEXT='o'; fi
+AC_SUBST(OBJEXT)
+if test "$LIBEXT" = ""; then LIBEXT='a'; fi
+AC_SUBST(LIBEXT)
+if test "$LIBEXT2" = ""; then LIBEXT2=""; fi
+AC_SUBST(LIBEXT2)
+if test "$CC_OUT" = ""; then CC_OUT="-o "; fi
+AC_SUBST(CC_OUT)
+if test "$CC_INC" = ""; then CC_INC="-I"; fi
+AC_SUBST(CC_INC)
+if test "$CC_DEF" = ""; then CC_DEF="-D"; fi
+AC_SUBST(CC_DEF)
+if test "$CC_OPTIMIZE" = ""; then CC_OPTIMIZE="-O2"; fi
+AC_SUBST(CC_OPTIMIZE)
+if test "$CC_CFLAGS" = ""; then CC_CFLAGS="-Wall"; fi
+AC_SUBST(CC_CFLAGS)
+
+
+
+AC_SUBST(ac_pjdir)
+AC_SUBST(ac_build_mak_vars)
+
+case $host in 
+    *mingw* | *cygw* | *win32* | *w32* )
+	if pwd -W 2&> /dev/null; then
+	   ac_pjdir=`pwd -W`
+	else
+	   # We're probably cross-compiling mingw on Linux
+	   ac_pjdir=`pwd`
+	fi
+	;;
+    *)
+	ac_pjdir=`pwd`
+	;;
+esac
+
+AC_SUBST(ac_shlib_suffix)
+case $target in
+    *mingw* | *cygw* | *win32* | *w32* )
+	ac_shlib_suffix=dll
+	;;
+    *darwin*)
+	ac_shlib_suffix=dylib
+	;;
+    *)
+	ac_shlib_suffix=so
+	;;
+esac
+
+AC_SUBST(ac_cross_compile)
+if test "$build" = "$host"; then
+    ac_cross_compile=
+else
+    ac_cross_compile=${host_orig}-
+fi
+
+AC_CHECK_LIB(pthread,pthread_create)
+AC_CHECK_LIB(wsock32,puts)
+AC_CHECK_LIB(ws2_32,puts)
+AC_CHECK_LIB(ole32,puts)
+AC_CHECK_LIB(winmm,puts)
+AC_CHECK_LIB(socket,puts)
+AC_CHECK_LIB(rt,puts)
+AC_CHECK_LIB(nsl,puts)
+AC_CHECK_LIB(m,sin)
+AC_CHECK_LIB(uuid,uuid_generate)
+AC_CHECK_LIB(uuid,uuid_generate,[ac_has_uuid_lib=1])
+
+AC_MSG_RESULT([Setting PJ_M_NAME to $target_cpu])
+AC_DEFINE_UNQUOTED(PJ_M_NAME,["$target_cpu"])
+
+dnl
+dnl Memory alignment detection
+dnl
+AC_MSG_CHECKING([memory alignment])
+case $target in
+    sparc64-* | ia64-* | x86_64-* )
+	AC_DEFINE(PJ_POOL_ALIGNMENT, 8)
+	AC_MSG_RESULT([8 bytes])
+	;;
+    * )
+	AC_DEFINE(PJ_POOL_ALIGNMENT, 4)
+	AC_MSG_RESULT([4 bytes (default)])
+	;;
+esac
+
+
+dnl
+dnl Endianness detection
+dnl
+AC_C_BIGENDIAN
+
+if test "x$ac_cv_c_bigendian" = "xyes"; then
+  CFLAGS="$CFLAGS -DPJ_IS_BIG_ENDIAN=1 -DPJ_IS_LITTLE_ENDIAN=0"
+else
+  CFLAGS="$CFLAGS -DPJ_IS_BIG_ENDIAN=0 -DPJ_IS_LITTLE_ENDIAN=1"
+fi
+
+dnl
+dnl Legacy macros
+dnl
+case $target in
+    *android*)
+	AC_DEFINE(PJ_ANDROID,1)
+	;;
+    *mingw* | *cygw* | *win32* | *w32* )
+	AC_DEFINE(PJ_WIN32,1)
+	AC_DEFINE(PJ_WIN32_WINNT,0x0400)
+	AC_DEFINE(WIN32_LEAN_AND_MEAN)
+	;;
+    *darwin*)
+	AC_DEFINE(PJ_DARWINOS,1)
+	;;
+    *linux*)
+	AC_DEFINE(PJ_LINUX,1)
+	;;
+    *rtems*)
+	AC_DEFINE(PJ_RTEMS,1)
+	;;
+    *sunos* | *solaris* )
+	AC_DEFINE(PJ_SUNOS,1)
+	;;
+    *)
+	;;
+esac
+
+
+
+
+dnl # --disable-floating-point option
+AC_ARG_ENABLE(floating-point,
+	      AC_HELP_STRING([--disable-floating-point],
+			     [Disable floating point where possible]),
+	      [if test "$enable_floating_point" = "no"; then
+		AC_DEFINE(PJ_HAS_FLOATING_POINT,0)
+		AC_MSG_RESULT([Checking if floating point is disabled... yes])
+	       fi],
+	      [
+		AC_DEFINE(PJ_HAS_FLOATING_POINT,1)
+	        AC_MSG_RESULT([Checking if floating point is disabled... no]) 
+	      ])
+
+
+AC_CHECK_HEADER(arpa/inet.h,[AC_DEFINE(PJ_HAS_ARPA_INET_H,1)])
+AC_CHECK_HEADER(assert.h,[AC_DEFINE(PJ_HAS_ASSERT_H,1)])
+AC_CHECK_HEADER(ctype.h,[AC_DEFINE(PJ_HAS_CTYPE_H,1)])
+
+case $target in
+    *mingw* | *cygw* | *win32* | *w32* )
+	AC_DEFINE(PJ_HAS_ERRNO_H,0)
+	;;
+    *)
+	AC_CHECK_HEADER(errno.h,[AC_DEFINE(PJ_HAS_ERRNO_H,1)])
+	;;
+esac
+
+AC_CHECK_HEADER(fcntl.h,[AC_DEFINE(PJ_HAS_FCNTL_H,1)])
+AC_CHECK_HEADER(linux/socket.h,[AC_DEFINE(PJ_HAS_LINUX_SOCKET_H,1)])
+AC_CHECK_HEADER(limits.h,[AC_DEFINE(PJ_HAS_LIMITS_H,1)])
+AC_CHECK_HEADER(malloc.h,[AC_DEFINE(PJ_HAS_MALLOC_H,1)])
+AC_CHECK_HEADER(netdb.h,[AC_DEFINE(PJ_HAS_NETDB_H,1)])
+AC_CHECK_HEADER(netinet/in_systm.h,[AC_DEFINE(PJ_HAS_NETINET_IN_SYSTM_H,1)])
+AC_CHECK_HEADER(netinet/in.h,[AC_DEFINE(PJ_HAS_NETINET_IN_H,1)])
+AC_CHECK_HEADER(netinet/ip.h,[AC_DEFINE(PJ_HAS_NETINET_IP_H,1)],[],
+		 [#if PJ_HAS_SYS_TYPES_H
+          	  #	include <sys/types.h>
+          	  #endif
+		  #if PJ_HAS_NETINET_IN_SYSTM_H
+          	  #	include <netinet/in_systm.h>
+          	  #endif
+		  #if PJ_HAS_NETINET_IN_H
+          	  #	include <netinet/in.h>
+          	  #endif
+          	 ])
+AC_CHECK_HEADER(netinet/tcp.h,[AC_DEFINE(PJ_HAS_NETINET_TCP_H,1)])
+AC_CHECK_HEADER(ifaddrs.h,
+		[AC_CHECK_FUNC(getifaddrs,[AC_DEFINE(PJ_HAS_IFADDRS_H,1)])])
+AC_CHECK_HEADER(semaphore.h,[AC_DEFINE(PJ_HAS_SEMAPHORE_H,1)])
+AC_CHECK_HEADER(setjmp.h,[AC_DEFINE(PJ_HAS_SETJMP_H,1)])
+AC_CHECK_HEADER(stdarg.h,[AC_DEFINE(PJ_HAS_STDARG_H,1)])
+AC_CHECK_HEADER(stddef.h,[AC_DEFINE(PJ_HAS_STDDEF_H,1)])
+AC_CHECK_HEADER(stdio.h,[AC_DEFINE(PJ_HAS_STDIO_H,1)])
+AC_CHECK_HEADER(stdint.h,[AC_DEFINE(PJ_HAS_STDINT_H,1)])
+AC_CHECK_HEADER(stdlib.h,[AC_DEFINE(PJ_HAS_STDLIB_H,1)])
+AC_CHECK_HEADER(string.h,[AC_DEFINE(PJ_HAS_STRING_H,1)])
+AC_CHECK_HEADER(sys/ioctl.h,[AC_DEFINE(PJ_HAS_SYS_IOCTL_H,1)])
+AC_CHECK_HEADER(sys/select.h,[AC_DEFINE(PJ_HAS_SYS_SELECT_H,1)])
+AC_CHECK_HEADER(sys/socket.h,[AC_DEFINE(PJ_HAS_SYS_SOCKET_H,1)])
+AC_CHECK_HEADER(sys/time.h,[AC_DEFINE(PJ_HAS_SYS_TIME_H,1)])
+AC_CHECK_HEADER(sys/timeb.h,[AC_DEFINE(PJ_HAS_SYS_TIMEB_H,1)])
+AC_CHECK_HEADER(sys/types.h,[AC_DEFINE(PJ_HAS_SYS_TYPES_H,1)])
+AC_CHECK_HEADER(sys/filio.h,[AC_DEFINE(PJ_HAS_SYS_FILIO_H,1)])
+AC_CHECK_HEADER(sys/sockio.h,[AC_DEFINE(PJ_HAS_SYS_SOCKIO_H,1)])
+AC_CHECK_HEADER(sys/utsname.h,[AC_DEFINE(PJ_HAS_SYS_UTSNAME_H,1)])
+AC_CHECK_HEADER(time.h,[AC_DEFINE(PJ_HAS_TIME_H,1)])
+AC_CHECK_HEADER(unistd.h,[AC_DEFINE(PJ_HAS_UNISTD_H,1)])
+AC_CHECK_HEADER(winsock.h,[AC_DEFINE(PJ_HAS_WINSOCK_H,1)])
+AC_CHECK_HEADER(winsock2.h,[AC_DEFINE(PJ_HAS_WINSOCK2_H,1)])
+AC_CHECK_HEADER(mswsock.h,[AC_DEFINE(PJ_HAS_MSWSOCK_H,1)],[],
+		 [#if PJ_HAS_WINSOCK2_H
+          	  #	include <winsock2.h>
+		  #elif PJ_HAS_WINSOCK_H
+          	  #	include <winsock.h>
+          	  #endif
+          	 ])
+AC_CHECK_HEADER(ws2tcpip.h,[AC_DEFINE(PJ_HAS_WS2TCPIP_H,1)])
+AC_CHECK_HEADER(uuid/uuid.h,[ac_has_uuid_h=1])
+AC_CHECK_HEADER(net/if.h,[AC_DEFINE(PJ_HAS_NET_IF_H,1)],[],
+		 [#if PJ_HAS_SYS_TYPES_H
+          	  #	include <sys/types.h>
+          	  #endif
+		  #if PJ_HAS_SYS_SOCKET_H
+
+          	  #	include <sys/socket.h>
+          	  #endif
+          	 ])
+AC_MSG_RESULT([Setting PJ_OS_NAME to $target])
+AC_DEFINE_UNQUOTED(PJ_OS_NAME,["$target"])
+
+AC_MSG_RESULT([Setting PJ_HAS_ERRNO_VAR to 1])
+AC_DEFINE(PJ_HAS_ERRNO_VAR,1)
+
+AC_MSG_RESULT([Setting PJ_HAS_HIGH_RES_TIMER to 1])
+AC_DEFINE(PJ_HAS_HIGH_RES_TIMER,1)
+
+AC_MSG_RESULT([Setting PJ_HAS_MALLOC to 1])
+AC_DEFINE(PJ_HAS_MALLOC,1)
+
+AC_MSG_RESULT([Setting PJ_NATIVE_STRING_IS_UNICODE to 0])
+AC_DEFINE(PJ_NATIVE_STRING_IS_UNICODE,0)
+
+AC_MSG_RESULT([Setting PJ_ATOMIC_VALUE_TYPE to long])
+AC_DEFINE(PJ_ATOMIC_VALUE_TYPE,long)
+
+dnl # Determine if inet_aton() is available
+AC_MSG_CHECKING([if inet_aton() is available])
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
+				     #include <sys/socket.h>
+				     #include <arpa/inet.h>]],
+		    		  [inet_aton(0, 0);])],
+		  [AC_DEFINE(PJ_SOCK_HAS_INET_ATON,1)
+		   AC_MSG_RESULT(yes)],
+		  [AC_MSG_RESULT(no)])
+
+dnl # Determine if inet_pton() is available
+AC_MSG_CHECKING([if inet_pton() is available])
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
+				     #include <sys/socket.h>
+				     #include <arpa/inet.h>]],
+		    		  [inet_pton(0, 0, 0);])],
+		  [AC_DEFINE(PJ_SOCK_HAS_INET_PTON,1)
+		   AC_MSG_RESULT(yes)],
+		  [AC_MSG_RESULT(no)])
+
+dnl # Determine if inet_ntop() is available
+AC_MSG_CHECKING([if inet_ntop() is available])
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
+				     #include <sys/socket.h>
+				     #include <arpa/inet.h>]],
+		    		  [inet_ntop(0, 0, 0, 0);])],
+		  [AC_DEFINE(PJ_SOCK_HAS_INET_NTOP,1)
+		   AC_MSG_RESULT(yes)],
+		  [AC_MSG_RESULT(no)])
+
+dnl # Determine if getaddrinfo() is available
+AC_MSG_CHECKING([if getaddrinfo() is available])
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
+				     #include <sys/socket.h>
+				     #include <netdb.h>]],
+		    		  [getaddrinfo(0, 0, 0, 0);])],
+		  [AC_DEFINE(PJ_SOCK_HAS_GETADDRINFO,1)
+		   AC_MSG_RESULT(yes)],
+		  [AC_MSG_RESULT(no)])
+
+dnl # Determine if sockaddr_in has sin_len member
+AC_MSG_CHECKING([if sockaddr_in has sin_len member])
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
+				     #include <sys/socket.h>
+		    		     #include <netinet/in.h>
+		    		     #include <arpa/inet.h>]],
+		    		  [struct sockaddr_in a; a.sin_len=0;])],
+		  [AC_DEFINE(PJ_SOCKADDR_HAS_LEN,1)
+		   AC_MSG_RESULT(yes)],
+		  AC_MSG_RESULT(no))
+
+dnl # Determine if socklen_t is available
+AC_MSG_CHECKING([if socklen_t is available])
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
+                                     #include <sys/socket.h>]],
+		    		   [socklen_t xxx = 0;])],
+		  [AC_DEFINE(PJ_HAS_SOCKLEN_T,1)
+		   AC_MSG_RESULT(yes)],
+		  AC_MSG_RESULT(no))
+
+dnl # Determine if SO_ERROR is available
+AC_MSG_CHECKING([if SO_ERROR is available])
+case $target in
+    *mingw* | *cygw* | *win32* | *w32* )
+	AC_DEFINE(PJ_HAS_SO_ERROR,1)
+	AC_MSG_RESULT(yes)
+	;;
+    *)
+	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
+					     #include <sys/socket.h>
+					     #include <netinet/in.h>
+					     #include <arpa/inet.h>]],
+					  [int i=SO_ERROR;])],
+			  [AC_DEFINE(PJ_HAS_SO_ERROR,1)
+			   AC_MSG_RESULT(yes)],
+			  AC_MSG_RESULT(no))
+	;;
+esac
+
+
+dnl # Determine if RW-mutex is available
+AC_MSG_CHECKING([if pthread_rwlock_t is available])
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <pthread.h>],
+		    		   [pthread_rwlock_t *x;])],
+		  [AC_DEFINE(PJ_EMULATE_RWMUTEX,0)
+		   ac_rwmutex="yes"
+  		   AC_MSG_RESULT(yes)],
+		  [AC_DEFINE(PJ_EMULATE_RWMUTEX,1)
+		   ac_rwmutex="no"
+		   AC_MSG_RESULT(no)])
+
+dnl # If rwmutex is not detected, check again but this time
+dnl # with _POSIX_READER_WRITER_LOCKS defined (newlib needs this)
+if test "$ac_rwmutex" = "no"; then
+    AC_MSG_CHECKING([if pthread_rwlock_t is available with _POSIX_READER_WRITER_LOCKS])
+    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#define _POSIX_READER_WRITER_LOCKS
+					 #include <pthread.h>]],
+				       [pthread_rwlock_t *x;])],
+		      [AC_DEFINE(PJ_EMULATE_RWMUTEX,0)
+		       CFLAGS="$CFLAGS -D_POSIX_THREADS -D_POSIX_READER_WRITER_LOCKS"
+		       AC_MSG_RESULT(yes)],
+		      [AC_DEFINE(PJ_EMULATE_RWMUTEX,1)
+		       AC_MSG_RESULT(no)])
+fi
+
+dnl # Do we have pthread_mutexattr_settype()?
+AC_MSG_CHECKING([if pthread_mutexattr_settype() is available])
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <pthread.h>],
+		    		   [pthread_mutexattr_settype(0,PTHREAD_MUTEX_FAST_NP);])],
+		  [AC_DEFINE(PJ_HAS_PTHREAD_MUTEXATTR_SETTYPE,1)
+  		   AC_MSG_RESULT(yes)],
+		  [AC_MSG_RESULT(no)])
+
+dnl # Does pthread_mutexattr_t has "recursive" member?
+AC_MSG_CHECKING([if pthread_mutexattr_t has recursive member])
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <pthread.h>],
+		    		   [[pthread_mutexattr_t attr;
+				     attr.recursive=1;]])],
+		  [AC_DEFINE(PJ_PTHREAD_MUTEXATTR_T_HAS_RECURSIVE,1)
+  		   AC_MSG_RESULT(yes)],
+		  [AC_MSG_RESULT(no)])
+
+dnl ######################
+dnl # ioqueue selection
+dnl # 
+AC_SUBST(ac_os_objs)
+AC_MSG_CHECKING([ioqueue backend])
+AC_ARG_ENABLE(epoll,
+	      AC_HELP_STRING([--enable-epoll],
+			     [Use /dev/epoll ioqueue on Linux (experimental)]),
+	      [
+		ac_os_objs=ioqueue_epoll.o
+		AC_MSG_RESULT([/dev/epoll])
+	      ],
+	      [
+		ac_os_objs=ioqueue_select.o
+	        AC_MSG_RESULT([select()]) 
+	      ])
+
+AC_SUBST(ac_shared_libraries)
+AC_ARG_ENABLE(shared,
+	      AC_HELP_STRING([--enable-shared],
+			     [Build shared libraries]),
+	      [if test "$enable_shared" = "yes"; then
+		[ac_shared_libraries=1]
+		CFLAGS="$CFLAGS -fPIC"
+		AC_MSG_RESULT([Building shared libraries... yes])
+	       fi],
+	      AC_MSG_RESULT([Building shared libraries... no])
+	      )
+
+
+dnl ######################
+dnl # OS specific files
+dnl #
+case $target in
+  *mingw* | *cygw* | *win32* | *w32* )
+	ac_os_objs="$ac_os_objs file_access_win32.o file_io_win32.o os_core_win32.o os_error_win32.o os_time_win32.o os_timestamp_win32.o guid_win32.o"
+	;;
+  *)
+	ac_os_objs="$ac_os_objs file_access_unistd.o file_io_ansi.o os_core_unix.o os_error_unix.o os_time_unix.o os_timestamp_posix.o"
+	case $target in
+	  arm-apple-darwin*)
+		ac_os_objs="$ac_os_objs os_info_iphone.o"
+		;;
+	esac
+	# UUID
+	if test "$ac_has_uuid_lib" = "1" -a "$ac_has_uuid_h" = "1"; then
+		ac_os_objs="$ac_os_objs guid_uuid.o"
+	else
+		ac_os_objs="$ac_os_objs guid_simple.o"
+	fi
+	;;
+esac
+
+case $target in
+  *darwin*)
+	ac_os_objs="$ac_os_objs os_core_darwin.o"
+	;;
+esac
+
+dnl ##########################################
+dnl #
+dnl # PJMEDIA
+dnl #
+
+dnl # Use external Speex installation
+AC_SUBST(ac_external_speex,0)
+AC_ARG_WITH(external-speex,
+    AC_HELP_STRING([--with-external-speex],
+		   [Use external Speex development files, not the one in "third_party" directory. When this option is set, make sure that Speex is accessible to use (hint: use CFLAGS and LDFLAGS env var to set the include/lib paths)]),
+    [
+	if test "x$with_external_speex" != "xno"; then
+		# Test Speex installation
+		AC_MSG_CHECKING([if external Speex devkit is installed])
+		AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <speex/speex.h>
+						     #include <speex/speex_echo.h>
+						     ]],
+						  [speex_echo_state_init(0, 0); speex_encoder_init(0); ])],
+				  [AC_MSG_RESULT(yes!!)
+				   AC_DEFINE(PJMEDIA_EXTERNAL_SPEEX_CODEC, 1)
+				   ac_external_speex="1"
+				   ],
+				  [AC_MSG_ERROR([Unable to use external Speex library. If Speex development files are not available in the default locations, use CFLAGS and LDFLAGS env var to set the include/lib paths])])
+	fi
+    ]
+    )
+
+dnl # Use external GSM codec library installation
+AC_SUBST(ac_external_gsm,0)
+AC_ARG_WITH(external-gsm,
+    AC_HELP_STRING([--with-external-gsm],
+		   [Use external GSM codec library, not the one in "third_party" directory. When this option is set, make sure that the GSM include/lib files are accessible to use (hint: use CFLAGS and LDFLAGS env var to set the include/lib paths)]),
+    [
+	if test "x$with_external_gsm" != "xno"; then
+                # Test GSM library installation
+                AC_MSG_CHECKING([if external GSM devkit is installed as gsm/gsm.h])
+                AC_COMPILE_IFELSE(
+                    [AC_LANG_PROGRAM([[#include <gsm/gsm.h> ]], [gsm_create(); ]) ],
+                    [AC_MSG_RESULT(yes!!)
+                     AC_DEFINE(PJMEDIA_EXTERNAL_GSM_CODEC, 1)
+                     AC_DEFINE(PJMEDIA_EXTERNAL_GSM_GSM_H, 1)
+                     ac_external_gsm="1"
+                    ],
+                    [
+                     AC_MSG_RESULT(no)
+                     AC_MSG_CHECKING([if external GSM devkit is installed as gsm.h])
+                     AC_COMPILE_IFELSE(
+                        [AC_LANG_PROGRAM([[#include <gsm.h> ]], [gsm_create(); ]) ],
+                        [AC_MSG_RESULT(yes!!)
+                         AC_DEFINE(PJMEDIA_EXTERNAL_GSM_CODEC, 1)
+                         AC_DEFINE(PJMEDIA_EXTERNAL_GSM_H, 1)
+                         ac_external_gsm="1"
+                        ],
+                        [AC_MSG_ERROR([Unable to use external GSM library. If GSM development files are not available in the default locations, use CFLAGS and LDFLAGS env var to set the include/lib paths])
+                        ]
+                     )
+                    ]
+                )
+	fi
+    ]
+    )
+
+
+
+dnl # Sound device backend selection
+AC_SUBST(ac_pjmedia_snd)
+AC_ARG_ENABLE(sound,
+	      AC_HELP_STRING([--disable-sound],
+			     [Exclude sound (i.e. use null sound)]),
+	      [if test "$enable_sound" = "no"; then
+		[ac_pjmedia_snd=null]
+		AC_MSG_RESULT([Checking if sound is disabled... yes])
+	       fi]
+	      )
+
+dnl # Use external PortAudio installation
+AC_SUBST(ac_external_pa,0)
+AC_ARG_WITH(external-pa,
+    AC_HELP_STRING([--with-external-pa],
+		   [Use external PortAudio development files, not the one in "third_party" directory. When this option is set, make sure that PortAudio is accessible to use (hint: use CFLAGS and LDFLAGS env var to set the include/lib paths)]),
+    [
+	if test "x$with_external_pa" != "xno"; then
+		# Test PortAudio installation
+		AC_MSG_CHECKING([if external PortAudio devkit is installed])
+		AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <portaudio.h>
+						     ]],
+						  [Pa_Initialize();])],
+				  [AC_MSG_RESULT(yes!!)
+				   ac_external_pa="1"
+				   ],
+				  [AC_MSG_ERROR([Unable to use PortAudio. If PortAudio development files are not available in the default locations, use CFLAGS and LDFLAGS env var to set the include/lib paths])])
+	fi
+    ]
+    )
+
+AC_SUBST(ac_pa_cflags)
+AC_CHECK_HEADER(sys/soundcard.h,
+	 	[ac_pa_cflags="$ac_pa_cflags -DHAVE_SYS_SOUNDCARD_H"])
+AC_CHECK_HEADER(linux/soundcard.h,
+	 	[ac_pa_cflags="$ac_pa_cflags -DHAVE_LINUX_SOUNDCARD_H"])
+AC_CHECK_HEADER(machine/soundcard.h,
+	 	[ac_pa_cflags="$ac_pa_cflags -DHAVE_MACHINE_SOUNDCARD_H"])
+
+if test "x$ac_cv_c_bigendian" = "xyes"; then
+  ac_pa_cflags="$ac_pa_cflags -DPA_BIG_ENDIAN"
+else
+  ac_pa_cflags="$ac_pa_cflags -DPA_LITTLE_ENDIAN"
+fi
+
+if test "$enable_sound" = "no"; then
+  true;
+else
+ AC_SUBST(ac_pjmedia_audiodev_objs)
+ case $target in
+  *android*)
+	LIBS="$LIBS -lOpenSLES"
+	AC_MSG_RESULT([Checking sound device backend... OpenSL ES])
+	;;
+  arm-apple-darwin*)
+	LIBS="$LIBS -framework CoreAudio -framework CoreFoundation -framework AudioToolbox -framework CFNetwork -framework UIKit"
+	ac_pjmedia_audiodev_objs="coreaudio_dev.o"
+	AC_MSG_RESULT([Checking sound device backend... AudioUnit])
+	;;
+  *darwin*)
+	LIBS="$LIBS -framework CoreAudio -framework CoreServices -framework AudioUnit -framework AudioToolbox"
+	ac_pjmedia_audiodev_objs="coreaudio_dev.o"
+	if test "`uname -r`" = "6.8"; then
+		#ac_pa_cflags="$ac_pa_cflags -DPA_OLD_CORE_AUDIO -DMOSX_USE_NON_ATOMIC_FLAG_BITS"
+		#AC_MSG_RESULT([Setting additional PortAudio CFLAGS.. -DPA_OLD_CORE_AUDIO -DMOSX_USE_NON_ATOMIC_FLAG_BITS])
+		ac_pjmedia_snd=pa_old_darwinos
+		AC_MSG_RESULT([Checking sound device backend... old coreaudio])
+	else
+		ac_pjmedia_snd=pa_darwinos
+		AC_MSG_RESULT([Checking sound device backend... coreaudio])
+	fi
+	;;
+  *cygwin* | *mingw*)
+	ac_pjmedia_snd=pa_win32
+	AC_MSG_RESULT([Checking sound device backend... win32 sound])
+	;;
+  *rtems*)
+	ac_pjmedia_snd=null
+	AC_MSG_RESULT([Checking sound device backend... null sound])
+	;;
+  *)
+	dnl # Check if ALSA is available
+	ac_pjmedia_snd=pa_unix
+	AC_CHECK_HEADER(alsa/version.h,
+			[AC_SUBST(ac_pa_use_alsa,1)
+			 LIBS="$LIBS -lasound"
+			],
+		        [AC_SUBST(ac_pa_use_alsa,0)])
+	AC_MSG_RESULT([Checking sound device backend... unix])
+
+	dnl # Check if OSS is disabled
+	AC_SUBST(ac_pa_use_oss,1)
+	AC_ARG_ENABLE(oss,
+		      AC_HELP_STRING([--disable-oss],
+				     [Disable OSS audio (default: not disabled)]),
+		      [
+			if test "$enable_oss" = "no"; then
+			 [ac_pa_use_oss=0]
+			 AC_MSG_RESULT([Checking if OSS audio is disabled... yes])
+			fi
+		      ])
+	;;
+ esac
+fi
+
+AC_SUBST(ac_pjmedia_video)
+
+dnl # --disable-video option
+AC_ARG_ENABLE(video,
+	      AC_HELP_STRING([--disable-video],
+	      		     [Disable video feature]),
+	      [if test "$enable_video" = "no"; then
+	        #AC_DEFINE(PJMEDIA_HAS_VIDEO,0)
+                AC_MSG_RESULT([Video is disabled]) 
+                enable_sdl="no"
+                enable_ffmpeg="no"
+		enable_v4l2="no"
+               fi],
+	      [])
+
+case $target in
+ *android*)
+	LIBS="$LIBS -llog -lgcc"
+	;;
+ arm-apple-darwin*)
+ 	LIBS="$LIBS -framework UIKit"
+	;;
+ *darwin*)
+ 	LIBS="$LIBS -framework Foundation -framework AppKit"
+	;;
+esac
+
+if test "$enable_video" = "no"; then
+  true;
+else
+ case $target in
+  arm-apple-darwin*)
+	ac_pjmedia_video=iphone_os
+	AC_SUBST(ac_pjmedia_video_has_ios)
+	AC_SUBST(ac_ios_cflags)
+	SAVED_LIBS="$LIBS"
+	LIBS="-framework AVFoundation -framework CoreGraphics -framework QuartzCore -framework CoreVideo -framework CoreMedia"
+	AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [])],[ac_pjmedia_video_has_ios=yes],[ac_pjmedia_video_has_ios=no])
+	LIBS="$SAVED_LIBS"
+	if test "$ac_pjmedia_video_has_ios" = "yes"; then
+	  ac_ios_cflags="-DPJMEDIA_VIDEO_DEV_HAS_IOS=1"
+	  LIBS="$LIBS -framework AVFoundation -framework CoreGraphics -framework QuartzCore -framework CoreVideo -framework CoreMedia"
+	  AC_MSG_RESULT([Checking if AVFoundation framework is available... yes])
+	else
+	  AC_MSG_RESULT([Checking if AVFoundation framework is available... no])
+	fi
+	;;
+  *darwin*)
+	ac_pjmedia_video=mac_os
+	AC_SUBST(ac_pjmedia_video_has_qt)
+	AC_SUBST(ac_qt_cflags)
+	SAVED_LIBS="$LIBS"
+	LIBS="-framework QTKit"
+	AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [])],[ac_pjmedia_video_has_qt=yes],[ac_pjmedia_video_has_qt=no])
+	LIBS="$SAVED_LIBS"
+	if test "$ac_pjmedia_video_has_qt" = "yes"; then
+	  ac_qt_cflags="-DPJMEDIA_VIDEO_DEV_HAS_QT=1"
+	  LIBS="$LIBS -framework QTKit -framework QuartzCore -framework OpenGL"
+	  AC_MSG_RESULT([Checking if QTKit framework is available... yes])
+	else
+	  AC_MSG_RESULT([Checking if QTKit framework is available... no])
+	fi
+	;;
+ esac
+fi
+
+AC_ARG_ENABLE(ext_sound,
+	      AC_HELP_STRING([--enable-ext-sound],
+			     [PJMEDIA will not provide any sound device backend]),
+	      [if test "$enable_ext_sound" = "yes"; then
+		[ac_pjmedia_snd=external]
+		AC_MSG_RESULT([Checking if external sound is set... yes])
+	       fi]
+	      )
+
+dnl # Include resampling small filter
+AC_SUBST(ac_no_small_filter)
+AC_ARG_ENABLE(small-filter,
+	      AC_HELP_STRING([--disable-small-filter],
+			     [Exclude small filter in resampling]),
+	      [if test "$enable_small_filter" = "no"; then
+		[ac_no_small_filter='-DPJMEDIA_HAS_SMALL_FILTER=0']
+		AC_MSG_RESULT([Checking if small filter is disabled... yes])
+	       fi],
+	      AC_MSG_RESULT([Checking if small filter is disabled... no]))
+
+dnl # Include resampling large filter
+AC_SUBST(ac_no_large_filter)
+AC_ARG_ENABLE(large-filter,
+	      AC_HELP_STRING([--disable-large-filter],
+			     [Exclude large filter in resampling]),
+	      [if test "$enable_large_filter" = "no"; then
+		[ac_no_large_filter='-DPJMEDIA_HAS_LARGE_FILTER=0']
+		AC_MSG_RESULT([Checking if large filter is disabled... yes])
+	       fi],
+	      AC_MSG_RESULT([Checking if large filter is disabled... no]))
+
+dnl # Include Speex AEC
+AC_SUBST(ac_no_speex_aec)
+AC_ARG_ENABLE(speex-aec,
+	      AC_HELP_STRING([--disable-speex-aec],
+			     [Exclude Speex Acoustic Echo Canceller/AEC]),
+	      [if test "$enable_speex_aec" = "no"; then
+		[ac_no_speex_aec='-DPJMEDIA_HAS_SPEEX_AEC=0']
+		AC_MSG_RESULT([Checking if Speex AEC is disabled...yes])
+	       fi],
+	      AC_MSG_RESULT([Checking if Speex AEC is disabled...no]))
+
+dnl # Include G711 codec
+AC_SUBST(ac_no_g711_codec)
+AC_ARG_ENABLE(g711-codec,
+	      AC_HELP_STRING([--disable-g711-codec],
+			     [Exclude G.711 codecs from the build]),
+	      [if test "$enable_g711_codec" = "no"; then
+		[ac_no_g711_codec=1]
+		AC_DEFINE(PJMEDIA_HAS_G711_CODEC,0)
+		AC_MSG_RESULT([Checking if G.711 codec is disabled...yes])
+	       fi],
+	      AC_MSG_RESULT([Checking if G.711 codec is disabled...no]))
+
+
+dnl # Include L16 codec
+AC_SUBST(ac_no_l16_codec)
+AC_ARG_ENABLE(l16-codec,
+	      AC_HELP_STRING([--disable-l16-codec],
+			     [Exclude Linear/L16 codec family from the build]),
+	      [if test "$enable_l16_codec" = "no"; then
+		[ac_no_l16_codec=1]
+		AC_DEFINE(PJMEDIA_HAS_L16_CODEC,0)
+		AC_MSG_RESULT([Checking if L16 codecs are disabled...yes])
+	       fi],
+	      AC_MSG_RESULT([Checking if L16 codec is disabled...no]))
+
+
+dnl # Include GSM codec
+AC_SUBST(ac_no_gsm_codec)
+AC_ARG_ENABLE(gsm-codec,
+	      AC_HELP_STRING([--disable-gsm-codec],
+			     [Exclude GSM codec in the build]),
+	      [if test "$enable_gsm_codec" = "no"; then
+		[ac_no_gsm_codec=1]
+		AC_DEFINE(PJMEDIA_HAS_GSM_CODEC,0)
+		AC_MSG_RESULT([Checking if GSM codec is disabled...yes])
+	       fi],
+	      AC_MSG_RESULT([Checking if GSM codec is disabled...no]))
+
+dnl # Include G.722 codec
+AC_SUBST(ac_no_g722_codec)
+AC_ARG_ENABLE(g722-codec,
+	      AC_HELP_STRING([--disable-g722-codec],
+			     [Exclude G.722 codec in the build]),
+	      [if test "$enable_g722_codec" = "no"; then
+		[ac_no_g722_codec=1]
+		AC_DEFINE(PJMEDIA_HAS_G722_CODEC,0)
+		AC_MSG_RESULT([Checking if G.722 codec is disabled...yes])
+	       fi],
+	      AC_MSG_RESULT([Checking if G.722 codec is disabled...no]))
+
+dnl # Include G722.1 codec
+AC_SUBST(ac_no_g7221_codec)
+AC_ARG_ENABLE(g7221-codec,
+	      AC_HELP_STRING([--disable-g7221-codec],
+			     [Exclude G.7221 codec in the build]),
+	      [if test "$enable_g7221_codec" = "no"; then
+		[ac_no_g7221_codec=1]
+		AC_DEFINE(PJMEDIA_HAS_G7221_CODEC,0)
+		AC_MSG_RESULT([Checking if G.722.1 codec is disabled...yes])
+	       fi],
+	      AC_MSG_RESULT([Checking if G.722.1 codec is disabled...no]))
+
+dnl # Include Speex codec
+AC_SUBST(ac_no_speex_codec)
+AC_ARG_ENABLE(speex-codec,
+	      AC_HELP_STRING([--disable-speex-codec],
+			     [Exclude Speex codecs in the build]),
+	      [if test "$enable_speex_codec" = "no"; then
+		[ac_no_speex_codec=1]
+		AC_DEFINE(PJMEDIA_HAS_SPEEX_CODEC,0)
+		AC_MSG_RESULT([Checking if Speex codec is disabled...yes])
+	       fi],
+	      AC_MSG_RESULT([Checking if Speex codec is disabled...no]))
+
+dnl # Include iLBC codec
+AC_SUBST(ac_no_ilbc_codec)
+AC_ARG_ENABLE(ilbc-codec,
+	      AC_HELP_STRING([--disable-ilbc-codec],
+			     [Exclude iLBC codec in the build]),
+	      [if test "$enable_ilbc_codec" = "no"; then
+		[ac_no_ilbc_codec=1]
+		AC_DEFINE(PJMEDIA_HAS_ILBC_CODEC,0)
+		AC_MSG_RESULT([Checking if iLBC codec is disabled...yes])
+	       fi],
+	      AC_MSG_RESULT([Checking if iLBC codec is disabled...no]))
+
+dnl # Include libsamplerate
+AC_ARG_ENABLE(libsamplerate,
+	      AC_HELP_STRING([--enable-libsamplerate],
+			     [Link with libsamplerate when available. Note that PJMEDIA_RESAMPLE_IMP must also be configured]),
+	      [ AC_CHECK_LIB(samplerate,src_new) ],
+	      AC_MSG_RESULT([Skipping libsamplerate detection])
+	     )
+
+AC_SUBST(ac_resample_dll)
+AC_ARG_ENABLE(resample_dll,
+	      AC_HELP_STRING([--enable-resample-dll],
+			     [Build libresample as shared library]),
+	      [if test "$enable_resample_dll" = "yes"; then
+		[ac_resample_dll=1]
+		AC_MSG_RESULT([Building libresample as shared library... yes])
+	       fi],
+	      AC_MSG_RESULT([Building libresample as shared library... no])
+	      )
+
+dnl # SDL alt prefix
+AC_ARG_WITH(sdl,
+    AC_HELP_STRING([--with-sdl=DIR],
+		   [Specify alternate libSDL prefix]),
+    [],
+    [with_sdl=no]
+    )
+
+dnl # Do not use default SDL installation if we are cross-compiling
+if test "x$ac_cross_compile" != "x" -a "x$with_sdl" = "xno"; then
+    enable_sdl=no
+fi
+
+dnl # SDL
+AC_ARG_ENABLE(sdl,
+	      AC_HELP_STRING([--disable-sdl],
+			     [Disable SDL (default: not disabled)]),
+	      [
+		if test "$enable_sdl" = "no"; then
+		  AC_MSG_RESULT([Checking if SDL is disabled... yes])
+		fi
+	      ],
+	      [
+		  if test "x$with_sdl" != "xno" -a "x$with_sdl" != "x"; then
+			AC_MSG_RESULT([Using SDL prefix... $with_sdl])
+			AC_PATH_PROGS(SDL_CONFIG,sdl2-config sdl-config,,$with_sdl/bin)
+                  else
+			AC_PATH_PROGS(SDL_CONFIG, sdl2-config sdl-config)
+		  fi
+		  
+		  AC_MSG_CHECKING([SDL availability])
+		  if test "x$SDL_CONFIG" = "x"; then
+			AC_MSG_RESULT([not found])
+		  elif (sh -c "$SDL_CONFIG --version" | grep -e '^1\.3' -e '^2\.') then
+			AC_SUBST(ac_sdl_cflags)
+			AC_SUBST(ac_sdl_ldflags)
+			ac_sdl_cflags=`$SDL_CONFIG --cflags`
+			ac_sdl_cflags="-DPJMEDIA_VIDEO_DEV_HAS_SDL=1 $ac_sdl_cflags"
+			ac_sdl_ldflags=`$SDL_CONFIG --libs`
+			LIBS="$LIBS $ac_sdl_ldflags"
+		  else
+			AC_MSG_RESULT([Unsupported SDL version])
+		  fi
+	      ])
+
+
+AC_ARG_WITH(ffmpeg,
+    AC_HELP_STRING([--with-ffmpeg=DIR],
+		   [Specify alternate FFMPEG prefix]),
+    [],
+    [with_ffmpeg=no]
+    )
+
+dnl # Do not use default ffmpeg installation if we are cross-compiling
+if test "x$ac_cross_compile" != "x" -a "x$with_ffmpeg" = "xno"; then
+    enable_ffmpeg=no
+fi
+
+dnl # FFMPEG stuffs
+AC_ARG_ENABLE(ffmpeg,
+	      AC_HELP_STRING([--disable-ffmpeg],
+			     [Disable ffmpeg (default: not disabled)]),
+	      [
+	        AC_SUBST(ac_has_ffmpeg,0)
+		if test "$enable_ffmpeg" = "no"; then
+			AC_MSG_RESULT([Checking if ffmpeg is disabled... yes])
+		fi
+	      ],
+	      [
+		AC_SUBST(ac_ffmpeg_cflags)
+		AC_SUBST(ac_ffmpeg_ldflags)
+
+		FFMPEG_PREFIX=""
+		AC_SUBST(SAVED_PKG_CONFIG_PATH)
+		SAVED_PKG_CONFIG_PATH=$PKG_CONFIG_PATH
+    		if test "x$with_ffmpeg" != "xno" -a "x$with_ffmpeg" != "x"; then
+			FFMPEG_PREFIX=$with_ffmpeg
+			AC_MSG_RESULT([Using ffmpeg prefix... $FFMPEG_PREFIX])
+			export PKG_CONFIG_PATH=$FFMPEG_PREFIX/lib/pkgconfig
+		fi
+
+		AC_CHECK_PROGS(PKG_CONFIG,pkg-config "python pkgconfig.py",none)
+
+		if test "$PKG_CONFIG" != "none"; then
+			AC_MSG_CHECKING([ffmpeg packages])
+			av_pkg=""
+			if $PKG_CONFIG --exists libdevice; then
+				ac_ffmpeg_cflags="$ac_ffmpeg_cflags -DPJMEDIA_HAS_LIBAVDEVICE=1"
+				av_pkg="$av_pkg libdevice"
+			fi
+			if $PKG_CONFIG --exists libavformat; then
+				ac_ffmpeg_cflags="$ac_ffmpeg_cflags -DPJMEDIA_HAS_LIBAVFORMAT=1"
+				av_pkg="$av_pkg libavformat"
+			fi
+			if $PKG_CONFIG --exists libavcodec; then
+				ac_ffmpeg_cflags="$ac_ffmpeg_cflags -DPJMEDIA_HAS_LIBAVCODEC=1"
+				av_pkg="$av_pkg libavcodec"
+			fi
+			if $PKG_CONFIG --exists libswscale; then
+				ac_ffmpeg_cflags="$ac_ffmpeg_cflags -DPJMEDIA_HAS_LIBSWSCALE=1"
+				av_pkg="$av_pkg libswscale"
+			fi
+			if $PKG_CONFIG --exists libavutil; then
+				ac_ffmpeg_cflags="$ac_ffmpeg_cflags -DPJMEDIA_HAS_LIBAVUTIL=1"
+				av_pkg="$av_pkg libavutil"
+			fi
+			if $PKG_CONFIG --exists libavcore; then
+				ac_ffmpeg_cflags="$ac_ffmpeg_cflags -DPJMEDIA_HAS_LIBAVCORE=1"
+				av_pkg="$av_pkg libavcore"
+			fi
+			
+			if test "x$av_pkg" == "x"; then
+			   AC_MSG_RESULT([none detected (check the prefix)! **])
+			else
+			   AC_MSG_RESULT([$av_pkg])
+			fi
+			
+			ac_ffmpeg_cflags="$ac_ffmpeg_cflags `$PKG_CONFIG --cflags $av_pkg`"
+			ac_ffmpeg_ldflags="$ac_ffmpeg_ldflags `$PKG_CONFIG --libs $av_pkg`"
+
+		else
+			dnl #
+			dnl # Use hardcoded values to configure ffmpeg
+			dnl #
+			
+			AC_MSG_RESULT([*** Warning: neither pkg-config nor python is available, ffmpeg dependency cannot be calculated. If ffmpeg libraries are not detected, you need to specify the correct CFLAGS and LDFLAGS settings for ffmpeg prior to invoking configure ***])
+			
+			LIBS="-L$FFMPEG_PREFIX/lib $LIBS"
+			LDFLAGS="-L$FFMPEG_PREFIX/lib $LDFLAGS"
+			CFLAGS="-I$FFMPEG_PREFIX/include $CFLAGS"
+			
+			AC_CHECK_LIB(avdevice,
+				     avdevice_version,
+				     [ac_ffmpeg_cflags="$ac_ffmpeg_cflags -DPJMEDIA_HAS_LIBAVDEVICE=1"
+				      ac_ffmpeg_ldflags="$ac_ffmpeg_ldflags -lavdevice"
+				     ]
+				     )
+			AC_CHECK_LIB(avutil,
+				     av_malloc,
+				     [ac_ffmpeg_cflags="$ac_ffmpeg_cflags -DPJMEDIA_HAS_LIBAVUTIL=1"
+				      ac_ffmpeg_ldflags="$ac_ffmpeg_ldflags -lavutil"
+				     ]
+				     )
+			AC_CHECK_LIB(avcodec,
+				     avcodec_init,
+				     [ac_ffmpeg_cflags="$ac_ffmpeg_cflags -DPJMEDIA_HAS_LIBAVCODEC=1"
+				      ac_ffmpeg_ldflags="$ac_ffmpeg_ldflags -lavcodec"
+				     ],
+				     [],
+				     [-lavutil]
+				     )
+			AC_CHECK_LIB(avformat,
+				     av_register_all,
+				     [ac_ffmpeg_cflags="$ac_ffmpeg_cflags -DPJMEDIA_HAS_LIBAVFORMAT=1"
+				      ac_ffmpeg_ldflags="$ac_ffmpeg_ldflags -lavformat"
+				     ],
+				     [],
+				     [-lavcodec -lavutil]
+				     )
+			AC_CHECK_LIB(swscale,
+				     sws_scale,
+				     [ac_ffmpeg_cflags="$ac_ffmpeg_cflags -DPJMEDIA_HAS_LIBSWSCALE=1"
+				      ac_ffmpeg_ldflags="$ac_ffmpeg_ldflags -lswscale"
+				     ],
+				     [],
+				     [-lavutil]
+				     )
+			AC_CHECK_LIB(avcore,
+				     avcore_version,
+				     [ac_ffmpeg_cflags="$ac_ffmpeg_cflags -DPJMEDIA_HAS_LIBAVCORE=1"
+				      ac_ffmpeg_ldflags="$ac_ffmpeg_ldflags -lavcore"
+				     ]
+				     )
+			
+		fi
+		
+		LIBS="$LIBS $ac_ffmpeg_ldflags"
+		export PKG_CONFIG_PATH=$SAVED_PKG_CONFIG_PATH
+	      ]
+	      )
+
+dnl # Video for Linux 2
+AC_ARG_ENABLE(v4l2,
+	      AC_HELP_STRING([--disable-v4l2],
+			     [Disable Video4Linux2 (default: not disabled)]),
+	      [
+		if test "$enable_v4l2" = "no"; then
+		  AC_MSG_RESULT([Checking if V4L2 is disabled... yes])
+		fi
+	      ],
+	      [
+	        AC_SUBST(ac_v4l2_cflags)
+	        AC_SUBST(ac_v4l2_ldflags)
+		AC_CHECK_LIB(v4l2,
+			     v4l2_open,
+			     [ac_v4l2_cflags="-DPJMEDIA_VIDEO_DEV_HAS_V4L2=1"
+			      ac_v4l2_ldflags="-lv4l2"
+			      LIBS="$LIBS -lv4l2"
+			     ]
+			     )
+	      ])
+
+dnl ########################################################
+dnl # Intel IPP support
+dnl #
+AC_ARG_ENABLE(ipp,
+    AC_HELP_STRING([--enable-ipp],
+		   [Enable Intel IPP support. Specify the Intel IPP package and samples location using IPPROOT and IPPSAMPLES env var or with --with-ipp and --with-ipp-samples options]),
+    [],
+    [enable_ipp=no]
+    )
+
+AC_ARG_WITH(ipp,
+    AC_HELP_STRING([--with-ipp=DIR],
+		   [Specify the Intel IPP location]),
+    [],
+    [with_ipp=no]
+    )
+
+AC_ARG_WITH(ipp-samples,
+    AC_HELP_STRING([--with-ipp-samples=DIR],
+		   [Specify the Intel IPP samples location]),
+    [],
+    [with_ipp_samples=no]
+    )
+
+AC_ARG_WITH(ipp-arch,
+    AC_HELP_STRING([--with-ipp-arch=ARCH],
+		   [Specify the Intel IPP ARCH suffix, e.g. "64" or "em64t. Default is blank for IA32"]),
+    [],
+    [with_ipp_arch=no]
+    )
+
+if test "x$enable_ipp" != "xno"; then
+    dnl # 
+    dnl # Verifying Intel IPP path
+    dnl #
+    AC_MSG_CHECKING([Intel IPP location])
+
+    if test "x$with_ipp" != "xno" -a "x$with_ipp" != "x"; then
+	AC_MSG_RESULT([$with_ipp])
+	IPPROOT=$with_ipp
+    elif test "x$IPPROOT" = "x"; then
+	if test -d /opt/intel/ipp; then
+	    IPPROOT=`ls -d /opt/intel/ipp/*/* | head -1`
+	    AC_MSG_RESULT([autodetected in $IPPROOT])
+	fi
+    else
+	AC_MSG_RESULT([$IPPROOT])
+    fi
+
+    if test "x$with_ipp_arch" != "xno"; then
+	IPP_SUFFIX=$with_ipp_arch
+	AC_MSG_RESULT([IPP arch suffix is set to $IPP_SUFFIX])
+    else
+	IPP_SUFFIX=""
+	AC_MSG_RESULT([IPP arch suffix is set to empty])
+    fi
+
+    if test x$IPPROOT = x; then
+	AC_MSG_ERROR([the location is neither specified nor can be guessed. Please specify with IPPROOT env var or with --with-ipp option])
+    elif test ! -d $IPPROOT; then
+	AC_MSG_ERROR([not found])
+    elif test ! -d $IPPROOT/include; then
+	AC_MSG_ERROR([directory doesn't seem to be valid])
+    else
+	# IPP directory looks okay.
+	# Remove trailing backslash
+	IPPROOT=`echo $IPPROOT | sed 's/\/$//'`
+
+	SAVED_CFLAGS="$CFLAGS"
+	SAVED_LDFLAGS="$LDFLAGS"
+	SAVED_LIBS="$LIBS"
+
+	IPP_CFLAGS="-I$IPPROOT/include"
+	IPP_LIBS="-lippsc${IPP_SUFFIX} -lipps${IPP_SUFFIX} -lippcore${IPP_SUFFIX}"
+
+#
+	# Some differences between Mac OS X and Linux
+	case $target in 
+	    *darwin* )
+		IPP_LDFLAGS="-L$IPPROOT/Libraries -L$IPPROOT/lib"
+		;;
+	    *)
+	    	# Find out where the libraries live.
+		IPP7_ARCH=""
+		if test -d $IPPROOT/lib/intel64; then
+		   IPP7_ARCH="intel64"
+		elif test -d $IPPROOT/lib/ia32; then
+		   IPP7_ARCH="ia32"
+		elif test -d $IPPROOT/lib/mic; then
+		   IPP7_ARCH="mic"
+		fi
+
+		if test -z "$IPP7_ARCH"; then
+		   # IPP6 (and possibly below)
+		   IPP_LDFLAGS="-L$IPPROOT/sharedlib"
+		   IPP_LIBS="$IPP_LIBS  -lippsr${IPP_SUFFIX} -lguide"
+		else
+		   # IPP7
+		   if ! test -d $IPPROOT/../compiler; then
+			AC_MSG_ERROR([Cannot find $IPPROOT/../compiler directory. Please set IPPROOT variable correctly])
+		   fi
+		   IPP_CFLAGS="$IPP_CFLAGS"
+		   IPP_LDFLAGS="-L$IPPROOT/lib/intel64 -L$IPPROOT/../compiler/lib/$IPP7_ARCH"
+		   IPP_LIBS="$IPP_LIBS -liomp5"
+		fi
+		;;
+	esac
+
+	#IPP_LDFLAGS="-L$IPPROOT/sharedlib"
+	#Static:
+	#IPP_LIBS="-lippscmerged -lippsrmerged -lippsmerged -lippcore"
+
+	CFLAGS="$CFLAGS $IPP_CFLAGS"
+	LDFLAGS="$LDFLAGS $IPP_LDFLAGS"
+	LIBS="$IPP_LIBS $LIBS"
+
+
+	AC_MSG_CHECKING([Intel IPP usability])
+	AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <ippcore.h>
+					   ]],
+					   [ippStaticInit();])],
+		  [AC_MSG_RESULT(ok)],
+		  [AC_MSG_FAILURE([Error: unable to recognize your IPP installation. Make sure the paths and ARCH suffix are set correctly, run with --help for more info])])
+
+	CFLAGS="$SAVED_CFLAGS"
+	LDFLAGS="$SAVED_LDFLAGS"
+	LIBS="$SAVED_LIBS"
+    fi
+
+    dnl # 
+    dnl # Verifying Intel IPP samples path
+    dnl #
+    AC_MSG_CHECKING([Intel IPP samples location])
+
+    if test "x$with_ipp_samples" != "xno" -a "x$with_ipp_samples" != "x"; then
+	AC_MSG_RESULT([$with_ipp_samples])
+	IPPSAMPLES=$with_ipp_samples
+    elif test "x$IPPSAMPLES" = "x"; then
+	if test -d /opt/intel/ipp-samples; then
+	    IPPSAMPLES=/opt/intel/ipp-samples
+	    AC_MSG_RESULT([autodetected in $IPPSAMPLES])
+	fi
+    else
+	AC_MSG_RESULT([$IPPSAMPLES])
+    fi
+
+    if test x$IPPSAMPLES = x; then
+	AC_MSG_ERROR([the location is neither specified nor can be guessed. Please specify with IPPSAMPLES env var or with --with-ipp-samples option])
+    elif test ! -d $IPPSAMPLES; then
+	AC_MSG_ERROR([not found])
+    elif test ! -d $IPPSAMPLES/speech-codecs; then
+	AC_MSG_ERROR([directory doesn't seem to be valid])
+    else
+	# Remove trailing backslash
+	IPPSAMPLES=`echo $IPPSAMPLES | sed 's/\/$//'`
+	
+	# Guess the libusc.a/libspeech.a build location
+	AC_MSG_CHECKING([Intel IPP USC build location])
+	if test -d $IPPSAMPLES/speech-codecs/bin; then
+	    IPPVER=5 
+	    IPPSAMP_DIR=`ls -d $IPPSAMPLES/speech-codecs/bin/*gcc*/lib | head -1`
+	elif test -d $IPPSAMPLES/speech-codecs/_bin; then
+	    IPPVER=6
+	    if test -d $IPPSAMPLES/speech-codecs/_bin/*gcc*; then
+		# gcc compiler
+	    	IPPSAMP_DIR=`ls -d $IPPSAMPLES/speech-codecs/_bin/*gcc*/lib | head -1`
+	    elif test -d $IPPSAMPLES/speech-codecs/_bin/*icc*; then
+		# icc compiler
+	    	IPPSAMP_DIR=`ls -d $IPPSAMPLES/speech-codecs/_bin/*icc*/lib | head -1`
+	    else
+		AC_MSG_FAILURE([Unable to find to find built binaries under $IPPSAMPLES/speech-codecs/{bin,_bin}. Have you built the IPP samples?])
+	    fi
+	else
+	    AC_MSG_FAILURE([unable to find $IPPSAMPLES/speech-codecs/bin/*gcc*/lib or $IPPSAMPLES/speech-codecs/_bin/*gcc*/lib directory. Have you built the samples?])
+	fi
+
+	# Test the directory
+	if test ! -d $IPPSAMP_DIR; then
+	    AC_MSG_FAILURE([There's something wrong with this script, directory $IPPSAMP_DIR does not exist])
+	    exit 1;
+	fi
+
+    	if test "x$IPPVER" = "x5"; then
+	    IPPSAMP_LIBS="libusc.a"
+	    IPPSAMP_LDLIBS="-lusc"
+	elif test "x$IPPVER" = "x6"; then
+	    IPPSAMP_LIBS="libspeech.a"
+	    IPPSAMP_LDLIBS="-lspeech"
+	else
+	    AC_MSG_FAILURE([bug in this script: unsupported IPP version])
+	fi
+
+	if test ! -f $IPPSAMP_DIR/$IPPSAMP_LIBS; then
+	    AC_MSG_FAILURE([$IPPSAMP_LIBS doesn't exist in $IPPSAMP_DIR])
+	fi
+
+	AC_MSG_RESULT([$IPPSAMP_DIR])
+
+	SAVED_CFLAGS="$CFLAGS"
+	SAVED_LDFLAGS="$LDFLAGS"
+	SAVED_LIBS="$LIBS"
+
+	IPPSAMP_INC="-I$IPPSAMPLES/speech-codecs/core/usc/include"
+	CFLAGS="$CFLAGS $IPPSAMP_INC"
+	LDFLAGS="$LDFLAGS -L$IPPSAMP_DIR"
+	LIBS="$IPPSAMP_LDLIBS $LIBS"
+
+	AC_MSG_CHECKING([Intel IPP USC usability])
+	AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <usc.h>
+					   ]],
+					   [extern USC_Fxns USC_G729AFP_Fxns;])],
+		  [AC_MSG_RESULT(ok)],
+		  [AC_MSG_FAILURE(failed)])
+
+	CFLAGS="$SAVED_CFLAGS"
+	LDFLAGS="$IPP_LDFLAGS $SAVED_LDFLAGS"
+	LIBS="$IPP_LIBS $SAVED_LIBS"
+
+	IPP_CFLAGS="$IPP_CFLAGS $IPPSAMP_INC"
+	IPP_LDFLAGS="$IPP_LDFLAGS -L$IPPSAMP_DIR"
+	IPP_LIBS="$IPPSAMP_LDLIBS $IPP_LIBS"
+    fi
+
+    CFLAGS="$CFLAGS $IPP_CFLAGS"
+    LDFLAGS="$LDFLAGS $IPP_LDFLAGS"
+    LIBS="$LIBS $IPP_LIBS"
+
+    ac_build_mak_vars="$ac_build_mak_vars\n\
+export IPP_CFLAGS=$IPP_CFLAGS\n\
+export IPP_LDFLAGS=$IPP_LDFLAGS\n\
+export IPP_LIBS=$IPP_LIBS"
+else
+    AC_MSG_RESULT([Skipping Intel IPP settings (not wanted)])
+fi
+
+
+dnl ##########################################
+dnl #
+dnl # PJSIP CONFIG
+dnl #
+
+dnl # SSL alt prefix
+AC_ARG_WITH(ssl,
+    AC_HELP_STRING([--with-ssl=DIR],
+		   [Specify alternate libssl prefix]),
+    [],
+    [with_ssl=no]
+    )
+
+dnl # Do not use default SSL installation if we are cross-compiling
+if test "x$ac_cross_compile" != "x" -a "x$with_ssl" = "xno"; then
+    enable_ssl=no
+fi
+
+dnl # Include SSL support
+AC_SUBST(ac_no_ssl)
+AC_ARG_ENABLE(ssl,
+	      AC_HELP_STRING([--disable-ssl],
+			     [Exclude SSL support the build (default: autodetect)])
+	      ,
+	      [
+		if test "$enable_ssl" = "no"; then
+		 [ac_no_ssl=1]
+		 AC_MSG_RESULT([Checking if SSL support is disabled... yes])
+	        fi
+	      ],
+	      [
+		AC_MSG_RESULT([checking for OpenSSL installations..])
+                if test "x$with_ssl" != "xno" -a "x$with_ssl" != "x"; then
+                    CFLAGS="$CFLAGS -I$with_ssl/include"
+                    LDFLAGS="$LDFLAGS -L$with_ssl/lib"
+                    AC_MSG_RESULT([Using SSL prefix... $with_ssl])
+                fi
+		AC_SUBST(openssl_h_present)
+		AC_SUBST(libssl_present)
+		AC_SUBST(libcrypto_present)
+		AC_CHECK_HEADER(openssl/ssl.h,[openssl_h_present=1])
+		AC_CHECK_LIB(crypto,ERR_load_BIO_strings,[libcrypto_present=1 && LIBS="$LIBS -lcrypto"])
+		AC_CHECK_LIB(ssl,SSL_library_init,[libssl_present=1 && LIBS="$LIBS -lssl"])
+		if test "x$openssl_h_present" = "x1" -a "x$libssl_present" = "x1" -a "x$libcrypto_present" = "x1"; then
+	        	AC_MSG_RESULT([OpenSSL library found, SSL support enabled])
+			# PJSIP_HAS_TLS_TRANSPORT setting follows PJ_HAS_SSL_SOCK
+			#AC_DEFINE(PJSIP_HAS_TLS_TRANSPORT, 1)
+			AC_DEFINE(PJ_HAS_SSL_SOCK, 1)
+		else
+			AC_MSG_RESULT([** OpenSSL libraries not found, disabling SSL support **])
+		fi
+	      ])
+
+dnl # Obsolete option --with-opencore-amrnb
+AC_ARG_WITH(opencore-amrnb,
+    AC_HELP_STRING([--with-opencore-amrnb=DIR],
+		   [This option is obsolete and replaced by --with-opencore-amr=DIR]),
+    [AC_MSG_ERROR(This option is obsolete and replaced by --with-opencore-amr=DIR)],
+    []
+    )
+
+dnl # opencore-amr alt prefix
+AC_ARG_WITH(opencore-amr,
+    AC_HELP_STRING([--with-opencore-amr=DIR],
+		   [Specify alternate libopencore-amr prefix]),
+    [],
+    [with_opencore_amr=no]
+    )
+
+dnl # Do not use default opencore-amr installation if we are cross-compiling
+if test "x$ac_cross_compile" != "x" -a "x$with_opencore_amr" = "xno"; then
+    enable_opencore_amr=no
+fi
+
+dnl # vo-amrwbenc alt prefix
+AC_ARG_WITH(opencore-amrwbenc,
+    AC_HELP_STRING([--with-opencore-amrwbenc=DIR],
+		   [Specify alternate libvo-amrwbenc prefix]),
+    [],
+    [with_opencore_amrwbenc=no]
+    )
+
+dnl # Do not use default vo-amrwbenc installation if we are cross-compiling
+if test "x$ac_cross_compile" != "x" -a "x$with_opencore_amrwbenc" = "xno"; then
+    enable_opencore_amrwbenc=no
+fi
+
+
+dnl # Include opencore-amr support
+AC_SUBST(ac_no_opencore_amrnb)
+AC_SUBST(ac_no_opencore_amrwb)
+AC_ARG_ENABLE(opencore_amr,
+	      AC_HELP_STRING([--disable-opencore-amr],
+			     [Exclude OpenCORE AMR support from the build (default: autodetect)])
+	      ,
+	      [
+		if test "$enable_opencore_amr" = "no"; then
+		 [ac_no_opencore_amrnb=1]
+		 [ac_no_opencore_amrwb=1]
+		 AC_DEFINE(PJMEDIA_HAS_OPENCORE_AMRNB_CODEC,0)
+		 AC_DEFINE(PJMEDIA_HAS_OPENCORE_AMRWB_CODEC,0)
+		 AC_MSG_RESULT([Checking if OpenCORE AMR support is disabled... yes])
+	        fi
+	      ],
+	      [
+		AC_MSG_RESULT([checking for OpenCORE AMR installations..])
+                if test "x$with_opencore_amr" != "xno" -a "x$with_opencore_amr" != "x"; then
+                    CFLAGS="$CFLAGS -I$with_opencore_amr/include"
+                    LDFLAGS="$LDFLAGS -L$with_opencore_amr/lib"
+                    AC_MSG_RESULT([Using OpenCORE AMR prefix... $with_opencore_amr])
+                fi
+                if test "x$with_opencore_amrwbenc" != "xno" -a "x$with_opencore_amrwbenc" != "x"; then
+                    CFLAGS="$CFLAGS -I$with_opencore_amrwbenc/include"
+                    LDFLAGS="$LDFLAGS -L$with_opencore_amrwbenc/lib"
+                    AC_MSG_RESULT([Using OpenCORE AMRWB-enc prefix... $with_opencore_amrwbenc])
+                fi
+		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
+		AC_SUBST(opencore_amrwb_enc_h_present)
+		AC_SUBST(opencore_amrwb_enc_present)
+		AC_SUBST(opencore_amrwb_dec_h_present)
+		AC_SUBST(opencore_amrwb_dec_present)
+		AC_CHECK_HEADER(vo-amrwbenc/enc_if.h,[opencore_amrwb_enc_h_present=1])
+		AC_CHECK_HEADER(opencore-amrwb/dec_if.h,[opencore_amrwb_dec_h_present=1])
+		AC_CHECK_LIB(opencore-amrwb,D_IF_init,[opencore_amrwb_dec_present=1 && LIBS="$LIBS -lopencore-amrwb"])
+		AC_CHECK_LIB(vo-amrwbenc,E_IF_init,[opencore_amrwb_enc_present=1 && LIBS="$LIBS -lvo-amrwbenc"])
+		if test "x$opencore_amrwb_enc_h_present" = "x1" -a "x$opencore_amrwb_dec_h_present" = "x1" -a "x$opencore_amrwb_enc_present" = "x1" -a "x$opencore_amrwb_dec_present" = "x1"; then
+	        	AC_MSG_RESULT([OpenCORE AMR-WB library found, AMR-WB support enabled])
+	        	AC_DEFINE(PJMEDIA_HAS_OPENCORE_AMRWB_CODEC,1)
+		else
+			[ac_no_opencore_amrwb=1]
+			AC_DEFINE(PJMEDIA_HAS_OPENCORE_AMRWB_CODEC,0)
+		fi
+
+	      ])
+
+dnl # SILK prefix
+AC_ARG_WITH(silk,
+    AC_HELP_STRING([--with-silk=DIR],
+		   [Specify alternate SILK prefix]),
+    [],
+    [with_silk=no]
+    )
+
+dnl # Do not use default SILK installation if we are cross-compiling
+if test "x$ac_cross_compile" != "x" -a "x$with_silk" = "xno"; then
+    enable_silk=no
+fi
+
+dnl # Include SILK support
+AC_SUBST(ac_no_silk)
+AC_ARG_ENABLE(silk,
+	      AC_HELP_STRING([--disable-silk],
+			     [Exclude SILK support from the build (default: autodetect)])
+	      ,
+	      [
+		if test "$enable_silk" = "no"; then
+		 [ac_no_silk=1]
+		 AC_DEFINE(PJMEDIA_HAS_SILK_CODEC,0)
+		 AC_MSG_RESULT([Checking if SILK support is disabled... yes])
+	        fi
+	      ],
+	      [
+		AC_MSG_RESULT([checking for SILK installations..])
+                if test "x$with_silk" != "xno" -a "x$with_silk" != "x"; then
+                    CFLAGS="$CFLAGS -I$with_silk/interface"
+		    CPPFLAGS="$CPPFLAGS -I$with_silk/interface"
+                    LDFLAGS="$LDFLAGS -L$with_silk"
+                    AC_MSG_RESULT([Using SILK prefix... $with_silk])
+                fi                
+		AC_SUBST(silk_h_present)
+		AC_SUBST(silk_present)
+		AC_CHECK_HEADER(SKP_Silk_SDK_API.h,[silk_h_present=1])
+		AC_CHECK_LIB(SKP_SILK_SDK,SKP_Silk_SDK_get_version,[silk_present=1 && LIBS="$LIBS -lSKP_SILK_SDK"])
+		if test "x$silk_h_present" = "x1" -a "x$silk_present" = "x1"; then
+	        	AC_MSG_RESULT([SILK library found, SILK support enabled])
+	        	AC_DEFINE(PJMEDIA_HAS_SILK_CODEC,1)
+		else
+			[ac_no_silk=1]
+			AC_DEFINE(PJMEDIA_HAS_SILK_CODEC,0)
+		fi
+	      ])
+
+
+dnl ##########################################
+dnl #
+dnl # MANUAL CONFIG
+dnl #
+
+
+dnl # Determine if select() requires nfds to be filled up with
+dnl # correct value (max_fd+1). If zero, nfds will be filled up with
+dnl # PJ_FD_SETSIZE
+AC_MSG_CHECKING([if select() needs correct nfds])
+case $target in
+  *rtems*) AC_DEFINE(PJ_SELECT_NEEDS_NFDS,1)
+	   AC_MSG_RESULT(yes)
+	;;
+  *) AC_DEFINE(PJ_SELECT_NEEDS_NFDS,0)
+     AC_MSG_RESULT([no (default)])
+     AC_MSG_RESULT([** Decided that select() doesn't need correct nfds (please check)])
+	;;
+esac
+
+dnl # Determine if pj_thread_create() should enforce thread stack size when
+dnl # creating thread. Default is zero, to allow OS to allocate appropriate
+dnl # thread's stack size.
+AC_MSG_CHECKING([if pj_thread_create() should enforce stack size])
+case $target in
+  *rtems*) AC_DEFINE(PJ_THREAD_SET_STACK_SIZE,1)
+	   AC_MSG_RESULT(yes)
+	;;
+  *) AC_DEFINE(PJ_THREAD_SET_STACK_SIZE,0)
+     AC_MSG_RESULT([no (default)])
+	;;
+esac
+
+dnl # Determine if pj_thread_create() should allocate thread's stack from
+dnl # the pool. Default is zero, to let OS allocate thread's stack.
+AC_MSG_CHECKING([if pj_thread_create() should allocate stack])
+case $target in
+  *rtems*) AC_DEFINE(PJ_THREAD_ALLOCATE_STACK,1)
+	   AC_MSG_RESULT(yes)
+	;;
+  *) AC_DEFINE(PJ_THREAD_ALLOCATE_STACK,0)
+     AC_MSG_RESULT([no (default)])
+	;;
+esac
+
+dnl # This value specifies the value set in errno by the OS when a non-blocking
+dnl # socket recv() can not return immediate data.
+case $target in
+  *mingw* | *cygw* | *win32* | *w32* )
+	AC_DEFINE(PJ_BLOCKING_ERROR_VAL,WSAEWOULDBLOCK)
+	;;
+  *) AC_DEFINE(PJ_BLOCKING_ERROR_VAL,EAGAIN)
+     AC_MSG_RESULT([** Setting non-blocking recv() retval to EAGAIN (please check)])
+	;;
+esac
+
+dnl # This value specifies the value set in errno by the OS when a non-blocking
+dnl # socket connect() can not get connected immediately.
+case $target in
+  *mingw* | *cygw* | *win32* | *w32* )
+	AC_DEFINE(PJ_BLOCKING_CONNECT_ERROR_VAL,WSAEWOULDBLOCK)
+	;;
+  *) AC_DEFINE(PJ_BLOCKING_CONNECT_ERROR_VAL,EINPROGRESS)
+     AC_MSG_RESULT([** Setting non-blocking connect() retval to EINPROGRESS (please check)])
+	;;
+esac
+
+
+AC_SUBST(target)
+AC_SUBST(ac_linux_poll,select)
+AC_SUBST(ac_host,unix)
+AC_SUBST(ac_main_obj)
+case $target in
+  *rtems*)
+	ac_main_obj=main_rtems.o
+	;;
+  *)
+	ac_main_obj=main.o
+	;;
+esac
+AC_SUBST(CC)
+
+ac_build_mak_vars=`echo $ac_build_mak_vars | sed 's/\\\\n/\n/g'`
+AC_OUTPUT()
+
+
+AC_MSG_RESULT([
+
+Configurations for current target have been written to 'build.mak', and 'os-auto.mak' in various build directories, and pjlib/include/pj/compat/os_auto.h.
+
+Further customizations can be put in:
+  - 'user.mak'
+  - 'pjlib/include/pj/config_site.h'
+
+The next step now is to run 'make dep' and 'make'.
+])
+
diff --git a/jni/pjproject-android/.svn/pristine/84/841ec9817f780faa5b678edc6c9a6b17e7dfc697.svn-base b/jni/pjproject-android/.svn/pristine/84/841ec9817f780faa5b678edc6c9a6b17e7dfc697.svn-base
new file mode 100644
index 0000000..bca343b
--- /dev/null
+++ b/jni/pjproject-android/.svn/pristine/84/841ec9817f780faa5b678edc6c9a6b17e7dfc697.svn-base
@@ -0,0 +1,6751 @@
+/* $Id$ */
+/* 
+ * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
+ * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
+ *
+ * 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 __PJSUA_H__
+#define __PJSUA_H__
+
+/**
+ * @file pjsua.h
+ * @brief PJSUA API.
+ */
+
+
+/* Include all PJSIP core headers. */
+#include <pjsip.h>
+
+/* Include all PJMEDIA headers. */
+#include <pjmedia.h>
+
+/* Include all PJMEDIA-CODEC headers. */
+#include <pjmedia-codec.h>
+
+/* Videodev too */
+#include <pjmedia_videodev.h>
+
+/* Include all PJSIP-UA headers */
+#include <pjsip_ua.h>
+
+/* Include all PJSIP-SIMPLE headers */
+#include <pjsip_simple.h>
+
+/* Include all PJNATH headers */
+#include <pjnath.h>
+
+/* Include all PJLIB-UTIL headers. */
+#include <pjlib-util.h>
+
+/* Include all PJLIB headers. */
+#include <pjlib.h>
+
+
+PJ_BEGIN_DECL
+
+
+/**
+ * @defgroup PJSUA_LIB PJSUA API - High Level Softphone API
+ * @brief Very high level API for constructing SIP UA applications.
+ * @{
+ *
+ * @section pjsua_api_intro A SIP User Agent API for C/C++
+ *
+ * PJSUA API is very high level API for constructing SIP multimedia user agent
+ * applications. It wraps together the signaling and media functionalities
+ * into an easy to use call API, provides account management, buddy
+ * management, presence, instant messaging, along with multimedia
+ * features such as conferencing, file streaming, local playback,
+ * voice recording, and so on.
+ *
+ * @subsection pjsua_for_c_cpp C/C++ Binding
+ * Application must link with <b>pjsua-lib</b> to use this API. In addition,
+ * this library depends on the following libraries:
+ *  - <b>pjsip-ua</b>, 
+ *  - <b>pjsip-simple</b>, 
+ *  - <b>pjsip-core</b>, 
+ *  - <b>pjmedia</b>,
+ *  - <b>pjmedia-codec</b>, 
+ *  - <b>pjlib-util</b>, and
+ *  - <b>pjlib</b>, 
+ *
+ * so application must also link with these libraries as well. For more 
+ * information, please refer to 
+ * <A HREF="http://www.pjsip.org/using.htm">Getting Started with PJSIP</A>
+ * page.
+ *
+ * @section pjsua_samples
+ *
+ * Few samples are provided:
+ *
+  - @ref page_pjsip_sample_simple_pjsuaua_c\n
+    Very simple SIP User Agent with registration, call, and media, using
+    PJSUA-API, all in under 200 lines of code.
+
+  - @ref page_pjsip_samples_pjsua\n
+    This is the reference implementation for PJSIP and PJMEDIA.
+    PJSUA is a console based application, designed to be simple enough
+    to be readble, but powerful enough to demonstrate all features
+    available in PJSIP and PJMEDIA.\n
+
+ * @section root_using_pjsua_lib Using PJSUA API
+ *
+ * Please refer to @ref PJSUA_LIB_BASE on how to create and initialize the API.
+ * And then see the Modules on the bottom of this page for more information
+ * about specific subject.
+ */ 
+
+
+
+/*****************************************************************************
+ * BASE API
+ */
+
+/**
+ * @defgroup PJSUA_LIB_BASE PJSUA-API Basic API
+ * @ingroup PJSUA_LIB
+ * @brief Basic application creation/initialization, logging configuration, etc.
+ * @{
+ *
+ * The base PJSUA API controls PJSUA creation, initialization, and startup, and
+ * also provides various auxiliary functions.
+ *
+ * @section using_pjsua_lib Using PJSUA Library
+ *
+ * @subsection creating_pjsua_lib Creating PJSUA
+ *
+ * Before anything else, application must create PJSUA by calling 
+ * #pjsua_create().
+ * This, among other things, will initialize PJLIB, which is crucial before 
+ * any PJLIB functions can be called, PJLIB-UTIL, and create a SIP endpoint.
+ *
+ * After this function is called, application can create a memory pool (with
+ * #pjsua_pool_create()) and read configurations from command line or file to
+ * build the settings to initialize PJSUA below.
+ *
+ * @subsection init_pjsua_lib Initializing PJSUA
+ *
+ * After PJSUA is created, application can initialize PJSUA by calling
+ * #pjsua_init(). This function takes several optional configuration settings 
+ * in the argument, if application wants to set them.
+ *
+ * @subsubsection init_pjsua_lib_c_cpp PJSUA-LIB Initialization (in C)
+ * Sample code to initialize PJSUA in C code:
+ \code
+
+ #include <pjsua-lib/pjsua.h>
+
+ #define THIS_FILE  __FILE__
+
+ static pj_status_t app_init(void)
+ {
+    pjsua_config	 ua_cfg;
+    pjsua_logging_config log_cfg;
+    pjsua_media_config   media_cfg;
+    pj_status_t status;
+
+    // Must create pjsua before anything else!
+    status = pjsua_create();
+    if (status != PJ_SUCCESS) {
+	pjsua_perror(THIS_FILE, "Error initializing pjsua", status);
+	return status;
+    }
+
+    // Initialize configs with default settings.
+    pjsua_config_default(&ua_cfg);
+    pjsua_logging_config_default(&log_cfg);
+    pjsua_media_config_default(&media_cfg);
+
+    // At the very least, application would want to override
+    // the call callbacks in pjsua_config:
+    ua_cfg.cb.on_incoming_call = ...
+    ua_cfg.cb.on_call_state = ..
+    ...
+
+    // Customize other settings (or initialize them from application specific
+    // configuration file):
+    ...
+
+    // Initialize pjsua
+    status = pjsua_init(&ua_cfg, &log_cfg, &media_cfg);
+    if (status != PJ_SUCCESS) {
+          pjsua_perror(THIS_FILE, "Error initializing pjsua", status);
+	  return status;
+    }
+    .
+    ...
+ }
+ \endcode
+ *
+ *
+
+
+ * @subsection other_init_pjsua_lib Other Initialization
+ *
+ * After PJSUA is initialized with #pjsua_init(), application will normally
+ * need/want to perform the following tasks:
+ *
+ *  - create SIP transport with #pjsua_transport_create(). Application would
+ *    to call #pjsua_transport_create() for each transport types that it
+ *    wants to support (for example, UDP, TCP, and TLS). Please see
+ *    @ref PJSUA_LIB_TRANSPORT section for more info.
+ *  - create one or more SIP accounts with #pjsua_acc_add() or
+ *    #pjsua_acc_add_local(). The SIP account is used for registering with
+ *    the SIP server, if any. Please see @ref PJSUA_LIB_ACC for more info.
+ *  - add one or more buddies with #pjsua_buddy_add(). Please see
+ *    @ref PJSUA_LIB_BUDDY section for more info.
+ *  - optionally configure the sound device, codec settings, and other
+ *    media settings. Please see @ref PJSUA_LIB_MEDIA for more info.
+ *
+ *
+ * @subsection starting_pjsua_lib Starting PJSUA
+ *
+ * After all initializations have been done, application must call
+ * #pjsua_start() to start PJSUA. This function will check that all settings
+ * have been properly configured, and apply default settings when they haven't,
+ * or report error status when it is unable to recover from missing settings.
+ *
+ * Most settings can be changed during run-time. For example, application
+ * may add, modify, or delete accounts, buddies, or change media settings
+ * during run-time.
+ *
+ * @subsubsection starting_pjsua_lib_c C Example for Starting PJSUA
+ * Sample code:
+ \code
+ static pj_status_t app_run(void)
+ {
+    pj_status_t status;
+
+    // Start pjsua
+    status = pjsua_start();
+    if (status != PJ_SUCCESS) {
+	pjsua_destroy();
+	pjsua_perror(THIS_FILE, "Error starting pjsua", status);
+	return status;
+    }
+
+    // Run application loop
+    while (1) {
+	char choice[10];
+	
+	printf("Select menu: ");
+	fgets(choice, sizeof(choice), stdin);
+	...
+    }
+ }
+ \endcode
+
+ */
+
+/** Constant to identify invalid ID for all sorts of IDs. */
+#define PJSUA_INVALID_ID	    (-1)
+
+/** Disabled features temporarily for media reorganization */
+#define DISABLED_FOR_TICKET_1185	0
+
+/** Call identification */
+typedef int pjsua_call_id;
+
+/** Account identification */
+typedef int pjsua_acc_id;
+
+/** Buddy identification */
+typedef int pjsua_buddy_id;
+
+/** File player identification */
+typedef int pjsua_player_id;
+
+/** File recorder identification */
+typedef int pjsua_recorder_id;
+
+/** Conference port identification */
+typedef int pjsua_conf_port_id;
+
+/** Opaque declaration for server side presence subscription */
+typedef struct pjsua_srv_pres pjsua_srv_pres;
+
+/** Forward declaration for pjsua_msg_data */
+typedef struct pjsua_msg_data pjsua_msg_data;
+
+
+/**
+ * Maximum proxies in account.
+ */
+#ifndef PJSUA_ACC_MAX_PROXIES
+#   define PJSUA_ACC_MAX_PROXIES    8
+#endif
+
+/**
+ * Default value of SRTP mode usage. Valid values are PJMEDIA_SRTP_DISABLED, 
+ * PJMEDIA_SRTP_OPTIONAL, and PJMEDIA_SRTP_MANDATORY.
+ */
+#ifndef PJSUA_DEFAULT_USE_SRTP
+    #define PJSUA_DEFAULT_USE_SRTP  PJMEDIA_SRTP_DISABLED
+#endif
+
+/**
+ * Default value of secure signaling requirement for SRTP.
+ * Valid values are:
+ *	0: SRTP does not require secure signaling
+ *	1: SRTP requires secure transport such as TLS
+ *	2: SRTP requires secure end-to-end transport (SIPS)
+ */
+#ifndef PJSUA_DEFAULT_SRTP_SECURE_SIGNALING
+    #define PJSUA_DEFAULT_SRTP_SECURE_SIGNALING 1
+#endif
+
+/**
+ * Controls whether PJSUA-LIB should add ICE media feature tag
+ * parameter (the ";+sip.ice" parameter) to Contact header if ICE
+ * is enabled in the config.
+ *
+ * Default: 1
+ */
+#ifndef PJSUA_ADD_ICE_TAGS
+#   define PJSUA_ADD_ICE_TAGS		1
+#endif
+
+/**
+ * Timeout value used to acquire mutex lock on a particular call.
+ *
+ * Default: 2000 ms
+ */
+#ifndef PJSUA_ACQUIRE_CALL_TIMEOUT
+#   define PJSUA_ACQUIRE_CALL_TIMEOUT 2000
+#endif
+
+/**
+ * Is video enabled.
+ */
+#ifndef PJSUA_HAS_VIDEO
+#   define PJSUA_HAS_VIDEO		PJMEDIA_HAS_VIDEO
+#endif
+
+
+/**
+ * Interval between two keyframe requests, in milliseconds.
+ *
+ * Default: 3000 ms
+ */
+#ifndef PJSUA_VID_REQ_KEYFRAME_INTERVAL
+#   define PJSUA_VID_REQ_KEYFRAME_INTERVAL	3000
+#endif
+
+
+/**
+ * This enumeration represents pjsua state.
+ */
+typedef enum pjsua_state
+{
+    /**
+     * The library has not been initialized.
+     */
+    PJSUA_STATE_NULL,
+
+    /**
+     * After pjsua_create() is called but before pjsua_init() is called.
+     */
+    PJSUA_STATE_CREATED,
+
+    /**
+     * After pjsua_init() is called but before pjsua_start() is called.
+     */
+    PJSUA_STATE_INIT,
+
+    /**
+     * After pjsua_start() is called but before everything is running.
+     */
+    PJSUA_STATE_STARTING,
+
+    /**
+     * After pjsua_start() is called and before pjsua_destroy() is called.
+     */
+    PJSUA_STATE_RUNNING,
+
+    /**
+     * After pjsua_destroy() is called but before the function returns.
+     */
+    PJSUA_STATE_CLOSING
+
+} pjsua_state;
+
+
+/**
+ * Logging configuration, which can be (optionally) specified when calling
+ * #pjsua_init(). Application must call #pjsua_logging_config_default() to
+ * initialize this structure with the default values.
+ */
+typedef struct pjsua_logging_config
+{
+    /**
+     * Log incoming and outgoing SIP message? Yes!
+     */
+    pj_bool_t	msg_logging;
+
+    /**
+     * Input verbosity level. Value 5 is reasonable.
+     */
+    unsigned	level;
+
+    /**
+     * Verbosity level for console. Value 4 is reasonable.
+     */
+    unsigned	console_level;
+
+    /**
+     * Log decoration.
+     */
+    unsigned	decor;
+
+    /**
+     * Optional log filename.
+     */
+    pj_str_t	log_filename;
+
+    /**
+     * Additional flags to be given to #pj_file_open() when opening
+     * the log file. By default, the flag is PJ_O_WRONLY. Application
+     * may set PJ_O_APPEND here so that logs are appended to existing
+     * file instead of overwriting it.
+     *
+     * Default is 0.
+     */
+    unsigned	log_file_flags;
+
+    /**
+     * Optional callback function to be called to write log to
+     * application specific device. This function will be called for
+     * log messages on input verbosity level.
+     */
+    void       (*cb)(int level, const char *data, int len);
+
+
+} pjsua_logging_config;
+
+
+/**
+ * Use this function to initialize logging config.
+ *
+ * @param cfg	The logging config to be initialized.
+ */
+PJ_DECL(void) pjsua_logging_config_default(pjsua_logging_config *cfg);
+
+
+/**
+ * Use this function to duplicate logging config.
+ *
+ * @param pool	    Pool to use.
+ * @param dst	    Destination config.
+ * @param src	    Source config.
+ */
+PJ_DECL(void) pjsua_logging_config_dup(pj_pool_t *pool,
+				       pjsua_logging_config *dst,
+				       const pjsua_logging_config *src);
+
+
+/**
+ * Structure to be passed on MWI callback.
+ */
+typedef struct pjsua_mwi_info
+{
+    pjsip_evsub	    *evsub;	/**< Event subscription session, for
+				     reference.				*/
+    pjsip_rx_data   *rdata;	/**< The received NOTIFY request.	*/
+} pjsua_mwi_info;
+
+
+/**
+ * Structure to be passed on registration callback.
+ */
+typedef struct pjsua_reg_info
+{
+    struct pjsip_regc_cbparam	*cbparam;   /**< Parameters returned by
+						 registration callback.	*/
+} pjsua_reg_info;
+
+
+/** 
+ * Enumeration of media transport state types.
+ */
+typedef enum pjsua_med_tp_st
+{
+    /** Null, this is the state before media transport is created. */
+    PJSUA_MED_TP_NULL,
+
+    /**
+     * Just before media transport is created, which can finish
+     * asynchronously later.
+     */
+    PJSUA_MED_TP_CREATING,
+
+    /** Media transport creation is completed, but not initialized yet. */
+    PJSUA_MED_TP_IDLE,
+
+    /** Initialized (media_create() has been called). */
+    PJSUA_MED_TP_INIT,
+
+    /** Running (media_start() has been called). */
+    PJSUA_MED_TP_RUNNING,
+
+    /** Disabled (transport is initialized, but media is being disabled). */
+    PJSUA_MED_TP_DISABLED
+
+} pjsua_med_tp_st;
+
+
+/**
+ * Structure to be passed on media transport state callback.
+ */
+typedef struct pjsua_med_tp_state_info
+{
+    /**
+     * The media index.
+     */
+    unsigned             med_idx;
+
+    /**
+     * The media transport state
+     */
+    pjsua_med_tp_st      state;
+
+    /**
+     * The last error code related to the media transport state.
+     */
+    pj_status_t		 status;
+
+    /**
+     * Optional SIP error code.
+     */
+    int		         sip_err_code;
+
+    /**
+     * Optional extended info, the content is specific for each transport type.
+     */
+    void		*ext_info;
+
+} pjsua_med_tp_state_info;
+
+
+/**
+  * Type of callback to be called when media transport state is changed.
+  *
+  * @param call_id	The call ID.
+  * @param info         The media transport state info.
+  *
+  * @return		The callback must return PJ_SUCCESS at the moment.
+  */
+typedef pj_status_t
+(*pjsua_med_tp_state_cb)(pjsua_call_id call_id,
+                         const pjsua_med_tp_state_info *info);
+
+
+/**
+ * This enumeration specifies the options for custom media transport creation.
+ */
+typedef enum pjsua_create_media_transport_flag
+{
+   /**
+    * This flag indicates that the media transport must also close its
+    * "member" or "child" transport when pjmedia_transport_close() is
+    * called. If this flag is not specified, then the media transport
+    * must not call pjmedia_transport_close() of its member transport.
+    */
+   PJSUA_MED_TP_CLOSE_MEMBER = 1
+
+} pjsua_create_media_transport_flag;
+
+
+/**
+ * This enumeration specifies the contact rewrite method.
+ */
+typedef enum pjsua_contact_rewrite_method
+{
+    /**
+      * The Contact update will be done by sending unregistration
+      * to the currently registered Contact, while simultaneously sending new
+      * registration (with different Call-ID) for the updated Contact.
+      */
+    PJSUA_CONTACT_REWRITE_UNREGISTER = 1,
+
+    /**
+      * The Contact update will be done in a single, current
+      * registration session, by removing the current binding (by setting its
+      * Contact's expires parameter to zero) and adding a new Contact binding,
+      * all done in a single request.
+      */
+    PJSUA_CONTACT_REWRITE_NO_UNREG = 2,
+
+    /**
+      * The Contact update will be done when receiving any registration final
+      * response. If this flag is not specified, contact update will only be
+      * done upon receiving 2xx response. This flag MUST be used with
+      * PJSUA_CONTACT_REWRITE_UNREGISTER or PJSUA_CONTACT_REWRITE_NO_UNREG
+      * above to specify how the Contact update should be performed when
+      * receiving 2xx response.
+      */
+    PJSUA_CONTACT_REWRITE_ALWAYS_UPDATE = 4
+
+} pjsua_contact_rewrite_method;
+
+
+/**
+ * Call settings.
+ */
+typedef struct pjsua_call_setting
+{
+    /**
+     * Bitmask of #pjsua_call_flag constants.
+     *
+     * Default: 0
+     */
+    unsigned	     flag;
+
+    /**
+     * This flag controls what methods to request keyframe are allowed on
+     * the call. Value is bitmask of #pjsua_vid_req_keyframe_method.
+     */
+    unsigned	     req_keyframe_method;
+
+    /**
+     * Number of simultaneous active audio streams for this call. Setting
+     * this to zero will disable audio in this call.
+     *
+     * Default: 1
+     */
+    unsigned         aud_cnt;
+
+    /**
+     * Number of simultaneous active video streams for this call. Setting
+     * this to zero will disable video in this call.
+     *
+     * Default: 1 (if video feature is enabled, otherwise it is zero)
+     */
+    unsigned         vid_cnt;
+
+} pjsua_call_setting;
+
+
+/**
+ * This structure describes application callback to receive various event
+ * notification from PJSUA-API. All of these callbacks are OPTIONAL,
+ * although definitely application would want to implement some of
+ * the important callbacks (such as \a on_incoming_call).
+ */
+typedef struct pjsua_callback
+{
+    /**
+     * Notify application when call state has changed.
+     * Application may then query the call info to get the
+     * detail call states by calling  pjsua_call_get_info() function.
+     *
+     * @param call_id	The call index.
+     * @param e		Event which causes the call state to change.
+     */
+    void (*on_call_state)(pjsua_call_id call_id, pjsip_event *e);
+
+    /**
+     * Notify application on incoming call.
+     *
+     * @param acc_id	The account which match the incoming call.
+     * @param call_id	The call id that has just been created for
+     *			the call.
+     * @param rdata	The incoming INVITE request.
+     */
+    void (*on_incoming_call)(pjsua_acc_id acc_id, pjsua_call_id call_id,
+			     pjsip_rx_data *rdata);
+
+    /**
+     * This is a general notification callback which is called whenever
+     * a transaction within the call has changed state. Application can
+     * implement this callback for example to monitor the state of
+     * outgoing requests, or to answer unhandled incoming requests
+     * (such as INFO) with a final response.
+     *
+     * @param call_id	Call identification.
+     * @param tsx	The transaction which has changed state.
+     * @param e		Transaction event that caused the state change.
+     */
+    void (*on_call_tsx_state)(pjsua_call_id call_id,
+			      pjsip_transaction *tsx,
+			      pjsip_event *e);
+
+    /**
+     * Notify application when media state in the call has changed.
+     * Normal application would need to implement this callback, e.g.
+     * to connect the call's media to sound device. When ICE is used,
+     * this callback will also be called to report ICE negotiation
+     * failure.
+     *
+     * @param call_id	The call index.
+     */
+    void (*on_call_media_state)(pjsua_call_id call_id);
+
+
+    /**
+     * Notify application when a call has just created a local SDP (for 
+     * initial or subsequent SDP offer/answer). Application can implement
+     * this callback to modify the SDP, before it is being sent and/or
+     * negotiated with remote SDP, for example to apply per account/call
+     * basis codecs priority or to add custom/proprietary SDP attributes.
+     *
+     * @param call_id	The call index.
+     * @param sdp	The SDP has just been created.
+     * @param pool	The pool instance, application should use this pool
+     *			to modify the SDP.
+     * @param rem_sdp	The remote SDP, will be NULL if local is SDP offerer.
+     */
+    void (*on_call_sdp_created)(pjsua_call_id call_id,
+			        pjmedia_sdp_session *sdp,
+			        pj_pool_t *pool,
+			        const pjmedia_sdp_session *rem_sdp);
+
+
+    /**
+     * Notify application when media session is created and before it is
+     * registered to the conference bridge. Application may return different
+     * media port if it has added media processing port to the stream. This
+     * media port then will be added to the conference bridge instead.
+     *
+     * @param call_id	    Call identification.
+     * @param strm	    Media stream.
+     * @param stream_idx    Stream index in the media session.
+     * @param p_port	    On input, it specifies the media port of the
+     *			    stream. Application may modify this pointer to
+     *			    point to different media port to be registered
+     *			    to the conference bridge.
+     */
+    void (*on_stream_created)(pjsua_call_id call_id,
+			      pjmedia_stream *strm,
+                              unsigned stream_idx,
+			      pjmedia_port **p_port);
+
+    /**
+     * Notify application when media session has been unregistered from the
+     * conference bridge and about to be destroyed.
+     *
+     * @param call_id	    Call identification.
+     * @param strm	    Media stream.
+     * @param stream_idx    Stream index in the media session.
+     */
+    void (*on_stream_destroyed)(pjsua_call_id call_id,
+                                pjmedia_stream *strm,
+				unsigned stream_idx);
+
+    /**
+     * Notify application upon incoming DTMF digits.
+     *
+     * @param call_id	The call index.
+     * @param digit	DTMF ASCII digit.
+     */
+    void (*on_dtmf_digit)(pjsua_call_id call_id, int digit);
+
+    /**
+     * Notify application on call being transfered (i.e. REFER is received).
+     * Application can decide to accept/reject transfer request
+     * by setting the code (default is 202). When this callback
+     * is not defined, the default behavior is to accept the
+     * transfer. See also on_call_transfer_request2() callback for
+     * the version with \a pjsua_call_setting in the argument list.
+     *
+     * @param call_id	The call index.
+     * @param dst	The destination where the call will be 
+     *			transfered to.
+     * @param code	Status code to be returned for the call transfer
+     *			request. On input, it contains status code 200.
+     */
+    void (*on_call_transfer_request)(pjsua_call_id call_id,
+				     const pj_str_t *dst,
+				     pjsip_status_code *code);
+
+    /**
+     * Notify application on call being transfered (i.e. REFER is received).
+     * Application can decide to accept/reject transfer request
+     * by setting the code (default is 202). When this callback
+     * is not defined, the default behavior is to accept the
+     * transfer.
+     *
+     * @param call_id	The call index.
+     * @param dst	The destination where the call will be 
+     *			transfered to.
+     * @param code	Status code to be returned for the call transfer
+     *			request. On input, it contains status code 200.
+     * @param opt	The current call setting, application can update
+     *			this setting for the call being transfered.
+     */
+    void (*on_call_transfer_request2)(pjsua_call_id call_id,
+				      const pj_str_t *dst,
+				      pjsip_status_code *code,
+				      pjsua_call_setting *opt);
+
+    /**
+     * Notify application of the status of previously sent call
+     * transfer request. Application can monitor the status of the
+     * call transfer request, for example to decide whether to 
+     * terminate existing call.
+     *
+     * @param call_id	    Call ID.
+     * @param st_code	    Status progress of the transfer request.
+     * @param st_text	    Status progress text.
+     * @param final	    If non-zero, no further notification will
+     *			    be reported. The st_code specified in
+     *			    this callback is the final status.
+     * @param p_cont	    Initially will be set to non-zero, application
+     *			    can set this to FALSE if it no longer wants
+     *			    to receie further notification (for example,
+     *			    after it hangs up the call).
+     */
+    void (*on_call_transfer_status)(pjsua_call_id call_id,
+				    int st_code,
+				    const pj_str_t *st_text,
+				    pj_bool_t final,
+				    pj_bool_t *p_cont);
+
+    /**
+     * Notify application about incoming INVITE with Replaces header.
+     * Application may reject the request by setting non-2xx code.
+     * See also on_call_replace_request2() callback for the version
+     * with \a pjsua_call_setting in the argument list.
+     *
+     * @param call_id	    The call ID to be replaced.
+     * @param rdata	    The incoming INVITE request to replace the call.
+     * @param st_code	    Status code to be set by application. Application
+     *			    should only return a final status (200-699).
+     * @param st_text	    Optional status text to be set by application.
+     */
+    void (*on_call_replace_request)(pjsua_call_id call_id,
+				    pjsip_rx_data *rdata,
+				    int *st_code,
+				    pj_str_t *st_text);
+
+    /**
+     * Notify application about incoming INVITE with Replaces header.
+     * Application may reject the request by setting non-2xx code.
+     *
+     * @param call_id	    The call ID to be replaced.
+     * @param rdata	    The incoming INVITE request to replace the call.
+     * @param st_code	    Status code to be set by application. Application
+     *			    should only return a final status (200-699).
+     * @param st_text	    Optional status text to be set by application.
+     * @param opt	    The current call setting, application can update
+     *			    this setting for the call being replaced.
+     */
+    void (*on_call_replace_request2)(pjsua_call_id call_id,
+				     pjsip_rx_data *rdata,
+				     int *st_code,
+				     pj_str_t *st_text,
+				     pjsua_call_setting *opt);
+
+    /**
+     * Notify application that an existing call has been replaced with
+     * a new call. This happens when PJSUA-API receives incoming INVITE
+     * request with Replaces header.
+     *
+     * After this callback is called, normally PJSUA-API will disconnect
+     * \a old_call_id and establish \a new_call_id.
+     *
+     * @param old_call_id   Existing call which to be replaced with the
+     *			    new call.
+     * @param new_call_id   The new call.
+     * @param rdata	    The incoming INVITE with Replaces request.
+     */
+    void (*on_call_replaced)(pjsua_call_id old_call_id,
+			     pjsua_call_id new_call_id);
+
+
+    /**
+     * Notify application when call has received new offer from remote
+     * (i.e. re-INVITE/UPDATE with SDP is received). Application can
+     * decide to accept/reject the offer by setting the code (default
+     * is 200). If the offer is accepted, application can update the 
+     * call setting to be applied in the answer. When this callback is
+     * not defined, the default behavior is to accept the offer using
+     * current call setting.
+     *
+     * @param call_id	The call index.
+     * @param offer	The new offer received.
+     * @param reserved	Reserved param, currently not used.
+     * @param code	Status code to be returned for answering the
+     *			offer. On input, it contains status code 200.
+     *			Currently, valid values are only 200 and 488.
+     * @param opt	The current call setting, application can update
+     *			this setting for answering the offer.
+     */
+    void (*on_call_rx_offer)(pjsua_call_id call_id,
+			     const pjmedia_sdp_session *offer,
+			     void *reserved,
+			     pjsip_status_code *code,
+			     pjsua_call_setting *opt);
+
+    /**
+     * Notify application when registration or unregistration has been
+     * initiated. Note that this only notifies the initial registration
+     * and unregistration. Once registration session is active, subsequent
+     * refresh will not cause this callback to be called.
+     *
+     * @param acc_id	    The account ID.
+     * @param renew	    Non-zero for registration and zero for
+     * 			    unregistration.
+     */
+    void (*on_reg_started)(pjsua_acc_id acc_id, pj_bool_t renew);
+    
+    /**
+     * Notify application when registration status has changed.
+     * Application may then query the account info to get the
+     * registration details.
+     *
+     * @param acc_id	    The account ID.
+     */
+    void (*on_reg_state)(pjsua_acc_id acc_id);
+
+    /**
+     * Notify application when registration status has changed.
+     * Application may inspect the registration info to get the
+     * registration status details.
+     *
+     * @param acc_id	    The account ID.
+     * @param info	    The registration info.
+     */
+    void (*on_reg_state2)(pjsua_acc_id acc_id, pjsua_reg_info *info);
+
+    /**
+     * Notification when incoming SUBSCRIBE request is received. Application
+     * may use this callback to authorize the incoming subscribe request
+     * (e.g. ask user permission if the request should be granted).
+     *
+     * If this callback is not implemented, all incoming presence subscription
+     * requests will be accepted.
+     *
+     * If this callback is implemented, application has several choices on
+     * what to do with the incoming request:
+     *	- it may reject the request immediately by specifying non-200 class
+     *    final response in the \a code argument.
+     *	- it may immediately accept the request by specifying 200 as the
+     *	  \a code argument. This is the default value if application doesn't
+     *	  set any value to the \a code argument. In this case, the library
+     *	  will automatically send NOTIFY request upon returning from this
+     *	  callback.
+     *  - it may delay the processing of the request, for example to request
+     *    user permission whether to accept or reject the request. In this 
+     *	  case, the application MUST set the \a code argument to 202, then
+     *    IMMEDIATELY calls #pjsua_pres_notify() with state
+     *    PJSIP_EVSUB_STATE_PENDING and later calls #pjsua_pres_notify()
+     *    again to accept or reject the subscription request.
+     *
+     * Any \a code other than 200 and 202 will be treated as 200.
+     *
+     * Application MUST return from this callback immediately (e.g. it must
+     * not block in this callback while waiting for user confirmation).
+     *
+     * @param srv_pres	    Server presence subscription instance. If
+     *			    application delays the acceptance of the request,
+     *			    it will need to specify this object when calling
+     *			    #pjsua_pres_notify().
+     * @param acc_id	    Account ID most appropriate for this request.
+     * @param buddy_id	    ID of the buddy matching the sender of the
+     *			    request, if any, or PJSUA_INVALID_ID if no
+     *			    matching buddy is found.
+     * @param from	    The From URI of the request.
+     * @param rdata	    The incoming request.
+     * @param code	    The status code to respond to the request. The
+     *			    default value is 200. Application may set this
+     *			    to other final status code to accept or reject
+     *			    the request.
+     * @param reason	    The reason phrase to respond to the request.
+     * @param msg_data	    If the application wants to send additional
+     *			    headers in the response, it can put it in this
+     *			    parameter.
+     */
+    void (*on_incoming_subscribe)(pjsua_acc_id acc_id,
+				  pjsua_srv_pres *srv_pres,
+				  pjsua_buddy_id buddy_id,
+				  const pj_str_t *from,
+				  pjsip_rx_data *rdata,
+				  pjsip_status_code *code,
+				  pj_str_t *reason,
+				  pjsua_msg_data *msg_data);
+
+    /**
+     * Notification when server side subscription state has changed.
+     * This callback is optional as application normally does not need
+     * to do anything to maintain server side presence subscription.
+     *
+     * @param acc_id	    The account ID.
+     * @param srv_pres	    Server presence subscription object.
+     * @param remote_uri    Remote URI string.
+     * @param state	    New subscription state.
+     * @param event	    PJSIP event that triggers the state change.
+     */
+    void (*on_srv_subscribe_state)(pjsua_acc_id acc_id,
+				   pjsua_srv_pres *srv_pres,
+				   const pj_str_t *remote_uri,
+				   pjsip_evsub_state state,
+				   pjsip_event *event);
+
+    /**
+     * Notify application when the buddy state has changed.
+     * Application may then query the buddy into to get the details.
+     *
+     * @param buddy_id	    The buddy id.
+     */
+    void (*on_buddy_state)(pjsua_buddy_id buddy_id);
+
+
+    /**
+     * Notify application when the state of client subscription session
+     * associated with a buddy has changed. Application may use this
+     * callback to retrieve more detailed information about the state
+     * changed event.
+     *
+     * @param buddy_id	    The buddy id.
+     * @param sub	    Event subscription session.
+     * @param event	    The event which triggers state change event.
+     */
+    void (*on_buddy_evsub_state)(pjsua_buddy_id buddy_id,
+				 pjsip_evsub *sub,
+				 pjsip_event *event);
+
+    /**
+     * Notify application on incoming pager (i.e. MESSAGE request).
+     * Argument call_id will be -1 if MESSAGE request is not related to an
+     * existing call.
+     *
+     * See also \a on_pager2() callback for the version with \a pjsip_rx_data
+     * passed as one of the argument.
+     *
+     * @param call_id	    Containts the ID of the call where the IM was
+     *			    sent, or PJSUA_INVALID_ID if the IM was sent
+     *			    outside call context.
+     * @param from	    URI of the sender.
+     * @param to	    URI of the destination message.
+     * @param contact	    The Contact URI of the sender, if present.
+     * @param mime_type	    MIME type of the message.
+     * @param body	    The message content.
+     */
+    void (*on_pager)(pjsua_call_id call_id, const pj_str_t *from,
+		     const pj_str_t *to, const pj_str_t *contact,
+		     const pj_str_t *mime_type, const pj_str_t *body);
+
+    /**
+     * This is the alternative version of the \a on_pager() callback with
+     * \a pjsip_rx_data argument.
+     *
+     * @param call_id	    Containts the ID of the call where the IM was
+     *			    sent, or PJSUA_INVALID_ID if the IM was sent
+     *			    outside call context.
+     * @param from	    URI of the sender.
+     * @param to	    URI of the destination message.
+     * @param contact	    The Contact URI of the sender, if present.
+     * @param mime_type	    MIME type of the message.
+     * @param body	    The message content.
+     * @param rdata	    The incoming MESSAGE request.
+     * @param acc_id	    Account ID most suitable for this message.
+     */
+    void (*on_pager2)(pjsua_call_id call_id, const pj_str_t *from,
+		      const pj_str_t *to, const pj_str_t *contact,
+		      const pj_str_t *mime_type, const pj_str_t *body,
+		      pjsip_rx_data *rdata, pjsua_acc_id acc_id);
+
+    /**
+     * Notify application about the delivery status of outgoing pager
+     * request. See also on_pager_status2() callback for the version with
+     * \a pjsip_rx_data in the argument list.
+     *
+     * @param call_id	    Containts the ID of the call where the IM was
+     *			    sent, or PJSUA_INVALID_ID if the IM was sent
+     *			    outside call context.
+     * @param to	    Destination URI.
+     * @param body	    Message body.
+     * @param user_data	    Arbitrary data that was specified when sending
+     *			    IM message.
+     * @param status	    Delivery status.
+     * @param reason	    Delivery status reason.
+     */
+    void (*on_pager_status)(pjsua_call_id call_id,
+			    const pj_str_t *to,
+			    const pj_str_t *body,
+			    void *user_data,
+			    pjsip_status_code status,
+			    const pj_str_t *reason);
+
+    /**
+     * Notify application about the delivery status of outgoing pager
+     * request.
+     *
+     * @param call_id	    Containts the ID of the call where the IM was
+     *			    sent, or PJSUA_INVALID_ID if the IM was sent
+     *			    outside call context.
+     * @param to	    Destination URI.
+     * @param body	    Message body.
+     * @param user_data	    Arbitrary data that was specified when sending
+     *			    IM message.
+     * @param status	    Delivery status.
+     * @param reason	    Delivery status reason.
+     * @param tdata	    The original MESSAGE request.
+     * @param rdata	    The incoming MESSAGE response, or NULL if the
+     *			    message transaction fails because of time out 
+     *			    or transport error.
+     * @param acc_id	    Account ID from this the instant message was
+     *			    send.
+     */
+    void (*on_pager_status2)(pjsua_call_id call_id,
+			     const pj_str_t *to,
+			     const pj_str_t *body,
+			     void *user_data,
+			     pjsip_status_code status,
+			     const pj_str_t *reason,
+			     pjsip_tx_data *tdata,
+			     pjsip_rx_data *rdata,
+			     pjsua_acc_id acc_id);
+
+    /**
+     * Notify application about typing indication.
+     *
+     * @param call_id	    Containts the ID of the call where the IM was
+     *			    sent, or PJSUA_INVALID_ID if the IM was sent
+     *			    outside call context.
+     * @param from	    URI of the sender.
+     * @param to	    URI of the destination message.
+     * @param contact	    The Contact URI of the sender, if present.
+     * @param is_typing	    Non-zero if peer is typing, or zero if peer
+     *			    has stopped typing a message.
+     */
+    void (*on_typing)(pjsua_call_id call_id, const pj_str_t *from,
+		      const pj_str_t *to, const pj_str_t *contact,
+		      pj_bool_t is_typing);
+
+    /**
+     * Notify application about typing indication.
+     *
+     * @param call_id	    Containts the ID of the call where the IM was
+     *			    sent, or PJSUA_INVALID_ID if the IM was sent
+     *			    outside call context.
+     * @param from	    URI of the sender.
+     * @param to	    URI of the destination message.
+     * @param contact	    The Contact URI of the sender, if present.
+     * @param is_typing	    Non-zero if peer is typing, or zero if peer
+     *			    has stopped typing a message.
+     * @param rdata	    The received request.
+     * @param acc_id	    Account ID most suitable for this message.
+     */
+    void (*on_typing2)(pjsua_call_id call_id, const pj_str_t *from,
+		       const pj_str_t *to, const pj_str_t *contact,
+		       pj_bool_t is_typing, pjsip_rx_data *rdata,
+		       pjsua_acc_id acc_id);
+
+    /**
+     * Callback when the library has finished performing NAT type
+     * detection.
+     *
+     * @param res	    NAT detection result.
+     */
+    void (*on_nat_detect)(const pj_stun_nat_detect_result *res);
+
+    /**
+     * This callback is called when the call is about to resend the 
+     * INVITE request to the specified target, following the previously
+     * received redirection response.
+     *
+     * Application may accept the redirection to the specified target,
+     * reject this target only and make the session continue to try the next 
+     * target in the list if such target exists, stop the whole
+     * redirection process altogether and cause the session to be
+     * disconnected, or defer the decision to ask for user confirmation.
+     *
+     * This callback is optional. If this callback is not implemented,
+     * the default behavior is to NOT follow the redirection response.
+     *
+     * @param call_id	The call ID.
+     * @param target	The current target to be tried.
+     * @param e		The event that caused this callback to be called.
+     *			This could be the receipt of 3xx response, or
+     *			4xx/5xx response received for the INVITE sent to
+     *			subsequent targets, or NULL if this callback is
+     *			called from within #pjsua_call_process_redirect()
+     *			context.
+     *
+     * @return		Action to be performed for the target. Set this
+     *			parameter to one of the value below:
+     *			- PJSIP_REDIRECT_ACCEPT: immediately accept the
+     *			  redirection. When set, the call will immediately
+     *			  resend INVITE request to the target.
+     *			- PJSIP_REDIRECT_ACCEPT_REPLACE: immediately accept
+     *			  the redirection and replace the To header with the
+     *			  current target. When set, the call will immediately
+     *			  resend INVITE request to the target.
+     *			- PJSIP_REDIRECT_REJECT: immediately reject this
+     *			  target. The call will continue retrying with
+     *			  next target if present, or disconnect the call
+     *			  if there is no more target to try.
+     *			- PJSIP_REDIRECT_STOP: stop the whole redirection
+     *			  process and immediately disconnect the call. The
+     *			  on_call_state() callback will be called with
+     *			  PJSIP_INV_STATE_DISCONNECTED state immediately
+     *			  after this callback returns.
+     *			- PJSIP_REDIRECT_PENDING: set to this value if
+     *			  no decision can be made immediately (for example
+     *			  to request confirmation from user). Application
+     *			  then MUST call #pjsua_call_process_redirect()
+     *			  to either accept or reject the redirection upon
+     *			  getting user decision.
+     */
+    pjsip_redirect_op (*on_call_redirected)(pjsua_call_id call_id, 
+					    const pjsip_uri *target,
+					    const pjsip_event *e);
+
+    /**
+     * This callback is called when message waiting indication subscription
+     * state has changed. Application can then query the subscription state
+     * by calling #pjsip_evsub_get_state().
+     *
+     * @param acc_id	The account ID.
+     * @param evsub	The subscription instance.
+     */
+    void (*on_mwi_state)(pjsua_acc_id acc_id, pjsip_evsub *evsub);
+
+    /**
+     * This callback is called when a NOTIFY request for message summary / 
+     * message waiting indication is received.
+     *
+     * @param acc_id	The account ID.
+     * @param mwi_info	Structure containing details of the event,
+     *			including the received NOTIFY request in the
+     *			\a rdata field.
+     */
+    void (*on_mwi_info)(pjsua_acc_id acc_id, pjsua_mwi_info *mwi_info);
+
+    /**
+     * This callback is called when transport state is changed. See also
+     * #pjsip_tp_state_callback.
+     */
+    pjsip_tp_state_callback on_transport_state;
+
+    /**
+     * This callback is called when media transport state is changed. See
+     * also #pjsua_med_tp_state_cb.
+     */
+    pjsua_med_tp_state_cb on_call_media_transport_state;
+
+    /**
+     * This callback is called to report error in ICE media transport.
+     * Currently it is used to report TURN Refresh error.
+     *
+     * @param index	Transport index.
+     * @param op	Operation which trigger the failure.
+     * @param status	Error status.
+     * @param param	Additional info about the event. Currently this will
+     * 			always be set to NULL.
+     */
+    void (*on_ice_transport_error)(int index, pj_ice_strans_op op,
+				   pj_status_t status, void *param);
+
+    /**
+     * Callback when the sound device is about to be opened or closed.
+     * This callback will be called even when null sound device or no
+     * sound device is configured by the application (i.e. the
+     * #pjsua_set_null_snd_dev() and #pjsua_set_no_snd_dev() APIs).
+     * This API is mostly useful when the application wants to manage
+     * the sound device by itself (i.e. with #pjsua_set_no_snd_dev()),
+     * to get notified when it should open or close the sound device.
+     *
+     * @param operation	The value will be set to 0 to signal that sound
+     * 			device is about to be closed, and 1 to be opened.
+     *
+     * @return		The callback must return PJ_SUCCESS at the moment.
+     */
+    pj_status_t (*on_snd_dev_operation)(int operation);
+
+    /**
+     * Notification about media events such as video notifications. This
+     * callback will most likely be called from media threads, thus
+     * application must not perform heavy processing in this callback.
+     * Especially, application must not destroy the call or media in this
+     * callback. If application needs to perform more complex tasks to
+     * handle the event, it should post the task to another thread.
+     *
+     * @param call_id	The call id.
+     * @param med_idx	The media stream index.
+     * @param event 	The media event.
+     */
+    void (*on_call_media_event)(pjsua_call_id call_id,
+				unsigned med_idx,
+				pjmedia_event *event);
+
+    /**
+     * This callback can be used by application to implement custom media
+     * transport adapter for the call, or to replace the media transport
+     * with something completely new altogether.
+     *
+     * This callback is called when a new call is created. The library has
+     * created a media transport for the call, and it is provided as the
+     * \a base_tp argument of this callback. Upon returning, the callback
+     * must return an instance of media transport to be used by the call.
+     *
+     * @param call_id       Call ID
+     * @param media_idx     The media index in the SDP for which this media
+     *                      transport will be used.
+     * @param base_tp       The media transport which otherwise will be
+     *                      used by the call has this callback not been
+     *                      implemented.
+     * @param flags         Bitmask from pjsua_create_media_transport_flag.
+     *
+     * @return              The callback must return an instance of media
+     *                      transport to be used by the call.
+     */
+    pjmedia_transport* (*on_create_media_transport)(pjsua_call_id call_id,
+                                                    unsigned media_idx,
+                                                    pjmedia_transport *base_tp,
+                                                    unsigned flags);
+
+    /**
+     * This callback can be used by application to override the account
+     * to be used to handle an incoming message. Initially, the account to
+     * be used will be calculated automatically by the library. This initial
+     * account will be used if application does not implement this callback,
+     * or application sets an invalid account upon returning from this
+     * callback.
+     *
+     * Note that currently the incoming messages requiring account assignment
+     * are INVITE, MESSAGE, SUBSCRIBE, and unsolicited NOTIFY. This callback
+     * may be called before the callback of the SIP event itself, i.e:
+     * incoming call, pager, subscription, or unsolicited-event.
+     *
+     * @param rdata	The incoming message.
+     * @param acc_id 	On input, initial account ID calculated automatically
+     *			by the library. On output, the account ID prefered
+     *			by application to handle the incoming message.
+     */
+    void (*on_acc_find_for_incoming)(const pjsip_rx_data *rdata,
+				     pjsua_acc_id* acc_id);
+
+} pjsua_callback;
+
+
+/**
+ * This enumeration specifies the usage of SIP Session Timers extension.
+ */
+typedef enum pjsua_sip_timer_use
+{
+    /**
+     * When this flag is specified, Session Timers will not be used in any
+     * session, except it is explicitly required in the remote request.
+     */
+    PJSUA_SIP_TIMER_INACTIVE,
+
+    /**
+     * When this flag is specified, Session Timers will be used in all 
+     * sessions whenever remote supports and uses it.
+     */
+    PJSUA_SIP_TIMER_OPTIONAL,
+
+    /**
+     * When this flag is specified, Session Timers support will be 
+     * a requirement for the remote to be able to establish a session.
+     */
+    PJSUA_SIP_TIMER_REQUIRED,
+
+    /**
+     * When this flag is specified, Session Timers will always be used
+     * in all sessions, regardless whether remote supports/uses it or not.
+     */
+    PJSUA_SIP_TIMER_ALWAYS
+
+} pjsua_sip_timer_use;
+
+
+/**
+ * This constants controls the use of 100rel extension.
+ */
+typedef enum pjsua_100rel_use
+{
+    /**
+     * Not used. For UAC, support for 100rel will be indicated in Supported
+     * header so that peer can opt to use it if it wants to. As UAS, this
+     * option will NOT cause 100rel to be used even if UAC indicates that
+     * it supports this feature.
+     */
+    PJSUA_100REL_NOT_USED,
+
+    /**
+     * Mandatory. UAC will place 100rel in Require header, and UAS will
+     * reject incoming calls unless it has 100rel in Supported header.
+     */
+    PJSUA_100REL_MANDATORY,
+
+    /**
+     * Optional. Similar to PJSUA_100REL_NOT_USED, except that as UAS, this
+     * option will cause 100rel to be used if UAC indicates that it supports it.
+     */
+    PJSUA_100REL_OPTIONAL
+
+} pjsua_100rel_use;
+
+
+/**
+ * This structure describes the settings to control the API and
+ * user agent behavior, and can be specified when calling #pjsua_init().
+ * Before setting the values, application must call #pjsua_config_default()
+ * to initialize this structure with the default values.
+ */
+typedef struct pjsua_config
+{
+
+    /** 
+     * Maximum calls to support (default: 4). The value specified here
+     * must be smaller than the compile time maximum settings 
+     * PJSUA_MAX_CALLS, which by default is 32. To increase this 
+     * limit, the library must be recompiled with new PJSUA_MAX_CALLS
+     * value.
+     */
+    unsigned	    max_calls;
+
+    /** 
+     * Number of worker threads. Normally application will want to have at
+     * least one worker thread, unless when it wants to poll the library
+     * periodically, which in this case the worker thread can be set to
+     * zero.
+     */
+    unsigned	    thread_cnt;
+
+    /**
+     * Number of nameservers. If no name server is configured, the SIP SRV
+     * resolution would be disabled, and domain will be resolved with
+     * standard pj_gethostbyname() function.
+     */
+    unsigned	    nameserver_count;
+
+    /**
+     * Array of nameservers to be used by the SIP resolver subsystem.
+     * The order of the name server specifies the priority (first name
+     * server will be used first, unless it is not reachable).
+     */
+    pj_str_t	    nameserver[4];
+
+    /**
+     * Force loose-route to be used in all route/proxy URIs (outbound_proxy
+     * and account's proxy settings). When this setting is enabled, the
+     * library will check all the route/proxy URIs specified in the settings
+     * and append ";lr" parameter to the URI if the parameter is not present.
+     *
+     * Default: 1
+     */
+    pj_bool_t	    force_lr;
+
+    /**
+     * Number of outbound proxies in the \a outbound_proxy array.
+     */
+    unsigned	    outbound_proxy_cnt;
+
+    /** 
+     * Specify the URL of outbound proxies to visit for all outgoing requests.
+     * The outbound proxies will be used for all accounts, and it will
+     * be used to build the route set for outgoing requests. The final
+     * route set for outgoing requests will consists of the outbound proxies
+     * and the proxy configured in the account.
+     */
+    pj_str_t	    outbound_proxy[4];
+
+    /**
+     * Warning: deprecated, please use \a stun_srv field instead. To maintain
+     * backward compatibility, if \a stun_srv_cnt is zero then the value of
+     * this field will be copied to \a stun_srv field, if present.
+     *
+     * Specify domain name to be resolved with DNS SRV resolution to get the
+     * address of the STUN server. Alternatively application may specify
+     * \a stun_host instead.
+     *
+     * If DNS SRV resolution failed for this domain, then DNS A resolution
+     * will be performed only if \a stun_host is specified.
+     */
+    pj_str_t	    stun_domain;
+
+    /**
+     * Warning: deprecated, please use \a stun_srv field instead. To maintain
+     * backward compatibility, if \a stun_srv_cnt is zero then the value of
+     * this field will be copied to \a stun_srv field, if present.
+     *
+     * Specify STUN server to be used, in "HOST[:PORT]" format. If port is
+     * not specified, default port 3478 will be used.
+     */
+    pj_str_t	    stun_host;
+
+    /**
+     * Number of STUN server entries in \a stun_srv array.
+     */
+    unsigned	    stun_srv_cnt;
+
+    /**
+     * Array of STUN servers to try. The library will try to resolve and
+     * contact each of the STUN server entry until it finds one that is
+     * usable. Each entry may be a domain name, host name, IP address, and
+     * it may contain an optional port number. For example:
+     *	- "pjsip.org" (domain name)
+     *	- "sip.pjsip.org" (host name)
+     *	- "pjsip.org:33478" (domain name and a non-standard port number)
+     *	- "10.0.0.1:3478" (IP address and port number)
+     *
+     * When nameserver is configured in the \a pjsua_config.nameserver field,
+     * if entry is not an IP address, it will be resolved with DNS SRV 
+     * resolution first, and it will fallback to use DNS A resolution if this
+     * fails. Port number may be specified even if the entry is a domain name,
+     * in case the DNS SRV resolution should fallback to a non-standard port.
+     *
+     * When nameserver is not configured, entries will be resolved with
+     * #pj_gethostbyname() if it's not an IP address. Port number may be
+     * specified if the server is not listening in standard STUN port.
+     */
+    pj_str_t	    stun_srv[8];
+
+    /**
+     * This specifies if the library startup should ignore failure with the
+     * STUN servers. If this is set to PJ_FALSE, the library will refuse to
+     * start if it fails to resolve or contact any of the STUN servers.
+     *
+     * Default: PJ_TRUE
+     */
+    pj_bool_t	    stun_ignore_failure;
+
+    /**
+     * This specifies whether STUN requests for resolving socket mapped
+     * address should use the new format, i.e: having STUN magic cookie
+     * in its transaction ID.
+     *
+     * Default: PJ_FALSE
+     */
+    pj_bool_t	    stun_map_use_stun2;
+
+    /**
+     * Support for adding and parsing NAT type in the SDP to assist 
+     * troubleshooting. The valid values are:
+     *	- 0: no information will be added in SDP, and parsing is disabled.
+     *	- 1: only the NAT type number is added.
+     *	- 2: add both NAT type number and name.
+     *
+     * Default: 1
+     */
+    int		    nat_type_in_sdp;
+
+    /**
+     * Specify how the support for reliable provisional response (100rel/
+     * PRACK) should be used by default. Note that this setting can be
+     * further customized in account configuration (#pjsua_acc_config).
+     *
+     * Default: PJSUA_100REL_NOT_USED
+     */
+    pjsua_100rel_use require_100rel;
+
+    /**
+     * Specify the usage of Session Timers for all sessions. See the
+     * #pjsua_sip_timer_use for possible values. Note that this setting can be
+     * further customized in account configuration (#pjsua_acc_config).
+     *
+     * Default: PJSUA_SIP_TIMER_OPTIONAL
+     */
+    pjsua_sip_timer_use use_timer;
+
+    /**
+     * Handle unsolicited NOTIFY requests containing message waiting 
+     * indication (MWI) info. Unsolicited MWI is incoming NOTIFY requests 
+     * which are not requested by client with SUBSCRIBE request. 
+     *
+     * If this is enabled, the library will respond 200/OK to the NOTIFY
+     * request and forward the request to \a on_mwi_info() callback.
+     *
+     * See also \a mwi_enabled field #on pjsua_acc_config.
+     *
+     * Default: PJ_TRUE
+     *
+     */
+    pj_bool_t	    enable_unsolicited_mwi;
+
+    /**
+     * Specify Session Timer settings, see #pjsip_timer_setting. 
+     * Note that this setting can be further customized in account 
+     * configuration (#pjsua_acc_config).
+     */
+    pjsip_timer_setting timer_setting;
+
+    /** 
+     * Number of credentials in the credential array.
+     */
+    unsigned	    cred_count;
+
+    /** 
+     * Array of credentials. These credentials will be used by all accounts,
+     * and can be used to authenticate against outbound proxies. If the
+     * credential is specific to the account, then application should set
+     * the credential in the pjsua_acc_config rather than the credential
+     * here.
+     */
+    pjsip_cred_info cred_info[PJSUA_ACC_MAX_PROXIES];
+
+    /**
+     * Application callback to receive various event notifications from
+     * the library.
+     */
+    pjsua_callback  cb;
+
+    /**
+     * Optional user agent string (default empty). If it's empty, no
+     * User-Agent header will be sent with outgoing requests.
+     */
+    pj_str_t	    user_agent;
+
+    /**
+     * Specify default value of secure media transport usage. 
+     * Valid values are PJMEDIA_SRTP_DISABLED, PJMEDIA_SRTP_OPTIONAL, and
+     * PJMEDIA_SRTP_MANDATORY.
+     *
+     * Note that this setting can be further customized in account 
+     * configuration (#pjsua_acc_config).
+     *
+     * Default: #PJSUA_DEFAULT_USE_SRTP
+     */
+    pjmedia_srtp_use	use_srtp;
+
+    /**
+     * Specify whether SRTP requires secure signaling to be used. This option
+     * is only used when \a use_srtp option above is non-zero.
+     *
+     * Valid values are:
+     *	0: SRTP does not require secure signaling
+     *	1: SRTP requires secure transport such as TLS
+     *	2: SRTP requires secure end-to-end transport (SIPS)
+     *
+     * Note that this setting can be further customized in account 
+     * configuration (#pjsua_acc_config).
+     *
+     * Default: #PJSUA_DEFAULT_SRTP_SECURE_SIGNALING
+     */
+    int		     srtp_secure_signaling;
+
+    /**
+     * This setting has been deprecated and will be ignored.
+     */
+    pj_bool_t	     srtp_optional_dup_offer;
+
+    /**
+     * Disconnect other call legs when more than one 2xx responses for 
+     * outgoing INVITE are received due to forking. Currently the library
+     * is not able to handle simultaneous forked media, so disconnecting
+     * the other call legs is necessary. 
+     *
+     * With this setting enabled, the library will handle only one of the
+     * connected call leg, and the other connected call legs will be
+     * disconnected. 
+     *
+     * Default: PJ_TRUE (only disable this setting for testing purposes).
+     */
+    pj_bool_t	     hangup_forked_call;
+
+} pjsua_config;
+
+
+/**
+ * Flags to be given to pjsua_destroy2()
+ */
+typedef enum pjsua_destroy_flag
+{
+    /**
+     * Allow sending outgoing messages (such as unregistration, event
+     * unpublication, BYEs, unsubscription, etc.), but do not wait for
+     * responses. This is useful to perform "best effort" clean up
+     * without delaying the shutdown process waiting for responses.
+     */
+    PJSUA_DESTROY_NO_RX_MSG = 1,
+
+    /**
+     * If this flag is set, do not send any outgoing messages at all.
+     * This flag is useful if application knows that the network which
+     * the messages are to be sent on is currently down.
+     */
+    PJSUA_DESTROY_NO_TX_MSG = 2,
+
+    /**
+     * Do not send or receive messages during destroy. This flag is
+     * shorthand for  PJSUA_DESTROY_NO_RX_MSG + PJSUA_DESTROY_NO_TX_MSG.
+     */
+    PJSUA_DESTROY_NO_NETWORK = PJSUA_DESTROY_NO_RX_MSG |
+			       PJSUA_DESTROY_NO_TX_MSG
+
+} pjsua_destroy_flag;
+
+/**
+ * Use this function to initialize pjsua config.
+ *
+ * @param cfg	pjsua config to be initialized.
+ */
+PJ_DECL(void) pjsua_config_default(pjsua_config *cfg);
+
+
+/** The implementation has been moved to sip_auth.h */
+#define pjsip_cred_dup	pjsip_cred_info_dup
+
+
+/**
+ * Duplicate pjsua_config.
+ *
+ * @param pool	    The pool to get memory from.
+ * @param dst	    Destination config.
+ * @param src	    Source config.
+ */
+PJ_DECL(void) pjsua_config_dup(pj_pool_t *pool,
+			       pjsua_config *dst,
+			       const pjsua_config *src);
+
+
+/**
+ * This structure describes additional information to be sent with
+ * outgoing SIP message. It can (optionally) be specified for example
+ * with #pjsua_call_make_call(), #pjsua_call_answer(), #pjsua_call_hangup(),
+ * #pjsua_call_set_hold(), #pjsua_call_send_im(), and many more.
+ *
+ * Application MUST call #pjsua_msg_data_init() to initialize this
+ * structure before setting its values.
+ */
+struct pjsua_msg_data
+{
+    /**
+     * Optional remote target URI (i.e. Target header). If NULL, the target
+     * will be set to the remote URI (To header). At the moment this field
+     * is only used by #pjsua_call_make_call() and #pjsua_im_send().
+     */
+    pj_str_t    target_uri;
+
+    /**
+     * Additional message headers as linked list. Application can add
+     * headers to the list by creating the header, either from the heap/pool
+     * or from temporary local variable, and add the header using
+     * linked list operation. See pjsua_app.c for some sample codes.
+     */
+    pjsip_hdr	hdr_list;
+
+    /**
+     * MIME type of optional message body. 
+     */
+    pj_str_t	content_type;
+
+    /**
+     * Optional message body to be added to the message, only when the
+     * message doesn't have a body.
+     */
+    pj_str_t	msg_body;
+
+    /**
+     * Content type of the multipart body. If application wants to send
+     * multipart message bodies, it puts the parts in \a parts and set
+     * the content type in \a multipart_ctype. If the message already
+     * contains a body, the body will be added to the multipart bodies.
+     */
+    pjsip_media_type  multipart_ctype;
+
+    /**
+     * List of multipart parts. If application wants to send multipart
+     * message bodies, it puts the parts in \a parts and set the content
+     * type in \a multipart_ctype. If the message already contains a body,
+     * the body will be added to the multipart bodies.
+     */
+    pjsip_multipart_part multipart_parts;
+};
+
+
+/**
+ * Initialize message data.
+ *
+ * @param msg_data  Message data to be initialized.
+ */
+PJ_DECL(void) pjsua_msg_data_init(pjsua_msg_data *msg_data);
+
+
+/**
+ * Clone message data.
+ *
+ * @param pool	    Pool to allocate memory for the new message data.
+ * @param rhs       Message data to be cloned.
+ *
+ * @return          The new message data.
+ */
+PJ_DECL(pjsua_msg_data*) pjsua_msg_data_clone(pj_pool_t *pool,
+                                              const pjsua_msg_data *rhs);
+
+
+/**
+ * Instantiate pjsua application. Application must call this function before
+ * calling any other functions, to make sure that the underlying libraries
+ * are properly initialized. Once this function has returned success,
+ * application must call pjsua_destroy() before quitting.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_create(void);
+
+
+/** Forward declaration */
+typedef struct pjsua_media_config pjsua_media_config;
+
+
+/**
+ * Initialize pjsua with the specified settings. All the settings are 
+ * optional, and the default values will be used when the config is not
+ * specified.
+ *
+ * Note that #pjsua_create() MUST be called before calling this function.
+ *
+ * @param ua_cfg	User agent configuration.
+ * @param log_cfg	Optional logging configuration.
+ * @param media_cfg	Optional media configuration.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_init(const pjsua_config *ua_cfg,
+				const pjsua_logging_config *log_cfg,
+				const pjsua_media_config *media_cfg);
+
+
+/**
+ * Application is recommended to call this function after all initialization
+ * is done, so that the library can do additional checking set up
+ * additional 
+ *
+ * Application may call this function anytime after #pjsua_init().
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_start(void);
+
+
+/**
+ * Destroy pjsua. Application is recommended to perform graceful shutdown
+ * before calling this function (such as unregister the account from the SIP 
+ * server, terminate presense subscription, and hangup active calls), however,
+ * this function will do all of these if it finds there are active sessions
+ * that need to be terminated. This function will approximately block for
+ * one second to wait for replies from remote.
+ *
+ * Application.may safely call this function more than once if it doesn't
+ * keep track of it's state.
+ *
+ * @see pjsua_destroy2()
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_destroy(void);
+
+
+/**
+ * Retrieve pjsua state.
+ *
+ * @return 	pjsua state.
+ */
+PJ_DECL(pjsua_state) pjsua_get_state(void);
+
+
+/**
+ * Variant of destroy with additional flags.
+ *
+ * @param flags		Combination of pjsua_destroy_flag enumeration.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_destroy2(unsigned flags);
+
+
+/**
+ * Poll pjsua for events, and if necessary block the caller thread for
+ * the specified maximum interval (in miliseconds).
+ *
+ * Application doesn't normally need to call this function if it has
+ * configured worker thread (\a thread_cnt field) in pjsua_config structure,
+ * because polling then will be done by these worker threads instead.
+ *
+ * @param msec_timeout	Maximum time to wait, in miliseconds.
+ *
+ * @return  The number of events that have been handled during the
+ *	    poll. Negative value indicates error, and application
+ *	    can retrieve the error as (status = -return_value).
+ */
+PJ_DECL(int) pjsua_handle_events(unsigned msec_timeout);
+
+
+/**
+ * Create memory pool to be used by the application. Once application
+ * finished using the pool, it must be released with pj_pool_release().
+ *
+ * @param name		Optional pool name.
+ * @param init_size	Initial size of the pool.
+ * @param increment	Increment size.
+ *
+ * @return		The pool, or NULL when there's no memory.
+ */
+PJ_DECL(pj_pool_t*) pjsua_pool_create(const char *name, pj_size_t init_size,
+				      pj_size_t increment);
+
+
+/**
+ * Application can call this function at any time (after pjsua_create(), of
+ * course) to change logging settings.
+ *
+ * @param c		Logging configuration.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_reconfigure_logging(const pjsua_logging_config *c);
+
+
+/**
+ * Internal function to get SIP endpoint instance of pjsua, which is
+ * needed for example to register module, create transports, etc.
+ * Only valid after #pjsua_init() is called.
+ * 
+ * @return		SIP endpoint instance.
+ */
+PJ_DECL(pjsip_endpoint*) pjsua_get_pjsip_endpt(void);
+
+/**
+ * Internal function to get media endpoint instance.
+ * Only valid after #pjsua_init() is called.
+ *
+ * @return		Media endpoint instance.
+ */
+PJ_DECL(pjmedia_endpt*) pjsua_get_pjmedia_endpt(void);
+
+/**
+ * Internal function to get PJSUA pool factory.
+ * Only valid after #pjsua_create() is called.
+ *
+ * @return		Pool factory currently used by PJSUA.
+ */
+PJ_DECL(pj_pool_factory*) pjsua_get_pool_factory(void);
+
+
+
+/*****************************************************************************
+ * Utilities.
+ *
+ */
+
+/**
+ * This structure is used to represent the result of the STUN server 
+ * resolution and testing, the #pjsua_resolve_stun_servers() function.
+ * This structure will be passed in #pj_stun_resolve_cb callback.
+ */
+typedef struct pj_stun_resolve_result
+{
+    /**
+     * Arbitrary data that was passed to #pjsua_resolve_stun_servers()
+     * function.
+     */
+    void	    *token;
+
+    /**
+     * This will contain PJ_SUCCESS if at least one usable STUN server
+     * is found, otherwise it will contain the last error code during
+     * the operation.
+     */
+    pj_status_t	     status;
+
+    /**
+     * The server name that yields successful result. This will only
+     * contain value if status is successful.
+     */
+    pj_str_t	     name;
+
+    /**
+     * The server IP address. This will only contain value if status 
+     * is successful.
+     */
+    pj_sockaddr	     addr;
+
+} pj_stun_resolve_result;
+
+
+/**
+ * Typedef of callback to be registered to #pjsua_resolve_stun_servers().
+ */
+typedef void (*pj_stun_resolve_cb)(const pj_stun_resolve_result *result);
+
+/**
+ * This is a utility function to detect NAT type in front of this
+ * endpoint. Once invoked successfully, this function will complete 
+ * asynchronously and report the result in \a on_nat_detect() callback
+ * of pjsua_callback.
+ *
+ * After NAT has been detected and the callback is called, application can
+ * get the detected NAT type by calling #pjsua_get_nat_type(). Application
+ * can also perform NAT detection by calling #pjsua_detect_nat_type()
+ * again at later time.
+ *
+ * Note that STUN must be enabled to run this function successfully.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_detect_nat_type(void);
+
+
+/**
+ * Get the NAT type as detected by #pjsua_detect_nat_type() function.
+ * This function will only return useful NAT type after #pjsua_detect_nat_type()
+ * has completed successfully and \a on_nat_detect() callback has been called.
+ *
+ * @param type		NAT type.
+ *
+ * @return		When detection is in progress, this function will 
+ *			return PJ_EPENDING and \a type will be set to 
+ *			PJ_STUN_NAT_TYPE_UNKNOWN. After NAT type has been
+ *			detected successfully, this function will return
+ *			PJ_SUCCESS and \a type will be set to the correct
+ *			value. Other return values indicate error and
+ *			\a type will be set to PJ_STUN_NAT_TYPE_ERR_UNKNOWN.
+ *
+ * @see pjsua_call_get_rem_nat_type()
+ */
+PJ_DECL(pj_status_t) pjsua_get_nat_type(pj_stun_nat_type *type);
+
+
+/**
+ * Auxiliary function to resolve and contact each of the STUN server
+ * entries (sequentially) to find which is usable. The #pjsua_init() must
+ * have been called before calling this function.
+ *
+ * @param count		Number of STUN server entries to try.
+ * @param srv		Array of STUN server entries to try. Please see
+ *			the \a stun_srv field in the #pjsua_config 
+ *			documentation about the format of this entry.
+ * @param wait		Specify non-zero to make the function block until
+ *			it gets the result. In this case, the function
+ *			will block while the resolution is being done,
+ *			and the callback will be called before this function
+ *			returns.
+ * @param token		Arbitrary token to be passed back to application
+ *			in the callback.
+ * @param cb		Callback to be called to notify the result of
+ *			the function.
+ *
+ * @return		If \a wait parameter is non-zero, this will return
+ *			PJ_SUCCESS if one usable STUN server is found.
+ *			Otherwise it will always return PJ_SUCCESS, and
+ *			application will be notified about the result in
+ *			the callback.
+ */
+PJ_DECL(pj_status_t) pjsua_resolve_stun_servers(unsigned count,
+						pj_str_t srv[],
+						pj_bool_t wait,
+						void *token,
+						pj_stun_resolve_cb cb);
+
+/**
+ * Cancel pending STUN resolution which match the specified token. 
+ *
+ * @param token		The token to match. This token was given to 
+ *			#pjsua_resolve_stun_servers()
+ * @param notify_cb	Boolean to control whether the callback should
+ *			be called for cancelled resolutions. When the
+ *			callback is called, the status in the result
+ *			will be set as PJ_ECANCELLED.
+ *
+ * @return		PJ_SUCCESS if there is at least one pending STUN
+ *			resolution cancelled, or PJ_ENOTFOUND if there is
+ *			no matching one, or other error.
+ */
+PJ_DECL(pj_status_t) pjsua_cancel_stun_resolution(void *token,
+						  pj_bool_t notify_cb);
+
+
+/**
+ * This is a utility function to verify that valid SIP url is given. If the
+ * URL is a valid SIP/SIPS scheme, PJ_SUCCESS will be returned.
+ *
+ * @param url		The URL, as NULL terminated string.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ *
+ * @see pjsua_verify_url()
+ */
+PJ_DECL(pj_status_t) pjsua_verify_sip_url(const char *url);
+
+
+/**
+ * This is a utility function to verify that valid URI is given. Unlike
+ * pjsua_verify_sip_url(), this function will return PJ_SUCCESS if tel: URI
+ * is given.
+ *
+ * @param url		The URL, as NULL terminated string.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ *
+ * @see pjsua_verify_sip_url()
+ */
+PJ_DECL(pj_status_t) pjsua_verify_url(const char *url);
+
+
+/**
+ * Schedule a timer entry. Note that the timer callback may be executed
+ * by different thread, depending on whether worker thread is enabled or
+ * not.
+ *
+ * @param entry		Timer heap entry.
+ * @param delay         The interval to expire.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ *
+ * @see pjsip_endpt_schedule_timer()
+ */
+#if PJ_TIMER_DEBUG
+#define pjsua_schedule_timer(e,d) pjsua_schedule_timer_dbg(e,d,\
+                                                           __FILE__,__LINE__)
+
+PJ_DECL(pj_status_t) pjsua_schedule_timer_dbg(pj_timer_entry *entry,
+                                              const pj_time_val *delay,
+                                              const char *src_file,
+                                              int src_line);
+#else
+PJ_DECL(pj_status_t) pjsua_schedule_timer(pj_timer_entry *entry,
+					  const pj_time_val *delay);
+#endif
+
+/**
+ * Schedule a callback function to be called after a specified time interval.
+ * Note that the callback may be executed by different thread, depending on
+ * whether worker thread is enabled or not.
+ *
+ * @param cb		The callback function.
+ * @param user_data     The user data.
+ * @param msec_delay    The time interval in msec.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+#if PJ_TIMER_DEBUG
+#define pjsua_schedule_timer2(cb,u,d) \
+			pjsua_schedule_timer2_dbg(cb,u,d,__FILE__,__LINE__)
+
+PJ_DECL(pj_status_t) pjsua_schedule_timer2_dbg(void (*cb)(void *user_data),
+                                               void *user_data,
+                                               unsigned msec_delay,
+                                               const char *src_file,
+                                               int src_line);
+#else
+PJ_DECL(pj_status_t) pjsua_schedule_timer2(void (*cb)(void *user_data),
+                                           void *user_data,
+                                           unsigned msec_delay);
+#endif
+
+/**
+ * Cancel the previously scheduled timer.
+ *
+ * @param entry		Timer heap entry.
+ *
+ * @see pjsip_endpt_cancel_timer()
+ */
+PJ_DECL(void) pjsua_cancel_timer(pj_timer_entry *entry);
+
+
+/**
+ * This is a utility function to display error message for the specified 
+ * error code. The error message will be sent to the log.
+ *
+ * @param sender	The log sender field.
+ * @param title		Message title for the error.
+ * @param status	Status code.
+ */
+PJ_DECL(void) pjsua_perror(const char *sender, const char *title, 
+			   pj_status_t status);
+
+
+/**
+ * This is a utility function to dump the stack states to log, using
+ * verbosity level 3.
+ *
+ * @param detail	Will print detailed output (such as list of
+ *			SIP transactions) when non-zero.
+ */
+PJ_DECL(void) pjsua_dump(pj_bool_t detail);
+
+/**
+ * @}
+ */
+
+
+
+/*****************************************************************************
+ * TRANSPORT API
+ */
+
+/**
+ * @defgroup PJSUA_LIB_TRANSPORT PJSUA-API Signaling Transport
+ * @ingroup PJSUA_LIB
+ * @brief API for managing SIP transports
+ * @{
+ *
+ * PJSUA-API supports creating multiple transport instances, for example UDP,
+ * TCP, and TLS transport. SIP transport must be created before adding an 
+ * account.
+ */
+
+
+/** SIP transport identification.
+ */
+typedef int pjsua_transport_id;
+
+
+/**
+ * Transport configuration for creating transports for both SIP
+ * and media. Before setting some values to this structure, application
+ * MUST call #pjsua_transport_config_default() to initialize its
+ * values with default settings.
+ */
+typedef struct pjsua_transport_config
+{
+    /**
+     * UDP port number to bind locally. This setting MUST be specified
+     * even when default port is desired. If the value is zero, the
+     * transport will be bound to any available port, and application
+     * can query the port by querying the transport info.
+     */
+    unsigned		port;
+
+    /**
+     * Specify the port range for socket binding, relative to the start
+     * port number specified in \a port. Note that this setting is only
+     * applicable when the start port number is non zero.
+     *
+     * Default value is zero.
+     */
+    unsigned		port_range;
+
+    /**
+     * Optional address to advertise as the address of this transport.
+     * Application can specify any address or hostname for this field,
+     * for example it can point to one of the interface address in the
+     * system, or it can point to the public address of a NAT router
+     * where port mappings have been configured for the application.
+     *
+     * Note: this option can be used for both UDP and TCP as well!
+     */
+    pj_str_t		public_addr;
+
+    /**
+     * Optional address where the socket should be bound to. This option
+     * SHOULD only be used to selectively bind the socket to particular
+     * interface (instead of 0.0.0.0), and SHOULD NOT be used to set the
+     * published address of a transport (the public_addr field should be
+     * used for that purpose).
+     *
+     * Note that unlike public_addr field, the address (or hostname) here 
+     * MUST correspond to the actual interface address in the host, since
+     * this address will be specified as bind() argument.
+     */
+    pj_str_t		bound_addr;
+
+    /**
+     * This specifies TLS settings for TLS transport. It is only be used
+     * when this transport config is being used to create a SIP TLS
+     * transport.
+     */
+    pjsip_tls_setting	tls_setting;
+
+    /**
+     * QoS traffic type to be set on this transport. When application wants
+     * to apply QoS tagging to the transport, it's preferable to set this
+     * field rather than \a qos_param fields since this is more portable.
+     *
+     * Default is QoS not set.
+     */
+    pj_qos_type		qos_type;
+
+    /**
+     * Set the low level QoS parameters to the transport. This is a lower
+     * level operation than setting the \a qos_type field and may not be
+     * supported on all platforms.
+     *
+     * Default is QoS not set.
+     */
+    pj_qos_params	qos_params;
+
+} pjsua_transport_config;
+
+
+/**
+ * Call this function to initialize UDP config with default values.
+ *
+ * @param cfg	    The UDP config to be initialized.
+ */
+PJ_DECL(void) pjsua_transport_config_default(pjsua_transport_config *cfg);
+
+
+/**
+ * Duplicate transport config.
+ *
+ * @param pool		The pool.
+ * @param dst		The destination config.
+ * @param src		The source config.
+ */
+PJ_DECL(void) pjsua_transport_config_dup(pj_pool_t *pool,
+					 pjsua_transport_config *dst,
+					 const pjsua_transport_config *src);
+
+
+/**
+ * This structure describes transport information returned by
+ * #pjsua_transport_get_info() function.
+ */
+typedef struct pjsua_transport_info
+{
+    /**
+     * PJSUA transport identification.
+     */
+    pjsua_transport_id	    id;
+
+    /**
+     * Transport type.
+     */
+    pjsip_transport_type_e  type;
+
+    /**
+     * Transport type name.
+     */
+    pj_str_t		    type_name;
+
+    /**
+     * Transport string info/description.
+     */
+    pj_str_t		    info;
+
+    /**
+     * Transport flag (see ##pjsip_transport_flags_e).
+     */
+    unsigned		    flag;
+
+    /**
+     * Local address length.
+     */
+    unsigned		    addr_len;
+
+    /**
+     * Local/bound address.
+     */
+    pj_sockaddr		    local_addr;
+
+    /**
+     * Published address (or transport address name).
+     */
+    pjsip_host_port	    local_name;
+
+    /**
+     * Current number of objects currently referencing this transport.
+     */
+    unsigned		    usage_count;
+
+
+} pjsua_transport_info;
+
+
+/**
+ * Create and start a new SIP transport according to the specified
+ * settings.
+ *
+ * @param type		Transport type.
+ * @param cfg		Transport configuration.
+ * @param p_id		Optional pointer to receive transport ID.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_transport_create(pjsip_transport_type_e type,
+					    const pjsua_transport_config *cfg,
+					    pjsua_transport_id *p_id);
+
+/**
+ * Register transport that has been created by application. This function
+ * is useful if application wants to implement custom SIP transport and use
+ * it with pjsua.
+ *
+ * @param tp		Transport instance.
+ * @param p_id		Optional pointer to receive transport ID.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_transport_register(pjsip_transport *tp,
+					      pjsua_transport_id *p_id);
+
+
+/**
+ * Enumerate all transports currently created in the system. This function
+ * will return all transport IDs, and application may then call 
+ * #pjsua_transport_get_info() function to retrieve detailed information
+ * about the transport.
+ *
+ * @param id		Array to receive transport ids.
+ * @param count		In input, specifies the maximum number of elements.
+ *			On return, it contains the actual number of elements.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_enum_transports( pjsua_transport_id id[],
+					    unsigned *count );
+
+
+/**
+ * Get information about transports.
+ *
+ * @param id		Transport ID.
+ * @param info		Pointer to receive transport info.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_transport_get_info(pjsua_transport_id id,
+					      pjsua_transport_info *info);
+
+
+/**
+ * Disable a transport or re-enable it. By default transport is always 
+ * enabled after it is created. Disabling a transport does not necessarily
+ * close the socket, it will only discard incoming messages and prevent
+ * the transport from being used to send outgoing messages.
+ *
+ * @param id		Transport ID.
+ * @param enabled	Non-zero to enable, zero to disable.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_transport_set_enable(pjsua_transport_id id,
+						pj_bool_t enabled);
+
+
+/**
+ * Close the transport. If transport is forcefully closed, it will be
+ * immediately closed, and any pending transactions that are using the
+ * transport may not terminate properly (it may even crash). Otherwise, 
+ * the system will wait until all transactions are closed while preventing 
+ * new users from using the transport, and will close the transport when 
+ * it is safe to do so.
+ *
+ * @param id		Transport ID.
+ * @param force		Non-zero to immediately close the transport. This
+ *			is not recommended!
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_transport_close( pjsua_transport_id id,
+					    pj_bool_t force );
+
+/**
+ * @}
+ */
+
+
+
+
+/*****************************************************************************
+ * ACCOUNT API
+ */
+
+
+/**
+ * @defgroup PJSUA_LIB_ACC PJSUA-API Accounts Management
+ * @ingroup PJSUA_LIB
+ * @brief PJSUA Accounts management
+ * @{
+ *
+ * PJSUA accounts provide identity (or identities) of the user who is currently
+ * using the application. In SIP terms, the identity is used as the <b>From</b>
+ * header in outgoing requests.
+ *
+ * PJSUA-API supports creating and managing multiple accounts. The maximum
+ * number of accounts is limited by a compile time constant
+ * <tt>PJSUA_MAX_ACC</tt>.
+ *
+ * Account may or may not have client registration associated with it.
+ * An account is also associated with <b>route set</b> and some <b>authentication
+ * credentials</b>, which are used when sending SIP request messages using the
+ * account. An account also has presence's <b>online status</b>, which
+ * will be reported to remote peer when they subscribe to the account's
+ * presence, or which is published to a presence server if presence 
+ * publication is enabled for the account.
+ *
+ * At least one account MUST be created in the application. If no user
+ * association is required, application can create a userless account by
+ * calling #pjsua_acc_add_local(). A userless account identifies local endpoint
+ * instead of a particular user, and it correspond with a particular
+ * transport instance.
+ *
+ * Also one account must be set as the <b>default account</b>, which is used as
+ * the account to use when PJSUA fails to match a request with any other
+ * accounts.
+ *
+ * When sending outgoing SIP requests (such as making calls or sending
+ * instant messages), normally PJSUA requires the application to specify
+ * which account to use for the request. If no account is specified,
+ * PJSUA may be able to select the account by matching the destination
+ * domain name, and fall back to default account when no match is found.
+ */
+
+/**
+ * Maximum accounts.
+ */
+#ifndef PJSUA_MAX_ACC
+#   define PJSUA_MAX_ACC	    8
+#endif
+
+
+/**
+ * Default registration interval.
+ */
+#ifndef PJSUA_REG_INTERVAL
+#   define PJSUA_REG_INTERVAL	    300
+#endif
+
+
+/**
+ * Default maximum time to wait for account unregistration transactions to
+ * complete during library shutdown sequence.
+ *
+ * Default: 4000 (4 seconds)
+ */
+#ifndef PJSUA_UNREG_TIMEOUT
+#   define PJSUA_UNREG_TIMEOUT	    4000
+#endif
+
+
+/**
+ * Default PUBLISH expiration
+ */
+#ifndef PJSUA_PUBLISH_EXPIRATION
+#   define PJSUA_PUBLISH_EXPIRATION PJSIP_PUBC_EXPIRATION_NOT_SPECIFIED
+#endif
+
+
+/**
+ * Default account priority.
+ */
+#ifndef PJSUA_DEFAULT_ACC_PRIORITY
+#   define PJSUA_DEFAULT_ACC_PRIORITY	0
+#endif
+
+
+/**
+ * Maximum time to wait for unpublication transaction(s) to complete
+ * during shutdown process, before sending unregistration. The library
+ * tries to wait for the unpublication (un-PUBLISH) to complete before
+ * sending REGISTER request to unregister the account, during library
+ * shutdown process. If the value is set too short, it is possible that
+ * the unregistration is sent before unpublication completes, causing
+ * unpublication request to fail.
+ *
+ * Default: 2000 (2 seconds)
+ */
+#ifndef PJSUA_UNPUBLISH_MAX_WAIT_TIME_MSEC
+#   define PJSUA_UNPUBLISH_MAX_WAIT_TIME_MSEC	2000
+#endif
+
+
+/**
+ * Default auto retry re-registration interval, in seconds. Set to 0
+ * to disable this. Application can set the timer on per account basis 
+ * by setting the pjsua_acc_config.reg_retry_interval field instead.
+ *
+ * Default: 300 (5 minutes)
+ */
+#ifndef PJSUA_REG_RETRY_INTERVAL
+#   define PJSUA_REG_RETRY_INTERVAL	300
+#endif
+
+
+/**
+ * This macro specifies the default value for \a contact_rewrite_method
+ * field in pjsua_acc_config. It specifies how Contact update will be
+ * done with the registration, if \a allow_contact_rewrite is enabled in
+ * the account config. See \a pjsua_contact_rewrite_method for the options.
+ *
+ * Value PJSUA_CONTACT_REWRITE_UNREGISTER(1) is the legacy behavior.
+ *
+ * Default value: PJSUA_CONTACT_REWRITE_NO_UNREG(2) |
+ *                PJSUA_CONTACT_REWRITE_ALWAYS_UPDATE(4)
+ */
+#ifndef PJSUA_CONTACT_REWRITE_METHOD
+#   define PJSUA_CONTACT_REWRITE_METHOD	   (PJSUA_CONTACT_REWRITE_NO_UNREG | \
+                                           PJSUA_CONTACT_REWRITE_ALWAYS_UPDATE)
+#endif
+
+
+/**
+ * Bit value used in pjsua_acc_config.reg_use_proxy field to indicate that
+ * the global outbound proxy list should be added to the REGISTER request.
+ */
+#define PJSUA_REG_USE_OUTBOUND_PROXY		1
+
+
+/**
+ * Bit value used in pjsua_acc_config.reg_use_proxy field to indicate that
+ * the account proxy list should be added to the REGISTER request.
+ */
+#define PJSUA_REG_USE_ACC_PROXY			2
+
+
+/**
+ * This enumeration specifies how we should offer call hold request to
+ * remote peer. The default value is set by compile time constant
+ * PJSUA_CALL_HOLD_TYPE_DEFAULT, and application may control the setting
+ * on per-account basis by manipulating \a call_hold_type field in
+ * #pjsua_acc_config.
+ */
+typedef enum pjsua_call_hold_type
+{
+    /**
+     * This will follow RFC 3264 recommendation to use a=sendonly,
+     * a=recvonly, and a=inactive attribute as means to signal call
+     * hold status. This is the correct value to use.
+     */
+    PJSUA_CALL_HOLD_TYPE_RFC3264,
+
+    /**
+     * This will use the old and deprecated method as specified in RFC 2543,
+     * and will offer c=0.0.0.0 in the SDP instead. Using this has many
+     * drawbacks such as inability to keep the media transport alive while
+     * the call is being put on hold, and should only be used if remote
+     * does not understand RFC 3264 style call hold offer.
+     */
+    PJSUA_CALL_HOLD_TYPE_RFC2543
+
+} pjsua_call_hold_type;
+
+
+/**
+ * Specify the default call hold type to be used in #pjsua_acc_config.
+ *
+ * Default is PJSUA_CALL_HOLD_TYPE_RFC3264, and there's no reason to change
+ * this except if you're communicating with an old/non-standard peer.
+ */
+#ifndef PJSUA_CALL_HOLD_TYPE_DEFAULT
+#   define PJSUA_CALL_HOLD_TYPE_DEFAULT		PJSUA_CALL_HOLD_TYPE_RFC3264
+#endif
+
+/**
+ * This enumeration controls the use of STUN in the account.
+ */
+typedef enum pjsua_stun_use
+{
+    /**
+     * Follow the default setting in the global \a pjsua_config.
+     */
+    PJSUA_STUN_USE_DEFAULT,
+
+    /**
+     * Disable STUN. If STUN is not enabled in the global \a pjsua_config,
+     * this setting has no effect.
+     */
+    PJSUA_STUN_USE_DISABLED
+
+} pjsua_stun_use;
+
+/**
+ * This enumeration controls the use of ICE settings in the account.
+ */
+typedef enum pjsua_ice_config_use
+{
+    /**
+     * Use the default settings in the global \a pjsua_media_config.
+     */
+    PJSUA_ICE_CONFIG_USE_DEFAULT,
+
+    /**
+     * Use the custom \a pjsua_ice_config setting in the account.
+     */
+    PJSUA_ICE_CONFIG_USE_CUSTOM
+
+} pjsua_ice_config_use;
+
+/**
+ * This enumeration controls the use of TURN settings in the account.
+ */
+typedef enum pjsua_turn_config_use
+{
+    /**
+     * Use the default setting in the global \a pjsua_media_config.
+     */
+    PJSUA_TURN_CONFIG_USE_DEFAULT,
+
+    /**
+     * Use the custom \a pjsua_turn_config setting in the account.
+     */
+    PJSUA_TURN_CONFIG_USE_CUSTOM
+
+} pjsua_turn_config_use;
+
+/**
+ * ICE setting. This setting is used in the pjsua_acc_config.
+ */
+typedef struct pjsua_ice_config
+{
+    /**
+     * Enable ICE.
+     */
+    pj_bool_t		enable_ice;
+
+    /**
+     * Set the maximum number of host candidates.
+     *
+     * Default: -1 (maximum not set)
+     */
+    int			ice_max_host_cands;
+
+    /**
+     * ICE session options.
+     */
+    pj_ice_sess_options	ice_opt;
+
+    /**
+     * Disable RTCP component.
+     *
+     * Default: no
+     */
+    pj_bool_t		ice_no_rtcp;
+
+    /**
+     * Send re-INVITE/UPDATE every after ICE connectivity check regardless
+     * the default ICE transport address is changed or not. When this is set
+     * to PJ_FALSE, re-INVITE/UPDATE will be sent only when the default ICE
+     * transport address is changed.
+     *
+     * Default: yes
+     */
+    pj_bool_t		ice_always_update;
+
+} pjsua_ice_config;
+
+/**
+ * TURN setting. This setting is used in the pjsua_acc_config.
+ */
+typedef struct pjsua_turn_config
+{
+    /**
+     * Enable TURN candidate in ICE.
+     */
+    pj_bool_t		enable_turn;
+
+    /**
+     * Specify TURN domain name or host name, in in "DOMAIN:PORT" or
+     * "HOST:PORT" format.
+     */
+    pj_str_t		turn_server;
+
+    /**
+     * Specify the connection type to be used to the TURN server. Valid
+     * values are PJ_TURN_TP_UDP or PJ_TURN_TP_TCP.
+     *
+     * Default: PJ_TURN_TP_UDP
+     */
+    pj_turn_tp_type	turn_conn_type;
+
+    /**
+     * Specify the credential to authenticate with the TURN server.
+     */
+    pj_stun_auth_cred	turn_auth_cred;
+
+} pjsua_turn_config;
+
+/**
+ * Specify how IPv6 transport should be used in account config.
+ */
+typedef enum pjsua_ipv6_use
+{
+    /**
+     * IPv6 is not used.
+     */
+    PJSUA_IPV6_DISABLED,
+
+    /**
+     * IPv6 is enabled.
+     */
+    PJSUA_IPV6_ENABLED
+
+} pjsua_ipv6_use;
+
+/**
+ * This structure describes account configuration to be specified when
+ * adding a new account with #pjsua_acc_add(). Application MUST initialize
+ * this structure first by calling #pjsua_acc_config_default().
+ */
+typedef struct pjsua_acc_config
+{
+    /**
+     * Arbitrary user data to be associated with the newly created account.
+     * Application may set this later with #pjsua_acc_set_user_data() and
+     * retrieve it with #pjsua_acc_get_user_data().
+     */
+    void	   *user_data;
+
+    /**
+     * Account priority, which is used to control the order of matching
+     * incoming/outgoing requests. The higher the number means the higher
+     * the priority is, and the account will be matched first.
+     */
+    int		    priority;
+
+    /** 
+     * The full SIP URL for the account. The value can take name address or 
+     * URL format, and will look something like "sip:account@serviceprovider"
+     * or "\"Display Name\" <sip:account@provider>".
+     *
+     * This field is mandatory.
+     */
+    pj_str_t	    id;
+
+    /** 
+     * This is the URL to be put in the request URI for the registration,
+     * and will look something like "sip:serviceprovider".
+     *
+     * This field should be specified if registration is desired. If the
+     * value is empty, no account registration will be performed.
+     */
+    pj_str_t	    reg_uri;
+
+    /** 
+     * The optional custom SIP headers to be put in the registration
+     * request.
+     */
+    pjsip_hdr	    reg_hdr_list;
+
+    /** 
+     * The optional custom SIP headers to be put in the presence
+     * subscription request.
+     */
+    pjsip_hdr	    sub_hdr_list;
+
+    /**
+     * Subscribe to message waiting indication events (RFC 3842).
+     *
+     * See also \a enable_unsolicited_mwi field on #pjsua_config.
+     *
+     * Default: no
+     */
+    pj_bool_t	    mwi_enabled;
+
+    /**
+     * Specify the default expiration time for Message Waiting Indication
+     * (RFC 3842) event subscription. This must not be zero.
+     *
+     * Default: PJSIP_MWI_DEFAULT_EXPIRES
+     */
+    unsigned	    mwi_expires;
+
+    /**
+     * If this flag is set, the presence information of this account will
+     * be PUBLISH-ed to the server where the account belongs.
+     *
+     * Default: PJ_FALSE
+     */
+    pj_bool_t	    publish_enabled;
+
+    /**
+     * Event publication options.
+     */
+    pjsip_publishc_opt	publish_opt;
+
+    /**
+     * Maximum time to wait for unpublication transaction(s) to complete
+     * during shutdown process, before sending unregistration. The library
+     * tries to wait for the unpublication (un-PUBLISH) to complete before
+     * sending REGISTER request to unregister the account, during library
+     * shutdown process. If the value is set too short, it is possible that
+     * the unregistration is sent before unpublication completes, causing
+     * unpublication request to fail.
+     *
+     * Default: PJSUA_UNPUBLISH_MAX_WAIT_TIME_MSEC
+     */
+    unsigned	    unpublish_max_wait_time_msec;
+
+    /**
+     * Authentication preference.
+     */
+    pjsip_auth_clt_pref auth_pref;
+
+    /**
+     * Optional PIDF tuple ID for outgoing PUBLISH and NOTIFY. If this value
+     * is not specified, a random string will be used.
+     */
+    pj_str_t	    pidf_tuple_id;
+
+    /** 
+     * Optional URI to be put as Contact for this account. It is recommended
+     * that this field is left empty, so that the value will be calculated
+     * automatically based on the transport address.
+     */
+    pj_str_t	    force_contact;
+
+    /**
+     * Additional parameters that will be appended in the Contact header
+     * for this account. This will affect the Contact header in all SIP 
+     * messages sent on behalf of this account, including but not limited to
+     * REGISTER, INVITE, and SUBCRIBE requests or responses.
+     *
+     * The parameters should be preceeded by semicolon, and all strings must
+     * be properly escaped. Example:
+     *	 ";my-param=X;another-param=Hi%20there"
+     */
+    pj_str_t	    contact_params;
+
+    /**
+     * Additional URI parameters that will be appended in the Contact URI
+     * for this account. This will affect the Contact URI in all SIP
+     * messages sent on behalf of this account, including but not limited to
+     * REGISTER, INVITE, and SUBCRIBE requests or responses.
+     *
+     * The parameters should be preceeded by semicolon, and all strings must
+     * be properly escaped. Example:
+     *	 ";my-param=X;another-param=Hi%20there"
+     */
+    pj_str_t	    contact_uri_params;
+
+    /**
+     * Specify how support for reliable provisional response (100rel/
+     * PRACK) should be used for all sessions in this account. See the
+     * documentation of pjsua_100rel_use enumeration for more info.
+     *
+     * Default: The default value is taken from the value of
+     *          require_100rel in pjsua_config.
+     */
+    pjsua_100rel_use require_100rel;
+
+    /**
+     * Specify the usage of Session Timers for all sessions. See the
+     * #pjsua_sip_timer_use for possible values.
+     *
+     * Default: PJSUA_SIP_TIMER_OPTIONAL
+     */
+    pjsua_sip_timer_use use_timer;
+
+    /**
+     * Specify Session Timer settings, see #pjsip_timer_setting. 
+     */
+    pjsip_timer_setting timer_setting;
+
+    /**
+     * Number of proxies in the proxy array below.
+     */
+    unsigned	    proxy_cnt;
+
+    /** 
+     * Optional URI of the proxies to be visited for all outgoing requests 
+     * that are using this account (REGISTER, INVITE, etc). Application need 
+     * to specify these proxies if the service provider requires that requests
+     * destined towards its network should go through certain proxies first
+     * (for example, border controllers).
+     *
+     * These proxies will be put in the route set for this account, with 
+     * maintaining the orders (the first proxy in the array will be visited
+     * first). If global outbound proxies are configured in pjsua_config,
+     * then these account proxies will be placed after the global outbound
+     * proxies in the routeset.
+     */
+    pj_str_t	    proxy[PJSUA_ACC_MAX_PROXIES];
+
+    /**
+     * If remote sends SDP answer containing more than one format or codec in
+     * the media line, send re-INVITE or UPDATE with just one codec to lock
+     * which codec to use.
+     *
+     * Default: 1 (Yes). Set to zero to disable.
+     */
+    unsigned	    lock_codec;
+
+    /** 
+     * Optional interval for registration, in seconds. If the value is zero, 
+     * default interval will be used (PJSUA_REG_INTERVAL, 300 seconds).
+     */
+    unsigned	    reg_timeout;
+
+    /**
+     * Specify the number of seconds to refresh the client registration
+     * before the registration expires.
+     *
+     * Default: PJSIP_REGISTER_CLIENT_DELAY_BEFORE_REFRESH, 5 seconds
+     */
+    unsigned	    reg_delay_before_refresh;
+
+    /**
+     * Specify the maximum time to wait for unregistration requests to
+     * complete during library shutdown sequence.
+     *
+     * Default: PJSUA_UNREG_TIMEOUT
+     */
+    unsigned	    unreg_timeout;
+
+    /** 
+     * Number of credentials in the credential array.
+     */
+    unsigned	    cred_count;
+
+    /** 
+     * Array of credentials. If registration is desired, normally there should
+     * be at least one credential specified, to successfully authenticate
+     * against the service provider. More credentials can be specified, for
+     * example when the requests are expected to be challenged by the
+     * proxies in the route set.
+     */
+    pjsip_cred_info cred_info[PJSUA_ACC_MAX_PROXIES];
+
+    /**
+     * Optionally bind this account to specific transport. This normally is
+     * not a good idea, as account should be able to send requests using
+     * any available transports according to the destination. But some
+     * application may want to have explicit control over the transport to
+     * use, so in that case it can set this field.
+     *
+     * Default: -1 (PJSUA_INVALID_ID)
+     *
+     * @see pjsua_acc_set_transport()
+     */
+    pjsua_transport_id  transport_id;
+
+    /**
+     * This option is used to update the transport address and the Contact
+     * header of REGISTER request. When this option is  enabled, the library 
+     * will keep track of the public IP address from the response of REGISTER
+     * request. Once it detects that the address has changed, it will 
+     * unregister current Contact, update the Contact with transport address
+     * learned from Via header, and register a new Contact to the registrar.
+     * This will also update the public name of UDP transport if STUN is
+     * configured. 
+     *
+     * See also contact_rewrite_method field.
+     *
+     * Default: 1 (yes)
+     */
+    pj_bool_t allow_contact_rewrite;
+
+    /**
+     * Specify how Contact update will be done with the registration, if
+     * \a allow_contact_rewrite is enabled. The value is bitmask combination of
+     * \a pjsua_contact_rewrite_method. See also pjsua_contact_rewrite_method.
+     *
+     * Value PJSUA_CONTACT_REWRITE_UNREGISTER(1) is the legacy behavior.
+     *
+     * Default value: PJSUA_CONTACT_REWRITE_METHOD
+     * (PJSUA_CONTACT_REWRITE_NO_UNREG | PJSUA_CONTACT_REWRITE_ALWAYS_UPDATE)
+     */
+    int		     contact_rewrite_method;
+
+    /**
+     * This option is used to overwrite the "sent-by" field of the Via header
+     * for outgoing messages with the same interface address as the one in
+     * the REGISTER request, as long as the request uses the same transport
+     * instance as the previous REGISTER request.
+     *
+     * Default: 1 (yes)
+     */
+    pj_bool_t        allow_via_rewrite;
+
+    /**
+     * This option controls whether the IP address in SDP should be replaced
+     * with the IP address found in Via header of the REGISTER response, ONLY
+     * when STUN and ICE are not used. If the value is FALSE (the original
+     * behavior), then the local IP address will be used. If TRUE, and when
+     * STUN and ICE are disabled, then the IP address found in registration
+     * response will be used.
+     *
+     * Default: PJ_FALSE (no)
+     */
+    pj_bool_t        allow_sdp_nat_rewrite;
+
+    /**
+     * Control the use of SIP outbound feature. SIP outbound is described in
+     * RFC 5626 to enable proxies or registrar to send inbound requests back
+     * to UA using the same connection initiated by the UA for its
+     * registration. This feature is highly useful in NAT-ed deployemtns,
+     * hence it is enabled by default.
+     *
+     * Note: currently SIP outbound can only be used with TCP and TLS
+     * transports. If UDP is used for the registration, the SIP outbound
+     * feature will be silently ignored for the account.
+     *
+     * Default: PJ_TRUE
+     */
+    unsigned	     use_rfc5626;
+
+    /**
+     * Specify SIP outbound (RFC 5626) instance ID to be used by this
+     * application. If empty, an instance ID will be generated based on
+     * the hostname of this agent. If application specifies this parameter, the
+     * value will look like "<urn:uuid:00000000-0000-1000-8000-AABBCCDDEEFF>"
+     * without the doublequote.
+     *
+     * Default: empty
+     */
+    pj_str_t	     rfc5626_instance_id;
+
+    /**
+     * Specify SIP outbound (RFC 5626) registration ID. The default value
+     * is empty, which would cause the library to automatically generate
+     * a suitable value.
+     *
+     * Default: empty
+     */
+    pj_str_t	     rfc5626_reg_id;
+
+    /**
+     * Set the interval for periodic keep-alive transmission for this account.
+     * If this value is zero, keep-alive will be disabled for this account.
+     * The keep-alive transmission will be sent to the registrar's address,
+     * after successful registration.
+     *
+     * Default: 15 (seconds)
+     */
+    unsigned	     ka_interval;
+
+    /**
+     * Specify the data to be transmitted as keep-alive packets.
+     *
+     * Default: CR-LF
+     */
+    pj_str_t	     ka_data;
+
+    /**
+     * Specify whether incoming video should be shown to screen by default.
+     * This applies to incoming call (INVITE), incoming re-INVITE, and
+     * incoming UPDATE requests.
+     *
+     * Regardless of this setting, application can detect incoming video
+     * by implementing \a on_call_media_state() callback and enumerating
+     * the media stream(s) with #pjsua_call_get_info(). Once incoming
+     * video is recognised, application may retrieve the window associated
+     * with the incoming video and show or hide it with
+     * #pjsua_vid_win_set_show().
+     *
+     * Default: PJ_FALSE
+     */
+    pj_bool_t        vid_in_auto_show;
+
+    /**
+     * Specify whether outgoing video should be activated by default when
+     * making outgoing calls and/or when incoming video is detected. This
+     * applies to incoming and outgoing calls, incoming re-INVITE, and
+     * incoming UPDATE. If the setting is non-zero, outgoing video
+     * transmission will be started as soon as response to these requests
+     * is sent (or received).
+     *
+     * Regardless of the value of this setting, application can start and
+     * stop outgoing video transmission with #pjsua_call_set_vid_strm().
+     *
+     * Default: PJ_FALSE
+     */
+    pj_bool_t        vid_out_auto_transmit;
+
+    /**
+     * Specify video window's flags. The value is a bitmask combination of
+     * #pjmedia_vid_dev_wnd_flag.
+     *
+     * Default: 0
+     */
+    unsigned         vid_wnd_flags;
+
+    /**
+     * Specify the default capture device to be used by this account. If
+     * \a vid_out_auto_transmit is enabled, this device will be used for
+     * capturing video.
+     *
+     * Default: PJMEDIA_VID_DEFAULT_CAPTURE_DEV
+     */
+    pjmedia_vid_dev_index vid_cap_dev;
+
+    /**
+     * Specify the default rendering device to be used by this account.
+     *
+     * Default: PJMEDIA_VID_DEFAULT_RENDER_DEV
+     */
+    pjmedia_vid_dev_index vid_rend_dev;
+
+    /**
+     * Specify the send rate control for video stream.
+     *
+     * Default: see #pjmedia_vid_stream_rc_config
+     */
+    pjmedia_vid_stream_rc_config vid_stream_rc_cfg;
+
+    /**
+     * Media transport config.
+     */
+    pjsua_transport_config rtp_cfg;
+
+    /**
+     * Specify whether IPv6 should be used on media.
+     */
+    pjsua_ipv6_use     		ipv6_media_use;
+
+    /**
+     * Control the use of STUN for the SIP signaling.
+     *
+     * Default: PJSUA_STUN_USE_DEFAULT
+     */
+    pjsua_stun_use 		sip_stun_use;
+
+    /**
+     * Control the use of STUN for the media transports.
+     *
+     * Default: PJSUA_STUN_USE_DEFAULT
+     */
+    pjsua_stun_use 		media_stun_use;
+
+    /**
+     * Control the use of ICE in the account. By default, the settings in the
+     * \a pjsua_media_config will be used.
+     *
+     * Default: PJSUA_ICE_CONFIG_USE_DEFAULT
+     */
+    pjsua_ice_config_use	ice_cfg_use;
+
+    /**
+     * The custom ICE setting for this account. This setting will only be
+     * used if \a ice_cfg_use is set to PJSUA_ICE_CONFIG_USE_CUSTOM
+     */
+    pjsua_ice_config		ice_cfg;
+
+    /**
+     * Control the use of TURN in the account. By default, the settings in the
+     * \a pjsua_media_config will be used
+     *
+     * Default: PJSUA_TURN_CONFIG_USE_DEFAULT
+     */
+    pjsua_turn_config_use	turn_cfg_use;
+
+    /**
+     * The custom TURN setting for this account. This setting will only be
+     * used if \a turn_cfg_use is set to PJSUA_TURN_CONFIG_USE_CUSTOM
+     */
+    pjsua_turn_config		turn_cfg;
+
+    /**
+     * Specify whether secure media transport should be used for this account.
+     * Valid values are PJMEDIA_SRTP_DISABLED, PJMEDIA_SRTP_OPTIONAL, and
+     * PJMEDIA_SRTP_MANDATORY.
+     *
+     * Default: #PJSUA_DEFAULT_USE_SRTP
+     */
+    pjmedia_srtp_use		use_srtp;
+
+    /**
+     * Specify whether SRTP requires secure signaling to be used. This option
+     * is only used when \a use_srtp option above is non-zero.
+     *
+     * Valid values are:
+     *	0: SRTP does not require secure signaling
+     *	1: SRTP requires secure transport such as TLS
+     *	2: SRTP requires secure end-to-end transport (SIPS)
+     *
+     * Default: #PJSUA_DEFAULT_SRTP_SECURE_SIGNALING
+     */
+    int		     srtp_secure_signaling;
+
+    /**
+     * This setting has been deprecated and will be ignored.
+     */
+    pj_bool_t	     srtp_optional_dup_offer;
+
+    /**
+     * Specify interval of auto registration retry upon registration failure
+     * (including caused by transport problem), in second. Set to 0 to
+     * disable auto re-registration. Note that if the registration retry
+     * occurs because of transport failure, the first retry will be done
+     * after \a reg_first_retry_interval seconds instead. Also note that
+     * the interval will be randomized slightly by approximately +/- ten
+     * seconds to avoid all clients re-registering at the same time.
+     *
+     * See also \a reg_first_retry_interval setting.
+     *
+     * Default: #PJSUA_REG_RETRY_INTERVAL
+     */
+    unsigned	     reg_retry_interval;
+
+    /**
+     * This specifies the interval for the first registration retry. The
+     * registration retry is explained in \a reg_retry_interval. Note that
+     * the value here will also be randomized by +/- ten seconds.
+     *
+     * Default: 0
+     */
+    unsigned	     reg_first_retry_interval;
+
+    /**
+     * Specify whether calls of the configured account should be dropped
+     * after registration failure and an attempt of re-registration has 
+     * also failed.
+     *
+     * Default: PJ_FALSE (disabled)
+     */
+    pj_bool_t	     drop_calls_on_reg_fail;
+
+    /**
+     * Specify how the registration uses the outbound and account proxy
+     * settings. This controls if and what Route headers will appear in
+     * the REGISTER request of this account. The value is bitmask combination
+     * of PJSUA_REG_USE_OUTBOUND_PROXY and PJSUA_REG_USE_ACC_PROXY bits.
+     * If the value is set to 0, the REGISTER request will not use any proxy
+     * (i.e. it will not have any Route headers).
+     *
+     * Default: 3 (PJSUA_REG_USE_OUTBOUND_PROXY | PJSUA_REG_USE_ACC_PROXY)
+     */
+    unsigned	     reg_use_proxy;
+
+#if defined(PJMEDIA_STREAM_ENABLE_KA) && (PJMEDIA_STREAM_ENABLE_KA != 0)
+    /**
+     * Specify whether stream keep-alive and NAT hole punching with
+     * non-codec-VAD mechanism (see @ref PJMEDIA_STREAM_ENABLE_KA) is enabled
+     * for this account.
+     *
+     * Default: PJ_FALSE (disabled)
+     */
+    pj_bool_t	     use_stream_ka;
+#endif
+
+    /**
+     * Specify how to offer call hold to remote peer. Please see the
+     * documentation on #pjsua_call_hold_type for more info.
+     *
+     * Default: PJSUA_CALL_HOLD_TYPE_DEFAULT
+     */
+    pjsua_call_hold_type call_hold_type;
+    
+    
+    /**
+     * Specify whether the account should register as soon as it is
+     * added to the UA. Application can set this to PJ_FALSE and control
+     * the registration manually with pjsua_acc_set_registration().
+     *
+     * Default: PJ_TRUE
+     */
+    pj_bool_t         register_on_acc_add;
+
+} pjsua_acc_config;
+
+
+/**
+ * Initialize ICE config from a media config. If the \a pool argument
+ * is NULL, a simple memcpy() will be used.
+ *
+ * @param pool	    Memory to duplicate strings.
+ * @param dst	    Destination config.
+ * @param src	    Source config.
+ */
+PJ_DECL(void) pjsua_ice_config_from_media_config(pj_pool_t *pool,
+                                              pjsua_ice_config *dst,
+                                              const pjsua_media_config *src);
+
+/**
+ * Clone. If the \a pool argument is NULL, a simple memcpy() will be used.
+ *
+ * @param pool	    Memory to duplicate strings.
+ * @param dst	    Destination config.
+ * @param src	    Source config.
+ */
+PJ_DECL(void) pjsua_ice_config_dup( pj_pool_t *pool,
+                                    pjsua_ice_config *dst,
+                                    const pjsua_ice_config *src);
+
+/**
+ * Initialize TURN config from a media config. If the \a pool argument
+ * is NULL, a simple memcpy() will be used.
+ *
+ * @param pool	    Memory to duplicate strings.
+ * @param dst	    Destination config.
+ * @param src	    Source config.
+ */
+PJ_DECL(void) pjsua_turn_config_from_media_config(pj_pool_t *pool,
+                                               pjsua_turn_config *dst,
+                                               const pjsua_media_config *src);
+
+/**
+ * Clone. If the \a pool argument is NULL, a simple memcpy() will be used.
+ *
+ * @param pool	    Memory to duplicate strings.
+ * @param dst	    Destination config.
+ * @param src	    Source config.
+ */
+PJ_DECL(void) pjsua_turn_config_dup(pj_pool_t *pool,
+                                    pjsua_turn_config *dst,
+                                    const pjsua_turn_config *src);
+
+/**
+ * Call this function to initialize account config with default values.
+ *
+ * @param cfg	    The account config to be initialized.
+ */
+PJ_DECL(void) pjsua_acc_config_default(pjsua_acc_config *cfg);
+
+
+/**
+ * Duplicate account config.
+ *
+ * @param pool	    Pool to be used for duplicating the config.
+ * @param dst	    Destination configuration.
+ * @param src	    Source configuration.
+ */
+PJ_DECL(void) pjsua_acc_config_dup(pj_pool_t *pool,
+				   pjsua_acc_config *dst,
+				   const pjsua_acc_config *src);
+
+
+/**
+ * Account info. Application can query account info by calling 
+ * #pjsua_acc_get_info().
+ */
+typedef struct pjsua_acc_info
+{
+    /** 
+     * The account ID. 
+     */
+    pjsua_acc_id	id;
+
+    /**
+     * Flag to indicate whether this is the default account.
+     */
+    pj_bool_t		is_default;
+
+    /** 
+     * Account URI 
+     */
+    pj_str_t		acc_uri;
+
+    /** 
+     * Flag to tell whether this account has registration setting
+     * (reg_uri is not empty).
+     */
+    pj_bool_t		has_registration;
+
+    /**
+     * An up to date expiration interval for account registration session.
+     */
+    int			expires;
+
+    /**
+     * Last registration status code. If status code is zero, the account
+     * is currently not registered. Any other value indicates the SIP
+     * status code of the registration.
+     */
+    pjsip_status_code	status;
+
+    /**
+     * Last registration error code. When the status field contains a SIP
+     * status code that indicates a registration failure, last registration
+     * error code contains the error code that causes the failure. In any
+     * other case, its value is zero.
+     */
+    pj_status_t	        reg_last_err;
+
+    /**
+     * String describing the registration status.
+     */
+    pj_str_t		status_text;
+
+    /**
+     * Presence online status for this account.
+     */
+    pj_bool_t		online_status;
+
+    /**
+     * Presence online status text.
+     */
+    pj_str_t		online_status_text;
+
+    /**
+     * Extended RPID online status information.
+     */
+    pjrpid_element	rpid;
+
+    /**
+     * Buffer that is used internally to store the status text.
+     */
+    char		buf_[PJ_ERR_MSG_SIZE];
+
+} pjsua_acc_info;
+
+
+
+/**
+ * Get number of current accounts.
+ *
+ * @return		Current number of accounts.
+ */
+PJ_DECL(unsigned) pjsua_acc_get_count(void);
+
+
+/**
+ * Check if the specified account ID is valid.
+ *
+ * @param acc_id	Account ID to check.
+ *
+ * @return		Non-zero if account ID is valid.
+ */
+PJ_DECL(pj_bool_t) pjsua_acc_is_valid(pjsua_acc_id acc_id);
+
+
+/**
+ * Set default account to be used when incoming and outgoing
+ * requests doesn't match any accounts.
+ *
+ * @param acc_id	The account ID to be used as default.
+ *
+ * @return		PJ_SUCCESS on success.
+ */
+PJ_DECL(pj_status_t) pjsua_acc_set_default(pjsua_acc_id acc_id);
+
+
+/**
+ * Get default account to be used when receiving incoming requests (calls),
+ * when the destination of the incoming call doesn't match any other
+ * accounts.
+ *
+ * @return		The default account ID, or PJSUA_INVALID_ID if no
+ *			default account is configured.
+ */
+PJ_DECL(pjsua_acc_id) pjsua_acc_get_default(void);
+
+
+/**
+ * Add a new account to pjsua. PJSUA must have been initialized (with
+ * #pjsua_init()) before calling this function. If registration is configured
+ * for this account, this function would also start the SIP registration
+ * session with the SIP registrar server. This SIP registration session
+ * will be maintained internally by the library, and application doesn't
+ * need to do anything to maintain the registration session.
+ *
+ *
+ * @param acc_cfg	Account configuration.
+ * @param is_default	If non-zero, this account will be set as the default
+ *			account. The default account will be used when sending
+ *			outgoing requests (e.g. making call) when no account is
+ *			specified, and when receiving incoming requests when the
+ *			request does not match any accounts. It is recommended
+ *			that default account is set to local/LAN account.
+ * @param p_acc_id	Pointer to receive account ID of the new account.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_acc_add(const pjsua_acc_config *acc_cfg,
+				   pj_bool_t is_default,
+				   pjsua_acc_id *p_acc_id);
+
+
+/**
+ * Add a local account. A local account is used to identify local endpoint
+ * instead of a specific user, and for this reason, a transport ID is needed
+ * to obtain the local address information.
+ *
+ * @param tid		Transport ID to generate account address.
+ * @param is_default	If non-zero, this account will be set as the default
+ *			account. The default account will be used when sending
+ *			outgoing requests (e.g. making call) when no account is
+ *			specified, and when receiving incoming requests when the
+ *			request does not match any accounts. It is recommended
+ *			that default account is set to local/LAN account.
+ * @param p_acc_id	Pointer to receive account ID of the new account.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_acc_add_local(pjsua_transport_id tid,
+					 pj_bool_t is_default,
+					 pjsua_acc_id *p_acc_id);
+
+/**
+ * Set arbitrary data to be associated with the account.
+ *
+ * @param acc_id	The account ID.
+ * @param user_data	User/application data.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_acc_set_user_data(pjsua_acc_id acc_id,
+					     void *user_data);
+
+
+/**
+ * Retrieve arbitrary data associated with the account.
+ *
+ * @param acc_id	The account ID.
+ *
+ * @return		The user data. In the case where the account ID is
+ *			not valid, NULL is returned.
+ */
+PJ_DECL(void*) pjsua_acc_get_user_data(pjsua_acc_id acc_id);
+
+
+/**
+ * Delete an account. This will unregister the account from the SIP server,
+ * if necessary, and terminate server side presence subscriptions associated
+ * with this account.
+ *
+ * @param acc_id	Id of the account to be deleted.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_acc_del(pjsua_acc_id acc_id);
+
+
+/**
+ * Get current config for the account. This will copy current account setting
+ * to the specified parameter. Note that all pointers in the settings will
+ * point to the original settings in the account and application must not
+ * modify the values in any way. Application must also take care that these
+ * data is only valid until the account is destroyed.
+ *
+ * @param acc_id	The account ID.
+ * @param pool		Pool to duplicate the config.
+ * @param acc_cfg	Structure to receive the settings.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_acc_get_config(pjsua_acc_id acc_id,
+                                          pj_pool_t *pool,
+                                          pjsua_acc_config *acc_cfg);
+
+
+/**
+ * Modify account information.
+ *
+ * @param acc_id	Id of the account to be modified.
+ * @param acc_cfg	New account configuration.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_acc_modify(pjsua_acc_id acc_id,
+				      const pjsua_acc_config *acc_cfg);
+
+
+/**
+ * Modify account's presence status to be advertised to remote/presence
+ * subscribers. This would trigger the sending of outgoing NOTIFY request
+ * if there are server side presence subscription for this account, and/or
+ * outgoing PUBLISH if presence publication is enabled for this account.
+ *
+ * @see pjsua_acc_set_online_status2()
+ *
+ * @param acc_id	The account ID.
+ * @param is_online	True of false.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_acc_set_online_status(pjsua_acc_id acc_id,
+						 pj_bool_t is_online);
+
+/**
+ * Modify account's presence status to be advertised to remote/presence
+ * subscribers. This would trigger the sending of outgoing NOTIFY request
+ * if there are server side presence subscription for this account, and/or
+ * outgoing PUBLISH if presence publication is enabled for this account.
+ *
+ * @see pjsua_acc_set_online_status()
+ *
+ * @param acc_id	The account ID.
+ * @param is_online	True of false.
+ * @param pr		Extended information in subset of RPID format
+ *			which allows setting custom presence text.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_acc_set_online_status2(pjsua_acc_id acc_id,
+						  pj_bool_t is_online,
+						  const pjrpid_element *pr);
+
+/**
+ * Update registration or perform unregistration. If registration is
+ * configured for this account, then initial SIP REGISTER will be sent
+ * when the account is added with #pjsua_acc_add(). Application normally
+ * only need to call this function if it wants to manually update the
+ * registration or to unregister from the server.
+ *
+ * @param acc_id	The account ID.
+ * @param renew		If renew argument is zero, this will start 
+ *			unregistration process.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_acc_set_registration(pjsua_acc_id acc_id, 
+						pj_bool_t renew);
+
+/**
+ * Get information about the specified account.
+ *
+ * @param acc_id	Account identification.
+ * @param info		Pointer to receive account information.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_acc_get_info(pjsua_acc_id acc_id,
+					pjsua_acc_info *info);
+
+
+/**
+ * Enumerate all account currently active in the library. This will fill
+ * the array with the account Ids, and application can then query the
+ * account information for each id with #pjsua_acc_get_info().
+ *
+ * @see pjsua_acc_enum_info().
+ *
+ * @param ids		Array of account IDs to be initialized.
+ * @param count		In input, specifies the maximum number of elements.
+ *			On return, it contains the actual number of elements.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_enum_accs(pjsua_acc_id ids[],
+				     unsigned *count );
+
+
+/**
+ * Enumerate account informations.
+ *
+ * @param info		Array of account infos to be initialized.
+ * @param count		In input, specifies the maximum number of elements.
+ *			On return, it contains the actual number of elements.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_acc_enum_info( pjsua_acc_info info[],
+					  unsigned *count );
+
+
+/**
+ * This is an internal function to find the most appropriate account to
+ * used to reach to the specified URL.
+ *
+ * @param url		The remote URL to reach.
+ *
+ * @return		Account id.
+ */
+PJ_DECL(pjsua_acc_id) pjsua_acc_find_for_outgoing(const pj_str_t *url);
+
+
+/**
+ * This is an internal function to find the most appropriate account to be
+ * used to handle incoming calls.
+ *
+ * @param rdata		The incoming request message.
+ *
+ * @return		Account id.
+ */
+PJ_DECL(pjsua_acc_id) pjsua_acc_find_for_incoming(pjsip_rx_data *rdata);
+
+
+/**
+ * Create arbitrary requests using the account. Application should only use
+ * this function to create auxiliary requests outside dialog, such as
+ * OPTIONS, and use the call or presence API to create dialog related
+ * requests.
+ *
+ * @param acc_id	The account ID.
+ * @param method	The SIP method of the request.
+ * @param target	Target URI.
+ * @param p_tdata	Pointer to receive the request.
+ *
+ * @return		PJ_SUCCESS or the error code.
+ */
+PJ_DECL(pj_status_t) pjsua_acc_create_request(pjsua_acc_id acc_id,
+					      const pjsip_method *method,
+					      const pj_str_t *target,
+					      pjsip_tx_data **p_tdata);
+
+
+/**
+ * Create a suitable Contact header value, based on the specified target URI 
+ * for the specified account.
+ *
+ * @param pool		Pool to allocate memory for the string.
+ * @param contact	The string where the Contact will be stored.
+ * @param acc_id	Account ID.
+ * @param uri		Destination URI of the request.
+ *
+ * @return		PJ_SUCCESS on success, other on error.
+ */
+PJ_DECL(pj_status_t) pjsua_acc_create_uac_contact( pj_pool_t *pool,
+						   pj_str_t *contact,
+						   pjsua_acc_id acc_id,
+						   const pj_str_t *uri);
+							   
+
+
+/**
+ * Create a suitable Contact header value, based on the information in the 
+ * incoming request.
+ *
+ * @param pool		Pool to allocate memory for the string.
+ * @param contact	The string where the Contact will be stored.
+ * @param acc_id	Account ID.
+ * @param rdata		Incoming request.
+ *
+ * @return		PJ_SUCCESS on success, other on error.
+ */
+PJ_DECL(pj_status_t) pjsua_acc_create_uas_contact( pj_pool_t *pool,
+						   pj_str_t *contact,
+						   pjsua_acc_id acc_id,
+						   pjsip_rx_data *rdata );
+							   
+
+/**
+ * Lock/bind this account to a specific transport/listener. Normally
+ * application shouldn't need to do this, as transports will be selected
+ * automatically by the stack according to the destination.
+ *
+ * When account is locked/bound to a specific transport, all outgoing
+ * requests from this account will use the specified transport (this
+ * includes SIP registration, dialog (call and event subscription), and
+ * out-of-dialog requests such as MESSAGE).
+ *
+ * Note that transport_id may be specified in pjsua_acc_config too.
+ *
+ * @param acc_id	The account ID.
+ * @param tp_id		The transport ID.
+ *
+ * @return		PJ_SUCCESS on success.
+ */
+PJ_DECL(pj_status_t) pjsua_acc_set_transport(pjsua_acc_id acc_id,
+					     pjsua_transport_id tp_id);
+
+
+/**
+ * @}
+ */
+
+
+/*****************************************************************************
+ * CALLS API
+ */
+
+
+/**
+ * @defgroup PJSUA_LIB_CALL PJSUA-API Calls Management
+ * @ingroup PJSUA_LIB
+ * @brief Call manipulation.
+ * @{
+ */
+
+/**
+ * Maximum simultaneous calls.
+ */
+#ifndef PJSUA_MAX_CALLS
+#   define PJSUA_MAX_CALLS	    32
+#endif
+
+/**
+ * Maximum active video windows
+ */
+#ifndef PJSUA_MAX_VID_WINS
+#   define PJSUA_MAX_VID_WINS	    16
+#endif
+
+/**
+ * Video window ID.
+ */
+typedef int pjsua_vid_win_id;
+
+
+/**
+ * This enumeration specifies the media status of a call, and it's part
+ * of pjsua_call_info structure.
+ */
+typedef enum pjsua_call_media_status
+{
+    /**
+     * Call currently has no media, or the media is not used.
+     */
+    PJSUA_CALL_MEDIA_NONE,
+
+    /**
+     * The media is active
+     */
+    PJSUA_CALL_MEDIA_ACTIVE,
+
+    /**
+     * The media is currently put on hold by local endpoint
+     */
+    PJSUA_CALL_MEDIA_LOCAL_HOLD,
+
+    /**
+     * The media is currently put on hold by remote endpoint
+     */
+    PJSUA_CALL_MEDIA_REMOTE_HOLD,
+
+    /**
+     * The media has reported error (e.g. ICE negotiation)
+     */
+    PJSUA_CALL_MEDIA_ERROR
+
+} pjsua_call_media_status;
+
+
+/**
+ * Enumeration of video keyframe request methods. Keyframe request is
+ * triggered by decoder, usually when the incoming video stream cannot
+ * be decoded properly due to missing video keyframe.
+ */
+typedef enum pjsua_vid_req_keyframe_method
+{
+    /**
+     * Requesting keyframe via SIP INFO message. Note that incoming keyframe
+     * request via SIP INFO will always be handled even if this flag is unset.
+     */
+    PJSUA_VID_REQ_KEYFRAME_SIP_INFO	= 1,
+
+    /**
+     * Requesting keyframe via Picture Loss Indication of RTCP feedback.
+     * This is currently not supported.
+     */
+    PJSUA_VID_REQ_KEYFRAME_RTCP_PLI	= 2
+
+} pjsua_vid_req_keyframe_method;
+
+
+/**
+ * Call media information.
+ */
+typedef struct pjsua_call_media_info
+{
+    /** Media index in SDP. */
+    unsigned		index;
+
+    /** Media type. */
+    pjmedia_type	type;
+
+    /** Media direction. */
+    pjmedia_dir		dir;
+
+    /** Call media status. */
+    pjsua_call_media_status status;
+
+    /** The specific media stream info. */
+    union {
+	/** Audio stream */
+	struct {
+	    /** The conference port number for the call.  */
+	    pjsua_conf_port_id	    conf_slot;
+	} aud;
+
+	/** Video stream */
+	struct {
+	    /**
+	     * The window id for incoming video, if any, or
+	     * PJSUA_INVALID_ID.
+	     */
+	    pjsua_vid_win_id	    win_in;
+
+	    /** The video capture device for outgoing transmission,
+	     *  if any, or PJMEDIA_VID_INVALID_DEV
+	     */
+	    pjmedia_vid_dev_index   cap_dev;
+
+	} vid;
+    } stream;
+
+} pjsua_call_media_info;
+
+
+/**
+ * This structure describes the information and current status of a call.
+ */
+typedef struct pjsua_call_info
+{
+    /** Call identification. */
+    pjsua_call_id	id;
+
+    /** Initial call role (UAC == caller) */
+    pjsip_role_e	role;
+
+    /** The account ID where this call belongs. */
+    pjsua_acc_id	acc_id;
+
+    /** Local URI */
+    pj_str_t		local_info;
+
+    /** Local Contact */
+    pj_str_t		local_contact;
+
+    /** Remote URI */
+    pj_str_t		remote_info;
+
+    /** Remote contact */
+    pj_str_t		remote_contact;
+
+    /** Dialog Call-ID string. */
+    pj_str_t		call_id;
+
+    /** Call setting */
+    pjsua_call_setting	setting;
+
+    /** Call state */
+    pjsip_inv_state	state;
+
+    /** Text describing the state */
+    pj_str_t		state_text;
+
+    /** Last status code heard, which can be used as cause code */
+    pjsip_status_code	last_status;
+
+    /** The reason phrase describing the status. */
+    pj_str_t		last_status_text;
+
+    /** Media status of the first audio stream. */
+    pjsua_call_media_status media_status;
+
+    /** Media direction of the first audio stream. */
+    pjmedia_dir		media_dir;
+
+    /** The conference port number for the first audio stream. */
+    pjsua_conf_port_id	conf_slot;
+
+    /** Number of active media info in this call. */
+    unsigned		media_cnt;
+
+    /** Array of active media information. */
+    pjsua_call_media_info media[PJMEDIA_MAX_SDP_MEDIA];
+
+    /** Number of provisional media info in this call. */
+    unsigned		prov_media_cnt;
+
+    /** Array of provisional media information. This contains the media info
+     *  in the provisioning state, that is when the media session is being
+     *  created/updated (SDP offer/answer is on progress).
+     */
+    pjsua_call_media_info prov_media[PJMEDIA_MAX_SDP_MEDIA];
+
+    /** Up-to-date call connected duration (zero when call is not 
+     *  established)
+     */
+    pj_time_val		connect_duration;
+
+    /** Total call duration, including set-up time */
+    pj_time_val		total_duration;
+
+    /** Flag if remote was SDP offerer */
+    pj_bool_t		rem_offerer;
+
+    /** Number of audio streams offered by remote */
+    unsigned		rem_aud_cnt;
+
+    /** Number of video streams offered by remote */
+    unsigned		rem_vid_cnt;
+
+    /** Internal */
+    struct {
+	char	local_info[128];
+	char	local_contact[128];
+	char	remote_info[128];
+	char	remote_contact[128];
+	char	call_id[128];
+	char	last_status_text[128];
+    } buf_;
+
+} pjsua_call_info;
+
+/**
+ * Flags to be given to various call APIs. More than one flags may be
+ * specified by bitmasking them.
+ */
+typedef enum pjsua_call_flag
+{
+    /**
+     * When the call is being put on hold, specify this flag to unhold it.
+     * This flag is only valid for #pjsua_call_reinvite(). Note: for
+     * compatibility reason, this flag must have value of 1 because
+     * previously the unhold option is specified as boolean value.
+     */
+    PJSUA_CALL_UNHOLD = 1,
+
+    /**
+     * Update the local invite session's contact with the contact URI from
+     * the account. This flag is only valid for #pjsua_call_set_hold2(),
+     * #pjsua_call_reinvite() and #pjsua_call_update(). This flag is useful
+     * in IP address change situation, after the local account's Contact has
+     * been updated (typically with re-registration) use this flag to update
+     * the invite session with the new Contact and to inform this new Contact
+     * to the remote peer with the outgoing re-INVITE or UPDATE.
+     */
+    PJSUA_CALL_UPDATE_CONTACT = 2,
+
+    /**
+     * Include SDP "m=" line with port set to zero for each disabled media
+     * (i.e when aud_cnt or vid_cnt is set to zero). This flag is only valid
+     * for #pjsua_call_make_call().
+     */
+    PJSUA_CALL_INCLUDE_DISABLED_MEDIA = 4
+
+} pjsua_call_flag;
+
+
+/**
+ * Media stream info.
+ */
+typedef struct pjsua_stream_info
+{
+    /** Media type of this stream. */
+    pjmedia_type type;
+
+    /** Stream info (union). */
+    union {
+	/** Audio stream info */
+	pjmedia_stream_info	aud;
+
+	/** Video stream info */
+	pjmedia_vid_stream_info	vid;
+    } info;
+
+} pjsua_stream_info;
+
+
+/**
+ * Media stream statistic.
+ */
+typedef struct pjsua_stream_stat
+{
+    /** RTCP statistic. */
+    pjmedia_rtcp_stat	rtcp;
+
+    /** Jitter buffer statistic. */
+    pjmedia_jb_state	jbuf;
+
+} pjsua_stream_stat;
+
+/**
+ * This enumeration represents video stream operation on a call.
+ * See also #pjsua_call_vid_strm_op_param for further info.
+ */
+typedef enum pjsua_call_vid_strm_op
+{
+    /**
+     * No operation
+     */
+    PJSUA_CALL_VID_STRM_NO_OP,
+
+    /**
+     * Add a new video stream. This will add a new m=video line to
+     * the media, regardless of whether existing video is/are present
+     * or not.  This will cause re-INVITE or UPDATE to be sent to remote
+     * party.
+     */
+    PJSUA_CALL_VID_STRM_ADD,
+
+    /**
+     * Remove/disable an existing video stream. This will
+     * cause re-INVITE or UPDATE to be sent to remote party.
+     */
+    PJSUA_CALL_VID_STRM_REMOVE,
+
+    /**
+     * Change direction of a video stream. This operation can be used
+     * to activate or deactivate an existing video media. This will
+     * cause re-INVITE or UPDATE to be sent to remote party.
+     */
+    PJSUA_CALL_VID_STRM_CHANGE_DIR,
+
+    /**
+     * Change capture device of a video stream.  This will not send
+     * re-INVITE or UPDATE to remote party.
+     */
+    PJSUA_CALL_VID_STRM_CHANGE_CAP_DEV,
+
+    /**
+     * Start transmitting video stream. This will cause previously
+     * stopped stream to start transmitting again. Note that no
+     * re-INVITE/UPDATE is to be transmitted to remote since this
+     * operation only operates on local stream.
+     */
+    PJSUA_CALL_VID_STRM_START_TRANSMIT,
+
+    /**
+     * Stop transmitting video stream. This will cause the stream to
+     * be paused in TX direction, causing it to stop sending any video
+     * packets. No re-INVITE/UPDATE is to be transmitted to remote
+     * with this operation.
+     */
+    PJSUA_CALL_VID_STRM_STOP_TRANSMIT,
+
+    /**
+     * Send keyframe in the video stream. This will force the stream to
+     * generate and send video keyframe as soon as possible. No
+     * re-INVITE/UPDATE is to be transmitted to remote with this operation.
+     */
+    PJSUA_CALL_VID_STRM_SEND_KEYFRAME
+
+} pjsua_call_vid_strm_op;
+
+
+/**
+ * Parameters for video stream operation on a call. Application should
+ * use #pjsua_call_vid_strm_op_param_default() to initialize this structure
+ * with its default values.
+ */
+typedef struct pjsua_call_vid_strm_op_param
+{
+    /**
+     * Specify the media stream index. This can be set to -1 to denote
+     * the default video stream in the call, which is the first active
+     * video stream or any first video stream if none is active.
+     *
+     * This field is valid for all video stream operations, except
+     * PJSUA_CALL_VID_STRM_ADD.
+     *
+     * Default: -1 (first active video stream, or any first video stream
+     *              if none is active)
+     */
+    int med_idx;
+
+    /**
+     * Specify the media stream direction.
+     *
+     * This field is valid for the following video stream operations:
+     * PJSUA_CALL_VID_STRM_ADD and PJSUA_CALL_VID_STRM_CHANGE_DIR.
+     *
+     * Default: PJMEDIA_DIR_ENCODING_DECODING
+     */
+    pjmedia_dir dir;
+
+    /**
+     * Specify the video capture device ID. This can be set to
+     * PJMEDIA_VID_DEFAULT_CAPTURE_DEV to specify the default capture
+     * device as configured in the account.
+     *
+     * This field is valid for the following video stream operations:
+     * PJSUA_CALL_VID_STRM_ADD and PJSUA_CALL_VID_STRM_CHANGE_CAP_DEV.
+     *
+     * Default: PJMEDIA_VID_DEFAULT_CAPTURE_DEV.
+     */
+    pjmedia_vid_dev_index cap_dev;
+
+} pjsua_call_vid_strm_op_param;
+
+
+/**
+ * Initialize call settings.
+ *
+ * @param opt		The call setting to be initialized.
+ */
+PJ_DECL(void) pjsua_call_setting_default(pjsua_call_setting *opt);
+
+
+/**
+ * Initialize video stream operation param with default values.
+ *
+ * @param param		The video stream operation param to be initialized.
+ */
+PJ_DECL(void)
+pjsua_call_vid_strm_op_param_default(pjsua_call_vid_strm_op_param *param);
+
+
+/**
+ * Get maximum number of calls configured in pjsua.
+ *
+ * @return		Maximum number of calls configured.
+ */
+PJ_DECL(unsigned) pjsua_call_get_max_count(void);
+
+/**
+ * Get number of currently active calls.
+ *
+ * @return		Number of currently active calls.
+ */
+PJ_DECL(unsigned) pjsua_call_get_count(void);
+
+/**
+ * Enumerate all active calls. Application may then query the information and
+ * state of each call by calling #pjsua_call_get_info().
+ *
+ * @param ids		Array of account IDs to be initialized.
+ * @param count		In input, specifies the maximum number of elements.
+ *			On return, it contains the actual number of elements.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_enum_calls(pjsua_call_id ids[],
+				      unsigned *count);
+
+
+/**
+ * Make outgoing call to the specified URI using the specified account.
+ *
+ * @param acc_id	The account to be used.
+ * @param dst_uri	URI to be put in the To header (normally is the same
+ *			as the target URI).
+ * @param opt		Optional call setting. This should be initialized
+ *			using #pjsua_call_setting_default().
+ * @param user_data	Arbitrary user data to be attached to the call, and
+ *			can be retrieved later.
+ * @param msg_data	Optional headers etc to be added to outgoing INVITE
+ *			request, or NULL if no custom header is desired.
+ * @param p_call_id	Pointer to receive call identification.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_call_make_call(pjsua_acc_id acc_id,
+					  const pj_str_t *dst_uri,
+					  const pjsua_call_setting *opt,
+					  void *user_data,
+					  const pjsua_msg_data *msg_data,
+					  pjsua_call_id *p_call_id);
+
+
+/**
+ * Check if the specified call has active INVITE session and the INVITE
+ * session has not been disconnected.
+ *
+ * @param call_id	Call identification.
+ *
+ * @return		Non-zero if call is active.
+ */
+PJ_DECL(pj_bool_t) pjsua_call_is_active(pjsua_call_id call_id);
+
+
+/**
+ * Check if call has an active media session.
+ *
+ * @param call_id	Call identification.
+ *
+ * @return		Non-zero if yes.
+ */
+PJ_DECL(pj_bool_t) pjsua_call_has_media(pjsua_call_id call_id);
+
+
+/**
+ * Get the conference port identification associated with the call.
+ *
+ * @param call_id	Call identification.
+ *
+ * @return		Conference port ID, or PJSUA_INVALID_ID when the
+ *			media has not been established or is not active.
+ */
+PJ_DECL(pjsua_conf_port_id) pjsua_call_get_conf_port(pjsua_call_id call_id);
+
+/**
+ * Obtain detail information about the specified call.
+ *
+ * @param call_id	Call identification.
+ * @param info		Call info to be initialized.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_call_get_info(pjsua_call_id call_id,
+					 pjsua_call_info *info);
+
+/**
+ * Check if remote peer support the specified capability.
+ *
+ * @param call_id	Call identification.
+ * @param htype		The header type to be checked, which value may be:
+ *			- PJSIP_H_ACCEPT
+ *			- PJSIP_H_ALLOW
+ *			- PJSIP_H_SUPPORTED
+ * @param hname		If htype specifies PJSIP_H_OTHER, then the header
+ *			name must be supplied in this argument. Otherwise the 
+ *			value must be set to NULL.
+ * @param token		The capability token to check. For example, if \a 
+ *			htype is PJSIP_H_ALLOW, then \a token specifies the 
+ *			method names; if \a htype is PJSIP_H_SUPPORTED, then
+ *			\a token specifies the extension names such as
+ *			 "100rel".
+ *
+ * @return		PJSIP_DIALOG_CAP_SUPPORTED if the specified capability
+ *			is explicitly supported, see @pjsip_dialog_cap_status
+ *			for more info.
+ */
+PJ_DECL(pjsip_dialog_cap_status) pjsua_call_remote_has_cap(
+						    pjsua_call_id call_id,
+						    int htype,
+						    const pj_str_t *hname,
+						    const pj_str_t *token);
+
+/**
+ * Attach application specific data to the call. Application can then
+ * inspect this data by calling #pjsua_call_get_user_data().
+ *
+ * @param call_id	Call identification.
+ * @param user_data	Arbitrary data to be attached to the call.
+ *
+ * @return		The user data.
+ */
+PJ_DECL(pj_status_t) pjsua_call_set_user_data(pjsua_call_id call_id,
+					      void *user_data);
+
+
+/**
+ * Get user data attached to the call, which has been previously set with
+ * #pjsua_call_set_user_data().
+ *
+ * @param call_id	Call identification.
+ *
+ * @return		The user data.
+ */
+PJ_DECL(void*) pjsua_call_get_user_data(pjsua_call_id call_id);
+
+
+/**
+ * Get the NAT type of remote's endpoint. This is a proprietary feature
+ * of PJSUA-LIB which sends its NAT type in the SDP when \a nat_type_in_sdp
+ * is set in #pjsua_config.
+ *
+ * This function can only be called after SDP has been received from remote,
+ * which means for incoming call, this function can be called as soon as
+ * call is received as long as incoming call contains SDP, and for outgoing
+ * call, this function can be called only after SDP is received (normally in
+ * 200/OK response to INVITE). As a general case, application should call 
+ * this function after or in \a on_call_media_state() callback.
+ *
+ * @param call_id	Call identification.
+ * @param p_type	Pointer to store the NAT type. Application can then
+ *			retrieve the string description of the NAT type
+ *			by calling pj_stun_get_nat_name().
+ *
+ * @return		PJ_SUCCESS on success.
+ *
+ * @see pjsua_get_nat_type(), nat_type_in_sdp
+ */
+PJ_DECL(pj_status_t) pjsua_call_get_rem_nat_type(pjsua_call_id call_id,
+						 pj_stun_nat_type *p_type);
+
+/**
+ * Send response to incoming INVITE request. Depending on the status
+ * code specified as parameter, this function may send provisional
+ * response, establish the call, or terminate the call. See also
+ * #pjsua_call_answer2().
+ *
+ * @param call_id	Incoming call identification.
+ * @param code		Status code, (100-699).
+ * @param reason	Optional reason phrase. If NULL, default text
+ *			will be used.
+ * @param msg_data	Optional list of headers etc to be added to outgoing
+ *			response message. Note that this message data will
+ *			be persistent in all next answers/responses for this
+ *			INVITE request.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_call_answer(pjsua_call_id call_id, 
+				       unsigned code,
+				       const pj_str_t *reason,
+				       const pjsua_msg_data *msg_data);
+
+
+/**
+ * Send response to incoming INVITE request with call setting param.
+ * Depending on the status code specified as parameter, this function may
+ * send provisional response, establish the call, or terminate the call.
+ * Notes about call setting:
+ *  - if call setting is changed in the subsequent call to this function,
+ *    only the first call setting supplied will applied. So normally
+ *    application will not supply call setting before getting confirmation
+ *    from the user.
+ *  - if no call setting is supplied when SDP has to be sent, i.e: answer
+ *    with status code 183 or 2xx, the default call setting will be used,
+ *    check #pjsua_call_setting for its default values.
+ *
+ * @param call_id	Incoming call identification.
+ * @param opt		Optional call setting.
+ * @param code		Status code, (100-699).
+ * @param reason	Optional reason phrase. If NULL, default text
+ *			will be used.
+ * @param msg_data	Optional list of headers etc to be added to outgoing
+ *			response message. Note that this message data will
+ *			be persistent in all next answers/responses for this
+ *			INVITE request.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_call_answer2(pjsua_call_id call_id, 
+					const pjsua_call_setting *opt,
+				        unsigned code,
+				        const pj_str_t *reason,
+				        const pjsua_msg_data *msg_data);
+
+
+/**
+ * Hangup call by using method that is appropriate according to the
+ * call state. This function is different than answering the call with
+ * 3xx-6xx response (with #pjsua_call_answer()), in that this function
+ * will hangup the call regardless of the state and role of the call,
+ * while #pjsua_call_answer() only works with incoming calls on EARLY
+ * state.
+ *
+ * @param call_id	Call identification.
+ * @param code		Optional status code to be sent when we're rejecting
+ *			incoming call. If the value is zero, "603/Decline"
+ *			will be sent.
+ * @param reason	Optional reason phrase to be sent when we're rejecting
+ *			incoming call.  If NULL, default text will be used.
+ * @param msg_data	Optional list of headers etc to be added to outgoing
+ *			request/response message.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_call_hangup(pjsua_call_id call_id,
+				       unsigned code,
+				       const pj_str_t *reason,
+				       const pjsua_msg_data *msg_data);
+
+/**
+ * Accept or reject redirection response. Application MUST call this function
+ * after it signaled PJSIP_REDIRECT_PENDING in the \a on_call_redirected() 
+ * callback, to notify the call whether to accept or reject the redirection
+ * to the current target. Application can use the combination of
+ * PJSIP_REDIRECT_PENDING command in \a on_call_redirected() callback and 
+ * this function to ask for user permission before redirecting the call.
+ *
+ * Note that if the application chooses to reject or stop redirection (by 
+ * using PJSIP_REDIRECT_REJECT or PJSIP_REDIRECT_STOP respectively), the
+ * call disconnection callback will be called before this function returns.
+ * And if the application rejects the target, the \a on_call_redirected() 
+ * callback may also be called before this function returns if there is 
+ * another target to try.
+ *
+ * @param call_id	The call ID.
+ * @param cmd		Redirection operation to be applied to the current
+ *			target. The semantic of this argument is similar
+ *			to the description in the \a on_call_redirected()
+ *			callback, except that the PJSIP_REDIRECT_PENDING is
+ *			not accepted here.
+ *
+ * @return		PJ_SUCCESS on successful operation.
+ */
+PJ_DECL(pj_status_t) pjsua_call_process_redirect(pjsua_call_id call_id,
+						 pjsip_redirect_op cmd);
+
+/**
+ * Put the specified call on hold. This will send re-INVITE with the
+ * appropriate SDP to inform remote that the call is being put on hold.
+ * The final status of the request itself will be reported on the
+ * \a on_call_media_state() callback, which inform the application that
+ * the media state of the call has changed.
+ *
+ * @param call_id	Call identification.
+ * @param msg_data	Optional message components to be sent with
+ *			the request.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_call_set_hold(pjsua_call_id call_id,
+					 const pjsua_msg_data *msg_data);
+
+/**
+ * Put the specified call on hold. This will send re-INVITE with the
+ * appropriate SDP to inform remote that the call is being put on hold.
+ * The final status of the request itself will be reported on the
+ * \a on_call_media_state() callback, which inform the application that
+ * the media state of the call has changed.
+ *
+ * @param call_id	Call identification.
+ * @param options	Bitmask of pjsua_call_flag constants. Currently, only
+ *                      the flag PJSUA_CALL_UPDATE_CONTACT can be used.
+ * @param msg_data	Optional message components to be sent with
+ *			the request.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_call_set_hold2(pjsua_call_id call_id,
+                                          unsigned options,
+					  const pjsua_msg_data *msg_data);
+
+/**
+ * Send re-INVITE to release hold.
+ * The final status of the request itself will be reported on the
+ * \a on_call_media_state() callback, which inform the application that
+ * the media state of the call has changed.
+ *
+ * @param call_id	Call identification.
+ * @param options	Bitmask of pjsua_call_flag constants. Note that
+ * 			for compatibility, specifying PJ_TRUE here is
+ * 			equal to specifying PJSUA_CALL_UNHOLD flag.
+ * @param msg_data	Optional message components to be sent with
+ *			the request.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_call_reinvite(pjsua_call_id call_id,
+					 unsigned options,
+					 const pjsua_msg_data *msg_data);
+
+
+/**
+ * Send re-INVITE to release hold.
+ * The final status of the request itself will be reported on the
+ * \a on_call_media_state() callback, which inform the application that
+ * the media state of the call has changed.
+ *
+ * @param call_id	Call identification.
+ * @param opt		Optional call setting, if NULL, the current call
+ *			setting will remain unchanged.
+ * @param msg_data	Optional message components to be sent with
+ *			the request.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_call_reinvite2(pjsua_call_id call_id,
+					  const pjsua_call_setting *opt,
+					  const pjsua_msg_data *msg_data);
+
+
+/**
+ * Send UPDATE request.
+ *
+ * @param call_id	Call identification.
+ * @param options	Bitmask of pjsua_call_flag constants.
+ * @param msg_data	Optional message components to be sent with
+ *			the request.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_call_update(pjsua_call_id call_id,
+				       unsigned options,
+				       const pjsua_msg_data *msg_data);
+
+
+/**
+ * Send UPDATE request.
+ *
+ * @param call_id	Call identification.
+ * @param opt		Optional call setting, if NULL, the current call
+ *			setting will remain unchanged.
+ * @param msg_data	Optional message components to be sent with
+ *			the request.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_call_update2(pjsua_call_id call_id,
+				        const pjsua_call_setting *opt,
+				        const pjsua_msg_data *msg_data);
+
+
+/**
+ * Initiate call transfer to the specified address. This function will send
+ * REFER request to instruct remote call party to initiate a new INVITE
+ * session to the specified destination/target.
+ *
+ * If application is interested to monitor the successfulness and 
+ * the progress of the transfer request, it can implement 
+ * \a on_call_transfer_status() callback which will report the progress
+ * of the call transfer request.
+ *
+ * @param call_id	The call id to be transfered.
+ * @param dest		URI of new target to be contacted. The URI may be
+ * 			in name address or addr-spec format.
+ * @param msg_data	Optional message components to be sent with
+ *			the request.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_call_xfer(pjsua_call_id call_id, 
+				     const pj_str_t *dest,
+				     const pjsua_msg_data *msg_data);
+
+/**
+ * Flag to indicate that "Require: replaces" should not be put in the
+ * outgoing INVITE request caused by REFER request created by 
+ * #pjsua_call_xfer_replaces().
+ */
+#define PJSUA_XFER_NO_REQUIRE_REPLACES	1
+
+/**
+ * Initiate attended call transfer. This function will send REFER request
+ * to instruct remote call party to initiate new INVITE session to the URL
+ * of \a dest_call_id. The party at \a dest_call_id then should "replace"
+ * the call with us with the new call from the REFER recipient.
+ *
+ * @param call_id	The call id to be transfered.
+ * @param dest_call_id	The call id to be replaced.
+ * @param options	Application may specify PJSUA_XFER_NO_REQUIRE_REPLACES
+ *			to suppress the inclusion of "Require: replaces" in
+ *			the outgoing INVITE request created by the REFER
+ *			request.
+ * @param msg_data	Optional message components to be sent with
+ *			the request.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_call_xfer_replaces(pjsua_call_id call_id, 
+					      pjsua_call_id dest_call_id,
+					      unsigned options,
+					      const pjsua_msg_data *msg_data);
+
+/**
+ * Send DTMF digits to remote using RFC 2833 payload formats.
+ *
+ * @param call_id	Call identification.
+ * @param digits	DTMF string digits to be sent.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_call_dial_dtmf(pjsua_call_id call_id, 
+					  const pj_str_t *digits);
+
+/**
+ * Send instant messaging inside INVITE session.
+ *
+ * @param call_id	Call identification.
+ * @param mime_type	Optional MIME type. If NULL, then "text/plain" is 
+ *			assumed.
+ * @param content	The message content.
+ * @param msg_data	Optional list of headers etc to be included in outgoing
+ *			request. The body descriptor in the msg_data is 
+ *			ignored.
+ * @param user_data	Optional user data, which will be given back when
+ *			the IM callback is called.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_call_send_im( pjsua_call_id call_id, 
+					 const pj_str_t *mime_type,
+					 const pj_str_t *content,
+					 const pjsua_msg_data *msg_data,
+					 void *user_data);
+
+
+/**
+ * Send IM typing indication inside INVITE session.
+ *
+ * @param call_id	Call identification.
+ * @param is_typing	Non-zero to indicate to remote that local person is
+ *			currently typing an IM.
+ * @param msg_data	Optional list of headers etc to be included in outgoing
+ *			request.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_call_send_typing_ind(pjsua_call_id call_id, 
+						pj_bool_t is_typing,
+						const pjsua_msg_data*msg_data);
+
+/**
+ * Send arbitrary request with the call. This is useful for example to send
+ * INFO request. Note that application should not use this function to send
+ * requests which would change the invite session's state, such as re-INVITE,
+ * UPDATE, PRACK, and BYE.
+ *
+ * @param call_id	Call identification.
+ * @param method	SIP method of the request.
+ * @param msg_data	Optional message body and/or list of headers to be 
+ *			included in outgoing request.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_call_send_request(pjsua_call_id call_id,
+					     const pj_str_t *method,
+					     const pjsua_msg_data *msg_data);
+
+
+/**
+ * Terminate all calls. This will initiate #pjsua_call_hangup() for all
+ * currently active calls. 
+ */
+PJ_DECL(void) pjsua_call_hangup_all(void);
+
+
+/**
+ * Dump call and media statistics to string.
+ *
+ * @param call_id	Call identification.
+ * @param with_media	Non-zero to include media information too.
+ * @param buffer	Buffer where the statistics are to be written to.
+ * @param maxlen	Maximum length of buffer.
+ * @param indent	Spaces for left indentation.
+ *
+ * @return		PJ_SUCCESS on success.
+ */
+PJ_DECL(pj_status_t) pjsua_call_dump(pjsua_call_id call_id, 
+				     pj_bool_t with_media, 
+				     char *buffer, 
+				     unsigned maxlen,
+				     const char *indent);
+
+/**
+ * Get the media stream index of the default video stream in the call.
+ * Typically this will just retrieve the stream index of the first
+ * activated video stream in the call. If none is active, it will return
+ * the first inactive video stream.
+ *
+ * @param call_id	Call identification.
+ *
+ * @return		The media stream index or -1 if no video stream
+ * 			is present in the call.
+ */
+PJ_DECL(int) pjsua_call_get_vid_stream_idx(pjsua_call_id call_id);
+
+
+/**
+ * Determine if video stream for the specified call is currently running
+ * (i.e. has been created, started, and not being paused) for the specified
+ *  direction.
+ *
+ * @param call_id	Call identification.
+ * @param med_idx	Media stream index, or -1 to specify default video
+ * 			media.
+ * @param dir		The direction to be checked.
+ *
+ * @return		PJ_TRUE if stream is currently running for the
+ * 			specified direction.
+ */
+PJ_DECL(pj_bool_t) pjsua_call_vid_stream_is_running(pjsua_call_id call_id,
+                                                    int med_idx,
+                                                    pjmedia_dir dir);
+
+/**
+ * Add, remove, modify, and/or manipulate video media stream for the
+ * specified call. This may trigger a re-INVITE or UPDATE to be sent
+ * for the call.
+ *
+ * @param call_id	Call identification.
+ * @param op		The video stream operation to be performed,
+ *			possible values are #pjsua_call_vid_strm_op.
+ * @param param		The parameters for the video stream operation,
+ *			or NULL for the default parameter values
+ *			(see #pjsua_call_vid_strm_op_param).
+ *
+ * @return		PJ_SUCCESS on success or the appropriate error.
+ */
+PJ_DECL(pj_status_t) pjsua_call_set_vid_strm (
+				pjsua_call_id call_id,
+				pjsua_call_vid_strm_op op,
+				const pjsua_call_vid_strm_op_param *param);
+
+
+/**
+ * Get media stream info for the specified media index.
+ *
+ * @param call_id	The call identification.
+ * @param med_idx	Media stream index.
+ * @param psi		To be filled with the stream info.
+ *
+ * @return		PJ_SUCCESS on success or the appropriate error.
+ */
+PJ_DECL(pj_status_t) pjsua_call_get_stream_info(pjsua_call_id call_id,
+                                                unsigned med_idx,
+                                                pjsua_stream_info *psi);
+
+/**
+ *  Get media stream statistic for the specified media index.
+ *
+ * @param call_id	The call identification.
+ * @param med_idx	Media stream index.
+ * @param psi		To be filled with the stream statistic.
+ *
+ * @return		PJ_SUCCESS on success or the appropriate error.
+ */
+PJ_DECL(pj_status_t) pjsua_call_get_stream_stat(pjsua_call_id call_id,
+                                                unsigned med_idx,
+                                                pjsua_stream_stat *stat);
+
+/**
+ * Get media transport info for the specified media index.
+ *
+ * @param call_id	The call identification.
+ * @param med_idx	Media stream index.
+ * @param t		To be filled with the transport info.
+ *
+ * @return		PJ_SUCCESS on success or the appropriate error.
+ */
+PJ_DECL(pj_status_t) 
+pjsua_call_get_med_transport_info(pjsua_call_id call_id,
+                                  unsigned med_idx,
+                                  pjmedia_transport_info *t);
+
+
+
+/**
+ * @}
+ */
+
+
+/*****************************************************************************
+ * BUDDY API
+ */
+
+
+/**
+ * @defgroup PJSUA_LIB_BUDDY PJSUA-API Buddy, Presence, and Instant Messaging
+ * @ingroup PJSUA_LIB
+ * @brief Buddy management, buddy's presence, and instant messaging.
+ * @{
+ *
+ * This section describes PJSUA-APIs related to buddies management,
+ * presence management, and instant messaging.
+ */
+
+/**
+ * Max buddies in buddy list.
+ */
+#ifndef PJSUA_MAX_BUDDIES
+#   define PJSUA_MAX_BUDDIES	    256
+#endif
+
+
+/**
+ * This specifies how long the library should wait before retrying failed
+ * SUBSCRIBE request, and there is no rule to automatically resubscribe 
+ * (for example, no "retry-after" parameter in Subscription-State header).
+ *
+ * This also controls the duration  before failed PUBLISH request will be
+ * retried.
+ *
+ * Default: 300 seconds
+ */
+#ifndef PJSUA_PRES_TIMER
+#   define PJSUA_PRES_TIMER	    300
+#endif
+
+
+/**
+ * This structure describes buddy configuration when adding a buddy to
+ * the buddy list with #pjsua_buddy_add(). Application MUST initialize
+ * the structure with #pjsua_buddy_config_default() to initialize this
+ * structure with default configuration.
+ */
+typedef struct pjsua_buddy_config
+{
+    /**
+     * Buddy URL or name address.
+     */
+    pj_str_t	uri;
+
+    /**
+     * Specify whether presence subscription should start immediately.
+     */
+    pj_bool_t	subscribe;
+
+    /**
+     * Specify arbitrary application data to be associated with with
+     * the buddy object.
+     */
+    void       *user_data;
+
+} pjsua_buddy_config;
+
+
+/**
+ * This enumeration describes basic buddy's online status.
+ */
+typedef enum pjsua_buddy_status
+{
+    /**
+     * Online status is unknown (possibly because no presence subscription
+     * has been established).
+     */
+    PJSUA_BUDDY_STATUS_UNKNOWN,
+
+    /**
+     * Buddy is known to be online.
+     */
+    PJSUA_BUDDY_STATUS_ONLINE,
+
+    /**
+     * Buddy is offline.
+     */
+    PJSUA_BUDDY_STATUS_OFFLINE,
+
+} pjsua_buddy_status;
+
+
+
+/**
+ * This structure describes buddy info, which can be retrieved by calling
+ * #pjsua_buddy_get_info().
+ */
+typedef struct pjsua_buddy_info
+{
+    /**
+     * The buddy ID.
+     */
+    pjsua_buddy_id	id;
+
+    /**
+     * The full URI of the buddy, as specified in the configuration.
+     */
+    pj_str_t		uri;
+
+    /**
+     * Buddy's Contact, only available when presence subscription has
+     * been established to the buddy.
+     */
+    pj_str_t		contact;
+
+    /**
+     * Buddy's online status.
+     */
+    pjsua_buddy_status	status;
+
+    /**
+     * Text to describe buddy's online status.
+     */
+    pj_str_t		status_text;
+
+    /**
+     * Flag to indicate that we should monitor the presence information for
+     * this buddy (normally yes, unless explicitly disabled).
+     */
+    pj_bool_t		monitor_pres;
+
+    /**
+     * If \a monitor_pres is enabled, this specifies the last state of the
+     * presence subscription. If presence subscription session is currently
+     * active, the value will be PJSIP_EVSUB_STATE_ACTIVE. If presence
+     * subscription request has been rejected, the value will be
+     * PJSIP_EVSUB_STATE_TERMINATED, and the termination reason will be
+     * specified in \a sub_term_reason.
+     */
+    pjsip_evsub_state	sub_state;
+
+    /**
+     * String representation of subscription state.
+     */
+    const char	       *sub_state_name;
+
+    /**
+     * Specifies the last presence subscription termination code. This would
+     * return the last status of the SUBSCRIBE request. If the subscription
+     * is terminated with NOTIFY by the server, this value will be set to
+     * 200, and subscription termination reason will be given in the
+     * \a sub_term_reason field.
+     */
+    unsigned		sub_term_code;
+
+    /**
+     * Specifies the last presence subscription termination reason. If 
+     * presence subscription is currently active, the value will be empty.
+     */
+    pj_str_t		sub_term_reason;
+
+    /**
+     * Extended RPID information about the person.
+     */
+    pjrpid_element	rpid;
+
+    /**
+     * Extended presence info.
+     */
+    pjsip_pres_status	pres_status;
+
+    /**
+     * Internal buffer.
+     */
+    char		buf_[512];
+
+} pjsua_buddy_info;
+
+
+/**
+ * Set default values to the buddy config.
+ */
+PJ_DECL(void) pjsua_buddy_config_default(pjsua_buddy_config *cfg);
+
+
+/**
+ * Get total number of buddies.
+ *
+ * @return		Number of buddies.
+ */
+PJ_DECL(unsigned) pjsua_get_buddy_count(void);
+
+
+/**
+ * Check if buddy ID is valid.
+ *
+ * @param buddy_id	Buddy ID to check.
+ *
+ * @return		Non-zero if buddy ID is valid.
+ */
+PJ_DECL(pj_bool_t) pjsua_buddy_is_valid(pjsua_buddy_id buddy_id);
+
+
+/**
+ * Enumerate all buddy IDs in the buddy list. Application then can use
+ * #pjsua_buddy_get_info() to get the detail information for each buddy
+ * id.
+ *
+ * @param ids		Array of ids to be initialized.
+ * @param count		On input, specifies max elements in the array.
+ *			On return, it contains actual number of elements
+ *			that have been initialized.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_enum_buddies(pjsua_buddy_id ids[],
+					unsigned *count);
+
+/**
+ * Find the buddy ID with the specified URI.
+ *
+ * @param uri		The buddy URI.
+ *
+ * @return		The buddy ID, or PJSUA_INVALID_ID if not found.
+ */
+PJ_DECL(pjsua_buddy_id) pjsua_buddy_find(const pj_str_t *uri);
+
+
+/**
+ * Get detailed buddy info.
+ *
+ * @param buddy_id	The buddy identification.
+ * @param info		Pointer to receive information about buddy.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_buddy_get_info(pjsua_buddy_id buddy_id,
+					  pjsua_buddy_info *info);
+
+/**
+ * Set the user data associated with the buddy object.
+ *
+ * @param buddy_id	The buddy identification.
+ * @param user_data	Arbitrary application data to be associated with
+ *			the buddy object.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_buddy_set_user_data(pjsua_buddy_id buddy_id,
+					       void *user_data);
+
+
+/**
+ * Get the user data associated with the budy object.
+ *
+ * @param buddy_id	The buddy identification.
+ *
+ * @return		The application data.
+ */
+PJ_DECL(void*) pjsua_buddy_get_user_data(pjsua_buddy_id buddy_id);
+
+
+/**
+ * Add new buddy to the buddy list. If presence subscription is enabled
+ * for this buddy, this function will also start the presence subscription
+ * session immediately.
+ *
+ * @param buddy_cfg	Buddy configuration.
+ * @param p_buddy_id	Pointer to receive buddy ID.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_buddy_add(const pjsua_buddy_config *buddy_cfg,
+				     pjsua_buddy_id *p_buddy_id);
+
+
+/**
+ * Delete the specified buddy from the buddy list. Any presence subscription
+ * to this buddy will be terminated.
+ *
+ * @param buddy_id	Buddy identification.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_buddy_del(pjsua_buddy_id buddy_id);
+
+
+/**
+ * Enable/disable buddy's presence monitoring. Once buddy's presence is
+ * subscribed, application will be informed about buddy's presence status
+ * changed via \a on_buddy_state() callback.
+ *
+ * @param buddy_id	Buddy identification.
+ * @param subscribe	Specify non-zero to activate presence subscription to
+ *			the specified buddy.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_buddy_subscribe_pres(pjsua_buddy_id buddy_id,
+						pj_bool_t subscribe);
+
+
+/**
+ * Update the presence information for the buddy. Although the library
+ * periodically refreshes the presence subscription for all buddies, some
+ * application may want to refresh the buddy's presence subscription
+ * immediately, and in this case it can use this function to accomplish
+ * this.
+ *
+ * Note that the buddy's presence subscription will only be initiated
+ * if presence monitoring is enabled for the buddy. See 
+ * #pjsua_buddy_subscribe_pres() for more info. Also if presence subscription
+ * for the buddy is already active, this function will not do anything.
+ *
+ * Once the presence subscription is activated successfully for the buddy,
+ * application will be notified about the buddy's presence status in the
+ * on_buddy_state() callback.
+ *
+ * @param buddy_id	Buddy identification.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_buddy_update_pres(pjsua_buddy_id buddy_id);
+
+
+/**
+ * Send NOTIFY to inform account presence status or to terminate server
+ * side presence subscription. If application wants to reject the incoming
+ * request, it should set the \a state to PJSIP_EVSUB_STATE_TERMINATED.
+ *
+ * @param acc_id	Account ID.
+ * @param srv_pres	Server presence subscription instance.
+ * @param state		New state to set.
+ * @param state_str	Optionally specify the state string name, if state
+ *			is not "active", "pending", or "terminated".
+ * @param reason	If the new state is PJSIP_EVSUB_STATE_TERMINATED,
+ *			optionally specify the termination reason. 
+ * @param with_body	If the new state is PJSIP_EVSUB_STATE_TERMINATED,
+ *			this specifies whether the NOTIFY request should
+ *			contain message body containing account's presence
+ *			information.
+ * @param msg_data	Optional list of headers to be sent with the NOTIFY
+ *			request.
+ *
+ * @return		PJ_SUCCESS on success.
+ */
+PJ_DECL(pj_status_t) pjsua_pres_notify(pjsua_acc_id acc_id,
+				       pjsua_srv_pres *srv_pres,
+				       pjsip_evsub_state state,
+				       const pj_str_t *state_str,
+				       const pj_str_t *reason,
+				       pj_bool_t with_body,
+				       const pjsua_msg_data *msg_data);
+
+/**
+ * Dump presence subscriptions to log.
+ *
+ * @param verbose	Yes or no.
+ */
+PJ_DECL(void) pjsua_pres_dump(pj_bool_t verbose);
+
+
+/**
+ * The MESSAGE method (defined in pjsua_im.c)
+ */
+extern const pjsip_method pjsip_message_method;
+
+
+/**
+ * The INFO method (defined in pjsua_call.c)
+ */
+extern const pjsip_method pjsip_info_method;
+
+
+/**
+ * Send instant messaging outside dialog, using the specified account for
+ * route set and authentication.
+ *
+ * @param acc_id	Account ID to be used to send the request.
+ * @param to		Remote URI.
+ * @param mime_type	Optional MIME type. If NULL, then "text/plain" is 
+ *			assumed.
+ * @param content	The message content.
+ * @param msg_data	Optional list of headers etc to be included in outgoing
+ *			request. The body descriptor in the msg_data is 
+ *			ignored.
+ * @param user_data	Optional user data, which will be given back when
+ *			the IM callback is called.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_im_send(pjsua_acc_id acc_id, 
+				   const pj_str_t *to,
+				   const pj_str_t *mime_type,
+				   const pj_str_t *content,
+				   const pjsua_msg_data *msg_data,
+				   void *user_data);
+
+
+/**
+ * Send typing indication outside dialog.
+ *
+ * @param acc_id	Account ID to be used to send the request.
+ * @param to		Remote URI.
+ * @param is_typing	If non-zero, it tells remote person that local person
+ *			is currently composing an IM.
+ * @param msg_data	Optional list of headers etc to be added to outgoing
+ *			request.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_im_typing(pjsua_acc_id acc_id, 
+				     const pj_str_t *to, 
+				     pj_bool_t is_typing,
+				     const pjsua_msg_data *msg_data);
+
+
+
+/**
+ * @}
+ */
+
+
+/*****************************************************************************
+ * MEDIA API
+ */
+
+
+/**
+ * @defgroup PJSUA_LIB_MEDIA PJSUA-API Media Manipulation
+ * @ingroup PJSUA_LIB
+ * @brief Media manipulation.
+ * @{
+ *
+ * PJSUA has rather powerful media features, which are built around the
+ * PJMEDIA conference bridge. Basically, all media "ports" (such as calls, WAV 
+ * players, WAV playlist, file recorders, sound device, tone generators, etc)
+ * are terminated in the conference bridge, and application can manipulate
+ * the interconnection between these terminations freely. 
+ *
+ * The conference bridge provides powerful switching and mixing functionality
+ * for application. With the conference bridge, each conference slot (e.g. 
+ * a call) can transmit to multiple destinations, and one destination can
+ * receive from multiple sources. If more than one media terminations are 
+ * terminated in the same slot, the conference bridge will mix the signal 
+ * automatically.
+ *
+ * Application connects one media termination/slot to another by calling
+ * #pjsua_conf_connect() function. This will establish <b>unidirectional</b>
+ * media flow from the source termination to the sink termination. To
+ * establish bidirectional media flow, application wound need to make another
+ * call to #pjsua_conf_connect(), this time inverting the source and 
+ * destination slots in the parameter.
+ *
+ * For example, to stream a WAV file to remote call, application may use
+ * the following steps:
+ *
+ \code
+  
+  pj_status_t stream_to_call( pjsua_call_id call_id )
+  {
+     pjsua_player_id player_id;
+     
+     status = pjsua_player_create("mysong.wav", 0, &player_id);
+     if (status != PJ_SUCCESS)
+        return status;
+
+     status = pjsua_conf_connect( pjsua_player_get_conf_port(),
+				  pjsua_call_get_conf_port() );
+  }
+ \endcode
+ *
+ *
+ * Other features of PJSUA media:
+ *  - efficient N to M interconnections between media terminations.
+ *  - media termination can be connected to itself to create loopback
+ *    media.
+ *  - the media termination may have different clock rates, and resampling
+ *    will be done automatically by conference bridge.
+ *  - media terminations may also have different frame time; the
+ *    conference bridge will perform the necessary bufferring to adjust
+ *    the difference between terminations.
+ *  - interconnections are removed automatically when media termination
+ *    is removed from the bridge.
+ *  - sound device may be changed even when there are active media 
+ *    interconnections.
+ *  - correctly report call's media quality (in #pjsua_call_dump()) from
+ *    RTCP packet exchange.
+ */
+
+/**
+ * Use PJMEDIA for media? Set this to zero when using third party media
+ * stack.
+ */
+#ifndef PJSUA_MEDIA_HAS_PJMEDIA
+#  define PJSUA_MEDIA_HAS_PJMEDIA	1
+#endif	/* PJSUA_MEDIA_HAS_PJMEDIA */
+
+
+/**
+ * Specify whether the third party stream has the capability of retrieving
+ * the stream info, i.e: pjmedia_stream_get_info() and
+ * pjmedia_vid_stream_get_info(). Currently this capability is required
+ * by smart media update and call dump.
+ */
+#ifndef PJSUA_THIRD_PARTY_STREAM_HAS_GET_INFO
+#   define PJSUA_THIRD_PARTY_STREAM_HAS_GET_INFO    0
+#endif
+
+
+/**
+ * Specify whether the third party stream has the capability of retrieving
+ * the stream statistics, i.e: pjmedia_stream_get_stat() and
+ * pjmedia_vid_stream_get_stat(). Currently this capability is required
+ * by call dump.
+ */
+#ifndef PJSUA_THIRD_PARTY_STREAM_HAS_GET_STAT
+#   define PJSUA_THIRD_PARTY_STREAM_HAS_GET_STAT    0
+#endif
+
+
+/**
+ * Max ports in the conference bridge. This setting is the default value
+ * for pjsua_media_config.max_media_ports.
+ */
+#ifndef PJSUA_MAX_CONF_PORTS
+#   define PJSUA_MAX_CONF_PORTS		254
+#endif
+
+/**
+ * The default clock rate to be used by the conference bridge. This setting
+ * is the default value for pjsua_media_config.clock_rate.
+ */
+#ifndef PJSUA_DEFAULT_CLOCK_RATE
+#   define PJSUA_DEFAULT_CLOCK_RATE	16000
+#endif
+
+/**
+ * Default frame length in the conference bridge. This setting
+ * is the default value for pjsua_media_config.audio_frame_ptime.
+ */
+#ifndef PJSUA_DEFAULT_AUDIO_FRAME_PTIME
+#   define PJSUA_DEFAULT_AUDIO_FRAME_PTIME  20
+#endif
+
+
+/**
+ * Default codec quality settings. This setting is the default value
+ * for pjsua_media_config.quality.
+ */
+#ifndef PJSUA_DEFAULT_CODEC_QUALITY
+#   define PJSUA_DEFAULT_CODEC_QUALITY	8
+#endif
+
+/**
+ * Default iLBC mode. This setting is the default value for 
+ * pjsua_media_config.ilbc_mode.
+ */
+#ifndef PJSUA_DEFAULT_ILBC_MODE
+#   define PJSUA_DEFAULT_ILBC_MODE	30
+#endif
+
+/**
+ * The default echo canceller tail length. This setting
+ * is the default value for pjsua_media_config.ec_tail_len.
+ */
+#ifndef PJSUA_DEFAULT_EC_TAIL_LEN
+#   define PJSUA_DEFAULT_EC_TAIL_LEN	200
+#endif
+
+
+/**
+ * The maximum file player.
+ */
+#ifndef PJSUA_MAX_PLAYERS
+#   define PJSUA_MAX_PLAYERS		32
+#endif
+
+
+/**
+ * The maximum file player.
+ */
+#ifndef PJSUA_MAX_RECORDERS
+#   define PJSUA_MAX_RECORDERS		32
+#endif
+
+
+/**
+ * Enable/disable "c=" line in SDP session level. Set to zero to disable it.
+ */
+#ifndef PJSUA_SDP_SESS_HAS_CONN
+#   define PJSUA_SDP_SESS_HAS_CONN	0
+#endif
+
+
+/**
+ * This structure describes media configuration, which will be specified
+ * when calling #pjsua_init(). Application MUST initialize this structure
+ * by calling #pjsua_media_config_default().
+ */
+struct pjsua_media_config
+{
+    /**
+     * Clock rate to be applied to the conference bridge.
+     * If value is zero, default clock rate will be used 
+     * (PJSUA_DEFAULT_CLOCK_RATE, which by default is 16KHz).
+     */
+    unsigned		clock_rate;
+
+    /**
+     * Clock rate to be applied when opening the sound device.
+     * If value is zero, conference bridge clock rate will be used.
+     */
+    unsigned		snd_clock_rate;
+
+    /**
+     * Channel count be applied when opening the sound device and
+     * conference bridge.
+     */
+    unsigned		channel_count;
+
+    /**
+     * Specify audio frame ptime. The value here will affect the 
+     * samples per frame of both the sound device and the conference
+     * bridge. Specifying lower ptime will normally reduce the
+     * latency.
+     *
+     * Default value: PJSUA_DEFAULT_AUDIO_FRAME_PTIME
+     */
+    unsigned		audio_frame_ptime;
+
+    /**
+     * Specify maximum number of media ports to be created in the
+     * conference bridge. Since all media terminate in the bridge
+     * (calls, file player, file recorder, etc), the value must be
+     * large enough to support all of them. However, the larger
+     * the value, the more computations are performed.
+     *
+     * Default value: PJSUA_MAX_CONF_PORTS
+     */
+    unsigned		max_media_ports;
+
+    /**
+     * Specify whether the media manager should manage its own
+     * ioqueue for the RTP/RTCP sockets. If yes, ioqueue will be created
+     * and at least one worker thread will be created too. If no,
+     * the RTP/RTCP sockets will share the same ioqueue as SIP sockets,
+     * and no worker thread is needed.
+     *
+     * Normally application would say yes here, unless it wants to
+     * run everything from a single thread.
+     */
+    pj_bool_t		has_ioqueue;
+
+    /**
+     * Specify the number of worker threads to handle incoming RTP
+     * packets. A value of one is recommended for most applications.
+     */
+    unsigned		thread_cnt;
+
+    /**
+     * Media quality, 0-10, according to this table:
+     *   5-10: resampling use large filter,
+     *   3-4:  resampling use small filter,
+     *   1-2:  resampling use linear.
+     * The media quality also sets speex codec quality/complexity to the
+     * number.
+     *
+     * Default: 5 (PJSUA_DEFAULT_CODEC_QUALITY).
+     */
+    unsigned		quality;
+
+    /**
+     * Specify default codec ptime.
+     *
+     * Default: 0 (codec specific)
+     */
+    unsigned		ptime;
+
+    /**
+     * Disable VAD?
+     *
+     * Default: 0 (no (meaning VAD is enabled))
+     */
+    pj_bool_t		no_vad;
+
+    /**
+     * iLBC mode (20 or 30).
+     *
+     * Default: 30 (PJSUA_DEFAULT_ILBC_MODE)
+     */
+    unsigned		ilbc_mode;
+
+    /**
+     * Percentage of RTP packet to drop in TX direction
+     * (to simulate packet lost).
+     *
+     * Default: 0
+     */
+    unsigned		tx_drop_pct;
+
+    /**
+     * Percentage of RTP packet to drop in RX direction
+     * (to simulate packet lost).
+     *
+     * Default: 0
+     */
+    unsigned		rx_drop_pct;
+
+    /**
+     * Echo canceller options (see #pjmedia_echo_create())
+     *
+     * Default: 0.
+     */
+    unsigned		ec_options;
+
+    /**
+     * Echo canceller tail length, in miliseconds.
+     *
+     * Default: PJSUA_DEFAULT_EC_TAIL_LEN
+     */
+    unsigned		ec_tail_len;
+
+    /**
+     * Audio capture buffer length, in milliseconds.
+     *
+     * Default: PJMEDIA_SND_DEFAULT_REC_LATENCY
+     */
+    unsigned		snd_rec_latency;
+
+    /**
+     * Audio playback buffer length, in milliseconds.
+     *
+     * Default: PJMEDIA_SND_DEFAULT_PLAY_LATENCY
+     */
+    unsigned		snd_play_latency;
+
+    /** 
+     * Jitter buffer initial prefetch delay in msec. The value must be
+     * between jb_min_pre and jb_max_pre below. If the value is 0,
+     * prefetching will be disabled.
+     *
+     * Default: -1 (to use default stream settings, currently 0)
+     */
+    int			jb_init;
+
+    /**
+     * Jitter buffer minimum prefetch delay in msec.
+     *
+     * Default: -1 (to use default stream settings, currently 60 msec)
+     */
+    int			jb_min_pre;
+    
+    /**
+     * Jitter buffer maximum prefetch delay in msec.
+     *
+     * Default: -1 (to use default stream settings, currently 240 msec)
+     */
+    int			jb_max_pre;
+
+    /**
+     * Set maximum delay that can be accomodated by the jitter buffer msec.
+     *
+     * Default: -1 (to use default stream settings, currently 360 msec)
+     */
+    int			jb_max;
+
+    /**
+     * Enable ICE
+     */
+    pj_bool_t		enable_ice;
+
+    /**
+     * Set the maximum number of host candidates.
+     *
+     * Default: -1 (maximum not set)
+     */
+    int			ice_max_host_cands;
+
+    /**
+     * ICE session options.
+     */
+    pj_ice_sess_options	ice_opt;
+
+    /**
+     * Disable RTCP component.
+     *
+     * Default: no
+     */
+    pj_bool_t		ice_no_rtcp;
+
+    /**
+     * Send re-INVITE/UPDATE every after ICE connectivity check regardless
+     * the default ICE transport address is changed or not. When this is set
+     * to PJ_FALSE, re-INVITE/UPDATE will be sent only when the default ICE
+     * transport address is changed.
+     *
+     * Default: yes
+     */
+    pj_bool_t		ice_always_update;
+
+    /**
+     * Enable TURN relay candidate in ICE.
+     */
+    pj_bool_t		enable_turn;
+
+    /**
+     * Specify TURN domain name or host name, in in "DOMAIN:PORT" or 
+     * "HOST:PORT" format.
+     */
+    pj_str_t		turn_server;
+
+    /**
+     * Specify the connection type to be used to the TURN server. Valid
+     * values are PJ_TURN_TP_UDP or PJ_TURN_TP_TCP.
+     *
+     * Default: PJ_TURN_TP_UDP
+     */
+    pj_turn_tp_type	turn_conn_type;
+
+    /**
+     * Specify the credential to authenticate with the TURN server.
+     */
+    pj_stun_auth_cred	turn_auth_cred;
+
+    /**
+     * Specify idle time of sound device before it is automatically closed,
+     * in seconds. Use value -1 to disable the auto-close feature of sound
+     * device
+     *
+     * Default : 1
+     */
+    int			snd_auto_close_time;
+
+    /**
+     * Specify whether built-in/native preview should be used if available.
+     * In some systems, video input devices have built-in capability to show
+     * preview window of the device. Using this built-in preview is preferable
+     * as it consumes less CPU power. If built-in preview is not available,
+     * the library will perform software rendering of the input. If this
+     * field is set to PJ_FALSE, software preview will always be used.
+     *
+     * Default: PJ_TRUE
+     */
+    pj_bool_t vid_preview_enable_native;
+
+    /**
+     * Disable smart media update (ticket #1568). The smart media update
+     * will check for any changes in the media properties after a successful
+     * SDP negotiation and the media will only be reinitialized when any
+     * change is found. When it is disabled, media streams will always be
+     * reinitialized after a successful SDP negotiation.
+     *
+     * Note for third party media, the smart media update requires stream info
+     * retrieval capability, see #PJSUA_THIRD_PARTY_STREAM_HAS_GET_INFO.
+     *
+     * Default: PJ_FALSE
+     */
+    pj_bool_t no_smart_media_update;
+
+    /**
+     * Omit RTCP SDES and BYE in outgoing RTCP packet, this setting will be
+     * applied for both audio and video streams. Note that, when RTCP SDES
+     * and BYE are set to be omitted, RTCP SDES will still be sent once when
+     * the stream starts/stops and RTCP BYE will be sent once when the stream
+     * stops.
+     *
+     * Default: PJ_FALSE
+     */
+    pj_bool_t no_rtcp_sdes_bye;
+};
+
+
+/**
+ * Use this function to initialize media config.
+ *
+ * @param cfg	The media config to be initialized.
+ */
+PJ_DECL(void) pjsua_media_config_default(pjsua_media_config *cfg);
+
+
+/**
+ * This structure describes codec information, which can be retrieved by
+ * calling #pjsua_enum_codecs().
+ */
+typedef struct pjsua_codec_info
+{
+    /**
+     * Codec unique identification.
+     */
+    pj_str_t		codec_id;
+
+    /**
+     * Codec priority (integer 0-255).
+     */
+    pj_uint8_t		priority;
+
+    /**
+     * Codec description.
+     */
+    pj_str_t		desc;
+
+    /**
+     * Internal buffer.
+     */
+    char		buf_[64];
+
+} pjsua_codec_info;
+
+
+/**
+ * This structure descibes information about a particular media port that
+ * has been registered into the conference bridge. Application can query
+ * this info by calling #pjsua_conf_get_port_info().
+ */
+typedef struct pjsua_conf_port_info
+{
+    /** Conference port number. */
+    pjsua_conf_port_id	slot_id;
+
+    /** Port name. */
+    pj_str_t		name;
+
+    /** Clock rate. */
+    unsigned		clock_rate;
+
+    /** Number of channels. */
+    unsigned		channel_count;
+
+    /** Samples per frame */
+    unsigned		samples_per_frame;
+
+    /** Bits per sample */
+    unsigned		bits_per_sample;
+
+    /** Number of listeners in the array. */
+    unsigned		listener_cnt;
+
+    /** Array of listeners (in other words, ports where this port is 
+     *  transmitting to.
+     */
+    pjsua_conf_port_id	listeners[PJSUA_MAX_CONF_PORTS];
+
+} pjsua_conf_port_info;
+
+
+/**
+ * This structure holds information about custom media transport to
+ * be registered to pjsua.
+ */
+typedef struct pjsua_media_transport
+{
+    /**
+     * Media socket information containing the address information
+     * of the RTP and RTCP socket.
+     */
+    pjmedia_sock_info	 skinfo;
+
+    /**
+     * The media transport instance.
+     */
+    pjmedia_transport	*transport;
+
+} pjsua_media_transport;
+
+
+/**
+ * Get maxinum number of conference ports.
+ *
+ * @return		Maximum number of ports in the conference bridge.
+ */
+PJ_DECL(unsigned) pjsua_conf_get_max_ports(void);
+
+
+/**
+ * Get current number of active ports in the bridge.
+ *
+ * @return		The number.
+ */
+PJ_DECL(unsigned) pjsua_conf_get_active_ports(void);
+
+
+/**
+ * Enumerate all conference ports.
+ *
+ * @param id		Array of conference port ID to be initialized.
+ * @param count		On input, specifies max elements in the array.
+ *			On return, it contains actual number of elements
+ *			that have been initialized.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_enum_conf_ports(pjsua_conf_port_id id[],
+					   unsigned *count);
+
+
+/**
+ * Get information about the specified conference port
+ *
+ * @param port_id	Port identification.
+ * @param info		Pointer to store the port info.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_conf_get_port_info( pjsua_conf_port_id port_id,
+					       pjsua_conf_port_info *info);
+
+
+/**
+ * Add arbitrary media port to PJSUA's conference bridge. Application
+ * can use this function to add the media port that it creates. For
+ * media ports that are created by PJSUA-LIB (such as calls, file player,
+ * or file recorder), PJSUA-LIB will automatically add the port to
+ * the bridge.
+ *
+ * @param pool		Pool to use.
+ * @param port		Media port to be added to the bridge.
+ * @param p_id		Optional pointer to receive the conference 
+ *			slot id.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_conf_add_port(pj_pool_t *pool,
+					 pjmedia_port *port,
+					 pjsua_conf_port_id *p_id);
+
+
+/**
+ * Remove arbitrary slot from the conference bridge. Application should only
+ * call this function if it registered the port manually with previous call
+ * to #pjsua_conf_add_port().
+ *
+ * @param port_id	The slot id of the port to be removed.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_conf_remove_port(pjsua_conf_port_id port_id);
+
+
+/**
+ * Establish unidirectional media flow from souce to sink. One source
+ * may transmit to multiple destinations/sink. And if multiple
+ * sources are transmitting to the same sink, the media will be mixed
+ * together. Source and sink may refer to the same ID, effectively
+ * looping the media.
+ *
+ * If bidirectional media flow is desired, application needs to call
+ * this function twice, with the second one having the arguments
+ * reversed.
+ *
+ * @param source	Port ID of the source media/transmitter.
+ * @param sink		Port ID of the destination media/received.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_conf_connect(pjsua_conf_port_id source,
+					pjsua_conf_port_id sink);
+
+
+/**
+ * Disconnect media flow from the source to destination port.
+ *
+ * @param source	Port ID of the source media/transmitter.
+ * @param sink		Port ID of the destination media/received.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_conf_disconnect(pjsua_conf_port_id source,
+					   pjsua_conf_port_id sink);
+
+
+/**
+ * Adjust the signal level to be transmitted from the bridge to the 
+ * specified port by making it louder or quieter.
+ *
+ * @param slot		The conference bridge slot number.
+ * @param level		Signal level adjustment. Value 1.0 means no level
+ *			adjustment, while value 0 means to mute the port.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_conf_adjust_tx_level(pjsua_conf_port_id slot,
+						float level);
+
+/**
+ * Adjust the signal level to be received from the specified port (to
+ * the bridge) by making it louder or quieter.
+ *
+ * @param slot		The conference bridge slot number.
+ * @param level		Signal level adjustment. Value 1.0 means no level
+ *			adjustment, while value 0 means to mute the port.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_conf_adjust_rx_level(pjsua_conf_port_id slot,
+						float level);
+
+/**
+ * Get last signal level transmitted to or received from the specified port.
+ * The signal level is an integer value in zero to 255, with zero indicates
+ * no signal, and 255 indicates the loudest signal level.
+ *
+ * @param slot		The conference bridge slot number.
+ * @param tx_level	Optional argument to receive the level of signal
+ *			transmitted to the specified port (i.e. the direction
+ *			is from the bridge to the port).
+ * @param rx_level	Optional argument to receive the level of signal
+ *			received from the port (i.e. the direction is from the
+ *			port to the bridge).
+ *
+ * @return		PJ_SUCCESS on success.
+ */
+PJ_DECL(pj_status_t) pjsua_conf_get_signal_level(pjsua_conf_port_id slot,
+						 unsigned *tx_level,
+						 unsigned *rx_level);
+
+
+/*****************************************************************************
+ * File player and playlist.
+ */
+
+/**
+ * Create a file player, and automatically add this player to
+ * the conference bridge.
+ *
+ * @param filename	The filename to be played. Currently only
+ *			WAV files are supported, and the WAV file MUST be
+ *			formatted as 16bit PCM mono/single channel (any
+ *			clock rate is supported).
+ * @param options	Optional option flag. Application may specify
+ *			PJMEDIA_FILE_NO_LOOP to prevent playback loop.
+ * @param p_id		Pointer to receive player ID.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_player_create(const pj_str_t *filename,
+					 unsigned options,
+					 pjsua_player_id *p_id);
+
+
+/**
+ * Create a file playlist media port, and automatically add the port
+ * to the conference bridge.
+ *
+ * @param file_names	Array of file names to be added to the play list.
+ *			Note that the files must have the same clock rate,
+ *			number of channels, and number of bits per sample.
+ * @param file_count	Number of files in the array.
+ * @param label		Optional label to be set for the media port.
+ * @param options	Optional option flag. Application may specify
+ *			PJMEDIA_FILE_NO_LOOP to prevent looping.
+ * @param p_id		Optional pointer to receive player ID.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_playlist_create(const pj_str_t file_names[],
+					   unsigned file_count,
+					   const pj_str_t *label,
+					   unsigned options,
+					   pjsua_player_id *p_id);
+
+/**
+ * Get conference port ID associated with player or playlist.
+ *
+ * @param id		The file player ID.
+ *
+ * @return		Conference port ID associated with this player.
+ */
+PJ_DECL(pjsua_conf_port_id) pjsua_player_get_conf_port(pjsua_player_id id);
+
+
+/**
+ * Get the media port for the player or playlist.
+ *
+ * @param id		The player ID.
+ * @param p_port	The media port associated with the player.
+ *
+ * @return		PJ_SUCCESS on success.
+ */
+PJ_DECL(pj_status_t) pjsua_player_get_port(pjsua_player_id id,
+					   pjmedia_port **p_port);
+
+/**
+ * Set playback position. This operation is not valid for playlist.
+ *
+ * @param id		The file player ID.
+ * @param samples	The playback position, in samples. Application can
+ *			specify zero to re-start the playback.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_player_set_pos(pjsua_player_id id,
+					  pj_uint32_t samples);
+
+
+/**
+ * Close the file of playlist, remove the player from the bridge, and free
+ * resources associated with the file player or playlist.
+ *
+ * @param id		The file player ID.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_player_destroy(pjsua_player_id id);
+
+
+/*****************************************************************************
+ * File recorder.
+ */
+
+/**
+ * Create a file recorder, and automatically connect this recorder to
+ * the conference bridge. The recorder currently supports recording WAV file.
+ * The type of the recorder to use is determined by the extension of the file 
+ * (e.g. ".wav").
+ *
+ * @param filename	Output file name. The function will determine the
+ *			default format to be used based on the file extension.
+ *			Currently ".wav" is supported on all platforms.
+ * @param enc_type	Optionally specify the type of encoder to be used to
+ *			compress the media, if the file can support different
+ *			encodings. This value must be zero for now.
+ * @param enc_param	Optionally specify codec specific parameter to be 
+ *			passed to the file writer. 
+ *			For .WAV recorder, this value must be NULL.
+ * @param max_size	Maximum file size. Specify zero or -1 to remove size
+ *			limitation. This value must be zero or -1 for now.
+ * @param options	Optional options.
+ * @param p_id		Pointer to receive the recorder instance.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_recorder_create(const pj_str_t *filename,
+					   unsigned enc_type,
+					   void *enc_param,
+					   pj_ssize_t max_size,
+					   unsigned options,
+					   pjsua_recorder_id *p_id);
+
+
+/**
+ * Get conference port associated with recorder.
+ *
+ * @param id		The recorder ID.
+ *
+ * @return		Conference port ID associated with this recorder.
+ */
+PJ_DECL(pjsua_conf_port_id) pjsua_recorder_get_conf_port(pjsua_recorder_id id);
+
+
+/**
+ * Get the media port for the recorder.
+ *
+ * @param id		The recorder ID.
+ * @param p_port	The media port associated with the recorder.
+ *
+ * @return		PJ_SUCCESS on success.
+ */
+PJ_DECL(pj_status_t) pjsua_recorder_get_port(pjsua_recorder_id id,
+					     pjmedia_port **p_port);
+
+
+/**
+ * Destroy recorder (this will complete recording).
+ *
+ * @param id		The recorder ID.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_recorder_destroy(pjsua_recorder_id id);
+
+
+/*****************************************************************************
+ * Sound devices.
+ */
+
+/**
+ * Enum all audio devices installed in the system.
+ *
+ * @param info		Array of info to be initialized.
+ * @param count		On input, specifies max elements in the array.
+ *			On return, it contains actual number of elements
+ *			that have been initialized.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_enum_aud_devs(pjmedia_aud_dev_info info[],
+					 unsigned *count);
+
+/**
+ * Enum all sound devices installed in the system (old API).
+ *
+ * @param info		Array of info to be initialized.
+ * @param count		On input, specifies max elements in the array.
+ *			On return, it contains actual number of elements
+ *			that have been initialized.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_enum_snd_devs(pjmedia_snd_dev_info info[],
+					 unsigned *count);
+
+/**
+ * Get currently active sound devices. If sound devices has not been created
+ * (for example when pjsua_start() is not called), it is possible that
+ * the function returns PJ_SUCCESS with -1 as device IDs.
+ *
+ * @param capture_dev   On return it will be filled with device ID of the 
+ *			capture device.
+ * @param playback_dev	On return it will be filled with device ID of the 
+ *			device ID of the playback device.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_get_snd_dev(int *capture_dev,
+				       int *playback_dev);
+
+
+/**
+ * Select or change sound device. Application may call this function at
+ * any time to replace current sound device.
+ *
+ * @param capture_dev   Device ID of the capture device.
+ * @param playback_dev	Device ID of the playback device.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_set_snd_dev(int capture_dev,
+				       int playback_dev);
+
+
+/**
+ * Set pjsua to use null sound device. The null sound device only provides
+ * the timing needed by the conference bridge, and will not interract with
+ * any hardware.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_set_null_snd_dev(void);
+
+
+/**
+ * Disconnect the main conference bridge from any sound devices, and let
+ * application connect the bridge to it's own sound device/master port.
+ *
+ * @return		The port interface of the conference bridge, 
+ *			so that application can connect this to it's own
+ *			sound device or master port.
+ */
+PJ_DECL(pjmedia_port*) pjsua_set_no_snd_dev(void);
+
+
+/**
+ * Change the echo cancellation settings.
+ *
+ * The behavior of this function depends on whether the sound device is
+ * currently active, and if it is, whether device or software AEC is 
+ * being used. 
+ *
+ * If the sound device is currently active, and if the device supports AEC,
+ * this function will forward the change request to the device and it will
+ * be up to the device on whether support the request. If software AEC is
+ * being used (the software EC will be used if the device does not support
+ * AEC), this function will change the software EC settings. In all cases,
+ * the setting will be saved for future opening of the sound device.
+ *
+ * If the sound device is not currently active, this will only change the
+ * default AEC settings and the setting will be applied next time the 
+ * sound device is opened.
+ *
+ * @param tail_ms	The tail length, in miliseconds. Set to zero to
+ *			disable AEC.
+ * @param options	Options to be passed to pjmedia_echo_create().
+ *			Normally the value should be zero.
+ *
+ * @return		PJ_SUCCESS on success.
+ */
+PJ_DECL(pj_status_t) pjsua_set_ec(unsigned tail_ms, unsigned options);
+
+
+/**
+ * Get current echo canceller tail length. 
+ *
+ * @param p_tail_ms	Pointer to receive the tail length, in miliseconds. 
+ *			If AEC is disabled, the value will be zero.
+ *
+ * @return		PJ_SUCCESS on success.
+ */
+PJ_DECL(pj_status_t) pjsua_get_ec_tail(unsigned *p_tail_ms);
+
+
+/**
+ * Check whether the sound device is currently active. The sound device
+ * may be inactive if the application has set the auto close feature to
+ * non-zero (the snd_auto_close_time setting in #pjsua_media_config), or
+ * if null sound device or no sound device has been configured via the
+ * #pjsua_set_no_snd_dev() function.
+ */
+PJ_DECL(pj_bool_t) pjsua_snd_is_active(void);
+
+    
+/**
+ * Configure sound device setting to the sound device being used. If sound 
+ * device is currently active, the function will forward the setting to the
+ * sound device instance to be applied immediately, if it supports it. 
+ *
+ * The setting will be saved for future opening of the sound device, if the 
+ * "keep" argument is set to non-zero. If the sound device is currently
+ * inactive, and the "keep" argument is false, this function will return
+ * error.
+ * 
+ * Note that in case the setting is kept for future use, it will be applied
+ * to any devices, even when application has changed the sound device to be
+ * used.
+ *
+ * Note also that the echo cancellation setting should be set with 
+ * #pjsua_set_ec() API instead.
+ *
+ * See also #pjmedia_aud_stream_set_cap() for more information about setting
+ * an audio device capability.
+ *
+ * @param cap		The sound device setting to change.
+ * @param pval		Pointer to value. Please see #pjmedia_aud_dev_cap
+ *			documentation about the type of value to be 
+ *			supplied for each setting.
+ * @param keep		Specify whether the setting is to be kept for future
+ *			use.
+ *
+ * @return		PJ_SUCCESS on success or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_snd_set_setting(pjmedia_aud_dev_cap cap,
+					   const void *pval,
+					   pj_bool_t keep);
+
+/**
+ * Retrieve a sound device setting. If sound device is currently active,
+ * the function will forward the request to the sound device. If sound device
+ * is currently inactive, and if application had previously set the setting
+ * and mark the setting as kept, then that setting will be returned.
+ * Otherwise, this function will return error.
+ *
+ * Note that echo cancellation settings should be retrieved with 
+ * #pjsua_get_ec_tail() API instead.
+ *
+ * @param cap		The sound device setting to retrieve.
+ * @param pval		Pointer to receive the value. 
+ *			Please see #pjmedia_aud_dev_cap documentation about
+ *			the type of value to be supplied for each setting.
+ *
+ * @return		PJ_SUCCESS on success or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_snd_get_setting(pjmedia_aud_dev_cap cap,
+					   void *pval);
+
+
+/*****************************************************************************
+ * Codecs.
+ */
+
+/**
+ * Enum all supported codecs in the system.
+ *
+ * @param id		Array of ID to be initialized.
+ * @param count		On input, specifies max elements in the array.
+ *			On return, it contains actual number of elements
+ *			that have been initialized.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_enum_codecs( pjsua_codec_info id[],
+				        unsigned *count );
+
+
+/**
+ * Change codec priority.
+ *
+ * @param codec_id	Codec ID, which is a string that uniquely identify
+ *			the codec (such as "speex/8000"). Please see pjsua
+ *			manual or pjmedia codec reference for details.
+ * @param priority	Codec priority, 0-255, where zero means to disable
+ *			the codec.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_codec_set_priority( const pj_str_t *codec_id,
+					       pj_uint8_t priority );
+
+
+/**
+ * Get codec parameters.
+ *
+ * @param codec_id	Codec ID.
+ * @param param		Structure to receive codec parameters.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_codec_get_param( const pj_str_t *codec_id,
+					    pjmedia_codec_param *param );
+
+
+/**
+ * Set codec parameters.
+ *
+ * @param codec_id	Codec ID.
+ * @param param		Codec parameter to set. Set to NULL to reset
+ *			codec parameter to library default settings.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_codec_set_param( const pj_str_t *codec_id,
+					    const pjmedia_codec_param *param);
+
+
+#if DISABLED_FOR_TICKET_1185
+/**
+ * Create UDP media transports for all the calls. This function creates
+ * one UDP media transport for each call.
+ *
+ * @param cfg		Media transport configuration. The "port" field in the
+ *			configuration is used as the start port to bind the
+ *			sockets.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t)
+pjsua_media_transports_create(const pjsua_transport_config *cfg);
+
+
+/**
+ * Register custom media transports to be used by calls. There must
+ * enough media transports for all calls.
+ *
+ * @param tp		The media transport array.
+ * @param count		Number of elements in the array. This number MUST
+ *			match the number of maximum calls configured when
+ *			pjsua is created.
+ * @param auto_delete	Flag to indicate whether the transports should be
+ *			destroyed when pjsua is shutdown.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t)
+pjsua_media_transports_attach( pjsua_media_transport tp[],
+			       unsigned count,
+			       pj_bool_t auto_delete);
+#endif
+
+
+/* end of MEDIA API */
+/**
+ * @}
+ */
+
+
+/*****************************************************************************
+ * VIDEO API
+ */
+
+
+/**
+ * @defgroup PJSUA_LIB_VIDEO PJSUA-API Video
+ * @ingroup PJSUA_LIB
+ * @brief Video support
+ * @{
+ */
+
+/*
+ * Video devices API
+ */
+
+/**
+ * Get the number of video devices installed in the system.
+ *
+ * @return		The number of devices.
+ */
+PJ_DECL(unsigned) pjsua_vid_dev_count(void);
+
+/**
+ * Retrieve the video device info for the specified device index.
+ *
+ * @param id		The device index.
+ * @param vdi		Device info to be initialized.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_vid_dev_get_info(pjmedia_vid_dev_index id,
+                                            pjmedia_vid_dev_info *vdi);
+
+/**
+ * Enum all video devices installed in the system.
+ *
+ * @param info		Array of info to be initialized.
+ * @param count		On input, specifies max elements in the array.
+ *			On return, it contains actual number of elements
+ *			that have been initialized.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_vid_enum_devs(pjmedia_vid_dev_info info[],
+					 unsigned *count);
+
+
+/*
+ * Video preview API
+ */
+
+/**
+ * Parameters for starting video preview with pjsua_vid_preview_start().
+ * Application should initialize this structure with
+ * pjsua_vid_preview_param_default().
+ */
+typedef struct pjsua_vid_preview_param
+{
+    /**
+     * Device ID for the video renderer to be used for rendering the
+     * capture stream for preview. This parameter is ignored if native
+     * preview is being used.
+     *
+     * Default: PJMEDIA_VID_DEFAULT_RENDER_DEV
+     */
+    pjmedia_vid_dev_index	rend_id;
+
+    /**
+     * Show window initially.
+     *
+     * Default: PJ_TRUE.
+     */
+    pj_bool_t			show;
+
+    /**
+     * Window flags.  The value is a bitmask combination of
+     * #pjmedia_vid_dev_wnd_flag.
+     *
+     * Default: 0.
+     */
+    unsigned			wnd_flags;
+
+} pjsua_vid_preview_param;
+
+
+/**
+ * Initialize pjsua_vid_preview_param
+ *
+ * @param p		The parameter to be initialized.
+ */
+PJ_DECL(void) pjsua_vid_preview_param_default(pjsua_vid_preview_param *p);
+
+/**
+ * Determine if the specified video input device has built-in native
+ * preview capability. This is a convenience function that is equal to
+ * querying device's capability for PJMEDIA_VID_DEV_CAP_INPUT_PREVIEW
+ * capability.
+ *
+ * @param id		The capture device ID.
+ *
+ * @return		PJ_TRUE if it has.
+ */
+PJ_DECL(pj_bool_t) pjsua_vid_preview_has_native(pjmedia_vid_dev_index id);
+
+/**
+ * Start video preview window for the specified capture device.
+ *
+ * @param id		The capture device ID where its preview will be
+ * 			started.
+ * @param p		Optional video preview parameters. Specify NULL
+ * 			to use default values.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_vid_preview_start(pjmedia_vid_dev_index id,
+                                             const pjsua_vid_preview_param *p);
+
+/**
+ * Get the preview window handle associated with the capture device, if any.
+ *
+ * @param id		The capture device ID.
+ *
+ * @return		The window ID of the preview window for the
+ * 			specified capture device ID, or PJSUA_INVALID_ID if
+ * 			preview has not been started for the device.
+ */
+PJ_DECL(pjsua_vid_win_id) pjsua_vid_preview_get_win(pjmedia_vid_dev_index id);
+
+/**
+ * Stop video preview.
+ *
+ * @param id		The capture device ID.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_vid_preview_stop(pjmedia_vid_dev_index id);
+
+
+/*
+ * Video window manipulation API.
+ */
+
+/**
+ * This structure describes video window info.
+ */
+typedef struct pjsua_vid_win_info
+{
+    /**
+     * Flag to indicate whether this window is a native window,
+     * such as created by built-in preview device. If this field is
+     * PJ_TRUE, only the native window handle field of this
+     * structure is valid.
+     */
+    pj_bool_t is_native;
+
+    /**
+     * Native window handle.
+     */
+    pjmedia_vid_dev_hwnd hwnd;
+
+    /**
+     * Renderer device ID.
+     */
+    pjmedia_vid_dev_index rdr_dev;
+
+    /**
+     * Window show status. The window is hidden if false.
+     */
+    pj_bool_t	show;
+
+    /**
+     * Window position.
+     */
+    pjmedia_coord pos;
+
+    /**
+     * Window size.
+     */
+    pjmedia_rect_size size;
+
+} pjsua_vid_win_info;
+
+
+/**
+ * Enumerates all video windows.
+ *
+ * @param id		Array of window ID to be initialized.
+ * @param count		On input, specifies max elements in the array.
+ *			On return, it contains actual number of elements
+ *			that have been initialized.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_vid_enum_wins(pjsua_vid_win_id wids[],
+					 unsigned *count);
+
+
+/**
+ * Get window info.
+ *
+ * @param wid		The video window ID.
+ * @param wi		The video window info to be initialized.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_vid_win_get_info(pjsua_vid_win_id wid,
+                                            pjsua_vid_win_info *wi);
+
+/**
+ * Show or hide window. This operation is not valid for native windows
+ * (pjsua_vid_win_info.is_native=PJ_TRUE), on which native windowing API
+ * must be used instead.
+ *
+ * @param wid		The video window ID.
+ * @param show		Set to PJ_TRUE to show the window, PJ_FALSE to
+ * 			hide the window.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_vid_win_set_show(pjsua_vid_win_id wid,
+                                            pj_bool_t show);
+
+/**
+ * Set video window position. This operation is not valid for native windows
+ * (pjsua_vid_win_info.is_native=PJ_TRUE), on which native windowing API
+ * must be used instead.
+ *
+ * @param wid		The video window ID.
+ * @param pos		The window position.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_vid_win_set_pos(pjsua_vid_win_id wid,
+                                           const pjmedia_coord *pos);
+
+/**
+ * Resize window. This operation is not valid for native windows
+ * (pjsua_vid_win_info.is_native=PJ_TRUE), on which native windowing API
+ * must be used instead.
+ *
+ * @param wid		The video window ID.
+ * @param size		The new window size.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_vid_win_set_size(pjsua_vid_win_id wid,
+                                            const pjmedia_rect_size *size);
+
+/**
+ * Rotate the video window. This function will change the video orientation
+ * and also possibly the video window size (width and height get swapped).
+ * This operation is not valid for native windows (pjsua_vid_win_info.is_native
+ * =PJ_TRUE), on which native windowing API must be used instead.
+ *
+ * @param wid		The video window ID.
+ * @param angle		The rotation angle in degrees, must be multiple of 90.
+ *			Specify positive value for clockwise rotation or
+ *			negative value for counter-clockwise rotation.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_vid_win_rotate(pjsua_vid_win_id wid,
+					  int angle);
+
+
+/*
+ * Video codecs API
+ */
+
+/**
+ * Enum all supported video codecs in the system.
+ *
+ * @param id		Array of ID to be initialized.
+ * @param count		On input, specifies max elements in the array.
+ *			On return, it contains actual number of elements
+ *			that have been initialized.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_vid_enum_codecs( pjsua_codec_info id[],
+					    unsigned *count );
+
+
+/**
+ * Change video codec priority.
+ *
+ * @param codec_id	Codec ID, which is a string that uniquely identify
+ *			the codec (such as "H263/90000"). Please see pjsua
+ *			manual or pjmedia codec reference for details.
+ * @param priority	Codec priority, 0-255, where zero means to disable
+ *			the codec.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_vid_codec_set_priority( const pj_str_t *codec_id,
+						   pj_uint8_t priority );
+
+
+/**
+ * Get video codec parameters.
+ *
+ * @param codec_id	Codec ID.
+ * @param param		Structure to receive video codec parameters.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_vid_codec_get_param(
+					const pj_str_t *codec_id,
+					pjmedia_vid_codec_param *param);
+
+
+/**
+ * Set video codec parameters.
+ *
+ * @param codec_id	Codec ID.
+ * @param param		Codec parameter to set. Set to NULL to reset
+ *			codec parameter to library default settings.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_vid_codec_set_param( 
+					const pj_str_t *codec_id,
+					const pjmedia_vid_codec_param *param);
+
+
+
+/* end of VIDEO API */
+/**
+ * @}
+ */
+
+
+/**
+ * @}
+ */
+
+PJ_END_DECL
+
+
+#endif	/* __PJSUA_H__ */
diff --git a/jni/pjproject-android/.svn/pristine/84/844ed8fc74f187393f3f1490482e8c70d5709faf.svn-base b/jni/pjproject-android/.svn/pristine/84/844ed8fc74f187393f3f1490482e8c70d5709faf.svn-base
new file mode 100644
index 0000000..aa2cf19
--- /dev/null
+++ b/jni/pjproject-android/.svn/pristine/84/844ed8fc74f187393f3f1490482e8c70d5709faf.svn-base
@@ -0,0 +1,1782 @@
+#! /bin/sh
+# Configuration validation subroutine script.
+#   Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
+#   2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
+#   2011, 2012 Free Software Foundation, Inc.
+
+timestamp='2012-06-17'
+
+# This file is (in principle) common to ALL GNU software.
+# The presence of a machine in this file suggests that SOME GNU software
+# can handle that machine.  It does not imply ALL GNU software can.
+#
+# This file 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, see <http://www.gnu.org/licenses/>.
+#
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that program.
+
+
+# Please send patches to <config-patches@gnu.org>.  Submit a context
+# diff and a properly formatted GNU ChangeLog entry.
+#
+# Configuration subroutine to validate and canonicalize a configuration type.
+# Supply the specified configuration type as an argument.
+# If it is invalid, we print an error message on stderr and exit with code 1.
+# Otherwise, we print the canonical config type on stdout and succeed.
+
+# You can get the latest version of this script from:
+# http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD
+
+# This file is supposed to be the same for all GNU packages
+# and recognize all the CPU types, system types and aliases
+# that are meaningful with *any* GNU software.
+# Each package is responsible for reporting which valid configurations
+# it does not support.  The user should be able to distinguish
+# a failure to support a valid configuration from a meaningless
+# configuration.
+
+# The goal of this file is to map all the various variations of a given
+# machine specification into a single specification in the form:
+#	CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM
+# or in some cases, the newer four-part form:
+#	CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM
+# It is wrong to echo any other type of specification.
+
+me=`echo "$0" | sed -e 's,.*/,,'`
+
+usage="\
+Usage: $0 [OPTION] CPU-MFR-OPSYS
+       $0 [OPTION] ALIAS
+
+Canonicalize a configuration name.
+
+Operation modes:
+  -h, --help         print this help, then exit
+  -t, --time-stamp   print date of last modification, then exit
+  -v, --version      print version number, then exit
+
+Report bugs and patches to <config-patches@gnu.org>."
+
+version="\
+GNU config.sub ($timestamp)
+
+Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
+2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
+Free Software Foundation, Inc.
+
+This is free software; see the source for copying conditions.  There is NO
+warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
+
+help="
+Try \`$me --help' for more information."
+
+# Parse command line
+while test $# -gt 0 ; do
+  case $1 in
+    --time-stamp | --time* | -t )
+       echo "$timestamp" ; exit ;;
+    --version | -v )
+       echo "$version" ; exit ;;
+    --help | --h* | -h )
+       echo "$usage"; exit ;;
+    -- )     # Stop option processing
+       shift; break ;;
+    - )	# Use stdin as input.
+       break ;;
+    -* )
+       echo "$me: invalid option $1$help"
+       exit 1 ;;
+
+    *local*)
+       # First pass through any local machine types.
+       echo $1
+       exit ;;
+
+    * )
+       break ;;
+  esac
+done
+
+case $# in
+ 0) echo "$me: missing argument$help" >&2
+    exit 1;;
+ 1) ;;
+ *) echo "$me: too many arguments$help" >&2
+    exit 1;;
+esac
+
+# Separate what the user gave into CPU-COMPANY and OS or KERNEL-OS (if any).
+# Here we must recognize all the valid KERNEL-OS combinations.
+maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'`
+case $maybe_os in
+  nto-qnx* | linux-gnu* | linux-android* | linux-dietlibc | linux-newlib* | \
+  linux-uclibc* | uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | \
+  knetbsd*-gnu* | netbsd*-gnu* | \
+  kopensolaris*-gnu* | \
+  storm-chaos* | os2-emx* | rtmk-nova*)
+    os=-$maybe_os
+    basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`
+    ;;
+  android-linux)
+    os=-linux-android
+    basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`-unknown
+    ;;
+  *)
+    basic_machine=`echo $1 | sed 's/-[^-]*$//'`
+    if [ $basic_machine != $1 ]
+    then os=`echo $1 | sed 's/.*-/-/'`
+    else os=; fi
+    ;;
+esac
+
+### Let's recognize common machines as not being operating systems so
+### that things like config.sub decstation-3100 work.  We also
+### recognize some manufacturers as not being operating systems, so we
+### can provide default operating systems below.
+case $os in
+	-sun*os*)
+		# Prevent following clause from handling this invalid input.
+		;;
+	-dec* | -mips* | -sequent* | -encore* | -pc532* | -sgi* | -sony* | \
+	-att* | -7300* | -3300* | -delta* | -motorola* | -sun[234]* | \
+	-unicom* | -ibm* | -next | -hp | -isi* | -apollo | -altos* | \
+	-convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\
+	-c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \
+	-harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \
+	-apple | -axis | -knuth | -cray | -microblaze)
+		os=
+		basic_machine=$1
+		;;
+	-bluegene*)
+		os=-cnk
+		;;
+	-sim | -cisco | -oki | -wec | -winbond)
+		os=
+		basic_machine=$1
+		;;
+	-scout)
+		;;
+	-wrs)
+		os=-vxworks
+		basic_machine=$1
+		;;
+	-chorusos*)
+		os=-chorusos
+		basic_machine=$1
+		;;
+	-chorusrdb)
+		os=-chorusrdb
+		basic_machine=$1
+		;;
+	-hiux*)
+		os=-hiuxwe2
+		;;
+	-sco6)
+		os=-sco5v6
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-sco5)
+		os=-sco3.2v5
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-sco4)
+		os=-sco3.2v4
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-sco3.2.[4-9]*)
+		os=`echo $os | sed -e 's/sco3.2./sco3.2v/'`
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-sco3.2v[4-9]*)
+		# Don't forget version if it is 3.2v4 or newer.
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-sco5v6*)
+		# Don't forget version if it is 3.2v4 or newer.
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-sco*)
+		os=-sco3.2v2
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-udk*)
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-isc)
+		os=-isc2.2
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-clix*)
+		basic_machine=clipper-intergraph
+		;;
+	-isc*)
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-lynx*178)
+		os=-lynxos178
+		;;
+	-lynx*5)
+		os=-lynxos5
+		;;
+	-lynx*)
+		os=-lynxos
+		;;
+	-ptx*)
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-sequent/'`
+		;;
+	-windowsnt*)
+		os=`echo $os | sed -e 's/windowsnt/winnt/'`
+		;;
+	-psos*)
+		os=-psos
+		;;
+	-mint | -mint[0-9]*)
+		basic_machine=m68k-atari
+		os=-mint
+		;;
+esac
+
+# Decode aliases for certain CPU-COMPANY combinations.
+case $basic_machine in
+	# Recognize the basic CPU types without company name.
+	# Some are omitted here because they have special meanings below.
+	1750a | 580 \
+	| a29k \
+	| aarch64 | aarch64_be \
+	| alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \
+	| alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \
+	| am33_2.0 \
+	| arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr | avr32 \
+        | be32 | be64 \
+	| bfin \
+	| c4x | clipper \
+	| d10v | d30v | dlx | dsp16xx \
+	| epiphany \
+	| fido | fr30 | frv \
+	| h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \
+	| hexagon \
+	| i370 | i860 | i960 | ia64 \
+	| ip2k | iq2000 \
+	| le32 | le64 \
+	| lm32 \
+	| m32c | m32r | m32rle | m68000 | m68k | m88k \
+	| maxq | mb | microblaze | mcore | mep | metag \
+	| mips | mipsbe | mipseb | mipsel | mipsle \
+	| mips16 \
+	| mips64 | mips64el \
+	| mips64octeon | mips64octeonel \
+	| mips64orion | mips64orionel \
+	| mips64r5900 | mips64r5900el \
+	| mips64vr | mips64vrel \
+	| mips64vr4100 | mips64vr4100el \
+	| mips64vr4300 | mips64vr4300el \
+	| mips64vr5000 | mips64vr5000el \
+	| mips64vr5900 | mips64vr5900el \
+	| mipsisa32 | mipsisa32el \
+	| mipsisa32r2 | mipsisa32r2el \
+	| mipsisa64 | mipsisa64el \
+	| mipsisa64r2 | mipsisa64r2el \
+	| mipsisa64sb1 | mipsisa64sb1el \
+	| mipsisa64sr71k | mipsisa64sr71kel \
+	| mipstx39 | mipstx39el \
+	| mn10200 | mn10300 \
+	| moxie \
+	| mt \
+	| msp430 \
+	| nds32 | nds32le | nds32be \
+	| nios | nios2 \
+	| ns16k | ns32k \
+	| open8 \
+	| or32 \
+	| pdp10 | pdp11 | pj | pjl \
+	| powerpc | powerpc64 | powerpc64le | powerpcle \
+	| pyramid \
+	| rl78 | rx \
+	| score \
+	| sh | sh[1234] | sh[24]a | sh[24]aeb | sh[23]e | sh[34]eb | sheb | shbe | shle | sh[1234]le | sh3ele \
+	| sh64 | sh64le \
+	| sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \
+	| sparcv8 | sparcv9 | sparcv9b | sparcv9v \
+	| spu \
+	| tahoe | tic4x | tic54x | tic55x | tic6x | tic80 | tron \
+	| ubicom32 \
+	| v850 | v850e | v850e1 | v850e2 | v850es | v850e2v3 \
+	| we32k \
+	| x86 | xc16x | xstormy16 | xtensa \
+	| z8k | z80)
+		basic_machine=$basic_machine-unknown
+		;;
+	c54x)
+		basic_machine=tic54x-unknown
+		;;
+	c55x)
+		basic_machine=tic55x-unknown
+		;;
+	c6x)
+		basic_machine=tic6x-unknown
+		;;
+	m6811 | m68hc11 | m6812 | m68hc12 | m68hcs12x | picochip)
+		basic_machine=$basic_machine-unknown
+		os=-none
+		;;
+	m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65 | z8k)
+		;;
+	ms1)
+		basic_machine=mt-unknown
+		;;
+
+	strongarm | thumb | xscale)
+		basic_machine=arm-unknown
+		;;
+	xgate)
+		basic_machine=$basic_machine-unknown
+		os=-none
+		;;
+	xscaleeb)
+		basic_machine=armeb-unknown
+		;;
+
+	xscaleel)
+		basic_machine=armel-unknown
+		;;
+
+	# We use `pc' rather than `unknown'
+	# because (1) that's what they normally are, and
+	# (2) the word "unknown" tends to confuse beginning users.
+	i*86 | x86_64)
+	  basic_machine=$basic_machine-pc
+	  ;;
+	# Object if more than one company name word.
+	*-*-*)
+		echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2
+		exit 1
+		;;
+	# Recognize the basic CPU types with company name.
+	580-* \
+	| a29k-* \
+	| aarch64-* | aarch64_be-* \
+	| alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \
+	| alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \
+	| alphapca5[67]-* | alpha64pca5[67]-* | arc-* \
+	| arm-*  | armbe-* | armle-* | armeb-* | armv*-* \
+	| avr-* | avr32-* \
+	| be32-* | be64-* \
+	| bfin-* | bs2000-* \
+	| c[123]* | c30-* | [cjt]90-* | c4x-* \
+	| clipper-* | craynv-* | cydra-* \
+	| d10v-* | d30v-* | dlx-* \
+	| elxsi-* \
+	| f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \
+	| h8300-* | h8500-* \
+	| hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \
+	| hexagon-* \
+	| i*86-* | i860-* | i960-* | ia64-* \
+	| ip2k-* | iq2000-* \
+	| le32-* | le64-* \
+	| lm32-* \
+	| m32c-* | m32r-* | m32rle-* \
+	| m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \
+	| m88110-* | m88k-* | maxq-* | mcore-* | metag-* | microblaze-* \
+	| mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \
+	| mips16-* \
+	| mips64-* | mips64el-* \
+	| mips64octeon-* | mips64octeonel-* \
+	| mips64orion-* | mips64orionel-* \
+	| mips64r5900-* | mips64r5900el-* \
+	| mips64vr-* | mips64vrel-* \
+	| mips64vr4100-* | mips64vr4100el-* \
+	| mips64vr4300-* | mips64vr4300el-* \
+	| mips64vr5000-* | mips64vr5000el-* \
+	| mips64vr5900-* | mips64vr5900el-* \
+	| mipsisa32-* | mipsisa32el-* \
+	| mipsisa32r2-* | mipsisa32r2el-* \
+	| mipsisa64-* | mipsisa64el-* \
+	| mipsisa64r2-* | mipsisa64r2el-* \
+	| mipsisa64sb1-* | mipsisa64sb1el-* \
+	| mipsisa64sr71k-* | mipsisa64sr71kel-* \
+	| mipstx39-* | mipstx39el-* \
+	| mmix-* \
+	| mt-* \
+	| msp430-* \
+	| nds32-* | nds32le-* | nds32be-* \
+	| nios-* | nios2-* \
+	| none-* | np1-* | ns16k-* | ns32k-* \
+	| open8-* \
+	| orion-* \
+	| pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \
+	| powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* \
+	| pyramid-* \
+	| rl78-* | romp-* | rs6000-* | rx-* \
+	| sh-* | sh[1234]-* | sh[24]a-* | sh[24]aeb-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \
+	| shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \
+	| sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \
+	| sparclite-* \
+	| sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | sv1-* | sx?-* \
+	| tahoe-* \
+	| tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \
+	| tile*-* \
+	| tron-* \
+	| ubicom32-* \
+	| v850-* | v850e-* | v850e1-* | v850es-* | v850e2-* | v850e2v3-* \
+	| vax-* \
+	| we32k-* \
+	| x86-* | x86_64-* | xc16x-* | xps100-* \
+	| xstormy16-* | xtensa*-* \
+	| ymp-* \
+	| z8k-* | z80-*)
+		;;
+	# Recognize the basic CPU types without company name, with glob match.
+	xtensa*)
+		basic_machine=$basic_machine-unknown
+		;;
+	# Recognize the various machine names and aliases which stand
+	# for a CPU type and a company and sometimes even an OS.
+	386bsd)
+		basic_machine=i386-unknown
+		os=-bsd
+		;;
+	3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc)
+		basic_machine=m68000-att
+		;;
+	3b*)
+		basic_machine=we32k-att
+		;;
+	a29khif)
+		basic_machine=a29k-amd
+		os=-udi
+		;;
+	abacus)
+		basic_machine=abacus-unknown
+		;;
+	adobe68k)
+		basic_machine=m68010-adobe
+		os=-scout
+		;;
+	alliant | fx80)
+		basic_machine=fx80-alliant
+		;;
+	altos | altos3068)
+		basic_machine=m68k-altos
+		;;
+	am29k)
+		basic_machine=a29k-none
+		os=-bsd
+		;;
+	amd64)
+		basic_machine=x86_64-pc
+		;;
+	amd64-*)
+		basic_machine=x86_64-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	amdahl)
+		basic_machine=580-amdahl
+		os=-sysv
+		;;
+	amiga | amiga-*)
+		basic_machine=m68k-unknown
+		;;
+	amigaos | amigados)
+		basic_machine=m68k-unknown
+		os=-amigaos
+		;;
+	amigaunix | amix)
+		basic_machine=m68k-unknown
+		os=-sysv4
+		;;
+	apollo68)
+		basic_machine=m68k-apollo
+		os=-sysv
+		;;
+	apollo68bsd)
+		basic_machine=m68k-apollo
+		os=-bsd
+		;;
+	aros)
+		basic_machine=i386-pc
+		os=-aros
+		;;
+	aux)
+		basic_machine=m68k-apple
+		os=-aux
+		;;
+	balance)
+		basic_machine=ns32k-sequent
+		os=-dynix
+		;;
+	blackfin)
+		basic_machine=bfin-unknown
+		os=-linux
+		;;
+	blackfin-*)
+		basic_machine=bfin-`echo $basic_machine | sed 's/^[^-]*-//'`
+		os=-linux
+		;;
+	bluegene*)
+		basic_machine=powerpc-ibm
+		os=-cnk
+		;;
+	c54x-*)
+		basic_machine=tic54x-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	c55x-*)
+		basic_machine=tic55x-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	c6x-*)
+		basic_machine=tic6x-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	c90)
+		basic_machine=c90-cray
+		os=-unicos
+		;;
+	cegcc)
+		basic_machine=arm-unknown
+		os=-cegcc
+		;;
+	convex-c1)
+		basic_machine=c1-convex
+		os=-bsd
+		;;
+	convex-c2)
+		basic_machine=c2-convex
+		os=-bsd
+		;;
+	convex-c32)
+		basic_machine=c32-convex
+		os=-bsd
+		;;
+	convex-c34)
+		basic_machine=c34-convex
+		os=-bsd
+		;;
+	convex-c38)
+		basic_machine=c38-convex
+		os=-bsd
+		;;
+	cray | j90)
+		basic_machine=j90-cray
+		os=-unicos
+		;;
+	craynv)
+		basic_machine=craynv-cray
+		os=-unicosmp
+		;;
+	cr16 | cr16-*)
+		basic_machine=cr16-unknown
+		os=-elf
+		;;
+	crds | unos)
+		basic_machine=m68k-crds
+		;;
+	crisv32 | crisv32-* | etraxfs*)
+		basic_machine=crisv32-axis
+		;;
+	cris | cris-* | etrax*)
+		basic_machine=cris-axis
+		;;
+	crx)
+		basic_machine=crx-unknown
+		os=-elf
+		;;
+	da30 | da30-*)
+		basic_machine=m68k-da30
+		;;
+	decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn)
+		basic_machine=mips-dec
+		;;
+	decsystem10* | dec10*)
+		basic_machine=pdp10-dec
+		os=-tops10
+		;;
+	decsystem20* | dec20*)
+		basic_machine=pdp10-dec
+		os=-tops20
+		;;
+	delta | 3300 | motorola-3300 | motorola-delta \
+	      | 3300-motorola | delta-motorola)
+		basic_machine=m68k-motorola
+		;;
+	delta88)
+		basic_machine=m88k-motorola
+		os=-sysv3
+		;;
+	dicos)
+		basic_machine=i686-pc
+		os=-dicos
+		;;
+	djgpp)
+		basic_machine=i586-pc
+		os=-msdosdjgpp
+		;;
+	dpx20 | dpx20-*)
+		basic_machine=rs6000-bull
+		os=-bosx
+		;;
+	dpx2* | dpx2*-bull)
+		basic_machine=m68k-bull
+		os=-sysv3
+		;;
+	ebmon29k)
+		basic_machine=a29k-amd
+		os=-ebmon
+		;;
+	elxsi)
+		basic_machine=elxsi-elxsi
+		os=-bsd
+		;;
+	encore | umax | mmax)
+		basic_machine=ns32k-encore
+		;;
+	es1800 | OSE68k | ose68k | ose | OSE)
+		basic_machine=m68k-ericsson
+		os=-ose
+		;;
+	fx2800)
+		basic_machine=i860-alliant
+		;;
+	genix)
+		basic_machine=ns32k-ns
+		;;
+	gmicro)
+		basic_machine=tron-gmicro
+		os=-sysv
+		;;
+	go32)
+		basic_machine=i386-pc
+		os=-go32
+		;;
+	h3050r* | hiux*)
+		basic_machine=hppa1.1-hitachi
+		os=-hiuxwe2
+		;;
+	h8300hms)
+		basic_machine=h8300-hitachi
+		os=-hms
+		;;
+	h8300xray)
+		basic_machine=h8300-hitachi
+		os=-xray
+		;;
+	h8500hms)
+		basic_machine=h8500-hitachi
+		os=-hms
+		;;
+	harris)
+		basic_machine=m88k-harris
+		os=-sysv3
+		;;
+	hp300-*)
+		basic_machine=m68k-hp
+		;;
+	hp300bsd)
+		basic_machine=m68k-hp
+		os=-bsd
+		;;
+	hp300hpux)
+		basic_machine=m68k-hp
+		os=-hpux
+		;;
+	hp3k9[0-9][0-9] | hp9[0-9][0-9])
+		basic_machine=hppa1.0-hp
+		;;
+	hp9k2[0-9][0-9] | hp9k31[0-9])
+		basic_machine=m68000-hp
+		;;
+	hp9k3[2-9][0-9])
+		basic_machine=m68k-hp
+		;;
+	hp9k6[0-9][0-9] | hp6[0-9][0-9])
+		basic_machine=hppa1.0-hp
+		;;
+	hp9k7[0-79][0-9] | hp7[0-79][0-9])
+		basic_machine=hppa1.1-hp
+		;;
+	hp9k78[0-9] | hp78[0-9])
+		# FIXME: really hppa2.0-hp
+		basic_machine=hppa1.1-hp
+		;;
+	hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893)
+		# FIXME: really hppa2.0-hp
+		basic_machine=hppa1.1-hp
+		;;
+	hp9k8[0-9][13679] | hp8[0-9][13679])
+		basic_machine=hppa1.1-hp
+		;;
+	hp9k8[0-9][0-9] | hp8[0-9][0-9])
+		basic_machine=hppa1.0-hp
+		;;
+	hppa-next)
+		os=-nextstep3
+		;;
+	hppaosf)
+		basic_machine=hppa1.1-hp
+		os=-osf
+		;;
+	hppro)
+		basic_machine=hppa1.1-hp
+		os=-proelf
+		;;
+	i370-ibm* | ibm*)
+		basic_machine=i370-ibm
+		;;
+	i*86v32)
+		basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
+		os=-sysv32
+		;;
+	i*86v4*)
+		basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
+		os=-sysv4
+		;;
+	i*86v)
+		basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
+		os=-sysv
+		;;
+	i*86sol2)
+		basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
+		os=-solaris2
+		;;
+	i386mach)
+		basic_machine=i386-mach
+		os=-mach
+		;;
+	i386-vsta | vsta)
+		basic_machine=i386-unknown
+		os=-vsta
+		;;
+	iris | iris4d)
+		basic_machine=mips-sgi
+		case $os in
+		    -irix*)
+			;;
+		    *)
+			os=-irix4
+			;;
+		esac
+		;;
+	isi68 | isi)
+		basic_machine=m68k-isi
+		os=-sysv
+		;;
+	m68knommu)
+		basic_machine=m68k-unknown
+		os=-linux
+		;;
+	m68knommu-*)
+		basic_machine=m68k-`echo $basic_machine | sed 's/^[^-]*-//'`
+		os=-linux
+		;;
+	m88k-omron*)
+		basic_machine=m88k-omron
+		;;
+	magnum | m3230)
+		basic_machine=mips-mips
+		os=-sysv
+		;;
+	merlin)
+		basic_machine=ns32k-utek
+		os=-sysv
+		;;
+	microblaze)
+		basic_machine=microblaze-xilinx
+		;;
+	mingw32)
+		basic_machine=i386-pc
+		os=-mingw32
+		;;
+	mingw32ce)
+		basic_machine=arm-unknown
+		os=-mingw32ce
+		;;
+	miniframe)
+		basic_machine=m68000-convergent
+		;;
+	*mint | -mint[0-9]* | *MiNT | *MiNT[0-9]*)
+		basic_machine=m68k-atari
+		os=-mint
+		;;
+	mips3*-*)
+		basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`
+		;;
+	mips3*)
+		basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown
+		;;
+	monitor)
+		basic_machine=m68k-rom68k
+		os=-coff
+		;;
+	morphos)
+		basic_machine=powerpc-unknown
+		os=-morphos
+		;;
+	msdos)
+		basic_machine=i386-pc
+		os=-msdos
+		;;
+	ms1-*)
+		basic_machine=`echo $basic_machine | sed -e 's/ms1-/mt-/'`
+		;;
+	msys)
+		basic_machine=i386-pc
+		os=-msys
+		;;
+	mvs)
+		basic_machine=i370-ibm
+		os=-mvs
+		;;
+	nacl)
+		basic_machine=le32-unknown
+		os=-nacl
+		;;
+	ncr3000)
+		basic_machine=i486-ncr
+		os=-sysv4
+		;;
+	netbsd386)
+		basic_machine=i386-unknown
+		os=-netbsd
+		;;
+	netwinder)
+		basic_machine=armv4l-rebel
+		os=-linux
+		;;
+	news | news700 | news800 | news900)
+		basic_machine=m68k-sony
+		os=-newsos
+		;;
+	news1000)
+		basic_machine=m68030-sony
+		os=-newsos
+		;;
+	news-3600 | risc-news)
+		basic_machine=mips-sony
+		os=-newsos
+		;;
+	necv70)
+		basic_machine=v70-nec
+		os=-sysv
+		;;
+	next | m*-next )
+		basic_machine=m68k-next
+		case $os in
+		    -nextstep* )
+			;;
+		    -ns2*)
+		      os=-nextstep2
+			;;
+		    *)
+		      os=-nextstep3
+			;;
+		esac
+		;;
+	nh3000)
+		basic_machine=m68k-harris
+		os=-cxux
+		;;
+	nh[45]000)
+		basic_machine=m88k-harris
+		os=-cxux
+		;;
+	nindy960)
+		basic_machine=i960-intel
+		os=-nindy
+		;;
+	mon960)
+		basic_machine=i960-intel
+		os=-mon960
+		;;
+	nonstopux)
+		basic_machine=mips-compaq
+		os=-nonstopux
+		;;
+	np1)
+		basic_machine=np1-gould
+		;;
+	neo-tandem)
+		basic_machine=neo-tandem
+		;;
+	nse-tandem)
+		basic_machine=nse-tandem
+		;;
+	nsr-tandem)
+		basic_machine=nsr-tandem
+		;;
+	op50n-* | op60c-*)
+		basic_machine=hppa1.1-oki
+		os=-proelf
+		;;
+	openrisc | openrisc-*)
+		basic_machine=or32-unknown
+		;;
+	os400)
+		basic_machine=powerpc-ibm
+		os=-os400
+		;;
+	OSE68000 | ose68000)
+		basic_machine=m68000-ericsson
+		os=-ose
+		;;
+	os68k)
+		basic_machine=m68k-none
+		os=-os68k
+		;;
+	pa-hitachi)
+		basic_machine=hppa1.1-hitachi
+		os=-hiuxwe2
+		;;
+	paragon)
+		basic_machine=i860-intel
+		os=-osf
+		;;
+	parisc)
+		basic_machine=hppa-unknown
+		os=-linux
+		;;
+	parisc-*)
+		basic_machine=hppa-`echo $basic_machine | sed 's/^[^-]*-//'`
+		os=-linux
+		;;
+	pbd)
+		basic_machine=sparc-tti
+		;;
+	pbb)
+		basic_machine=m68k-tti
+		;;
+	pc532 | pc532-*)
+		basic_machine=ns32k-pc532
+		;;
+	pc98)
+		basic_machine=i386-pc
+		;;
+	pc98-*)
+		basic_machine=i386-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	pentium | p5 | k5 | k6 | nexgen | viac3)
+		basic_machine=i586-pc
+		;;
+	pentiumpro | p6 | 6x86 | athlon | athlon_*)
+		basic_machine=i686-pc
+		;;
+	pentiumii | pentium2 | pentiumiii | pentium3)
+		basic_machine=i686-pc
+		;;
+	pentium4)
+		basic_machine=i786-pc
+		;;
+	pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*)
+		basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	pentiumpro-* | p6-* | 6x86-* | athlon-*)
+		basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	pentiumii-* | pentium2-* | pentiumiii-* | pentium3-*)
+		basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	pentium4-*)
+		basic_machine=i786-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	pn)
+		basic_machine=pn-gould
+		;;
+	power)	basic_machine=power-ibm
+		;;
+	ppc | ppcbe)	basic_machine=powerpc-unknown
+		;;
+	ppc-* | ppcbe-*)
+		basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	ppcle | powerpclittle | ppc-le | powerpc-little)
+		basic_machine=powerpcle-unknown
+		;;
+	ppcle-* | powerpclittle-*)
+		basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	ppc64)	basic_machine=powerpc64-unknown
+		;;
+	ppc64-*) basic_machine=powerpc64-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	ppc64le | powerpc64little | ppc64-le | powerpc64-little)
+		basic_machine=powerpc64le-unknown
+		;;
+	ppc64le-* | powerpc64little-*)
+		basic_machine=powerpc64le-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	ps2)
+		basic_machine=i386-ibm
+		;;
+	pw32)
+		basic_machine=i586-unknown
+		os=-pw32
+		;;
+	rdos)
+		basic_machine=i386-pc
+		os=-rdos
+		;;
+	rom68k)
+		basic_machine=m68k-rom68k
+		os=-coff
+		;;
+	rm[46]00)
+		basic_machine=mips-siemens
+		;;
+	rtpc | rtpc-*)
+		basic_machine=romp-ibm
+		;;
+	s390 | s390-*)
+		basic_machine=s390-ibm
+		;;
+	s390x | s390x-*)
+		basic_machine=s390x-ibm
+		;;
+	sa29200)
+		basic_machine=a29k-amd
+		os=-udi
+		;;
+	sb1)
+		basic_machine=mipsisa64sb1-unknown
+		;;
+	sb1el)
+		basic_machine=mipsisa64sb1el-unknown
+		;;
+	sde)
+		basic_machine=mipsisa32-sde
+		os=-elf
+		;;
+	sei)
+		basic_machine=mips-sei
+		os=-seiux
+		;;
+	sequent)
+		basic_machine=i386-sequent
+		;;
+	sh)
+		basic_machine=sh-hitachi
+		os=-hms
+		;;
+	sh5el)
+		basic_machine=sh5le-unknown
+		;;
+	sh64)
+		basic_machine=sh64-unknown
+		;;
+	sparclite-wrs | simso-wrs)
+		basic_machine=sparclite-wrs
+		os=-vxworks
+		;;
+	sps7)
+		basic_machine=m68k-bull
+		os=-sysv2
+		;;
+	spur)
+		basic_machine=spur-unknown
+		;;
+	st2000)
+		basic_machine=m68k-tandem
+		;;
+	stratus)
+		basic_machine=i860-stratus
+		os=-sysv4
+		;;
+	strongarm-* | thumb-*)
+		basic_machine=arm-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	sun2)
+		basic_machine=m68000-sun
+		;;
+	sun2os3)
+		basic_machine=m68000-sun
+		os=-sunos3
+		;;
+	sun2os4)
+		basic_machine=m68000-sun
+		os=-sunos4
+		;;
+	sun3os3)
+		basic_machine=m68k-sun
+		os=-sunos3
+		;;
+	sun3os4)
+		basic_machine=m68k-sun
+		os=-sunos4
+		;;
+	sun4os3)
+		basic_machine=sparc-sun
+		os=-sunos3
+		;;
+	sun4os4)
+		basic_machine=sparc-sun
+		os=-sunos4
+		;;
+	sun4sol2)
+		basic_machine=sparc-sun
+		os=-solaris2
+		;;
+	sun3 | sun3-*)
+		basic_machine=m68k-sun
+		;;
+	sun4)
+		basic_machine=sparc-sun
+		;;
+	sun386 | sun386i | roadrunner)
+		basic_machine=i386-sun
+		;;
+	sv1)
+		basic_machine=sv1-cray
+		os=-unicos
+		;;
+	symmetry)
+		basic_machine=i386-sequent
+		os=-dynix
+		;;
+	t3e)
+		basic_machine=alphaev5-cray
+		os=-unicos
+		;;
+	t90)
+		basic_machine=t90-cray
+		os=-unicos
+		;;
+	tile*)
+		basic_machine=$basic_machine-unknown
+		os=-linux-gnu
+		;;
+	tx39)
+		basic_machine=mipstx39-unknown
+		;;
+	tx39el)
+		basic_machine=mipstx39el-unknown
+		;;
+	toad1)
+		basic_machine=pdp10-xkl
+		os=-tops20
+		;;
+	tower | tower-32)
+		basic_machine=m68k-ncr
+		;;
+	tpf)
+		basic_machine=s390x-ibm
+		os=-tpf
+		;;
+	udi29k)
+		basic_machine=a29k-amd
+		os=-udi
+		;;
+	ultra3)
+		basic_machine=a29k-nyu
+		os=-sym1
+		;;
+	v810 | necv810)
+		basic_machine=v810-nec
+		os=-none
+		;;
+	vaxv)
+		basic_machine=vax-dec
+		os=-sysv
+		;;
+	vms)
+		basic_machine=vax-dec
+		os=-vms
+		;;
+	vpp*|vx|vx-*)
+		basic_machine=f301-fujitsu
+		;;
+	vxworks960)
+		basic_machine=i960-wrs
+		os=-vxworks
+		;;
+	vxworks68)
+		basic_machine=m68k-wrs
+		os=-vxworks
+		;;
+	vxworks29k)
+		basic_machine=a29k-wrs
+		os=-vxworks
+		;;
+	w65*)
+		basic_machine=w65-wdc
+		os=-none
+		;;
+	w89k-*)
+		basic_machine=hppa1.1-winbond
+		os=-proelf
+		;;
+	xbox)
+		basic_machine=i686-pc
+		os=-mingw32
+		;;
+	xps | xps100)
+		basic_machine=xps100-honeywell
+		;;
+	xscale-* | xscalee[bl]-*)
+		basic_machine=`echo $basic_machine | sed 's/^xscale/arm/'`
+		;;
+	ymp)
+		basic_machine=ymp-cray
+		os=-unicos
+		;;
+	z8k-*-coff)
+		basic_machine=z8k-unknown
+		os=-sim
+		;;
+	z80-*-coff)
+		basic_machine=z80-unknown
+		os=-sim
+		;;
+	none)
+		basic_machine=none-none
+		os=-none
+		;;
+
+# Here we handle the default manufacturer of certain CPU types.  It is in
+# some cases the only manufacturer, in others, it is the most popular.
+	w89k)
+		basic_machine=hppa1.1-winbond
+		;;
+	op50n)
+		basic_machine=hppa1.1-oki
+		;;
+	op60c)
+		basic_machine=hppa1.1-oki
+		;;
+	romp)
+		basic_machine=romp-ibm
+		;;
+	mmix)
+		basic_machine=mmix-knuth
+		;;
+	rs6000)
+		basic_machine=rs6000-ibm
+		;;
+	vax)
+		basic_machine=vax-dec
+		;;
+	pdp10)
+		# there are many clones, so DEC is not a safe bet
+		basic_machine=pdp10-unknown
+		;;
+	pdp11)
+		basic_machine=pdp11-dec
+		;;
+	we32k)
+		basic_machine=we32k-att
+		;;
+	sh[1234] | sh[24]a | sh[24]aeb | sh[34]eb | sh[1234]le | sh[23]ele)
+		basic_machine=sh-unknown
+		;;
+	sparc | sparcv8 | sparcv9 | sparcv9b | sparcv9v)
+		basic_machine=sparc-sun
+		;;
+	cydra)
+		basic_machine=cydra-cydrome
+		;;
+	orion)
+		basic_machine=orion-highlevel
+		;;
+	orion105)
+		basic_machine=clipper-highlevel
+		;;
+	mac | mpw | mac-mpw)
+		basic_machine=m68k-apple
+		;;
+	pmac | pmac-mpw)
+		basic_machine=powerpc-apple
+		;;
+	*-unknown)
+		# Make sure to match an already-canonicalized machine name.
+		;;
+	*)
+		echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2
+		exit 1
+		;;
+esac
+
+# Here we canonicalize certain aliases for manufacturers.
+case $basic_machine in
+	*-digital*)
+		basic_machine=`echo $basic_machine | sed 's/digital.*/dec/'`
+		;;
+	*-commodore*)
+		basic_machine=`echo $basic_machine | sed 's/commodore.*/cbm/'`
+		;;
+	*)
+		;;
+esac
+
+# Decode manufacturer-specific aliases for certain operating systems.
+
+if [ x"$os" != x"" ]
+then
+case $os in
+	# First match some system type aliases
+	# that might get confused with valid system types.
+	# -solaris* is a basic system type, with this one exception.
+	-auroraux)
+		os=-auroraux
+		;;
+	-solaris1 | -solaris1.*)
+		os=`echo $os | sed -e 's|solaris1|sunos4|'`
+		;;
+	-solaris)
+		os=-solaris2
+		;;
+	-svr4*)
+		os=-sysv4
+		;;
+	-unixware*)
+		os=-sysv4.2uw
+		;;
+	-gnu/linux*)
+		os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'`
+		;;
+	# First accept the basic system types.
+	# The portable systems comes first.
+	# Each alternative MUST END IN A *, to match a version number.
+	# -sysv* is not here because it comes later, after sysvr4.
+	-gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \
+	      | -*vms* | -sco* | -esix* | -isc* | -aix* | -cnk* | -sunos | -sunos[34]*\
+	      | -hpux* | -unos* | -osf* | -luna* | -dgux* | -auroraux* | -solaris* \
+	      | -sym* | -kopensolaris* \
+	      | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \
+	      | -aos* | -aros* \
+	      | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \
+	      | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \
+	      | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \
+	      | -bitrig* | -openbsd* | -solidbsd* \
+	      | -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \
+	      | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \
+	      | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \
+	      | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \
+	      | -chorusos* | -chorusrdb* | -cegcc* \
+	      | -cygwin* | -msys* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
+	      | -mingw32* | -linux-gnu* | -linux-android* \
+	      | -linux-newlib* | -linux-uclibc* \
+	      | -uxpv* | -beos* | -mpeix* | -udk* \
+	      | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \
+	      | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \
+	      | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \
+	      | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \
+	      | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \
+	      | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \
+	      | -skyos* | -haiku* | -rdos* | -toppers* | -drops* | -es*)
+	# Remember, each alternative MUST END IN *, to match a version number.
+		;;
+	-qnx*)
+		case $basic_machine in
+		    x86-* | i*86-*)
+			;;
+		    *)
+			os=-nto$os
+			;;
+		esac
+		;;
+	-nto-qnx*)
+		;;
+	-nto*)
+		os=`echo $os | sed -e 's|nto|nto-qnx|'`
+		;;
+	-sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \
+	      | -windows* | -osx | -abug | -netware* | -os9* | -beos* | -haiku* \
+	      | -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*)
+		;;
+	-mac*)
+		os=`echo $os | sed -e 's|mac|macos|'`
+		;;
+	-linux-dietlibc)
+		os=-linux-dietlibc
+		;;
+	-linux*)
+		os=`echo $os | sed -e 's|linux|linux-gnu|'`
+		;;
+	-sunos5*)
+		os=`echo $os | sed -e 's|sunos5|solaris2|'`
+		;;
+	-sunos6*)
+		os=`echo $os | sed -e 's|sunos6|solaris3|'`
+		;;
+	-opened*)
+		os=-openedition
+		;;
+	-os400*)
+		os=-os400
+		;;
+	-wince*)
+		os=-wince
+		;;
+	-osfrose*)
+		os=-osfrose
+		;;
+	-osf*)
+		os=-osf
+		;;
+	-utek*)
+		os=-bsd
+		;;
+	-dynix*)
+		os=-bsd
+		;;
+	-acis*)
+		os=-aos
+		;;
+	-atheos*)
+		os=-atheos
+		;;
+	-syllable*)
+		os=-syllable
+		;;
+	-386bsd)
+		os=-bsd
+		;;
+	-ctix* | -uts*)
+		os=-sysv
+		;;
+	-nova*)
+		os=-rtmk-nova
+		;;
+	-ns2 )
+		os=-nextstep2
+		;;
+	-nsk*)
+		os=-nsk
+		;;
+	# Preserve the version number of sinix5.
+	-sinix5.*)
+		os=`echo $os | sed -e 's|sinix|sysv|'`
+		;;
+	-sinix*)
+		os=-sysv4
+		;;
+	-tpf*)
+		os=-tpf
+		;;
+	-triton*)
+		os=-sysv3
+		;;
+	-oss*)
+		os=-sysv3
+		;;
+	-svr4)
+		os=-sysv4
+		;;
+	-svr3)
+		os=-sysv3
+		;;
+	-sysvr4)
+		os=-sysv4
+		;;
+	# This must come after -sysvr4.
+	-sysv*)
+		;;
+	-ose*)
+		os=-ose
+		;;
+	-es1800*)
+		os=-ose
+		;;
+	-xenix)
+		os=-xenix
+		;;
+	-*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*)
+		os=-mint
+		;;
+	-aros*)
+		os=-aros
+		;;
+	-kaos*)
+		os=-kaos
+		;;
+	-zvmoe)
+		os=-zvmoe
+		;;
+	-dicos*)
+		os=-dicos
+		;;
+	-nacl*)
+		;;
+	-none)
+		;;
+	*)
+		# Get rid of the `-' at the beginning of $os.
+		os=`echo $os | sed 's/[^-]*-//'`
+		echo Invalid configuration \`$1\': system \`$os\' not recognized 1>&2
+		exit 1
+		;;
+esac
+else
+
+# Here we handle the default operating systems that come with various machines.
+# The value should be what the vendor currently ships out the door with their
+# machine or put another way, the most popular os provided with the machine.
+
+# Note that if you're going to try to match "-MANUFACTURER" here (say,
+# "-sun"), then you have to tell the case statement up towards the top
+# that MANUFACTURER isn't an operating system.  Otherwise, code above
+# will signal an error saying that MANUFACTURER isn't an operating
+# system, and we'll never get to this point.
+
+case $basic_machine in
+	score-*)
+		os=-elf
+		;;
+	spu-*)
+		os=-elf
+		;;
+	*-acorn)
+		os=-riscix1.2
+		;;
+	arm*-rebel)
+		os=-linux
+		;;
+	arm*-semi)
+		os=-aout
+		;;
+	c4x-* | tic4x-*)
+		os=-coff
+		;;
+	hexagon-*)
+		os=-elf
+		;;
+	tic54x-*)
+		os=-coff
+		;;
+	tic55x-*)
+		os=-coff
+		;;
+	tic6x-*)
+		os=-coff
+		;;
+	# This must come before the *-dec entry.
+	pdp10-*)
+		os=-tops20
+		;;
+	pdp11-*)
+		os=-none
+		;;
+	*-dec | vax-*)
+		os=-ultrix4.2
+		;;
+	m68*-apollo)
+		os=-domain
+		;;
+	i386-sun)
+		os=-sunos4.0.2
+		;;
+	m68000-sun)
+		os=-sunos3
+		;;
+	m68*-cisco)
+		os=-aout
+		;;
+	mep-*)
+		os=-elf
+		;;
+	mips*-cisco)
+		os=-elf
+		;;
+	mips*-*)
+		os=-elf
+		;;
+	or32-*)
+		os=-coff
+		;;
+	*-tti)	# must be before sparc entry or we get the wrong os.
+		os=-sysv3
+		;;
+	sparc-* | *-sun)
+		os=-sunos4.1.1
+		;;
+	*-be)
+		os=-beos
+		;;
+	*-haiku)
+		os=-haiku
+		;;
+	*-ibm)
+		os=-aix
+		;;
+	*-knuth)
+		os=-mmixware
+		;;
+	*-wec)
+		os=-proelf
+		;;
+	*-winbond)
+		os=-proelf
+		;;
+	*-oki)
+		os=-proelf
+		;;
+	*-hp)
+		os=-hpux
+		;;
+	*-hitachi)
+		os=-hiux
+		;;
+	i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent)
+		os=-sysv
+		;;
+	*-cbm)
+		os=-amigaos
+		;;
+	*-dg)
+		os=-dgux
+		;;
+	*-dolphin)
+		os=-sysv3
+		;;
+	m68k-ccur)
+		os=-rtu
+		;;
+	m88k-omron*)
+		os=-luna
+		;;
+	*-next )
+		os=-nextstep
+		;;
+	*-sequent)
+		os=-ptx
+		;;
+	*-crds)
+		os=-unos
+		;;
+	*-ns)
+		os=-genix
+		;;
+	i370-*)
+		os=-mvs
+		;;
+	*-next)
+		os=-nextstep3
+		;;
+	*-gould)
+		os=-sysv
+		;;
+	*-highlevel)
+		os=-bsd
+		;;
+	*-encore)
+		os=-bsd
+		;;
+	*-sgi)
+		os=-irix
+		;;
+	*-siemens)
+		os=-sysv4
+		;;
+	*-masscomp)
+		os=-rtu
+		;;
+	f30[01]-fujitsu | f700-fujitsu)
+		os=-uxpv
+		;;
+	*-rom68k)
+		os=-coff
+		;;
+	*-*bug)
+		os=-coff
+		;;
+	*-apple)
+		os=-macos
+		;;
+	*-atari*)
+		os=-mint
+		;;
+	*)
+		os=-none
+		;;
+esac
+fi
+
+# Here we handle the case where we know the os, and the CPU type, but not the
+# manufacturer.  We pick the logical manufacturer.
+vendor=unknown
+case $basic_machine in
+	*-unknown)
+		case $os in
+			-riscix*)
+				vendor=acorn
+				;;
+			-sunos*)
+				vendor=sun
+				;;
+			-cnk*|-aix*)
+				vendor=ibm
+				;;
+			-beos*)
+				vendor=be
+				;;
+			-hpux*)
+				vendor=hp
+				;;
+			-mpeix*)
+				vendor=hp
+				;;
+			-hiux*)
+				vendor=hitachi
+				;;
+			-unos*)
+				vendor=crds
+				;;
+			-dgux*)
+				vendor=dg
+				;;
+			-luna*)
+				vendor=omron
+				;;
+			-genix*)
+				vendor=ns
+				;;
+			-mvs* | -opened*)
+				vendor=ibm
+				;;
+			-os400*)
+				vendor=ibm
+				;;
+			-ptx*)
+				vendor=sequent
+				;;
+			-tpf*)
+				vendor=ibm
+				;;
+			-vxsim* | -vxworks* | -windiss*)
+				vendor=wrs
+				;;
+			-aux*)
+				vendor=apple
+				;;
+			-hms*)
+				vendor=hitachi
+				;;
+			-mpw* | -macos*)
+				vendor=apple
+				;;
+			-*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*)
+				vendor=atari
+				;;
+			-vos*)
+				vendor=stratus
+				;;
+		esac
+		basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"`
+		;;
+esac
+
+echo $basic_machine$os
+exit
+
+# Local variables:
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "timestamp='"
+# time-stamp-format: "%:y-%02m-%02d"
+# time-stamp-end: "'"
+# End:
diff --git a/jni/pjproject-android/.svn/pristine/84/84503da1c087dbb28424fe3e5eeb372fcc7f1978.svn-base b/jni/pjproject-android/.svn/pristine/84/84503da1c087dbb28424fe3e5eeb372fcc7f1978.svn-base
new file mode 100644
index 0000000..dc1ff20
--- /dev/null
+++ b/jni/pjproject-android/.svn/pristine/84/84503da1c087dbb28424fe3e5eeb372fcc7f1978.svn-base
@@ -0,0 +1,107 @@
+/* $Id$ */
+/* 
+ * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
+ * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
+ *
+ * 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 __PJLIB_UTIL_HMAC_SHA1_H__
+#define __PJLIB_UTIL_HMAC_SHA1_H__
+
+/**
+ * @file hmac_sha1.h
+ * @brief HMAC SHA1 Message Authentication
+ */
+
+#include <pj/types.h>
+#include <pjlib-util/sha1.h>
+
+PJ_BEGIN_DECL
+
+/**
+ * @defgroup PJLIB_UTIL_HMAC_SHA1 HMAC SHA1 Message Authentication
+ * @ingroup PJLIB_UTIL_ENCRYPTION
+ * @{
+ *
+ * This module contains the implementation of HMAC: Keyed-Hashing 
+ * for Message Authentication, as described in RFC 2104.
+ */
+
+/**
+ * The HMAC-SHA1 context used in the incremental HMAC calculation.
+ */
+typedef struct pj_hmac_sha1_context
+{
+    pj_sha1_context context;	/**< SHA1 context	    */
+    pj_uint8_t	    k_opad[64];	/**< opad xor-ed with key   */
+} pj_hmac_sha1_context;
+
+
+/**
+ * Calculate HMAC-SHA1 digest for the specified input and key with this
+ * single function call.
+ *
+ * @param input		Pointer to the input stream.
+ * @param input_len	Length of input stream in bytes.
+ * @param key		Pointer to the authentication key.
+ * @param key_len	Length of the authentication key.
+ * @param digest	Buffer to be filled with HMAC SHA1 digest.
+ */
+PJ_DECL(void) pj_hmac_sha1(const pj_uint8_t *input, unsigned input_len, 
+			   const pj_uint8_t *key, unsigned key_len, 
+			   pj_uint8_t digest[20]);
+
+
+/**
+ * Initiate HMAC-SHA1 context for incremental hashing.
+ *
+ * @param hctx		HMAC-SHA1 context.
+ * @param key		Pointer to the authentication key.
+ * @param key_len	Length of the authentication key.
+ */
+PJ_DECL(void) pj_hmac_sha1_init(pj_hmac_sha1_context *hctx, 
+			        const pj_uint8_t *key, unsigned key_len);
+
+/**
+ * Append string to the message.
+ *
+ * @param hctx		HMAC-SHA1 context.
+ * @param input		Pointer to the input stream.
+ * @param input_len	Length of input stream in bytes.
+ */
+PJ_DECL(void) pj_hmac_sha1_update(pj_hmac_sha1_context *hctx,
+				  const pj_uint8_t *input, 
+				  unsigned input_len);
+
+/**
+ * Finish the message and return the digest. 
+ *
+ * @param hctx		HMAC-SHA1 context.
+ * @param digest	Buffer to be filled with HMAC SHA1 digest.
+ */
+PJ_DECL(void) pj_hmac_sha1_final(pj_hmac_sha1_context *hctx,
+				 pj_uint8_t digest[20]);
+
+
+/**
+ * @}
+ */
+
+PJ_END_DECL
+
+
+#endif	/* __PJLIB_UTIL_HMAC_SHA1_H__ */
+
+
diff --git a/jni/pjproject-android/.svn/pristine/84/8457b0a057c2a3992fde2a3e18a0c777194662bf.svn-base b/jni/pjproject-android/.svn/pristine/84/8457b0a057c2a3992fde2a3e18a0c777194662bf.svn-base
new file mode 100644
index 0000000..20d2804
--- /dev/null
+++ b/jni/pjproject-android/.svn/pristine/84/8457b0a057c2a3992fde2a3e18a0c777194662bf.svn-base
@@ -0,0 +1,84 @@
+/*
+ * aes.h
+ *
+ * header file for the AES block cipher
+ *
+ * David A. McGrew
+ * Cisco Systems, Inc.
+ */
+
+/*
+ *	
+ * Copyright (c) 2001-2006, Cisco Systems, Inc.
+ * All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 
+ *   Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * 
+ *   Redistributions in binary form must reproduce the above
+ *   copyright notice, this list of conditions and the following
+ *   disclaimer in the documentation and/or other materials provided
+ *   with the distribution.
+ * 
+ *   Neither the name of the Cisco Systems, Inc. nor the names of its
+ *   contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef _AES_H
+#define _AES_H
+
+#include "srtp_config.h"
+
+#include "datatypes.h"
+#include "gf2_8.h"
+
+/* aes internals */
+
+typedef v128_t aes_expanded_key_t[11];
+
+void
+aes_expand_encryption_key(const v128_t *key,
+			  aes_expanded_key_t expanded_key);
+
+void
+aes_expand_decryption_key(const v128_t *key,
+			  aes_expanded_key_t expanded_key);
+
+void
+aes_encrypt(v128_t *plaintext, const aes_expanded_key_t exp_key);
+
+void
+aes_decrypt(v128_t *plaintext, const aes_expanded_key_t exp_key);
+
+#if 0
+/*
+ * internal functions 
+ */
+
+void
+aes_init_sbox(void);
+
+void
+aes_compute_tables(void);
+#endif 
+
+#endif /* _AES_H */
diff --git a/jni/pjproject-android/.svn/pristine/84/84654618cc74711b214b24a634c6ad89f372c2b5.svn-base b/jni/pjproject-android/.svn/pristine/84/84654618cc74711b214b24a634c6ad89f372c2b5.svn-base
new file mode 100644
index 0000000..1cc2746
--- /dev/null
+++ b/jni/pjproject-android/.svn/pristine/84/84654618cc74711b214b24a634c6ad89f372c2b5.svn-base
@@ -0,0 +1,102 @@
+/* $Id$ */
+/*
+ * Copyright (C) 2011-2011 Teluu Inc. (http://www.teluu.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 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 VIDGUI_H_
+#define VIDGUI_H_
+
+#include <QApplication>
+#include <QCheckBox>
+#include <QFont>
+#include <QLabel>
+#include <QLineEdit>
+#include <QMainWindow>
+#include <QObject>
+#include <QPushButton>
+#include <QStatusBar>
+#include <QTextEdit>
+#include <QVBoxLayout>
+#include <QWidget>
+
+#include <pjsua.h>
+
+class VidWin;
+
+class MainWin : public QWidget
+{
+    Q_OBJECT
+
+public:
+    MainWin(QWidget *parent = 0);
+    virtual ~MainWin();
+
+    static MainWin *instance();
+
+    bool initStack();
+    void showError(const char *title, pj_status_t status);
+    void showStatus(const char *msg);
+
+    void on_reg_state(pjsua_acc_id acc_id);
+    void on_call_state(pjsua_call_id call_id, pjsip_event *e);
+    void on_incoming_call(pjsua_acc_id acc_id, pjsua_call_id call_id, pjsip_rx_data *rdata);
+    void on_call_media_state(pjsua_call_id call_id);
+
+signals:
+    void signalNewCall(int, bool);
+    void signalCallReleased();
+    void signalInitVideoWindow();
+    void signalShowStatus(const QString&);
+    
+public slots:
+    void preview();
+    void call();
+    void hangup();
+    void quit();
+    void onVidEnabledChanged(int state);
+
+    void onNewCall(int cid, bool incoming);
+    void onCallReleased();
+    void initVideoWindow();
+    void doShowStatus(const QString& msg);
+
+private:
+    static MainWin *theInstance_;
+    pjsua_acc_id accountId_;
+    pjsua_call_id currentCall_;
+    bool preview_on;
+
+private:
+    QPushButton *callButton_,
+		*hangupButton_,
+		*quitButton_,
+		*previewButton_;
+    QCheckBox   *vidEnabled_;
+    QLineEdit *url_;
+    VidWin *video_;
+    VidWin *video_prev_;
+    //QStatusBar *statusBar_;
+    QLabel *statusBar_;
+    QLabel *localUri_;
+
+    QVBoxLayout *vbox_left;
+
+    void initLayout();
+};
+
+
+
+#endif /* VIDGUI_H_ */
diff --git a/jni/pjproject-android/.svn/pristine/84/84875ad205d6fdfe5efaee07157ca92da0db1119.svn-base b/jni/pjproject-android/.svn/pristine/84/84875ad205d6fdfe5efaee07157ca92da0db1119.svn-base
new file mode 100644
index 0000000..f8ea4d1
--- /dev/null
+++ b/jni/pjproject-android/.svn/pristine/84/84875ad205d6fdfe5efaee07157ca92da0db1119.svn-base
@@ -0,0 +1,762 @@
+/* $Id$ */
+/* 
+ * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
+ * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
+ *
+ * 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 __PJNATH_STUN_SESSION_H__
+#define __PJNATH_STUN_SESSION_H__
+
+/**
+ * @file stun_session.h
+ * @brief STUN session management for client/server.
+ */
+
+#include <pjnath/stun_msg.h>
+#include <pjnath/stun_auth.h>
+#include <pjnath/stun_config.h>
+#include <pjnath/stun_transaction.h>
+#include <pj/list.h>
+#include <pj/lock.h>
+#include <pj/timer.h>
+
+PJ_BEGIN_DECL
+
+
+/* **************************************************************************/
+/**
+ * @addtogroup PJNATH_STUN_SESSION
+ * @{
+ *
+ * This is is a transport-independent object to manage a client or server 
+ * STUN session. It has the following features:
+ * 
+ *  - <b>transport independent</b>:\n
+ *    the object does not have it's own socket, but rather it provides
+ *    functions and callbacks to send and receive packets. This way the
+ *    object can be used by different transport types (e.g. UDP, TCP, 
+ *    TLS, etc.) as well as better integration to application which
+ *    already has its own means to send and receive packets.
+ * 
+ *  - <b>authentication management</b>:\n
+ *    the object manages STUN authentication throughout the lifetime of
+ *    the session. For client sessions, once it's given a credential to
+ *    authenticate itself with the server, the object will automatically
+ *    add authentication info (the MESSAGE-INTEGRITY) to the request as
+ *    well as authenticate the response. It will also handle long-term 
+ *    authentication challenges, including handling of nonce expiration,
+ *    and retry the request automatically. For server sessions, it can 
+ *    be configured to authenticate incoming requests automatically.
+ *  
+ *  - <b>static or dynamic credential</b>:\n
+ *    application may specify static or dynamic credential to be used by
+ *    the STUN session. Static credential means a static combination of
+ *    username and password (and these cannot change during the session
+ *    duration), while dynamic credential provides callback to ask the
+ *    application about which username/password to use everytime
+ *    authentication is about to be performed.
+ *    
+ *  - <b>client transaction management</b>:\n
+ *    outgoing requests may be sent with a STUN transaction for reliability,
+ *    and the object will manage the transaction internally (including
+ *    performing retransmissions). Application will be notified about the
+ *    result of the request when the response arrives (or the transaction
+ *    times out). When the request is challenged with authentication, the
+ *    object will retry the request with new authentication info, and 
+ *    application will be notified about the final result of this request.
+ * 
+ *  - <b>server transaction management</b>:\n
+ *    application may ask response to incoming requests to be cached by
+ *    the object, and in this case the object will check for cached
+ *    response everytime request is received. The cached response will be
+ *    deleted once a timer expires.
+ *
+ * \section using_stun_sess_sec Using the STUN session
+ *
+ * The following steps describes how to use the STUN session:
+ *
+ *  - <b>create the object configuration</b>:\n
+ *    The #pj_stun_config contains the configuration to create the STUN
+ *    session, such as the timer heap to register internal timers and
+ *    various STUN timeout values. You can initialize this structure by
+ *    calling #pj_stun_config_init()
+ *
+ *  - <b>create the STUN session</b>:\n
+ *    by calling #pj_stun_session_create(). Among other things, this
+ *    function requires the instance of #pj_stun_config and also 
+ *    #pj_stun_session_cb structure which stores callbacks to send
+ *    outgoing packets as well as to notify application about incoming
+ *    STUN requests, responses, and indicates and other events.
+ *
+ *  - <b>configure credential:</b>\n
+ *    if authentication is required for the session, configure the
+ *    credential with #pj_stun_session_set_credential()
+ *
+ *  - <b>configuring other settings:</b>\n
+ *    several APIs are provided to configure the behavior of the STUN
+ *    session (for example, to set the SOFTWARE attribute value, controls
+ *    the logging behavior, fine tune the mutex locking, etc.). Please see
+ *    the API reference for more info.
+ *
+ *  - <b>creating outgoing STUN requests or indications:</b>\n
+ *    create the STUN message by using #pj_stun_session_create_req() or
+ *    #pj_stun_session_create_ind(). This will create a transmit data
+ *    buffer containing a blank STUN request or indication. You will then
+ *    typically need to add STUN attributes that are relevant to the
+ *    request or indication, but note that some default attributes will
+ *    be added by the session later when the message is sent (such as
+ *    SOFTWARE attribute and attributes related to authentication).
+ *    The message is now ready to be sent.
+ *
+ *  - <b>sending outgoing message:</b>\n
+ *    use #pj_stun_session_send_msg() to send outgoing STUN messages (this
+ *    includes STUN requests, indications, and responses). The function has
+ *    options whether to retransmit the request (for non reliable transports)
+ *    or to cache the response if we're sending response. This function in 
+ *    turn will call the \a on_send_msg() callback of #pj_stun_session_cb 
+ *    to request the application to send the packet.
+ *
+ *  - <b>handling incoming packet:</b>\n
+ *    call #pj_stun_session_on_rx_pkt() everytime the application receives
+ *    a STUN packet. This function will decode the packet and process the
+ *    packet according to the message, and normally this will cause one
+ *    of the callback in the #pj_stun_session_cb to be called to notify
+ *    the application about the event.
+ *
+ *  - <b>handling incoming requests:</b>\n
+ *    incoming requests are notified to application in the \a on_rx_request
+ *    callback of the #pj_stun_session_cb. If authentication is enabled in
+ *    the session, the application will only receive this callback after
+ *    the incoming request has been authenticated (if the authentication
+ *    fails, the session would respond automatically with 401 error and
+ *    the callback will not be called). Application now must create and
+ *    send response for this request.
+ *
+ *  - <b>creating and sending response:</b>\n
+ *    create the STUN response with #pj_stun_session_create_res(). This will
+ *    create a transmit data buffer containing a blank STUN response. You 
+ *    will then typically need to add STUN attributes that are relevant to
+ *    the response, but note that some default attributes will
+ *    be added by the session later when the message is sent (such as
+ *    SOFTWARE attribute and attributes related to authentication).
+ *    The message is now ready to be sent. Use #pj_stun_session_send_msg()
+ *    (as explained above) to send the response.
+ *
+ *  - <b>convenient way to send response:</b>\n
+ *    the #pj_stun_session_respond() is provided as a convenient way to
+ *    create and send simple STUN responses, such as error responses.
+ *    
+ *  - <b>destroying the session:</b>\n
+ *    once the session is done, use #pj_stun_session_destroy() to destroy
+ *    the session.
+ */
+
+
+/** Forward declaration for pj_stun_tx_data */
+typedef struct pj_stun_tx_data pj_stun_tx_data;
+
+/** Forward declaration for pj_stun_rx_data */
+typedef struct pj_stun_rx_data pj_stun_rx_data;
+
+/** Forward declaration for pj_stun_session */
+typedef struct pj_stun_session pj_stun_session;
+
+
+/**
+ * This is the callback to be registered to pj_stun_session, to send
+ * outgoing message and to receive various notifications from the STUN
+ * session.
+ */
+typedef struct pj_stun_session_cb
+{
+    /**
+     * Callback to be called by the STUN session to send outgoing message.
+     *
+     * @param sess	    The STUN session.
+     * @param token	    The token associated with this outgoing message
+     *			    and was set by the application. This token was 
+     *			    set by application in pj_stun_session_send_msg()
+     *			    for outgoing messages that are initiated by the
+     *			    application, or in pj_stun_session_on_rx_pkt()
+     *			    if this message is a response that was internally
+     *			    generated by the STUN session (for example, an
+     *			    401/Unauthorized response). Application may use
+     *			    this facility for any purposes.
+     * @param pkt	    Packet to be sent.
+     * @param pkt_size	    Size of the packet to be sent.
+     * @param dst_addr	    The destination address.
+     * @param addr_len	    Length of destination address.
+     *
+     * @return		    The callback should return the status of the
+     *			    packet sending.
+     */
+    pj_status_t (*on_send_msg)(pj_stun_session *sess,
+			       void *token,
+			       const void *pkt,
+			       pj_size_t pkt_size,
+			       const pj_sockaddr_t *dst_addr,
+			       unsigned addr_len);
+
+    /** 
+     * Callback to be called on incoming STUN request message. This function
+     * is called when application calls pj_stun_session_on_rx_pkt() and when
+     * the STUN session has detected that the incoming STUN message is a
+     * STUN request message. In the 
+     * callback processing, application MUST create a response by calling
+     * pj_stun_session_create_response() function and send the response
+     * with pj_stun_session_send_msg() function, before returning from
+     * the callback.
+     *
+     * @param sess	    The STUN session.
+     * @param pkt	    Pointer to the original STUN packet.
+     * @param pkt_len	    Length of the STUN packet.
+     * @param rdata	    Data containing incoming request message.
+     * @param token	    The token that was set by the application when
+     *			    calling pj_stun_session_on_rx_pkt() function.
+     * @param src_addr	    Source address of the packet.
+     * @param src_addr_len  Length of the source address.
+     *
+     * @return		    The return value of this callback will be
+     *			    returned back to pj_stun_session_on_rx_pkt()
+     *			    function.
+     */
+    pj_status_t (*on_rx_request)(pj_stun_session *sess,
+				 const pj_uint8_t *pkt,
+				 unsigned pkt_len,
+				 const pj_stun_rx_data *rdata,
+				 void *token,
+				 const pj_sockaddr_t *src_addr,
+				 unsigned src_addr_len);
+
+    /**
+     * Callback to be called when response is received or the transaction 
+     * has timed out. This callback is called either when application calls
+     * pj_stun_session_on_rx_pkt() with the packet containing a STUN
+     * response for the client transaction, or when the internal timer of
+     * the STUN client transaction has timed-out before a STUN response is
+     * received.
+     *
+     * @param sess	    The STUN session.
+     * @param status	    Status of the request. If the value if not
+     *			    PJ_SUCCESS, the transaction has timed-out
+     *			    or other error has occurred, and the response
+     *			    argument may be NULL.
+     *			    Note that when the status is not success, the
+     *			    response may contain non-NULL value if the 
+     *			    response contains STUN ERROR-CODE attribute.
+     * @param token	    The token that was set by the application  when
+     *			    calling pj_stun_session_send_msg() function.
+     *			    Please not that this token IS NOT the token
+     *			    that was given in pj_stun_session_on_rx_pkt().
+     * @param tdata	    The original STUN request.
+     * @param response	    The response message, on successful transaction,
+     *			    or otherwise MAY BE NULL if status is not success.
+     *			    Note that when the status is not success, this
+     *			    argument may contain non-NULL value if the 
+     *			    response contains STUN ERROR-CODE attribute.
+     * @param src_addr	    The source address where the response was 
+     *			    received, or NULL if the response is NULL.
+     * @param src_addr_len  The length of the source  address.
+     */
+    void (*on_request_complete)(pj_stun_session *sess,
+			        pj_status_t status,
+				void *token,
+			        pj_stun_tx_data *tdata,
+			        const pj_stun_msg *response,
+				const pj_sockaddr_t *src_addr,
+				unsigned src_addr_len);
+
+
+    /**
+     * Callback to be called on incoming STUN request message. This function
+     * is called when application calls pj_stun_session_on_rx_pkt() and when
+     * the STUN session has detected that the incoming STUN message is a
+     * STUN indication message.
+     *
+     * @param sess	    The STUN session.
+     * @param pkt	    Pointer to the original STUN packet.
+     * @param pkt_len	    Length of the STUN packet.
+     * @param msg	    The parsed STUN indication.
+     * @param token	    The token that was set by the application when
+     *			    calling pj_stun_session_on_rx_pkt() function.
+     * @param src_addr	    Source address of the packet.
+     * @param src_addr_len  Length of the source address.
+     *
+     * @return		    The return value of this callback will be
+     *			    returned back to pj_stun_session_on_rx_pkt()
+     *			    function.
+     */
+    pj_status_t (*on_rx_indication)(pj_stun_session *sess,
+				    const pj_uint8_t *pkt,
+				    unsigned pkt_len,
+				    const pj_stun_msg *msg,
+				    void *token,
+				    const pj_sockaddr_t *src_addr,
+				    unsigned src_addr_len);
+
+} pj_stun_session_cb;
+
+
+/**
+ * This structure describes incoming request message.
+ */
+struct pj_stun_rx_data
+{
+    /**
+     * The parsed request message.
+     */
+    pj_stun_msg		    *msg;
+
+    /**
+     * Credential information that is found and used to authenticate 
+     * incoming request. Application may use this information when 
+     * generating  authentication for the outgoing response.
+     */
+    pj_stun_req_cred_info   info;
+};
+
+
+/**
+ * This structure describe the outgoing STUN transmit data to carry the
+ * message to be sent.
+ */
+struct pj_stun_tx_data
+{
+    /** PJLIB list interface */
+    PJ_DECL_LIST_MEMBER(struct pj_stun_tx_data);
+
+    pj_pool_t		*pool;		/**< Pool.			    */
+    pj_stun_session	*sess;		/**< The STUN session.		    */
+    pj_stun_msg		*msg;		/**< The STUN message.		    */
+
+    void		*token;		/**< The token.			    */
+
+    pj_stun_client_tsx	*client_tsx;	/**< Client STUN transaction.	    */
+    pj_bool_t		 retransmit;	/**< Retransmit request?	    */
+    pj_uint32_t		 msg_magic;	/**< Message magic.		    */
+    pj_uint8_t		 msg_key[12];	/**< Message/transaction key.	    */
+
+    pj_stun_req_cred_info auth_info;	/**< Credential info		    */
+
+    void		*pkt;		/**< The STUN packet.		    */
+    unsigned		 max_len;	/**< Length of packet buffer.	    */
+    pj_size_t		 pkt_size;	/**< The actual length of STUN pkt. */
+
+    unsigned		 addr_len;	/**< Length of destination address. */
+    const pj_sockaddr_t	*dst_addr;	/**< Destination address.	    */
+
+    pj_timer_entry	 res_timer;	/**< Response cache timer.	    */
+};
+
+
+/**
+ * These are the flags to control the message logging in the STUN session.
+ */
+typedef enum pj_stun_sess_msg_log_flag
+{
+    PJ_STUN_SESS_LOG_TX_REQ=1,	/**< Log outgoing STUN requests.    */
+    PJ_STUN_SESS_LOG_TX_RES=2,	/**< Log outgoing STUN responses.   */
+    PJ_STUN_SESS_LOG_TX_IND=4,	/**< Log outgoing STUN indications. */
+
+    PJ_STUN_SESS_LOG_RX_REQ=8,	/**< Log incoming STUN requests.    */
+    PJ_STUN_SESS_LOG_RX_RES=16,	/**< Log incoming STUN responses    */
+    PJ_STUN_SESS_LOG_RX_IND=32	/**< Log incoming STUN indications  */
+} pj_stun_sess_msg_log_flag;
+
+
+/**
+ * Create a STUN session.
+ *
+ * @param cfg		The STUN endpoint, to be used to register timers etc.
+ * @param name		Optional name to be associated with this instance. The
+ *			name will be used for example for logging purpose.
+ * @param cb		Session callback.
+ * @param fingerprint	Enable message fingerprint for outgoing messages.
+ * @param grp_lock	Optional group lock to be used by this session.
+ * 			If NULL, the session will create one itself.
+ * @param p_sess	Pointer to receive STUN session instance.
+ *
+ * @return	    PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pj_stun_session_create(pj_stun_config *cfg,
+					    const char *name,
+					    const pj_stun_session_cb *cb,
+					    pj_bool_t fingerprint,
+					    pj_grp_lock_t *grp_lock,
+					    pj_stun_session **p_sess);
+
+/**
+ * Destroy the STUN session and all objects created in the context of
+ * this session.
+ *
+ * @param sess	    The STUN session instance.
+ *
+ * @return	    PJ_SUCCESS on success, or the appropriate error code.
+ *		    This function will return PJ_EPENDING if the operation
+ *		    cannot be performed immediately because callbacks are
+ *		    being called; in this case the session will be destroyed
+ *		    as soon as the last callback returns.
+ */
+PJ_DECL(pj_status_t) pj_stun_session_destroy(pj_stun_session *sess);
+
+/**
+ * Associated an arbitrary data with this STUN session. The user data may
+ * be retrieved later with pj_stun_session_get_user_data() function.
+ *
+ * @param sess	    The STUN session instance.
+ * @param user_data The user data.
+ *
+ * @return	    PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pj_stun_session_set_user_data(pj_stun_session *sess,
+						   void *user_data);
+
+/**
+ * Retrieve the user data previously associated to this STUN session with
+ * pj_stun_session_set_user_data().
+ *
+ * @param sess	    The STUN session instance.
+ *
+ * @return	    The user data associated with this STUN session.
+ */
+PJ_DECL(void*) pj_stun_session_get_user_data(pj_stun_session *sess);
+
+/**
+ * Get the group lock for this STUN session.
+ *
+ * @param sess	    The STUN session instance.
+ *
+ * @return	    The group lock.
+ */
+PJ_DECL(pj_grp_lock_t *) pj_stun_session_get_grp_lock(pj_stun_session *sess);
+
+/**
+ * Set SOFTWARE name to be included in all requests and responses.
+ *
+ * @param sess	    The STUN session instance.
+ * @param sw	    Software name string. If this argument is NULL or
+ *		    empty, the session will not include SOFTWARE attribute
+ *		    in STUN requests and responses.
+ *
+ * @return	    PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pj_stun_session_set_software_name(pj_stun_session *sess,
+						       const pj_str_t *sw);
+
+/**
+ * Set credential to be used by this session. Once credential is set, all
+ * outgoing messages will include MESSAGE-INTEGRITY, and all incoming
+ * message will be authenticated against this credential.
+ *
+ * To disable authentication after it has been set, call this function
+ * again with NULL as the argument.
+ *
+ * @param sess	    The STUN session instance.
+ * @param auth_type Type of authentication.
+ * @param cred	    The credential to be used by this session. If NULL
+ *		    is specified, authentication will be disabled.
+ *
+ * @return	    PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pj_stun_session_set_credential(pj_stun_session *sess,
+						pj_stun_auth_type auth_type,
+						const pj_stun_auth_cred *cred);
+/**
+ * Configure message logging. By default all flags are enabled.
+ *
+ * @param sess	    The STUN session instance.
+ * @param flags	    Bitmask combination of #pj_stun_sess_msg_log_flag
+ */
+PJ_DECL(void) pj_stun_session_set_log(pj_stun_session *sess,
+				      unsigned flags);
+/**
+ * Configure whether the STUN session should utilize FINGERPRINT in
+ * outgoing messages.
+ *
+ * @param sess	    The STUN session instance.
+ * @param use	    Boolean for the setting.
+ *
+ * @return	    The previous configured value of FINGERPRINT
+ *		    utilization of the sessoin.
+ */
+PJ_DECL(pj_bool_t) pj_stun_session_use_fingerprint(pj_stun_session *sess,
+						   pj_bool_t use);
+
+/**
+ * Create a STUN request message. After the message has been successfully
+ * created, application can send the message by calling 
+ * pj_stun_session_send_msg().
+ *
+ * @param sess	    The STUN session instance.
+ * @param msg_type  The STUN request message type, from pj_stun_method_e or
+ *		    from pj_stun_msg_type.
+ * @param magic	    STUN magic, use PJ_STUN_MAGIC.
+ * @param tsx_id    Optional transaction ID.
+ * @param p_tdata   Pointer to receive STUN transmit data instance containing
+ *		    the request.
+ *
+ * @return	    PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pj_stun_session_create_req(pj_stun_session *sess,
+						int msg_type,
+						pj_uint32_t magic,
+						const pj_uint8_t tsx_id[12],
+						pj_stun_tx_data **p_tdata);
+
+/**
+ * Create a STUN Indication message. After the message  has been successfully
+ * created, application can send the message by calling 
+ * pj_stun_session_send_msg().
+ *
+ * @param sess	    The STUN session instance.
+ * @param msg_type  The STUN request message type, from pj_stun_method_e or
+ *		    from pj_stun_msg_type. This function will add the
+ *		    indication bit as necessary.
+ * @param p_tdata   Pointer to receive STUN transmit data instance containing
+ *		    the message.
+ *
+ * @return	    PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pj_stun_session_create_ind(pj_stun_session *sess,
+						int msg_type,
+					        pj_stun_tx_data **p_tdata);
+
+/**
+ * Create a STUN response message. After the message has been 
+ * successfully created, application can send the message by calling 
+ * pj_stun_session_send_msg(). Alternatively application may use
+ * pj_stun_session_respond() to create and send response in one function
+ * call.
+ *
+ * @param sess	    The STUN session instance.
+ * @param rdata	    The STUN request where the response is to be created.
+ * @param err_code  Error code to be set in the response, if error response
+ *		    is to be created, according to pj_stun_status enumeration.
+ *		    This argument MUST be zero if successful response is
+ *		    to be created.
+ * @param err_msg   Optional pointer for the error message string, when
+ *		    creating error response. If the value is NULL and the
+ *		    \a err_code is non-zero, then default error message will
+ *		    be used.
+ * @param p_tdata   Pointer to receive the response message created.
+ *
+ * @return	    PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pj_stun_session_create_res(pj_stun_session *sess,
+						const pj_stun_rx_data *rdata,
+						unsigned err_code,
+						const pj_str_t *err_msg,
+						pj_stun_tx_data **p_tdata);
+
+/**
+ * Send STUN message to the specified destination. This function will encode
+ * the pj_stun_msg instance to a packet buffer, and add credential or
+ * fingerprint if necessary. If the message is a request, the session will
+ * also create and manage a STUN client transaction to be used to manage the
+ * retransmission of the request. After the message has been encoded and
+ * transaction is setup, the \a on_send_msg() callback of pj_stun_session_cb
+ * (which is registered when the STUN session is created) will be called
+ * to actually send the message to the wire.
+ *
+ * @param sess	    The STUN session instance.
+ * @param token	    Optional token which will be given back to application in
+ *		    \a on_send_msg() callback and \a on_request_complete()
+ *		    callback, if the message is a STUN request message. 
+ *		    Internally this function will put the token in the 
+ *		    \a token field of pj_stun_tx_data, hence it will
+ *		    overwrite any value that the application puts there.
+ * @param cache_res If the message is a response message for an incoming
+ *		    request, specify PJ_TRUE to instruct the STUN session
+ *		    to cache this response for subsequent incoming request
+ *		    retransmission. Otherwise this parameter will be ignored
+ *		    for non-response message.
+ * @param retransmit If the message is a request message, specify whether the
+ *		    request should be retransmitted. Normally application will
+ *		    specify TRUE if the underlying transport is UDP and FALSE
+ *		    if the underlying transport is TCP or TLS.
+ * @param dst_addr  The destination socket address.
+ * @param addr_len  Length of destination address.
+ * @param tdata	    The STUN transmit data containing the STUN message to
+ *		    be sent.
+ *
+ * @return	    PJ_SUCCESS on success, or the appropriate error code.
+ *		    This function will return PJNATH_ESTUNDESTROYED if 
+ *		    application has destroyed the session in 
+ *		    \a on_send_msg() callback.
+ */
+PJ_DECL(pj_status_t) pj_stun_session_send_msg(pj_stun_session *sess,
+					      void *token,
+					      pj_bool_t cache_res,
+					      pj_bool_t retransmit,
+					      const pj_sockaddr_t *dst_addr,
+					      unsigned addr_len,
+					      pj_stun_tx_data *tdata);
+
+/**
+ * This is a utility function to create and send response for an incoming
+ * STUN request. Internally this function calls pj_stun_session_create_res()
+ * and pj_stun_session_send_msg(). It is provided here as a matter of
+ * convenience.
+ *
+ * @param sess	    The STUN session instance.
+ * @param rdata	    The STUN request message to be responded.
+ * @param code	    Error code to be set in the response, if error response
+ *		    is to be created, according to pj_stun_status enumeration.
+ *		    This argument MUST be zero if successful response is
+ *		    to be created.
+ * @param err_msg   Optional pointer for the error message string, when
+ *		    creating error response. If the value is NULL and the
+ *		    \a err_code is non-zero, then default error message will
+ *		    be used.
+ * @param token	    Optional token which will be given back to application in
+ *		    \a on_send_msg() callback and \a on_request_complete()
+ *		    callback, if the message is a STUN request message. 
+ *		    Internally this function will put the token in the 
+ *		    \a token field of pj_stun_tx_data, hence it will
+ *		    overwrite any value that the application puts there.
+ * @param cache	    Specify whether session should cache this response for
+ *		    future request retransmission. If TRUE, subsequent request
+ *		    retransmission will be handled by the session and it 
+ *		    will not call request callback.
+ * @param dst_addr  Destination address of the response (or equal to the
+ *		    source address of the original request).
+ * @param addr_len  Address length.
+ *
+ * @return	    PJ_SUCCESS on success, or the appropriate error code.
+ *		    This function will return PJNATH_ESTUNDESTROYED if 
+ *		    application has destroyed the session in 
+ *		    \a on_send_msg() callback.
+ */
+PJ_DECL(pj_status_t) pj_stun_session_respond(pj_stun_session *sess, 
+					     const pj_stun_rx_data *rdata,
+					     unsigned code, 
+					     const char *err_msg,
+					     void *token,
+					     pj_bool_t cache, 
+					     const pj_sockaddr_t *dst_addr, 
+					     unsigned addr_len);
+
+/**
+ * Cancel outgoing STUN transaction. This operation is only valid for outgoing
+ * STUN request, to cease retransmission of the request and destroy the
+ * STUN client transaction that is used to send the request.
+ *
+ * @param sess	    The STUN session instance.
+ * @param tdata	    The request message previously sent.
+ * @param notify    Specify whether \a on_request_complete() callback should
+ *		    be called.
+ * @param status    If \a on_request_complete() callback is to be called,
+ *		    specify the error status to be given when calling the
+ *		    callback. This error status MUST NOT be PJ_SUCCESS.
+ *
+ * @return	    PJ_SUCCESS if transaction is successfully cancelled.
+ *		    This function will return PJNATH_ESTUNDESTROYED if 
+ *		    application has destroyed the session in 
+ *		    \a on_request_complete() callback.
+ */
+PJ_DECL(pj_status_t) pj_stun_session_cancel_req(pj_stun_session *sess,
+						pj_stun_tx_data *tdata,
+						pj_bool_t notify,
+						pj_status_t status);
+
+/**
+ * Explicitly request retransmission of the request. Normally application
+ * doesn't need to do this, but this functionality is needed by ICE to
+ * speed up connectivity check completion.
+ *
+ * @param sess	    The STUN session instance.
+ * @param tdata	    The request message previously sent.
+ * @param mod_count Boolean flag to indicate whether transmission count
+ *                  needs to be incremented.
+ *
+ * @return	    PJ_SUCCESS on success, or the appropriate error.
+ *		    This function will return PJNATH_ESTUNDESTROYED if 
+ *		    application has destroyed the session in \a on_send_msg()
+ *		    callback.
+ */
+PJ_DECL(pj_status_t) pj_stun_session_retransmit_req(pj_stun_session *sess,
+						    pj_stun_tx_data *tdata,
+                                                    pj_bool_t mod_count);
+
+
+/**
+ * Application must call this function to notify the STUN session about
+ * the arrival of STUN packet. The STUN packet MUST have been checked
+ * first with #pj_stun_msg_check() to verify that this is indeed a valid
+ * STUN packet.
+ *
+ * The STUN session will decode the packet into pj_stun_msg, and process
+ * the message accordingly. If the message is a response, it will search
+ * through the outstanding STUN client transactions for a matching
+ * transaction ID and hand over the response to the transaction.
+ *
+ * On successful message processing, application will be notified about
+ * the message via one of the pj_stun_session_cb callback.
+ *
+ * @param sess		The STUN session instance.
+ * @param packet	The packet containing STUN message.
+ * @param pkt_size	Size of the packet.
+ * @param options	Options, from #pj_stun_decode_options.
+ * @param parsed_len	Optional pointer to receive the size of the parsed
+ *			STUN message (useful if packet is received via a
+ *			stream oriented protocol).
+ * @param token		Optional token which will be given back to application
+ *			in the \a on_rx_request(), \a on_rx_indication() and 
+ *			\a on_send_msg() callbacks. The token can be used to 
+ *			associate processing or incoming request or indication
+ *			with some context.
+ * @param src_addr	The source address of the packet, which will also
+ *			be given back to application callbacks, along with
+ *			source address length.
+ * @param src_addr_len	Length of the source address.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ *			This function will return PJNATH_ESTUNDESTROYED if 
+ *			application has destroyed the session in one of the
+ *			callback.
+ */
+PJ_DECL(pj_status_t) pj_stun_session_on_rx_pkt(pj_stun_session *sess,
+					       const void *packet,
+					       pj_size_t pkt_size,
+					       unsigned options,
+					       void *token,
+					       pj_size_t *parsed_len,
+					       const pj_sockaddr_t *src_addr,
+					       unsigned src_addr_len);
+
+/**
+ * Destroy the transmit data. Call this function only when tdata has been
+ * created but application doesn't want to send the message (perhaps
+ * because of other error).
+ *
+ * @param sess	    The STUN session.
+ * @param tdata	    The transmit data.
+ *
+ * @return	    PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(void) pj_stun_msg_destroy_tdata(pj_stun_session *sess,
+					pj_stun_tx_data *tdata);
+
+
+/**
+ * @}
+ */
+
+
+PJ_END_DECL
+
+#endif	/* __PJNATH_STUN_SESSION_H__ */
+
diff --git a/jni/pjproject-android/.svn/pristine/84/84a8f8f4ac7f702dd2ff98ffc4fa2e87e72344f5.svn-base b/jni/pjproject-android/.svn/pristine/84/84a8f8f4ac7f702dd2ff98ffc4fa2e87e72344f5.svn-base
new file mode 100644
index 0000000..015c0c2
--- /dev/null
+++ b/jni/pjproject-android/.svn/pristine/84/84a8f8f4ac7f702dd2ff98ffc4fa2e87e72344f5.svn-base
@@ -0,0 +1,305 @@
+BODY,H1,H2,H3,H4,H5,H6,P,CENTER,TD,TH,UL,DL,DIV {
+	font-family: Geneva, Arial, Helvetica, sans-serif;
+}
+BODY,TD {
+       font-size: 80%;
+}
+CODE {
+	font-size: 120%;
+       font-family: monospace;
+}
+.fragment, pre {
+	font-size: 110%;
+       font-family: monospace;
+}
+H1 {
+	text-align: center;
+       font-size: 240%;
+}
+H2 {
+       	font-size: 200%;
+	margin-top     : 60px;
+}
+H3 {
+       font-size: 160%;
+}
+H4 {
+       font-size: 120%;
+}
+CAPTION { font-weight: bold }
+DIV.qindex {
+	width: 100%;
+	background-color: #eeeeff;
+	border: 1px solid #b0b0b0;
+	text-align: center;
+	margin: 2px;
+	padding: 2px;
+	line-height: 140%;
+}
+DIV.nav {
+	width: 100%;
+	background-color: #eeeeff;
+	border: 1px solid #b0b0b0;
+	text-align: center;
+	margin: 2px;
+	padding: 2px;
+	line-height: 140%;
+}
+A.qindex {
+       text-decoration: none;
+       font-size: 120%;
+       color: #1A419D;
+}
+A.qindex:visited {
+       text-decoration: none;
+       color: #1A419D
+}
+A.qindex:hover {
+	text-decoration: none;
+	background-color: #ddddff;
+}
+A.qindexHL {
+	text-decoration: none;
+	font-weight: bold;
+	background-color: #6666cc;
+	color: #ffffff;
+	border: 1px double #9295C2;
+}
+A.qindexHL:hover {
+	text-decoration: none;
+	background-color: #6666cc;
+	color: #ffffff;
+}
+A.qindexHL:visited { text-decoration: none; background-color: #6666cc; color: #ffffff }
+A.el { text-decoration: none; font-weight: bold }
+A.elRef { font-weight: bold }
+A.code:link { text-decoration: none; font-weight: normal; color: #0000FF; }
+A.code:visited { text-decoration: none; font-weight: normal; color: #0000FF}
+A.codeRef:link { font-weight: normal; color: #0000FF}
+A.codeRef:visited { font-weight: normal; color: #0000FF}
+A:hover { text-decoration: none; background-color: #f2f2ff }
+DL.el { margin-left: -1cm }
+PRE.fragment {
+	border: 1px solid #CCCCCC;
+	background-color: #f5f5f5;
+	margin-top: 4px;
+	margin-bottom: 4px;
+	margin-left: 2px;
+	margin-right: 8px;
+	padding-left: 6px;
+	padding-right: 6px;
+	padding-top: 4px;
+	padding-bottom: 4px;
+}
+DIV.ah { background-color: black; font-weight: bold; color: #ffffff; margin-bottom: 3px; margin-top: 3px }
+TD.md { background-color: #F4F4FB; font-weight: bold; }
+TD.mdPrefix {
+       background-color: #F4F4FB;
+       color: #606060;
+	font-size: 80%;
+}
+TD.mdname1 { background-color: #F4F4FB; font-weight: bold; color: #602020; }
+TD.mdname { background-color: #F4F4FB; font-weight: bold; color: #602020; width: 600px; }
+DIV.groupHeader {
+       margin-left: 16px;
+       margin-top: 12px;
+       margin-bottom: 6px;
+       font-weight: bold;
+}
+DIV.groupText { margin-left: 16px; font-style: italic; font-size: 90% }
+BODY {
+	background: white;
+	color: black;
+	margin-right: 20px;
+	margin-left: 20px;
+}
+TD.indexkey {
+	background-color: #eeeeff;
+	font-weight: bold;
+	padding-right  : 10px;
+	padding-top    : 2px;
+	padding-left   : 10px;
+	padding-bottom : 2px;
+	margin-left    : 0px;
+	margin-right   : 0px;
+	margin-top     : 2px;
+	margin-bottom  : 2px;
+	border: 1px solid #CCCCCC;
+}
+TD.indexvalue {
+	background-color: #eeeeff;
+	font-style: italic;
+	padding-right  : 10px;
+	padding-top    : 2px;
+	padding-left   : 10px;
+	padding-bottom : 2px;
+	margin-left    : 0px;
+	margin-right   : 0px;
+	margin-top     : 2px;
+	margin-bottom  : 2px;
+	border: 1px solid #CCCCCC;
+}
+TR.memlist {
+   background-color: #f0f0f0; 
+}
+P.formulaDsp { text-align: center; }
+IMG.formulaDsp { }
+IMG.formulaInl { vertical-align: middle; }
+SPAN.keyword       { color: #008000 }
+SPAN.keywordtype   { color: #604020 }
+SPAN.keywordflow   { color: #e08000 }
+SPAN.comment       { color: #800000 }
+SPAN.preprocessor  { color: #806020 }
+SPAN.stringliteral { color: #002080 }
+SPAN.charliteral   { color: #008080 }
+.mdTable {
+	border: 1px solid #868686;
+	background-color: #F4F4FB;
+}
+.mdRow {
+	padding: 8px 10px;
+}
+.mdescLeft {
+       padding: 0px 8px 4px 8px;
+	font-size: 80%;
+	font-style: italic;
+	background-color: #FAFAFA;
+	border-top: 1px none #E0E0E0;
+	border-right: 1px none #E0E0E0;
+	border-bottom: 1px none #E0E0E0;
+	border-left: 1px none #E0E0E0;
+	margin: 0px;
+}
+.mdescRight {
+       padding: 0px 8px 4px 8px;
+	font-size: 80%;
+	font-style: italic;
+	background-color: #FAFAFA;
+	border-top: 1px none #E0E0E0;
+	border-right: 1px none #E0E0E0;
+	border-bottom: 1px none #E0E0E0;
+	border-left: 1px none #E0E0E0;
+	margin: 0px;
+}
+.memItemLeft {
+	padding: 1px 0px 0px 8px;
+	margin: 4px;
+	border-top-width: 1px;
+	border-right-width: 1px;
+	border-bottom-width: 1px;
+	border-left-width: 1px;
+	border-top-color: #E0E0E0;
+	border-right-color: #E0E0E0;
+	border-bottom-color: #E0E0E0;
+	border-left-color: #E0E0E0;
+	border-top-style: solid;
+	border-right-style: none;
+	border-bottom-style: none;
+	border-left-style: none;
+	background-color: #FAFAFA;
+	font-size: 80%;
+}
+.memItemRight {
+	padding: 1px 8px 0px 8px;
+	margin: 4px;
+	border-top-width: 1px;
+	border-right-width: 1px;
+	border-bottom-width: 1px;
+	border-left-width: 1px;
+	border-top-color: #E0E0E0;
+	border-right-color: #E0E0E0;
+	border-bottom-color: #E0E0E0;
+	border-left-color: #E0E0E0;
+	border-top-style: solid;
+	border-right-style: none;
+	border-bottom-style: none;
+	border-left-style: none;
+	background-color: #FAFAFA;
+	font-size: 80%;
+}
+.memTemplItemLeft {
+	padding: 1px 0px 0px 8px;
+	margin: 4px;
+	border-top-width: 1px;
+	border-right-width: 1px;
+	border-bottom-width: 1px;
+	border-left-width: 1px;
+	border-top-color: #E0E0E0;
+	border-right-color: #E0E0E0;
+	border-bottom-color: #E0E0E0;
+	border-left-color: #E0E0E0;
+	border-top-style: none;
+	border-right-style: none;
+	border-bottom-style: none;
+	border-left-style: none;
+	background-color: #FAFAFA;
+	font-size: 80%;
+}
+.memTemplItemRight {
+	padding: 1px 8px 0px 8px;
+	margin: 4px;
+	border-top-width: 1px;
+	border-right-width: 1px;
+	border-bottom-width: 1px;
+	border-left-width: 1px;
+	border-top-color: #E0E0E0;
+	border-right-color: #E0E0E0;
+	border-bottom-color: #E0E0E0;
+	border-left-color: #E0E0E0;
+	border-top-style: none;
+	border-right-style: none;
+	border-bottom-style: none;
+	border-left-style: none;
+	background-color: #FAFAFA;
+	font-size: 80%;
+}
+.memTemplParams {
+	padding: 1px 0px 0px 8px;
+	margin: 4px;
+	border-top-width: 1px;
+	border-right-width: 1px;
+	border-bottom-width: 1px;
+	border-left-width: 1px;
+	border-top-color: #E0E0E0;
+	border-right-color: #E0E0E0;
+	border-bottom-color: #E0E0E0;
+	border-left-color: #E0E0E0;
+	border-top-style: solid;
+	border-right-style: none;
+	border-bottom-style: none;
+	border-left-style: none;
+       color: #606060;
+	background-color: #FAFAFA;
+	font-size: 80%;
+}
+.search     { color: #003399;
+              font-weight: bold;
+}
+FORM.search {
+              margin-bottom: 0px;
+              margin-top: 0px;
+}
+INPUT.search { font-size: 75%;
+               color: #000080;
+               font-weight: normal;
+               background-color: #eeeeff;
+}
+TD.tiny      { font-size: 75%;
+}
+a {
+	color: #252E78;
+}
+a:visited {
+	color: #3D2185;
+}
+.dirtab { padding: 4px;
+          border-collapse: collapse;
+          border: 1px solid #b0b0b0;
+}
+TH.dirtab { background: #eeeeff;
+            font-weight: bold;
+}
+HR { height: 1px;
+     border: none;
+     border-top: 1px solid black;
+}
diff --git a/jni/pjproject-android/.svn/pristine/84/84d0f6c6f254f8c6dca33d8f9f6388365f8b28bc.svn-base b/jni/pjproject-android/.svn/pristine/84/84d0f6c6f254f8c6dca33d8f9f6388365f8b28bc.svn-base
new file mode 100644
index 0000000..30021a3
--- /dev/null
+++ b/jni/pjproject-android/.svn/pristine/84/84d0f6c6f254f8c6dca33d8f9f6388365f8b28bc.svn-base
@@ -0,0 +1,1139 @@
+/* $Id$ */
+/* 
+ * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
+ * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
+ *
+ * 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 
+ */
+#include <pjmedia/wsola.h>
+#include <pjmedia/circbuf.h>
+#include <pjmedia/errno.h>
+#include <pj/assert.h>
+#include <pj/log.h>
+#include <pj/math.h>
+#include <pj/pool.h>
+
+/*
+ * This file contains implementation of WSOLA using PJMEDIA_WSOLA_IMP_WSOLA
+ * or PJMEDIA_WSOLA_IMP_NULL
+ */
+#define THIS_FILE   "wsola.c"
+
+/*
+ * http://trac.pjsip.org/repos/ticket/683:
+ *  Workaround for segfault problem in the fixed point version of create_win()
+ *  on ARM9 platform, possibly due to gcc optimization bug.
+ *
+ *  For now, we will use linear window when floating point is disabled.
+ */
+#ifndef PJMEDIA_WSOLA_LINEAR_WIN
+#   define PJMEDIA_WSOLA_LINEAR_WIN    (!PJ_HAS_FLOATING_POINT)
+#endif
+
+
+#if 0
+#   define TRACE_(x)	PJ_LOG(4,x)
+#else
+#   define TRACE_(x)
+#endif
+
+#if 0
+#   define CHECK_(x)	pj_assert(x)
+#else
+#   define CHECK_(x)
+#endif
+
+
+#if (PJMEDIA_WSOLA_IMP==PJMEDIA_WSOLA_IMP_WSOLA) || \
+    (PJMEDIA_WSOLA_IMP==PJMEDIA_WSOLA_IMP_WSOLA_LITE)
+
+/*
+ * WSOLA implementation using WSOLA
+ */
+
+/* Buffer size including history, in frames */
+#define FRAME_CNT	6
+
+/* Number of history frames in buffer */
+#define HIST_CNT	1.5
+
+/* Template size, in msec */
+#define TEMPLATE_PTIME	PJMEDIA_WSOLA_TEMPLATE_LENGTH_MSEC
+
+/* Hanning window size, in msec */
+#define HANNING_PTIME	PJMEDIA_WSOLA_DELAY_MSEC
+
+/* Number of frames in erase buffer */
+#define ERASE_CNT	((unsigned)3)
+
+/* Minimum distance from template for find_pitch() of expansion, in frames */
+#define EXP_MIN_DIST	0.5
+
+/* Maximum distance from template for find_pitch() of expansion, in frames */
+#define EXP_MAX_DIST	HIST_CNT
+
+/* Duration of a continuous synthetic frames after which the volume 
+ * of the synthetic frame will be set to zero with fading-out effect.
+ */
+#define MAX_EXPAND_MSEC	PJMEDIA_WSOLA_MAX_EXPAND_MSEC
+
+
+/* Buffer content:
+ *
+ *  +---------+-----------+--------------------+
+ *  | history | min_extra | more extra / empty |
+ *  +---------+-----------+--------------------+
+ *  ^         ^           ^                    ^
+ * buf    hist_size   min_extra            buf_size
+ * 
+ * History size (hist_size) is a constant value, initialized upon creation.
+ *
+ * min_extra size is equal to HANNING_PTIME, this samples is useful for 
+ * smoothening samples transition between generated frame & history 
+ * (when PLC is invoked), or between generated samples & normal frame 
+ * (after lost/PLC). Since min_extra samples need to be available at 
+ * any time, this will introduce delay of HANNING_PTIME ms.
+ *
+ * More extra is excess samples produced by PLC (PLC frame generation may 
+ * produce more than exact one frame).
+ *
+ * At any particular time, the buffer will contain at least (hist_size + 
+ * min_extra) samples.
+ *
+ * A "save" operation will append the new frame to the end of the buffer,
+ * return the frame from samples right after history and shift the buffer
+ * by one frame.
+ *
+ */
+
+/* WSOLA structure */
+struct pjmedia_wsola
+{
+    unsigned		 clock_rate;	    /* Sampling rate.		    */
+    pj_uint16_t		 samples_per_frame; /* Samples per frame (const)    */
+    pj_uint16_t		 channel_count;	    /* Channel countt (const)	    */
+    pj_uint16_t		 options;	    /* Options.			    */
+
+    pjmedia_circ_buf	*buf;		    /* The buffer.		    */
+    pj_int16_t		*erase_buf;	    /* Temporary erase buffer.	    */
+    pj_int16_t		*merge_buf;	    /* Temporary merge buffer.	    */
+
+    pj_uint16_t		 buf_size;	    /* Total buffer size (const)    */
+    pj_uint16_t		 hanning_size;	    /* Hanning window size (const)  */
+    pj_uint16_t		 templ_size;	    /* Template size (const)	    */
+    pj_uint16_t		 hist_size;	    /* History size (const)	    */
+
+    pj_uint16_t		 min_extra;	    /* Minimum extra (const)	    */
+    unsigned		 max_expand_cnt;    /* Max # of synthetic samples   */
+    unsigned		 fade_out_pos;	    /* Last fade-out position	    */
+    pj_uint16_t		 expand_sr_min_dist;/* Minimum distance from template 
+					       for find_pitch() on expansion
+					       (const)			    */
+    pj_uint16_t		 expand_sr_max_dist;/* Maximum distance from template 
+					       for find_pitch() on expansion
+					       (const)			    */
+
+#if defined(PJ_HAS_FLOATING_POINT) && PJ_HAS_FLOATING_POINT!=0
+    float		*hanning;	    /* Hanning window.		    */
+#else
+    pj_uint16_t		*hanning;	    /* Hanning window.		    */
+#endif
+
+    pj_timestamp	 ts;		    /* Running timestamp.	    */
+
+};
+
+#if (PJMEDIA_WSOLA_IMP==PJMEDIA_WSOLA_IMP_WSOLA_LITE)
+
+/* In this implementation, waveform similarity comparison is done by calculating
+ * the difference of total level between template frame and the target buffer 
+ * for each template_cnt samples. The smallest difference value assumed to be 
+ * the most similar block. This seems to be naive, however some tests show
+ * acceptable results and the processing speed is amazing.
+ *
+ * diff level = (template[1]+..+template[n]) - (target[1]+..+target[n])
+ */
+static pj_int16_t *find_pitch(pj_int16_t *frm, pj_int16_t *beg, pj_int16_t *end, 
+			 unsigned template_cnt, int first)
+{
+    pj_int16_t *sr, *best=beg;
+    int best_corr = 0x7FFFFFFF;
+    int frm_sum = 0;
+    unsigned i;
+
+    for (i = 0; i<template_cnt; ++i)
+	frm_sum += frm[i];
+
+    for (sr=beg; sr!=end; ++sr) {
+	int corr = frm_sum;
+	int abs_corr = 0;
+
+	/* Do calculation on 8 samples at once */
+	for (i = 0; i<template_cnt-8; i+=8) {
+	    corr -= (int)sr[i+0] +
+		    (int)sr[i+1] +
+		    (int)sr[i+2] +
+		    (int)sr[i+3] +
+		    (int)sr[i+4] +
+		    (int)sr[i+5] +
+		    (int)sr[i+6] +
+		    (int)sr[i+7];
+	}
+
+	/* Process remaining samples */
+	for (; i<template_cnt; ++i)
+	    corr -= (int)sr[i];
+
+	abs_corr = corr > 0? corr : -corr;
+
+	if (first) {
+	    if (abs_corr < best_corr) {
+		best_corr = abs_corr;
+		best = sr;
+	    }
+	} else {
+	    if (abs_corr <= best_corr) {
+		best_corr = abs_corr;
+		best = sr;
+	    }
+	}
+    }
+
+    /*TRACE_((THIS_FILE, "found pitch at %u", best-beg));*/
+    return best;
+}
+
+#endif
+
+#if defined(PJ_HAS_FLOATING_POINT) && PJ_HAS_FLOATING_POINT!=0
+/*
+ * Floating point version.
+ */
+
+#if (PJMEDIA_WSOLA_IMP==PJMEDIA_WSOLA_IMP_WSOLA)
+
+static pj_int16_t *find_pitch(pj_int16_t *frm, pj_int16_t *beg, pj_int16_t *end, 
+			 unsigned template_cnt, int first)
+{
+    pj_int16_t *sr, *best=beg;
+    double best_corr = 0;
+
+    for (sr=beg; sr!=end; ++sr) {
+	double corr = 0;
+	unsigned i;
+
+	/* Do calculation on 8 samples at once */
+	for (i=0; i<template_cnt-8; i += 8) {
+	    corr += ((float)frm[i+0]) * ((float)sr[i+0]) + 
+		    ((float)frm[i+1]) * ((float)sr[i+1]) + 
+		    ((float)frm[i+2]) * ((float)sr[i+2]) + 
+		    ((float)frm[i+3]) * ((float)sr[i+3]) + 
+		    ((float)frm[i+4]) * ((float)sr[i+4]) + 
+		    ((float)frm[i+5]) * ((float)sr[i+5]) + 
+		    ((float)frm[i+6]) * ((float)sr[i+6]) + 
+		    ((float)frm[i+7]) * ((float)sr[i+7]);
+	}
+
+	/* Process remaining samples. */
+	for (; i<template_cnt; ++i) {
+	    corr += ((float)frm[i]) * ((float)sr[i]);
+	}
+
+	if (first) {
+	    if (corr > best_corr) {
+		best_corr = corr;
+		best = sr;
+	    }
+	} else {
+	    if (corr >= best_corr) {
+		best_corr = corr;
+		best = sr;
+	    }
+	}
+    }
+
+    /*TRACE_((THIS_FILE, "found pitch at %u", best-beg));*/
+    return best;
+}
+
+#endif
+
+static void overlapp_add(pj_int16_t dst[], unsigned count,
+			 pj_int16_t l[], pj_int16_t r[],
+			 float w[])
+{
+    unsigned i;
+
+    for (i=0; i<count; ++i) {
+	dst[i] = (pj_int16_t)(l[i] * w[count-1-i] + r[i] * w[i]);
+    }
+}
+
+static void overlapp_add_simple(pj_int16_t dst[], unsigned count,
+				pj_int16_t l[], pj_int16_t r[])
+{
+    float step = (float)(1.0 / count), stepdown = 1.0;
+    unsigned i;
+
+    for (i=0; i<count; ++i) {
+	dst[i] = (pj_int16_t)(l[i] * stepdown + r[i] * (1-stepdown));
+	stepdown -= step;
+    }
+}
+
+static void create_win(pj_pool_t *pool, float **pw, unsigned count)
+{
+    unsigned i;
+    float *w = (float*)pj_pool_calloc(pool, count, sizeof(float));
+
+    *pw = w;
+
+    for (i=0;i<count; i++) {
+	w[i] = (float)(0.5 - 0.5 * cos(2.0 * PJ_PI * i / (count*2-1)) );
+    }
+}
+
+#else	/* PJ_HAS_FLOATING_POINT */
+/*
+ * Fixed point version.
+ */
+#define WINDOW_BITS	15
+enum { WINDOW_MAX_VAL = (1 << WINDOW_BITS)-1 };
+
+#if (PJMEDIA_WSOLA_IMP==PJMEDIA_WSOLA_IMP_WSOLA)
+
+static pj_int16_t *find_pitch(pj_int16_t *frm, pj_int16_t *beg, pj_int16_t *end, 
+			 unsigned template_cnt, int first)
+{
+    pj_int16_t *sr, *best=beg;
+    pj_int64_t best_corr = 0;
+
+    
+    for (sr=beg; sr!=end; ++sr) {
+	pj_int64_t corr = 0;
+	unsigned i;
+
+	/* Do calculation on 8 samples at once */
+	for (i=0; i<template_cnt-8; i+=8) {
+	    corr += ((int)frm[i+0]) * ((int)sr[i+0]) + 
+		    ((int)frm[i+1]) * ((int)sr[i+1]) + 
+		    ((int)frm[i+2]) * ((int)sr[i+2]) +
+		    ((int)frm[i+3]) * ((int)sr[i+3]) +
+		    ((int)frm[i+4]) * ((int)sr[i+4]) +
+		    ((int)frm[i+5]) * ((int)sr[i+5]) +
+		    ((int)frm[i+6]) * ((int)sr[i+6]) +
+		    ((int)frm[i+7]) * ((int)sr[i+7]);
+	}
+
+	/* Process remaining samples. */
+	for (; i<template_cnt; ++i) {
+	    corr += ((int)frm[i]) * ((int)sr[i]);
+	}
+
+	if (first) {
+	    if (corr > best_corr) {
+		best_corr = corr;
+		best = sr;
+	    }
+	} else {
+	    if (corr >= best_corr) {
+		best_corr = corr;
+		best = sr;
+	    }
+	}
+    }
+
+    /*TRACE_((THIS_FILE, "found pitch at %u", best-beg));*/
+    return best;
+}
+
+#endif
+
+
+static void overlapp_add(pj_int16_t dst[], unsigned count,
+			 pj_int16_t l[], pj_int16_t r[],
+			 pj_uint16_t w[])
+{
+    unsigned i;
+
+    for (i=0; i<count; ++i) {
+	dst[i] = (pj_int16_t)(((int)(l[i]) * (int)(w[count-1-i]) + 
+	                  (int)(r[i]) * (int)(w[i])) >> WINDOW_BITS);
+    }
+}
+
+static void overlapp_add_simple(pj_int16_t dst[], unsigned count,
+				pj_int16_t l[], pj_int16_t r[])
+{
+    int step = ((WINDOW_MAX_VAL+1) / count), 
+	stepdown = WINDOW_MAX_VAL;
+    unsigned i;
+
+    for (i=0; i<count; ++i) {
+	dst[i]=(pj_int16_t)((l[i] * stepdown + r[i] * (1-stepdown)) >> WINDOW_BITS);
+	stepdown -= step;
+    }
+}
+
+#if PJ_HAS_INT64 && !PJMEDIA_WSOLA_LINEAR_WIN
+/* approx_cos():
+ *   see: http://www.audiomulch.com/~rossb/code/sinusoids/ 
+ */
+static pj_uint32_t approx_cos( pj_uint32_t x )
+{
+    pj_uint32_t i,j,k;
+
+    if( x == 0 )
+	return 0xFFFFFFFF;
+
+    i = x << 1;
+    k = ((x + 0xBFFFFFFD) & 0x80000000) >> 30;
+    j = i - i * ((i & 0x80000000)>>30);
+    j = j >> 15;
+    j = (j * j + j) >> 1;
+    j = j - j * k;
+
+    return j;
+}
+#endif	/* PJ_HAS_INT64 && .. */
+
+static void create_win(pj_pool_t *pool, pj_uint16_t **pw, unsigned count)
+{
+    
+    unsigned i;
+    pj_uint16_t *w = (pj_uint16_t*)pj_pool_calloc(pool, count, 
+						  sizeof(pj_uint16_t));
+
+    *pw = w;
+
+    for (i=0; i<count; i++) {
+#if PJ_HAS_INT64 && !PJMEDIA_WSOLA_LINEAR_WIN
+	pj_uint32_t phase;
+	pj_uint64_t cos_val;
+
+	/* w[i] = (float)(0.5 - 0.5 * cos(2.0 * PJ_PI * i / (count*2-1)) ); */
+
+	phase = (pj_uint32_t)(PJ_INT64(0xFFFFFFFF) * i / (count*2-1));
+	cos_val = approx_cos(phase);
+
+	w[i] = (pj_uint16_t)(WINDOW_MAX_VAL - 
+			      (WINDOW_MAX_VAL * cos_val) / 0xFFFFFFFF);
+#else
+	/* Revert to linear */
+	w[i] = (pj_uint16_t)(i * WINDOW_MAX_VAL / count);
+#endif
+    }
+}
+
+#endif	/* PJ_HAS_FLOATING_POINT */
+
+/* Apply fade-in to the buffer.
+ *  - fade_cnt is the number of samples on which the volume
+ *       will go from zero to 100%
+ *  - fade_pos is current sample position within fade_cnt range.
+ *       It is zero for the first sample, so the first sample will
+ *	 have zero volume. This value is increasing.
+ */
+static void fade_in(pj_int16_t buf[], int count,
+		    int fade_in_pos, int fade_cnt)
+{
+#if defined(PJ_HAS_FLOATING_POINT) && PJ_HAS_FLOATING_POINT!=0
+    float fade_pos = (float)fade_in_pos;
+#else
+    int fade_pos = fade_in_pos;
+#endif
+
+    if (fade_cnt - fade_pos < count) {
+	for (; fade_pos < fade_cnt; ++fade_pos, ++buf) {
+	    *buf = (pj_int16_t)(*buf * fade_pos / fade_cnt);
+	}
+	/* Leave the remaining samples as is */
+    } else {
+	pj_int16_t *end = buf + count;
+	for (; buf != end; ++fade_pos, ++buf) {
+	    *buf = (pj_int16_t)(*buf * fade_pos / fade_cnt);
+	}
+    }
+}
+
+/* Apply fade-out to the buffer. */
+static void wsola_fade_out(pjmedia_wsola *wsola, 
+			   pj_int16_t buf[], int count)
+{
+    pj_int16_t *end = buf + count;
+    int fade_cnt = wsola->max_expand_cnt;
+#if defined(PJ_HAS_FLOATING_POINT) && PJ_HAS_FLOATING_POINT!=0
+    float fade_pos = (float)wsola->fade_out_pos;
+#else
+    int fade_pos = wsola->fade_out_pos;
+#endif
+
+    if (wsola->fade_out_pos == 0) {
+	pjmedia_zero_samples(buf, count);
+    } else if (fade_pos < count) {
+	for (; fade_pos; --fade_pos, ++buf) {
+	    *buf = (pj_int16_t)(*buf * fade_pos / fade_cnt);
+	}
+	if (buf != end)
+	    pjmedia_zero_samples(buf, (unsigned)(end - buf));
+	wsola->fade_out_pos = 0;
+    } else {
+	for (; buf != end; --fade_pos, ++buf) {
+	    *buf = (pj_int16_t)(*buf * fade_pos / fade_cnt);
+	}
+	wsola->fade_out_pos -= count;
+    }
+}
+
+
+PJ_DEF(pj_status_t) pjmedia_wsola_create( pj_pool_t *pool, 
+					  unsigned clock_rate,
+					  unsigned samples_per_frame,
+					  unsigned channel_count,
+					  unsigned options,
+					  pjmedia_wsola **p_wsola)
+{
+    pjmedia_wsola *wsola;
+    pj_status_t status;
+
+    PJ_ASSERT_RETURN(pool && clock_rate && samples_per_frame && p_wsola,
+		     PJ_EINVAL);
+    PJ_ASSERT_RETURN(clock_rate <= 65535, PJ_EINVAL);
+    PJ_ASSERT_RETURN(samples_per_frame < clock_rate, PJ_EINVAL);
+    PJ_ASSERT_RETURN(channel_count > 0, PJ_EINVAL);
+
+    /* Allocate wsola and initialize vars */
+    wsola = PJ_POOL_ZALLOC_T(pool, pjmedia_wsola);
+    wsola->clock_rate= (pj_uint16_t) clock_rate;
+    wsola->samples_per_frame = (pj_uint16_t) samples_per_frame;
+    wsola->channel_count = (pj_uint16_t) channel_count;
+    wsola->options = (pj_uint16_t) options;
+    wsola->max_expand_cnt = clock_rate * MAX_EXPAND_MSEC / 1000;
+    wsola->fade_out_pos = wsola->max_expand_cnt;
+
+    /* Create circular buffer */
+    wsola->buf_size = (pj_uint16_t) (samples_per_frame * FRAME_CNT);
+    status = pjmedia_circ_buf_create(pool, wsola->buf_size, &wsola->buf);
+    if (status != PJ_SUCCESS) {
+	PJ_LOG(3, (THIS_FILE, "Failed to create circular buf"));
+	return status;
+    }
+
+    /* Calculate history size */
+    wsola->hist_size = (pj_uint16_t)(HIST_CNT * samples_per_frame);
+
+    /* Calculate template size */
+    wsola->templ_size = (pj_uint16_t)(TEMPLATE_PTIME * clock_rate * 
+				      channel_count / 1000);
+    if (wsola->templ_size > samples_per_frame)
+	wsola->templ_size = wsola->samples_per_frame;
+
+    /* Calculate hanning window size */
+    wsola->hanning_size = (pj_uint16_t)(HANNING_PTIME * clock_rate * 
+				        channel_count / 1000);
+    if (wsola->hanning_size > wsola->samples_per_frame)
+	wsola->hanning_size = wsola->samples_per_frame;
+
+    pj_assert(wsola->templ_size <= wsola->hanning_size);
+
+    /* Create merge buffer */
+    wsola->merge_buf = (pj_int16_t*) pj_pool_calloc(pool, 
+						    wsola->hanning_size,
+						    sizeof(pj_int16_t));
+
+    /* Setup with PLC */
+    if ((options & PJMEDIA_WSOLA_NO_PLC) == 0) {
+	wsola->min_extra = wsola->hanning_size;
+	wsola->expand_sr_min_dist = (pj_uint16_t)
+				    (EXP_MIN_DIST * wsola->samples_per_frame);
+	wsola->expand_sr_max_dist = (pj_uint16_t)
+				    (EXP_MAX_DIST * wsola->samples_per_frame);
+    }
+
+    /* Setup with hanning */
+    if ((options & PJMEDIA_WSOLA_NO_HANNING) == 0) {
+	create_win(pool, &wsola->hanning, wsola->hanning_size);
+    }
+
+    /* Setup with discard */
+    if ((options & PJMEDIA_WSOLA_NO_DISCARD) == 0) {
+	wsola->erase_buf = (pj_int16_t*)pj_pool_calloc(pool, samples_per_frame *
+						       ERASE_CNT,
+						       sizeof(pj_int16_t));
+    }
+
+    /* Generate dummy extra */
+    pjmedia_circ_buf_set_len(wsola->buf, wsola->hist_size + wsola->min_extra);
+
+    *p_wsola = wsola;
+    return PJ_SUCCESS;
+
+}
+
+PJ_DEF(pj_status_t) pjmedia_wsola_destroy(pjmedia_wsola *wsola)
+{
+    /* Nothing to do */
+    PJ_UNUSED_ARG(wsola);
+
+    return PJ_SUCCESS;
+}
+
+PJ_DEF(pj_status_t) pjmedia_wsola_set_max_expand(pjmedia_wsola *wsola,
+						  unsigned msec)
+{
+    PJ_ASSERT_RETURN(wsola, PJ_EINVAL);
+    wsola->max_expand_cnt = msec * wsola->clock_rate / 1000;
+    return PJ_SUCCESS;
+}
+
+PJ_DEF(pj_status_t) pjmedia_wsola_reset( pjmedia_wsola *wsola,
+					 unsigned options)
+{
+    PJ_ASSERT_RETURN(wsola && options==0, PJ_EINVAL);
+    PJ_UNUSED_ARG(options);
+
+    pjmedia_circ_buf_reset(wsola->buf);
+    pjmedia_circ_buf_set_len(wsola->buf, wsola->hist_size + wsola->min_extra);
+    pjmedia_zero_samples(wsola->buf->start, wsola->buf->len); 
+    wsola->fade_out_pos = wsola->max_expand_cnt;
+
+    return PJ_SUCCESS;
+}
+
+
+static void expand(pjmedia_wsola *wsola, unsigned needed)
+{
+    unsigned generated = 0;
+    unsigned rep;
+
+    pj_int16_t *reg1, *reg2;
+    unsigned reg1_len, reg2_len;
+
+    pjmedia_circ_buf_pack_buffer(wsola->buf);
+    pjmedia_circ_buf_get_read_regions(wsola->buf, &reg1, &reg1_len, 
+				      &reg2, &reg2_len);
+    CHECK_(reg2_len == 0);
+
+    for (rep=1;; ++rep) {
+	pj_int16_t *start, *templ;
+	unsigned dist;
+
+	templ = reg1 + reg1_len - wsola->hanning_size;
+	CHECK_(templ - reg1 >= wsola->hist_size);
+
+	start = find_pitch(templ, 
+			   templ - wsola->expand_sr_max_dist, 
+			   templ - wsola->expand_sr_min_dist,
+			   wsola->templ_size, 
+			   1);
+
+	/* Should we make sure that "start" is really aligned to
+	 * channel #0, in case of stereo? Probably not necessary, as
+	 * find_pitch() should have found the best match anyway.
+	 */
+
+	if (wsola->options & PJMEDIA_WSOLA_NO_HANNING) {
+	    overlapp_add_simple(wsola->merge_buf, wsola->hanning_size, 
+			        templ, start);
+	} else {
+	    /* Check if pointers are in the valid range */
+	    CHECK_(templ >= wsola->buf->buf &&
+		   templ + wsola->hanning_size <= 
+		   wsola->buf->buf + wsola->buf->capacity);
+	    CHECK_(start >= wsola->buf->buf &&
+		   start + wsola->hanning_size <= 
+		   wsola->buf->buf + wsola->buf->capacity);
+
+	    overlapp_add(wsola->merge_buf, wsola->hanning_size, templ, 
+			 start, wsola->hanning);
+	}
+
+	/* How many new samples do we have */
+	dist = (unsigned)(templ - start);
+
+	/* Not enough buffer to hold the result */
+	if (reg1_len + dist > wsola->buf_size) {
+	    pj_assert(!"WSOLA buffer size may be to small!");
+	    break;
+	}
+
+	/* Copy the "tail" (excess frame) to the end */
+	pjmedia_move_samples(templ + wsola->hanning_size, 
+			     start + wsola->hanning_size,
+			     dist);
+
+	/* Copy the merged frame */
+	pjmedia_copy_samples(templ, wsola->merge_buf, wsola->hanning_size);
+
+	/* We have new samples */
+	reg1_len += dist;
+	pjmedia_circ_buf_set_len(wsola->buf, reg1_len);
+
+	generated += dist;
+
+	if (generated >= needed) {
+	    TRACE_((THIS_FILE, "WSOLA frame expanded after %d iterations", 
+		    rep));
+	    break;
+	}
+    }
+}
+
+
+static unsigned compress(pjmedia_wsola *wsola, pj_int16_t *buf, unsigned count,
+			 unsigned del_cnt)
+{
+    unsigned samples_del = 0, rep;
+
+    for (rep=1; ; ++rep) {
+	pj_int16_t *start, *end;
+	unsigned dist;
+
+	if (count <= wsola->hanning_size + del_cnt) {
+	    TRACE_((THIS_FILE, "Not enough samples to compress!"));
+	    return samples_del;
+	}
+
+	// Make start distance to del_cnt, so discard will be performed in
+	// only one iteration.
+	//start = buf + (frmsz >> 1);
+	start = buf + del_cnt - samples_del;
+	end = start + wsola->samples_per_frame;
+
+	if (end + wsola->hanning_size > buf + count) {
+	    end = buf+count-wsola->hanning_size;
+	}
+
+	CHECK_(start < end);
+
+	start = find_pitch(buf, start, end, wsola->templ_size, 0);
+	dist = (unsigned)(start - buf);
+
+	if (wsola->options & PJMEDIA_WSOLA_NO_HANNING) {
+	    overlapp_add_simple(buf, wsola->hanning_size, buf, start);
+	} else {
+	    overlapp_add(buf, wsola->hanning_size, buf, start, wsola->hanning);
+	}
+
+	pjmedia_move_samples(buf + wsola->hanning_size, 
+			     buf + wsola->hanning_size + dist,
+			     count - wsola->hanning_size - dist);
+
+	count -= dist;
+	samples_del += dist;
+
+	if (samples_del >= del_cnt) {
+	    TRACE_((THIS_FILE, 
+		    "Erased %d of %d requested after %d iteration(s)",
+		    samples_del, del_cnt, rep));
+	    break;
+	}
+    }
+
+    return samples_del;
+}
+
+
+
+PJ_DEF(pj_status_t) pjmedia_wsola_save( pjmedia_wsola *wsola, 
+					pj_int16_t frm[], 
+					pj_bool_t prev_lost)
+{
+    unsigned buf_len;
+    pj_status_t status;
+
+    buf_len = pjmedia_circ_buf_get_len(wsola->buf);
+
+    /* Update vars */
+    wsola->ts.u64 += wsola->samples_per_frame;
+
+    /* If previous frame was lost, smoothen this frame with the generated one */
+    if (prev_lost) {
+	pj_int16_t *reg1, *reg2;
+	unsigned reg1_len, reg2_len;
+	pj_int16_t *ola_left;
+
+	/* Trim excessive len */
+	if ((int)buf_len > wsola->hist_size + (wsola->min_extra<<1)) {
+	    buf_len = wsola->hist_size + (wsola->min_extra<<1);
+	    pjmedia_circ_buf_set_len(wsola->buf, buf_len);
+	}
+
+	pjmedia_circ_buf_get_read_regions(wsola->buf, &reg1, &reg1_len, 
+					  &reg2, &reg2_len);
+
+	CHECK_(pjmedia_circ_buf_get_len(wsola->buf) >= 
+	       (unsigned)(wsola->hist_size + (wsola->min_extra<<1)));
+
+	/* Continue applying fade out to the extra samples */
+	if ((wsola->options & PJMEDIA_WSOLA_NO_FADING)==0) {
+	    if (reg2_len == 0) {
+		wsola_fade_out(wsola, reg1 + reg1_len - (wsola->min_extra<<1),
+			       (wsola->min_extra<<1));
+	    } else if ((int)reg2_len >= (wsola->min_extra<<1)) {
+		wsola_fade_out(wsola, reg2 + reg2_len - (wsola->min_extra<<1),
+			       (wsola->min_extra<<1));
+	    } else {
+		unsigned tmp = (wsola->min_extra<<1) - reg2_len;
+		wsola_fade_out(wsola, reg1 + reg1_len - tmp, tmp);
+		wsola_fade_out(wsola, reg2, reg2_len);
+	    }
+	}
+
+	/* Get the region in buffer to be merged with the frame */
+	if (reg2_len == 0) {
+	    ola_left = reg1 + reg1_len - wsola->min_extra;
+	} else if (reg2_len >= wsola->min_extra) {
+	    ola_left = reg2 + reg2_len - wsola->min_extra;
+	} else {
+	    unsigned tmp;
+
+	    tmp = wsola->min_extra - reg2_len;
+	    pjmedia_copy_samples(wsola->merge_buf, reg1 + reg1_len - tmp, tmp);
+	    pjmedia_copy_samples(wsola->merge_buf + tmp, reg2, reg2_len);
+	    ola_left = wsola->merge_buf;
+	}
+
+	/* Apply fade-in to the frame before merging */
+	if ((wsola->options & PJMEDIA_WSOLA_NO_FADING)==0) {
+	    unsigned count = wsola->min_extra;
+	    int fade_in_pos;
+
+	    /* Scale fade_in position based on last fade-out */
+	    fade_in_pos = wsola->fade_out_pos * count /
+			  wsola->max_expand_cnt;
+
+	    /* Fade-in it */
+	    fade_in(frm, wsola->samples_per_frame,
+		    fade_in_pos, count);
+	}
+
+	/* Merge it */
+	overlapp_add_simple(frm, wsola->min_extra, ola_left, frm);
+
+	/* Trim len */
+	buf_len -= wsola->min_extra;
+	pjmedia_circ_buf_set_len(wsola->buf, buf_len);
+
+    } else if ((wsola->options & PJMEDIA_WSOLA_NO_FADING)==0 &&
+	       wsola->fade_out_pos != wsola->max_expand_cnt) 
+    {
+	unsigned count = wsola->min_extra;
+	int fade_in_pos;
+
+	/* Fade out the remaining synthetic samples */
+	if (buf_len > wsola->hist_size) {
+	    pj_int16_t *reg1, *reg2;
+	    unsigned reg1_len, reg2_len;
+
+	    /* Number of samples to fade out */
+	    count = buf_len - wsola->hist_size;
+
+	    pjmedia_circ_buf_get_read_regions(wsola->buf, &reg1, &reg1_len, 
+					      &reg2, &reg2_len);
+
+	    CHECK_(pjmedia_circ_buf_get_len(wsola->buf) >= 
+		   (unsigned)(wsola->hist_size + (wsola->min_extra<<1)));
+
+	    /* Continue applying fade out to the extra samples */
+	    if (reg2_len == 0) {
+		wsola_fade_out(wsola, reg1 + reg1_len - count, count);
+	    } else if (reg2_len >= count) {
+		wsola_fade_out(wsola, reg2 + reg2_len - count, count);
+	    } else {
+		unsigned tmp = count - reg2_len;
+		wsola_fade_out(wsola, reg1 + reg1_len - tmp, tmp);
+		wsola_fade_out(wsola, reg2, reg2_len);
+	    }
+	}
+
+	/* Apply fade-in to the frame */
+	count = wsola->min_extra;
+
+	/* Scale fade_in position based on last fade-out */
+	fade_in_pos = wsola->fade_out_pos * count /
+		      wsola->max_expand_cnt;
+
+	/* Fade it in */
+	fade_in(frm, wsola->samples_per_frame,
+		fade_in_pos, count);
+
+    }
+
+    wsola->fade_out_pos = wsola->max_expand_cnt;
+
+    status = pjmedia_circ_buf_write(wsola->buf, frm, wsola->samples_per_frame);
+    if (status != PJ_SUCCESS) {
+	TRACE_((THIS_FILE, "Failed writing to circbuf [err=%d]", status));
+	return status;
+    }
+
+    status = pjmedia_circ_buf_copy(wsola->buf, wsola->hist_size, frm, 
+				   wsola->samples_per_frame);
+    if (status != PJ_SUCCESS) {
+	TRACE_((THIS_FILE, "Failed copying from circbuf [err=%d]", status));
+	return status;
+    }
+
+    return pjmedia_circ_buf_adv_read_ptr(wsola->buf, wsola->samples_per_frame);
+}
+
+
+PJ_DEF(pj_status_t) pjmedia_wsola_generate( pjmedia_wsola *wsola, 
+					    pj_int16_t frm[])
+{
+    unsigned samples_len, samples_req;
+    pj_status_t status = PJ_SUCCESS;
+
+    CHECK_(pjmedia_circ_buf_get_len(wsola->buf) >= wsola->hist_size + 
+	   wsola->min_extra);
+
+    /* Calculate how many samples in the buffer */
+    samples_len = pjmedia_circ_buf_get_len(wsola->buf) - wsola->hist_size;
+
+    /* Calculate how many samples are required to be available in the buffer */
+    samples_req = wsola->samples_per_frame + (wsola->min_extra << 1);
+    
+    wsola->ts.u64 += wsola->samples_per_frame;
+
+    if (samples_len < samples_req) {
+	/* Expand buffer */
+	expand(wsola, samples_req - samples_len);
+	TRACE_((THIS_FILE, "Buf size after expanded = %d", 
+		pjmedia_circ_buf_get_len(wsola->buf)));
+    }
+
+    status = pjmedia_circ_buf_copy(wsola->buf, wsola->hist_size, frm, 
+				   wsola->samples_per_frame);
+    if (status != PJ_SUCCESS) {
+	TRACE_((THIS_FILE, "Failed copying from circbuf [err=%d]", status));
+	return status;
+    }
+
+    pjmedia_circ_buf_adv_read_ptr(wsola->buf, wsola->samples_per_frame);
+
+    /* Apply fade-out to the frame */
+    if ((wsola->options & PJMEDIA_WSOLA_NO_FADING)==0) {
+	wsola_fade_out(wsola, frm, wsola->samples_per_frame);
+    }
+
+    return PJ_SUCCESS;
+}
+
+
+PJ_DEF(pj_status_t) pjmedia_wsola_discard( pjmedia_wsola *wsola, 
+					   pj_int16_t buf1[],
+					   unsigned buf1_cnt, 
+					   pj_int16_t buf2[],
+					   unsigned buf2_cnt,
+					   unsigned *del_cnt)
+{
+    PJ_ASSERT_RETURN(wsola && buf1 && buf1_cnt && del_cnt, PJ_EINVAL);
+    PJ_ASSERT_RETURN(*del_cnt, PJ_EINVAL);
+
+    if (buf2_cnt == 0) {
+	/* The whole buffer is contiguous space, straight away. */
+	*del_cnt = compress(wsola, buf1, buf1_cnt, *del_cnt);
+    } else {
+	PJ_ASSERT_RETURN(buf2, PJ_EINVAL);
+
+	if (buf1_cnt < ERASE_CNT * wsola->samples_per_frame &&
+	    buf2_cnt < ERASE_CNT * wsola->samples_per_frame &&
+	    wsola->erase_buf == NULL)
+	{
+	    /* We need erase_buf but WSOLA was created with 
+	     * PJMEDIA_WSOLA_NO_DISCARD flag.
+	     */
+	    pj_assert(!"WSOLA need erase buffer!");
+	    return PJ_EINVALIDOP;
+	}
+
+	if (buf2_cnt >= ERASE_CNT * wsola->samples_per_frame) {
+	    /* Enough space to perform compress in the second buffer. */
+	    *del_cnt = compress(wsola, buf2, buf2_cnt, *del_cnt);
+	} else if (buf1_cnt >= ERASE_CNT * wsola->samples_per_frame) {
+	    /* Enough space to perform compress in the first buffer, but then
+	     * we need to re-arrange the buffers so there is no gap between 
+	     * buffers.
+	     */
+	    unsigned max;
+
+	    *del_cnt = compress(wsola, buf1, buf1_cnt, *del_cnt);
+
+	    max = *del_cnt;
+	    if (max > buf2_cnt)
+		max = buf2_cnt;
+
+	    pjmedia_move_samples(buf1 + buf1_cnt - (*del_cnt), buf2, max);
+
+	    if (max < buf2_cnt) {
+		pjmedia_move_samples(buf2, buf2+(*del_cnt), 
+				     buf2_cnt-max);
+	    }
+	} else {
+	    /* Not enough samples in either buffers to perform compress. 
+	     * Need to combine the buffers in a contiguous space, the erase_buf.
+	     */
+	    unsigned buf_size = buf1_cnt + buf2_cnt;
+	    pj_int16_t *rem;	/* remainder */
+	    unsigned rem_cnt;
+
+	    if (buf_size > ERASE_CNT * wsola->samples_per_frame) {
+		buf_size = ERASE_CNT * wsola->samples_per_frame;
+		
+		rem_cnt = buf1_cnt + buf2_cnt - buf_size;
+		rem = buf2 + buf2_cnt - rem_cnt;
+		
+	    } else {
+		rem = NULL;
+		rem_cnt = 0;
+	    }
+
+	    pjmedia_copy_samples(wsola->erase_buf, buf1, buf1_cnt);
+	    pjmedia_copy_samples(wsola->erase_buf+buf1_cnt, buf2, 
+				 buf_size-buf1_cnt);
+
+	    *del_cnt = compress(wsola, wsola->erase_buf, buf_size, *del_cnt);
+
+	    buf_size -= (*del_cnt);
+
+	    /* Copy back to buffers */
+	    if (buf_size == buf1_cnt) {
+		pjmedia_copy_samples(buf1, wsola->erase_buf, buf_size);
+		if (rem_cnt) {
+		    pjmedia_move_samples(buf2, rem, rem_cnt);
+		}
+	    } else if (buf_size < buf1_cnt) {
+		pjmedia_copy_samples(buf1, wsola->erase_buf, buf_size);
+		if (rem_cnt) {
+		    unsigned c = rem_cnt;
+		    if (c > buf1_cnt-buf_size) {
+			c = buf1_cnt-buf_size;
+		    }
+		    pjmedia_copy_samples(buf1+buf_size, rem, c);
+		    rem += c;
+		    rem_cnt -= c;
+		    if (rem_cnt)
+			pjmedia_move_samples(buf2, rem, rem_cnt);
+		}
+	    } else {
+		pjmedia_copy_samples(buf1, wsola->erase_buf, buf1_cnt);
+		pjmedia_copy_samples(buf2, wsola->erase_buf+buf1_cnt, 
+				     buf_size-buf1_cnt);
+		if (rem_cnt) {
+		    pjmedia_move_samples(buf2+buf_size-buf1_cnt, rem,
+				         rem_cnt);
+		}
+	    }
+	    
+	}
+    }
+
+    return (*del_cnt) > 0 ? PJ_SUCCESS : PJ_ETOOSMALL;
+}
+
+
+#elif PJMEDIA_WSOLA_IMP==PJMEDIA_WSOLA_IMP_NULL
+/*
+ * WSOLA implementation using NULL
+ */
+
+struct pjmedia_wsola
+{
+    unsigned samples_per_frame;
+};
+
+
+PJ_DEF(pj_status_t) pjmedia_wsola_create( pj_pool_t *pool, 
+					  unsigned clock_rate,
+					  unsigned samples_per_frame,
+					  unsigned channel_count,
+					  unsigned options,
+					  pjmedia_wsola **p_wsola)
+{
+    pjmedia_wsola *wsola;
+
+    wsola = PJ_POOL_ZALLOC_T(pool, struct pjmedia_wsola);
+    wsola->samples_per_frame = samples_per_frame;
+
+    PJ_UNUSED_ARG(clock_rate);
+    PJ_UNUSED_ARG(channel_count);
+    PJ_UNUSED_ARG(options);
+
+    *p_wsola = wsola;
+
+    return PJ_SUCCESS;
+}
+
+
+PJ_DEF(pj_status_t) pjmedia_wsola_destroy(pjmedia_wsola *wsola)
+{
+    PJ_UNUSED_ARG(wsola);
+    return PJ_SUCCESS;
+}
+
+
+PJ_DEF(pj_status_t) pjmedia_wsola_reset( pjmedia_wsola *wsola,
+					 unsigned options)
+{
+    PJ_UNUSED_ARG(wsola);
+    PJ_UNUSED_ARG(options);
+
+    return PJ_SUCCESS;
+}
+
+
+PJ_DEF(pj_status_t) pjmedia_wsola_save( pjmedia_wsola *wsola, 
+					pj_int16_t frm[], 
+					pj_bool_t prev_lost)
+{
+    PJ_UNUSED_ARG(wsola);
+    PJ_UNUSED_ARG(frm);
+    PJ_UNUSED_ARG(prev_lost);
+
+    return PJ_SUCCESS;
+}
+
+
+PJ_DEF(pj_status_t) pjmedia_wsola_generate( pjmedia_wsola *wsola, 
+					    pj_int16_t frm[])
+{
+    pjmedia_zero_samples(frm, wsola->samples_per_frame);
+    return PJ_SUCCESS;
+}
+
+
+PJ_DEF(pj_status_t) pjmedia_wsola_discard( pjmedia_wsola *wsola, 
+					   pj_int16_t buf1[],
+					   unsigned buf1_cnt, 
+					   pj_int16_t buf2[],
+					   unsigned buf2_cnt,
+					   unsigned *del_cnt)
+{
+    CHECK_(buf1_cnt + buf2_cnt >= wsola->samples_per_frame);
+
+    PJ_UNUSED_ARG(buf1);
+    PJ_UNUSED_ARG(buf1_cnt);
+    PJ_UNUSED_ARG(buf2);
+    PJ_UNUSED_ARG(buf2_cnt);
+
+    *del_cnt = wsola->samples_per_frame;
+
+    return PJ_SUCCESS;
+}
+
+#endif	/* #if PJMEDIA_WSOLA_IMP.. */
+
+
diff --git a/jni/pjproject-android/.svn/pristine/84/84e845707d60fd6512cc4ede19a821a772a6f3c8.svn-base b/jni/pjproject-android/.svn/pristine/84/84e845707d60fd6512cc4ede19a821a772a6f3c8.svn-base
new file mode 100644
index 0000000..06cb499
--- /dev/null
+++ b/jni/pjproject-android/.svn/pristine/84/84e845707d60fd6512cc4ede19a821a772a6f3c8.svn-base
@@ -0,0 +1,631 @@
+/* $Id$ */
+/* 
+ * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
+ * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
+ *
+ * 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 
+ */
+#include <pjnath/stun_auth.h>
+#include <pjnath/errno.h>
+#include <pjlib-util/hmac_sha1.h>
+#include <pjlib-util/md5.h>
+#include <pjlib-util/sha1.h>
+#include <pj/assert.h>
+#include <pj/log.h>
+#include <pj/pool.h>
+#include <pj/string.h>
+
+#define THIS_FILE   "stun_auth.c"
+
+/* Duplicate credential */
+PJ_DEF(void) pj_stun_auth_cred_dup( pj_pool_t *pool,
+				      pj_stun_auth_cred *dst,
+				      const pj_stun_auth_cred *src)
+{
+    dst->type = src->type;
+
+    switch (src->type) {
+    case PJ_STUN_AUTH_CRED_STATIC:
+	pj_strdup(pool, &dst->data.static_cred.realm,
+			&src->data.static_cred.realm);
+	pj_strdup(pool, &dst->data.static_cred.username,
+			&src->data.static_cred.username);
+	dst->data.static_cred.data_type = src->data.static_cred.data_type;
+	pj_strdup(pool, &dst->data.static_cred.data,
+			&src->data.static_cred.data);
+	pj_strdup(pool, &dst->data.static_cred.nonce,
+			&src->data.static_cred.nonce);
+	break;
+    case PJ_STUN_AUTH_CRED_DYNAMIC:
+	pj_memcpy(&dst->data.dyn_cred, &src->data.dyn_cred, 
+		  sizeof(src->data.dyn_cred));
+	break;
+    }
+}
+
+
+/*
+ * Duplicate request credential.
+ */
+PJ_DEF(void) pj_stun_req_cred_info_dup( pj_pool_t *pool,
+					pj_stun_req_cred_info *dst,
+					const pj_stun_req_cred_info *src)
+{
+    pj_strdup(pool, &dst->realm, &src->realm);
+    pj_strdup(pool, &dst->username, &src->username);
+    pj_strdup(pool, &dst->nonce, &src->nonce);
+    pj_strdup(pool, &dst->auth_key, &src->auth_key);
+}
+
+
+/* Calculate HMAC-SHA1 key for long term credential, by getting
+ * MD5 digest of username, realm, and password. 
+ */
+static void calc_md5_key(pj_uint8_t digest[16],
+			 const pj_str_t *realm,
+			 const pj_str_t *username,
+			 const pj_str_t *passwd)
+{
+    /* The 16-byte key for MESSAGE-INTEGRITY HMAC is formed by taking
+     * the MD5 hash of the result of concatenating the following five
+     * fields: (1) The username, with any quotes and trailing nulls
+     * removed, (2) A single colon, (3) The realm, with any quotes and
+     * trailing nulls removed, (4) A single colon, and (5) The 
+     * password, with any trailing nulls removed.
+     */
+    pj_md5_context ctx;
+    pj_str_t s;
+
+    pj_md5_init(&ctx);
+
+#define REMOVE_QUOTE(s)	if (s.slen && *s.ptr=='"') \
+			    s.ptr++, s.slen--; \
+			if (s.slen && s.ptr[s.slen-1]=='"') \
+			    s.slen--;
+
+    /* Add username */
+    s = *username;
+    REMOVE_QUOTE(s);
+    pj_md5_update(&ctx, (pj_uint8_t*)s.ptr, (unsigned)s.slen);
+
+    /* Add single colon */
+    pj_md5_update(&ctx, (pj_uint8_t*)":", 1);
+
+    /* Add realm */
+    s = *realm;
+    REMOVE_QUOTE(s);
+    pj_md5_update(&ctx, (pj_uint8_t*)s.ptr, (unsigned)s.slen);
+
+#undef REMOVE_QUOTE
+
+    /* Another colon */
+    pj_md5_update(&ctx, (pj_uint8_t*)":", 1);
+
+    /* Add password */
+    pj_md5_update(&ctx, (pj_uint8_t*)passwd->ptr, (unsigned)passwd->slen);
+
+    /* Done */
+    pj_md5_final(&ctx, digest);
+}
+
+
+/*
+ * Create authentication key to be used for encoding the message with
+ * MESSAGE-INTEGRITY. 
+ */
+PJ_DEF(void) pj_stun_create_key(pj_pool_t *pool,
+				pj_str_t *key,
+				const pj_str_t *realm,
+				const pj_str_t *username,
+				pj_stun_passwd_type data_type,
+				const pj_str_t *data)
+{
+    PJ_ASSERT_ON_FAIL(pool && key && username && data, return);
+
+    if (realm && realm->slen) {
+	if (data_type == PJ_STUN_PASSWD_PLAIN) {
+	    key->ptr = (char*) pj_pool_alloc(pool, 16);
+	    calc_md5_key((pj_uint8_t*)key->ptr, realm, username, data);
+	    key->slen = 16;
+	} else {
+	    pj_strdup(pool, key, data);
+	}
+    } else {
+	pj_assert(data_type == PJ_STUN_PASSWD_PLAIN);
+	pj_strdup(pool, key, data);
+    }
+}
+
+
+PJ_INLINE(pj_uint16_t) GET_VAL16(const pj_uint8_t *pdu, unsigned pos)
+{
+    return (pj_uint16_t) ((pdu[pos] << 8) + pdu[pos+1]);
+}
+
+
+PJ_INLINE(void) PUT_VAL16(pj_uint8_t *buf, unsigned pos, pj_uint16_t hval)
+{
+    buf[pos+0] = (pj_uint8_t) ((hval & 0xFF00) >> 8);
+    buf[pos+1] = (pj_uint8_t) ((hval & 0x00FF) >> 0);
+}
+
+
+/* Send 401 response */
+static pj_status_t create_challenge(pj_pool_t *pool,
+				    const pj_stun_msg *msg,
+				    int err_code,
+				    const char *errstr,
+				    const pj_str_t *realm,
+				    const pj_str_t *nonce,
+				    pj_stun_msg **p_response)
+{
+    pj_stun_msg *response;
+    pj_str_t tmp_nonce;
+    pj_str_t err_msg;
+    pj_status_t rc;
+
+    rc = pj_stun_msg_create_response(pool, msg, err_code, 
+			             (errstr?pj_cstr(&err_msg, errstr):NULL), 
+				     &response);
+    if (rc != PJ_SUCCESS)
+	return rc;
+
+    /* SHOULD NOT add REALM, NONCE, USERNAME, and M-I on 400 response */
+    if (err_code!=400 && realm && realm->slen) {
+	rc = pj_stun_msg_add_string_attr(pool, response,
+					 PJ_STUN_ATTR_REALM, 
+					 realm);
+	if (rc != PJ_SUCCESS)
+	    return rc;
+
+	/* long term must include nonce */
+	if (!nonce || nonce->slen == 0) {
+	    tmp_nonce = pj_str("pjstun");
+	    nonce = &tmp_nonce;
+	}
+    }
+
+    if (err_code!=400 && nonce && nonce->slen) {
+	rc = pj_stun_msg_add_string_attr(pool, response,
+					 PJ_STUN_ATTR_NONCE, 
+					 nonce);
+	if (rc != PJ_SUCCESS)
+	    return rc;
+    }
+
+    *p_response = response;
+
+    return PJ_SUCCESS;
+}
+
+
+/* Verify credential in the request */
+PJ_DEF(pj_status_t) pj_stun_authenticate_request(const pj_uint8_t *pkt,
+					         unsigned pkt_len,
+					         const pj_stun_msg *msg,
+					         pj_stun_auth_cred *cred,
+					         pj_pool_t *pool,
+						 pj_stun_req_cred_info *p_info,
+					         pj_stun_msg **p_response)
+{
+    pj_stun_req_cred_info tmp_info;
+    const pj_stun_msgint_attr *amsgi;
+    unsigned i, amsgi_pos;
+    pj_bool_t has_attr_beyond_mi;
+    const pj_stun_username_attr *auser;
+    const pj_stun_realm_attr *arealm;
+    const pj_stun_realm_attr *anonce;
+    pj_hmac_sha1_context ctx;
+    pj_uint8_t digest[PJ_SHA1_DIGEST_SIZE];
+    pj_stun_status err_code;
+    const char *err_text = NULL;
+    pj_status_t status;
+
+    /* msg and credential MUST be specified */
+    PJ_ASSERT_RETURN(pkt && pkt_len && msg && cred, PJ_EINVAL);
+
+    /* If p_response is specified, pool MUST be specified. */
+    PJ_ASSERT_RETURN(!p_response || pool, PJ_EINVAL);
+
+    if (p_response)
+	*p_response = NULL;
+
+    if (!PJ_STUN_IS_REQUEST(msg->hdr.type))
+	p_response = NULL;
+
+    if (p_info == NULL)
+	p_info = &tmp_info;
+
+    pj_bzero(p_info, sizeof(pj_stun_req_cred_info));
+
+    /* Get realm and nonce from credential */
+    p_info->realm.slen = p_info->nonce.slen = 0;
+    if (cred->type == PJ_STUN_AUTH_CRED_STATIC) {
+	p_info->realm = cred->data.static_cred.realm;
+	p_info->nonce = cred->data.static_cred.nonce;
+    } else if (cred->type == PJ_STUN_AUTH_CRED_DYNAMIC) {
+	status = cred->data.dyn_cred.get_auth(cred->data.dyn_cred.user_data,
+					      pool, &p_info->realm, 
+					      &p_info->nonce);
+	if (status != PJ_SUCCESS)
+	    return status;
+    } else {
+	pj_assert(!"Invalid credential type");
+	return PJ_EBUG;
+    }
+
+    /* Look for MESSAGE-INTEGRITY while counting the position */
+    amsgi_pos = 0;
+    has_attr_beyond_mi = PJ_FALSE;
+    amsgi = NULL;
+    for (i=0; i<msg->attr_count; ++i) {
+	if (msg->attr[i]->type == PJ_STUN_ATTR_MESSAGE_INTEGRITY) {
+	    amsgi = (const pj_stun_msgint_attr*) msg->attr[i];
+	} else if (amsgi) {
+	    has_attr_beyond_mi = PJ_TRUE;
+	    break;
+	} else {
+	    amsgi_pos += ((msg->attr[i]->length+3) & ~0x03) + 4;
+	}
+    }
+
+    if (amsgi == NULL) {
+	/* According to rfc3489bis-10 Sec 10.1.2/10.2.2, we should return 400
+	   for short term, and 401 for long term.
+	   The rule has been changed from rfc3489bis-06
+	*/
+	err_code = p_info->realm.slen ? PJ_STUN_SC_UNAUTHORIZED : 
+		    PJ_STUN_SC_BAD_REQUEST;
+	goto on_auth_failed;
+    }
+
+    /* Next check that USERNAME is present */
+    auser = (const pj_stun_username_attr*)
+	    pj_stun_msg_find_attr(msg, PJ_STUN_ATTR_USERNAME, 0);
+    if (auser == NULL) {
+	/* According to rfc3489bis-10 Sec 10.1.2/10.2.2, we should return 400
+	   for both short and long term, since M-I is present.
+	   The rule has been changed from rfc3489bis-06
+	*/
+	err_code = PJ_STUN_SC_BAD_REQUEST;
+	err_text = "Missing USERNAME";
+	goto on_auth_failed;
+    }
+
+    /* Get REALM, if any */
+    arealm = (const pj_stun_realm_attr*)
+	     pj_stun_msg_find_attr(msg, PJ_STUN_ATTR_REALM, 0);
+
+    /* Reject with 400 if we have long term credential and the request
+     * is missing REALM attribute.
+     */
+    if (p_info->realm.slen && arealm==NULL) {
+	err_code = PJ_STUN_SC_BAD_REQUEST;
+	err_text = "Missing REALM";
+	goto on_auth_failed;
+    }
+
+    /* Check if username match */
+    if (cred->type == PJ_STUN_AUTH_CRED_STATIC) {
+	pj_bool_t username_ok;
+	username_ok = !pj_strcmp(&auser->value, 
+				 &cred->data.static_cred.username);
+	if (username_ok) {
+	    pj_strdup(pool, &p_info->username, 
+		      &cred->data.static_cred.username);
+	    pj_stun_create_key(pool, &p_info->auth_key, &p_info->realm,
+			       &auser->value, cred->data.static_cred.data_type,
+			       &cred->data.static_cred.data);
+	} else {
+	    /* Username mismatch */
+	    /* According to rfc3489bis-10 Sec 10.1.2/10.2.2, we should 
+	     * return 401 
+	     */
+	    err_code = PJ_STUN_SC_UNAUTHORIZED;
+	    goto on_auth_failed;
+	}
+    } else if (cred->type == PJ_STUN_AUTH_CRED_DYNAMIC) {
+	pj_stun_passwd_type data_type = PJ_STUN_PASSWD_PLAIN;
+	pj_str_t password;
+	pj_status_t rc;
+
+	rc = cred->data.dyn_cred.get_password(msg, 
+					      cred->data.dyn_cred.user_data,
+					      (arealm?&arealm->value:NULL),
+					      &auser->value, pool,
+					      &data_type, &password);
+	if (rc == PJ_SUCCESS) {
+	    pj_strdup(pool, &p_info->username, &auser->value);
+	    pj_stun_create_key(pool, &p_info->auth_key, 
+			       (arealm?&arealm->value:NULL), &auser->value, 
+			       data_type, &password);
+	} else {
+	    err_code = PJ_STUN_SC_UNAUTHORIZED;
+	    goto on_auth_failed;
+	}
+    } else {
+	pj_assert(!"Invalid credential type");
+	return PJ_EBUG;
+    }
+
+
+
+    /* Get NONCE attribute */
+    anonce = (pj_stun_nonce_attr*)
+	     pj_stun_msg_find_attr(msg, PJ_STUN_ATTR_NONCE, 0);
+
+    /* Check for long term/short term requirements. */
+    if (p_info->realm.slen != 0 && arealm == NULL) {
+	/* Long term credential is required and REALM is not present */
+	err_code = PJ_STUN_SC_BAD_REQUEST;
+	err_text = "Missing REALM";
+	goto on_auth_failed;
+
+    } else if (p_info->realm.slen != 0 && arealm != NULL) {
+	/* We want long term, and REALM is present */
+
+	/* NONCE must be present. */
+	if (anonce == NULL && p_info->nonce.slen) {
+	    err_code = PJ_STUN_SC_BAD_REQUEST;
+	    err_text = "Missing NONCE";
+	    goto on_auth_failed;
+	}
+
+	/* Verify REALM matches */
+	if (pj_stricmp(&arealm->value, &p_info->realm)) {
+	    /* REALM doesn't match */
+	    err_code = PJ_STUN_SC_UNAUTHORIZED;
+	    err_text = "Invalid REALM";
+	    goto on_auth_failed;
+	}
+
+	/* Valid case, will validate the message integrity later */
+
+    } else if (p_info->realm.slen == 0 && arealm != NULL) {
+	/* We want to use short term credential, but client uses long
+	 * term credential. The draft doesn't mention anything about
+	 * switching between long term and short term.
+	 */
+	
+	/* For now just accept the credential, anyway it will probably
+	 * cause wrong message integrity value later.
+	 */
+    } else if (p_info->realm.slen==0 && arealm == NULL) {
+	/* Short term authentication is wanted, and one is supplied */
+
+	/* Application MAY request NONCE to be supplied */
+	if (p_info->nonce.slen != 0) {
+	    err_code = PJ_STUN_SC_UNAUTHORIZED;
+	    err_text = "NONCE required";
+	    goto on_auth_failed;
+	}
+    }
+
+    /* If NONCE is present, validate it */
+    if (anonce) {
+	pj_bool_t ok;
+
+	if (cred->type == PJ_STUN_AUTH_CRED_DYNAMIC &&
+	    cred->data.dyn_cred.verify_nonce != NULL) 
+	{
+	    ok=cred->data.dyn_cred.verify_nonce(msg, 
+						cred->data.dyn_cred.user_data,
+						(arealm?&arealm->value:NULL),
+						&auser->value,
+						&anonce->value);
+	} else if (cred->type == PJ_STUN_AUTH_CRED_DYNAMIC) {
+	    ok = PJ_TRUE;
+	} else {
+	    if (p_info->nonce.slen) {
+		ok = !pj_strcmp(&anonce->value, &p_info->nonce);
+	    } else {
+		ok = PJ_TRUE;
+	    }
+	}
+
+	if (!ok) {
+	    err_code = PJ_STUN_SC_STALE_NONCE;
+	    goto on_auth_failed;
+	}
+    }
+
+    /* Now calculate HMAC of the message. */
+    pj_hmac_sha1_init(&ctx, (pj_uint8_t*)p_info->auth_key.ptr, 
+		      (unsigned)p_info->auth_key.slen);
+
+#if PJ_STUN_OLD_STYLE_MI_FINGERPRINT
+    /* Pre rfc3489bis-06 style of calculation */
+    pj_hmac_sha1_update(&ctx, pkt, 20);
+#else
+    /* First calculate HMAC for the header.
+     * The calculation is different depending on whether FINGERPRINT attribute
+     * is present in the message.
+     */
+    if (has_attr_beyond_mi) {
+	pj_uint8_t hdr_copy[20];
+	pj_memcpy(hdr_copy, pkt, 20);
+	PUT_VAL16(hdr_copy, 2, (pj_uint16_t)(amsgi_pos + 24));
+	pj_hmac_sha1_update(&ctx, hdr_copy, 20);
+    } else {
+	pj_hmac_sha1_update(&ctx, pkt, 20);
+    }
+#endif	/* PJ_STUN_OLD_STYLE_MI_FINGERPRINT */
+
+    /* Now update with the message body */
+    pj_hmac_sha1_update(&ctx, pkt+20, amsgi_pos);
+#if PJ_STUN_OLD_STYLE_MI_FINGERPRINT
+    // This is no longer necessary as per rfc3489bis-08
+    if ((amsgi_pos+20) & 0x3F) {
+    	pj_uint8_t zeroes[64];
+    	pj_bzero(zeroes, sizeof(zeroes));
+    	pj_hmac_sha1_update(&ctx, zeroes, 64-((amsgi_pos+20) & 0x3F));
+    }
+#endif
+    pj_hmac_sha1_final(&ctx, digest);
+
+
+    /* Compare HMACs */
+    if (pj_memcmp(amsgi->hmac, digest, 20)) {
+	/* HMAC value mismatch */
+	/* According to rfc3489bis-10 Sec 10.1.2 we should return 401 */
+	err_code = PJ_STUN_SC_UNAUTHORIZED;
+	err_text = "MESSAGE-INTEGRITY mismatch";
+	goto on_auth_failed;
+    }
+
+    /* Everything looks okay! */
+    return PJ_SUCCESS;
+
+on_auth_failed:
+    if (p_response) {
+	create_challenge(pool, msg, err_code, err_text,
+			 &p_info->realm, &p_info->nonce, p_response);
+    }
+    return PJ_STATUS_FROM_STUN_CODE(err_code);
+}
+
+
+/* Determine if STUN message can be authenticated */
+PJ_DEF(pj_bool_t) pj_stun_auth_valid_for_msg(const pj_stun_msg *msg)
+{
+    unsigned msg_type = msg->hdr.type;
+    const pj_stun_errcode_attr *err_attr;
+
+    /* STUN requests and success response can be authenticated */
+    if (!PJ_STUN_IS_ERROR_RESPONSE(msg_type) && 
+	!PJ_STUN_IS_INDICATION(msg_type))
+    {
+	return PJ_TRUE;
+    }
+
+    /* STUN Indication cannot be authenticated */
+    if (PJ_STUN_IS_INDICATION(msg_type))
+	return PJ_FALSE;
+
+    /* Authentication for STUN error responses depend on the error
+     * code.
+     */
+    err_attr = (const pj_stun_errcode_attr*)
+	       pj_stun_msg_find_attr(msg, PJ_STUN_ATTR_ERROR_CODE, 0);
+    if (err_attr == NULL) {
+	PJ_LOG(4,(THIS_FILE, "STUN error code attribute not present in "
+			     "error response"));
+	return PJ_TRUE;
+    }
+
+    switch (err_attr->err_code) {
+    case PJ_STUN_SC_BAD_REQUEST:	    /* 400 (Bad Request)	    */
+    case PJ_STUN_SC_UNAUTHORIZED:	    /* 401 (Unauthorized)	    */
+    case PJ_STUN_SC_STALE_NONCE:	    /* 438 (Stale Nonce)	    */
+
+    /* Due to the way this response is generated here, we can't really
+     * authenticate 420 (Unknown Attribute) response			    */
+    case PJ_STUN_SC_UNKNOWN_ATTRIBUTE:
+	return PJ_FALSE;
+    default:
+	return PJ_TRUE;
+    }
+}
+
+
+/* Authenticate MESSAGE-INTEGRITY in the response */
+PJ_DEF(pj_status_t) pj_stun_authenticate_response(const pj_uint8_t *pkt,
+					          unsigned pkt_len,
+					          const pj_stun_msg *msg,
+					          const pj_str_t *key)
+{
+    const pj_stun_msgint_attr *amsgi;
+    unsigned i, amsgi_pos;
+    pj_bool_t has_attr_beyond_mi;
+    pj_hmac_sha1_context ctx;
+    pj_uint8_t digest[PJ_SHA1_DIGEST_SIZE];
+
+    PJ_ASSERT_RETURN(pkt && pkt_len && msg && key, PJ_EINVAL);
+
+    /* First check that MESSAGE-INTEGRITY is present */
+    amsgi = (const pj_stun_msgint_attr*)
+	    pj_stun_msg_find_attr(msg, PJ_STUN_ATTR_MESSAGE_INTEGRITY, 0);
+    if (amsgi == NULL) {
+	return PJ_STATUS_FROM_STUN_CODE(PJ_STUN_SC_UNAUTHORIZED);
+    }
+
+
+    /* Check that message length is valid */
+    if (msg->hdr.length < 24) {
+	return PJNATH_EINSTUNMSGLEN;
+    }
+
+    /* Look for MESSAGE-INTEGRITY while counting the position */
+    amsgi_pos = 0;
+    has_attr_beyond_mi = PJ_FALSE;
+    amsgi = NULL;
+    for (i=0; i<msg->attr_count; ++i) {
+	if (msg->attr[i]->type == PJ_STUN_ATTR_MESSAGE_INTEGRITY) {
+	    amsgi = (const pj_stun_msgint_attr*) msg->attr[i];
+	} else if (amsgi) {
+	    has_attr_beyond_mi = PJ_TRUE;
+	    break;
+	} else {
+	    amsgi_pos += ((msg->attr[i]->length+3) & ~0x03) + 4;
+	}
+    }
+
+    if (amsgi == NULL) {
+	return PJ_STATUS_FROM_STUN_CODE(PJ_STUN_SC_BAD_REQUEST);
+    }
+
+    /* Now calculate HMAC of the message. */
+    pj_hmac_sha1_init(&ctx, (pj_uint8_t*)key->ptr, (unsigned)key->slen);
+
+#if PJ_STUN_OLD_STYLE_MI_FINGERPRINT
+    /* Pre rfc3489bis-06 style of calculation */
+    pj_hmac_sha1_update(&ctx, pkt, 20);
+#else
+    /* First calculate HMAC for the header.
+     * The calculation is different depending on whether FINGERPRINT attribute
+     * is present in the message.
+     */
+    if (has_attr_beyond_mi) {
+	pj_uint8_t hdr_copy[20];
+	pj_memcpy(hdr_copy, pkt, 20);
+	PUT_VAL16(hdr_copy, 2, (pj_uint16_t)(amsgi_pos+24));
+	pj_hmac_sha1_update(&ctx, hdr_copy, 20);
+    } else {
+	pj_hmac_sha1_update(&ctx, pkt, 20);
+    }
+#endif	/* PJ_STUN_OLD_STYLE_MI_FINGERPRINT */
+
+    /* Now update with the message body */
+    pj_hmac_sha1_update(&ctx, pkt+20, amsgi_pos);
+#if PJ_STUN_OLD_STYLE_MI_FINGERPRINT
+    // This is no longer necessary as per rfc3489bis-08
+    if ((amsgi_pos+20) & 0x3F) {
+    	pj_uint8_t zeroes[64];
+    	pj_bzero(zeroes, sizeof(zeroes));
+    	pj_hmac_sha1_update(&ctx, zeroes, 64-((amsgi_pos+20) & 0x3F));
+    }
+#endif
+    pj_hmac_sha1_final(&ctx, digest);
+
+    /* Compare HMACs */
+    if (pj_memcmp(amsgi->hmac, digest, 20)) {
+	/* HMAC value mismatch */
+	return PJ_STATUS_FROM_STUN_CODE(PJ_STUN_SC_UNAUTHORIZED);
+    }
+
+    /* Everything looks okay! */
+    return PJ_SUCCESS;
+}
+