- Timestamp:
- Jul 17, 2013 8:20:50 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/projects/jni/pjsip-apps/src/jni/hello.java
r4558 r4566 5 5 import java.io.IOException; 6 6 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; 7 import org.pjsip.pjsua.*; 8 9 class app_config { 10 public static int cur_call_id = -1; 11 } 19 12 20 13 class MyPjsuaCallback extends PjsuaCallback { … … 30 23 } 31 24 } 25 26 /* Testing pj_str_t-String map with director */ 32 27 @Override 33 28 public void on_pager(int call_id, String from, String to, String contact, String mime_type, String body) … … 44 39 /* Auto answer */ 45 40 pjsua.call_answer(call_id, 200, null, null); 46 } 47 } 41 app_config.cur_call_id = call_id; 42 } 43 } 44 45 class MyLogger extends PjsuaLoggingConfigCallback { 46 @Override 47 public void on_log(int level, String data) 48 { 49 System.out.print("LOG: " + data); 50 } 51 } 52 53 class 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 48 66 49 67 public class hello { … … 80 98 pjsua_config cfg = new pjsua_config(); 81 99 pjsua.config_default(cfg); 82 /* Setup callback */83 100 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); 85 108 if (status != pjsua.PJ_SUCCESS) { 86 109 pj_error_exit("Error inintializing pjsua", status); … … 117 140 /* Make call to the URL. */ 118 141 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); 120 143 if (status != pjsua.PJ_SUCCESS) { 121 144 pj_error_exit("Error making call", status); 122 145 } 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); 123 159 } 124 160 … … 141 177 } else if (userInput.equals("h")) { 142 178 pjsua.call_hangup_all(); 179 app_config.cur_call_id = -1; 143 180 } else if (userInput.equals("c")) { 144 181 /* Test string as output param, it is wrapped as string array */ … … 154 191 } else if (userInput.equals("dd")) { 155 192 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); 156 209 } 157 210 }
Note: See TracChangeset
for help on using the changeset viewer.