Changeset 2163 for pjproject/trunk/pjsip-apps/src/python/pjsua.py
- Timestamp:
- Jul 21, 2008 6:20:57 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 " **"
Note: See TracChangeset
for help on using the changeset viewer.