Ignore:
Timestamp:
Feb 16, 2018 9:37:00 AM (7 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/sample2.java

    r5402 r5738  
    3434class MyObserver implements MyAppObserver { 
    3535        private static MyCall currentCall = null; 
     36        private static boolean del_call_scheduled = false; 
     37         
     38        public void check_call_deletion() 
     39        { 
     40                if (del_call_scheduled && currentCall != null) { 
     41                        currentCall.delete(); 
     42                        currentCall = null; 
     43                        del_call_scheduled = false; 
     44                } 
     45        } 
    3646         
    3747        @Override 
     
    6777                } 
    6878                if (ci.getState() == pjsip_inv_state.PJSIP_INV_STATE_DISCONNECTED) { 
    69                         currentCall = null;                         
     79                        // Should not delete call instance here, so let's schedule it. 
     80                        // The call will be deleted by our main worker thread. 
     81                        del_call_scheduled = true;                  
    7082                } else if (ci.getState() == pjsip_inv_state.PJSIP_INV_STATE_CONFIRMED) { 
    7183                        if (ci.getSetting().getVideoCount() != 0) { 
     
    89101class MyThread extends Thread { 
    90102        private static MyApp app = new MyApp(); 
    91         private static MyAppObserver observer = new MyObserver(); 
     103        private static MyObserver observer = new MyObserver(); 
    92104        private static MyAccount account = null; 
    93105        private static AccountConfig accCfg = null;                   
     
    118130 
    119131                while (!Thread.currentThread().isInterrupted()) { 
     132                        // Handle events 
    120133                        MyApp.ep.libHandleEvents(10); 
     134 
     135                        // Check if any call instance need to be deleted 
     136                        observer.check_call_deletion(); 
    121137                        try { 
    122138                                Thread.currentThread().sleep(50); 
Note: See TracChangeset for help on using the changeset viewer.