- Timestamp:
- Jul 19, 2008 3:40:21 PM (16 years ago)
- Location:
- pjproject/trunk/pjsip-apps/src/python
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip-apps/src/python/_pjsua.c
r2156 r2158 3458 3458 3459 3459 /* 3460 * py_pjsua_conf_set_tx_level 3461 */ 3462 static PyObject *py_pjsua_conf_set_tx_level 3463 (PyObject *pSelf, PyObject *pArgs) 3464 { 3465 int slot; 3466 float level; 3467 int status; 3468 3469 PJ_UNUSED_ARG(pSelf); 3470 3471 if (!PyArg_ParseTuple(pArgs, "if", &slot, &level)) 3472 { 3473 return NULL; 3474 } 3475 3476 status = pjsua_conf_adjust_tx_level(slot, level); 3477 3478 3479 return Py_BuildValue("i", status); 3480 } 3481 3482 /* 3483 * py_pjsua_conf_set_rx_level 3484 */ 3485 static PyObject *py_pjsua_conf_set_rx_level 3486 (PyObject *pSelf, PyObject *pArgs) 3487 { 3488 int slot; 3489 float level; 3490 int status; 3491 3492 PJ_UNUSED_ARG(pSelf); 3493 3494 if (!PyArg_ParseTuple(pArgs, "if", &slot, &level)) 3495 { 3496 return NULL; 3497 } 3498 3499 status = pjsua_conf_adjust_rx_level(slot, level); 3500 3501 3502 return Py_BuildValue("i", status); 3503 } 3504 3505 /* 3506 * py_pjsua_conf_get_signal_level 3507 */ 3508 static PyObject *py_pjsua_conf_get_signal_level 3509 (PyObject *pSelf, PyObject *pArgs) 3510 { 3511 int slot; 3512 unsigned tx_level, rx_level; 3513 int status; 3514 3515 PJ_UNUSED_ARG(pSelf); 3516 3517 if (!PyArg_ParseTuple(pArgs, "i", &slot)) 3518 { 3519 return NULL; 3520 } 3521 3522 status = pjsua_conf_get_signal_level(slot, &tx_level, &rx_level); 3523 3524 3525 return Py_BuildValue("iff", status, (float)(tx_level/255.0), 3526 (float)(rx_level/255.0)); 3527 } 3528 3529 /* 3460 3530 * py_pjsua_player_create 3461 3531 */ … … 3478 3548 str.slen = strlen(PyString_AsString(filename)); 3479 3549 status = pjsua_player_create(&str, options, &id); 3550 3551 return Py_BuildValue("ii", status, id); 3552 } 3553 3554 /* 3555 * py_pjsua_playlist_create 3556 */ 3557 static PyObject *py_pjsua_playlist_create 3558 (PyObject *pSelf, PyObject *pArgs) 3559 { 3560 int id; 3561 int options; 3562 PyObject *arg_label, *arg_filelist; 3563 pj_str_t label; 3564 int count; 3565 pj_str_t files[64]; 3566 int status; 3567 3568 PJ_UNUSED_ARG(pSelf); 3569 3570 if (!PyArg_ParseTuple(pArgs, "OOi", &arg_label, &arg_filelist, &options)) 3571 { 3572 return NULL; 3573 } 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); 3480 3589 3481 3590 return Py_BuildValue("ii", status, id); … … 5766 5875 }, 5767 5876 { 5877 "conf_set_tx_level", py_pjsua_conf_set_tx_level, METH_VARARGS, 5878 "Adjust the signal level to be transmitted from the bridge to the" 5879 " specified port by making it louder or quieter" 5880 }, 5881 { 5882 "conf_set_rx_level", py_pjsua_conf_set_rx_level, METH_VARARGS, 5883 "Adjust the signal level to be received from the specified port (to" 5884 " the bridge) by making it louder or quieter" 5885 }, 5886 { 5887 "conf_get_signal_level", py_pjsua_conf_get_signal_level, METH_VARARGS, 5888 "Get last signal level transmitted to or received from the specified port" 5889 }, 5890 { 5768 5891 "player_create", py_pjsua_player_create, METH_VARARGS, 5769 5892 pjsua_player_create_doc 5893 }, 5894 { 5895 "playlist_create", py_pjsua_playlist_create, METH_VARARGS, 5896 "Create WAV playlist" 5770 5897 }, 5771 5898 { -
pjproject/trunk/pjsip-apps/src/python/pjsua.py
r2156 r2158 12 12 13 13 14 FEATURES15 16 - Session Initiation Protocol (SIP :14 1. FEATURES 15 16 - Session Initiation Protocol (SIP) features: 17 17 - Basic registration and call 18 18 - Multiple accounts … … 20 20 - Presence 21 21 - Instant messaging 22 - Media stack: 22 - Multiple SIP accounts 23 - Media features: 23 24 - Audio 24 25 - Conferencing … … 26 27 - Codecs: PCMA, PCMU, GSM, iLBC, Speex, G.722, L16 27 28 - RTP/RTCP 28 - Secure RTP (SRTP 29 - Secure RTP (SRTP) 30 - WAV playback, recording, and playlist 29 31 - NAT traversal features 30 32 - Symmetric RTP … … 33 35 - ICE 34 36 37 38 2. USING 39 40 See http://www.pjsip.org/trac/wiki/Python_SIP_Tutorial for a more thorough 41 tutorial. The paragraphs below explain basic tasks on using this module. 42 43 44 2.1 Initialization 45 46 Instantiate Lib class. This class is a singleton class, there can only be 47 one instance of this class in the program. 48 49 Initialize the library with lib.init() method, and optionally specify various 50 settings like UAConfig, MediaConfig, and LogConfig. 51 52 Create one or more SIP Transport instances. 53 54 Create one or more SIP Account's instances, as explained below. 55 56 Once initialization is complete, call lib.start(). 57 58 59 2.2 Accounts 60 61 At least one Account must be created in the program. Use Lib's create_account() 62 or create_account_for_transport() to create the account instance. 63 64 Account may emit events, and to capture these events, application must derive 65 a class from AccountCallback class, and install the callback to the Account 66 instance using set_callback() method. 67 68 69 2.3 Calls 70 71 Calls are represented with Call class. Use the Call methods to operate the 72 call. Outgoing calls are made with make_call() method of Account class. 73 Incoming calls are reported by on_incoming_call() callback of AccountCallback 74 class. 75 76 Call may emit events, and to capture these events, application must derive 77 a class from CallCallback class, and install the callback to the Call instance 78 using set_callback() method. 79 80 Note that just like every other operations in this module, the make_call() 81 method is non-blocking (i.e. it doesn't wait until the call is established 82 before the function returns). Progress to the Call is reported via CallCallback 83 class above. 84 85 86 2.4 Media 87 88 Every objects that can transmit or receive media/audio (e.g. calls, WAV player, 89 WAV recorder, WAV playlist) are connected to a central conference bridge. 90 Application can use the object's method or Lib's method to retrieve the slot 91 number of that particular object in the conference bridge: 92 - to retrieve the slot number of a call, use Call.info().conf_slot 93 - to retrieve the slot number of a WAV player, use Lib.player_get_slot() 94 - to retrieve the slot number of a WAV recorder, use Lib.recorder_get_slot() 95 - to retrieve the slot number of a playlist, use Lib.playlist_get_slot() 96 - the slot number zero is used to identity the sound device. 97 98 The conference bridge provides powerful switching and mixing functionality 99 for application. With the conference bridge, each conference slot (e.g. 100 a call) can transmit to multiple destinations, and one destination can 101 receive from multiple sources. If more than one media terminations are 102 terminated in the same slot, the conference bridge will mix the signal 103 automatically. 104 105 Application connects one media termination/slot to another by calling 106 lib.conf_connect() method. This will establish unidirectional media flow from 107 the source termination to the sink termination. To establish bidirectional 108 media flow, application would need to make another call to lib/conf_connect(), 109 this time inverting the source and destination slots in the parameter. 110 111 112 2.5 Presence 113 114 To subscribe to presence information of a buddy, add Buddy object with 115 add_buddy() method of Account class. Subsequent presence information for that 116 Buddy will be reported via BuddyCallback class (which application should 117 device and install to the Buddy object). 118 119 Each Account has presence status associated with it, which will be informed 120 to remote buddies when they subscribe to our presence information. Incoming 121 presence subscription request by default will be accepted automatically, 122 unless on_incoming_subscribe() method of AccountCallback is implemented. 123 124 125 2.6 Instant Messaging 126 127 Use Buddy's send_pager() and send_typing_ind() to send instant message and 128 typing indication to the specified buddy. 129 130 Incoming instant messages and typing indications will be reported via one of 131 the three mechanisms below. 132 133 If the instant message or typing indication is received in the context of an 134 active call, then it will be reported via on_pager() or on_typing() method 135 of CallCallback class. 136 137 If the instant message or typing indication is received outside any call 138 contexts, and it is received from a registered buddy, then it will be reported 139 via on_pager() or on_typing() method of BuddyCallback class. 140 141 If the criterias above are not met, the instant message or typing indication 142 will be reported via on_pager() or on_typing() method of the AccountCallback 143 class. 144 145 The delivery status of outgoing instant messages are reported via 146 on_pager_status() method of CallCallback, BuddyCallback, or AccountCallback, 147 depending on whether the instant message was sent using Call, Buddy, or 148 Account's send_pager() method. 35 149 36 150 """ … … 223 337 224 338 max_calls -- maximum number of calls to be supported. 225 nameserver -- arrayof nameserver hostnames or IP addresses. Nameserver339 nameserver -- list of nameserver hostnames or IP addresses. Nameserver 226 340 must be configured if DNS SRV resolution is desired. 227 341 stun_domain -- if nameserver is configured, this can be used to query … … 2050 2164 2051 2165 Return: 2052 arrayof SoundDeviceInfo. The index of the element specifies2166 list of SoundDeviceInfo. The index of the element specifies 2053 2167 the device ID for the device. 2054 2168 """ 2055 sdi_ array= _pjsua.enum_snd_devs()2169 sdi_list = _pjsua.enum_snd_devs() 2056 2170 info = [] 2057 for sdi in sdi_ array:2171 for sdi in sdi_list: 2058 2172 info.append(SoundDeviceInfo(sdi)) 2059 2173 return info … … 2133 2247 self._err_check("conf_disconnect()", self, err) 2134 2248 2249 def conf_set_tx_level(self, slot, level): 2250 """Adjust the signal level to be transmitted from the bridge to 2251 the specified port by making it louder or quieter. 2252 2253 Keyword arguments: 2254 slot -- integer to identify the conference slot number. 2255 level -- Signal level adjustment. Value 1.0 means no level 2256 adjustment, while value 0 means to mute the port. 2257 """ 2258 err = _pjsua.conf_set_tx_level(slot, level) 2259 self._err_check("conf_set_tx_level()", self, err) 2260 2261 def conf_set_rx_level(self, slot, level): 2262 """Adjust the signal level to be received from the specified port 2263 (to the bridge) by making it louder or quieter. 2264 2265 Keyword arguments: 2266 slot -- integer to identify the conference slot number. 2267 level -- Signal level adjustment. Value 1.0 means no level 2268 adjustment, while value 0 means to mute the port. 2269 """ 2270 err = _pjsua.conf_set_rx_level(slot, level) 2271 self._err_check("conf_set_rx_level()", self, err) 2272 2273 def conf_get_signal_level(self, slot): 2274 """Get last signal level transmitted to or received from the 2275 specified port. The signal levels are float values from 0.0 to 1.0, 2276 with 0.0 indicates no signal, and 1.0 indicates the loudest signal 2277 level. 2278 2279 Keyword arguments: 2280 slot -- integer to identify the conference slot number. 2281 2282 Return value: 2283 (tx_level, rx_level) tuple. 2284 """ 2285 err, tx_level, rx_level = _pjsua.conf_get_signal_level(slot) 2286 self._err_check("conf_get_signal_level()", self, err) 2287 return (tx_level, rx_level) 2288 2289 2290 2135 2291 # Codecs API 2136 2292 … … 2139 2295 2140 2296 Return: 2141 arrayof CodecInfo2142 2143 """ 2144 ci_ array= _pjsua.enum_codecs()2297 list of CodecInfo 2298 2299 """ 2300 ci_list = _pjsua.enum_codecs() 2145 2301 codec_info = [] 2146 for ci in ci_ array:2302 for ci in ci_list: 2147 2303 cp = _pjsua.codec_get_param(ci.id) 2148 2304 if cp: … … 2192 2348 Keyword arguments 2193 2349 filename -- WAV file name 2194 loop -- boolean to specify whet er playback shoudl2195 automatically restart 2350 loop -- boolean to specify whether playback should 2351 automatically restart upon EOF 2196 2352 Return: 2197 2353 WAV player ID … … 2241 2397 err = _pjsua.player_destroy(player_id) 2242 2398 self._err_check("player_destroy()", self, err) 2399 2400 def create_playlist(self, filelist, label="playlist", loop=True): 2401 """Create WAV playlist. 2402 2403 Keyword arguments: 2404 filelist -- List of WAV file names. 2405 label -- Optional name to be assigned to the playlist 2406 object (useful for logging) 2407 loop -- boolean to specify whether playback should 2408 automatically restart upon EOF 2409 2410 Return: 2411 playlist_id 2412 """ 2413 opt = 0 2414 if not loop: 2415 opt = opt + 1 2416 err, playlist_id = _pjsua.playlist_create(label, filelist, opt) 2417 self._err_check("create_playlist()", self, err) 2418 return playlist_id 2419 2420 def playlist_get_slot(self, playlist_id): 2421 """Get the conference port ID for the specified playlist. 2422 2423 Keyword arguments: 2424 playlist_id -- the WAV playlist ID 2425 2426 Return: 2427 Conference slot number for the playlist 2428 2429 """ 2430 slot = _pjsua.player_get_conf_port(playlist_id) 2431 if slot < 0: 2432 self._err_check("playlist_get_slot()", self, -1, 2433 "Invalid playlist id") 2434 return slot 2435 2436 def playlist_destroy(self, playlist_id): 2437 """Destroy the WAV playlist. 2438 2439 Keyword arguments: 2440 playlist_id -- the WAV playlist ID. 2441 2442 """ 2443 err = _pjsua.player_destroy(playlist_id) 2444 self._err_check("playlist_destroy()", self, err) 2243 2445 2244 2446 def create_recorder(self, filename):
Note: See TracChangeset
for help on using the changeset viewer.