blob: 2766d17a51b2da49a32819980fcc971480a892b9 [file] [log] [blame]
Benny Prijono572d4852006-11-23 21:50:02 +00001/* $Id$ */
2/*
Nanang Izzuddina62ffc92011-05-05 06:14:19 +00003 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
Benny Prijono32177c02008-06-20 22:44:47 +00004 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
Benny Prijono572d4852006-11-23 21:50:02 +00005 *
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.
10 *
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.
15 *
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
19 */
Benny Prijono1f63cc42007-09-10 16:54:22 +000020#include "py_pjsua.h"
Benny Prijono8b8b9972006-11-16 11:18:03 +000021
Benny Prijono572d4852006-11-23 21:50:02 +000022#define THIS_FILE "main.c"
Fahris6f35cb82007-02-01 07:41:26 +000023#define POOL_SIZE 4000
24#define SND_DEV_NUM 64
Fahrise314b882007-02-02 10:52:04 +000025#define SND_NAME_LEN 64
Benny Prijono8b8b9972006-11-16 11:18:03 +000026
Benny Prijono98793592006-12-04 08:33:20 +000027/* LIB BASE */
28
Benny Prijonoda275f62007-02-18 23:49:14 +000029static PyObject* obj_log_cb;
Benny Prijonoed7a5a72007-01-29 18:36:38 +000030static long thread_id;
Benny Prijono572d4852006-11-23 21:50:02 +000031
Benny Prijonoda275f62007-02-18 23:49:14 +000032#define ENTER_PYTHON() PyGILState_STATE state = PyGILState_Ensure()
33#define LEAVE_PYTHON() PyGILState_Release(state)
34
Benny Prijono572d4852006-11-23 21:50:02 +000035/*
Benny Prijonoda275f62007-02-18 23:49:14 +000036 * cb_log_cb
Benny Prijono572d4852006-11-23 21:50:02 +000037 * declares method for reconfiguring logging process for callback struct
38 */
Benny Prijono429fa1f2008-01-18 17:18:55 +000039static void cb_log_cb(int level, const char *data, int len)
Benny Prijono572d4852006-11-23 21:50:02 +000040{
Fahris17d91812007-01-29 12:09:33 +000041
Benny Prijonoed7a5a72007-01-29 18:36:38 +000042 /* Ignore if this callback is called from alien thread context,
43 * or otherwise it will crash Python.
44 */
45 if (pj_thread_local_get(thread_id) == 0)
46 return;
47
Benny Prijonoda275f62007-02-18 23:49:14 +000048 if (PyCallable_Check(obj_log_cb))
Benny Prijono572d4852006-11-23 21:50:02 +000049 {
Benny Prijonoda275f62007-02-18 23:49:14 +000050 ENTER_PYTHON();
51
Benny Prijono572d4852006-11-23 21:50:02 +000052 PyObject_CallFunctionObjArgs(
Benny Prijonoda275f62007-02-18 23:49:14 +000053 obj_log_cb, Py_BuildValue("i",level),
Benny Prijono572d4852006-11-23 21:50:02 +000054 PyString_FromString(data), Py_BuildValue("i",len), NULL
55 );
Benny Prijonoda275f62007-02-18 23:49:14 +000056
57 LEAVE_PYTHON();
Benny Prijono572d4852006-11-23 21:50:02 +000058 }
59}
60
61
Benny Prijono572d4852006-11-23 21:50:02 +000062
63/*
64 * The global callback object.
65 */
Benny Prijono1f63cc42007-09-10 16:54:22 +000066static PyObj_pjsua_callback * g_obj_callback;
Benny Prijono572d4852006-11-23 21:50:02 +000067
68
69/*
70 * cb_on_call_state
71 * declares method on_call_state for callback struct
72 */
73static void cb_on_call_state(pjsua_call_id call_id, pjsip_event *e)
74{
Benny Prijonoed7a5a72007-01-29 18:36:38 +000075 if (PyCallable_Check(g_obj_callback->on_call_state))
Fahris17d91812007-01-29 12:09:33 +000076 {
Benny Prijono1f63cc42007-09-10 16:54:22 +000077 PyObj_pjsip_event * obj;
Benny Prijonoda275f62007-02-18 23:49:14 +000078
79 ENTER_PYTHON();
80
Benny Prijono1f63cc42007-09-10 16:54:22 +000081 obj = (PyObj_pjsip_event *)PyType_GenericNew(&PyTyp_pjsip_event,
Benny Prijonoda275f62007-02-18 23:49:14 +000082 NULL, NULL);
Fahris17d91812007-01-29 12:09:33 +000083
Fahris6f35cb82007-02-01 07:41:26 +000084 obj->event = e;
Fahris17d91812007-01-29 12:09:33 +000085
Benny Prijono572d4852006-11-23 21:50:02 +000086 PyObject_CallFunctionObjArgs(
Benny Prijono1f63cc42007-09-10 16:54:22 +000087 g_obj_callback->on_call_state,
88 Py_BuildValue("i",call_id),
89 obj,
90 NULL
Benny Prijono572d4852006-11-23 21:50:02 +000091 );
Benny Prijonoda275f62007-02-18 23:49:14 +000092
93 LEAVE_PYTHON();
Benny Prijono572d4852006-11-23 21:50:02 +000094 }
95}
96
97
98/*
99 * cb_on_incoming_call
100 * declares method on_incoming_call for callback struct
101 */
102static void cb_on_incoming_call(pjsua_acc_id acc_id, pjsua_call_id call_id,
103 pjsip_rx_data *rdata)
104{
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000105 if (PyCallable_Check(g_obj_callback->on_incoming_call))
Benny Prijono572d4852006-11-23 21:50:02 +0000106 {
Benny Prijono1f63cc42007-09-10 16:54:22 +0000107 PyObj_pjsip_rx_data * obj;
Benny Prijonoda275f62007-02-18 23:49:14 +0000108
109 ENTER_PYTHON();
110
Benny Prijono1f63cc42007-09-10 16:54:22 +0000111 obj = (PyObj_pjsip_rx_data *)PyType_GenericNew(&PyTyp_pjsip_rx_data,
Benny Prijono572d4852006-11-23 21:50:02 +0000112 NULL, NULL);
113 obj->rdata = rdata;
114
115 PyObject_CallFunctionObjArgs(
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000116 g_obj_callback->on_incoming_call,
Benny Prijono572d4852006-11-23 21:50:02 +0000117 Py_BuildValue("i",acc_id),
118 Py_BuildValue("i",call_id),
119 obj,
120 NULL
121 );
Benny Prijonoda275f62007-02-18 23:49:14 +0000122
123 LEAVE_PYTHON();
Benny Prijono572d4852006-11-23 21:50:02 +0000124 }
125}
126
127
128/*
129 * cb_on_call_media_state
130 * declares method on_call_media_state for callback struct
131 */
132static void cb_on_call_media_state(pjsua_call_id call_id)
133{
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000134 if (PyCallable_Check(g_obj_callback->on_call_media_state))
Benny Prijono572d4852006-11-23 21:50:02 +0000135 {
Benny Prijonoda275f62007-02-18 23:49:14 +0000136 ENTER_PYTHON();
137
Benny Prijono1f63cc42007-09-10 16:54:22 +0000138 PyObject_CallFunction(
139 g_obj_callback->on_call_media_state,
140 "i",
141 call_id,
142 NULL
143 );
144
145 LEAVE_PYTHON();
146 }
147}
148
149
150/*
151 * cb_on_dtmf_digit()
152 * Callback from PJSUA-LIB on receiving DTMF digit
153 */
154static void cb_on_dtmf_digit(pjsua_call_id call_id, int digit)
155{
Benny Prijono0c97d532008-02-14 15:50:46 +0000156 if (PyCallable_Check(g_obj_callback->on_dtmf_digit))
Benny Prijono1f63cc42007-09-10 16:54:22 +0000157 {
158 char digit_str[10];
159
160 ENTER_PYTHON();
161
162 pj_ansi_snprintf(digit_str, sizeof(digit_str), "%c", digit);
163
164 PyObject_CallFunctionObjArgs(
Benny Prijono0c97d532008-02-14 15:50:46 +0000165 g_obj_callback->on_dtmf_digit,
Benny Prijono1f63cc42007-09-10 16:54:22 +0000166 Py_BuildValue("i",call_id),
167 PyString_FromString(digit_str),
168 NULL
169 );
Benny Prijonoda275f62007-02-18 23:49:14 +0000170
171 LEAVE_PYTHON();
Benny Prijono572d4852006-11-23 21:50:02 +0000172 }
173}
174
175
176/*
177 * Notify application on call being transfered.
Benny Prijonodc308702006-12-09 00:39:42 +0000178 * !modified @061206
Benny Prijono572d4852006-11-23 21:50:02 +0000179 */
180static void cb_on_call_transfer_request(pjsua_call_id call_id,
181 const pj_str_t *dst,
182 pjsip_status_code *code)
183{
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000184 if (PyCallable_Check(g_obj_callback->on_call_transfer_request))
Benny Prijono572d4852006-11-23 21:50:02 +0000185 {
Benny Prijonoda275f62007-02-18 23:49:14 +0000186 PyObject * ret;
187 int cd;
188
189 ENTER_PYTHON();
190
Benny Prijonodc308702006-12-09 00:39:42 +0000191 ret = PyObject_CallFunctionObjArgs(
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000192 g_obj_callback->on_call_transfer_request,
Benny Prijono572d4852006-11-23 21:50:02 +0000193 Py_BuildValue("i",call_id),
194 PyString_FromStringAndSize(dst->ptr, dst->slen),
195 Py_BuildValue("i",*code),
196 NULL
197 );
Benny Prijonodc308702006-12-09 00:39:42 +0000198 if (ret != NULL) {
199 if (ret != Py_None) {
200 if (PyArg_Parse(ret,"i",&cd)) {
201 *code = cd;
202 }
203 }
204 }
Benny Prijonoda275f62007-02-18 23:49:14 +0000205
206 LEAVE_PYTHON();
Benny Prijono572d4852006-11-23 21:50:02 +0000207 }
208}
209
210
211/*
212 * Notify application of the status of previously sent call
213 * transfer request. Application can monitor the status of the
214 * call transfer request, for example to decide whether to
215 * terminate existing call.
Benny Prijonodc308702006-12-09 00:39:42 +0000216 * !modified @061206
Benny Prijono572d4852006-11-23 21:50:02 +0000217 */
218static void cb_on_call_transfer_status( pjsua_call_id call_id,
219 int status_code,
220 const pj_str_t *status_text,
221 pj_bool_t final,
222 pj_bool_t *p_cont)
223{
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000224 if (PyCallable_Check(g_obj_callback->on_call_transfer_status))
Benny Prijono572d4852006-11-23 21:50:02 +0000225 {
Benny Prijonoda275f62007-02-18 23:49:14 +0000226 PyObject * ret;
227 int cnt;
228
229 ENTER_PYTHON();
230
Benny Prijonodc308702006-12-09 00:39:42 +0000231 ret = PyObject_CallFunctionObjArgs(
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000232 g_obj_callback->on_call_transfer_status,
Benny Prijono572d4852006-11-23 21:50:02 +0000233 Py_BuildValue("i",call_id),
234 Py_BuildValue("i",status_code),
235 PyString_FromStringAndSize(status_text->ptr, status_text->slen),
236 Py_BuildValue("i",final),
237 Py_BuildValue("i",*p_cont),
238 NULL
239 );
Benny Prijonodc308702006-12-09 00:39:42 +0000240 if (ret != NULL) {
241 if (ret != Py_None) {
242 if (PyArg_Parse(ret,"i",&cnt)) {
243 *p_cont = cnt;
244 }
245 }
246 }
Benny Prijonoda275f62007-02-18 23:49:14 +0000247
248 LEAVE_PYTHON();
Benny Prijono572d4852006-11-23 21:50:02 +0000249 }
250}
251
252
253/*
254 * Notify application about incoming INVITE with Replaces header.
255 * Application may reject the request by setting non-2xx code.
Benny Prijonodc308702006-12-09 00:39:42 +0000256 * !modified @061206
Benny Prijono572d4852006-11-23 21:50:02 +0000257 */
258static void cb_on_call_replace_request( pjsua_call_id call_id,
259 pjsip_rx_data *rdata,
260 int *st_code,
261 pj_str_t *st_text)
262{
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000263 if (PyCallable_Check(g_obj_callback->on_call_replace_request))
Benny Prijono572d4852006-11-23 21:50:02 +0000264 {
Benny Prijonoda275f62007-02-18 23:49:14 +0000265 PyObject * ret;
266 PyObject * txt;
267 int cd;
Benny Prijono1f63cc42007-09-10 16:54:22 +0000268 PyObj_pjsip_rx_data * obj;
Benny Prijonoda275f62007-02-18 23:49:14 +0000269
270 ENTER_PYTHON();
271
Benny Prijono1f63cc42007-09-10 16:54:22 +0000272 obj = (PyObj_pjsip_rx_data *)PyType_GenericNew(&PyTyp_pjsip_rx_data,
Benny Prijono572d4852006-11-23 21:50:02 +0000273 NULL, NULL);
Benny Prijonodc308702006-12-09 00:39:42 +0000274 obj->rdata = rdata;
Benny Prijono572d4852006-11-23 21:50:02 +0000275
Benny Prijonodc308702006-12-09 00:39:42 +0000276 ret = PyObject_CallFunctionObjArgs(
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000277 g_obj_callback->on_call_replace_request,
Benny Prijono572d4852006-11-23 21:50:02 +0000278 Py_BuildValue("i",call_id),
279 obj,
280 Py_BuildValue("i",*st_code),
281 PyString_FromStringAndSize(st_text->ptr, st_text->slen),
282 NULL
283 );
Benny Prijonodc308702006-12-09 00:39:42 +0000284 if (ret != NULL) {
285 if (ret != Py_None) {
286 if (PyArg_ParseTuple(ret,"iO",&cd, &txt)) {
287 *st_code = cd;
288 st_text->ptr = PyString_AsString(txt);
289 st_text->slen = strlen(PyString_AsString(txt));
290 }
291 }
292 }
Benny Prijonoda275f62007-02-18 23:49:14 +0000293
294 LEAVE_PYTHON();
Benny Prijono572d4852006-11-23 21:50:02 +0000295 }
296}
297
298
299/*
300 * Notify application that an existing call has been replaced with
301 * a new call. This happens when PJSUA-API receives incoming INVITE
302 * request with Replaces header.
303 */
304static void cb_on_call_replaced(pjsua_call_id old_call_id,
305 pjsua_call_id new_call_id)
306{
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000307 if (PyCallable_Check(g_obj_callback->on_call_replaced))
Benny Prijono572d4852006-11-23 21:50:02 +0000308 {
Benny Prijonoda275f62007-02-18 23:49:14 +0000309 ENTER_PYTHON();
310
Benny Prijono572d4852006-11-23 21:50:02 +0000311 PyObject_CallFunctionObjArgs(
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000312 g_obj_callback->on_call_replaced,
Benny Prijono572d4852006-11-23 21:50:02 +0000313 Py_BuildValue("i",old_call_id),
Benny Prijono1f63cc42007-09-10 16:54:22 +0000314 Py_BuildValue("i",new_call_id),
Benny Prijono572d4852006-11-23 21:50:02 +0000315 NULL
316 );
Benny Prijonoda275f62007-02-18 23:49:14 +0000317
318 LEAVE_PYTHON();
Benny Prijono572d4852006-11-23 21:50:02 +0000319 }
320}
321
322
323/*
324 * cb_on_reg_state
325 * declares method on_reg_state for callback struct
326 */
327static void cb_on_reg_state(pjsua_acc_id acc_id)
328{
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000329 if (PyCallable_Check(g_obj_callback->on_reg_state))
Benny Prijono572d4852006-11-23 21:50:02 +0000330 {
Benny Prijonoda275f62007-02-18 23:49:14 +0000331 ENTER_PYTHON();
332
Benny Prijono1f63cc42007-09-10 16:54:22 +0000333 PyObject_CallFunction(
334 g_obj_callback->on_reg_state,
335 "i",
336 acc_id,
337 NULL
338 );
Benny Prijonoda275f62007-02-18 23:49:14 +0000339
340 LEAVE_PYTHON();
Benny Prijono572d4852006-11-23 21:50:02 +0000341 }
342}
343
344
345/*
346 * cb_on_buddy_state
347 * declares method on_buddy state for callback struct
348 */
349static void cb_on_buddy_state(pjsua_buddy_id buddy_id)
350{
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000351 if (PyCallable_Check(g_obj_callback->on_buddy_state))
Benny Prijono572d4852006-11-23 21:50:02 +0000352 {
Benny Prijonoda275f62007-02-18 23:49:14 +0000353 ENTER_PYTHON();
354
Benny Prijono1f63cc42007-09-10 16:54:22 +0000355 PyObject_CallFunction(
356 g_obj_callback->on_buddy_state,
357 "i",
358 buddy_id,
359 NULL
360 );
Benny Prijonoda275f62007-02-18 23:49:14 +0000361
362 LEAVE_PYTHON();
Benny Prijono572d4852006-11-23 21:50:02 +0000363 }
364}
365
366/*
367 * cb_on_pager
Fahrise314b882007-02-02 10:52:04 +0000368 * declares method on_pager for callback struct
Benny Prijono572d4852006-11-23 21:50:02 +0000369 */
370static void cb_on_pager(pjsua_call_id call_id, const pj_str_t *from,
371 const pj_str_t *to, const pj_str_t *contact,
372 const pj_str_t *mime_type, const pj_str_t *body)
373{
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000374 if (PyCallable_Check(g_obj_callback->on_pager))
Benny Prijono572d4852006-11-23 21:50:02 +0000375 {
Benny Prijonoda275f62007-02-18 23:49:14 +0000376 ENTER_PYTHON();
377
Benny Prijono572d4852006-11-23 21:50:02 +0000378 PyObject_CallFunctionObjArgs(
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000379 g_obj_callback->on_pager,Py_BuildValue("i",call_id),
Benny Prijono572d4852006-11-23 21:50:02 +0000380 PyString_FromStringAndSize(from->ptr, from->slen),
381 PyString_FromStringAndSize(to->ptr, to->slen),
382 PyString_FromStringAndSize(contact->ptr, contact->slen),
383 PyString_FromStringAndSize(mime_type->ptr, mime_type->slen),
Benny Prijono1f63cc42007-09-10 16:54:22 +0000384 PyString_FromStringAndSize(body->ptr, body->slen),
385 NULL
Benny Prijono572d4852006-11-23 21:50:02 +0000386 );
Benny Prijonoda275f62007-02-18 23:49:14 +0000387
388 LEAVE_PYTHON();
Benny Prijono572d4852006-11-23 21:50:02 +0000389 }
390}
391
392
393/*
394 * cb_on_pager_status
395 * declares method on_pager_status for callback struct
396 */
397static void cb_on_pager_status(pjsua_call_id call_id, const pj_str_t *to,
398 const pj_str_t *body, void *user_data,
399 pjsip_status_code status,
400 const pj_str_t *reason)
401{
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000402 if (PyCallable_Check(g_obj_callback->on_pager))
Benny Prijono572d4852006-11-23 21:50:02 +0000403 {
Benny Prijonoda275f62007-02-18 23:49:14 +0000404 PyObject * obj_user_data;
405
406 ENTER_PYTHON();
407
408 obj_user_data = Py_BuildValue("i", user_data);
409
Benny Prijono572d4852006-11-23 21:50:02 +0000410 PyObject_CallFunctionObjArgs(
Benny Prijonoda275f62007-02-18 23:49:14 +0000411 g_obj_callback->on_pager_status,
412 Py_BuildValue("i",call_id),
Benny Prijono572d4852006-11-23 21:50:02 +0000413 PyString_FromStringAndSize(to->ptr, to->slen),
Benny Prijonoda275f62007-02-18 23:49:14 +0000414 PyString_FromStringAndSize(body->ptr, body->slen),
415 obj_user_data,
416 Py_BuildValue("i",status),
417 PyString_FromStringAndSize(reason->ptr,reason->slen),
418 NULL
Benny Prijono572d4852006-11-23 21:50:02 +0000419 );
Benny Prijonoda275f62007-02-18 23:49:14 +0000420
421 LEAVE_PYTHON();
Benny Prijono572d4852006-11-23 21:50:02 +0000422 }
423}
424
425
426/*
427 * cb_on_typing
428 * declares method on_typing for callback struct
429 */
430static void cb_on_typing(pjsua_call_id call_id, const pj_str_t *from,
431 const pj_str_t *to, const pj_str_t *contact,
432 pj_bool_t is_typing)
433{
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000434 if (PyCallable_Check(g_obj_callback->on_typing))
Benny Prijono572d4852006-11-23 21:50:02 +0000435 {
Benny Prijonoda275f62007-02-18 23:49:14 +0000436 ENTER_PYTHON();
437
Benny Prijono572d4852006-11-23 21:50:02 +0000438 PyObject_CallFunctionObjArgs(
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000439 g_obj_callback->on_typing,Py_BuildValue("i",call_id),
Benny Prijono572d4852006-11-23 21:50:02 +0000440 PyString_FromStringAndSize(from->ptr, from->slen),
441 PyString_FromStringAndSize(to->ptr, to->slen),
442 PyString_FromStringAndSize(contact->ptr, contact->slen),
Benny Prijono1f63cc42007-09-10 16:54:22 +0000443 Py_BuildValue("i",is_typing),
444 NULL
Benny Prijono572d4852006-11-23 21:50:02 +0000445 );
Benny Prijonoda275f62007-02-18 23:49:14 +0000446
447 LEAVE_PYTHON();
Benny Prijono572d4852006-11-23 21:50:02 +0000448 }
449}
450
451
Benny Prijono572d4852006-11-23 21:50:02 +0000452
Benny Prijonodc308702006-12-09 00:39:42 +0000453/*
454 * translate_hdr
455 * internal function
456 * translate from hdr_list to pjsip_generic_string_hdr
457 */
458void translate_hdr(pj_pool_t *pool, pjsip_hdr *hdr, PyObject *py_hdr_list)
459{
Benny Prijonoda275f62007-02-18 23:49:14 +0000460 pj_list_init(hdr);
Benny Prijonodc308702006-12-09 00:39:42 +0000461
462 if (PyList_Check(py_hdr_list)) {
Benny Prijonoda275f62007-02-18 23:49:14 +0000463 int i;
Benny Prijonodc308702006-12-09 00:39:42 +0000464
Fahris6f35cb82007-02-01 07:41:26 +0000465 for (i = 0; i < PyList_Size(py_hdr_list); i++)
466 {
Benny Prijonodc308702006-12-09 00:39:42 +0000467 pj_str_t hname, hvalue;
468 pjsip_generic_string_hdr * new_hdr;
469 PyObject * tuple = PyList_GetItem(py_hdr_list, i);
470
Fahris6f35cb82007-02-01 07:41:26 +0000471 if (PyTuple_Check(tuple))
472 {
Benny Prijonodc308702006-12-09 00:39:42 +0000473 hname.ptr = PyString_AsString(PyTuple_GetItem(tuple,0));
Fahris17d91812007-01-29 12:09:33 +0000474 hname.slen = strlen(PyString_AsString
475 (PyTuple_GetItem(tuple,0)));
Benny Prijonodc308702006-12-09 00:39:42 +0000476 hvalue.ptr = PyString_AsString(PyTuple_GetItem(tuple,1));
Fahris17d91812007-01-29 12:09:33 +0000477 hvalue.slen = strlen(PyString_AsString
478 (PyTuple_GetItem(tuple,1)));
Benny Prijonodc308702006-12-09 00:39:42 +0000479 } else {
480 hname.ptr = "";
481 hname.slen = 0;
482 hvalue.ptr = "";
483 hvalue.slen = 0;
484 }
485 new_hdr = pjsip_generic_string_hdr_create(pool, &hname, &hvalue);
486 pj_list_push_back((pj_list_type *)hdr, (pj_list_type *)new_hdr);
487 }
488 }
489}
490
491/*
492 * translate_hdr_rev
493 * internal function
494 * translate from pjsip_generic_string_hdr to hdr_list
495 */
496
497void translate_hdr_rev(pjsip_generic_string_hdr *hdr, PyObject *py_hdr_list)
498{
499 int i;
500 int len;
501 pjsip_generic_string_hdr * p_hdr;
502
503 len = pj_list_size(hdr);
504
Fahris6f35cb82007-02-01 07:41:26 +0000505 if (len > 0)
506 {
507 p_hdr = hdr;
Benny Prijonodc308702006-12-09 00:39:42 +0000508 Py_XDECREF(py_hdr_list);
509 py_hdr_list = PyList_New(len);
510
Fahris6f35cb82007-02-01 07:41:26 +0000511 for (i = 0; i < len && p_hdr != NULL; i++)
512 {
513 PyObject * tuple;
514 PyObject * str;
Benny Prijonodc308702006-12-09 00:39:42 +0000515
Fahris6f35cb82007-02-01 07:41:26 +0000516 tuple = PyTuple_New(2);
Benny Prijonodc308702006-12-09 00:39:42 +0000517
Fahris6f35cb82007-02-01 07:41:26 +0000518 str = PyString_FromStringAndSize(p_hdr->name.ptr, p_hdr->name.slen);
519 PyTuple_SetItem(tuple, 0, str);
520 str = PyString_FromStringAndSize
521 (hdr->hvalue.ptr, p_hdr->hvalue.slen);
522 PyTuple_SetItem(tuple, 1, str);
523 PyList_SetItem(py_hdr_list, i, tuple);
524 p_hdr = p_hdr->next;
Benny Prijonodc308702006-12-09 00:39:42 +0000525 }
526 }
527
528
529}
Benny Prijono572d4852006-11-23 21:50:02 +0000530
531/*
Benny Prijonodc308702006-12-09 00:39:42 +0000532 * py_pjsua_thread_register
533 * !added @ 061206
534 */
Benny Prijono1f63cc42007-09-10 16:54:22 +0000535static PyObject *py_pjsua_thread_register(PyObject *pSelf, PyObject *pArgs)
Benny Prijonodc308702006-12-09 00:39:42 +0000536{
537
538 pj_status_t status;
539 const char *name;
540 PyObject *py_desc;
541 pj_thread_t *thread;
542 void *thread_desc;
Fahrisdcf8fa42006-12-28 03:13:48 +0000543#if 0
Benny Prijonodc308702006-12-09 00:39:42 +0000544 int size;
545 int i;
546 int *td;
Fahrisdcf8fa42006-12-28 03:13:48 +0000547#endif
Benny Prijonodc308702006-12-09 00:39:42 +0000548
Benny Prijono1f63cc42007-09-10 16:54:22 +0000549 PJ_UNUSED_ARG(pSelf);
550
Benny Prijonodc308702006-12-09 00:39:42 +0000551 if (!PyArg_ParseTuple(pArgs, "sO", &name, &py_desc))
552 {
553 return NULL;
554 }
555#if 0
556 size = PyList_Size(py_desc);
557 td = (int *)malloc(size * sizeof(int));
Fahris6f35cb82007-02-01 07:41:26 +0000558 for (i = 0; i < size; i++)
559 {
560 if (!PyArg_Parse(PyList_GetItem(py_desc,i),"i", td[i]))
561 {
Benny Prijonodc308702006-12-09 00:39:42 +0000562 return NULL;
563 }
564 }
565 thread_desc = td;
566#else
567 thread_desc = malloc(sizeof(pj_thread_desc));
568#endif
569 status = pj_thread_register(name, thread_desc, &thread);
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000570
571 if (status == PJ_SUCCESS)
572 status = pj_thread_local_set(thread_id, (void*)1);
Benny Prijonodc308702006-12-09 00:39:42 +0000573 return Py_BuildValue("i",status);
574}
Benny Prijono572d4852006-11-23 21:50:02 +0000575
576/*
577 * py_pjsua_logging_config_default
Benny Prijonodc308702006-12-09 00:39:42 +0000578 * !modified @ 051206
Benny Prijono572d4852006-11-23 21:50:02 +0000579 */
580static PyObject *py_pjsua_logging_config_default(PyObject *pSelf,
581 PyObject *pArgs)
582{
Benny Prijono1f63cc42007-09-10 16:54:22 +0000583 PyObj_pjsua_logging_config *obj;
Benny Prijono572d4852006-11-23 21:50:02 +0000584 pjsua_logging_config cfg;
585
Benny Prijono1f63cc42007-09-10 16:54:22 +0000586 PJ_UNUSED_ARG(pSelf);
587
Benny Prijonodc308702006-12-09 00:39:42 +0000588 if (!PyArg_ParseTuple(pArgs, ""))
Benny Prijono572d4852006-11-23 21:50:02 +0000589 {
590 return NULL;
591 }
Benny Prijonodc308702006-12-09 00:39:42 +0000592
Benny Prijono572d4852006-11-23 21:50:02 +0000593 pjsua_logging_config_default(&cfg);
Benny Prijono1f63cc42007-09-10 16:54:22 +0000594 obj = (PyObj_pjsua_logging_config *) PyObj_pjsua_logging_config_new
595 (&PyTyp_pjsua_logging_config,NULL,NULL);
596 PyObj_pjsua_logging_config_import(obj, &cfg);
Benny Prijonodc308702006-12-09 00:39:42 +0000597
598 return (PyObject *)obj;
Benny Prijono572d4852006-11-23 21:50:02 +0000599}
600
601
602/*
603 * py_pjsua_config_default
Benny Prijonodc308702006-12-09 00:39:42 +0000604 * !modified @ 051206
Benny Prijono572d4852006-11-23 21:50:02 +0000605 */
606static PyObject *py_pjsua_config_default(PyObject *pSelf, PyObject *pArgs)
607{
Benny Prijono1f63cc42007-09-10 16:54:22 +0000608 PyObj_pjsua_config *obj;
Benny Prijono572d4852006-11-23 21:50:02 +0000609 pjsua_config cfg;
610
Benny Prijono1f63cc42007-09-10 16:54:22 +0000611 PJ_UNUSED_ARG(pSelf);
612
Benny Prijonodc308702006-12-09 00:39:42 +0000613 if (!PyArg_ParseTuple(pArgs, ""))
Benny Prijono572d4852006-11-23 21:50:02 +0000614 {
615 return NULL;
616 }
617 pjsua_config_default(&cfg);
Benny Prijono1f63cc42007-09-10 16:54:22 +0000618 obj = (PyObj_pjsua_config *) PyObj_pjsua_config_new(&PyTyp_pjsua_config, NULL, NULL);
619 PyObj_pjsua_config_import(obj, &cfg);
620
Benny Prijonodc308702006-12-09 00:39:42 +0000621 return (PyObject *)obj;
Benny Prijono572d4852006-11-23 21:50:02 +0000622}
623
624
625/*
626 * py_pjsua_media_config_default
Benny Prijonodc308702006-12-09 00:39:42 +0000627 * !modified @ 051206
Benny Prijono572d4852006-11-23 21:50:02 +0000628 */
629static PyObject * py_pjsua_media_config_default(PyObject *pSelf,
630 PyObject *pArgs)
631{
Benny Prijono1f63cc42007-09-10 16:54:22 +0000632 PyObj_pjsua_media_config *obj;
Benny Prijono572d4852006-11-23 21:50:02 +0000633 pjsua_media_config cfg;
Benny Prijono1f63cc42007-09-10 16:54:22 +0000634
635 PJ_UNUSED_ARG(pSelf);
636
Benny Prijonodc308702006-12-09 00:39:42 +0000637 if (!PyArg_ParseTuple(pArgs, ""))
Benny Prijono572d4852006-11-23 21:50:02 +0000638 {
639 return NULL;
640 }
641 pjsua_media_config_default(&cfg);
Benny Prijono1f63cc42007-09-10 16:54:22 +0000642 obj = (PyObj_pjsua_media_config *)
643 PyType_GenericNew(&PyTyp_pjsua_media_config, NULL, NULL);
644 PyObj_pjsua_media_config_import(obj, &cfg);
Benny Prijonodc308702006-12-09 00:39:42 +0000645 return (PyObject *)obj;
Benny Prijono572d4852006-11-23 21:50:02 +0000646}
647
648
649/*
650 * py_pjsua_msg_data_init
Benny Prijonodc308702006-12-09 00:39:42 +0000651 * !modified @ 051206
Benny Prijono572d4852006-11-23 21:50:02 +0000652 */
653static PyObject *py_pjsua_msg_data_init(PyObject *pSelf, PyObject *pArgs)
654{
Benny Prijono1f63cc42007-09-10 16:54:22 +0000655 PyObj_pjsua_msg_data *obj;
Benny Prijono572d4852006-11-23 21:50:02 +0000656 pjsua_msg_data msg;
Benny Prijonodc308702006-12-09 00:39:42 +0000657
Benny Prijono1f63cc42007-09-10 16:54:22 +0000658 PJ_UNUSED_ARG(pSelf);
659
Benny Prijonodc308702006-12-09 00:39:42 +0000660 if (!PyArg_ParseTuple(pArgs, ""))
Benny Prijono572d4852006-11-23 21:50:02 +0000661 {
662 return NULL;
663 }
664 pjsua_msg_data_init(&msg);
Benny Prijono1f63cc42007-09-10 16:54:22 +0000665 obj = (PyObj_pjsua_msg_data *)PyObj_pjsua_msg_data_new(&PyTyp_pjsua_msg_data, NULL, NULL);
Benny Prijono572d4852006-11-23 21:50:02 +0000666 Py_XDECREF(obj->content_type);
667 obj->content_type = PyString_FromStringAndSize(
668 msg.content_type.ptr, msg.content_type.slen
669 );
670 Py_XDECREF(obj->msg_body);
671 obj->msg_body = PyString_FromStringAndSize(
672 msg.msg_body.ptr, msg.msg_body.slen
673 );
Benny Prijono572d4852006-11-23 21:50:02 +0000674
Fahris17d91812007-01-29 12:09:33 +0000675 translate_hdr_rev((pjsip_generic_string_hdr *)&msg.hdr_list,obj->hdr_list);
Benny Prijonodc308702006-12-09 00:39:42 +0000676
677 return (PyObject *)obj;
Benny Prijono572d4852006-11-23 21:50:02 +0000678}
679
680
681/*
682 * py_pjsua_reconfigure_logging
683 */
684static PyObject *py_pjsua_reconfigure_logging(PyObject *pSelf, PyObject *pArgs)
685{
Fahris6f35cb82007-02-01 07:41:26 +0000686 PyObject * logObj;
Benny Prijono1f63cc42007-09-10 16:54:22 +0000687 PyObj_pjsua_logging_config *log;
Benny Prijono572d4852006-11-23 21:50:02 +0000688 pjsua_logging_config cfg;
689 pj_status_t status;
690
Benny Prijono1f63cc42007-09-10 16:54:22 +0000691 PJ_UNUSED_ARG(pSelf);
692
Fahris17d91812007-01-29 12:09:33 +0000693 if (!PyArg_ParseTuple(pArgs, "O", &logObj))
Benny Prijono572d4852006-11-23 21:50:02 +0000694 {
695 return NULL;
696 }
Fahris6f35cb82007-02-01 07:41:26 +0000697 if (logObj != Py_None)
698 {
Benny Prijono1f63cc42007-09-10 16:54:22 +0000699 log = (PyObj_pjsua_logging_config *)logObj;
Fahris17d91812007-01-29 12:09:33 +0000700 cfg.msg_logging = log->msg_logging;
701 cfg.level = log->level;
702 cfg.console_level = log->console_level;
703 cfg.decor = log->decor;
704 cfg.log_filename.ptr = PyString_AsString(log->log_filename);
705 cfg.log_filename.slen = strlen(cfg.log_filename.ptr);
Benny Prijonoda275f62007-02-18 23:49:14 +0000706 Py_XDECREF(obj_log_cb);
707 obj_log_cb = log->cb;
708 Py_INCREF(obj_log_cb);
709 cfg.cb = &cb_log_cb;
Fahris17d91812007-01-29 12:09:33 +0000710 status = pjsua_reconfigure_logging(&cfg);
711 } else {
712 status = pjsua_reconfigure_logging(NULL);
Fahris6f35cb82007-02-01 07:41:26 +0000713 }
Benny Prijono572d4852006-11-23 21:50:02 +0000714 return Py_BuildValue("i",status);
715}
716
717
718/*
719 * py_pjsua_pool_create
720 */
721static PyObject *py_pjsua_pool_create(PyObject *pSelf, PyObject *pArgs)
722{
723 pj_size_t init_size;
724 pj_size_t increment;
725 const char * name;
726 pj_pool_t *p;
Benny Prijono1f63cc42007-09-10 16:54:22 +0000727 PyObj_pj_pool *pool;
728
729 PJ_UNUSED_ARG(pSelf);
Benny Prijono572d4852006-11-23 21:50:02 +0000730
731 if (!PyArg_ParseTuple(pArgs, "sII", &name, &init_size, &increment))
732 {
733 return NULL;
734 }
Fahris89ea3d02007-02-07 08:18:35 +0000735
Benny Prijono572d4852006-11-23 21:50:02 +0000736 p = pjsua_pool_create(name, init_size, increment);
Benny Prijono1f63cc42007-09-10 16:54:22 +0000737 pool = (PyObj_pj_pool *)PyType_GenericNew(&PyTyp_pj_pool_t, NULL, NULL);
Benny Prijono572d4852006-11-23 21:50:02 +0000738 pool->pool = p;
739 return (PyObject *)pool;
740
741}
742
743
744/*
745 * py_pjsua_get_pjsip_endpt
746 */
747static PyObject *py_pjsua_get_pjsip_endpt(PyObject *pSelf, PyObject *pArgs)
748{
Benny Prijono1f63cc42007-09-10 16:54:22 +0000749 PyObj_pjsip_endpoint *endpt;
Benny Prijono572d4852006-11-23 21:50:02 +0000750 pjsip_endpoint *e;
751
Benny Prijono1f63cc42007-09-10 16:54:22 +0000752 PJ_UNUSED_ARG(pSelf);
753
Benny Prijono572d4852006-11-23 21:50:02 +0000754 if (!PyArg_ParseTuple(pArgs, ""))
755 {
756 return NULL;
757 }
758 e = pjsua_get_pjsip_endpt();
Benny Prijono1f63cc42007-09-10 16:54:22 +0000759 endpt = (PyObj_pjsip_endpoint *)PyType_GenericNew(
760 &PyTyp_pjsip_endpoint, NULL, NULL
Benny Prijono572d4852006-11-23 21:50:02 +0000761 );
762 endpt->endpt = e;
763 return (PyObject *)endpt;
764}
765
766
767/*
768 * py_pjsua_get_pjmedia_endpt
769 */
770static PyObject *py_pjsua_get_pjmedia_endpt(PyObject *pSelf, PyObject *pArgs)
771{
Benny Prijono1f63cc42007-09-10 16:54:22 +0000772 PyObj_pjmedia_endpt *endpt;
Benny Prijono572d4852006-11-23 21:50:02 +0000773 pjmedia_endpt *e;
774
Benny Prijono1f63cc42007-09-10 16:54:22 +0000775 PJ_UNUSED_ARG(pSelf);
776
Benny Prijono572d4852006-11-23 21:50:02 +0000777 if (!PyArg_ParseTuple(pArgs, ""))
778 {
779 return NULL;
780 }
781 e = pjsua_get_pjmedia_endpt();
Benny Prijono1f63cc42007-09-10 16:54:22 +0000782 endpt = (PyObj_pjmedia_endpt *)PyType_GenericNew(
783 &PyTyp_pjmedia_endpt, NULL, NULL
Benny Prijono572d4852006-11-23 21:50:02 +0000784 );
785 endpt->endpt = e;
786 return (PyObject *)endpt;
787}
788
789
790/*
791 * py_pjsua_get_pool_factory
792 */
793static PyObject *py_pjsua_get_pool_factory(PyObject *pSelf, PyObject *pArgs)
794{
Benny Prijono1f63cc42007-09-10 16:54:22 +0000795 PyObj_pj_pool_factory *pool;
Benny Prijono572d4852006-11-23 21:50:02 +0000796 pj_pool_factory *p;
797
Benny Prijono1f63cc42007-09-10 16:54:22 +0000798 PJ_UNUSED_ARG(pSelf);
799
Benny Prijono572d4852006-11-23 21:50:02 +0000800 if (!PyArg_ParseTuple(pArgs, ""))
801 {
802 return NULL;
803 }
804 p = pjsua_get_pool_factory();
Benny Prijono1f63cc42007-09-10 16:54:22 +0000805 pool = (PyObj_pj_pool_factory *)PyType_GenericNew(
806 &PyTyp_pj_pool_factory, NULL, NULL
Benny Prijono572d4852006-11-23 21:50:02 +0000807 );
808 pool->pool_fact = p;
809 return (PyObject *)pool;
810}
811
812
813/*
814 * py_pjsua_perror
815 */
816static PyObject *py_pjsua_perror(PyObject *pSelf, PyObject *pArgs)
817{
818 const char *sender;
819 const char *title;
820 pj_status_t status;
Benny Prijono1f63cc42007-09-10 16:54:22 +0000821
822 PJ_UNUSED_ARG(pSelf);
823
Benny Prijono572d4852006-11-23 21:50:02 +0000824 if (!PyArg_ParseTuple(pArgs, "ssi", &sender, &title, &status))
825 {
826 return NULL;
827 }
Benny Prijonodc308702006-12-09 00:39:42 +0000828
Benny Prijono572d4852006-11-23 21:50:02 +0000829 pjsua_perror(sender, title, status);
830 Py_INCREF(Py_None);
831 return Py_None;
832}
833
834
835/*
836 * py_pjsua_create
837 */
838static PyObject *py_pjsua_create(PyObject *pSelf, PyObject *pArgs)
839{
840 pj_status_t status;
Benny Prijono1f63cc42007-09-10 16:54:22 +0000841
842 PJ_UNUSED_ARG(pSelf);
843
Benny Prijono572d4852006-11-23 21:50:02 +0000844 if (!PyArg_ParseTuple(pArgs, ""))
845 {
846 return NULL;
847 }
848 status = pjsua_create();
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000849
Fahris6f35cb82007-02-01 07:41:26 +0000850 if (status == PJ_SUCCESS)
851 {
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000852 status = pj_thread_local_alloc(&thread_id);
853 if (status == PJ_SUCCESS)
854 status = pj_thread_local_set(thread_id, (void*)1);
855 }
856
Benny Prijono572d4852006-11-23 21:50:02 +0000857 return Py_BuildValue("i",status);
858}
859
860
861/*
862 * py_pjsua_init
863 */
864static PyObject *py_pjsua_init(PyObject *pSelf, PyObject *pArgs)
865{
866 pj_status_t status;
Benny Prijono1f63cc42007-09-10 16:54:22 +0000867 PyObject *o_ua_cfg, *o_log_cfg, *o_media_cfg;
868 pjsua_config cfg_ua, *p_cfg_ua;
869 pjsua_logging_config cfg_log, *p_cfg_log;
870 pjsua_media_config cfg_media, *p_cfg_media;
Benny Prijono572d4852006-11-23 21:50:02 +0000871
Benny Prijono1f63cc42007-09-10 16:54:22 +0000872 PJ_UNUSED_ARG(pSelf);
873
874 if (!PyArg_ParseTuple(pArgs, "OOO", &o_ua_cfg, &o_log_cfg, &o_media_cfg))
Benny Prijono572d4852006-11-23 21:50:02 +0000875 {
876 return NULL;
877 }
Fahris17d91812007-01-29 12:09:33 +0000878
Benny Prijono572d4852006-11-23 21:50:02 +0000879 pjsua_config_default(&cfg_ua);
880 pjsua_logging_config_default(&cfg_log);
881 pjsua_media_config_default(&cfg_media);
Benny Prijono572d4852006-11-23 21:50:02 +0000882
Benny Prijono1f63cc42007-09-10 16:54:22 +0000883 if (o_ua_cfg != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +0000884 {
Benny Prijono1f63cc42007-09-10 16:54:22 +0000885 PyObj_pjsua_config *obj_ua_cfg = (PyObj_pjsua_config*)o_ua_cfg;
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000886
Benny Prijono1f63cc42007-09-10 16:54:22 +0000887 PyObj_pjsua_config_export(&cfg_ua, obj_ua_cfg);
888
889 g_obj_callback = obj_ua_cfg->cb;
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000890 Py_INCREF(g_obj_callback);
891
892 cfg_ua.cb.on_call_state = &cb_on_call_state;
893 cfg_ua.cb.on_incoming_call = &cb_on_incoming_call;
894 cfg_ua.cb.on_call_media_state = &cb_on_call_media_state;
Benny Prijono1f63cc42007-09-10 16:54:22 +0000895 cfg_ua.cb.on_dtmf_digit = &cb_on_dtmf_digit;
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000896 cfg_ua.cb.on_call_transfer_request = &cb_on_call_transfer_request;
897 cfg_ua.cb.on_call_transfer_status = &cb_on_call_transfer_status;
898 cfg_ua.cb.on_call_replace_request = &cb_on_call_replace_request;
899 cfg_ua.cb.on_call_replaced = &cb_on_call_replaced;
900 cfg_ua.cb.on_reg_state = &cb_on_reg_state;
901 cfg_ua.cb.on_buddy_state = &cb_on_buddy_state;
902 cfg_ua.cb.on_pager = &cb_on_pager;
903 cfg_ua.cb.on_pager_status = &cb_on_pager_status;
904 cfg_ua.cb.on_typing = &cb_on_typing;
Benny Prijono572d4852006-11-23 21:50:02 +0000905
Fahris17d91812007-01-29 12:09:33 +0000906 p_cfg_ua = &cfg_ua;
Benny Prijono1f63cc42007-09-10 16:54:22 +0000907
Fahris17d91812007-01-29 12:09:33 +0000908 } else {
909 p_cfg_ua = NULL;
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000910 }
911
Benny Prijono1f63cc42007-09-10 16:54:22 +0000912 if (o_log_cfg != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +0000913 {
Benny Prijono1f63cc42007-09-10 16:54:22 +0000914 PyObj_pjsua_logging_config * obj_log;
915
916 obj_log = (PyObj_pjsua_logging_config *)o_log_cfg;
917
918 PyObj_pjsua_logging_config_export(&cfg_log, obj_log);
919
Benny Prijonoda275f62007-02-18 23:49:14 +0000920 Py_XDECREF(obj_log_cb);
Benny Prijono1f63cc42007-09-10 16:54:22 +0000921 obj_log_cb = obj_log->cb;
Benny Prijonoda275f62007-02-18 23:49:14 +0000922 Py_INCREF(obj_log_cb);
Benny Prijono1f63cc42007-09-10 16:54:22 +0000923
Benny Prijonoda275f62007-02-18 23:49:14 +0000924 cfg_log.cb = &cb_log_cb;
Fahris17d91812007-01-29 12:09:33 +0000925 p_cfg_log = &cfg_log;
Benny Prijono1f63cc42007-09-10 16:54:22 +0000926
Fahris17d91812007-01-29 12:09:33 +0000927 } else {
928 p_cfg_log = NULL;
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000929 }
930
Benny Prijono1f63cc42007-09-10 16:54:22 +0000931 if (o_media_cfg != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +0000932 {
Benny Prijono1f63cc42007-09-10 16:54:22 +0000933 PyObj_pjsua_media_config_export(&cfg_media,
934 (PyObj_pjsua_media_config*)o_media_cfg);
935 p_cfg_media = &cfg_media;
936
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000937 } else {
Fahris17d91812007-01-29 12:09:33 +0000938 p_cfg_media = NULL;
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000939 }
940
Fahris17d91812007-01-29 12:09:33 +0000941 status = pjsua_init(p_cfg_ua, p_cfg_log, p_cfg_media);
Benny Prijono572d4852006-11-23 21:50:02 +0000942 return Py_BuildValue("i",status);
943}
944
945
946/*
947 * py_pjsua_start
948 */
949static PyObject *py_pjsua_start(PyObject *pSelf, PyObject *pArgs)
950{
951 pj_status_t status;
Benny Prijono1f63cc42007-09-10 16:54:22 +0000952
953 PJ_UNUSED_ARG(pSelf);
954
Benny Prijono572d4852006-11-23 21:50:02 +0000955 if (!PyArg_ParseTuple(pArgs, ""))
956 {
957 return NULL;
958 }
959 status = pjsua_start();
Fahris89ea3d02007-02-07 08:18:35 +0000960
Benny Prijono572d4852006-11-23 21:50:02 +0000961 return Py_BuildValue("i",status);
962}
963
964
965/*
966 * py_pjsua_destroy
967 */
968static PyObject *py_pjsua_destroy(PyObject *pSelf, PyObject *pArgs)
969{
970 pj_status_t status;
Benny Prijono1f63cc42007-09-10 16:54:22 +0000971
972 PJ_UNUSED_ARG(pSelf);
973
Benny Prijono572d4852006-11-23 21:50:02 +0000974 if (!PyArg_ParseTuple(pArgs, ""))
975 {
976 return NULL;
977 }
978 status = pjsua_destroy();
Fahris89ea3d02007-02-07 08:18:35 +0000979
Benny Prijono572d4852006-11-23 21:50:02 +0000980 return Py_BuildValue("i",status);
981}
982
983
984/*
985 * py_pjsua_handle_events
986 */
987static PyObject *py_pjsua_handle_events(PyObject *pSelf, PyObject *pArgs)
988{
989 int ret;
990 unsigned msec;
Benny Prijono1f63cc42007-09-10 16:54:22 +0000991
992 PJ_UNUSED_ARG(pSelf);
993
Benny Prijono572d4852006-11-23 21:50:02 +0000994 if (!PyArg_ParseTuple(pArgs, "i", &msec))
995 {
996 return NULL;
997 }
Benny Prijono4759f9c2007-02-14 02:15:19 +0000998
999 /* Since handle_events() will block, we must wrap it with ALLOW_THREADS
1000 * construct, or otherwise many Python blocking functions (such as
1001 * time.sleep(), readline(), etc.) may hang/block indefinitely.
1002 * See http://www.python.org/doc/current/api/threads.html for more info.
1003 */
1004 Py_BEGIN_ALLOW_THREADS
Benny Prijono572d4852006-11-23 21:50:02 +00001005 ret = pjsua_handle_events(msec);
Benny Prijono4759f9c2007-02-14 02:15:19 +00001006 Py_END_ALLOW_THREADS
Fahris89ea3d02007-02-07 08:18:35 +00001007
Benny Prijono572d4852006-11-23 21:50:02 +00001008 return Py_BuildValue("i",ret);
1009}
1010
1011
1012/*
1013 * py_pjsua_verify_sip_url
1014 */
1015static PyObject *py_pjsua_verify_sip_url(PyObject *pSelf, PyObject *pArgs)
1016{
1017 pj_status_t status;
1018 const char *url;
Benny Prijono1f63cc42007-09-10 16:54:22 +00001019
1020 PJ_UNUSED_ARG(pSelf);
1021
Benny Prijono572d4852006-11-23 21:50:02 +00001022 if (!PyArg_ParseTuple(pArgs, "s", &url))
1023 {
1024 return NULL;
1025 }
1026 status = pjsua_verify_sip_url(url);
Fahris89ea3d02007-02-07 08:18:35 +00001027
Benny Prijono572d4852006-11-23 21:50:02 +00001028 return Py_BuildValue("i",status);
1029}
1030
1031
Benny Prijono572d4852006-11-23 21:50:02 +00001032/*
Benny Prijonodc308702006-12-09 00:39:42 +00001033 * function doc
Benny Prijono572d4852006-11-23 21:50:02 +00001034 */
1035
Benny Prijonodc308702006-12-09 00:39:42 +00001036static char pjsua_thread_register_doc[] =
1037 "int py_pjsua.thread_register(string name, int[] desc)";
Benny Prijono572d4852006-11-23 21:50:02 +00001038static char pjsua_perror_doc[] =
1039 "void py_pjsua.perror (string sender, string title, int status) "
1040 "Display error message for the specified error code. Parameters: "
Fahris6f35cb82007-02-01 07:41:26 +00001041 "sender: The log sender field; "
1042 "title: Message title for the error; "
1043 "status: Status code.";
Benny Prijono572d4852006-11-23 21:50:02 +00001044
1045static char pjsua_create_doc[] =
1046 "int py_pjsua.create (void) "
1047 "Instantiate pjsua application. Application "
1048 "must call this function before calling any other functions, to make sure "
1049 "that the underlying libraries are properly initialized. Once this "
1050 "function has returned success, application must call pjsua_destroy() "
1051 "before quitting.";
1052
1053static char pjsua_init_doc[] =
Benny Prijono1f63cc42007-09-10 16:54:22 +00001054 "int py_pjsua.init (py_pjsua.Config obj_ua_cfg, "
Benny Prijono572d4852006-11-23 21:50:02 +00001055 "py_pjsua.Logging_Config log_cfg, py_pjsua.Media_Config media_cfg) "
1056 "Initialize pjsua with the specified settings. All the settings are "
1057 "optional, and the default values will be used when the config is not "
1058 "specified. Parameters: "
Benny Prijono1f63cc42007-09-10 16:54:22 +00001059 "obj_ua_cfg : User agent configuration; "
Fahris6f35cb82007-02-01 07:41:26 +00001060 "log_cfg : Optional logging configuration; "
1061 "media_cfg : Optional media configuration.";
Benny Prijono572d4852006-11-23 21:50:02 +00001062
1063static char pjsua_start_doc[] =
1064 "int py_pjsua.start (void) "
1065 "Application is recommended to call this function after all "
1066 "initialization is done, so that the library can do additional checking "
1067 "set up additional";
1068
1069static char pjsua_destroy_doc[] =
1070 "int py_pjsua.destroy (void) "
1071 "Destroy pjsua This function must be called once PJSUA is created. To "
1072 "make it easier for application, application may call this function "
1073 "several times with no danger.";
1074
1075static char pjsua_handle_events_doc[] =
1076 "int py_pjsua.handle_events (int msec_timeout) "
1077 "Poll pjsua for events, and if necessary block the caller thread for the "
1078 "specified maximum interval (in miliseconds) Parameters: "
Fahris6f35cb82007-02-01 07:41:26 +00001079 "msec_timeout: Maximum time to wait, in miliseconds. "
Benny Prijono572d4852006-11-23 21:50:02 +00001080 "Returns: The number of events that have been handled during the poll. "
1081 "Negative value indicates error, and application can retrieve the error "
1082 "as (err = -return_value).";
1083
1084static char pjsua_verify_sip_url_doc[] =
1085 "int py_pjsua.verify_sip_url (string c_url) "
1086 "Verify that valid SIP url is given Parameters: "
Fahris6f35cb82007-02-01 07:41:26 +00001087 "c_url: The URL, as NULL terminated string.";
Benny Prijono572d4852006-11-23 21:50:02 +00001088
1089static char pjsua_pool_create_doc[] =
Benny Prijono1f63cc42007-09-10 16:54:22 +00001090 "py_pjsua.Pj_Pool py_pjsua.pool_create (string name, int init_size, "
Benny Prijono572d4852006-11-23 21:50:02 +00001091 "int increment) "
1092 "Create memory pool Parameters: "
Fahris6f35cb82007-02-01 07:41:26 +00001093 "name: Optional pool name; "
1094 "init_size: Initial size of the pool; "
1095 "increment: Increment size.";
Benny Prijono572d4852006-11-23 21:50:02 +00001096
1097static char pjsua_get_pjsip_endpt_doc[] =
Benny Prijono1f63cc42007-09-10 16:54:22 +00001098 "py_pjsua.Pjsip_Endpoint py_pjsua.get_pjsip_endpt (void) "
Benny Prijono572d4852006-11-23 21:50:02 +00001099 "Internal function to get SIP endpoint instance of pjsua, which is needed "
1100 "for example to register module, create transports, etc. Probably is only "
1101 "valid after pjsua_init() is called.";
1102
1103static char pjsua_get_pjmedia_endpt_doc[] =
Benny Prijono1f63cc42007-09-10 16:54:22 +00001104 "py_pjsua.Pjmedia_Endpt py_pjsua.get_pjmedia_endpt (void) "
Benny Prijono572d4852006-11-23 21:50:02 +00001105 "Internal function to get media endpoint instance. Only valid after "
1106 "pjsua_init() is called.";
1107
1108static char pjsua_get_pool_factory_doc[] =
Benny Prijono1f63cc42007-09-10 16:54:22 +00001109 "py_pjsua.Pj_Pool_Factory py_pjsua.get_pool_factory (void) "
Benny Prijono572d4852006-11-23 21:50:02 +00001110 "Internal function to get PJSUA pool factory. Only valid after "
1111 "pjsua_init() is called.";
1112
1113static char pjsua_reconfigure_logging_doc[] =
1114 "int py_pjsua.reconfigure_logging (py_pjsua.Logging_Config c) "
1115 "Application can call this function at any time (after pjsua_create(), of "
1116 "course) to change logging settings. Parameters: "
Fahris6f35cb82007-02-01 07:41:26 +00001117 "c: Logging configuration.";
Benny Prijono572d4852006-11-23 21:50:02 +00001118
1119static char pjsua_logging_config_default_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00001120 "py_pjsua.Logging_Config py_pjsua.logging_config_default () "
Benny Prijono572d4852006-11-23 21:50:02 +00001121 "Use this function to initialize logging config.";
1122
1123static char pjsua_config_default_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00001124 "py_pjsua.Config py_pjsua.config_default (). Use this function to "
1125 "initialize pjsua config. ";
Benny Prijono572d4852006-11-23 21:50:02 +00001126
1127static char pjsua_media_config_default_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00001128 "py_pjsua.Media_Config py_pjsua.media_config_default (). "
Benny Prijono572d4852006-11-23 21:50:02 +00001129 "Use this function to initialize media config.";
1130
Benny Prijono572d4852006-11-23 21:50:02 +00001131static char pjsua_msg_data_init_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00001132 "py_pjsua.Msg_Data void py_pjsua.msg_data_init () "
1133 "Initialize message data ";
1134
Benny Prijono572d4852006-11-23 21:50:02 +00001135
Benny Prijono98793592006-12-04 08:33:20 +00001136/* END OF LIB BASE */
1137
1138/* LIB TRANSPORT */
1139
1140/*
Benny Prijono98793592006-12-04 08:33:20 +00001141 * py_pjsua_transport_config_default
Benny Prijonodc308702006-12-09 00:39:42 +00001142 * !modified @ 051206
Benny Prijono98793592006-12-04 08:33:20 +00001143 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00001144static PyObject *py_pjsua_transport_config_default(PyObject *pSelf,
1145 PyObject *pArgs)
Benny Prijono98793592006-12-04 08:33:20 +00001146{
Benny Prijono1f63cc42007-09-10 16:54:22 +00001147 PyObj_pjsua_transport_config *obj;
Benny Prijono98793592006-12-04 08:33:20 +00001148 pjsua_transport_config cfg;
1149
Benny Prijono1f63cc42007-09-10 16:54:22 +00001150 PJ_UNUSED_ARG(pSelf);
1151
1152 if (!PyArg_ParseTuple(pArgs, "")) {
Benny Prijono98793592006-12-04 08:33:20 +00001153 return NULL;
1154 }
Benny Prijono1f63cc42007-09-10 16:54:22 +00001155
Benny Prijono98793592006-12-04 08:33:20 +00001156 pjsua_transport_config_default(&cfg);
Benny Prijono1f63cc42007-09-10 16:54:22 +00001157 obj = (PyObj_pjsua_transport_config*)
1158 PyObj_pjsua_transport_config_new(&PyTyp_pjsua_transport_config,
1159 NULL, NULL);
1160 PyObj_pjsua_transport_config_import(obj, &cfg);
1161
Benny Prijonodc308702006-12-09 00:39:42 +00001162 return (PyObject *)obj;
Benny Prijono98793592006-12-04 08:33:20 +00001163}
1164
1165/*
Benny Prijono98793592006-12-04 08:33:20 +00001166 * py_pjsua_transport_create
Benny Prijonodc308702006-12-09 00:39:42 +00001167 * !modified @ 051206
Benny Prijono98793592006-12-04 08:33:20 +00001168 */
1169static PyObject *py_pjsua_transport_create(PyObject *pSelf, PyObject *pArgs)
1170{
1171 pj_status_t status;
Benny Prijonodc308702006-12-09 00:39:42 +00001172 int type;
Fahris6f35cb82007-02-01 07:41:26 +00001173 PyObject * tmpObj;
Benny Prijonodc308702006-12-09 00:39:42 +00001174 pjsua_transport_config cfg;
1175 pjsua_transport_id id;
Benny Prijono1f63cc42007-09-10 16:54:22 +00001176
1177 PJ_UNUSED_ARG(pSelf);
1178
1179 if (!PyArg_ParseTuple(pArgs, "iO", &type, &tmpObj)) {
Benny Prijono98793592006-12-04 08:33:20 +00001180 return NULL;
1181 }
Benny Prijono1f63cc42007-09-10 16:54:22 +00001182
1183 if (tmpObj != Py_None) {
1184 PyObj_pjsua_transport_config *obj;
1185 obj = (PyObj_pjsua_transport_config*)tmpObj;
1186 PyObj_pjsua_transport_config_export(&cfg, obj);
Fahris17d91812007-01-29 12:09:33 +00001187 status = pjsua_transport_create(type, &cfg, &id);
Fahris6f35cb82007-02-01 07:41:26 +00001188 } else {
Fahris17d91812007-01-29 12:09:33 +00001189 status = pjsua_transport_create(type, NULL, &id);
Fahris6f35cb82007-02-01 07:41:26 +00001190 }
Benny Prijonodc308702006-12-09 00:39:42 +00001191
1192
Benny Prijono1f63cc42007-09-10 16:54:22 +00001193 return Py_BuildValue("ii", status, id);
Benny Prijono98793592006-12-04 08:33:20 +00001194}
1195
1196/*
1197 * py_pjsua_enum_transports
Fahrisdcf8fa42006-12-28 03:13:48 +00001198 * !modified @ 261206
Benny Prijono98793592006-12-04 08:33:20 +00001199 */
1200static PyObject *py_pjsua_enum_transports(PyObject *pSelf, PyObject *pArgs)
1201{
1202 pj_status_t status;
Benny Prijonodc308702006-12-09 00:39:42 +00001203 PyObject *list;
1204
Fahrisdcf8fa42006-12-28 03:13:48 +00001205 pjsua_transport_id id[PJSIP_MAX_TRANSPORTS];
Fahris17d91812007-01-29 12:09:33 +00001206 unsigned c, i;
Benny Prijono1f63cc42007-09-10 16:54:22 +00001207
1208 PJ_UNUSED_ARG(pSelf);
1209
Fahrisdcf8fa42006-12-28 03:13:48 +00001210 if (!PyArg_ParseTuple(pArgs, ""))
Benny Prijono98793592006-12-04 08:33:20 +00001211 {
1212 return NULL;
1213 }
Benny Prijonodc308702006-12-09 00:39:42 +00001214
Fahrisdcf8fa42006-12-28 03:13:48 +00001215 c = PJ_ARRAY_SIZE(id);
Benny Prijono98793592006-12-04 08:33:20 +00001216 status = pjsua_enum_transports(id, &c);
Benny Prijonodc308702006-12-09 00:39:42 +00001217
1218 list = PyList_New(c);
1219 for (i = 0; i < c; i++)
1220 {
1221 int ret = PyList_SetItem(list, i, Py_BuildValue("i", id[i]));
1222 if (ret == -1)
1223 {
1224 return NULL;
1225 }
1226 }
1227
Benny Prijonodc308702006-12-09 00:39:42 +00001228 return Py_BuildValue("O",list);
Benny Prijono98793592006-12-04 08:33:20 +00001229}
1230
1231/*
1232 * py_pjsua_transport_get_info
Benny Prijonodc308702006-12-09 00:39:42 +00001233 * !modified @ 051206
Benny Prijono98793592006-12-04 08:33:20 +00001234 */
1235static PyObject *py_pjsua_transport_get_info(PyObject *pSelf, PyObject *pArgs)
1236{
1237 pj_status_t status;
Benny Prijonodc308702006-12-09 00:39:42 +00001238 int id;
Benny Prijonodc308702006-12-09 00:39:42 +00001239 pjsua_transport_info info;
1240
Benny Prijono1f63cc42007-09-10 16:54:22 +00001241 PJ_UNUSED_ARG(pSelf);
Benny Prijono98793592006-12-04 08:33:20 +00001242
Benny Prijono1f63cc42007-09-10 16:54:22 +00001243 if (!PyArg_ParseTuple(pArgs, "i", &id)) {
Benny Prijono98793592006-12-04 08:33:20 +00001244 return NULL;
1245 }
Benny Prijonodc308702006-12-09 00:39:42 +00001246
Benny Prijono98793592006-12-04 08:33:20 +00001247 status = pjsua_transport_get_info(id, &info);
Benny Prijonodc308702006-12-09 00:39:42 +00001248 if (status == PJ_SUCCESS) {
Benny Prijono1f63cc42007-09-10 16:54:22 +00001249 PyObj_pjsua_transport_info *obj;
1250 obj = (PyObj_pjsua_transport_info *)
1251 PyObj_pjsua_transport_info_new(&PyTyp_pjsua_transport_info,
1252 NULL, NULL);
1253 PyObj_pjsua_transport_info_import(obj, &info);
Benny Prijonodc308702006-12-09 00:39:42 +00001254 return Py_BuildValue("O", obj);
1255 } else {
1256 Py_INCREF(Py_None);
1257 return Py_None;
1258 }
Benny Prijono98793592006-12-04 08:33:20 +00001259}
1260
1261/*
1262 * py_pjsua_transport_set_enable
1263 */
1264static PyObject *py_pjsua_transport_set_enable
1265(PyObject *pSelf, PyObject *pArgs)
1266{
1267 pj_status_t status;
Benny Prijonodc308702006-12-09 00:39:42 +00001268 int id;
1269 int enabled;
Benny Prijono1f63cc42007-09-10 16:54:22 +00001270
1271 PJ_UNUSED_ARG(pSelf);
1272
Benny Prijono98793592006-12-04 08:33:20 +00001273 if (!PyArg_ParseTuple(pArgs, "ii", &id, &enabled))
1274 {
1275 return NULL;
1276 }
1277 status = pjsua_transport_set_enable(id, enabled);
Fahris89ea3d02007-02-07 08:18:35 +00001278
Benny Prijono98793592006-12-04 08:33:20 +00001279 return Py_BuildValue("i",status);
1280}
1281
1282/*
1283 * py_pjsua_transport_close
1284 */
1285static PyObject *py_pjsua_transport_close(PyObject *pSelf, PyObject *pArgs)
1286{
1287 pj_status_t status;
Benny Prijonodc308702006-12-09 00:39:42 +00001288 int id;
1289 int force;
Benny Prijono1f63cc42007-09-10 16:54:22 +00001290
1291 PJ_UNUSED_ARG(pSelf);
1292
Benny Prijono98793592006-12-04 08:33:20 +00001293 if (!PyArg_ParseTuple(pArgs, "ii", &id, &force))
1294 {
1295 return NULL;
1296 }
1297 status = pjsua_transport_close(id, force);
Fahris89ea3d02007-02-07 08:18:35 +00001298
Benny Prijono98793592006-12-04 08:33:20 +00001299 return Py_BuildValue("i",status);
1300}
1301
Benny Prijono98793592006-12-04 08:33:20 +00001302static char pjsua_transport_config_default_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00001303 "py_pjsua.Transport_Config py_pjsua.transport_config_default () "
1304 "Call this function to initialize UDP config with default values.";
Benny Prijono98793592006-12-04 08:33:20 +00001305static char pjsua_transport_create_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00001306 "int, int py_pjsua.transport_create (int type, "
1307 "py_pjsua.Transport_Config cfg) "
1308 "Create SIP transport.";
Benny Prijono98793592006-12-04 08:33:20 +00001309static char pjsua_enum_transports_doc[] =
Fahrisdcf8fa42006-12-28 03:13:48 +00001310 "int[] py_pjsua.enum_transports () "
Benny Prijonodc308702006-12-09 00:39:42 +00001311 "Enumerate all transports currently created in the system.";
Benny Prijono98793592006-12-04 08:33:20 +00001312static char pjsua_transport_get_info_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00001313 "void py_pjsua.transport_get_info "
1314 "(py_pjsua.Transport_ID id, py_pjsua.Transport_Info info) "
1315 "Get information about transports.";
Benny Prijono98793592006-12-04 08:33:20 +00001316static char pjsua_transport_set_enable_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00001317 "void py_pjsua.transport_set_enable "
1318 "(py_pjsua.Transport_ID id, int enabled) "
1319 "Disable a transport or re-enable it. "
1320 "By default transport is always enabled after it is created. "
1321 "Disabling a transport does not necessarily close the socket, "
1322 "it will only discard incoming messages and prevent the transport "
1323 "from being used to send outgoing messages.";
Benny Prijono98793592006-12-04 08:33:20 +00001324static char pjsua_transport_close_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00001325 "void py_pjsua.transport_close (py_pjsua.Transport_ID id, int force) "
1326 "Close the transport. If transport is forcefully closed, "
1327 "it will be immediately closed, and any pending transactions "
1328 "that are using the transport may not terminate properly. "
1329 "Otherwise, the system will wait until all transactions are closed "
1330 "while preventing new users from using the transport, and will close "
1331 "the transport when it is safe to do so.";
Benny Prijono98793592006-12-04 08:33:20 +00001332
1333/* END OF LIB TRANSPORT */
1334
1335/* LIB ACCOUNT */
1336
Benny Prijono98793592006-12-04 08:33:20 +00001337
1338/*
Benny Prijono98793592006-12-04 08:33:20 +00001339 * py_pjsua_acc_config_default
Benny Prijonodc308702006-12-09 00:39:42 +00001340 * !modified @ 051206
Benny Prijono98793592006-12-04 08:33:20 +00001341 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00001342static PyObject *py_pjsua_acc_config_default(PyObject *pSelf, PyObject *pArgs)
Benny Prijono98793592006-12-04 08:33:20 +00001343{
Benny Prijono1f63cc42007-09-10 16:54:22 +00001344 PyObj_pjsua_acc_config *obj;
Benny Prijono98793592006-12-04 08:33:20 +00001345 pjsua_acc_config cfg;
Benny Prijono98793592006-12-04 08:33:20 +00001346
Benny Prijono1f63cc42007-09-10 16:54:22 +00001347 PJ_UNUSED_ARG(pSelf);
1348
1349 if (!PyArg_ParseTuple(pArgs, "")) {
Benny Prijono98793592006-12-04 08:33:20 +00001350 return NULL;
1351 }
Benny Prijono1f63cc42007-09-10 16:54:22 +00001352
Benny Prijono98793592006-12-04 08:33:20 +00001353 pjsua_acc_config_default(&cfg);
Benny Prijono1f63cc42007-09-10 16:54:22 +00001354 obj = (PyObj_pjsua_acc_config *)
1355 PyObj_pjsua_acc_config_new(&PyTyp_pjsua_acc_config,
1356 NULL, NULL);
1357 PyObj_pjsua_acc_config_import(obj, &cfg);
Benny Prijonodc308702006-12-09 00:39:42 +00001358 return (PyObject *)obj;
Benny Prijono98793592006-12-04 08:33:20 +00001359}
1360
1361/*
1362 * py_pjsua_acc_get_count
1363 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00001364static PyObject *py_pjsua_acc_get_count(PyObject *pSelf, PyObject *pArgs)
Benny Prijono98793592006-12-04 08:33:20 +00001365{
Benny Prijonodc308702006-12-09 00:39:42 +00001366 int count;
Benny Prijono1f63cc42007-09-10 16:54:22 +00001367
1368 PJ_UNUSED_ARG(pSelf);
1369
1370 if (!PyArg_ParseTuple(pArgs, "")) {
Benny Prijono98793592006-12-04 08:33:20 +00001371 return NULL;
1372 }
Benny Prijono1f63cc42007-09-10 16:54:22 +00001373
Benny Prijono98793592006-12-04 08:33:20 +00001374 count = pjsua_acc_get_count();
1375 return Py_BuildValue("i",count);
1376}
1377
1378/*
1379 * py_pjsua_acc_is_valid
1380 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00001381static PyObject *py_pjsua_acc_is_valid(PyObject *pSelf, PyObject *pArgs)
Benny Prijono98793592006-12-04 08:33:20 +00001382{
Benny Prijonodc308702006-12-09 00:39:42 +00001383 int id;
1384 int is_valid;
Benny Prijono98793592006-12-04 08:33:20 +00001385
Benny Prijono1f63cc42007-09-10 16:54:22 +00001386 PJ_UNUSED_ARG(pSelf);
1387
1388 if (!PyArg_ParseTuple(pArgs, "i", &id)) {
Benny Prijono98793592006-12-04 08:33:20 +00001389 return NULL;
1390 }
Benny Prijono1f63cc42007-09-10 16:54:22 +00001391
1392 is_valid = pjsua_acc_is_valid(id);
Benny Prijono98793592006-12-04 08:33:20 +00001393 return Py_BuildValue("i", is_valid);
1394}
1395
1396/*
1397 * py_pjsua_acc_set_default
1398 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00001399static PyObject *py_pjsua_acc_set_default(PyObject *pSelf, PyObject *pArgs)
Benny Prijono98793592006-12-04 08:33:20 +00001400{
Benny Prijonodc308702006-12-09 00:39:42 +00001401 int id;
1402 int status;
Benny Prijono98793592006-12-04 08:33:20 +00001403
Benny Prijono1f63cc42007-09-10 16:54:22 +00001404 PJ_UNUSED_ARG(pSelf);
1405
1406 if (!PyArg_ParseTuple(pArgs, "i", &id)) {
Benny Prijono98793592006-12-04 08:33:20 +00001407 return NULL;
1408 }
1409 status = pjsua_acc_set_default(id);
1410
1411 return Py_BuildValue("i", status);
1412}
1413
1414/*
1415 * py_pjsua_acc_get_default
1416 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00001417static PyObject *py_pjsua_acc_get_default(PyObject *pSelf, PyObject *pArgs)
Benny Prijono98793592006-12-04 08:33:20 +00001418{
Benny Prijonodc308702006-12-09 00:39:42 +00001419 int id;
Benny Prijono98793592006-12-04 08:33:20 +00001420
Benny Prijono1f63cc42007-09-10 16:54:22 +00001421 PJ_UNUSED_ARG(pSelf);
1422
1423 if (!PyArg_ParseTuple(pArgs, "")) {
Benny Prijono98793592006-12-04 08:33:20 +00001424 return NULL;
1425 }
Benny Prijono1f63cc42007-09-10 16:54:22 +00001426
Benny Prijono98793592006-12-04 08:33:20 +00001427 id = pjsua_acc_get_default();
1428
1429 return Py_BuildValue("i", id);
1430}
1431
1432/*
1433 * py_pjsua_acc_add
Benny Prijonodc308702006-12-09 00:39:42 +00001434 * !modified @ 051206
Benny Prijono98793592006-12-04 08:33:20 +00001435 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00001436static PyObject *py_pjsua_acc_add(PyObject *pSelf, PyObject *pArgs)
Benny Prijono98793592006-12-04 08:33:20 +00001437{
Benny Prijonodc308702006-12-09 00:39:42 +00001438 int is_default;
Fahris6f35cb82007-02-01 07:41:26 +00001439 PyObject * acObj;
Benny Prijono1f63cc42007-09-10 16:54:22 +00001440 PyObj_pjsua_acc_config * ac;
1441 int acc_id;
Benny Prijonodc308702006-12-09 00:39:42 +00001442 int status;
Benny Prijono98793592006-12-04 08:33:20 +00001443
Benny Prijono1f63cc42007-09-10 16:54:22 +00001444 PJ_UNUSED_ARG(pSelf);
1445
1446 if (!PyArg_ParseTuple(pArgs, "Oi", &acObj, &is_default)) {
Benny Prijono98793592006-12-04 08:33:20 +00001447 return NULL;
1448 }
Benny Prijonodc308702006-12-09 00:39:42 +00001449
Benny Prijono1f63cc42007-09-10 16:54:22 +00001450 if (acObj != Py_None) {
1451 pjsua_acc_config cfg;
1452
1453 pjsua_acc_config_default(&cfg);
1454 ac = (PyObj_pjsua_acc_config *)acObj;
1455 PyObj_pjsua_acc_config_export(&cfg, ac);
1456 status = pjsua_acc_add(&cfg, is_default, &acc_id);
Fahris17d91812007-01-29 12:09:33 +00001457 } else {
Benny Prijono1f63cc42007-09-10 16:54:22 +00001458 status = PJ_EINVAL;
1459 acc_id = PJSUA_INVALID_ID;
Fahris6f35cb82007-02-01 07:41:26 +00001460 }
Benny Prijonodc308702006-12-09 00:39:42 +00001461
Benny Prijono1f63cc42007-09-10 16:54:22 +00001462 return Py_BuildValue("ii", status, acc_id);
Benny Prijono98793592006-12-04 08:33:20 +00001463}
1464
1465/*
1466 * py_pjsua_acc_add_local
Benny Prijonodc308702006-12-09 00:39:42 +00001467 * !modified @ 051206
Benny Prijono98793592006-12-04 08:33:20 +00001468 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00001469static PyObject *py_pjsua_acc_add_local(PyObject *pSelf, PyObject *pArgs)
Benny Prijono98793592006-12-04 08:33:20 +00001470{
Benny Prijonodc308702006-12-09 00:39:42 +00001471 int is_default;
1472 int tid;
Benny Prijonodc308702006-12-09 00:39:42 +00001473 int p_acc_id;
1474 int status;
Benny Prijono98793592006-12-04 08:33:20 +00001475
Benny Prijono1f63cc42007-09-10 16:54:22 +00001476 PJ_UNUSED_ARG(pSelf);
Benny Prijono98793592006-12-04 08:33:20 +00001477
Benny Prijono1f63cc42007-09-10 16:54:22 +00001478 if (!PyArg_ParseTuple(pArgs, "ii", &tid, &is_default)) {
Benny Prijono98793592006-12-04 08:33:20 +00001479 return NULL;
1480 }
1481
Benny Prijonodc308702006-12-09 00:39:42 +00001482
Benny Prijono98793592006-12-04 08:33:20 +00001483 status = pjsua_acc_add_local(tid, is_default, &p_acc_id);
Benny Prijonodc308702006-12-09 00:39:42 +00001484
1485 return Py_BuildValue("ii", status, p_acc_id);
Benny Prijono98793592006-12-04 08:33:20 +00001486}
1487
1488/*
1489 * py_pjsua_acc_del
1490 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00001491static PyObject *py_pjsua_acc_del(PyObject *pSelf, PyObject *pArgs)
Benny Prijono98793592006-12-04 08:33:20 +00001492{
Benny Prijonodc308702006-12-09 00:39:42 +00001493 int acc_id;
1494 int status;
1495
Benny Prijono1f63cc42007-09-10 16:54:22 +00001496 PJ_UNUSED_ARG(pSelf);
1497
Benny Prijono98793592006-12-04 08:33:20 +00001498 if (!PyArg_ParseTuple(pArgs, "i", &acc_id))
1499 {
1500 return NULL;
1501 }
1502
1503
1504 status = pjsua_acc_del(acc_id);
1505 return Py_BuildValue("i", status);
1506}
1507
1508/*
1509 * py_pjsua_acc_modify
1510 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00001511static PyObject *py_pjsua_acc_modify(PyObject *pSelf, PyObject *pArgs)
Benny Prijono98793592006-12-04 08:33:20 +00001512{
Fahris6f35cb82007-02-01 07:41:26 +00001513 PyObject * acObj;
Benny Prijono1f63cc42007-09-10 16:54:22 +00001514 PyObj_pjsua_acc_config * ac;
Benny Prijonodc308702006-12-09 00:39:42 +00001515 int acc_id;
1516 int status;
Benny Prijono98793592006-12-04 08:33:20 +00001517
Benny Prijono1f63cc42007-09-10 16:54:22 +00001518 PJ_UNUSED_ARG(pSelf);
1519
1520 if (!PyArg_ParseTuple(pArgs, "iO", &acc_id, &acObj)) {
Benny Prijono98793592006-12-04 08:33:20 +00001521 return NULL;
1522 }
Benny Prijono1f63cc42007-09-10 16:54:22 +00001523
1524 if (acObj != Py_None) {
1525 pjsua_acc_config cfg;
1526
1527 pjsua_acc_config_default(&cfg);
1528 ac = (PyObj_pjsua_acc_config *)acObj;
1529 PyObj_pjsua_acc_config_export(&cfg, ac);
1530
Fahris17d91812007-01-29 12:09:33 +00001531 status = pjsua_acc_modify(acc_id, &cfg);
Fahris6f35cb82007-02-01 07:41:26 +00001532 } else {
Benny Prijono1f63cc42007-09-10 16:54:22 +00001533 status = PJ_EINVAL;
Fahris6f35cb82007-02-01 07:41:26 +00001534 }
Benny Prijono98793592006-12-04 08:33:20 +00001535 return Py_BuildValue("i", status);
1536}
1537
1538/*
1539 * py_pjsua_acc_set_online_status
1540 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00001541static PyObject *py_pjsua_acc_set_online_status(PyObject *pSelf,
1542 PyObject *pArgs)
Benny Prijono98793592006-12-04 08:33:20 +00001543{
Benny Prijonodc308702006-12-09 00:39:42 +00001544 int is_online;
1545 int acc_id;
1546 int status;
Benny Prijono98793592006-12-04 08:33:20 +00001547
Benny Prijono1f63cc42007-09-10 16:54:22 +00001548 PJ_UNUSED_ARG(pSelf);
1549
1550 if (!PyArg_ParseTuple(pArgs, "ii", &acc_id, &is_online)) {
Benny Prijono98793592006-12-04 08:33:20 +00001551 return NULL;
1552 }
1553
1554 status = pjsua_acc_set_online_status(acc_id, is_online);
1555
1556 return Py_BuildValue("i", status);
1557}
1558
1559/*
Benny Prijono1f63cc42007-09-10 16:54:22 +00001560 * py_pjsua_acc_set_online_status2
1561 */
1562static PyObject *py_pjsua_acc_set_online_status2(PyObject *pSelf,
1563 PyObject *pArgs)
1564{
1565 int is_online;
1566 int acc_id;
1567 int activity_id;
1568 const char *activity_text;
1569 pjrpid_element rpid;
1570 pj_status_t status;
1571
1572 PJ_UNUSED_ARG(pSelf);
1573
1574 if (!PyArg_ParseTuple(pArgs, "iiis", &acc_id, &is_online,
1575 &activity_id, &activity_text)) {
1576 return NULL;
1577 }
1578
1579 pj_bzero(&rpid, sizeof(rpid));
1580 rpid.activity = activity_id;
1581 rpid.note = pj_str((char*)activity_text);
1582
1583 status = pjsua_acc_set_online_status2(acc_id, is_online, &rpid);
1584
1585 return Py_BuildValue("i", status);
1586}
1587
1588/*
Benny Prijono98793592006-12-04 08:33:20 +00001589 * py_pjsua_acc_set_registration
1590 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00001591static PyObject *py_pjsua_acc_set_registration(PyObject *pSelf,
1592 PyObject *pArgs)
Benny Prijono98793592006-12-04 08:33:20 +00001593{
Benny Prijonodc308702006-12-09 00:39:42 +00001594 int renew;
1595 int acc_id;
1596 int status;
Benny Prijono98793592006-12-04 08:33:20 +00001597
Benny Prijono1f63cc42007-09-10 16:54:22 +00001598 PJ_UNUSED_ARG(pSelf);
1599
1600 if (!PyArg_ParseTuple(pArgs, "ii", &acc_id, &renew)) {
Benny Prijono98793592006-12-04 08:33:20 +00001601 return NULL;
1602 }
1603
1604 status = pjsua_acc_set_registration(acc_id, renew);
1605
1606 return Py_BuildValue("i", status);
1607}
1608
1609/*
Benny Prijonodc308702006-12-09 00:39:42 +00001610 * py_pjsua_acc_get_info
1611 * !modified @ 051206
Benny Prijono98793592006-12-04 08:33:20 +00001612 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00001613static PyObject *py_pjsua_acc_get_info(PyObject *pSelf, PyObject *pArgs)
Benny Prijono98793592006-12-04 08:33:20 +00001614{
Benny Prijonodc308702006-12-09 00:39:42 +00001615 int acc_id;
Benny Prijono1f63cc42007-09-10 16:54:22 +00001616 PyObj_pjsua_acc_info * obj;
Benny Prijonodc308702006-12-09 00:39:42 +00001617 pjsua_acc_info info;
1618 int status;
Benny Prijono98793592006-12-04 08:33:20 +00001619
Benny Prijono1f63cc42007-09-10 16:54:22 +00001620 PJ_UNUSED_ARG(pSelf);
1621
1622 if (!PyArg_ParseTuple(pArgs, "i", &acc_id)) {
Benny Prijono98793592006-12-04 08:33:20 +00001623 return NULL;
1624 }
Benny Prijonodc308702006-12-09 00:39:42 +00001625
Benny Prijono98793592006-12-04 08:33:20 +00001626 status = pjsua_acc_get_info(acc_id, &info);
Benny Prijono1f63cc42007-09-10 16:54:22 +00001627 if (status == PJ_SUCCESS) {
1628 obj = (PyObj_pjsua_acc_info *)
1629 PyObj_pjsua_acc_info_new(&PyTyp_pjsua_acc_info,NULL, NULL);
1630 PyObj_pjsua_acc_info_import(obj, &info);
Benny Prijonodc308702006-12-09 00:39:42 +00001631 return Py_BuildValue("O", obj);
1632 } else {
1633 Py_INCREF(Py_None);
1634 return Py_None;
1635 }
Benny Prijono98793592006-12-04 08:33:20 +00001636}
1637
1638/*
1639 * py_pjsua_enum_accs
Fahrisdcf8fa42006-12-28 03:13:48 +00001640 * !modified @ 241206
Benny Prijono98793592006-12-04 08:33:20 +00001641 */
1642static PyObject *py_pjsua_enum_accs(PyObject *pSelf, PyObject *pArgs)
1643{
1644 pj_status_t status;
Benny Prijonodc308702006-12-09 00:39:42 +00001645 PyObject *list;
1646
Fahrisdcf8fa42006-12-28 03:13:48 +00001647 pjsua_acc_id id[PJSUA_MAX_ACC];
Fahris17d91812007-01-29 12:09:33 +00001648 unsigned c, i;
Benny Prijono1f63cc42007-09-10 16:54:22 +00001649
1650 PJ_UNUSED_ARG(pSelf);
1651
Fahrisdcf8fa42006-12-28 03:13:48 +00001652 if (!PyArg_ParseTuple(pArgs, ""))
Benny Prijono98793592006-12-04 08:33:20 +00001653 {
1654 return NULL;
1655 }
Fahrisdcf8fa42006-12-28 03:13:48 +00001656 c = PJ_ARRAY_SIZE(id);
Benny Prijonodc308702006-12-09 00:39:42 +00001657
Benny Prijono98793592006-12-04 08:33:20 +00001658 status = pjsua_enum_accs(id, &c);
Benny Prijonodc308702006-12-09 00:39:42 +00001659
1660 list = PyList_New(c);
Fahris6f35cb82007-02-01 07:41:26 +00001661 for (i = 0; i < c; i++)
1662 {
Benny Prijonodc308702006-12-09 00:39:42 +00001663 int ret = PyList_SetItem(list, i, Py_BuildValue("i", id[i]));
Fahris6f35cb82007-02-01 07:41:26 +00001664 if (ret == -1)
1665 {
Benny Prijonodc308702006-12-09 00:39:42 +00001666 return NULL;
Fahrisdcf8fa42006-12-28 03:13:48 +00001667 }
Benny Prijonodc308702006-12-09 00:39:42 +00001668 }
1669
Benny Prijonodc308702006-12-09 00:39:42 +00001670 return Py_BuildValue("O",list);
Benny Prijono98793592006-12-04 08:33:20 +00001671}
1672
1673/*
1674 * py_pjsua_acc_enum_info
Fahrisdcf8fa42006-12-28 03:13:48 +00001675 * !modified @ 241206
Benny Prijono98793592006-12-04 08:33:20 +00001676 */
1677static PyObject *py_pjsua_acc_enum_info(PyObject *pSelf, PyObject *pArgs)
1678{
1679 pj_status_t status;
Benny Prijonodc308702006-12-09 00:39:42 +00001680 PyObject *list;
Fahrisdcf8fa42006-12-28 03:13:48 +00001681 pjsua_acc_info info[PJSUA_MAX_ACC];
Fahris17d91812007-01-29 12:09:33 +00001682 unsigned c, i;
Benny Prijono1f63cc42007-09-10 16:54:22 +00001683
1684 PJ_UNUSED_ARG(pSelf);
1685
1686 if (!PyArg_ParseTuple(pArgs, "")) {
Benny Prijono98793592006-12-04 08:33:20 +00001687 return NULL;
1688 }
Benny Prijonodc308702006-12-09 00:39:42 +00001689
Fahrisdcf8fa42006-12-28 03:13:48 +00001690 c = PJ_ARRAY_SIZE(info);
Benny Prijono98793592006-12-04 08:33:20 +00001691 status = pjsua_acc_enum_info(info, &c);
Benny Prijonodc308702006-12-09 00:39:42 +00001692
1693 list = PyList_New(c);
Benny Prijono1f63cc42007-09-10 16:54:22 +00001694 for (i = 0; i < c; i++) {
1695 PyObj_pjsua_acc_info *obj;
1696 obj = (PyObj_pjsua_acc_info *)
1697 PyObj_pjsua_acc_info_new(&PyTyp_pjsua_acc_info, NULL, NULL);
1698
1699 PyObj_pjsua_acc_info_import(obj, &info[i]);
1700
1701 PyList_SetItem(list, i, (PyObject *)obj);
Benny Prijonodc308702006-12-09 00:39:42 +00001702 }
1703
Benny Prijonodc308702006-12-09 00:39:42 +00001704 return Py_BuildValue("O",list);
Benny Prijono98793592006-12-04 08:33:20 +00001705}
1706
1707/*
1708 * py_pjsua_acc_find_for_outgoing
1709 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00001710static PyObject *py_pjsua_acc_find_for_outgoing(PyObject *pSelf,
1711 PyObject *pArgs)
1712{
Benny Prijonodc308702006-12-09 00:39:42 +00001713 int acc_id;
1714 PyObject * url;
1715 pj_str_t str;
Benny Prijono98793592006-12-04 08:33:20 +00001716
Benny Prijono1f63cc42007-09-10 16:54:22 +00001717 PJ_UNUSED_ARG(pSelf);
1718
Benny Prijono98793592006-12-04 08:33:20 +00001719 if (!PyArg_ParseTuple(pArgs, "O", &url))
1720 {
1721 return NULL;
1722 }
Benny Prijonodc308702006-12-09 00:39:42 +00001723 str.ptr = PyString_AsString(url);
1724 str.slen = strlen(PyString_AsString(url));
Benny Prijono98793592006-12-04 08:33:20 +00001725
1726 acc_id = pjsua_acc_find_for_outgoing(&str);
1727
1728 return Py_BuildValue("i", acc_id);
1729}
1730
1731/*
1732 * py_pjsua_acc_find_for_incoming
1733 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00001734static PyObject *py_pjsua_acc_find_for_incoming(PyObject *pSelf,
1735 PyObject *pArgs)
Benny Prijono98793592006-12-04 08:33:20 +00001736{
Benny Prijonodc308702006-12-09 00:39:42 +00001737 int acc_id;
Fahris6f35cb82007-02-01 07:41:26 +00001738 PyObject * tmpObj;
Benny Prijono1f63cc42007-09-10 16:54:22 +00001739 PyObj_pjsip_rx_data * obj;
Benny Prijonodc308702006-12-09 00:39:42 +00001740 pjsip_rx_data * rdata;
Benny Prijono98793592006-12-04 08:33:20 +00001741
Benny Prijono1f63cc42007-09-10 16:54:22 +00001742 PJ_UNUSED_ARG(pSelf);
1743
Fahris17d91812007-01-29 12:09:33 +00001744 if (!PyArg_ParseTuple(pArgs, "O", &tmpObj))
Benny Prijono98793592006-12-04 08:33:20 +00001745 {
1746 return NULL;
1747 }
Fahris17d91812007-01-29 12:09:33 +00001748 if (tmpObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00001749 {
Benny Prijono1f63cc42007-09-10 16:54:22 +00001750 obj = (PyObj_pjsip_rx_data *)tmpObj;
Fahris17d91812007-01-29 12:09:33 +00001751 rdata = obj->rdata;
1752 acc_id = pjsua_acc_find_for_incoming(rdata);
Fahris6f35cb82007-02-01 07:41:26 +00001753 } else {
Fahris17d91812007-01-29 12:09:33 +00001754 acc_id = pjsua_acc_find_for_incoming(NULL);
Fahris6f35cb82007-02-01 07:41:26 +00001755 }
Benny Prijono98793592006-12-04 08:33:20 +00001756 return Py_BuildValue("i", acc_id);
1757}
1758
1759/*
1760 * py_pjsua_acc_create_uac_contact
Benny Prijonodc308702006-12-09 00:39:42 +00001761 * !modified @ 061206
Benny Prijono98793592006-12-04 08:33:20 +00001762 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00001763static PyObject *py_pjsua_acc_create_uac_contact(PyObject *pSelf,
1764 PyObject *pArgs)
Benny Prijono98793592006-12-04 08:33:20 +00001765{
Benny Prijonodc308702006-12-09 00:39:42 +00001766 int status;
Fahris17d91812007-01-29 12:09:33 +00001767 int acc_id;
Fahris6f35cb82007-02-01 07:41:26 +00001768 PyObject * pObj;
Benny Prijono1f63cc42007-09-10 16:54:22 +00001769 PyObj_pj_pool * p;
Benny Prijonodc308702006-12-09 00:39:42 +00001770 pj_pool_t * pool;
1771 PyObject * strc;
1772 pj_str_t contact;
1773 PyObject * stru;
1774 pj_str_t uri;
Benny Prijono98793592006-12-04 08:33:20 +00001775
Benny Prijono1f63cc42007-09-10 16:54:22 +00001776 PJ_UNUSED_ARG(pSelf);
1777
Fahris17d91812007-01-29 12:09:33 +00001778 if (!PyArg_ParseTuple(pArgs, "OiO", &pObj, &acc_id, &stru))
Benny Prijono98793592006-12-04 08:33:20 +00001779 {
1780 return NULL;
1781 }
Fahris17d91812007-01-29 12:09:33 +00001782 if (pObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00001783 {
Benny Prijono1f63cc42007-09-10 16:54:22 +00001784 p = (PyObj_pj_pool *)pObj;
Fahris17d91812007-01-29 12:09:33 +00001785 pool = p->pool;
1786 uri.ptr = PyString_AsString(stru);
1787 uri.slen = strlen(PyString_AsString(stru));
1788 status = pjsua_acc_create_uac_contact(pool, &contact, acc_id, &uri);
Fahris6f35cb82007-02-01 07:41:26 +00001789 } else {
Fahris17d91812007-01-29 12:09:33 +00001790 status = pjsua_acc_create_uac_contact(NULL, &contact, acc_id, &uri);
Fahris6f35cb82007-02-01 07:41:26 +00001791 }
Benny Prijonodc308702006-12-09 00:39:42 +00001792 strc = PyString_FromStringAndSize(contact.ptr, contact.slen);
Benny Prijono98793592006-12-04 08:33:20 +00001793
Benny Prijonodc308702006-12-09 00:39:42 +00001794 return Py_BuildValue("O", strc);
Benny Prijono98793592006-12-04 08:33:20 +00001795}
1796
1797/*
1798 * py_pjsua_acc_create_uas_contact
Benny Prijonodc308702006-12-09 00:39:42 +00001799 * !modified @ 061206
Benny Prijono98793592006-12-04 08:33:20 +00001800 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00001801static PyObject *py_pjsua_acc_create_uas_contact(PyObject *pSelf,
1802 PyObject *pArgs)
Benny Prijono98793592006-12-04 08:33:20 +00001803{
Benny Prijonodc308702006-12-09 00:39:42 +00001804 int status;
1805 int acc_id;
Fahris6f35cb82007-02-01 07:41:26 +00001806 PyObject * pObj;
Benny Prijono1f63cc42007-09-10 16:54:22 +00001807 PyObj_pj_pool * p;
Benny Prijonodc308702006-12-09 00:39:42 +00001808 pj_pool_t * pool;
1809 PyObject * strc;
1810 pj_str_t contact;
Fahris6f35cb82007-02-01 07:41:26 +00001811 PyObject * rObj;
Benny Prijono1f63cc42007-09-10 16:54:22 +00001812 PyObj_pjsip_rx_data * objr;
Benny Prijonodc308702006-12-09 00:39:42 +00001813 pjsip_rx_data * rdata;
Benny Prijono98793592006-12-04 08:33:20 +00001814
Benny Prijono1f63cc42007-09-10 16:54:22 +00001815 PJ_UNUSED_ARG(pSelf);
1816
Fahris17d91812007-01-29 12:09:33 +00001817 if (!PyArg_ParseTuple(pArgs, "OiO", &pObj, &acc_id, &rObj))
Benny Prijono98793592006-12-04 08:33:20 +00001818 {
1819 return NULL;
1820 }
Fahris17d91812007-01-29 12:09:33 +00001821 if (pObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00001822 {
Benny Prijono1f63cc42007-09-10 16:54:22 +00001823 p = (PyObj_pj_pool *)pObj;
Fahris17d91812007-01-29 12:09:33 +00001824 pool = p->pool;
1825 } else {
1826 pool = NULL;
Fahris6f35cb82007-02-01 07:41:26 +00001827 }
Fahris17d91812007-01-29 12:09:33 +00001828 if (rObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00001829 {
Benny Prijono1f63cc42007-09-10 16:54:22 +00001830 objr = (PyObj_pjsip_rx_data *)rObj;
Fahris17d91812007-01-29 12:09:33 +00001831 rdata = objr->rdata;
Fahris6f35cb82007-02-01 07:41:26 +00001832 } else {
Fahris17d91812007-01-29 12:09:33 +00001833 rdata = NULL;
Fahris6f35cb82007-02-01 07:41:26 +00001834 }
Benny Prijono98793592006-12-04 08:33:20 +00001835 status = pjsua_acc_create_uas_contact(pool, &contact, acc_id, rdata);
Benny Prijonodc308702006-12-09 00:39:42 +00001836 strc = PyString_FromStringAndSize(contact.ptr, contact.slen);
Benny Prijono98793592006-12-04 08:33:20 +00001837
Benny Prijonodc308702006-12-09 00:39:42 +00001838 return Py_BuildValue("O", strc);
Benny Prijono98793592006-12-04 08:33:20 +00001839}
1840
1841static char pjsua_acc_config_default_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00001842 "py_pjsua.Acc_Config py_pjsua.acc_config_default () "
Benny Prijono98793592006-12-04 08:33:20 +00001843 "Call this function to initialize account config with default values.";
1844static char pjsua_acc_get_count_doc[] =
1845 "int py_pjsua.acc_get_count () "
1846 "Get number of current accounts.";
1847static char pjsua_acc_is_valid_doc[] =
1848 "int py_pjsua.acc_is_valid (int acc_id) "
1849 "Check if the specified account ID is valid.";
1850static char pjsua_acc_set_default_doc[] =
1851 "int py_pjsua.acc_set_default (int acc_id) "
1852 "Set default account to be used when incoming "
Benny Prijonodc308702006-12-09 00:39:42 +00001853 "and outgoing requests doesn't match any accounts.";
Benny Prijono98793592006-12-04 08:33:20 +00001854static char pjsua_acc_get_default_doc[] =
1855 "int py_pjsua.acc_get_default () "
1856 "Get default account.";
1857static char pjsua_acc_add_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00001858 "int, int py_pjsua.acc_add (py_pjsua.Acc_Config cfg, "
1859 "int is_default) "
Benny Prijono98793592006-12-04 08:33:20 +00001860 "Add a new account to pjsua. PJSUA must have been initialized "
Benny Prijonodc308702006-12-09 00:39:42 +00001861 "(with pjsua_init()) before calling this function.";
Benny Prijono98793592006-12-04 08:33:20 +00001862static char pjsua_acc_add_local_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00001863 "int,int py_pjsua.acc_add_local (int tid, "
1864 "int is_default) "
Benny Prijono98793592006-12-04 08:33:20 +00001865 "Add a local account. A local account is used to identify "
Benny Prijonodc308702006-12-09 00:39:42 +00001866 "local endpoint instead of a specific user, and for this reason, "
1867 "a transport ID is needed to obtain the local address information.";
Benny Prijono98793592006-12-04 08:33:20 +00001868static char pjsua_acc_del_doc[] =
1869 "int py_pjsua.acc_del (int acc_id) "
1870 "Delete account.";
1871static char pjsua_acc_modify_doc[] =
1872 "int py_pjsua.acc_modify (int acc_id, py_pjsua.Acc_Config cfg) "
1873 "Modify account information.";
1874static char pjsua_acc_set_online_status_doc[] =
Benny Prijono1f63cc42007-09-10 16:54:22 +00001875 "int py_pjsua.acc_set_online_status2(int acc_id, int is_online) "
1876 "Modify account's presence status to be advertised "
1877 "to remote/presence subscribers.";
1878static char pjsua_acc_set_online_status2_doc[] =
1879 "int py_pjsua.acc_set_online_status (int acc_id, int is_online, "
1880 "int activity_id, string activity_text) "
Benny Prijono98793592006-12-04 08:33:20 +00001881 "Modify account's presence status to be advertised "
Benny Prijonodc308702006-12-09 00:39:42 +00001882 "to remote/presence subscribers.";
Benny Prijono98793592006-12-04 08:33:20 +00001883static char pjsua_acc_set_registration_doc[] =
1884 "int py_pjsua.acc_set_registration (int acc_id, int renew) "
1885 "Update registration or perform unregistration.";
1886static char pjsua_acc_get_info_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00001887 "py_pjsua.Acc_Info py_pjsua.acc_get_info (int acc_id) "
Benny Prijono98793592006-12-04 08:33:20 +00001888 "Get account information.";
1889static char pjsua_enum_accs_doc[] =
Fahrisdcf8fa42006-12-28 03:13:48 +00001890 "int[] py_pjsua.enum_accs () "
Benny Prijono98793592006-12-04 08:33:20 +00001891 "Enum accounts all account ids.";
1892static char pjsua_acc_enum_info_doc[] =
Fahrisdcf8fa42006-12-28 03:13:48 +00001893 "py_pjsua.Acc_Info[] py_pjsua.acc_enum_info () "
Benny Prijono98793592006-12-04 08:33:20 +00001894 "Enum accounts info.";
1895static char pjsua_acc_find_for_outgoing_doc[] =
1896 "int py_pjsua.acc_find_for_outgoing (string url) "
1897 "This is an internal function to find the most appropriate account "
Benny Prijonodc308702006-12-09 00:39:42 +00001898 "to used to reach to the specified URL.";
Benny Prijono98793592006-12-04 08:33:20 +00001899static char pjsua_acc_find_for_incoming_doc[] =
Benny Prijono1f63cc42007-09-10 16:54:22 +00001900 "int py_pjsua.acc_find_for_incoming (PyObj_pjsip_rx_data rdata) "
Benny Prijono98793592006-12-04 08:33:20 +00001901 "This is an internal function to find the most appropriate account "
Benny Prijonodc308702006-12-09 00:39:42 +00001902 "to be used to handle incoming calls.";
Benny Prijono98793592006-12-04 08:33:20 +00001903static char pjsua_acc_create_uac_contact_doc[] =
Benny Prijono1f63cc42007-09-10 16:54:22 +00001904 "string py_pjsua.acc_create_uac_contact (PyObj_pj_pool pool, "
Benny Prijonodc308702006-12-09 00:39:42 +00001905 "int acc_id, string uri) "
Benny Prijono98793592006-12-04 08:33:20 +00001906 "Create a suitable URI to be put as Contact based on the specified "
Benny Prijonodc308702006-12-09 00:39:42 +00001907 "target URI for the specified account.";
Benny Prijono98793592006-12-04 08:33:20 +00001908static char pjsua_acc_create_uas_contact_doc[] =
Benny Prijono1f63cc42007-09-10 16:54:22 +00001909 "string py_pjsua.acc_create_uas_contact (PyObj_pj_pool pool, "
1910 "int acc_id, PyObj_pjsip_rx_data rdata) "
Benny Prijono98793592006-12-04 08:33:20 +00001911 "Create a suitable URI to be put as Contact based on the information "
Benny Prijonodc308702006-12-09 00:39:42 +00001912 "in the incoming request.";
Benny Prijono98793592006-12-04 08:33:20 +00001913
1914/* END OF LIB ACCOUNT */
1915
Benny Prijonodc308702006-12-09 00:39:42 +00001916/* LIB BUDDY */
1917
1918
1919
1920/*
Fahris6f35cb82007-02-01 07:41:26 +00001921 * py_pjsua_buddy_config_default
1922 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00001923static PyObject *py_pjsua_buddy_config_default(PyObject *pSelf,
1924 PyObject *pArgs)
Fahris6f35cb82007-02-01 07:41:26 +00001925{
Benny Prijono1f63cc42007-09-10 16:54:22 +00001926 PyObj_pjsua_buddy_config *obj;
Fahris6f35cb82007-02-01 07:41:26 +00001927 pjsua_buddy_config cfg;
1928
Benny Prijono1f63cc42007-09-10 16:54:22 +00001929 PJ_UNUSED_ARG(pSelf);
1930
1931 if (!PyArg_ParseTuple(pArgs, "")) {
Fahris6f35cb82007-02-01 07:41:26 +00001932 return NULL;
1933 }
1934
1935 pjsua_buddy_config_default(&cfg);
Benny Prijono1f63cc42007-09-10 16:54:22 +00001936 obj = (PyObj_pjsua_buddy_config *)
1937 PyObj_pjsua_buddy_config_new(&PyTyp_pjsua_buddy_config, NULL, NULL);
1938 PyObj_pjsua_buddy_config_import(obj, &cfg);
Fahris6f35cb82007-02-01 07:41:26 +00001939
1940 return (PyObject *)obj;
1941}
1942
1943/*
Benny Prijonodc308702006-12-09 00:39:42 +00001944 * py_pjsua_get_buddy_count
1945 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00001946static PyObject *py_pjsua_get_buddy_count(PyObject *pSelf, PyObject *pArgs)
Benny Prijono98793592006-12-04 08:33:20 +00001947{
Benny Prijonodc308702006-12-09 00:39:42 +00001948 int ret;
Benny Prijono98793592006-12-04 08:33:20 +00001949
Benny Prijono1f63cc42007-09-10 16:54:22 +00001950 PJ_UNUSED_ARG(pSelf);
1951
1952 if (!PyArg_ParseTuple(pArgs, "")) {
Benny Prijono98793592006-12-04 08:33:20 +00001953 return NULL;
1954 }
Benny Prijonodc308702006-12-09 00:39:42 +00001955 ret = pjsua_get_buddy_count();
1956
1957 return Py_BuildValue("i", ret);
1958}
Benny Prijono98793592006-12-04 08:33:20 +00001959
Benny Prijonodc308702006-12-09 00:39:42 +00001960/*
1961 * py_pjsua_buddy_is_valid
1962 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00001963static PyObject *py_pjsua_buddy_is_valid(PyObject *pSelf, PyObject *pArgs)
Benny Prijonodc308702006-12-09 00:39:42 +00001964{
1965 int id;
1966 int is_valid;
Benny Prijono98793592006-12-04 08:33:20 +00001967
Benny Prijono1f63cc42007-09-10 16:54:22 +00001968 PJ_UNUSED_ARG(pSelf);
1969
1970 if (!PyArg_ParseTuple(pArgs, "i", &id)) {
Benny Prijonodc308702006-12-09 00:39:42 +00001971 return NULL;
1972 }
1973 is_valid = pjsua_buddy_is_valid(id);
1974
1975 return Py_BuildValue("i", is_valid);
1976}
1977
1978/*
1979 * py_pjsua_enum_buddies
Fahrisdcf8fa42006-12-28 03:13:48 +00001980 * !modified @ 241206
Benny Prijonodc308702006-12-09 00:39:42 +00001981 */
1982static PyObject *py_pjsua_enum_buddies(PyObject *pSelf, PyObject *pArgs)
1983{
1984 pj_status_t status;
1985 PyObject *list;
1986
Fahrisdcf8fa42006-12-28 03:13:48 +00001987 pjsua_buddy_id id[PJSUA_MAX_BUDDIES];
Fahris17d91812007-01-29 12:09:33 +00001988 unsigned c, i;
Benny Prijono1f63cc42007-09-10 16:54:22 +00001989
1990 PJ_UNUSED_ARG(pSelf);
1991
1992 if (!PyArg_ParseTuple(pArgs, "")) {
Benny Prijonodc308702006-12-09 00:39:42 +00001993 return NULL;
1994 }
Fahrisdcf8fa42006-12-28 03:13:48 +00001995 c = PJ_ARRAY_SIZE(id);
Benny Prijonodc308702006-12-09 00:39:42 +00001996 status = pjsua_enum_buddies(id, &c);
Benny Prijonodc308702006-12-09 00:39:42 +00001997 list = PyList_New(c);
Benny Prijono1f63cc42007-09-10 16:54:22 +00001998 for (i = 0; i < c; i++) {
1999 PyList_SetItem(list, i, Py_BuildValue("i", id[i]));
Benny Prijonodc308702006-12-09 00:39:42 +00002000 }
2001
Benny Prijonodc308702006-12-09 00:39:42 +00002002 return Py_BuildValue("O",list);
2003}
2004
2005/*
2006 * py_pjsua_buddy_get_info
2007 * !modified @ 071206
2008 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00002009static PyObject *py_pjsua_buddy_get_info(PyObject *pSelf, PyObject *pArgs)
Benny Prijonodc308702006-12-09 00:39:42 +00002010{
2011 int buddy_id;
Benny Prijono1f63cc42007-09-10 16:54:22 +00002012 PyObj_pjsua_buddy_info * obj;
Benny Prijonodc308702006-12-09 00:39:42 +00002013 pjsua_buddy_info info;
2014 int status;
Benny Prijonodc308702006-12-09 00:39:42 +00002015
Benny Prijono1f63cc42007-09-10 16:54:22 +00002016 PJ_UNUSED_ARG(pSelf);
2017
2018 if (!PyArg_ParseTuple(pArgs, "i", &buddy_id)) {
Benny Prijonodc308702006-12-09 00:39:42 +00002019 return NULL;
2020 }
Benny Prijono1f63cc42007-09-10 16:54:22 +00002021
Benny Prijonodc308702006-12-09 00:39:42 +00002022 status = pjsua_buddy_get_info(buddy_id, &info);
Benny Prijono1f63cc42007-09-10 16:54:22 +00002023 if (status == PJ_SUCCESS) {
2024 obj = (PyObj_pjsua_buddy_info *)
2025 PyObj_pjsua_buddy_config_new(&PyTyp_pjsua_buddy_info,NULL,NULL);
2026 PyObj_pjsua_buddy_info_import(obj, &info);
Benny Prijonodc308702006-12-09 00:39:42 +00002027 return Py_BuildValue("O", obj);
2028 } else {
2029 Py_INCREF(Py_None);
2030 return Py_None;
2031 }
2032}
2033
2034/*
2035 * py_pjsua_buddy_add
2036 * !modified @ 061206
2037 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00002038static PyObject *py_pjsua_buddy_add(PyObject *pSelf, PyObject *pArgs)
Fahris17d91812007-01-29 12:09:33 +00002039{
2040 PyObject * bcObj;
Benny Prijono1f63cc42007-09-10 16:54:22 +00002041 int buddy_id;
Benny Prijonodc308702006-12-09 00:39:42 +00002042 int status;
2043
Benny Prijono1f63cc42007-09-10 16:54:22 +00002044 PJ_UNUSED_ARG(pSelf);
2045
2046 if (!PyArg_ParseTuple(pArgs, "O", &bcObj)) {
Benny Prijonodc308702006-12-09 00:39:42 +00002047 return NULL;
2048 }
Fahris17d91812007-01-29 12:09:33 +00002049
Benny Prijono1f63cc42007-09-10 16:54:22 +00002050 if (bcObj != Py_None) {
2051 pjsua_buddy_config cfg;
2052 PyObj_pjsua_buddy_config * bc;
2053
2054 bc = (PyObj_pjsua_buddy_config *)bcObj;
2055
2056 pjsua_buddy_config_default(&cfg);
2057 PyObj_pjsua_buddy_config_export(&cfg, bc);
Benny Prijonodc308702006-12-09 00:39:42 +00002058
Benny Prijono1f63cc42007-09-10 16:54:22 +00002059 status = pjsua_buddy_add(&cfg, &buddy_id);
Fahris6f35cb82007-02-01 07:41:26 +00002060 } else {
Benny Prijono1f63cc42007-09-10 16:54:22 +00002061 status = PJ_EINVAL;
2062 buddy_id = PJSUA_INVALID_ID;
Fahris17d91812007-01-29 12:09:33 +00002063 }
Benny Prijono1f63cc42007-09-10 16:54:22 +00002064 return Py_BuildValue("ii", status, buddy_id);
Benny Prijonodc308702006-12-09 00:39:42 +00002065}
2066
2067/*
2068 * py_pjsua_buddy_del
2069 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00002070static PyObject *py_pjsua_buddy_del(PyObject *pSelf, PyObject *pArgs)
Benny Prijonodc308702006-12-09 00:39:42 +00002071{
2072 int buddy_id;
2073 int status;
2074
Benny Prijono1f63cc42007-09-10 16:54:22 +00002075 PJ_UNUSED_ARG(pSelf);
2076
2077 if (!PyArg_ParseTuple(pArgs, "i", &buddy_id)) {
Benny Prijonodc308702006-12-09 00:39:42 +00002078 return NULL;
2079 }
2080
2081
2082 status = pjsua_buddy_del(buddy_id);
2083 return Py_BuildValue("i", status);
2084}
2085
2086/*
2087 * py_pjsua_buddy_subscribe_pres
2088 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00002089static PyObject *py_pjsua_buddy_subscribe_pres(PyObject *pSelf, PyObject *pArgs)
Benny Prijonodc308702006-12-09 00:39:42 +00002090{
2091 int buddy_id;
2092 int status;
2093 int subscribe;
2094
Benny Prijono1f63cc42007-09-10 16:54:22 +00002095 PJ_UNUSED_ARG(pSelf);
2096
2097 if (!PyArg_ParseTuple(pArgs, "ii", &buddy_id, &subscribe)) {
Benny Prijonodc308702006-12-09 00:39:42 +00002098 return NULL;
2099 }
2100
2101
2102 status = pjsua_buddy_subscribe_pres(buddy_id, subscribe);
2103 return Py_BuildValue("i", status);
2104}
2105
2106/*
2107 * py_pjsua_pres_dump
2108 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00002109static PyObject *py_pjsua_pres_dump(PyObject *pSelf, PyObject *pArgs)
Benny Prijonodc308702006-12-09 00:39:42 +00002110{
2111 int verbose;
2112
Benny Prijono1f63cc42007-09-10 16:54:22 +00002113 PJ_UNUSED_ARG(pSelf);
2114
2115 if (!PyArg_ParseTuple(pArgs, "i", &verbose)) {
Benny Prijonodc308702006-12-09 00:39:42 +00002116 return NULL;
2117 }
2118
2119
2120 pjsua_pres_dump(verbose);
Benny Prijono98793592006-12-04 08:33:20 +00002121 Py_INCREF(Py_None);
2122 return Py_None;
2123}
2124
Benny Prijonodc308702006-12-09 00:39:42 +00002125/*
2126 * py_pjsua_im_send
2127 * !modified @ 071206
2128 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00002129static PyObject *py_pjsua_im_send(PyObject *pSelf, PyObject *pArgs)
Benny Prijonodc308702006-12-09 00:39:42 +00002130{
2131 int status;
2132 int acc_id;
Fahrise314b882007-02-02 10:52:04 +00002133 pj_str_t * mime_type, tmp_mime_type;
Fahris6f35cb82007-02-01 07:41:26 +00002134 pj_str_t to, content;
Benny Prijonodc308702006-12-09 00:39:42 +00002135 PyObject * st;
2136 PyObject * smt;
2137 PyObject * sc;
2138 pjsua_msg_data msg_data;
Fahris17d91812007-01-29 12:09:33 +00002139 PyObject * omdObj;
Benny Prijono1f63cc42007-09-10 16:54:22 +00002140 PyObj_pjsua_msg_data * omd;
Fahris6f35cb82007-02-01 07:41:26 +00002141
Benny Prijonodc308702006-12-09 00:39:42 +00002142 int user_data;
2143 pj_pool_t *pool;
2144
Benny Prijono1f63cc42007-09-10 16:54:22 +00002145 PJ_UNUSED_ARG(pSelf);
2146
Fahris17d91812007-01-29 12:09:33 +00002147 if (!PyArg_ParseTuple(pArgs, "iOOOOi", &acc_id,
2148 &st, &smt, &sc, &omdObj, &user_data))
Benny Prijonodc308702006-12-09 00:39:42 +00002149 {
2150 return NULL;
2151 }
Benny Prijono1f63cc42007-09-10 16:54:22 +00002152 if (smt != Py_None) {
Fahrise314b882007-02-02 10:52:04 +00002153 mime_type = &tmp_mime_type;
Benny Prijono1f63cc42007-09-10 16:54:22 +00002154 tmp_mime_type = PyString_to_pj_str(smt);
Fahris6f35cb82007-02-01 07:41:26 +00002155 } else {
2156 mime_type = NULL;
2157 }
Benny Prijono1f63cc42007-09-10 16:54:22 +00002158 to = PyString_to_pj_str(st);
2159 content = PyString_to_pj_str(sc);
2160
2161 if (omdObj != Py_None) {
Fahris17d91812007-01-29 12:09:33 +00002162
Benny Prijono1f63cc42007-09-10 16:54:22 +00002163 omd = (PyObj_pjsua_msg_data *)omdObj;
2164 msg_data.content_type = PyString_to_pj_str(omd->content_type);
2165 msg_data.msg_body = PyString_to_pj_str(omd->msg_body);
Fahris6f35cb82007-02-01 07:41:26 +00002166 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Benny Prijonodc308702006-12-09 00:39:42 +00002167
Fahris17d91812007-01-29 12:09:33 +00002168 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
Fahris6f35cb82007-02-01 07:41:26 +00002169 status = pjsua_im_send(acc_id, &to, mime_type,
2170 &content, &msg_data, (void *)user_data);
Fahris17d91812007-01-29 12:09:33 +00002171 pj_pool_release(pool);
Fahris6f35cb82007-02-01 07:41:26 +00002172 } else {
Fahris17d91812007-01-29 12:09:33 +00002173
Fahris6f35cb82007-02-01 07:41:26 +00002174 status = pjsua_im_send(acc_id, &to, mime_type,
Fahris17d91812007-01-29 12:09:33 +00002175 &content, NULL, NULL);
Fahris6f35cb82007-02-01 07:41:26 +00002176 }
Fahrise314b882007-02-02 10:52:04 +00002177
Benny Prijonodc308702006-12-09 00:39:42 +00002178 return Py_BuildValue("i",status);
2179}
2180
2181/*
2182 * py_pjsua_im_typing
2183 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00002184static PyObject *py_pjsua_im_typing(PyObject *pSelf, PyObject *pArgs)
Benny Prijonodc308702006-12-09 00:39:42 +00002185{
2186 int status;
2187 int acc_id;
2188 pj_str_t to;
2189 PyObject * st;
2190 int is_typing;
2191 pjsua_msg_data msg_data;
Fahris6f35cb82007-02-01 07:41:26 +00002192 PyObject * omdObj;
Benny Prijono1f63cc42007-09-10 16:54:22 +00002193 PyObj_pjsua_msg_data * omd;
Benny Prijonodc308702006-12-09 00:39:42 +00002194 pj_pool_t * pool;
2195
Benny Prijono1f63cc42007-09-10 16:54:22 +00002196 PJ_UNUSED_ARG(pSelf);
2197
2198 if (!PyArg_ParseTuple(pArgs, "iOiO", &acc_id, &st, &is_typing, &omdObj)) {
Benny Prijonodc308702006-12-09 00:39:42 +00002199 return NULL;
2200 }
2201
Benny Prijono1f63cc42007-09-10 16:54:22 +00002202 to = PyString_to_pj_str(st);
2203
2204 if (omdObj != Py_None) {
2205 omd = (PyObj_pjsua_msg_data *)omdObj;
2206 msg_data.content_type = PyString_to_pj_str(omd->content_type);
2207 msg_data.msg_body = PyString_to_pj_str(omd->msg_body);
Fahris6f35cb82007-02-01 07:41:26 +00002208 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Benny Prijonodc308702006-12-09 00:39:42 +00002209
Fahris17d91812007-01-29 12:09:33 +00002210 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
2211 status = pjsua_im_typing(acc_id, &to, is_typing, &msg_data);
2212 pj_pool_release(pool);
Fahris6f35cb82007-02-01 07:41:26 +00002213 } else {
Fahris17d91812007-01-29 12:09:33 +00002214 status = pjsua_im_typing(acc_id, &to, is_typing, NULL);
Fahris6f35cb82007-02-01 07:41:26 +00002215 }
Benny Prijonodc308702006-12-09 00:39:42 +00002216 return Py_BuildValue("i",status);
2217}
2218
Fahris6f35cb82007-02-01 07:41:26 +00002219static char pjsua_buddy_config_default_doc[] =
2220 "py_pjsua.Buddy_Config py_pjsua.buddy_config_default () "
2221 "Set default values to the buddy config.";
Benny Prijonodc308702006-12-09 00:39:42 +00002222static char pjsua_get_buddy_count_doc[] =
2223 "int py_pjsua.get_buddy_count () "
2224 "Get total number of buddies.";
2225static char pjsua_buddy_is_valid_doc[] =
2226 "int py_pjsua.buddy_is_valid (int buddy_id) "
2227 "Check if buddy ID is valid.";
2228static char pjsua_enum_buddies_doc[] =
Fahrisdcf8fa42006-12-28 03:13:48 +00002229 "int[] py_pjsua.enum_buddies () "
Benny Prijonodc308702006-12-09 00:39:42 +00002230 "Enum buddy IDs.";
2231static char pjsua_buddy_get_info_doc[] =
2232 "py_pjsua.Buddy_Info py_pjsua.buddy_get_info (int buddy_id) "
2233 "Get detailed buddy info.";
2234static char pjsua_buddy_add_doc[] =
2235 "int,int py_pjsua.buddy_add (py_pjsua.Buddy_Config cfg) "
2236 "Add new buddy.";
2237static char pjsua_buddy_del_doc[] =
2238 "int py_pjsua.buddy_del (int buddy_id) "
2239 "Delete buddy.";
2240static char pjsua_buddy_subscribe_pres_doc[] =
2241 "int py_pjsua.buddy_subscribe_pres (int buddy_id, int subscribe) "
2242 "Enable/disable buddy's presence monitoring.";
2243static char pjsua_pres_dump_doc[] =
2244 "void py_pjsua.pres_dump (int verbose) "
2245 "Dump presence subscriptions to log file.";
2246static char pjsua_im_send_doc[] =
2247 "int py_pjsua.im_send (int acc_id, string to, string mime_type, "
2248 "string content, py_pjsua.Msg_Data msg_data, int user_data) "
2249 "Send instant messaging outside dialog, using the specified account "
2250 "for route set and authentication.";
2251static char pjsua_im_typing_doc[] =
2252 "int py_pjsua.im_typing (int acc_id, string to, int is_typing, "
2253 "py_pjsua.Msg_Data msg_data) "
2254 "Send typing indication outside dialog.";
2255
2256/* END OF LIB BUDDY */
2257
Fahrisdcf8fa42006-12-28 03:13:48 +00002258/* LIB MEDIA */
Benny Prijono98793592006-12-04 08:33:20 +00002259
Benny Prijono572d4852006-11-23 21:50:02 +00002260
Fahrisdcf8fa42006-12-28 03:13:48 +00002261
2262/*
Benny Prijono1f63cc42007-09-10 16:54:22 +00002263 * PyObj_pjsua_codec_info
Fahrisdcf8fa42006-12-28 03:13:48 +00002264 * Codec Info
2265 * !modified @ 071206
2266 */
2267typedef struct
2268{
2269 PyObject_HEAD
2270 /* Type-specific fields go here. */
2271
2272 PyObject * codec_id;
2273 pj_uint8_t priority;
2274 char buf_[32];
Benny Prijono1f63cc42007-09-10 16:54:22 +00002275} PyObj_pjsua_codec_info;
Fahrisdcf8fa42006-12-28 03:13:48 +00002276
2277
2278/*
2279 * codec_info_dealloc
2280 * deletes a codec_info from memory
2281 * !modified @ 071206
2282 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00002283static void codec_info_dealloc(PyObj_pjsua_codec_info* self)
Fahrisdcf8fa42006-12-28 03:13:48 +00002284{
2285 Py_XDECREF(self->codec_id);
2286
2287 self->ob_type->tp_free((PyObject*)self);
2288}
2289
2290
2291/*
2292 * codec_info_new
2293 * constructor for codec_info object
2294 * !modified @ 071206
2295 */
2296static PyObject * codec_info_new(PyTypeObject *type, PyObject *args,
2297 PyObject *kwds)
2298{
Benny Prijono1f63cc42007-09-10 16:54:22 +00002299 PyObj_pjsua_codec_info *self;
Fahrisdcf8fa42006-12-28 03:13:48 +00002300
Benny Prijono1f63cc42007-09-10 16:54:22 +00002301 PJ_UNUSED_ARG(args);
2302 PJ_UNUSED_ARG(kwds);
2303
2304 self = (PyObj_pjsua_codec_info *)type->tp_alloc(type, 0);
Fahrisdcf8fa42006-12-28 03:13:48 +00002305 if (self != NULL)
2306 {
2307 self->codec_id = PyString_FromString("");
2308 if (self->codec_id == NULL)
2309 {
2310 Py_DECREF(self);
2311 return NULL;
2312 }
2313
2314
2315 }
2316 return (PyObject *)self;
2317}
2318
2319/*
2320 * codec_info_members
2321 * !modified @ 071206
2322 */
2323static PyMemberDef codec_info_members[] =
2324{
2325 {
2326 "codec_id", T_OBJECT_EX,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002327 offsetof(PyObj_pjsua_codec_info, codec_id), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002328 "Codec unique identification."
2329 },
2330
2331 {
2332 "priority", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002333 offsetof(PyObj_pjsua_codec_info, priority), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002334 "Codec priority (integer 0-255)."
2335 },
2336
2337
2338
2339 {NULL} /* Sentinel */
2340};
2341
2342
2343
2344
2345/*
Benny Prijono1f63cc42007-09-10 16:54:22 +00002346 * PyTyp_pjsua_codec_info
Fahrisdcf8fa42006-12-28 03:13:48 +00002347 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00002348static PyTypeObject PyTyp_pjsua_codec_info =
Fahrisdcf8fa42006-12-28 03:13:48 +00002349{
2350 PyObject_HEAD_INIT(NULL)
2351 0, /*ob_size*/
2352 "py_pjsua.Codec_Info", /*tp_name*/
Benny Prijono1f63cc42007-09-10 16:54:22 +00002353 sizeof(PyObj_pjsua_codec_info), /*tp_basicsize*/
Fahrisdcf8fa42006-12-28 03:13:48 +00002354 0, /*tp_itemsize*/
2355 (destructor)codec_info_dealloc,/*tp_dealloc*/
2356 0, /*tp_print*/
2357 0, /*tp_getattr*/
2358 0, /*tp_setattr*/
2359 0, /*tp_compare*/
2360 0, /*tp_repr*/
2361 0, /*tp_as_number*/
2362 0, /*tp_as_sequence*/
2363 0, /*tp_as_mapping*/
2364 0, /*tp_hash */
2365 0, /*tp_call*/
2366 0, /*tp_str*/
2367 0, /*tp_getattro*/
2368 0, /*tp_setattro*/
2369 0, /*tp_as_buffer*/
2370 Py_TPFLAGS_DEFAULT, /*tp_flags*/
2371 "Codec Info objects", /* tp_doc */
2372 0, /* tp_traverse */
2373 0, /* tp_clear */
2374 0, /* tp_richcompare */
2375 0, /* tp_weaklistoffset */
2376 0, /* tp_iter */
2377 0, /* tp_iternext */
2378 0, /* tp_methods */
2379 codec_info_members, /* tp_members */
2380 0, /* tp_getset */
2381 0, /* tp_base */
2382 0, /* tp_dict */
2383 0, /* tp_descr_get */
2384 0, /* tp_descr_set */
2385 0, /* tp_dictoffset */
2386 0, /* tp_init */
2387 0, /* tp_alloc */
2388 codec_info_new, /* tp_new */
2389
2390};
2391
2392/*
Benny Prijono1f63cc42007-09-10 16:54:22 +00002393 * PyObj_pjsua_conf_port_info
Fahrisdcf8fa42006-12-28 03:13:48 +00002394 * Conf Port Info
2395 */
2396typedef struct
2397{
2398 PyObject_HEAD
2399 /* Type-specific fields go here. */
2400
2401 int slot_id;
2402 PyObject * name;
2403 unsigned clock_rate;
2404 unsigned channel_count;
2405 unsigned samples_per_frame;
2406 unsigned bits_per_sample;
Fahrisdcf8fa42006-12-28 03:13:48 +00002407 PyListObject * listeners;
2408
Benny Prijono1f63cc42007-09-10 16:54:22 +00002409} PyObj_pjsua_conf_port_info;
Fahrisdcf8fa42006-12-28 03:13:48 +00002410
2411
2412/*
2413 * conf_port_info_dealloc
2414 * deletes a conf_port_info from memory
2415 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00002416static void conf_port_info_dealloc(PyObj_pjsua_conf_port_info* self)
Fahrisdcf8fa42006-12-28 03:13:48 +00002417{
2418 Py_XDECREF(self->name);
2419 Py_XDECREF(self->listeners);
2420 self->ob_type->tp_free((PyObject*)self);
2421}
2422
2423
2424/*
2425 * conf_port_info_new
2426 * constructor for conf_port_info object
2427 */
2428static PyObject * conf_port_info_new(PyTypeObject *type, PyObject *args,
2429 PyObject *kwds)
2430{
Benny Prijono1f63cc42007-09-10 16:54:22 +00002431 PyObj_pjsua_conf_port_info *self;
Fahrisdcf8fa42006-12-28 03:13:48 +00002432
Benny Prijono1f63cc42007-09-10 16:54:22 +00002433 PJ_UNUSED_ARG(args);
2434 PJ_UNUSED_ARG(kwds);
2435
2436 self = (PyObj_pjsua_conf_port_info *)type->tp_alloc(type, 0);
Fahrisdcf8fa42006-12-28 03:13:48 +00002437 if (self != NULL)
2438 {
2439 self->name = PyString_FromString("");
2440 if (self->name == NULL)
2441 {
2442 Py_DECREF(self);
2443 return NULL;
2444 }
2445
Benny Prijonod7ea6052007-09-17 15:44:47 +00002446 self->listeners = (PyListObject *)PyList_New(0);
Fahrisdcf8fa42006-12-28 03:13:48 +00002447 if (self->listeners == NULL)
2448 {
2449 Py_DECREF(self);
2450 return NULL;
2451 }
2452 }
2453 return (PyObject *)self;
2454}
2455
2456/*
2457 * conf_port_info_members
2458 */
2459static PyMemberDef conf_port_info_members[] =
2460{
2461 {
2462 "slot_id", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002463 offsetof(PyObj_pjsua_conf_port_info, slot_id), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002464 "Conference port number."
2465 },
2466 {
2467 "name", T_OBJECT_EX,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002468 offsetof(PyObj_pjsua_conf_port_info, name), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002469 "Port name"
2470 },
2471 {
2472 "clock_rate", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002473 offsetof(PyObj_pjsua_conf_port_info, clock_rate), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002474 "Clock rate"
2475 },
2476 {
2477 "channel_count", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002478 offsetof(PyObj_pjsua_conf_port_info, channel_count), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002479 "Number of channels."
2480 },
2481 {
2482 "samples_per_frame", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002483 offsetof(PyObj_pjsua_conf_port_info, samples_per_frame), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002484 "Samples per frame "
2485 },
2486 {
2487 "bits_per_sample", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002488 offsetof(PyObj_pjsua_conf_port_info, bits_per_sample), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002489 "Bits per sample"
2490 },
Fahris89ea3d02007-02-07 08:18:35 +00002491 {
Fahrisdcf8fa42006-12-28 03:13:48 +00002492 "listeners", T_OBJECT_EX,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002493 offsetof(PyObj_pjsua_conf_port_info, listeners), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002494 "Array of listeners (in other words, ports where this port "
2495 "is transmitting to"
2496 },
2497
2498 {NULL} /* Sentinel */
2499};
2500
2501
2502
2503
2504/*
Benny Prijono1f63cc42007-09-10 16:54:22 +00002505 * PyTyp_pjsua_conf_port_info
Fahrisdcf8fa42006-12-28 03:13:48 +00002506 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00002507static PyTypeObject PyTyp_pjsua_conf_port_info =
Fahrisdcf8fa42006-12-28 03:13:48 +00002508{
2509 PyObject_HEAD_INIT(NULL)
2510 0, /*ob_size*/
2511 "py_pjsua.Conf_Port_Info", /*tp_name*/
Benny Prijono1f63cc42007-09-10 16:54:22 +00002512 sizeof(PyObj_pjsua_conf_port_info), /*tp_basicsize*/
Fahrisdcf8fa42006-12-28 03:13:48 +00002513 0, /*tp_itemsize*/
2514 (destructor)conf_port_info_dealloc,/*tp_dealloc*/
2515 0, /*tp_print*/
2516 0, /*tp_getattr*/
2517 0, /*tp_setattr*/
2518 0, /*tp_compare*/
2519 0, /*tp_repr*/
2520 0, /*tp_as_number*/
2521 0, /*tp_as_sequence*/
2522 0, /*tp_as_mapping*/
2523 0, /*tp_hash */
2524 0, /*tp_call*/
2525 0, /*tp_str*/
2526 0, /*tp_getattro*/
2527 0, /*tp_setattro*/
2528 0, /*tp_as_buffer*/
2529 Py_TPFLAGS_DEFAULT, /*tp_flags*/
2530 "Conf Port Info objects", /* tp_doc */
2531 0, /* tp_traverse */
2532 0, /* tp_clear */
2533 0, /* tp_richcompare */
2534 0, /* tp_weaklistoffset */
2535 0, /* tp_iter */
2536 0, /* tp_iternext */
2537 0, /* tp_methods */
2538 conf_port_info_members, /* tp_members */
2539 0, /* tp_getset */
2540 0, /* tp_base */
2541 0, /* tp_dict */
2542 0, /* tp_descr_get */
2543 0, /* tp_descr_set */
2544 0, /* tp_dictoffset */
2545 0, /* tp_init */
2546 0, /* tp_alloc */
2547 conf_port_info_new, /* tp_new */
2548
2549};
2550
2551/*
Benny Prijono1f63cc42007-09-10 16:54:22 +00002552 * PyObj_pjmedia_port
Fahrisdcf8fa42006-12-28 03:13:48 +00002553 */
2554typedef struct
2555{
2556 PyObject_HEAD
2557 /* Type-specific fields go here. */
2558 pjmedia_port * port;
Benny Prijono1f63cc42007-09-10 16:54:22 +00002559} PyObj_pjmedia_port;
Fahrisdcf8fa42006-12-28 03:13:48 +00002560
2561
2562/*
Benny Prijono1f63cc42007-09-10 16:54:22 +00002563 * PyTyp_pjmedia_port
Fahrisdcf8fa42006-12-28 03:13:48 +00002564 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00002565static PyTypeObject PyTyp_pjmedia_port =
Fahrisdcf8fa42006-12-28 03:13:48 +00002566{
2567 PyObject_HEAD_INIT(NULL)
2568 0, /*ob_size*/
2569 "py_pjsua.PJMedia_Port", /*tp_name*/
Benny Prijono1f63cc42007-09-10 16:54:22 +00002570 sizeof(PyObj_pjmedia_port), /*tp_basicsize*/
Fahrisdcf8fa42006-12-28 03:13:48 +00002571 0, /*tp_itemsize*/
2572 0, /*tp_dealloc*/
2573 0, /*tp_print*/
2574 0, /*tp_getattr*/
2575 0, /*tp_setattr*/
2576 0, /*tp_compare*/
2577 0, /*tp_repr*/
2578 0, /*tp_as_number*/
2579 0, /*tp_as_sequence*/
2580 0, /*tp_as_mapping*/
2581 0, /*tp_hash */
2582 0, /*tp_call*/
2583 0, /*tp_str*/
2584 0, /*tp_getattro*/
2585 0, /*tp_setattro*/
2586 0, /*tp_as_buffer*/
2587 Py_TPFLAGS_DEFAULT, /*tp_flags*/
2588 "pjmedia_port objects", /* tp_doc */
2589
2590};
2591
2592/*
Benny Prijono1f63cc42007-09-10 16:54:22 +00002593 * PyObj_pjmedia_snd_dev_info
Fahrisdcf8fa42006-12-28 03:13:48 +00002594 * PJMedia Snd Dev Info
2595 */
2596typedef struct
2597{
2598 PyObject_HEAD
2599 /* Type-specific fields go here. */
2600
2601
2602 unsigned input_count;
2603 unsigned output_count;
2604 unsigned default_samples_per_sec;
Fahrise314b882007-02-02 10:52:04 +00002605 PyObject * name;
Fahrisdcf8fa42006-12-28 03:13:48 +00002606
Benny Prijono1f63cc42007-09-10 16:54:22 +00002607} PyObj_pjmedia_snd_dev_info;
Fahrisdcf8fa42006-12-28 03:13:48 +00002608
2609
2610/*
2611 * pjmedia_snd_dev_info_dealloc
2612 * deletes a pjmedia_snd_dev_info from memory
2613 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00002614static void pjmedia_snd_dev_info_dealloc(PyObj_pjmedia_snd_dev_info* self)
Fahrisdcf8fa42006-12-28 03:13:48 +00002615{
2616 Py_XDECREF(self->name);
2617 self->ob_type->tp_free((PyObject*)self);
2618}
2619
2620
2621/*
2622 * pjmedia_snd_dev_info_new
2623 * constructor for pjmedia_snd_dev_info object
2624 */
2625static PyObject * pjmedia_snd_dev_info_new(PyTypeObject *type, PyObject *args,
2626 PyObject *kwds)
2627{
Benny Prijono1f63cc42007-09-10 16:54:22 +00002628 PyObj_pjmedia_snd_dev_info *self;
Fahrisdcf8fa42006-12-28 03:13:48 +00002629
Benny Prijono1f63cc42007-09-10 16:54:22 +00002630 PJ_UNUSED_ARG(args);
2631 PJ_UNUSED_ARG(kwds);
2632
2633 self = (PyObj_pjmedia_snd_dev_info *)type->tp_alloc(type, 0);
Fahrisdcf8fa42006-12-28 03:13:48 +00002634 if (self != NULL)
2635 {
Fahrise314b882007-02-02 10:52:04 +00002636 self->name = PyString_FromString("");
Fahrisdcf8fa42006-12-28 03:13:48 +00002637 if (self->name == NULL)
2638 {
2639 Py_DECREF(self);
2640 return NULL;
2641 }
2642
2643 }
2644 return (PyObject *)self;
2645}
2646
2647/*
2648 * pjmedia_snd_dev_info_members
2649 */
2650static PyMemberDef pjmedia_snd_dev_info_members[] =
2651{
2652
2653 {
2654 "name", T_OBJECT_EX,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002655 offsetof(PyObj_pjmedia_snd_dev_info, name), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002656 "Device name"
2657 },
2658 {
2659 "input_count", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002660 offsetof(PyObj_pjmedia_snd_dev_info, input_count), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002661 "Max number of input channels"
2662 },
2663 {
2664 "output_count", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002665 offsetof(PyObj_pjmedia_snd_dev_info, output_count), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002666 "Max number of output channels"
2667 },
2668 {
2669 "default_samples_per_sec", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002670 offsetof(PyObj_pjmedia_snd_dev_info, default_samples_per_sec), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002671 "Default sampling rate."
2672 },
2673
2674
2675 {NULL} /* Sentinel */
2676};
2677
2678
2679
2680
2681/*
Benny Prijono1f63cc42007-09-10 16:54:22 +00002682 * PyTyp_pjmedia_snd_dev_info
Fahrisdcf8fa42006-12-28 03:13:48 +00002683 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00002684static PyTypeObject PyTyp_pjmedia_snd_dev_info =
Fahrisdcf8fa42006-12-28 03:13:48 +00002685{
2686 PyObject_HEAD_INIT(NULL)
2687 0, /*ob_size*/
2688 "py_pjsua.PJMedia_Snd_Dev_Info", /*tp_name*/
Benny Prijono1f63cc42007-09-10 16:54:22 +00002689 sizeof(PyObj_pjmedia_snd_dev_info), /*tp_basicsize*/
Fahrisdcf8fa42006-12-28 03:13:48 +00002690 0, /*tp_itemsize*/
2691 (destructor)pjmedia_snd_dev_info_dealloc,/*tp_dealloc*/
2692 0, /*tp_print*/
2693 0, /*tp_getattr*/
2694 0, /*tp_setattr*/
2695 0, /*tp_compare*/
2696 0, /*tp_repr*/
2697 0, /*tp_as_number*/
2698 0, /*tp_as_sequence*/
2699 0, /*tp_as_mapping*/
2700 0, /*tp_hash */
2701 0, /*tp_call*/
2702 0, /*tp_str*/
2703 0, /*tp_getattro*/
2704 0, /*tp_setattro*/
2705 0, /*tp_as_buffer*/
2706 Py_TPFLAGS_DEFAULT, /*tp_flags*/
2707 "PJMedia Snd Dev Info objects", /* tp_doc */
2708 0, /* tp_traverse */
2709 0, /* tp_clear */
2710 0, /* tp_richcompare */
2711 0, /* tp_weaklistoffset */
2712 0, /* tp_iter */
2713 0, /* tp_iternext */
2714 0, /* tp_methods */
2715 pjmedia_snd_dev_info_members, /* tp_members */
2716 0, /* tp_getset */
2717 0, /* tp_base */
2718 0, /* tp_dict */
2719 0, /* tp_descr_get */
2720 0, /* tp_descr_set */
2721 0, /* tp_dictoffset */
2722 0, /* tp_init */
2723 0, /* tp_alloc */
2724 pjmedia_snd_dev_info_new, /* tp_new */
2725
2726};
2727
2728/*
Benny Prijono1f63cc42007-09-10 16:54:22 +00002729 * PyObj_pjmedia_codec_param_info
Fahrisdcf8fa42006-12-28 03:13:48 +00002730 * PJMedia Codec Param Info
2731 */
2732typedef struct
2733{
2734 PyObject_HEAD
2735 /* Type-specific fields go here. */
2736
2737 unsigned clock_rate;
2738 unsigned channel_cnt;
2739 pj_uint32_t avg_bps;
2740 pj_uint16_t frm_ptime;
2741 pj_uint8_t pcm_bits_per_sample;
2742 pj_uint8_t pt;
2743
Benny Prijono1f63cc42007-09-10 16:54:22 +00002744} PyObj_pjmedia_codec_param_info;
Fahrisdcf8fa42006-12-28 03:13:48 +00002745
2746
2747
2748/*
2749 * pjmedia_codec_param_info_members
2750 */
2751static PyMemberDef pjmedia_codec_param_info_members[] =
2752{
2753
2754 {
2755 "clock_rate", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002756 offsetof(PyObj_pjmedia_codec_param_info, clock_rate), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002757 "Sampling rate in Hz"
2758 },
2759 {
2760 "channel_cnt", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002761 offsetof(PyObj_pjmedia_codec_param_info, channel_cnt), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002762 "Channel count"
2763 },
2764 {
2765 "avg_bps", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002766 offsetof(PyObj_pjmedia_codec_param_info, avg_bps), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002767 "Average bandwidth in bits/sec"
2768 },
2769 {
2770 "frm_ptime", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002771 offsetof(PyObj_pjmedia_codec_param_info, frm_ptime), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002772 "Base frame ptime in msec."
2773 },
2774 {
2775 "pcm_bits_per_sample", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002776 offsetof(PyObj_pjmedia_codec_param_info, pcm_bits_per_sample), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002777 "Bits/sample in the PCM side"
2778 },
2779 {
2780 "pt", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002781 offsetof(PyObj_pjmedia_codec_param_info, pt), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002782 "Payload type"
2783 },
2784
2785 {NULL} /* Sentinel */
2786};
2787
2788
2789
2790
2791/*
Benny Prijono1f63cc42007-09-10 16:54:22 +00002792 * PyTyp_pjmedia_codec_param_info
Fahrisdcf8fa42006-12-28 03:13:48 +00002793 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00002794static PyTypeObject PyTyp_pjmedia_codec_param_info =
Fahrisdcf8fa42006-12-28 03:13:48 +00002795{
2796 PyObject_HEAD_INIT(NULL)
2797 0, /*ob_size*/
2798 "py_pjsua.PJMedia_Codec_Param_Info", /*tp_name*/
Benny Prijono1f63cc42007-09-10 16:54:22 +00002799 sizeof(PyObj_pjmedia_codec_param_info), /*tp_basicsize*/
Fahrisdcf8fa42006-12-28 03:13:48 +00002800 0, /*tp_itemsize*/
2801 0,/*tp_dealloc*/
2802 0, /*tp_print*/
2803 0, /*tp_getattr*/
2804 0, /*tp_setattr*/
2805 0, /*tp_compare*/
2806 0, /*tp_repr*/
2807 0, /*tp_as_number*/
2808 0, /*tp_as_sequence*/
2809 0, /*tp_as_mapping*/
2810 0, /*tp_hash */
2811 0, /*tp_call*/
2812 0, /*tp_str*/
2813 0, /*tp_getattro*/
2814 0, /*tp_setattro*/
2815 0, /*tp_as_buffer*/
2816 Py_TPFLAGS_DEFAULT, /*tp_flags*/
2817 "PJMedia Codec Param Info objects", /* tp_doc */
2818 0, /* tp_traverse */
2819 0, /* tp_clear */
2820 0, /* tp_richcompare */
2821 0, /* tp_weaklistoffset */
2822 0, /* tp_iter */
2823 0, /* tp_iternext */
2824 0, /* tp_methods */
2825 pjmedia_codec_param_info_members, /* tp_members */
2826
2827
2828};
2829
2830/*
Benny Prijono1f63cc42007-09-10 16:54:22 +00002831 * PyObj_pjmedia_codec_param_setting
Fahrisdcf8fa42006-12-28 03:13:48 +00002832 * PJMedia Codec Param Setting
2833 */
2834typedef struct
2835{
2836 PyObject_HEAD
2837 /* Type-specific fields go here. */
2838 pj_uint8_t frm_per_pkt;
2839 unsigned vad;
2840 unsigned cng;
2841 unsigned penh;
2842 unsigned plc;
2843 unsigned reserved;
2844 pj_uint8_t enc_fmtp_mode;
2845 pj_uint8_t dec_fmtp_mode;
2846
Benny Prijono1f63cc42007-09-10 16:54:22 +00002847} PyObj_pjmedia_codec_param_setting;
Fahrisdcf8fa42006-12-28 03:13:48 +00002848
2849
2850
2851/*
2852 * pjmedia_codec_param_setting_members
2853 */
2854static PyMemberDef pjmedia_codec_param_setting_members[] =
2855{
2856
2857 {
2858 "frm_per_pkt", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002859 offsetof(PyObj_pjmedia_codec_param_setting, frm_per_pkt), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002860 "Number of frames per packet"
2861 },
2862 {
2863 "vad", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002864 offsetof(PyObj_pjmedia_codec_param_setting, vad), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002865 "Voice Activity Detector"
2866 },
2867 {
2868 "penh", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002869 offsetof(PyObj_pjmedia_codec_param_setting, penh), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002870 "Perceptual Enhancement"
2871 },
2872 {
2873 "plc", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002874 offsetof(PyObj_pjmedia_codec_param_setting, plc), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002875 "Packet loss concealment"
2876 },
2877 {
2878 "reserved", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002879 offsetof(PyObj_pjmedia_codec_param_setting, reserved), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002880 "Reserved, must be zero"
2881 },
2882 {
2883 "cng", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002884 offsetof(PyObj_pjmedia_codec_param_setting, cng), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002885 "Comfort Noise Generator"
2886 },
2887 {
2888 "enc_fmtp_mode", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002889 offsetof(PyObj_pjmedia_codec_param_setting, enc_fmtp_mode), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002890 "Mode param in fmtp (def:0)"
2891 },
2892 {
2893 "dec_fmtp_mode", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002894 offsetof(PyObj_pjmedia_codec_param_setting, dec_fmtp_mode), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002895 "Mode param in fmtp (def:0)"
2896 },
2897
2898 {NULL} /* Sentinel */
2899};
2900
2901
2902
2903
2904/*
Benny Prijono1f63cc42007-09-10 16:54:22 +00002905 * PyTyp_pjmedia_codec_param_setting
Fahrisdcf8fa42006-12-28 03:13:48 +00002906 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00002907static PyTypeObject PyTyp_pjmedia_codec_param_setting =
Fahrisdcf8fa42006-12-28 03:13:48 +00002908{
2909 PyObject_HEAD_INIT(NULL)
2910 0, /*ob_size*/
2911 "py_pjsua.PJMedia_Codec_Param_Setting", /*tp_name*/
Benny Prijono1f63cc42007-09-10 16:54:22 +00002912 sizeof(PyObj_pjmedia_codec_param_setting), /*tp_basicsize*/
Fahrisdcf8fa42006-12-28 03:13:48 +00002913 0, /*tp_itemsize*/
2914 0,/*tp_dealloc*/
2915 0, /*tp_print*/
2916 0, /*tp_getattr*/
2917 0, /*tp_setattr*/
2918 0, /*tp_compare*/
2919 0, /*tp_repr*/
2920 0, /*tp_as_number*/
2921 0, /*tp_as_sequence*/
2922 0, /*tp_as_mapping*/
2923 0, /*tp_hash */
2924 0, /*tp_call*/
2925 0, /*tp_str*/
2926 0, /*tp_getattro*/
2927 0, /*tp_setattro*/
2928 0, /*tp_as_buffer*/
2929 Py_TPFLAGS_DEFAULT, /*tp_flags*/
2930 "PJMedia Codec Param Setting objects", /* tp_doc */
2931 0, /* tp_traverse */
2932 0, /* tp_clear */
2933 0, /* tp_richcompare */
2934 0, /* tp_weaklistoffset */
2935 0, /* tp_iter */
2936 0, /* tp_iternext */
2937 0, /* tp_methods */
2938 pjmedia_codec_param_setting_members, /* tp_members */
2939
2940
2941};
2942
2943/*
Benny Prijono1f63cc42007-09-10 16:54:22 +00002944 * PyObj_pjmedia_codec_param
Fahrisdcf8fa42006-12-28 03:13:48 +00002945 * PJMedia Codec Param
2946 */
2947typedef struct
2948{
2949 PyObject_HEAD
2950 /* Type-specific fields go here. */
2951
Benny Prijono1f63cc42007-09-10 16:54:22 +00002952 PyObj_pjmedia_codec_param_info * info;
2953 PyObj_pjmedia_codec_param_setting * setting;
Fahrisdcf8fa42006-12-28 03:13:48 +00002954
Benny Prijono1f63cc42007-09-10 16:54:22 +00002955} PyObj_pjmedia_codec_param;
Fahrisdcf8fa42006-12-28 03:13:48 +00002956
2957
2958/*
2959 * pjmedia_codec_param_dealloc
2960 * deletes a pjmedia_codec_param from memory
2961 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00002962static void pjmedia_codec_param_dealloc(PyObj_pjmedia_codec_param* self)
Fahrisdcf8fa42006-12-28 03:13:48 +00002963{
2964 Py_XDECREF(self->info);
2965 Py_XDECREF(self->setting);
2966 self->ob_type->tp_free((PyObject*)self);
2967}
2968
2969
2970/*
2971 * pjmedia_codec_param_new
2972 * constructor for pjmedia_codec_param object
2973 */
2974static PyObject * pjmedia_codec_param_new(PyTypeObject *type, PyObject *args,
2975 PyObject *kwds)
2976{
Benny Prijono1f63cc42007-09-10 16:54:22 +00002977 PyObj_pjmedia_codec_param *self;
Fahrisdcf8fa42006-12-28 03:13:48 +00002978
Benny Prijono1f63cc42007-09-10 16:54:22 +00002979 PJ_UNUSED_ARG(args);
2980 PJ_UNUSED_ARG(kwds);
2981
2982 self = (PyObj_pjmedia_codec_param *)type->tp_alloc(type, 0);
Fahrisdcf8fa42006-12-28 03:13:48 +00002983 if (self != NULL)
2984 {
Benny Prijono1f63cc42007-09-10 16:54:22 +00002985 self->info = (PyObj_pjmedia_codec_param_info *)
2986 PyType_GenericNew(&PyTyp_pjmedia_codec_param_info, NULL, NULL);
Fahrisdcf8fa42006-12-28 03:13:48 +00002987 if (self->info == NULL)
2988 {
2989 Py_DECREF(self);
2990 return NULL;
2991 }
Benny Prijono1f63cc42007-09-10 16:54:22 +00002992 self->setting = (PyObj_pjmedia_codec_param_setting *)
2993 PyType_GenericNew(&PyTyp_pjmedia_codec_param_setting, NULL, NULL);
Fahrisdcf8fa42006-12-28 03:13:48 +00002994 if (self->setting == NULL)
2995 {
2996 Py_DECREF(self);
2997 return NULL;
2998 }
2999 }
3000 return (PyObject *)self;
3001}
3002
3003/*
3004 * pjmedia_codec_param_members
3005 */
3006static PyMemberDef pjmedia_codec_param_members[] =
3007{
3008
3009 {
3010 "info", T_OBJECT_EX,
Benny Prijono1f63cc42007-09-10 16:54:22 +00003011 offsetof(PyObj_pjmedia_codec_param, info), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00003012 "The 'info' part of codec param describes the capability of the codec,"
3013 " and the value should NOT be changed by application."
3014 },
3015 {
3016 "setting", T_OBJECT_EX,
Benny Prijono1f63cc42007-09-10 16:54:22 +00003017 offsetof(PyObj_pjmedia_codec_param, setting), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00003018 "The 'setting' part of codec param describes various settings to be "
3019 "applied to the codec. When the codec param is retrieved from the "
3020 "codec or codec factory, the values of these will be filled by "
3021 "the capability of the codec. Any features that are supported by "
3022 "the codec (e.g. vad or plc) will be turned on, so that application "
3023 "can query which capabilities are supported by the codec. "
3024 "Application may change the settings here before instantiating "
3025 "the codec/stream."
3026 },
3027
3028 {NULL} /* Sentinel */
3029};
3030
3031
3032
3033
3034/*
Benny Prijono1f63cc42007-09-10 16:54:22 +00003035 * PyTyp_pjmedia_codec_param
Fahrisdcf8fa42006-12-28 03:13:48 +00003036 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00003037static PyTypeObject PyTyp_pjmedia_codec_param =
Fahrisdcf8fa42006-12-28 03:13:48 +00003038{
3039 PyObject_HEAD_INIT(NULL)
3040 0, /*ob_size*/
3041 "py_pjsua.PJMedia_Codec_Param", /*tp_name*/
Benny Prijono1f63cc42007-09-10 16:54:22 +00003042 sizeof(PyObj_pjmedia_codec_param), /*tp_basicsize*/
Fahrisdcf8fa42006-12-28 03:13:48 +00003043 0, /*tp_itemsize*/
3044 (destructor)pjmedia_codec_param_dealloc,/*tp_dealloc*/
3045 0, /*tp_print*/
3046 0, /*tp_getattr*/
3047 0, /*tp_setattr*/
3048 0, /*tp_compare*/
3049 0, /*tp_repr*/
3050 0, /*tp_as_number*/
3051 0, /*tp_as_sequence*/
3052 0, /*tp_as_mapping*/
3053 0, /*tp_hash */
3054 0, /*tp_call*/
3055 0, /*tp_str*/
3056 0, /*tp_getattro*/
3057 0, /*tp_setattro*/
3058 0, /*tp_as_buffer*/
3059 Py_TPFLAGS_DEFAULT, /*tp_flags*/
3060 "PJMedia Codec Param objects", /* tp_doc */
3061 0, /* tp_traverse */
3062 0, /* tp_clear */
3063 0, /* tp_richcompare */
3064 0, /* tp_weaklistoffset */
3065 0, /* tp_iter */
3066 0, /* tp_iternext */
3067 0, /* tp_methods */
3068 pjmedia_codec_param_members, /* tp_members */
3069 0, /* tp_getset */
3070 0, /* tp_base */
3071 0, /* tp_dict */
3072 0, /* tp_descr_get */
3073 0, /* tp_descr_set */
3074 0, /* tp_dictoffset */
3075 0, /* tp_init */
3076 0, /* tp_alloc */
3077 pjmedia_codec_param_new, /* tp_new */
3078
3079};
3080
3081/*
3082 * py_pjsua_conf_get_max_ports
3083 */
3084static PyObject *py_pjsua_conf_get_max_ports
3085(PyObject *pSelf, PyObject *pArgs)
3086{
3087 int ret;
3088
Benny Prijono1f63cc42007-09-10 16:54:22 +00003089 PJ_UNUSED_ARG(pSelf);
3090
Fahrisdcf8fa42006-12-28 03:13:48 +00003091 if (!PyArg_ParseTuple(pArgs, ""))
3092 {
3093 return NULL;
3094 }
3095 ret = pjsua_conf_get_max_ports();
3096
3097 return Py_BuildValue("i", ret);
3098}
3099
3100/*
3101 * py_pjsua_conf_get_active_ports
3102 */
3103static PyObject *py_pjsua_conf_get_active_ports
3104(PyObject *pSelf, PyObject *pArgs)
3105{
3106 int ret;
Benny Prijono1f63cc42007-09-10 16:54:22 +00003107
3108 PJ_UNUSED_ARG(pSelf);
3109
Fahrisdcf8fa42006-12-28 03:13:48 +00003110 if (!PyArg_ParseTuple(pArgs, ""))
3111 {
3112 return NULL;
3113 }
3114 ret = pjsua_conf_get_active_ports();
3115
3116 return Py_BuildValue("i", ret);
3117}
3118
3119/*
3120 * py_pjsua_enum_conf_ports
3121 * !modified @ 241206
3122 */
3123static PyObject *py_pjsua_enum_conf_ports(PyObject *pSelf, PyObject *pArgs)
3124{
3125 pj_status_t status;
3126 PyObject *list;
3127
3128 pjsua_conf_port_id id[PJSUA_MAX_CONF_PORTS];
Fahris17d91812007-01-29 12:09:33 +00003129 unsigned c, i;
Benny Prijono1f63cc42007-09-10 16:54:22 +00003130
3131 PJ_UNUSED_ARG(pSelf);
3132
Fahrisdcf8fa42006-12-28 03:13:48 +00003133 if (!PyArg_ParseTuple(pArgs, ""))
3134 {
3135 return NULL;
3136 }
3137
3138 c = PJ_ARRAY_SIZE(id);
3139 status = pjsua_enum_conf_ports(id, &c);
3140
3141 list = PyList_New(c);
Fahris6f35cb82007-02-01 07:41:26 +00003142 for (i = 0; i < c; i++)
3143 {
Fahrisdcf8fa42006-12-28 03:13:48 +00003144 int ret = PyList_SetItem(list, i, Py_BuildValue("i", id[i]));
Fahris6f35cb82007-02-01 07:41:26 +00003145 if (ret == -1)
3146 {
Fahrisdcf8fa42006-12-28 03:13:48 +00003147 return NULL;
3148 }
3149 }
3150
Fahrisdcf8fa42006-12-28 03:13:48 +00003151 return Py_BuildValue("O",list);
3152}
3153
3154/*
3155 * py_pjsua_conf_get_port_info
3156 */
3157static PyObject *py_pjsua_conf_get_port_info
3158(PyObject *pSelf, PyObject *pArgs)
3159{
3160 int id;
Benny Prijono1f63cc42007-09-10 16:54:22 +00003161 PyObj_pjsua_conf_port_info * obj;
Fahrisdcf8fa42006-12-28 03:13:48 +00003162 pjsua_conf_port_info info;
3163 int status;
Benny Prijonod7ea6052007-09-17 15:44:47 +00003164 unsigned i;
Fahrisdcf8fa42006-12-28 03:13:48 +00003165
Benny Prijono1f63cc42007-09-10 16:54:22 +00003166 PJ_UNUSED_ARG(pSelf);
3167
Fahrisdcf8fa42006-12-28 03:13:48 +00003168 if (!PyArg_ParseTuple(pArgs, "i", &id))
3169 {
3170 return NULL;
3171 }
3172
3173
3174 status = pjsua_conf_get_port_info(id, &info);
Benny Prijono1f63cc42007-09-10 16:54:22 +00003175 obj = (PyObj_pjsua_conf_port_info *)conf_port_info_new
3176 (&PyTyp_pjsua_conf_port_info,NULL,NULL);
Fahrisdcf8fa42006-12-28 03:13:48 +00003177 obj->bits_per_sample = info.bits_per_sample;
3178 obj->channel_count = info.bits_per_sample;
3179 obj->clock_rate = info.clock_rate;
Fahrisdcf8fa42006-12-28 03:13:48 +00003180 obj->name = PyString_FromStringAndSize(info.name.ptr, info.name.slen);
3181 obj->samples_per_frame = info.samples_per_frame;
3182 obj->slot_id = info.slot_id;
3183
Benny Prijonod7ea6052007-09-17 15:44:47 +00003184 obj->listeners = (PyListObject *)PyList_New(info.listener_cnt);
3185 for (i = 0; i < info.listener_cnt; i++) {
Fahrisdcf8fa42006-12-28 03:13:48 +00003186 PyObject * item = Py_BuildValue("i",info.listeners[i]);
3187 PyList_SetItem((PyObject *)obj->listeners, i, item);
3188 }
3189 return Py_BuildValue("O", obj);
3190}
3191
3192/*
3193 * py_pjsua_conf_add_port
3194 */
3195static PyObject *py_pjsua_conf_add_port
3196(PyObject *pSelf, PyObject *pArgs)
3197{
3198 int p_id;
Fahris6f35cb82007-02-01 07:41:26 +00003199 PyObject * oportObj;
Benny Prijono1f63cc42007-09-10 16:54:22 +00003200 PyObj_pjmedia_port * oport;
Fahris6f35cb82007-02-01 07:41:26 +00003201 pjmedia_port * port;
3202 PyObject * opoolObj;
Benny Prijono1f63cc42007-09-10 16:54:22 +00003203 PyObj_pj_pool * opool;
Fahris6f35cb82007-02-01 07:41:26 +00003204 pj_pool_t * pool;
Fahrisdcf8fa42006-12-28 03:13:48 +00003205
3206 int status;
3207
Benny Prijono1f63cc42007-09-10 16:54:22 +00003208 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00003209
Fahris17d91812007-01-29 12:09:33 +00003210 if (!PyArg_ParseTuple(pArgs, "OO", &opoolObj, &oportObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00003211 {
3212 return NULL;
3213 }
Fahris17d91812007-01-29 12:09:33 +00003214 if (opoolObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00003215 {
Benny Prijono1f63cc42007-09-10 16:54:22 +00003216 opool = (PyObj_pj_pool *)opoolObj;
Fahris17d91812007-01-29 12:09:33 +00003217 pool = opool->pool;
Fahris6f35cb82007-02-01 07:41:26 +00003218 } else {
3219 opool = NULL;
3220 pool = NULL;
Fahris17d91812007-01-29 12:09:33 +00003221 }
3222 if (oportObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00003223 {
Benny Prijono1f63cc42007-09-10 16:54:22 +00003224 oport = (PyObj_pjmedia_port *)oportObj;
Fahris17d91812007-01-29 12:09:33 +00003225 port = oport->port;
Fahris6f35cb82007-02-01 07:41:26 +00003226 } else {
Fahris17d91812007-01-29 12:09:33 +00003227 oport = NULL;
Fahris6f35cb82007-02-01 07:41:26 +00003228 port = NULL;
Fahris17d91812007-01-29 12:09:33 +00003229 }
Fahrisdcf8fa42006-12-28 03:13:48 +00003230
Fahris17d91812007-01-29 12:09:33 +00003231 status = pjsua_conf_add_port(pool, port, &p_id);
Fahrisdcf8fa42006-12-28 03:13:48 +00003232
3233
3234 return Py_BuildValue("ii", status, p_id);
3235}
3236
3237/*
3238 * py_pjsua_conf_remove_port
3239 */
3240static PyObject *py_pjsua_conf_remove_port
3241(PyObject *pSelf, PyObject *pArgs)
3242{
3243 int id;
3244 int status;
3245
Benny Prijono1f63cc42007-09-10 16:54:22 +00003246 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00003247
3248 if (!PyArg_ParseTuple(pArgs, "i", &id))
3249 {
3250 return NULL;
3251 }
3252
3253 status = pjsua_conf_remove_port(id);
3254
3255
3256 return Py_BuildValue("i", status);
3257}
3258
3259/*
3260 * py_pjsua_conf_connect
3261 */
3262static PyObject *py_pjsua_conf_connect
3263(PyObject *pSelf, PyObject *pArgs)
3264{
3265 int source, sink;
3266 int status;
3267
Benny Prijono1f63cc42007-09-10 16:54:22 +00003268 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00003269
3270 if (!PyArg_ParseTuple(pArgs, "ii", &source, &sink))
3271 {
3272 return NULL;
3273 }
3274
3275 status = pjsua_conf_connect(source, sink);
3276
3277
3278 return Py_BuildValue("i", status);
3279}
3280
3281/*
3282 * py_pjsua_conf_disconnect
3283 */
3284static PyObject *py_pjsua_conf_disconnect
3285(PyObject *pSelf, PyObject *pArgs)
3286{
3287 int source, sink;
3288 int status;
3289
Benny Prijono1f63cc42007-09-10 16:54:22 +00003290 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00003291
3292 if (!PyArg_ParseTuple(pArgs, "ii", &source, &sink))
3293 {
3294 return NULL;
3295 }
3296
3297 status = pjsua_conf_disconnect(source, sink);
3298
3299
3300 return Py_BuildValue("i", status);
3301}
3302
3303/*
3304 * py_pjsua_player_create
3305 */
3306static PyObject *py_pjsua_player_create
3307(PyObject *pSelf, PyObject *pArgs)
3308{
3309 int id;
3310 int options;
3311 PyObject * filename;
3312 pj_str_t str;
3313 int status;
3314
Benny Prijono1f63cc42007-09-10 16:54:22 +00003315 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00003316
3317 if (!PyArg_ParseTuple(pArgs, "Oi", &filename, &options))
3318 {
3319 return NULL;
3320 }
3321 str.ptr = PyString_AsString(filename);
3322 str.slen = strlen(PyString_AsString(filename));
3323 status = pjsua_player_create(&str, options, &id);
3324
3325 return Py_BuildValue("ii", status, id);
3326}
3327
3328/*
3329 * py_pjsua_player_get_conf_port
3330 */
3331static PyObject *py_pjsua_player_get_conf_port
3332(PyObject *pSelf, PyObject *pArgs)
3333{
3334
3335 int id, port_id;
3336
Benny Prijono1f63cc42007-09-10 16:54:22 +00003337 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00003338
3339 if (!PyArg_ParseTuple(pArgs, "i", &id))
3340 {
3341 return NULL;
3342 }
3343
3344 port_id = pjsua_player_get_conf_port(id);
3345
3346
3347 return Py_BuildValue("i", port_id);
3348}
3349
3350/*
3351 * py_pjsua_player_set_pos
3352 */
3353static PyObject *py_pjsua_player_set_pos
3354(PyObject *pSelf, PyObject *pArgs)
3355{
3356 int id;
3357 pj_uint32_t samples;
3358 int status;
3359
Benny Prijono1f63cc42007-09-10 16:54:22 +00003360 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00003361
3362 if (!PyArg_ParseTuple(pArgs, "iI", &id, &samples))
3363 {
3364 return NULL;
3365 }
3366
3367 status = pjsua_player_set_pos(id, samples);
3368
3369
3370 return Py_BuildValue("i", status);
3371}
3372
3373/*
3374 * py_pjsua_player_destroy
3375 */
3376static PyObject *py_pjsua_player_destroy
3377(PyObject *pSelf, PyObject *pArgs)
3378{
3379 int id;
3380 int status;
3381
Benny Prijono1f63cc42007-09-10 16:54:22 +00003382 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00003383
3384 if (!PyArg_ParseTuple(pArgs, "i", &id))
3385 {
3386 return NULL;
3387 }
3388
3389 status = pjsua_player_destroy(id);
3390
3391
3392 return Py_BuildValue("i", status);
3393}
3394
3395/*
3396 * py_pjsua_recorder_create
3397 * !modified @ 261206
3398 */
3399static PyObject *py_pjsua_recorder_create
3400(PyObject *pSelf, PyObject *pArgs)
3401{
3402 int p_id;
3403 int options;
3404 int max_size;
3405 PyObject * filename;
3406 pj_str_t str;
3407 PyObject * enc_param;
Fahris6f35cb82007-02-01 07:41:26 +00003408 pj_str_t strparam;
Fahrisdcf8fa42006-12-28 03:13:48 +00003409 int enc_type;
3410
3411 int status;
3412
Benny Prijono1f63cc42007-09-10 16:54:22 +00003413 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00003414
Fahris17d91812007-01-29 12:09:33 +00003415 if (!PyArg_ParseTuple(pArgs, "OiOii", &filename,
3416 &enc_type, &enc_param, &max_size, &options))
Fahrisdcf8fa42006-12-28 03:13:48 +00003417 {
3418 return NULL;
3419 }
3420 str.ptr = PyString_AsString(filename);
3421 str.slen = strlen(PyString_AsString(filename));
Fahris89ea3d02007-02-07 08:18:35 +00003422 if (enc_param != Py_None)
3423 {
3424 strparam.ptr = PyString_AsString(enc_param);
3425 strparam.slen = strlen(PyString_AsString(enc_param));
3426 status = pjsua_recorder_create
Fahris17d91812007-01-29 12:09:33 +00003427 (&str, enc_type, NULL, max_size, options, &p_id);
Fahris89ea3d02007-02-07 08:18:35 +00003428 } else {
3429 status = pjsua_recorder_create
3430 (&str, enc_type, NULL, max_size, options, &p_id);
3431 }
Fahrisdcf8fa42006-12-28 03:13:48 +00003432 return Py_BuildValue("ii", status, p_id);
3433}
3434
3435/*
3436 * py_pjsua_recorder_get_conf_port
3437 */
3438static PyObject *py_pjsua_recorder_get_conf_port
3439(PyObject *pSelf, PyObject *pArgs)
3440{
3441
3442 int id, port_id;
3443
Benny Prijono1f63cc42007-09-10 16:54:22 +00003444 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00003445
3446 if (!PyArg_ParseTuple(pArgs, "i", &id))
3447 {
3448 return NULL;
3449 }
3450
3451 port_id = pjsua_recorder_get_conf_port(id);
3452
3453
3454 return Py_BuildValue("i", port_id);
3455}
3456
3457/*
3458 * py_pjsua_recorder_destroy
3459 */
3460static PyObject *py_pjsua_recorder_destroy
3461(PyObject *pSelf, PyObject *pArgs)
3462{
3463 int id;
3464 int status;
3465
Benny Prijono1f63cc42007-09-10 16:54:22 +00003466 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00003467
3468 if (!PyArg_ParseTuple(pArgs, "i", &id))
3469 {
3470 return NULL;
3471 }
3472
3473 status = pjsua_recorder_destroy(id);
3474
3475
3476 return Py_BuildValue("i", status);
3477}
3478
3479/*
3480 * py_pjsua_enum_snd_devs
3481 */
3482static PyObject *py_pjsua_enum_snd_devs(PyObject *pSelf, PyObject *pArgs)
3483{
3484 pj_status_t status;
3485 PyObject *list;
3486
Fahris6f35cb82007-02-01 07:41:26 +00003487 pjmedia_snd_dev_info info[SND_DEV_NUM];
Fahris17d91812007-01-29 12:09:33 +00003488 unsigned c, i;
Benny Prijono1f63cc42007-09-10 16:54:22 +00003489
3490 PJ_UNUSED_ARG(pSelf);
3491
Fahrisb721aa32007-01-29 05:07:41 +00003492 if (!PyArg_ParseTuple(pArgs, ""))
Fahrisdcf8fa42006-12-28 03:13:48 +00003493 {
3494 return NULL;
3495 }
3496
Fahrisb721aa32007-01-29 05:07:41 +00003497 c = PJ_ARRAY_SIZE(info);
Fahrisdcf8fa42006-12-28 03:13:48 +00003498 status = pjsua_enum_snd_devs(info, &c);
3499
3500 list = PyList_New(c);
Fahris6f35cb82007-02-01 07:41:26 +00003501 for (i = 0; i < c; i++)
3502 {
Fahrisdcf8fa42006-12-28 03:13:48 +00003503 int ret;
Fahris6f35cb82007-02-01 07:41:26 +00003504 int j;
Fahrise314b882007-02-02 10:52:04 +00003505 char * str;
3506
Benny Prijono1f63cc42007-09-10 16:54:22 +00003507 PyObj_pjmedia_snd_dev_info * obj;
3508 obj = (PyObj_pjmedia_snd_dev_info *)pjmedia_snd_dev_info_new
3509 (&PyTyp_pjmedia_snd_dev_info, NULL, NULL);
Fahrisdcf8fa42006-12-28 03:13:48 +00003510 obj->default_samples_per_sec = info[i].default_samples_per_sec;
3511 obj->input_count = info[i].input_count;
3512 obj->output_count = info[i].output_count;
Fahrise314b882007-02-02 10:52:04 +00003513 str = (char *)malloc(SND_NAME_LEN * sizeof(char));
3514 memset(str, 0, SND_NAME_LEN);
3515 for (j = 0; j < SND_NAME_LEN; j++)
Fahrisdcf8fa42006-12-28 03:13:48 +00003516 {
Fahrise314b882007-02-02 10:52:04 +00003517 str[j] = info[i].name[j];
Fahrisdcf8fa42006-12-28 03:13:48 +00003518 }
Fahrise314b882007-02-02 10:52:04 +00003519 obj->name = PyString_FromStringAndSize(str, SND_NAME_LEN);
3520 free(str);
Fahrisdcf8fa42006-12-28 03:13:48 +00003521 ret = PyList_SetItem(list, i, (PyObject *)obj);
Fahris6f35cb82007-02-01 07:41:26 +00003522 if (ret == -1)
3523 {
Fahrisdcf8fa42006-12-28 03:13:48 +00003524 return NULL;
3525 }
3526 }
3527
Fahrisdcf8fa42006-12-28 03:13:48 +00003528 return Py_BuildValue("O",list);
3529}
3530
3531/*
3532 * py_pjsua_get_snd_dev
3533 */
3534static PyObject *py_pjsua_get_snd_dev
3535(PyObject *pSelf, PyObject *pArgs)
3536{
3537 int capture_dev, playback_dev;
3538 int status;
3539
Benny Prijono1f63cc42007-09-10 16:54:22 +00003540 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00003541
3542 if (!PyArg_ParseTuple(pArgs, ""))
3543 {
3544 return NULL;
3545 }
3546
3547 status = pjsua_get_snd_dev(&capture_dev, &playback_dev);
3548
3549
3550 return Py_BuildValue("ii", capture_dev, playback_dev);
3551}
3552
3553/*
3554 * py_pjsua_set_snd_dev
3555 */
3556static PyObject *py_pjsua_set_snd_dev
3557(PyObject *pSelf, PyObject *pArgs)
3558{
3559 int capture_dev, playback_dev;
3560 int status;
3561
Benny Prijono1f63cc42007-09-10 16:54:22 +00003562 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00003563
3564 if (!PyArg_ParseTuple(pArgs, "ii", &capture_dev, &playback_dev))
3565 {
3566 return NULL;
3567 }
3568
3569 status = pjsua_set_snd_dev(capture_dev, playback_dev);
3570
3571
3572 return Py_BuildValue("i", status);
3573}
3574
3575/*
3576 * py_pjsua_set_null_snd_dev
3577 */
3578static PyObject *py_pjsua_set_null_snd_dev
3579(PyObject *pSelf, PyObject *pArgs)
3580{
3581
3582 int status;
3583
Benny Prijono1f63cc42007-09-10 16:54:22 +00003584 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00003585
3586 if (!PyArg_ParseTuple(pArgs, ""))
3587 {
3588 return NULL;
3589 }
3590
3591 status = pjsua_set_null_snd_dev();
3592
3593
3594 return Py_BuildValue("i", status);
3595}
3596
3597/*
3598 * py_pjsua_set_no_snd_dev
3599 */
3600static PyObject *py_pjsua_set_no_snd_dev
3601(PyObject *pSelf, PyObject *pArgs)
3602{
3603
Benny Prijono1f63cc42007-09-10 16:54:22 +00003604 PyObj_pjmedia_port * obj;
Fahrisdcf8fa42006-12-28 03:13:48 +00003605
Benny Prijono1f63cc42007-09-10 16:54:22 +00003606 PJ_UNUSED_ARG(pSelf);
3607
Fahrisdcf8fa42006-12-28 03:13:48 +00003608 if (!PyArg_ParseTuple(pArgs, ""))
3609 {
3610 return NULL;
3611 }
3612
Benny Prijono1f63cc42007-09-10 16:54:22 +00003613 obj = (PyObj_pjmedia_port *)PyType_GenericNew
3614 (&PyTyp_pjmedia_port, NULL, NULL);
Fahrisdcf8fa42006-12-28 03:13:48 +00003615 obj->port = pjsua_set_no_snd_dev();
3616 return Py_BuildValue("O", obj);
3617}
3618
3619/*
3620 * py_pjsua_set_ec
3621 */
3622static PyObject *py_pjsua_set_ec
3623(PyObject *pSelf, PyObject *pArgs)
3624{
3625 int options;
3626 int tail_ms;
3627 int status;
3628
Benny Prijono1f63cc42007-09-10 16:54:22 +00003629 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00003630
3631 if (!PyArg_ParseTuple(pArgs, "ii", &tail_ms, &options))
3632 {
3633 return NULL;
3634 }
3635
3636 status = pjsua_set_ec(tail_ms, options);
3637
3638
3639 return Py_BuildValue("i", status);
3640}
3641
3642/*
3643 * py_pjsua_get_ec_tail
3644 */
3645static PyObject *py_pjsua_get_ec_tail
3646(PyObject *pSelf, PyObject *pArgs)
3647{
3648
3649 int status;
Fahris17d91812007-01-29 12:09:33 +00003650 unsigned p_tail_ms;
Fahrisdcf8fa42006-12-28 03:13:48 +00003651
Benny Prijono1f63cc42007-09-10 16:54:22 +00003652 PJ_UNUSED_ARG(pSelf);
3653
Fahrisdcf8fa42006-12-28 03:13:48 +00003654 if (!PyArg_ParseTuple(pArgs, ""))
3655 {
3656 return NULL;
3657 }
3658
3659 status = pjsua_get_ec_tail(&p_tail_ms);
3660
3661
3662 return Py_BuildValue("i", p_tail_ms);
3663}
3664
3665/*
3666 * py_pjsua_enum_codecs
3667 * !modified @ 261206
3668 */
3669static PyObject *py_pjsua_enum_codecs(PyObject *pSelf, PyObject *pArgs)
3670{
3671 pj_status_t status;
3672 PyObject *list;
3673
3674 pjsua_codec_info info[PJMEDIA_CODEC_MGR_MAX_CODECS];
Fahris17d91812007-01-29 12:09:33 +00003675 unsigned c, i;
Benny Prijono1f63cc42007-09-10 16:54:22 +00003676
3677 PJ_UNUSED_ARG(pSelf);
3678
Fahrisdcf8fa42006-12-28 03:13:48 +00003679 if (!PyArg_ParseTuple(pArgs, ""))
3680 {
3681 return NULL;
3682 }
3683
3684 c = PJ_ARRAY_SIZE(info);
3685 status = pjsua_enum_codecs(info, &c);
3686
3687 list = PyList_New(c);
Fahris6f35cb82007-02-01 07:41:26 +00003688 for (i = 0; i < c; i++)
3689 {
Fahrisdcf8fa42006-12-28 03:13:48 +00003690 int ret;
3691 int j;
Benny Prijono1f63cc42007-09-10 16:54:22 +00003692 PyObj_pjsua_codec_info * obj;
3693 obj = (PyObj_pjsua_codec_info *)codec_info_new
3694 (&PyTyp_pjsua_codec_info, NULL, NULL);
Fahrisdcf8fa42006-12-28 03:13:48 +00003695 obj->codec_id = PyString_FromStringAndSize
3696 (info[i].codec_id.ptr, info[i].codec_id.slen);
3697 obj->priority = info[i].priority;
3698 for (j = 0; j < 32; j++)
3699 {
3700 obj->buf_[j] = info[i].buf_[j];
3701 }
3702 ret = PyList_SetItem(list, i, (PyObject *)obj);
3703 if (ret == -1) {
3704 return NULL;
3705 }
3706 }
3707
Fahris17d91812007-01-29 12:09:33 +00003708
Fahrisdcf8fa42006-12-28 03:13:48 +00003709 return Py_BuildValue("O",list);
3710}
3711
3712/*
3713 * py_pjsua_codec_set_priority
3714 */
3715static PyObject *py_pjsua_codec_set_priority
3716(PyObject *pSelf, PyObject *pArgs)
3717{
3718
3719 int status;
3720 PyObject * id;
3721 pj_str_t str;
3722 pj_uint8_t priority;
3723
Benny Prijono1f63cc42007-09-10 16:54:22 +00003724 PJ_UNUSED_ARG(pSelf);
3725
Fahrisdcf8fa42006-12-28 03:13:48 +00003726 if (!PyArg_ParseTuple(pArgs, "OB", &id, &priority))
3727 {
3728 return NULL;
3729 }
3730 str.ptr = PyString_AsString(id);
3731 str.slen = strlen(PyString_AsString(id));
3732 status = pjsua_codec_set_priority(&str, priority);
3733
3734
3735 return Py_BuildValue("i", status);
3736}
3737
3738/*
3739 * py_pjsua_codec_get_param
3740 */
3741static PyObject *py_pjsua_codec_get_param
3742(PyObject *pSelf, PyObject *pArgs)
3743{
3744
3745 int status;
3746 PyObject * id;
3747 pj_str_t str;
3748 pjmedia_codec_param param;
Benny Prijono1f63cc42007-09-10 16:54:22 +00003749 PyObj_pjmedia_codec_param *obj;
Fahrisdcf8fa42006-12-28 03:13:48 +00003750
Benny Prijono1f63cc42007-09-10 16:54:22 +00003751 PJ_UNUSED_ARG(pSelf);
3752
Fahrisdcf8fa42006-12-28 03:13:48 +00003753 if (!PyArg_ParseTuple(pArgs, "O", &id))
3754 {
3755 return NULL;
3756 }
3757 str.ptr = PyString_AsString(id);
3758 str.slen = strlen(PyString_AsString(id));
3759 status = pjsua_codec_get_param(&str, &param);
Benny Prijono1f63cc42007-09-10 16:54:22 +00003760 obj = (PyObj_pjmedia_codec_param *)pjmedia_codec_param_new
3761 (&PyTyp_pjmedia_codec_param, NULL, NULL);
Fahrisdcf8fa42006-12-28 03:13:48 +00003762 obj->info->avg_bps = param.info.avg_bps;
3763 obj->info->channel_cnt = param.info.channel_cnt;
3764 obj->info->clock_rate = param.info.clock_rate;
3765 obj->info->frm_ptime = param.info.frm_ptime;
3766 obj->info->pcm_bits_per_sample = param.info.pcm_bits_per_sample;
3767 obj->info->pt = param.info.pt;
3768 obj->setting->cng = param.setting.cng;
Benny Prijonofb4b4e12009-05-06 10:28:52 +00003769 //deprecated:
3770 //obj->setting->dec_fmtp_mode = param.setting.dec_fmtp_mode;
3771 //obj->setting->enc_fmtp_mode = param.setting.enc_fmtp_mode;
Fahrisdcf8fa42006-12-28 03:13:48 +00003772 obj->setting->frm_per_pkt = param.setting.frm_per_pkt;
3773 obj->setting->penh = param.setting.penh;
3774 obj->setting->plc = param.setting.plc;
3775 obj->setting->reserved = param.setting.reserved;
3776 obj->setting->vad = param.setting.vad;
3777
3778 return Py_BuildValue("O", obj);
3779}
3780/*
3781 * py_pjsua_codec_set_param
3782 */
3783static PyObject *py_pjsua_codec_set_param
3784(PyObject *pSelf, PyObject *pArgs)
3785{
3786
3787 int status;
3788 PyObject * id;
3789 pj_str_t str;
3790 pjmedia_codec_param param;
Fahris6f35cb82007-02-01 07:41:26 +00003791 PyObject * tmpObj;
Benny Prijono1f63cc42007-09-10 16:54:22 +00003792 PyObj_pjmedia_codec_param *obj;
Fahrisdcf8fa42006-12-28 03:13:48 +00003793
Benny Prijono1f63cc42007-09-10 16:54:22 +00003794 PJ_UNUSED_ARG(pSelf);
3795
Fahris17d91812007-01-29 12:09:33 +00003796 if (!PyArg_ParseTuple(pArgs, "OO", &id, &tmpObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00003797 {
3798 return NULL;
3799 }
Fahris17d91812007-01-29 12:09:33 +00003800
Fahrisdcf8fa42006-12-28 03:13:48 +00003801 str.ptr = PyString_AsString(id);
3802 str.slen = strlen(PyString_AsString(id));
Fahris17d91812007-01-29 12:09:33 +00003803 if (tmpObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00003804 {
Benny Prijono1f63cc42007-09-10 16:54:22 +00003805 obj = (PyObj_pjmedia_codec_param *)tmpObj;
Fahris17d91812007-01-29 12:09:33 +00003806 param.info.avg_bps = obj->info->avg_bps;
3807 param.info.channel_cnt = obj->info->channel_cnt;
3808 param.info.clock_rate = obj->info->clock_rate;
3809 param.info.frm_ptime = obj->info->frm_ptime;
3810 param.info.pcm_bits_per_sample = obj->info->pcm_bits_per_sample;
3811 param.info.pt = obj->info->pt;
3812 param.setting.cng = obj->setting->cng;
Benny Prijonofb4b4e12009-05-06 10:28:52 +00003813 //Deprecated:
3814 //param.setting.dec_fmtp_mode = obj->setting->dec_fmtp_mode;
3815 //param.setting.enc_fmtp_mode = obj->setting->enc_fmtp_mode;
Fahris17d91812007-01-29 12:09:33 +00003816 param.setting.frm_per_pkt = obj->setting->frm_per_pkt;
3817 param.setting.penh = obj->setting->penh;
3818 param.setting.plc = obj->setting->plc;
3819 param.setting.reserved = obj->setting->reserved;
3820 param.setting.vad = obj->setting->vad;
3821 status = pjsua_codec_set_param(&str, &param);
3822 } else {
3823 status = pjsua_codec_set_param(&str, NULL);
Fahris6f35cb82007-02-01 07:41:26 +00003824 }
Fahrisdcf8fa42006-12-28 03:13:48 +00003825 return Py_BuildValue("i", status);
3826}
3827
3828static char pjsua_conf_get_max_ports_doc[] =
3829 "int py_pjsua.conf_get_max_ports () "
3830 "Get maxinum number of conference ports.";
3831static char pjsua_conf_get_active_ports_doc[] =
3832 "int py_pjsua.conf_get_active_ports () "
3833 "Get current number of active ports in the bridge.";
3834static char pjsua_enum_conf_ports_doc[] =
3835 "int[] py_pjsua.enum_conf_ports () "
3836 "Enumerate all conference ports.";
3837static char pjsua_conf_get_port_info_doc[] =
3838 "py_pjsua.Conf_Port_Info py_pjsua.conf_get_port_info (int id) "
3839 "Get information about the specified conference port";
3840static char pjsua_conf_add_port_doc[] =
3841 "int, int py_pjsua.conf_add_port "
Benny Prijono1f63cc42007-09-10 16:54:22 +00003842 "(py_pjsua.Pj_Pool pool, py_pjsua.PJMedia_Port port) "
Fahrisdcf8fa42006-12-28 03:13:48 +00003843 "Add arbitrary media port to PJSUA's conference bridge. "
3844 "Application can use this function to add the media port "
3845 "that it creates. For media ports that are created by PJSUA-LIB "
3846 "(such as calls, file player, or file recorder), PJSUA-LIB will "
3847 "automatically add the port to the bridge.";
3848static char pjsua_conf_remove_port_doc[] =
3849 "int py_pjsua.conf_remove_port (int id) "
3850 "Remove arbitrary slot from the conference bridge. "
3851 "Application should only call this function "
3852 "if it registered the port manually.";
3853static char pjsua_conf_connect_doc[] =
3854 "int py_pjsua.conf_connect (int source, int sink) "
3855 "Establish unidirectional media flow from souce to sink. "
3856 "One source may transmit to multiple destinations/sink. "
3857 "And if multiple sources are transmitting to the same sink, "
3858 "the media will be mixed together. Source and sink may refer "
3859 "to the same ID, effectively looping the media. "
3860 "If bidirectional media flow is desired, application "
3861 "needs to call this function twice, with the second "
3862 "one having the arguments reversed.";
3863static char pjsua_conf_disconnect_doc[] =
3864 "int py_pjsua.conf_disconnect (int source, int sink) "
3865 "Disconnect media flow from the source to destination port.";
3866static char pjsua_player_create_doc[] =
3867 "int, int py_pjsua.player_create (string filename, int options) "
3868 "Create a file player, and automatically connect "
3869 "this player to the conference bridge.";
3870static char pjsua_player_get_conf_port_doc[] =
3871 "int py_pjsua.player_get_conf_port (int) "
3872 "Get conference port ID associated with player.";
3873static char pjsua_player_set_pos_doc[] =
3874 "int py_pjsua.player_set_pos (int id, int samples) "
3875 "Set playback position.";
3876static char pjsua_player_destroy_doc[] =
3877 "int py_pjsua.player_destroy (int id) "
3878 "Close the file, remove the player from the bridge, "
3879 "and free resources associated with the file player.";
3880static char pjsua_recorder_create_doc[] =
3881 "int, int py_pjsua.recorder_create (string filename, "
3882 "int enc_type, int enc_param, int max_size, int options) "
3883 "Create a file recorder, and automatically connect this recorder "
3884 "to the conference bridge. The recorder currently supports recording "
3885 "WAV file, and on Windows, MP3 file. The type of the recorder to use "
3886 "is determined by the extension of the file (e.g. '.wav' or '.mp3').";
3887static char pjsua_recorder_get_conf_port_doc[] =
3888 "int py_pjsua.recorder_get_conf_port (int id) "
3889 "Get conference port associated with recorder.";
3890static char pjsua_recorder_destroy_doc[] =
3891 "int py_pjsua.recorder_destroy (int id) "
3892 "Destroy recorder (this will complete recording).";
3893static char pjsua_enum_snd_devs_doc[] =
3894 "py_pjsua.PJMedia_Snd_Dev_Info[] py_pjsua.enum_snd_devs (int count) "
3895 "Enum sound devices.";
3896static char pjsua_get_snd_dev_doc[] =
3897 "int, int py_pjsua.get_snd_dev () "
3898 "Get currently active sound devices. "
3899 "If sound devices has not been created "
3900 "(for example when pjsua_start() is not called), "
3901 "it is possible that the function returns "
3902 "PJ_SUCCESS with -1 as device IDs.";
3903static char pjsua_set_snd_dev_doc[] =
3904 "int py_pjsua.set_snd_dev (int capture_dev, int playback_dev) "
3905 "Select or change sound device. Application may call this function "
3906 "at any time to replace current sound device.";
3907static char pjsua_set_null_snd_dev_doc[] =
3908 "int py_pjsua.set_null_snd_dev () "
3909 "Set pjsua to use null sound device. The null sound device only "
3910 "provides the timing needed by the conference bridge, and will not "
3911 "interract with any hardware.";
3912static char pjsua_set_no_snd_dev_doc[] =
3913 "py_pjsua.PJMedia_Port py_pjsua.set_no_snd_dev () "
3914 "Disconnect the main conference bridge from any sound devices, "
3915 "and let application connect the bridge to it's "
3916 "own sound device/master port.";
3917static char pjsua_set_ec_doc[] =
3918 "int py_pjsua.set_ec (int tail_ms, int options) "
3919 "Configure the echo canceller tail length of the sound port.";
3920static char pjsua_get_ec_tail_doc[] =
3921 "int py_pjsua.get_ec_tail () "
3922 "Get current echo canceller tail length.";
3923static char pjsua_enum_codecs_doc[] =
3924 "py_pjsua.Codec_Info[] py_pjsua.enum_codecs () "
3925 "Enum all supported codecs in the system.";
3926static char pjsua_codec_set_priority_doc[] =
3927 "int py_pjsua.codec_set_priority (string id, int priority) "
3928 "Change codec priority.";
3929static char pjsua_codec_get_param_doc[] =
3930 "py_pjsua.PJMedia_Codec_Param py_pjsua.codec_get_param (string id) "
3931 "Get codec parameters";
3932static char pjsua_codec_set_param_doc[] =
3933 "int py_pjsua.codec_set_param (string id, "
3934 "py_pjsua.PJMedia_Codec_Param param) "
3935 "Set codec parameters.";
3936
3937/* END OF LIB MEDIA */
3938
3939/* LIB CALL */
3940
3941/*
Benny Prijono1f63cc42007-09-10 16:54:22 +00003942 * PyObj_pj_time_val
Fahrisdcf8fa42006-12-28 03:13:48 +00003943 * PJ Time Val
3944 */
3945typedef struct
3946{
3947 PyObject_HEAD
3948 /* Type-specific fields go here. */
3949 long sec;
3950 long msec;
3951
Benny Prijono1f63cc42007-09-10 16:54:22 +00003952} PyObj_pj_time_val;
Fahrisdcf8fa42006-12-28 03:13:48 +00003953
3954
3955
3956/*
3957 * pj_time_val_members
3958 */
3959static PyMemberDef pj_time_val_members[] =
3960{
3961
3962 {
3963 "sec", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00003964 offsetof(PyObj_pj_time_val, sec), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00003965 "The seconds part of the time"
3966 },
3967 {
3968 "msec", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00003969 offsetof(PyObj_pj_time_val, sec), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00003970 "The milliseconds fraction of the time"
3971 },
3972
3973
3974 {NULL} /* Sentinel */
3975};
3976
3977
3978
3979
3980/*
Benny Prijono1f63cc42007-09-10 16:54:22 +00003981 * PyTyp_pj_time_val
Fahrisdcf8fa42006-12-28 03:13:48 +00003982 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00003983static PyTypeObject PyTyp_pj_time_val =
Fahrisdcf8fa42006-12-28 03:13:48 +00003984{
3985 PyObject_HEAD_INIT(NULL)
3986 0, /*ob_size*/
3987 "py_pjsua.PJ_Time_Val", /*tp_name*/
Benny Prijono1f63cc42007-09-10 16:54:22 +00003988 sizeof(PyObj_pj_time_val), /*tp_basicsize*/
Fahrisdcf8fa42006-12-28 03:13:48 +00003989 0, /*tp_itemsize*/
3990 0,/*tp_dealloc*/
3991 0, /*tp_print*/
3992 0, /*tp_getattr*/
3993 0, /*tp_setattr*/
3994 0, /*tp_compare*/
3995 0, /*tp_repr*/
3996 0, /*tp_as_number*/
3997 0, /*tp_as_sequence*/
3998 0, /*tp_as_mapping*/
3999 0, /*tp_hash */
4000 0, /*tp_call*/
4001 0, /*tp_str*/
4002 0, /*tp_getattro*/
4003 0, /*tp_setattro*/
4004 0, /*tp_as_buffer*/
4005 Py_TPFLAGS_DEFAULT, /*tp_flags*/
4006 "PJ Time Val objects", /* tp_doc */
4007 0, /* tp_traverse */
4008 0, /* tp_clear */
4009 0, /* tp_richcompare */
4010 0, /* tp_weaklistoffset */
4011 0, /* tp_iter */
4012 0, /* tp_iternext */
4013 0, /* tp_methods */
4014 pj_time_val_members, /* tp_members */
4015
4016
4017};
4018
4019/*
Benny Prijono1f63cc42007-09-10 16:54:22 +00004020 * PyObj_pjsua_call_info
Fahrisdcf8fa42006-12-28 03:13:48 +00004021 * Call Info
4022 */
4023typedef struct
4024{
4025 PyObject_HEAD
4026 /* Type-specific fields go here. */
4027
4028 int id;
4029 int role;
4030 int acc_id;
4031 PyObject * local_info;
4032 PyObject * local_contact;
4033 PyObject * remote_info;
4034 PyObject * remote_contact;
4035 PyObject * call_id;
4036 int state;
4037 PyObject * state_text;
4038 int last_status;
4039 PyObject * last_status_text;
4040 int media_status;
4041 int media_dir;
4042 int conf_slot;
Benny Prijono1f63cc42007-09-10 16:54:22 +00004043 PyObj_pj_time_val * connect_duration;
4044 PyObj_pj_time_val * total_duration;
Fahrisdcf8fa42006-12-28 03:13:48 +00004045 struct {
4046 char local_info[128];
4047 char local_contact[128];
4048 char remote_info[128];
4049 char remote_contact[128];
4050 char call_id[128];
4051 char last_status_text[128];
4052 } buf_;
4053
Benny Prijono1f63cc42007-09-10 16:54:22 +00004054} PyObj_pjsua_call_info;
Fahrisdcf8fa42006-12-28 03:13:48 +00004055
4056
4057/*
4058 * call_info_dealloc
4059 * deletes a call_info from memory
4060 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00004061static void call_info_dealloc(PyObj_pjsua_call_info* self)
Fahrisdcf8fa42006-12-28 03:13:48 +00004062{
4063 Py_XDECREF(self->local_info);
4064 Py_XDECREF(self->local_contact);
4065 Py_XDECREF(self->remote_info);
4066 Py_XDECREF(self->remote_contact);
4067 Py_XDECREF(self->call_id);
4068 Py_XDECREF(self->state_text);
4069 Py_XDECREF(self->last_status_text);
4070 Py_XDECREF(self->connect_duration);
4071 Py_XDECREF(self->total_duration);
4072 self->ob_type->tp_free((PyObject*)self);
4073}
4074
4075
4076/*
4077 * call_info_new
4078 * constructor for call_info object
4079 */
4080static PyObject * call_info_new(PyTypeObject *type, PyObject *args,
4081 PyObject *kwds)
4082{
Benny Prijono1f63cc42007-09-10 16:54:22 +00004083 PyObj_pjsua_call_info *self;
Fahrisdcf8fa42006-12-28 03:13:48 +00004084
Benny Prijono1f63cc42007-09-10 16:54:22 +00004085 PJ_UNUSED_ARG(args);
4086 PJ_UNUSED_ARG(kwds);
4087
4088 self = (PyObj_pjsua_call_info *)type->tp_alloc(type, 0);
Fahrisdcf8fa42006-12-28 03:13:48 +00004089 if (self != NULL)
4090 {
4091 self->local_info = PyString_FromString("");
4092 if (self->local_info == NULL)
4093 {
4094 Py_DECREF(self);
4095 return NULL;
4096 }
4097 self->local_contact = PyString_FromString("");
4098 if (self->local_contact == NULL)
4099 {
4100 Py_DECREF(self);
4101 return NULL;
4102 }
4103 self->remote_info = PyString_FromString("");
4104 if (self->remote_info == NULL)
4105 {
4106 Py_DECREF(self);
4107 return NULL;
4108 }
4109 self->remote_contact = PyString_FromString("");
4110 if (self->remote_contact == NULL)
4111 {
4112 Py_DECREF(self);
4113 return NULL;
4114 }
4115 self->call_id = PyString_FromString("");
4116 if (self->call_id == NULL)
4117 {
4118 Py_DECREF(self);
4119 return NULL;
4120 }
4121 self->state_text = PyString_FromString("");
4122 if (self->state_text == NULL)
4123 {
4124 Py_DECREF(self);
4125 return NULL;
4126 }
4127 self->last_status_text = PyString_FromString("");
4128 if (self->last_status_text == NULL)
4129 {
4130 Py_DECREF(self);
4131 return NULL;
4132 }
Benny Prijono1f63cc42007-09-10 16:54:22 +00004133 self->connect_duration = (PyObj_pj_time_val *)PyType_GenericNew
4134 (&PyTyp_pj_time_val,NULL,NULL);
Fahrisdcf8fa42006-12-28 03:13:48 +00004135 if (self->connect_duration == NULL)
4136 {
4137 Py_DECREF(self);
4138 return NULL;
4139 }
Benny Prijono1f63cc42007-09-10 16:54:22 +00004140 self->total_duration = (PyObj_pj_time_val *)PyType_GenericNew
4141 (&PyTyp_pj_time_val,NULL,NULL);
Fahrisdcf8fa42006-12-28 03:13:48 +00004142 if (self->total_duration == NULL)
4143 {
4144 Py_DECREF(self);
4145 return NULL;
4146 }
4147 }
4148 return (PyObject *)self;
4149}
4150
4151/*
4152 * call_info_members
4153 */
4154static PyMemberDef call_info_members[] =
4155{
4156 {
4157 "id", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00004158 offsetof(PyObj_pjsua_call_info, id), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00004159 "Call identification"
4160 },
4161 {
4162 "role", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00004163 offsetof(PyObj_pjsua_call_info, role), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00004164 "Initial call role (UAC == caller)"
4165 },
4166 {
4167 "acc_id", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00004168 offsetof(PyObj_pjsua_call_info, acc_id), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00004169 "The account ID where this call belongs."
4170 },
4171 {
4172 "local_info", T_OBJECT_EX,
Benny Prijono1f63cc42007-09-10 16:54:22 +00004173 offsetof(PyObj_pjsua_call_info, local_info), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00004174 "Local URI"
4175 },
4176 {
4177 "local_contact", T_OBJECT_EX,
Benny Prijono1f63cc42007-09-10 16:54:22 +00004178 offsetof(PyObj_pjsua_call_info, local_contact), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00004179 "Local Contact"
4180 },
4181 {
4182 "remote_info", T_OBJECT_EX,
Benny Prijono1f63cc42007-09-10 16:54:22 +00004183 offsetof(PyObj_pjsua_call_info, remote_info), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00004184 "Remote URI"
4185 },
4186 {
4187 "remote_contact", T_OBJECT_EX,
Benny Prijono1f63cc42007-09-10 16:54:22 +00004188 offsetof(PyObj_pjsua_call_info, remote_contact), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00004189 "Remote Contact"
4190 },
4191 {
4192 "call_id", T_OBJECT_EX,
Benny Prijono1f63cc42007-09-10 16:54:22 +00004193 offsetof(PyObj_pjsua_call_info, call_id), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00004194 "Dialog Call-ID string"
4195 },
4196 {
4197 "state", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00004198 offsetof(PyObj_pjsua_call_info, state), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00004199 "Call state"
4200 },
4201 {
4202 "state_text", T_OBJECT_EX,
Benny Prijono1f63cc42007-09-10 16:54:22 +00004203 offsetof(PyObj_pjsua_call_info, state_text), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00004204 "Text describing the state "
4205 },
4206 {
4207 "last_status", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00004208 offsetof(PyObj_pjsua_call_info, last_status), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00004209 "Last status code heard, which can be used as cause code"
4210 },
4211 {
4212 "last_status_text", T_OBJECT_EX,
Benny Prijono1f63cc42007-09-10 16:54:22 +00004213 offsetof(PyObj_pjsua_call_info, last_status_text), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00004214 "The reason phrase describing the status."
4215 },
4216 {
4217 "media_status", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00004218 offsetof(PyObj_pjsua_call_info, media_status), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00004219 "Call media status."
4220 },
4221 {
4222 "media_dir", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00004223 offsetof(PyObj_pjsua_call_info, media_dir), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00004224 "Media direction"
4225 },
4226 {
4227 "conf_slot", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00004228 offsetof(PyObj_pjsua_call_info, conf_slot), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00004229 "The conference port number for the call"
4230 },
4231 {
4232 "connect_duration", T_OBJECT_EX,
Benny Prijono1f63cc42007-09-10 16:54:22 +00004233 offsetof(PyObj_pjsua_call_info, connect_duration), 0,
Fahris17d91812007-01-29 12:09:33 +00004234 "Up-to-date call connected duration(zero when call is not established)"
Fahrisdcf8fa42006-12-28 03:13:48 +00004235 },
4236 {
4237 "total_duration", T_OBJECT_EX,
Benny Prijono1f63cc42007-09-10 16:54:22 +00004238 offsetof(PyObj_pjsua_call_info, total_duration), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00004239 "Total call duration, including set-up time"
4240 },
4241
4242 {NULL} /* Sentinel */
4243};
4244
4245
4246
4247
4248/*
Benny Prijono1f63cc42007-09-10 16:54:22 +00004249 * PyTyp_pjsua_call_info
Fahrisdcf8fa42006-12-28 03:13:48 +00004250 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00004251static PyTypeObject PyTyp_pjsua_call_info =
Fahrisdcf8fa42006-12-28 03:13:48 +00004252{
4253 PyObject_HEAD_INIT(NULL)
4254 0, /*ob_size*/
4255 "py_pjsua.Call_Info", /*tp_name*/
Benny Prijono1f63cc42007-09-10 16:54:22 +00004256 sizeof(PyObj_pjsua_call_info), /*tp_basicsize*/
Fahrisdcf8fa42006-12-28 03:13:48 +00004257 0, /*tp_itemsize*/
4258 (destructor)call_info_dealloc,/*tp_dealloc*/
4259 0, /*tp_print*/
4260 0, /*tp_getattr*/
4261 0, /*tp_setattr*/
4262 0, /*tp_compare*/
4263 0, /*tp_repr*/
4264 0, /*tp_as_number*/
4265 0, /*tp_as_sequence*/
4266 0, /*tp_as_mapping*/
4267 0, /*tp_hash */
4268 0, /*tp_call*/
4269 0, /*tp_str*/
4270 0, /*tp_getattro*/
4271 0, /*tp_setattro*/
4272 0, /*tp_as_buffer*/
4273 Py_TPFLAGS_DEFAULT, /*tp_flags*/
4274 "Call Info objects", /* tp_doc */
4275 0, /* tp_traverse */
4276 0, /* tp_clear */
4277 0, /* tp_richcompare */
4278 0, /* tp_weaklistoffset */
4279 0, /* tp_iter */
4280 0, /* tp_iternext */
4281 0, /* tp_methods */
4282 call_info_members, /* tp_members */
4283 0, /* tp_getset */
4284 0, /* tp_base */
4285 0, /* tp_dict */
4286 0, /* tp_descr_get */
4287 0, /* tp_descr_set */
4288 0, /* tp_dictoffset */
4289 0, /* tp_init */
4290 0, /* tp_alloc */
4291 call_info_new, /* tp_new */
4292
4293};
4294
4295/*
4296 * py_pjsua_call_get_max_count
4297 */
4298static PyObject *py_pjsua_call_get_max_count
4299(PyObject *pSelf, PyObject *pArgs)
4300{
4301 int count;
4302
Benny Prijono1f63cc42007-09-10 16:54:22 +00004303 PJ_UNUSED_ARG(pSelf);
4304
Fahrisdcf8fa42006-12-28 03:13:48 +00004305 if (!PyArg_ParseTuple(pArgs, ""))
4306 {
4307 return NULL;
4308 }
4309
4310 count = pjsua_call_get_max_count();
4311
4312
4313 return Py_BuildValue("i", count);
4314}
4315
4316/*
4317 * py_pjsua_call_get_count
4318 */
4319static PyObject *py_pjsua_call_get_count
4320(PyObject *pSelf, PyObject *pArgs)
4321{
4322
4323 int count;
4324
Benny Prijono1f63cc42007-09-10 16:54:22 +00004325 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00004326
4327 if (!PyArg_ParseTuple(pArgs, ""))
4328 {
4329 return NULL;
4330 }
4331
4332 count = pjsua_call_get_count();
4333
4334
4335 return Py_BuildValue("i", count);
4336}
4337
4338/*
4339 * py_pjsua_enum_calls
4340 */
4341static PyObject *py_pjsua_enum_calls(PyObject *pSelf, PyObject *pArgs)
4342{
4343 pj_status_t status;
4344 PyObject *list;
4345
4346 pjsua_transport_id id[PJSUA_MAX_CALLS];
Fahris17d91812007-01-29 12:09:33 +00004347 unsigned c, i;
Benny Prijono1f63cc42007-09-10 16:54:22 +00004348
4349 PJ_UNUSED_ARG(pSelf);
4350
Fahrisdcf8fa42006-12-28 03:13:48 +00004351 if (!PyArg_ParseTuple(pArgs, ""))
4352 {
4353 return NULL;
4354 }
4355
4356 c = PJ_ARRAY_SIZE(id);
4357 status = pjsua_enum_calls(id, &c);
4358
4359 list = PyList_New(c);
4360 for (i = 0; i < c; i++)
4361 {
4362 int ret = PyList_SetItem(list, i, Py_BuildValue("i", id[i]));
4363 if (ret == -1)
4364 {
4365 return NULL;
4366 }
4367 }
4368
Fahrisdcf8fa42006-12-28 03:13:48 +00004369 return Py_BuildValue("O",list);
4370}
4371
4372/*
4373 * py_pjsua_call_make_call
4374 */
4375static PyObject *py_pjsua_call_make_call
4376(PyObject *pSelf, PyObject *pArgs)
4377{
4378 int status;
4379 int acc_id;
4380 pj_str_t dst_uri;
4381 PyObject * sd;
4382 unsigned options;
4383 pjsua_msg_data msg_data;
Fahris6f35cb82007-02-01 07:41:26 +00004384 PyObject * omdObj;
Benny Prijono1f63cc42007-09-10 16:54:22 +00004385 PyObj_pjsua_msg_data * omd;
Fahrisdcf8fa42006-12-28 03:13:48 +00004386 int user_data;
4387 int call_id;
4388 pj_pool_t * pool;
4389
Benny Prijono1f63cc42007-09-10 16:54:22 +00004390 PJ_UNUSED_ARG(pSelf);
4391
Fahris17d91812007-01-29 12:09:33 +00004392 if (!PyArg_ParseTuple
4393 (pArgs, "iOIiO", &acc_id, &sd, &options, &user_data, &omdObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00004394 {
4395 return NULL;
4396 }
4397
4398 dst_uri.ptr = PyString_AsString(sd);
4399 dst_uri.slen = strlen(PyString_AsString(sd));
Fahris6f35cb82007-02-01 07:41:26 +00004400 if (omdObj != Py_None)
4401 {
Benny Prijono1f63cc42007-09-10 16:54:22 +00004402 omd = (PyObj_pjsua_msg_data *)omdObj;
Fahris17d91812007-01-29 12:09:33 +00004403 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
4404 msg_data.content_type.slen = strlen
4405 (PyString_AsString(omd->content_type));
4406 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
4407 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00004408 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Fahris17d91812007-01-29 12:09:33 +00004409 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
4410 status = pjsua_call_make_call(acc_id, &dst_uri,
Benny Prijonoe6ead542007-01-31 20:53:31 +00004411 options, (void*)user_data, &msg_data, &call_id);
Fahris17d91812007-01-29 12:09:33 +00004412 pj_pool_release(pool);
Benny Prijonoed7a5a72007-01-29 18:36:38 +00004413 } else {
Fahris89ea3d02007-02-07 08:18:35 +00004414
Fahris17d91812007-01-29 12:09:33 +00004415 status = pjsua_call_make_call(acc_id, &dst_uri,
Benny Prijonoe6ead542007-01-31 20:53:31 +00004416 options, (void*)user_data, NULL, &call_id);
Benny Prijonoed7a5a72007-01-29 18:36:38 +00004417 }
Fahris89ea3d02007-02-07 08:18:35 +00004418
Fahrisdcf8fa42006-12-28 03:13:48 +00004419 return Py_BuildValue("ii",status, call_id);
Fahris89ea3d02007-02-07 08:18:35 +00004420
Fahrisdcf8fa42006-12-28 03:13:48 +00004421}
4422
4423/*
4424 * py_pjsua_call_is_active
4425 */
4426static PyObject *py_pjsua_call_is_active
4427(PyObject *pSelf, PyObject *pArgs)
4428{
4429 int call_id;
4430 int isActive;
4431
Benny Prijono1f63cc42007-09-10 16:54:22 +00004432 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00004433
4434 if (!PyArg_ParseTuple(pArgs, "i", &call_id))
4435 {
4436 return NULL;
4437 }
4438
4439 isActive = pjsua_call_is_active(call_id);
4440
4441
4442 return Py_BuildValue("i", isActive);
4443}
4444
4445/*
4446 * py_pjsua_call_has_media
4447 */
4448static PyObject *py_pjsua_call_has_media
4449(PyObject *pSelf, PyObject *pArgs)
4450{
4451 int call_id;
4452 int hasMedia;
4453
Benny Prijono1f63cc42007-09-10 16:54:22 +00004454 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00004455
4456 if (!PyArg_ParseTuple(pArgs, "i", &call_id))
4457 {
4458 return NULL;
4459 }
4460
4461 hasMedia = pjsua_call_has_media(call_id);
4462
4463
4464 return Py_BuildValue("i", hasMedia);
4465}
4466
4467/*
4468 * py_pjsua_call_get_conf_port
4469 */
4470static PyObject *py_pjsua_call_get_conf_port
4471(PyObject *pSelf, PyObject *pArgs)
4472{
4473 int call_id;
4474 int port_id;
4475
Benny Prijono1f63cc42007-09-10 16:54:22 +00004476 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00004477
4478 if (!PyArg_ParseTuple(pArgs, "i", &call_id))
4479 {
4480 return NULL;
4481 }
4482
4483 port_id = pjsua_call_get_conf_port(call_id);
4484
4485
4486 return Py_BuildValue("i", port_id);
4487}
4488
4489/*
4490 * py_pjsua_call_get_info
4491 */
4492static PyObject *py_pjsua_call_get_info
4493(PyObject *pSelf, PyObject *pArgs)
4494{
4495 int call_id;
4496 int status;
Benny Prijono1f63cc42007-09-10 16:54:22 +00004497 PyObj_pjsua_call_info * oi;
Fahrisdcf8fa42006-12-28 03:13:48 +00004498 pjsua_call_info info;
Fahrisdcf8fa42006-12-28 03:13:48 +00004499
Benny Prijono1f63cc42007-09-10 16:54:22 +00004500 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00004501
4502 if (!PyArg_ParseTuple(pArgs, "i", &call_id))
4503 {
4504 return NULL;
4505 }
4506
4507
4508 status = pjsua_call_get_info(call_id, &info);
4509 if (status == PJ_SUCCESS)
4510 {
Benny Prijono1f63cc42007-09-10 16:54:22 +00004511 oi = (PyObj_pjsua_call_info *)call_info_new(&PyTyp_pjsua_call_info, NULL, NULL);
Fahrisdcf8fa42006-12-28 03:13:48 +00004512 oi->acc_id = info.acc_id;
Fahris6f35cb82007-02-01 07:41:26 +00004513 pj_ansi_snprintf(oi->buf_.call_id, sizeof(oi->buf_.call_id),
4514 "%.*s", (int)info.call_id.slen, info.call_id.ptr);
4515 pj_ansi_snprintf(oi->buf_.last_status_text,
4516 sizeof(oi->buf_.last_status_text),
4517 "%.*s", (int)info.last_status_text.slen, info.last_status_text.ptr);
4518 pj_ansi_snprintf(oi->buf_.local_contact, sizeof(oi->buf_.local_contact),
4519 "%.*s", (int)info.local_contact.slen, info.local_contact.ptr);
4520 pj_ansi_snprintf(oi->buf_.local_info, sizeof(oi->buf_.local_info),
4521 "%.*s", (int)info.local_info.slen, info.local_info.ptr);
4522 pj_ansi_snprintf(oi->buf_.remote_contact,
4523 sizeof(oi->buf_.remote_contact),
4524 "%.*s", (int)info.remote_contact.slen, info.remote_contact.ptr);
4525 pj_ansi_snprintf(oi->buf_.remote_info, sizeof(oi->buf_.remote_info),
4526 "%.*s", (int)info.remote_info.slen, info.remote_info.ptr);
Benny Prijonoed7a5a72007-01-29 18:36:38 +00004527
Fahrisdcf8fa42006-12-28 03:13:48 +00004528 oi->call_id = PyString_FromStringAndSize(info.call_id.ptr,
4529 info.call_id.slen);
4530 oi->conf_slot = info.conf_slot;
4531 oi->connect_duration->sec = info.connect_duration.sec;
4532 oi->connect_duration->msec = info.connect_duration.msec;
4533 oi->total_duration->sec = info.total_duration.sec;
4534 oi->total_duration->msec = info.total_duration.msec;
4535 oi->id = info.id;
4536 oi->last_status = info.last_status;
4537 oi->last_status_text = PyString_FromStringAndSize(
4538 info.last_status_text.ptr, info.last_status_text.slen);
4539 oi->local_contact = PyString_FromStringAndSize(
4540 info.local_contact.ptr, info.local_contact.slen);
4541 oi->local_info = PyString_FromStringAndSize(
4542 info.local_info.ptr, info.local_info.slen);
4543 oi->remote_contact = PyString_FromStringAndSize(
4544 info.remote_contact.ptr, info.remote_contact.slen);
4545 oi->remote_info = PyString_FromStringAndSize(
4546 info.remote_info.ptr, info.remote_info.slen);
4547 oi->media_dir = info.media_dir;
4548 oi->media_status = info.media_status;
4549 oi->role = info.role;
4550 oi->state = info.state;
4551 oi->state_text = PyString_FromStringAndSize(
4552 info.state_text.ptr, info.state_text.slen);
4553
4554 return Py_BuildValue("O", oi);
4555 } else {
4556 Py_INCREF(Py_None);
4557 return Py_None;
4558 }
4559}
4560
4561/*
4562 * py_pjsua_call_set_user_data
4563 */
4564static PyObject *py_pjsua_call_set_user_data
4565(PyObject *pSelf, PyObject *pArgs)
4566{
4567 int call_id;
4568 int user_data;
4569 int status;
4570
Benny Prijono1f63cc42007-09-10 16:54:22 +00004571 PJ_UNUSED_ARG(pSelf);
4572
Fahrisdcf8fa42006-12-28 03:13:48 +00004573 if (!PyArg_ParseTuple(pArgs, "ii", &call_id, &user_data))
4574 {
4575 return NULL;
4576 }
4577
Benny Prijonoe6ead542007-01-31 20:53:31 +00004578 status = pjsua_call_set_user_data(call_id, (void*)user_data);
Fahrisdcf8fa42006-12-28 03:13:48 +00004579
4580
4581 return Py_BuildValue("i", status);
4582}
4583
4584/*
4585 * py_pjsua_call_get_user_data
4586 */
4587static PyObject *py_pjsua_call_get_user_data
4588(PyObject *pSelf, PyObject *pArgs)
4589{
4590 int call_id;
Benny Prijonoe6ead542007-01-31 20:53:31 +00004591 void * user_data;
Fahrisdcf8fa42006-12-28 03:13:48 +00004592
Benny Prijono1f63cc42007-09-10 16:54:22 +00004593 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00004594
4595 if (!PyArg_ParseTuple(pArgs, "i", &call_id))
4596 {
4597 return NULL;
4598 }
4599
4600 user_data = pjsua_call_get_user_data(call_id);
4601
4602
Benny Prijonoe6ead542007-01-31 20:53:31 +00004603 return Py_BuildValue("i", (int)user_data);
Fahrisdcf8fa42006-12-28 03:13:48 +00004604}
4605
4606/*
4607 * py_pjsua_call_answer
4608 */
4609static PyObject *py_pjsua_call_answer
4610(PyObject *pSelf, PyObject *pArgs)
4611{
4612 int status;
4613 int call_id;
Fahrise314b882007-02-02 10:52:04 +00004614 pj_str_t * reason, tmp_reason;
Fahrisdcf8fa42006-12-28 03:13:48 +00004615 PyObject * sr;
4616 unsigned code;
4617 pjsua_msg_data msg_data;
Fahris6f35cb82007-02-01 07:41:26 +00004618 PyObject * omdObj;
Benny Prijono1f63cc42007-09-10 16:54:22 +00004619 PyObj_pjsua_msg_data * omd;
Fahrisdcf8fa42006-12-28 03:13:48 +00004620 pj_pool_t * pool;
4621
Benny Prijono1f63cc42007-09-10 16:54:22 +00004622 PJ_UNUSED_ARG(pSelf);
4623
Fahris17d91812007-01-29 12:09:33 +00004624 if (!PyArg_ParseTuple(pArgs, "iIOO", &call_id, &code, &sr, &omdObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00004625 {
4626 return NULL;
4627 }
Fahris6f35cb82007-02-01 07:41:26 +00004628 if (sr == Py_None)
4629 {
4630 reason = NULL;
4631 } else {
Fahrise314b882007-02-02 10:52:04 +00004632 reason = &tmp_reason;
4633 tmp_reason.ptr = PyString_AsString(sr);
4634 tmp_reason.slen = strlen(PyString_AsString(sr));
Fahris6f35cb82007-02-01 07:41:26 +00004635 }
4636 if (omdObj != Py_None)
4637 {
Benny Prijono1f63cc42007-09-10 16:54:22 +00004638 omd = (PyObj_pjsua_msg_data *)omdObj;
Fahris17d91812007-01-29 12:09:33 +00004639 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
4640 msg_data.content_type.slen = strlen
4641 (PyString_AsString(omd->content_type));
4642 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
4643 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00004644 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Fahris17d91812007-01-29 12:09:33 +00004645 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
4646
Fahris6f35cb82007-02-01 07:41:26 +00004647 status = pjsua_call_answer(call_id, code, reason, &msg_data);
Fahrisdcf8fa42006-12-28 03:13:48 +00004648
Fahris17d91812007-01-29 12:09:33 +00004649 pj_pool_release(pool);
4650 } else {
4651
Fahris89ea3d02007-02-07 08:18:35 +00004652 status = pjsua_call_answer(call_id, code, reason, NULL);
4653
Fahris6f35cb82007-02-01 07:41:26 +00004654 }
Fahrise314b882007-02-02 10:52:04 +00004655
Fahrisdcf8fa42006-12-28 03:13:48 +00004656 return Py_BuildValue("i",status);
4657}
4658
4659/*
4660 * py_pjsua_call_hangup
4661 */
4662static PyObject *py_pjsua_call_hangup
4663(PyObject *pSelf, PyObject *pArgs)
4664{
4665 int status;
4666 int call_id;
Fahrise314b882007-02-02 10:52:04 +00004667 pj_str_t * reason, tmp_reason;
Fahrisdcf8fa42006-12-28 03:13:48 +00004668 PyObject * sr;
4669 unsigned code;
4670 pjsua_msg_data msg_data;
Fahris6f35cb82007-02-01 07:41:26 +00004671 PyObject * omdObj;
Benny Prijono1f63cc42007-09-10 16:54:22 +00004672 PyObj_pjsua_msg_data * omd;
Benny Prijonoed7a5a72007-01-29 18:36:38 +00004673 pj_pool_t * pool = NULL;
Fahrisdcf8fa42006-12-28 03:13:48 +00004674
Benny Prijono1f63cc42007-09-10 16:54:22 +00004675 PJ_UNUSED_ARG(pSelf);
4676
Fahris17d91812007-01-29 12:09:33 +00004677 if (!PyArg_ParseTuple(pArgs, "iIOO", &call_id, &code, &sr, &omdObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00004678 {
4679 return NULL;
4680 }
Benny Prijonoaa286042007-02-03 17:23:22 +00004681 if (sr == Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00004682 {
4683 reason = NULL;
4684 } else {
Fahrise314b882007-02-02 10:52:04 +00004685 reason = &tmp_reason;
4686 tmp_reason.ptr = PyString_AsString(sr);
4687 tmp_reason.slen = strlen(PyString_AsString(sr));
Fahris6f35cb82007-02-01 07:41:26 +00004688 }
4689 if (omdObj != Py_None)
4690 {
Benny Prijono1f63cc42007-09-10 16:54:22 +00004691 omd = (PyObj_pjsua_msg_data *)omdObj;
Fahris17d91812007-01-29 12:09:33 +00004692 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
4693 msg_data.content_type.slen = strlen
4694 (PyString_AsString(omd->content_type));
4695 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
4696 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00004697 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Fahris17d91812007-01-29 12:09:33 +00004698 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
Fahris6f35cb82007-02-01 07:41:26 +00004699 status = pjsua_call_hangup(call_id, code, reason, &msg_data);
Fahris17d91812007-01-29 12:09:33 +00004700 pj_pool_release(pool);
Benny Prijonoed7a5a72007-01-29 18:36:38 +00004701 } else {
Fahris6f35cb82007-02-01 07:41:26 +00004702 status = pjsua_call_hangup(call_id, code, reason, NULL);
4703 }
Fahrise314b882007-02-02 10:52:04 +00004704
Fahrisdcf8fa42006-12-28 03:13:48 +00004705 return Py_BuildValue("i",status);
4706}
4707
4708/*
4709 * py_pjsua_call_set_hold
4710 */
4711static PyObject *py_pjsua_call_set_hold
4712(PyObject *pSelf, PyObject *pArgs)
4713{
4714 int status;
4715 int call_id;
4716 pjsua_msg_data msg_data;
Benny Prijono1f63cc42007-09-10 16:54:22 +00004717 PyObject * omdObj;
4718 PyObj_pjsua_msg_data * omd;
Fahrisdcf8fa42006-12-28 03:13:48 +00004719 pj_pool_t * pool;
4720
Benny Prijono1f63cc42007-09-10 16:54:22 +00004721 PJ_UNUSED_ARG(pSelf);
4722
Fahris17d91812007-01-29 12:09:33 +00004723 if (!PyArg_ParseTuple(pArgs, "iO", &call_id, &omdObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00004724 {
4725 return NULL;
4726 }
Fahris17d91812007-01-29 12:09:33 +00004727
Fahris6f35cb82007-02-01 07:41:26 +00004728 if (omdObj != Py_None)
4729 {
Benny Prijono1f63cc42007-09-10 16:54:22 +00004730 omd = (PyObj_pjsua_msg_data *)omdObj;
Fahris17d91812007-01-29 12:09:33 +00004731 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
4732 msg_data.content_type.slen = strlen
4733 (PyString_AsString(omd->content_type));
4734 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
4735 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00004736 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Fahris17d91812007-01-29 12:09:33 +00004737 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
4738 status = pjsua_call_set_hold(call_id, &msg_data);
4739 pj_pool_release(pool);
Fahris6f35cb82007-02-01 07:41:26 +00004740 } else {
Fahris17d91812007-01-29 12:09:33 +00004741 status = pjsua_call_set_hold(call_id, NULL);
Fahris6f35cb82007-02-01 07:41:26 +00004742 }
Fahrisdcf8fa42006-12-28 03:13:48 +00004743 return Py_BuildValue("i",status);
4744}
4745
4746/*
4747 * py_pjsua_call_reinvite
4748 */
4749static PyObject *py_pjsua_call_reinvite
4750(PyObject *pSelf, PyObject *pArgs)
4751{
4752 int status;
4753 int call_id;
4754 int unhold;
4755 pjsua_msg_data msg_data;
Fahris17d91812007-01-29 12:09:33 +00004756 PyObject * omdObj;
Benny Prijono1f63cc42007-09-10 16:54:22 +00004757 PyObj_pjsua_msg_data * omd;
Fahrisdcf8fa42006-12-28 03:13:48 +00004758 pj_pool_t * pool;
4759
Benny Prijono1f63cc42007-09-10 16:54:22 +00004760 PJ_UNUSED_ARG(pSelf);
4761
Fahris17d91812007-01-29 12:09:33 +00004762 if (!PyArg_ParseTuple(pArgs, "iiO", &call_id, &unhold, &omdObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00004763 {
4764 return NULL;
4765 }
Fahris17d91812007-01-29 12:09:33 +00004766
4767 if (omdObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00004768 {
Benny Prijono1f63cc42007-09-10 16:54:22 +00004769 omd = (PyObj_pjsua_msg_data *)omdObj;
Fahris17d91812007-01-29 12:09:33 +00004770 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
4771 msg_data.content_type.slen = strlen
4772 (PyString_AsString(omd->content_type));
4773 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
4774 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00004775 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Fahris17d91812007-01-29 12:09:33 +00004776 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
4777 status = pjsua_call_reinvite(call_id, unhold, &msg_data);
4778 pj_pool_release(pool);
4779 } else {
4780 status = pjsua_call_reinvite(call_id, unhold, NULL);
4781 }
Fahrisdcf8fa42006-12-28 03:13:48 +00004782 return Py_BuildValue("i",status);
4783}
4784
4785/*
4786 * py_pjsua_call_xfer
4787 */
4788static PyObject *py_pjsua_call_xfer
4789(PyObject *pSelf, PyObject *pArgs)
4790{
4791 int status;
4792 int call_id;
4793 pj_str_t dest;
4794 PyObject * sd;
4795 pjsua_msg_data msg_data;
Fahris17d91812007-01-29 12:09:33 +00004796 PyObject * omdObj;
Benny Prijono1f63cc42007-09-10 16:54:22 +00004797 PyObj_pjsua_msg_data * omd;
Fahrisdcf8fa42006-12-28 03:13:48 +00004798 pj_pool_t * pool;
4799
Benny Prijono1f63cc42007-09-10 16:54:22 +00004800 PJ_UNUSED_ARG(pSelf);
4801
Fahris17d91812007-01-29 12:09:33 +00004802 if (!PyArg_ParseTuple(pArgs, "iOO", &call_id, &sd, &omdObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00004803 {
4804 return NULL;
4805 }
4806
4807 dest.ptr = PyString_AsString(sd);
4808 dest.slen = strlen(PyString_AsString(sd));
4809
Fahris17d91812007-01-29 12:09:33 +00004810 if (omdObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00004811 {
Benny Prijono1f63cc42007-09-10 16:54:22 +00004812 omd = (PyObj_pjsua_msg_data *)omdObj;
Fahris17d91812007-01-29 12:09:33 +00004813 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
4814 msg_data.content_type.slen = strlen
4815 (PyString_AsString(omd->content_type));
4816 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
4817 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00004818 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Fahris17d91812007-01-29 12:09:33 +00004819 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
4820 status = pjsua_call_xfer(call_id, &dest, &msg_data);
4821 pj_pool_release(pool);
Fahris6f35cb82007-02-01 07:41:26 +00004822 } else {
Fahris17d91812007-01-29 12:09:33 +00004823 status = pjsua_call_xfer(call_id, &dest, NULL);
Fahris6f35cb82007-02-01 07:41:26 +00004824 }
Fahrisdcf8fa42006-12-28 03:13:48 +00004825 return Py_BuildValue("i",status);
4826}
4827
4828/*
4829 * py_pjsua_call_xfer_replaces
4830 */
4831static PyObject *py_pjsua_call_xfer_replaces
4832(PyObject *pSelf, PyObject *pArgs)
4833{
4834 int status;
4835 int call_id;
4836 int dest_call_id;
4837 unsigned options;
4838 pjsua_msg_data msg_data;
Fahris17d91812007-01-29 12:09:33 +00004839 PyObject * omdObj;
Benny Prijono1f63cc42007-09-10 16:54:22 +00004840 PyObj_pjsua_msg_data * omd;
Fahrisdcf8fa42006-12-28 03:13:48 +00004841 pj_pool_t * pool;
4842
Benny Prijono1f63cc42007-09-10 16:54:22 +00004843 PJ_UNUSED_ARG(pSelf);
4844
Fahris17d91812007-01-29 12:09:33 +00004845 if (!PyArg_ParseTuple
4846 (pArgs, "iiIO", &call_id, &dest_call_id, &options, &omdObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00004847 {
4848 return NULL;
4849 }
4850
Fahris17d91812007-01-29 12:09:33 +00004851 if (omdObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00004852 {
Benny Prijono1f63cc42007-09-10 16:54:22 +00004853 omd = (PyObj_pjsua_msg_data *)omdObj;
Fahris17d91812007-01-29 12:09:33 +00004854 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
4855 msg_data.content_type.slen = strlen
4856 (PyString_AsString(omd->content_type));
4857 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
4858 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00004859 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Fahris17d91812007-01-29 12:09:33 +00004860 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
4861 status = pjsua_call_xfer_replaces
4862 (call_id, dest_call_id, options, &msg_data);
4863 pj_pool_release(pool);
Fahris6f35cb82007-02-01 07:41:26 +00004864 } else {
Fahris17d91812007-01-29 12:09:33 +00004865 status = pjsua_call_xfer_replaces(call_id, dest_call_id,options, NULL);
Fahris6f35cb82007-02-01 07:41:26 +00004866 }
Fahrisdcf8fa42006-12-28 03:13:48 +00004867 return Py_BuildValue("i",status);
4868}
4869
4870/*
4871 * py_pjsua_call_dial_dtmf
4872 */
4873static PyObject *py_pjsua_call_dial_dtmf
4874(PyObject *pSelf, PyObject *pArgs)
4875{
4876 int call_id;
4877 PyObject * sd;
4878 pj_str_t digits;
4879 int status;
4880
Benny Prijono1f63cc42007-09-10 16:54:22 +00004881 PJ_UNUSED_ARG(pSelf);
4882
Fahrisdcf8fa42006-12-28 03:13:48 +00004883 if (!PyArg_ParseTuple(pArgs, "iO", &call_id, &sd))
4884 {
4885 return NULL;
4886 }
4887 digits.ptr = PyString_AsString(sd);
4888 digits.slen = strlen(PyString_AsString(sd));
4889 status = pjsua_call_dial_dtmf(call_id, &digits);
4890
4891 return Py_BuildValue("i", status);
4892}
4893
4894/*
4895 * py_pjsua_call_send_im
4896 */
4897static PyObject *py_pjsua_call_send_im
4898(PyObject *pSelf, PyObject *pArgs)
4899{
4900 int status;
4901 int call_id;
Fahris6f35cb82007-02-01 07:41:26 +00004902 pj_str_t content;
Fahrise314b882007-02-02 10:52:04 +00004903 pj_str_t * mime_type, tmp_mime_type;
Fahrisdcf8fa42006-12-28 03:13:48 +00004904 PyObject * sm;
4905 PyObject * sc;
4906 pjsua_msg_data msg_data;
Fahris17d91812007-01-29 12:09:33 +00004907 PyObject * omdObj;
Benny Prijono1f63cc42007-09-10 16:54:22 +00004908 PyObj_pjsua_msg_data * omd;
Fahrisdcf8fa42006-12-28 03:13:48 +00004909 int user_data;
4910 pj_pool_t * pool;
4911
Benny Prijono1f63cc42007-09-10 16:54:22 +00004912 PJ_UNUSED_ARG(pSelf);
4913
Fahris17d91812007-01-29 12:09:33 +00004914 if (!PyArg_ParseTuple
4915 (pArgs, "iOOOi", &call_id, &sm, &sc, &omdObj, &user_data))
Fahrisdcf8fa42006-12-28 03:13:48 +00004916 {
4917 return NULL;
4918 }
Fahris6f35cb82007-02-01 07:41:26 +00004919 if (sm == Py_None)
4920 {
4921 mime_type = NULL;
4922 } else {
Fahrise314b882007-02-02 10:52:04 +00004923 mime_type = &tmp_mime_type;
4924 tmp_mime_type.ptr = PyString_AsString(sm);
4925 tmp_mime_type.slen = strlen(PyString_AsString(sm));
Fahris6f35cb82007-02-01 07:41:26 +00004926 }
Fahrisdcf8fa42006-12-28 03:13:48 +00004927 content.ptr = PyString_AsString(sc);
4928 content.slen = strlen(PyString_AsString(sc));
4929
Fahris17d91812007-01-29 12:09:33 +00004930 if (omdObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00004931 {
Benny Prijono1f63cc42007-09-10 16:54:22 +00004932 omd = (PyObj_pjsua_msg_data *)omdObj;
Fahris17d91812007-01-29 12:09:33 +00004933 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
4934 msg_data.content_type.slen = strlen
4935 (PyString_AsString(omd->content_type));
4936 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
4937 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00004938 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Fahris17d91812007-01-29 12:09:33 +00004939 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
4940 status = pjsua_call_send_im
Fahris6f35cb82007-02-01 07:41:26 +00004941 (call_id, mime_type, &content, &msg_data, (void *)user_data);
Fahris17d91812007-01-29 12:09:33 +00004942 pj_pool_release(pool);
Fahris6f35cb82007-02-01 07:41:26 +00004943 } else {
Fahris17d91812007-01-29 12:09:33 +00004944 status = pjsua_call_send_im
Fahris6f35cb82007-02-01 07:41:26 +00004945 (call_id, mime_type, &content, NULL, (void *)user_data);
4946 }
Fahrise314b882007-02-02 10:52:04 +00004947
Fahrisdcf8fa42006-12-28 03:13:48 +00004948 return Py_BuildValue("i",status);
4949}
4950
4951/*
4952 * py_pjsua_call_send_typing_ind
4953 */
4954static PyObject *py_pjsua_call_send_typing_ind
4955(PyObject *pSelf, PyObject *pArgs)
4956{
4957 int status;
4958 int call_id;
4959 int is_typing;
4960 pjsua_msg_data msg_data;
Fahris17d91812007-01-29 12:09:33 +00004961 PyObject * omdObj;
Benny Prijono1f63cc42007-09-10 16:54:22 +00004962 PyObj_pjsua_msg_data * omd;
Fahrisdcf8fa42006-12-28 03:13:48 +00004963 pj_pool_t * pool;
4964
Benny Prijono1f63cc42007-09-10 16:54:22 +00004965 PJ_UNUSED_ARG(pSelf);
4966
Fahris17d91812007-01-29 12:09:33 +00004967 if (!PyArg_ParseTuple(pArgs, "iiO", &call_id, &is_typing, &omdObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00004968 {
4969 return NULL;
4970 }
4971
Fahris17d91812007-01-29 12:09:33 +00004972 if (omdObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00004973 {
Benny Prijono1f63cc42007-09-10 16:54:22 +00004974 omd = (PyObj_pjsua_msg_data *)omdObj;
Fahris17d91812007-01-29 12:09:33 +00004975 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
4976 msg_data.content_type.slen = strlen
4977 (PyString_AsString(omd->content_type));
4978 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
4979 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00004980 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Fahris17d91812007-01-29 12:09:33 +00004981 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
4982 status = pjsua_call_send_typing_ind(call_id, is_typing, &msg_data);
4983 pj_pool_release(pool);
Fahris6f35cb82007-02-01 07:41:26 +00004984 } else {
Fahris17d91812007-01-29 12:09:33 +00004985 status = pjsua_call_send_typing_ind(call_id, is_typing, NULL);
Fahris6f35cb82007-02-01 07:41:26 +00004986 }
Fahrisdcf8fa42006-12-28 03:13:48 +00004987 return Py_BuildValue("i",status);
4988}
4989
4990/*
4991 * py_pjsua_call_hangup_all
4992 */
4993static PyObject *py_pjsua_call_hangup_all
4994(PyObject *pSelf, PyObject *pArgs)
4995{
4996
Benny Prijono1f63cc42007-09-10 16:54:22 +00004997 PJ_UNUSED_ARG(pSelf);
4998
Fahrisdcf8fa42006-12-28 03:13:48 +00004999 if (!PyArg_ParseTuple(pArgs, ""))
5000 {
5001 return NULL;
5002 }
5003
5004 pjsua_call_hangup_all();
5005
5006 Py_INCREF(Py_None);
5007 return Py_None;
5008}
5009
5010/*
5011 * py_pjsua_call_dump
5012 */
5013static PyObject *py_pjsua_call_dump
5014(PyObject *pSelf, PyObject *pArgs)
5015{
5016 int call_id;
5017 int with_media;
5018 PyObject * sb;
5019 PyObject * si;
5020 char * buffer;
5021 char * indent;
5022 unsigned maxlen;
5023 int status;
5024
Benny Prijono1f63cc42007-09-10 16:54:22 +00005025 PJ_UNUSED_ARG(pSelf);
5026
Fahrisdcf8fa42006-12-28 03:13:48 +00005027 if (!PyArg_ParseTuple(pArgs, "iiIO", &call_id, &with_media, &maxlen, &si))
5028 {
5029 return NULL;
5030 }
5031 buffer = (char *) malloc (maxlen * sizeof(char));
5032 indent = PyString_AsString(si);
5033
5034 status = pjsua_call_dump(call_id, with_media, buffer, maxlen, indent);
5035 sb = PyString_FromStringAndSize(buffer, maxlen);
Fahris6f35cb82007-02-01 07:41:26 +00005036 free(buffer);
Fahrisdcf8fa42006-12-28 03:13:48 +00005037 return Py_BuildValue("O", sb);
5038}
5039
Benny Prijonoda275f62007-02-18 23:49:14 +00005040
5041/*
5042 * py_pjsua_dump
5043 * Dump application states.
5044 */
5045static PyObject *py_pjsua_dump(PyObject *pSelf, PyObject *pArgs)
5046{
5047 unsigned old_decor;
5048 char buf[1024];
5049 int detail;
5050
Benny Prijono1f63cc42007-09-10 16:54:22 +00005051 PJ_UNUSED_ARG(pSelf);
5052
Benny Prijonoda275f62007-02-18 23:49:14 +00005053 if (!PyArg_ParseTuple(pArgs, "i", &detail))
5054 {
5055 return NULL;
5056 }
5057
5058 PJ_LOG(3,(THIS_FILE, "Start dumping application states:"));
5059
5060 old_decor = pj_log_get_decor();
5061 pj_log_set_decor(old_decor & (PJ_LOG_HAS_NEWLINE | PJ_LOG_HAS_CR));
5062
5063 if (detail)
5064 pj_dump_config();
5065
5066 pjsip_endpt_dump(pjsua_get_pjsip_endpt(), detail);
5067 pjmedia_endpt_dump(pjsua_get_pjmedia_endpt());
5068 pjsip_tsx_layer_dump(detail);
5069 pjsip_ua_dump(detail);
5070
5071
5072 /* Dump all invite sessions: */
5073 PJ_LOG(3,(THIS_FILE, "Dumping invite sessions:"));
5074
5075 if (pjsua_call_get_count() == 0) {
5076
5077 PJ_LOG(3,(THIS_FILE, " - no sessions -"));
5078
5079 } else {
5080 unsigned i, max;
5081
5082 max = pjsua_call_get_max_count();
5083 for (i=0; i<max; ++i) {
5084 if (pjsua_call_is_active(i)) {
5085 pjsua_call_dump(i, detail, buf, sizeof(buf), " ");
5086 PJ_LOG(3,(THIS_FILE, "%s", buf));
5087 }
5088 }
5089 }
5090
5091 /* Dump presence status */
5092 pjsua_pres_dump(detail);
5093
5094 pj_log_set_decor(old_decor);
5095 PJ_LOG(3,(THIS_FILE, "Dump complete"));
5096
5097 Py_INCREF(Py_None);
5098 return Py_None;
5099}
5100
5101
Fahrisdcf8fa42006-12-28 03:13:48 +00005102static char pjsua_call_get_max_count_doc[] =
5103 "int py_pjsua.call_get_max_count () "
5104 "Get maximum number of calls configured in pjsua.";
5105static char pjsua_call_get_count_doc[] =
5106 "int py_pjsua.call_get_count () "
5107 "Get number of currently active calls.";
5108static char pjsua_enum_calls_doc[] =
5109 "int[] py_pjsua.enum_calls () "
5110 "Get maximum number of calls configured in pjsua.";
5111static char pjsua_call_make_call_doc[] =
5112 "int,int py_pjsua.call_make_call (int acc_id, string dst_uri, int options,"
5113 "int user_data, py_pjsua.Msg_Data msg_data) "
5114 "Make outgoing call to the specified URI using the specified account.";
5115static char pjsua_call_is_active_doc[] =
5116 "int py_pjsua.call_is_active (int call_id) "
5117 "Check if the specified call has active INVITE session and the INVITE "
5118 "session has not been disconnected.";
5119static char pjsua_call_has_media_doc[] =
5120 "int py_pjsua.call_has_media (int call_id) "
5121 "Check if call has an active media session.";
5122static char pjsua_call_get_conf_port_doc[] =
5123 "int py_pjsua.call_get_conf_port (int call_id) "
5124 "Get the conference port identification associated with the call.";
5125static char pjsua_call_get_info_doc[] =
5126 "py_pjsua.Call_Info py_pjsua.call_get_info (int call_id) "
5127 "Obtain detail information about the specified call.";
5128static char pjsua_call_set_user_data_doc[] =
5129 "int py_pjsua.call_set_user_data (int call_id, int user_data) "
5130 "Attach application specific data to the call.";
5131static char pjsua_call_get_user_data_doc[] =
5132 "int py_pjsua.call_get_user_data (int call_id) "
5133 "Get user data attached to the call.";
5134static char pjsua_call_answer_doc[] =
5135 "int py_pjsua.call_answer (int call_id, int code, string reason, "
5136 "py_pjsua.Msg_Data msg_data) "
5137 "Send response to incoming INVITE request.";
5138static char pjsua_call_hangup_doc[] =
5139 "int py_pjsua.call_hangup (int call_id, int code, string reason, "
5140 "py_pjsua.Msg_Data msg_data) "
5141 "Hangup call by using method that is appropriate according "
5142 "to the call state.";
5143static char pjsua_call_set_hold_doc[] =
5144 "int py_pjsua.call_set_hold (int call_id, py_pjsua.Msg_Data msg_data) "
5145 "Put the specified call on hold.";
5146static char pjsua_call_reinvite_doc[] =
5147 "int py_pjsua.call_reinvite (int call_id, int unhold, "
5148 "py_pjsua.Msg_Data msg_data) "
5149 "Send re-INVITE (to release hold).";
5150static char pjsua_call_xfer_doc[] =
5151 "int py_pjsua.call_xfer (int call_id, string dest, "
5152 "py_pjsua.Msg_Data msg_data) "
5153 "Initiate call transfer to the specified address. "
5154 "This function will send REFER request to instruct remote call party "
5155 "to initiate a new INVITE session to the specified destination/target.";
5156static char pjsua_call_xfer_replaces_doc[] =
5157 "int py_pjsua.call_xfer_replaces (int call_id, int dest_call_id, "
5158 "int options, py_pjsua.Msg_Data msg_data) "
5159 "Initiate attended call transfer. This function will send REFER request "
5160 "to instruct remote call party to initiate new INVITE session to the URL "
5161 "of dest_call_id. The party at dest_call_id then should 'replace' the call"
5162 "with us with the new call from the REFER recipient.";
5163static char pjsua_call_dial_dtmf_doc[] =
5164 "int py_pjsua.call_dial_dtmf (int call_id, string digits) "
5165 "Send DTMF digits to remote using RFC 2833 payload formats.";
5166static char pjsua_call_send_im_doc[] =
5167 "int py_pjsua.call_send_im (int call_id, string mime_type, string content,"
5168 "py_pjsua.Msg_Data msg_data, int user_data) "
5169 "Send instant messaging inside INVITE session.";
5170static char pjsua_call_send_typing_ind_doc[] =
5171 "int py_pjsua.call_send_typing_ind (int call_id, int is_typing, "
5172 "py_pjsua.Msg_Data msg_data) "
5173 "Send IM typing indication inside INVITE session.";
5174static char pjsua_call_hangup_all_doc[] =
5175 "void py_pjsua.call_hangup_all () "
5176 "Terminate all calls.";
5177static char pjsua_call_dump_doc[] =
5178 "int py_pjsua.call_dump (int call_id, int with_media, int maxlen, "
5179 "string indent) "
5180 "Dump call and media statistics to string.";
5181
5182/* END OF LIB CALL */
5183
Benny Prijono572d4852006-11-23 21:50:02 +00005184/*
5185 * Map of function names to functions
5186 */
5187static PyMethodDef py_pjsua_methods[] =
5188{
5189 {
Benny Prijonodc308702006-12-09 00:39:42 +00005190 "thread_register", py_pjsua_thread_register, METH_VARARGS,
5191 pjsua_thread_register_doc
Benny Prijono98793592006-12-04 08:33:20 +00005192 },
5193 {
Benny Prijono572d4852006-11-23 21:50:02 +00005194 "perror", py_pjsua_perror, METH_VARARGS, pjsua_perror_doc
5195 },
5196 {
5197 "create", py_pjsua_create, METH_VARARGS, pjsua_create_doc
5198 },
5199 {
5200 "init", py_pjsua_init, METH_VARARGS, pjsua_init_doc
5201 },
5202 {
5203 "start", py_pjsua_start, METH_VARARGS, pjsua_start_doc
5204 },
5205 {
5206 "destroy", py_pjsua_destroy, METH_VARARGS, pjsua_destroy_doc
5207 },
5208 {
5209 "handle_events", py_pjsua_handle_events, METH_VARARGS,
5210 pjsua_handle_events_doc
5211 },
5212 {
5213 "verify_sip_url", py_pjsua_verify_sip_url, METH_VARARGS,
5214 pjsua_verify_sip_url_doc
5215 },
5216 {
5217 "pool_create", py_pjsua_pool_create, METH_VARARGS,
5218 pjsua_pool_create_doc
5219 },
5220 {
5221 "get_pjsip_endpt", py_pjsua_get_pjsip_endpt, METH_VARARGS,
5222 pjsua_get_pjsip_endpt_doc
5223 },
5224 {
5225 "get_pjmedia_endpt", py_pjsua_get_pjmedia_endpt, METH_VARARGS,
5226 pjsua_get_pjmedia_endpt_doc
5227 },
5228 {
5229 "get_pool_factory", py_pjsua_get_pool_factory, METH_VARARGS,
5230 pjsua_get_pool_factory_doc
5231 },
5232 {
5233 "reconfigure_logging", py_pjsua_reconfigure_logging, METH_VARARGS,
5234 pjsua_reconfigure_logging_doc
5235 },
5236 {
5237 "logging_config_default", py_pjsua_logging_config_default,
5238 METH_VARARGS, pjsua_logging_config_default_doc
5239 },
5240 {
5241 "config_default", py_pjsua_config_default, METH_VARARGS,
5242 pjsua_config_default_doc
5243 },
5244 {
5245 "media_config_default", py_pjsua_media_config_default, METH_VARARGS,
5246 pjsua_media_config_default_doc
5247 },
Benny Prijonodc308702006-12-09 00:39:42 +00005248
5249
Benny Prijono572d4852006-11-23 21:50:02 +00005250 {
5251 "msg_data_init", py_pjsua_msg_data_init, METH_VARARGS,
5252 pjsua_msg_data_init_doc
5253 },
Benny Prijonodc308702006-12-09 00:39:42 +00005254 {
Benny Prijonodc308702006-12-09 00:39:42 +00005255 "transport_config_default", py_pjsua_transport_config_default,
5256 METH_VARARGS,pjsua_transport_config_default_doc
Benny Prijono98793592006-12-04 08:33:20 +00005257 },
Benny Prijonodc308702006-12-09 00:39:42 +00005258 {
Benny Prijonodc308702006-12-09 00:39:42 +00005259 "transport_create", py_pjsua_transport_create, METH_VARARGS,
5260 pjsua_transport_create_doc
Benny Prijono98793592006-12-04 08:33:20 +00005261 },
Benny Prijonodc308702006-12-09 00:39:42 +00005262 {
Benny Prijonodc308702006-12-09 00:39:42 +00005263 "transport_enum_transports", py_pjsua_enum_transports, METH_VARARGS,
5264 pjsua_enum_transports_doc
Benny Prijono98793592006-12-04 08:33:20 +00005265 },
Benny Prijonodc308702006-12-09 00:39:42 +00005266 {
5267 "transport_get_info", py_pjsua_transport_get_info, METH_VARARGS,
5268 pjsua_transport_get_info_doc
Benny Prijono98793592006-12-04 08:33:20 +00005269 },
Benny Prijonodc308702006-12-09 00:39:42 +00005270 {
5271 "transport_set_enable", py_pjsua_transport_set_enable, METH_VARARGS,
5272 pjsua_transport_set_enable_doc
Benny Prijono98793592006-12-04 08:33:20 +00005273 },
Benny Prijonodc308702006-12-09 00:39:42 +00005274 {
5275 "transport_close", py_pjsua_transport_close, METH_VARARGS,
5276 pjsua_transport_close_doc
Benny Prijono98793592006-12-04 08:33:20 +00005277 },
Benny Prijonodc308702006-12-09 00:39:42 +00005278 {
5279 "acc_config_default", py_pjsua_acc_config_default, METH_VARARGS,
5280 pjsua_acc_config_default_doc
Benny Prijono98793592006-12-04 08:33:20 +00005281 },
Benny Prijonodc308702006-12-09 00:39:42 +00005282 {
5283 "acc_get_count", py_pjsua_acc_get_count, METH_VARARGS,
5284 pjsua_acc_get_count_doc
Benny Prijono98793592006-12-04 08:33:20 +00005285 },
Benny Prijonodc308702006-12-09 00:39:42 +00005286 {
5287 "acc_is_valid", py_pjsua_acc_is_valid, METH_VARARGS,
5288 pjsua_acc_is_valid_doc
Benny Prijono98793592006-12-04 08:33:20 +00005289 },
Benny Prijonodc308702006-12-09 00:39:42 +00005290 {
5291 "acc_set_default", py_pjsua_acc_set_default, METH_VARARGS,
5292 pjsua_acc_set_default_doc
Benny Prijono98793592006-12-04 08:33:20 +00005293 },
Benny Prijonodc308702006-12-09 00:39:42 +00005294 {
5295 "acc_get_default", py_pjsua_acc_get_default, METH_VARARGS,
5296 pjsua_acc_get_default_doc
Benny Prijono98793592006-12-04 08:33:20 +00005297 },
Benny Prijonodc308702006-12-09 00:39:42 +00005298 {
5299 "acc_add", py_pjsua_acc_add, METH_VARARGS,
5300 pjsua_acc_add_doc
Benny Prijono98793592006-12-04 08:33:20 +00005301 },
Benny Prijonodc308702006-12-09 00:39:42 +00005302 {
5303 "acc_add_local", py_pjsua_acc_add_local, METH_VARARGS,
5304 pjsua_acc_add_local_doc
Benny Prijono98793592006-12-04 08:33:20 +00005305 },
Benny Prijonodc308702006-12-09 00:39:42 +00005306 {
5307 "acc_del", py_pjsua_acc_del, METH_VARARGS,
5308 pjsua_acc_del_doc
Benny Prijono98793592006-12-04 08:33:20 +00005309 },
Benny Prijonodc308702006-12-09 00:39:42 +00005310 {
5311 "acc_modify", py_pjsua_acc_modify, METH_VARARGS,
5312 pjsua_acc_modify_doc
Benny Prijono98793592006-12-04 08:33:20 +00005313 },
Benny Prijonodc308702006-12-09 00:39:42 +00005314 {
5315 "acc_set_online_status", py_pjsua_acc_set_online_status, METH_VARARGS,
5316 pjsua_acc_set_online_status_doc
Benny Prijono98793592006-12-04 08:33:20 +00005317 },
Benny Prijonodc308702006-12-09 00:39:42 +00005318 {
Benny Prijono1f63cc42007-09-10 16:54:22 +00005319 "acc_set_online_status2", py_pjsua_acc_set_online_status2, METH_VARARGS,
5320 pjsua_acc_set_online_status2_doc
5321 },
5322 {
Benny Prijonodc308702006-12-09 00:39:42 +00005323 "acc_set_registration", py_pjsua_acc_set_registration, METH_VARARGS,
5324 pjsua_acc_set_registration_doc
Benny Prijono98793592006-12-04 08:33:20 +00005325 },
Benny Prijonodc308702006-12-09 00:39:42 +00005326 {
5327 "acc_get_info", py_pjsua_acc_get_info, METH_VARARGS,
5328 pjsua_acc_get_info_doc
Benny Prijono98793592006-12-04 08:33:20 +00005329 },
Benny Prijonodc308702006-12-09 00:39:42 +00005330 {
5331 "enum_accs", py_pjsua_enum_accs, METH_VARARGS,
5332 pjsua_enum_accs_doc
Benny Prijono98793592006-12-04 08:33:20 +00005333 },
Benny Prijonodc308702006-12-09 00:39:42 +00005334 {
5335 "acc_enum_info", py_pjsua_acc_enum_info, METH_VARARGS,
5336 pjsua_acc_enum_info_doc
Benny Prijono98793592006-12-04 08:33:20 +00005337 },
Benny Prijonodc308702006-12-09 00:39:42 +00005338 {
5339 "acc_find_for_outgoing", py_pjsua_acc_find_for_outgoing, METH_VARARGS,
5340 pjsua_acc_find_for_outgoing_doc
Benny Prijono98793592006-12-04 08:33:20 +00005341 },
Benny Prijonodc308702006-12-09 00:39:42 +00005342 {
5343 "acc_find_for_incoming", py_pjsua_acc_find_for_incoming, METH_VARARGS,
5344 pjsua_acc_find_for_incoming_doc
Benny Prijono98793592006-12-04 08:33:20 +00005345 },
Benny Prijonodc308702006-12-09 00:39:42 +00005346 {
5347 "acc_create_uac_contact", py_pjsua_acc_create_uac_contact, METH_VARARGS,
5348 pjsua_acc_create_uac_contact_doc
Benny Prijono98793592006-12-04 08:33:20 +00005349 },
Benny Prijonodc308702006-12-09 00:39:42 +00005350 {
5351 "acc_create_uas_contact", py_pjsua_acc_create_uas_contact, METH_VARARGS,
5352 pjsua_acc_create_uas_contact_doc
Benny Prijono98793592006-12-04 08:33:20 +00005353 },
Benny Prijonodc308702006-12-09 00:39:42 +00005354 {
Fahris6f35cb82007-02-01 07:41:26 +00005355 "buddy_config_default", py_pjsua_buddy_config_default, METH_VARARGS,
5356 pjsua_buddy_config_default_doc
5357 },
5358 {
Benny Prijonodc308702006-12-09 00:39:42 +00005359 "get_buddy_count", py_pjsua_get_buddy_count, METH_VARARGS,
5360 pjsua_get_buddy_count_doc
Benny Prijono98793592006-12-04 08:33:20 +00005361 },
Benny Prijonodc308702006-12-09 00:39:42 +00005362 {
5363 "buddy_is_valid", py_pjsua_buddy_is_valid, METH_VARARGS,
5364 pjsua_buddy_is_valid_doc
5365 },
5366 {
5367 "enum_buddies", py_pjsua_enum_buddies, METH_VARARGS,
5368 pjsua_enum_buddies_doc
Fahris6f35cb82007-02-01 07:41:26 +00005369 },
Benny Prijonodc308702006-12-09 00:39:42 +00005370 {
5371 "buddy_get_info", py_pjsua_buddy_get_info, METH_VARARGS,
5372 pjsua_buddy_get_info_doc
5373 },
5374 {
5375 "buddy_add", py_pjsua_buddy_add, METH_VARARGS,
5376 pjsua_buddy_add_doc
5377 },
5378 {
5379 "buddy_del", py_pjsua_buddy_del, METH_VARARGS,
5380 pjsua_buddy_del_doc
5381 },
5382 {
5383 "buddy_subscribe_pres", py_pjsua_buddy_subscribe_pres, METH_VARARGS,
5384 pjsua_buddy_subscribe_pres_doc
5385 },
5386 {
5387 "pres_dump", py_pjsua_pres_dump, METH_VARARGS,
5388 pjsua_pres_dump_doc
5389 },
5390 {
5391 "im_send", py_pjsua_im_send, METH_VARARGS,
5392 pjsua_im_send_doc
5393 },
5394 {
5395 "im_typing", py_pjsua_im_typing, METH_VARARGS,
5396 pjsua_im_typing_doc
5397 },
Fahrisdcf8fa42006-12-28 03:13:48 +00005398 {
5399 "conf_get_max_ports", py_pjsua_conf_get_max_ports, METH_VARARGS,
5400 pjsua_conf_get_max_ports_doc
5401 },
5402 {
5403 "conf_get_active_ports", py_pjsua_conf_get_active_ports, METH_VARARGS,
5404 pjsua_conf_get_active_ports_doc
5405 },
5406 {
5407 "enum_conf_ports", py_pjsua_enum_conf_ports, METH_VARARGS,
5408 pjsua_enum_conf_ports_doc
5409 },
5410 {
5411 "conf_get_port_info", py_pjsua_conf_get_port_info, METH_VARARGS,
5412 pjsua_conf_get_port_info_doc
5413 },
5414 {
5415 "conf_add_port", py_pjsua_conf_add_port, METH_VARARGS,
5416 pjsua_conf_add_port_doc
5417 },
5418 {
5419 "conf_remove_port", py_pjsua_conf_remove_port, METH_VARARGS,
5420 pjsua_conf_remove_port_doc
5421 },
5422 {
5423 "conf_connect", py_pjsua_conf_connect, METH_VARARGS,
5424 pjsua_conf_connect_doc
5425 },
5426 {
5427 "conf_disconnect", py_pjsua_conf_disconnect, METH_VARARGS,
5428 pjsua_conf_disconnect_doc
5429 },
5430 {
5431 "player_create", py_pjsua_player_create, METH_VARARGS,
5432 pjsua_player_create_doc
5433 },
5434 {
5435 "player_get_conf_port", py_pjsua_player_get_conf_port, METH_VARARGS,
5436 pjsua_player_get_conf_port_doc
5437 },
5438 {
5439 "player_set_pos", py_pjsua_player_set_pos, METH_VARARGS,
5440 pjsua_player_set_pos_doc
5441 },
5442 {
5443 "player_destroy", py_pjsua_player_destroy, METH_VARARGS,
5444 pjsua_player_destroy_doc
5445 },
5446 {
5447 "recorder_create", py_pjsua_recorder_create, METH_VARARGS,
5448 pjsua_recorder_create_doc
5449 },
5450 {
5451 "recorder_get_conf_port", py_pjsua_recorder_get_conf_port, METH_VARARGS,
5452 pjsua_recorder_get_conf_port_doc
5453 },
5454 {
5455 "recorder_destroy", py_pjsua_recorder_destroy, METH_VARARGS,
5456 pjsua_recorder_destroy_doc
5457 },
5458 {
5459 "enum_snd_devs", py_pjsua_enum_snd_devs, METH_VARARGS,
5460 pjsua_enum_snd_devs_doc
5461 },
Benny Prijonoebdf8772007-02-01 19:25:50 +00005462 {
Fahrisdcf8fa42006-12-28 03:13:48 +00005463 "get_snd_dev", py_pjsua_get_snd_dev, METH_VARARGS,
5464 pjsua_get_snd_dev_doc
Benny Prijonoebdf8772007-02-01 19:25:50 +00005465 },
Fahrisdcf8fa42006-12-28 03:13:48 +00005466 {
5467 "set_snd_dev", py_pjsua_set_snd_dev, METH_VARARGS,
5468 pjsua_set_snd_dev_doc
5469 },
5470 {
5471 "set_null_snd_dev", py_pjsua_set_null_snd_dev, METH_VARARGS,
5472 pjsua_set_null_snd_dev_doc
5473 },
5474 {
5475 "set_no_snd_dev", py_pjsua_set_no_snd_dev, METH_VARARGS,
5476 pjsua_set_no_snd_dev_doc
5477 },
5478 {
5479 "set_ec", py_pjsua_set_ec, METH_VARARGS,
5480 pjsua_set_ec_doc
5481 },
5482 {
5483 "get_ec_tail", py_pjsua_get_ec_tail, METH_VARARGS,
5484 pjsua_get_ec_tail_doc
5485 },
5486 {
5487 "enum_codecs", py_pjsua_enum_codecs, METH_VARARGS,
5488 pjsua_enum_codecs_doc
5489 },
5490 {
5491 "codec_set_priority", py_pjsua_codec_set_priority, METH_VARARGS,
5492 pjsua_codec_set_priority_doc
5493 },
5494 {
5495 "codec_get_param", py_pjsua_codec_get_param, METH_VARARGS,
5496 pjsua_codec_get_param_doc
5497 },
5498 {
5499 "codec_set_param", py_pjsua_codec_set_param, METH_VARARGS,
5500 pjsua_codec_set_param_doc
5501 },
5502 {
5503 "call_get_max_count", py_pjsua_call_get_max_count, METH_VARARGS,
5504 pjsua_call_get_max_count_doc
5505 },
5506 {
5507 "call_get_count", py_pjsua_call_get_count, METH_VARARGS,
5508 pjsua_call_get_count_doc
5509 },
5510 {
5511 "enum_calls", py_pjsua_enum_calls, METH_VARARGS,
5512 pjsua_enum_calls_doc
5513 },
5514 {
5515 "call_make_call", py_pjsua_call_make_call, METH_VARARGS,
5516 pjsua_call_make_call_doc
5517 },
5518 {
5519 "call_is_active", py_pjsua_call_is_active, METH_VARARGS,
5520 pjsua_call_is_active_doc
5521 },
5522 {
5523 "call_has_media", py_pjsua_call_has_media, METH_VARARGS,
5524 pjsua_call_has_media_doc
5525 },
5526 {
5527 "call_get_conf_port", py_pjsua_call_get_conf_port, METH_VARARGS,
5528 pjsua_call_get_conf_port_doc
5529 },
5530 {
5531 "call_get_info", py_pjsua_call_get_info, METH_VARARGS,
5532 pjsua_call_get_info_doc
5533 },
5534 {
5535 "call_set_user_data", py_pjsua_call_set_user_data, METH_VARARGS,
5536 pjsua_call_set_user_data_doc
5537 },
5538 {
5539 "call_get_user_data", py_pjsua_call_get_user_data, METH_VARARGS,
5540 pjsua_call_get_user_data_doc
5541 },
5542 {
5543 "call_answer", py_pjsua_call_answer, METH_VARARGS,
5544 pjsua_call_answer_doc
5545 },
5546 {
5547 "call_hangup", py_pjsua_call_hangup, METH_VARARGS,
5548 pjsua_call_hangup_doc
5549 },
5550 {
5551 "call_set_hold", py_pjsua_call_set_hold, METH_VARARGS,
5552 pjsua_call_set_hold_doc
5553 },
5554 {
5555 "call_reinvite", py_pjsua_call_reinvite, METH_VARARGS,
5556 pjsua_call_reinvite_doc
5557 },
5558 {
5559 "call_xfer", py_pjsua_call_xfer, METH_VARARGS,
5560 pjsua_call_xfer_doc
5561 },
5562 {
5563 "call_xfer_replaces", py_pjsua_call_xfer_replaces, METH_VARARGS,
5564 pjsua_call_xfer_replaces_doc
5565 },
5566 {
5567 "call_dial_dtmf", py_pjsua_call_dial_dtmf, METH_VARARGS,
5568 pjsua_call_dial_dtmf_doc
5569 },
5570 {
5571 "call_send_im", py_pjsua_call_send_im, METH_VARARGS,
5572 pjsua_call_send_im_doc
5573 },
5574 {
5575 "call_send_typing_ind", py_pjsua_call_send_typing_ind, METH_VARARGS,
5576 pjsua_call_send_typing_ind_doc
5577 },
5578 {
5579 "call_hangup_all", py_pjsua_call_hangup_all, METH_VARARGS,
5580 pjsua_call_hangup_all_doc
5581 },
5582 {
5583 "call_dump", py_pjsua_call_dump, METH_VARARGS,
5584 pjsua_call_dump_doc
5585 },
Benny Prijonoda275f62007-02-18 23:49:14 +00005586 {
5587 "dump", py_pjsua_dump, METH_VARARGS, "Dump application state"
5588 },
Fahrisdcf8fa42006-12-28 03:13:48 +00005589
Benny Prijonodc308702006-12-09 00:39:42 +00005590
Benny Prijono572d4852006-11-23 21:50:02 +00005591 {NULL, NULL} /* end of function list */
5592};
5593
5594
5595
5596/*
5597 * Mapping C structs from and to Python objects & initializing object
5598 */
5599DL_EXPORT(void)
Benny Prijono8b8b9972006-11-16 11:18:03 +00005600initpy_pjsua(void)
5601{
Benny Prijono572d4852006-11-23 21:50:02 +00005602 PyObject* m = NULL;
Benny Prijonoaa286042007-02-03 17:23:22 +00005603#define ADD_CONSTANT(mod,name) PyModule_AddIntConstant(mod,#name,name)
Benny Prijono572d4852006-11-23 21:50:02 +00005604
Benny Prijonodc308702006-12-09 00:39:42 +00005605
Benny Prijonoda275f62007-02-18 23:49:14 +00005606 PyEval_InitThreads();
5607
Benny Prijono1f63cc42007-09-10 16:54:22 +00005608 if (PyType_Ready(&PyTyp_pjsua_callback) < 0)
Benny Prijono572d4852006-11-23 21:50:02 +00005609 return;
Benny Prijono1f63cc42007-09-10 16:54:22 +00005610 if (PyType_Ready(&PyTyp_pjsua_config) < 0)
Benny Prijono572d4852006-11-23 21:50:02 +00005611 return;
Benny Prijono1f63cc42007-09-10 16:54:22 +00005612 if (PyType_Ready(&PyTyp_pjsua_logging_config) < 0)
Benny Prijono572d4852006-11-23 21:50:02 +00005613 return;
Benny Prijono1f63cc42007-09-10 16:54:22 +00005614 if (PyType_Ready(&PyTyp_pjsua_msg_data) < 0)
Benny Prijono572d4852006-11-23 21:50:02 +00005615 return;
Benny Prijono1f63cc42007-09-10 16:54:22 +00005616 PyTyp_pjsua_media_config.tp_new = PyType_GenericNew;
5617 if (PyType_Ready(&PyTyp_pjsua_media_config) < 0)
Benny Prijono572d4852006-11-23 21:50:02 +00005618 return;
Benny Prijono1f63cc42007-09-10 16:54:22 +00005619 PyTyp_pjsip_event.tp_new = PyType_GenericNew;
5620 if (PyType_Ready(&PyTyp_pjsip_event) < 0)
Benny Prijono572d4852006-11-23 21:50:02 +00005621 return;
Benny Prijono1f63cc42007-09-10 16:54:22 +00005622 PyTyp_pjsip_rx_data.tp_new = PyType_GenericNew;
5623 if (PyType_Ready(&PyTyp_pjsip_rx_data) < 0)
Benny Prijono572d4852006-11-23 21:50:02 +00005624 return;
Benny Prijono1f63cc42007-09-10 16:54:22 +00005625 PyTyp_pj_pool_t.tp_new = PyType_GenericNew;
5626 if (PyType_Ready(&PyTyp_pj_pool_t) < 0)
Benny Prijono572d4852006-11-23 21:50:02 +00005627 return;
Benny Prijono1f63cc42007-09-10 16:54:22 +00005628 PyTyp_pjsip_endpoint.tp_new = PyType_GenericNew;
5629 if (PyType_Ready(&PyTyp_pjsip_endpoint) < 0)
Benny Prijono572d4852006-11-23 21:50:02 +00005630 return;
Benny Prijono1f63cc42007-09-10 16:54:22 +00005631 PyTyp_pjmedia_endpt.tp_new = PyType_GenericNew;
5632 if (PyType_Ready(&PyTyp_pjmedia_endpt) < 0)
Benny Prijono572d4852006-11-23 21:50:02 +00005633 return;
Benny Prijono1f63cc42007-09-10 16:54:22 +00005634 PyTyp_pj_pool_factory.tp_new = PyType_GenericNew;
5635 if (PyType_Ready(&PyTyp_pj_pool_factory) < 0)
Benny Prijono572d4852006-11-23 21:50:02 +00005636 return;
Benny Prijono1f63cc42007-09-10 16:54:22 +00005637 PyTyp_pjsip_cred_info.tp_new = PyType_GenericNew;
5638 if (PyType_Ready(&PyTyp_pjsip_cred_info) < 0)
Benny Prijono572d4852006-11-23 21:50:02 +00005639 return;
5640
Benny Prijonodc308702006-12-09 00:39:42 +00005641 /* LIB TRANSPORT */
Benny Prijono98793592006-12-04 08:33:20 +00005642
Benny Prijono1f63cc42007-09-10 16:54:22 +00005643 if (PyType_Ready(&PyTyp_pjsua_transport_config) < 0)
Benny Prijono98793592006-12-04 08:33:20 +00005644 return;
Benny Prijonodc308702006-12-09 00:39:42 +00005645
Benny Prijono1f63cc42007-09-10 16:54:22 +00005646 if (PyType_Ready(&PyTyp_pjsua_transport_info) < 0)
Benny Prijono98793592006-12-04 08:33:20 +00005647 return;
Benny Prijonodc308702006-12-09 00:39:42 +00005648
Benny Prijonodc308702006-12-09 00:39:42 +00005649 /* END OF LIB TRANSPORT */
Benny Prijono98793592006-12-04 08:33:20 +00005650
Benny Prijonodc308702006-12-09 00:39:42 +00005651 /* LIB ACCOUNT */
Benny Prijono98793592006-12-04 08:33:20 +00005652
Benny Prijonodc308702006-12-09 00:39:42 +00005653
Benny Prijono1f63cc42007-09-10 16:54:22 +00005654 if (PyType_Ready(&PyTyp_pjsua_acc_config) < 0)
Benny Prijono98793592006-12-04 08:33:20 +00005655 return;
Benny Prijono1f63cc42007-09-10 16:54:22 +00005656 if (PyType_Ready(&PyTyp_pjsua_acc_info) < 0)
Benny Prijono98793592006-12-04 08:33:20 +00005657 return;
5658
Benny Prijonodc308702006-12-09 00:39:42 +00005659 /* END OF LIB ACCOUNT */
5660
5661 /* LIB BUDDY */
5662
Benny Prijono1f63cc42007-09-10 16:54:22 +00005663 if (PyType_Ready(&PyTyp_pjsua_buddy_config) < 0)
Benny Prijonodc308702006-12-09 00:39:42 +00005664 return;
Benny Prijono1f63cc42007-09-10 16:54:22 +00005665 if (PyType_Ready(&PyTyp_pjsua_buddy_info) < 0)
Benny Prijonodc308702006-12-09 00:39:42 +00005666 return;
5667
5668 /* END OF LIB BUDDY */
5669
Fahrisdcf8fa42006-12-28 03:13:48 +00005670 /* LIB MEDIA */
5671
Benny Prijono1f63cc42007-09-10 16:54:22 +00005672 if (PyType_Ready(&PyTyp_pjsua_codec_info) < 0)
Fahrisdcf8fa42006-12-28 03:13:48 +00005673 return;
5674
Benny Prijono1f63cc42007-09-10 16:54:22 +00005675 if (PyType_Ready(&PyTyp_pjsua_conf_port_info) < 0)
Fahrisdcf8fa42006-12-28 03:13:48 +00005676 return;
5677
Benny Prijono1f63cc42007-09-10 16:54:22 +00005678 PyTyp_pjmedia_port.tp_new = PyType_GenericNew;
5679 if (PyType_Ready(&PyTyp_pjmedia_port) < 0)
Fahrisdcf8fa42006-12-28 03:13:48 +00005680 return;
5681
Benny Prijono1f63cc42007-09-10 16:54:22 +00005682 if (PyType_Ready(&PyTyp_pjmedia_snd_dev_info) < 0)
Fahrisdcf8fa42006-12-28 03:13:48 +00005683 return;
5684
Benny Prijono1f63cc42007-09-10 16:54:22 +00005685 PyTyp_pjmedia_codec_param_info.tp_new = PyType_GenericNew;
5686 if (PyType_Ready(&PyTyp_pjmedia_codec_param_info) < 0)
Fahrisdcf8fa42006-12-28 03:13:48 +00005687 return;
Benny Prijono1f63cc42007-09-10 16:54:22 +00005688 PyTyp_pjmedia_codec_param_setting.tp_new = PyType_GenericNew;
5689 if (PyType_Ready(&PyTyp_pjmedia_codec_param_setting) < 0)
Fahrisdcf8fa42006-12-28 03:13:48 +00005690 return;
5691
Benny Prijono1f63cc42007-09-10 16:54:22 +00005692 if (PyType_Ready(&PyTyp_pjmedia_codec_param) < 0)
Fahrisdcf8fa42006-12-28 03:13:48 +00005693 return;
5694
5695 /* END OF LIB MEDIA */
5696
5697 /* LIB CALL */
5698
Benny Prijono1f63cc42007-09-10 16:54:22 +00005699 PyTyp_pj_time_val.tp_new = PyType_GenericNew;
5700 if (PyType_Ready(&PyTyp_pj_time_val) < 0)
Fahrisdcf8fa42006-12-28 03:13:48 +00005701 return;
5702
Benny Prijono1f63cc42007-09-10 16:54:22 +00005703 if (PyType_Ready(&PyTyp_pjsua_call_info) < 0)
Fahrisdcf8fa42006-12-28 03:13:48 +00005704 return;
5705
5706 /* END OF LIB CALL */
Benny Prijono98793592006-12-04 08:33:20 +00005707
Benny Prijono572d4852006-11-23 21:50:02 +00005708 m = Py_InitModule3(
5709 "py_pjsua", py_pjsua_methods,"PJSUA-lib module for python"
5710 );
5711
Benny Prijono1f63cc42007-09-10 16:54:22 +00005712 Py_INCREF(&PyTyp_pjsua_callback);
5713 PyModule_AddObject(m, "Callback", (PyObject *)&PyTyp_pjsua_callback);
Benny Prijono572d4852006-11-23 21:50:02 +00005714
Benny Prijono1f63cc42007-09-10 16:54:22 +00005715 Py_INCREF(&PyTyp_pjsua_config);
5716 PyModule_AddObject(m, "Config", (PyObject *)&PyTyp_pjsua_config);
Benny Prijono572d4852006-11-23 21:50:02 +00005717
Benny Prijono1f63cc42007-09-10 16:54:22 +00005718 Py_INCREF(&PyTyp_pjsua_media_config);
5719 PyModule_AddObject(m, "Media_Config", (PyObject *)&PyTyp_pjsua_media_config);
Benny Prijono572d4852006-11-23 21:50:02 +00005720
Benny Prijono1f63cc42007-09-10 16:54:22 +00005721 Py_INCREF(&PyTyp_pjsua_logging_config);
5722 PyModule_AddObject(m, "Logging_Config", (PyObject *)&PyTyp_pjsua_logging_config);
Benny Prijono572d4852006-11-23 21:50:02 +00005723
Benny Prijono1f63cc42007-09-10 16:54:22 +00005724 Py_INCREF(&PyTyp_pjsua_msg_data);
5725 PyModule_AddObject(m, "Msg_Data", (PyObject *)&PyTyp_pjsua_msg_data);
Benny Prijono572d4852006-11-23 21:50:02 +00005726
Benny Prijono1f63cc42007-09-10 16:54:22 +00005727 Py_INCREF(&PyTyp_pjsip_event);
5728 PyModule_AddObject(m, "Pjsip_Event", (PyObject *)&PyTyp_pjsip_event);
Benny Prijono572d4852006-11-23 21:50:02 +00005729
Benny Prijono1f63cc42007-09-10 16:54:22 +00005730 Py_INCREF(&PyTyp_pjsip_rx_data);
5731 PyModule_AddObject(m, "Pjsip_Rx_Data", (PyObject *)&PyTyp_pjsip_rx_data);
Benny Prijono572d4852006-11-23 21:50:02 +00005732
Benny Prijono1f63cc42007-09-10 16:54:22 +00005733 Py_INCREF(&PyTyp_pj_pool_t);
5734 PyModule_AddObject(m, "Pj_Pool", (PyObject *)&PyTyp_pj_pool_t);
Benny Prijono572d4852006-11-23 21:50:02 +00005735
Benny Prijono1f63cc42007-09-10 16:54:22 +00005736 Py_INCREF(&PyTyp_pjsip_endpoint);
5737 PyModule_AddObject(m, "Pjsip_Endpoint", (PyObject *)&PyTyp_pjsip_endpoint);
Benny Prijono572d4852006-11-23 21:50:02 +00005738
Benny Prijono1f63cc42007-09-10 16:54:22 +00005739 Py_INCREF(&PyTyp_pjmedia_endpt);
5740 PyModule_AddObject(m, "Pjmedia_Endpt", (PyObject *)&PyTyp_pjmedia_endpt);
Benny Prijono572d4852006-11-23 21:50:02 +00005741
Benny Prijono1f63cc42007-09-10 16:54:22 +00005742 Py_INCREF(&PyTyp_pj_pool_factory);
Benny Prijono572d4852006-11-23 21:50:02 +00005743 PyModule_AddObject(
Benny Prijono1f63cc42007-09-10 16:54:22 +00005744 m, "Pj_Pool_Factory", (PyObject *)&PyTyp_pj_pool_factory
Benny Prijono572d4852006-11-23 21:50:02 +00005745 );
5746
Benny Prijono1f63cc42007-09-10 16:54:22 +00005747 Py_INCREF(&PyTyp_pjsip_cred_info);
5748 PyModule_AddObject(m, "Pjsip_Cred_Info",
5749 (PyObject *)&PyTyp_pjsip_cred_info
Benny Prijono572d4852006-11-23 21:50:02 +00005750 );
5751
Benny Prijonodc308702006-12-09 00:39:42 +00005752 /* LIB TRANSPORT */
Benny Prijono98793592006-12-04 08:33:20 +00005753
Benny Prijono1f63cc42007-09-10 16:54:22 +00005754 Py_INCREF(&PyTyp_pjsua_transport_config);
Benny Prijono98793592006-12-04 08:33:20 +00005755 PyModule_AddObject
Benny Prijono1f63cc42007-09-10 16:54:22 +00005756 (m, "Transport_Config", (PyObject *)&PyTyp_pjsua_transport_config);
Benny Prijonodc308702006-12-09 00:39:42 +00005757
Benny Prijono1f63cc42007-09-10 16:54:22 +00005758 Py_INCREF(&PyTyp_pjsua_transport_info);
5759 PyModule_AddObject(m, "Transport_Info", (PyObject *)&PyTyp_pjsua_transport_info);
Benny Prijonodc308702006-12-09 00:39:42 +00005760
Benny Prijono98793592006-12-04 08:33:20 +00005761
Benny Prijonodc308702006-12-09 00:39:42 +00005762 /* END OF LIB TRANSPORT */
Benny Prijono98793592006-12-04 08:33:20 +00005763
Benny Prijonodc308702006-12-09 00:39:42 +00005764 /* LIB ACCOUNT */
Benny Prijono98793592006-12-04 08:33:20 +00005765
Benny Prijonodc308702006-12-09 00:39:42 +00005766
Benny Prijono1f63cc42007-09-10 16:54:22 +00005767 Py_INCREF(&PyTyp_pjsua_acc_config);
5768 PyModule_AddObject(m, "Acc_Config", (PyObject *)&PyTyp_pjsua_acc_config);
5769 Py_INCREF(&PyTyp_pjsua_acc_info);
5770 PyModule_AddObject(m, "Acc_Info", (PyObject *)&PyTyp_pjsua_acc_info);
Benny Prijono98793592006-12-04 08:33:20 +00005771
Benny Prijonodc308702006-12-09 00:39:42 +00005772 /* END OF LIB ACCOUNT */
5773
5774 /* LIB BUDDY */
5775
Benny Prijono1f63cc42007-09-10 16:54:22 +00005776 Py_INCREF(&PyTyp_pjsua_buddy_config);
5777 PyModule_AddObject(m, "Buddy_Config", (PyObject *)&PyTyp_pjsua_buddy_config);
5778 Py_INCREF(&PyTyp_pjsua_buddy_info);
5779 PyModule_AddObject(m, "Buddy_Info", (PyObject *)&PyTyp_pjsua_buddy_info);
Benny Prijonodc308702006-12-09 00:39:42 +00005780
5781 /* END OF LIB BUDDY */
5782
Fahrisdcf8fa42006-12-28 03:13:48 +00005783 /* LIB MEDIA */
5784
Benny Prijono1f63cc42007-09-10 16:54:22 +00005785 Py_INCREF(&PyTyp_pjsua_codec_info);
5786 PyModule_AddObject(m, "Codec_Info", (PyObject *)&PyTyp_pjsua_codec_info);
5787 Py_INCREF(&PyTyp_pjsua_conf_port_info);
5788 PyModule_AddObject(m, "Conf_Port_Info", (PyObject *)&PyTyp_pjsua_conf_port_info);
5789 Py_INCREF(&PyTyp_pjmedia_port);
5790 PyModule_AddObject(m, "PJMedia_Port", (PyObject *)&PyTyp_pjmedia_port);
5791 Py_INCREF(&PyTyp_pjmedia_snd_dev_info);
Fahrisdcf8fa42006-12-28 03:13:48 +00005792 PyModule_AddObject(m, "PJMedia_Snd_Dev_Info",
Benny Prijono1f63cc42007-09-10 16:54:22 +00005793 (PyObject *)&PyTyp_pjmedia_snd_dev_info);
5794 Py_INCREF(&PyTyp_pjmedia_codec_param_info);
Fahrisdcf8fa42006-12-28 03:13:48 +00005795 PyModule_AddObject(m, "PJMedia_Codec_Param_Info",
Benny Prijono1f63cc42007-09-10 16:54:22 +00005796 (PyObject *)&PyTyp_pjmedia_codec_param_info);
5797 Py_INCREF(&PyTyp_pjmedia_codec_param_setting);
Fahrisdcf8fa42006-12-28 03:13:48 +00005798 PyModule_AddObject(m, "PJMedia_Codec_Param_Setting",
Benny Prijono1f63cc42007-09-10 16:54:22 +00005799 (PyObject *)&PyTyp_pjmedia_codec_param_setting);
5800 Py_INCREF(&PyTyp_pjmedia_codec_param);
Fahrisdcf8fa42006-12-28 03:13:48 +00005801 PyModule_AddObject(m, "PJMedia_Codec_Param",
Benny Prijono1f63cc42007-09-10 16:54:22 +00005802 (PyObject *)&PyTyp_pjmedia_codec_param);
Fahrisdcf8fa42006-12-28 03:13:48 +00005803
5804 /* END OF LIB MEDIA */
5805
5806 /* LIB CALL */
5807
Benny Prijono1f63cc42007-09-10 16:54:22 +00005808 Py_INCREF(&PyTyp_pj_time_val);
5809 PyModule_AddObject(m, "PJ_Time_Val", (PyObject *)&PyTyp_pj_time_val);
Fahrisdcf8fa42006-12-28 03:13:48 +00005810
Benny Prijono1f63cc42007-09-10 16:54:22 +00005811 Py_INCREF(&PyTyp_pjsua_call_info);
5812 PyModule_AddObject(m, "Call_Info", (PyObject *)&PyTyp_pjsua_call_info);
Fahrisdcf8fa42006-12-28 03:13:48 +00005813
5814 /* END OF LIB CALL */
Benny Prijono572d4852006-11-23 21:50:02 +00005815
Benny Prijonodc308702006-12-09 00:39:42 +00005816
Fahrisdcf8fa42006-12-28 03:13:48 +00005817 /*
Benny Prijonoaa286042007-02-03 17:23:22 +00005818 * Add various constants.
Fahrisdcf8fa42006-12-28 03:13:48 +00005819 */
Benny Prijonodc308702006-12-09 00:39:42 +00005820
Benny Prijonoaa286042007-02-03 17:23:22 +00005821 /* Call states */
5822 ADD_CONSTANT(m, PJSIP_INV_STATE_NULL);
5823 ADD_CONSTANT(m, PJSIP_INV_STATE_CALLING);
5824 ADD_CONSTANT(m, PJSIP_INV_STATE_INCOMING);
5825 ADD_CONSTANT(m, PJSIP_INV_STATE_EARLY);
5826 ADD_CONSTANT(m, PJSIP_INV_STATE_CONNECTING);
5827 ADD_CONSTANT(m, PJSIP_INV_STATE_CONFIRMED);
5828 ADD_CONSTANT(m, PJSIP_INV_STATE_DISCONNECTED);
Fahrisdcf8fa42006-12-28 03:13:48 +00005829
Benny Prijonoaa286042007-02-03 17:23:22 +00005830 /* Call media status (enum pjsua_call_media_status) */
5831 ADD_CONSTANT(m, PJSUA_CALL_MEDIA_NONE);
5832 ADD_CONSTANT(m, PJSUA_CALL_MEDIA_ACTIVE);
5833 ADD_CONSTANT(m, PJSUA_CALL_MEDIA_LOCAL_HOLD);
5834 ADD_CONSTANT(m, PJSUA_CALL_MEDIA_REMOTE_HOLD);
Fahrisdcf8fa42006-12-28 03:13:48 +00005835
Benny Prijonoaa286042007-02-03 17:23:22 +00005836 /* Buddy status */
5837 ADD_CONSTANT(m, PJSUA_BUDDY_STATUS_UNKNOWN);
5838 ADD_CONSTANT(m, PJSUA_BUDDY_STATUS_ONLINE);
5839 ADD_CONSTANT(m, PJSUA_BUDDY_STATUS_OFFLINE);
Fahrisdcf8fa42006-12-28 03:13:48 +00005840
Benny Prijonoaa286042007-02-03 17:23:22 +00005841 /* PJSIP transport types (enum pjsip_transport_type_e) */
5842 ADD_CONSTANT(m, PJSIP_TRANSPORT_UNSPECIFIED);
5843 ADD_CONSTANT(m, PJSIP_TRANSPORT_UDP);
5844 ADD_CONSTANT(m, PJSIP_TRANSPORT_TCP);
5845 ADD_CONSTANT(m, PJSIP_TRANSPORT_TLS);
5846 ADD_CONSTANT(m, PJSIP_TRANSPORT_SCTP);
5847 ADD_CONSTANT(m, PJSIP_TRANSPORT_LOOP);
5848 ADD_CONSTANT(m, PJSIP_TRANSPORT_LOOP_DGRAM);
Fahrisdcf8fa42006-12-28 03:13:48 +00005849
Fahrisdcf8fa42006-12-28 03:13:48 +00005850
Benny Prijonoaa286042007-02-03 17:23:22 +00005851 /* Invalid IDs */
5852 ADD_CONSTANT(m, PJSUA_INVALID_ID);
Fahrisdcf8fa42006-12-28 03:13:48 +00005853
Fahrisdcf8fa42006-12-28 03:13:48 +00005854
Benny Prijonoaa286042007-02-03 17:23:22 +00005855 /* Various compile time constants */
5856 ADD_CONSTANT(m, PJSUA_ACC_MAX_PROXIES);
5857 ADD_CONSTANT(m, PJSUA_MAX_ACC);
5858 ADD_CONSTANT(m, PJSUA_REG_INTERVAL);
5859 ADD_CONSTANT(m, PJSUA_PUBLISH_EXPIRATION);
5860 ADD_CONSTANT(m, PJSUA_DEFAULT_ACC_PRIORITY);
5861 ADD_CONSTANT(m, PJSUA_MAX_BUDDIES);
5862 ADD_CONSTANT(m, PJSUA_MAX_CONF_PORTS);
5863 ADD_CONSTANT(m, PJSUA_DEFAULT_CLOCK_RATE);
5864 ADD_CONSTANT(m, PJSUA_DEFAULT_CODEC_QUALITY);
5865 ADD_CONSTANT(m, PJSUA_DEFAULT_ILBC_MODE);
5866 ADD_CONSTANT(m, PJSUA_DEFAULT_EC_TAIL_LEN);
5867 ADD_CONSTANT(m, PJSUA_MAX_CALLS);
5868 ADD_CONSTANT(m, PJSUA_XFER_NO_REQUIRE_REPLACES);
Fahrisdcf8fa42006-12-28 03:13:48 +00005869
Fahrisdcf8fa42006-12-28 03:13:48 +00005870
Benny Prijonoaa286042007-02-03 17:23:22 +00005871#undef ADD_CONSTANT
Benny Prijono8b8b9972006-11-16 11:18:03 +00005872}