Changeset 2163
- Timestamp:
- Jul 21, 2008 6:20:57 PM (16 years ago)
- Location:
- pjproject/trunk/pjsip-apps/src/python
- Files:
-
- 1 deleted
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip-apps/src/python/_pjsua.c
r2158 r2163 20 20 21 21 #define THIS_FILE "main.c" 22 #define POOL_SIZE 400022 #define POOL_SIZE 512 23 23 #define SND_DEV_NUM 64 24 24 #define SND_NAME_LEN 64 … … 26 26 /* LIB BASE */ 27 27 28 static PyObject* obj_log_cb; 29 static long thread_id; 30 31 #define ENTER_PYTHON() PyGILState_STATE state = PyGILState_Ensure() 32 #define LEAVE_PYTHON() PyGILState_Release(state) 28 static PyObject* g_obj_log_cb; 29 static long g_thread_id; 30 static struct py_thread_desc 31 { 32 struct py_thread_desc *next; 33 pj_thread_desc desc; 34 } *py_thread_desc; 35 36 /* 37 * The global callback object. 38 */ 39 static PyObj_pjsua_callback * g_obj_callback; 40 41 /* Set this to 1 if all threads are created by Python */ 42 #define NO_PJSIP_THREAD 1 43 44 #if NO_PJSIP_THREAD 45 # define ENTER_PYTHON() 46 # define LEAVE_PYTHON() 47 #else 48 # define ENTER_PYTHON() PyGILState_STATE state = PyGILState_Ensure() 49 # define LEAVE_PYTHON() PyGILState_Release(state) 50 #endif 51 52 53 static void clear_py_thread_desc(void) 54 { 55 while (py_thread_desc) { 56 struct py_thread_desc *next = py_thread_desc->next; 57 free(py_thread_desc); 58 py_thread_desc = next; 59 } 60 } 61 33 62 34 63 /* … … 42 71 * or otherwise it will crash Python. 43 72 */ 44 if (pj_thread_local_get( thread_id) == 0)73 if (pj_thread_local_get(g_thread_id) == 0) 45 74 return; 46 75 47 if (PyCallable_Check(obj_log_cb)) 48 { 76 if (PyCallable_Check(g_obj_log_cb)) { 77 PyObject *param_data; 78 49 79 ENTER_PYTHON(); 50 80 51 PyObject_CallFunctionObjArgs( 52 obj_log_cb, Py_BuildValue("i",level), 53 PyString_FromString(data), Py_BuildValue("i",len), NULL 81 param_data = PyString_FromStringAndSize(data, len); 82 83 PyObject_CallFunction( 84 g_obj_log_cb, 85 "iOi", 86 level, 87 param_data, 88 len, 89 NULL 54 90 ); 55 91 92 Py_DECREF(param_data); 93 56 94 LEAVE_PYTHON(); 57 95 } 58 96 } 59 60 61 62 /*63 * The global callback object.64 */65 static PyObj_pjsua_callback * g_obj_callback;66 67 97 68 98 /* … … 72 102 static void cb_on_call_state(pjsua_call_id call_id, pjsip_event *e) 73 103 { 74 if (PyCallable_Check(g_obj_callback->on_call_state)) 75 { 76 PyObj_pjsip_event * obj; 104 PJ_UNUSED_ARG(e); 105 106 if (PyCallable_Check(g_obj_callback->on_call_state)) { 107 PyObject * obj; 77 108 78 109 ENTER_PYTHON(); 79 110 80 obj = (PyObj_pjsip_event *)PyType_GenericNew(&PyTyp_pjsip_event, 81 NULL, NULL); 111 obj = Py_BuildValue(""); 82 112 83 obj->event = e; 84 85 PyObject_CallFunctionObjArgs( 113 PyObject_CallFunction( 86 114 g_obj_callback->on_call_state, 87 Py_BuildValue("i",call_id), 115 "iO", 116 call_id, 88 117 obj, 89 118 NULL 90 119 ); 91 120 121 Py_DECREF(obj); 122 92 123 LEAVE_PYTHON(); 93 124 } … … 102 133 pjsip_rx_data *rdata) 103 134 { 104 if (PyCallable_Check(g_obj_callback->on_incoming_call)) 105 { 106 PyObj_pjsip_rx_data * obj; 135 PJ_UNUSED_ARG(rdata); 136 137 if (PyCallable_Check(g_obj_callback->on_incoming_call)) { 138 PyObject *obj; 107 139 108 140 ENTER_PYTHON(); 109 141 110 obj = (PyObj_pjsip_rx_data *)PyType_GenericNew(&PyTyp_pjsip_rx_data, 111 NULL, NULL); 112 obj->rdata = rdata; 113 114 PyObject_CallFunctionObjArgs( 142 obj = Py_BuildValue(""); 143 144 PyObject_CallFunction( 115 145 g_obj_callback->on_incoming_call, 116 Py_BuildValue("i",acc_id), 117 Py_BuildValue("i",call_id), 146 "iiO", 147 acc_id, 148 call_id, 118 149 obj, 119 150 NULL 120 151 ); 121 152 153 Py_DECREF(obj); 154 122 155 LEAVE_PYTHON(); 123 156 } … … 131 164 static void cb_on_call_media_state(pjsua_call_id call_id) 132 165 { 133 if (PyCallable_Check(g_obj_callback->on_call_media_state)) 134 { 166 if (PyCallable_Check(g_obj_callback->on_call_media_state)) { 167 135 168 ENTER_PYTHON(); 136 169 … … 153 186 static void cb_on_dtmf_digit(pjsua_call_id call_id, int digit) 154 187 { 155 if (PyCallable_Check(g_obj_callback->on_dtmf_digit)) 156 { 188 if (PyCallable_Check(g_obj_callback->on_dtmf_digit)) { 157 189 char digit_str[10]; 158 190 … … 161 193 pj_ansi_snprintf(digit_str, sizeof(digit_str), "%c", digit); 162 194 163 PyObject_CallFunction ObjArgs(195 PyObject_CallFunction( 164 196 g_obj_callback->on_dtmf_digit, 165 Py_BuildValue("i",call_id), 166 PyString_FromString(digit_str), 197 "is", 198 call_id, 199 digit_str, 167 200 NULL 168 201 ); … … 181 214 pjsip_status_code *code) 182 215 { 183 if (PyCallable_Check(g_obj_callback->on_call_transfer_request)) 184 { 185 PyObject * ret; 216 if (PyCallable_Check(g_obj_callback->on_call_transfer_request)) { 217 PyObject *ret, *param_dst; 186 218 int cd; 187 219 188 220 ENTER_PYTHON(); 189 221 190 ret = PyObject_CallFunctionObjArgs( 191 g_obj_callback->on_call_transfer_request, 192 Py_BuildValue("i",call_id), 193 PyString_FromStringAndSize(dst->ptr, dst->slen), 194 Py_BuildValue("i",*code), 195 NULL 196 ); 222 param_dst = PyString_FromPJ(dst); 223 224 ret = PyObject_CallFunction( 225 g_obj_callback->on_call_transfer_request, 226 "iOi", 227 call_id, 228 param_dst, 229 *code, 230 NULL 231 ); 232 233 Py_DECREF(param_dst); 234 197 235 if (ret != NULL) { 198 236 if (ret != Py_None) { … … 201 239 } 202 240 } 241 Py_DECREF(ret); 203 242 } 204 243 … … 221 260 pj_bool_t *p_cont) 222 261 { 223 if (PyCallable_Check(g_obj_callback->on_call_transfer_status)) 224 { 225 PyObject * ret; 226 int cnt; 262 if (PyCallable_Check(g_obj_callback->on_call_transfer_status)) { 263 PyObject *ret, *param_reason; 227 264 228 265 ENTER_PYTHON(); 229 266 230 ret = PyObject_CallFunctionObjArgs( 231 g_obj_callback->on_call_transfer_status, 232 Py_BuildValue("i",call_id), 233 Py_BuildValue("i",status_code), 234 PyString_FromStringAndSize(status_text->ptr, status_text->slen), 235 Py_BuildValue("i",final), 236 Py_BuildValue("i",*p_cont), 237 NULL 238 ); 267 param_reason = PyString_FromPJ(status_text); 268 269 ret = PyObject_CallFunction( 270 g_obj_callback->on_call_transfer_status, 271 "iiOii", 272 call_id, 273 status_code, 274 param_reason, 275 final, 276 *p_cont, 277 NULL 278 ); 279 280 Py_DECREF(param_reason); 281 239 282 if (ret != NULL) { 240 283 if (ret != Py_None) { 284 int cnt; 241 285 if (PyArg_Parse(ret,"i",&cnt)) { 242 286 *p_cont = cnt; 243 287 } 244 288 } 289 Py_DECREF(ret); 245 290 } 246 291 … … 260 305 pj_str_t *st_text) 261 306 { 262 if (PyCallable_Check(g_obj_callback->on_call_replace_request))263 { 264 PyObject * ret; 265 PyObject * txt;307 PJ_UNUSED_ARG(rdata); 308 309 if (PyCallable_Check(g_obj_callback->on_call_replace_request)) { 310 PyObject *ret, *param_reason, *param_rdata; 266 311 int cd; 267 PyObj_pjsip_rx_data * obj;268 312 269 313 ENTER_PYTHON(); 270 314 271 obj = (PyObj_pjsip_rx_data *)PyType_GenericNew(&PyTyp_pjsip_rx_data, 272 NULL, NULL); 273 obj->rdata = rdata; 274 275 ret = PyObject_CallFunctionObjArgs( 276 g_obj_callback->on_call_replace_request, 277 Py_BuildValue("i",call_id), 278 obj, 279 Py_BuildValue("i",*st_code), 280 PyString_FromStringAndSize(st_text->ptr, st_text->slen), 281 NULL 282 ); 315 param_reason = PyString_FromPJ(st_text); 316 param_rdata = Py_BuildValue(""); 317 318 ret = PyObject_CallFunction( 319 g_obj_callback->on_call_replace_request, 320 "iOiO", 321 call_id, 322 param_rdata, 323 *st_code, 324 param_reason, 325 NULL 326 ); 327 328 Py_DECREF(param_rdata); 329 Py_DECREF(param_reason); 330 283 331 if (ret != NULL) { 284 332 if (ret != Py_None) { 333 PyObject * txt; 285 334 if (PyArg_ParseTuple(ret,"iO",&cd, &txt)) { 286 335 *st_code = cd; 287 st_text->ptr = PyString_AsString(txt); 288 st_text->slen = strlen(PyString_AsString(txt)); 336 *st_text = PyString_ToPJ(txt); 289 337 } 290 338 } 339 Py_DECREF(ret); 291 340 } 292 341 … … 304 353 pjsua_call_id new_call_id) 305 354 { 306 if (PyCallable_Check(g_obj_callback->on_call_replaced)) 307 { 355 if (PyCallable_Check(g_obj_callback->on_call_replaced)) { 308 356 ENTER_PYTHON(); 309 357 310 PyObject_CallFunction ObjArgs(358 PyObject_CallFunction( 311 359 g_obj_callback->on_call_replaced, 312 Py_BuildValue("i",old_call_id), 313 Py_BuildValue("i",new_call_id), 360 "ii", 361 old_call_id, 362 new_call_id, 314 363 NULL 315 364 ); … … 326 375 static void cb_on_reg_state(pjsua_acc_id acc_id) 327 376 { 328 if (PyCallable_Check(g_obj_callback->on_reg_state)) 329 { 377 if (PyCallable_Check(g_obj_callback->on_reg_state)) { 330 378 ENTER_PYTHON(); 331 379 … … 358 406 PJ_UNUSED_ARG(msg_data); 359 407 360 if (PyCallable_Check(g_obj_callback->on_incoming_subscribe)) 361 { 362 PyObject *ret; 408 if (PyCallable_Check(g_obj_callback->on_incoming_subscribe)) { 409 PyObject *ret, *param_from, *param_contact, *param_srv_pres; 410 pjsip_contact_hdr *contact_hdr; 411 pj_pool_t *pool = NULL; 363 412 364 413 ENTER_PYTHON(); 365 414 366 ret = PyObject_CallFunctionObjArgs( 367 g_obj_callback->on_incoming_subscribe, 368 Py_BuildValue("i", acc_id), 369 Py_BuildValue("i", buddy_id), 370 PyString_FromStringAndSize(from->ptr, from->slen), 371 PyLong_FromLong((long)srv_pres), 372 NULL 373 ); 415 param_from = PyString_FromPJ(from); 416 param_srv_pres = PyLong_FromLong((long)srv_pres); 417 418 contact_hdr = (pjsip_contact_hdr*) 419 pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_CONTACT, 420 NULL); 421 if (contact_hdr) { 422 char *contact; 423 int len; 424 425 pool = pjsua_pool_create("pytmp", 512, 512); 426 contact = (char*) pj_pool_alloc(pool, PJSIP_MAX_URL_SIZE+1); 427 len = pjsip_uri_print(PJSIP_URI_IN_CONTACT_HDR, contact_hdr->uri, 428 contact, PJSIP_MAX_URL_SIZE); 429 if (len < 1) 430 len = 0; 431 contact[len] = '\0'; 432 433 param_contact = PyString_FromStringAndSize(contact, len); 434 } else { 435 param_contact = Py_BuildValue(""); 436 } 437 438 ret = PyObject_CallFunction( 439 g_obj_callback->on_incoming_subscribe, 440 "iiOOO", 441 acc_id, 442 buddy_id, 443 param_from, 444 param_contact, 445 param_srv_pres, 446 NULL 447 ); 448 449 if (pool) 450 pj_pool_release(pool); 451 452 Py_DECREF(param_from); 453 Py_DECREF(param_contact); 454 Py_DECREF(param_srv_pres); 374 455 375 456 if (ret && PyTuple_Check(ret)) { … … 379 460 if (PyTuple_GetItem(ret, 1) != Py_None) { 380 461 pj_str_t tmp; 381 tmp = PyString_ to_pj_str(PyTuple_GetItem(ret, 1));462 tmp = PyString_ToPJ(PyTuple_GetItem(ret, 1)); 382 463 reason->ptr = reason_buf; 383 464 pj_strncpy(reason, &tmp, sizeof(reason_buf)); 384 465 } else { 466 reason->slen = 0; 385 467 } 386 468 } 387 469 Py_XDECREF(ret); 388 470 } else if (ret) { 389 471 Py_XDECREF(ret); … … 400 482 static void cb_on_buddy_state(pjsua_buddy_id buddy_id) 401 483 { 402 if (PyCallable_Check(g_obj_callback->on_buddy_state)) 403 { 484 if (PyCallable_Check(g_obj_callback->on_buddy_state)) { 404 485 ENTER_PYTHON(); 405 486 … … 426 507 PJ_UNUSED_ARG(rdata); 427 508 428 if (PyCallable_Check(g_obj_callback->on_pager)) 429 { 509 if (PyCallable_Check(g_obj_callback->on_pager)) { 510 PyObject *param_from, *param_to, *param_contact, *param_mime_type, 511 *param_body; 512 430 513 ENTER_PYTHON(); 431 514 432 PyObject_CallFunctionObjArgs( 433 g_obj_callback->on_pager, 434 Py_BuildValue("i",call_id), 435 PyString_FromStringAndSize(from->ptr, from->slen), 436 PyString_FromStringAndSize(to->ptr, to->slen), 437 PyString_FromStringAndSize(contact->ptr, contact->slen), 438 PyString_FromStringAndSize(mime_type->ptr, mime_type->slen), 439 PyString_FromStringAndSize(body->ptr, body->slen), 440 Py_BuildValue("i",acc_id), 441 NULL 442 ); 515 param_from = PyString_FromPJ(from); 516 param_to = PyString_FromPJ(to); 517 param_contact = PyString_FromPJ(contact); 518 param_mime_type = PyString_FromPJ(mime_type); 519 param_body = PyString_FromPJ(body); 520 521 PyObject_CallFunction( 522 g_obj_callback->on_pager, 523 "iOOOOOi", 524 call_id, 525 param_from, 526 param_to, 527 param_contact, 528 param_mime_type, 529 param_body, 530 acc_id, 531 NULL 532 ); 533 534 Py_DECREF(param_body); 535 Py_DECREF(param_mime_type); 536 Py_DECREF(param_contact); 537 Py_DECREF(param_to); 538 Py_DECREF(param_from); 443 539 444 540 LEAVE_PYTHON(); … … 459 555 pjsua_acc_id acc_id) 460 556 { 461 if (PyCallable_Check(g_obj_callback->on_pager)) 462 { 463 PyObject * obj_user_data; 557 if (PyCallable_Check(g_obj_callback->on_pager)) { 558 PyObject *param_call_id, *param_to, *param_body, 559 *param_user_data, *param_status, *param_reason, 560 *param_acc_id; 464 561 465 562 ENTER_PYTHON(); … … 468 565 PJ_UNUSED_ARG(rdata); 469 566 470 obj_user_data = Py_BuildValue("i", user_data);471 472 567 PyObject_CallFunctionObjArgs( 473 g_obj_callback->on_pager_status, 474 Py_BuildValue("i",call_id), 475 PyString_FromStringAndSize(to->ptr, to->slen), 476 PyString_FromStringAndSize(body->ptr, body->slen), 477 obj_user_data, 478 Py_BuildValue("i",status), 479 PyString_FromStringAndSize(reason->ptr,reason->slen), 480 Py_BuildValue("i",acc_id), 481 NULL 482 ); 568 g_obj_callback->on_pager_status, 569 param_call_id = Py_BuildValue("i",call_id), 570 param_to = PyString_FromPJ(to), 571 param_body = PyString_FromPJ(body), 572 param_user_data = Py_BuildValue("i", user_data), 573 param_status = Py_BuildValue("i",status), 574 param_reason = PyString_FromPJ(reason), 575 param_acc_id = Py_BuildValue("i",acc_id), 576 NULL 577 ); 578 579 Py_DECREF(param_call_id); 580 Py_DECREF(param_to); 581 Py_DECREF(param_body); 582 Py_DECREF(param_user_data); 583 Py_DECREF(param_status); 584 Py_DECREF(param_reason); 585 Py_DECREF(param_acc_id); 483 586 484 587 LEAVE_PYTHON(); … … 496 599 pjsua_acc_id acc_id) 497 600 { 498 if (PyCallable_Check(g_obj_callback->on_typing)) 499 { 601 if (PyCallable_Check(g_obj_callback->on_typing)) { 602 PyObject *param_call_id, *param_from, *param_to, *param_contact, 603 *param_is_typing, *param_acc_id; 604 500 605 ENTER_PYTHON(); 501 606 … … 503 608 504 609 PyObject_CallFunctionObjArgs( 505 g_obj_callback->on_typing,Py_BuildValue("i",call_id), 506 PyString_FromStringAndSize(from->ptr, from->slen), 507 PyString_FromStringAndSize(to->ptr, to->slen), 508 PyString_FromStringAndSize(contact->ptr, contact->slen), 509 Py_BuildValue("i",is_typing), 510 Py_BuildValue("i",acc_id), 511 NULL 512 ); 610 g_obj_callback->on_typing, 611 param_call_id = Py_BuildValue("i",call_id), 612 param_from = PyString_FromPJ(from), 613 param_to = PyString_FromPJ(to), 614 param_contact = PyString_FromPJ(contact), 615 param_is_typing = Py_BuildValue("i",is_typing), 616 param_acc_id = Py_BuildValue("i",acc_id), 617 NULL 618 ); 619 620 Py_DECREF(param_call_id); 621 Py_DECREF(param_from); 622 Py_DECREF(param_to); 623 Py_DECREF(param_contact); 624 Py_DECREF(param_is_typing); 625 Py_DECREF(param_acc_id); 513 626 514 627 LEAVE_PYTHON(); … … 530 643 int i; 531 644 532 for (i = 0; i < PyList_Size(py_hdr_list); i++) 533 { 645 for (i=0; i<PyList_Size(py_hdr_list); ++i) { 534 646 pj_str_t hname, hvalue; 535 647 pjsip_generic_string_hdr * new_hdr; 536 648 PyObject * tuple = PyList_GetItem(py_hdr_list, i); 537 649 538 if (PyTuple_Check(tuple)) 539 { 540 hname.ptr = PyString_AsString(PyTuple_GetItem(tuple,0)); 541 hname.slen = strlen(PyString_AsString 542 (PyTuple_GetItem(tuple,0))); 543 hvalue.ptr = PyString_AsString(PyTuple_GetItem(tuple,1)); 544 hvalue.slen = strlen(PyString_AsString 545 (PyTuple_GetItem(tuple,1))); 650 if (PyTuple_Check(tuple)) { 651 if (PyTuple_Size(tuple) >= 1) 652 hname = PyString_ToPJ(PyTuple_GetItem(tuple,0)); 653 else 654 hname.slen = 0; 655 if (PyTuple_Size(tuple) >= 2) 656 hvalue = PyString_ToPJ(PyTuple_GetItem(tuple,1)); 657 else 658 hvalue.slen = 0; 546 659 } else { 547 660 hname.ptr = ""; … … 556 669 } 557 670 558 /*559 * translate_hdr_rev560 * internal function561 * translate from pjsip_generic_string_hdr to hdr_list562 */563 564 void translate_hdr_rev(pjsip_generic_string_hdr *hdr, PyObject *py_hdr_list)565 {566 int i;567 int len;568 pjsip_generic_string_hdr * p_hdr;569 570 len = pj_list_size(hdr);571 572 if (len > 0)573 {574 p_hdr = hdr;575 Py_XDECREF(py_hdr_list);576 py_hdr_list = PyList_New(len);577 578 for (i = 0; i < len && p_hdr != NULL; i++)579 {580 PyObject * tuple;581 PyObject * str;582 583 tuple = PyTuple_New(2);584 585 str = PyString_FromStringAndSize(p_hdr->name.ptr, p_hdr->name.slen);586 PyTuple_SetItem(tuple, 0, str);587 str = PyString_FromStringAndSize588 (hdr->hvalue.ptr, p_hdr->hvalue.slen);589 PyTuple_SetItem(tuple, 1, str);590 PyList_SetItem(py_hdr_list, i, tuple);591 p_hdr = p_hdr->next;592 }593 }594 595 596 }597 598 671 /* 599 672 * py_pjsua_thread_register 600 * !added @ 061206601 673 */ 602 674 static PyObject *py_pjsua_thread_register(PyObject *pSelf, PyObject *pArgs) 603 675 { 604 605 676 pj_status_t status; 606 677 const char *name; 607 678 PyObject *py_desc; 608 679 pj_thread_t *thread; 609 void *thread_desc; 610 #if 0 611 int size; 612 int i; 613 int *td; 614 #endif 615 616 PJ_UNUSED_ARG(pSelf); 617 618 if (!PyArg_ParseTuple(pArgs, "sO", &name, &py_desc)) 619 { 680 struct py_thread_desc *thread_desc; 681 682 PJ_UNUSED_ARG(pSelf); 683 684 if (!PyArg_ParseTuple(pArgs, "sO", &name, &py_desc)) { 620 685 return NULL; 621 686 } 622 #if 0 623 size = PyList_Size(py_desc); 624 td = (int *)malloc(size * sizeof(int)); 625 for (i = 0; i < size; i++) 626 { 627 if (!PyArg_Parse(PyList_GetItem(py_desc,i),"i", td[i])) 628 { 629 return NULL; 630 } 631 } 632 thread_desc = td; 633 #else 634 thread_desc = malloc(sizeof(pj_thread_desc)); 635 #endif 636 status = pj_thread_register(name, thread_desc, &thread); 687 thread_desc = (struct py_thread_desc*) 688 malloc(sizeof(struct py_thread_desc)); 689 thread_desc->next = py_thread_desc; 690 py_thread_desc = thread_desc; 691 692 status = pj_thread_register(name, thread_desc->desc, &thread); 637 693 638 694 if (status == PJ_SUCCESS) 639 status = pj_thread_local_set(thread_id, (void*)1); 695 status = pj_thread_local_set(g_thread_id, (void*)1); 696 640 697 return Py_BuildValue("i",status); 641 698 } … … 643 700 /* 644 701 * py_pjsua_logging_config_default 645 * !modified @ 051206646 702 */ 647 703 static PyObject *py_pjsua_logging_config_default(PyObject *pSelf, 648 704 PyObject *pArgs) 649 705 { 650 706 PyObj_pjsua_logging_config *obj; … … 652 708 653 709 PJ_UNUSED_ARG(pSelf); 654 655 if (!PyArg_ParseTuple(pArgs, "")) 656 { 657 return NULL; 658 } 659 710 PJ_UNUSED_ARG(pArgs); 711 660 712 pjsua_logging_config_default(&cfg); 661 obj = (PyObj_pjsua_logging_config *) PyObj_pjsua_logging_config_new 662 (&PyTyp_pjsua_logging_config,NULL,NULL); 713 obj = (PyObj_pjsua_logging_config*) 714 PyObj_pjsua_logging_config_new(&PyTyp_pjsua_logging_config, 715 NULL, NULL); 663 716 PyObj_pjsua_logging_config_import(obj, &cfg); 664 717 665 return (PyObject 718 return (PyObject*)obj; 666 719 } 667 720 … … 669 722 /* 670 723 * py_pjsua_config_default 671 * !modified @ 051206672 724 */ 673 725 static PyObject *py_pjsua_config_default(PyObject *pSelf, PyObject *pArgs) … … 677 729 678 730 PJ_UNUSED_ARG(pSelf); 679 680 if (!PyArg_ParseTuple(pArgs, "")) 681 { 682 return NULL; 683 } 731 PJ_UNUSED_ARG(pArgs); 732 684 733 pjsua_config_default(&cfg); 685 obj = (PyObj_pjsua_config *) PyObj_pjsua_config_new(&PyTyp_pjsua_config, NULL, NULL); 734 obj = (PyObj_pjsua_config *) PyObj_pjsua_config_new(&PyTyp_pjsua_config, 735 NULL, NULL); 686 736 PyObj_pjsua_config_import(obj, &cfg); 687 737 688 return (PyObject 738 return (PyObject*)obj; 689 739 } 690 740 … … 692 742 /* 693 743 * py_pjsua_media_config_default 694 * !modified @ 051206695 744 */ 696 745 static PyObject * py_pjsua_media_config_default(PyObject *pSelf, … … 701 750 702 751 PJ_UNUSED_ARG(pSelf); 703 704 if (!PyArg_ParseTuple(pArgs, "")) 705 { 706 return NULL; 707 } 752 PJ_UNUSED_ARG(pArgs); 753 708 754 pjsua_media_config_default(&cfg); 709 755 obj = (PyObj_pjsua_media_config *) 710 756 PyType_GenericNew(&PyTyp_pjsua_media_config, NULL, NULL); 711 757 PyObj_pjsua_media_config_import(obj, &cfg); 758 712 759 return (PyObject *)obj; 713 760 } … … 716 763 /* 717 764 * py_pjsua_msg_data_init 718 * !modified @ 051206719 765 */ 720 766 static PyObject *py_pjsua_msg_data_init(PyObject *pSelf, PyObject *pArgs) 721 767 { 722 PyObj_pjsua_msg_data *obj; 723 pjsua_msg_data msg; 724 725 PJ_UNUSED_ARG(pSelf); 726 727 if (!PyArg_ParseTuple(pArgs, "")) 728 { 729 return NULL; 730 } 731 pjsua_msg_data_init(&msg); 732 obj = (PyObj_pjsua_msg_data *)PyObj_pjsua_msg_data_new(&PyTyp_pjsua_msg_data, NULL, NULL); 733 Py_XDECREF(obj->content_type); 734 obj->content_type = PyString_FromStringAndSize( 735 msg.content_type.ptr, msg.content_type.slen 736 ); 737 Py_XDECREF(obj->msg_body); 738 obj->msg_body = PyString_FromStringAndSize( 739 msg.msg_body.ptr, msg.msg_body.slen 740 ); 741 742 translate_hdr_rev((pjsip_generic_string_hdr *)&msg.hdr_list,obj->hdr_list); 743 744 return (PyObject *)obj; 768 PJ_UNUSED_ARG(pSelf); 769 PJ_UNUSED_ARG(pArgs); 770 771 return (PyObject *)PyObj_pjsua_msg_data_new(&PyTyp_pjsua_msg_data, 772 NULL, NULL); 745 773 } 746 774 … … 749 777 * py_pjsua_reconfigure_logging 750 778 */ 751 static PyObject *py_pjsua_reconfigure_logging(PyObject *pSelf, PyObject *pArgs) 752 { 753 PyObject * logObj; 754 PyObj_pjsua_logging_config *log; 755 pjsua_logging_config cfg; 779 static PyObject *py_pjsua_reconfigure_logging(PyObject *pSelf, 780 PyObject *pArgs) 781 { 782 PyObject *logObj; 756 783 pj_status_t status; 757 784 758 785 PJ_UNUSED_ARG(pSelf); 759 786 760 if (!PyArg_ParseTuple(pArgs, "O", &logObj)) 761 { 762 return NULL; 763 } 764 if (logObj != Py_None) 765 { 766 log = (PyObj_pjsua_logging_config *)logObj; 787 if (!PyArg_ParseTuple(pArgs, "O", &logObj)) { 788 return NULL; 789 } 790 791 if (logObj != Py_None) { 792 PyObj_pjsua_logging_config *log; 793 pjsua_logging_config cfg; 794 795 log = (PyObj_pjsua_logging_config*)logObj; 767 796 cfg.msg_logging = log->msg_logging; 768 797 cfg.level = log->level; 769 798 cfg.console_level = log->console_level; 770 799 cfg.decor = log->decor; 771 cfg.log_filename.ptr = PyString_AsString(log->log_filename); 772 cfg.log_filename.slen = strlen(cfg.log_filename.ptr); 773 Py_XDECREF(obj_log_cb); 774 obj_log_cb = log->cb; 775 Py_INCREF(obj_log_cb); 800 cfg.log_filename = PyString_ToPJ(log->log_filename); 801 Py_XDECREF(g_obj_log_cb); 802 g_obj_log_cb = log->cb; 803 Py_INCREF(g_obj_log_cb); 776 804 cfg.cb = &cb_log_cb; 777 805 status = pjsua_reconfigure_logging(&cfg); … … 779 807 status = pjsua_reconfigure_logging(NULL); 780 808 } 809 781 810 return Py_BuildValue("i",status); 782 }783 784 785 /*786 * py_pjsua_pool_create787 */788 static PyObject *py_pjsua_pool_create(PyObject *pSelf, PyObject *pArgs)789 {790 pj_size_t init_size;791 pj_size_t increment;792 const char * name;793 pj_pool_t *p;794 PyObj_pj_pool *pool;795 796 PJ_UNUSED_ARG(pSelf);797 798 if (!PyArg_ParseTuple(pArgs, "sII", &name, &init_size, &increment))799 {800 return NULL;801 }802 803 p = pjsua_pool_create(name, init_size, increment);804 pool = (PyObj_pj_pool *)PyType_GenericNew(&PyTyp_pj_pool_t, NULL, NULL);805 pool->pool = p;806 return (PyObject *)pool;807 808 }809 810 811 /*812 * py_pjsua_get_pjsip_endpt813 */814 static PyObject *py_pjsua_get_pjsip_endpt(PyObject *pSelf, PyObject *pArgs)815 {816 PyObj_pjsip_endpoint *endpt;817 pjsip_endpoint *e;818 819 PJ_UNUSED_ARG(pSelf);820 821 if (!PyArg_ParseTuple(pArgs, ""))822 {823 return NULL;824 }825 e = pjsua_get_pjsip_endpt();826 endpt = (PyObj_pjsip_endpoint *)PyType_GenericNew(827 &PyTyp_pjsip_endpoint, NULL, NULL828 );829 endpt->endpt = e;830 return (PyObject *)endpt;831 }832 833 834 /*835 * py_pjsua_get_pjmedia_endpt836 */837 static PyObject *py_pjsua_get_pjmedia_endpt(PyObject *pSelf, PyObject *pArgs)838 {839 PyObj_pjmedia_endpt *endpt;840 pjmedia_endpt *e;841 842 PJ_UNUSED_ARG(pSelf);843 844 if (!PyArg_ParseTuple(pArgs, ""))845 {846 return NULL;847 }848 e = pjsua_get_pjmedia_endpt();849 endpt = (PyObj_pjmedia_endpt *)PyType_GenericNew(850 &PyTyp_pjmedia_endpt, NULL, NULL851 );852 endpt->endpt = e;853 return (PyObject *)endpt;854 }855 856 857 /*858 * py_pjsua_get_pool_factory859 */860 static PyObject *py_pjsua_get_pool_factory(PyObject *pSelf, PyObject *pArgs)861 {862 PyObj_pj_pool_factory *pool;863 pj_pool_factory *p;864 865 PJ_UNUSED_ARG(pSelf);866 867 if (!PyArg_ParseTuple(pArgs, ""))868 {869 return NULL;870 }871 p = pjsua_get_pool_factory();872 pool = (PyObj_pj_pool_factory *)PyType_GenericNew(873 &PyTyp_pj_pool_factory, NULL, NULL874 );875 pool->pool_fact = p;876 return (PyObject *)pool;877 811 } 878 812 … … 889 823 PJ_UNUSED_ARG(pSelf); 890 824 891 if (!PyArg_ParseTuple(pArgs, "ssi", &sender, &title, &status)) 892 { 825 if (!PyArg_ParseTuple(pArgs, "ssi", &sender, &title, &status)) { 893 826 return NULL; 894 827 } 895 828 896 829 pjsua_perror(sender, title, status); 897 Py_INCREF(Py_None); 898 return Py_ None;830 831 return Py_BuildValue(""); 899 832 } 900 833 … … 908 841 909 842 PJ_UNUSED_ARG(pSelf); 910 911 if (!PyArg_ParseTuple(pArgs, "")) 912 { 913 return NULL; 914 } 843 PJ_UNUSED_ARG(pArgs); 844 915 845 status = pjsua_create(); 916 846 917 if (status == PJ_SUCCESS) 918 { 919 status = pj_thread_local_alloc(&thread_id); 847 if (status == PJ_SUCCESS) { 848 status = pj_thread_local_alloc(&g_thread_id); 920 849 if (status == PJ_SUCCESS) 921 status = pj_thread_local_set(thread_id, (void*)1); 850 status = pj_thread_local_set(g_thread_id, (void*)1); 851 852 pj_atexit(&clear_py_thread_desc); 922 853 } 923 854 … … 939 870 PJ_UNUSED_ARG(pSelf); 940 871 941 if (!PyArg_ParseTuple(pArgs, "OOO", &o_ua_cfg, &o_log_cfg, &o_media_cfg)) 942 { 872 if (!PyArg_ParseTuple(pArgs, "OOO", &o_ua_cfg, &o_log_cfg, &o_media_cfg)) { 943 873 return NULL; 944 874 } … … 948 878 pjsua_media_config_default(&cfg_media); 949 879 950 if (o_ua_cfg != Py_None) 951 { 880 if (o_ua_cfg != Py_None) { 952 881 PyObj_pjsua_config *obj_ua_cfg = (PyObj_pjsua_config*)o_ua_cfg; 953 882 954 883 PyObj_pjsua_config_export(&cfg_ua, obj_ua_cfg); 955 884 885 Py_XDECREF(g_obj_callback); 956 886 g_obj_callback = obj_ua_cfg->cb; 957 887 Py_INCREF(g_obj_callback); … … 978 908 } 979 909 980 if (o_log_cfg != Py_None) 981 { 910 if (o_log_cfg != Py_None) { 982 911 PyObj_pjsua_logging_config * obj_log; 983 912 … … 986 915 PyObj_pjsua_logging_config_export(&cfg_log, obj_log); 987 916 988 Py_XDECREF( obj_log_cb);989 obj_log_cb = obj_log->cb;990 Py_INCREF( obj_log_cb);917 Py_XDECREF(g_obj_log_cb); 918 g_obj_log_cb = obj_log->cb; 919 Py_INCREF(g_obj_log_cb); 991 920 992 921 cfg_log.cb = &cb_log_cb; … … 997 926 } 998 927 999 if (o_media_cfg != Py_None) 1000 { 928 if (o_media_cfg != Py_None) { 1001 929 PyObj_pjsua_media_config_export(&cfg_media, 1002 930 (PyObj_pjsua_media_config*)o_media_cfg); … … 1008 936 1009 937 status = pjsua_init(p_cfg_ua, p_cfg_log, p_cfg_media); 1010 return Py_BuildValue("i",status); 938 939 return Py_BuildValue("i", status); 1011 940 } 1012 941 … … 1020 949 1021 950 PJ_UNUSED_ARG(pSelf); 1022 1023 if (!PyArg_ParseTuple(pArgs, "")) 1024 { 1025 return NULL; 1026 } 951 PJ_UNUSED_ARG(pArgs); 952 1027 953 status = pjsua_start(); 1028 954 1029 return Py_BuildValue("i", status);955 return Py_BuildValue("i", status); 1030 956 } 1031 957 … … 1039 965 1040 966 PJ_UNUSED_ARG(pSelf); 1041 1042 if (!PyArg_ParseTuple(pArgs, "")) 1043 { 1044 return NULL; 1045 } 967 PJ_UNUSED_ARG(pArgs); 968 1046 969 status = pjsua_destroy(); 1047 970 1048 return Py_BuildValue("i", status);971 return Py_BuildValue("i", status); 1049 972 } 1050 973 … … 1056 979 { 1057 980 int ret; 1058 unsigned msec; 1059 1060 PJ_UNUSED_ARG(pSelf); 1061 1062 if (!PyArg_ParseTuple(pArgs, "i", &msec)) 1063 { 1064 return NULL; 1065 } 1066 981 int msec; 982 983 PJ_UNUSED_ARG(pSelf); 984 985 if (!PyArg_ParseTuple(pArgs, "i", &msec)) { 986 return NULL; 987 } 988 989 if (msec < 0) 990 msec = 0; 991 992 #if !NO_PJSIP_THREAD 1067 993 /* Since handle_events() will block, we must wrap it with ALLOW_THREADS 1068 994 * construct, or otherwise many Python blocking functions (such as … … 1071 997 */ 1072 998 Py_BEGIN_ALLOW_THREADS 999 #endif 1000 1073 1001 ret = pjsua_handle_events(msec); 1002 1003 #if !NO_PJSIP_THREAD 1074 1004 Py_END_ALLOW_THREADS 1075 1076 return Py_BuildValue("i",ret); 1005 #endif 1006 1007 return Py_BuildValue("i", ret); 1077 1008 } 1078 1009 … … 1088 1019 PJ_UNUSED_ARG(pSelf); 1089 1020 1090 if (!PyArg_ParseTuple(pArgs, "s", &url)) 1091 {1092 return NULL;1093 } 1021 if (!PyArg_ParseTuple(pArgs, "s", &url)) { 1022 return NULL; 1023 } 1024 1094 1025 status = pjsua_verify_sip_url(url); 1095 1026 1096 return Py_BuildValue("i", status);1027 return Py_BuildValue("i", status); 1097 1028 } 1098 1029 … … 1155 1086 "c_url: The URL, as NULL terminated string."; 1156 1087 1157 static char pjsua_pool_create_doc[] =1158 "_pjsua.Pj_Pool _pjsua.pool_create (string name, int init_size, "1159 "int increment) "1160 "Create memory pool Parameters: "1161 "name: Optional pool name; "1162 "init_size: Initial size of the pool; "1163 "increment: Increment size.";1164 1165 static char pjsua_get_pjsip_endpt_doc[] =1166 "_pjsua.Pjsip_Endpoint _pjsua.get_pjsip_endpt (void) "1167 "Internal function to get SIP endpoint instance of pjsua, which is needed "1168 "for example to register module, create transports, etc. Probably is only "1169 "valid after pjsua_init() is called.";1170 1171 static char pjsua_get_pjmedia_endpt_doc[] =1172 "_pjsua.Pjmedia_Endpt _pjsua.get_pjmedia_endpt (void) "1173 "Internal function to get media endpoint instance. Only valid after "1174 "pjsua_init() is called.";1175 1176 static char pjsua_get_pool_factory_doc[] =1177 "_pjsua.Pj_Pool_Factory _pjsua.get_pool_factory (void) "1178 "Internal function to get PJSUA pool factory. Only valid after "1179 "pjsua_init() is called.";1180 1181 1088 static char pjsua_reconfigure_logging_doc[] = 1182 1089 "int _pjsua.reconfigure_logging (_pjsua.Logging_Config c) " … … 1208 1115 /* 1209 1116 * py_pjsua_transport_config_default 1210 * !modified @ 0512061211 1117 */ 1212 1118 static PyObject *py_pjsua_transport_config_default(PyObject *pSelf, … … 1217 1123 1218 1124 PJ_UNUSED_ARG(pSelf); 1219 1220 if (!PyArg_ParseTuple(pArgs, "")) { 1221 return NULL; 1222 } 1125 PJ_UNUSED_ARG(pArgs); 1223 1126 1224 1127 pjsua_transport_config_default(&cfg); … … 1233 1136 /* 1234 1137 * py_pjsua_transport_create 1235 * !modified @ 0512061236 1138 */ 1237 1139 static PyObject *py_pjsua_transport_create(PyObject *pSelf, PyObject *pArgs) … … 1239 1141 pj_status_t status; 1240 1142 int type; 1241 PyObject * tmpObj;1143 PyObject *pCfg; 1242 1144 pjsua_transport_config cfg; 1243 1145 pjsua_transport_id id; … … 1245 1147 PJ_UNUSED_ARG(pSelf); 1246 1148 1247 if (!PyArg_ParseTuple(pArgs, "iO", &type, & tmpObj)) {1248 return NULL; 1249 } 1250 1251 if ( tmpObj!= Py_None) {1149 if (!PyArg_ParseTuple(pArgs, "iO", &type, &pCfg)) { 1150 return NULL; 1151 } 1152 1153 if (pCfg != Py_None) { 1252 1154 PyObj_pjsua_transport_config *obj; 1253 obj = (PyObj_pjsua_transport_config*)tmpObj; 1155 1156 obj = (PyObj_pjsua_transport_config*)pCfg; 1254 1157 PyObj_pjsua_transport_config_export(&cfg, obj); 1255 1158 status = pjsua_transport_create(type, &cfg, &id); … … 1264 1167 /* 1265 1168 * py_pjsua_enum_transports 1266 * !modified @ 2612061267 1169 */ 1268 1170 static PyObject *py_pjsua_enum_transports(PyObject *pSelf, PyObject *pArgs) … … 1270 1172 pj_status_t status; 1271 1173 PyObject *list; 1272 1273 1174 pjsua_transport_id id[PJSIP_MAX_TRANSPORTS]; 1274 1175 unsigned c, i; 1275 1176 1276 1177 PJ_UNUSED_ARG(pSelf); 1277 1278 if (!PyArg_ParseTuple(pArgs, "")) 1279 { 1280 return NULL; 1281 } 1282 1178 PJ_UNUSED_ARG(pArgs); 1179 1283 1180 c = PJ_ARRAY_SIZE(id); 1284 1181 status = pjsua_enum_transports(id, &c); 1285 1182 1286 1183 list = PyList_New(c); 1287 for (i = 0; i < c; i++) 1288 { 1289 int ret = PyList_SetItem(list, i, Py_BuildValue("i", id[i])); 1290 if (ret == -1) 1291 { 1292 return NULL; 1293 } 1294 } 1295 1296 return Py_BuildValue("O",list); 1184 for (i = 0; i < c; i++) { 1185 PyList_SetItem(list, i, Py_BuildValue("i", id[i])); 1186 } 1187 1188 return (PyObject*)list; 1297 1189 } 1298 1190 … … 1320 1212 NULL, NULL); 1321 1213 PyObj_pjsua_transport_info_import(obj, &info); 1322 return Py_BuildValue("O", obj);1214 return (PyObject*)obj; 1323 1215 } else { 1324 Py_INCREF(Py_None); 1325 return Py_None; 1216 return Py_BuildValue(""); 1326 1217 } 1327 1218 } … … 1330 1221 * py_pjsua_transport_set_enable 1331 1222 */ 1332 static PyObject *py_pjsua_transport_set_enable 1333 (PyObject *pSelf,PyObject *pArgs)1223 static PyObject *py_pjsua_transport_set_enable(PyObject *pSelf, 1224 PyObject *pArgs) 1334 1225 { 1335 1226 pj_status_t status; … … 1339 1230 PJ_UNUSED_ARG(pSelf); 1340 1231 1341 if (!PyArg_ParseTuple(pArgs, "ii", &id, &enabled)) 1342 { 1343 return NULL; 1344 } 1345 status = pjsua_transport_set_enable(id, enabled); 1346 1347 return Py_BuildValue("i",status); 1232 if (!PyArg_ParseTuple(pArgs, "ii", &id, &enabled)) { 1233 return NULL; 1234 } 1235 status = pjsua_transport_set_enable(id, enabled); 1236 1237 return Py_BuildValue("i", status); 1348 1238 } 1349 1239 … … 1359 1249 PJ_UNUSED_ARG(pSelf); 1360 1250 1361 if (!PyArg_ParseTuple(pArgs, "ii", &id, &force)) 1362 { 1251 if (!PyArg_ParseTuple(pArgs, "ii", &id, &force)) { 1363 1252 return NULL; 1364 1253 } 1365 1254 status = pjsua_transport_close(id, force); 1366 1255 1367 return Py_BuildValue("i", status);1256 return Py_BuildValue("i", status); 1368 1257 } 1369 1258 … … 1406 1295 /* 1407 1296 * py_pjsua_acc_config_default 1408 * !modified @ 0512061409 1297 */ 1410 1298 static PyObject *py_pjsua_acc_config_default(PyObject *pSelf, PyObject *pArgs) … … 1414 1302 1415 1303 PJ_UNUSED_ARG(pSelf); 1304 PJ_UNUSED_ARG(pArgs); 1416 1305 1417 1306 if (!PyArg_ParseTuple(pArgs, "")) { … … 1435 1324 1436 1325 PJ_UNUSED_ARG(pSelf); 1437 1438 if (!PyArg_ParseTuple(pArgs, "")) { 1439 return NULL; 1440 } 1326 PJ_UNUSED_ARG(pArgs); 1441 1327 1442 1328 count = pjsua_acc_get_count(); 1443 return Py_BuildValue("i", count);1329 return Py_BuildValue("i", count); 1444 1330 } 1445 1331 … … 1488 1374 1489 1375 PJ_UNUSED_ARG(pSelf); 1490 1491 if (!PyArg_ParseTuple(pArgs, "")) { 1492 return NULL; 1493 } 1376 PJ_UNUSED_ARG(pArgs); 1494 1377 1495 1378 id = pjsua_acc_get_default(); … … 1500 1383 /* 1501 1384 * py_pjsua_acc_add 1502 * !modified @ 0512061503 1385 */ 1504 1386 static PyObject *py_pjsua_acc_add(PyObject *pSelf, PyObject *pArgs) 1505 1387 { 1506 1388 int is_default; 1507 PyObject * acObj; 1508 PyObj_pjsua_acc_config * ac; 1389 PyObject *pCfg; 1509 1390 int acc_id; 1510 1391 int status; … … 1512 1393 PJ_UNUSED_ARG(pSelf); 1513 1394 1514 if (!PyArg_ParseTuple(pArgs, "Oi", & acObj, &is_default)) {1515 return NULL; 1516 } 1517 1518 if ( acObj!= Py_None) {1395 if (!PyArg_ParseTuple(pArgs, "Oi", &pCfg, &is_default)) { 1396 return NULL; 1397 } 1398 1399 if (pCfg != Py_None) { 1519 1400 pjsua_acc_config cfg; 1401 PyObj_pjsua_acc_config *ac; 1520 1402 1521 1403 pjsua_acc_config_default(&cfg); 1522 ac = (PyObj_pjsua_acc_config *) acObj;1404 ac = (PyObj_pjsua_acc_config *)pCfg; 1523 1405 PyObj_pjsua_acc_config_export(&cfg, ac); 1524 1406 status = pjsua_acc_add(&cfg, is_default, &acc_id); … … 1533 1415 /* 1534 1416 * py_pjsua_acc_add_local 1535 * !modified @ 0512061536 1417 */ 1537 1418 static PyObject *py_pjsua_acc_add_local(PyObject *pSelf, PyObject *pArgs) … … 1539 1420 int is_default; 1540 1421 int tid; 1541 int p_acc_id;1422 int acc_id; 1542 1423 int status; 1543 1424 … … 1548 1429 } 1549 1430 1550 1551 status = pjsua_acc_add_local(tid, is_default, &p_acc_id); 1552 1553 return Py_BuildValue("ii", status, p_acc_id); 1431 status = pjsua_acc_add_local(tid, is_default, &acc_id); 1432 1433 return Py_BuildValue("ii", status, acc_id); 1434 } 1435 1436 /* 1437 * py_pjsua_acc_set_user_data 1438 */ 1439 static PyObject *py_pjsua_acc_set_user_data(PyObject *pSelf, PyObject *pArgs) 1440 { 1441 int acc_id; 1442 PyObject *pUserData, *old_user_data; 1443 int status; 1444 1445 PJ_UNUSED_ARG(pSelf); 1446 1447 if (!PyArg_ParseTuple(pArgs, "iO", &acc_id, &pUserData)) { 1448 return NULL; 1449 } 1450 1451 old_user_data = (PyObject*) pjsua_acc_get_user_data(acc_id); 1452 1453 status = pjsua_acc_set_user_data(acc_id, (void*)pUserData); 1454 1455 if (status == PJ_SUCCESS) { 1456 Py_XINCREF(pUserData); 1457 Py_XDECREF(old_user_data); 1458 } 1459 1460 return Py_BuildValue("i", status); 1461 } 1462 1463 /* 1464 * py_pjsua_acc_get_user_data 1465 */ 1466 static PyObject *py_pjsua_acc_get_user_data(PyObject *pSelf, PyObject *pArgs) 1467 { 1468 int acc_id; 1469 PyObject *user_data; 1470 1471 PJ_UNUSED_ARG(pSelf); 1472 1473 if (!PyArg_ParseTuple(pArgs, "i", &acc_id)) { 1474 return NULL; 1475 } 1476 1477 user_data = (PyObject*) pjsua_acc_get_user_data(acc_id); 1478 1479 return user_data ? Py_BuildValue("O", user_data) : Py_BuildValue(""); 1554 1480 } 1555 1481 … … 1560 1486 { 1561 1487 int acc_id; 1488 PyObject *user_data; 1562 1489 int status; 1563 1490 1564 1491 PJ_UNUSED_ARG(pSelf); 1565 1492 1566 if (!PyArg_ParseTuple(pArgs, "i", &acc_id)) 1567 { 1568 return NULL; 1569 } 1570 1571 1572 status = pjsua_acc_del(acc_id); 1493 if (!PyArg_ParseTuple(pArgs, "i", &acc_id)) { 1494 return NULL; 1495 } 1496 1497 user_data = (PyObject*) pjsua_acc_get_user_data(acc_id); 1498 Py_XDECREF(user_data); 1499 1500 status = pjsua_acc_del(acc_id); 1501 1573 1502 return Py_BuildValue("i", status); 1574 1503 } … … 1579 1508 static PyObject *py_pjsua_acc_modify(PyObject *pSelf, PyObject *pArgs) 1580 1509 { 1581 PyObject * acObj;1510 PyObject *pCfg; 1582 1511 PyObj_pjsua_acc_config * ac; 1583 1512 int acc_id; … … 1586 1515 PJ_UNUSED_ARG(pSelf); 1587 1516 1588 if (!PyArg_ParseTuple(pArgs, "iO", &acc_id, & acObj)) {1589 return NULL; 1590 } 1591 1592 if ( acObj!= Py_None) {1517 if (!PyArg_ParseTuple(pArgs, "iO", &acc_id, &pCfg)) { 1518 return NULL; 1519 } 1520 1521 if (pCfg != Py_None) { 1593 1522 pjsua_acc_config cfg; 1594 1523 1595 1524 pjsua_acc_config_default(&cfg); 1596 ac = (PyObj_pjsua_acc_config *)acObj;1525 ac = (PyObj_pjsua_acc_config*)pCfg; 1597 1526 PyObj_pjsua_acc_config_export(&cfg, ac); 1598 1527 … … 1634 1563 int acc_id; 1635 1564 int activity_id; 1636 const char *activity_text ;1637 const char *rpid_id ;1565 const char *activity_text = NULL; 1566 const char *rpid_id = NULL; 1638 1567 pjrpid_element rpid; 1639 1568 pj_status_t status; … … 1642 1571 1643 1572 if (!PyArg_ParseTuple(pArgs, "iiiss", &acc_id, &is_online, 1644 &activity_id, &activity_text, &rpid_id)) { 1573 &activity_id, &activity_text, &rpid_id)) 1574 { 1645 1575 return NULL; 1646 1576 } … … 1649 1579 rpid.type = PJRPID_ELEMENT_TYPE_PERSON; 1650 1580 rpid.activity = activity_id; 1651 rpid.note = pj_str((char*)activity_text); 1581 if (activity_text) 1582 rpid.note = pj_str((char*)activity_text); 1652 1583 1653 1584 if (rpid_id) … … 1682 1613 /* 1683 1614 * py_pjsua_acc_get_info 1684 * !modified @ 0512061685 1615 */ 1686 1616 static PyObject *py_pjsua_acc_get_info(PyObject *pSelf, PyObject *pArgs) … … 1699 1629 status = pjsua_acc_get_info(acc_id, &info); 1700 1630 if (status == PJ_SUCCESS) { 1701 obj = (PyObj_pjsua_acc_info 1702 PyObj_pjsua_acc_info_new(&PyTyp_pjsua_acc_info,NULL, NULL);1631 obj = (PyObj_pjsua_acc_info*) 1632 PyObj_pjsua_acc_info_new(&PyTyp_pjsua_acc_info, NULL, NULL); 1703 1633 PyObj_pjsua_acc_info_import(obj, &info); 1704 return Py_BuildValue("O", obj);1634 return (PyObject*)obj; 1705 1635 } else { 1706 Py_INCREF(Py_None); 1707 return Py_None; 1636 return Py_BuildValue(""); 1708 1637 } 1709 1638 } … … 1711 1640 /* 1712 1641 * py_pjsua_enum_accs 1713 * !modified @ 2412061714 1642 */ 1715 1643 static PyObject *py_pjsua_enum_accs(PyObject *pSelf, PyObject *pArgs) … … 1717 1645 pj_status_t status; 1718 1646 PyObject *list; 1719 1720 1647 pjsua_acc_id id[PJSUA_MAX_ACC]; 1721 1648 unsigned c, i; 1722 1649 1723 1650 PJ_UNUSED_ARG(pSelf); 1724 1725 if (!PyArg_ParseTuple(pArgs, "")) 1726 { 1727 return NULL; 1728 } 1651 PJ_UNUSED_ARG(pArgs); 1652 1729 1653 c = PJ_ARRAY_SIZE(id); 1730 1731 1654 status = pjsua_enum_accs(id, &c); 1655 if (status != PJ_SUCCESS) 1656 c = 0; 1732 1657 1733 1658 list = PyList_New(c); 1734 for (i = 0; i < c; i++) 1735 { 1736 int ret = PyList_SetItem(list, i, Py_BuildValue("i", id[i])); 1737 if (ret == -1) 1738 { 1739 return NULL; 1740 } 1741 } 1742 1743 return Py_BuildValue("O",list); 1659 for (i = 0; i < c; i++) { 1660 PyList_SetItem(list, i, Py_BuildValue("i", id[i])); 1661 } 1662 1663 return (PyObject*)list; 1744 1664 } 1745 1665 1746 1666 /* 1747 1667 * py_pjsua_acc_enum_info 1748 * !modified @ 2412061749 1668 */ 1750 1669 static PyObject *py_pjsua_acc_enum_info(PyObject *pSelf, PyObject *pArgs) … … 1756 1675 1757 1676 PJ_UNUSED_ARG(pSelf); 1677 PJ_UNUSED_ARG(pArgs); 1758 1678 1759 1679 if (!PyArg_ParseTuple(pArgs, "")) { … … 1763 1683 c = PJ_ARRAY_SIZE(info); 1764 1684 status = pjsua_acc_enum_info(info, &c); 1765 1685 if (status != PJ_SUCCESS) 1686 c = 0; 1687 1766 1688 list = PyList_New(c); 1767 1689 for (i = 0; i < c; i++) { … … 1772 1694 PyObj_pjsua_acc_info_import(obj, &info[i]); 1773 1695 1774 PyList_SetItem(list, i, (PyObject *)obj); 1775 } 1776 1777 return Py_BuildValue("O",list); 1778 } 1779 1780 /* 1781 * py_pjsua_acc_find_for_outgoing 1782 */ 1783 static PyObject *py_pjsua_acc_find_for_outgoing(PyObject *pSelf, 1784 PyObject *pArgs) 1785 { 1786 int acc_id; 1787 PyObject * url; 1788 pj_str_t str; 1789 1790 PJ_UNUSED_ARG(pSelf); 1791 1792 if (!PyArg_ParseTuple(pArgs, "O", &url)) 1793 { 1794 return NULL; 1795 } 1796 str.ptr = PyString_AsString(url); 1797 str.slen = strlen(PyString_AsString(url)); 1798 1799 acc_id = pjsua_acc_find_for_outgoing(&str); 1800 1801 return Py_BuildValue("i", acc_id); 1802 } 1803 1804 /* 1805 * py_pjsua_acc_find_for_incoming 1806 */ 1807 static PyObject *py_pjsua_acc_find_for_incoming(PyObject *pSelf, 1808 PyObject *pArgs) 1809 { 1810 int acc_id; 1811 PyObject * tmpObj; 1812 PyObj_pjsip_rx_data * obj; 1813 pjsip_rx_data * rdata; 1814 1815 PJ_UNUSED_ARG(pSelf); 1816 1817 if (!PyArg_ParseTuple(pArgs, "O", &tmpObj)) 1818 { 1819 return NULL; 1820 } 1821 if (tmpObj != Py_None) 1822 { 1823 obj = (PyObj_pjsip_rx_data *)tmpObj; 1824 rdata = obj->rdata; 1825 acc_id = pjsua_acc_find_for_incoming(rdata); 1826 } else { 1827 acc_id = pjsua_acc_find_for_incoming(NULL); 1828 } 1829 return Py_BuildValue("i", acc_id); 1830 } 1831 1832 /* 1833 * py_pjsua_acc_create_uac_contact 1834 * !modified @ 061206 1835 */ 1836 static PyObject *py_pjsua_acc_create_uac_contact(PyObject *pSelf, 1837 PyObject *pArgs) 1838 { 1839 int status; 1840 int acc_id; 1841 PyObject * pObj; 1842 PyObj_pj_pool * p; 1843 pj_pool_t * pool; 1844 PyObject * strc; 1845 pj_str_t contact; 1846 PyObject * stru; 1847 pj_str_t uri; 1848 1849 PJ_UNUSED_ARG(pSelf); 1850 1851 if (!PyArg_ParseTuple(pArgs, "OiO", &pObj, &acc_id, &stru)) 1852 { 1853 return NULL; 1854 } 1855 if (pObj != Py_None) 1856 { 1857 p = (PyObj_pj_pool *)pObj; 1858 pool = p->pool; 1859 uri.ptr = PyString_AsString(stru); 1860 uri.slen = strlen(PyString_AsString(stru)); 1861 status = pjsua_acc_create_uac_contact(pool, &contact, acc_id, &uri); 1862 } else { 1863 status = pjsua_acc_create_uac_contact(NULL, &contact, acc_id, &uri); 1864 } 1865 strc = PyString_FromStringAndSize(contact.ptr, contact.slen); 1866 1867 return Py_BuildValue("O", strc); 1868 } 1869 1870 /* 1871 * py_pjsua_acc_create_uas_contact 1872 * !modified @ 061206 1873 */ 1874 static PyObject *py_pjsua_acc_create_uas_contact(PyObject *pSelf, 1875 PyObject *pArgs) 1876 { 1877 int status; 1878 int acc_id; 1879 PyObject * pObj; 1880 PyObj_pj_pool * p; 1881 pj_pool_t * pool; 1882 PyObject * strc; 1883 pj_str_t contact; 1884 PyObject * rObj; 1885 PyObj_pjsip_rx_data * objr; 1886 pjsip_rx_data * rdata; 1887 1888 PJ_UNUSED_ARG(pSelf); 1889 1890 if (!PyArg_ParseTuple(pArgs, "OiO", &pObj, &acc_id, &rObj)) 1891 { 1892 return NULL; 1893 } 1894 if (pObj != Py_None) 1895 { 1896 p = (PyObj_pj_pool *)pObj; 1897 pool = p->pool; 1898 } else { 1899 pool = NULL; 1900 } 1901 if (rObj != Py_None) 1902 { 1903 objr = (PyObj_pjsip_rx_data *)rObj; 1904 rdata = objr->rdata; 1905 } else { 1906 rdata = NULL; 1907 } 1908 status = pjsua_acc_create_uas_contact(pool, &contact, acc_id, rdata); 1909 strc = PyString_FromStringAndSize(contact.ptr, contact.slen); 1910 1911 return Py_BuildValue("O", strc); 1696 PyList_SetItem(list, i, (PyObject*)obj); 1697 } 1698 1699 return (PyObject*)list; 1912 1700 } 1913 1701 … … 1915 1703 * py_pjsua_acc_set_transport 1916 1704 */ 1917 static PyObject *py_pjsua_acc_set_transport 1918 (PyObject *pSelf, PyObject *pArgs) 1705 static PyObject *py_pjsua_acc_set_transport(PyObject *pSelf, PyObject *pArgs) 1919 1706 { 1920 1707 int acc_id, transport_id; … … 1923 1710 PJ_UNUSED_ARG(pSelf); 1924 1711 1925 if (!PyArg_ParseTuple(pArgs, "ii", &acc_id, &transport_id)) 1926 { 1712 if (!PyArg_ParseTuple(pArgs, "ii", &acc_id, &transport_id)) { 1927 1713 return NULL; 1928 1714 } … … 1938 1724 * py_pjsua_acc_pres_notify 1939 1725 */ 1940 static PyObject *py_pjsua_acc_pres_notify 1941 (PyObject *pSelf, PyObject *pArgs) 1942 { 1943 static char reason_buf[64]; 1726 static PyObject *py_pjsua_acc_pres_notify(PyObject *pSelf, 1727 PyObject *pArgs) 1728 { 1944 1729 int acc_id, state; 1945 PyObject *arg_pres, *arg_msg_data ;1730 PyObject *arg_pres, *arg_msg_data, *arg_reason; 1946 1731 void *srv_pres; 1947 1732 pjsua_msg_data msg_data; 1948 const char *arg_reason;1949 1733 pj_str_t reason; 1950 1734 pj_bool_t with_body; … … 1954 1738 PJ_UNUSED_ARG(pSelf); 1955 1739 1956 if (!PyArg_ParseTuple(pArgs, "iOi sO", &acc_id, &arg_pres,1740 if (!PyArg_ParseTuple(pArgs, "iOiOO", &acc_id, &arg_pres, 1957 1741 &state, &arg_reason, &arg_msg_data)) 1958 1742 { … … 1961 1745 1962 1746 srv_pres = (void*) PyLong_AsLong(arg_pres); 1963 pjsua_msg_data_init(&msg_data);1964 1747 with_body = (state != PJSIP_EVSUB_STATE_TERMINATED); 1965 1748 1966 if (arg_reason) { 1967 strncpy(reason_buf, arg_reason, sizeof(reason_buf)); 1968 reason.ptr = reason_buf; 1969 reason.slen = strlen(arg_reason); 1749 if (arg_reason && PyString_Check(arg_reason)) { 1750 reason = PyString_ToPJ(arg_reason); 1970 1751 } else { 1971 1752 reason = pj_str(""); 1972 1753 } 1973 1754 1755 pjsua_msg_data_init(&msg_data); 1974 1756 if (arg_msg_data && arg_msg_data != Py_None) { 1975 1757 PyObj_pjsua_msg_data *omd = (PyObj_pjsua_msg_data *)arg_msg_data; 1976 msg_data.content_type.ptr = PyString_AsString(omd->content_type); 1977 msg_data.content_type.slen = PyString_Size(omd->content_type); 1978 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body); 1979 msg_data.msg_body.slen = PyString_Size(omd->msg_body); 1758 msg_data.content_type = PyString_ToPJ(omd->content_type); 1759 msg_data.msg_body = PyString_ToPJ(omd->msg_body); 1980 1760 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE); 1981 1761 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list); 1982 } else if (arg_msg_data) {1983 Py_XDECREF(arg_msg_data);1984 1762 } 1985 1763 … … 2049 1827 "_pjsua.Acc_Info[] _pjsua.acc_enum_info () " 2050 1828 "Enum accounts info."; 2051 static char pjsua_acc_find_for_outgoing_doc[] =2052 "int _pjsua.acc_find_for_outgoing (string url) "2053 "This is an internal function to find the most appropriate account "2054 "to used to reach to the specified URL.";2055 static char pjsua_acc_find_for_incoming_doc[] =2056 "int _pjsua.acc_find_for_incoming (PyObj_pjsip_rx_data rdata) "2057 "This is an internal function to find the most appropriate account "2058 "to be used to handle incoming calls.";2059 static char pjsua_acc_create_uac_contact_doc[] =2060 "string _pjsua.acc_create_uac_contact (PyObj_pj_pool pool, "2061 "int acc_id, string uri) "2062 "Create a suitable URI to be put as Contact based on the specified "2063 "target URI for the specified account.";2064 static char pjsua_acc_create_uas_contact_doc[] =2065 "string _pjsua.acc_create_uas_contact (PyObj_pj_pool pool, "2066 "int acc_id, PyObj_pjsip_rx_data rdata) "2067 "Create a suitable URI to be put as Contact based on the information "2068 "in the incoming request.";2069 1829 2070 1830 /* END OF LIB ACCOUNT */ … … 2084 1844 2085 1845 PJ_UNUSED_ARG(pSelf); 2086 2087 if (!PyArg_ParseTuple(pArgs, "")) { 2088 return NULL; 2089 } 2090 1846 PJ_UNUSED_ARG(pArgs); 1847 2091 1848 pjsua_buddy_config_default(&cfg); 2092 1849 obj = (PyObj_pjsua_buddy_config *) … … 2102 1859 static PyObject *py_pjsua_get_buddy_count(PyObject *pSelf, PyObject *pArgs) 2103 1860 { 2104 int ret; 2105 2106 PJ_UNUSED_ARG(pSelf); 2107 2108 if (!PyArg_ParseTuple(pArgs, "")) { 2109 return NULL; 2110 } 2111 ret = pjsua_get_buddy_count(); 2112 2113 return Py_BuildValue("i", ret); 1861 PJ_UNUSED_ARG(pSelf); 1862 PJ_UNUSED_ARG(pArgs); 1863 1864 return Py_BuildValue("i", pjsua_get_buddy_count()); 2114 1865 } 2115 1866 … … 2134 1885 /* 2135 1886 * py_pjsua_enum_buddies 2136 * !modified @ 2412062137 1887 */ 2138 1888 static PyObject *py_pjsua_enum_buddies(PyObject *pSelf, PyObject *pArgs) … … 2140 1890 pj_status_t status; 2141 1891 PyObject *list; 2142 2143 1892 pjsua_buddy_id id[PJSUA_MAX_BUDDIES]; 2144 1893 unsigned c, i; 2145 1894 2146 1895 PJ_UNUSED_ARG(pSelf); 2147 2148 if (!PyArg_ParseTuple(pArgs, "")) { 2149 return NULL; 2150 } 1896 PJ_UNUSED_ARG(pArgs); 1897 2151 1898 c = PJ_ARRAY_SIZE(id); 2152 1899 status = pjsua_enum_buddies(id, &c); 1900 if (status != PJ_SUCCESS) 1901 c = 0; 1902 2153 1903 list = PyList_New(c); 2154 1904 for (i = 0; i < c; i++) { … … 2156 1906 } 2157 1907 2158 return Py_BuildValue("O",list); 1908 return (PyObject*)list; 1909 } 1910 1911 /* 1912 * py_pjsua_buddy_find 1913 */ 1914 static PyObject *py_pjsua_buddy_find(PyObject *pSelf, PyObject *pArgs) 1915 { 1916 PyObject *pURI; 1917 pj_str_t uri; 1918 pjsua_buddy_id buddy_id; 1919 1920 PJ_UNUSED_ARG(pSelf); 1921 1922 if (!PyArg_ParseTuple(pArgs, "O", &pURI)) { 1923 return NULL; 1924 } 1925 1926 if (!PyString_Check(pURI)) 1927 return Py_BuildValue("i", PJSUA_INVALID_ID); 1928 1929 uri = PyString_ToPJ(pURI); 1930 buddy_id = pjsua_buddy_find(&uri); 1931 1932 return Py_BuildValue("i", buddy_id); 2159 1933 } 2160 1934 2161 1935 /* 2162 1936 * py_pjsua_buddy_get_info 2163 * !modified @ 0712062164 1937 */ 2165 1938 static PyObject *py_pjsua_buddy_get_info(PyObject *pSelf, PyObject *pArgs) 2166 1939 { 2167 1940 int buddy_id; 2168 PyObj_pjsua_buddy_info * obj;2169 1941 pjsua_buddy_info info; 2170 1942 int status; … … 2178 1950 status = pjsua_buddy_get_info(buddy_id, &info); 2179 1951 if (status == PJ_SUCCESS) { 1952 PyObj_pjsua_buddy_info *obj; 1953 2180 1954 obj = (PyObj_pjsua_buddy_info *) 2181 PyObj_pjsua_buddy_config_new(&PyTyp_pjsua_buddy_info,NULL,NULL); 1955 PyObj_pjsua_buddy_config_new(&PyTyp_pjsua_buddy_info, 1956 NULL, NULL); 2182 1957 PyObj_pjsua_buddy_info_import(obj, &info); 2183 return Py_BuildValue("O", obj);1958 return (PyObject*)obj; 2184 1959 } else { 2185 Py_INCREF(Py_None); 2186 return Py_None; 1960 return Py_BuildValue(""); 2187 1961 } 2188 1962 } … … 2190 1964 /* 2191 1965 * py_pjsua_buddy_add 2192 * !modified @ 0612062193 1966 */ 2194 1967 static PyObject *py_pjsua_buddy_add(PyObject *pSelf, PyObject *pArgs) 2195 1968 { 2196 PyObject * bcObj;1969 PyObject *pCfg; 2197 1970 int buddy_id; 2198 1971 int status; … … 2200 1973 PJ_UNUSED_ARG(pSelf); 2201 1974 2202 if (!PyArg_ParseTuple(pArgs, "O", & bcObj)) {2203 return NULL; 2204 } 2205 2206 if ( bcObj!= Py_None) {1975 if (!PyArg_ParseTuple(pArgs, "O", &pCfg)) { 1976 return NULL; 1977 } 1978 1979 if (pCfg != Py_None) { 2207 1980 pjsua_buddy_config cfg; 2208 PyObj_pjsua_buddy_config * 2209 2210 bc = (PyObj_pjsua_buddy_config *) bcObj;1981 PyObj_pjsua_buddy_config *bc; 1982 1983 bc = (PyObj_pjsua_buddy_config *)pCfg; 2211 1984 2212 1985 pjsua_buddy_config_default(&cfg); … … 2214 1987 2215 1988 status = pjsua_buddy_add(&cfg, &buddy_id); 1989 2216 1990 } else { 2217 1991 status = PJ_EINVAL; … … 2228 2002 int buddy_id; 2229 2003 int status; 2004 PyObject *user_data; 2230 2005 2231 2006 PJ_UNUSED_ARG(pSelf); … … 2234 2009 return NULL; 2235 2010 } 2236 2237 2238 status = pjsua_buddy_del(buddy_id); 2011 2012 user_data = (PyObject*) pjsua_buddy_get_user_data(buddy_id); 2013 Py_XDECREF(user_data); 2014 2015 status = pjsua_buddy_del(buddy_id); 2016 2239 2017 return Py_BuildValue("i", status); 2240 2018 } 2241 2019 2242 2020 /* 2243 * py_pjsua_buddy_s ubscribe_pres2244 */ 2245 static PyObject *py_pjsua_buddy_s ubscribe_pres(PyObject *pSelf, PyObject *pArgs)2021 * py_pjsua_buddy_set_user_data 2022 */ 2023 static PyObject *py_pjsua_buddy_set_user_data(PyObject *pSelf, PyObject *pArgs) 2246 2024 { 2247 2025 int buddy_id; 2248 2026 int status; 2027 PyObject *user_data, *old_user_data; 2028 2029 PJ_UNUSED_ARG(pSelf); 2030 2031 if (!PyArg_ParseTuple(pArgs, "iO", &buddy_id, &user_data)) { 2032 return NULL; 2033 } 2034 2035 old_user_data = (PyObject*) pjsua_buddy_get_user_data(buddy_id); 2036 2037 status = pjsua_buddy_set_user_data(buddy_id, (void*)user_data); 2038 2039 if (status == PJ_SUCCESS) { 2040 Py_XINCREF(user_data); 2041 Py_XDECREF(old_user_data); 2042 } 2043 2044 return Py_BuildValue("i", status); 2045 } 2046 2047 /* 2048 * py_pjsua_buddy_get_user_data 2049 */ 2050 static PyObject *py_pjsua_buddy_get_user_data(PyObject *pSelf, PyObject *pArgs) 2051 { 2052 int buddy_id; 2053 PyObject *user_data; 2054 2055 PJ_UNUSED_ARG(pSelf); 2056 2057 if (!PyArg_ParseTuple(pArgs, "i", &buddy_id)) { 2058 return NULL; 2059 } 2060 2061 user_data = (PyObject*) pjsua_buddy_get_user_data(buddy_id); 2062 2063 return user_data? Py_BuildValue("O", user_data) : Py_BuildValue(""); 2064 } 2065 2066 /* 2067 * py_pjsua_buddy_subscribe_pres 2068 */ 2069 static PyObject *py_pjsua_buddy_subscribe_pres(PyObject *pSelf, 2070 PyObject *pArgs) 2071 { 2072 int buddy_id; 2073 int status; 2249 2074 int subscribe; 2250 2075 … … 2254 2079 return NULL; 2255 2080 } 2256 2257 2258 status = pjsua_buddy_subscribe_pres(buddy_id, subscribe); 2081 2082 status = pjsua_buddy_subscribe_pres(buddy_id, subscribe); 2083 2259 2084 return Py_BuildValue("i", status); 2260 2085 } … … 2272 2097 return NULL; 2273 2098 } 2274 2275 2099 2276 2100 pjsua_pres_dump(verbose); 2277 Py_INCREF(Py_None); 2278 return Py_ None;2101 2102 return Py_BuildValue(""); 2279 2103 } 2280 2104 2281 2105 /* 2282 2106 * py_pjsua_im_send 2283 * !modified @ 0712062284 2107 */ 2285 2108 static PyObject *py_pjsua_im_send(PyObject *pSelf, PyObject *pArgs) … … 2287 2110 int status; 2288 2111 int acc_id; 2289 pj_str_t * 2112 pj_str_t *mime_type, tmp_mime_type; 2290 2113 pj_str_t to, content; 2291 PyObject * st;2292 PyObject * smt;2293 PyObject * sc;2114 PyObject *pTo; 2115 PyObject *pMimeType; 2116 PyObject *pContent; 2294 2117 pjsua_msg_data msg_data; 2295 PyObject * omdObj; 2296 PyObj_pjsua_msg_data * omd; 2297 2118 PyObject *pMsgData; 2298 2119 int user_data; 2299 pj_pool_t *pool ;2120 pj_pool_t *pool = NULL; 2300 2121 2301 2122 PJ_UNUSED_ARG(pSelf); 2302 2123 2303 2124 if (!PyArg_ParseTuple(pArgs, "iOOOOi", &acc_id, 2304 &st, &smt, &sc, &omdObj, &user_data)) 2305 { 2306 return NULL; 2307 } 2308 if (smt != Py_None) { 2125 &pTo, &pMimeType, &pContent, &pMsgData, &user_data)) 2126 { 2127 return NULL; 2128 } 2129 2130 if (pMimeType != Py_None) { 2309 2131 mime_type = &tmp_mime_type; 2310 tmp_mime_type = PyString_ to_pj_str(smt);2132 tmp_mime_type = PyString_ToPJ(pMimeType); 2311 2133 } else { 2312 2134 mime_type = NULL; 2313 2135 } 2314 to = PyString_to_pj_str(st); 2315 content = PyString_to_pj_str(sc); 2316 2317 if (omdObj != Py_None) { 2318 2319 omd = (PyObj_pjsua_msg_data *)omdObj; 2320 msg_data.content_type = PyString_to_pj_str(omd->content_type); 2321 msg_data.msg_body = PyString_to_pj_str(omd->msg_body); 2322 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE); 2323 2136 2137 to = PyString_ToPJ(pTo); 2138 content = PyString_ToPJ(pContent); 2139 2140 if (pMsgData != Py_None) { 2141 PyObj_pjsua_msg_data *omd; 2142 2143 omd = (PyObj_pjsua_msg_data *)pMsgData; 2144 msg_data.content_type = PyString_ToPJ(omd->content_type); 2145 msg_data.msg_body = PyString_ToPJ(omd->msg_body); 2146 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE); 2324 2147 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list); 2325 status = pjsua_im_send(acc_id, &to, mime_type, 2326 &content, &msg_data, (void *)user_data); 2327 pj_pool_release(pool); 2328 } else { 2329 2330 status = pjsua_im_send(acc_id, &to, mime_type, 2331 &content, NULL, NULL); 2332 } 2148 } 2149 2150 status = pjsua_im_send(acc_id, &to, mime_type, &content, 2151 &msg_data, (void *)user_data); 2152 if (pool) 2153 pj_pool_release(pool); 2333 2154 2334 2155 return Py_BuildValue("i",status); … … 2343 2164 int acc_id; 2344 2165 pj_str_t to; 2345 PyObject * st;2166 PyObject *pTo; 2346 2167 int is_typing; 2347 2168 pjsua_msg_data msg_data; 2348 PyObject * omdObj; 2349 PyObj_pjsua_msg_data * omd; 2350 pj_pool_t * pool; 2351 2352 PJ_UNUSED_ARG(pSelf); 2353 2354 if (!PyArg_ParseTuple(pArgs, "iOiO", &acc_id, &st, &is_typing, &omdObj)) { 2169 PyObject *pMsgData; 2170 pj_pool_t *pool = NULL; 2171 2172 PJ_UNUSED_ARG(pSelf); 2173 2174 if (!PyArg_ParseTuple(pArgs, "iOiO", &acc_id, &pTo, &is_typing, 2175 &pMsgData)) 2176 { 2355 2177 return NULL; 2356 2178 } 2357 2179 2358 to = PyString_to_pj_str(st); 2359 2360 if (omdObj != Py_None) { 2361 omd = (PyObj_pjsua_msg_data *)omdObj; 2362 msg_data.content_type = PyString_to_pj_str(omd->content_type); 2363 msg_data.msg_body = PyString_to_pj_str(omd->msg_body); 2364 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE); 2180 to = PyString_ToPJ(pTo); 2181 2182 if (pMsgData != Py_None) { 2183 PyObj_pjsua_msg_data *omd; 2184 2185 omd = (PyObj_pjsua_msg_data *)pMsgData; 2186 msg_data.content_type = PyString_ToPJ(omd->content_type); 2187 msg_data.msg_body = PyString_ToPJ(omd->msg_body); 2188 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE); 2365 2189 2366 2190 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list); 2367 status = pjsua_im_typing(acc_id, &to, is_typing, &msg_data); 2368 pj_pool_release(pool); 2369 } else { 2370 status = pjsua_im_typing(acc_id, &to, is_typing, NULL); 2371 } 2372 return Py_BuildValue("i",status); 2191 } 2192 2193 status = pjsua_im_typing(acc_id, &to, is_typing, &msg_data); 2194 2195 if (pool) 2196 pj_pool_release(pool); 2197 2198 return Py_BuildValue("i", status); 2373 2199 } 2374 2200 … … 2415 2241 2416 2242 2417 2418 /* 2419 * PyObj_pjsua_codec_info 2420 * Codec Info 2421 * !modified @ 071206 2422 */ 2423 typedef struct 2424 { 2425 PyObject_HEAD 2426 /* Type-specific fields go here. */ 2427 2428 PyObject * codec_id; 2429 pj_uint8_t priority; 2430 char buf_[32]; 2431 } PyObj_pjsua_codec_info; 2432 2433 2434 /* 2435 * codec_info_dealloc 2436 * deletes a codec_info from memory 2437 * !modified @ 071206 2438 */ 2439 static void codec_info_dealloc(PyObj_pjsua_codec_info* self) 2440 { 2441 Py_XDECREF(self->codec_id); 2442 2443 self->ob_type->tp_free((PyObject*)self); 2444 } 2445 2446 2447 /* 2448 * codec_info_new 2449 * constructor for codec_info object 2450 * !modified @ 071206 2451 */ 2452 static PyObject * codec_info_new(PyTypeObject *type, PyObject *args, 2453 PyObject *kwds) 2454 { 2455 PyObj_pjsua_codec_info *self; 2456 2457 PJ_UNUSED_ARG(args); 2458 PJ_UNUSED_ARG(kwds); 2459 2460 self = (PyObj_pjsua_codec_info *)type->tp_alloc(type, 0); 2461 if (self != NULL) 2462 { 2463 self->codec_id = PyString_FromString(""); 2464 if (self->codec_id == NULL) 2465 { 2466 Py_DECREF(self); 2467 return NULL; 2468 } 2469 2470 2471 } 2472 return (PyObject *)self; 2473 } 2474 2475 /* 2476 * codec_info_members 2477 * !modified @ 071206 2478 */ 2479 static PyMemberDef codec_info_members[] = 2243 /* 2244 * py_pjsua_conf_get_max_ports 2245 */ 2246 static PyObject *py_pjsua_conf_get_max_ports(PyObject *pSelf, PyObject *pArgs) 2480 2247 { 2481 { 2482 "codec_id", T_OBJECT_EX, 2483 offsetof(PyObj_pjsua_codec_info, codec_id), 0, 2484 "Codec unique identification." 2485 }, 2486 2487 { 2488 "priority", T_INT, 2489 offsetof(PyObj_pjsua_codec_info, priority), 0, 2490 "Codec priority (integer 0-255)." 2491 }, 2492 2493 2494 2495 {NULL} /* Sentinel */ 2496 }; 2497 2498 2499 2500 2501 /* 2502 * PyTyp_pjsua_codec_info 2503 */ 2504 static PyTypeObject PyTyp_pjsua_codec_info = 2505 { 2506 PyObject_HEAD_INIT(NULL) 2507 0, /*ob_size*/ 2508 "_pjsua.Codec_Info", /*tp_name*/ 2509 sizeof(PyObj_pjsua_codec_info), /*tp_basicsize*/ 2510 0, /*tp_itemsize*/ 2511 (destructor)codec_info_dealloc,/*tp_dealloc*/ 2512 0, /*tp_print*/ 2513 0, /*tp_getattr*/ 2514 0, /*tp_setattr*/ 2515 0, /*tp_compare*/ 2516 0, /*tp_repr*/ 2517 0, /*tp_as_number*/ 2518 0, /*tp_as_sequence*/ 2519 0, /*tp_as_mapping*/ 2520 0, /*tp_hash */ 2521 0, /*tp_call*/ 2522 0, /*tp_str*/ 2523 0, /*tp_getattro*/ 2524 0, /*tp_setattro*/ 2525 0, /*tp_as_buffer*/ 2526 Py_TPFLAGS_DEFAULT, /*tp_flags*/ 2527 "Codec Info objects", /* tp_doc */ 2528 0, /* tp_traverse */ 2529 0, /* tp_clear */ 2530 0, /* tp_richcompare */ 2531 0, /* tp_weaklistoffset */ 2532 0, /* tp_iter */ 2533 0, /* tp_iternext */ 2534 0, /* tp_methods */ 2535 codec_info_members, /* tp_members */ 2536 0, /* tp_getset */ 2537 0, /* tp_base */ 2538 0, /* tp_dict */ 2539 0, /* tp_descr_get */ 2540 0, /* tp_descr_set */ 2541 0, /* tp_dictoffset */ 2542 0, /* tp_init */ 2543 0, /* tp_alloc */ 2544 codec_info_new, /* tp_new */ 2545 2546 }; 2547 2548 /* 2549 * PyObj_pjsua_conf_port_info 2550 * Conf Port Info 2551 */ 2552 typedef struct 2553 { 2554 PyObject_HEAD 2555 /* Type-specific fields go here. */ 2556 2557 int slot_id; 2558 PyObject * name; 2559 unsigned clock_rate; 2560 unsigned channel_count; 2561 unsigned samples_per_frame; 2562 unsigned bits_per_sample; 2563 PyListObject * listeners; 2564 2565 } PyObj_pjsua_conf_port_info; 2566 2567 2568 /* 2569 * conf_port_info_dealloc 2570 * deletes a conf_port_info from memory 2571 */ 2572 static void conf_port_info_dealloc(PyObj_pjsua_conf_port_info* self) 2573 { 2574 Py_XDECREF(self->name); 2575 Py_XDECREF(self->listeners); 2576 self->ob_type->tp_free((PyObject*)self); 2577 } 2578 2579 2580 /* 2581 * conf_port_info_new 2582 * constructor for conf_port_info object 2583 */ 2584 static PyObject * conf_port_info_new(PyTypeObject *type, PyObject *args, 2585 PyObject *kwds) 2586 { 2587 PyObj_pjsua_conf_port_info *self; 2588 2589 PJ_UNUSED_ARG(args); 2590 PJ_UNUSED_ARG(kwds); 2591 2592 self = (PyObj_pjsua_conf_port_info *)type->tp_alloc(type, 0); 2593 if (self != NULL) 2594 { 2595 self->name = PyString_FromString(""); 2596 if (self->name == NULL) 2597 { 2598 Py_DECREF(self); 2599 return NULL; 2600 } 2601 2602 self->listeners = (PyListObject *)PyList_New(0); 2603 if (self->listeners == NULL) 2604 { 2605 Py_DECREF(self); 2606 return NULL; 2607 } 2608 } 2609 return (PyObject *)self; 2610 } 2611 2612 /* 2613 * conf_port_info_members 2614 */ 2615 static PyMemberDef conf_port_info_members[] = 2616 { 2617 { 2618 "slot_id", T_INT, 2619 offsetof(PyObj_pjsua_conf_port_info, slot_id), 0, 2620 "Conference port number." 2621 }, 2622 { 2623 "name", T_OBJECT_EX, 2624 offsetof(PyObj_pjsua_conf_port_info, name), 0, 2625 "Port name" 2626 }, 2627 { 2628 "clock_rate", T_INT, 2629 offsetof(PyObj_pjsua_conf_port_info, clock_rate), 0, 2630 "Clock rate" 2631 }, 2632 { 2633 "channel_count", T_INT, 2634 offsetof(PyObj_pjsua_conf_port_info, channel_count), 0, 2635 "Number of channels." 2636 }, 2637 { 2638 "samples_per_frame", T_INT, 2639 offsetof(PyObj_pjsua_conf_port_info, samples_per_frame), 0, 2640 "Samples per frame " 2641 }, 2642 { 2643 "bits_per_sample", T_INT, 2644 offsetof(PyObj_pjsua_conf_port_info, bits_per_sample), 0, 2645 "Bits per sample" 2646 }, 2647 { 2648 "listeners", T_OBJECT_EX, 2649 offsetof(PyObj_pjsua_conf_port_info, listeners), 0, 2650 "Array of listeners (in other words, ports where this port " 2651 "is transmitting to" 2652 }, 2653 2654 {NULL} /* Sentinel */ 2655 }; 2656 2657 2658 2659 2660 /* 2661 * PyTyp_pjsua_conf_port_info 2662 */ 2663 static PyTypeObject PyTyp_pjsua_conf_port_info = 2664 { 2665 PyObject_HEAD_INIT(NULL) 2666 0, /*ob_size*/ 2667 "_pjsua.Conf_Port_Info", /*tp_name*/ 2668 sizeof(PyObj_pjsua_conf_port_info), /*tp_basicsize*/ 2669 0, /*tp_itemsize*/ 2670 (destructor)conf_port_info_dealloc,/*tp_dealloc*/ 2671 0, /*tp_print*/ 2672 0, /*tp_getattr*/ 2673 0, /*tp_setattr*/ 2674 0, /*tp_compare*/ 2675 0, /*tp_repr*/ 2676 0, /*tp_as_number*/ 2677 0, /*tp_as_sequence*/ 2678 0, /*tp_as_mapping*/ 2679 0, /*tp_hash */ 2680 0, /*tp_call*/ 2681 0, /*tp_str*/ 2682 0, /*tp_getattro*/ 2683 0, /*tp_setattro*/ 2684 0, /*tp_as_buffer*/ 2685 Py_TPFLAGS_DEFAULT, /*tp_flags*/ 2686 "Conf Port Info objects", /* tp_doc */ 2687 0, /* tp_traverse */ 2688 0, /* tp_clear */ 2689 0, /* tp_richcompare */ 2690 0, /* tp_weaklistoffset */ 2691 0, /* tp_iter */ 2692 0, /* tp_iternext */ 2693 0, /* tp_methods */ 2694 conf_port_info_members, /* tp_members */ 2695 0, /* tp_getset */ 2696 0, /* tp_base */ 2697 0, /* tp_dict */ 2698 0, /* tp_descr_get */ 2699 0, /* tp_descr_set */ 2700 0, /* tp_dictoffset */ 2701 0, /* tp_init */ 2702 0, /* tp_alloc */ 2703 conf_port_info_new, /* tp_new */ 2704 2705 }; 2706 2707 /* 2708 * PyObj_pjmedia_port 2709 */ 2710 typedef struct 2711 { 2712 PyObject_HEAD 2713 /* Type-specific fields go here. */ 2714 pjmedia_port * port; 2715 } PyObj_pjmedia_port; 2716 2717 2718 /* 2719 * PyTyp_pjmedia_port 2720 */ 2721 static PyTypeObject PyTyp_pjmedia_port = 2722 { 2723 PyObject_HEAD_INIT(NULL) 2724 0, /*ob_size*/ 2725 "_pjsua.PJMedia_Port", /*tp_name*/ 2726 sizeof(PyObj_pjmedia_port), /*tp_basicsize*/ 2727 0, /*tp_itemsize*/ 2728 0, /*tp_dealloc*/ 2729 0, /*tp_print*/ 2730 0, /*tp_getattr*/ 2731 0, /*tp_setattr*/ 2732 0, /*tp_compare*/ 2733 0, /*tp_repr*/ 2734 0, /*tp_as_number*/ 2735 0, /*tp_as_sequence*/ 2736 0, /*tp_as_mapping*/ 2737 0, /*tp_hash */ 2738 0, /*tp_call*/ 2739 0, /*tp_str*/ 2740 0, /*tp_getattro*/ 2741 0, /*tp_setattro*/ 2742 0, /*tp_as_buffer*/ 2743 Py_TPFLAGS_DEFAULT, /*tp_flags*/ 2744 "pjmedia_port objects", /* tp_doc */ 2745 2746 }; 2747 2748 /* 2749 * PyObj_pjmedia_snd_dev_info 2750 * PJMedia Snd Dev Info 2751 */ 2752 typedef struct 2753 { 2754 PyObject_HEAD 2755 /* Type-specific fields go here. */ 2756 2757 2758 unsigned input_count; 2759 unsigned output_count; 2760 unsigned default_samples_per_sec; 2761 PyObject * name; 2762 2763 } PyObj_pjmedia_snd_dev_info; 2764 2765 2766 /* 2767 * pjmedia_snd_dev_info_dealloc 2768 * deletes a pjmedia_snd_dev_info from memory 2769 */ 2770 static void pjmedia_snd_dev_info_dealloc(PyObj_pjmedia_snd_dev_info* self) 2771 { 2772 Py_XDECREF(self->name); 2773 self->ob_type->tp_free((PyObject*)self); 2774 } 2775 2776 2777 /* 2778 * pjmedia_snd_dev_info_new 2779 * constructor for pjmedia_snd_dev_info object 2780 */ 2781 static PyObject * pjmedia_snd_dev_info_new(PyTypeObject *type, PyObject *args, 2782 PyObject *kwds) 2783 { 2784 PyObj_pjmedia_snd_dev_info *self; 2785 2786 PJ_UNUSED_ARG(args); 2787 PJ_UNUSED_ARG(kwds); 2788 2789 self = (PyObj_pjmedia_snd_dev_info *)type->tp_alloc(type, 0); 2790 if (self != NULL) 2791 { 2792 self->name = PyString_FromString(""); 2793 if (self->name == NULL) 2794 { 2795 Py_DECREF(self); 2796 return NULL; 2797 } 2798 2799 } 2800 return (PyObject *)self; 2801 } 2802 2803 /* 2804 * pjmedia_snd_dev_info_members 2805 */ 2806 static PyMemberDef pjmedia_snd_dev_info_members[] = 2807 { 2808 2809 { 2810 "name", T_OBJECT_EX, 2811 offsetof(PyObj_pjmedia_snd_dev_info, name), 0, 2812 "Device name" 2813 }, 2814 { 2815 "input_count", T_INT, 2816 offsetof(PyObj_pjmedia_snd_dev_info, input_count), 0, 2817 "Max number of input channels" 2818 }, 2819 { 2820 "output_count", T_INT, 2821 offsetof(PyObj_pjmedia_snd_dev_info, output_count), 0, 2822 "Max number of output channels" 2823 }, 2824 { 2825 "default_samples_per_sec", T_INT, 2826 offsetof(PyObj_pjmedia_snd_dev_info, default_samples_per_sec), 0, 2827 "Default sampling rate." 2828 }, 2829 2830 2831 {NULL} /* Sentinel */ 2832 }; 2833 2834 2835 2836 2837 /* 2838 * PyTyp_pjmedia_snd_dev_info 2839 */ 2840 static PyTypeObject PyTyp_pjmedia_snd_dev_info = 2841 { 2842 PyObject_HEAD_INIT(NULL) 2843 0, /*ob_size*/ 2844 "_pjsua.PJMedia_Snd_Dev_Info", /*tp_name*/ 2845 sizeof(PyObj_pjmedia_snd_dev_info), /*tp_basicsize*/ 2846 0, /*tp_itemsize*/ 2847 (destructor)pjmedia_snd_dev_info_dealloc,/*tp_dealloc*/ 2848 0, /*tp_print*/ 2849 0, /*tp_getattr*/ 2850 0, /*tp_setattr*/ 2851 0, /*tp_compare*/ 2852 0, /*tp_repr*/ 2853 0, /*tp_as_number*/ 2854 0, /*tp_as_sequence*/ 2855 0, /*tp_as_mapping*/ 2856 0, /*tp_hash */ 2857 0, /*tp_call*/ 2858 0, /*tp_str*/ 2859 0, /*tp_getattro*/ 2860 0, /*tp_setattro*/ 2861 0, /*tp_as_buffer*/ 2862 Py_TPFLAGS_DEFAULT, /*tp_flags*/ 2863 "PJMedia Snd Dev Info objects", /* tp_doc */ 2864 0, /* tp_traverse */ 2865 0, /* tp_clear */ 2866 0, /* tp_richcompare */ 2867 0, /* tp_weaklistoffset */ 2868 0, /* tp_iter */ 2869 0, /* tp_iternext */ 2870 0, /* tp_methods */ 2871 pjmedia_snd_dev_info_members, /* tp_members */ 2872 0, /* tp_getset */ 2873 0, /* tp_base */ 2874 0, /* tp_dict */ 2875 0, /* tp_descr_get */ 2876 0, /* tp_descr_set */ 2877 0, /* tp_dictoffset */ 2878 0, /* tp_init */ 2879 0, /* tp_alloc */ 2880 pjmedia_snd_dev_info_new, /* tp_new */ 2881 2882 }; 2883 2884 /* 2885 * PyObj_pjmedia_codec_param_info 2886 * PJMedia Codec Param Info 2887 */ 2888 typedef struct 2889 { 2890 PyObject_HEAD 2891 /* Type-specific fields go here. */ 2892 2893 unsigned clock_rate; 2894 unsigned channel_cnt; 2895 pj_uint32_t avg_bps; 2896 pj_uint16_t frm_ptime; 2897 pj_uint8_t pcm_bits_per_sample; 2898 pj_uint8_t pt; 2899 2900 } PyObj_pjmedia_codec_param_info; 2901 2902 2903 2904 /* 2905 * pjmedia_codec_param_info_members 2906 */ 2907 static PyMemberDef pjmedia_codec_param_info_members[] = 2908 { 2909 2910 { 2911 "clock_rate", T_INT, 2912 offsetof(PyObj_pjmedia_codec_param_info, clock_rate), 0, 2913 "Sampling rate in Hz" 2914 }, 2915 { 2916 "channel_cnt", T_INT, 2917 offsetof(PyObj_pjmedia_codec_param_info, channel_cnt), 0, 2918 "Channel count" 2919 }, 2920 { 2921 "avg_bps", T_INT, 2922 offsetof(PyObj_pjmedia_codec_param_info, avg_bps), 0, 2923 "Average bandwidth in bits/sec" 2924 }, 2925 { 2926 "frm_ptime", T_INT, 2927 offsetof(PyObj_pjmedia_codec_param_info, frm_ptime), 0, 2928 "Base frame ptime in msec." 2929 }, 2930 { 2931 "pcm_bits_per_sample", T_INT, 2932 offsetof(PyObj_pjmedia_codec_param_info, pcm_bits_per_sample), 0, 2933 "Bits/sample in the PCM side" 2934 }, 2935 { 2936 "pt", T_INT, 2937 offsetof(PyObj_pjmedia_codec_param_info, pt), 0, 2938 "Payload type" 2939 }, 2940 2941 {NULL} /* Sentinel */ 2942 }; 2943 2944 2945 2946 2947 /* 2948 * PyTyp_pjmedia_codec_param_info 2949 */ 2950 static PyTypeObject PyTyp_pjmedia_codec_param_info = 2951 { 2952 PyObject_HEAD_INIT(NULL) 2953 0, /*ob_size*/ 2954 "_pjsua.PJMedia_Codec_Param_Info", /*tp_name*/ 2955 sizeof(PyObj_pjmedia_codec_param_info), /*tp_basicsize*/ 2956 0, /*tp_itemsize*/ 2957 0,/*tp_dealloc*/ 2958 0, /*tp_print*/ 2959 0, /*tp_getattr*/ 2960 0, /*tp_setattr*/ 2961 0, /*tp_compare*/ 2962 0, /*tp_repr*/ 2963 0, /*tp_as_number*/ 2964 0, /*tp_as_sequence*/ 2965 0, /*tp_as_mapping*/ 2966 0, /*tp_hash */ 2967 0, /*tp_call*/ 2968 0, /*tp_str*/ 2969 0, /*tp_getattro*/ 2970 0, /*tp_setattro*/ 2971 0, /*tp_as_buffer*/ 2972 Py_TPFLAGS_DEFAULT, /*tp_flags*/ 2973 "PJMedia Codec Param Info objects", /* tp_doc */ 2974 0, /* tp_traverse */ 2975 0, /* tp_clear */ 2976 0, /* tp_richcompare */ 2977 0, /* tp_weaklistoffset */ 2978 0, /* tp_iter */ 2979 0, /* tp_iternext */ 2980 0, /* tp_methods */ 2981 pjmedia_codec_param_info_members, /* tp_members */ 2982 2983 2984 }; 2985 2986 /* 2987 * PyObj_pjmedia_codec_param_setting 2988 * PJMedia Codec Param Setting 2989 */ 2990 typedef struct 2991 { 2992 PyObject_HEAD 2993 /* Type-specific fields go here. */ 2994 pj_uint8_t frm_per_pkt; 2995 unsigned vad; 2996 unsigned cng; 2997 unsigned penh; 2998 unsigned plc; 2999 unsigned reserved; 3000 pj_uint8_t enc_fmtp_mode; 3001 pj_uint8_t dec_fmtp_mode; 3002 3003 } PyObj_pjmedia_codec_param_setting; 3004 3005 3006 3007 /* 3008 * pjmedia_codec_param_setting_members 3009 */ 3010 static PyMemberDef pjmedia_codec_param_setting_members[] = 3011 { 3012 3013 { 3014 "frm_per_pkt", T_INT, 3015 offsetof(PyObj_pjmedia_codec_param_setting, frm_per_pkt), 0, 3016 "Number of frames per packet" 3017 }, 3018 { 3019 "vad", T_INT, 3020 offsetof(PyObj_pjmedia_codec_param_setting, vad), 0, 3021 "Voice Activity Detector" 3022 }, 3023 { 3024 "penh", T_INT, 3025 offsetof(PyObj_pjmedia_codec_param_setting, penh), 0, 3026 "Perceptual Enhancement" 3027 }, 3028 { 3029 "plc", T_INT, 3030 offsetof(PyObj_pjmedia_codec_param_setting, plc), 0, 3031 "Packet loss concealment" 3032 }, 3033 { 3034 "reserved", T_INT, 3035 offsetof(PyObj_pjmedia_codec_param_setting, reserved), 0, 3036 "Reserved, must be zero" 3037 }, 3038 { 3039 "cng", T_INT, 3040 offsetof(PyObj_pjmedia_codec_param_setting, cng), 0, 3041 "Comfort Noise Generator" 3042 }, 3043 { 3044 "enc_fmtp_mode", T_INT, 3045 offsetof(PyObj_pjmedia_codec_param_setting, enc_fmtp_mode), 0, 3046 "Mode param in fmtp (def:0)" 3047 }, 3048 { 3049 "dec_fmtp_mode", T_INT, 3050 offsetof(PyObj_pjmedia_codec_param_setting, dec_fmtp_mode), 0, 3051 "Mode param in fmtp (def:0)" 3052 }, 3053 3054 {NULL} /* Sentinel */ 3055 }; 3056 3057 3058 3059 3060 /* 3061 * PyTyp_pjmedia_codec_param_setting 3062 */ 3063 static PyTypeObject PyTyp_pjmedia_codec_param_setting = 3064 { 3065 PyObject_HEAD_INIT(NULL) 3066 0, /*ob_size*/ 3067 "_pjsua.PJMedia_Codec_Param_Setting", /*tp_name*/ 3068 sizeof(PyObj_pjmedia_codec_param_setting), /*tp_basicsize*/ 3069 0, /*tp_itemsize*/ 3070 0,/*tp_dealloc*/ 3071 0, /*tp_print*/ 3072 0, /*tp_getattr*/ 3073 0, /*tp_setattr*/ 3074 0, /*tp_compare*/ 3075 0, /*tp_repr*/ 3076 0, /*tp_as_number*/ 3077 0, /*tp_as_sequence*/ 3078 0, /*tp_as_mapping*/ 3079 0, /*tp_hash */ 3080 0, /*tp_call*/ 3081 0, /*tp_str*/ 3082 0, /*tp_getattro*/ 3083 0, /*tp_setattro*/ 3084 0, /*tp_as_buffer*/ 3085 Py_TPFLAGS_DEFAULT, /*tp_flags*/ 3086 "PJMedia Codec Param Setting objects", /* tp_doc */ 3087 0, /* tp_traverse */ 3088 0, /* tp_clear */ 3089 0, /* tp_richcompare */ 3090 0, /* tp_weaklistoffset */ 3091 0, /* tp_iter */ 3092 0, /* tp_iternext */ 3093 0, /* tp_methods */ 3094 pjmedia_codec_param_setting_members, /* tp_members */ 3095 3096 3097 }; 3098 3099 /* 3100 * PyObj_pjmedia_codec_param 3101 * PJMedia Codec Param 3102 */ 3103 typedef struct 3104 { 3105 PyObject_HEAD 3106 /* Type-specific fields go here. */ 3107 3108 PyObj_pjmedia_codec_param_info * info; 3109 PyObj_pjmedia_codec_param_setting * setting; 3110 3111 } PyObj_pjmedia_codec_param; 3112 3113 3114 /* 3115 * pjmedia_codec_param_dealloc 3116 * deletes a pjmedia_codec_param from memory 3117 */ 3118 static void pjmedia_codec_param_dealloc(PyObj_pjmedia_codec_param* self) 3119 { 3120 Py_XDECREF(self->info); 3121 Py_XDECREF(self->setting); 3122 self->ob_type->tp_free((PyObject*)self); 3123 } 3124 3125 3126 /* 3127 * pjmedia_codec_param_new 3128 * constructor for pjmedia_codec_param object 3129 */ 3130 static PyObject * pjmedia_codec_param_new(PyTypeObject *type, PyObject *args, 3131 PyObject *kwds) 3132 { 3133 PyObj_pjmedia_codec_param *self; 3134 3135 PJ_UNUSED_ARG(args); 3136 PJ_UNUSED_ARG(kwds); 3137 3138 self = (PyObj_pjmedia_codec_param *)type->tp_alloc(type, 0); 3139 if (self != NULL) 3140 { 3141 self->info = (PyObj_pjmedia_codec_param_info *) 3142 PyType_GenericNew(&PyTyp_pjmedia_codec_param_info, NULL, NULL); 3143 if (self->info == NULL) 3144 { 3145 Py_DECREF(self); 3146 return NULL; 3147 } 3148 self->setting = (PyObj_pjmedia_codec_param_setting *) 3149 PyType_GenericNew(&PyTyp_pjmedia_codec_param_setting, NULL, NULL); 3150 if (self->setting == NULL) 3151 { 3152 Py_DECREF(self); 3153 return NULL; 3154 } 3155 } 3156 return (PyObject *)self; 3157 } 3158 3159 /* 3160 * pjmedia_codec_param_members 3161 */ 3162 static PyMemberDef pjmedia_codec_param_members[] = 3163 { 3164 3165 { 3166 "info", T_OBJECT_EX, 3167 offsetof(PyObj_pjmedia_codec_param, info), 0, 3168 "The 'info' part of codec param describes the capability of the codec," 3169 " and the value should NOT be changed by application." 3170 }, 3171 { 3172 "setting", T_OBJECT_EX, 3173 offsetof(PyObj_pjmedia_codec_param, setting), 0, 3174 "The 'setting' part of codec param describes various settings to be " 3175 "applied to the codec. When the codec param is retrieved from the " 3176 "codec or codec factory, the values of these will be filled by " 3177 "the capability of the codec. Any features that are supported by " 3178 "the codec (e.g. vad or plc) will be turned on, so that application " 3179 "can query which capabilities are supported by the codec. " 3180 "Application may change the settings here before instantiating " 3181 "the codec/stream." 3182 }, 3183 3184 {NULL} /* Sentinel */ 3185 }; 3186 3187 3188 3189 3190 /* 3191 * PyTyp_pjmedia_codec_param 3192 */ 3193 static PyTypeObject PyTyp_pjmedia_codec_param = 3194 { 3195 PyObject_HEAD_INIT(NULL) 3196 0, /*ob_size*/ 3197 "_pjsua.PJMedia_Codec_Param", /*tp_name*/ 3198 sizeof(PyObj_pjmedia_codec_param), /*tp_basicsize*/ 3199 0, /*tp_itemsize*/ 3200 (destructor)pjmedia_codec_param_dealloc,/*tp_dealloc*/ 3201 0, /*tp_print*/ 3202 0, /*tp_getattr*/ 3203 0, /*tp_setattr*/ 3204 0, /*tp_compare*/ 3205 0, /*tp_repr*/ 3206 0, /*tp_as_number*/ 3207 0, /*tp_as_sequence*/ 3208 0, /*tp_as_mapping*/ 3209 0, /*tp_hash */ 3210 0, /*tp_call*/ 3211 0, /*tp_str*/ 3212 0, /*tp_getattro*/ 3213 0, /*tp_setattro*/ 3214 0, /*tp_as_buffer*/ 3215 Py_TPFLAGS_DEFAULT, /*tp_flags*/ 3216 "PJMedia Codec Param objects", /* tp_doc */ 3217 0, /* tp_traverse */ 3218 0, /* tp_clear */ 3219 0, /* tp_richcompare */ 3220 0, /* tp_weaklistoffset */ 3221 0, /* tp_iter */ 3222 0, /* tp_iternext */ 3223 0, /* tp_methods */ 3224 pjmedia_codec_param_members, /* tp_members */ 3225 0, /* tp_getset */ 3226 0, /* tp_base */ 3227 0, /* tp_dict */ 3228 0, /* tp_descr_get */ 3229 0, /* tp_descr_set */ 3230 0, /* tp_dictoffset */ 3231 0, /* tp_init */ 3232 0, /* tp_alloc */ 3233 pjmedia_codec_param_new, /* tp_new */ 3234 3235 }; 3236 3237 /* 3238 * py_pjsua_conf_get_max_ports 3239 */ 3240 static PyObject *py_pjsua_conf_get_max_ports 3241 (PyObject *pSelf, PyObject *pArgs) 2248 PJ_UNUSED_ARG(pSelf); 2249 PJ_UNUSED_ARG(pArgs); 2250 2251 return Py_BuildValue("i", pjsua_conf_get_max_ports()); 2252 } 2253 2254 /* 2255 * py_pjsua_conf_get_active_ports 2256 */ 2257 static PyObject *py_pjsua_conf_get_active_ports(PyObject *pSelf, 2258 PyObject *pArgs) 3242 2259 { 3243 int ret; 3244 3245 PJ_UNUSED_ARG(pSelf); 3246 3247 if (!PyArg_ParseTuple(pArgs, "")) 3248 { 3249 return NULL; 3250 } 3251 ret = pjsua_conf_get_max_ports(); 3252 3253 return Py_BuildValue("i", ret); 3254 } 3255 3256 /* 3257 * py_pjsua_conf_get_active_ports 3258 */ 3259 static PyObject *py_pjsua_conf_get_active_ports 3260 (PyObject *pSelf, PyObject *pArgs) 3261 { 3262 int ret; 3263 3264 PJ_UNUSED_ARG(pSelf); 3265 3266 if (!PyArg_ParseTuple(pArgs, "")) 3267 { 3268 return NULL; 3269 } 3270 ret = pjsua_conf_get_active_ports(); 3271 3272 return Py_BuildValue("i", ret); 2260 PJ_UNUSED_ARG(pSelf); 2261 PJ_UNUSED_ARG(pArgs); 2262 2263 return Py_BuildValue("i", pjsua_conf_get_active_ports()); 3273 2264 } 3274 2265 3275 2266 /* 3276 2267 * py_pjsua_enum_conf_ports 3277 * !modified @ 2412063278 2268 */ 3279 2269 static PyObject *py_pjsua_enum_conf_ports(PyObject *pSelf, PyObject *pArgs) … … 3281 2271 pj_status_t status; 3282 2272 PyObject *list; 3283 3284 2273 pjsua_conf_port_id id[PJSUA_MAX_CONF_PORTS]; 3285 2274 unsigned c, i; 3286 2275 3287 2276 PJ_UNUSED_ARG(pSelf); 3288 3289 if (!PyArg_ParseTuple(pArgs, "")) 3290 { 3291 return NULL; 3292 } 3293 2277 PJ_UNUSED_ARG(pArgs); 2278 3294 2279 c = PJ_ARRAY_SIZE(id); 3295 2280 status = pjsua_enum_conf_ports(id, &c); 2281 if (status != PJ_SUCCESS) 2282 c = 0; 3296 2283 3297 2284 list = PyList_New(c); 3298 for (i = 0; i < c; i++) 3299 { 3300 int ret = PyList_SetItem(list, i, Py_BuildValue("i", id[i])); 3301 if (ret == -1) 3302 { 3303 return NULL; 3304 } 3305 } 3306 3307 return Py_BuildValue("O",list); 2285 for (i = 0; i < c; i++) { 2286 PyList_SetItem(list, i, Py_BuildValue("i", id[i])); 2287 } 2288 2289 return (PyObject*)list; 3308 2290 } 3309 2291 … … 3311 2293 * py_pjsua_conf_get_port_info 3312 2294 */ 3313 static PyObject *py_pjsua_conf_get_port_info 3314 (PyObject *pSelf, PyObject *pArgs) 2295 static PyObject *py_pjsua_conf_get_port_info(PyObject *pSelf, PyObject *pArgs) 3315 2296 { 3316 2297 int id; 3317 PyObj_pjsua_conf_port_info * obj;2298 PyObj_pjsua_conf_port_info *ret; 3318 2299 pjsua_conf_port_info info; 3319 2300 int status; … … 3322 2303 PJ_UNUSED_ARG(pSelf); 3323 2304 3324 if (!PyArg_ParseTuple(pArgs, "i", &id)) 3325 { 3326 return NULL; 3327 } 3328 2305 if (!PyArg_ParseTuple(pArgs, "i", &id)) { 2306 return NULL; 2307 } 3329 2308 3330 2309 status = pjsua_conf_get_port_info(id, &info); 3331 obj = (PyObj_pjsua_conf_port_info *)conf_port_info_new3332 (&PyTyp_pjsua_conf_port_info,NULL,NULL);3333 obj->bits_per_sample = info.bits_per_sample;3334 obj->channel_count = info.bits_per_sample;3335 obj->clock_rate = info.clock_rate;3336 obj->name = PyString_FromStringAndSize(info.name.ptr, info.name.slen);3337 obj->samples_per_frame = info.samples_per_frame;3338 obj->slot_id = info.slot_id;3339 3340 obj->listeners = (PyListObject *)PyList_New(info.listener_cnt);2310 ret = (PyObj_pjsua_conf_port_info *) 2311 conf_port_info_new(&PyTyp_pjsua_conf_port_info, NULL, NULL); 2312 ret->bits_per_sample = info.bits_per_sample; 2313 ret->channel_count = info.bits_per_sample; 2314 ret->clock_rate = info.clock_rate; 2315 ret->name = PyString_FromPJ(&info.name); 2316 ret->samples_per_frame = info.samples_per_frame; 2317 ret->slot_id = info.slot_id; 2318 Py_XDECREF(ret->listeners); 2319 ret->listeners = PyList_New(info.listener_cnt); 3341 2320 for (i = 0; i < info.listener_cnt; i++) { 3342 PyObject * item = Py_BuildValue("i",info.listeners[i]); 3343 PyList_SetItem((PyObject *)obj->listeners, i, item); 3344 } 3345 return Py_BuildValue("O", obj); 3346 } 3347 3348 /* 3349 * py_pjsua_conf_add_port 3350 */ 3351 static PyObject *py_pjsua_conf_add_port 3352 (PyObject *pSelf, PyObject *pArgs) 3353 { 3354 int p_id; 3355 PyObject * oportObj; 3356 PyObj_pjmedia_port * oport; 3357 pjmedia_port * port; 3358 PyObject * opoolObj; 3359 PyObj_pj_pool * opool; 3360 pj_pool_t * pool; 3361 3362 int status; 3363 3364 PJ_UNUSED_ARG(pSelf); 3365 3366 if (!PyArg_ParseTuple(pArgs, "OO", &opoolObj, &oportObj)) 3367 { 3368 return NULL; 3369 } 3370 if (opoolObj != Py_None) 3371 { 3372 opool = (PyObj_pj_pool *)opoolObj; 3373 pool = opool->pool; 3374 } else { 3375 opool = NULL; 3376 pool = NULL; 3377 } 3378 if (oportObj != Py_None) 3379 { 3380 oport = (PyObj_pjmedia_port *)oportObj; 3381 port = oport->port; 3382 } else { 3383 oport = NULL; 3384 port = NULL; 3385 } 3386 3387 status = pjsua_conf_add_port(pool, port, &p_id); 3388 3389 3390 return Py_BuildValue("ii", status, p_id); 2321 PyObject *item = Py_BuildValue("i",info.listeners[i]); 2322 PyList_SetItem(ret->listeners, i, item); 2323 } 2324 return (PyObject*)ret; 3391 2325 } 3392 2326 … … 3394 2328 * py_pjsua_conf_remove_port 3395 2329 */ 3396 static PyObject *py_pjsua_conf_remove_port 3397 (PyObject *pSelf, PyObject *pArgs) 2330 static PyObject *py_pjsua_conf_remove_port(PyObject *pSelf, PyObject *pArgs) 3398 2331 { 3399 2332 int id; … … 3402 2335 PJ_UNUSED_ARG(pSelf); 3403 2336 3404 if (!PyArg_ParseTuple(pArgs, "i", &id)) 3405 { 2337 if (!PyArg_ParseTuple(pArgs, "i", &id)) { 3406 2338 return NULL; 3407 2339 } … … 3409 2341 status = pjsua_conf_remove_port(id); 3410 2342 3411 3412 2343 return Py_BuildValue("i", status); 3413 2344 } … … 3416 2347 * py_pjsua_conf_connect 3417 2348 */ 3418 static PyObject *py_pjsua_conf_connect 3419 (PyObject *pSelf, PyObject *pArgs) 2349 static PyObject *py_pjsua_conf_connect(PyObject *pSelf, PyObject *pArgs) 3420 2350 { 3421 2351 int source, sink; … … 3424 2354 PJ_UNUSED_ARG(pSelf); 3425 2355 3426 if (!PyArg_ParseTuple(pArgs, "ii", &source, &sink)) 3427 { 2356 if (!PyArg_ParseTuple(pArgs, "ii", &source, &sink)) { 3428 2357 return NULL; 3429 2358 } … … 3431 2360 status = pjsua_conf_connect(source, sink); 3432 2361 3433 3434 2362 return Py_BuildValue("i", status); 3435 2363 } … … 3438 2366 * py_pjsua_conf_disconnect 3439 2367 */ 3440 static PyObject *py_pjsua_conf_disconnect 3441 (PyObject *pSelf, PyObject *pArgs) 2368 static PyObject *py_pjsua_conf_disconnect(PyObject *pSelf, PyObject *pArgs) 3442 2369 { 3443 2370 int source, sink; … … 3446 2373 PJ_UNUSED_ARG(pSelf); 3447 2374 3448 if (!PyArg_ParseTuple(pArgs, "ii", &source, &sink)) 3449 { 2375 if (!PyArg_ParseTuple(pArgs, "ii", &source, &sink)) { 3450 2376 return NULL; 3451 2377 } … … 3453 2379 status = pjsua_conf_disconnect(source, sink); 3454 2380 3455 3456 2381 return Py_BuildValue("i", status); 3457 2382 } … … 3460 2385 * py_pjsua_conf_set_tx_level 3461 2386 */ 3462 static PyObject *py_pjsua_conf_set_tx_level 3463 (PyObject *pSelf, PyObject *pArgs) 2387 static PyObject *py_pjsua_conf_set_tx_level(PyObject *pSelf, PyObject *pArgs) 3464 2388 { 3465 2389 int slot; … … 3469 2393 PJ_UNUSED_ARG(pSelf); 3470 2394 3471 if (!PyArg_ParseTuple(pArgs, "if", &slot, &level)) 3472 { 2395 if (!PyArg_ParseTuple(pArgs, "if", &slot, &level)) { 3473 2396 return NULL; 3474 2397 } … … 3476 2399 status = pjsua_conf_adjust_tx_level(slot, level); 3477 2400 3478 3479 2401 return Py_BuildValue("i", status); 3480 2402 } … … 3483 2405 * py_pjsua_conf_set_rx_level 3484 2406 */ 3485 static PyObject *py_pjsua_conf_set_rx_level 3486 (PyObject *pSelf, PyObject *pArgs) 2407 static PyObject *py_pjsua_conf_set_rx_level(PyObject *pSelf, PyObject *pArgs) 3487 2408 { 3488 2409 int slot; … … 3492 2413 PJ_UNUSED_ARG(pSelf); 3493 2414 3494 if (!PyArg_ParseTuple(pArgs, "if", &slot, &level)) 3495 { 2415 if (!PyArg_ParseTuple(pArgs, "if", &slot, &level)) { 3496 2416 return NULL; 3497 2417 } … … 3499 2419 status = pjsua_conf_adjust_rx_level(slot, level); 3500 2420 3501 3502 2421 return Py_BuildValue("i", status); 3503 2422 } … … 3506 2425 * py_pjsua_conf_get_signal_level 3507 2426 */ 3508 static PyObject *py_pjsua_conf_get_signal_level 3509 (PyObject *pSelf,PyObject *pArgs)2427 static PyObject *py_pjsua_conf_get_signal_level(PyObject *pSelf, 2428 PyObject *pArgs) 3510 2429 { 3511 2430 int slot; … … 3515 2434 PJ_UNUSED_ARG(pSelf); 3516 2435 3517 if (!PyArg_ParseTuple(pArgs, "i", &slot)) 3518 { 2436 if (!PyArg_ParseTuple(pArgs, "i", &slot)) { 3519 2437 return NULL; 3520 2438 } … … 3522 2440 status = pjsua_conf_get_signal_level(slot, &tx_level, &rx_level); 3523 2441 3524 3525 2442 return Py_BuildValue("iff", status, (float)(tx_level/255.0), 3526 2443 (float)(rx_level/255.0)); 3527 2444 } 3528 2445 … … 3530 2447 * py_pjsua_player_create 3531 2448 */ 3532 static PyObject *py_pjsua_player_create 3533 (PyObject *pSelf, PyObject *pArgs) 2449 static PyObject *py_pjsua_player_create(PyObject *pSelf, PyObject *pArgs) 3534 2450 { 3535 2451 int id; 3536 2452 int options; 3537 PyObject * filename;3538 pj_str_t str;2453 PyObject *pFilename; 2454 pj_str_t filename; 3539 2455 int status; 3540 2456 3541 2457 PJ_UNUSED_ARG(pSelf); 3542 2458 3543 if (!PyArg_ParseTuple(pArgs, "Oi", &filename, &options)) 3544 { 3545 return NULL; 3546 } 3547 str.ptr = PyString_AsString(filename); 3548 str.slen = strlen(PyString_AsString(filename)); 3549 status = pjsua_player_create(&str, options, &id); 2459 if (!PyArg_ParseTuple(pArgs, "Oi", &pFilename, &options)) { 2460 return NULL; 2461 } 2462 2463 filename = PyString_ToPJ(pFilename); 2464 status = pjsua_player_create(&filename, options, &id); 3550 2465 3551 2466 return Py_BuildValue("ii", status, id); … … 3555 2470 * py_pjsua_playlist_create 3556 2471 */ 3557 static PyObject *py_pjsua_playlist_create 3558 (PyObject *pSelf, PyObject *pArgs) 2472 static PyObject *py_pjsua_playlist_create(PyObject *pSelf, PyObject *pArgs) 3559 2473 { 3560 2474 int id; 3561 2475 int options; 3562 PyObject * arg_label, *arg_filelist;2476 PyObject *pLabel, *pFileList; 3563 2477 pj_str_t label; 3564 2478 int count; … … 3568 2482 PJ_UNUSED_ARG(pSelf); 3569 2483 3570 if (!PyArg_ParseTuple(pArgs, "OOi", &arg_label, &arg_filelist, &options)) 3571 { 2484 if (!PyArg_ParseTuple(pArgs, "OOi", &pLabel, &pFileList, &options)) { 2485 return NULL; 2486 } 2487 2488 label = PyString_ToPJ(pLabel); 2489 if (!PyList_Check(pFileList)) 2490 return Py_BuildValue("ii", PJ_EINVAL, PJSUA_INVALID_ID); 2491 2492 count = 0; 2493 for (count=0; count<PyList_Size(pFileList) && 2494 count<PJ_ARRAY_SIZE(files); ++count) 2495 { 2496 files[count] = PyString_ToPJ(PyList_GetItem(pFileList, count)); 2497 } 2498 2499 status = pjsua_playlist_create(files, count, &label, options, &id); 2500 2501 return Py_BuildValue("ii", status, id); 2502 } 2503 2504 /* 2505 * py_pjsua_player_get_conf_port 2506 */ 2507 static PyObject *py_pjsua_player_get_conf_port(PyObject *pSelf, 2508 PyObject *pArgs) 2509 { 2510 2511 int id, port_id; 2512 2513 PJ_UNUSED_ARG(pSelf); 2514 2515 if (!PyArg_ParseTuple(pArgs, "i", &id)) { 3572 2516 return NULL; 3573 2517 } 3574 label.ptr = PyString_AsString(arg_label);3575 label.slen = PyString_Size(arg_label);3576 3577 if (!PyList_Check(arg_filelist))3578 return NULL;3579 3580 count = 0;3581 for (count=0; count<PyList_Size(arg_filelist) &&3582 count<PJ_ARRAY_SIZE(files); ++count)3583 {3584 files[count].ptr = PyString_AsString(PyList_GetItem(arg_filelist, count));3585 files[count].slen = PyString_Size(PyList_GetItem(arg_filelist, count));3586 }3587 3588 status = pjsua_playlist_create(files, count, &label, options, &id);3589 3590 return Py_BuildValue("ii", status, id);3591 }3592 3593 /*3594 * py_pjsua_player_get_conf_port3595 */3596 static PyObject *py_pjsua_player_get_conf_port3597 (PyObject *pSelf, PyObject *pArgs)3598 {3599 3600 int id, port_id;3601 3602 PJ_UNUSED_ARG(pSelf);3603 3604 if (!PyArg_ParseTuple(pArgs, "i", &id))3605 {3606 return NULL;3607 }3608 2518 3609 2519 port_id = pjsua_player_get_conf_port(id); 3610 2520 3611 3612 2521 return Py_BuildValue("i", port_id); 3613 2522 } … … 3616 2525 * py_pjsua_player_set_pos 3617 2526 */ 3618 static PyObject *py_pjsua_player_set_pos 3619 (PyObject *pSelf, PyObject *pArgs) 2527 static PyObject *py_pjsua_player_set_pos(PyObject *pSelf, PyObject *pArgs) 3620 2528 { 3621 2529 int id; 3622 pj_uint32_t samples;2530 int samples; 3623 2531 int status; 3624 2532 3625 2533 PJ_UNUSED_ARG(pSelf); 3626 2534 3627 if (!PyArg_ParseTuple(pArgs, "iI", &id, &samples)) 3628 { 2535 if (!PyArg_ParseTuple(pArgs, "ii", &id, &samples)) { 3629 2536 return NULL; 3630 2537 } 3631 2538 2539 if (samples < 0) 2540 samples = 0; 2541 3632 2542 status = pjsua_player_set_pos(id, samples); 3633 2543 3634 3635 2544 return Py_BuildValue("i", status); 3636 2545 } … … 3639 2548 * py_pjsua_player_destroy 3640 2549 */ 3641 static PyObject *py_pjsua_player_destroy 3642 (PyObject *pSelf, PyObject *pArgs) 2550 static PyObject *py_pjsua_player_destroy(PyObject *pSelf, PyObject *pArgs) 3643 2551 { 3644 2552 int id; … … 3647 2555 PJ_UNUSED_ARG(pSelf); 3648 2556 3649 if (!PyArg_ParseTuple(pArgs, "i", &id)) 3650 { 2557 if (!PyArg_ParseTuple(pArgs, "i", &id)) { 3651 2558 return NULL; 3652 2559 } … … 3654 2561 status = pjsua_player_destroy(id); 3655 2562 3656 3657 2563 return Py_BuildValue("i", status); 3658 2564 } … … 3660 2566 /* 3661 2567 * py_pjsua_recorder_create 3662 * !modified @ 261206 3663 */ 3664 static PyObject *py_pjsua_recorder_create 3665 (PyObject *pSelf, PyObject *pArgs) 2568 */ 2569 static PyObject *py_pjsua_recorder_create(PyObject *pSelf, PyObject *pArgs) 3666 2570 { 3667 int p_id; 3668 int options; 2571 int id, options; 3669 2572 int max_size; 3670 PyObject * filename; 3671 pj_str_t str; 3672 PyObject * enc_param; 3673 pj_str_t strparam; 2573 PyObject *pFilename, *pEncParam; 2574 pj_str_t filename; 3674 2575 int enc_type; 3675 2576 … … 3678 2579 PJ_UNUSED_ARG(pSelf); 3679 2580 3680 if (!PyArg_ParseTuple(pArgs, "OiOii", &filename, 3681 &enc_type, &enc_param, &max_size, &options)) 3682 { 2581 if (!PyArg_ParseTuple(pArgs, "OiOii", &pFilename, &enc_type, &pEncParam, 2582 &max_size, &options)) 2583 { 2584 return NULL; 2585 } 2586 2587 filename = PyString_ToPJ(pFilename); 2588 2589 status = pjsua_recorder_create(&filename, enc_type, NULL, max_size, 2590 options, &id); 2591 2592 return Py_BuildValue("ii", status, id); 2593 } 2594 2595 /* 2596 * py_pjsua_recorder_get_conf_port 2597 */ 2598 static PyObject *py_pjsua_recorder_get_conf_port(PyObject *pSelf, 2599 PyObject *pArgs) 2600 { 2601 2602 int id, port_id; 2603 2604 PJ_UNUSED_ARG(pSelf); 2605 2606 if (!PyArg_ParseTuple(pArgs, "i", &id)) { 3683 2607 return NULL; 3684 2608 } 3685 str.ptr = PyString_AsString(filename);3686 str.slen = strlen(PyString_AsString(filename));3687 if (enc_param != Py_None)3688 {3689 strparam.ptr = PyString_AsString(enc_param);3690 strparam.slen = strlen(PyString_AsString(enc_param));3691 status = pjsua_recorder_create3692 (&str, enc_type, NULL, max_size, options, &p_id);3693 } else {3694 status = pjsua_recorder_create3695 (&str, enc_type, NULL, max_size, options, &p_id);3696 }3697 return Py_BuildValue("ii", status, p_id);3698 }3699 3700 /*3701 * py_pjsua_recorder_get_conf_port3702 */3703 static PyObject *py_pjsua_recorder_get_conf_port3704 (PyObject *pSelf, PyObject *pArgs)3705 {3706 3707 int id, port_id;3708 3709 PJ_UNUSED_ARG(pSelf);3710 3711 if (!PyArg_ParseTuple(pArgs, "i", &id))3712 {3713 return NULL;3714 }3715 2609 3716 2610 port_id = pjsua_recorder_get_conf_port(id); 3717 2611 3718 3719 2612 return Py_BuildValue("i", port_id); 3720 2613 } … … 3723 2616 * py_pjsua_recorder_destroy 3724 2617 */ 3725 static PyObject *py_pjsua_recorder_destroy 3726 (PyObject *pSelf, PyObject *pArgs) 2618 static PyObject *py_pjsua_recorder_destroy(PyObject *pSelf, PyObject *pArgs) 3727 2619 { 3728 2620 int id; … … 3731 2623 PJ_UNUSED_ARG(pSelf); 3732 2624 3733 if (!PyArg_ParseTuple(pArgs, "i", &id)) 3734 { 2625 if (!PyArg_ParseTuple(pArgs, "i", &id)) { 3735 2626 return NULL; 3736 2627 } … … 3738 2629 status = pjsua_recorder_destroy(id); 3739 2630 3740 3741 2631 return Py_BuildValue("i", status); 3742 2632 } … … 3748 2638 { 3749 2639 pj_status_t status; 3750 PyObject *list; 3751 2640 PyObject *ret; 3752 2641 pjmedia_snd_dev_info info[SND_DEV_NUM]; 3753 2642 unsigned c, i; 3754 2643 3755 2644 PJ_UNUSED_ARG(pSelf); 3756 3757 if (!PyArg_ParseTuple(pArgs, "")) 3758 { 3759 return NULL; 3760 } 3761 2645 PJ_UNUSED_ARG(pArgs); 2646 3762 2647 c = PJ_ARRAY_SIZE(info); 3763 2648 status = pjsua_enum_snd_devs(info, &c); 3764 3765 list = PyList_New(c); 3766 for (i = 0; i < c; i++) 3767 { 3768 int ret; 3769 int j; 3770 char * str; 3771 2649 if (status != PJ_SUCCESS) 2650 c = 0; 2651 2652 ret = PyList_New(c); 2653 for (i = 0; i < c; i++) { 3772 2654 PyObj_pjmedia_snd_dev_info * obj; 3773 obj = (PyObj_pjmedia_snd_dev_info *)pjmedia_snd_dev_info_new 3774 (&PyTyp_pjmedia_snd_dev_info, NULL, NULL); 2655 2656 obj = (PyObj_pjmedia_snd_dev_info *) 2657 pjmedia_snd_dev_info_new(&PyTyp_pjmedia_snd_dev_info, 2658 NULL, NULL); 3775 2659 obj->default_samples_per_sec = info[i].default_samples_per_sec; 3776 2660 obj->input_count = info[i].input_count; 3777 2661 obj->output_count = info[i].output_count; 3778 str = (char *)malloc(SND_NAME_LEN * sizeof(char)); 3779 memset(str, 0, SND_NAME_LEN); 3780 for (j = 0; j < SND_NAME_LEN; j++) 3781 { 3782 str[j] = info[i].name[j]; 3783 } 3784 obj->name = PyString_FromStringAndSize(str, SND_NAME_LEN); 3785 free(str); 3786 ret = PyList_SetItem(list, i, (PyObject *)obj); 3787 if (ret == -1) 3788 { 3789 return NULL; 3790 } 3791 } 3792 3793 return Py_BuildValue("O",list); 2662 obj->name = PyString_FromString(info[i].name); 2663 2664 PyList_SetItem(ret, i, (PyObject *)obj); 2665 } 2666 2667 return (PyObject*)ret; 3794 2668 } 3795 2669 … … 3797 2671 * py_pjsua_get_snd_dev 3798 2672 */ 3799 static PyObject *py_pjsua_get_snd_dev 3800 (PyObject *pSelf, PyObject *pArgs) 2673 static PyObject *py_pjsua_get_snd_dev(PyObject *pSelf, PyObject *pArgs) 3801 2674 { 3802 2675 int capture_dev, playback_dev; … … 3804 2677 3805 2678 PJ_UNUSED_ARG(pSelf); 3806 3807 if (!PyArg_ParseTuple(pArgs, "")) 3808 { 3809 return NULL; 3810 } 3811 2679 PJ_UNUSED_ARG(pArgs); 2680 3812 2681 status = pjsua_get_snd_dev(&capture_dev, &playback_dev); 3813 2682 3814 3815 2683 return Py_BuildValue("ii", capture_dev, playback_dev); 3816 2684 } … … 3819 2687 * py_pjsua_set_snd_dev 3820 2688 */ 3821 static PyObject *py_pjsua_set_snd_dev 3822 (PyObject *pSelf, PyObject *pArgs) 2689 static PyObject *py_pjsua_set_snd_dev(PyObject *pSelf, PyObject *pArgs) 3823 2690 { 3824 2691 int capture_dev, playback_dev; … … 3827 2694 PJ_UNUSED_ARG(pSelf); 3828 2695 3829 if (!PyArg_ParseTuple(pArgs, "ii", &capture_dev, &playback_dev)) 3830 { 2696 if (!PyArg_ParseTuple(pArgs, "ii", &capture_dev, &playback_dev)) { 3831 2697 return NULL; 3832 2698 } … … 3834 2700 status = pjsua_set_snd_dev(capture_dev, playback_dev); 3835 2701 3836 3837 2702 return Py_BuildValue("i", status); 3838 2703 } … … 3841 2706 * py_pjsua_set_null_snd_dev 3842 2707 */ 3843 static PyObject *py_pjsua_set_null_snd_dev 3844 (PyObject *pSelf, PyObject *pArgs) 2708 static PyObject *py_pjsua_set_null_snd_dev(PyObject *pSelf, PyObject *pArgs) 3845 2709 { 3846 3847 2710 int status; 3848 3849 PJ_UNUSED_ARG(pSelf); 3850 3851 if (!PyArg_ParseTuple(pArgs, "")) 3852 { 3853 return NULL; 3854 } 3855 2711 2712 PJ_UNUSED_ARG(pSelf); 2713 PJ_UNUSED_ARG(pArgs); 2714 3856 2715 status = pjsua_set_null_snd_dev(); 3857 3858 2716 3859 2717 return Py_BuildValue("i", status); 3860 2718 } 3861 2719 3862 2720 /* 3863 * py_pjsua_set_no_snd_dev3864 */3865 static PyObject *py_pjsua_set_no_snd_dev3866 (PyObject *pSelf, PyObject *pArgs)3867 {3868 3869 PyObj_pjmedia_port * obj;3870 3871 PJ_UNUSED_ARG(pSelf);3872 3873 if (!PyArg_ParseTuple(pArgs, ""))3874 {3875 return NULL;3876 }3877 3878 obj = (PyObj_pjmedia_port *)PyType_GenericNew3879 (&PyTyp_pjmedia_port, NULL, NULL);3880 obj->port = pjsua_set_no_snd_dev();3881 return Py_BuildValue("O", obj);3882 }3883 3884 /*3885 2721 * py_pjsua_set_ec 3886 2722 */ 3887 static PyObject *py_pjsua_set_ec 3888 (PyObject *pSelf, PyObject *pArgs) 2723 static PyObject *py_pjsua_set_ec(PyObject *pSelf, PyObject *pArgs) 3889 2724 { 3890 2725 int options; … … 3894 2729 PJ_UNUSED_ARG(pSelf); 3895 2730 3896 if (!PyArg_ParseTuple(pArgs, "ii", &tail_ms, &options)) 3897 { 2731 if (!PyArg_ParseTuple(pArgs, "ii", &tail_ms, &options)) { 3898 2732 return NULL; 3899 2733 } 3900 2734 3901 2735 status = pjsua_set_ec(tail_ms, options); 3902 2736 3903 3904 2737 return Py_BuildValue("i", status); 3905 2738 } … … 3908 2741 * py_pjsua_get_ec_tail 3909 2742 */ 3910 static PyObject *py_pjsua_get_ec_tail 3911 (PyObject *pSelf, PyObject *pArgs) 2743 static PyObject *py_pjsua_get_ec_tail(PyObject *pSelf, PyObject *pArgs) 3912 2744 { 3913 3914 2745 int status; 3915 unsigned p_tail_ms; 3916 3917 PJ_UNUSED_ARG(pSelf); 3918 3919 if (!PyArg_ParseTuple(pArgs, "")) 3920 { 3921 return NULL; 3922 } 3923 3924 status = pjsua_get_ec_tail(&p_tail_ms); 3925 3926 3927 return Py_BuildValue("i", p_tail_ms); 2746 unsigned tail_ms; 2747 2748 PJ_UNUSED_ARG(pSelf); 2749 PJ_UNUSED_ARG(pArgs); 2750 2751 status = pjsua_get_ec_tail(&tail_ms); 2752 if (status != PJ_SUCCESS) 2753 tail_ms = 0; 2754 2755 return Py_BuildValue("i", tail_ms); 3928 2756 } 3929 2757 3930 2758 /* 3931 2759 * py_pjsua_enum_codecs 3932 * !modified @ 2612063933 2760 */ 3934 2761 static PyObject *py_pjsua_enum_codecs(PyObject *pSelf, PyObject *pArgs) 3935 2762 { 3936 2763 pj_status_t status; 3937 PyObject *list; 3938 2764 PyObject *ret; 3939 2765 pjsua_codec_info info[PJMEDIA_CODEC_MGR_MAX_CODECS]; 3940 2766 unsigned c, i; 3941 2767 3942 2768 PJ_UNUSED_ARG(pSelf); 3943 3944 if (!PyArg_ParseTuple(pArgs, "")) 3945 { 3946 return NULL; 3947 } 3948 2769 PJ_UNUSED_ARG(pArgs); 2770 3949 2771 c = PJ_ARRAY_SIZE(info); 3950 2772 status = pjsua_enum_codecs(info, &c); 3951 3952 list = PyList_New(c); 3953 for (i = 0; i < c; i++) 3954 { 3955 int ret; 3956 int j; 2773 if (status != PJ_SUCCESS) 2774 c = 0; 2775 2776 ret = PyList_New(c); 2777 for (i = 0; i < c; i++) { 3957 2778 PyObj_pjsua_codec_info * obj; 3958 obj = (PyObj_pjsua_codec_info *)codec_info_new 3959 (&PyTyp_pjsua_codec_info, NULL, NULL); 3960 obj->codec_id = PyString_FromStringAndSize 3961 (info[i].codec_id.ptr, info[i].codec_id.slen); 2779 obj = (PyObj_pjsua_codec_info *) 2780 codec_info_new(&PyTyp_pjsua_codec_info, NULL, NULL); 2781 obj->codec_id = PyString_FromPJ(&info[i].codec_id); 3962 2782 obj->priority = info[i].priority; 3963 for (j = 0; j < 32; j++) 3964 { 3965 obj->buf_[j] = info[i].buf_[j]; 3966 } 3967 ret = PyList_SetItem(list, i, (PyObject *)obj); 3968 if (ret == -1) { 3969 return NULL; 3970 } 3971 } 3972 3973 3974 return Py_BuildValue("O",list); 2783 2784 PyList_SetItem(ret, i, (PyObject *)obj); 2785 } 2786 2787 return (PyObject*)ret; 3975 2788 } 3976 2789 … … 3978 2791 * py_pjsua_codec_set_priority 3979 2792 */ 3980 static PyObject *py_pjsua_codec_set_priority 3981 (PyObject *pSelf, PyObject *pArgs) 2793 static PyObject *py_pjsua_codec_set_priority(PyObject *pSelf, PyObject *pArgs) 3982 2794 { 3983 3984 2795 int status; 3985 PyObject * id; 3986 pj_str_t str; 3987 pj_uint8_t priority; 3988 3989 PJ_UNUSED_ARG(pSelf); 3990 3991 if (!PyArg_ParseTuple(pArgs, "OB", &id, &priority)) 3992 { 2796 PyObject *pCodecId; 2797 pj_str_t codec_id; 2798 int priority; 2799 2800 PJ_UNUSED_ARG(pSelf); 2801 2802 if (!PyArg_ParseTuple(pArgs, "Oi", &pCodecId, &priority)) { 2803 return NULL; 2804 } 2805 2806 codec_id = PyString_ToPJ(pCodecId); 2807 if (priority < 0) 2808 priority = 0; 2809 if (priority > 255) 2810 priority = 255; 2811 2812 status = pjsua_codec_set_priority(&codec_id, (pj_uint8_t)priority); 2813 2814 return Py_BuildValue("i", status); 2815 } 2816 2817 /* 2818 * py_pjsua_codec_get_param 2819 */ 2820 static PyObject *py_pjsua_codec_get_param(PyObject *pSelf, PyObject *pArgs) 2821 { 2822 int status; 2823 PyObject *pCodecId; 2824 pj_str_t codec_id; 2825 pjmedia_codec_param param; 2826 PyObj_pjmedia_codec_param *ret; 2827 2828 PJ_UNUSED_ARG(pSelf); 2829 2830 if (!PyArg_ParseTuple(pArgs, "O", &pCodecId)) { 3993 2831 return NULL; 3994 2832 } 3995 str.ptr = PyString_AsString(id); 3996 str.slen = strlen(PyString_AsString(id)); 3997 status = pjsua_codec_set_priority(&str, priority); 3998 3999 4000 return Py_BuildValue("i", status); 4001 } 4002 4003 /* 4004 * py_pjsua_codec_get_param 4005 */ 4006 static PyObject *py_pjsua_codec_get_param 4007 (PyObject *pSelf, PyObject *pArgs) 2833 2834 codec_id = PyString_ToPJ(pCodecId); 2835 2836 status = pjsua_codec_get_param(&codec_id, ¶m); 2837 if (status != PJ_SUCCESS) 2838 return Py_BuildValue(""); 2839 2840 ret = (PyObj_pjmedia_codec_param *) 2841 pjmedia_codec_param_new(&PyTyp_pjmedia_codec_param, NULL, NULL); 2842 2843 ret->info->avg_bps = param.info.avg_bps; 2844 ret->info->channel_cnt = param.info.channel_cnt; 2845 ret->info->clock_rate = param.info.clock_rate; 2846 ret->info->frm_ptime = param.info.frm_ptime; 2847 ret->info->pcm_bits_per_sample = param.info.pcm_bits_per_sample; 2848 ret->info->pt = param.info.pt; 2849 ret->setting->cng = param.setting.cng; 2850 ret->setting->dec_fmtp_mode = param.setting.dec_fmtp_mode; 2851 ret->setting->enc_fmtp_mode = param.setting.enc_fmtp_mode; 2852 ret->setting->frm_per_pkt = param.setting.frm_per_pkt; 2853 ret->setting->penh = param.setting.penh; 2854 ret->setting->plc = param.setting.plc; 2855 ret->setting->vad = param.setting.vad; 2856 2857 return (PyObject*)ret; 2858 } 2859 2860 2861 /* 2862 * py_pjsua_codec_set_param 2863 */ 2864 static PyObject *py_pjsua_codec_set_param(PyObject *pSelf, PyObject *pArgs) 4008 2865 { 4009 4010 2866 int status; 4011 PyObject * id;4012 pj_str_t str;2867 PyObject *pCodecId, *pCodecParam; 2868 pj_str_t codec_id; 4013 2869 pjmedia_codec_param param; 4014 PyObj_pjmedia_codec_param *obj; 4015 4016 PJ_UNUSED_ARG(pSelf); 4017 4018 if (!PyArg_ParseTuple(pArgs, "O", &id)) 4019 { 2870 2871 PJ_UNUSED_ARG(pSelf); 2872 2873 if (!PyArg_ParseTuple(pArgs, "OO", &pCodecId, &pCodecParam)) { 4020 2874 return NULL; 4021 2875 } 4022 str.ptr = PyString_AsString(id); 4023 str.slen = strlen(PyString_AsString(id)); 4024 status = pjsua_codec_get_param(&str, ¶m); 4025 obj = (PyObj_pjmedia_codec_param *)pjmedia_codec_param_new 4026 (&PyTyp_pjmedia_codec_param, NULL, NULL); 4027 obj->info->avg_bps = param.info.avg_bps; 4028 obj->info->channel_cnt = param.info.channel_cnt; 4029 obj->info->clock_rate = param.info.clock_rate; 4030 obj->info->frm_ptime = param.info.frm_ptime; 4031 obj->info->pcm_bits_per_sample = param.info.pcm_bits_per_sample; 4032 obj->info->pt = param.info.pt; 4033 obj->setting->cng = param.setting.cng; 4034 obj->setting->dec_fmtp_mode = param.setting.dec_fmtp_mode; 4035 obj->setting->enc_fmtp_mode = param.setting.enc_fmtp_mode; 4036 obj->setting->frm_per_pkt = param.setting.frm_per_pkt; 4037 obj->setting->penh = param.setting.penh; 4038 obj->setting->plc = param.setting.plc; 4039 obj->setting->reserved = param.setting.reserved; 4040 obj->setting->vad = param.setting.vad; 4041 4042 return Py_BuildValue("O", obj); 4043 } 4044 /* 4045 * py_pjsua_codec_set_param 4046 */ 4047 static PyObject *py_pjsua_codec_set_param 4048 (PyObject *pSelf, PyObject *pArgs) 4049 { 4050 4051 int status; 4052 PyObject * id; 4053 pj_str_t str; 4054 pjmedia_codec_param param; 4055 PyObject * tmpObj; 4056 PyObj_pjmedia_codec_param *obj; 4057 4058 PJ_UNUSED_ARG(pSelf); 4059 4060 if (!PyArg_ParseTuple(pArgs, "OO", &id, &tmpObj)) 4061 { 4062 return NULL; 4063 } 4064 4065 str.ptr = PyString_AsString(id); 4066 str.slen = strlen(PyString_AsString(id)); 4067 if (tmpObj != Py_None) 4068 { 4069 obj = (PyObj_pjmedia_codec_param *)tmpObj; 2876 2877 codec_id = PyString_ToPJ(pCodecId); 2878 2879 if (pCodecParam != Py_None) { 2880 PyObj_pjmedia_codec_param *obj; 2881 2882 obj = (PyObj_pjmedia_codec_param *)pCodecParam; 2883 4070 2884 param.info.avg_bps = obj->info->avg_bps; 4071 2885 param.info.channel_cnt = obj->info->channel_cnt; … … 4080 2894 param.setting.penh = obj->setting->penh; 4081 2895 param.setting.plc = obj->setting->plc; 4082 param.setting.reserved = obj->setting->reserved;4083 2896 param.setting.vad = obj->setting->vad; 4084 status = pjsua_codec_set_param(&str, ¶m); 2897 status = pjsua_codec_set_param(&codec_id, ¶m); 2898 4085 2899 } else { 4086 status = pjsua_codec_set_param(&str, NULL); 4087 } 2900 status = pjsua_codec_set_param(&codec_id, NULL); 2901 } 2902 4088 2903 return Py_BuildValue("i", status); 4089 2904 } … … 4101 2916 "_pjsua.Conf_Port_Info _pjsua.conf_get_port_info (int id) " 4102 2917 "Get information about the specified conference port"; 4103 static char pjsua_conf_add_port_doc[] =4104 "int, int _pjsua.conf_add_port "4105 "(_pjsua.Pj_Pool pool, _pjsua.PJMedia_Port port) "4106 "Add arbitrary media port to PJSUA's conference bridge. "4107 "Application can use this function to add the media port "4108 "that it creates. For media ports that are created by PJSUA-LIB "4109 "(such as calls, file player, or file recorder), PJSUA-LIB will "4110 "automatically add the port to the bridge.";4111 2918 static char pjsua_conf_remove_port_doc[] = 4112 2919 "int _pjsua.conf_remove_port (int id) " … … 4173 2980 "provides the timing needed by the conference bridge, and will not " 4174 2981 "interract with any hardware."; 4175 static char pjsua_set_no_snd_dev_doc[] =4176 "_pjsua.PJMedia_Port _pjsua.set_no_snd_dev () "4177 "Disconnect the main conference bridge from any sound devices, "4178 "and let application connect the bridge to it's "4179 "own sound device/master port.";4180 2982 static char pjsua_set_ec_doc[] = 4181 2983 "int _pjsua.set_ec (int tail_ms, int options) " … … 4203 3005 4204 3006 /* 4205 * PyObj_pj_time_val4206 * PJ Time Val4207 */4208 typedef struct4209 {4210 PyObject_HEAD4211 /* Type-specific fields go here. */4212 long sec;4213 long msec;4214 4215 } PyObj_pj_time_val;4216 4217 4218 4219 /*4220 * pj_time_val_members4221 */4222 static PyMemberDef pj_time_val_members[] =4223 {4224 4225 {4226 "sec", T_INT,4227 offsetof(PyObj_pj_time_val, sec), 0,4228 "The seconds part of the time"4229 },4230 {4231 "msec", T_INT,4232 offsetof(PyObj_pj_time_val, sec), 0,4233 "The milliseconds fraction of the time"4234 },4235 4236 4237 {NULL} /* Sentinel */4238 };4239 4240 4241 4242 4243 /*4244 * PyTyp_pj_time_val4245 */4246 static PyTypeObject PyTyp_pj_time_val =4247 {4248 PyObject_HEAD_INIT(NULL)4249 0, /*ob_size*/4250 "_pjsua.PJ_Time_Val", /*tp_name*/4251 sizeof(PyObj_pj_time_val), /*tp_basicsize*/4252 0, /*tp_itemsize*/4253 0,/*tp_dealloc*/4254 0, /*tp_print*/4255 0, /*tp_getattr*/4256 0, /*tp_setattr*/4257 0, /*tp_compare*/4258 0, /*tp_repr*/4259 0, /*tp_as_number*/4260 0, /*tp_as_sequence*/4261 0, /*tp_as_mapping*/4262 0, /*tp_hash */4263 0, /*tp_call*/4264 0, /*tp_str*/4265 0, /*tp_getattro*/4266 0, /*tp_setattro*/4267 0, /*tp_as_buffer*/4268 Py_TPFLAGS_DEFAULT, /*tp_flags*/4269 "PJ Time Val objects", /* tp_doc */4270 0, /* tp_traverse */4271 0, /* tp_clear */4272 0, /* tp_richcompare */4273 0, /* tp_weaklistoffset */4274 0, /* tp_iter */4275 0, /* tp_iternext */4276 0, /* tp_methods */4277 pj_time_val_members, /* tp_members */4278 4279 4280 };4281 4282 /*4283 * PyObj_pjsua_call_info4284 * Call Info4285 */4286 typedef struct4287 {4288 PyObject_HEAD4289 /* Type-specific fields go here. */4290 4291 int id;4292 int role;4293 int acc_id;4294 PyObject * local_info;4295 PyObject * local_contact;4296 PyObject * remote_info;4297 PyObject * remote_contact;4298 PyObject * call_id;4299 int state;4300 PyObject * state_text;4301 int last_status;4302 PyObject * last_status_text;4303 int media_status;4304 int media_dir;4305 int conf_slot;4306 PyObj_pj_time_val * connect_duration;4307 PyObj_pj_time_val * total_duration;4308 struct {4309 char local_info[128];4310 char local_contact[128];4311 char remote_info[128];4312 char remote_contact[128];4313 char call_id[128];4314 char last_status_text[128];4315 } buf_;4316 4317 } PyObj_pjsua_call_info;4318 4319 4320 /*4321 * call_info_dealloc4322 * deletes a call_info from memory4323 */4324 static void call_info_dealloc(PyObj_pjsua_call_info* self)4325 {4326 Py_XDECREF(self->local_info);4327 Py_XDECREF(self->local_contact);4328 Py_XDECREF(self->remote_info);4329 Py_XDECREF(self->remote_contact);4330 Py_XDECREF(self->call_id);4331 Py_XDECREF(self->state_text);4332 Py_XDECREF(self->last_status_text);4333 Py_XDECREF(self->connect_duration);4334 Py_XDECREF(self->total_duration);4335 self->ob_type->tp_free((PyObject*)self);4336 }4337 4338 4339 /*4340 * call_info_new4341 * constructor for call_info object4342 */4343 static PyObject * call_info_new(PyTypeObject *type, PyObject *args,4344 PyObject *kwds)4345 {4346 PyObj_pjsua_call_info *self;4347 4348 PJ_UNUSED_ARG(args);4349 PJ_UNUSED_ARG(kwds);4350 4351 self = (PyObj_pjsua_call_info *)type->tp_alloc(type, 0);4352 if (self != NULL)4353 {4354 self->local_info = PyString_FromString("");4355 if (self->local_info == NULL)4356 {4357 Py_DECREF(self);4358 return NULL;4359 }4360 self->local_contact = PyString_FromString("");4361 if (self->local_contact == NULL)4362 {4363 Py_DECREF(self);4364 return NULL;4365 }4366 self->remote_info = PyString_FromString("");4367 if (self->remote_info == NULL)4368 {4369 Py_DECREF(self);4370 return NULL;4371 }4372 self->remote_contact = PyString_FromString("");4373 if (self->remote_contact == NULL)4374 {4375 Py_DECREF(self);4376 return NULL;4377 }4378 self->call_id = PyString_FromString("");4379 if (self->call_id == NULL)4380 {4381 Py_DECREF(self);4382 return NULL;4383 }4384 self->state_text = PyString_FromString("");4385 if (self->state_text == NULL)4386 {4387 Py_DECREF(self);4388 return NULL;4389 }4390 self->last_status_text = PyString_FromString("");4391 if (self->last_status_text == NULL)4392 {4393 Py_DECREF(self);4394 return NULL;4395 }4396 self->connect_duration = (PyObj_pj_time_val *)PyType_GenericNew4397 (&PyTyp_pj_time_val,NULL,NULL);4398 if (self->connect_duration == NULL)4399 {4400 Py_DECREF(self);4401 return NULL;4402 }4403 self->total_duration = (PyObj_pj_time_val *)PyType_GenericNew4404 (&PyTyp_pj_time_val,NULL,NULL);4405 if (self->total_duration == NULL)4406 {4407 Py_DECREF(self);4408 return NULL;4409 }4410 }4411 return (PyObject *)self;4412 }4413 4414 /*4415 * call_info_members4416 */4417 static PyMemberDef call_info_members[] =4418 {4419 {4420 "id", T_INT,4421 offsetof(PyObj_pjsua_call_info, id), 0,4422 "Call identification"4423 },4424 {4425 "role", T_INT,4426 offsetof(PyObj_pjsua_call_info, role), 0,4427 "Initial call role (UAC == caller)"4428 },4429 {4430 "acc_id", T_INT,4431 offsetof(PyObj_pjsua_call_info, acc_id), 0,4432 "The account ID where this call belongs."4433 },4434 {4435 "local_info", T_OBJECT_EX,4436 offsetof(PyObj_pjsua_call_info, local_info), 0,4437 "Local URI"4438 },4439 {4440 "local_contact", T_OBJECT_EX,4441 offsetof(PyObj_pjsua_call_info, local_contact), 0,4442 "Local Contact"4443 },4444 {4445 "remote_info", T_OBJECT_EX,4446 offsetof(PyObj_pjsua_call_info, remote_info), 0,4447 "Remote URI"4448 },4449 {4450 "remote_contact", T_OBJECT_EX,4451 offsetof(PyObj_pjsua_call_info, remote_contact), 0,4452 "Remote Contact"4453 },4454 {4455 "call_id", T_OBJECT_EX,4456 offsetof(PyObj_pjsua_call_info, call_id), 0,4457 "Dialog Call-ID string"4458 },4459 {4460 "state", T_INT,4461 offsetof(PyObj_pjsua_call_info, state), 0,4462 "Call state"4463 },4464 {4465 "state_text", T_OBJECT_EX,4466 offsetof(PyObj_pjsua_call_info, state_text), 0,4467 "Text describing the state "4468 },4469 {4470 "last_status", T_INT,4471 offsetof(PyObj_pjsua_call_info, last_status), 0,4472 "Last status code heard, which can be used as cause code"4473 },4474 {4475 "last_status_text", T_OBJECT_EX,4476 offsetof(PyObj_pjsua_call_info, last_status_text), 0,4477 "The reason phrase describing the status."4478 },4479 {4480 "media_status", T_INT,4481 offsetof(PyObj_pjsua_call_info, media_status), 0,4482 "Call media status."4483 },4484 {4485 "media_dir", T_INT,4486 offsetof(PyObj_pjsua_call_info, media_dir), 0,4487 "Media direction"4488 },4489 {4490 "conf_slot", T_INT,4491 offsetof(PyObj_pjsua_call_info, conf_slot), 0,4492 "The conference port number for the call"4493 },4494 {4495 "connect_duration", T_OBJECT_EX,4496 offsetof(PyObj_pjsua_call_info, connect_duration), 0,4497 "Up-to-date call connected duration(zero when call is not established)"4498 },4499 {4500 "total_duration", T_OBJECT_EX,4501 offsetof(PyObj_pjsua_call_info, total_duration), 0,4502 "Total call duration, including set-up time"4503 },4504 4505 {NULL} /* Sentinel */4506 };4507 4508 4509 4510 4511 /*4512 * PyTyp_pjsua_call_info4513 */4514 static PyTypeObject PyTyp_pjsua_call_info =4515 {4516 PyObject_HEAD_INIT(NULL)4517 0, /*ob_size*/4518 "_pjsua.Call_Info", /*tp_name*/4519 sizeof(PyObj_pjsua_call_info), /*tp_basicsize*/4520 0, /*tp_itemsize*/4521 (destructor)call_info_dealloc,/*tp_dealloc*/4522 0, /*tp_print*/4523 0, /*tp_getattr*/4524 0, /*tp_setattr*/4525 0, /*tp_compare*/4526 0, /*tp_repr*/4527 0, /*tp_as_number*/4528 0, /*tp_as_sequence*/4529 0, /*tp_as_mapping*/4530 0, /*tp_hash */4531 0, /*tp_call*/4532 0, /*tp_str*/4533 0, /*tp_getattro*/4534 0, /*tp_setattro*/4535 0, /*tp_as_buffer*/4536 Py_TPFLAGS_DEFAULT, /*tp_flags*/4537 "Call Info objects", /* tp_doc */4538 0, /* tp_traverse */4539 0, /* tp_clear */4540 0, /* tp_richcompare */4541 0, /* tp_weaklistoffset */4542 0, /* tp_iter */4543 0, /* tp_iternext */4544 0, /* tp_methods */4545 call_info_members, /* tp_members */4546 0, /* tp_getset */4547 0, /* tp_base */4548 0, /* tp_dict */4549 0, /* tp_descr_get */4550 0, /* tp_descr_set */4551 0, /* tp_dictoffset */4552 0, /* tp_init */4553 0, /* tp_alloc */4554 call_info_new, /* tp_new */4555 4556 };4557 4558 /*4559 3007 * py_pjsua_call_get_max_count 4560 3008 */ 4561 static PyObject *py_pjsua_call_get_max_count 4562 (PyObject *pSelf, PyObject *pArgs) 3009 static PyObject *py_pjsua_call_get_max_count(PyObject *pSelf, PyObject *pArgs) 4563 3010 { 4564 3011 int count; 4565 3012 4566 3013 PJ_UNUSED_ARG(pSelf); 4567 4568 if (!PyArg_ParseTuple(pArgs, "")) 4569 { 4570 return NULL; 4571 } 4572 3014 PJ_UNUSED_ARG(pArgs); 3015 4573 3016 count = pjsua_call_get_max_count(); 4574 3017 4575 4576 3018 return Py_BuildValue("i", count); 4577 3019 } … … 4580 3022 * py_pjsua_call_get_count 4581 3023 */ 4582 static PyObject *py_pjsua_call_get_count 4583 (PyObject *pSelf, PyObject *pArgs) 3024 static PyObject *py_pjsua_call_get_count(PyObject *pSelf, PyObject *pArgs) 4584 3025 { 4585 4586 3026 int count; 4587 3027 4588 3028 PJ_UNUSED_ARG(pSelf); 4589 4590 if (!PyArg_ParseTuple(pArgs, "")) 4591 { 4592 return NULL; 4593 } 4594 3029 PJ_UNUSED_ARG(pArgs); 3030 4595 3031 count = pjsua_call_get_count(); 4596 3032 4597 4598 3033 return Py_BuildValue("i", count); 4599 3034 } … … 4605 3040 { 4606 3041 pj_status_t status; 4607 PyObject *list; 4608 3042 PyObject *ret; 4609 3043 pjsua_transport_id id[PJSUA_MAX_CALLS]; 4610 3044 unsigned c, i; 4611 3045 4612 3046 PJ_UNUSED_ARG(pSelf); 4613 4614 if (!PyArg_ParseTuple(pArgs, "")) 4615 { 4616 return NULL; 4617 } 4618 3047 PJ_UNUSED_ARG(pArgs); 3048 4619 3049 c = PJ_ARRAY_SIZE(id); 4620 3050 status = pjsua_enum_calls(id, &c); 4621 4622 list = PyList_New(c); 4623 for (i = 0; i < c; i++) 4624 { 4625 int ret = PyList_SetItem(list, i, Py_BuildValue("i", id[i])); 4626 if (ret == -1) 4627 { 4628 return NULL; 4629 } 4630 } 4631 4632 return Py_BuildValue("O",list); 3051 if (status != PJ_SUCCESS) 3052 c = 0; 3053 3054 ret = PyList_New(c); 3055 for (i = 0; i < c; i++) { 3056 PyList_SetItem(ret, i, Py_BuildValue("i", id[i])); 3057 } 3058 3059 return (PyObject*)ret; 4633 3060 } 4634 3061 … … 4636 3063 * py_pjsua_call_make_call 4637 3064 */ 4638 static PyObject *py_pjsua_call_make_call 4639 (PyObject *pSelf, PyObject *pArgs) 3065 static PyObject *py_pjsua_call_make_call(PyObject *pSelf, PyObject *pArgs) 4640 3066 { 4641 3067 int status; 4642 3068 int acc_id; 4643 3069 pj_str_t dst_uri; 4644 PyObject * sd;3070 PyObject *pDstUri, *pMsgData, *pUserData; 4645 3071 unsigned options; 4646 3072 pjsua_msg_data msg_data; 4647 PyObject * omdObj;4648 PyObj_pjsua_msg_data * omd;4649 int user_data;4650 3073 int call_id; 4651 pj_pool_t * pool;4652 4653 PJ_UNUSED_ARG(pSelf); 4654 4655 if (!PyArg_ParseTuple 4656 (pArgs, "iOIiO", &acc_id, &sd, &options, &user_data, &omdObj))3074 pj_pool_t *pool = NULL; 3075 3076 PJ_UNUSED_ARG(pSelf); 3077 3078 if (!PyArg_ParseTuple(pArgs, "iOIOO", &acc_id, &pDstUri, &options, 3079 &pUserData, &pMsgData)) 4657 3080 { 4658 3081 return NULL; 4659 3082 } 4660 3083 4661 dst_uri .ptr = PyString_AsString(sd);4662 dst_uri.slen = strlen(PyString_AsString(sd));4663 if (omdObj != Py_None) 4664 {4665 omd = (PyObj_pjsua_msg_data *)omdObj;4666 msg_data.content_type.ptr = PyString_AsString(omd->content_type); 4667 msg_data.content_type.slen = strlen4668 (PyString_AsString(omd->content_type)); 4669 msg_data. msg_body.ptr = PyString_AsString(omd->msg_body);4670 msg_data.msg_body .slen = strlen(PyString_AsString(omd->msg_body));4671 pool = pjsua_pool_create("p jsua", POOL_SIZE, POOL_SIZE);3084 dst_uri = PyString_ToPJ(pDstUri); 3085 pjsua_msg_data_init(&msg_data); 3086 3087 if (pMsgData != Py_None) { 3088 PyObj_pjsua_msg_data * omd; 3089 3090 omd = (PyObj_pjsua_msg_data *)pMsgData; 3091 3092 msg_data.content_type = PyString_ToPJ(omd->content_type); 3093 msg_data.msg_body = PyString_ToPJ(omd->msg_body); 3094 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE); 4672 3095 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list); 4673 status = pjsua_call_make_call(acc_id, &dst_uri, 4674 options, (void*)user_data, &msg_data, &call_id); 4675 pj_pool_release(pool); 4676 } else { 4677 4678 status = pjsua_call_make_call(acc_id, &dst_uri, 4679 options, (void*)user_data, NULL, &call_id); 4680 } 4681 4682 return Py_BuildValue("ii",status, call_id); 4683 3096 } 3097 3098 Py_XINCREF(pUserData); 3099 3100 status = pjsua_call_make_call(acc_id, &dst_uri, 3101 options, (void*)pUserData, 3102 &msg_data, &call_id); 3103 if (pool != NULL) 3104 pj_pool_release(pool); 3105 3106 if (status != PJ_SUCCESS) 3107 Py_XDECREF(pUserData); 3108 3109 return Py_BuildValue("ii", status, call_id); 4684 3110 } 4685 3111 … … 4687 3113 * py_pjsua_call_is_active 4688 3114 */ 4689 static PyObject *py_pjsua_call_is_active 4690 (PyObject *pSelf, PyObject *pArgs) 3115 static PyObject *py_pjsua_call_is_active(PyObject *pSelf, PyObject *pArgs) 4691 3116 { 4692 3117 int call_id; 4693 int isActive; 4694 4695 PJ_UNUSED_ARG(pSelf); 4696 4697 if (!PyArg_ParseTuple(pArgs, "i", &call_id)) 4698 { 3118 int is_active; 3119 3120 PJ_UNUSED_ARG(pSelf); 3121 3122 if (!PyArg_ParseTuple(pArgs, "i", &call_id)) { 4699 3123 return NULL; 4700 3124 } 4701 3125 4702 isActive = pjsua_call_is_active(call_id); 4703 4704 4705 return Py_BuildValue("i", isActive); 3126 is_active = pjsua_call_is_active(call_id); 3127 3128 return Py_BuildValue("i", is_active); 4706 3129 } 4707 3130 … … 4709 3132 * py_pjsua_call_has_media 4710 3133 */ 4711 static PyObject *py_pjsua_call_has_media 4712 (PyObject *pSelf, PyObject *pArgs) 3134 static PyObject *py_pjsua_call_has_media(PyObject *pSelf, PyObject *pArgs) 4713 3135 { 4714 3136 int call_id; 4715 int hasMedia; 4716 4717 PJ_UNUSED_ARG(pSelf); 4718 4719 if (!PyArg_ParseTuple(pArgs, "i", &call_id)) 4720 { 3137 int has_media; 3138 3139 PJ_UNUSED_ARG(pSelf); 3140 3141 if (!PyArg_ParseTuple(pArgs, "i", &call_id)) { 4721 3142 return NULL; 4722 3143 } 4723 3144 4724 hasMedia = pjsua_call_has_media(call_id); 4725 4726 4727 return Py_BuildValue("i", hasMedia); 3145 has_media = pjsua_call_has_media(call_id); 3146 3147 return Py_BuildValue("i", has_media); 4728 3148 } 4729 3149 … … 4731 3151 * py_pjsua_call_get_conf_port 4732 3152 */ 4733 static PyObject *py_pjsua_call_get_conf_port 4734 (PyObject *pSelf, PyObject *pArgs) 3153 static PyObject* py_pjsua_call_get_conf_port(PyObject *pSelf, PyObject *pArgs) 4735 3154 { 4736 3155 int call_id; 4737 int port_id; 4738 4739 PJ_UNUSED_ARG(pSelf); 4740 4741 if (!PyArg_ParseTuple(pArgs, "i", &call_id)) 4742 { 4743 return NULL; 4744 } 4745 3156 int port_id; 3157 3158 PJ_UNUSED_ARG(pSelf); 3159 3160 if (!PyArg_ParseTuple(pArgs, "i", &call_id)) { 3161 return NULL; 3162 } 3163 4746 3164 port_id = pjsua_call_get_conf_port(call_id); 4747 4748 3165 4749 3166 return Py_BuildValue("i", port_id); 4750 3167 } … … 4753 3170 * py_pjsua_call_get_info 4754 3171 */ 4755 static PyObject *py_pjsua_call_get_info 4756 (PyObject *pSelf, PyObject *pArgs) 3172 static PyObject* py_pjsua_call_get_info(PyObject *pSelf, PyObject *pArgs) 4757 3173 { 4758 3174 int call_id; 4759 3175 int status; 4760 PyObj_pjsua_call_info * oi;3176 PyObj_pjsua_call_info *ret; 4761 3177 pjsua_call_info info; 4762 3178 4763 3179 PJ_UNUSED_ARG(pSelf); 4764 3180 4765 if (!PyArg_ParseTuple(pArgs, "i", &call_id)) 4766 { 3181 if (!PyArg_ParseTuple(pArgs, "i", &call_id)) { 4767 3182 return NULL; 4768 3183 } 4769 3184 4770 4771 3185 status = pjsua_call_get_info(call_id, &info); 4772 if (status == PJ_SUCCESS) 4773 { 4774 oi = (PyObj_pjsua_call_info *)call_info_new(&PyTyp_pjsua_call_info, NULL, NULL); 4775 oi->acc_id = info.acc_id; 4776 pj_ansi_snprintf(oi->buf_.call_id, sizeof(oi->buf_.call_id), 4777 "%.*s", (int)info.call_id.slen, info.call_id.ptr); 4778 pj_ansi_snprintf(oi->buf_.last_status_text, 4779 sizeof(oi->buf_.last_status_text), 4780 "%.*s", (int)info.last_status_text.slen, info.last_status_text.ptr); 4781 pj_ansi_snprintf(oi->buf_.local_contact, sizeof(oi->buf_.local_contact), 4782 "%.*s", (int)info.local_contact.slen, info.local_contact.ptr); 4783 pj_ansi_snprintf(oi->buf_.local_info, sizeof(oi->buf_.local_info), 4784 "%.*s", (int)info.local_info.slen, info.local_info.ptr); 4785 pj_ansi_snprintf(oi->buf_.remote_contact, 4786 sizeof(oi->buf_.remote_contact), 4787 "%.*s", (int)info.remote_contact.slen, info.remote_contact.ptr); 4788 pj_ansi_snprintf(oi->buf_.remote_info, sizeof(oi->buf_.remote_info), 4789 "%.*s", (int)info.remote_info.slen, info.remote_info.ptr); 4790 4791 oi->call_id = PyString_FromStringAndSize(info.call_id.ptr, 4792 info.call_id.slen); 4793 oi->conf_slot = info.conf_slot; 4794 oi->connect_duration->sec = info.connect_duration.sec; 4795 oi->connect_duration->msec = info.connect_duration.msec; 4796 oi->total_duration->sec = info.total_duration.sec; 4797 oi->total_duration->msec = info.total_duration.msec; 4798 oi->id = info.id; 4799 oi->last_status = info.last_status; 4800 oi->last_status_text = PyString_FromStringAndSize( 4801 info.last_status_text.ptr, info.last_status_text.slen); 4802 oi->local_contact = PyString_FromStringAndSize( 4803 info.local_contact.ptr, info.local_contact.slen); 4804 oi->local_info = PyString_FromStringAndSize( 4805 info.local_info.ptr, info.local_info.slen); 4806 oi->remote_contact = PyString_FromStringAndSize( 4807 info.remote_contact.ptr, info.remote_contact.slen); 4808 oi->remote_info = PyString_FromStringAndSize( 4809 info.remote_info.ptr, info.remote_info.slen); 4810 oi->media_dir = info.media_dir; 4811 oi->media_status = info.media_status; 4812 oi->role = info.role; 4813 oi->state = info.state; 4814 oi->state_text = PyString_FromStringAndSize( 4815 info.state_text.ptr, info.state_text.slen); 4816 4817 return Py_BuildValue("O", oi); 4818 } else { 4819 Py_INCREF(Py_None); 4820 return Py_None; 4821 } 3186 if (status != PJ_SUCCESS) 3187 return Py_BuildValue(""); 3188 3189 ret = (PyObj_pjsua_call_info *)call_info_new(&PyTyp_pjsua_call_info, 3190 NULL, NULL); 3191 ret->acc_id = info.acc_id; 3192 Py_XDECREF(ret->call_id); 3193 ret->call_id = PyString_FromPJ(&info.call_id); 3194 ret->conf_slot = info.conf_slot; 3195 ret->connect_duration = info.connect_duration.sec * 1000 + 3196 info.connect_duration.msec; 3197 ret->total_duration = info.total_duration.sec * 1000 + 3198 info.total_duration.msec; 3199 ret->id = info.id; 3200 ret->last_status = info.last_status; 3201 Py_XDECREF(ret->last_status_text); 3202 ret->last_status_text = PyString_FromPJ(&info.last_status_text); 3203 Py_XDECREF(ret->local_contact); 3204 ret->local_contact = PyString_FromPJ(&info.local_contact); 3205 Py_XDECREF(ret->local_info); 3206 ret->local_info = PyString_FromPJ(&info.local_info); 3207 Py_XDECREF(ret->remote_contact); 3208 ret->remote_contact = PyString_FromPJ(&info.remote_contact); 3209 Py_XDECREF(ret->remote_info); 3210 ret->remote_info = PyString_FromPJ(&info.remote_info); 3211 ret->media_dir = info.media_dir; 3212 ret->media_status = info.media_status; 3213 ret->role = info.role; 3214 ret->state = info.state; 3215 Py_XDECREF(ret->state_text); 3216 ret->state_text = PyString_FromPJ(&info.state_text); 3217 3218 return (PyObject*)ret; 4822 3219 } 4823 3220 … … 4825 3222 * py_pjsua_call_set_user_data 4826 3223 */ 4827 static PyObject *py_pjsua_call_set_user_data 4828 (PyObject *pSelf, PyObject *pArgs) 3224 static PyObject *py_pjsua_call_set_user_data(PyObject *pSelf, PyObject *pArgs) 4829 3225 { 4830 3226 int call_id; 4831 int user_data;3227 PyObject *pUserData, *old_user_data; 4832 3228 int status; 4833 3229 4834 3230 PJ_UNUSED_ARG(pSelf); 4835 3231 4836 if (!PyArg_ParseTuple(pArgs, "ii", &call_id, &user_data)) 4837 { 4838 return NULL; 4839 } 4840 4841 status = pjsua_call_set_user_data(call_id, (void*)user_data); 4842 4843 3232 if (!PyArg_ParseTuple(pArgs, "iO", &call_id, &pUserData)) { 3233 return NULL; 3234 } 3235 3236 old_user_data = (PyObject*) pjsua_call_get_user_data(call_id); 3237 3238 if (old_user_data == pUserData) { 3239 return Py_BuildValue("i", PJ_SUCCESS); 3240 } 3241 3242 Py_XINCREF(pUserData); 3243 Py_XDECREF(old_user_data); 3244 3245 status = pjsua_call_set_user_data(call_id, (void*)pUserData); 3246 3247 if (status != PJ_SUCCESS) 3248 Py_XDECREF(pUserData); 3249 4844 3250 return Py_BuildValue("i", status); 4845 3251 } … … 4848 3254 * py_pjsua_call_get_user_data 4849 3255 */ 4850 static PyObject *py_pjsua_call_get_user_data 4851 (PyObject *pSelf, PyObject *pArgs) 3256 static PyObject *py_pjsua_call_get_user_data(PyObject *pSelf, PyObject *pArgs) 4852 3257 { 4853 3258 int call_id; 4854 void * user_data; 4855 4856 PJ_UNUSED_ARG(pSelf); 4857 4858 if (!PyArg_ParseTuple(pArgs, "i", &call_id)) 4859 { 3259 PyObject *user_data; 3260 3261 PJ_UNUSED_ARG(pSelf); 3262 3263 if (!PyArg_ParseTuple(pArgs, "i", &call_id)) { 4860 3264 return NULL; 4861 3265 } 4862 3266 4863 user_data = pjsua_call_get_user_data(call_id); 4864 4865 4866 return Py_BuildValue("i", (int)user_data); 3267 user_data = (PyObject*)pjsua_call_get_user_data(call_id); 3268 return user_data ? Py_BuildValue("O", user_data) : Py_BuildValue(""); 4867 3269 } 4868 3270 … … 4870 3272 * py_pjsua_call_answer 4871 3273 */ 4872 static PyObject *py_pjsua_call_answer 4873 (PyObject *pSelf, PyObject *pArgs) 3274 static PyObject *py_pjsua_call_answer(PyObject *pSelf, PyObject *pArgs) 4874 3275 { 4875 3276 int status; 4876 3277 int call_id; 4877 3278 pj_str_t * reason, tmp_reason; 4878 PyObject * sr;3279 PyObject *pReason; 4879 3280 unsigned code; 4880 3281 pjsua_msg_data msg_data; 4881 3282 PyObject * omdObj; 4882 PyObj_pjsua_msg_data * omd; 4883 pj_pool_t * pool; 4884 4885 PJ_UNUSED_ARG(pSelf); 4886 4887 if (!PyArg_ParseTuple(pArgs, "iIOO", &call_id, &code, &sr, &omdObj)) 4888 { 4889 return NULL; 4890 } 4891 if (sr == Py_None) 4892 { 3283 pj_pool_t * pool = NULL; 3284 3285 PJ_UNUSED_ARG(pSelf); 3286 3287 if (!PyArg_ParseTuple(pArgs, "iIOO", &call_id, &code, &pReason, &omdObj)) { 3288 return NULL; 3289 } 3290 3291 if (pReason == Py_None) { 4893 3292 reason = NULL; 4894 3293 } else { 4895 3294 reason = &tmp_reason; 4896 tmp_reason.ptr = PyString_AsString(sr); 4897 tmp_reason.slen = strlen(PyString_AsString(sr)); 4898 } 4899 if (omdObj != Py_None) 4900 { 3295 tmp_reason = PyString_ToPJ(pReason); 3296 } 3297 3298 pjsua_msg_data_init(&msg_data); 3299 if (omdObj != Py_None) { 3300 PyObj_pjsua_msg_data *omd; 3301 4901 3302 omd = (PyObj_pjsua_msg_data *)omdObj; 4902 msg_data.content_type.ptr = PyString_AsString(omd->content_type); 4903 msg_data.content_type.slen = strlen 4904 (PyString_AsString(omd->content_type)); 4905 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body); 4906 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body)); 4907 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE); 3303 msg_data.content_type = PyString_ToPJ(omd->content_type); 3304 msg_data.msg_body = PyString_ToPJ(omd->msg_body); 3305 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE); 4908 3306 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list); 4909 4910 status = pjsua_call_answer(call_id, code, reason, &msg_data); 4911 4912 pj_pool_release(pool); 4913 } else { 4914 4915 status = pjsua_call_answer(call_id, code, reason, NULL); 4916 4917 } 4918 4919 return Py_BuildValue("i",status); 3307 } 3308 3309 status = pjsua_call_answer(call_id, code, reason, &msg_data); 3310 3311 if (pool) 3312 pj_pool_release(pool); 3313 3314 return Py_BuildValue("i", status); 4920 3315 } 4921 3316 … … 4923 3318 * py_pjsua_call_hangup 4924 3319 */ 4925 static PyObject *py_pjsua_call_hangup 4926 (PyObject *pSelf, PyObject *pArgs) 3320 static PyObject *py_pjsua_call_hangup(PyObject *pSelf, PyObject *pArgs) 4927 3321 { 4928 3322 int status; 4929 3323 int call_id; 4930 pj_str_t * 4931 PyObject * sr;3324 pj_str_t *reason, tmp_reason; 3325 PyObject *pReason; 4932 3326 unsigned code; 4933 3327 pjsua_msg_data msg_data; 4934 PyObject * 4935 PyObj_pjsua_msg_data * omd;4936 pj_pool_t * pool = NULL; 4937 4938 PJ_UNUSED_ARG(pSelf); 4939 4940 if (!PyArg_ParseTuple(pArgs, "iIOO", &call_id, &code, &sr,&omdObj))4941 { 4942 return NULL; 4943 } 4944 if (sr == Py_None) 4945 {3328 PyObject *omdObj; 3329 pj_pool_t *pool = NULL; 3330 3331 PJ_UNUSED_ARG(pSelf); 3332 3333 if (!PyArg_ParseTuple(pArgs, "iIOO", &call_id, &code, &pReason, 3334 &omdObj)) 3335 { 3336 return NULL; 3337 } 3338 3339 if (pReason == Py_None) { 4946 3340 reason = NULL; 4947 3341 } else { 4948 3342 reason = &tmp_reason; 4949 tmp_reason.ptr = PyString_AsString(sr); 4950 tmp_reason.slen = strlen(PyString_AsString(sr)); 4951 } 4952 if (omdObj != Py_None) 4953 { 3343 tmp_reason = PyString_ToPJ(pReason); 3344 } 3345 3346 pjsua_msg_data_init(&msg_data); 3347 if (omdObj != Py_None) { 3348 PyObj_pjsua_msg_data *omd; 3349 4954 3350 omd = (PyObj_pjsua_msg_data *)omdObj; 4955 msg_data.content_type.ptr = PyString_AsString(omd->content_type); 4956 msg_data.content_type.slen = strlen 4957 (PyString_AsString(omd->content_type)); 4958 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body); 4959 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body)); 4960 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE); 3351 msg_data.content_type = PyString_ToPJ(omd->content_type); 3352 msg_data.msg_body = PyString_ToPJ(omd->msg_body); 3353 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE); 4961 3354 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list); 4962 status = pjsua_call_hangup(call_id, code, reason, &msg_data);4963 pj_pool_release(pool);4964 } else {4965 status = pjsua_call_hangup(call_id, code, reason, NULL);4966 } 4967 4968 return Py_BuildValue("i", status);3355 } 3356 3357 status = pjsua_call_hangup(call_id, code, reason, &msg_data); 3358 if (pool) 3359 pj_pool_release(pool); 3360 3361 return Py_BuildValue("i", status); 4969 3362 } 4970 3363 … … 4972 3365 * py_pjsua_call_set_hold 4973 3366 */ 4974 static PyObject *py_pjsua_call_set_hold 4975 (PyObject *pSelf, PyObject *pArgs) 3367 static PyObject *py_pjsua_call_set_hold(PyObject *pSelf, PyObject *pArgs) 4976 3368 { 4977 3369 int status; 4978 3370 int call_id; 4979 3371 pjsua_msg_data msg_data; 4980 PyObject * 4981 PyObj_pjsua_msg_data * omd;4982 pj_pool_t * pool; 4983 4984 PJ_UNUSED_ARG(pSelf); 4985 4986 if (!PyArg_ParseTuple(pArgs, "iO", &call_id, &omdObj))4987 {4988 return NULL; 4989 }4990 4991 if (omdObj != Py_None)4992 { 3372 PyObject *omdObj; 3373 pj_pool_t *pool = NULL; 3374 3375 PJ_UNUSED_ARG(pSelf); 3376 3377 if (!PyArg_ParseTuple(pArgs, "iO", &call_id, &omdObj)) { 3378 return NULL; 3379 } 3380 3381 pjsua_msg_data_init(&msg_data); 3382 if (omdObj != Py_None) { 3383 PyObj_pjsua_msg_data *omd; 3384 4993 3385 omd = (PyObj_pjsua_msg_data *)omdObj; 4994 msg_data.content_type.ptr = PyString_AsString(omd->content_type); 4995 msg_data.content_type.slen = strlen 4996 (PyString_AsString(omd->content_type)); 4997 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body); 4998 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body)); 4999 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE); 3386 msg_data.content_type = PyString_ToPJ(omd->content_type); 3387 msg_data.msg_body = PyString_ToPJ(omd->msg_body); 3388 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE); 5000 3389 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list); 5001 status = pjsua_call_set_hold(call_id, &msg_data); 3390 } 3391 3392 status = pjsua_call_set_hold(call_id, &msg_data); 3393 3394 if (pool) 5002 3395 pj_pool_release(pool); 5003 } else { 5004 status = pjsua_call_set_hold(call_id, NULL); 5005 } 3396 5006 3397 return Py_BuildValue("i",status); 5007 3398 } … … 5010 3401 * py_pjsua_call_reinvite 5011 3402 */ 5012 static PyObject *py_pjsua_call_reinvite 5013 (PyObject *pSelf, PyObject *pArgs) 3403 static PyObject *py_pjsua_call_reinvite(PyObject *pSelf, PyObject *pArgs) 5014 3404 { 5015 3405 int status; 5016 int call_id; 3406 int call_id; 5017 3407 int unhold; 5018 3408 pjsua_msg_data msg_data; 5019 PyObject * 5020 PyObj_pjsua_msg_data * omd;5021 pj_pool_t * pool; 5022 5023 PJ_UNUSED_ARG(pSelf); 5024 5025 if (!PyArg_ParseTuple(pArgs, "iiO", &call_id, &unhold, &omdObj))5026 {5027 return NULL; 5028 }5029 5030 if (omdObj != Py_None) 5031 { 3409 PyObject *omdObj; 3410 pj_pool_t *pool = NULL; 3411 3412 PJ_UNUSED_ARG(pSelf); 3413 3414 if (!PyArg_ParseTuple(pArgs, "iiO", &call_id, &unhold, &omdObj)) { 3415 return NULL; 3416 } 3417 3418 pjsua_msg_data_init(&msg_data); 3419 if (omdObj != Py_None) { 3420 PyObj_pjsua_msg_data *omd; 3421 5032 3422 omd = (PyObj_pjsua_msg_data *)omdObj; 5033 msg_data.content_type.ptr = PyString_AsString(omd->content_type); 5034 msg_data.content_type.slen = strlen 5035 (PyString_AsString(omd->content_type)); 5036 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body); 5037 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body)); 5038 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE); 3423 msg_data.content_type = PyString_ToPJ(omd->content_type); 3424 msg_data.msg_body = PyString_ToPJ(omd->msg_body); 3425 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE); 5039 3426 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list); 5040 status = pjsua_call_reinvite(call_id, unhold, &msg_data); 3427 } 3428 3429 status = pjsua_call_reinvite(call_id, unhold, &msg_data); 3430 3431 if (pool) 5041 3432 pj_pool_release(pool); 5042 } else { 5043 status = pjsua_call_reinvite(call_id, unhold, NULL); 5044 } 5045 return Py_BuildValue("i",status); 3433 3434 return Py_BuildValue("i", status); 5046 3435 } 5047 3436 … … 5049 3438 * py_pjsua_call_update 5050 3439 */ 5051 static PyObject *py_pjsua_call_update 5052 (PyObject *pSelf, PyObject *pArgs) 3440 static PyObject *py_pjsua_call_update(PyObject *pSelf, PyObject *pArgs) 5053 3441 { 5054 3442 int status; … … 5056 3444 int option; 5057 3445 pjsua_msg_data msg_data; 5058 PyObject * 5059 PyObj_pjsua_msg_data * omd;5060 pj_pool_t * pool; 5061 5062 PJ_UNUSED_ARG(pSelf); 5063 5064 if (!PyArg_ParseTuple(pArgs, "iiO", &call_id, &option, &omdObj))5065 {5066 return NULL; 5067 }5068 5069 if (omdObj != Py_None) 5070 { 3446 PyObject *omdObj; 3447 pj_pool_t *pool = NULL; 3448 3449 PJ_UNUSED_ARG(pSelf); 3450 3451 if (!PyArg_ParseTuple(pArgs, "iiO", &call_id, &option, &omdObj)) { 3452 return NULL; 3453 } 3454 3455 pjsua_msg_data_init(&msg_data); 3456 if (omdObj != Py_None) { 3457 PyObj_pjsua_msg_data *omd; 3458 5071 3459 omd = (PyObj_pjsua_msg_data *)omdObj; 5072 msg_data.content_type.ptr = PyString_AsString(omd->content_type); 5073 msg_data.content_type.slen = strlen 5074 (PyString_AsString(omd->content_type)); 5075 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body); 5076 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body)); 5077 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE); 3460 msg_data.content_type = PyString_ToPJ(omd->content_type); 3461 msg_data.msg_body = PyString_ToPJ(omd->msg_body); 3462 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE); 5078 3463 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list); 5079 status = pjsua_call_update(call_id, option, &msg_data); 3464 } 3465 3466 status = pjsua_call_update(call_id, option, &msg_data); 3467 3468 if (pool) 5080 3469 pj_pool_release(pool); 5081 } else { 5082 status = pjsua_call_update(call_id, option, NULL); 5083 } 5084 return Py_BuildValue("i",status); 3470 3471 return Py_BuildValue("i", status); 5085 3472 } 5086 3473 … … 5088 3475 * py_pjsua_call_send_request 5089 3476 */ 5090 static PyObject *py_pjsua_call_send_request 5091 (PyObject *pSelf, PyObject *pArgs) 3477 static PyObject *py_pjsua_call_send_request(PyObject *pSelf, PyObject *pArgs) 5092 3478 { 5093 3479 int status; 5094 3480 int call_id; 5095 PyObject * method_obj;3481 PyObject *pMethod; 5096 3482 pj_str_t method; 5097 3483 pjsua_msg_data msg_data; 5098 PyObject * omdObj; 5099 PyObj_pjsua_msg_data * omd; 5100 pj_pool_t * pool; 5101 5102 PJ_UNUSED_ARG(pSelf); 5103 5104 if (!PyArg_ParseTuple(pArgs, "iOO", &call_id, &method_obj, &omdObj)) 5105 { 5106 return NULL; 5107 } 5108 5109 if (!PyString_Check(method_obj)) { 3484 PyObject *omdObj; 3485 pj_pool_t *pool = NULL; 3486 3487 PJ_UNUSED_ARG(pSelf); 3488 3489 if (!PyArg_ParseTuple(pArgs, "iOO", &call_id, &pMethod, &omdObj)) { 3490 return NULL; 3491 } 3492 3493 if (!PyString_Check(pMethod)) { 5110 3494 return NULL; 5111 3495 } 5112 3496 5113 method.ptr = PyString_AsString(method_obj); 5114 method.slen = PyString_Size(method_obj); 5115 5116 if (omdObj != Py_None) 5117 { 3497 method = PyString_ToPJ(pMethod); 3498 pjsua_msg_data_init(&msg_data); 3499 3500 if (omdObj != Py_None) { 3501 PyObj_pjsua_msg_data *omd; 3502 5118 3503 omd = (PyObj_pjsua_msg_data *)omdObj; 5119 msg_data.content_type.ptr = PyString_AsString(omd->content_type); 5120 msg_data.content_type.slen = strlen 5121 (PyString_AsString(omd->content_type)); 5122 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body); 5123 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body)); 5124 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE); 3504 msg_data.content_type = PyString_ToPJ(omd->content_type); 3505 msg_data.msg_body = PyString_ToPJ(omd->msg_body); 3506 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE); 5125 3507 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list); 5126 status = pjsua_call_send_request(call_id, &method, &msg_data); 3508 } 3509 3510 status = pjsua_call_send_request(call_id, &method, &msg_data); 3511 3512 if (pool) 5127 3513 pj_pool_release(pool); 5128 } else { 5129 status = pjsua_call_send_request(call_id, &method, NULL); 5130 } 5131 return Py_BuildValue("i",status); 3514 3515 return Py_BuildValue("i", status); 5132 3516 } 5133 3517 … … 5135 3519 * py_pjsua_call_xfer 5136 3520 */ 5137 static PyObject *py_pjsua_call_xfer 5138 (PyObject *pSelf, PyObject *pArgs) 3521 static PyObject *py_pjsua_call_xfer(PyObject *pSelf, PyObject *pArgs) 5139 3522 { 5140 3523 int status; 5141 3524 int call_id; 5142 3525 pj_str_t dest; 5143 PyObject * sd;3526 PyObject *pDstUri; 5144 3527 pjsua_msg_data msg_data; 5145 PyObject * omdObj; 5146 PyObj_pjsua_msg_data * omd; 5147 pj_pool_t * pool; 5148 5149 PJ_UNUSED_ARG(pSelf); 5150 5151 if (!PyArg_ParseTuple(pArgs, "iOO", &call_id, &sd, &omdObj)) 5152 { 5153 return NULL; 5154 } 5155 5156 dest.ptr = PyString_AsString(sd); 5157 dest.slen = strlen(PyString_AsString(sd)); 5158 5159 if (omdObj != Py_None) 5160 { 3528 PyObject *omdObj; 3529 pj_pool_t *pool = NULL; 3530 3531 PJ_UNUSED_ARG(pSelf); 3532 3533 if (!PyArg_ParseTuple(pArgs, "iOO", &call_id, &pDstUri, &omdObj)) { 3534 return NULL; 3535 } 3536 3537 if (!PyString_Check(pDstUri)) 3538 return NULL; 3539 3540 dest = PyString_ToPJ(pDstUri); 3541 pjsua_msg_data_init(&msg_data); 3542 3543 if (omdObj != Py_None) { 3544 PyObj_pjsua_msg_data *omd; 3545 5161 3546 omd = (PyObj_pjsua_msg_data *)omdObj; 5162 msg_data.content_type.ptr = PyString_AsString(omd->content_type); 5163 msg_data.content_type.slen = strlen 5164 (PyString_AsString(omd->content_type)); 5165 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body); 5166 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body)); 5167 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE); 3547 msg_data.content_type = PyString_ToPJ(omd->content_type); 3548 msg_data.msg_body = PyString_ToPJ(omd->msg_body); 3549 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE); 5168 3550 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list); 5169 status = pjsua_call_xfer(call_id, &dest, &msg_data); 3551 } 3552 3553 status = pjsua_call_xfer(call_id, &dest, &msg_data); 3554 3555 if (pool) 5170 3556 pj_pool_release(pool); 5171 } else { 5172 status = pjsua_call_xfer(call_id, &dest, NULL); 5173 } 5174 return Py_BuildValue("i",status); 3557 3558 return Py_BuildValue("i", status); 5175 3559 } 5176 3560 … … 5178 3562 * py_pjsua_call_xfer_replaces 5179 3563 */ 5180 static PyObject *py_pjsua_call_xfer_replaces 5181 (PyObject *pSelf, PyObject *pArgs) 3564 static PyObject *py_pjsua_call_xfer_replaces(PyObject *pSelf, PyObject *pArgs) 5182 3565 { 5183 3566 int status; … … 5186 3569 unsigned options; 5187 3570 pjsua_msg_data msg_data; 5188 PyObject * omdObj; 5189 PyObj_pjsua_msg_data * omd; 5190 pj_pool_t * pool; 5191 5192 PJ_UNUSED_ARG(pSelf); 5193 5194 if (!PyArg_ParseTuple 5195 (pArgs, "iiIO", &call_id, &dest_call_id, &options, &omdObj)) 5196 { 5197 return NULL; 5198 } 5199 5200 if (omdObj != Py_None) 5201 { 5202 omd = (PyObj_pjsua_msg_data *)omdObj; 5203 msg_data.content_type.ptr = PyString_AsString(omd->content_type); 5204 msg_data.content_type.slen = strlen 5205 (PyString_AsString(omd->content_type)); 5206 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body); 5207 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body)); 5208 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE); 3571 PyObject *omdObj; 3572 pj_pool_t *pool = NULL; 3573 3574 PJ_UNUSED_ARG(pSelf); 3575 3576 if (!PyArg_ParseTuple(pArgs, "iiIO", &call_id, &dest_call_id, 3577 &options, &omdObj)) 3578 { 3579 return NULL; 3580 } 3581 3582 pjsua_msg_data_init(&msg_data); 3583 3584 if (omdObj != Py_None) { 3585 PyObj_pjsua_msg_data *omd; 3586 3587 omd = (PyObj_pjsua_msg_data *)omdObj; 3588 msg_data.content_type = PyString_ToPJ(omd->content_type); 3589 msg_data.msg_body = PyString_ToPJ(omd->msg_body); 3590 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE); 5209 3591 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list); 5210 status = pjsua_call_xfer_replaces 5211 (call_id, dest_call_id, options, &msg_data); 5212 pj_pool_release(pool); 5213 } else { 5214 status = pjsua_call_xfer_replaces(call_id, dest_call_id,options, NULL); 5215 } 5216 return Py_BuildValue("i",status); 3592 } 3593 3594 status = pjsua_call_xfer_replaces(call_id, dest_call_id, options, 3595 &msg_data); 3596 3597 if (pool) 3598 pj_pool_release(pool); 3599 3600 return Py_BuildValue("i", status); 5217 3601 } 5218 3602 … … 5220 3604 * py_pjsua_call_dial_dtmf 5221 3605 */ 5222 static PyObject *py_pjsua_call_dial_dtmf 5223 (PyObject *pSelf, PyObject *pArgs) 3606 static PyObject *py_pjsua_call_dial_dtmf(PyObject *pSelf, PyObject *pArgs) 5224 3607 { 5225 3608 int call_id; 5226 PyObject * sd;3609 PyObject *pDigits; 5227 3610 pj_str_t digits; 5228 3611 int status; … … 5230 3613 PJ_UNUSED_ARG(pSelf); 5231 3614 5232 if (!PyArg_ParseTuple(pArgs, "iO", &call_id, &sd)) 5233 { 5234 return NULL; 5235 } 5236 digits.ptr = PyString_AsString(sd); 5237 digits.slen = strlen(PyString_AsString(sd)); 3615 if (!PyArg_ParseTuple(pArgs, "iO", &call_id, &pDigits)) { 3616 return NULL; 3617 } 3618 3619 if (!PyString_Check(pDigits)) 3620 return Py_BuildValue("i", PJ_EINVAL); 3621 3622 digits = PyString_ToPJ(pDigits); 5238 3623 status = pjsua_call_dial_dtmf(call_id, &digits); 5239 3624 … … 5244 3629 * py_pjsua_call_send_im 5245 3630 */ 5246 static PyObject *py_pjsua_call_send_im 5247 (PyObject *pSelf, PyObject *pArgs) 3631 static PyObject *py_pjsua_call_send_im(PyObject *pSelf, PyObject *pArgs) 5248 3632 { 5249 3633 int status; … … 5251 3635 pj_str_t content; 5252 3636 pj_str_t * mime_type, tmp_mime_type; 5253 PyObject * sm; 5254 PyObject * sc; 3637 PyObject *pMimeType, *pContent, *omdObj; 5255 3638 pjsua_msg_data msg_data; 5256 PyObject * omdObj;5257 PyObj_pjsua_msg_data * omd;5258 3639 int user_data; 5259 pj_pool_t * pool; 5260 5261 PJ_UNUSED_ARG(pSelf); 5262 5263 if (!PyArg_ParseTuple 5264 (pArgs, "iOOOi", &call_id, &sm, &sc, &omdObj, &user_data)) 5265 { 5266 return NULL; 5267 } 5268 if (sm == Py_None) 5269 { 5270 mime_type = NULL; 3640 pj_pool_t *pool = NULL; 3641 3642 PJ_UNUSED_ARG(pSelf); 3643 3644 if (!PyArg_ParseTuple(pArgs, "iOOOi", &call_id, &pMimeType, &pContent, 3645 &omdObj, &user_data)) 3646 { 3647 return NULL; 3648 } 3649 3650 if (!PyString_Check(pContent)) 3651 return Py_BuildValue("i", PJ_EINVAL); 3652 3653 content = PyString_ToPJ(pContent); 3654 3655 if (PyString_Check(pMimeType)) { 3656 mime_type = &tmp_mime_type; 3657 tmp_mime_type = PyString_ToPJ(pMimeType); 5271 3658 } else { 5272 mime_type = &tmp_mime_type; 5273 tmp_mime_type.ptr = PyString_AsString(sm); 5274 tmp_mime_type.slen = strlen(PyString_AsString(sm)); 5275 } 5276 content.ptr = PyString_AsString(sc); 5277 content.slen = strlen(PyString_AsString(sc)); 5278 5279 if (omdObj != Py_None) 5280 { 3659 mime_type = NULL; 3660 } 3661 3662 pjsua_msg_data_init(&msg_data); 3663 if (omdObj != Py_None) { 3664 PyObj_pjsua_msg_data * omd; 3665 5281 3666 omd = (PyObj_pjsua_msg_data *)omdObj; 5282 msg_data.content_type.ptr = PyString_AsString(omd->content_type); 5283 msg_data.content_type.slen = strlen 5284 (PyString_AsString(omd->content_type)); 5285 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body); 5286 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body)); 5287 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE); 3667 msg_data.content_type = PyString_ToPJ(omd->content_type); 3668 msg_data.msg_body = PyString_ToPJ(omd->msg_body); 3669 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE); 5288 3670 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list); 5289 status = pjsua_call_send_im 5290 (call_id, mime_type, &content, &msg_data, (void *)user_data); 3671 } 3672 3673 status = pjsua_call_send_im(call_id, mime_type, &content, 3674 &msg_data, (void *)user_data); 3675 3676 if (pool) 5291 3677 pj_pool_release(pool); 5292 } else { 5293 status = pjsua_call_send_im 5294 (call_id, mime_type, &content, NULL, (void *)user_data); 5295 } 5296 5297 return Py_BuildValue("i",status); 3678 3679 return Py_BuildValue("i", status); 5298 3680 } 5299 3681 … … 5301 3683 * py_pjsua_call_send_typing_ind 5302 3684 */ 5303 static PyObject *py_pjsua_call_send_typing_ind 5304 (PyObject *pSelf,PyObject *pArgs)3685 static PyObject *py_pjsua_call_send_typing_ind(PyObject *pSelf, 3686 PyObject *pArgs) 5305 3687 { 5306 3688 int status; … … 5308 3690 int is_typing; 5309 3691 pjsua_msg_data msg_data; 5310 PyObject * omdObj; 5311 PyObj_pjsua_msg_data * omd; 5312 pj_pool_t * pool; 5313 5314 PJ_UNUSED_ARG(pSelf); 5315 5316 if (!PyArg_ParseTuple(pArgs, "iiO", &call_id, &is_typing, &omdObj)) 5317 { 3692 PyObject *omdObj; 3693 pj_pool_t *pool = NULL; 3694 3695 PJ_UNUSED_ARG(pSelf); 3696 3697 if (!PyArg_ParseTuple(pArgs, "iiO", &call_id, &is_typing, &omdObj)) { 5318 3698 return NULL; 5319 3699 } 5320 3700 5321 if (omdObj != Py_None) 5322 { 3701 pjsua_msg_data_init(&msg_data); 3702 if (omdObj != Py_None) { 3703 PyObj_pjsua_msg_data *omd; 3704 5323 3705 omd = (PyObj_pjsua_msg_data *)omdObj; 5324 msg_data.content_type.ptr = PyString_AsString(omd->content_type); 5325 msg_data.content_type.slen = strlen 5326 (PyString_AsString(omd->content_type)); 5327 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body); 5328 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body)); 5329 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE); 3706 msg_data.content_type = PyString_ToPJ(omd->content_type); 3707 msg_data.msg_body = PyString_ToPJ(omd->msg_body); 3708 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE); 5330 3709 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list); 5331 status = pjsua_call_send_typing_ind(call_id, is_typing, &msg_data); 3710 } 3711 3712 status = pjsua_call_send_typing_ind(call_id, is_typing, &msg_data); 3713 3714 if (pool) 5332 3715 pj_pool_release(pool); 5333 } else { 5334 status = pjsua_call_send_typing_ind(call_id, is_typing, NULL); 5335 } 5336 return Py_BuildValue("i",status); 3716 3717 return Py_BuildValue("i", status); 5337 3718 } 5338 3719 … … 5340 3721 * py_pjsua_call_hangup_all 5341 3722 */ 5342 static PyObject *py_pjsua_call_hangup_all 5343 (PyObject *pSelf, PyObject *pArgs) 3723 static PyObject *py_pjsua_call_hangup_all(PyObject *pSelf, PyObject *pArgs) 5344 3724 { 5345 5346 PJ_UNUSED_ARG(pSelf); 5347 5348 if (!PyArg_ParseTuple(pArgs, "")) 5349 { 5350 return NULL; 5351 } 5352 3725 PJ_UNUSED_ARG(pSelf); 3726 PJ_UNUSED_ARG(pArgs); 3727 5353 3728 pjsua_call_hangup_all(); 5354 3729 5355 Py_INCREF(Py_None); 5356 return Py_None; 3730 return Py_BuildValue(""); 5357 3731 } 5358 3732 … … 5360 3734 * py_pjsua_call_dump 5361 3735 */ 5362 static PyObject *py_pjsua_call_dump 5363 (PyObject *pSelf, PyObject *pArgs) 3736 static PyObject *py_pjsua_call_dump(PyObject *pSelf, PyObject *pArgs) 5364 3737 { 5365 3738 int call_id; 5366 3739 int with_media; 5367 PyObject * sb;5368 PyObject * si;5369 char * 5370 char * 3740 PyObject *ret; 3741 PyObject *pIndent; 3742 char *buffer; 3743 char *indent; 5371 3744 unsigned maxlen; 5372 3745 int status; … … 5374 3747 PJ_UNUSED_ARG(pSelf); 5375 3748 5376 if (!PyArg_ParseTuple(pArgs, "iiIO", &call_id, &with_media, &maxlen, &si)) 3749 if (!PyArg_ParseTuple(pArgs, "iiIO", &call_id, &with_media, 3750 &maxlen, &pIndent)) 5377 3751 { 5378 3752 return NULL; 5379 3753 } 5380 buffer = (char *) malloc (maxlen * sizeof(char)); 5381 indent = PyString_AsString(si); 3754 3755 buffer = (char*) malloc(maxlen * sizeof(char)); 3756 indent = PyString_AsString(pIndent); 5382 3757 5383 3758 status = pjsua_call_dump(call_id, with_media, buffer, maxlen, indent); 5384 sb = PyString_FromStringAndSize(buffer, maxlen); 3759 if (status != PJ_SUCCESS) { 3760 free(buffer); 3761 return PyString_FromString(""); 3762 } 3763 3764 ret = PyString_FromString(buffer); 5385 3765 free(buffer); 5386 return Py_BuildValue("O", sb);3766 return (PyObject*)ret; 5387 3767 } 5388 3768 … … 5394 3774 static PyObject *py_pjsua_dump(PyObject *pSelf, PyObject *pArgs) 5395 3775 { 5396 unsigned old_decor;5397 char buf[1024];5398 3776 int detail; 5399 3777 5400 3778 PJ_UNUSED_ARG(pSelf); 5401 3779 5402 if (!PyArg_ParseTuple(pArgs, "i", &detail)) 5403 { 3780 if (!PyArg_ParseTuple(pArgs, "i", &detail)) { 5404 3781 return NULL; 5405 3782 } 5406 3783 5407 PJ_LOG(3,(THIS_FILE, "Start dumping application states:")); 5408 5409 old_decor = pj_log_get_decor(); 5410 pj_log_set_decor(old_decor & (PJ_LOG_HAS_NEWLINE | PJ_LOG_HAS_CR)); 5411 5412 if (detail) 5413 pj_dump_config(); 5414 5415 pjsip_endpt_dump(pjsua_get_pjsip_endpt(), detail); 5416 pjmedia_endpt_dump(pjsua_get_pjmedia_endpt()); 5417 pjsip_tsx_layer_dump(detail); 5418 pjsip_ua_dump(detail); 5419 5420 5421 /* Dump all invite sessions: */ 5422 PJ_LOG(3,(THIS_FILE, "Dumping invite sessions:")); 5423 5424 if (pjsua_call_get_count() == 0) { 5425 5426 PJ_LOG(3,(THIS_FILE, " - no sessions -")); 5427 5428 } else { 5429 unsigned i, max; 5430 5431 max = pjsua_call_get_max_count(); 5432 for (i=0; i<max; ++i) { 5433 if (pjsua_call_is_active(i)) { 5434 pjsua_call_dump(i, detail, buf, sizeof(buf), " "); 5435 PJ_LOG(3,(THIS_FILE, "%s", buf)); 5436 } 5437 } 5438 } 5439 5440 /* Dump presence status */ 5441 pjsua_pres_dump(detail); 5442 5443 pj_log_set_decor(old_decor); 5444 PJ_LOG(3,(THIS_FILE, "Dump complete")); 5445 5446 Py_INCREF(Py_None); 5447 return Py_None; 3784 pjsua_dump(detail); 3785 3786 return Py_BuildValue(""); 5448 3787 } 5449 3788 … … 5456 3795 int err; 5457 3796 char err_msg[PJ_ERR_MSG_SIZE]; 5458 5459 PJ_UNUSED_ARG(pSelf); 5460 5461 if (!PyArg_ParseTuple(pArgs, "i", &err)) 5462 {5463 return NULL; 5464 } 5465 5466 pj_strerror(err, err_msg, sizeof(err_msg));5467 5468 return PyString_FromString (err_msg);3797 pj_str_t ret; 3798 3799 PJ_UNUSED_ARG(pSelf); 3800 3801 if (!PyArg_ParseTuple(pArgs, "i", &err)) { 3802 return NULL; 3803 } 3804 3805 ret = pj_strerror(err, err_msg, sizeof(err_msg)); 3806 3807 return PyString_FromStringAndSize(err_msg, ret.slen); 5469 3808 } 5470 3809 … … 5475 3814 static PyObject *py_pj_parse_simple_sip(PyObject *pSelf, PyObject *pArgs) 5476 3815 { 5477 const char * uri_param;3816 const char *arg_uri; 5478 3817 pj_pool_t *pool; 5479 3818 char tmp[PJSIP_MAX_URL_SIZE]; … … 5484 3823 PJ_UNUSED_ARG(pSelf); 5485 3824 5486 if (!PyArg_ParseTuple(pArgs, "s", &uri_param)) 5487 { 5488 return NULL; 5489 } 5490 5491 strncpy(tmp, uri_param, sizeof(tmp)); 3825 if (!PyArg_ParseTuple(pArgs, "s", &arg_uri)) { 3826 return NULL; 3827 } 3828 3829 strncpy(tmp, arg_uri, sizeof(tmp)); 5492 3830 tmp[sizeof(tmp)-1] = '\0'; 5493 3831 … … 5498 3836 !PJSIP_URI_SCHEME_IS_SIPS(uri))) { 5499 3837 pj_pool_release(pool); 5500 Py_INCREF(Py_None); 5501 return Py_None; 3838 return Py_BuildValue(""); 5502 3839 } 5503 3840 … … 5506 3843 5507 3844 /* Scheme */ 5508 item = PyString_FromStringAndSize(pjsip_uri_get_scheme(uri)->ptr, 5509 pjsip_uri_get_scheme(uri)->slen); 3845 item = PyString_FromPJ(pjsip_uri_get_scheme(uri)); 5510 3846 PyTuple_SetItem(ret, 0, item); 5511 3847 5512 3848 /* Username */ 5513 item = PyString_From StringAndSize(sip_uri->user.ptr, sip_uri->user.slen);3849 item = PyString_FromPJ(&sip_uri->user); 5514 3850 PyTuple_SetItem(ret, 1, item); 5515 3851 5516 3852 /* Host */ 5517 item = PyString_From StringAndSize(sip_uri->host.ptr, sip_uri->host.slen);3853 item = PyString_FromPJ(&sip_uri->host); 5518 3854 PyTuple_SetItem(ret, 2, item); 5519 3855 … … 5530 3866 sip_uri->transport_param.slen = 0; 5531 3867 } 5532 item = PyString_FromStringAndSize(sip_uri->transport_param.ptr, 5533 sip_uri->transport_param.slen); 3868 item = PyString_FromPJ(&sip_uri->transport_param); 5534 3869 PyTuple_SetItem(ret, 4, item); 5535 3870 … … 5653 3988 }, 5654 3989 { 5655 "pool_create", py_pjsua_pool_create, METH_VARARGS,5656 pjsua_pool_create_doc5657 },5658 {5659 "get_pjsip_endpt", py_pjsua_get_pjsip_endpt, METH_VARARGS,5660 pjsua_get_pjsip_endpt_doc5661 },5662 {5663 "get_pjmedia_endpt", py_pjsua_get_pjmedia_endpt, METH_VARARGS,5664 pjsua_get_pjmedia_endpt_doc5665 },5666 {5667 "get_pool_factory", py_pjsua_get_pool_factory, METH_VARARGS,5668 pjsua_get_pool_factory_doc5669 },5670 {5671 3990 "reconfigure_logging", py_pjsua_reconfigure_logging, METH_VARARGS, 5672 3991 pjsua_reconfigure_logging_doc … … 5747 4066 }, 5748 4067 { 4068 "acc_set_user_data", py_pjsua_acc_set_user_data, METH_VARARGS, 4069 "Accociate user data with the account" 4070 }, 4071 { 4072 "acc_get_user_data", py_pjsua_acc_get_user_data, METH_VARARGS, 4073 "Get account's user data" 4074 }, 4075 { 5749 4076 "acc_modify", py_pjsua_acc_modify, METH_VARARGS, 5750 4077 pjsua_acc_modify_doc … … 5777 4104 "acc_enum_info", py_pjsua_acc_enum_info, METH_VARARGS, 5778 4105 pjsua_acc_enum_info_doc 5779 },5780 {5781 "acc_find_for_outgoing", py_pjsua_acc_find_for_outgoing, METH_VARARGS,5782 pjsua_acc_find_for_outgoing_doc5783 },5784 {5785 "acc_find_for_incoming", py_pjsua_acc_find_for_incoming, METH_VARARGS,5786 pjsua_acc_find_for_incoming_doc5787 },5788 {5789 "acc_create_uac_contact", py_pjsua_acc_create_uac_contact, METH_VARARGS,5790 pjsua_acc_create_uac_contact_doc5791 },5792 {5793 "acc_create_uas_contact", py_pjsua_acc_create_uas_contact, METH_VARARGS,5794 pjsua_acc_create_uas_contact_doc5795 4106 }, 5796 4107 { … … 5815 4126 }, 5816 4127 { 4128 "buddy_find", py_pjsua_buddy_find, METH_VARARGS, 4129 "Find buddy with the specified URI" 4130 }, 4131 { 5817 4132 "buddy_get_info", py_pjsua_buddy_get_info, METH_VARARGS, 5818 4133 pjsua_buddy_get_info_doc … … 5825 4140 "buddy_del", py_pjsua_buddy_del, METH_VARARGS, 5826 4141 pjsua_buddy_del_doc 4142 }, 4143 { 4144 "buddy_set_user_data", py_pjsua_buddy_set_user_data, METH_VARARGS, 4145 "Associate user data to the buddy object" 4146 }, 4147 { 4148 "buddy_get_user_data", py_pjsua_buddy_get_user_data, METH_VARARGS, 4149 "Get buddy user data" 5827 4150 }, 5828 4151 { … … 5859 4182 }, 5860 4183 { 5861 "conf_add_port", py_pjsua_conf_add_port, METH_VARARGS,5862 pjsua_conf_add_port_doc5863 },5864 {5865 4184 "conf_remove_port", py_pjsua_conf_remove_port, METH_VARARGS, 5866 4185 pjsua_conf_remove_port_doc … … 5935 4254 "set_null_snd_dev", py_pjsua_set_null_snd_dev, METH_VARARGS, 5936 4255 pjsua_set_null_snd_dev_doc 5937 },5938 {5939 "set_no_snd_dev", py_pjsua_set_no_snd_dev, METH_VARARGS,5940 pjsua_set_no_snd_dev_doc5941 4256 }, 5942 4257 { … … 6095 4410 if (PyType_Ready(&PyTyp_pjsua_media_config) < 0) 6096 4411 return; 6097 PyTyp_pjsip_event.tp_new = PyType_GenericNew;6098 if (PyType_Ready(&PyTyp_pjsip_event) < 0)6099 return;6100 PyTyp_pjsip_rx_data.tp_new = PyType_GenericNew;6101 if (PyType_Ready(&PyTyp_pjsip_rx_data) < 0)6102 return;6103 PyTyp_pj_pool_t.tp_new = PyType_GenericNew;6104 if (PyType_Ready(&PyTyp_pj_pool_t) < 0)6105 return;6106 PyTyp_pjsip_endpoint.tp_new = PyType_GenericNew;6107 if (PyType_Ready(&PyTyp_pjsip_endpoint) < 0)6108 return;6109 PyTyp_pjmedia_endpt.tp_new = PyType_GenericNew;6110 if (PyType_Ready(&PyTyp_pjmedia_endpt) < 0)6111 return;6112 PyTyp_pj_pool_factory.tp_new = PyType_GenericNew;6113 if (PyType_Ready(&PyTyp_pj_pool_factory) < 0)6114 return;6115 4412 PyTyp_pjsip_cred_info.tp_new = PyType_GenericNew; 6116 4413 if (PyType_Ready(&PyTyp_pjsip_cred_info) < 0) … … 6152 4449 6153 4450 if (PyType_Ready(&PyTyp_pjsua_conf_port_info) < 0) 6154 return;6155 6156 PyTyp_pjmedia_port.tp_new = PyType_GenericNew;6157 if (PyType_Ready(&PyTyp_pjmedia_port) < 0)6158 4451 return; 6159 4452 … … 6175 4468 /* LIB CALL */ 6176 4469 6177 PyTyp_pj_time_val.tp_new = PyType_GenericNew;6178 if (PyType_Ready(&PyTyp_pj_time_val) < 0)6179 return;6180 6181 4470 if (PyType_Ready(&PyTyp_pjsua_call_info) < 0) 6182 4471 return; … … 6185 4474 6186 4475 m = Py_InitModule3( 6187 "_pjsua", py_pjsua_methods, "PJSUA-lib module for python"4476 "_pjsua", py_pjsua_methods, "PJSUA-lib module for python" 6188 4477 ); 6189 4478 … … 6202 4491 Py_INCREF(&PyTyp_pjsua_msg_data); 6203 4492 PyModule_AddObject(m, "Msg_Data", (PyObject *)&PyTyp_pjsua_msg_data); 6204 6205 Py_INCREF(&PyTyp_pjsip_event);6206 PyModule_AddObject(m, "Pjsip_Event", (PyObject *)&PyTyp_pjsip_event);6207 6208 Py_INCREF(&PyTyp_pjsip_rx_data);6209 PyModule_AddObject(m, "Pjsip_Rx_Data", (PyObject *)&PyTyp_pjsip_rx_data);6210 6211 Py_INCREF(&PyTyp_pj_pool_t);6212 PyModule_AddObject(m, "Pj_Pool", (PyObject *)&PyTyp_pj_pool_t);6213 6214 Py_INCREF(&PyTyp_pjsip_endpoint);6215 PyModule_AddObject(m, "Pjsip_Endpoint", (PyObject *)&PyTyp_pjsip_endpoint);6216 6217 Py_INCREF(&PyTyp_pjmedia_endpt);6218 PyModule_AddObject(m, "Pjmedia_Endpt", (PyObject *)&PyTyp_pjmedia_endpt);6219 6220 Py_INCREF(&PyTyp_pj_pool_factory);6221 PyModule_AddObject(6222 m, "Pj_Pool_Factory", (PyObject *)&PyTyp_pj_pool_factory6223 );6224 4493 6225 4494 Py_INCREF(&PyTyp_pjsip_cred_info); … … 6265 4534 Py_INCREF(&PyTyp_pjsua_conf_port_info); 6266 4535 PyModule_AddObject(m, "Conf_Port_Info", (PyObject *)&PyTyp_pjsua_conf_port_info); 6267 Py_INCREF(&PyTyp_pjmedia_port);6268 PyModule_AddObject(m, "PJMedia_Port", (PyObject *)&PyTyp_pjmedia_port);6269 4536 Py_INCREF(&PyTyp_pjmedia_snd_dev_info); 6270 4537 PyModule_AddObject(m, "PJMedia_Snd_Dev_Info", … … 6284 4551 /* LIB CALL */ 6285 4552 6286 Py_INCREF(&PyTyp_pj_time_val);6287 PyModule_AddObject(m, "PJ_Time_Val", (PyObject *)&PyTyp_pj_time_val);6288 6289 4553 Py_INCREF(&PyTyp_pjsua_call_info); 6290 4554 PyModule_AddObject(m, "Call_Info", (PyObject *)&PyTyp_pjsua_call_info); … … 6296 4560 * Add various constants. 6297 4561 */ 6298 6299 /* Call states */ 6300 ADD_CONSTANT(m, PJSIP_INV_STATE_NULL); 6301 ADD_CONSTANT(m, PJSIP_INV_STATE_CALLING); 6302 ADD_CONSTANT(m, PJSIP_INV_STATE_INCOMING); 6303 ADD_CONSTANT(m, PJSIP_INV_STATE_EARLY); 6304 ADD_CONSTANT(m, PJSIP_INV_STATE_CONNECTING); 6305 ADD_CONSTANT(m, PJSIP_INV_STATE_CONFIRMED); 6306 ADD_CONSTANT(m, PJSIP_INV_STATE_DISCONNECTED); 6307 6308 /* Call media status (enum pjsua_call_media_status) */ 6309 ADD_CONSTANT(m, PJSUA_CALL_MEDIA_NONE); 6310 ADD_CONSTANT(m, PJSUA_CALL_MEDIA_ACTIVE); 6311 ADD_CONSTANT(m, PJSUA_CALL_MEDIA_LOCAL_HOLD); 6312 ADD_CONSTANT(m, PJSUA_CALL_MEDIA_REMOTE_HOLD); 6313 6314 /* Buddy status */ 6315 ADD_CONSTANT(m, PJSUA_BUDDY_STATUS_UNKNOWN); 6316 ADD_CONSTANT(m, PJSUA_BUDDY_STATUS_ONLINE); 6317 ADD_CONSTANT(m, PJSUA_BUDDY_STATUS_OFFLINE); 6318 6319 /* PJSIP transport types (enum pjsip_transport_type_e) */ 6320 ADD_CONSTANT(m, PJSIP_TRANSPORT_UNSPECIFIED); 6321 ADD_CONSTANT(m, PJSIP_TRANSPORT_UDP); 6322 ADD_CONSTANT(m, PJSIP_TRANSPORT_TCP); 6323 ADD_CONSTANT(m, PJSIP_TRANSPORT_TLS); 6324 ADD_CONSTANT(m, PJSIP_TRANSPORT_SCTP); 6325 ADD_CONSTANT(m, PJSIP_TRANSPORT_LOOP); 6326 ADD_CONSTANT(m, PJSIP_TRANSPORT_LOOP_DGRAM); 6327 6328 6329 /* Invalid IDs */ 6330 ADD_CONSTANT(m, PJSUA_INVALID_ID); 6331 6332 6333 /* Various compile time constants */ 6334 ADD_CONSTANT(m, PJSUA_ACC_MAX_PROXIES); 6335 ADD_CONSTANT(m, PJSUA_MAX_ACC); 6336 ADD_CONSTANT(m, PJSUA_REG_INTERVAL); 6337 ADD_CONSTANT(m, PJSUA_PUBLISH_EXPIRATION); 6338 ADD_CONSTANT(m, PJSUA_DEFAULT_ACC_PRIORITY); 6339 ADD_CONSTANT(m, PJSUA_MAX_BUDDIES); 6340 ADD_CONSTANT(m, PJSUA_MAX_CONF_PORTS); 6341 ADD_CONSTANT(m, PJSUA_DEFAULT_CLOCK_RATE); 6342 ADD_CONSTANT(m, PJSUA_DEFAULT_CODEC_QUALITY); 6343 ADD_CONSTANT(m, PJSUA_DEFAULT_ILBC_MODE); 6344 ADD_CONSTANT(m, PJSUA_DEFAULT_EC_TAIL_LEN); 6345 ADD_CONSTANT(m, PJSUA_MAX_CALLS); 6346 ADD_CONSTANT(m, PJSUA_XFER_NO_REQUIRE_REPLACES); 6347 4562 /* Skip it.. */ 6348 4563 6349 4564 #undef ADD_CONSTANT -
pjproject/trunk/pjsip-apps/src/python/_pjsua.h
r2156 r2163 27 27 28 28 29 PJ_INLINE(pj_str_t) PyString_ to_pj_str(const PyObject *obj)29 PJ_INLINE(pj_str_t) PyString_ToPJ(const PyObject *obj) 30 30 { 31 31 pj_str_t str; 32 32 33 if (obj ) {33 if (obj && PyString_Check(obj)) { 34 34 str.ptr = PyString_AS_STRING(obj); 35 35 str.slen = PyString_GET_SIZE(obj); … … 42 42 } 43 43 44 45 ////////////////////////////////////////////////////////////////////////////// 46 /* 47 * PyObj_pj_pool 48 */ 49 typedef struct 50 { 51 PyObject_HEAD 52 /* Type-specific fields go here. */ 53 pj_pool_t * pool; 54 } PyObj_pj_pool; 55 56 57 /* 58 * PyTyp_pj_pool_t 59 */ 60 static PyTypeObject PyTyp_pj_pool_t = 61 { 62 PyObject_HEAD_INIT(NULL) 63 0, /*ob_size*/ 64 "_pjsua.Pj_Pool", /*tp_name*/ 65 sizeof(PyObj_pj_pool), /*tp_basicsize*/ 66 0, /*tp_itemsize*/ 67 0, /*tp_dealloc*/ 68 0, /*tp_print*/ 69 0, /*tp_getattr*/ 70 0, /*tp_setattr*/ 71 0, /*tp_compare*/ 72 0, /*tp_repr*/ 73 0, /*tp_as_number*/ 74 0, /*tp_as_sequence*/ 75 0, /*tp_as_mapping*/ 76 0, /*tp_hash */ 77 0, /*tp_call*/ 78 0, /*tp_str*/ 79 0, /*tp_getattro*/ 80 0, /*tp_setattro*/ 81 0, /*tp_as_buffer*/ 82 Py_TPFLAGS_DEFAULT, /*tp_flags*/ 83 "pj_pool_t objects", /* tp_doc */ 84 85 }; 86 87 88 ////////////////////////////////////////////////////////////////////////////// 89 /* 90 * PyObj_pjsip_endpoint 91 */ 92 typedef struct 93 { 94 PyObject_HEAD 95 /* Type-specific fields go here. */ 96 pjsip_endpoint * endpt; 97 } PyObj_pjsip_endpoint; 98 99 100 /* 101 * PyTyp_pjsip_endpoint 102 */ 103 static PyTypeObject PyTyp_pjsip_endpoint = 104 { 105 PyObject_HEAD_INIT(NULL) 106 0, /*ob_size*/ 107 "_pjsua.Pjsip_Endpoint", /*tp_name*/ 108 sizeof(PyObj_pjsip_endpoint),/*tp_basicsize*/ 109 0, /*tp_itemsize*/ 110 0, /*tp_dealloc*/ 111 0, /*tp_print*/ 112 0, /*tp_getattr*/ 113 0, /*tp_setattr*/ 114 0, /*tp_compare*/ 115 0, /*tp_repr*/ 116 0, /*tp_as_number*/ 117 0, /*tp_as_sequence*/ 118 0, /*tp_as_mapping*/ 119 0, /*tp_hash */ 120 0, /*tp_call*/ 121 0, /*tp_str*/ 122 0, /*tp_getattro*/ 123 0, /*tp_setattro*/ 124 0, /*tp_as_buffer*/ 125 Py_TPFLAGS_DEFAULT, /*tp_flags*/ 126 "pjsip_endpoint objects", /* tp_doc */ 127 }; 128 129 130 /* 131 * PyObj_pjmedia_endpt 132 */ 133 typedef struct 134 { 135 PyObject_HEAD 136 /* Type-specific fields go here. */ 137 pjmedia_endpt * endpt; 138 } PyObj_pjmedia_endpt; 139 140 141 ////////////////////////////////////////////////////////////////////////////// 142 /* 143 * PyTyp_pjmedia_endpt 144 */ 145 static PyTypeObject PyTyp_pjmedia_endpt = 146 { 147 PyObject_HEAD_INIT(NULL) 148 0, /*ob_size*/ 149 "_pjsua.Pjmedia_Endpt", /*tp_name*/ 150 sizeof(PyObj_pjmedia_endpt), /*tp_basicsize*/ 151 0, /*tp_itemsize*/ 152 0, /*tp_dealloc*/ 153 0, /*tp_print*/ 154 0, /*tp_getattr*/ 155 0, /*tp_setattr*/ 156 0, /*tp_compare*/ 157 0, /*tp_repr*/ 158 0, /*tp_as_number*/ 159 0, /*tp_as_sequence*/ 160 0, /*tp_as_mapping*/ 161 0, /*tp_hash */ 162 0, /*tp_call*/ 163 0, /*tp_str*/ 164 0, /*tp_getattro*/ 165 0, /*tp_setattro*/ 166 0, /*tp_as_buffer*/ 167 Py_TPFLAGS_DEFAULT, /*tp_flags*/ 168 "pjmedia_endpt objects", /* tp_doc */ 169 170 }; 171 172 173 ////////////////////////////////////////////////////////////////////////////// 174 /* 175 * PyObj_pj_pool_factory 176 */ 177 typedef struct 178 { 179 PyObject_HEAD 180 /* Type-specific fields go here. */ 181 pj_pool_factory * pool_fact; 182 } PyObj_pj_pool_factory; 183 184 185 186 /* 187 * PyTyp_pj_pool_factory 188 */ 189 static PyTypeObject PyTyp_pj_pool_factory = 190 { 191 PyObject_HEAD_INIT(NULL) 192 0, /*ob_size*/ 193 "_pjsua.Pj_Pool_Factory",/*tp_name*/ 194 sizeof(PyObj_pj_pool_factory), /*tp_basicsize*/ 195 0, /*tp_itemsize*/ 196 0, /*tp_dealloc*/ 197 0, /*tp_print*/ 198 0, /*tp_getattr*/ 199 0, /*tp_setattr*/ 200 0, /*tp_compare*/ 201 0, /*tp_repr*/ 202 0, /*tp_as_number*/ 203 0, /*tp_as_sequence*/ 204 0, /*tp_as_mapping*/ 205 0, /*tp_hash */ 206 0, /*tp_call*/ 207 0, /*tp_str*/ 208 0, /*tp_getattro*/ 209 0, /*tp_setattro*/ 210 0, /*tp_as_buffer*/ 211 Py_TPFLAGS_DEFAULT, /*tp_flags*/ 212 "pj_pool_factory objects", /* tp_doc */ 213 214 }; 215 44 PJ_INLINE(PyObject*) PyString_FromPJ(const pj_str_t *str) 45 { 46 return PyString_FromStringAndSize(str->ptr, str->slen); 47 } 216 48 217 49 ////////////////////////////////////////////////////////////////////////////// … … 250 82 { 251 83 Py_XDECREF(obj->realm); 252 obj->realm = PyString_From StringAndSize(cfg->realm.ptr, cfg->realm.slen);84 obj->realm = PyString_FromPJ(&cfg->realm); 253 85 Py_XDECREF(obj->scheme); 254 obj->scheme = PyString_From StringAndSize(cfg->scheme.ptr, cfg->scheme.slen);86 obj->scheme = PyString_FromPJ(&cfg->scheme); 255 87 Py_XDECREF(obj->username); 256 obj->username = PyString_From StringAndSize(cfg->username.ptr, cfg->username.slen);88 obj->username = PyString_FromPJ(&cfg->username); 257 89 obj->data_type = cfg->data_type; 258 90 Py_XDECREF(obj->data); 259 obj->data = PyString_From StringAndSize(cfg->data.ptr, cfg->data.slen);91 obj->data = PyString_FromPJ(&cfg->data); 260 92 } 261 93 … … 263 95 PyObj_pjsip_cred_info *obj) 264 96 { 265 cfg->realm = PyString_ to_pj_str(obj->realm);266 cfg->scheme = PyString_ to_pj_str(obj->scheme);267 cfg->username = PyString_ to_pj_str(obj->username);97 cfg->realm = PyString_ToPJ(obj->realm); 98 cfg->scheme = PyString_ToPJ(obj->scheme); 99 cfg->username = PyString_ToPJ(obj->username); 268 100 cfg->data_type = obj->data_type; 269 cfg->data = PyString_ to_pj_str(obj->data);101 cfg->data = PyString_ToPJ(obj->data); 270 102 } 271 103 … … 285 117 286 118 self = (PyObj_pjsip_cred_info *)type->tp_alloc(type, 0); 287 if (self != NULL) 288 { 119 if (self != NULL) { 289 120 self->realm = PyString_FromString(""); 290 if (self->realm == NULL)291 {292 Py_DECREF(self);293 return NULL;294 }295 121 self->scheme = PyString_FromString(""); 296 if (self->scheme == NULL)297 {298 Py_DECREF(self);299 return NULL;300 }301 122 self->username = PyString_FromString(""); 302 if (self->username == NULL)303 {304 Py_DECREF(self);305 return NULL;306 }307 123 self->data_type = PJSIP_CRED_DATA_PLAIN_PASSWD; 308 124 self->data = PyString_FromString(""); 309 if (self->data == NULL)310 {311 Py_DECREF(self);312 return NULL;313 }314 125 } 315 126 … … 387 198 0, /* tp_iternext */ 388 199 0, /* tp_methods */ 389 PyObj_pjsip_cred_info_members, 200 PyObj_pjsip_cred_info_members, /* tp_members */ 390 201 0, /* tp_getset */ 391 202 0, /* tp_base */ … … 396 207 0, /* tp_init */ 397 208 0, /* tp_alloc */ 398 PyObj_pjsip_cred_info_new, /* tp_new */ 399 400 }; 401 402 403 ////////////////////////////////////////////////////////////////////////////// 404 /* 405 * PyObj_pjsip_event 406 * C/python typewrapper for event struct 407 */ 408 typedef struct 409 { 410 PyObject_HEAD 411 /* Type-specific fields go here. */ 412 pjsip_event * event; 413 } PyObj_pjsip_event; 414 415 416 417 /* 418 * PyTyp_pjsip_event 419 * event struct signatures 420 */ 421 static PyTypeObject PyTyp_pjsip_event = 422 { 423 PyObject_HEAD_INIT(NULL) 424 0, /*ob_size*/ 425 "_pjsua.Pjsip_Event", /*tp_name*/ 426 sizeof(PyObj_pjsip_event), /*tp_basicsize*/ 427 0, /*tp_itemsize*/ 428 0, /*tp_dealloc*/ 429 0, /*tp_print*/ 430 0, /*tp_getattr*/ 431 0, /*tp_setattr*/ 432 0, /*tp_compare*/ 433 0, /*tp_repr*/ 434 0, /*tp_as_number*/ 435 0, /*tp_as_sequence*/ 436 0, /*tp_as_mapping*/ 437 0, /*tp_hash */ 438 0, /*tp_call*/ 439 0, /*tp_str*/ 440 0, /*tp_getattro*/ 441 0, /*tp_setattro*/ 442 0, /*tp_as_buffer*/ 443 Py_TPFLAGS_DEFAULT, /*tp_flags*/ 444 "pjsip_event object", /*tp_doc */ 445 }; 446 447 448 ////////////////////////////////////////////////////////////////////////////// 449 /* 450 * PyObj_pjsip_rx_data 451 * C/python typewrapper for pjsip_rx_data struct 452 */ 453 typedef struct 454 { 455 PyObject_HEAD 456 /* Type-specific fields go here. */ 457 pjsip_rx_data * rdata; 458 } PyObj_pjsip_rx_data; 459 460 461 /* 462 * PyTyp_pjsip_rx_data 463 */ 464 static PyTypeObject PyTyp_pjsip_rx_data = 465 { 466 PyObject_HEAD_INIT(NULL) 467 0, /*ob_size*/ 468 "_pjsua.Pjsip_Rx_Data", /*tp_name*/ 469 sizeof(PyObj_pjsip_rx_data), /*tp_basicsize*/ 470 0, /*tp_itemsize*/ 471 0, /*tp_dealloc*/ 472 0, /*tp_print*/ 473 0, /*tp_getattr*/ 474 0, /*tp_setattr*/ 475 0, /*tp_compare*/ 476 0, /*tp_repr*/ 477 0, /*tp_as_number*/ 478 0, /*tp_as_sequence*/ 479 0, /*tp_as_mapping*/ 480 0, /*tp_hash */ 481 0, /*tp_call*/ 482 0, /*tp_str*/ 483 0, /*tp_getattro*/ 484 0, /*tp_setattro*/ 485 0, /*tp_as_buffer*/ 486 Py_TPFLAGS_DEFAULT, /*tp_flags*/ 487 "pjsip_rx_data object", /*tp_doc*/ 488 }; 489 209 PyObj_pjsip_cred_info_new, /* tp_new */ 210 211 }; 490 212 491 213 … … 554 276 555 277 self = (PyObj_pjsua_callback *)type->tp_alloc(type, 0); 556 if (self != NULL) 557 { 558 Py_INCREF(Py_None); 559 self->on_call_state = Py_None; 560 if (self->on_call_state == NULL) 561 { 562 Py_DECREF(Py_None); 563 return NULL; 564 } 565 Py_INCREF(Py_None); 566 self->on_incoming_call = Py_None; 567 if (self->on_incoming_call == NULL) 568 { 569 Py_DECREF(Py_None); 570 return NULL; 571 } 572 Py_INCREF(Py_None); 573 self->on_call_media_state = Py_None; 574 if (self->on_call_media_state == NULL) 575 { 576 Py_DECREF(Py_None); 577 return NULL; 578 } 579 Py_INCREF(Py_None); 580 self->on_dtmf_digit = Py_None; 581 if (self->on_dtmf_digit == NULL) 582 { 583 Py_DECREF(Py_None); 584 return NULL; 585 } 586 Py_INCREF(Py_None); 587 self->on_call_transfer_request = Py_None; 588 if (self->on_call_transfer_request == NULL) 589 { 590 Py_DECREF(Py_None); 591 return NULL; 592 } 593 Py_INCREF(Py_None); 594 self->on_call_transfer_status = Py_None; 595 if (self->on_call_transfer_status == NULL) 596 { 597 Py_DECREF(Py_None); 598 return NULL; 599 } 600 Py_INCREF(Py_None); 601 self->on_call_replace_request = Py_None; 602 if (self->on_call_replace_request == NULL) 603 { 604 Py_DECREF(Py_None); 605 return NULL; 606 } 607 Py_INCREF(Py_None); 608 self->on_call_replaced = Py_None; 609 if (self->on_call_replaced == NULL) 610 { 611 Py_DECREF(Py_None); 612 return NULL; 613 } 614 Py_INCREF(Py_None); 615 self->on_reg_state = Py_None; 616 if (self->on_reg_state == NULL) 617 { 618 Py_DECREF(Py_None); 619 return NULL; 620 } 621 Py_INCREF(Py_None); 622 self->on_incoming_subscribe = Py_None; 623 Py_INCREF(Py_None); 624 self->on_buddy_state = Py_None; 625 if (self->on_buddy_state == NULL) 626 { 627 Py_DECREF(Py_None); 628 return NULL; 629 } 630 Py_INCREF(Py_None); 631 self->on_pager = Py_None; 632 if (self->on_pager == NULL) 633 { 634 Py_DECREF(Py_None); 635 return NULL; 636 } 637 Py_INCREF(Py_None); 638 self->on_pager_status = Py_None; 639 if (self->on_pager_status == NULL) 640 { 641 Py_DECREF(Py_None); 642 return NULL; 643 } 644 Py_INCREF(Py_None); 645 self->on_typing = Py_None; 646 if (self->on_typing == NULL) 647 { 648 Py_DECREF(Py_None); 649 return NULL; 650 } 278 if (self != NULL) { 279 self->on_call_state = Py_BuildValue(""); 280 self->on_incoming_call = Py_BuildValue(""); 281 self->on_call_media_state = Py_BuildValue(""); 282 self->on_dtmf_digit = Py_BuildValue(""); 283 self->on_call_transfer_request = Py_BuildValue(""); 284 self->on_call_transfer_status = Py_BuildValue(""); 285 self->on_call_replace_request = Py_BuildValue(""); 286 self->on_call_replaced = Py_BuildValue(""); 287 self->on_reg_state = Py_BuildValue(""); 288 self->on_incoming_subscribe = Py_BuildValue(""); 289 self->on_buddy_state = Py_BuildValue(""); 290 self->on_pager = Py_BuildValue(""); 291 self->on_pager_status = Py_BuildValue(""); 292 self->on_typing = Py_BuildValue(""); 651 293 } 652 294 … … 989 631 }, 990 632 { 991 "turn_passw ", T_OBJECT_EX,633 "turn_passwd", T_OBJECT_EX, 992 634 offsetof(PyObj_pjsua_media_config, turn_passwd), 0, 993 635 "Specify the TURN password." … … 1008 650 1009 651 self = (PyObj_pjsua_media_config*)type->tp_alloc(type, 0); 1010 if (self != NULL) 1011 { 652 if (self != NULL) { 1012 653 self->turn_server = PyString_FromString(""); 1013 654 self->turn_realm = PyString_FromString(""); … … 1052 693 obj->enable_turn = cfg->enable_turn; 1053 694 Py_XDECREF(obj->turn_server); 1054 obj->turn_server = PyString_FromStringAndSize(cfg->turn_server.ptr, 1055 cfg->turn_server.slen); 695 obj->turn_server = PyString_FromPJ(&cfg->turn_server); 1056 696 obj->turn_conn_type = cfg->turn_conn_type; 1057 697 if (cfg->turn_auth_cred.type == PJ_STUN_AUTH_CRED_STATIC) { … … 1059 699 1060 700 Py_XDECREF(obj->turn_realm); 1061 obj->turn_realm = PyString_FromStringAndSize(cred->data.static_cred.realm.ptr, 1062 cred->data.static_cred.realm.slen); 701 obj->turn_realm = PyString_FromPJ(&cred->data.static_cred.realm); 1063 702 Py_XDECREF(obj->turn_username); 1064 obj->turn_username = PyString_FromStringAndSize(cred->data.static_cred.username.ptr, 1065 cred->data.static_cred.username.slen); 703 obj->turn_username = PyString_FromPJ(&cred->data.static_cred.username); 1066 704 obj->turn_passwd_type = cred->data.static_cred.data_type; 1067 705 Py_XDECREF(obj->turn_passwd); 1068 obj->turn_passwd = PyString_FromStringAndSize(cred->data.static_cred.data.ptr, 1069 cred->data.static_cred.data.slen); 706 obj->turn_passwd = PyString_FromPJ(&cred->data.static_cred.data); 1070 707 } else { 1071 708 Py_XDECREF(obj->turn_realm); … … 1104 741 1105 742 if (cfg->enable_turn) { 1106 cfg->turn_server = PyString_ to_pj_str(obj->turn_server);743 cfg->turn_server = PyString_ToPJ(obj->turn_server); 1107 744 cfg->turn_conn_type = obj->turn_conn_type; 1108 745 cfg->turn_auth_cred.type = PJ_STUN_AUTH_CRED_STATIC; 1109 cfg->turn_auth_cred.data.static_cred.realm = PyString_ to_pj_str(obj->turn_realm);1110 cfg->turn_auth_cred.data.static_cred.username = PyString_ to_pj_str(obj->turn_username);746 cfg->turn_auth_cred.data.static_cred.realm = PyString_ToPJ(obj->turn_realm); 747 cfg->turn_auth_cred.data.static_cred.username = PyString_ToPJ(obj->turn_username); 1111 748 cfg->turn_auth_cred.data.static_cred.data_type= obj->turn_passwd_type; 1112 cfg->turn_auth_cred.data.static_cred.data = PyString_ to_pj_str(obj->turn_passwd);749 cfg->turn_auth_cred.data.static_cred.data = PyString_ToPJ(obj->turn_passwd); 1113 750 } 1114 751 } … … 1202 839 obj->thread_cnt = cfg->thread_cnt; 1203 840 Py_XDECREF(obj->outbound_proxy); 1204 obj->outbound_proxy = PyString_FromStringAndSize(cfg->outbound_proxy[0].ptr, 1205 cfg->outbound_proxy[0].slen); 841 if (cfg->outbound_proxy_cnt) 842 obj->outbound_proxy = PyString_FromPJ(&cfg->outbound_proxy[0]); 843 else 844 obj->outbound_proxy = PyString_FromString(""); 845 1206 846 Py_XDECREF(obj->stun_domain); 1207 obj->stun_domain = PyString_FromStringAndSize(cfg->stun_domain.ptr, 1208 cfg->stun_domain.slen); 847 obj->stun_domain = PyString_FromPJ(&cfg->stun_domain); 1209 848 Py_XDECREF(obj->stun_host); 1210 obj->stun_host = PyString_FromStringAndSize(cfg->stun_host.ptr, 1211 cfg->stun_host.slen); 849 obj->stun_host = PyString_FromPJ(&cfg->stun_host); 1212 850 Py_XDECREF(obj->nameserver); 1213 851 obj->nameserver = (PyListObject *)PyList_New(0); 1214 852 for (i=0; i<cfg->nameserver_count; ++i) { 1215 853 PyObject * str; 1216 str = PyString_FromStringAndSize(cfg->nameserver[i].ptr, 1217 cfg->nameserver[i].slen); 854 str = PyString_FromPJ(&cfg->nameserver[i]); 1218 855 PyList_Append((PyObject *)obj->nameserver, str); 1219 856 } 1220 857 Py_XDECREF(obj->user_agent); 1221 obj->user_agent = PyString_FromStringAndSize(cfg->user_agent.ptr, 1222 cfg->user_agent.slen); 858 obj->user_agent = PyString_FromPJ(&cfg->user_agent); 1223 859 } 1224 860 … … 1233 869 if (PyString_Size(obj->outbound_proxy) > 0) { 1234 870 cfg->outbound_proxy_cnt = 1; 1235 cfg->outbound_proxy[0] = PyString_ to_pj_str(obj->outbound_proxy);871 cfg->outbound_proxy[0] = PyString_ToPJ(obj->outbound_proxy); 1236 872 } else { 1237 873 cfg->outbound_proxy_cnt = 0; … … 1241 877 cfg->nameserver_count = PJ_ARRAY_SIZE(cfg->nameserver); 1242 878 for (i = 0; i < cfg->nameserver_count; i++) { 1243 cfg->nameserver[i] = PyString_to_pj_str(PyList_GetItem((PyObject *)obj->nameserver,i)); 879 PyObject *item = PyList_GetItem((PyObject *)obj->nameserver,i); 880 cfg->nameserver[i] = PyString_ToPJ(item); 1244 881 } 1245 cfg->stun_domain = PyString_ to_pj_str(obj->stun_domain);1246 cfg->stun_host = PyString_ to_pj_str(obj->stun_host);1247 cfg->user_agent = PyString_ to_pj_str(obj->user_agent);882 cfg->stun_domain = PyString_ToPJ(obj->stun_domain); 883 cfg->stun_host = PyString_ToPJ(obj->stun_host); 884 cfg->user_agent = PyString_ToPJ(obj->user_agent); 1248 885 1249 886 } … … 1260 897 1261 898 self = (PyObj_pjsua_config *)type->tp_alloc(type, 0); 1262 if (self != NULL) 1263 { 899 if (self != NULL) { 1264 900 self->user_agent = PyString_FromString(""); 1265 if (self->user_agent == NULL)1266 {1267 Py_DECREF(self);1268 return NULL;1269 }1270 901 self->outbound_proxy = PyString_FromString(""); 1271 if (self->outbound_proxy == NULL) 1272 { 1273 Py_DECREF(self); 1274 return NULL; 1275 } 902 self->stun_domain = PyString_FromString(""); 903 self->stun_host = PyString_FromString(""); 1276 904 self->cb = (PyObj_pjsua_callback *) 1277 905 PyType_GenericNew(&PyTyp_pjsua_callback, NULL, NULL); 1278 if (self->cb == NULL)1279 {1280 Py_DECREF(Py_None);1281 return NULL;1282 }1283 906 } 1284 907 return (PyObject *)self; … … 1426 1049 obj->console_level = cfg->console_level; 1427 1050 obj->decor = cfg->decor; 1051 Py_XDECREF(obj->log_filename); 1052 obj->log_filename = PyString_FromPJ(&cfg->log_filename); 1428 1053 } 1429 1054 … … 1435 1060 cfg->console_level = obj->console_level; 1436 1061 cfg->decor = obj->decor; 1437 cfg->log_filename = PyString_ to_pj_str(obj->log_filename);1062 cfg->log_filename = PyString_ToPJ(obj->log_filename); 1438 1063 } 1439 1064 … … 1453 1078 1454 1079 self = (PyObj_pjsua_logging_config *)type->tp_alloc(type, 0); 1455 if (self != NULL) 1456 { 1080 if (self != NULL) { 1457 1081 self->log_filename = PyString_FromString(""); 1458 if (self->log_filename == NULL) 1459 { 1460 Py_DECREF(self); 1461 return NULL; 1462 } 1463 Py_INCREF(Py_None); 1464 self->cb = Py_None; 1465 if (self->cb == NULL) 1466 { 1467 Py_DECREF(Py_None); 1468 return NULL; 1469 } 1082 self->cb = Py_BuildValue(""); 1470 1083 } 1471 1084 … … 1610 1223 1611 1224 self = (PyObj_pjsua_msg_data *)type->tp_alloc(type, 0); 1612 if (self != NULL) 1613 { 1614 Py_INCREF(Py_None); 1615 self->hdr_list = Py_None; 1616 if (self->hdr_list == NULL) { 1617 Py_DECREF(self); 1618 return NULL; 1619 } 1225 if (self != NULL) { 1226 self->hdr_list = PyList_New(0); 1620 1227 self->content_type = PyString_FromString(""); 1621 if (self->content_type == NULL) {1622 Py_DECREF(self);1623 return NULL;1624 }1625 1228 self->msg_body = PyString_FromString(""); 1626 if (self->msg_body == NULL) {1627 Py_DECREF(self);1628 return NULL;1629 }1630 1229 } 1631 1230 … … 1738 1337 PyObj_pjsua_transport_config *obj) 1739 1338 { 1740 cfg->public_addr = PyString_ to_pj_str(obj->public_addr);1741 cfg->bound_addr = PyString_ to_pj_str(obj->bound_addr);1339 cfg->public_addr = PyString_ToPJ(obj->public_addr); 1340 cfg->bound_addr = PyString_ToPJ(obj->bound_addr); 1742 1341 cfg->port = obj->port; 1743 1342 … … 1748 1347 { 1749 1348 Py_XDECREF(obj->public_addr); 1750 obj->public_addr = PyString_FromStringAndSize(cfg->public_addr.ptr, 1751 cfg->public_addr.slen); 1349 obj->public_addr = PyString_FromPJ(&cfg->public_addr); 1752 1350 1753 1351 Py_XDECREF(obj->bound_addr); 1754 obj->bound_addr = PyString_FromStringAndSize(cfg->bound_addr.ptr, 1755 cfg->bound_addr.slen); 1352 obj->bound_addr = PyString_FromPJ(&cfg->bound_addr); 1756 1353 1757 1354 obj->port = cfg->port; … … 1775 1372 if (self != NULL) { 1776 1373 self->public_addr = PyString_FromString(""); 1777 if (self->public_addr == NULL) {1778 Py_DECREF(self);1779 return NULL;1780 }1781 1374 self->bound_addr = PyString_FromString(""); 1782 if (self->bound_addr == NULL) {1783 Py_DECREF(self);1784 return NULL;1785 }1786 1375 } 1787 1376 … … 1912 1501 obj->id = info->id; 1913 1502 obj->type = info->type; 1914 obj->type_name = PyString_FromStringAndSize(info->type_name.ptr, 1915 info->type_name.slen); 1916 obj->info = PyString_FromStringAndSize(info->info.ptr, 1917 info->info.slen); 1503 obj->type_name = PyString_FromPJ(&info->type_name); 1504 obj->info = PyString_FromPJ(&info->info); 1918 1505 obj->flag = info->flag; 1919 obj->addr = PyString_FromStringAndSize(info->local_name.host.ptr, 1920 info->local_name.host.slen); 1506 obj->addr = PyString_FromPJ(&info->local_name.host); 1921 1507 obj->port = info->local_name.port; 1922 1508 obj->usage_count= info->usage_count; … … 1940 1526 { 1941 1527 self->type_name = PyString_FromString(""); 1942 if (self->type_name == NULL) {1943 Py_DECREF(self);1944 return NULL;1945 }1946 1528 self->info = PyString_FromString(""); 1947 if (self->info == NULL) {1948 Py_DECREF(self);1949 return NULL;1950 }1951 1529 self->addr = PyString_FromString(""); 1952 if (self->addr == NULL) {1953 Py_DECREF(self);1954 return NULL;1955 }1956 1530 } 1957 1531 … … 1972 1546 { 1973 1547 "type", T_INT, 1974 offsetof(PyObj_pjsua_transport_info, id), 0,1548 offsetof(PyObj_pjsua_transport_info, type), 0, 1975 1549 "Transport type." 1976 1550 }, … … 2072 1646 int publish_enabled; 2073 1647 PyObject *force_contact; 2074 /*pj_str_t proxy[8];*/2075 1648 PyListObject *proxy; 2076 1649 unsigned reg_timeout; 2077 /*pjsip_cred_info cred_info[8];*/2078 1650 PyListObject *cred_info; 2079 1651 int transport_id; 2080 2081 1652 int auth_initial_send; 2082 1653 PyObject *auth_initial_algorithm; … … 2116 1687 obj->priority = cfg->priority; 2117 1688 Py_XDECREF(obj->id); 2118 obj->id = PyString_From StringAndSize(cfg->id.ptr, cfg->id.slen);1689 obj->id = PyString_FromPJ(&cfg->id); 2119 1690 Py_XDECREF(obj->reg_uri); 2120 obj->reg_uri = PyString_FromStringAndSize(cfg->reg_uri.ptr, 2121 cfg->reg_uri.slen); 1691 obj->reg_uri = PyString_FromPJ(&cfg->reg_uri); 2122 1692 obj->publish_enabled = cfg->publish_enabled; 2123 1693 Py_XDECREF(obj->force_contact); 2124 obj->force_contact = PyString_FromStringAndSize(cfg->force_contact.ptr, 2125 cfg->force_contact.slen); 1694 obj->force_contact = PyString_FromPJ(&cfg->force_contact); 2126 1695 Py_XDECREF(obj->proxy); 2127 1696 obj->proxy = (PyListObject *)PyList_New(0); 2128 1697 for (i=0; i<cfg->proxy_cnt; ++i) { 2129 1698 PyObject * str; 2130 str = PyString_FromStringAndSize(cfg->proxy[i].ptr, 2131 cfg->proxy[i].slen); 1699 str = PyString_FromPJ(&cfg->proxy[i]); 2132 1700 PyList_Append((PyObject *)obj->proxy, str); 2133 1701 } … … 2150 1718 obj->auth_initial_send = cfg->auth_pref.initial_auth; 2151 1719 Py_XDECREF(obj->auth_initial_algorithm); 2152 obj->auth_initial_algorithm = PyString_FromStringAndSize(cfg->auth_pref.algorithm.ptr, 2153 cfg->auth_pref.algorithm.slen); 1720 obj->auth_initial_algorithm = PyString_FromPJ(&cfg->auth_pref.algorithm); 2154 1721 Py_XDECREF(obj->pidf_tuple_id); 2155 obj->pidf_tuple_id = PyString_FromStringAndSize(cfg->pidf_tuple_id.ptr, 2156 cfg->pidf_tuple_id.slen); 1722 obj->pidf_tuple_id = PyString_FromPJ(&cfg->pidf_tuple_id); 2157 1723 obj->require_100rel = cfg->require_100rel; 2158 1724 obj->allow_contact_rewrite = cfg->allow_contact_rewrite; 2159 1725 obj->ka_interval = cfg->ka_interval; 2160 1726 Py_XDECREF(obj->ka_data); 2161 obj->ka_data = PyString_From StringAndSize(cfg->ka_data.ptr, cfg->ka_data.slen);1727 obj->ka_data = PyString_FromPJ(&cfg->ka_data); 2162 1728 obj->use_srtp = cfg->use_srtp; 2163 1729 obj->srtp_secure_signaling = cfg->srtp_secure_signaling; … … 2170 1736 2171 1737 cfg->priority = obj->priority; 2172 cfg->id = PyString_ to_pj_str(obj->id);2173 cfg->reg_uri = PyString_ to_pj_str(obj->reg_uri);1738 cfg->id = PyString_ToPJ(obj->id); 1739 cfg->reg_uri = PyString_ToPJ(obj->reg_uri); 2174 1740 cfg->publish_enabled = obj->publish_enabled; 2175 cfg->force_contact = PyString_ to_pj_str(obj->force_contact);1741 cfg->force_contact = PyString_ToPJ(obj->force_contact); 2176 1742 2177 1743 cfg->proxy_cnt = PyList_Size((PyObject*)obj->proxy); 1744 if (cfg->proxy_cnt > PJ_ARRAY_SIZE(cfg->proxy)) 1745 cfg->proxy_cnt = PJ_ARRAY_SIZE(cfg->proxy); 2178 1746 for (i = 0; i < cfg->proxy_cnt; i++) { 2179 /*cfg.proxy[i] = ac->proxy[i];*/ 2180 cfg->proxy[i] = PyString_ to_pj_str(PyList_GetItem((PyObject *)obj->proxy,i));1747 PyObject *item = PyList_GetItem((PyObject *)obj->proxy, i); 1748 cfg->proxy[i] = PyString_ToPJ(item); 2181 1749 } 2182 1750 … … 2184 1752 2185 1753 cfg->cred_count = PyList_Size((PyObject*)obj->cred_info); 1754 if (cfg->cred_count > PJ_ARRAY_SIZE(cfg->cred_info)) 1755 cfg->cred_count = PJ_ARRAY_SIZE(cfg->cred_info); 2186 1756 for (i = 0; i < cfg->cred_count; i++) { 2187 /*cfg.cred_info[i] = ac->cred_info[i];*/2188 1757 PyObj_pjsip_cred_info *ci; 2189 1758 ci = (PyObj_pjsip_cred_info*) 2190 PyList_GetItem((PyObject *)obj->cred_info, i);1759 PyList_GetItem((PyObject *)obj->cred_info, i); 2191 1760 PyObj_pjsip_cred_info_export(&cfg->cred_info[i], ci); 2192 1761 } … … 2194 1763 cfg->transport_id = obj->transport_id; 2195 1764 cfg->auth_pref.initial_auth = obj->auth_initial_send; 2196 cfg->auth_pref.algorithm = PyString_ to_pj_str(obj->auth_initial_algorithm);2197 cfg->pidf_tuple_id = PyString_ to_pj_str(obj->pidf_tuple_id);1765 cfg->auth_pref.algorithm = PyString_ToPJ(obj->auth_initial_algorithm); 1766 cfg->pidf_tuple_id = PyString_ToPJ(obj->pidf_tuple_id); 2198 1767 cfg->require_100rel = obj->require_100rel; 2199 1768 cfg->allow_contact_rewrite = obj->allow_contact_rewrite; 2200 1769 cfg->ka_interval = obj->ka_interval; 2201 cfg->ka_data = PyString_ to_pj_str(obj->ka_data);1770 cfg->ka_data = PyString_ToPJ(obj->ka_data); 2202 1771 cfg->use_srtp = obj->use_srtp; 2203 1772 cfg->srtp_secure_signaling = obj->srtp_secure_signaling; … … 2221 1790 if (self != NULL) { 2222 1791 self->id = PyString_FromString(""); 2223 if (self->id == NULL) {2224 Py_DECREF(self);2225 return NULL;2226 }2227 1792 self->reg_uri = PyString_FromString(""); 2228 if (self->reg_uri == NULL) {2229 Py_DECREF(self);2230 return NULL;2231 }2232 1793 self->force_contact = PyString_FromString(""); 2233 if (self->force_contact == NULL) {2234 Py_DECREF(self);2235 return NULL;2236 }2237 1794 self->proxy = (PyListObject *)PyList_New(0); 2238 if (self->proxy == NULL) {2239 Py_DECREF(self);2240 return NULL;2241 }2242 1795 self->cred_info = (PyListObject *)PyList_New(0); 2243 if (self->cred_info == NULL) {2244 Py_DECREF(self);2245 return NULL;2246 }2247 1796 self->auth_initial_algorithm = PyString_FromString(""); 2248 1797 self->pidf_tuple_id = PyString_FromString(""); … … 2305 1854 }, 2306 1855 { 2307 "reg_timeout", T_INT, offsetof(PyObj_pjsua_acc_config, reg_timeout), 0, 1856 "reg_timeout", T_INT, 1857 offsetof(PyObj_pjsua_acc_config, reg_timeout), 0, 2308 1858 "Optional interval for registration, in seconds. " 2309 1859 "If the value is zero, default interval will be used " … … 2328 1878 " use, so in that case it can set this field." 2329 1879 }, 2330 2331 1880 { 2332 1881 "auth_initial_send", T_INT, … … 2388 1937 PyObject_HEAD_INIT(NULL) 2389 1938 0, /*ob_size*/ 2390 "_pjsua.Acc_Config", 2391 sizeof(PyObj_pjsua_acc_config), 1939 "_pjsua.Acc_Config", /*tp_name*/ 1940 sizeof(PyObj_pjsua_acc_config), /*tp_basicsize*/ 2392 1941 0, /*tp_itemsize*/ 2393 1942 (destructor)PyObj_pjsua_acc_config_delete,/*tp_dealloc*/ … … 2407 1956 0, /*tp_as_buffer*/ 2408 1957 Py_TPFLAGS_DEFAULT, /*tp_flags*/ 2409 "Acc Config objects",/* tp_doc */1958 "Account settings", /* tp_doc */ 2410 1959 0, /* tp_traverse */ 2411 1960 0, /* tp_clear */ … … 2414 1963 0, /* tp_iter */ 2415 1964 0, /* tp_iternext */ 2416 0 /*acc_config_methods*/, /* tp_methods */2417 PyObj_pjsua_acc_config_members, 1965 0, /* tp_methods */ 1966 PyObj_pjsua_acc_config_members, /* tp_members */ 2418 1967 0, /* tp_getset */ 2419 1968 0, /* tp_base */ … … 2424 1973 0, /* tp_init */ 2425 1974 0, /* tp_alloc */ 2426 PyObj_pjsua_acc_config_new, 1975 PyObj_pjsua_acc_config_new, /* tp_new */ 2427 1976 2428 1977 }; … … 2468 2017 obj->id = info->id; 2469 2018 obj->is_default = info->is_default; 2470 obj->acc_uri = PyString_FromStringAndSize(info->acc_uri.ptr,2471 info->acc_uri.slen);2019 Py_XDECREF(obj->acc_uri); 2020 obj->acc_uri = PyString_FromPJ(&info->acc_uri); 2472 2021 obj->has_registration = info->has_registration; 2473 2022 obj->expires = info->expires; 2474 2023 obj->status = info->status; 2475 obj->status_text= PyString_FromStringAndSize(info->status_text.ptr,2476 info->status_text.slen);2024 Py_XDECREF(obj->status_text); 2025 obj->status_text= PyString_FromPJ(&info->status_text); 2477 2026 obj->online_status = info->online_status; 2478 obj->online_status_text = PyString_FromStringAndSize(info->online_status_text.ptr,2479 info->online_status_text.slen);2027 Py_XDECREF(obj->online_status_text); 2028 obj->online_status_text = PyString_FromPJ(&info->online_status_text); 2480 2029 } 2481 2030 … … 2497 2046 if (self != NULL) { 2498 2047 self->acc_uri = PyString_FromString(""); 2499 if (self->acc_uri == NULL) {2500 Py_DECREF(self);2501 return NULL;2502 }2503 2048 self->status_text = PyString_FromString(""); 2504 if (self->status_text == NULL) {2505 Py_DECREF(self);2506 return NULL;2507 }2508 2049 self->online_status_text = PyString_FromString(""); 2509 if (self->online_status_text == NULL) {2510 Py_DECREF(self);2511 return NULL;2512 }2513 2050 } 2514 2051 … … 2582 2119 PyObject_HEAD_INIT(NULL) 2583 2120 0, /*ob_size*/ 2584 "_pjsua.Acc_Info", 2585 sizeof(PyObj_pjsua_acc_info), /*tp_basicsize*/2121 "_pjsua.Acc_Info", /*tp_name*/ 2122 sizeof(PyObj_pjsua_acc_info), /*tp_basicsize*/ 2586 2123 0, /*tp_itemsize*/ 2587 2124 (destructor)PyObj_pjsua_acc_info_delete,/*tp_dealloc*/ … … 2601 2138 0, /*tp_as_buffer*/ 2602 2139 Py_TPFLAGS_DEFAULT, /*tp_flags*/ 2603 "Acc Info objects",/* tp_doc */2140 "Account info", /* tp_doc */ 2604 2141 0, /* tp_traverse */ 2605 2142 0, /* tp_clear */ … … 2653 2190 { 2654 2191 Py_XDECREF(obj->uri); 2655 obj->uri = PyString_From StringAndSize(cfg->uri.ptr, cfg->uri.slen);2192 obj->uri = PyString_FromPJ(&cfg->uri); 2656 2193 obj->subscribe = cfg->subscribe; 2657 2194 } … … 2661 2198 PyObj_pjsua_buddy_config *obj) 2662 2199 { 2663 cfg->uri = PyString_ to_pj_str(obj->uri);2200 cfg->uri = PyString_ToPJ(obj->uri); 2664 2201 cfg->subscribe = obj->subscribe; 2665 } 2666 2202 cfg->user_data = NULL; 2203 } 2667 2204 2668 2205 … … 2683 2220 if (self != NULL) { 2684 2221 self->uri = PyString_FromString(""); 2685 if (self->uri == NULL) {2686 Py_DECREF(self);2687 return NULL;2688 }2689 2222 } 2690 2223 return (PyObject *)self; … … 2741 2274 0, /*tp_as_buffer*/ 2742 2275 Py_TPFLAGS_DEFAULT, /*tp_flags*/ 2743 "Buddy Config objects",/* tp_doc */2276 "Buddy config", /* tp_doc */ 2744 2277 0, /* tp_traverse */ 2745 2278 0, /* tp_clear */ … … 2749 2282 0, /* tp_iternext */ 2750 2283 0, /* tp_methods */ 2751 PyObj_pjsua_buddy_config_members, 2284 PyObj_pjsua_buddy_config_members,/* tp_members */ 2752 2285 0, /* tp_getset */ 2753 2286 0, /* tp_base */ … … 2804 2337 obj->id = info->id; 2805 2338 Py_XDECREF(obj->uri); 2806 obj->uri = PyString_From StringAndSize(info->uri.ptr, info->uri.slen);2339 obj->uri = PyString_FromPJ(&info->uri); 2807 2340 Py_XDECREF(obj->contact); 2808 obj->contact = PyString_From StringAndSize(info->contact.ptr, info->contact.slen);2341 obj->contact = PyString_FromPJ(&info->contact); 2809 2342 obj->status = info->status; 2810 2343 Py_XDECREF(obj->status_text); 2811 obj->status_text = PyString_FromStringAndSize(info->status_text.ptr, 2812 info->status_text.slen); 2344 obj->status_text = PyString_FromPJ(&info->status_text); 2813 2345 obj->monitor_pres = info->monitor_pres; 2814 2346 obj->activity = info->rpid.activity; 2815 2347 obj->sub_state = info->sub_state; 2816 2348 Py_XDECREF(obj->sub_term_reason); 2817 obj->sub_term_reason = PyString_FromStringAndSize(info->sub_term_reason.ptr, 2818 info->sub_term_reason.slen); 2349 obj->sub_term_reason = PyString_FromPJ(&info->sub_term_reason); 2819 2350 } 2820 2351 … … 2837 2368 if (self != NULL) { 2838 2369 self->uri = PyString_FromString(""); 2839 if (self->uri == NULL) {2840 Py_DECREF(self);2841 return NULL;2842 }2843 2370 self->contact = PyString_FromString(""); 2844 if (self->contact == NULL) {2845 Py_DECREF(self);2846 return NULL;2847 }2848 2371 self->status_text = PyString_FromString(""); 2849 if (self->status_text == NULL) {2850 Py_DECREF(self);2851 return NULL;2852 }2853 2372 self->sub_term_reason = PyString_FromString(""); 2854 2373 } … … 2924 2443 PyObject_HEAD_INIT(NULL) 2925 2444 0, /*ob_size*/ 2926 "_pjsua.Buddy_Info", 2927 sizeof(PyObj_pjsua_buddy_info), 2445 "_pjsua.Buddy_Info", /*tp_name*/ 2446 sizeof(PyObj_pjsua_buddy_info), /*tp_basicsize*/ 2928 2447 0, /*tp_itemsize*/ 2929 2448 (destructor)PyObj_pjsua_buddy_info_delete,/*tp_dealloc*/ … … 2943 2462 0, /*tp_as_buffer*/ 2944 2463 Py_TPFLAGS_DEFAULT, /*tp_flags*/ 2945 "Buddy Info object s",/* tp_doc */2464 "Buddy Info object", /* tp_doc */ 2946 2465 0, /* tp_traverse */ 2947 2466 0, /* tp_clear */ … … 2951 2470 0, /* tp_iternext */ 2952 2471 0, /* tp_methods */ 2953 PyObj_pjsua_buddy_info_members, 2472 PyObj_pjsua_buddy_info_members, /* tp_members */ 2954 2473 0, /* tp_getset */ 2955 2474 0, /* tp_base */ … … 2960 2479 0, /* tp_init */ 2961 2480 0, /* tp_alloc */ 2962 PyObj_pjsua_buddy_info_new, /* tp_new */ 2963 2964 }; 2965 2966 2967 2968 2481 PyObj_pjsua_buddy_info_new, /* tp_new */ 2482 2483 }; 2484 2485 2486 ////////////////////////////////////////////////////////////////////////////// 2487 2488 /* 2489 * PyObj_pjsua_codec_info 2490 * Codec Info 2491 */ 2492 typedef struct 2493 { 2494 PyObject_HEAD 2495 /* Type-specific fields go here. */ 2496 2497 PyObject * codec_id; 2498 pj_uint8_t priority; 2499 } PyObj_pjsua_codec_info; 2500 2501 2502 /* 2503 * codec_info_dealloc 2504 * deletes a codec_info from memory 2505 */ 2506 static void codec_info_dealloc(PyObj_pjsua_codec_info* self) 2507 { 2508 Py_XDECREF(self->codec_id); 2509 self->ob_type->tp_free((PyObject*)self); 2510 } 2511 2512 2513 /* 2514 * codec_info_new 2515 * constructor for codec_info object 2516 */ 2517 static PyObject * codec_info_new(PyTypeObject *type, PyObject *args, 2518 PyObject *kwds) 2519 { 2520 PyObj_pjsua_codec_info *self; 2521 2522 PJ_UNUSED_ARG(args); 2523 PJ_UNUSED_ARG(kwds); 2524 2525 self = (PyObj_pjsua_codec_info *)type->tp_alloc(type, 0); 2526 if (self != NULL) { 2527 self->codec_id = PyString_FromString(""); 2528 } 2529 return (PyObject *)self; 2530 } 2531 2532 /* 2533 * codec_info_members 2534 * !modified @ 071206 2535 */ 2536 static PyMemberDef codec_info_members[] = 2537 { 2538 { 2539 "codec_id", T_OBJECT_EX, 2540 offsetof(PyObj_pjsua_codec_info, codec_id), 0, 2541 "Codec unique identification." 2542 }, 2543 { 2544 "priority", T_INT, 2545 offsetof(PyObj_pjsua_codec_info, priority), 0, 2546 "Codec priority (integer 0-255)." 2547 }, 2548 2549 {NULL} /* Sentinel */ 2550 }; 2551 2552 /* 2553 * PyTyp_pjsua_codec_info 2554 */ 2555 static PyTypeObject PyTyp_pjsua_codec_info = 2556 { 2557 PyObject_HEAD_INIT(NULL) 2558 0, /*ob_size*/ 2559 "_pjsua.Codec_Info", /*tp_name*/ 2560 sizeof(PyObj_pjsua_codec_info), /*tp_basicsize*/ 2561 0, /*tp_itemsize*/ 2562 (destructor)codec_info_dealloc, /*tp_dealloc*/ 2563 0, /*tp_print*/ 2564 0, /*tp_getattr*/ 2565 0, /*tp_setattr*/ 2566 0, /*tp_compare*/ 2567 0, /*tp_repr*/ 2568 0, /*tp_as_number*/ 2569 0, /*tp_as_sequence*/ 2570 0, /*tp_as_mapping*/ 2571 0, /*tp_hash */ 2572 0, /*tp_call*/ 2573 0, /*tp_str*/ 2574 0, /*tp_getattro*/ 2575 0, /*tp_setattro*/ 2576 0, /*tp_as_buffer*/ 2577 Py_TPFLAGS_DEFAULT, /*tp_flags*/ 2578 "Codec Info", /* tp_doc */ 2579 0, /* tp_traverse */ 2580 0, /* tp_clear */ 2581 0, /* tp_richcompare */ 2582 0, /* tp_weaklistoffset */ 2583 0, /* tp_iter */ 2584 0, /* tp_iternext */ 2585 0, /* tp_methods */ 2586 codec_info_members, /* tp_members */ 2587 0, /* tp_getset */ 2588 0, /* tp_base */ 2589 0, /* tp_dict */ 2590 0, /* tp_descr_get */ 2591 0, /* tp_descr_set */ 2592 0, /* tp_dictoffset */ 2593 0, /* tp_init */ 2594 0, /* tp_alloc */ 2595 codec_info_new, /* tp_new */ 2596 2597 }; 2598 2599 2600 ////////////////////////////////////////////////////////////////////////////// 2601 2602 /* 2603 * PyObj_pjsua_conf_port_info 2604 * Conf Port Info 2605 */ 2606 typedef struct 2607 { 2608 PyObject_HEAD 2609 /* Type-specific fields go here. */ 2610 2611 int slot_id; 2612 PyObject *name; 2613 unsigned clock_rate; 2614 unsigned channel_count; 2615 unsigned samples_per_frame; 2616 unsigned bits_per_sample; 2617 PyObject *listeners; 2618 2619 } PyObj_pjsua_conf_port_info; 2620 2621 2622 /* 2623 * conf_port_info_dealloc 2624 * deletes a conf_port_info from memory 2625 */ 2626 static void conf_port_info_dealloc(PyObj_pjsua_conf_port_info* self) 2627 { 2628 Py_XDECREF(self->name); 2629 Py_XDECREF(self->listeners); 2630 self->ob_type->tp_free((PyObject*)self); 2631 } 2632 2633 2634 /* 2635 * conf_port_info_new 2636 * constructor for conf_port_info object 2637 */ 2638 static PyObject * conf_port_info_new(PyTypeObject *type, PyObject *args, 2639 PyObject *kwds) 2640 { 2641 PyObj_pjsua_conf_port_info *self; 2642 2643 PJ_UNUSED_ARG(args); 2644 PJ_UNUSED_ARG(kwds); 2645 2646 self = (PyObj_pjsua_conf_port_info *)type->tp_alloc(type, 0); 2647 if (self != NULL) { 2648 self->name = PyString_FromString(""); 2649 self->listeners = PyList_New(0); 2650 } 2651 return (PyObject *)self; 2652 } 2653 2654 /* 2655 * conf_port_info_members 2656 */ 2657 static PyMemberDef conf_port_info_members[] = 2658 { 2659 { 2660 "slot_id", T_INT, 2661 offsetof(PyObj_pjsua_conf_port_info, slot_id), 0, 2662 "Conference port number." 2663 }, 2664 { 2665 "name", T_OBJECT_EX, 2666 offsetof(PyObj_pjsua_conf_port_info, name), 0, 2667 "Port name" 2668 }, 2669 { 2670 "clock_rate", T_INT, 2671 offsetof(PyObj_pjsua_conf_port_info, clock_rate), 0, 2672 "Clock rate" 2673 }, 2674 { 2675 "channel_count", T_INT, 2676 offsetof(PyObj_pjsua_conf_port_info, channel_count), 0, 2677 "Number of channels." 2678 }, 2679 { 2680 "samples_per_frame", T_INT, 2681 offsetof(PyObj_pjsua_conf_port_info, samples_per_frame), 0, 2682 "Samples per frame " 2683 }, 2684 { 2685 "bits_per_sample", T_INT, 2686 offsetof(PyObj_pjsua_conf_port_info, bits_per_sample), 0, 2687 "Bits per sample" 2688 }, 2689 { 2690 "listeners", T_OBJECT_EX, 2691 offsetof(PyObj_pjsua_conf_port_info, listeners), 0, 2692 "Array of listeners (in other words, ports where this port " 2693 "is transmitting to" 2694 }, 2695 2696 {NULL} /* Sentinel */ 2697 }; 2698 2699 2700 2701 2702 /* 2703 * PyTyp_pjsua_conf_port_info 2704 */ 2705 static PyTypeObject PyTyp_pjsua_conf_port_info = 2706 { 2707 PyObject_HEAD_INIT(NULL) 2708 0, /*ob_size*/ 2709 "_pjsua.Conf_Port_Info", /*tp_name*/ 2710 sizeof(PyObj_pjsua_conf_port_info), /*tp_basicsize*/ 2711 0, /*tp_itemsize*/ 2712 (destructor)conf_port_info_dealloc,/*tp_dealloc*/ 2713 0, /*tp_print*/ 2714 0, /*tp_getattr*/ 2715 0, /*tp_setattr*/ 2716 0, /*tp_compare*/ 2717 0, /*tp_repr*/ 2718 0, /*tp_as_number*/ 2719 0, /*tp_as_sequence*/ 2720 0, /*tp_as_mapping*/ 2721 0, /*tp_hash */ 2722 0, /*tp_call*/ 2723 0, /*tp_str*/ 2724 0, /*tp_getattro*/ 2725 0, /*tp_setattro*/ 2726 0, /*tp_as_buffer*/ 2727 Py_TPFLAGS_DEFAULT, /*tp_flags*/ 2728 "Conf Port Info objects", /* tp_doc */ 2729 0, /* tp_traverse */ 2730 0, /* tp_clear */ 2731 0, /* tp_richcompare */ 2732 0, /* tp_weaklistoffset */ 2733 0, /* tp_iter */ 2734 0, /* tp_iternext */ 2735 0, /* tp_methods */ 2736 conf_port_info_members, /* tp_members */ 2737 0, /* tp_getset */ 2738 0, /* tp_base */ 2739 0, /* tp_dict */ 2740 0, /* tp_descr_get */ 2741 0, /* tp_descr_set */ 2742 0, /* tp_dictoffset */ 2743 0, /* tp_init */ 2744 0, /* tp_alloc */ 2745 conf_port_info_new, /* tp_new */ 2746 2747 }; 2748 2749 ////////////////////////////////////////////////////////////////////////////// 2750 2751 /* 2752 * PyObj_pjmedia_snd_dev_info 2753 * PJMedia Snd Dev Info 2754 */ 2755 typedef struct 2756 { 2757 PyObject_HEAD 2758 /* Type-specific fields go here. */ 2759 2760 unsigned input_count; 2761 unsigned output_count; 2762 unsigned default_samples_per_sec; 2763 PyObject *name; 2764 2765 } PyObj_pjmedia_snd_dev_info; 2766 2767 /* 2768 * pjmedia_snd_dev_info_dealloc 2769 * deletes a pjmedia_snd_dev_info from memory 2770 */ 2771 static void pjmedia_snd_dev_info_dealloc(PyObj_pjmedia_snd_dev_info* self) 2772 { 2773 Py_XDECREF(self->name); 2774 self->ob_type->tp_free((PyObject*)self); 2775 } 2776 2777 /* 2778 * pjmedia_snd_dev_info_new 2779 * constructor for pjmedia_snd_dev_info object 2780 */ 2781 static PyObject * pjmedia_snd_dev_info_new(PyTypeObject *type, 2782 PyObject *args, 2783 PyObject *kwds) 2784 { 2785 PyObj_pjmedia_snd_dev_info *self; 2786 2787 PJ_UNUSED_ARG(args); 2788 PJ_UNUSED_ARG(kwds); 2789 2790 self = (PyObj_pjmedia_snd_dev_info *)type->tp_alloc(type, 0); 2791 if (self != NULL) { 2792 self->name = PyString_FromString(""); 2793 } 2794 return (PyObject *)self; 2795 } 2796 2797 /* 2798 * pjmedia_snd_dev_info_members 2799 */ 2800 static PyMemberDef pjmedia_snd_dev_info_members[] = 2801 { 2802 { 2803 "input_count", T_INT, 2804 offsetof(PyObj_pjmedia_snd_dev_info, input_count), 0, 2805 "Max number of input channels" 2806 }, 2807 { 2808 "output_count", T_INT, 2809 offsetof(PyObj_pjmedia_snd_dev_info, output_count), 0, 2810 "Max number of output channels" 2811 }, 2812 { 2813 "default_samples_per_sec", T_INT, 2814 offsetof(PyObj_pjmedia_snd_dev_info, default_samples_per_sec), 0, 2815 "Default sampling rate." 2816 }, 2817 { 2818 "name", T_OBJECT_EX, 2819 offsetof(PyObj_pjmedia_snd_dev_info, name), 0, 2820 "Device name" 2821 }, 2822 2823 {NULL} /* Sentinel */ 2824 }; 2825 2826 2827 /* 2828 * PyTyp_pjmedia_snd_dev_info 2829 */ 2830 static PyTypeObject PyTyp_pjmedia_snd_dev_info = 2831 { 2832 PyObject_HEAD_INIT(NULL) 2833 0, /*ob_size*/ 2834 "_pjsua.PJMedia_Snd_Dev_Info", /*tp_name*/ 2835 sizeof(PyObj_pjmedia_snd_dev_info), /*tp_basicsize*/ 2836 0, /*tp_itemsize*/ 2837 (destructor)pjmedia_snd_dev_info_dealloc,/*tp_dealloc*/ 2838 0, /*tp_print*/ 2839 0, /*tp_getattr*/ 2840 0, /*tp_setattr*/ 2841 0, /*tp_compare*/ 2842 0, /*tp_repr*/ 2843 0, /*tp_as_number*/ 2844 0, /*tp_as_sequence*/ 2845 0, /*tp_as_mapping*/ 2846 0, /*tp_hash */ 2847 0, /*tp_call*/ 2848 0, /*tp_str*/ 2849 0, /*tp_getattro*/ 2850 0, /*tp_setattro*/ 2851 0, /*tp_as_buffer*/ 2852 Py_TPFLAGS_DEFAULT, /*tp_flags*/ 2853 "PJMedia Snd Dev Info object", /* tp_doc */ 2854 0, /* tp_traverse */ 2855 0, /* tp_clear */ 2856 0, /* tp_richcompare */ 2857 0, /* tp_weaklistoffset */ 2858 0, /* tp_iter */ 2859 0, /* tp_iternext */ 2860 0, /* tp_methods */ 2861 pjmedia_snd_dev_info_members, /* tp_members */ 2862 0, /* tp_getset */ 2863 0, /* tp_base */ 2864 0, /* tp_dict */ 2865 0, /* tp_descr_get */ 2866 0, /* tp_descr_set */ 2867 0, /* tp_dictoffset */ 2868 0, /* tp_init */ 2869 0, /* tp_alloc */ 2870 pjmedia_snd_dev_info_new, /* tp_new */ 2871 2872 }; 2873 2874 ////////////////////////////////////////////////////////////////////////////// 2875 2876 /* 2877 * PyObj_pjmedia_codec_param_info 2878 * PJMedia Codec Param Info 2879 */ 2880 typedef struct 2881 { 2882 PyObject_HEAD 2883 /* Type-specific fields go here. */ 2884 2885 unsigned clock_rate; 2886 unsigned channel_cnt; 2887 pj_uint32_t avg_bps; 2888 pj_uint16_t frm_ptime; 2889 pj_uint8_t pcm_bits_per_sample; 2890 pj_uint8_t pt; 2891 2892 } PyObj_pjmedia_codec_param_info; 2893 2894 2895 2896 /* 2897 * pjmedia_codec_param_info_members 2898 */ 2899 static PyMemberDef pjmedia_codec_param_info_members[] = 2900 { 2901 { 2902 "clock_rate", T_INT, 2903 offsetof(PyObj_pjmedia_codec_param_info, clock_rate), 0, 2904 "Sampling rate in Hz" 2905 }, 2906 { 2907 "channel_cnt", T_INT, 2908 offsetof(PyObj_pjmedia_codec_param_info, channel_cnt), 0, 2909 "Channel count" 2910 }, 2911 { 2912 "avg_bps", T_INT, 2913 offsetof(PyObj_pjmedia_codec_param_info, avg_bps), 0, 2914 "Average bandwidth in bits/sec" 2915 }, 2916 { 2917 "frm_ptime", T_INT, 2918 offsetof(PyObj_pjmedia_codec_param_info, frm_ptime), 0, 2919 "Base frame ptime in msec." 2920 }, 2921 { 2922 "pcm_bits_per_sample", T_INT, 2923 offsetof(PyObj_pjmedia_codec_param_info, pcm_bits_per_sample), 0, 2924 "Bits/sample in the PCM side" 2925 }, 2926 { 2927 "pt", T_INT, 2928 offsetof(PyObj_pjmedia_codec_param_info, pt), 0, 2929 "Payload type" 2930 }, 2931 2932 {NULL} /* Sentinel */ 2933 }; 2934 2935 2936 /* 2937 * PyTyp_pjmedia_codec_param_info 2938 */ 2939 static PyTypeObject PyTyp_pjmedia_codec_param_info = 2940 { 2941 PyObject_HEAD_INIT(NULL) 2942 0, /*ob_size*/ 2943 "_pjsua.PJMedia_Codec_Param_Info", /*tp_name*/ 2944 sizeof(PyObj_pjmedia_codec_param_info), /*tp_basicsize*/ 2945 0, /*tp_itemsize*/ 2946 0, /*tp_dealloc*/ 2947 0, /*tp_print*/ 2948 0, /*tp_getattr*/ 2949 0, /*tp_setattr*/ 2950 0, /*tp_compare*/ 2951 0, /*tp_repr*/ 2952 0, /*tp_as_number*/ 2953 0, /*tp_as_sequence*/ 2954 0, /*tp_as_mapping*/ 2955 0, /*tp_hash */ 2956 0, /*tp_call*/ 2957 0, /*tp_str*/ 2958 0, /*tp_getattro*/ 2959 0, /*tp_setattro*/ 2960 0, /*tp_as_buffer*/ 2961 Py_TPFLAGS_DEFAULT, /*tp_flags*/ 2962 "PJMedia Codec Param Info objects",/* tp_doc */ 2963 0, /* tp_traverse */ 2964 0, /* tp_clear */ 2965 0, /* tp_richcompare */ 2966 0, /* tp_weaklistoffset */ 2967 0, /* tp_iter */ 2968 0, /* tp_iternext */ 2969 0, /* tp_methods */ 2970 pjmedia_codec_param_info_members,/* tp_members */ 2971 }; 2972 2973 2974 ////////////////////////////////////////////////////////////////////////////// 2975 2976 /* 2977 * PyObj_pjmedia_codec_param_setting 2978 * PJMedia Codec Param Setting 2979 */ 2980 typedef struct 2981 { 2982 PyObject_HEAD 2983 /* Type-specific fields go here. */ 2984 pj_uint8_t frm_per_pkt; 2985 unsigned vad; 2986 unsigned cng; 2987 unsigned penh; 2988 unsigned plc; 2989 pj_uint8_t enc_fmtp_mode; 2990 pj_uint8_t dec_fmtp_mode; 2991 2992 } PyObj_pjmedia_codec_param_setting; 2993 2994 2995 2996 /* 2997 * pjmedia_codec_param_setting_members 2998 */ 2999 static PyMemberDef pjmedia_codec_param_setting_members[] = 3000 { 3001 { 3002 "frm_per_pkt", T_INT, 3003 offsetof(PyObj_pjmedia_codec_param_setting, frm_per_pkt), 0, 3004 "Number of frames per packet" 3005 }, 3006 { 3007 "vad", T_INT, 3008 offsetof(PyObj_pjmedia_codec_param_setting, vad), 0, 3009 "Voice Activity Detector" 3010 }, 3011 { 3012 "cng", T_INT, 3013 offsetof(PyObj_pjmedia_codec_param_setting, cng), 0, 3014 "Comfort Noise Generator" 3015 }, 3016 { 3017 "penh", T_INT, 3018 offsetof(PyObj_pjmedia_codec_param_setting, penh), 0, 3019 "Perceptual Enhancement" 3020 }, 3021 { 3022 "plc", T_INT, 3023 offsetof(PyObj_pjmedia_codec_param_setting, plc), 0, 3024 "Packet loss concealment" 3025 }, 3026 { 3027 "enc_fmtp_mode", T_INT, 3028 offsetof(PyObj_pjmedia_codec_param_setting, enc_fmtp_mode), 0, 3029 "Mode param in fmtp (def:0)" 3030 }, 3031 { 3032 "dec_fmtp_mode", T_INT, 3033 offsetof(PyObj_pjmedia_codec_param_setting, dec_fmtp_mode), 0, 3034 "Mode param in fmtp (def:0)" 3035 }, 3036 3037 {NULL} /* Sentinel */ 3038 }; 3039 3040 3041 /* 3042 * PyTyp_pjmedia_codec_param_setting 3043 */ 3044 static PyTypeObject PyTyp_pjmedia_codec_param_setting = 3045 { 3046 PyObject_HEAD_INIT(NULL) 3047 0, /*ob_size*/ 3048 "_pjsua.PJMedia_Codec_Param_Setting",/*tp_name*/ 3049 sizeof(PyObj_pjmedia_codec_param_setting), /*tp_basicsize*/ 3050 0, /*tp_itemsize*/ 3051 0, /*tp_dealloc*/ 3052 0, /*tp_print*/ 3053 0, /*tp_getattr*/ 3054 0, /*tp_setattr*/ 3055 0, /*tp_compare*/ 3056 0, /*tp_repr*/ 3057 0, /*tp_as_number*/ 3058 0, /*tp_as_sequence*/ 3059 0, /*tp_as_mapping*/ 3060 0, /*tp_hash */ 3061 0, /*tp_call*/ 3062 0, /*tp_str*/ 3063 0, /*tp_getattro*/ 3064 0, /*tp_setattro*/ 3065 0, /*tp_as_buffer*/ 3066 Py_TPFLAGS_DEFAULT, /*tp_flags*/ 3067 "PJMedia Codec Param Setting", /* tp_doc */ 3068 0, /* tp_traverse */ 3069 0, /* tp_clear */ 3070 0, /* tp_richcompare */ 3071 0, /* tp_weaklistoffset */ 3072 0, /* tp_iter */ 3073 0, /* tp_iternext */ 3074 0, /* tp_methods */ 3075 pjmedia_codec_param_setting_members,/* tp_members */ 3076 }; 3077 3078 ////////////////////////////////////////////////////////////////////////////// 3079 3080 3081 /* 3082 * PyObj_pjmedia_codec_param 3083 * PJMedia Codec Param 3084 */ 3085 typedef struct 3086 { 3087 PyObject_HEAD 3088 /* Type-specific fields go here. */ 3089 3090 PyObj_pjmedia_codec_param_info * info; 3091 PyObj_pjmedia_codec_param_setting * setting; 3092 3093 } PyObj_pjmedia_codec_param; 3094 3095 /* 3096 * pjmedia_codec_param_dealloc 3097 * deletes a pjmedia_codec_param from memory 3098 */ 3099 static void pjmedia_codec_param_dealloc(PyObj_pjmedia_codec_param* self) 3100 { 3101 Py_XDECREF(self->info); 3102 Py_XDECREF(self->setting); 3103 self->ob_type->tp_free((PyObject*)self); 3104 } 3105 3106 /* 3107 * pjmedia_codec_param_new 3108 * constructor for pjmedia_codec_param object 3109 */ 3110 static PyObject * pjmedia_codec_param_new(PyTypeObject *type, 3111 PyObject *args, 3112 PyObject *kwds) 3113 { 3114 PyObj_pjmedia_codec_param *self; 3115 3116 PJ_UNUSED_ARG(args); 3117 PJ_UNUSED_ARG(kwds); 3118 3119 self = (PyObj_pjmedia_codec_param *)type->tp_alloc(type, 0); 3120 if (self != NULL) { 3121 self->info = (PyObj_pjmedia_codec_param_info *) 3122 PyType_GenericNew(&PyTyp_pjmedia_codec_param_info, 3123 NULL, NULL); 3124 self->setting = (PyObj_pjmedia_codec_param_setting *) 3125 PyType_GenericNew(&PyTyp_pjmedia_codec_param_setting, 3126 NULL, NULL); 3127 } 3128 return (PyObject *)self; 3129 } 3130 3131 /* 3132 * pjmedia_codec_param_members 3133 */ 3134 static PyMemberDef pjmedia_codec_param_members[] = 3135 { 3136 3137 { 3138 "info", T_OBJECT_EX, 3139 offsetof(PyObj_pjmedia_codec_param, info), 0, 3140 "The 'info' part of codec param describes the capability of the codec," 3141 " and the value should NOT be changed by application." 3142 }, 3143 { 3144 "setting", T_OBJECT_EX, 3145 offsetof(PyObj_pjmedia_codec_param, setting), 0, 3146 "The 'setting' part of codec param describes various settings to be " 3147 "applied to the codec. When the codec param is retrieved from the " 3148 "codec or codec factory, the values of these will be filled by " 3149 "the capability of the codec. Any features that are supported by " 3150 "the codec (e.g. vad or plc) will be turned on, so that application " 3151 "can query which capabilities are supported by the codec. " 3152 "Application may change the settings here before instantiating " 3153 "the codec/stream." 3154 }, 3155 3156 {NULL} /* Sentinel */ 3157 }; 3158 3159 /* 3160 * PyTyp_pjmedia_codec_param 3161 */ 3162 static PyTypeObject PyTyp_pjmedia_codec_param = 3163 { 3164 PyObject_HEAD_INIT(NULL) 3165 0, /*ob_size*/ 3166 "_pjsua.PJMedia_Codec_Param", /*tp_name*/ 3167 sizeof(PyObj_pjmedia_codec_param),/*tp_basicsize*/ 3168 0, /*tp_itemsize*/ 3169 (destructor)pjmedia_codec_param_dealloc,/*tp_dealloc*/ 3170 0, /*tp_print*/ 3171 0, /*tp_getattr*/ 3172 0, /*tp_setattr*/ 3173 0, /*tp_compare*/ 3174 0, /*tp_repr*/ 3175 0, /*tp_as_number*/ 3176 0, /*tp_as_sequence*/ 3177 0, /*tp_as_mapping*/ 3178 0, /*tp_hash */ 3179 0, /*tp_call*/ 3180 0, /*tp_str*/ 3181 0, /*tp_getattro*/ 3182 0, /*tp_setattro*/ 3183 0, /*tp_as_buffer*/ 3184 Py_TPFLAGS_DEFAULT, /*tp_flags*/ 3185 "PJMedia Codec Param", /* tp_doc */ 3186 0, /* tp_traverse */ 3187 0, /* tp_clear */ 3188 0, /* tp_richcompare */ 3189 0, /* tp_weaklistoffset */ 3190 0, /* tp_iter */ 3191 0, /* tp_iternext */ 3192 0, /* tp_methods */ 3193 pjmedia_codec_param_members, /* tp_members */ 3194 0, /* tp_getset */ 3195 0, /* tp_base */ 3196 0, /* tp_dict */ 3197 0, /* tp_descr_get */ 3198 0, /* tp_descr_set */ 3199 0, /* tp_dictoffset */ 3200 0, /* tp_init */ 3201 0, /* tp_alloc */ 3202 pjmedia_codec_param_new, /* tp_new */ 3203 3204 }; 3205 3206 ////////////////////////////////////////////////////////////////////////////// 3207 3208 /* 3209 * PyObj_pjsua_call_info 3210 * Call Info 3211 */ 3212 typedef struct 3213 { 3214 PyObject_HEAD 3215 /* Type-specific fields go here. */ 3216 3217 int id; 3218 int role; 3219 int acc_id; 3220 PyObject *local_info; 3221 PyObject *local_contact; 3222 PyObject *remote_info; 3223 PyObject *remote_contact; 3224 PyObject *call_id; 3225 int state; 3226 PyObject *state_text; 3227 int last_status; 3228 PyObject *last_status_text; 3229 int media_status; 3230 int media_dir; 3231 int conf_slot; 3232 int connect_duration; 3233 int total_duration; 3234 3235 } PyObj_pjsua_call_info; 3236 3237 3238 /* 3239 * call_info_dealloc 3240 * deletes a call_info from memory 3241 */ 3242 static void call_info_dealloc(PyObj_pjsua_call_info* self) 3243 { 3244 Py_XDECREF(self->local_info); 3245 Py_XDECREF(self->local_contact); 3246 Py_XDECREF(self->remote_info); 3247 Py_XDECREF(self->remote_contact); 3248 Py_XDECREF(self->call_id); 3249 Py_XDECREF(self->state_text); 3250 Py_XDECREF(self->last_status_text); 3251 self->ob_type->tp_free((PyObject*)self); 3252 } 3253 3254 3255 /* 3256 * call_info_new 3257 * constructor for call_info object 3258 */ 3259 static PyObject * call_info_new(PyTypeObject *type, PyObject *args, 3260 PyObject *kwds) 3261 { 3262 PyObj_pjsua_call_info *self; 3263 3264 PJ_UNUSED_ARG(args); 3265 PJ_UNUSED_ARG(kwds); 3266 3267 self = (PyObj_pjsua_call_info *)type->tp_alloc(type, 0); 3268 if (self != NULL) { 3269 self->local_info = PyString_FromString(""); 3270 self->local_contact = PyString_FromString(""); 3271 self->remote_info = PyString_FromString(""); 3272 self->remote_contact = PyString_FromString(""); 3273 self->call_id = PyString_FromString(""); 3274 self->state_text = PyString_FromString(""); 3275 self->last_status_text = PyString_FromString(""); 3276 } 3277 return (PyObject *)self; 3278 } 3279 3280 /* 3281 * call_info_members 3282 */ 3283 static PyMemberDef call_info_members[] = 3284 { 3285 { 3286 "id", T_INT, 3287 offsetof(PyObj_pjsua_call_info, id), 0, 3288 "Call identification" 3289 }, 3290 { 3291 "role", T_INT, 3292 offsetof(PyObj_pjsua_call_info, role), 0, 3293 "Initial call role (UAC == caller)" 3294 }, 3295 { 3296 "acc_id", T_INT, 3297 offsetof(PyObj_pjsua_call_info, acc_id), 0, 3298 "The account ID where this call belongs." 3299 }, 3300 { 3301 "local_info", T_OBJECT_EX, 3302 offsetof(PyObj_pjsua_call_info, local_info), 0, 3303 "Local URI" 3304 }, 3305 { 3306 "local_contact", T_OBJECT_EX, 3307 offsetof(PyObj_pjsua_call_info, local_contact), 0, 3308 "Local Contact" 3309 }, 3310 { 3311 "remote_info", T_OBJECT_EX, 3312 offsetof(PyObj_pjsua_call_info, remote_info), 0, 3313 "Remote URI" 3314 }, 3315 { 3316 "remote_contact", T_OBJECT_EX, 3317 offsetof(PyObj_pjsua_call_info, remote_contact), 0, 3318 "Remote Contact" 3319 }, 3320 { 3321 "call_id", T_OBJECT_EX, 3322 offsetof(PyObj_pjsua_call_info, call_id), 0, 3323 "Dialog Call-ID string" 3324 }, 3325 { 3326 "state", T_INT, 3327 offsetof(PyObj_pjsua_call_info, state), 0, 3328 "Call state" 3329 }, 3330 { 3331 "state_text", T_OBJECT_EX, 3332 offsetof(PyObj_pjsua_call_info, state_text), 0, 3333 "Text describing the state " 3334 }, 3335 { 3336 "last_status", T_INT, 3337 offsetof(PyObj_pjsua_call_info, last_status), 0, 3338 "Last status code heard, which can be used as cause code" 3339 }, 3340 { 3341 "last_status_text", T_OBJECT_EX, 3342 offsetof(PyObj_pjsua_call_info, last_status_text), 0, 3343 "The reason phrase describing the status." 3344 }, 3345 { 3346 "media_status", T_INT, 3347 offsetof(PyObj_pjsua_call_info, media_status), 0, 3348 "Call media status." 3349 }, 3350 { 3351 "media_dir", T_INT, 3352 offsetof(PyObj_pjsua_call_info, media_dir), 0, 3353 "Media direction" 3354 }, 3355 { 3356 "conf_slot", T_INT, 3357 offsetof(PyObj_pjsua_call_info, conf_slot), 0, 3358 "The conference port number for the call" 3359 }, 3360 { 3361 "connect_duration", T_INT, 3362 offsetof(PyObj_pjsua_call_info, connect_duration), 0, 3363 "Up-to-date call connected duration(zero when call is not established)" 3364 }, 3365 { 3366 "total_duration", T_INT, 3367 offsetof(PyObj_pjsua_call_info, total_duration), 0, 3368 "Total call duration, including set-up time" 3369 }, 3370 3371 {NULL} /* Sentinel */ 3372 }; 3373 3374 3375 3376 3377 /* 3378 * PyTyp_pjsua_call_info 3379 */ 3380 static PyTypeObject PyTyp_pjsua_call_info = 3381 { 3382 PyObject_HEAD_INIT(NULL) 3383 0, /*ob_size*/ 3384 "_pjsua.Call_Info", /*tp_name*/ 3385 sizeof(PyObj_pjsua_call_info), /*tp_basicsize*/ 3386 0, /*tp_itemsize*/ 3387 (destructor)call_info_dealloc, /*tp_dealloc*/ 3388 0, /*tp_print*/ 3389 0, /*tp_getattr*/ 3390 0, /*tp_setattr*/ 3391 0, /*tp_compare*/ 3392 0, /*tp_repr*/ 3393 0, /*tp_as_number*/ 3394 0, /*tp_as_sequence*/ 3395 0, /*tp_as_mapping*/ 3396 0, /*tp_hash */ 3397 0, /*tp_call*/ 3398 0, /*tp_str*/ 3399 0, /*tp_getattro*/ 3400 0, /*tp_setattro*/ 3401 0, /*tp_as_buffer*/ 3402 Py_TPFLAGS_DEFAULT, /*tp_flags*/ 3403 "Call Info", /* tp_doc */ 3404 0, /* tp_traverse */ 3405 0, /* tp_clear */ 3406 0, /* tp_richcompare */ 3407 0, /* tp_weaklistoffset */ 3408 0, /* tp_iter */ 3409 0, /* tp_iternext */ 3410 0, /* tp_methods */ 3411 call_info_members, /* tp_members */ 3412 0, /* tp_getset */ 3413 0, /* tp_base */ 3414 0, /* tp_dict */ 3415 0, /* tp_descr_get */ 3416 0, /* tp_descr_set */ 3417 0, /* tp_dictoffset */ 3418 0, /* tp_init */ 3419 0, /* tp_alloc */ 3420 call_info_new, /* tp_new */ 3421 3422 }; 3423 3424 3425 3426 ////////////////////////////////////////////////////////////////////////////// 2969 3427 2970 3428 #endif /* __PY_PJSUA_H__ */ -
pjproject/trunk/pjsip-apps/src/python/pjsua.py
r2158 r2163 151 151 import _pjsua 152 152 import thread 153 import threading 154 import weakref 153 155 154 156 class Error: … … 624 626 625 627 def __init__(self, lib, id): 626 self._lib = lib628 self._lib = weakref.proxy(lib) 627 629 self._id = id 628 self._obj_name = "Transport " + self.info().description 629 630 self._obj_name = "{Transport " + self.info().description + "}" 631 _Trace((self, 'created')) 632 633 def __del__(self): 634 _Trace((self, 'destroyed')) 635 630 636 def __str__(self): 631 637 return self._obj_name … … 634 640 """Get TransportInfo. 635 641 """ 642 lck = self._lib.auto_lock() 636 643 ti = _pjsua.transport_get_info(self._id) 637 644 if not ti: … … 641 648 def enable(self): 642 649 """Enable this transport.""" 650 lck = self._lib.auto_lock() 643 651 err = _pjsua.transport_set_enable(self._id, True) 644 652 self._lib._err_check("enable()", self, err) … … 646 654 def disable(self): 647 655 """Disable this transport.""" 656 lck = self._lib.auto_lock() 648 657 err = _pjsua.transport_set_enable(self._id, 0) 649 658 self._lib._err_check("disable()", self, err) … … 655 664 force -- force deletion of this transport (not recommended). 656 665 """ 666 lck = self._lib.auto_lock() 657 667 err = _pjsua.transport_close(self._id, force) 658 668 self._lib._err_check("close()", self, err) … … 976 986 account = None 977 987 978 def __init__(self, account): 979 self.account = account 988 def __init__(self, account=None): 989 self._set_account(account) 990 991 def __del__(self): 992 pass 993 994 def _set_account(self, account): 995 if account: 996 self.account = weakref.proxy(account) 997 else: 998 self.account = None 980 999 981 1000 def on_reg_state(self): … … 995 1014 call.hangup() 996 1015 997 def on_incoming_subscribe(self, buddy, from_uri, pres_obj):1016 def on_incoming_subscribe(self, buddy, from_uri, contact_uri, pres_obj): 998 1017 """Notification when incoming SUBSCRIBE request is received. 999 1018 … … 1099 1118 _obj_name = "" 1100 1119 1101 def __init__(self, lib, id ):1120 def __init__(self, lib, id, cb=None): 1102 1121 """Construct this class. This is normally called by Lib class and 1103 1122 not by application. … … 1106 1125 lib -- the Lib instance. 1107 1126 id -- the pjsua account ID. 1108 """ 1109 self._cb = AccountCallback(self) 1127 cb -- AccountCallback instance to receive events from this Account. 1128 If callback is not specified here, it must be set later 1129 using set_callback(). 1130 """ 1110 1131 self._id = id 1111 self._lib = lib 1112 self._lib._associate_account(self._id, self) 1113 self._obj_name = "Account " + self.info().uri 1132 self._lib = weakref.ref(lib) 1133 self._obj_name = "{Account " + self.info().uri + "}" 1134 self.set_callback(cb) 1135 _pjsua.acc_set_user_data(self._id, self) 1136 _Trace((self, 'created')) 1114 1137 1115 1138 def __del__(self): 1116 self._lib._disassociate_account(self._id, self) 1139 if self._id != -1: 1140 _pjsua.acc_set_user_data(self._id, 0) 1141 _Trace((self, 'destroyed')) 1117 1142 1118 1143 def __str__(self): … … 1122 1147 """Retrieve AccountInfo for this account. 1123 1148 """ 1149 lck = self._lib().auto_lock() 1124 1150 ai = _pjsua.acc_get_info(self._id) 1125 1151 if ai==None: 1126 self._lib ._err_check("info()", self, -1, "Invalid account")1152 self._lib()._err_check("info()", self, -1, "Invalid account") 1127 1153 return AccountInfo(ai) 1128 1154 … … 1132 1158 1133 1159 """ 1160 lck = self._lib().auto_lock() 1134 1161 return _pjsua.acc_is_valid(self._id) 1135 1162 … … 1145 1172 else: 1146 1173 self._cb = AccountCallback(self) 1174 self._cb._set_account(self) 1147 1175 1148 1176 def set_default(self): … … 1151 1179 matching criteria fails. 1152 1180 """ 1181 lck = self._lib().auto_lock() 1153 1182 err = _pjsua.acc_set_default(self._id) 1154 self._lib ._err_check("set_default()", self, err)1183 self._lib()._err_check("set_default()", self, err) 1155 1184 1156 1185 def is_default(self): … … 1158 1187 1159 1188 """ 1189 lck = self._lib().auto_lock() 1160 1190 def_id = _pjsua.acc_get_default() 1161 1191 return self.is_valid() and def_id==self._id … … 1165 1195 1166 1196 """ 1197 lck = self._lib().auto_lock() 1198 err = _pjsua.acc_set_user_data(self._id, 0) 1199 self._lib()._err_check("delete()", self, err) 1167 1200 err = _pjsua.acc_del(self._id) 1168 self._lib._err_check("delete()", self, err) 1201 self._lib()._err_check("delete()", self, err) 1202 self._id = -1 1169 1203 1170 1204 def set_basic_status(self, is_online): … … 1175 1209 1176 1210 """ 1211 lck = self._lib().auto_lock() 1177 1212 err = _pjsua.acc_set_online_status(self._id, is_online) 1178 self._lib ._err_check("set_basic_status()", self, err)1213 self._lib()._err_check("set_basic_status()", self, err) 1179 1214 1180 1215 def set_presence_status(self, is_online, … … 1191 1226 1192 1227 """ 1228 lck = self._lib().auto_lock() 1193 1229 err = _pjsua.acc_set_online_status2(self._id, is_online, activity, 1194 1230 pres_text, rpid_id) 1195 self._lib ._err_check("set_presence_status()", self, err)1231 self._lib()._err_check("set_presence_status()", self, err) 1196 1232 1197 1233 def set_registration(self, renew): … … 1203 1239 1204 1240 """ 1241 lck = self._lib().auto_lock() 1205 1242 err = _pjsua.acc_set_registration(self._id, renew) 1206 self._lib._err_check("set_registration()", self, err) 1207 1208 def has_registration(self): 1209 """Returns True if registration is active for this account. 1210 1211 """ 1212 acc_info = _pjsua.acc_get_info(self._id) 1213 if not acc_info: 1214 self._lib._err_check("has_registration()", self, -1, 1215 "invalid account") 1216 return acc_info.has_registration 1243 self._lib()._err_check("set_registration()", self, err) 1217 1244 1218 1245 def set_transport(self, transport): … … 1224 1251 1225 1252 """ 1253 lck = self._lib().auto_lock() 1226 1254 err = _pjsua.acc_set_transport(self._id, transport._id) 1227 self._lib ._err_check("set_transport()", self, err)1228 1229 def make_call(self, dst_uri, hdr_list=None):1255 self._lib()._err_check("set_transport()", self, err) 1256 1257 def make_call(self, dst_uri, cb=None, hdr_list=None): 1230 1258 """Make outgoing call to the specified URI. 1231 1259 1232 1260 Keyword arguments: 1233 1261 dst_uri -- Destination SIP URI. 1262 cb -- CallCallback instance to be installed to the newly 1263 created Call object. If this CallCallback is not 1264 specified (i.e. None is given), it must be installed 1265 later using call.set_callback(). 1234 1266 hdr_list -- Optional list of headers to be sent with outgoing 1235 1267 INVITE 1236 1268 1237 """ 1269 Return: 1270 Call instance. 1271 """ 1272 lck = self._lib().auto_lock() 1273 call = Call(self._lib(), -1, cb) 1238 1274 err, cid = _pjsua.call_make_call(self._id, dst_uri, 0, 1239 0, Lib._create_msg_data(hdr_list)) 1240 self._lib._err_check("make_call()", self, err) 1241 return Call(self._lib, cid) 1242 1243 def add_buddy(self, uri): 1275 call, Lib._create_msg_data(hdr_list)) 1276 self._lib()._err_check("make_call()", self, err) 1277 call.attach_to_id(cid) 1278 return call 1279 1280 def add_buddy(self, uri, cb=None): 1244 1281 """Add new buddy. 1245 1282 1246 1283 Keyword argument: 1247 uri -- SIP URI of the buddy 1284 uri -- SIP URI of the buddy 1285 cb -- BuddyCallback instance to be installed to the newly 1286 created Buddy object. If this callback is not specified 1287 (i.e. None is given), it must be installed later using 1288 buddy.set_callback(). 1248 1289 1249 1290 Return: 1250 1291 Buddy object 1251 1292 """ 1293 lck = self._lib().auto_lock() 1252 1294 buddy_cfg = _pjsua.buddy_config_default() 1253 1295 buddy_cfg.uri = uri 1254 1296 buddy_cfg.subscribe = False 1255 1297 err, buddy_id = _pjsua.buddy_add(buddy_cfg) 1256 self._lib._err_check("add_buddy()", self, err) 1257 return Buddy(self._lib, buddy_id, self) 1298 self._lib()._err_check("add_buddy()", self, err) 1299 buddy = Buddy(self._lib(), buddy_id, self, cb) 1300 return buddy 1258 1301 1259 1302 def pres_notify(self, pres_obj, state, reason="", hdr_list=None): … … 1268 1311 hdr_list -- Optional header list. 1269 1312 """ 1313 lck = self._lib().auto_lock() 1270 1314 _pjsua.acc_pres_notify(self._id, pres_obj, state, reason, 1271 1315 Lib._create_msg_data(hdr_list)) … … 1284 1328 call = None 1285 1329 1286 def __init__(self, call): 1287 self.call = call 1330 def __init__(self, call=None): 1331 self._set_call(call) 1332 1333 def __del__(self): 1334 pass 1335 1336 def _set_call(self, call): 1337 if call: 1338 self.call = weakref.proxy(call) 1339 else: 1340 self.call = None 1288 1341 1289 1342 def on_state(self): … … 1469 1522 self.media_dir = ci.media_dir 1470 1523 self.conf_slot = ci.conf_slot 1471 self.call_time = ci.connect_duration .sec1472 self.total_time = ci.total_duration .sec1524 self.call_time = ci.connect_duration / 1000 1525 self.total_time = ci.total_duration / 1000 1473 1526 1474 1527 … … 1484 1537 _obj_name = "" 1485 1538 1486 def __init__(self, lib, call_id): 1487 self._cb = CallCallback(self) 1488 self._id = call_id 1489 self._lib = lib 1490 self._lib._associate_call(call_id, self) 1491 self._obj_name = "Call " + self.info().remote_uri 1539 def __init__(self, lib, call_id, cb=None): 1540 self._lib = weakref.ref(lib) 1541 self.set_callback(cb) 1542 self.attach_to_id(call_id) 1543 _Trace((self, 'created')) 1492 1544 1493 1545 def __del__(self): 1494 self._lib._disassociate_call(self._id, self) 1546 if self._id != -1: 1547 _pjsua.call_set_user_data(self._id, 0) 1548 _Trace((self, 'destroyed')) 1495 1549 1496 1550 def __str__(self): 1497 1551 return self._obj_name 1552 1553 def attach_to_id(self, call_id): 1554 lck = self._lib().auto_lock() 1555 if self._id != -1: 1556 _pjsua.call_set_user_data(self._id, 0) 1557 self._id = call_id 1558 if self._id != -1: 1559 _pjsua.call_set_user_data(self._id, self) 1560 self._obj_name = "{Call " + self.info().remote_uri + "}" 1561 else: 1562 self._obj_name = "{Call object}" 1498 1563 1499 1564 def set_callback(self, cb): … … 1508 1573 else: 1509 1574 self._cb = CallCallback(self) 1575 self._cb._set_call(self) 1510 1576 1511 1577 def info(self): … … 1513 1579 Get the CallInfo. 1514 1580 """ 1581 lck = self._lib().auto_lock() 1515 1582 ci = _pjsua.call_get_info(self._id) 1516 1583 if not ci: 1517 self._lib._err_check("info", self, -1, "Invalid call") 1518 return CallInfo(self._lib, ci) 1584 self._lib()._err_check("info", self, -1, "Invalid call") 1585 call_info = CallInfo(self._lib(), ci) 1586 return call_info 1519 1587 1520 1588 def is_valid(self): … … 1522 1590 Check if this call is still valid. 1523 1591 """ 1592 lck = self._lib().auto_lock() 1524 1593 return _pjsua.call_is_active(self._id) 1525 1594 … … 1528 1597 Dump the call status. 1529 1598 """ 1599 lck = self._lib().auto_lock() 1530 1600 return _pjsua.call_dump(self._id, with_media, max_len, indent) 1531 1601 … … 1542 1612 1543 1613 """ 1614 lck = self._lib().auto_lock() 1544 1615 err = _pjsua.call_answer(self._id, code, reason, 1545 1616 Lib._create_msg_data(hdr_list)) 1546 self._lib ._err_check("answer()", self, err)1617 self._lib()._err_check("answer()", self, err) 1547 1618 1548 1619 def hangup(self, code=603, reason="", hdr_list=None): … … 1558 1629 1559 1630 """ 1631 lck = self._lib().auto_lock() 1560 1632 err = _pjsua.call_hangup(self._id, code, reason, 1561 1633 Lib._create_msg_data(hdr_list)) 1562 self._lib ._err_check("hangup()", self, err)1634 self._lib()._err_check("hangup()", self, err) 1563 1635 1564 1636 def hold(self, hdr_list=None): … … 1570 1642 message. 1571 1643 """ 1644 lck = self._lib().auto_lock() 1572 1645 err = _pjsua.call_set_hold(self._id, Lib._create_msg_data(hdr_list)) 1573 self._lib ._err_check("hold()", self, err)1646 self._lib()._err_check("hold()", self, err) 1574 1647 1575 1648 def unhold(self, hdr_list=None): … … 1582 1655 1583 1656 """ 1657 lck = self._lib().auto_lock() 1584 1658 err = _pjsua.call_reinvite(self._id, True, 1585 1659 Lib._create_msg_data(hdr_list)) 1586 self._lib ._err_check("unhold()", self, err)1660 self._lib()._err_check("unhold()", self, err) 1587 1661 1588 1662 def reinvite(self, hdr_list=None): … … 1595 1669 1596 1670 """ 1671 lck = self._lib().auto_lock() 1597 1672 err = _pjsua.call_reinvite(self._id, True, 1598 1673 Lib._create_msg_data(hdr_list)) 1599 self._lib ._err_check("reinvite()", self, err)1674 self._lib()._err_check("reinvite()", self, err) 1600 1675 1601 1676 def update(self, hdr_list=None, options=0): … … 1609 1684 1610 1685 """ 1686 lck = self._lib().auto_lock() 1611 1687 err = _pjsua.call_update(self._id, options, 1612 1688 Lib._create_msg_data(hdr_list)) 1613 self._lib ._err_check("update()", self, err)1689 self._lib()._err_check("update()", self, err) 1614 1690 1615 1691 def transfer(self, dest_uri, hdr_list=None): … … 1623 1699 1624 1700 """ 1701 lck = self._lib().auto_lock() 1625 1702 err = _pjsua.call_xfer(self._id, dest_uri, 1626 1703 Lib._create_msg_data(hdr_list)) 1627 self._lib ._err_check("transfer()", self, err)1704 self._lib()._err_check("transfer()", self, err) 1628 1705 1629 1706 def transfer_to_call(self, call, hdr_list=None, options=0): … … 1638 1715 1639 1716 """ 1717 lck = self._lib().auto_lock() 1640 1718 err = _pjsua.call_xfer_replaces(self._id, call._id, options, 1641 1719 Lib._create_msg_data(hdr_list)) 1642 self._lib ._err_check("transfer_to_call()", self, err)1720 self._lib()._err_check("transfer_to_call()", self, err) 1643 1721 1644 1722 def dial_dtmf(self, digits): … … 1650 1728 1651 1729 """ 1730 lck = self._lib().auto_lock() 1652 1731 err = _pjsua.call_dial_dtmf(self._id, digits) 1653 self._lib ._err_check("dial_dtmf()", self, err)1732 self._lib()._err_check("dial_dtmf()", self, err) 1654 1733 1655 1734 def send_request(self, method, hdr_list=None, content_type=None, … … 1670 1749 1671 1750 """ 1751 lck = self._lib().auto_lock() 1672 1752 if hdr_list and body: 1673 1753 msg_data = _pjsua.Msg_Data() … … 1682 1762 1683 1763 err = _pjsua.call_send_request(self._id, method, msg_data) 1684 self._lib ._err_check("send_request()", self, err)1764 self._lib()._err_check("send_request()", self, err) 1685 1765 1686 1766 … … 1737 1817 buddy = None 1738 1818 1739 def __init__(self, buddy): 1740 self.buddy = buddy 1819 def __init__(self, buddy=None): 1820 self._set_buddy(buddy) 1821 1822 def _set_buddy(self, buddy): 1823 if buddy: 1824 self.buddy = weakref.proxy(buddy) 1825 else: 1826 self.buddy = None 1741 1827 1742 1828 def on_state(self): … … 1794 1880 _acc = None 1795 1881 1796 def __init__(self, lib, id, account): 1797 self._cb = BuddyCallback(self) 1798 self._lib = lib 1882 def __init__(self, lib, id, account, cb): 1799 1883 self._id = id 1800 self._acc = account 1801 lib._associate_buddy(self._id, self) 1802 self._obj_name = "Buddy " + self.info().uri 1884 self._lib = weakref.ref(lib) 1885 self._acc = weakref.ref(account) 1886 self._obj_name = "{Buddy " + self.info().uri + "}" 1887 self.set_callback(cb) 1888 _pjsua.buddy_set_user_data(self._id, self) 1889 _Trace((self, 'created')) 1803 1890 1804 1891 def __del__(self): 1805 self._lib._disassociate_buddy(self) 1892 if self._id != -1: 1893 _pjsua.buddy_set_user_data(self._id, 0) 1894 _Trace((self, 'destroyed')) 1806 1895 1807 1896 def __str__(self): … … 1812 1901 Get buddy info as BuddyInfo. 1813 1902 """ 1903 lck = self._lib().auto_lock() 1814 1904 return BuddyInfo(_pjsua.buddy_get_info(self._id)) 1815 1905 … … 1824 1914 else: 1825 1915 self._cb = BuddyCallback(self) 1916 self._cb._set_buddy(self) 1826 1917 1827 1918 def subscribe(self): … … 1829 1920 Subscribe to buddy's presence status notification. 1830 1921 """ 1922 lck = self._lib().auto_lock() 1831 1923 err = _pjsua.buddy_subscribe_pres(self._id, True) 1832 self._lib ._err_check("subscribe()", self, err)1924 self._lib()._err_check("subscribe()", self, err) 1833 1925 1834 1926 def unsubscribe(self): … … 1836 1928 Unsubscribe from buddy's presence status notification. 1837 1929 """ 1930 lck = self._lib().auto_lock() 1838 1931 err = _pjsua.buddy_subscribe_pres(self._id, False) 1839 self._lib ._err_check("unsubscribe()", self, err)1932 self._lib()._err_check("unsubscribe()", self, err) 1840 1933 1841 1934 def delete(self): … … 1843 1936 Remove this buddy from the buddy list. 1844 1937 """ 1938 lck = self._lib().auto_lock() 1939 if self._id != -1: 1940 _pjsua.buddy_set_user_data(self._id, 0) 1845 1941 err = _pjsua.buddy_del(self._id) 1846 self._lib ._err_check("delete()", self, err)1942 self._lib()._err_check("delete()", self, err) 1847 1943 1848 1944 def send_pager(self, text, im_id=0, content_type="text/plain", \ … … 1860 1956 1861 1957 """ 1862 err = _pjsua.im_send(self._acc._id, self.info().uri, \ 1958 lck = self._lib().auto_lock() 1959 err = _pjsua.im_send(self._acc()._id, self.info().uri, \ 1863 1960 content_type, text, \ 1864 1961 Lib._create_msg_data(hdr_list), \ 1865 1962 im_id) 1866 self._lib ._err_check("send_pager()", self, err)1963 self._lib()._err_check("send_pager()", self, err) 1867 1964 1868 1965 def send_typing_ind(self, is_typing=True, hdr_list=None): … … 1875 1972 1876 1973 """ 1877 err = _pjsua.im_typing(self._acc._id, self.info().uri, \ 1974 lck = self._lib().auto_lock() 1975 err = _pjsua.im_typing(self._acc()._id, self.info().uri, \ 1878 1976 is_typing, Lib._create_msg_data(hdr_list)) 1879 self._lib ._err_check("send_typing_ind()", self, err)1977 self._lib()._err_check("send_typing_ind()", self, err) 1880 1978 1881 1979 … … 1982 2080 1983 2081 2082 # Library mutex 2083 class _LibMutex: 2084 def __init__(self, lck): 2085 self._lck = lck 2086 self._lck.acquire() 2087 #print 'lck acquire' 2088 2089 def __del__(self): 2090 self._lck.release() 2091 #print 'lck release' 2092 2093 1984 2094 # PJSUA Library 1985 2095 _lib = None … … 1988 2098 1989 2099 """ 1990 call = {}1991 account = {}1992 buddy = {}1993 buddy_by_uri = {}1994 buddy_by_contact = {}1995 2100 _quit = False 1996 2101 _has_thread = False 2102 _lock = None 1997 2103 1998 2104 def __init__(self): … … 2001 2107 raise Error("__init()__", None, -1, 2002 2108 "Library instance already exist") 2003 2109 2110 self._lock = threading.RLock() 2004 2111 err = _pjsua.create() 2005 2112 self._err_check("_pjsua.create()", None, err) … … 2008 2115 def __del__(self): 2009 2116 _pjsua.destroy() 2117 del self._lock 2118 print 'Lib destroyed' 2010 2119 2011 2120 def __str__(self): … … 2049 2158 2050 2159 err = _pjsua.init(py_ua_cfg, log_cfg._cvt_to_pjsua(), 2051 2160 media_cfg._cvt_to_pjsua()) 2052 2161 self._err_check("init()", self, err) 2053 2162 … … 2059 2168 loop = 0 2060 2169 while self._quit != 2 and loop < 400: 2061 _pjsua.handle_events(50)2170 self.handle_events(50) 2062 2171 loop = loop + 1 2063 2172 _pjsua.destroy() 2064 2173 _lib = None 2065 2174 2066 2175 def start(self, with_thread=True): 2067 2176 """Start the library. … … 2088 2197 2089 2198 """ 2199 lck = self.auto_lock() 2090 2200 return _pjsua.handle_events(timeout) 2091 2201 … … 2101 2211 2102 2212 """ 2213 lck = self.auto_lock() 2103 2214 return _pjsua.verify_sip_url(sip_url) 2104 2215 … … 2114 2225 2115 2226 """ 2227 lck = self.auto_lock() 2116 2228 if not cfg: cfg=TransportConfig(type) 2117 2229 err, tp_id = _pjsua.transport_create(type, cfg._cvt_to_pjsua()) … … 2119 2231 return Transport(self, tp_id) 2120 2232 2121 def create_account(self, acc_config, set_default=True ):2233 def create_account(self, acc_config, set_default=True, cb=None): 2122 2234 """ 2123 2235 Create a new local pjsua account using the specified configuration. … … 2127 2239 set_default -- boolean to specify whether to use this as the 2128 2240 default account. 2241 cb -- AccountCallback instance. 2129 2242 2130 2243 Return: … … 2132 2245 2133 2246 """ 2247 lck = self.auto_lock() 2134 2248 err, acc_id = _pjsua.acc_add(acc_config._cvt_to_pjsua(), set_default) 2135 2249 self._err_check("create_account()", self, err) 2136 return Account(self, acc_id) 2137 2138 def create_account_for_transport(self, transport, set_default=True): 2250 return Account(self, acc_id, cb) 2251 2252 def create_account_for_transport(self, transport, set_default=True, 2253 cb=None): 2139 2254 """Create a new local pjsua transport for the specified transport. 2140 2255 … … 2143 2258 set_default -- boolean to specify whether to use this as the 2144 2259 default account. 2260 cb -- AccountCallback instance. 2145 2261 2146 2262 Return: … … 2148 2264 2149 2265 """ 2266 lck = self.auto_lock() 2150 2267 err, acc_id = _pjsua.acc_add_local(transport._id, set_default) 2151 2268 self._err_check("create_account_for_transport()", self, err) 2152 return Account(self, acc_id )2269 return Account(self, acc_id, cb) 2153 2270 2154 2271 def hangup_all(self): … … 2156 2273 2157 2274 """ 2275 lck = self.auto_lock() 2158 2276 _pjsua.call_hangup_all() 2159 2277 … … 2167 2285 the device ID for the device. 2168 2286 """ 2287 lck = self.auto_lock() 2169 2288 sdi_list = _pjsua.enum_snd_devs() 2170 2289 info = [] … … 2179 2298 (capture_dev_id, playback_dev_id) tuple 2180 2299 """ 2300 lck = self.auto_lock() 2181 2301 return _pjsua.get_snd_dev() 2182 2302 … … 2189 2309 2190 2310 """ 2311 lck = self.auto_lock() 2191 2312 err = _pjsua.set_snd_dev(capture_dev, playback_dev) 2192 2313 self._err_check("set_current_sound_devices()", self, err) … … 2197 2318 2198 2319 """ 2320 lck = self.auto_lock() 2199 2321 err = _pjsua.set_null_snd_dev() 2200 2322 self._err_check("set_null_snd_dev()", self, err) … … 2210 2332 2211 2333 """ 2334 lck = self.auto_lock() 2212 2335 return _pjsua.conf_get_max_ports() 2213 2336 … … 2231 2354 2232 2355 """ 2356 lck = self.auto_lock() 2233 2357 err = _pjsua.conf_connect(src_slot, dst_slot) 2234 2358 self._err_check("conf_connect()", self, err) … … 2244 2368 2245 2369 """ 2370 lck = self.auto_lock() 2246 2371 err = _pjsua.conf_disconnect(src_slot, dst_slot) 2247 2372 self._err_check("conf_disconnect()", self, err) … … 2256 2381 adjustment, while value 0 means to mute the port. 2257 2382 """ 2383 lck = self.auto_lock() 2258 2384 err = _pjsua.conf_set_tx_level(slot, level) 2259 2385 self._err_check("conf_set_tx_level()", self, err) … … 2268 2394 adjustment, while value 0 means to mute the port. 2269 2395 """ 2396 lck = self.auto_lock() 2270 2397 err = _pjsua.conf_set_rx_level(slot, level) 2271 2398 self._err_check("conf_set_rx_level()", self, err) … … 2283 2410 (tx_level, rx_level) tuple. 2284 2411 """ 2412 lck = self.auto_lock() 2285 2413 err, tx_level, rx_level = _pjsua.conf_get_signal_level(slot) 2286 2414 self._err_check("conf_get_signal_level()", self, err) … … 2298 2426 2299 2427 """ 2428 lck = self.auto_lock() 2300 2429 ci_list = _pjsua.enum_codecs() 2301 2430 codec_info = [] … … 2314 2443 2315 2444 """ 2445 lck = self.auto_lock() 2316 2446 err = _pjsua.codec_set_priority(name, priority) 2317 2447 self._err_check("set_codec_priority()", self, err) … … 2324 2454 2325 2455 """ 2456 lck = self.auto_lock() 2326 2457 cp = _pjsua.codec_get_param(name) 2327 2458 if not cp: … … 2338 2469 2339 2470 """ 2471 lck = self.auto_lock() 2340 2472 err = _pjsua.codec_set_param(name, param._cvt_to_pjsua()) 2341 2473 self._err_check("set_codec_parameter()", self, err) … … 2354 2486 2355 2487 """ 2488 lck = self.auto_lock() 2356 2489 opt = 0 2357 2490 if not loop: … … 2371 2504 2372 2505 """ 2506 lck = self.auto_lock() 2373 2507 slot = _pjsua.player_get_conf_port(player_id) 2374 2508 if slot < 0: … … 2385 2519 2386 2520 """ 2521 lck = self.auto_lock() 2387 2522 err = _pjsua.player_set_pos(player_id, pos) 2388 2523 self._err_check("player_set_pos()", self, err) … … 2395 2530 2396 2531 """ 2532 lck = self.auto_lock() 2397 2533 err = _pjsua.player_destroy(player_id) 2398 2534 self._err_check("player_destroy()", self, err) … … 2411 2547 playlist_id 2412 2548 """ 2549 lck = self.auto_lock() 2413 2550 opt = 0 2414 2551 if not loop: … … 2428 2565 2429 2566 """ 2567 lck = self.auto_lock() 2430 2568 slot = _pjsua.player_get_conf_port(playlist_id) 2431 2569 if slot < 0: … … 2441 2579 2442 2580 """ 2581 lck = self.auto_lock() 2443 2582 err = _pjsua.player_destroy(playlist_id) 2444 2583 self._err_check("playlist_destroy()", self, err) … … 2454 2593 2455 2594 """ 2595 lck = self.auto_lock() 2456 2596 err, rec_id = _pjsua.recorder_create(filename, 0, None, -1, 0) 2457 2597 self._err_check("create_recorder()", self, err) … … 2468 2608 2469 2609 """ 2610 lck = self.auto_lock() 2470 2611 slot = _pjsua.recorder_get_conf_port(rec_id) 2471 2612 if slot < 1: … … 2481 2622 2482 2623 """ 2624 lck = self.auto_lock() 2483 2625 err = _pjsua.recorder_destroy(rec_id) 2484 2626 self._err_check("recorder_destroy()", self, err) … … 2503 2645 return msg_data 2504 2646 2647 def auto_lock(self): 2648 return _LibMutex(self._lock) 2649 2505 2650 # Internal dictionary manipulation for calls, accounts, and buddies 2506 2651 2507 def _associate_call(self, call_id, call):2508 self.call[call_id] = call2509 2510 2652 def _lookup_call(self, call_id): 2511 return self.call.has_key(call_id) and self.call[call_id] or None 2512 2513 def _disassociate_call(self, call): 2514 if self._lookup_call(call._id)==call: 2515 del self.call[call._id] 2516 2517 def _associate_account(self, acc_id, account): 2518 self.account[acc_id] = account 2653 return _pjsua.call_get_user_data(call_id) 2519 2654 2520 2655 def _lookup_account(self, acc_id): 2521 return self.account.has_key(acc_id) and self.account[acc_id] or None 2522 2523 def _disassociate_account(self, account): 2524 if self._lookup_account(account._id)==account: 2525 del self.account[account._id] 2526 2527 def _associate_buddy(self, buddy_id, buddy): 2528 self.buddy[buddy_id] = buddy 2529 uri = SIPUri(buddy.info().uri) 2530 self.buddy_by_uri[(uri.user, uri.host)] = buddy 2656 return _pjsua.acc_get_user_data(acc_id) 2531 2657 2532 2658 def _lookup_buddy(self, buddy_id, uri=None): 2533 buddy = self.buddy.has_key(buddy_id) and self.buddy[buddy_id] or None 2534 if uri and not buddy: 2535 sip_uri = SIPUri(uri) 2536 buddy = self.buddy_by_uri.has_key( (sip_uri.user, sip_uri.host) ) \ 2537 and self.buddy_by_uri[(sip_uri.user, sip_uri.host)] or \ 2538 None 2659 if buddy_id != -1: 2660 buddy = _pjsua.buddy_get_user_data(buddy_id) 2661 elif uri: 2662 buddy_id = _pjsua.buddy_find(uri) 2663 if buddy_id != -1: 2664 buddy = _pjsua.buddy_get_user_data(buddy_id) 2665 else: 2666 buddy = None 2667 else: 2668 buddy = None 2669 2539 2670 return buddy 2540 2541 def _disassociate_buddy(self, buddy):2542 if self._lookup_buddy(buddy._id)==buddy:2543 del self.buddy[buddy._id]2544 if self.buddy_by_uri.has_key(buddy.info().uri):2545 del self.buddy_by_uri[buddy.info().uri]2546 2671 2547 2672 # Account allbacks … … 2552 2677 acc._cb.on_reg_state() 2553 2678 2554 def _cb_on_incoming_subscribe(self, acc_id, buddy_id, from_uri, pres_obj): 2679 def _cb_on_incoming_subscribe(self, acc_id, buddy_id, from_uri, 2680 contact_uri, pres_obj): 2555 2681 acc = self._lookup_account(acc_id) 2556 2682 if acc: 2557 2683 buddy = self._lookup_buddy(buddy_id) 2558 return acc._cb.on_incoming_subscribe(buddy, from_uri, pres_obj) 2684 return acc._cb.on_incoming_subscribe(buddy, from_uri, contact_uri, 2685 pres_obj) 2559 2686 else: 2560 2687 return (404, None) … … 2572 2699 call = self._lookup_call(call_id) 2573 2700 if call: 2701 if call._id == -1: 2702 call.attach_to_id(call_id) 2703 done = (call.info().state == CallState.DISCONNECTED) 2574 2704 call._cb.on_state() 2705 if done: 2706 _pjsua.call_set_user_data(call_id, 0) 2707 else: 2708 pass 2575 2709 2576 2710 def _cb_on_call_media_state(self, call_id): … … 2695 2829 _lib._cb_on_reg_state(acc_id) 2696 2830 2697 def _cb_on_incoming_subscribe(acc_id, buddy_id, from_uri, pres): 2698 return _lib._cb_on_incoming_subscribe(acc_id, buddy_id, from_uri, pres) 2831 def _cb_on_incoming_subscribe(acc_id, buddy_id, from_uri, contact_uri, pres): 2832 return _lib._cb_on_incoming_subscribe(acc_id, buddy_id, from_uri, 2833 contact_uri, pres) 2699 2834 2700 2835 def _cb_on_buddy_state(buddy_id): … … 2718 2853 err = _pjsua.thread_register("python worker", thread_desc) 2719 2854 _lib._err_check("thread_register()", _lib, err) 2720 while _lib._quit == 0: 2721 _pjsua.handle_events(50) 2722 _lib._quit = 2 2723 2724 2855 while _lib and _lib._quit == 0: 2856 _lib.handle_events(50) 2857 if _lib: 2858 _lib._quit = 2 2859 2860 def _Trace(args): 2861 if True: 2862 print "** ", 2863 for arg in args: 2864 print arg, 2865 print " **" -
pjproject/trunk/pjsip-apps/src/python/samples/call.py
r2119 r2163 1 # $Id :$1 # $Id$ 2 2 # 3 3 # SIP call sample. … … 19 19 class MyAccountCallback(pj.AccountCallback): 20 20 21 def __init__(self, account ):21 def __init__(self, account=None): 22 22 pj.AccountCallback.__init__(self, account) 23 23 … … 25 25 def on_incoming_call(self, call): 26 26 global current_call 27 28 27 if current_call: 29 28 call.answer(486, "Busy") … … 44 43 class MyCallCallback(pj.CallCallback): 45 44 46 def __init__(self, call ):45 def __init__(self, call=None): 47 46 pj.CallCallback.__init__(self, call) 48 47 … … 50 49 def on_state(self): 51 50 global current_call 52 53 51 print "Call with", self.call.info().remote_uri, 54 52 print "is", self.call.info().state_text, … … 58 56 if self.call.info().state == pj.CallState.DISCONNECTED: 59 57 current_call = None 58 print 'Current call is', current_call 60 59 61 60 # Notification when call's media state has changed. … … 74 73 try: 75 74 print "Making call to", uri 76 call = acc.make_call(uri) 77 call_cb = MyCallCallback(call) 78 call.set_callback(call_cb) 79 return call 75 return acc.make_call(uri, cb=MyCallCallback()) 80 76 except pj.Error, e: 81 print "E rror: " + str(e)77 print "Exception: " + str(e) 82 78 return None 83 79 … … 101 97 102 98 # Create local account 103 acc = lib.create_account_for_transport(transport) 104 acc_cb = MyAccountCallback(acc) 105 acc.set_callback(acc_cb) 99 acc = lib.create_account_for_transport(transport, cb=MyAccountCallback()) 106 100 107 101 # If argument is specified then make call to the URI 108 102 if len(sys.argv) > 1: 103 lck = lib.auto_lock() 109 104 current_call = make_call(sys.argv[1]) 105 print 'Current call is', current_call 106 del lck 110 107 111 108 my_sip_uri = "sip:" + transport.info().host + \ … … 126 123 if input == "": 127 124 continue 125 lck = lib.auto_lock() 128 126 current_call = make_call(input) 127 del lck 129 128 130 129 elif input == "h": … … 144 143 145 144 # Shutdown the library 145 transport = None 146 acc.delete() 147 acc = None 146 148 lib.destroy() 147 149 lib = None -
pjproject/trunk/pjsip-apps/src/python/samples/presence.py
r2120 r2163 9 9 10 10 LOG_LEVEL = 3 11 pending_pres = None 12 pending_uri = None 11 13 12 14 def log_cb(level, str, len): 13 15 print str, 14 16 17 class MyAccountCallback(pj.AccountCallback): 18 def __init__(self, account=None): 19 pj.AccountCallback.__init__(self, account) 20 21 def on_incoming_subscribe(self, buddy, from_uri, contact_uri, pres): 22 global pending_pres, pending_uri 23 # Allow buddy to subscribe to our presence 24 if buddy: 25 return (200, None) 26 print 'Incoming SUBSCRIBE request from', from_uri 27 print 'Press "A" to accept and add, "R" to reject the request' 28 pending_pres = pres 29 pending_uri = from_uri 30 return (202, None) 31 32 15 33 class MyBuddyCallback(pj.BuddyCallback): 16 def __init__(self, buddy ):34 def __init__(self, buddy=None): 17 35 pj.BuddyCallback.__init__(self, buddy) 18 36 … … 55 73 56 74 # Create local account 57 acc = lib.create_account_for_transport(transport) 58 75 acc = lib.create_account_for_transport(transport, cb=MyAccountCallback()) 76 acc.set_basic_status(True) 77 59 78 my_sip_uri = "sip:" + transport.info().host + \ 60 79 ":" + str(transport.info().port) … … 65 84 while True: 66 85 print "My SIP URI is", my_sip_uri 67 print "Menu: a=add buddy, t=toggle online status, i=send IM, q=quit" 86 print "Menu: a=add buddy, d=delete buddy, t=toggle", \ 87 " online status, i=send IM, q=quit" 68 88 69 89 input = sys.stdin.readline().rstrip("\r\n") … … 75 95 continue 76 96 77 buddy = acc.add_buddy(input) 78 cb = MyBuddyCallback(buddy) 79 buddy.set_callback(cb) 80 97 buddy = acc.add_buddy(input, cb=MyBuddyCallback()) 81 98 buddy.subscribe() 82 99 … … 98 115 99 116 buddy.send_pager(input) 100 117 118 elif input == "d": 119 if buddy: 120 buddy.delete() 121 buddy = None 122 else: 123 print 'No buddy was added' 124 125 elif input == "A": 126 if pending_pres: 127 acc.pres_notify(pending_pres, pj.SubscriptionState.ACTIVE) 128 buddy = acc.add_buddy(pending_uri, cb=MyBuddyCallback()) 129 buddy.subscribe() 130 pending_pres = None 131 pending_uri = None 132 else: 133 print "No pending request" 134 135 elif input == "R": 136 if pending_pres: 137 acc.pres_notify(pending_pres, pj.SubscriptionState.TERMINATED, 138 "rejected") 139 pending_pres = None 140 pending_uri = None 141 else: 142 print "No pending request" 143 101 144 elif input == "q": 102 145 break 103 146 104 147 # Shutdown the library 148 acc.delete() 149 acc = None 150 if pending_pres: 151 acc.pres_notify(pending_pres, pj.SubscriptionState.TERMINATED, 152 "rejected") 153 transport = None 105 154 lib.destroy() 106 155 lib = None -
pjproject/trunk/pjsip-apps/src/python/samples/registration.py
r2119 r2163 1 # $Id :$1 # $Id$ 2 2 # 3 3 # SIP account and registration sample. In this sample, the program
Note: See TracChangeset
for help on using the changeset viewer.