3 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #define THIS_FILE "main.c"
24 #define SND_DEV_NUM 64
25 #define SND_NAME_LEN 64
29 static PyObject* g_obj_log_cb;
30 static long g_thread_id;
31 static struct py_thread_desc
33 struct py_thread_desc *next;
38 * The global callback object.
40 static PyObj_pjsua_callback * g_obj_callback;
42 /* Set this to 1 if all threads are created by Python */
43 #define NO_PJSIP_THREAD 1
46 # define ENTER_PYTHON()
47 # define LEAVE_PYTHON()
49 # define ENTER_PYTHON() PyGILState_STATE state = PyGILState_Ensure()
50 # define LEAVE_PYTHON() PyGILState_Release(state)
54 static void clear_py_thread_desc(void)
56 while (py_thread_desc) {
57 struct py_thread_desc *next = py_thread_desc->next;
59 py_thread_desc = next;
66 * declares method for reconfiguring logging process for callback struct
68 static void cb_log_cb(int level, const char *data, int len)
71 /* Ignore if this callback is called from alien thread context,
72 * or otherwise it will crash Python.
74 if (pj_thread_local_get(g_thread_id) == 0)
77 if (PyCallable_Check(g_obj_log_cb)) {
82 param_data = PyString_FromStringAndSize(data, len);
84 PyObject_CallFunction(
93 Py_DECREF(param_data);
101 * declares method on_call_state for callback struct
103 static void cb_on_call_state(pjsua_call_id call_id, pjsip_event *e)
107 if (PyCallable_Check(g_obj_callback->on_call_state)) {
112 obj = Py_BuildValue("");
114 PyObject_CallFunction(
115 g_obj_callback->on_call_state,
130 * cb_on_incoming_call
131 * declares method on_incoming_call for callback struct
133 static void cb_on_incoming_call(pjsua_acc_id acc_id, pjsua_call_id call_id,
134 pjsip_rx_data *rdata)
136 PJ_UNUSED_ARG(rdata);
138 if (PyCallable_Check(g_obj_callback->on_incoming_call)) {
143 obj = Py_BuildValue("");
145 PyObject_CallFunction(
146 g_obj_callback->on_incoming_call,
162 * cb_on_call_media_state
163 * declares method on_call_media_state for callback struct
165 static void cb_on_call_media_state(pjsua_call_id call_id)
167 if (PyCallable_Check(g_obj_callback->on_call_media_state)) {
171 PyObject_CallFunction(
172 g_obj_callback->on_call_media_state,
185 * Callback from PJSUA-LIB on receiving DTMF digit
187 static void cb_on_dtmf_digit(pjsua_call_id call_id, int digit)
189 if (PyCallable_Check(g_obj_callback->on_dtmf_digit)) {
192 PyGILState_STATE state = PyGILState_Ensure();
194 pj_ansi_snprintf(digit_str, sizeof(digit_str), "%c", digit);
196 PyObject_CallFunction(
197 g_obj_callback->on_dtmf_digit,
204 PyGILState_Release(state);
210 * Notify application on call being transfered.
213 static void cb_on_call_transfer_request(pjsua_call_id call_id,
215 pjsip_status_code *code)
217 if (PyCallable_Check(g_obj_callback->on_call_transfer_request)) {
218 PyObject *ret, *param_dst;
223 param_dst = PyString_FromPJ(dst);
225 ret = PyObject_CallFunction(
226 g_obj_callback->on_call_transfer_request,
234 Py_DECREF(param_dst);
237 if (ret != Py_None) {
238 if (PyArg_Parse(ret,"i",&cd)) {
251 * Notify application of the status of previously sent call
252 * transfer request. Application can monitor the status of the
253 * call transfer request, for example to decide whether to
254 * terminate existing call.
257 static void cb_on_call_transfer_status( pjsua_call_id call_id,
259 const pj_str_t *status_text,
263 if (PyCallable_Check(g_obj_callback->on_call_transfer_status)) {
264 PyObject *ret, *param_reason;
268 param_reason = PyString_FromPJ(status_text);
270 ret = PyObject_CallFunction(
271 g_obj_callback->on_call_transfer_status,
281 Py_DECREF(param_reason);
284 if (ret != Py_None) {
286 if (PyArg_Parse(ret,"i",&cnt)) {
299 * Notify application about incoming INVITE with Replaces header.
300 * Application may reject the request by setting non-2xx code.
303 static void cb_on_call_replace_request( pjsua_call_id call_id,
304 pjsip_rx_data *rdata,
308 PJ_UNUSED_ARG(rdata);
310 if (PyCallable_Check(g_obj_callback->on_call_replace_request)) {
311 PyObject *ret, *param_reason, *param_rdata;
316 param_reason = PyString_FromPJ(st_text);
317 param_rdata = Py_BuildValue("");
319 ret = PyObject_CallFunction(
320 g_obj_callback->on_call_replace_request,
329 Py_DECREF(param_rdata);
330 Py_DECREF(param_reason);
333 if (ret != Py_None) {
335 if (PyArg_ParseTuple(ret,"iO",&cd, &txt)) {
337 *st_text = PyString_ToPJ(txt);
349 * Notify application that an existing call has been replaced with
350 * a new call. This happens when PJSUA-API receives incoming INVITE
351 * request with Replaces header.
353 static void cb_on_call_replaced(pjsua_call_id old_call_id,
354 pjsua_call_id new_call_id)
356 if (PyCallable_Check(g_obj_callback->on_call_replaced)) {
359 PyObject_CallFunction(
360 g_obj_callback->on_call_replaced,
374 * declares method on_reg_state for callback struct
376 static void cb_on_reg_state(pjsua_acc_id acc_id)
378 if (PyCallable_Check(g_obj_callback->on_reg_state)) {
381 PyObject_CallFunction(
382 g_obj_callback->on_reg_state,
393 * cb_on_incoming_subscribe
395 static void cb_on_incoming_subscribe( pjsua_acc_id acc_id,
396 pjsua_srv_pres *srv_pres,
397 pjsua_buddy_id buddy_id,
398 const pj_str_t *from,
399 pjsip_rx_data *rdata,
400 pjsip_status_code *code,
402 pjsua_msg_data *msg_data)
404 static char reason_buf[64];
406 PJ_UNUSED_ARG(rdata);
407 PJ_UNUSED_ARG(msg_data);
409 if (PyCallable_Check(g_obj_callback->on_incoming_subscribe)) {
410 PyObject *ret, *param_from, *param_contact, *param_srv_pres;
411 pjsip_contact_hdr *contact_hdr;
412 pj_pool_t *pool = NULL;
416 param_from = PyString_FromPJ(from);
417 param_srv_pres = PyLong_FromLong((long)srv_pres);
419 contact_hdr = (pjsip_contact_hdr*)
420 pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_CONTACT,
426 pool = pjsua_pool_create("pytmp", 512, 512);
427 contact = (char*) pj_pool_alloc(pool, PJSIP_MAX_URL_SIZE+1);
428 len = pjsip_uri_print(PJSIP_URI_IN_CONTACT_HDR, contact_hdr->uri,
429 contact, PJSIP_MAX_URL_SIZE);
434 param_contact = PyString_FromStringAndSize(contact, len);
436 param_contact = Py_BuildValue("");
439 ret = PyObject_CallFunction(
440 g_obj_callback->on_incoming_subscribe,
451 pj_pool_release(pool);
453 Py_DECREF(param_from);
454 Py_DECREF(param_contact);
455 Py_DECREF(param_srv_pres);
457 if (ret && PyTuple_Check(ret)) {
458 if (PyTuple_Size(ret) >= 1)
459 *code = (int)PyInt_AsLong(PyTuple_GetItem(ret, 0));
460 if (PyTuple_Size(ret) >= 2) {
461 if (PyTuple_GetItem(ret, 1) != Py_None) {
463 tmp = PyString_ToPJ(PyTuple_GetItem(ret, 1));
464 reason->ptr = reason_buf;
465 pj_strncpy(reason, &tmp, sizeof(reason_buf));
481 * declares method on_buddy state for callback struct
483 static void cb_on_buddy_state(pjsua_buddy_id buddy_id)
485 if (PyCallable_Check(g_obj_callback->on_buddy_state)) {
488 PyObject_CallFunction(
489 g_obj_callback->on_buddy_state,
501 * declares method on_pager for callback struct
503 static void cb_on_pager(pjsua_call_id call_id, const pj_str_t *from,
504 const pj_str_t *to, const pj_str_t *contact,
505 const pj_str_t *mime_type, const pj_str_t *body,
506 pjsip_rx_data *rdata, pjsua_acc_id acc_id)
508 PJ_UNUSED_ARG(rdata);
510 if (PyCallable_Check(g_obj_callback->on_pager)) {
511 PyObject *param_from, *param_to, *param_contact, *param_mime_type,
516 param_from = PyString_FromPJ(from);
517 param_to = PyString_FromPJ(to);
518 param_contact = PyString_FromPJ(contact);
519 param_mime_type = PyString_FromPJ(mime_type);
520 param_body = PyString_FromPJ(body);
522 PyObject_CallFunction(
523 g_obj_callback->on_pager,
535 Py_DECREF(param_body);
536 Py_DECREF(param_mime_type);
537 Py_DECREF(param_contact);
539 Py_DECREF(param_from);
548 * declares method on_pager_status for callback struct
550 static void cb_on_pager_status(pjsua_call_id call_id, const pj_str_t *to,
551 const pj_str_t *body, void *user_data,
552 pjsip_status_code status,
553 const pj_str_t *reason,
554 pjsip_tx_data *tdata,
555 pjsip_rx_data *rdata,
558 if (PyCallable_Check(g_obj_callback->on_pager)) {
559 PyObject *param_call_id, *param_to, *param_body,
560 *param_user_data, *param_status, *param_reason,
565 PJ_UNUSED_ARG(tdata);
566 PJ_UNUSED_ARG(rdata);
568 PyObject_CallFunctionObjArgs(
569 g_obj_callback->on_pager_status,
570 param_call_id = Py_BuildValue("i",call_id),
571 param_to = PyString_FromPJ(to),
572 param_body = PyString_FromPJ(body),
573 param_user_data = Py_BuildValue("i", user_data),
574 param_status = Py_BuildValue("i",status),
575 param_reason = PyString_FromPJ(reason),
576 param_acc_id = Py_BuildValue("i",acc_id),
580 Py_DECREF(param_call_id);
582 Py_DECREF(param_body);
583 Py_DECREF(param_user_data);
584 Py_DECREF(param_status);
585 Py_DECREF(param_reason);
586 Py_DECREF(param_acc_id);
595 * declares method on_typing for callback struct
597 static void cb_on_typing(pjsua_call_id call_id, const pj_str_t *from,
598 const pj_str_t *to, const pj_str_t *contact,
599 pj_bool_t is_typing, pjsip_rx_data *rdata,
602 if (PyCallable_Check(g_obj_callback->on_typing)) {
603 PyObject *param_call_id, *param_from, *param_to, *param_contact,
604 *param_is_typing, *param_acc_id;
608 PJ_UNUSED_ARG(rdata);
610 PyObject_CallFunctionObjArgs(
611 g_obj_callback->on_typing,
612 param_call_id = Py_BuildValue("i",call_id),
613 param_from = PyString_FromPJ(from),
614 param_to = PyString_FromPJ(to),
615 param_contact = PyString_FromPJ(contact),
616 param_is_typing = Py_BuildValue("i",is_typing),
617 param_acc_id = Py_BuildValue("i",acc_id),
621 Py_DECREF(param_call_id);
622 Py_DECREF(param_from);
624 Py_DECREF(param_contact);
625 Py_DECREF(param_is_typing);
626 Py_DECREF(param_acc_id);
636 static void cb_on_mwi_info(pjsua_acc_id acc_id, pjsua_mwi_info *mwi_info)
638 if (PyCallable_Check(g_obj_callback->on_mwi_info)) {
639 PyObject *param_acc_id, *param_body;
644 body.ptr = mwi_info->rdata->msg_info.msg->body->data;
645 body.slen = mwi_info->rdata->msg_info.msg->body->len;
647 PyObject_CallFunctionObjArgs(
648 g_obj_callback->on_mwi_info,
649 param_acc_id = Py_BuildValue("i",acc_id),
650 param_body = PyString_FromPJ(&body),
654 Py_DECREF(param_acc_id);
655 Py_DECREF(param_body);
664 * translate from hdr_list to pjsip_generic_string_hdr
666 void translate_hdr(pj_pool_t *pool, pjsip_hdr *hdr, PyObject *py_hdr_list)
670 if (PyList_Check(py_hdr_list)) {
673 for (i=0; i<PyList_Size(py_hdr_list); ++i) {
674 pj_str_t hname, hvalue;
675 pjsip_generic_string_hdr * new_hdr;
676 PyObject * tuple = PyList_GetItem(py_hdr_list, i);
678 if (PyTuple_Check(tuple)) {
679 if (PyTuple_Size(tuple) >= 1)
680 hname = PyString_ToPJ(PyTuple_GetItem(tuple,0));
683 if (PyTuple_Size(tuple) >= 2)
684 hvalue = PyString_ToPJ(PyTuple_GetItem(tuple,1));
693 new_hdr = pjsip_generic_string_hdr_create(pool, &hname, &hvalue);
694 pj_list_push_back((pj_list_type *)hdr, (pj_list_type *)new_hdr);
700 * py_pjsua_thread_register
702 static PyObject *py_pjsua_thread_register(PyObject *pSelf, PyObject *pArgs)
708 struct py_thread_desc *thread_desc;
710 PJ_UNUSED_ARG(pSelf);
712 if (!PyArg_ParseTuple(pArgs, "sO", &name, &py_desc)) {
715 thread_desc = (struct py_thread_desc*)
716 malloc(sizeof(struct py_thread_desc));
717 thread_desc->next = py_thread_desc;
718 py_thread_desc = thread_desc;
720 status = pj_thread_register(name, thread_desc->desc, &thread);
722 if (status == PJ_SUCCESS)
723 status = pj_thread_local_set(g_thread_id, (void*)1);
725 return Py_BuildValue("i",status);
729 * py_pjsua_logging_config_default
731 static PyObject *py_pjsua_logging_config_default(PyObject *pSelf,
734 PyObj_pjsua_logging_config *obj;
735 pjsua_logging_config cfg;
737 PJ_UNUSED_ARG(pSelf);
738 PJ_UNUSED_ARG(pArgs);
740 pjsua_logging_config_default(&cfg);
741 obj = (PyObj_pjsua_logging_config*)
742 PyObj_pjsua_logging_config_new(&PyTyp_pjsua_logging_config,
744 PyObj_pjsua_logging_config_import(obj, &cfg);
746 return (PyObject*)obj;
751 * py_pjsua_config_default
753 static PyObject *py_pjsua_config_default(PyObject *pSelf, PyObject *pArgs)
755 PyObj_pjsua_config *obj;
758 PJ_UNUSED_ARG(pSelf);
759 PJ_UNUSED_ARG(pArgs);
761 pjsua_config_default(&cfg);
762 obj = (PyObj_pjsua_config *) PyObj_pjsua_config_new(&PyTyp_pjsua_config,
764 PyObj_pjsua_config_import(obj, &cfg);
766 return (PyObject*)obj;
771 * py_pjsua_media_config_default
773 static PyObject * py_pjsua_media_config_default(PyObject *pSelf,
776 PyObj_pjsua_media_config *obj;
777 pjsua_media_config cfg;
779 PJ_UNUSED_ARG(pSelf);
780 PJ_UNUSED_ARG(pArgs);
782 pjsua_media_config_default(&cfg);
783 obj = (PyObj_pjsua_media_config *)
784 PyType_GenericNew(&PyTyp_pjsua_media_config, NULL, NULL);
785 PyObj_pjsua_media_config_import(obj, &cfg);
787 return (PyObject *)obj;
792 * py_pjsua_msg_data_init
794 static PyObject *py_pjsua_msg_data_init(PyObject *pSelf, PyObject *pArgs)
796 PJ_UNUSED_ARG(pSelf);
797 PJ_UNUSED_ARG(pArgs);
799 return (PyObject *)PyObj_pjsua_msg_data_new(&PyTyp_pjsua_msg_data,
805 * py_pjsua_reconfigure_logging
807 static PyObject *py_pjsua_reconfigure_logging(PyObject *pSelf,
813 PJ_UNUSED_ARG(pSelf);
815 if (!PyArg_ParseTuple(pArgs, "O", &logObj)) {
819 if (logObj != Py_None) {
820 PyObj_pjsua_logging_config *log;
821 pjsua_logging_config cfg;
823 log = (PyObj_pjsua_logging_config*)logObj;
824 cfg.msg_logging = log->msg_logging;
825 cfg.level = log->level;
826 cfg.console_level = log->console_level;
827 cfg.decor = log->decor;
828 cfg.log_filename = PyString_ToPJ(log->log_filename);
829 Py_XDECREF(g_obj_log_cb);
830 g_obj_log_cb = log->cb;
831 Py_INCREF(g_obj_log_cb);
833 status = pjsua_reconfigure_logging(&cfg);
835 status = pjsua_reconfigure_logging(NULL);
838 return Py_BuildValue("i",status);
845 static PyObject *py_pjsua_perror(PyObject *pSelf, PyObject *pArgs)
851 PJ_UNUSED_ARG(pSelf);
853 if (!PyArg_ParseTuple(pArgs, "ssi", &sender, &title, &status)) {
857 pjsua_perror(sender, title, status);
859 return Py_BuildValue("");
866 static PyObject *py_pjsua_create(PyObject *pSelf, PyObject *pArgs)
870 PJ_UNUSED_ARG(pSelf);
871 PJ_UNUSED_ARG(pArgs);
873 status = pjsua_create();
875 if (status == PJ_SUCCESS) {
876 status = pj_thread_local_alloc(&g_thread_id);
877 if (status == PJ_SUCCESS)
878 status = pj_thread_local_set(g_thread_id, (void*)1);
880 pj_atexit(&clear_py_thread_desc);
883 return Py_BuildValue("i",status);
890 static PyObject *py_pjsua_init(PyObject *pSelf, PyObject *pArgs)
893 PyObject *o_ua_cfg, *o_log_cfg, *o_media_cfg;
894 pjsua_config cfg_ua, *p_cfg_ua;
895 pjsua_logging_config cfg_log, *p_cfg_log;
896 pjsua_media_config cfg_media, *p_cfg_media;
898 PJ_UNUSED_ARG(pSelf);
900 if (!PyArg_ParseTuple(pArgs, "OOO", &o_ua_cfg, &o_log_cfg, &o_media_cfg)) {
904 pjsua_config_default(&cfg_ua);
905 pjsua_logging_config_default(&cfg_log);
906 pjsua_media_config_default(&cfg_media);
908 if (o_ua_cfg != Py_None) {
909 PyObj_pjsua_config *obj_ua_cfg = (PyObj_pjsua_config*)o_ua_cfg;
911 PyObj_pjsua_config_export(&cfg_ua, obj_ua_cfg);
913 Py_XDECREF(g_obj_callback);
914 g_obj_callback = obj_ua_cfg->cb;
915 Py_INCREF(g_obj_callback);
917 cfg_ua.cb.on_call_state = &cb_on_call_state;
918 cfg_ua.cb.on_incoming_call = &cb_on_incoming_call;
919 cfg_ua.cb.on_call_media_state = &cb_on_call_media_state;
920 cfg_ua.cb.on_dtmf_digit = &cb_on_dtmf_digit;
921 cfg_ua.cb.on_call_transfer_request = &cb_on_call_transfer_request;
922 cfg_ua.cb.on_call_transfer_status = &cb_on_call_transfer_status;
923 cfg_ua.cb.on_call_replace_request = &cb_on_call_replace_request;
924 cfg_ua.cb.on_call_replaced = &cb_on_call_replaced;
925 cfg_ua.cb.on_reg_state = &cb_on_reg_state;
926 cfg_ua.cb.on_incoming_subscribe = &cb_on_incoming_subscribe;
927 cfg_ua.cb.on_buddy_state = &cb_on_buddy_state;
928 cfg_ua.cb.on_pager2 = &cb_on_pager;
929 cfg_ua.cb.on_pager_status2 = &cb_on_pager_status;
930 cfg_ua.cb.on_typing2 = &cb_on_typing;
931 cfg_ua.cb.on_mwi_info = &cb_on_mwi_info;
939 if (o_log_cfg != Py_None) {
940 PyObj_pjsua_logging_config * obj_log;
942 obj_log = (PyObj_pjsua_logging_config *)o_log_cfg;
944 PyObj_pjsua_logging_config_export(&cfg_log, obj_log);
946 Py_XDECREF(g_obj_log_cb);
947 g_obj_log_cb = obj_log->cb;
948 Py_INCREF(g_obj_log_cb);
950 cfg_log.cb = &cb_log_cb;
951 p_cfg_log = &cfg_log;
957 if (o_media_cfg != Py_None) {
958 PyObj_pjsua_media_config_export(&cfg_media,
959 (PyObj_pjsua_media_config*)o_media_cfg);
960 p_cfg_media = &cfg_media;
966 status = pjsua_init(p_cfg_ua, p_cfg_log, p_cfg_media);
968 return Py_BuildValue("i", status);
975 static PyObject *py_pjsua_start(PyObject *pSelf, PyObject *pArgs)
979 PJ_UNUSED_ARG(pSelf);
980 PJ_UNUSED_ARG(pArgs);
982 status = pjsua_start();
984 return Py_BuildValue("i", status);
991 static PyObject *py_pjsua_destroy(PyObject *pSelf, PyObject *pArgs)
995 PJ_UNUSED_ARG(pSelf);
996 PJ_UNUSED_ARG(pArgs);
998 status = pjsua_destroy();
1000 return Py_BuildValue("i", status);
1005 * py_pjsua_handle_events
1007 static PyObject *py_pjsua_handle_events(PyObject *pSelf, PyObject *pArgs)
1012 PJ_UNUSED_ARG(pSelf);
1014 if (!PyArg_ParseTuple(pArgs, "i", &msec)) {
1021 #if !NO_PJSIP_THREAD
1022 /* Since handle_events() will block, we must wrap it with ALLOW_THREADS
1023 * construct, or otherwise many Python blocking functions (such as
1024 * time.sleep(), readline(), etc.) may hang/block indefinitely.
1025 * See http://www.python.org/doc/current/api/threads.html for more info.
1027 Py_BEGIN_ALLOW_THREADS
1030 ret = pjsua_handle_events(msec);
1032 #if !NO_PJSIP_THREAD
1033 Py_END_ALLOW_THREADS
1036 return Py_BuildValue("i", ret);
1041 * py_pjsua_verify_sip_url
1043 static PyObject *py_pjsua_verify_sip_url(PyObject *pSelf, PyObject *pArgs)
1048 PJ_UNUSED_ARG(pSelf);
1050 if (!PyArg_ParseTuple(pArgs, "s", &url)) {
1054 status = pjsua_verify_sip_url(url);
1056 return Py_BuildValue("i", status);
1064 static char pjsua_thread_register_doc[] =
1065 "int _pjsua.thread_register(string name, int[] desc)";
1066 static char pjsua_perror_doc[] =
1067 "void _pjsua.perror (string sender, string title, int status) "
1068 "Display error message for the specified error code. Parameters: "
1069 "sender: The log sender field; "
1070 "title: Message title for the error; "
1071 "status: Status code.";
1073 static char pjsua_create_doc[] =
1074 "int _pjsua.create (void) "
1075 "Instantiate pjsua application. Application "
1076 "must call this function before calling any other functions, to make sure "
1077 "that the underlying libraries are properly initialized. Once this "
1078 "function has returned success, application must call pjsua_destroy() "
1081 static char pjsua_init_doc[] =
1082 "int _pjsua.init (_pjsua.Config obj_ua_cfg, "
1083 "_pjsua.Logging_Config log_cfg, _pjsua.Media_Config media_cfg) "
1084 "Initialize pjsua with the specified settings. All the settings are "
1085 "optional, and the default values will be used when the config is not "
1086 "specified. Parameters: "
1087 "obj_ua_cfg : User agent configuration; "
1088 "log_cfg : Optional logging configuration; "
1089 "media_cfg : Optional media configuration.";
1091 static char pjsua_start_doc[] =
1092 "int _pjsua.start (void) "
1093 "Application is recommended to call this function after all "
1094 "initialization is done, so that the library can do additional checking "
1095 "set up additional";
1097 static char pjsua_destroy_doc[] =
1098 "int _pjsua.destroy (void) "
1099 "Destroy pjsua This function must be called once PJSUA is created. To "
1100 "make it easier for application, application may call this function "
1101 "several times with no danger.";
1103 static char pjsua_handle_events_doc[] =
1104 "int _pjsua.handle_events (int msec_timeout) "
1105 "Poll pjsua for events, and if necessary block the caller thread for the "
1106 "specified maximum interval (in miliseconds) Parameters: "
1107 "msec_timeout: Maximum time to wait, in miliseconds. "
1108 "Returns: The number of events that have been handled during the poll. "
1109 "Negative value indicates error, and application can retrieve the error "
1110 "as (err = -return_value).";
1112 static char pjsua_verify_sip_url_doc[] =
1113 "int _pjsua.verify_sip_url (string c_url) "
1114 "Verify that valid SIP url is given Parameters: "
1115 "c_url: The URL, as NULL terminated string.";
1117 static char pjsua_reconfigure_logging_doc[] =
1118 "int _pjsua.reconfigure_logging (_pjsua.Logging_Config c) "
1119 "Application can call this function at any time (after pjsua_create(), of "
1120 "course) to change logging settings. Parameters: "
1121 "c: Logging configuration.";
1123 static char pjsua_logging_config_default_doc[] =
1124 "_pjsua.Logging_Config _pjsua.logging_config_default () "
1125 "Use this function to initialize logging config.";
1127 static char pjsua_config_default_doc[] =
1128 "_pjsua.Config _pjsua.config_default (). Use this function to "
1129 "initialize pjsua config. ";
1131 static char pjsua_media_config_default_doc[] =
1132 "_pjsua.Media_Config _pjsua.media_config_default (). "
1133 "Use this function to initialize media config.";
1135 static char pjsua_msg_data_init_doc[] =
1136 "_pjsua.Msg_Data void _pjsua.msg_data_init () "
1137 "Initialize message data ";
1140 /* END OF LIB BASE */
1145 * py_pjsua_transport_config_default
1147 static PyObject *py_pjsua_transport_config_default(PyObject *pSelf,
1150 PyObj_pjsua_transport_config *obj;
1151 pjsua_transport_config cfg;
1153 PJ_UNUSED_ARG(pSelf);
1154 PJ_UNUSED_ARG(pArgs);
1156 pjsua_transport_config_default(&cfg);
1157 obj = (PyObj_pjsua_transport_config*)
1158 PyObj_pjsua_transport_config_new(&PyTyp_pjsua_transport_config,
1160 PyObj_pjsua_transport_config_import(obj, &cfg);
1162 return (PyObject *)obj;
1166 * py_pjsua_transport_create
1168 static PyObject *py_pjsua_transport_create(PyObject *pSelf, PyObject *pArgs)
1173 pjsua_transport_config cfg;
1174 pjsua_transport_id id;
1176 PJ_UNUSED_ARG(pSelf);
1178 if (!PyArg_ParseTuple(pArgs, "iO", &type, &pCfg)) {
1182 if (pCfg != Py_None) {
1183 PyObj_pjsua_transport_config *obj;
1185 obj = (PyObj_pjsua_transport_config*)pCfg;
1186 PyObj_pjsua_transport_config_export(&cfg, obj);
1187 status = pjsua_transport_create(type, &cfg, &id);
1189 status = pjsua_transport_create(type, NULL, &id);
1193 return Py_BuildValue("ii", status, id);
1197 * py_pjsua_enum_transports
1199 static PyObject *py_pjsua_enum_transports(PyObject *pSelf, PyObject *pArgs)
1203 pjsua_transport_id id[PJSIP_MAX_TRANSPORTS];
1206 PJ_UNUSED_ARG(pSelf);
1207 PJ_UNUSED_ARG(pArgs);
1209 c = PJ_ARRAY_SIZE(id);
1210 status = pjsua_enum_transports(id, &c);
1212 list = PyList_New(c);
1213 for (i = 0; i < c; i++) {
1214 PyList_SetItem(list, i, Py_BuildValue("i", id[i]));
1217 return (PyObject*)list;
1221 * py_pjsua_transport_get_info
1222 * !modified @ 051206
1224 static PyObject *py_pjsua_transport_get_info(PyObject *pSelf, PyObject *pArgs)
1228 pjsua_transport_info info;
1230 PJ_UNUSED_ARG(pSelf);
1232 if (!PyArg_ParseTuple(pArgs, "i", &id)) {
1236 status = pjsua_transport_get_info(id, &info);
1237 if (status == PJ_SUCCESS) {
1238 PyObj_pjsua_transport_info *obj;
1239 obj = (PyObj_pjsua_transport_info *)
1240 PyObj_pjsua_transport_info_new(&PyTyp_pjsua_transport_info,
1242 PyObj_pjsua_transport_info_import(obj, &info);
1243 return (PyObject*)obj;
1245 return Py_BuildValue("");
1250 * py_pjsua_transport_set_enable
1252 static PyObject *py_pjsua_transport_set_enable(PyObject *pSelf,
1259 PJ_UNUSED_ARG(pSelf);
1261 if (!PyArg_ParseTuple(pArgs, "ii", &id, &enabled)) {
1264 status = pjsua_transport_set_enable(id, enabled);
1266 return Py_BuildValue("i", status);
1270 * py_pjsua_transport_close
1272 static PyObject *py_pjsua_transport_close(PyObject *pSelf, PyObject *pArgs)
1278 PJ_UNUSED_ARG(pSelf);
1280 if (!PyArg_ParseTuple(pArgs, "ii", &id, &force)) {
1283 status = pjsua_transport_close(id, force);
1285 return Py_BuildValue("i", status);
1288 static char pjsua_transport_config_default_doc[] =
1289 "_pjsua.Transport_Config _pjsua.transport_config_default () "
1290 "Call this function to initialize UDP config with default values.";
1291 static char pjsua_transport_create_doc[] =
1292 "int, int _pjsua.transport_create (int type, "
1293 "_pjsua.Transport_Config cfg) "
1294 "Create SIP transport.";
1295 static char pjsua_enum_transports_doc[] =
1296 "int[] _pjsua.enum_transports () "
1297 "Enumerate all transports currently created in the system.";
1298 static char pjsua_transport_get_info_doc[] =
1299 "void _pjsua.transport_get_info "
1300 "(_pjsua.Transport_ID id, _pjsua.Transport_Info info) "
1301 "Get information about transports.";
1302 static char pjsua_transport_set_enable_doc[] =
1303 "void _pjsua.transport_set_enable "
1304 "(_pjsua.Transport_ID id, int enabled) "
1305 "Disable a transport or re-enable it. "
1306 "By default transport is always enabled after it is created. "
1307 "Disabling a transport does not necessarily close the socket, "
1308 "it will only discard incoming messages and prevent the transport "
1309 "from being used to send outgoing messages.";
1310 static char pjsua_transport_close_doc[] =
1311 "void _pjsua.transport_close (_pjsua.Transport_ID id, int force) "
1312 "Close the transport. If transport is forcefully closed, "
1313 "it will be immediately closed, and any pending transactions "
1314 "that are using the transport may not terminate properly. "
1315 "Otherwise, the system will wait until all transactions are closed "
1316 "while preventing new users from using the transport, and will close "
1317 "the transport when it is safe to do so.";
1319 /* END OF LIB TRANSPORT */
1325 * py_pjsua_acc_config_default
1327 static PyObject *py_pjsua_acc_config_default(PyObject *pSelf, PyObject *pArgs)
1329 PyObj_pjsua_acc_config *obj;
1330 pjsua_acc_config cfg;
1332 PJ_UNUSED_ARG(pSelf);
1333 PJ_UNUSED_ARG(pArgs);
1335 if (!PyArg_ParseTuple(pArgs, "")) {
1339 pjsua_acc_config_default(&cfg);
1340 obj = (PyObj_pjsua_acc_config *)
1341 PyObj_pjsua_acc_config_new(&PyTyp_pjsua_acc_config,
1343 PyObj_pjsua_acc_config_import(obj, &cfg);
1344 return (PyObject *)obj;
1348 * py_pjsua_acc_get_count
1350 static PyObject *py_pjsua_acc_get_count(PyObject *pSelf, PyObject *pArgs)
1354 PJ_UNUSED_ARG(pSelf);
1355 PJ_UNUSED_ARG(pArgs);
1357 count = pjsua_acc_get_count();
1358 return Py_BuildValue("i", count);
1362 * py_pjsua_acc_is_valid
1364 static PyObject *py_pjsua_acc_is_valid(PyObject *pSelf, PyObject *pArgs)
1369 PJ_UNUSED_ARG(pSelf);
1371 if (!PyArg_ParseTuple(pArgs, "i", &id)) {
1375 is_valid = pjsua_acc_is_valid(id);
1376 return Py_BuildValue("i", is_valid);
1380 * py_pjsua_acc_set_default
1382 static PyObject *py_pjsua_acc_set_default(PyObject *pSelf, PyObject *pArgs)
1387 PJ_UNUSED_ARG(pSelf);
1389 if (!PyArg_ParseTuple(pArgs, "i", &id)) {
1392 status = pjsua_acc_set_default(id);
1394 return Py_BuildValue("i", status);
1398 * py_pjsua_acc_get_default
1400 static PyObject *py_pjsua_acc_get_default(PyObject *pSelf, PyObject *pArgs)
1404 PJ_UNUSED_ARG(pSelf);
1405 PJ_UNUSED_ARG(pArgs);
1407 id = pjsua_acc_get_default();
1409 return Py_BuildValue("i", id);
1415 static PyObject *py_pjsua_acc_add(PyObject *pSelf, PyObject *pArgs)
1422 PJ_UNUSED_ARG(pSelf);
1424 if (!PyArg_ParseTuple(pArgs, "Oi", &pCfg, &is_default)) {
1428 if (pCfg != Py_None) {
1429 pjsua_acc_config cfg;
1430 PyObj_pjsua_acc_config *ac;
1432 pjsua_acc_config_default(&cfg);
1433 ac = (PyObj_pjsua_acc_config *)pCfg;
1434 PyObj_pjsua_acc_config_export(&cfg, ac);
1435 status = pjsua_acc_add(&cfg, is_default, &acc_id);
1438 acc_id = PJSUA_INVALID_ID;
1441 return Py_BuildValue("ii", status, acc_id);
1445 * py_pjsua_acc_add_local
1447 static PyObject *py_pjsua_acc_add_local(PyObject *pSelf, PyObject *pArgs)
1454 PJ_UNUSED_ARG(pSelf);
1456 if (!PyArg_ParseTuple(pArgs, "ii", &tid, &is_default)) {
1460 status = pjsua_acc_add_local(tid, is_default, &acc_id);
1462 return Py_BuildValue("ii", status, acc_id);
1466 * py_pjsua_acc_set_user_data
1468 static PyObject *py_pjsua_acc_set_user_data(PyObject *pSelf, PyObject *pArgs)
1471 PyObject *pUserData, *old_user_data;
1474 PJ_UNUSED_ARG(pSelf);
1476 if (!PyArg_ParseTuple(pArgs, "iO", &acc_id, &pUserData)) {
1480 old_user_data = (PyObject*) pjsua_acc_get_user_data(acc_id);
1482 status = pjsua_acc_set_user_data(acc_id, (void*)pUserData);
1484 if (status == PJ_SUCCESS) {
1485 Py_XINCREF(pUserData);
1486 Py_XDECREF(old_user_data);
1489 return Py_BuildValue("i", status);
1493 * py_pjsua_acc_get_user_data
1495 static PyObject *py_pjsua_acc_get_user_data(PyObject *pSelf, PyObject *pArgs)
1498 PyObject *user_data;
1500 PJ_UNUSED_ARG(pSelf);
1502 if (!PyArg_ParseTuple(pArgs, "i", &acc_id)) {
1506 user_data = (PyObject*) pjsua_acc_get_user_data(acc_id);
1508 return user_data ? Py_BuildValue("O", user_data) : Py_BuildValue("");
1514 static PyObject *py_pjsua_acc_del(PyObject *pSelf, PyObject *pArgs)
1517 PyObject *user_data;
1520 PJ_UNUSED_ARG(pSelf);
1522 if (!PyArg_ParseTuple(pArgs, "i", &acc_id)) {
1526 user_data = (PyObject*) pjsua_acc_get_user_data(acc_id);
1527 Py_XDECREF(user_data);
1529 status = pjsua_acc_del(acc_id);
1531 return Py_BuildValue("i", status);
1535 * py_pjsua_acc_modify
1537 static PyObject *py_pjsua_acc_modify(PyObject *pSelf, PyObject *pArgs)
1540 PyObj_pjsua_acc_config * ac;
1544 PJ_UNUSED_ARG(pSelf);
1546 if (!PyArg_ParseTuple(pArgs, "iO", &acc_id, &pCfg)) {
1550 if (pCfg != Py_None) {
1551 pjsua_acc_config cfg;
1553 pjsua_acc_config_default(&cfg);
1554 ac = (PyObj_pjsua_acc_config*)pCfg;
1555 PyObj_pjsua_acc_config_export(&cfg, ac);
1557 status = pjsua_acc_modify(acc_id, &cfg);
1561 return Py_BuildValue("i", status);
1565 * py_pjsua_acc_set_online_status
1567 static PyObject *py_pjsua_acc_set_online_status(PyObject *pSelf,
1574 PJ_UNUSED_ARG(pSelf);
1576 if (!PyArg_ParseTuple(pArgs, "ii", &acc_id, &is_online)) {
1580 status = pjsua_acc_set_online_status(acc_id, is_online);
1582 return Py_BuildValue("i", status);
1586 * py_pjsua_acc_set_online_status2
1588 static PyObject *py_pjsua_acc_set_online_status2(PyObject *pSelf,
1594 const char *activity_text = NULL;
1595 const char *rpid_id = NULL;
1596 pjrpid_element rpid;
1599 PJ_UNUSED_ARG(pSelf);
1601 if (!PyArg_ParseTuple(pArgs, "iiiss", &acc_id, &is_online,
1602 &activity_id, &activity_text, &rpid_id))
1607 pj_bzero(&rpid, sizeof(rpid));
1608 rpid.type = PJRPID_ELEMENT_TYPE_PERSON;
1609 rpid.activity = activity_id;
1611 rpid.note = pj_str((char*)activity_text);
1614 rpid.id = pj_str((char*)rpid_id);
1616 status = pjsua_acc_set_online_status2(acc_id, is_online, &rpid);
1618 return Py_BuildValue("i", status);
1622 * py_pjsua_acc_set_registration
1624 static PyObject *py_pjsua_acc_set_registration(PyObject *pSelf,
1631 PJ_UNUSED_ARG(pSelf);
1633 if (!PyArg_ParseTuple(pArgs, "ii", &acc_id, &renew)) {
1637 status = pjsua_acc_set_registration(acc_id, renew);
1639 return Py_BuildValue("i", status);
1643 * py_pjsua_acc_get_info
1645 static PyObject *py_pjsua_acc_get_info(PyObject *pSelf, PyObject *pArgs)
1648 PyObj_pjsua_acc_info * obj;
1649 pjsua_acc_info info;
1652 PJ_UNUSED_ARG(pSelf);
1654 if (!PyArg_ParseTuple(pArgs, "i", &acc_id)) {
1658 status = pjsua_acc_get_info(acc_id, &info);
1659 if (status == PJ_SUCCESS) {
1660 obj = (PyObj_pjsua_acc_info*)
1661 PyObj_pjsua_acc_info_new(&PyTyp_pjsua_acc_info, NULL, NULL);
1662 PyObj_pjsua_acc_info_import(obj, &info);
1663 return (PyObject*)obj;
1665 return Py_BuildValue("");
1670 * py_pjsua_enum_accs
1672 static PyObject *py_pjsua_enum_accs(PyObject *pSelf, PyObject *pArgs)
1676 pjsua_acc_id id[PJSUA_MAX_ACC];
1679 PJ_UNUSED_ARG(pSelf);
1680 PJ_UNUSED_ARG(pArgs);
1682 c = PJ_ARRAY_SIZE(id);
1683 status = pjsua_enum_accs(id, &c);
1684 if (status != PJ_SUCCESS)
1687 list = PyList_New(c);
1688 for (i = 0; i < c; i++) {
1689 PyList_SetItem(list, i, Py_BuildValue("i", id[i]));
1692 return (PyObject*)list;
1696 * py_pjsua_acc_enum_info
1698 static PyObject *py_pjsua_acc_enum_info(PyObject *pSelf, PyObject *pArgs)
1702 pjsua_acc_info info[PJSUA_MAX_ACC];
1705 PJ_UNUSED_ARG(pSelf);
1706 PJ_UNUSED_ARG(pArgs);
1708 if (!PyArg_ParseTuple(pArgs, "")) {
1712 c = PJ_ARRAY_SIZE(info);
1713 status = pjsua_acc_enum_info(info, &c);
1714 if (status != PJ_SUCCESS)
1717 list = PyList_New(c);
1718 for (i = 0; i < c; i++) {
1719 PyObj_pjsua_acc_info *obj;
1720 obj = (PyObj_pjsua_acc_info *)
1721 PyObj_pjsua_acc_info_new(&PyTyp_pjsua_acc_info, NULL, NULL);
1723 PyObj_pjsua_acc_info_import(obj, &info[i]);
1725 PyList_SetItem(list, i, (PyObject*)obj);
1728 return (PyObject*)list;
1732 * py_pjsua_acc_set_transport
1734 static PyObject *py_pjsua_acc_set_transport(PyObject *pSelf, PyObject *pArgs)
1736 int acc_id, transport_id;
1739 PJ_UNUSED_ARG(pSelf);
1741 if (!PyArg_ParseTuple(pArgs, "ii", &acc_id, &transport_id)) {
1745 status = pjsua_acc_set_transport(acc_id, transport_id);
1748 return Py_BuildValue("i", status);
1753 * py_pjsua_acc_pres_notify
1755 static PyObject *py_pjsua_acc_pres_notify(PyObject *pSelf,
1759 PyObject *arg_pres, *arg_msg_data, *arg_reason;
1761 pjsua_msg_data msg_data;
1763 pj_bool_t with_body;
1764 pj_pool_t *pool = NULL;
1767 PJ_UNUSED_ARG(pSelf);
1769 if (!PyArg_ParseTuple(pArgs, "iOiOO", &acc_id, &arg_pres,
1770 &state, &arg_reason, &arg_msg_data))
1775 srv_pres = (void*) PyLong_AsLong(arg_pres);
1776 with_body = (state != PJSIP_EVSUB_STATE_TERMINATED);
1778 if (arg_reason && PyString_Check(arg_reason)) {
1779 reason = PyString_ToPJ(arg_reason);
1781 reason = pj_str("");
1784 pjsua_msg_data_init(&msg_data);
1785 if (arg_msg_data && arg_msg_data != Py_None) {
1786 PyObj_pjsua_msg_data *omd = (PyObj_pjsua_msg_data *)arg_msg_data;
1787 msg_data.content_type = PyString_ToPJ(omd->content_type);
1788 msg_data.msg_body = PyString_ToPJ(omd->msg_body);
1789 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
1790 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
1793 status = pjsua_pres_notify(acc_id, (pjsua_srv_pres*)srv_pres,
1794 (pjsip_evsub_state)state, NULL,
1795 &reason, with_body, &msg_data);
1798 pj_pool_release(pool);
1801 return Py_BuildValue("i", status);
1804 static char pjsua_acc_config_default_doc[] =
1805 "_pjsua.Acc_Config _pjsua.acc_config_default () "
1806 "Call this function to initialize account config with default values.";
1807 static char pjsua_acc_get_count_doc[] =
1808 "int _pjsua.acc_get_count () "
1809 "Get number of current accounts.";
1810 static char pjsua_acc_is_valid_doc[] =
1811 "int _pjsua.acc_is_valid (int acc_id) "
1812 "Check if the specified account ID is valid.";
1813 static char pjsua_acc_set_default_doc[] =
1814 "int _pjsua.acc_set_default (int acc_id) "
1815 "Set default account to be used when incoming "
1816 "and outgoing requests doesn't match any accounts.";
1817 static char pjsua_acc_get_default_doc[] =
1818 "int _pjsua.acc_get_default () "
1819 "Get default account.";
1820 static char pjsua_acc_add_doc[] =
1821 "int, int _pjsua.acc_add (_pjsua.Acc_Config cfg, "
1823 "Add a new account to pjsua. PJSUA must have been initialized "
1824 "(with pjsua_init()) before calling this function.";
1825 static char pjsua_acc_add_local_doc[] =
1826 "int,int _pjsua.acc_add_local (int tid, "
1828 "Add a local account. A local account is used to identify "
1829 "local endpoint instead of a specific user, and for this reason, "
1830 "a transport ID is needed to obtain the local address information.";
1831 static char pjsua_acc_del_doc[] =
1832 "int _pjsua.acc_del (int acc_id) "
1834 static char pjsua_acc_modify_doc[] =
1835 "int _pjsua.acc_modify (int acc_id, _pjsua.Acc_Config cfg) "
1836 "Modify account information.";
1837 static char pjsua_acc_set_online_status_doc[] =
1838 "int _pjsua.acc_set_online_status2(int acc_id, int is_online) "
1839 "Modify account's presence status to be advertised "
1840 "to remote/presence subscribers.";
1841 static char pjsua_acc_set_online_status2_doc[] =
1842 "int _pjsua.acc_set_online_status (int acc_id, int is_online, "
1843 "int activity_id, string activity_text) "
1844 "Modify account's presence status to be advertised "
1845 "to remote/presence subscribers.";
1846 static char pjsua_acc_set_registration_doc[] =
1847 "int _pjsua.acc_set_registration (int acc_id, int renew) "
1848 "Update registration or perform unregistration.";
1849 static char pjsua_acc_get_info_doc[] =
1850 "_pjsua.Acc_Info _pjsua.acc_get_info (int acc_id) "
1851 "Get account information.";
1852 static char pjsua_enum_accs_doc[] =
1853 "int[] _pjsua.enum_accs () "
1854 "Enum accounts all account ids.";
1855 static char pjsua_acc_enum_info_doc[] =
1856 "_pjsua.Acc_Info[] _pjsua.acc_enum_info () "
1857 "Enum accounts info.";
1859 /* END OF LIB ACCOUNT */
1866 * py_pjsua_buddy_config_default
1868 static PyObject *py_pjsua_buddy_config_default(PyObject *pSelf,
1871 PyObj_pjsua_buddy_config *obj;
1872 pjsua_buddy_config cfg;
1874 PJ_UNUSED_ARG(pSelf);
1875 PJ_UNUSED_ARG(pArgs);
1877 pjsua_buddy_config_default(&cfg);
1878 obj = (PyObj_pjsua_buddy_config *)
1879 PyObj_pjsua_buddy_config_new(&PyTyp_pjsua_buddy_config, NULL, NULL);
1880 PyObj_pjsua_buddy_config_import(obj, &cfg);
1882 return (PyObject *)obj;
1886 * py_pjsua_get_buddy_count
1888 static PyObject *py_pjsua_get_buddy_count(PyObject *pSelf, PyObject *pArgs)
1890 PJ_UNUSED_ARG(pSelf);
1891 PJ_UNUSED_ARG(pArgs);
1893 return Py_BuildValue("i", pjsua_get_buddy_count());
1897 * py_pjsua_buddy_is_valid
1899 static PyObject *py_pjsua_buddy_is_valid(PyObject *pSelf, PyObject *pArgs)
1904 PJ_UNUSED_ARG(pSelf);
1906 if (!PyArg_ParseTuple(pArgs, "i", &id)) {
1909 is_valid = pjsua_buddy_is_valid(id);
1911 return Py_BuildValue("i", is_valid);
1915 * py_pjsua_enum_buddies
1917 static PyObject *py_pjsua_enum_buddies(PyObject *pSelf, PyObject *pArgs)
1921 pjsua_buddy_id id[PJSUA_MAX_BUDDIES];
1924 PJ_UNUSED_ARG(pSelf);
1925 PJ_UNUSED_ARG(pArgs);
1927 c = PJ_ARRAY_SIZE(id);
1928 status = pjsua_enum_buddies(id, &c);
1929 if (status != PJ_SUCCESS)
1932 list = PyList_New(c);
1933 for (i = 0; i < c; i++) {
1934 PyList_SetItem(list, i, Py_BuildValue("i", id[i]));
1937 return (PyObject*)list;
1941 * py_pjsua_buddy_find
1943 static PyObject *py_pjsua_buddy_find(PyObject *pSelf, PyObject *pArgs)
1947 pjsua_buddy_id buddy_id;
1949 PJ_UNUSED_ARG(pSelf);
1951 if (!PyArg_ParseTuple(pArgs, "O", &pURI)) {
1955 if (!PyString_Check(pURI))
1956 return Py_BuildValue("i", PJSUA_INVALID_ID);
1958 uri = PyString_ToPJ(pURI);
1959 buddy_id = pjsua_buddy_find(&uri);
1961 return Py_BuildValue("i", buddy_id);
1965 * py_pjsua_buddy_get_info
1967 static PyObject *py_pjsua_buddy_get_info(PyObject *pSelf, PyObject *pArgs)
1970 pjsua_buddy_info info;
1973 PJ_UNUSED_ARG(pSelf);
1975 if (!PyArg_ParseTuple(pArgs, "i", &buddy_id)) {
1979 status = pjsua_buddy_get_info(buddy_id, &info);
1980 if (status == PJ_SUCCESS) {
1981 PyObj_pjsua_buddy_info *obj;
1983 obj = (PyObj_pjsua_buddy_info *)
1984 PyObj_pjsua_buddy_config_new(&PyTyp_pjsua_buddy_info,
1986 PyObj_pjsua_buddy_info_import(obj, &info);
1987 return (PyObject*)obj;
1989 return Py_BuildValue("");
1994 * py_pjsua_buddy_add
1996 static PyObject *py_pjsua_buddy_add(PyObject *pSelf, PyObject *pArgs)
2002 PJ_UNUSED_ARG(pSelf);
2004 if (!PyArg_ParseTuple(pArgs, "O", &pCfg)) {
2008 if (pCfg != Py_None) {
2009 pjsua_buddy_config cfg;
2010 PyObj_pjsua_buddy_config *bc;
2012 bc = (PyObj_pjsua_buddy_config *)pCfg;
2014 pjsua_buddy_config_default(&cfg);
2015 PyObj_pjsua_buddy_config_export(&cfg, bc);
2017 status = pjsua_buddy_add(&cfg, &buddy_id);
2021 buddy_id = PJSUA_INVALID_ID;
2023 return Py_BuildValue("ii", status, buddy_id);
2027 * py_pjsua_buddy_del
2029 static PyObject *py_pjsua_buddy_del(PyObject *pSelf, PyObject *pArgs)
2033 PyObject *user_data;
2035 PJ_UNUSED_ARG(pSelf);
2037 if (!PyArg_ParseTuple(pArgs, "i", &buddy_id)) {
2041 user_data = (PyObject*) pjsua_buddy_get_user_data(buddy_id);
2042 Py_XDECREF(user_data);
2044 status = pjsua_buddy_del(buddy_id);
2046 return Py_BuildValue("i", status);
2050 * py_pjsua_buddy_set_user_data
2052 static PyObject *py_pjsua_buddy_set_user_data(PyObject *pSelf, PyObject *pArgs)
2056 PyObject *user_data, *old_user_data;
2058 PJ_UNUSED_ARG(pSelf);
2060 if (!PyArg_ParseTuple(pArgs, "iO", &buddy_id, &user_data)) {
2064 if (!pjsua_buddy_is_valid(buddy_id)) {
2065 return Py_BuildValue("i", 0);
2068 old_user_data = (PyObject*) pjsua_buddy_get_user_data(buddy_id);
2070 status = pjsua_buddy_set_user_data(buddy_id, (void*)user_data);
2072 if (status == PJ_SUCCESS) {
2073 Py_XINCREF(user_data);
2074 Py_XDECREF(old_user_data);
2077 return Py_BuildValue("i", status);
2081 * py_pjsua_buddy_get_user_data
2083 static PyObject *py_pjsua_buddy_get_user_data(PyObject *pSelf, PyObject *pArgs)
2086 PyObject *user_data;
2088 PJ_UNUSED_ARG(pSelf);
2090 if (!PyArg_ParseTuple(pArgs, "i", &buddy_id)) {
2094 user_data = (PyObject*) pjsua_buddy_get_user_data(buddy_id);
2096 return user_data? Py_BuildValue("O", user_data) : Py_BuildValue("");
2100 * py_pjsua_buddy_subscribe_pres
2102 static PyObject *py_pjsua_buddy_subscribe_pres(PyObject *pSelf,
2109 PJ_UNUSED_ARG(pSelf);
2111 if (!PyArg_ParseTuple(pArgs, "ii", &buddy_id, &subscribe)) {
2115 status = pjsua_buddy_subscribe_pres(buddy_id, subscribe);
2117 return Py_BuildValue("i", status);
2121 * py_pjsua_pres_dump
2123 static PyObject *py_pjsua_pres_dump(PyObject *pSelf, PyObject *pArgs)
2127 PJ_UNUSED_ARG(pSelf);
2129 if (!PyArg_ParseTuple(pArgs, "i", &verbose)) {
2133 pjsua_pres_dump(verbose);
2135 return Py_BuildValue("");
2141 static PyObject *py_pjsua_im_send(PyObject *pSelf, PyObject *pArgs)
2145 pj_str_t *mime_type, tmp_mime_type;
2146 pj_str_t to, content;
2148 PyObject *pMimeType;
2150 pjsua_msg_data msg_data;
2153 pj_pool_t *pool = NULL;
2155 PJ_UNUSED_ARG(pSelf);
2157 if (!PyArg_ParseTuple(pArgs, "iOOOOi", &acc_id,
2158 &pTo, &pMimeType, &pContent, &pMsgData, &user_data))
2163 if (pMimeType != Py_None) {
2164 mime_type = &tmp_mime_type;
2165 tmp_mime_type = PyString_ToPJ(pMimeType);
2170 to = PyString_ToPJ(pTo);
2171 content = PyString_ToPJ(pContent);
2173 pjsua_msg_data_init(&msg_data);
2175 if (pMsgData != Py_None) {
2176 PyObj_pjsua_msg_data *omd;
2178 omd = (PyObj_pjsua_msg_data *)pMsgData;
2179 msg_data.content_type = PyString_ToPJ(omd->content_type);
2180 msg_data.msg_body = PyString_ToPJ(omd->msg_body);
2181 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
2182 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
2185 status = pjsua_im_send(acc_id, &to, mime_type, &content,
2186 &msg_data, (void*)(long)user_data);
2188 pj_pool_release(pool);
2190 return Py_BuildValue("i",status);
2194 * py_pjsua_im_typing
2196 static PyObject *py_pjsua_im_typing(PyObject *pSelf, PyObject *pArgs)
2203 pjsua_msg_data msg_data;
2205 pj_pool_t *pool = NULL;
2207 PJ_UNUSED_ARG(pSelf);
2209 if (!PyArg_ParseTuple(pArgs, "iOiO", &acc_id, &pTo, &is_typing,
2215 to = PyString_ToPJ(pTo);
2217 pjsua_msg_data_init(&msg_data);
2219 if (pMsgData != Py_None) {
2220 PyObj_pjsua_msg_data *omd;
2222 omd = (PyObj_pjsua_msg_data *)pMsgData;
2223 msg_data.content_type = PyString_ToPJ(omd->content_type);
2224 msg_data.msg_body = PyString_ToPJ(omd->msg_body);
2225 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
2227 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
2230 status = pjsua_im_typing(acc_id, &to, is_typing, &msg_data);
2233 pj_pool_release(pool);
2235 return Py_BuildValue("i", status);
2238 static char pjsua_buddy_config_default_doc[] =
2239 "_pjsua.Buddy_Config _pjsua.buddy_config_default () "
2240 "Set default values to the buddy config.";
2241 static char pjsua_get_buddy_count_doc[] =
2242 "int _pjsua.get_buddy_count () "
2243 "Get total number of buddies.";
2244 static char pjsua_buddy_is_valid_doc[] =
2245 "int _pjsua.buddy_is_valid (int buddy_id) "
2246 "Check if buddy ID is valid.";
2247 static char pjsua_enum_buddies_doc[] =
2248 "int[] _pjsua.enum_buddies () "
2250 static char pjsua_buddy_get_info_doc[] =
2251 "_pjsua.Buddy_Info _pjsua.buddy_get_info (int buddy_id) "
2252 "Get detailed buddy info.";
2253 static char pjsua_buddy_add_doc[] =
2254 "int,int _pjsua.buddy_add (_pjsua.Buddy_Config cfg) "
2256 static char pjsua_buddy_del_doc[] =
2257 "int _pjsua.buddy_del (int buddy_id) "
2259 static char pjsua_buddy_subscribe_pres_doc[] =
2260 "int _pjsua.buddy_subscribe_pres (int buddy_id, int subscribe) "
2261 "Enable/disable buddy's presence monitoring.";
2262 static char pjsua_pres_dump_doc[] =
2263 "void _pjsua.pres_dump (int verbose) "
2264 "Dump presence subscriptions to log file.";
2265 static char pjsua_im_send_doc[] =
2266 "int _pjsua.im_send (int acc_id, string to, string mime_type, "
2267 "string content, _pjsua.Msg_Data msg_data, int user_data) "
2268 "Send instant messaging outside dialog, using the specified account "
2269 "for route set and authentication.";
2270 static char pjsua_im_typing_doc[] =
2271 "int _pjsua.im_typing (int acc_id, string to, int is_typing, "
2272 "_pjsua.Msg_Data msg_data) "
2273 "Send typing indication outside dialog.";
2275 /* END OF LIB BUDDY */
2281 * py_pjsua_conf_get_max_ports
2283 static PyObject *py_pjsua_conf_get_max_ports(PyObject *pSelf, PyObject *pArgs)
2285 PJ_UNUSED_ARG(pSelf);
2286 PJ_UNUSED_ARG(pArgs);
2288 return Py_BuildValue("i", pjsua_conf_get_max_ports());
2292 * py_pjsua_conf_get_active_ports
2294 static PyObject *py_pjsua_conf_get_active_ports(PyObject *pSelf,
2297 PJ_UNUSED_ARG(pSelf);
2298 PJ_UNUSED_ARG(pArgs);
2300 return Py_BuildValue("i", pjsua_conf_get_active_ports());
2304 * py_pjsua_enum_conf_ports
2306 static PyObject *py_pjsua_enum_conf_ports(PyObject *pSelf, PyObject *pArgs)
2310 pjsua_conf_port_id id[PJSUA_MAX_CONF_PORTS];
2313 PJ_UNUSED_ARG(pSelf);
2314 PJ_UNUSED_ARG(pArgs);
2316 c = PJ_ARRAY_SIZE(id);
2317 status = pjsua_enum_conf_ports(id, &c);
2318 if (status != PJ_SUCCESS)
2321 list = PyList_New(c);
2322 for (i = 0; i < c; i++) {
2323 PyList_SetItem(list, i, Py_BuildValue("i", id[i]));
2326 return (PyObject*)list;
2330 * py_pjsua_conf_get_port_info
2332 static PyObject *py_pjsua_conf_get_port_info(PyObject *pSelf, PyObject *pArgs)
2335 PyObj_pjsua_conf_port_info *ret;
2336 pjsua_conf_port_info info;
2340 PJ_UNUSED_ARG(pSelf);
2342 if (!PyArg_ParseTuple(pArgs, "i", &id)) {
2346 status = pjsua_conf_get_port_info(id, &info);
2347 ret = (PyObj_pjsua_conf_port_info *)
2348 conf_port_info_new(&PyTyp_pjsua_conf_port_info, NULL, NULL);
2349 ret->bits_per_sample = info.bits_per_sample;
2350 ret->channel_count = info.channel_count;
2351 ret->clock_rate = info.clock_rate;
2352 ret->name = PyString_FromPJ(&info.name);
2353 ret->samples_per_frame = info.samples_per_frame;
2354 ret->slot_id = info.slot_id;
2355 Py_XDECREF(ret->listeners);
2356 ret->listeners = PyList_New(info.listener_cnt);
2357 for (i = 0; i < info.listener_cnt; i++) {
2358 PyObject *item = Py_BuildValue("i",info.listeners[i]);
2359 PyList_SetItem(ret->listeners, i, item);
2361 return (PyObject*)ret;
2365 * py_pjsua_conf_remove_port
2367 static PyObject *py_pjsua_conf_remove_port(PyObject *pSelf, PyObject *pArgs)
2372 PJ_UNUSED_ARG(pSelf);
2374 if (!PyArg_ParseTuple(pArgs, "i", &id)) {
2378 status = pjsua_conf_remove_port(id);
2380 return Py_BuildValue("i", status);
2384 * py_pjsua_conf_connect
2386 static PyObject *py_pjsua_conf_connect(PyObject *pSelf, PyObject *pArgs)
2391 PJ_UNUSED_ARG(pSelf);
2393 if (!PyArg_ParseTuple(pArgs, "ii", &source, &sink)) {
2397 status = pjsua_conf_connect(source, sink);
2399 return Py_BuildValue("i", status);
2403 * py_pjsua_conf_disconnect
2405 static PyObject *py_pjsua_conf_disconnect(PyObject *pSelf, PyObject *pArgs)
2410 PJ_UNUSED_ARG(pSelf);
2412 if (!PyArg_ParseTuple(pArgs, "ii", &source, &sink)) {
2416 status = pjsua_conf_disconnect(source, sink);
2418 return Py_BuildValue("i", status);
2422 * py_pjsua_conf_set_tx_level
2424 static PyObject *py_pjsua_conf_set_tx_level(PyObject *pSelf, PyObject *pArgs)
2430 PJ_UNUSED_ARG(pSelf);
2432 if (!PyArg_ParseTuple(pArgs, "if", &slot, &level)) {
2436 status = pjsua_conf_adjust_tx_level(slot, level);
2438 return Py_BuildValue("i", status);
2442 * py_pjsua_conf_set_rx_level
2444 static PyObject *py_pjsua_conf_set_rx_level(PyObject *pSelf, PyObject *pArgs)
2450 PJ_UNUSED_ARG(pSelf);
2452 if (!PyArg_ParseTuple(pArgs, "if", &slot, &level)) {
2456 status = pjsua_conf_adjust_rx_level(slot, level);
2458 return Py_BuildValue("i", status);
2462 * py_pjsua_conf_get_signal_level
2464 static PyObject *py_pjsua_conf_get_signal_level(PyObject *pSelf,
2468 unsigned tx_level, rx_level;
2471 PJ_UNUSED_ARG(pSelf);
2473 if (!PyArg_ParseTuple(pArgs, "i", &slot)) {
2477 status = pjsua_conf_get_signal_level(slot, &tx_level, &rx_level);
2479 return Py_BuildValue("iff", status, (float)(tx_level/255.0),
2480 (float)(rx_level/255.0));
2484 * py_pjsua_player_create
2486 static PyObject *py_pjsua_player_create(PyObject *pSelf, PyObject *pArgs)
2490 PyObject *pFilename;
2494 PJ_UNUSED_ARG(pSelf);
2496 if (!PyArg_ParseTuple(pArgs, "Oi", &pFilename, &options)) {
2500 filename = PyString_ToPJ(pFilename);
2501 status = pjsua_player_create(&filename, options, &id);
2503 return Py_BuildValue("ii", status, id);
2507 * py_pjsua_playlist_create
2509 static PyObject *py_pjsua_playlist_create(PyObject *pSelf, PyObject *pArgs)
2513 PyObject *pLabel, *pFileList;
2519 PJ_UNUSED_ARG(pSelf);
2521 if (!PyArg_ParseTuple(pArgs, "OOi", &pLabel, &pFileList, &options)) {
2525 label = PyString_ToPJ(pLabel);
2526 if (!PyList_Check(pFileList))
2527 return Py_BuildValue("ii", PJ_EINVAL, PJSUA_INVALID_ID);
2530 for (count=0; count<PyList_Size(pFileList) &&
2531 count<PJ_ARRAY_SIZE(files); ++count)
2533 files[count] = PyString_ToPJ(PyList_GetItem(pFileList, count));
2536 status = pjsua_playlist_create(files, count, &label, options, &id);
2538 return Py_BuildValue("ii", status, id);
2542 * py_pjsua_player_get_conf_port
2544 static PyObject *py_pjsua_player_get_conf_port(PyObject *pSelf,
2550 PJ_UNUSED_ARG(pSelf);
2552 if (!PyArg_ParseTuple(pArgs, "i", &id)) {
2556 port_id = pjsua_player_get_conf_port(id);
2558 return Py_BuildValue("i", port_id);
2562 * py_pjsua_player_set_pos
2564 static PyObject *py_pjsua_player_set_pos(PyObject *pSelf, PyObject *pArgs)
2570 PJ_UNUSED_ARG(pSelf);
2572 if (!PyArg_ParseTuple(pArgs, "ii", &id, &samples)) {
2579 status = pjsua_player_set_pos(id, samples);
2581 return Py_BuildValue("i", status);
2585 * py_pjsua_player_destroy
2587 static PyObject *py_pjsua_player_destroy(PyObject *pSelf, PyObject *pArgs)
2592 PJ_UNUSED_ARG(pSelf);
2594 if (!PyArg_ParseTuple(pArgs, "i", &id)) {
2598 status = pjsua_player_destroy(id);
2600 return Py_BuildValue("i", status);
2604 * py_pjsua_recorder_create
2606 static PyObject *py_pjsua_recorder_create(PyObject *pSelf, PyObject *pArgs)
2610 PyObject *pFilename, *pEncParam;
2616 PJ_UNUSED_ARG(pSelf);
2618 if (!PyArg_ParseTuple(pArgs, "OiOii", &pFilename, &enc_type, &pEncParam,
2619 &max_size, &options))
2624 filename = PyString_ToPJ(pFilename);
2626 status = pjsua_recorder_create(&filename, enc_type, NULL, max_size,
2629 return Py_BuildValue("ii", status, id);
2633 * py_pjsua_recorder_get_conf_port
2635 static PyObject *py_pjsua_recorder_get_conf_port(PyObject *pSelf,
2641 PJ_UNUSED_ARG(pSelf);
2643 if (!PyArg_ParseTuple(pArgs, "i", &id)) {
2647 port_id = pjsua_recorder_get_conf_port(id);
2649 return Py_BuildValue("i", port_id);
2653 * py_pjsua_recorder_destroy
2655 static PyObject *py_pjsua_recorder_destroy(PyObject *pSelf, PyObject *pArgs)
2660 PJ_UNUSED_ARG(pSelf);
2662 if (!PyArg_ParseTuple(pArgs, "i", &id)) {
2666 status = pjsua_recorder_destroy(id);
2668 return Py_BuildValue("i", status);
2672 * py_pjsua_enum_snd_devs
2674 static PyObject *py_pjsua_enum_snd_devs(PyObject *pSelf, PyObject *pArgs)
2678 pjmedia_snd_dev_info info[SND_DEV_NUM];
2681 PJ_UNUSED_ARG(pSelf);
2682 PJ_UNUSED_ARG(pArgs);
2684 c = PJ_ARRAY_SIZE(info);
2685 status = pjsua_enum_snd_devs(info, &c);
2686 if (status != PJ_SUCCESS)
2689 ret = PyList_New(c);
2690 for (i = 0; i < c; i++) {
2691 PyObj_pjmedia_snd_dev_info * obj;
2693 obj = (PyObj_pjmedia_snd_dev_info *)
2694 pjmedia_snd_dev_info_new(&PyTyp_pjmedia_snd_dev_info,
2696 obj->default_samples_per_sec = info[i].default_samples_per_sec;
2697 obj->input_count = info[i].input_count;
2698 obj->output_count = info[i].output_count;
2699 obj->name = PyString_FromString(info[i].name);
2701 PyList_SetItem(ret, i, (PyObject *)obj);
2704 return (PyObject*)ret;
2708 * py_pjsua_get_snd_dev
2710 static PyObject *py_pjsua_get_snd_dev(PyObject *pSelf, PyObject *pArgs)
2712 int capture_dev, playback_dev;
2715 PJ_UNUSED_ARG(pSelf);
2716 PJ_UNUSED_ARG(pArgs);
2718 status = pjsua_get_snd_dev(&capture_dev, &playback_dev);
2720 return Py_BuildValue("ii", capture_dev, playback_dev);
2724 * py_pjsua_set_snd_dev
2726 static PyObject *py_pjsua_set_snd_dev(PyObject *pSelf, PyObject *pArgs)
2728 int capture_dev, playback_dev;
2731 PJ_UNUSED_ARG(pSelf);
2733 if (!PyArg_ParseTuple(pArgs, "ii", &capture_dev, &playback_dev)) {
2737 status = pjsua_set_snd_dev(capture_dev, playback_dev);
2739 return Py_BuildValue("i", status);
2743 * py_pjsua_set_null_snd_dev
2745 static PyObject *py_pjsua_set_null_snd_dev(PyObject *pSelf, PyObject *pArgs)
2749 PJ_UNUSED_ARG(pSelf);
2750 PJ_UNUSED_ARG(pArgs);
2752 status = pjsua_set_null_snd_dev();
2754 return Py_BuildValue("i", status);
2760 static PyObject *py_pjsua_set_ec(PyObject *pSelf, PyObject *pArgs)
2766 PJ_UNUSED_ARG(pSelf);
2768 if (!PyArg_ParseTuple(pArgs, "ii", &tail_ms, &options)) {
2772 status = pjsua_set_ec(tail_ms, options);
2774 return Py_BuildValue("i", status);
2778 * py_pjsua_get_ec_tail
2780 static PyObject *py_pjsua_get_ec_tail(PyObject *pSelf, PyObject *pArgs)
2785 PJ_UNUSED_ARG(pSelf);
2786 PJ_UNUSED_ARG(pArgs);
2788 status = pjsua_get_ec_tail(&tail_ms);
2789 if (status != PJ_SUCCESS)
2792 return Py_BuildValue("i", tail_ms);
2796 * py_pjsua_enum_codecs
2798 static PyObject *py_pjsua_enum_codecs(PyObject *pSelf, PyObject *pArgs)
2802 pjsua_codec_info info[PJMEDIA_CODEC_MGR_MAX_CODECS];
2805 PJ_UNUSED_ARG(pSelf);
2806 PJ_UNUSED_ARG(pArgs);
2808 c = PJ_ARRAY_SIZE(info);
2809 status = pjsua_enum_codecs(info, &c);
2810 if (status != PJ_SUCCESS)
2813 ret = PyList_New(c);
2814 for (i = 0; i < c; i++) {
2815 PyObj_pjsua_codec_info * obj;
2816 obj = (PyObj_pjsua_codec_info *)
2817 codec_info_new(&PyTyp_pjsua_codec_info, NULL, NULL);
2818 obj->codec_id = PyString_FromPJ(&info[i].codec_id);
2819 obj->priority = info[i].priority;
2821 PyList_SetItem(ret, i, (PyObject *)obj);
2824 return (PyObject*)ret;
2828 * py_pjsua_codec_set_priority
2830 static PyObject *py_pjsua_codec_set_priority(PyObject *pSelf, PyObject *pArgs)
2837 PJ_UNUSED_ARG(pSelf);
2839 if (!PyArg_ParseTuple(pArgs, "Oi", &pCodecId, &priority)) {
2843 codec_id = PyString_ToPJ(pCodecId);
2849 status = pjsua_codec_set_priority(&codec_id, (pj_uint8_t)priority);
2851 return Py_BuildValue("i", status);
2855 * py_pjsua_codec_get_param
2857 static PyObject *py_pjsua_codec_get_param(PyObject *pSelf, PyObject *pArgs)
2862 pjmedia_codec_param param;
2863 PyObj_pjmedia_codec_param *ret;
2865 PJ_UNUSED_ARG(pSelf);
2867 if (!PyArg_ParseTuple(pArgs, "O", &pCodecId)) {
2871 codec_id = PyString_ToPJ(pCodecId);
2873 status = pjsua_codec_get_param(&codec_id, ¶m);
2874 if (status != PJ_SUCCESS)
2875 return Py_BuildValue("");
2877 ret = (PyObj_pjmedia_codec_param *)
2878 pjmedia_codec_param_new(&PyTyp_pjmedia_codec_param, NULL, NULL);
2880 ret->info->avg_bps = param.info.avg_bps;
2881 ret->info->channel_cnt = param.info.channel_cnt;
2882 ret->info->clock_rate = param.info.clock_rate;
2883 ret->info->frm_ptime = param.info.frm_ptime;
2884 ret->info->pcm_bits_per_sample = param.info.pcm_bits_per_sample;
2885 ret->info->pt = param.info.pt;
2886 ret->setting->cng = param.setting.cng;
2887 //ret->setting->dec_fmtp_mode = param.setting.dec_fmtp_mode;
2888 //ret->setting->enc_fmtp_mode = param.setting.enc_fmtp_mode;
2889 ret->setting->frm_per_pkt = param.setting.frm_per_pkt;
2890 ret->setting->penh = param.setting.penh;
2891 ret->setting->plc = param.setting.plc;
2892 ret->setting->vad = param.setting.vad;
2894 return (PyObject*)ret;
2899 * py_pjsua_codec_set_param
2901 static PyObject *py_pjsua_codec_set_param(PyObject *pSelf, PyObject *pArgs)
2904 PyObject *pCodecId, *pCodecParam;
2906 pjmedia_codec_param param;
2908 PJ_UNUSED_ARG(pSelf);
2910 if (!PyArg_ParseTuple(pArgs, "OO", &pCodecId, &pCodecParam)) {
2914 codec_id = PyString_ToPJ(pCodecId);
2916 if (pCodecParam != Py_None) {
2917 PyObj_pjmedia_codec_param *obj;
2919 obj = (PyObj_pjmedia_codec_param *)pCodecParam;
2921 param.info.avg_bps = obj->info->avg_bps;
2922 param.info.channel_cnt = obj->info->channel_cnt;
2923 param.info.clock_rate = obj->info->clock_rate;
2924 param.info.frm_ptime = obj->info->frm_ptime;
2925 param.info.pcm_bits_per_sample = obj->info->pcm_bits_per_sample;
2926 param.info.pt = obj->info->pt;
2927 param.setting.cng = obj->setting->cng;
2928 //param.setting.dec_fmtp_mode = obj->setting->dec_fmtp_mode;
2929 //param.setting.enc_fmtp_mode = obj->setting->enc_fmtp_mode;
2930 param.setting.frm_per_pkt = obj->setting->frm_per_pkt;
2931 param.setting.penh = obj->setting->penh;
2932 param.setting.plc = obj->setting->plc;
2933 param.setting.vad = obj->setting->vad;
2934 status = pjsua_codec_set_param(&codec_id, ¶m);
2937 status = pjsua_codec_set_param(&codec_id, NULL);
2940 return Py_BuildValue("i", status);
2943 static char pjsua_conf_get_max_ports_doc[] =
2944 "int _pjsua.conf_get_max_ports () "
2945 "Get maxinum number of conference ports.";
2946 static char pjsua_conf_get_active_ports_doc[] =
2947 "int _pjsua.conf_get_active_ports () "
2948 "Get current number of active ports in the bridge.";
2949 static char pjsua_enum_conf_ports_doc[] =
2950 "int[] _pjsua.enum_conf_ports () "
2951 "Enumerate all conference ports.";
2952 static char pjsua_conf_get_port_info_doc[] =
2953 "_pjsua.Conf_Port_Info _pjsua.conf_get_port_info (int id) "
2954 "Get information about the specified conference port";
2955 static char pjsua_conf_remove_port_doc[] =
2956 "int _pjsua.conf_remove_port (int id) "
2957 "Remove arbitrary slot from the conference bridge. "
2958 "Application should only call this function "
2959 "if it registered the port manually.";
2960 static char pjsua_conf_connect_doc[] =
2961 "int _pjsua.conf_connect (int source, int sink) "
2962 "Establish unidirectional media flow from souce to sink. "
2963 "One source may transmit to multiple destinations/sink. "
2964 "And if multiple sources are transmitting to the same sink, "
2965 "the media will be mixed together. Source and sink may refer "
2966 "to the same ID, effectively looping the media. "
2967 "If bidirectional media flow is desired, application "
2968 "needs to call this function twice, with the second "
2969 "one having the arguments reversed.";
2970 static char pjsua_conf_disconnect_doc[] =
2971 "int _pjsua.conf_disconnect (int source, int sink) "
2972 "Disconnect media flow from the source to destination port.";
2973 static char pjsua_player_create_doc[] =
2974 "int, int _pjsua.player_create (string filename, int options) "
2975 "Create a file player, and automatically connect "
2976 "this player to the conference bridge.";
2977 static char pjsua_player_get_conf_port_doc[] =
2978 "int _pjsua.player_get_conf_port (int) "
2979 "Get conference port ID associated with player.";
2980 static char pjsua_player_set_pos_doc[] =
2981 "int _pjsua.player_set_pos (int id, int samples) "
2982 "Set playback position.";
2983 static char pjsua_player_destroy_doc[] =
2984 "int _pjsua.player_destroy (int id) "
2985 "Close the file, remove the player from the bridge, "
2986 "and free resources associated with the file player.";
2987 static char pjsua_recorder_create_doc[] =
2988 "int, int _pjsua.recorder_create (string filename, "
2989 "int enc_type, int enc_param, int max_size, int options) "
2990 "Create a file recorder, and automatically connect this recorder "
2991 "to the conference bridge. The recorder currently supports recording "
2992 "WAV file, and on Windows, MP3 file. The type of the recorder to use "
2993 "is determined by the extension of the file (e.g. '.wav' or '.mp3').";
2994 static char pjsua_recorder_get_conf_port_doc[] =
2995 "int _pjsua.recorder_get_conf_port (int id) "
2996 "Get conference port associated with recorder.";
2997 static char pjsua_recorder_destroy_doc[] =
2998 "int _pjsua.recorder_destroy (int id) "
2999 "Destroy recorder (this will complete recording).";
3000 static char pjsua_enum_snd_devs_doc[] =
3001 "_pjsua.PJMedia_Snd_Dev_Info[] _pjsua.enum_snd_devs (int count) "
3002 "Enum sound devices.";
3003 static char pjsua_get_snd_dev_doc[] =
3004 "int, int _pjsua.get_snd_dev () "
3005 "Get currently active sound devices. "
3006 "If sound devices has not been created "
3007 "(for example when pjsua_start() is not called), "
3008 "it is possible that the function returns "
3009 "PJ_SUCCESS with -1 as device IDs.";
3010 static char pjsua_set_snd_dev_doc[] =
3011 "int _pjsua.set_snd_dev (int capture_dev, int playback_dev) "
3012 "Select or change sound device. Application may call this function "
3013 "at any time to replace current sound device.";
3014 static char pjsua_set_null_snd_dev_doc[] =
3015 "int _pjsua.set_null_snd_dev () "
3016 "Set pjsua to use null sound device. The null sound device only "
3017 "provides the timing needed by the conference bridge, and will not "
3018 "interract with any hardware.";
3019 static char pjsua_set_ec_doc[] =
3020 "int _pjsua.set_ec (int tail_ms, int options) "
3021 "Configure the echo canceller tail length of the sound port.";
3022 static char pjsua_get_ec_tail_doc[] =
3023 "int _pjsua.get_ec_tail () "
3024 "Get current echo canceller tail length.";
3025 static char pjsua_enum_codecs_doc[] =
3026 "_pjsua.Codec_Info[] _pjsua.enum_codecs () "
3027 "Enum all supported codecs in the system.";
3028 static char pjsua_codec_set_priority_doc[] =
3029 "int _pjsua.codec_set_priority (string id, int priority) "
3030 "Change codec priority.";
3031 static char pjsua_codec_get_param_doc[] =
3032 "_pjsua.PJMedia_Codec_Param _pjsua.codec_get_param (string id) "
3033 "Get codec parameters";
3034 static char pjsua_codec_set_param_doc[] =
3035 "int _pjsua.codec_set_param (string id, "
3036 "_pjsua.PJMedia_Codec_Param param) "
3037 "Set codec parameters.";
3039 /* END OF LIB MEDIA */
3044 * py_pjsua_call_get_max_count
3046 static PyObject *py_pjsua_call_get_max_count(PyObject *pSelf, PyObject *pArgs)
3050 PJ_UNUSED_ARG(pSelf);
3051 PJ_UNUSED_ARG(pArgs);
3053 count = pjsua_call_get_max_count();
3055 return Py_BuildValue("i", count);
3059 * py_pjsua_call_get_count
3061 static PyObject *py_pjsua_call_get_count(PyObject *pSelf, PyObject *pArgs)
3065 PJ_UNUSED_ARG(pSelf);
3066 PJ_UNUSED_ARG(pArgs);
3068 count = pjsua_call_get_count();
3070 return Py_BuildValue("i", count);
3074 * py_pjsua_enum_calls
3076 static PyObject *py_pjsua_enum_calls(PyObject *pSelf, PyObject *pArgs)
3080 pjsua_transport_id id[PJSUA_MAX_CALLS];
3083 PJ_UNUSED_ARG(pSelf);
3084 PJ_UNUSED_ARG(pArgs);
3086 c = PJ_ARRAY_SIZE(id);
3087 status = pjsua_enum_calls(id, &c);
3088 if (status != PJ_SUCCESS)
3091 ret = PyList_New(c);
3092 for (i = 0; i < c; i++) {
3093 PyList_SetItem(ret, i, Py_BuildValue("i", id[i]));
3096 return (PyObject*)ret;
3100 * py_pjsua_call_make_call
3102 static PyObject *py_pjsua_call_make_call(PyObject *pSelf, PyObject *pArgs)
3107 PyObject *pDstUri, *pMsgData, *pUserData;
3109 pjsua_msg_data msg_data;
3111 pj_pool_t *pool = NULL;
3113 PJ_UNUSED_ARG(pSelf);
3115 if (!PyArg_ParseTuple(pArgs, "iOIOO", &acc_id, &pDstUri, &options,
3116 &pUserData, &pMsgData))
3121 dst_uri = PyString_ToPJ(pDstUri);
3122 pjsua_msg_data_init(&msg_data);
3124 if (pMsgData != Py_None) {
3125 PyObj_pjsua_msg_data * omd;
3127 omd = (PyObj_pjsua_msg_data *)pMsgData;
3129 msg_data.content_type = PyString_ToPJ(omd->content_type);
3130 msg_data.msg_body = PyString_ToPJ(omd->msg_body);
3131 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
3132 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
3135 Py_XINCREF(pUserData);
3137 status = pjsua_call_make_call(acc_id, &dst_uri,
3138 options, (void*)pUserData,
3139 &msg_data, &call_id);
3141 pj_pool_release(pool);
3143 if (status != PJ_SUCCESS) {
3144 Py_XDECREF(pUserData);
3147 return Py_BuildValue("ii", status, call_id);
3151 * py_pjsua_call_is_active
3153 static PyObject *py_pjsua_call_is_active(PyObject *pSelf, PyObject *pArgs)
3158 PJ_UNUSED_ARG(pSelf);
3160 if (!PyArg_ParseTuple(pArgs, "i", &call_id)) {
3164 is_active = pjsua_call_is_active(call_id);
3166 return Py_BuildValue("i", is_active);
3170 * py_pjsua_call_has_media
3172 static PyObject *py_pjsua_call_has_media(PyObject *pSelf, PyObject *pArgs)
3177 PJ_UNUSED_ARG(pSelf);
3179 if (!PyArg_ParseTuple(pArgs, "i", &call_id)) {
3183 has_media = pjsua_call_has_media(call_id);
3185 return Py_BuildValue("i", has_media);
3189 * py_pjsua_call_get_conf_port
3191 static PyObject* py_pjsua_call_get_conf_port(PyObject *pSelf, PyObject *pArgs)
3196 PJ_UNUSED_ARG(pSelf);
3198 if (!PyArg_ParseTuple(pArgs, "i", &call_id)) {
3202 port_id = pjsua_call_get_conf_port(call_id);
3204 return Py_BuildValue("i", port_id);
3208 * py_pjsua_call_get_info
3210 static PyObject* py_pjsua_call_get_info(PyObject *pSelf, PyObject *pArgs)
3214 PyObj_pjsua_call_info *ret;
3215 pjsua_call_info info;
3217 PJ_UNUSED_ARG(pSelf);
3219 if (!PyArg_ParseTuple(pArgs, "i", &call_id)) {
3223 status = pjsua_call_get_info(call_id, &info);
3224 if (status != PJ_SUCCESS)
3225 return Py_BuildValue("");
3227 ret = (PyObj_pjsua_call_info *)call_info_new(&PyTyp_pjsua_call_info,
3229 ret->acc_id = info.acc_id;
3230 Py_XDECREF(ret->call_id);
3231 ret->call_id = PyString_FromPJ(&info.call_id);
3232 ret->conf_slot = info.conf_slot;
3233 ret->connect_duration = info.connect_duration.sec * 1000 +
3234 info.connect_duration.msec;
3235 ret->total_duration = info.total_duration.sec * 1000 +
3236 info.total_duration.msec;
3238 ret->last_status = info.last_status;
3239 Py_XDECREF(ret->last_status_text);
3240 ret->last_status_text = PyString_FromPJ(&info.last_status_text);
3241 Py_XDECREF(ret->local_contact);
3242 ret->local_contact = PyString_FromPJ(&info.local_contact);
3243 Py_XDECREF(ret->local_info);
3244 ret->local_info = PyString_FromPJ(&info.local_info);
3245 Py_XDECREF(ret->remote_contact);
3246 ret->remote_contact = PyString_FromPJ(&info.remote_contact);
3247 Py_XDECREF(ret->remote_info);
3248 ret->remote_info = PyString_FromPJ(&info.remote_info);
3249 ret->media_dir = info.media_dir;
3250 ret->media_status = info.media_status;
3251 ret->role = info.role;
3252 ret->state = info.state;
3253 Py_XDECREF(ret->state_text);
3254 ret->state_text = PyString_FromPJ(&info.state_text);
3256 return (PyObject*)ret;
3260 * py_pjsua_call_set_user_data
3262 static PyObject *py_pjsua_call_set_user_data(PyObject *pSelf, PyObject *pArgs)
3265 PyObject *pUserData, *old_user_data;
3268 PJ_UNUSED_ARG(pSelf);
3270 if (!PyArg_ParseTuple(pArgs, "iO", &call_id, &pUserData)) {
3274 old_user_data = (PyObject*) pjsua_call_get_user_data(call_id);
3276 if (old_user_data == pUserData) {
3277 return Py_BuildValue("i", PJ_SUCCESS);
3280 Py_XINCREF(pUserData);
3281 Py_XDECREF(old_user_data);
3283 status = pjsua_call_set_user_data(call_id, (void*)pUserData);
3285 if (status != PJ_SUCCESS) {
3286 Py_XDECREF(pUserData);
3289 return Py_BuildValue("i", status);
3293 * py_pjsua_call_get_user_data
3295 static PyObject *py_pjsua_call_get_user_data(PyObject *pSelf, PyObject *pArgs)
3298 PyObject *user_data;
3300 PJ_UNUSED_ARG(pSelf);
3302 if (!PyArg_ParseTuple(pArgs, "i", &call_id)) {
3306 user_data = (PyObject*)pjsua_call_get_user_data(call_id);
3307 return user_data ? Py_BuildValue("O", user_data) : Py_BuildValue("");
3311 * py_pjsua_call_answer
3313 static PyObject *py_pjsua_call_answer(PyObject *pSelf, PyObject *pArgs)
3317 pj_str_t * reason, tmp_reason;
3320 pjsua_msg_data msg_data;
3322 pj_pool_t * pool = NULL;
3324 PJ_UNUSED_ARG(pSelf);
3326 if (!PyArg_ParseTuple(pArgs, "iIOO", &call_id, &code, &pReason, &omdObj)) {
3330 if (pReason == Py_None) {
3333 reason = &tmp_reason;
3334 tmp_reason = PyString_ToPJ(pReason);
3337 pjsua_msg_data_init(&msg_data);
3338 if (omdObj != Py_None) {
3339 PyObj_pjsua_msg_data *omd;
3341 omd = (PyObj_pjsua_msg_data *)omdObj;
3342 msg_data.content_type = PyString_ToPJ(omd->content_type);
3343 msg_data.msg_body = PyString_ToPJ(omd->msg_body);
3344 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
3345 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
3348 status = pjsua_call_answer(call_id, code, reason, &msg_data);
3351 pj_pool_release(pool);
3353 return Py_BuildValue("i", status);
3357 * py_pjsua_call_hangup
3359 static PyObject *py_pjsua_call_hangup(PyObject *pSelf, PyObject *pArgs)
3363 pj_str_t *reason, tmp_reason;
3366 pjsua_msg_data msg_data;
3368 pj_pool_t *pool = NULL;
3370 PJ_UNUSED_ARG(pSelf);
3372 if (!PyArg_ParseTuple(pArgs, "iIOO", &call_id, &code, &pReason,
3378 if (pReason == Py_None) {
3381 reason = &tmp_reason;
3382 tmp_reason = PyString_ToPJ(pReason);
3385 pjsua_msg_data_init(&msg_data);
3386 if (omdObj != Py_None) {
3387 PyObj_pjsua_msg_data *omd;
3389 omd = (PyObj_pjsua_msg_data *)omdObj;
3390 msg_data.content_type = PyString_ToPJ(omd->content_type);
3391 msg_data.msg_body = PyString_ToPJ(omd->msg_body);
3392 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
3393 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
3396 status = pjsua_call_hangup(call_id, code, reason, &msg_data);
3398 pj_pool_release(pool);
3400 return Py_BuildValue("i", status);
3404 * py_pjsua_call_set_hold
3406 static PyObject *py_pjsua_call_set_hold(PyObject *pSelf, PyObject *pArgs)
3410 pjsua_msg_data msg_data;
3412 pj_pool_t *pool = NULL;
3414 PJ_UNUSED_ARG(pSelf);
3416 if (!PyArg_ParseTuple(pArgs, "iO", &call_id, &omdObj)) {
3420 pjsua_msg_data_init(&msg_data);
3421 if (omdObj != Py_None) {
3422 PyObj_pjsua_msg_data *omd;