Ignore:
Timestamp:
Feb 16, 2018 9:37:00 AM (6 years ago)
Author:
nanang
Message:

Misc (#2059): Update Android & Java app samples to avoid call instance deletion in the library callback context (thanks Kai Ludwig for the feedbacks).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip-apps/src/swig/java/sample.java

    r5649 r5738  
    2626class MyObserver implements MyAppObserver { 
    2727        private static MyCall currentCall = null; 
     28        private boolean del_call_scheduled = false; 
     29         
     30        public void check_call_deletion() 
     31        { 
     32                if (del_call_scheduled && currentCall != null) { 
     33                        currentCall.delete(); 
     34                        currentCall = null; 
     35                        del_call_scheduled = false; 
     36                } 
     37        } 
    2838         
    2939        @Override 
     
    5868                        ci = null; 
    5969                } 
    60                 if (ci.getState() == pjsip_inv_state.PJSIP_INV_STATE_DISCONNECTED) 
    61                         currentCall = null;              
     70                if (ci.getState() == pjsip_inv_state.PJSIP_INV_STATE_DISCONNECTED) { 
     71                        // Should not delete call instance in this context, 
     72                        // so let's just schedule it, the call will be deleted 
     73                        // in our main worker thread context. 
     74                        del_call_scheduled = true; 
     75                } 
     76                         
    6277        } 
    6378         
     
    86101public class sample { 
    87102        private static MyApp app = new MyApp(); 
    88         private static MyAppObserver observer = new MyObserver(); 
     103        private static MyObserver observer = new MyObserver(); 
    89104        private static MyAccount account = null; 
    90105        private static AccountConfig accCfg = null;              
     
    142157 
    143158                while (!Thread.currentThread().isInterrupted()) { 
     159                        // Handle events 
    144160                        MyApp.ep.libHandleEvents(10); 
     161                         
     162                        // Check if any call instance need to be deleted 
     163                        observer.check_call_deletion(); 
     164                         
    145165                        try {                                            
    146166                                Thread.currentThread().sleep(50); 
    147167                        } catch (InterruptedException ie) {                                              
    148168                                break; 
    149                         }                                        
     169                        }                        
    150170                } 
    151171                app.deinit(); 
Note: See TracChangeset for help on using the changeset viewer.