Ignore:
Timestamp:
Jul 21, 2008 6:20:57 PM (16 years ago)
Author:
bennylp
Message:

Major modifications in Python module and pjsua.py wrapper:

  • replaced call/acc/buddy dictionaries with user data attachment
  • recommended to install callback when creating the object, to prevent missing some events
  • fixed circular references by using weakref
  • protect access to pjsua with mutex; found out that without this there will be deadlock in Python
  • fixed memory leaks in the _pjsua.c module (objects reference counter not properly maintained)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip-apps/src/python/samples/call.py

    r2119 r2163  
    1 # $Id:$ 
     1# $Id$ 
    22# 
    33# SIP call sample. 
     
    1919class MyAccountCallback(pj.AccountCallback): 
    2020 
    21     def __init__(self, account): 
     21    def __init__(self, account=None): 
    2222        pj.AccountCallback.__init__(self, account) 
    2323 
     
    2525    def on_incoming_call(self, call): 
    2626        global current_call  
    27  
    2827        if current_call: 
    2928            call.answer(486, "Busy") 
     
    4443class MyCallCallback(pj.CallCallback): 
    4544 
    46     def __init__(self, call): 
     45    def __init__(self, call=None): 
    4746        pj.CallCallback.__init__(self, call) 
    4847 
     
    5049    def on_state(self): 
    5150        global current_call 
    52  
    5351        print "Call with", self.call.info().remote_uri, 
    5452        print "is", self.call.info().state_text, 
     
    5856        if self.call.info().state == pj.CallState.DISCONNECTED: 
    5957            current_call = None 
     58            print 'Current call is', current_call 
    6059 
    6160    # Notification when call's media state has changed. 
     
    7473    try: 
    7574        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()) 
    8076    except pj.Error, e: 
    81         print "Error: " + str(e) 
     77        print "Exception: " + str(e) 
    8278        return None 
    8379         
     
    10197 
    10298    # 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()) 
    106100 
    107101    # If argument is specified then make call to the URI 
    108102    if len(sys.argv) > 1: 
     103        lck = lib.auto_lock() 
    109104        current_call = make_call(sys.argv[1]) 
     105        print 'Current call is', current_call 
     106        del lck 
    110107 
    111108    my_sip_uri = "sip:" + transport.info().host + \ 
     
    126123            if input == "": 
    127124                continue 
     125            lck = lib.auto_lock() 
    128126            current_call = make_call(input) 
     127            del lck 
    129128 
    130129        elif input == "h": 
     
    144143 
    145144    # Shutdown the library 
     145    transport = None 
     146    acc.delete() 
     147    acc = None 
    146148    lib.destroy() 
    147149    lib = None 
Note: See TracChangeset for help on using the changeset viewer.