- Timestamp:
- Feb 7, 2007 8:18:35 AM (18 years ago)
- Location:
- pjproject/trunk/pjsip-apps/src/py_pjsua
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip-apps/src/py_pjsua/pjsua_app.py
r928 r934 27 27 # Globals 28 28 # 29 g_ua_cfg = None 29 30 g_acc_id = py_pjsua.PJSUA_INVALID_ID 30 31 g_current_call = py_pjsua.PJSUA_INVALID_ID 31 32 g_wav_files = [] 33 g_wav_id = 0 34 g_wav_port = 0 35 g_rec_file = "" 36 g_rec_id = 0 37 g_rec_port = 0 32 38 33 39 # Utility to get call info … … 50 56 def on_incoming_call(acc_id, call_id, rdata): 51 57 global g_current_call 58 52 59 if g_current_call != py_pjsua.PJSUA_INVALID_ID: 53 60 # There's call in progress - answer Busy 54 61 py_pjsua.call_answer(call_id, 486, None, None) 55 62 return 56 63 57 64 g_current_call = call_id 58 65 ci = py_pjsua.call_get_info(call_id) 59 66 write_log(3, "*** Incoming call: " + call_name(call_id) + "***") 60 write_log(3, "*** Press a to answer or h to hangup ***"); 61 67 write_log(3, "*** Press a to answer or h to hangup ***") 68 69 62 70 63 71 # Callback when media state has changed (e.g. established or terminated) … … 105 113 106 114 115 # Received typing indication 116 # 117 def on_typing(call_id, strfrom, to, contact, is_typing): 118 str_t = "" 119 if is_typing: 120 str_t = "is typing.." 121 else: 122 str_t = "has stopped typing" 123 write_log(3, "IM indication: " + strfrom + " " + str_t) 124 125 # on call transfer status 126 # 127 def on_call_transfer_status(call_id,status_code,status_text,final,p_cont): 128 strfinal = "" 129 if final == 1: 130 strfinal = "[final]" 131 132 write_log(3, "Call " + `call_id` + ": transfer status= " + `status_code` + " " + status_text+ " " + strfinal) 133 134 if status_code/100 == 2: 135 write_log(3, "Call " + `call_id` + " : call transfered successfully, disconnecting call") 136 status = py_pjsua.call_hangup(call_id, 410, None, None) 137 p_cont = 0 138 139 # on call transfer request 140 # 141 def on_call_transfer_request(call_id, dst, code): 142 write_log(3, "Call transfer request from " + `call_id` + " to " + dst + " with code " + `code`) 143 107 144 # Utility: display PJ error and exit 108 145 # … … 126 163 # 127 164 def app_init(): 128 global g_acc_id 165 global g_acc_id, g_ua_cfg 129 166 130 167 # Create pjsua before anything else … … 152 189 ua_cfg.cb.on_pager = on_pager 153 190 ua_cfg.cb.on_pager_status = on_pager_status 154 191 ua_cfg.cb.on_typing = on_typing 192 ua_cfg.cb.on_call_transfer_status = on_call_transfer_status 193 ua_cfg.cb.on_call_transfer_request = on_call_transfer_request 155 194 156 195 # Create and initialize media config … … 193 232 194 233 g_acc_id = acc_id 234 g_ua_cfg = ua_cfg 195 235 196 236 # Add SIP account interractively … … 242 282 write_log(3, "Account " + acc_cfg.id + " added") 243 283 244 284 def add_player(): 285 global g_wav_files 286 global g_wav_id 287 global g_wav_port 288 289 file_name = "" 290 status = -1 291 wav_id = 0 292 293 print "Enter the path of the file player(e.g. /tmp/audio.wav): ", 294 file_name = sys.stdin.readline() 295 if file_name == "\n": 296 return 297 file_name = file_name.replace("\n", "") 298 status, wav_id = py_pjsua.player_create(file_name, 0) 299 if status != 0: 300 py_pjsua.perror(THIS_FILE, "Error adding file player ", status) 301 else: 302 g_wav_files.append(file_name) 303 if g_wav_id == 0: 304 g_wav_id = wav_id 305 g_wav_port = py_pjsua.player_get_conf_port(wav_id) 306 write_log(3, "File player " + file_name + " added") 307 308 def add_recorder(): 309 global g_rec_file 310 global g_rec_id 311 global g_rec_port 312 313 file_name = "" 314 status = -1 315 rec_id = 0 316 317 print "Enter the path of the file recorder(e.g. /tmp/audio.wav): ", 318 file_name = sys.stdin.readline() 319 if file_name == "\n": 320 return 321 file_name = file_name.replace("\n", "") 322 status, rec_id = py_pjsua.recorder_create(file_name, 0, None, 0, 0) 323 if status != 0: 324 py_pjsua.perror(THIS_FILE, "Error adding file recorder ", status) 325 else: 326 g_rec_file = file_name 327 g_rec_id = rec_id 328 g_rec_port = py_pjsua.recorder_get_conf_port(rec_id) 329 write_log(3, "File recorder " + file_name + " added") 330 331 def conf_list(): 332 333 334 ports = None 335 336 print "Conference ports : " 337 338 339 ports = py_pjsua.enum_conf_ports() 340 341 for port in ports: 342 info = None 343 info = py_pjsua.conf_get_port_info(port) 344 txlist = "" 345 for i in range(info.listener_cnt): 346 txlist = txlist + "#" + `info.listeners[i]` + " " 347 348 print "Port #" + `info.slot_id` + "[" + `(info.clock_rate/1000)` + "KHz/" + `(info.samples_per_frame * 1000 / info.clock_rate)` + "ms] " + info.name + " transmitting to: " + txlist 349 350 def connect_port(): 351 src_port = 0 352 dst_port = 0 353 354 print "Connect src port # (empty to cancel): " 355 src_port = sys.stdin.readline() 356 if src_port == "\n": 357 return 358 src_port = src_port.replace("\n", "") 359 src_port = int(src_port) 360 print "To dst port # (empty to cancel): " 361 dst_port = sys.stdin.readline() 362 if dst_port == "\n": 363 return 364 dst_port = dst_port.replace("\n", "") 365 dst_port = int(dst_port) 366 status = py_pjsua.conf_connect(src_port, dst_port) 367 if status != 0: 368 py_pjsua.perror(THIS_FILE, "Error connecting port ", status) 369 else: 370 write_log(3, "Port connected from " + `src_port` + " to " + `dst_port`) 371 372 def disconnect_port(): 373 src_port = 0 374 dst_port = 0 375 376 print "Disconnect src port # (empty to cancel): " 377 src_port = sys.stdin.readline() 378 if src_port == "\n": 379 return 380 src_port = src_port.replace("\n", "") 381 src_port = int(src_port) 382 print "From dst port # (empty to cancel): " 383 dst_port = sys.stdin.readline() 384 if dst_port == "\n": 385 return 386 dst_port = dst_port.replace("\n", "") 387 dst_port = int(dst_port) 388 status = py_pjsua.conf_disconnect(src_port, dst_port) 389 if status != 0: 390 py_pjsua.perror(THIS_FILE, "Error disconnecting port ", status) 391 else: 392 write_log(3, "Port disconnected " + `src_port` + " from " + `dst_port`) 393 394 def dump_call_quality(): 395 global g_current_call 396 397 buf = "" 398 if g_current_call != -1: 399 buf = py_pjsua.call_dump(g_current_call, 1, 1024, " ") 400 write_log(3, "\n" + buf) 401 else: 402 write_log(3, "No current call") 403 404 def xfer_call(): 405 global g_current_call 406 407 if g_current_call == -1: 408 409 write_log(3, "No current call") 410 411 else: 412 call = g_current_call 413 ci = py_pjsua.call_get_info(g_current_call) 414 print "Transfering current call ["+ `g_current_call` + "] " + ci.remote_info 415 print "Enter sip url : " 416 url = sys.stdin.readline() 417 if url == "\n": 418 return 419 url = url.replace("\n", "") 420 if call != g_current_call: 421 print "Call has been disconnected" 422 return 423 msg_data = py_pjsua.msg_data_init() 424 status = py_pjsua.call_xfer(g_current_call, url, msg_data); 425 if status != 0: 426 py_pjsua.perror(THIS_FILE, "Error transfering call ", status) 427 else: 428 write_log(3, "Call transfered to " + url) 429 430 def xfer_call_replaces(): 431 if g_current_call == -1: 432 write_log(3, "No current call") 433 else: 434 call = g_current_call 435 436 ids = py_pjsua.enum_calls() 437 if len(ids) <= 1: 438 print "There are no other calls" 439 return 440 441 ci = py_pjsua.call_get_info(g_current_call) 442 print "Transfer call [" + `g_current_call` + "] " + ci.remote_info + " to one of the following:" 443 for i in range(0, len(ids)): 444 if ids[i] == call: 445 continue 446 call_info = py_pjsua.call_get_info(ids[i]) 447 print `ids[i]` + " " + call_info.remote_info + " [" + call_info.state_text + "]" 448 449 print "Enter call number to be replaced : " 450 buf = sys.stdin.readline() 451 buf = buf.replace("\n","") 452 if buf == "": 453 return 454 dst_call = int(buf) 455 456 if call != g_current_call: 457 print "Call has been disconnected" 458 return 459 460 if dst_call == call: 461 print "Destination call number must not be the same as the call being transfered" 462 return 463 464 if dst_call >= py_pjsua.PJSUA_MAX_CALLS: 465 print "Invalid destination call number" 466 return 467 468 if py_pjsua.call_is_active(dst_call) == 0: 469 print "Invalid destination call number" 470 return 471 472 py_pjsua.call_xfer_replaces(call, dst_call, 0, None) 473 245 474 # 246 475 # Worker thread function. … … 282 511 def print_menu(): 283 512 print """ 284 Menu: 285 q Quit application 286 +a Add account 287 +b Add buddy 288 m Make call 289 a Answer current call (if any) 290 h Hangup current call (if any) 291 i Send instant message 513 +============================================================================+ 514 | Call Commands : | Buddy, IM & Presence: | Account: | 515 | | | | 516 | m Make call | +b Add buddy | +a Add account | 517 | a Answer current call | -b Delete buddy | -a Delete accnt | 518 | h Hangup current call | | | 519 | H Hold call | i Send instant message | rr register | 520 | v re-inVite (release Hold) | s Subscribe presence | ru Unregister | 521 | # Send DTMF string | u Unsubscribe presence | | 522 | dq Dump curr. call quality | t ToGgle Online status | | 523 | +--------------------------+------------------+ 524 | x Xfer call | Media Commands: | Status: | 525 | X Xfer with Replaces | | | 526 | | cl List ports | d Dump status | 527 | | cc Connect port | | 528 | | cd Disconnect port | | 529 | | +p Add file player | | 530 |------------------------------+ +r Add file recorder | | 531 | q Quit application | | | 532 +============================================================================+ 292 533 """ 293 534 print "Choice: ", … … 355 596 if status != 0: 356 597 py_pjsua.perror(THIS_FILE, "Error adding buddy", status) 357 598 elif choice[0] == "-" and choice[1] == "b": 599 print "Enter buddy ID to delete : " 600 buf = sys.stdin.readline() 601 buf = buf.replace("\n","") 602 if buf == "": 603 continue 604 i = int(buf) 605 if py_pjsua.buddy_is_valid(i) == 0: 606 print "Invalid buddy id " + `i` 607 else: 608 py_pjsua.buddy_del(i) 609 print "Buddy " + `i` + " deleted" 358 610 elif choice[0] == "+" and choice[1] == "a": 359 611 # Add account 360 612 add_account() 361 613 elif choice[0] == "-" and choice[1] == "a": 614 print "Enter account ID to delete : " 615 buf = sys.stdin.readline() 616 buf = buf.replace("\n","") 617 if buf == "": 618 continue 619 i = int(buf) 620 621 if py_pjsua.acc_is_valid(i) == 0: 622 print "Invalid account id " + `i` 623 else: 624 py_pjsua.acc_del(i) 625 print "Account " + `i` + " deleted" 626 627 elif choice[0] == "+" and choice[1] == "p": 628 add_player() 629 elif choice[0] == "+" and choice[1] == "r": 630 add_recorder() 631 elif choice[0] == "c" and choice[1] == "l": 632 conf_list() 633 elif choice[0] == "c" and choice[1] == "c": 634 connect_port() 635 elif choice[0] == "c" and choice[1] == "d": 636 disconnect_port() 637 elif choice[0] == "d" and choice[1] == "q": 638 dump_call_quality() 639 elif choice[0] == "x": 640 xfer_call() 641 elif choice[0] == "X": 642 xfer_call_replaces() 362 643 elif choice[0] == "h": 363 644 if g_current_call != py_pjsua.PJSUA_INVALID_ID: … … 365 646 else: 366 647 print "No current call" 367 648 elif choice[0] == "H": 649 if g_current_call != py_pjsua.PJSUA_INVALID_ID: 650 py_pjsua.call_set_hold(g_current_call, None) 651 652 else: 653 print "No current call" 654 elif choice[0] == "v": 655 if g_current_call != py_pjsua.PJSUA_INVALID_ID: 656 657 py_pjsua.call_reinvite(g_current_call, 1, None); 658 659 else: 660 print "No current call" 661 elif choice[0] == "#": 662 if g_current_call == py_pjsua.PJSUA_INVALID_ID: 663 print "No current call" 664 elif py_pjsua.call_has_media(g_current_call) == 0: 665 print "Media is not established yet!" 666 else: 667 call = g_current_call 668 print "DTMF strings to send (0-9*#A-B)" 669 buf = sys.stdin.readline() 670 buf = buf.replace("\n", "") 671 if buf == "": 672 continue 673 if call != g_current_call: 674 print "Call has been disconnected" 675 continue 676 status = py_pjsua.call_dial_dtmf(g_current_call, buf) 677 if status != 0: 678 py_pjsua.perror(THIS_FILE, "Unable to send DTMF", status); 679 else: 680 print "DTMF digits enqueued for transmission" 681 elif choice[0] == "s": 682 print "Subscribe presence of (buddy id) : " 683 buf = sys.stdin.readline() 684 buf = buf.replace("\n","") 685 if buf == "": 686 continue 687 i = int(buf) 688 py_pjsua.buddy_subscribe_pres(i, 1) 689 elif choice[0] == "u": 690 print "Unsubscribe presence of (buddy id) : " 691 buf = sys.stdin.readline() 692 buf = buf.replace("\n","") 693 if buf == "": 694 continue 695 i = int(buf) 696 py_pjsua.buddy_subscribe_pres(i, 0) 697 elif choice[0] == "t": 698 acc_info = py_pjsua.acc_get_info(g_acc_id) 699 if acc_info.online_status == 0: 700 acc_info.online_status = 1 701 else: 702 acc_info.online_status = 0 703 py_pjsua.acc_set_online_status(g_acc_id, acc_info.online_status) 704 st = "" 705 if acc_info.online_status == 0: 706 st = "offline" 707 else: 708 st = "online" 709 print "Setting " + acc_info.acc_uri + " online status to " + st 710 elif choice[0] == "r": 711 if choice[1] == "r": 712 py_pjsua.acc_set_registration(g_acc_id, 1) 713 elif choice[1] == "u": 714 py_pjsua.acc_set_registration(g_acc_id, 0) 715 elif choice[0] == "d": 716 717 write_log(3, "Start dumping application states : ") 718 write_log(3, "Dumping invite sessions : ") 719 720 if py_pjsua.call_get_count() == 0: 721 write_log(3, " - no sessions -") 722 else: 723 for i in range(0, g_ua_cfg.max_calls): 724 if py_pjsua.call_is_active(i): 725 buf = py_pjsua.call_dump(i, 1, 1024, " ") 726 write_log(3, buf) 727 py_pjsua.pres_dump(1) 728 write_log(3, "Dump complete") 368 729 elif choice[0] == "a": 369 if g_current_call != py_pjsua.PJSUA_INVALID_ID: 730 if g_current_call != py_pjsua.PJSUA_INVALID_ID: 731 370 732 py_pjsua.call_answer(g_current_call, 200, None, None) 371 733 else: -
pjproject/trunk/pjsip-apps/src/py_pjsua/py_pjsua.c
r928 r934 63 63 if (PyCallable_Check(obj_logging_init)) 64 64 { 65 //PyObject_CallFunction(obj_logging_init,"iSi",level,data,len); 66 //printf("level : %d data : %s len : %d\n",level, data, len); 65 67 66 PyObject_CallFunctionObjArgs( 68 67 obj_logging_init, Py_BuildValue("i",level), … … 1895 1894 return NULL; 1896 1895 } 1897 /*printf("name : %s\n",name); 1898 printf("init : %d\n", init_size); 1899 printf("increment : %d\n", increment);*/ 1896 1900 1897 p = pjsua_pool_create(name, init_size, increment); 1901 1898 pool = (pj_pool_Object *)PyType_GenericNew(&pj_pool_Type, NULL, NULL); … … 2135 2132 } 2136 2133 status = pjsua_start(); 2137 //printf("status %d\n",status);2134 2138 2135 return Py_BuildValue("i",status); 2139 2136 } … … 2151 2148 } 2152 2149 status = pjsua_destroy(); 2153 //printf("status %d\n",status);2150 2154 2151 return Py_BuildValue("i",status); 2155 2152 } … … 2168 2165 } 2169 2166 ret = pjsua_handle_events(msec); 2170 //printf("return %d\n",ret);2167 2171 2168 return Py_BuildValue("i",ret); 2172 2169 } … … 2185 2182 } 2186 2183 status = pjsua_verify_sip_url(url); 2187 //printf("status %d\n",status);2184 2188 2185 return Py_BuildValue("i",status); 2189 2186 } … … 3326 3323 } 3327 3324 status = pjsua_transport_set_enable(id, enabled); 3328 //printf("status %d\n",status);3325 3329 3326 return Py_BuildValue("i",status); 3330 3327 } … … 3343 3340 } 3344 3341 status = pjsua_transport_close(id, force); 3345 //printf("status %d\n",status);3342 3346 3343 return Py_BuildValue("i",status); 3347 3344 } … … 5393 5390 "Bits per sample" 5394 5391 }, 5395 /*{5392 { 5396 5393 "listener_cnt", T_INT, 5397 5394 offsetof(conf_port_info_Object, listener_cnt), 0, 5398 5395 "Number of listeners in the array." 5399 }, */5396 }, 5400 5397 { 5401 5398 "listeners", T_OBJECT_EX, … … 6304 6301 str.ptr = PyString_AsString(filename); 6305 6302 str.slen = strlen(PyString_AsString(filename)); 6306 strparam.ptr = PyString_AsString(enc_param); 6307 strparam.slen = strlen(PyString_AsString(enc_param)); 6308 status = pjsua_recorder_create 6303 if (enc_param != Py_None) 6304 { 6305 strparam.ptr = PyString_AsString(enc_param); 6306 strparam.slen = strlen(PyString_AsString(enc_param)); 6307 status = pjsua_recorder_create 6309 6308 (&str, enc_type, NULL, max_size, options, &p_id); 6310 6309 } else { 6310 status = pjsua_recorder_create 6311 (&str, enc_type, NULL, max_size, options, &p_id); 6312 } 6311 6313 return Py_BuildValue("ii", status, p_id); 6312 6314 } … … 7258 7260 pj_pool_release(pool); 7259 7261 } else { 7262 7260 7263 status = pjsua_call_make_call(acc_id, &dst_uri, 7261 7264 options, (void*)user_data, NULL, &call_id); 7262 7265 } 7263 7266 7264 7267 return Py_BuildValue("ii",status, call_id); 7268 7265 7269 } 7266 7270 … … 7485 7489 } else { 7486 7490 7487 status = pjsua_call_answer(call_id, code, reason, NULL); 7491 status = pjsua_call_answer(call_id, code, reason, NULL); 7492 7488 7493 } 7489 7494
Note: See TracChangeset
for help on using the changeset viewer.