Ignore:
Timestamp:
Jul 17, 2013 8:20:50 PM (11 years ago)
Author:
nanang
Message:

JNI projects:

  • More work on callbacks wrapper, i.e: pj_timer_heap_callback for pjsua_schedule_timer() and pjsua_logging_config::cb.
  • Map pjsua_call_dump() output buffer.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/branches/projects/jni/pjsip-apps/src/jni/hello.java

    r4558 r4566  
    55import java.io.IOException; 
    66 
    7 import org.pjsip.pjsua.pj_pool_t; 
    8 import org.pjsip.pjsua.pjsip_rx_data; 
    9 import org.pjsip.pjsua.pjsip_transport_type_e; 
    10  
    11 import org.pjsip.pjsua.pjsua; 
    12 import org.pjsip.pjsua.pjsua_acc_config; 
    13 import org.pjsip.pjsua.pjsua_call_info; 
    14 import org.pjsip.pjsua.pjsua_call_media_status; 
    15 import org.pjsip.pjsua.pjsua_config; 
    16 import org.pjsip.pjsua.pjsua_logging_config; 
    17 import org.pjsip.pjsua.pjsua_transport_config; 
    18 import org.pjsip.pjsua.PjsuaCallback; 
     7import org.pjsip.pjsua.*; 
     8 
     9class app_config { 
     10        public static int cur_call_id = -1; 
     11} 
    1912 
    2013class MyPjsuaCallback extends PjsuaCallback { 
     
    3023                } 
    3124        } 
     25         
     26        /* Testing pj_str_t-String map with director */ 
    3227        @Override 
    3328        public void on_pager(int call_id, String from, String to, String contact, String mime_type, String body) 
     
    4439                /* Auto answer */ 
    4540                pjsua.call_answer(call_id, 200, null, null); 
    46         } 
    47 } 
     41                app_config.cur_call_id = call_id; 
     42        } 
     43} 
     44 
     45class MyLogger extends PjsuaLoggingConfigCallback { 
     46        @Override 
     47        public void on_log(int level, String data) 
     48        { 
     49                System.out.print("LOG: " + data); 
     50        } 
     51} 
     52 
     53class MyTimerCallback extends PjTimerHeapCallback { 
     54        private int _user_data; 
     55         
     56        /* Use this class itself to store app user data */ 
     57        MyTimerCallback(int user_data) { _user_data = user_data; } 
     58         
     59        @Override 
     60        public void on_timer(pj_timer_heap_t timer_heap, pj_timer_entry entry) 
     61        { 
     62                System.out.println("======== Timer fired (user data = " + _user_data + ")"); 
     63        } 
     64} 
     65 
    4866 
    4967public class hello { 
     
    8098                        pjsua_config cfg = new pjsua_config(); 
    8199                        pjsua.config_default(cfg); 
    82                         /* Setup callback */ 
    83100                        cfg.setCb(new MyPjsuaCallback()); 
    84                         status = pjsua.init(cfg, null, null); 
     101 
     102                        pjsua_logging_config log_cfg = new pjsua_logging_config(); 
     103                        pjsua.logging_config_default(log_cfg); 
     104                        log_cfg.setLevel(4); 
     105                        log_cfg.setCb(new MyLogger()); 
     106 
     107                        status = pjsua.init(cfg, log_cfg, null); 
    85108                        if (status != pjsua.PJ_SUCCESS) { 
    86109                                pj_error_exit("Error inintializing pjsua", status); 
     
    117140                /* Make call to the URL. */ 
    118141                if (false) { 
    119                         status = pjsua.call_make_call(acc_id[0], "sip:localhost", null, 0, null, call_id); 
     142                        status = pjsua.call_make_call(acc_id[0], "sip:localhost:6000", null, 0, null, call_id); 
    120143                        if (status != pjsua.PJ_SUCCESS) { 
    121144                                pj_error_exit("Error making call", status); 
    122145                        } 
     146                        app_config.cur_call_id = call_id[0]; 
     147                } 
     148                 
     149                /* Test timer */ 
     150                { 
     151                        pj_timer_entry timer = new pj_timer_entry(); 
     152                        timer.setCb(new MyTimerCallback(1234567890)); 
     153 
     154                        pj_time_val tv = new pj_time_val(); 
     155                        tv.setSec(0); 
     156                        tv.setMsec(1000); 
     157 
     158                        pjsua.schedule_timer(timer, tv); 
    123159                } 
    124160                 
     
    141177                        } else if (userInput.equals("h")) { 
    142178                                pjsua.call_hangup_all(); 
     179                                app_config.cur_call_id = -1; 
    143180                        } else if (userInput.equals("c")) { 
    144181                                /* Test string as output param, it is wrapped as string array */ 
     
    154191                        } else if (userInput.equals("dd")) { 
    155192                                pjsua.dump(true); 
     193                        } else if (userInput.equals("dq")) { 
     194                                if (app_config.cur_call_id == -1) { 
     195                                        System.out.println("No active call"); 
     196                                        continue; 
     197                                } 
     198                                 
     199                                byte[] buf = new byte[1024*2]; 
     200                                pjsua.call_dump(app_config.cur_call_id, true, buf, ""); 
     201 
     202                                /* Build string from byte array, find null terminator first */ 
     203                                int len = 0; 
     204                                while (len < buf.length && buf[len] != 0) ++len; 
     205                                String call_dump = new String(buf, 0, len); 
     206 
     207                                System.out.println("Statistics of call " + app_config.cur_call_id); 
     208                                System.out.println(call_dump); 
    156209                        } 
    157210                } 
Note: See TracChangeset for help on using the changeset viewer.