* #39226: Switch back to pjsip rev 4710

Rev 4716 introduces errors when building for android (miltiple definitions)
diff --git a/jni/pjproject-android/.svn/pristine/1e/1e28929dc32c179b80b506c49f56b0941772d871.svn-base b/jni/pjproject-android/.svn/pristine/1e/1e28929dc32c179b80b506c49f56b0941772d871.svn-base
new file mode 100644
index 0000000..866f4fa
--- /dev/null
+++ b/jni/pjproject-android/.svn/pristine/1e/1e28929dc32c179b80b506c49f56b0941772d871.svn-base
@@ -0,0 +1,184 @@
+/* $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_WAVE_H__
+#define __PJMEDIA_WAVE_H__
+
+
+/**
+ * @file wave.h
+ * @brief WAVE file manipulation.
+ */
+#include <pjmedia/types.h>
+
+/**
+ * @defgroup PJMEDIA_FILE_FORMAT File Formats
+ * @brief Supported file formats
+ */
+
+
+/**
+ * @defgroup PJMEDIA_WAVE WAVE Header
+ * @ingroup PJMEDIA_FILE_FORMAT
+ * @brief Representation of RIFF/WAVE file format
+ * @{
+ *
+ * This the the low level representation of RIFF/WAVE file format. For
+ * higher abstraction, please see \ref PJMEDIA_FILE_PLAY and 
+ * \ref PJMEDIA_FILE_REC.
+ */
+
+
+PJ_BEGIN_DECL
+
+/**
+ * Standard RIFF tag to identify RIFF file format in the WAVE header.
+ */
+#define PJMEDIA_RIFF_TAG	('F'<<24|'F'<<16|'I'<<8|'R')
+
+/**
+ * Standard WAVE tag to identify WAVE header.
+ */
+#define PJMEDIA_WAVE_TAG	('E'<<24|'V'<<16|'A'<<8|'W')
+
+/**
+ * Standard FMT tag to identify format chunks.
+ */
+#define PJMEDIA_FMT_TAG		(' '<<24|'t'<<16|'m'<<8|'f')
+
+/**
+ * Standard DATA tag to identify data chunks.
+ */
+#define PJMEDIA_DATA_TAG	('a'<<24|'t'<<16|'a'<<8|'d')
+
+/**
+ * Standard FACT tag to identify fact chunks.
+ */
+#define PJMEDIA_FACT_TAG	('t'<<24|'c'<<16|'a'<<8|'f')
+
+
+/**
+ * Enumeration of format compression tag.
+ */
+typedef enum {
+    PJMEDIA_WAVE_FMT_TAG_PCM	= 1,
+    PJMEDIA_WAVE_FMT_TAG_ALAW	= 6,
+    PJMEDIA_WAVE_FMT_TAG_ULAW	= 7
+} pjmedia_wave_fmt_tag;
+
+
+/**
+ * This file describes the simpler/canonical version of a WAVE file.
+ * It does not support the full RIFF format specification.
+ */
+#pragma pack(2)
+struct pjmedia_wave_hdr
+{
+    /** This structure describes RIFF WAVE file header */
+    struct {
+	pj_uint32_t riff;		/**< "RIFF" ASCII tag.		*/
+	pj_uint32_t file_len;		/**< File length minus 8 bytes	*/
+	pj_uint32_t wave;		/**< "WAVE" ASCII tag.		*/
+    } riff_hdr;
+
+    /** This structure describes format chunks/header  */
+    struct {
+	pj_uint32_t fmt;		/**< "fmt " ASCII tag.		*/
+	pj_uint32_t len;		/**< 16 for PCM.		*/
+	pj_uint16_t fmt_tag;		/**< 1 for PCM			*/
+	pj_uint16_t nchan;		/**< Number of channels.	*/
+	pj_uint32_t sample_rate;	/**< Sampling rate.		*/
+	pj_uint32_t bytes_per_sec;	/**< Average bytes per second.	*/
+	pj_uint16_t block_align;	/**< nchannels * bits / 8	*/
+	pj_uint16_t bits_per_sample;	/**< Bits per sample.		*/
+    } fmt_hdr;
+
+    /** The data header preceeds the actual data in the file. */
+    struct {
+	pj_uint32_t data;		/**< "data" ASCII tag.		*/
+	pj_uint32_t len;		/**< Data length.		*/
+    } data_hdr;
+};
+#pragma pack()
+
+/**
+ * @see pjmedia_wave_hdr
+ */
+typedef struct pjmedia_wave_hdr pjmedia_wave_hdr;
+
+/**
+ * This structure describes generic RIFF subchunk header.
+ */
+typedef struct pjmedia_wave_subchunk
+{
+    pj_uint32_t	    id;			/**< Subchunk ASCII tag.	    */
+    pj_uint32_t	    len;		/**< Length following this field    */
+} pjmedia_wave_subchunk;
+
+
+/**
+ * Normalize subchunk header from little endian (the representation of
+ * RIFF file) into host's endian.
+ */
+#if defined(PJ_IS_BIG_ENDIAN) && PJ_IS_BIG_ENDIAN!=0
+#   define PJMEDIA_WAVE_NORMALIZE_SUBCHUNK(ch)  \
+	    do { \
+		(ch)->id = pj_swap32((ch)->id); \
+		(ch)->len = pj_swap32((ch)->len); \
+	    } while (0)
+#else
+#   define PJMEDIA_WAVE_NORMALIZE_SUBCHUNK(ch)
+#endif
+
+
+/**
+ * On big-endian hosts, this function swaps the byte order of the values
+ * in the WAVE header fields. On little-endian hosts, this function does 
+ * nothing.
+ *
+ * Application SHOULD call this function after reading the WAVE header
+ * chunks from a file.
+ *
+ * @param hdr	    The WAVE header.
+ */
+PJ_DECL(void) pjmedia_wave_hdr_file_to_host( pjmedia_wave_hdr *hdr );
+
+
+/**
+ * On big-endian hosts, this function swaps the byte order of the values
+ * in the WAVE header fields. On little-endian hosts, this function does 
+ * nothing.
+ *
+ * Application SHOULD call this function before writing the WAVE header
+ * to a file.
+ *
+ * @param hdr	    The WAVE header.
+ */
+PJ_DECL(void) pjmedia_wave_hdr_host_to_file( pjmedia_wave_hdr *hdr );
+
+
+PJ_END_DECL
+
+/**
+ * @}
+ */
+
+
+#endif	/* __PJMEDIA_WAVE_H__ */
+
diff --git a/jni/pjproject-android/.svn/pristine/1e/1e2ba18d7ee58c57a81b61e3aee3e5f97e233293.svn-base b/jni/pjproject-android/.svn/pristine/1e/1e2ba18d7ee58c57a81b61e3aee3e5f97e233293.svn-base
new file mode 100644
index 0000000..d3783b8
--- /dev/null
+++ b/jni/pjproject-android/.svn/pristine/1e/1e2ba18d7ee58c57a81b61e3aee3e5f97e233293.svn-base
@@ -0,0 +1,9 @@
+export OS_CFLAGS   := $(CC_DEF)PJ_LINUX=1
+
+export OS_CXXFLAGS := 
+
+export OS_LDFLAGS  := -lportaudio-$(TARGET_NAME) -lgsmcodec-$(TARGET_NAME) -lilbccodec-$(TARGET_NAME) -lspeex-$(TARGET_NAME) -lresample-$(TARGET_NAME) $(CC_LIB)pthread$(LIBEXT2) -lm
+
+export OS_SOURCES  := 
+
+
diff --git a/jni/pjproject-android/.svn/pristine/1e/1e2d9a940e981762385c6c07e067a88b456b8ea1.svn-base b/jni/pjproject-android/.svn/pristine/1e/1e2d9a940e981762385c6c07e067a88b456b8ea1.svn-base
new file mode 100644
index 0000000..6db3b2a
--- /dev/null
+++ b/jni/pjproject-android/.svn/pristine/1e/1e2d9a940e981762385c6c07e067a88b456b8ea1.svn-base
@@ -0,0 +1,59 @@
+gsm-1.0/COPYRIGHT
+gsm-1.0/ChangeLog
+gsm-1.0/INSTALL
+gsm-1.0/MACHINES
+gsm-1.0/MANIFEST
+gsm-1.0/Makefile
+gsm-1.0/README
+gsm-1.0/add-test/add_test.c
+gsm-1.0/add-test/add_test.dta
+gsm-1.0/inc/gsm.h
+gsm-1.0/inc/proto.h
+gsm-1.0/inc/unproto.h
+gsm-1.0/inc/config.h
+gsm-1.0/inc/private.h
+gsm-1.0/inc/toast.h
+gsm-1.0/man/bitter.1
+gsm-1.0/man/gsm.3
+gsm-1.0/man/gsm_explode.3
+gsm-1.0/man/gsm_print.3
+gsm-1.0/man/gsm_option.3
+gsm-1.0/man/toast.1
+gsm-1.0/src/add.c
+gsm-1.0/src/code.c
+gsm-1.0/src/debug.c
+gsm-1.0/src/decode.c
+gsm-1.0/src/gsm_destroy.c
+gsm-1.0/src/gsm_decode.c
+gsm-1.0/src/gsm_encode.c
+gsm-1.0/src/gsm_explode.c
+gsm-1.0/src/gsm_implode.c
+gsm-1.0/src/gsm_create.c
+gsm-1.0/src/gsm_print.c
+gsm-1.0/src/gsm_option.c
+gsm-1.0/src/long_term.c
+gsm-1.0/src/lpc.c
+gsm-1.0/src/preprocess.c
+gsm-1.0/src/rpe.c
+gsm-1.0/src/short_term.c
+gsm-1.0/src/table.c
+gsm-1.0/src/toast.c
+gsm-1.0/src/toast_alaw.c
+gsm-1.0/src/toast_audio.c
+gsm-1.0/src/toast_lin.c
+gsm-1.0/src/toast_ulaw.c
+gsm-1.0/tls/bitter.c
+gsm-1.0/tls/bitter.dta
+gsm-1.0/tls/taste.c
+gsm-1.0/tls/taste.h
+gsm-1.0/tls/sweet.c
+gsm-1.0/tls/sour.c
+gsm-1.0/tls/sour1.dta
+gsm-1.0/tls/sour2.dta
+gsm-1.0/tls/ginger.c
+gsm-1.0/tst/cod2lin.c
+gsm-1.0/tst/cod2txt.c
+gsm-1.0/tst/gsm2cod.c
+gsm-1.0/tst/lin2cod.c
+gsm-1.0/tst/lin2txt.c
+gsm-1.0/tst/run
diff --git a/jni/pjproject-android/.svn/pristine/1e/1e70e8792c8d64acccccc886c29de72cc8818498.svn-base b/jni/pjproject-android/.svn/pristine/1e/1e70e8792c8d64acccccc886c29de72cc8818498.svn-base
new file mode 100644
index 0000000..dffd3b8
--- /dev/null
+++ b/jni/pjproject-android/.svn/pristine/1e/1e70e8792c8d64acccccc886c29de72cc8818498.svn-base
@@ -0,0 +1,4615 @@
+/* $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 "_pjsua.h"
+
+#define THIS_FILE    "main.c"
+#define POOL_SIZE    512
+#define SND_DEV_NUM  64
+#define SND_NAME_LEN  64
+
+/* LIB BASE */
+
+static PyObject* g_obj_log_cb;
+static long g_thread_id;
+static struct py_thread_desc
+{
+    struct py_thread_desc *next;
+    pj_thread_desc	   desc;
+} *py_thread_desc;
+
+/*
+ * The global callback object.
+ */
+static PyObj_pjsua_callback * g_obj_callback;
+
+/* Set this to 1 if all threads are created by Python */
+#define NO_PJSIP_THREAD 1
+
+#if NO_PJSIP_THREAD
+#   define ENTER_PYTHON()
+#   define LEAVE_PYTHON()
+#else
+#   define ENTER_PYTHON()   PyGILState_STATE state = PyGILState_Ensure()
+#   define LEAVE_PYTHON()   PyGILState_Release(state)
+#endif
+
+
+static void clear_py_thread_desc(void)
+{
+    while (py_thread_desc) {
+	struct py_thread_desc *next = py_thread_desc->next;
+	free(py_thread_desc);
+	py_thread_desc = next;
+    }
+}
+
+
+/*
+ * cb_log_cb
+ * declares method for reconfiguring logging process for callback struct
+ */
+static void cb_log_cb(int level, const char *data, int len)
+{
+	
+    /* Ignore if this callback is called from alien thread context,
+     * or otherwise it will crash Python.
+     */
+    if (pj_thread_local_get(g_thread_id) == 0)
+	return;
+
+    if (PyCallable_Check(g_obj_log_cb)) {
+	PyObject *param_data;
+
+	ENTER_PYTHON();
+
+	param_data = PyString_FromStringAndSize(data, len);
+
+        PyObject_CallFunction(
+            g_obj_log_cb, 
+	    "iOi",
+	    level,
+            param_data, 
+	    len, 
+	    NULL
+        );
+
+	Py_DECREF(param_data);
+
+	LEAVE_PYTHON();
+    }
+}
+
+/*
+ * cb_on_call_state
+ * declares method on_call_state for callback struct
+ */
+static void cb_on_call_state(pjsua_call_id call_id, pjsip_event *e)
+{
+    PJ_UNUSED_ARG(e);
+
+    if (PyCallable_Check(g_obj_callback->on_call_state)) {	
+        PyObject * obj;
+
+	ENTER_PYTHON();
+
+	obj = Py_BuildValue("");
+		
+        PyObject_CallFunction(
+            g_obj_callback->on_call_state,
+	    "iO",
+	    call_id,
+	    obj,
+	    NULL
+        );
+
+	Py_DECREF(obj);
+
+	LEAVE_PYTHON();
+    }
+}
+
+
+/*
+ * cb_on_incoming_call
+ * declares method on_incoming_call for callback struct
+ */
+static void cb_on_incoming_call(pjsua_acc_id acc_id, pjsua_call_id call_id,
+				pjsip_rx_data *rdata)
+{
+    if (PyCallable_Check(g_obj_callback->on_incoming_call)) {
+	PyObj_pjsip_rx_data *obj;
+	
+	ENTER_PYTHON();
+	
+	obj = (PyObj_pjsip_rx_data*)
+	      PyObj_pjsip_rx_data_new(&PyTyp_pjsip_rx_data,
+				      NULL, NULL);
+	PyObj_pjsip_rx_data_import(obj, rdata);
+
+	PyObject_CallFunction(
+	    g_obj_callback->on_incoming_call,
+	    "iiO",
+	    acc_id,
+	    call_id,
+	    obj,
+	    NULL
+	);
+
+	Py_DECREF(obj);
+
+	LEAVE_PYTHON();
+    }
+}
+
+
+/*
+ * cb_on_call_media_state
+ * declares method on_call_media_state for callback struct
+ */
+static void cb_on_call_media_state(pjsua_call_id call_id)
+{
+    if (PyCallable_Check(g_obj_callback->on_call_media_state)) {
+
+	ENTER_PYTHON();
+
+        PyObject_CallFunction(
+	    g_obj_callback->on_call_media_state,
+	    "i",
+	    call_id,
+	    NULL
+	);
+
+	LEAVE_PYTHON();
+    }
+}
+
+
+/*
+ * cb_on_dtmf_digit()
+ * Callback from PJSUA-LIB on receiving DTMF digit
+ */
+static void cb_on_dtmf_digit(pjsua_call_id call_id, int digit)
+{
+    if (PyCallable_Check(g_obj_callback->on_dtmf_digit)) {
+	char digit_str[10];
+
+	PyGILState_STATE state = PyGILState_Ensure();
+
+	pj_ansi_snprintf(digit_str, sizeof(digit_str), "%c", digit);
+
+        PyObject_CallFunction(
+	    g_obj_callback->on_dtmf_digit,
+	    "is",
+	    call_id,
+	    digit_str,
+	    NULL
+	);
+
+	PyGILState_Release(state);
+    }
+}
+
+
+/*
+ * Notify application on call being transfered.
+ * !modified @061206
+ */
+static void cb_on_call_transfer_request(pjsua_call_id call_id,
+				        const pj_str_t *dst,
+				        pjsip_status_code *code)
+{
+    if (PyCallable_Check(g_obj_callback->on_call_transfer_request)) {
+	PyObject *ret, *param_dst;
+	int cd;
+
+	ENTER_PYTHON();
+
+	param_dst = PyString_FromPJ(dst);
+
+        ret = PyObject_CallFunction(
+		    g_obj_callback->on_call_transfer_request,
+		    "iOi",
+		    call_id,
+		    param_dst,
+		    *code,
+		    NULL
+		);
+
+	Py_DECREF(param_dst);
+
+	if (ret != NULL) {
+	    if (ret != Py_None) {
+		if (PyArg_Parse(ret,"i",&cd)) {
+		    *code = cd;
+		}
+	    }
+	    Py_DECREF(ret);
+	}
+
+	LEAVE_PYTHON();
+    }
+}
+
+
+/*
+ * 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.
+ * !modified @061206
+ */
+static void cb_on_call_transfer_status( pjsua_call_id call_id,
+					int status_code,
+					const pj_str_t *status_text,
+					pj_bool_t final,
+					pj_bool_t *p_cont)
+{
+    if (PyCallable_Check(g_obj_callback->on_call_transfer_status)) {
+	PyObject *ret, *param_reason;
+
+	ENTER_PYTHON();
+
+	param_reason = PyString_FromPJ(status_text);
+
+        ret = PyObject_CallFunction(
+		    g_obj_callback->on_call_transfer_status,
+		    "iiOii",
+		    call_id,
+		    status_code,
+		    param_reason,
+		    final,
+		    *p_cont,
+		    NULL
+		);
+
+	Py_DECREF(param_reason);
+
+	if (ret != NULL) {
+	    if (ret != Py_None) {
+		int cnt;
+		if (PyArg_Parse(ret,"i",&cnt)) {
+		    *p_cont = cnt;
+		}
+	    }
+	    Py_DECREF(ret);
+	}
+
+	LEAVE_PYTHON();
+    }
+}
+
+
+/*
+ * Notify application about incoming INVITE with Replaces header.
+ * Application may reject the request by setting non-2xx code.
+ * !modified @061206
+ */
+static void cb_on_call_replace_request( pjsua_call_id call_id,
+					pjsip_rx_data *rdata,
+					int *st_code,
+					pj_str_t *st_text)
+{
+    PJ_UNUSED_ARG(rdata);
+
+    if (PyCallable_Check(g_obj_callback->on_call_replace_request)) {
+	PyObject *ret, *param_reason, *param_rdata;
+	int cd;
+
+	ENTER_PYTHON();
+
+	param_reason = PyString_FromPJ(st_text);
+	param_rdata = Py_BuildValue("");
+
+        ret = PyObject_CallFunction(
+		    g_obj_callback->on_call_replace_request,
+		    "iOiO",
+		    call_id,
+		    param_rdata,
+		    *st_code,
+		    param_reason,
+		    NULL
+		);
+
+	Py_DECREF(param_rdata);
+	Py_DECREF(param_reason);
+
+	if (ret != NULL) {
+	    if (ret != Py_None) {
+		PyObject * txt;
+		if (PyArg_ParseTuple(ret,"iO",&cd, &txt)) {
+		    *st_code = cd;
+		    *st_text = PyString_ToPJ(txt);
+		}
+	    }
+	    Py_DECREF(ret);
+	}
+
+	LEAVE_PYTHON();
+    }
+}
+
+
+/*
+ * 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.
+ */
+static void cb_on_call_replaced(pjsua_call_id old_call_id,
+				pjsua_call_id new_call_id)
+{
+    if (PyCallable_Check(g_obj_callback->on_call_replaced)) {
+	ENTER_PYTHON();
+
+        PyObject_CallFunction(
+            g_obj_callback->on_call_replaced,
+	    "ii",
+	    old_call_id,
+	    new_call_id,
+	    NULL
+        );
+
+	LEAVE_PYTHON();
+    }
+}
+
+
+/*
+ * cb_on_reg_state
+ * declares method on_reg_state for callback struct
+ */
+static void cb_on_reg_state(pjsua_acc_id acc_id)
+{
+    if (PyCallable_Check(g_obj_callback->on_reg_state)) {
+	ENTER_PYTHON();
+
+        PyObject_CallFunction(
+	    g_obj_callback->on_reg_state,
+	    "i",
+	    acc_id,
+	    NULL
+	);
+
+	LEAVE_PYTHON();
+    }
+}
+
+/* 
+ * cb_on_incoming_subscribe
+ */
+static void cb_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)
+{
+    static char reason_buf[64];
+
+    PJ_UNUSED_ARG(rdata);
+    PJ_UNUSED_ARG(msg_data);
+
+    if (PyCallable_Check(g_obj_callback->on_incoming_subscribe)) {
+	PyObject *ret, *param_from, *param_contact, *param_srv_pres;
+	pjsip_contact_hdr *contact_hdr;
+	pj_pool_t *pool = NULL;
+
+	ENTER_PYTHON();
+
+	param_from = PyString_FromPJ(from);
+	param_srv_pres = PyLong_FromLong((long)srv_pres);
+
+	contact_hdr = (pjsip_contact_hdr*)
+		      pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_CONTACT,
+					 NULL);
+	if (contact_hdr) {
+	    char *contact;
+	    int len;
+
+	    pool = pjsua_pool_create("pytmp", 512, 512);
+	    contact = (char*) pj_pool_alloc(pool, PJSIP_MAX_URL_SIZE+1);
+	    len = pjsip_uri_print(PJSIP_URI_IN_CONTACT_HDR, contact_hdr->uri, 
+				  contact, PJSIP_MAX_URL_SIZE);
+	    if (len < 1)
+		len = 0;
+	    contact[len] = '\0';
+
+	    param_contact = PyString_FromStringAndSize(contact, len);
+	} else {
+	    param_contact = Py_BuildValue("");
+	}
+
+        ret = PyObject_CallFunction(
+		    g_obj_callback->on_incoming_subscribe,
+		    "iiOOO",
+		    acc_id,
+		    buddy_id,
+		    param_from,
+		    param_contact,
+		    param_srv_pres,
+		    NULL
+		);
+
+	if (pool)
+	    pj_pool_release(pool);
+
+	Py_DECREF(param_from);
+	Py_DECREF(param_contact);
+	Py_DECREF(param_srv_pres);
+
+	if (ret && PyTuple_Check(ret)) {
+	    if (PyTuple_Size(ret) >= 1)
+		*code = (int)PyInt_AsLong(PyTuple_GetItem(ret, 0));
+	    if (PyTuple_Size(ret) >= 2) {
+		if (PyTuple_GetItem(ret, 1) != Py_None) {
+		    pj_str_t tmp;
+		    tmp = PyString_ToPJ(PyTuple_GetItem(ret, 1));
+		    reason->ptr = reason_buf;
+		    pj_strncpy(reason, &tmp, sizeof(reason_buf));
+		} else {
+		    reason->slen = 0;
+		}
+	    }
+	    Py_XDECREF(ret);
+	} else if (ret) {
+	    Py_XDECREF(ret);
+	}
+
+	LEAVE_PYTHON();
+    }
+}
+
+/*
+ * cb_on_buddy_state
+ * declares method on_buddy state for callback struct
+ */
+static void cb_on_buddy_state(pjsua_buddy_id buddy_id)
+{
+    if (PyCallable_Check(g_obj_callback->on_buddy_state)) {
+	ENTER_PYTHON();
+
+        PyObject_CallFunction(
+	    g_obj_callback->on_buddy_state,
+	    "i",
+	    buddy_id,
+	    NULL
+	);
+
+	LEAVE_PYTHON();
+    }
+}
+
+/*
+ * cb_on_pager
+ * declares method on_pager for callback struct
+ */
+static void cb_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,
+			pjsip_rx_data *rdata, pjsua_acc_id acc_id)
+{
+    PJ_UNUSED_ARG(rdata);
+
+    if (PyCallable_Check(g_obj_callback->on_pager)) {
+	PyObject *param_from, *param_to, *param_contact, *param_mime_type,
+		 *param_body;
+
+	ENTER_PYTHON();
+
+	param_from = PyString_FromPJ(from);
+	param_to = PyString_FromPJ(to);
+	param_contact = PyString_FromPJ(contact);
+	param_mime_type = PyString_FromPJ(mime_type);
+	param_body = PyString_FromPJ(body);
+
+        PyObject_CallFunction(
+		g_obj_callback->on_pager,
+		"iOOOOOi",
+		call_id,
+		param_from,
+		param_to,
+		param_contact,
+		param_mime_type,
+		param_body, 
+		acc_id,
+		NULL
+	    );
+
+	Py_DECREF(param_body);
+	Py_DECREF(param_mime_type);
+	Py_DECREF(param_contact);
+	Py_DECREF(param_to);
+	Py_DECREF(param_from);
+
+	LEAVE_PYTHON();
+    }
+}
+
+
+/*
+ * cb_on_pager_status
+ * declares method on_pager_status for callback struct
+ */
+static void cb_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,
+				pjsip_tx_data *tdata,
+				pjsip_rx_data *rdata,
+				pjsua_acc_id acc_id)
+{
+    if (PyCallable_Check(g_obj_callback->on_pager)) {
+	PyObject *param_call_id, *param_to, *param_body,
+		 *param_user_data, *param_status, *param_reason,
+		 *param_acc_id;
+
+	ENTER_PYTHON();
+
+	PJ_UNUSED_ARG(tdata);
+	PJ_UNUSED_ARG(rdata);
+
+        PyObject_CallFunctionObjArgs(
+		g_obj_callback->on_pager_status,
+		param_call_id	= Py_BuildValue("i",call_id),
+		param_to	= PyString_FromPJ(to),
+		param_body	= PyString_FromPJ(body), 
+		param_user_data = Py_BuildValue("i", user_data),
+		param_status	= Py_BuildValue("i",status),
+		param_reason	= PyString_FromPJ(reason),
+		param_acc_id	= Py_BuildValue("i",acc_id),
+		NULL
+	    );
+
+	Py_DECREF(param_call_id);
+	Py_DECREF(param_to);
+	Py_DECREF(param_body);
+	Py_DECREF(param_user_data);
+	Py_DECREF(param_status);
+	Py_DECREF(param_reason);
+	Py_DECREF(param_acc_id);
+
+	LEAVE_PYTHON();
+    }
+}
+
+
+/*
+ * cb_on_typing
+ * declares method on_typing for callback struct
+ */
+static void cb_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, pjsip_rx_data *rdata,
+			    pjsua_acc_id acc_id)
+{
+    if (PyCallable_Check(g_obj_callback->on_typing)) {
+	PyObject *param_call_id, *param_from, *param_to, *param_contact,
+		 *param_is_typing, *param_acc_id;
+
+	ENTER_PYTHON();
+
+	PJ_UNUSED_ARG(rdata);
+
+        PyObject_CallFunctionObjArgs(
+		g_obj_callback->on_typing,
+		param_call_id	= Py_BuildValue("i",call_id),
+		param_from	= PyString_FromPJ(from),
+		param_to	= PyString_FromPJ(to),
+		param_contact	= PyString_FromPJ(contact),
+		param_is_typing = Py_BuildValue("i",is_typing),
+		param_acc_id	= Py_BuildValue("i",acc_id),
+		NULL
+	    );
+
+	Py_DECREF(param_call_id);
+	Py_DECREF(param_from);
+	Py_DECREF(param_to);
+	Py_DECREF(param_contact);
+	Py_DECREF(param_is_typing); 
+	Py_DECREF(param_acc_id);
+
+	LEAVE_PYTHON();
+    }
+}
+
+
+/*
+ * on_mwi_info
+ */
+static void cb_on_mwi_info(pjsua_acc_id acc_id, pjsua_mwi_info *mwi_info)
+{
+    if (PyCallable_Check(g_obj_callback->on_mwi_info)) {
+	PyObject *param_acc_id, *param_body;
+	pj_str_t body;
+
+	ENTER_PYTHON();
+
+	body.ptr = mwi_info->rdata->msg_info.msg->body->data;
+	body.slen = mwi_info->rdata->msg_info.msg->body->len;
+
+        PyObject_CallFunctionObjArgs(
+		g_obj_callback->on_mwi_info,
+		param_acc_id	= Py_BuildValue("i",acc_id),
+		param_body	= PyString_FromPJ(&body),
+		NULL
+	    );
+
+	Py_DECREF(param_acc_id);
+	Py_DECREF(param_body);
+
+	LEAVE_PYTHON();
+    }
+}
+
+/* 
+ * translate_hdr
+ * internal function 
+ * translate from hdr_list to pjsip_generic_string_hdr
+ */
+void translate_hdr(pj_pool_t *pool, pjsip_hdr *hdr, PyObject *py_hdr_list)
+{
+    pj_list_init(hdr);
+
+    if (PyList_Check(py_hdr_list)) {
+	int i;
+
+        for (i=0; i<PyList_Size(py_hdr_list); ++i)  { 
+            pj_str_t hname, hvalue;
+	    pjsip_generic_string_hdr * new_hdr;
+            PyObject * tuple = PyList_GetItem(py_hdr_list, i);
+
+            if (PyTuple_Check(tuple)) {
+		if (PyTuple_Size(tuple) >= 1)
+		    hname = PyString_ToPJ(PyTuple_GetItem(tuple,0));
+		else
+		    hname.slen = 0;
+		if (PyTuple_Size(tuple) >= 2)
+		    hvalue = PyString_ToPJ(PyTuple_GetItem(tuple,1));
+		else
+		    hvalue.slen = 0;
+            } else {
+		hname.ptr = "";
+		hname.slen = 0;
+		hvalue.ptr = "";
+		hvalue.slen = 0;
+            }  
+            new_hdr = pjsip_generic_string_hdr_create(pool, &hname, &hvalue);
+            pj_list_push_back((pj_list_type *)hdr, (pj_list_type *)new_hdr);
+	}     
+    }
+}
+
+/*
+ * py_pjsua_thread_register
+ */
+static PyObject *py_pjsua_thread_register(PyObject *pSelf, PyObject *pArgs)
+{
+    pj_status_t status;	
+    const char *name;
+    PyObject *py_desc;
+    pj_thread_t *thread;
+    struct py_thread_desc *thread_desc;
+
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "sO", &name, &py_desc)) {
+         return NULL;
+    }
+    thread_desc = (struct py_thread_desc*)
+		  malloc(sizeof(struct py_thread_desc));
+    thread_desc->next = py_thread_desc;
+    py_thread_desc = thread_desc;
+
+    status = pj_thread_register(name, thread_desc->desc, &thread);
+
+    if (status == PJ_SUCCESS)
+	status = pj_thread_local_set(g_thread_id, (void*)1);
+
+    return Py_BuildValue("i",status);
+}
+
+/*
+ * py_pjsua_logging_config_default
+ */
+static PyObject *py_pjsua_logging_config_default(PyObject *pSelf,
+                                                 PyObject *pArgs)
+{
+    PyObj_pjsua_logging_config *obj;	
+    pjsua_logging_config cfg;
+
+    PJ_UNUSED_ARG(pSelf);
+    PJ_UNUSED_ARG(pArgs);
+
+    pjsua_logging_config_default(&cfg);
+    obj = (PyObj_pjsua_logging_config*) 
+	  PyObj_pjsua_logging_config_new(&PyTyp_pjsua_logging_config, 
+					 NULL, NULL);
+    PyObj_pjsua_logging_config_import(obj, &cfg);
+    
+    return (PyObject*)obj;
+}
+
+
+/*
+ * py_pjsua_config_default
+ */
+static PyObject *py_pjsua_config_default(PyObject *pSelf, PyObject *pArgs)
+{
+    PyObj_pjsua_config *obj;
+    pjsua_config cfg;
+
+    PJ_UNUSED_ARG(pSelf);
+    PJ_UNUSED_ARG(pArgs);
+
+    pjsua_config_default(&cfg);
+    obj = (PyObj_pjsua_config *) PyObj_pjsua_config_new(&PyTyp_pjsua_config, 
+							NULL, NULL);
+    PyObj_pjsua_config_import(obj, &cfg);
+
+    return (PyObject*)obj;
+}
+
+
+/*
+ * py_pjsua_media_config_default
+ */
+static PyObject * py_pjsua_media_config_default(PyObject *pSelf,
+                                                PyObject *pArgs)
+{
+    PyObj_pjsua_media_config *obj;
+    pjsua_media_config cfg;
+
+    PJ_UNUSED_ARG(pSelf);
+    PJ_UNUSED_ARG(pArgs);
+
+    pjsua_media_config_default(&cfg);
+    obj = (PyObj_pjsua_media_config *)
+	  PyType_GenericNew(&PyTyp_pjsua_media_config, NULL, NULL);
+    PyObj_pjsua_media_config_import(obj, &cfg);
+
+    return (PyObject *)obj;
+}
+
+
+/*
+ * py_pjsua_msg_data_init
+ */
+static PyObject *py_pjsua_msg_data_init(PyObject *pSelf, PyObject *pArgs)
+{
+    PJ_UNUSED_ARG(pSelf);
+    PJ_UNUSED_ARG(pArgs);
+
+    return (PyObject *)PyObj_pjsua_msg_data_new(&PyTyp_pjsua_msg_data, 
+						NULL, NULL);
+}
+
+
+/*
+ * py_pjsua_reconfigure_logging
+ */
+static PyObject *py_pjsua_reconfigure_logging(PyObject *pSelf, 
+					      PyObject *pArgs)
+{
+    PyObject *logObj;
+    pj_status_t status;
+
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "O", &logObj)) {
+        return NULL;
+    }
+
+    if (logObj != Py_None) {
+	PyObj_pjsua_logging_config *log;
+	pjsua_logging_config cfg;
+
+        log = (PyObj_pjsua_logging_config*)logObj;
+        cfg.msg_logging = log->msg_logging;
+        cfg.level = log->level;
+        cfg.console_level = log->console_level;
+        cfg.decor = log->decor;
+        cfg.log_filename = PyString_ToPJ(log->log_filename);
+        Py_XDECREF(g_obj_log_cb);
+        g_obj_log_cb = log->cb;
+        Py_INCREF(g_obj_log_cb);
+        cfg.cb = &cb_log_cb;
+        status = pjsua_reconfigure_logging(&cfg);
+    } else {
+        status = pjsua_reconfigure_logging(NULL);
+    }
+
+    return Py_BuildValue("i",status);
+}
+
+
+/*
+ * py_pjsua_perror
+ */
+static PyObject *py_pjsua_perror(PyObject *pSelf, PyObject *pArgs)
+{
+    const char *sender;
+    const char *title;
+    pj_status_t status;
+
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "ssi", &sender, &title, &status)) {
+        return NULL;
+    }
+	
+    pjsua_perror(sender, title, status);
+
+    return Py_BuildValue("");
+}
+
+
+/*
+ * py_pjsua_create
+ */
+static PyObject *py_pjsua_create(PyObject *pSelf, PyObject *pArgs)
+{
+    pj_status_t status;
+
+    PJ_UNUSED_ARG(pSelf);
+    PJ_UNUSED_ARG(pArgs);
+
+    status = pjsua_create();
+    
+    if (status == PJ_SUCCESS)  {
+	status = pj_thread_local_alloc(&g_thread_id);
+	if (status == PJ_SUCCESS)
+	    status = pj_thread_local_set(g_thread_id, (void*)1);
+
+	pj_atexit(&clear_py_thread_desc);
+    }
+
+    return Py_BuildValue("i",status);
+}
+
+
+/*
+ * py_pjsua_init
+ */
+static PyObject *py_pjsua_init(PyObject *pSelf, PyObject *pArgs)
+{
+    pj_status_t status;
+    PyObject *o_ua_cfg, *o_log_cfg, *o_media_cfg;
+    pjsua_config cfg_ua, *p_cfg_ua;
+    pjsua_logging_config cfg_log, *p_cfg_log;
+    pjsua_media_config cfg_media, *p_cfg_media;
+
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "OOO", &o_ua_cfg, &o_log_cfg, &o_media_cfg)) {
+        return NULL;
+    }
+    
+    pjsua_config_default(&cfg_ua);
+    pjsua_logging_config_default(&cfg_log);
+    pjsua_media_config_default(&cfg_media);
+
+    if (o_ua_cfg != Py_None) {
+	PyObj_pjsua_config *obj_ua_cfg = (PyObj_pjsua_config*)o_ua_cfg;
+
+	PyObj_pjsua_config_export(&cfg_ua, obj_ua_cfg);
+
+	Py_XDECREF(g_obj_callback);
+    	g_obj_callback = obj_ua_cfg->cb;
+    	Py_INCREF(g_obj_callback);
+
+    	cfg_ua.cb.on_call_state = &cb_on_call_state;
+    	cfg_ua.cb.on_incoming_call = &cb_on_incoming_call;
+    	cfg_ua.cb.on_call_media_state = &cb_on_call_media_state;
+	cfg_ua.cb.on_dtmf_digit = &cb_on_dtmf_digit;
+    	cfg_ua.cb.on_call_transfer_request = &cb_on_call_transfer_request;
+    	cfg_ua.cb.on_call_transfer_status = &cb_on_call_transfer_status;
+    	cfg_ua.cb.on_call_replace_request = &cb_on_call_replace_request;
+    	cfg_ua.cb.on_call_replaced = &cb_on_call_replaced;
+    	cfg_ua.cb.on_reg_state = &cb_on_reg_state;
+	cfg_ua.cb.on_incoming_subscribe = &cb_on_incoming_subscribe;
+    	cfg_ua.cb.on_buddy_state = &cb_on_buddy_state;
+    	cfg_ua.cb.on_pager2 = &cb_on_pager;
+    	cfg_ua.cb.on_pager_status2 = &cb_on_pager_status;
+    	cfg_ua.cb.on_typing2 = &cb_on_typing;
+	cfg_ua.cb.on_mwi_info = &cb_on_mwi_info;
+
+        p_cfg_ua = &cfg_ua;
+
+    } else {
+        p_cfg_ua = NULL;
+    }
+
+    if (o_log_cfg != Py_None)  {
+	PyObj_pjsua_logging_config * obj_log;
+
+        obj_log = (PyObj_pjsua_logging_config *)o_log_cfg;
+        
+        PyObj_pjsua_logging_config_export(&cfg_log, obj_log);
+
+        Py_XDECREF(g_obj_log_cb);
+        g_obj_log_cb = obj_log->cb;
+        Py_INCREF(g_obj_log_cb);
+
+        cfg_log.cb = &cb_log_cb;
+        p_cfg_log = &cfg_log;
+
+    } else {
+        p_cfg_log = NULL;
+    }
+
+    if (o_media_cfg != Py_None) {
+	PyObj_pjsua_media_config_export(&cfg_media, 
+				        (PyObj_pjsua_media_config*)o_media_cfg);
+	p_cfg_media = &cfg_media;
+
+    } else {
+        p_cfg_media = NULL;
+    }
+
+    status = pjsua_init(p_cfg_ua, p_cfg_log, p_cfg_media);
+
+    return Py_BuildValue("i", status);
+}
+
+
+/*
+ * py_pjsua_start
+ */
+static PyObject *py_pjsua_start(PyObject *pSelf, PyObject *pArgs)
+{
+    pj_status_t status;
+
+    PJ_UNUSED_ARG(pSelf);
+    PJ_UNUSED_ARG(pArgs);
+
+    status = pjsua_start();
+    
+    return Py_BuildValue("i", status);
+}
+
+
+/*
+ * py_pjsua_destroy
+ */
+static PyObject *py_pjsua_destroy(PyObject *pSelf, PyObject *pArgs)
+{
+    pj_status_t status;
+
+    PJ_UNUSED_ARG(pSelf);
+    PJ_UNUSED_ARG(pArgs);
+
+    status = pjsua_destroy();
+    
+    return Py_BuildValue("i", status);
+}
+
+
+/*
+ * py_pjsua_handle_events
+ */
+static PyObject *py_pjsua_handle_events(PyObject *pSelf, PyObject *pArgs)
+{
+    int ret;
+    int msec;
+
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "i", &msec)) {
+        return NULL;
+    }
+
+    if (msec < 0)
+	msec = 0;
+
+#if !NO_PJSIP_THREAD
+    /* Since handle_events() will block, we must wrap it with ALLOW_THREADS
+     * construct, or otherwise many Python blocking functions (such as
+     * time.sleep(), readline(), etc.) may hang/block indefinitely.
+     * See http://www.python.org/doc/current/api/threads.html for more info.
+     */
+    Py_BEGIN_ALLOW_THREADS
+#endif
+
+    ret = pjsua_handle_events(msec);
+
+#if !NO_PJSIP_THREAD
+    Py_END_ALLOW_THREADS
+#endif
+    
+    return Py_BuildValue("i", ret);
+}
+
+
+/*
+ * py_pjsua_verify_sip_url
+ */
+static PyObject *py_pjsua_verify_sip_url(PyObject *pSelf, PyObject *pArgs)
+{
+    pj_status_t status;
+    const char *url;
+
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "s", &url)) {
+        return NULL;
+    }
+
+    status = pjsua_verify_sip_url(url);
+    
+    return Py_BuildValue("i", status);
+}
+
+
+/*
+ * function doc
+ */
+
+static char pjsua_thread_register_doc[] =
+    "int _pjsua.thread_register(string name, int[] desc)";
+static char pjsua_perror_doc[] =
+    "void _pjsua.perror (string sender, string title, int status) "
+    "Display error message for the specified error code. Parameters: "
+    "sender: The log sender field;  "
+    "title: Message title for the error; "
+    "status: Status code.";
+
+static char pjsua_create_doc[] =
+    "int _pjsua.create (void) "
+    "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.";
+
+static char pjsua_init_doc[] =
+    "int _pjsua.init (_pjsua.Config obj_ua_cfg, "
+        "_pjsua.Logging_Config log_cfg, _pjsua.Media_Config media_cfg) "
+    "Initialize pjsua with the specified settings. All the settings are "
+    "optional, and the default values will be used when the config is not "
+    "specified. Parameters: "
+    "obj_ua_cfg : User agent configuration;  "
+    "log_cfg : Optional logging configuration; "
+    "media_cfg : Optional media configuration.";
+
+static char pjsua_start_doc[] =
+    "int _pjsua.start (void) "
+    "Application is recommended to call this function after all "
+    "initialization is done, so that the library can do additional checking "
+    "set up additional";
+
+static char pjsua_destroy_doc[] =
+    "int _pjsua.destroy (void) "
+    "Destroy pjsua This function must be called once PJSUA is created. To "
+    "make it easier for application, application may call this function "
+    "several times with no danger.";
+
+static char pjsua_handle_events_doc[] =
+    "int _pjsua.handle_events (int msec_timeout) "
+    "Poll pjsua for events, and if necessary block the caller thread for the "
+    "specified maximum interval (in miliseconds) Parameters: "
+    "msec_timeout: Maximum time to wait, in miliseconds. "
+    "Returns: The number of events that have been handled during the poll. "
+    "Negative value indicates error, and application can retrieve the error "
+    "as (err = -return_value).";
+
+static char pjsua_verify_sip_url_doc[] =
+    "int _pjsua.verify_sip_url (string c_url) "
+    "Verify that valid SIP url is given Parameters: "
+    "c_url: The URL, as NULL terminated string.";
+
+static char pjsua_reconfigure_logging_doc[] =
+    "int _pjsua.reconfigure_logging (_pjsua.Logging_Config c) "
+    "Application can call this function at any time (after pjsua_create(), of "
+    "course) to change logging settings. Parameters: "
+    "c: Logging configuration.";
+
+static char pjsua_logging_config_default_doc[] =
+    "_pjsua.Logging_Config _pjsua.logging_config_default  ()  "
+    "Use this function to initialize logging config.";
+
+static char pjsua_config_default_doc[] =
+    "_pjsua.Config _pjsua.config_default (). Use this function to "
+    "initialize pjsua config. ";
+
+static char pjsua_media_config_default_doc[] =
+    "_pjsua.Media_Config _pjsua.media_config_default (). "
+    "Use this function to initialize media config.";
+
+static char pjsua_msg_data_init_doc[] =
+    "_pjsua.Msg_Data void _pjsua.msg_data_init () "
+    "Initialize message data ";
+        
+
+/* END OF LIB BASE */
+
+/* LIB TRANSPORT */
+
+/*
+ * py_pjsua_transport_config_default
+ */
+static PyObject *py_pjsua_transport_config_default(PyObject *pSelf, 
+						   PyObject *pArgs)
+{
+    PyObj_pjsua_transport_config *obj;
+    pjsua_transport_config cfg;
+
+    PJ_UNUSED_ARG(pSelf);
+    PJ_UNUSED_ARG(pArgs);
+
+    pjsua_transport_config_default(&cfg);
+    obj = (PyObj_pjsua_transport_config*)
+	  PyObj_pjsua_transport_config_new(&PyTyp_pjsua_transport_config,
+					   NULL, NULL);
+    PyObj_pjsua_transport_config_import(obj, &cfg);
+
+    return (PyObject *)obj;
+}
+
+/*
+ * py_pjsua_transport_create
+ */
+static PyObject *py_pjsua_transport_create(PyObject *pSelf, PyObject *pArgs)
+{
+    pj_status_t status;
+    int type;
+    PyObject *pCfg;
+    pjsua_transport_config cfg;
+    pjsua_transport_id id;
+
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "iO", &type, &pCfg)) {
+        return NULL;
+    }
+
+    if (pCfg != Py_None) {
+	PyObj_pjsua_transport_config *obj;
+
+        obj = (PyObj_pjsua_transport_config*)pCfg;
+	PyObj_pjsua_transport_config_export(&cfg, obj);
+        status = pjsua_transport_create(type, &cfg, &id);
+    } else {
+        status = pjsua_transport_create(type, NULL, &id);
+    }
+    
+    
+    return Py_BuildValue("ii", status, id);
+}
+
+/*
+ * py_pjsua_enum_transports
+ */
+static PyObject *py_pjsua_enum_transports(PyObject *pSelf, PyObject *pArgs)
+{
+    pj_status_t status;
+    PyObject *list;
+    pjsua_transport_id id[PJSIP_MAX_TRANSPORTS];
+    unsigned c, i;
+
+    PJ_UNUSED_ARG(pSelf);
+    PJ_UNUSED_ARG(pArgs);
+
+    c = PJ_ARRAY_SIZE(id);
+    status = pjsua_enum_transports(id, &c);
+    
+    list = PyList_New(c);
+    for (i = 0; i < c; i++) {     
+        PyList_SetItem(list, i, Py_BuildValue("i", id[i]));
+    }
+    
+    return (PyObject*)list;
+}
+
+/*
+ * py_pjsua_transport_get_info
+ * !modified @ 051206
+ */
+static PyObject *py_pjsua_transport_get_info(PyObject *pSelf, PyObject *pArgs)
+{
+    pj_status_t status;
+    int id;
+    pjsua_transport_info info;
+    
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "i", &id)) {
+        return NULL;
+    }	
+    
+    status = pjsua_transport_get_info(id, &info);	
+    if (status == PJ_SUCCESS) {
+	PyObj_pjsua_transport_info *obj;
+        obj = (PyObj_pjsua_transport_info *) 
+	      PyObj_pjsua_transport_info_new(&PyTyp_pjsua_transport_info, 
+					     NULL, NULL);
+	PyObj_pjsua_transport_info_import(obj, &info);
+        return (PyObject*)obj;
+    } else {
+        return Py_BuildValue("");
+    }
+}
+
+/*
+ * py_pjsua_transport_set_enable
+ */
+static PyObject *py_pjsua_transport_set_enable(PyObject *pSelf, 
+					       PyObject *pArgs)
+{
+    pj_status_t status;
+    int id;
+    int enabled;
+
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "ii", &id, &enabled)) {
+        return NULL;
+    }
+    status = pjsua_transport_set_enable(id, enabled);
+
+    return Py_BuildValue("i", status);
+}
+
+/*
+ * py_pjsua_transport_close
+ */
+static PyObject *py_pjsua_transport_close(PyObject *pSelf, PyObject *pArgs)
+{
+    pj_status_t status;
+    int id;
+    int force;
+
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "ii", &id, &force)) {
+        return NULL;
+    }	
+    status = pjsua_transport_close(id, force);	
+    
+    return Py_BuildValue("i", status);
+}
+
+static char pjsua_transport_config_default_doc[] =
+    "_pjsua.Transport_Config _pjsua.transport_config_default () "
+    "Call this function to initialize UDP config with default values.";
+static char pjsua_transport_create_doc[] =
+    "int, int _pjsua.transport_create (int type, "
+    "_pjsua.Transport_Config cfg) "
+    "Create SIP transport.";
+static char pjsua_enum_transports_doc[] =
+    "int[] _pjsua.enum_transports () "
+    "Enumerate all transports currently created in the system.";
+static char pjsua_transport_get_info_doc[] =
+    "void _pjsua.transport_get_info "
+    "(_pjsua.Transport_ID id, _pjsua.Transport_Info info) "
+    "Get information about transports.";
+static char pjsua_transport_set_enable_doc[] =
+    "void _pjsua.transport_set_enable "
+    "(_pjsua.Transport_ID id, int enabled) "
+    "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.";
+static char pjsua_transport_close_doc[] =
+    "void _pjsua.transport_close (_pjsua.Transport_ID id, int force) "
+    "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. "
+    "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.";
+
+/* END OF LIB TRANSPORT */
+
+/* LIB ACCOUNT */
+
+
+/*
+ * py_pjsua_acc_config_default
+ */
+static PyObject *py_pjsua_acc_config_default(PyObject *pSelf, PyObject *pArgs)
+{
+    PyObj_pjsua_acc_config *obj;
+    pjsua_acc_config cfg;
+
+    PJ_UNUSED_ARG(pSelf);
+    PJ_UNUSED_ARG(pArgs);
+
+    if (!PyArg_ParseTuple(pArgs, "")) {
+        return NULL;
+    }
+
+    pjsua_acc_config_default(&cfg);
+    obj = (PyObj_pjsua_acc_config *)
+	  PyObj_pjsua_acc_config_new(&PyTyp_pjsua_acc_config, 
+				     NULL, NULL);
+    PyObj_pjsua_acc_config_import(obj, &cfg);
+    return (PyObject *)obj;
+}
+
+/*
+ * py_pjsua_acc_get_count
+ */
+static PyObject *py_pjsua_acc_get_count(PyObject *pSelf, PyObject *pArgs)
+{
+    int count;
+
+    PJ_UNUSED_ARG(pSelf);
+    PJ_UNUSED_ARG(pArgs);
+
+    count = pjsua_acc_get_count();
+    return Py_BuildValue("i", count);
+}
+
+/*
+ * py_pjsua_acc_is_valid
+ */
+static PyObject *py_pjsua_acc_is_valid(PyObject *pSelf, PyObject *pArgs)
+{    
+    int id;
+    int is_valid;
+
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "i", &id)) {
+        return NULL;
+    }
+
+    is_valid = pjsua_acc_is_valid(id);	
+    return Py_BuildValue("i", is_valid);
+}
+
+/*
+ * py_pjsua_acc_set_default
+ */
+static PyObject *py_pjsua_acc_set_default(PyObject *pSelf, PyObject *pArgs)
+{    
+    int id;
+    int status;
+
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "i", &id)) {
+        return NULL;
+    }
+    status = pjsua_acc_set_default(id);
+	
+    return Py_BuildValue("i", status);
+}
+
+/*
+ * py_pjsua_acc_get_default
+ */
+static PyObject *py_pjsua_acc_get_default(PyObject *pSelf, PyObject *pArgs)
+{    
+    int id;
+	
+    PJ_UNUSED_ARG(pSelf);
+    PJ_UNUSED_ARG(pArgs);
+
+    id = pjsua_acc_get_default();
+	
+    return Py_BuildValue("i", id);
+}
+
+/*
+ * py_pjsua_acc_add
+ */
+static PyObject *py_pjsua_acc_add(PyObject *pSelf, PyObject *pArgs)
+{    
+    int is_default;
+    PyObject *pCfg;
+    int acc_id;
+    int status;
+
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "Oi", &pCfg, &is_default)) {
+        return NULL;
+    }
+    
+    if (pCfg != Py_None) {
+	pjsua_acc_config cfg;
+	PyObj_pjsua_acc_config *ac;
+
+	pjsua_acc_config_default(&cfg);
+        ac = (PyObj_pjsua_acc_config *)pCfg;
+        PyObj_pjsua_acc_config_export(&cfg, ac);
+        status = pjsua_acc_add(&cfg, is_default, &acc_id);
+    } else {
+        status = PJ_EINVAL;
+	acc_id = PJSUA_INVALID_ID;
+    }
+    
+    return Py_BuildValue("ii", status, acc_id);
+}
+
+/*
+ * py_pjsua_acc_add_local
+ */
+static PyObject *py_pjsua_acc_add_local(PyObject *pSelf, PyObject *pArgs)
+{    
+    int is_default;
+    int tid;
+    int acc_id;
+    int status;
+	
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "ii", &tid, &is_default)) {
+        return NULL;
+    }
+	
+    status = pjsua_acc_add_local(tid, is_default, &acc_id);
+    
+    return Py_BuildValue("ii", status, acc_id);
+}
+
+/*
+ * py_pjsua_acc_set_user_data
+ */
+static PyObject *py_pjsua_acc_set_user_data(PyObject *pSelf, PyObject *pArgs)
+{    
+    int acc_id;
+    PyObject *pUserData, *old_user_data;
+    int status;
+
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "iO", &acc_id, &pUserData)) {
+        return NULL;
+    }
+
+    old_user_data = (PyObject*) pjsua_acc_get_user_data(acc_id);
+
+    status = pjsua_acc_set_user_data(acc_id, (void*)pUserData);
+
+    if (status == PJ_SUCCESS) {
+	Py_XINCREF(pUserData);
+	Py_XDECREF(old_user_data);
+    }
+
+    return Py_BuildValue("i", status);
+}
+
+/*
+ * py_pjsua_acc_get_user_data
+ */
+static PyObject *py_pjsua_acc_get_user_data(PyObject *pSelf, PyObject *pArgs)
+{    
+    int acc_id;
+    PyObject *user_data;
+
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "i", &acc_id)) {
+        return NULL;
+    }
+
+    user_data = (PyObject*) pjsua_acc_get_user_data(acc_id);
+
+    return user_data ? Py_BuildValue("O", user_data) : Py_BuildValue("");
+}
+
+/*
+ * py_pjsua_acc_del
+ */
+static PyObject *py_pjsua_acc_del(PyObject *pSelf, PyObject *pArgs)
+{    
+    int acc_id;
+    PyObject *user_data;
+    int status;
+
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "i", &acc_id)) {
+        return NULL;
+    }
+
+    user_data = (PyObject*) pjsua_acc_get_user_data(acc_id);
+    Py_XDECREF(user_data);
+
+    status = pjsua_acc_del(acc_id);
+
+    return Py_BuildValue("i", status);
+}
+
+/*
+ * py_pjsua_acc_modify
+ */
+static PyObject *py_pjsua_acc_modify(PyObject *pSelf, PyObject *pArgs)
+{    	
+    PyObject *pCfg;
+    PyObj_pjsua_acc_config * ac;
+    int acc_id;
+    int status;
+
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "iO", &acc_id, &pCfg)) {
+        return NULL;
+    }
+
+    if (pCfg != Py_None) {
+	pjsua_acc_config cfg;	
+
+	pjsua_acc_config_default(&cfg);
+        ac = (PyObj_pjsua_acc_config*)pCfg;
+        PyObj_pjsua_acc_config_export(&cfg, ac);
+
+        status = pjsua_acc_modify(acc_id, &cfg);
+    } else {
+        status = PJ_EINVAL;
+    }
+    return Py_BuildValue("i", status);
+}
+
+/*
+ * py_pjsua_acc_set_online_status
+ */
+static PyObject *py_pjsua_acc_set_online_status(PyObject *pSelf, 
+						PyObject *pArgs)
+{    
+    int is_online;	
+    int acc_id;
+    int status;	
+
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "ii", &acc_id, &is_online)) {
+        return NULL;
+    }
+	
+    status = pjsua_acc_set_online_status(acc_id, is_online);
+	
+    return Py_BuildValue("i", status);
+}
+
+/*
+ * py_pjsua_acc_set_online_status2
+ */
+static PyObject *py_pjsua_acc_set_online_status2(PyObject *pSelf, 
+						 PyObject *pArgs)
+{    
+    int is_online;	
+    int acc_id;
+    int activity_id;
+    const char *activity_text = NULL;
+    const char *rpid_id = NULL;
+    pjrpid_element rpid;
+    pj_status_t status;	
+
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "iiiss", &acc_id, &is_online,
+			  &activity_id, &activity_text, &rpid_id)) 
+    {
+        return NULL;
+    }
+
+    pj_bzero(&rpid, sizeof(rpid));
+    rpid.type = PJRPID_ELEMENT_TYPE_PERSON;
+    rpid.activity = activity_id;
+    if (activity_text)
+	rpid.note = pj_str((char*)activity_text);
+
+    if (rpid_id)
+	rpid.id = pj_str((char*)rpid_id);
+
+    status = pjsua_acc_set_online_status2(acc_id, is_online, &rpid);
+
+    return Py_BuildValue("i", status);
+}
+
+/*
+ * py_pjsua_acc_set_registration
+ */
+static PyObject *py_pjsua_acc_set_registration(PyObject *pSelf, 
+					       PyObject *pArgs)
+{    
+    int renew;	
+    int acc_id;
+    int status;	
+
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "ii", &acc_id, &renew)) {
+        return NULL;
+    }
+	
+    status = pjsua_acc_set_registration(acc_id, renew);
+	
+    return Py_BuildValue("i", status);
+}
+
+/*
+ * py_pjsua_acc_get_info
+ */
+static PyObject *py_pjsua_acc_get_info(PyObject *pSelf, PyObject *pArgs)
+{    	
+    int acc_id;
+    PyObj_pjsua_acc_info * obj;
+    pjsua_acc_info info;
+    int status;	
+
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "i", &acc_id)) {
+        return NULL;
+    }
+    
+    status = pjsua_acc_get_info(acc_id, &info);
+    if (status == PJ_SUCCESS) {
+	obj = (PyObj_pjsua_acc_info*)
+	      PyObj_pjsua_acc_info_new(&PyTyp_pjsua_acc_info, NULL, NULL);
+	PyObj_pjsua_acc_info_import(obj, &info);
+        return (PyObject*)obj;
+    } else {
+	return Py_BuildValue("");
+    }
+}
+
+/*
+ * py_pjsua_enum_accs
+ */
+static PyObject *py_pjsua_enum_accs(PyObject *pSelf, PyObject *pArgs)
+{
+    pj_status_t status;
+    PyObject *list;
+    pjsua_acc_id id[PJSUA_MAX_ACC];
+    unsigned c, i;
+
+    PJ_UNUSED_ARG(pSelf);
+    PJ_UNUSED_ARG(pArgs);
+
+    c = PJ_ARRAY_SIZE(id);
+    status = pjsua_enum_accs(id, &c);
+    if (status != PJ_SUCCESS)
+	c = 0;
+    
+    list = PyList_New(c);
+    for (i = 0; i < c; i++) {
+        PyList_SetItem(list, i, Py_BuildValue("i", id[i]));
+    }
+    
+    return (PyObject*)list;
+}
+
+/*
+ * py_pjsua_acc_enum_info
+ */
+static PyObject *py_pjsua_acc_enum_info(PyObject *pSelf, PyObject *pArgs)
+{
+    pj_status_t status;
+    PyObject *list;
+    pjsua_acc_info info[PJSUA_MAX_ACC];
+    unsigned c, i;
+
+    PJ_UNUSED_ARG(pSelf);
+    PJ_UNUSED_ARG(pArgs);
+
+    if (!PyArg_ParseTuple(pArgs, "")) {
+        return NULL;
+    }	
+    
+    c = PJ_ARRAY_SIZE(info);
+    status = pjsua_acc_enum_info(info, &c);
+    if (status != PJ_SUCCESS)
+	c = 0;
+
+    list = PyList_New(c);
+    for (i = 0; i < c; i++) {
+        PyObj_pjsua_acc_info *obj;
+        obj = (PyObj_pjsua_acc_info *)
+	      PyObj_pjsua_acc_info_new(&PyTyp_pjsua_acc_info, NULL, NULL);
+
+	PyObj_pjsua_acc_info_import(obj, &info[i]);
+
+        PyList_SetItem(list, i, (PyObject*)obj);
+    }
+    
+    return (PyObject*)list;
+}
+
+/*
+ * py_pjsua_acc_set_transport
+ */
+static PyObject *py_pjsua_acc_set_transport(PyObject *pSelf, PyObject *pArgs)
+{    	
+    int acc_id, transport_id;
+    int status;	
+    
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "ii", &acc_id, &transport_id)) {
+        return NULL;
+    }	
+    
+    status = pjsua_acc_set_transport(acc_id, transport_id);
+    
+    
+    return Py_BuildValue("i", status);
+}
+
+
+/*
+ * py_pjsua_acc_pres_notify
+ */
+static PyObject *py_pjsua_acc_pres_notify(PyObject *pSelf, 
+					  PyObject *pArgs)
+{
+    int acc_id, state;
+    PyObject *arg_pres, *arg_msg_data, *arg_reason;
+    void *srv_pres;
+    pjsua_msg_data msg_data;
+    pj_str_t reason;
+    pj_bool_t with_body;
+    pj_pool_t *pool = NULL;
+    int status;	
+    
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "iOiOO", &acc_id, &arg_pres, 
+			  &state, &arg_reason, &arg_msg_data))
+    {
+        return NULL;
+    }	
+    
+    srv_pres = (void*) PyLong_AsLong(arg_pres);
+    with_body = (state != PJSIP_EVSUB_STATE_TERMINATED);
+
+    if (arg_reason && PyString_Check(arg_reason)) {
+	reason = PyString_ToPJ(arg_reason);
+    } else {
+	reason = pj_str("");
+    }
+
+    pjsua_msg_data_init(&msg_data);
+    if (arg_msg_data && arg_msg_data != Py_None) {
+        PyObj_pjsua_msg_data *omd = (PyObj_pjsua_msg_data *)arg_msg_data;
+        msg_data.content_type = PyString_ToPJ(omd->content_type);
+        msg_data.msg_body = PyString_ToPJ(omd->msg_body);
+        pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
+        translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
+    }
+
+    status = pjsua_pres_notify(acc_id, (pjsua_srv_pres*)srv_pres,
+			       (pjsip_evsub_state)state, NULL,
+			       &reason, with_body, &msg_data);
+    
+    if (pool) {
+	pj_pool_release(pool);
+    }
+
+    return Py_BuildValue("i", status);
+}
+
+static char pjsua_acc_config_default_doc[] =
+    "_pjsua.Acc_Config _pjsua.acc_config_default () "
+    "Call this function to initialize account config with default values.";
+static char pjsua_acc_get_count_doc[] =
+    "int _pjsua.acc_get_count () "
+    "Get number of current accounts.";
+static char pjsua_acc_is_valid_doc[] =
+    "int _pjsua.acc_is_valid (int acc_id)  "
+    "Check if the specified account ID is valid.";
+static char pjsua_acc_set_default_doc[] =
+    "int _pjsua.acc_set_default (int acc_id) "
+    "Set default account to be used when incoming "
+    "and outgoing requests doesn't match any accounts.";
+static char pjsua_acc_get_default_doc[] =
+    "int _pjsua.acc_get_default () "
+    "Get default account.";
+static char pjsua_acc_add_doc[] =
+    "int, int _pjsua.acc_add (_pjsua.Acc_Config cfg, "
+    "int is_default) "
+    "Add a new account to pjsua. PJSUA must have been initialized "
+    "(with pjsua_init()) before calling this function.";
+static char pjsua_acc_add_local_doc[] =
+    "int,int _pjsua.acc_add_local (int tid, "
+    "int is_default) "
+    "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.";
+static char pjsua_acc_del_doc[] =
+    "int _pjsua.acc_del (int acc_id) "
+    "Delete account.";
+static char pjsua_acc_modify_doc[] =
+    "int _pjsua.acc_modify (int acc_id, _pjsua.Acc_Config cfg) "
+    "Modify account information.";
+static char pjsua_acc_set_online_status_doc[] =
+    "int _pjsua.acc_set_online_status2(int acc_id, int is_online) "
+    "Modify account's presence status to be advertised "
+    "to remote/presence subscribers.";
+static char pjsua_acc_set_online_status2_doc[] =
+    "int _pjsua.acc_set_online_status (int acc_id, int is_online, "
+                                         "int activity_id, string activity_text) "
+    "Modify account's presence status to be advertised "
+    "to remote/presence subscribers.";
+static char pjsua_acc_set_registration_doc[] =
+    "int _pjsua.acc_set_registration (int acc_id, int renew) "
+    "Update registration or perform unregistration.";
+static char pjsua_acc_get_info_doc[] =
+    "_pjsua.Acc_Info _pjsua.acc_get_info (int acc_id) "
+    "Get account information.";
+static char pjsua_enum_accs_doc[] =
+    "int[] _pjsua.enum_accs () "
+    "Enum accounts all account ids.";
+static char pjsua_acc_enum_info_doc[] =
+    "_pjsua.Acc_Info[] _pjsua.acc_enum_info () "
+    "Enum accounts info.";
+
+/* END OF LIB ACCOUNT */
+
+/* LIB BUDDY */
+
+
+
+/*
+ * py_pjsua_buddy_config_default
+ */
+static PyObject *py_pjsua_buddy_config_default(PyObject *pSelf, 
+					       PyObject *pArgs)
+{    
+    PyObj_pjsua_buddy_config *obj;	
+    pjsua_buddy_config cfg;
+
+    PJ_UNUSED_ARG(pSelf);
+    PJ_UNUSED_ARG(pArgs);
+
+    pjsua_buddy_config_default(&cfg);
+    obj = (PyObj_pjsua_buddy_config *) 
+	  PyObj_pjsua_buddy_config_new(&PyTyp_pjsua_buddy_config, NULL, NULL);
+    PyObj_pjsua_buddy_config_import(obj, &cfg);
+    
+    return (PyObject *)obj;
+}
+
+/*
+ * py_pjsua_get_buddy_count
+ */
+static PyObject *py_pjsua_get_buddy_count(PyObject *pSelf, PyObject *pArgs)
+{    
+    PJ_UNUSED_ARG(pSelf);
+    PJ_UNUSED_ARG(pArgs);
+
+    return Py_BuildValue("i", pjsua_get_buddy_count());
+}
+
+/*
+ * py_pjsua_buddy_is_valid
+ */
+static PyObject *py_pjsua_buddy_is_valid(PyObject *pSelf, PyObject *pArgs)
+{    
+    int id;
+    int is_valid;
+
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "i", &id)) {
+        return NULL;
+    }
+    is_valid = pjsua_buddy_is_valid(id);
+	
+    return Py_BuildValue("i", is_valid);
+}
+
+/*
+ * py_pjsua_enum_buddies
+ */
+static PyObject *py_pjsua_enum_buddies(PyObject *pSelf, PyObject *pArgs)
+{
+    pj_status_t status;
+    PyObject *list;
+    pjsua_buddy_id id[PJSUA_MAX_BUDDIES];
+    unsigned c, i;
+
+    PJ_UNUSED_ARG(pSelf);
+    PJ_UNUSED_ARG(pArgs);
+
+    c = PJ_ARRAY_SIZE(id);
+    status = pjsua_enum_buddies(id, &c);
+    if (status != PJ_SUCCESS)
+	c = 0;
+
+    list = PyList_New(c);
+    for (i = 0; i < c; i++) {
+        PyList_SetItem(list, i, Py_BuildValue("i", id[i]));
+    }
+    
+    return (PyObject*)list;
+}
+
+/*
+ * py_pjsua_buddy_find
+ */
+static PyObject *py_pjsua_buddy_find(PyObject *pSelf, PyObject *pArgs)
+{    
+    PyObject *pURI;
+    pj_str_t uri;
+    pjsua_buddy_id buddy_id;
+
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "O", &pURI)) {
+        return NULL;
+    }
+
+    if (!PyString_Check(pURI))
+	return Py_BuildValue("i", PJSUA_INVALID_ID);
+
+    uri = PyString_ToPJ(pURI);
+    buddy_id = pjsua_buddy_find(&uri);
+
+    return Py_BuildValue("i", buddy_id);
+}
+
+/*
+ * py_pjsua_buddy_get_info
+ */
+static PyObject *py_pjsua_buddy_get_info(PyObject *pSelf, PyObject *pArgs)
+{    	
+    int buddy_id;
+    pjsua_buddy_info info;
+    int status;	
+
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "i", &buddy_id)) {
+        return NULL;
+    }
+
+    status = pjsua_buddy_get_info(buddy_id, &info);
+    if (status == PJ_SUCCESS) {
+	PyObj_pjsua_buddy_info *obj;
+
+	obj = (PyObj_pjsua_buddy_info *)
+	      PyObj_pjsua_buddy_config_new(&PyTyp_pjsua_buddy_info, 
+					   NULL, NULL);
+	PyObj_pjsua_buddy_info_import(obj, &info);	
+        return (PyObject*)obj;
+    } else {
+	return Py_BuildValue("");
+    }
+}
+
+/*
+ * py_pjsua_buddy_add
+ */
+static PyObject *py_pjsua_buddy_add(PyObject *pSelf, PyObject *pArgs)
+{   
+    PyObject *pCfg;
+    int buddy_id;
+    int status;
+
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "O", &pCfg)) {
+        return NULL;
+    }
+
+    if (pCfg != Py_None) {
+	pjsua_buddy_config cfg;
+	PyObj_pjsua_buddy_config *bc;
+
+        bc = (PyObj_pjsua_buddy_config *)pCfg;
+
+	pjsua_buddy_config_default(&cfg);
+        PyObj_pjsua_buddy_config_export(&cfg, bc);  
+    
+        status = pjsua_buddy_add(&cfg, &buddy_id);
+
+    } else {
+        status = PJ_EINVAL;
+	buddy_id = PJSUA_INVALID_ID;
+    }
+    return Py_BuildValue("ii", status, buddy_id);
+}
+
+/*
+ * py_pjsua_buddy_del
+ */
+static PyObject *py_pjsua_buddy_del(PyObject *pSelf, PyObject *pArgs)
+{    
+    int buddy_id;
+    int status;
+    PyObject *user_data;
+
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "i", &buddy_id)) {
+        return NULL;
+    }
+
+    user_data = (PyObject*) pjsua_buddy_get_user_data(buddy_id);
+    Py_XDECREF(user_data);
+
+    status = pjsua_buddy_del(buddy_id);
+
+    return Py_BuildValue("i", status);
+}
+
+/*
+ * py_pjsua_buddy_set_user_data
+ */
+static PyObject *py_pjsua_buddy_set_user_data(PyObject *pSelf, PyObject *pArgs)
+{    
+    int buddy_id;
+    int status;
+    PyObject *user_data, *old_user_data;
+
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "iO", &buddy_id, &user_data)) {
+        return NULL;
+    }
+
+    if (!pjsua_buddy_is_valid(buddy_id)) {
+	return Py_BuildValue("i", 0);
+    }
+
+    old_user_data = (PyObject*) pjsua_buddy_get_user_data(buddy_id);
+
+    status = pjsua_buddy_set_user_data(buddy_id, (void*)user_data);
+
+    if (status == PJ_SUCCESS) {
+	Py_XINCREF(user_data);
+	Py_XDECREF(old_user_data);
+    }
+
+    return Py_BuildValue("i", status);
+}
+
+/*
+ * py_pjsua_buddy_get_user_data
+ */
+static PyObject *py_pjsua_buddy_get_user_data(PyObject *pSelf, PyObject *pArgs)
+{    
+    int buddy_id;
+    PyObject *user_data;
+
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "i", &buddy_id)) {
+        return NULL;
+    }
+
+    user_data = (PyObject*) pjsua_buddy_get_user_data(buddy_id);
+
+    return user_data? Py_BuildValue("O", user_data) : Py_BuildValue("");
+}
+
+/*
+ * py_pjsua_buddy_subscribe_pres
+ */
+static PyObject *py_pjsua_buddy_subscribe_pres(PyObject *pSelf, 
+					       PyObject *pArgs)
+{
+    int buddy_id;
+    int status;
+    int subscribe;
+
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "ii", &buddy_id, &subscribe)) {
+        return NULL;
+    }
+
+    status = pjsua_buddy_subscribe_pres(buddy_id, subscribe);
+
+    return Py_BuildValue("i", status);
+}
+
+/*
+ * py_pjsua_pres_dump
+ */
+static PyObject *py_pjsua_pres_dump(PyObject *pSelf, PyObject *pArgs)
+{    
+    int verbose;
+
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "i", &verbose)) {
+        return NULL;
+    }
+
+    pjsua_pres_dump(verbose);	
+
+    return Py_BuildValue("");
+}
+
+/*
+ * py_pjsua_im_send
+ */
+static PyObject *py_pjsua_im_send(PyObject *pSelf, PyObject *pArgs)
+{    
+    int status;
+    int acc_id;
+    pj_str_t *mime_type, tmp_mime_type;
+    pj_str_t to, content;
+    PyObject *pTo;
+    PyObject *pMimeType;
+    PyObject *pContent;
+    pjsua_msg_data msg_data;
+    PyObject *pMsgData;
+    int user_data;
+    pj_pool_t *pool = NULL;
+
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "iOOOOi", &acc_id, 
+		&pTo, &pMimeType, &pContent, &pMsgData, &user_data))
+    {
+        return NULL;
+    }
+
+    if (pMimeType != Py_None) {
+        mime_type = &tmp_mime_type;
+	tmp_mime_type = PyString_ToPJ(pMimeType);
+    } else {
+        mime_type = NULL;
+    }
+
+    to = PyString_ToPJ(pTo);
+    content = PyString_ToPJ(pContent);
+
+    pjsua_msg_data_init(&msg_data);
+
+    if (pMsgData != Py_None) {
+	PyObj_pjsua_msg_data *omd;
+
+        omd = (PyObj_pjsua_msg_data *)pMsgData;
+	msg_data.content_type = PyString_ToPJ(omd->content_type);
+	msg_data.msg_body = PyString_ToPJ(omd->msg_body);
+        pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
+        translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
+    }
+
+    status = pjsua_im_send(acc_id, &to, mime_type, &content, 
+			   &msg_data, (void*)(long)user_data);
+    if (pool)
+	pj_pool_release(pool);
+    
+    return Py_BuildValue("i",status);
+}
+
+/*
+ * py_pjsua_im_typing
+ */
+static PyObject *py_pjsua_im_typing(PyObject *pSelf, PyObject *pArgs)
+{    
+    int status;
+    int acc_id;
+    pj_str_t to;
+    PyObject *pTo;
+    int is_typing;
+    pjsua_msg_data msg_data;
+    PyObject *pMsgData;
+    pj_pool_t *pool = NULL;
+
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "iOiO", &acc_id, &pTo, &is_typing, 
+			  &pMsgData)) 
+    {
+        return NULL;
+    }
+	
+    to = PyString_ToPJ(pTo);
+
+    pjsua_msg_data_init(&msg_data);
+
+    if (pMsgData != Py_None) {
+	PyObj_pjsua_msg_data *omd;
+
+        omd = (PyObj_pjsua_msg_data *)pMsgData;
+	msg_data.content_type = PyString_ToPJ(omd->content_type);
+	msg_data.msg_body = PyString_ToPJ(omd->msg_body);
+        pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
+
+        translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
+    }
+
+    status = pjsua_im_typing(acc_id, &to, is_typing, &msg_data);
+
+    if (pool)
+	pj_pool_release(pool);
+
+    return Py_BuildValue("i", status);
+}
+
+static char pjsua_buddy_config_default_doc[] =
+    "_pjsua.Buddy_Config _pjsua.buddy_config_default () "
+    "Set default values to the buddy config.";
+static char pjsua_get_buddy_count_doc[] =
+    "int _pjsua.get_buddy_count () "
+    "Get total number of buddies.";
+static char pjsua_buddy_is_valid_doc[] =
+    "int _pjsua.buddy_is_valid (int buddy_id) "
+    "Check if buddy ID is valid.";
+static char pjsua_enum_buddies_doc[] =
+    "int[] _pjsua.enum_buddies () "
+    "Enum buddy IDs.";
+static char pjsua_buddy_get_info_doc[] =
+    "_pjsua.Buddy_Info _pjsua.buddy_get_info (int buddy_id) "
+    "Get detailed buddy info.";
+static char pjsua_buddy_add_doc[] =
+    "int,int _pjsua.buddy_add (_pjsua.Buddy_Config cfg) "
+    "Add new buddy.";
+static char pjsua_buddy_del_doc[] =
+    "int _pjsua.buddy_del (int buddy_id) "
+    "Delete buddy.";
+static char pjsua_buddy_subscribe_pres_doc[] =
+    "int _pjsua.buddy_subscribe_pres (int buddy_id, int subscribe) "
+    "Enable/disable buddy's presence monitoring.";
+static char pjsua_pres_dump_doc[] =
+    "void _pjsua.pres_dump (int verbose) "
+    "Dump presence subscriptions to log file.";
+static char pjsua_im_send_doc[] =
+    "int _pjsua.im_send (int acc_id, string to, string mime_type, "
+    "string content, _pjsua.Msg_Data msg_data, int user_data) "
+    "Send instant messaging outside dialog, using the specified account "
+    "for route set and authentication.";
+static char pjsua_im_typing_doc[] =
+    "int _pjsua.im_typing (int acc_id, string to, int is_typing, "
+    "_pjsua.Msg_Data msg_data) "
+    "Send typing indication outside dialog.";
+
+/* END OF LIB BUDDY */
+
+/* LIB MEDIA */
+
+
+/*
+ * py_pjsua_conf_get_max_ports
+ */
+static PyObject *py_pjsua_conf_get_max_ports(PyObject *pSelf, PyObject *pArgs)
+{    
+    PJ_UNUSED_ARG(pSelf);
+    PJ_UNUSED_ARG(pArgs);
+
+    return Py_BuildValue("i", pjsua_conf_get_max_ports());
+}
+
+/*
+ * py_pjsua_conf_get_active_ports
+ */
+static PyObject *py_pjsua_conf_get_active_ports(PyObject *pSelf, 
+						PyObject *pArgs)
+{    
+    PJ_UNUSED_ARG(pSelf);
+    PJ_UNUSED_ARG(pArgs);
+
+    return Py_BuildValue("i", pjsua_conf_get_active_ports());
+}
+
+/*
+ * py_pjsua_enum_conf_ports
+ */
+static PyObject *py_pjsua_enum_conf_ports(PyObject *pSelf, PyObject *pArgs)
+{
+    pj_status_t status;
+    PyObject *list;
+    pjsua_conf_port_id id[PJSUA_MAX_CONF_PORTS];
+    unsigned c, i;
+
+    PJ_UNUSED_ARG(pSelf);
+    PJ_UNUSED_ARG(pArgs);
+
+    c = PJ_ARRAY_SIZE(id);
+    status = pjsua_enum_conf_ports(id, &c);
+    if (status != PJ_SUCCESS)
+	c = 0;
+    
+    list = PyList_New(c);
+    for (i = 0; i < c; i++) {
+        PyList_SetItem(list, i, Py_BuildValue("i", id[i]));
+    }
+    
+    return (PyObject*)list;
+}
+
+/*
+ * py_pjsua_conf_get_port_info
+ */
+static PyObject *py_pjsua_conf_get_port_info(PyObject *pSelf, PyObject *pArgs)
+{    	
+    int id;
+    PyObj_pjsua_conf_port_info *ret;
+    pjsua_conf_port_info info;
+    int status;	
+    unsigned i;
+
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "i", &id)) {
+        return NULL;
+    }
+    
+    status = pjsua_conf_get_port_info(id, &info);
+    ret = (PyObj_pjsua_conf_port_info *)
+	  conf_port_info_new(&PyTyp_pjsua_conf_port_info, NULL, NULL);
+    ret->bits_per_sample = info.bits_per_sample;
+    ret->channel_count = info.channel_count;
+    ret->clock_rate = info.clock_rate;
+    ret->name = PyString_FromPJ(&info.name);
+    ret->samples_per_frame = info.samples_per_frame;
+    ret->slot_id = info.slot_id;
+    Py_XDECREF(ret->listeners);
+    ret->listeners = PyList_New(info.listener_cnt);
+    for (i = 0; i < info.listener_cnt; i++) {
+	PyObject *item = Py_BuildValue("i",info.listeners[i]);
+	PyList_SetItem(ret->listeners, i, item);
+    }
+    return (PyObject*)ret;
+}
+
+/*
+ * py_pjsua_conf_remove_port
+ */
+static PyObject *py_pjsua_conf_remove_port(PyObject *pSelf, PyObject *pArgs)
+{    	
+    int id;
+    int status;	
+    
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "i", &id)) {
+        return NULL;
+    }	
+    
+    status = pjsua_conf_remove_port(id);
+    
+    return Py_BuildValue("i", status);
+}
+
+/*
+ * py_pjsua_conf_connect
+ */
+static PyObject *py_pjsua_conf_connect(PyObject *pSelf, PyObject *pArgs)
+{    	
+    int source, sink;
+    int status;	
+    
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "ii", &source, &sink)) {
+        return NULL;
+    }	
+    
+    status = pjsua_conf_connect(source, sink);
+    
+    return Py_BuildValue("i", status);
+}
+
+/*
+ * py_pjsua_conf_disconnect
+ */
+static PyObject *py_pjsua_conf_disconnect(PyObject *pSelf, PyObject *pArgs)
+{    	
+    int source, sink;
+    int status;	
+    
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "ii", &source, &sink)) {
+        return NULL;
+    }	
+    
+    status = pjsua_conf_disconnect(source, sink);
+    
+    return Py_BuildValue("i", status);
+}
+
+/*
+ * py_pjsua_conf_set_tx_level
+ */
+static PyObject *py_pjsua_conf_set_tx_level(PyObject *pSelf, PyObject *pArgs)
+{    	
+    int slot;
+    float level;
+    int status;	
+    
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "if", &slot, &level)) {
+        return NULL;
+    }	
+    
+    status = pjsua_conf_adjust_tx_level(slot, level);
+    
+    return Py_BuildValue("i", status);
+}
+
+/*
+ * py_pjsua_conf_set_rx_level
+ */
+static PyObject *py_pjsua_conf_set_rx_level(PyObject *pSelf, PyObject *pArgs)
+{    	
+    int slot;
+    float level;
+    int status;	
+    
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "if", &slot, &level)) {
+        return NULL;
+    }	
+    
+    status = pjsua_conf_adjust_rx_level(slot, level);
+    
+    return Py_BuildValue("i", status);
+}
+
+/*
+ * py_pjsua_conf_get_signal_level
+ */
+static PyObject *py_pjsua_conf_get_signal_level(PyObject *pSelf, 
+						PyObject *pArgs)
+{    	
+    int slot;
+    unsigned tx_level, rx_level;
+    int status;	
+    
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "i", &slot)) {
+        return NULL;
+    }	
+    
+    status = pjsua_conf_get_signal_level(slot, &tx_level, &rx_level);
+    
+    return Py_BuildValue("iff", status, (float)(tx_level/255.0), 
+			 (float)(rx_level/255.0));
+}
+
+/*
+ * py_pjsua_player_create
+ */
+static PyObject *py_pjsua_player_create(PyObject *pSelf, PyObject *pArgs)
+{    	
+    int id;
+    int options;
+    PyObject *pFilename;
+    pj_str_t filename;
+    int status;	
+    
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "Oi", &pFilename, &options)) {
+        return NULL;
+    }
+
+    filename = PyString_ToPJ(pFilename);
+    status = pjsua_player_create(&filename, options, &id);
+    
+    return Py_BuildValue("ii", status, id);
+}
+
+/*
+ * py_pjsua_playlist_create
+ */
+static PyObject *py_pjsua_playlist_create(PyObject *pSelf, PyObject *pArgs)
+{    	
+    int id;
+    int options;
+    PyObject *pLabel, *pFileList;
+    pj_str_t label;
+    int count;
+    pj_str_t files[64];
+    int status;	
+    
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "OOi", &pLabel, &pFileList, &options)) {
+        return NULL;
+    }
+
+    label = PyString_ToPJ(pLabel);
+    if (!PyList_Check(pFileList))
+	return Py_BuildValue("ii", PJ_EINVAL, PJSUA_INVALID_ID);
+
+    count = 0;
+    for (count=0; count<PyList_Size(pFileList) && 
+		  count<PJ_ARRAY_SIZE(files); ++count) 
+    {
+	files[count] = PyString_ToPJ(PyList_GetItem(pFileList, count));
+    }
+
+    status = pjsua_playlist_create(files, count, &label, options, &id);
+    
+    return Py_BuildValue("ii", status, id);
+}
+
+/*
+ * py_pjsua_player_get_conf_port
+ */
+static PyObject *py_pjsua_player_get_conf_port(PyObject *pSelf, 
+					       PyObject *pArgs)
+{    	
+    
+    int id, port_id;	
+    
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "i", &id)) {
+        return NULL;
+    }	
+    
+    port_id = pjsua_player_get_conf_port(id);
+    
+    return Py_BuildValue("i", port_id);
+}
+
+/*
+ * py_pjsua_player_set_pos
+ */
+static PyObject *py_pjsua_player_set_pos(PyObject *pSelf, PyObject *pArgs)
+{    	
+    int id;
+    int samples;
+    int status;	
+    
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "ii", &id, &samples)) {
+        return NULL;
+    }	
+    
+    if (samples < 0)
+	samples = 0;
+
+    status = pjsua_player_set_pos(id, samples);
+    
+    return Py_BuildValue("i", status);
+}
+
+/*
+ * py_pjsua_player_destroy
+ */
+static PyObject *py_pjsua_player_destroy(PyObject *pSelf, PyObject *pArgs)
+{    	
+    int id;
+    int status;	
+    
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "i", &id)) {
+        return NULL;
+    }	
+    
+    status = pjsua_player_destroy(id);
+    
+    return Py_BuildValue("i", status);
+}
+
+/*
+ * py_pjsua_recorder_create
+ */
+static PyObject *py_pjsua_recorder_create(PyObject *pSelf, PyObject *pArgs)
+{    	
+    int id, options;
+    int max_size;
+    PyObject *pFilename, *pEncParam;
+    pj_str_t filename;
+    int enc_type;
+    
+    int status;	
+    
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "OiOii", &pFilename, &enc_type, &pEncParam,
+			  &max_size, &options))
+    {
+        return NULL;
+    }
+
+    filename = PyString_ToPJ(pFilename);
+
+    status = pjsua_recorder_create(&filename, enc_type, NULL, max_size,
+				   options, &id);
+
+    return Py_BuildValue("ii", status, id);
+}
+
+/*
+ * py_pjsua_recorder_get_conf_port
+ */
+static PyObject *py_pjsua_recorder_get_conf_port(PyObject *pSelf, 
+						 PyObject *pArgs)
+{    	
+    
+    int id, port_id;	
+    
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "i", &id)) {
+        return NULL;
+    }	
+    
+    port_id = pjsua_recorder_get_conf_port(id);
+    
+    return Py_BuildValue("i", port_id);
+}
+
+/*
+ * py_pjsua_recorder_destroy
+ */
+static PyObject *py_pjsua_recorder_destroy(PyObject *pSelf, PyObject *pArgs)
+{    	
+    int id;
+    int status;	
+    
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "i", &id)) {
+        return NULL;
+    }	
+    
+    status = pjsua_recorder_destroy(id);
+    
+    return Py_BuildValue("i", status);
+}
+
+/*
+ * py_pjsua_enum_snd_devs
+ */
+static PyObject *py_pjsua_enum_snd_devs(PyObject *pSelf, PyObject *pArgs)
+{
+    pj_status_t status;
+    PyObject *ret;
+    pjmedia_snd_dev_info info[SND_DEV_NUM];
+    unsigned c, i;
+
+    PJ_UNUSED_ARG(pSelf);
+    PJ_UNUSED_ARG(pArgs);
+
+    c = PJ_ARRAY_SIZE(info);
+    status = pjsua_enum_snd_devs(info, &c);
+    if (status != PJ_SUCCESS)
+	c = 0;
+    
+    ret = PyList_New(c);
+    for (i = 0; i < c; i++)  {
+        PyObj_pjmedia_snd_dev_info * obj;
+
+        obj = (PyObj_pjmedia_snd_dev_info *)
+	      pjmedia_snd_dev_info_new(&PyTyp_pjmedia_snd_dev_info, 
+				       NULL, NULL);
+        obj->default_samples_per_sec = info[i].default_samples_per_sec;
+        obj->input_count = info[i].input_count;
+        obj->output_count = info[i].output_count;
+        obj->name = PyString_FromString(info[i].name);
+
+        PyList_SetItem(ret, i, (PyObject *)obj);
+    }
+    
+    return (PyObject*)ret;
+}
+
+/*
+ * py_pjsua_get_snd_dev
+ */
+static PyObject *py_pjsua_get_snd_dev(PyObject *pSelf, PyObject *pArgs)
+{    	
+    int capture_dev, playback_dev;
+    int status;	
+    
+    PJ_UNUSED_ARG(pSelf);
+    PJ_UNUSED_ARG(pArgs);
+
+    status = pjsua_get_snd_dev(&capture_dev, &playback_dev);
+    
+    return Py_BuildValue("ii", capture_dev, playback_dev);
+}
+
+/*
+ * py_pjsua_set_snd_dev
+ */
+static PyObject *py_pjsua_set_snd_dev(PyObject *pSelf, PyObject *pArgs)
+{    	
+    int capture_dev, playback_dev;
+    int status;	
+    
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "ii", &capture_dev, &playback_dev)) {
+        return NULL;
+    }	
+    
+    status = pjsua_set_snd_dev(capture_dev, playback_dev);
+    
+    return Py_BuildValue("i", status);
+}
+
+/*
+ * py_pjsua_set_null_snd_dev
+ */
+static PyObject *py_pjsua_set_null_snd_dev(PyObject *pSelf, PyObject *pArgs)
+{    	
+    int status;	
+
+    PJ_UNUSED_ARG(pSelf);
+    PJ_UNUSED_ARG(pArgs);
+
+    status = pjsua_set_null_snd_dev();
+
+    return Py_BuildValue("i", status);
+}
+
+/*
+ * py_pjsua_set_ec
+ */
+static PyObject *py_pjsua_set_ec(PyObject *pSelf, PyObject *pArgs)
+{    	
+    int options;
+    int tail_ms;
+    int status;	
+    
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "ii", &tail_ms, &options)) {
+        return NULL;
+    }	
+
+    status = pjsua_set_ec(tail_ms, options);
+    
+    return Py_BuildValue("i", status);
+}
+
+/*
+ * py_pjsua_get_ec_tail
+ */
+static PyObject *py_pjsua_get_ec_tail(PyObject *pSelf, PyObject *pArgs)
+{    	
+    int status;	
+    unsigned tail_ms;
+
+    PJ_UNUSED_ARG(pSelf);
+    PJ_UNUSED_ARG(pArgs);
+
+    status = pjsua_get_ec_tail(&tail_ms);
+    if (status != PJ_SUCCESS)
+	tail_ms = 0;
+    
+    return Py_BuildValue("i", tail_ms);
+}
+
+/*
+ * py_pjsua_enum_codecs
+ */
+static PyObject *py_pjsua_enum_codecs(PyObject *pSelf, PyObject *pArgs)
+{
+    pj_status_t status;
+    PyObject *ret;
+    pjsua_codec_info info[PJMEDIA_CODEC_MGR_MAX_CODECS];
+    unsigned c, i;
+
+    PJ_UNUSED_ARG(pSelf);
+    PJ_UNUSED_ARG(pArgs);
+
+    c = PJ_ARRAY_SIZE(info);
+    status = pjsua_enum_codecs(info, &c);
+    if (status != PJ_SUCCESS)
+	c = 0;
+    
+    ret = PyList_New(c);
+    for (i = 0; i < c; i++)  {
+        PyObj_pjsua_codec_info * obj;
+        obj = (PyObj_pjsua_codec_info *)
+	      codec_info_new(&PyTyp_pjsua_codec_info, NULL, NULL);
+        obj->codec_id = PyString_FromPJ(&info[i].codec_id);
+        obj->priority = info[i].priority;
+
+        PyList_SetItem(ret, i, (PyObject *)obj);
+    }
+
+    return (PyObject*)ret;
+}
+
+/*
+ * py_pjsua_codec_set_priority
+ */
+static PyObject *py_pjsua_codec_set_priority(PyObject *pSelf, PyObject *pArgs)
+{    	
+    int status;	
+    PyObject *pCodecId;
+    pj_str_t codec_id;
+    int priority;
+    
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "Oi", &pCodecId, &priority)) {
+        return NULL;
+    }
+
+    codec_id = PyString_ToPJ(pCodecId);
+    if (priority < 0)
+	priority = 0;
+    if (priority > 255)
+	priority = 255;
+
+    status = pjsua_codec_set_priority(&codec_id, (pj_uint8_t)priority);
+    
+    return Py_BuildValue("i", status);
+}
+
+/*
+ * py_pjsua_codec_get_param
+ */
+static PyObject *py_pjsua_codec_get_param(PyObject *pSelf, PyObject *pArgs)
+{    	
+    int status;	
+    PyObject *pCodecId;
+    pj_str_t codec_id;
+    pjmedia_codec_param param;
+    PyObj_pjmedia_codec_param *ret;
+    
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "O", &pCodecId)) {
+        return NULL;
+    }	
+
+    codec_id = PyString_ToPJ(pCodecId);
+
+    status = pjsua_codec_get_param(&codec_id, &param);
+    if (status != PJ_SUCCESS)
+	return Py_BuildValue("");
+
+    ret = (PyObj_pjmedia_codec_param *)
+	  pjmedia_codec_param_new(&PyTyp_pjmedia_codec_param, NULL, NULL);
+
+    ret->info->avg_bps = param.info.avg_bps;
+    ret->info->channel_cnt = param.info.channel_cnt;
+    ret->info->clock_rate = param.info.clock_rate;
+    ret->info->frm_ptime = param.info.frm_ptime;
+    ret->info->pcm_bits_per_sample = param.info.pcm_bits_per_sample;
+    ret->info->pt = param.info.pt;
+    ret->setting->cng = param.setting.cng;
+    //ret->setting->dec_fmtp_mode = param.setting.dec_fmtp_mode;
+    //ret->setting->enc_fmtp_mode = param.setting.enc_fmtp_mode;
+    ret->setting->frm_per_pkt = param.setting.frm_per_pkt;
+    ret->setting->penh = param.setting.penh;
+    ret->setting->plc = param.setting.plc;
+    ret->setting->vad = param.setting.vad;
+
+    return (PyObject*)ret;
+}
+
+
+/*
+ * py_pjsua_codec_set_param
+ */
+static PyObject *py_pjsua_codec_set_param(PyObject *pSelf, PyObject *pArgs)
+{    	
+    int status;	
+    PyObject *pCodecId, *pCodecParam;
+    pj_str_t codec_id;
+    pjmedia_codec_param param;
+    
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "OO", &pCodecId, &pCodecParam)) {
+        return NULL;
+    }	
+
+    codec_id = PyString_ToPJ(pCodecId);
+
+    if (pCodecParam != Py_None) {
+	PyObj_pjmedia_codec_param *obj;
+
+        obj = (PyObj_pjmedia_codec_param *)pCodecParam;
+
+        param.info.avg_bps = obj->info->avg_bps;
+        param.info.channel_cnt = obj->info->channel_cnt;
+        param.info.clock_rate = obj->info->clock_rate;
+        param.info.frm_ptime = obj->info->frm_ptime;
+        param.info.pcm_bits_per_sample = obj->info->pcm_bits_per_sample;
+        param.info.pt = obj->info->pt;
+        param.setting.cng = obj->setting->cng;
+        //param.setting.dec_fmtp_mode = obj->setting->dec_fmtp_mode;
+        //param.setting.enc_fmtp_mode = obj->setting->enc_fmtp_mode;
+        param.setting.frm_per_pkt = obj->setting->frm_per_pkt;
+        param.setting.penh = obj->setting->penh;
+        param.setting.plc = obj->setting->plc;
+        param.setting.vad = obj->setting->vad;
+        status = pjsua_codec_set_param(&codec_id, &param);
+
+    } else {
+        status = pjsua_codec_set_param(&codec_id, NULL);
+    }
+
+    return Py_BuildValue("i", status);
+}
+
+static char pjsua_conf_get_max_ports_doc[] =
+    "int _pjsua.conf_get_max_ports () "
+    "Get maxinum number of conference ports.";
+static char pjsua_conf_get_active_ports_doc[] =
+    "int _pjsua.conf_get_active_ports () "
+    "Get current number of active ports in the bridge.";
+static char pjsua_enum_conf_ports_doc[] =
+    "int[] _pjsua.enum_conf_ports () "
+    "Enumerate all conference ports.";
+static char pjsua_conf_get_port_info_doc[] =
+    "_pjsua.Conf_Port_Info _pjsua.conf_get_port_info (int id) "
+    "Get information about the specified conference port";
+static char pjsua_conf_remove_port_doc[] =
+    "int _pjsua.conf_remove_port (int id) "
+    "Remove arbitrary slot from the conference bridge. "
+    "Application should only call this function "
+    "if it registered the port manually.";
+static char pjsua_conf_connect_doc[] =
+    "int _pjsua.conf_connect (int source, int sink) "
+    "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.";
+static char pjsua_conf_disconnect_doc[] =
+    "int _pjsua.conf_disconnect (int source, int sink) "
+    "Disconnect media flow from the source to destination port.";
+static char pjsua_player_create_doc[] =
+    "int, int _pjsua.player_create (string filename, int options) "
+    "Create a file player, and automatically connect "
+    "this player to the conference bridge.";
+static char pjsua_player_get_conf_port_doc[] =
+    "int _pjsua.player_get_conf_port (int) "
+    "Get conference port ID associated with player.";
+static char pjsua_player_set_pos_doc[] =
+    "int _pjsua.player_set_pos (int id, int samples) "
+    "Set playback position.";
+static char pjsua_player_destroy_doc[] =
+    "int _pjsua.player_destroy (int id) "
+    "Close the file, remove the player from the bridge, "
+    "and free resources associated with the file player.";
+static char pjsua_recorder_create_doc[] =
+    "int, int _pjsua.recorder_create (string filename, "
+    "int enc_type, int enc_param, int max_size, int options) "
+    "Create a file recorder, and automatically connect this recorder "
+    "to the conference bridge. The recorder currently supports recording "
+    "WAV file, and on Windows, MP3 file. The type of the recorder to use "
+    "is determined by the extension of the file (e.g. '.wav' or '.mp3').";
+static char pjsua_recorder_get_conf_port_doc[] =
+    "int _pjsua.recorder_get_conf_port (int id) "
+    "Get conference port associated with recorder.";
+static char pjsua_recorder_destroy_doc[] =
+    "int _pjsua.recorder_destroy (int id) "
+    "Destroy recorder (this will complete recording).";
+static char pjsua_enum_snd_devs_doc[] =
+    "_pjsua.PJMedia_Snd_Dev_Info[] _pjsua.enum_snd_devs (int count) "
+    "Enum sound devices.";
+static char pjsua_get_snd_dev_doc[] =
+    "int, int _pjsua.get_snd_dev () "
+    "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.";
+static char pjsua_set_snd_dev_doc[] =
+    "int _pjsua.set_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.";
+static char pjsua_set_null_snd_dev_doc[] =
+    "int _pjsua.set_null_snd_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.";
+static char pjsua_set_ec_doc[] =
+    "int _pjsua.set_ec (int tail_ms, int options) "
+    "Configure the echo canceller tail length of the sound port.";
+static char pjsua_get_ec_tail_doc[] =
+    "int _pjsua.get_ec_tail () "
+    "Get current echo canceller tail length.";
+static char pjsua_enum_codecs_doc[] =
+    "_pjsua.Codec_Info[] _pjsua.enum_codecs () "
+    "Enum all supported codecs in the system.";
+static char pjsua_codec_set_priority_doc[] =
+    "int _pjsua.codec_set_priority (string id, int priority) "
+    "Change codec priority.";
+static char pjsua_codec_get_param_doc[] =
+    "_pjsua.PJMedia_Codec_Param _pjsua.codec_get_param (string id) "
+    "Get codec parameters";
+static char pjsua_codec_set_param_doc[] =
+    "int _pjsua.codec_set_param (string id, "
+    "_pjsua.PJMedia_Codec_Param param) "
+    "Set codec parameters.";
+
+/* END OF LIB MEDIA */
+
+/* LIB CALL */
+
+/*
+ * py_pjsua_call_get_max_count
+ */
+static PyObject *py_pjsua_call_get_max_count(PyObject *pSelf, PyObject *pArgs)
+{    	
+    int count;
+
+    PJ_UNUSED_ARG(pSelf);
+    PJ_UNUSED_ARG(pArgs);
+
+    count = pjsua_call_get_max_count();
+    
+    return Py_BuildValue("i", count);
+}
+
+/*
+ * py_pjsua_call_get_count
+ */
+static PyObject *py_pjsua_call_get_count(PyObject *pSelf, PyObject *pArgs)
+{    	
+    int count;	
+    
+    PJ_UNUSED_ARG(pSelf);
+    PJ_UNUSED_ARG(pArgs);
+
+    count = pjsua_call_get_count();
+    
+    return Py_BuildValue("i", count);
+}
+
+/*
+ * py_pjsua_enum_calls
+ */
+static PyObject *py_pjsua_enum_calls(PyObject *pSelf, PyObject *pArgs)
+{
+    pj_status_t status;
+    PyObject *ret;
+    pjsua_transport_id id[PJSUA_MAX_CALLS];
+    unsigned c, i;
+
+    PJ_UNUSED_ARG(pSelf);
+    PJ_UNUSED_ARG(pArgs);
+
+    c = PJ_ARRAY_SIZE(id);
+    status = pjsua_enum_calls(id, &c);
+    if (status != PJ_SUCCESS)
+	c = 0;
+    
+    ret = PyList_New(c);
+    for (i = 0; i < c; i++)  {     
+        PyList_SetItem(ret, i, Py_BuildValue("i", id[i]));
+    }
+    
+    return (PyObject*)ret;
+}
+
+/*
+ * py_pjsua_call_make_call
+ */
+static PyObject *py_pjsua_call_make_call(PyObject *pSelf, PyObject *pArgs)
+{    
+    int status;
+    int acc_id;
+    pj_str_t dst_uri;
+    PyObject *pDstUri, *pMsgData, *pUserData;
+	pjsua_call_setting option;
+    pjsua_msg_data msg_data;
+    int call_id;
+    pj_pool_t *pool = NULL;
+
+    PJ_UNUSED_ARG(pSelf);
+
+	pjsua_call_setting_default(&option);
+	if (!PyArg_ParseTuple(pArgs, "iOIOO", &acc_id, &pDstUri, &option.flag, 
+			  &pUserData, &pMsgData))
+    {
+        return NULL;
+    }
+	
+    dst_uri = PyString_ToPJ(pDstUri);
+    pjsua_msg_data_init(&msg_data);
+
+    if (pMsgData != Py_None) {
+	PyObj_pjsua_msg_data * omd;
+
+        omd = (PyObj_pjsua_msg_data *)pMsgData;
+
+        msg_data.content_type = PyString_ToPJ(omd->content_type);
+        msg_data.msg_body = PyString_ToPJ(omd->msg_body);
+        pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
+        translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
+    }
+
+    Py_XINCREF(pUserData);
+
+    status = pjsua_call_make_call(acc_id, &dst_uri, 
+				  &option, (void*)pUserData, 
+				  &msg_data, &call_id);	
+    if (pool != NULL)
+	pj_pool_release(pool);
+    
+    if (status != PJ_SUCCESS) {
+    	Py_XDECREF(pUserData);
+    }
+
+    return Py_BuildValue("ii", status, call_id);	
+}
+
+/*
+ * py_pjsua_call_is_active
+ */
+static PyObject *py_pjsua_call_is_active(PyObject *pSelf, PyObject *pArgs)
+{    	
+    int call_id;
+    int is_active;
+    
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "i", &call_id)) {
+        return NULL;
+    }	
+    
+    is_active = pjsua_call_is_active(call_id);
+    
+    return Py_BuildValue("i", is_active);
+}
+
+/*
+ * py_pjsua_call_has_media
+ */
+static PyObject *py_pjsua_call_has_media(PyObject *pSelf, PyObject *pArgs)
+{    	
+    int call_id;
+    int has_media;
+    
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "i", &call_id)) {
+        return NULL;
+    }	
+    
+    has_media = pjsua_call_has_media(call_id);
+
+    return Py_BuildValue("i", has_media);
+}
+
+/*
+ * py_pjsua_call_get_conf_port
+ */
+static PyObject* py_pjsua_call_get_conf_port(PyObject *pSelf, PyObject *pArgs)
+{    	
+    int call_id;
+    int port_id;
+
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "i", &call_id)) {
+        return NULL;
+    }
+
+    port_id = pjsua_call_get_conf_port(call_id);
+
+    return Py_BuildValue("i", port_id);
+}
+
+/*
+ * py_pjsua_call_get_info
+ */
+static PyObject* py_pjsua_call_get_info(PyObject *pSelf, PyObject *pArgs)
+{    	
+    int call_id;
+    int status;
+    PyObj_pjsua_call_info *ret;
+    pjsua_call_info info;
+    
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "i", &call_id)) {
+        return NULL;
+    }	
+    
+    status = pjsua_call_get_info(call_id, &info);
+    if (status != PJ_SUCCESS)
+	return Py_BuildValue("");
+
+    ret = (PyObj_pjsua_call_info *)call_info_new(&PyTyp_pjsua_call_info,
+						 NULL, NULL);
+    ret->acc_id = info.acc_id;
+    Py_XDECREF(ret->call_id);
+    ret->call_id = PyString_FromPJ(&info.call_id);
+    ret->conf_slot = info.conf_slot;
+    ret->connect_duration = info.connect_duration.sec * 1000 +
+			    info.connect_duration.msec;
+    ret->total_duration = info.total_duration.sec * 1000 +
+			  info.total_duration.msec;
+    ret->id = info.id;
+    ret->last_status = info.last_status;
+    Py_XDECREF(ret->last_status_text);
+    ret->last_status_text = PyString_FromPJ(&info.last_status_text);
+    Py_XDECREF(ret->local_contact);
+    ret->local_contact = PyString_FromPJ(&info.local_contact);
+    Py_XDECREF(ret->local_info);
+    ret->local_info = PyString_FromPJ(&info.local_info);
+    Py_XDECREF(ret->remote_contact);
+    ret->remote_contact = PyString_FromPJ(&info.remote_contact);
+    Py_XDECREF(ret->remote_info);
+    ret->remote_info = PyString_FromPJ(&info.remote_info);
+    ret->media_dir = info.media_dir;
+    ret->media_status = info.media_status;
+    ret->role = info.role;
+    ret->state = info.state;
+    Py_XDECREF(ret->state_text);
+    ret->state_text = PyString_FromPJ(&info.state_text);
+
+    return (PyObject*)ret;
+}
+
+/*
+ * py_pjsua_call_set_user_data
+ */
+static PyObject *py_pjsua_call_set_user_data(PyObject *pSelf, PyObject *pArgs)
+{    	
+    int call_id;
+    PyObject *pUserData, *old_user_data;
+    int status;
+
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "iO", &call_id, &pUserData)) {
+        return NULL;
+    }
+
+    old_user_data = (PyObject*) pjsua_call_get_user_data(call_id);
+
+    if (old_user_data == pUserData) {
+	return Py_BuildValue("i", PJ_SUCCESS);
+    }
+
+    Py_XINCREF(pUserData);
+    Py_XDECREF(old_user_data);
+
+    status = pjsua_call_set_user_data(call_id, (void*)pUserData);
+    
+    if (status != PJ_SUCCESS) {
+    	Py_XDECREF(pUserData);
+    }
+
+    return Py_BuildValue("i", status);
+}
+
+/*
+ * py_pjsua_call_get_user_data
+ */
+static PyObject *py_pjsua_call_get_user_data(PyObject *pSelf, PyObject *pArgs)
+{    	
+    int call_id;
+    PyObject *user_data;	
+    
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "i", &call_id)) {
+        return NULL;
+    }	
+    
+    user_data = (PyObject*)pjsua_call_get_user_data(call_id);
+    return user_data ? Py_BuildValue("O", user_data) : Py_BuildValue("");
+}
+
+/*
+ * py_pjsua_call_answer
+ */
+static PyObject *py_pjsua_call_answer(PyObject *pSelf, PyObject *pArgs)
+{    
+    int status;
+    int call_id;
+    pj_str_t * reason, tmp_reason;
+    PyObject *pReason;
+    unsigned code;
+    pjsua_msg_data msg_data;
+    PyObject * omdObj;
+    pj_pool_t * pool = NULL;
+
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "iIOO", &call_id, &code, &pReason, &omdObj)) {
+        return NULL;
+    }
+
+    if (pReason == Py_None) {
+        reason = NULL;
+    } else {
+	reason = &tmp_reason;
+        tmp_reason = PyString_ToPJ(pReason);
+    }
+
+    pjsua_msg_data_init(&msg_data);
+    if (omdObj != Py_None) {
+	PyObj_pjsua_msg_data *omd;
+
+        omd = (PyObj_pjsua_msg_data *)omdObj;
+        msg_data.content_type = PyString_ToPJ(omd->content_type);
+        msg_data.msg_body = PyString_ToPJ(omd->msg_body);
+        pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
+        translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
+    }
+    
+    status = pjsua_call_answer(call_id, code, reason, &msg_data);	
+
+    if (pool)
+	pj_pool_release(pool);
+
+    return Py_BuildValue("i", status);
+}
+
+/*
+ * py_pjsua_call_hangup
+ */
+static PyObject *py_pjsua_call_hangup(PyObject *pSelf, PyObject *pArgs)
+{    
+    int status;
+    int call_id;
+    pj_str_t *reason, tmp_reason;
+    PyObject *pReason;
+    unsigned code;
+    pjsua_msg_data msg_data;
+    PyObject *omdObj;
+    pj_pool_t *pool = NULL;
+
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "iIOO", &call_id, &code, &pReason, 
+			  &omdObj))
+    {
+        return NULL;
+    }
+
+    if (pReason == Py_None) {
+        reason = NULL;
+    } else {
+        reason = &tmp_reason;
+        tmp_reason = PyString_ToPJ(pReason);
+    }
+
+    pjsua_msg_data_init(&msg_data);
+    if (omdObj != Py_None)  {
+	PyObj_pjsua_msg_data *omd;
+
+        omd = (PyObj_pjsua_msg_data *)omdObj;
+        msg_data.content_type = PyString_ToPJ(omd->content_type);
+        msg_data.msg_body = PyString_ToPJ(omd->msg_body);
+        pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
+        translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
+    }
+    
+    status = pjsua_call_hangup(call_id, code, reason, &msg_data);
+    if (pool)
+	pj_pool_release(pool);
+
+    return Py_BuildValue("i", status);
+}
+
+/*
+ * py_pjsua_call_set_hold
+ */
+static PyObject *py_pjsua_call_set_hold(PyObject *pSelf, PyObject *pArgs)
+{    
+    int status;
+    int call_id;    
+    pjsua_msg_data msg_data;
+    PyObject *omdObj;
+    pj_pool_t *pool = NULL;
+
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "iO", &call_id, &omdObj)) {
+        return NULL;
+    }
+
+    pjsua_msg_data_init(&msg_data);
+    if (omdObj != Py_None) {
+	PyObj_pjsua_msg_data *omd;    
+
+        omd = (PyObj_pjsua_msg_data *)omdObj;
+        msg_data.content_type = PyString_ToPJ(omd->content_type);
+        msg_data.msg_body = PyString_ToPJ(omd->msg_body);
+        pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
+        translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
+    }
+
+    status = pjsua_call_set_hold(call_id, &msg_data);
+
+    if (pool)
+        pj_pool_release(pool);
+
+    return Py_BuildValue("i",status);
+}
+
+/*
+ * py_pjsua_call_reinvite
+ */
+static PyObject *py_pjsua_call_reinvite(PyObject *pSelf, PyObject *pArgs)
+{    
+    int status;
+    int call_id;
+    int unhold;
+    pjsua_msg_data msg_data;
+    PyObject *omdObj;
+    pj_pool_t *pool = NULL;
+
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "iiO", &call_id, &unhold, &omdObj)) {
+        return NULL;
+    }
+
+    pjsua_msg_data_init(&msg_data);
+    if (omdObj != Py_None) {
+	PyObj_pjsua_msg_data *omd;
+
+        omd = (PyObj_pjsua_msg_data *)omdObj;
+        msg_data.content_type = PyString_ToPJ(omd->content_type);
+        msg_data.msg_body = PyString_ToPJ(omd->msg_body);
+        pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
+        translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
+    }
+
+    status = pjsua_call_reinvite(call_id, unhold, &msg_data);
+
+    if (pool)
+        pj_pool_release(pool);
+
+    return Py_BuildValue("i", status);
+}
+
+/*
+ * py_pjsua_call_update
+ */
+static PyObject *py_pjsua_call_update(PyObject *pSelf, PyObject *pArgs)
+{    
+    int status;
+    int call_id;    
+    int option;
+    pjsua_msg_data msg_data;
+    PyObject *omdObj;
+    pj_pool_t *pool = NULL;
+
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "iiO", &call_id, &option, &omdObj)) {
+        return NULL;
+    }
+
+    pjsua_msg_data_init(&msg_data);
+    if (omdObj != Py_None) {
+	PyObj_pjsua_msg_data *omd;
+
+        omd = (PyObj_pjsua_msg_data *)omdObj;
+        msg_data.content_type = PyString_ToPJ(omd->content_type);
+        msg_data.msg_body = PyString_ToPJ(omd->msg_body);
+        pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
+        translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
+    }
+
+    status = pjsua_call_update(call_id, option, &msg_data);	
+
+    if (pool)
+        pj_pool_release(pool);
+
+    return Py_BuildValue("i", status);
+}
+
+/*
+ * py_pjsua_call_send_request
+ */
+static PyObject *py_pjsua_call_send_request(PyObject *pSelf, PyObject *pArgs)
+{    
+    int status;
+    int call_id;    
+    PyObject *pMethod;
+    pj_str_t method;
+    pjsua_msg_data msg_data;
+    PyObject *omdObj;
+    pj_pool_t *pool = NULL;
+
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "iOO", &call_id, &pMethod, &omdObj)) {
+        return NULL;
+    }
+
+    if (!PyString_Check(pMethod)) {
+	return NULL;
+    }
+
+    method = PyString_ToPJ(pMethod);
+    pjsua_msg_data_init(&msg_data);
+
+    if (omdObj != Py_None) {
+	PyObj_pjsua_msg_data *omd;
+
+        omd = (PyObj_pjsua_msg_data *)omdObj;
+        msg_data.content_type = PyString_ToPJ(omd->content_type);
+        msg_data.msg_body = PyString_ToPJ(omd->msg_body);
+        pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
+        translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
+    }
+
+    status = pjsua_call_send_request(call_id, &method, &msg_data);	
+
+    if (pool)
+        pj_pool_release(pool);
+
+    return Py_BuildValue("i", status);
+}
+
+/*
+ * py_pjsua_call_xfer
+ */
+static PyObject *py_pjsua_call_xfer(PyObject *pSelf, PyObject *pArgs)
+{    
+    int status;
+    int call_id;
+    pj_str_t dest;
+    PyObject *pDstUri;
+    pjsua_msg_data msg_data;
+    PyObject *omdObj;
+    pj_pool_t *pool = NULL;
+
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "iOO", &call_id, &pDstUri, &omdObj)) {
+        return NULL;
+    }
+
+    if (!PyString_Check(pDstUri))
+	return NULL;
+
+    dest = PyString_ToPJ(pDstUri);
+    pjsua_msg_data_init(&msg_data);
+
+    if (omdObj != Py_None) {
+	PyObj_pjsua_msg_data *omd;
+
+        omd = (PyObj_pjsua_msg_data *)omdObj;
+        msg_data.content_type = PyString_ToPJ(omd->content_type);
+        msg_data.msg_body = PyString_ToPJ(omd->msg_body);
+        pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
+        translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
+    }
+
+    status = pjsua_call_xfer(call_id, &dest, &msg_data);
+
+    if (pool)
+        pj_pool_release(pool);
+
+    return Py_BuildValue("i", status);
+}
+
+/*
+ * py_pjsua_call_xfer_replaces
+ */
+static PyObject *py_pjsua_call_xfer_replaces(PyObject *pSelf, PyObject *pArgs)
+{    
+    int status;
+    int call_id;
+    int dest_call_id;
+    unsigned options;    
+    pjsua_msg_data msg_data;
+    PyObject *omdObj;
+    pj_pool_t *pool = NULL;
+
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "iiIO", &call_id, &dest_call_id, 
+			  &options, &omdObj))
+    {
+        return NULL;
+    }
+
+    pjsua_msg_data_init(&msg_data);
+
+    if (omdObj != Py_None) {
+	PyObj_pjsua_msg_data *omd;
+
+        omd = (PyObj_pjsua_msg_data *)omdObj;
+        msg_data.content_type = PyString_ToPJ(omd->content_type);
+        msg_data.msg_body = PyString_ToPJ(omd->msg_body);
+        pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
+        translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
+    }
+
+    status = pjsua_call_xfer_replaces(call_id, dest_call_id, options, 
+				      &msg_data);
+
+    if (pool)
+	pj_pool_release(pool);
+
+    return Py_BuildValue("i", status);
+}
+
+/*
+ * py_pjsua_call_dial_dtmf
+ */
+static PyObject *py_pjsua_call_dial_dtmf(PyObject *pSelf, PyObject *pArgs)
+{    	
+    int call_id;
+    PyObject *pDigits;
+    pj_str_t digits;
+    int status;
+
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "iO", &call_id, &pDigits)) {
+        return NULL;
+    }
+
+    if (!PyString_Check(pDigits))
+	return Py_BuildValue("i", PJ_EINVAL);
+
+    digits = PyString_ToPJ(pDigits);
+    status = pjsua_call_dial_dtmf(call_id, &digits);
+    
+    return Py_BuildValue("i", status);
+}
+
+/*
+ * py_pjsua_call_send_im
+ */
+static PyObject *py_pjsua_call_send_im(PyObject *pSelf, PyObject *pArgs)
+{    
+    int status;
+    int call_id;
+    pj_str_t content;
+    pj_str_t * mime_type, tmp_mime_type;
+    PyObject *pMimeType, *pContent, *omdObj;
+    pjsua_msg_data msg_data;
+    int user_data;
+    pj_pool_t *pool = NULL;
+
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "iOOOi", &call_id, &pMimeType, &pContent, 
+			  &omdObj, &user_data))
+    {
+        return NULL;
+    }
+
+    if (!PyString_Check(pContent))
+	return Py_BuildValue("i", PJ_EINVAL);
+
+    content = PyString_ToPJ(pContent);
+
+    if (PyString_Check(pMimeType)) {
+        mime_type = &tmp_mime_type;
+        tmp_mime_type = PyString_ToPJ(pMimeType);
+    } else {
+	mime_type = NULL;   
+    }
+
+    pjsua_msg_data_init(&msg_data);
+    if (omdObj != Py_None) {
+	PyObj_pjsua_msg_data * omd;
+
+        omd = (PyObj_pjsua_msg_data *)omdObj;
+        msg_data.content_type = PyString_ToPJ(omd->content_type);
+        msg_data.msg_body = PyString_ToPJ(omd->msg_body);
+        pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
+        translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
+    }
+    
+    status = pjsua_call_send_im(call_id, mime_type, &content, 
+				&msg_data, (void*)(long)user_data);
+
+    if (pool)
+        pj_pool_release(pool);
+
+    return Py_BuildValue("i", status);
+}
+
+/*
+ * py_pjsua_call_send_typing_ind
+ */
+static PyObject *py_pjsua_call_send_typing_ind(PyObject *pSelf, 
+					       PyObject *pArgs)
+{    
+    int status;
+    int call_id;    
+    int is_typing;
+    pjsua_msg_data msg_data;
+    PyObject *omdObj;
+    pj_pool_t *pool = NULL;
+
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "iiO", &call_id, &is_typing, &omdObj)) {
+        return NULL;
+    }
+	
+    pjsua_msg_data_init(&msg_data);
+    if (omdObj != Py_None) {
+	PyObj_pjsua_msg_data *omd;
+
+        omd = (PyObj_pjsua_msg_data *)omdObj;
+        msg_data.content_type = PyString_ToPJ(omd->content_type);
+        msg_data.msg_body = PyString_ToPJ(omd->msg_body);
+        pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
+        translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
+    }
+
+    status = pjsua_call_send_typing_ind(call_id, is_typing, &msg_data);	
+
+    if (pool)
+        pj_pool_release(pool);
+
+    return Py_BuildValue("i", status);
+}
+
+/*
+ * py_pjsua_call_hangup_all
+ */
+static PyObject *py_pjsua_call_hangup_all(PyObject *pSelf, PyObject *pArgs)
+{    	
+    PJ_UNUSED_ARG(pSelf);
+    PJ_UNUSED_ARG(pArgs);
+
+    pjsua_call_hangup_all();
+    
+    return Py_BuildValue("");
+}
+
+/*
+ * py_pjsua_call_dump
+ */
+static PyObject *py_pjsua_call_dump(PyObject *pSelf, PyObject *pArgs)
+{    	
+    int call_id;
+    int with_media;
+    PyObject *ret;
+    PyObject *pIndent;
+    char *buffer;
+    char *indent;
+    unsigned maxlen;    
+    int status;
+
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "iiIO", &call_id, &with_media, 
+			  &maxlen, &pIndent))
+    {
+        return NULL;
+    }	
+
+    buffer = (char*) malloc(maxlen * sizeof(char));
+    indent = PyString_AsString(pIndent);
+    
+    status = pjsua_call_dump(call_id, with_media, buffer, maxlen, indent);
+    if (status != PJ_SUCCESS) {
+	free(buffer);
+	return PyString_FromString("");
+    }
+
+    ret = PyString_FromString(buffer);
+    free(buffer);
+    return (PyObject*)ret;
+}
+
+
+/*
+ * py_pjsua_dump
+ * Dump application states.
+ */
+static PyObject *py_pjsua_dump(PyObject *pSelf, PyObject *pArgs)
+{
+    int detail;
+
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "i", &detail)) {
+        return NULL;
+    }	
+
+    pjsua_dump(detail);
+
+    return Py_BuildValue("");
+}
+
+
+/*
+ * py_pj_strerror
+ */
+static PyObject *py_pj_strerror(PyObject *pSelf, PyObject *pArgs)
+{
+    int err;
+    char err_msg[PJ_ERR_MSG_SIZE];
+    pj_str_t ret;
+
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "i", &err)) {
+        return NULL;
+    }
+    
+    ret = pj_strerror(err, err_msg, sizeof(err_msg));
+    
+    return PyString_FromStringAndSize(err_msg, ret.slen);
+}
+
+
+/*
+ * py_pj_parse_simple_sip
+ */
+static PyObject *py_pj_parse_simple_sip(PyObject *pSelf, PyObject *pArgs)
+{
+    const char *arg_uri;
+    pj_pool_t *pool;
+    char tmp[PJSIP_MAX_URL_SIZE];
+    pjsip_uri *uri;
+    pjsip_sip_uri *sip_uri;
+    PyObject *ret, *item;
+
+    PJ_UNUSED_ARG(pSelf);
+
+    if (!PyArg_ParseTuple(pArgs, "s", &arg_uri)) {
+        return NULL;
+    }
+    
+    strncpy(tmp, arg_uri, sizeof(tmp));
+    tmp[sizeof(tmp)-1] = '\0';
+
+    pool = pjsua_pool_create("py_pj_parse_simple_sip", 512, 512);
+    uri = pjsip_parse_uri(pool, tmp, strlen(tmp), 0);
+    
+    if (uri == NULL || (!PJSIP_URI_SCHEME_IS_SIP(uri) &&
+			!PJSIP_URI_SCHEME_IS_SIPS(uri))) {
+	pj_pool_release(pool);
+	return Py_BuildValue("");
+    }
+    
+    ret = PyTuple_New(5);
+    sip_uri = (pjsip_sip_uri*) pjsip_uri_get_uri(uri);
+
+    /* Scheme */
+    item = PyString_FromPJ(pjsip_uri_get_scheme(uri));
+    PyTuple_SetItem(ret, 0, item);
+
+    /* Username */
+    item = PyString_FromPJ(&sip_uri->user);
+    PyTuple_SetItem(ret, 1, item);
+
+    /* Host */
+    item = PyString_FromPJ(&sip_uri->host);
+    PyTuple_SetItem(ret, 2, item);
+
+    /* Port */
+    if (sip_uri->port == 5060) {
+	sip_uri->port = 0;
+    }
+    item = Py_BuildValue("i", sip_uri->port);
+    PyTuple_SetItem(ret, 3, item);
+
+    /* Transport */
+    if (pj_stricmp2(&sip_uri->transport_param, "udp")) {
+	sip_uri->transport_param.ptr = "";
+	sip_uri->transport_param.slen = 0;
+    }
+    item = PyString_FromPJ(&sip_uri->transport_param);
+    PyTuple_SetItem(ret, 4, item);
+
+    pj_pool_release(pool);
+    return ret;
+}
+
+
+static char pjsua_call_get_max_count_doc[] =
+    "int _pjsua.call_get_max_count () "
+    "Get maximum number of calls configured in pjsua.";
+static char pjsua_call_get_count_doc[] =
+    "int _pjsua.call_get_count () "
+    "Get number of currently active calls.";
+static char pjsua_enum_calls_doc[] =
+    "int[] _pjsua.enum_calls () "
+    "Get maximum number of calls configured in pjsua.";
+static char pjsua_call_make_call_doc[] =
+    "int,int _pjsua.call_make_call (int acc_id, string dst_uri, int options,"
+    "int user_data, _pjsua.Msg_Data msg_data) "
+    "Make outgoing call to the specified URI using the specified account.";
+static char pjsua_call_is_active_doc[] =
+    "int _pjsua.call_is_active (int call_id) "
+    "Check if the specified call has active INVITE session and the INVITE "
+    "session has not been disconnected.";
+static char pjsua_call_has_media_doc[] =
+    "int _pjsua.call_has_media (int call_id) "
+    "Check if call has an active media session.";
+static char pjsua_call_get_conf_port_doc[] =
+    "int _pjsua.call_get_conf_port (int call_id) "
+    "Get the conference port identification associated with the call.";
+static char pjsua_call_get_info_doc[] =
+    "_pjsua.Call_Info _pjsua.call_get_info (int call_id) "
+    "Obtain detail information about the specified call.";
+static char pjsua_call_set_user_data_doc[] =
+    "int _pjsua.call_set_user_data (int call_id, int user_data) "
+    "Attach application specific data to the call.";
+static char pjsua_call_get_user_data_doc[] =
+    "int _pjsua.call_get_user_data (int call_id) "
+    "Get user data attached to the call.";
+static char pjsua_call_answer_doc[] =
+    "int _pjsua.call_answer (int call_id, int code, string reason, "
+    "_pjsua.Msg_Data msg_data) "
+    "Send response to incoming INVITE request.";
+static char pjsua_call_hangup_doc[] =
+    "int _pjsua.call_hangup (int call_id, int code, string reason, "
+    "_pjsua.Msg_Data msg_data) "
+    "Hangup call by using method that is appropriate according "
+    "to the call state.";
+static char pjsua_call_set_hold_doc[] =
+    "int _pjsua.call_set_hold (int call_id, _pjsua.Msg_Data msg_data) "
+    "Put the specified call on hold.";
+static char pjsua_call_reinvite_doc[] =
+    "int _pjsua.call_reinvite (int call_id, int unhold, "
+    "_pjsua.Msg_Data msg_data) "
+    "Send re-INVITE (to release hold).";
+static char pjsua_call_xfer_doc[] =
+    "int _pjsua.call_xfer (int call_id, string dest, "
+    "_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.";
+static char pjsua_call_xfer_replaces_doc[] =
+    "int _pjsua.call_xfer_replaces (int call_id, int dest_call_id, "
+    "int options, _pjsua.Msg_Data msg_data) "
+    "Initiate attended call transfer. This function will send REFER request "
+    "to instruct remote call party to initiate new INVITE session to the URL "
+    "of dest_call_id. The party at dest_call_id then should 'replace' the call"
+    "with us with the new call from the REFER recipient.";
+static char pjsua_call_dial_dtmf_doc[] =
+    "int _pjsua.call_dial_dtmf (int call_id, string digits) "
+    "Send DTMF digits to remote using RFC 2833 payload formats.";
+static char pjsua_call_send_im_doc[] =
+    "int _pjsua.call_send_im (int call_id, string mime_type, string content,"
+    "_pjsua.Msg_Data msg_data, int user_data) "
+    "Send instant messaging inside INVITE session.";
+static char pjsua_call_send_typing_ind_doc[] =
+    "int _pjsua.call_send_typing_ind (int call_id, int is_typing, "
+    "_pjsua.Msg_Data msg_data) "
+    "Send IM typing indication inside INVITE session.";
+static char pjsua_call_hangup_all_doc[] =
+    "void _pjsua.call_hangup_all () "
+    "Terminate all calls.";
+static char pjsua_call_dump_doc[] =
+    "int _pjsua.call_dump (int call_id, int with_media, int maxlen, "
+    "string indent) "
+    "Dump call and media statistics to string.";
+
+/* END OF LIB CALL */
+
+/*
+ * Map of function names to functions
+ */
+static PyMethodDef py_pjsua_methods[] =
+{
+    {
+        "thread_register", py_pjsua_thread_register, METH_VARARGS, 
+         pjsua_thread_register_doc
+    },
+    {
+    	"perror", py_pjsua_perror, METH_VARARGS, pjsua_perror_doc
+    },
+    {
+    	"create", py_pjsua_create, METH_VARARGS, pjsua_create_doc
+    },
+    {
+    	"init", py_pjsua_init, METH_VARARGS, pjsua_init_doc
+    },
+    {
+    	"start", py_pjsua_start, METH_VARARGS, pjsua_start_doc
+    },
+    {
+    	"destroy", py_pjsua_destroy, METH_VARARGS, pjsua_destroy_doc
+    },
+    {
+    	"handle_events", py_pjsua_handle_events, METH_VARARGS,
+    	pjsua_handle_events_doc
+    },
+    {
+    	"verify_sip_url", py_pjsua_verify_sip_url, METH_VARARGS,
+    	pjsua_verify_sip_url_doc
+    },
+    {
+    	"reconfigure_logging", py_pjsua_reconfigure_logging, METH_VARARGS,
+    	pjsua_reconfigure_logging_doc
+    },
+    {
+    	"logging_config_default", py_pjsua_logging_config_default,
+    	METH_VARARGS, pjsua_logging_config_default_doc
+    },
+    {
+    	"config_default", py_pjsua_config_default, METH_VARARGS,
+    	pjsua_config_default_doc
+    },
+    {
+    	"media_config_default", py_pjsua_media_config_default, METH_VARARGS,
+    	pjsua_media_config_default_doc
+    },
+    
+    
+    {
+    	"msg_data_init", py_pjsua_msg_data_init, METH_VARARGS,
+    	pjsua_msg_data_init_doc
+    },
+    {
+        "transport_config_default", py_pjsua_transport_config_default, 
+        METH_VARARGS,pjsua_transport_config_default_doc
+    },
+    {
+        "transport_create", py_pjsua_transport_create, METH_VARARGS,
+        pjsua_transport_create_doc
+    },
+    {
+        "transport_enum_transports", py_pjsua_enum_transports, METH_VARARGS,
+        pjsua_enum_transports_doc
+    },
+    {
+        "transport_get_info", py_pjsua_transport_get_info, METH_VARARGS,
+        pjsua_transport_get_info_doc
+    },
+    {
+        "transport_set_enable", py_pjsua_transport_set_enable, METH_VARARGS,
+        pjsua_transport_set_enable_doc
+    },
+    {
+       "transport_close", py_pjsua_transport_close, METH_VARARGS,
+        pjsua_transport_close_doc
+    },
+    {
+        "acc_config_default", py_pjsua_acc_config_default, METH_VARARGS,
+        pjsua_acc_config_default_doc
+    },
+    {
+        "acc_get_count", py_pjsua_acc_get_count, METH_VARARGS,
+        pjsua_acc_get_count_doc
+    },
+    {
+        "acc_is_valid", py_pjsua_acc_is_valid, METH_VARARGS,
+        pjsua_acc_is_valid_doc
+    },
+    {
+        "acc_set_default", py_pjsua_acc_set_default, METH_VARARGS,
+        pjsua_acc_set_default_doc
+    },
+    {
+        "acc_get_default", py_pjsua_acc_get_default, METH_VARARGS,
+        pjsua_acc_get_default_doc
+    },
+    {
+        "acc_add", py_pjsua_acc_add, METH_VARARGS,
+        pjsua_acc_add_doc
+    },
+    {
+        "acc_add_local", py_pjsua_acc_add_local, METH_VARARGS,
+        pjsua_acc_add_local_doc
+    },
+    {
+        "acc_del", py_pjsua_acc_del, METH_VARARGS,
+        pjsua_acc_del_doc
+    },
+    {
+        "acc_set_user_data", py_pjsua_acc_set_user_data, METH_VARARGS,
+        "Accociate user data with the account"
+    },
+    {
+        "acc_get_user_data", py_pjsua_acc_get_user_data, METH_VARARGS,
+        "Get account's user data"
+    },
+    {
+        "acc_modify", py_pjsua_acc_modify, METH_VARARGS,
+        pjsua_acc_modify_doc
+    },
+    {
+        "acc_set_online_status", py_pjsua_acc_set_online_status, METH_VARARGS,
+        pjsua_acc_set_online_status_doc
+    },
+    {
+        "acc_set_online_status2", py_pjsua_acc_set_online_status2, METH_VARARGS,
+        pjsua_acc_set_online_status2_doc
+    },
+    {
+        "acc_set_registration", py_pjsua_acc_set_registration, METH_VARARGS,
+        pjsua_acc_set_registration_doc
+    },
+    {
+        "acc_get_info", py_pjsua_acc_get_info, METH_VARARGS,
+        pjsua_acc_get_info_doc
+    },
+    {
+	"acc_pres_notify", py_pjsua_acc_pres_notify, METH_VARARGS,
+	"Accept or reject subscription request"
+    },
+    {
+        "enum_accs", py_pjsua_enum_accs, METH_VARARGS,
+        pjsua_enum_accs_doc
+    },
+    {
+        "acc_enum_info", py_pjsua_acc_enum_info, METH_VARARGS,
+        pjsua_acc_enum_info_doc
+    },
+    {
+        "acc_set_transport", py_pjsua_acc_set_transport, METH_VARARGS,
+        "Lock transport to use the specified transport"
+    },
+    {
+        "buddy_config_default", py_pjsua_buddy_config_default, METH_VARARGS,
+        pjsua_buddy_config_default_doc
+    },
+    {
+        "get_buddy_count", py_pjsua_get_buddy_count, METH_VARARGS,
+        pjsua_get_buddy_count_doc
+    },
+    {
+        "buddy_is_valid", py_pjsua_buddy_is_valid, METH_VARARGS,
+        pjsua_buddy_is_valid_doc
+    },
+    {
+        "enum_buddies", py_pjsua_enum_buddies, METH_VARARGS,
+        pjsua_enum_buddies_doc
+    },    
+    {
+        "buddy_find", py_pjsua_buddy_find, METH_VARARGS,
+        "Find buddy with the specified URI"
+    },    
+    {
+        "buddy_get_info", py_pjsua_buddy_get_info, METH_VARARGS,
+        pjsua_buddy_get_info_doc
+    },
+    {
+        "buddy_add", py_pjsua_buddy_add, METH_VARARGS,
+        pjsua_buddy_add_doc
+    },
+    {
+        "buddy_del", py_pjsua_buddy_del, METH_VARARGS,
+        pjsua_buddy_del_doc
+    },
+    {
+        "buddy_set_user_data", py_pjsua_buddy_set_user_data, METH_VARARGS,
+        "Associate user data to the buddy object"
+    },
+    {
+        "buddy_get_user_data", py_pjsua_buddy_get_user_data, METH_VARARGS,
+        "Get buddy user data"
+    },
+    {
+        "buddy_subscribe_pres", py_pjsua_buddy_subscribe_pres, METH_VARARGS,
+        pjsua_buddy_subscribe_pres_doc
+    },
+    {
+        "pres_dump", py_pjsua_pres_dump, METH_VARARGS,
+        pjsua_pres_dump_doc
+    },
+    {
+        "im_send", py_pjsua_im_send, METH_VARARGS,
+        pjsua_im_send_doc
+    },
+    {
+        "im_typing", py_pjsua_im_typing, METH_VARARGS,
+        pjsua_im_typing_doc
+    },
+        {
+        "conf_get_max_ports", py_pjsua_conf_get_max_ports, METH_VARARGS,
+        pjsua_conf_get_max_ports_doc
+    },
+    {
+        "conf_get_active_ports", py_pjsua_conf_get_active_ports, METH_VARARGS,
+        pjsua_conf_get_active_ports_doc
+    },
+    {
+        "enum_conf_ports", py_pjsua_enum_conf_ports, METH_VARARGS,
+        pjsua_enum_conf_ports_doc
+    },
+    {
+        "conf_get_port_info", py_pjsua_conf_get_port_info, METH_VARARGS,
+        pjsua_conf_get_port_info_doc
+    },
+    {
+        "conf_remove_port", py_pjsua_conf_remove_port, METH_VARARGS,
+        pjsua_conf_remove_port_doc
+    },
+    {
+        "conf_connect", py_pjsua_conf_connect, METH_VARARGS,
+        pjsua_conf_connect_doc
+    },
+    {
+        "conf_disconnect", py_pjsua_conf_disconnect, METH_VARARGS,
+        pjsua_conf_disconnect_doc
+    },
+    {
+	"conf_set_tx_level", py_pjsua_conf_set_tx_level, METH_VARARGS,
+	"Adjust the signal level to be transmitted from the bridge to the" 
+	" specified port by making it louder or quieter"
+    },
+    {
+	"conf_set_rx_level", py_pjsua_conf_set_rx_level, METH_VARARGS,
+	"Adjust the signal level to be received from the specified port (to"
+	" the bridge) by making it louder or quieter"
+    },
+    {
+	"conf_get_signal_level", py_pjsua_conf_get_signal_level, METH_VARARGS,
+	"Get last signal level transmitted to or received from the specified port"
+    },
+    {
+        "player_create", py_pjsua_player_create, METH_VARARGS,
+        pjsua_player_create_doc
+    },
+    {
+        "playlist_create", py_pjsua_playlist_create, METH_VARARGS,
+        "Create WAV playlist"
+    },
+    {
+        "player_get_conf_port", py_pjsua_player_get_conf_port, METH_VARARGS,
+        pjsua_player_get_conf_port_doc
+    },
+    {
+        "player_set_pos", py_pjsua_player_set_pos, METH_VARARGS,
+        pjsua_player_set_pos_doc
+    },
+    {
+        "player_destroy", py_pjsua_player_destroy, METH_VARARGS,
+        pjsua_player_destroy_doc
+    },
+    {
+        "recorder_create", py_pjsua_recorder_create, METH_VARARGS,
+        pjsua_recorder_create_doc
+    },
+    {
+        "recorder_get_conf_port", py_pjsua_recorder_get_conf_port, METH_VARARGS,
+        pjsua_recorder_get_conf_port_doc
+    },
+    {
+        "recorder_destroy", py_pjsua_recorder_destroy, METH_VARARGS,
+        pjsua_recorder_destroy_doc
+    },
+    {
+        "enum_snd_devs", py_pjsua_enum_snd_devs, METH_VARARGS,
+        pjsua_enum_snd_devs_doc
+    },
+    {
+        "get_snd_dev", py_pjsua_get_snd_dev, METH_VARARGS,
+        pjsua_get_snd_dev_doc
+    },
+    {
+        "set_snd_dev", py_pjsua_set_snd_dev, METH_VARARGS,
+        pjsua_set_snd_dev_doc
+    },
+    {
+        "set_null_snd_dev", py_pjsua_set_null_snd_dev, METH_VARARGS,
+        pjsua_set_null_snd_dev_doc
+    },
+    {
+        "set_ec", py_pjsua_set_ec, METH_VARARGS,
+        pjsua_set_ec_doc
+    },
+    {
+        "get_ec_tail", py_pjsua_get_ec_tail, METH_VARARGS,
+        pjsua_get_ec_tail_doc
+    },
+    {
+        "enum_codecs", py_pjsua_enum_codecs, METH_VARARGS,
+        pjsua_enum_codecs_doc
+    },
+    {
+        "codec_set_priority", py_pjsua_codec_set_priority, METH_VARARGS,
+        pjsua_codec_set_priority_doc
+    },
+    {
+        "codec_get_param", py_pjsua_codec_get_param, METH_VARARGS,
+        pjsua_codec_get_param_doc
+    },
+    {
+        "codec_set_param", py_pjsua_codec_set_param, METH_VARARGS,
+        pjsua_codec_set_param_doc
+    },
+    {
+        "call_get_max_count", py_pjsua_call_get_max_count, METH_VARARGS,
+        pjsua_call_get_max_count_doc
+    },
+    {
+        "call_get_count", py_pjsua_call_get_count, METH_VARARGS,
+        pjsua_call_get_count_doc
+    },
+    {
+        "enum_calls", py_pjsua_enum_calls, METH_VARARGS,
+        pjsua_enum_calls_doc
+    },
+    {
+        "call_make_call", py_pjsua_call_make_call, METH_VARARGS,
+        pjsua_call_make_call_doc
+    },
+    {
+        "call_is_active", py_pjsua_call_is_active, METH_VARARGS,
+        pjsua_call_is_active_doc
+    },
+    {
+        "call_has_media", py_pjsua_call_has_media, METH_VARARGS,
+        pjsua_call_has_media_doc
+    },
+    {
+        "call_get_conf_port", py_pjsua_call_get_conf_port, METH_VARARGS,
+        pjsua_call_get_conf_port_doc
+    },
+    {
+        "call_get_info", py_pjsua_call_get_info, METH_VARARGS,
+        pjsua_call_get_info_doc
+    },
+    {
+        "call_set_user_data", py_pjsua_call_set_user_data, METH_VARARGS,
+        pjsua_call_set_user_data_doc
+    },
+    {
+        "call_get_user_data", py_pjsua_call_get_user_data, METH_VARARGS,
+        pjsua_call_get_user_data_doc
+    },
+    {
+        "call_answer", py_pjsua_call_answer, METH_VARARGS,
+        pjsua_call_answer_doc
+    },
+    {
+        "call_hangup", py_pjsua_call_hangup, METH_VARARGS,
+        pjsua_call_hangup_doc
+    },
+    {
+        "call_set_hold", py_pjsua_call_set_hold, METH_VARARGS,
+        pjsua_call_set_hold_doc
+    },
+    {
+        "call_reinvite", py_pjsua_call_reinvite, METH_VARARGS,
+        pjsua_call_reinvite_doc
+    },
+    {
+        "call_update", py_pjsua_call_update, METH_VARARGS,
+        "Send UPDATE"
+    },
+    {
+        "call_xfer", py_pjsua_call_xfer, METH_VARARGS,
+        pjsua_call_xfer_doc
+    },
+    {
+        "call_xfer_replaces", py_pjsua_call_xfer_replaces, METH_VARARGS,
+        pjsua_call_xfer_replaces_doc
+    },
+    {
+        "call_dial_dtmf", py_pjsua_call_dial_dtmf, METH_VARARGS,
+        pjsua_call_dial_dtmf_doc
+    },
+    {
+        "call_send_im", py_pjsua_call_send_im, METH_VARARGS,
+        pjsua_call_send_im_doc
+    },
+    {
+        "call_send_typing_ind", py_pjsua_call_send_typing_ind, METH_VARARGS,
+        pjsua_call_send_typing_ind_doc
+    },
+    {
+        "call_hangup_all", py_pjsua_call_hangup_all, METH_VARARGS,
+        pjsua_call_hangup_all_doc
+    },
+    {
+        "call_dump", py_pjsua_call_dump, METH_VARARGS,
+        pjsua_call_dump_doc
+    },
+    {
+        "call_send_request", py_pjsua_call_send_request, METH_VARARGS,
+        "Send arbitrary request"
+    },
+    {
+	"dump", py_pjsua_dump, METH_VARARGS, "Dump application state"
+    },
+    {
+	"strerror", py_pj_strerror, METH_VARARGS, "Get error message"
+    },
+    {
+	"parse_simple_uri", py_pj_parse_simple_sip, METH_VARARGS, "Parse URI"
+    },
+
+    
+    {NULL, NULL} /* end of function list */
+};
+
+
+
+/*
+ * Mapping C structs from and to Python objects & initializing object
+ */
+DL_EXPORT(void)
+init_pjsua(void)
+{
+    PyObject* m = NULL;
+#define ADD_CONSTANT(mod,name)	PyModule_AddIntConstant(mod,#name,name)
+
+    
+    PyEval_InitThreads();
+
+    if (PyType_Ready(&PyTyp_pjsua_callback) < 0)
+        return;
+    if (PyType_Ready(&PyTyp_pjsua_config) < 0)
+        return;
+    if (PyType_Ready(&PyTyp_pjsua_logging_config) < 0)
+        return;
+    if (PyType_Ready(&PyTyp_pjsua_msg_data) < 0)
+        return;
+    PyTyp_pjsua_media_config.tp_new = PyType_GenericNew;
+    if (PyType_Ready(&PyTyp_pjsua_media_config) < 0)
+        return;
+    PyTyp_pjsip_cred_info.tp_new = PyType_GenericNew;
+    if (PyType_Ready(&PyTyp_pjsip_cred_info) < 0)
+        return;
+    PyTyp_pjsip_rx_data.tp_new = PyType_GenericNew;
+    if (PyType_Ready(&PyTyp_pjsip_rx_data) < 0)
+        return;
+
+    /* LIB TRANSPORT */
+
+    if (PyType_Ready(&PyTyp_pjsua_transport_config) < 0)
+        return;
+    
+    if (PyType_Ready(&PyTyp_pjsua_transport_info) < 0)
+        return;
+    
+    /* END OF LIB TRANSPORT */
+
+    /* LIB ACCOUNT */
+
+    
+    if (PyType_Ready(&PyTyp_pjsua_acc_config) < 0)
+        return;
+    if (PyType_Ready(&PyTyp_pjsua_acc_info) < 0)
+        return;
+
+    /* END OF LIB ACCOUNT */
+
+    /* LIB BUDDY */
+
+    if (PyType_Ready(&PyTyp_pjsua_buddy_config) < 0)
+        return;
+    if (PyType_Ready(&PyTyp_pjsua_buddy_info) < 0)
+        return;
+
+    /* END OF LIB BUDDY */
+
+    /* LIB MEDIA */
+  
+    if (PyType_Ready(&PyTyp_pjsua_codec_info) < 0)
+        return;
+
+    if (PyType_Ready(&PyTyp_pjsua_conf_port_info) < 0)
+        return;
+
+    if (PyType_Ready(&PyTyp_pjmedia_snd_dev_info) < 0)
+        return;
+
+    PyTyp_pjmedia_codec_param_info.tp_new = PyType_GenericNew;
+    if (PyType_Ready(&PyTyp_pjmedia_codec_param_info) < 0)
+        return;
+    PyTyp_pjmedia_codec_param_setting.tp_new = PyType_GenericNew;
+    if (PyType_Ready(&PyTyp_pjmedia_codec_param_setting) < 0)
+        return;
+
+    if (PyType_Ready(&PyTyp_pjmedia_codec_param) < 0)
+        return;
+
+    /* END OF LIB MEDIA */
+
+    /* LIB CALL */
+
+    if (PyType_Ready(&PyTyp_pjsua_call_info) < 0)
+        return;
+
+    /* END OF LIB CALL */
+
+    m = Py_InitModule3(
+        "_pjsua", py_pjsua_methods, "PJSUA-lib module for python"
+    );
+
+    Py_INCREF(&PyTyp_pjsua_callback);
+    PyModule_AddObject(m, "Callback", (PyObject *)&PyTyp_pjsua_callback);
+
+    Py_INCREF(&PyTyp_pjsua_config);
+    PyModule_AddObject(m, "Config", (PyObject *)&PyTyp_pjsua_config);
+
+    Py_INCREF(&PyTyp_pjsua_media_config);
+    PyModule_AddObject(m, "Media_Config", (PyObject *)&PyTyp_pjsua_media_config);
+
+    Py_INCREF(&PyTyp_pjsua_logging_config);
+    PyModule_AddObject(m, "Logging_Config", (PyObject *)&PyTyp_pjsua_logging_config);
+
+    Py_INCREF(&PyTyp_pjsua_msg_data);
+    PyModule_AddObject(m, "Msg_Data", (PyObject *)&PyTyp_pjsua_msg_data);
+
+    Py_INCREF(&PyTyp_pjsip_cred_info);
+    PyModule_AddObject(m, "Pjsip_Cred_Info",
+        (PyObject *)&PyTyp_pjsip_cred_info
+    );
+
+    Py_INCREF(&PyTyp_pjsip_rx_data);
+    PyModule_AddObject(m, "Pjsip_Rx_Data",
+        (PyObject *)&PyTyp_pjsip_rx_data
+    );
+
+    /* LIB TRANSPORT */
+
+    Py_INCREF(&PyTyp_pjsua_transport_config);
+    PyModule_AddObject
+        (m, "Transport_Config", (PyObject *)&PyTyp_pjsua_transport_config);
+    
+    Py_INCREF(&PyTyp_pjsua_transport_info);
+    PyModule_AddObject(m, "Transport_Info", (PyObject *)&PyTyp_pjsua_transport_info);
+    
+
+    /* END OF LIB TRANSPORT */
+
+    /* LIB ACCOUNT */
+
+    
+    Py_INCREF(&PyTyp_pjsua_acc_config);
+    PyModule_AddObject(m, "Acc_Config", (PyObject *)&PyTyp_pjsua_acc_config);
+    Py_INCREF(&PyTyp_pjsua_acc_info);
+    PyModule_AddObject(m, "Acc_Info", (PyObject *)&PyTyp_pjsua_acc_info);
+
+    /* END OF LIB ACCOUNT */
+
+    /* LIB BUDDY */
+    
+    Py_INCREF(&PyTyp_pjsua_buddy_config);
+    PyModule_AddObject(m, "Buddy_Config", (PyObject *)&PyTyp_pjsua_buddy_config);
+    Py_INCREF(&PyTyp_pjsua_buddy_info);
+    PyModule_AddObject(m, "Buddy_Info", (PyObject *)&PyTyp_pjsua_buddy_info);
+
+    /* END OF LIB BUDDY */
+
+    /* LIB MEDIA */
+
+    Py_INCREF(&PyTyp_pjsua_codec_info);
+    PyModule_AddObject(m, "Codec_Info", (PyObject *)&PyTyp_pjsua_codec_info);
+    Py_INCREF(&PyTyp_pjsua_conf_port_info);
+    PyModule_AddObject(m, "Conf_Port_Info", (PyObject *)&PyTyp_pjsua_conf_port_info);
+    Py_INCREF(&PyTyp_pjmedia_snd_dev_info);
+    PyModule_AddObject(m, "PJMedia_Snd_Dev_Info", 
+	(PyObject *)&PyTyp_pjmedia_snd_dev_info);
+    Py_INCREF(&PyTyp_pjmedia_codec_param_info);
+    PyModule_AddObject(m, "PJMedia_Codec_Param_Info", 
+	(PyObject *)&PyTyp_pjmedia_codec_param_info);
+    Py_INCREF(&PyTyp_pjmedia_codec_param_setting);
+    PyModule_AddObject(m, "PJMedia_Codec_Param_Setting", 
+	(PyObject *)&PyTyp_pjmedia_codec_param_setting);
+    Py_INCREF(&PyTyp_pjmedia_codec_param);
+    PyModule_AddObject(m, "PJMedia_Codec_Param", 
+	(PyObject *)&PyTyp_pjmedia_codec_param);
+
+    /* END OF LIB MEDIA */
+
+    /* LIB CALL */
+
+    Py_INCREF(&PyTyp_pjsua_call_info);
+    PyModule_AddObject(m, "Call_Info", (PyObject *)&PyTyp_pjsua_call_info);
+
+    /* END OF LIB CALL */
+
+
+    /*
+     * Add various constants.
+     */
+    /* Skip it.. */
+
+#undef ADD_CONSTANT
+}
diff --git a/jni/pjproject-android/.svn/pristine/1e/1e9691d4fa23439a7918e0d3bc72b1f899d5bbad.svn-base b/jni/pjproject-android/.svn/pristine/1e/1e9691d4fa23439a7918e0d3bc72b1f899d5bbad.svn-base
new file mode 100644
index 0000000..13c2449
--- /dev/null
+++ b/jni/pjproject-android/.svn/pristine/1e/1e9691d4fa23439a7918e0d3bc72b1f899d5bbad.svn-base
@@ -0,0 +1,26 @@
+# $Id$
+import inc_sip as sip
+import inc_sdp as sdp
+
+sdp = \
+"""
+v=0
+o=- 0 0 IN IP4 127.0.0.1
+s=pjmedia
+c=IN IP4 127.0.0.1
+t=0 0
+m=audio 4000 RTP/AVP 0 101
+a=rtpmap:0 PCMU/8000
+a=sendrecv
+a=rtpmap:101 telephone-event/8000
+a=fmtp:101 0-15
+"""
+
+pjsua_args = "--null-audio --auto-answer 200 --timer-min-se 90"
+extra_headers = "Supported: timer\nSession-Expires: 1800;refresher=uac\n"
+include = ["Session-Expires:.*;refresher=ua[cs]"]
+exclude = []
+sendto_cfg = sip.SendtoCfg("Session Timer offer refresher uac", pjsua_args, sdp, 200, 
+			   extra_headers=extra_headers,
+			   resp_inc=include, resp_exc=exclude) 
+			   
diff --git a/jni/pjproject-android/.svn/pristine/1e/1ebdd2a8dacfb4c95c22aed78a148a9c56671493.svn-base b/jni/pjproject-android/.svn/pristine/1e/1ebdd2a8dacfb4c95c22aed78a148a9c56671493.svn-base
new file mode 100644
index 0000000..608f9eb
--- /dev/null
+++ b/jni/pjproject-android/.svn/pristine/1e/1ebdd2a8dacfb4c95c22aed78a148a9c56671493.svn-base
@@ -0,0 +1,13 @@
+export OS_CFLAGS   := $(CC_DEF)PJ_SUNOS=1
+
+export OS_CXXFLAGS := 
+
+export OS_LDFLAGS  := $(CC_LIB)pthread$(LIBEXT2) \
+		      $(CC_LIB)socket$(LIBEXT2) \
+		      $(CC_LIB)rt$(LIBEXT2) \
+		      $(CC_LIB)nsl$(LIBEXT2) \
+		      $(CC_LIB)m$(LIBEXT2)
+
+export OS_SOURCES  := 
+
+
diff --git a/jni/pjproject-android/.svn/pristine/1e/1ec3e99fbb54372d7bbbd7e86c31943d88d2dc54.svn-base b/jni/pjproject-android/.svn/pristine/1e/1ec3e99fbb54372d7bbbd7e86c31943d88d2dc54.svn-base
new file mode 100644
index 0000000..276c032
--- /dev/null
+++ b/jni/pjproject-android/.svn/pristine/1e/1ec3e99fbb54372d7bbbd7e86c31943d88d2dc54.svn-base
@@ -0,0 +1,950 @@
+/* $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-codec/g7221.h>
+#include <pjmedia-codec/g7221_sdp_match.h>
+#include <pjmedia/codec.h>
+#include <pjmedia/errno.h>
+#include <pjmedia/endpoint.h>
+#include <pjmedia/port.h>
+#include <pjmedia/silencedet.h>
+#include <pj/assert.h>
+#include <pj/log.h>
+#include <pj/math.h>
+#include <pj/pool.h>
+#include <pj/string.h>
+#include <pj/os.h>
+
+/*
+ * Only build this file if PJMEDIA_HAS_G7221_CODEC != 0
+ */
+#if defined(PJMEDIA_HAS_G7221_CODEC) && PJMEDIA_HAS_G7221_CODEC!=0
+
+#include "../../../third_party/g7221/common/defs.h"
+
+#define THIS_FILE	    "g7221.c"
+
+/* Codec tag, it is the SDP encoding name and also MIME subtype name */
+#define CODEC_TAG	    "G7221"
+
+/* Sampling rates definition */
+#define WB_SAMPLE_RATE	    16000
+#define UWB_SAMPLE_RATE	    32000
+
+/* Maximum number of samples per frame. */
+#define MAX_SAMPLES_PER_FRAME (UWB_SAMPLE_RATE * 20 / 1000)
+
+/* Maximum number of codec params. */
+#define MAX_CODEC_MODES	    8
+#define START_RSV_MODES_IDX 6
+
+
+/* Prototypes for G722.1 codec factory */
+static pj_status_t test_alloc( pjmedia_codec_factory *factory, 
+			       const pjmedia_codec_info *id );
+static pj_status_t default_attr( pjmedia_codec_factory *factory, 
+				 const pjmedia_codec_info *id, 
+				 pjmedia_codec_param *attr );
+static pj_status_t enum_codecs( pjmedia_codec_factory *factory, 
+				unsigned *count, 
+				pjmedia_codec_info codecs[]);
+static pj_status_t alloc_codec( pjmedia_codec_factory *factory, 
+				const pjmedia_codec_info *id, 
+				pjmedia_codec **p_codec);
+static pj_status_t dealloc_codec( pjmedia_codec_factory *factory, 
+				  pjmedia_codec *codec );
+
+/* Prototypes for G722.1 codec implementation. */
+static pj_status_t codec_init( pjmedia_codec *codec, 
+			       pj_pool_t *pool );
+static pj_status_t codec_open( pjmedia_codec *codec, 
+			       pjmedia_codec_param *attr );
+static pj_status_t codec_close( pjmedia_codec *codec );
+static pj_status_t codec_modify(pjmedia_codec *codec, 
+			        const pjmedia_codec_param *attr );
+static pj_status_t codec_parse( pjmedia_codec *codec,
+			        void *pkt,
+				pj_size_t pkt_size,
+				const pj_timestamp *ts,
+				unsigned *frame_cnt,
+				pjmedia_frame frames[]);
+static pj_status_t codec_encode( pjmedia_codec *codec, 
+				 const struct pjmedia_frame *input,
+				 unsigned output_buf_len,
+				 struct pjmedia_frame *output);
+static pj_status_t codec_decode( pjmedia_codec *codec,
+				 const struct pjmedia_frame *input,
+				 unsigned output_buf_len, 
+				 struct pjmedia_frame *output);
+static pj_status_t codec_recover( pjmedia_codec *codec, 
+				  unsigned output_buf_len, 
+				  struct pjmedia_frame *output);
+
+/* Definition for G722.1 codec operations. */
+static pjmedia_codec_op codec_op = 
+{
+    &codec_init,
+    &codec_open,
+    &codec_close,
+    &codec_modify,
+    &codec_parse,
+    &codec_encode,
+    &codec_decode,
+    &codec_recover
+};
+
+/* Definition for G722.1 codec factory operations. */
+static pjmedia_codec_factory_op codec_factory_op =
+{
+    &test_alloc,
+    &default_attr,
+    &enum_codecs,
+    &alloc_codec,
+    &dealloc_codec,
+    &pjmedia_codec_g7221_deinit
+};
+
+
+/* Structure of G722.1 mode */
+typedef struct codec_mode
+{
+    pj_bool_t	     enabled;		/* Is this mode enabled?	    */
+    pj_uint8_t	     pt;		/* Payload type.		    */
+    unsigned	     sample_rate;	/* Default sampling rate to be used.*/
+    unsigned	     bitrate;		/* Bitrate.			    */
+    char	     bitrate_str[8];	/* Bitrate in string.		    */
+} codec_mode;
+
+
+/* G722.1 codec factory */
+static struct codec_factory {
+    pjmedia_codec_factory    base;	    /**< Base class.		    */
+    pjmedia_endpt	    *endpt;	    /**< PJMEDIA endpoint instance. */
+    pj_pool_t		    *pool;	    /**< Codec factory pool.	    */
+    pj_mutex_t		    *mutex;	    /**< Codec factory mutex.	    */
+
+    int			     pcm_shift;	    /**< Level adjustment	    */
+    unsigned		     mode_count;    /**< Number of G722.1 modes.    */
+    codec_mode		     modes[MAX_CODEC_MODES]; /**< The G722.1 modes. */
+    unsigned		     mode_rsv_start;/**< Start index of G722.1 non-
+						 standard modes, currently
+						 there can only be up to two 
+						 non-standard modes enabled
+						 at the same time.	    */
+} codec_factory;
+
+/* G722.1 codec private data. */
+typedef struct codec_private {
+    pj_pool_t		*pool;		    /**< Pool for each instance.    */
+    pj_bool_t		 plc_enabled;	    /**< PLC enabled?		    */
+    pj_bool_t		 vad_enabled;	    /**< VAD enabled?		    */
+    pjmedia_silence_det	*vad;		    /**< PJMEDIA VAD instance.	    */
+    pj_timestamp	 last_tx;	    /**< Timestamp of last transmit.*/
+
+    /* ITU ref implementation seems to leave the codec engine states to be
+     * managed by the application, so here we go.
+     */
+
+    /* Common engine state */
+    pj_uint16_t		 samples_per_frame; /**< Samples per frame.	    */
+    pj_uint16_t		 bitrate;	    /**< Coded stream bitrate.	    */
+    pj_uint16_t		 frame_size;	    /**< Coded frame size.	    */
+    pj_uint16_t		 frame_size_bits;   /**< Coded frame size in bits.  */
+    pj_uint16_t		 number_of_regions; /**< Number of regions.	    */
+    int			 pcm_shift;	    /**< Adjustment for PCM in/out  */
+    
+    /* Encoder specific state */
+    Word16		*enc_frame;	    /**< 16bit to 14bit buffer	    */
+    Word16		*enc_old_frame;
+    
+    /* Decoder specific state */
+    Word16		*dec_old_frame;
+    Rand_Obj		 dec_randobj;
+    Word16		 dec_old_mag_shift;
+    Word16		*dec_old_mlt_coefs;
+} codec_private_t;
+
+/* 
+ * Helper function for looking up mode based on payload type.
+ */
+static codec_mode* lookup_mode(unsigned pt)
+{
+    codec_mode* mode = NULL;
+    unsigned i;
+
+    for (i = 0; i < codec_factory.mode_count; ++i) {
+	mode = &codec_factory.modes[i];
+	if (mode->pt == pt)
+	    break;
+    }
+
+    return mode;
+}
+
+/* 
+ * Helper function to validate G722.1 mode. Valid modes are defined as:
+ * 1. sample rate must be 16kHz or 32kHz,
+ * 2. bitrate:
+ *    - for sampling rate 16kHz: 16000 to 32000 bps, it must be a multiple 
+ *      of 400 (to keep RTP payload octed-aligned)
+ *    - for sampling rate 32kHz: 24000 to 48000 bps, it must be a multiple 
+ *      of 400 (to keep RTP payload octed-aligned)
+ */
+static pj_bool_t validate_mode(unsigned sample_rate, unsigned bitrate)
+{
+    if (sample_rate == WB_SAMPLE_RATE) {
+	if (bitrate < 16000 || bitrate > 32000 ||
+	    ((bitrate-16000) % 400 != 0))
+	{
+	    return PJ_FALSE;
+	}
+    } else if (sample_rate == UWB_SAMPLE_RATE) {
+	if (bitrate < 24000 || bitrate > 48000 ||
+	    ((bitrate-24000) % 400 != 0))
+	{
+	    return PJ_FALSE;
+	}
+    } else {
+	return PJ_FALSE;
+    }
+
+    return PJ_TRUE;
+}
+
+#if defined(PJ_IS_LITTLE_ENDIAN) && PJ_IS_LITTLE_ENDIAN!=0
+PJ_INLINE(void) swap_bytes(pj_uint16_t *buf, unsigned count)
+{
+    pj_uint16_t *end = buf + count;
+    while (buf != end) {
+	*buf = (pj_uint16_t)((*buf << 8) | (*buf >> 8));
+	++buf;
+    }
+}
+#else
+#define swap_bytes(buf, count)
+#endif
+
+/*
+ * Initialize and register G722.1 codec factory to pjmedia endpoint.
+ */
+PJ_DEF(pj_status_t) pjmedia_codec_g7221_init( pjmedia_endpt *endpt )
+{
+    pjmedia_codec_mgr *codec_mgr;
+    codec_mode *mode;
+    pj_str_t codec_name;
+    pj_status_t status;
+
+    if (codec_factory.pool != NULL) {
+	/* Already initialized. */
+	return PJ_SUCCESS;
+    }
+
+    /* Initialize codec modes, by default all standard bitrates are enabled */
+    codec_factory.mode_count = 0;
+    codec_factory.pcm_shift = PJMEDIA_G7221_DEFAULT_PCM_SHIFT;
+
+    mode = &codec_factory.modes[codec_factory.mode_count++];
+    mode->enabled = PJ_TRUE;
+    mode->pt = PJMEDIA_RTP_PT_G722_1_24;
+    mode->sample_rate = WB_SAMPLE_RATE;
+    mode->bitrate = 24000;
+    pj_utoa(mode->bitrate, mode->bitrate_str);
+
+    mode = &codec_factory.modes[codec_factory.mode_count++];
+    mode->enabled = PJ_TRUE;
+    mode->pt = PJMEDIA_RTP_PT_G722_1_32;
+    mode->sample_rate = WB_SAMPLE_RATE;
+    mode->bitrate = 32000;
+    pj_utoa(mode->bitrate, mode->bitrate_str);
+
+    mode = &codec_factory.modes[codec_factory.mode_count++];
+    mode->enabled = PJ_TRUE;
+    mode->pt = PJMEDIA_RTP_PT_G7221C_24;
+    mode->sample_rate = UWB_SAMPLE_RATE;
+    mode->bitrate = 24000;
+    pj_utoa(mode->bitrate, mode->bitrate_str);
+
+    mode = &codec_factory.modes[codec_factory.mode_count++];
+    mode->enabled = PJ_TRUE;
+    mode->pt = PJMEDIA_RTP_PT_G7221C_32;
+    mode->sample_rate = UWB_SAMPLE_RATE;
+    mode->bitrate = 32000;
+    pj_utoa(mode->bitrate, mode->bitrate_str);
+
+    mode = &codec_factory.modes[codec_factory.mode_count++];
+    mode->enabled = PJ_TRUE;
+    mode->pt = PJMEDIA_RTP_PT_G7221C_48;
+    mode->sample_rate = UWB_SAMPLE_RATE;
+    mode->bitrate = 48000;
+    pj_utoa(mode->bitrate, mode->bitrate_str);
+
+    /* Non-standard bitrates */
+
+    /* Bitrate 16kbps is non-standard but rather commonly used. */
+    mode = &codec_factory.modes[codec_factory.mode_count++];
+    mode->enabled = PJ_FALSE;
+    mode->pt = PJMEDIA_RTP_PT_G722_1_16;
+    mode->sample_rate = WB_SAMPLE_RATE;
+    mode->bitrate = 16000;
+    pj_utoa(mode->bitrate, mode->bitrate_str);
+
+    /* Reserved two modes for non-standard bitrates */
+    codec_factory.mode_rsv_start = codec_factory.mode_count;
+    mode = &codec_factory.modes[codec_factory.mode_count++];
+    mode->enabled = PJ_FALSE;
+    mode->pt = PJMEDIA_RTP_PT_G7221_RSV1;
+
+    mode = &codec_factory.modes[codec_factory.mode_count++];
+    mode->enabled = PJ_FALSE;
+    mode->pt = PJMEDIA_RTP_PT_G7221_RSV2;
+
+    pj_assert(codec_factory.mode_count <= MAX_CODEC_MODES);
+
+    /* Create G722.1 codec factory. */
+    codec_factory.base.op = &codec_factory_op;
+    codec_factory.base.factory_data = NULL;
+    codec_factory.endpt = endpt;
+
+    codec_factory.pool = pjmedia_endpt_create_pool(endpt, "G722.1 codec",
+						   4000, 4000);
+    if (!codec_factory.pool)
+	return PJ_ENOMEM;
+
+    /* Create mutex. */
+    status = pj_mutex_create_simple(codec_factory.pool, "G722.1 codec",
+				    &codec_factory.mutex);
+    if (status != PJ_SUCCESS)
+	goto on_error;
+
+    /* Get the codec manager. */
+    codec_mgr = pjmedia_endpt_get_codec_mgr(endpt);
+    if (!codec_mgr) {
+	status = PJ_EINVALIDOP;
+	goto on_error;
+    }
+
+    /* Register format match callback. */
+    pj_cstr(&codec_name, CODEC_TAG);
+    status = pjmedia_sdp_neg_register_fmt_match_cb(
+					&codec_name,
+					&pjmedia_codec_g7221_match_sdp);
+    if (status != PJ_SUCCESS)
+	goto on_error;
+
+    /* Register codec factory to endpoint. */
+    status = pjmedia_codec_mgr_register_factory(codec_mgr, 
+						&codec_factory.base);
+    if (status != PJ_SUCCESS)
+	goto on_error;
+
+    /* Done. */
+    return PJ_SUCCESS;
+
+on_error:
+    if (codec_factory.mutex) {
+	pj_mutex_destroy(codec_factory.mutex);
+	codec_factory.mutex = NULL;
+    }
+
+    pj_pool_release(codec_factory.pool);
+    codec_factory.pool = NULL;
+    return status;
+}
+
+
+/**
+ * Enable and disable G722.1 modes, including non-standard modes.
+ */
+PJ_DEF(pj_status_t) pjmedia_codec_g7221_set_mode(unsigned sample_rate, 
+						 unsigned bitrate, 
+						 pj_bool_t enabled)
+{
+    unsigned i;
+
+    /* Validate mode */
+    if (!validate_mode(sample_rate, bitrate))
+	return PJMEDIA_CODEC_EINMODE;
+
+    /* Look up in factory modes table */
+    for (i = 0; i < codec_factory.mode_count; ++i) {
+	if (codec_factory.modes[i].sample_rate == sample_rate &&
+	    codec_factory.modes[i].bitrate == bitrate)
+	{
+	    codec_factory.modes[i].enabled = enabled;
+	    return PJ_SUCCESS;
+	}
+    }
+
+    /* Mode not found in modes table, this may be a request to enable
+     * a non-standard G722.1 mode.
+     */
+
+    /* Non-standard mode need to be initialized first before user 
+     * can disable it.
+     */
+    if (!enabled)
+	return PJ_ENOTFOUND;
+
+    /* Initialize a non-standard mode, look for available space. */
+    for (i = codec_factory.mode_rsv_start; 
+	 i < codec_factory.mode_count; ++i) 
+    {
+	if (!codec_factory.modes[i].enabled)
+	{
+	    codec_mode *mode = &codec_factory.modes[i];
+	    mode->enabled = PJ_TRUE;
+	    mode->sample_rate = sample_rate;
+	    mode->bitrate = bitrate;
+	    pj_utoa(mode->bitrate, mode->bitrate_str);
+
+	    return PJ_SUCCESS;
+	}
+    }
+    
+    /* No space for non-standard mode. */
+    return PJ_ETOOMANY;
+}
+
+
+/*
+ * Set level adjustment.
+ */
+PJ_DEF(pj_status_t)  pjmedia_codec_g7221_set_pcm_shift(int val)
+{
+    codec_factory.pcm_shift = val;
+    return PJ_SUCCESS;
+}
+
+/*
+ * Unregister G722.1 codec factory from pjmedia endpoint.
+ */
+PJ_DEF(pj_status_t) pjmedia_codec_g7221_deinit(void)
+{
+    pjmedia_codec_mgr *codec_mgr;
+    pj_status_t status;
+
+    if (codec_factory.pool == NULL) {
+	/* Already deinitialized */
+	return PJ_SUCCESS;
+    }
+
+    pj_mutex_lock(codec_factory.mutex);
+
+    /* Get the codec manager. */
+    codec_mgr = pjmedia_endpt_get_codec_mgr(codec_factory.endpt);
+    if (!codec_mgr) {
+	pj_pool_release(codec_factory.pool);
+	codec_factory.pool = NULL;
+	return PJ_EINVALIDOP;
+    }
+
+    /* Unregister G722.1 codec factory. */
+    status = pjmedia_codec_mgr_unregister_factory(codec_mgr,
+						  &codec_factory.base);
+    
+    /* Destroy mutex. */
+    pj_mutex_destroy(codec_factory.mutex);
+
+    /* Destroy pool. */
+    pj_pool_release(codec_factory.pool);
+    codec_factory.pool = NULL;
+
+    return status;
+}
+
+/* 
+ * Check if factory can allocate the specified codec. 
+ */
+static pj_status_t test_alloc( pjmedia_codec_factory *factory, 
+			       const pjmedia_codec_info *info )
+{
+    PJ_UNUSED_ARG(factory);
+
+    /* Type MUST be audio. */
+    if (info->type != PJMEDIA_TYPE_AUDIO)
+	return PJMEDIA_CODEC_EUNSUP;
+
+    /* Check encoding name. */
+    if (pj_stricmp2(&info->encoding_name, CODEC_TAG) != 0)
+	return PJMEDIA_CODEC_EUNSUP;
+
+    /* Check clock-rate */
+    if (info->clock_rate != WB_SAMPLE_RATE && 
+	info->clock_rate != UWB_SAMPLE_RATE)
+    {
+	return PJMEDIA_CODEC_EUNSUP;
+    }
+
+    return PJ_SUCCESS;
+}
+
+/*
+ * Generate default attribute.
+ */
+static pj_status_t default_attr ( pjmedia_codec_factory *factory, 
+				  const pjmedia_codec_info *id, 
+				  pjmedia_codec_param *attr )
+{
+    codec_mode *mode;
+
+    PJ_ASSERT_RETURN(factory==&codec_factory.base, PJ_EINVAL);
+
+    pj_bzero(attr, sizeof(pjmedia_codec_param));
+
+    mode = lookup_mode(id->pt);
+    if (mode == NULL || !mode->enabled)
+	return PJMEDIA_CODEC_EUNSUP;
+
+    attr->info.pt = (pj_uint8_t)id->pt;
+    attr->info.channel_cnt = 1;
+    attr->info.clock_rate = mode->sample_rate;
+    attr->info.max_bps = mode->bitrate;
+    attr->info.avg_bps = mode->bitrate;
+    attr->info.pcm_bits_per_sample = 16;
+    attr->info.frm_ptime = 20;
+
+    /* Default flags. */
+    attr->setting.plc = 1;
+    attr->setting.vad = 0;
+    attr->setting.frm_per_pkt = 1;
+
+    /* Default FMTP setting */
+    attr->setting.dec_fmtp.cnt = 1;
+    attr->setting.dec_fmtp.param[0].name = pj_str("bitrate");
+    attr->setting.dec_fmtp.param[0].val = pj_str(mode->bitrate_str);
+
+    return PJ_SUCCESS;
+}
+
+/*
+ * Enum codecs supported by this factory.
+ */
+static pj_status_t enum_codecs( pjmedia_codec_factory *factory, 
+				unsigned *count, 
+				pjmedia_codec_info codecs[])
+{
+    unsigned i, max_cnt;
+
+    PJ_ASSERT_RETURN(factory==&codec_factory.base, PJ_EINVAL);
+    PJ_ASSERT_RETURN(codecs && *count > 0, PJ_EINVAL);
+
+    max_cnt = *count;
+    *count = 0;
+    
+    for (i=0; (i < codec_factory.mode_count) && (*count < max_cnt); ++i)
+    {
+	if (!codec_factory.modes[i].enabled)
+	    continue;
+
+	pj_bzero(&codecs[*count], sizeof(pjmedia_codec_info));
+	codecs[*count].encoding_name = pj_str((char*)CODEC_TAG);
+	codecs[*count].pt = codec_factory.modes[i].pt;
+	codecs[*count].type = PJMEDIA_TYPE_AUDIO;
+	codecs[*count].clock_rate = codec_factory.modes[i].sample_rate;
+	codecs[*count].channel_cnt = 1;
+
+	++ *count;
+    }
+
+    return PJ_SUCCESS;
+}
+
+/*
+ * Allocate a new codec instance.
+ */
+static pj_status_t alloc_codec( pjmedia_codec_factory *factory, 
+				const pjmedia_codec_info *id,
+				pjmedia_codec **p_codec)
+{
+    codec_private_t *codec_data;
+    pjmedia_codec *codec;
+    pj_pool_t *pool;
+    pj_status_t status;
+
+    PJ_ASSERT_RETURN(factory && id && p_codec, PJ_EINVAL);
+    PJ_ASSERT_RETURN(factory == &codec_factory.base, PJ_EINVAL);
+
+    pj_mutex_lock(codec_factory.mutex);
+
+    /* Create pool for codec instance */
+    pool = pjmedia_endpt_create_pool(codec_factory.endpt, "G7221", 512, 512);
+    codec = PJ_POOL_ZALLOC_T(pool, pjmedia_codec);
+    codec->op = &codec_op;
+    codec->factory = factory;
+    codec->codec_data = PJ_POOL_ZALLOC_T(pool, codec_private_t);
+    codec_data = (codec_private_t*) codec->codec_data;
+    codec_data->pool = pool;
+
+    /* Create silence detector */
+    status = pjmedia_silence_det_create(pool, id->clock_rate, 
+					id->clock_rate * 20 / 1000,
+					&codec_data->vad);
+    if (status != PJ_SUCCESS) {
+	pj_mutex_unlock(codec_factory.mutex);
+	return status;
+    }
+
+    pj_mutex_unlock(codec_factory.mutex);
+
+    *p_codec = codec;
+    return PJ_SUCCESS;
+}
+
+/*
+ * Free codec.
+ */
+static pj_status_t dealloc_codec( pjmedia_codec_factory *factory, 
+				  pjmedia_codec *codec )
+{
+    codec_private_t *codec_data;
+    pj_pool_t *pool;
+
+    PJ_ASSERT_RETURN(factory && codec, PJ_EINVAL);
+    PJ_ASSERT_RETURN(factory == &codec_factory.base, PJ_EINVAL);
+
+    /* Close codec, if it's not closed. */
+    codec_data = (codec_private_t*) codec->codec_data;
+    pool = codec_data->pool;
+    codec_close(codec);
+
+    /* Release codec pool */
+    pj_pool_release(pool);
+
+    return PJ_SUCCESS;
+}
+
+/*
+ * Init codec.
+ */
+static pj_status_t codec_init( pjmedia_codec *codec, 
+			       pj_pool_t *pool )
+{
+    PJ_UNUSED_ARG(codec);
+    PJ_UNUSED_ARG(pool);
+    return PJ_SUCCESS;
+}
+
+/*
+ * Open codec.
+ */
+static pj_status_t codec_open( pjmedia_codec *codec, 
+			       pjmedia_codec_param *attr )
+{
+    codec_private_t *codec_data = (codec_private_t*) codec->codec_data;
+    pj_pool_t *pool;
+    unsigned tmp;
+
+    /* Validation mode first! */
+    if (!validate_mode(attr->info.clock_rate, attr->info.avg_bps))
+	return PJMEDIA_CODEC_EINMODE;
+
+    pool = codec_data->pool;
+
+    /* Initialize common state */
+    codec_data->vad_enabled = (attr->setting.vad != 0);
+    codec_data->plc_enabled = (attr->setting.plc != 0);
+
+    codec_data->bitrate = (pj_uint16_t)attr->info.avg_bps;
+    codec_data->frame_size_bits = (pj_uint16_t)(attr->info.avg_bps*20/1000);
+    codec_data->frame_size = (pj_uint16_t)(codec_data->frame_size_bits>>3);
+    codec_data->samples_per_frame = (pj_uint16_t)
+				    (attr->info.clock_rate*20/1000);
+    codec_data->number_of_regions = (pj_uint16_t)
+				    (attr->info.clock_rate <= WB_SAMPLE_RATE?
+				     NUMBER_OF_REGIONS:MAX_NUMBER_OF_REGIONS);
+    codec_data->pcm_shift = codec_factory.pcm_shift;
+
+    /* Initialize encoder state */
+    tmp = codec_data->samples_per_frame << 1;
+    codec_data->enc_old_frame = (Word16*)pj_pool_zalloc(pool, tmp);
+    codec_data->enc_frame = (Word16*)pj_pool_alloc(pool, tmp);
+
+    /* Initialize decoder state */
+    tmp = codec_data->samples_per_frame;
+    codec_data->dec_old_frame = (Word16*)pj_pool_zalloc(pool, tmp);
+
+    tmp = codec_data->samples_per_frame << 1;
+    codec_data->dec_old_mlt_coefs = (Word16*)pj_pool_zalloc(pool, tmp);
+
+    codec_data->dec_randobj.seed0 = 1;
+    codec_data->dec_randobj.seed1 = 1;
+    codec_data->dec_randobj.seed2 = 1;
+    codec_data->dec_randobj.seed3 = 1;
+
+    return PJ_SUCCESS;
+}
+
+/*
+ * Close codec.
+ */
+static pj_status_t codec_close( pjmedia_codec *codec )
+{
+    PJ_UNUSED_ARG(codec);
+
+    return PJ_SUCCESS;
+}
+
+
+/*
+ * Modify codec settings.
+ */
+static pj_status_t codec_modify( pjmedia_codec *codec, 
+				 const pjmedia_codec_param *attr )
+{
+    codec_private_t *codec_data = (codec_private_t*) codec->codec_data;
+
+    codec_data->vad_enabled = (attr->setting.vad != 0);
+    codec_data->plc_enabled = (attr->setting.plc != 0);
+
+    return PJ_SUCCESS;
+}
+
+/*
+ * Get frames in the packet.
+ */
+static pj_status_t codec_parse( pjmedia_codec *codec,
+				void *pkt,
+				pj_size_t pkt_size,
+				const pj_timestamp *ts,
+				unsigned *frame_cnt,
+				pjmedia_frame frames[])
+{
+    codec_private_t *codec_data = (codec_private_t*) codec->codec_data;
+    unsigned count = 0;
+
+    PJ_ASSERT_RETURN(frame_cnt, PJ_EINVAL);
+
+    /* Parse based on fixed frame size. */
+    while (pkt_size >= codec_data->frame_size && count < *frame_cnt) {
+	frames[count].type = PJMEDIA_FRAME_TYPE_AUDIO;
+	frames[count].buf = pkt;
+	frames[count].size = codec_data->frame_size;
+	frames[count].timestamp.u64 = ts->u64 + 
+				      count * codec_data->samples_per_frame;
+
+	pkt = (pj_uint8_t*)pkt + codec_data->frame_size;
+	pkt_size -= codec_data->frame_size;
+
+	++count;
+    }
+
+    pj_assert(pkt_size == 0);
+    *frame_cnt = count;
+
+    return PJ_SUCCESS;
+}
+
+/*
+ * Encode frames.
+ */
+static pj_status_t codec_encode( pjmedia_codec *codec, 
+				 const struct pjmedia_frame *input,
+				 unsigned output_buf_len, 
+				 struct pjmedia_frame *output)
+{
+    codec_private_t *codec_data = (codec_private_t*) codec->codec_data;
+    unsigned nsamples, processed;
+
+    /* Check frame in & out size */
+    nsamples = input->size >> 1;
+    PJ_ASSERT_RETURN(nsamples % codec_data->samples_per_frame == 0, 
+		     PJMEDIA_CODEC_EPCMFRMINLEN);
+    PJ_ASSERT_RETURN(output_buf_len >= codec_data->frame_size * nsamples /
+		     codec_data->samples_per_frame,
+		     PJMEDIA_CODEC_EFRMTOOSHORT);
+
+    /* Apply silence detection if VAD is enabled */
+    if (codec_data->vad_enabled) {
+	pj_bool_t is_silence;
+	pj_int32_t silence_duration;
+
+	pj_assert(codec_data->vad);
+
+	silence_duration = pj_timestamp_diff32(&codec_data->last_tx, 
+					       &input->timestamp);
+
+	is_silence = pjmedia_silence_det_detect(codec_data->vad, 
+					        (const pj_int16_t*) input->buf,
+						(input->size >> 1),
+						NULL);
+	if (is_silence &&
+	    (PJMEDIA_CODEC_MAX_SILENCE_PERIOD == -1 ||
+	     silence_duration < (PJMEDIA_CODEC_MAX_SILENCE_PERIOD *
+			         (int)codec_data->samples_per_frame / 20)))
+	{
+	    output->type = PJMEDIA_FRAME_TYPE_NONE;
+	    output->buf = NULL;
+	    output->size = 0;
+	    output->timestamp = input->timestamp;
+	    return PJ_SUCCESS;
+	} else {
+	    codec_data->last_tx = input->timestamp;
+	}
+    }
+
+    processed = 0;
+    output->size = 0;
+    while (processed < nsamples) {
+	Word16 mlt_coefs[MAX_SAMPLES_PER_FRAME];
+	Word16 mag_shift;
+	const Word16 *pcm_input;
+	pj_int8_t *out_bits;
+	
+	pcm_input = (const Word16*)input->buf + processed;
+	out_bits = (pj_int8_t*)output->buf + output->size;
+
+	/* Encoder adjust the input signal level */
+	if (codec_data->pcm_shift) {
+	    unsigned i;
+	    for (i=0; i<codec_data->samples_per_frame; ++i) {
+		codec_data->enc_frame[i] = 
+			(Word16)(pcm_input[i] >> codec_data->pcm_shift);
+	    }
+	    pcm_input = codec_data->enc_frame;
+	}
+
+	/* Convert input samples to rmlt coefs */
+	mag_shift = samples_to_rmlt_coefs(pcm_input,
+					  codec_data->enc_old_frame, 
+					  mlt_coefs, 
+					  codec_data->samples_per_frame);
+
+	/* Encode the mlt coefs. Note that encoder output stream is
+	 * 16 bit array, so we need to take care about endianness.
+	 */
+	encoder(codec_data->frame_size_bits,
+		codec_data->number_of_regions,
+		mlt_coefs,
+		mag_shift,
+		(Word16*)out_bits);
+
+	/* Encoder output are in native host byte order, while ITU says
+	 * it must be in network byte order (MSB first).
+	 */
+	swap_bytes((pj_uint16_t*)out_bits, codec_data->frame_size/2);
+
+	processed += codec_data->samples_per_frame;
+	output->size += codec_data->frame_size;
+    }
+
+    output->type = PJMEDIA_FRAME_TYPE_AUDIO;
+    output->timestamp = input->timestamp;
+
+    return PJ_SUCCESS;
+}
+
+/*
+ * Decode frame.
+ */
+static pj_status_t codec_decode( pjmedia_codec *codec, 
+				 const struct pjmedia_frame *input,
+				 unsigned output_buf_len, 
+				 struct pjmedia_frame *output)
+{
+    codec_private_t *codec_data = (codec_private_t*) codec->codec_data;
+    Word16 mlt_coefs[MAX_SAMPLES_PER_FRAME];
+    Word16 mag_shift;
+    Bit_Obj bitobj;
+    Word16 frame_error_flag = 0;
+
+    /* Check frame out length size */
+    PJ_ASSERT_RETURN(output_buf_len >= 
+		    (unsigned)(codec_data->samples_per_frame<<1),
+		     PJMEDIA_CODEC_EPCMTOOSHORT);
+
+    /* If input is NULL, perform PLC by settting frame_error_flag to 1 */
+    if (input) {
+	/* Check frame in length size */
+	PJ_ASSERT_RETURN((pj_uint16_t)input->size == codec_data->frame_size,
+			 PJMEDIA_CODEC_EFRMINLEN);
+
+	/* Decoder requires input of 16-bits array in native host byte
+	 * order, while the frame received from the network are in
+	 * network byte order (MSB first).
+	 */
+	swap_bytes((pj_uint16_t*)input->buf, codec_data->frame_size/2);
+
+	bitobj.code_word_ptr = (Word16*)input->buf;
+	bitobj.current_word =  *bitobj.code_word_ptr;
+	bitobj.code_bit_count = 0;
+	bitobj.number_of_bits_left = codec_data->frame_size_bits;
+
+	output->timestamp = input->timestamp;
+    } else {
+	pj_bzero(&bitobj, sizeof(bitobj));
+	frame_error_flag = 1;
+    }
+
+    /* Process the input frame to get mlt coefs */
+    decoder(&bitobj,
+	    &codec_data->dec_randobj,
+            codec_data->number_of_regions,
+	    mlt_coefs,
+            &mag_shift,
+	    &codec_data->dec_old_mag_shift,
+            codec_data->dec_old_mlt_coefs,
+            frame_error_flag);
+
+    /* Convert the mlt_coefs to PCM samples */
+    rmlt_coefs_to_samples(mlt_coefs, 
+			  codec_data->dec_old_frame, 
+			  (Word16*)output->buf, 
+			  codec_data->samples_per_frame, 
+			  mag_shift);
+
+    /* Decoder adjust PCM signal */
+    if (codec_data->pcm_shift) {
+	unsigned i;
+	pj_int16_t *buf = (Word16*)output->buf;
+
+	for (i=0; i<codec_data->samples_per_frame; ++i) {
+	    buf[i] <<= codec_data->pcm_shift;
+	}
+    }
+
+    output->type = PJMEDIA_FRAME_TYPE_AUDIO;
+    output->size = codec_data->samples_per_frame << 1;
+
+    return PJ_SUCCESS;
+}
+
+/* 
+ * Recover lost frame.
+ */
+static pj_status_t codec_recover( pjmedia_codec *codec, 
+				  unsigned output_buf_len, 
+				  struct pjmedia_frame *output)
+{
+    codec_private_t *codec_data = (codec_private_t*) codec->codec_data;
+
+    /* Use native PLC when PLC is enabled. */
+    if (codec_data->plc_enabled)
+	return codec_decode(codec, NULL, output_buf_len, output);
+
+    /* Otherwise just return zero-fill frame. */
+    output->type = PJMEDIA_FRAME_TYPE_AUDIO;
+    output->size = codec_data->samples_per_frame << 1;
+
+    pjmedia_zero_samples((pj_int16_t*)output->buf, 
+			 codec_data->samples_per_frame);
+
+    return PJ_SUCCESS;
+}
+
+#endif	/* PJMEDIA_HAS_G7221_CODEC */
diff --git a/jni/pjproject-android/.svn/pristine/1e/1ed8b7e8df781243bfc98932798bc922c9a6963d.svn-base b/jni/pjproject-android/.svn/pristine/1e/1ed8b7e8df781243bfc98932798bc922c9a6963d.svn-base
new file mode 100644
index 0000000..72310ae
--- /dev/null
+++ b/jni/pjproject-android/.svn/pristine/1e/1ed8b7e8df781243bfc98932798bc922c9a6963d.svn-base
@@ -0,0 +1,133 @@
+include build.mak
+include build/host-$(HOST_NAME).mak
+-include user.mak
+include version.mak
+
+LIB_DIRS = pjlib/build pjlib-util/build pjnath/build third_party/build pjmedia/build pjsip/build
+DIRS = $(LIB_DIRS) pjsip-apps/build $(EXTRA_DIRS)
+
+ifdef MINSIZE
+MAKE_FLAGS := MINSIZE=1
+endif
+
+all clean dep depend distclean print realclean:
+	for dir in $(DIRS); do \
+		if $(MAKE) $(MAKE_FLAGS) -C $$dir $@; then \
+		    true; \
+		else \
+		    exit 1; \
+		fi; \
+	done
+
+lib:
+	for dir in $(LIB_DIRS); do \
+		if $(MAKE) $(MAKE_FLAGS) -C $$dir all; then \
+		    true; \
+		else \
+		    exit 1; \
+		fi; \
+	done; \
+
+
+.PHONY: lib 
+
+doc:
+	@if test \( ! "$(WWWDIR)" == "" \) -a \( ! -d $(WWWDIR)/pjlib/docs/html \) ; then \
+		echo 'Directory "$(WWWDIR)" does not look like a valid pjsip web directory'; \
+		exit 1; \
+	fi
+	for dir in $(DIRS); do \
+		if $(MAKE) $(MAKE_FLAGS) -C $$dir $@; then \
+		    true; \
+		else \
+		    exit 1; \
+		fi; \
+	done
+	
+LIBS = 	pjlib/lib/libpj-$(TARGET_NAME).a \
+	pjlib-util/lib/libpjlib-util-$(TARGET_NAME).a \
+	pjnath/lib/libpjnath-$(TARGET_NAME).a \
+	pjmedia/lib/libpjmedia-$(TARGET_NAME).a \
+	pjmedia/lib/libpjmedia-audiodev-$(TARGET_NAME).a \
+	pjmedia/lib/libpjmedia-codec-$(TARGET_NAME).a \
+    	pjsip/lib/libpjsip-$(TARGET_NAME).a \
+	pjsip/lib/libpjsip-ua-$(TARGET_NAME).a \
+	pjsip/lib/libpjsip-simple-$(TARGET_NAME).a \
+	pjsip/lib/libpjsua-$(TARGET_NAME).a
+BINS = 	pjsip-apps/bin/pjsua-$(TARGET_NAME)$(HOST_EXE) 
+
+size:
+	@echo -n 'Date: '
+	@date
+	@echo
+	@for lib in $(LIBS); do \
+		echo "$$lib:"; \
+		size -t $$lib | awk '{print $$1 "\t" $$2 "\t" $$3 "\t" $$6}'; \
+		echo; \
+	done
+	@echo
+	@for bin in $(BINS); do \
+		echo "size $$bin:"; \
+		size $$bin; \
+	done
+
+#dos2unix:
+#	for f in `find . | egrep '(mak|h|c|S|s|Makefile)$$'`; do \
+#		dos2unix "$$f" > dos2unix.tmp; \
+#		cp dos2unix.tmp "$$f"; \
+#	done
+#	rm -f dos2unix.tmp
+
+xhdrid:
+	for f in `find . | egrep '\.(h|c|S|s|cpp|hpp)$$'`; do \
+		echo Processing $$f...; \
+		cat $$f | sed 's/.*\$$Author\$$/ */' > /tmp/id; \
+		cp /tmp/id $$f; \
+	done
+
+selftest: pjlib-test pjlib-util-test pjnath-test pjmedia-test pjsip-test pjsua-test
+
+pjlib-test: pjlib/bin/pjlib-test-$(TARGET_NAME)
+	cd pjlib/build && ../bin/pjlib-test-$(TARGET_NAME)
+
+pjlib-util-test: pjlib-util/bin/pjlib-util-test-$(TARGET_NAME)
+	cd pjlib-util/build && ../bin/pjlib-util-test-$(TARGET_NAME)
+
+pjnath-test: pjnath/bin/pjnath-test-$(TARGET_NAME)
+	cd pjnath/build && ../bin/pjnath-test-$(TARGET_NAME)
+
+pjmedia-test: pjmedia/bin/pjmedia-test-$(TARGET_NAME)
+	cd pjmedia/build && ../bin/pjmedia-test-$(TARGET_NAME)
+
+pjsip-test: pjsip/bin/pjsip-test-$(TARGET_NAME)
+	cd pjsip/build && ../bin/pjsip-test-$(TARGET_NAME)
+
+pjsua-test:
+	cd tests/pjsua && python runall.py
+
+install:
+	mkdir -p $(DESTDIR)$(libdir)/
+	cp -af $(APP_LIB_FILES) $(DESTDIR)$(libdir)/
+	mkdir -p $(DESTDIR)$(includedir)/
+	for d in pjlib pjlib-util pjnath pjmedia pjsip; do \
+		cp -RLf $$d/include/* $(DESTDIR)$(includedir)/; \
+	done
+	mkdir -p $(DESTDIR)$(libdir)/pkgconfig
+	sed -e "s!@PREFIX@!$(prefix)!" libpjproject.pc.in | \
+		sed -e "s!@INCLUDEDIR@!$(includedir)!" | \
+		sed -e "s!@LIBDIR@!$(libdir)!" | \
+		sed -e "s/@PJ_VERSION@/$(PJ_VERSION)/" | \
+		sed -e "s!@PJ_LDLIBS@!$(PJ_LDLIBS)!" | \
+		sed -e "s!@PJ_INSTALL_CFLAGS@!$(PJ_INSTALL_CFLAGS)!" > $(DESTDIR)/$(libdir)/pkgconfig/libpjproject.pc
+
+uninstall:
+	$(RM) $(DESTDIR)$(libdir)/pkgconfig/libpjproject.pc
+	-rmdir $(DESTDIR)$(libdir)/pkgconfig 2> /dev/null
+	for d in pjlib pjlib-util pjnath pjmedia pjsip; do \
+		for f in $$d/include/*; do \
+			$(RM) -r "$(DESTDIR)$(includedir)/`basename $$f`"; \
+		done; \
+	done
+	-rmdir $(DESTDIR)$(includedir) 2> /dev/null
+	$(RM) $(addprefix $(DESTDIR)$(libdir)/,$(notdir $(APP_LIB_FILES)))
+	-rmdir $(DESTDIR)$(libdir) 2> /dev/null