Changeset 4549
- Timestamp:
- Jun 29, 2013 1:14:27 AM (11 years ago)
- Location:
- pjproject/branches/projects/jni
- Files:
-
- 3 added
- 2 deleted
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/projects/jni/pjsip-apps/src/jni
-
Property
svn:ignore
set to
output
yacctab.py
lextab.py
*.log
-
Property
svn:ignore
set to
-
pjproject/branches/projects/jni/pjsip-apps/src/jni/Makefile
r4541 r4549 13 13 MY_JNI_LDFLAGS = -L$(MY_JDK)/lib -Wl,--kill-at 14 14 15 # Choose C or C++ SWIG wrapper target, just for dev purpose.16 # Note that C target doesn't support callback, and C++ target doesn't support nested class/struct.17 SWIG_CPP_TARGET = 018 19 15 # Build settings 20 16 MY_CFLAGS = $(PJ_CFLAGS) $(MY_JNI_CFLAGS) 21 MY_LDFLAGS = $(PJ_LDFLAGS) $(PJ_LDLIBS) $(MY_JNI_LDFLAGS) 17 MY_LDFLAGS = $(PJ_LDFLAGS) $(PJ_LDLIBS) $(MY_JNI_LDFLAGS) -static-libstdc++ 22 18 23 19 # Output/intermediate path settings … … 25 21 MY_OUT_DIR = output 26 22 MY_SWIG_IF = $(MY_OUT_DIR)/pjsua.i 27 MY_SWIG_FLAG = - Wall23 MY_SWIG_FLAG = -c++ -I$(MY_OUT_DIR) # -Wall 28 24 MY_SWIG_WRAPPER = $(MY_OUT_DIR)/pjsua_wrap 29 MY_CALLBACKS = callbacks30 25 MY_PACKAGE_SRC = $(MY_OUT_DIR)/src/$(subst .,/,$(MY_PACKAGE)) 31 26 MY_PACKAGE_BIN = $(MY_OUT_DIR)/bin 32 27 MY_JNI_LIB = $(MY_PACKAGE_BIN)/pjsua.dll 33 34 # Adjust setting for C/C++35 ifeq ($(SWIG_CPP_TARGET),1)36 MY_CC = $(PJ_CXX)37 MY_LDFLAGS += -static-libstdc++38 MY_SWIG_FLAG += -c++ -debug-tmsearch -debug-tmused39 else40 MY_CC = $(PJ_CC)41 MY_SWIG_FLAG += -debug-tmsearch -debug-tmused42 endif43 28 44 29 all: $(MY_JNI_LIB) java … … 47 32 rm -rf $(MY_OUT_DIR) 48 33 34 $(MY_SWIG_IF).tmp: swig_gen.py 35 @mkdir -p $(MY_OUT_DIR) 36 python swig_gen.py > $(MY_SWIG_IF).tmp 37 49 38 $(MY_SWIG_IF): header.i $(MY_SWIG_IF).tmp 50 39 cat header.i > $(MY_SWIG_IF) 51 40 cat $(MY_SWIG_IF).tmp >> $(MY_SWIG_IF) 52 41 53 $(MY_SWIG_IF).tmp: swig_gen.py 54 @mkdir -p $(MY_OUT_DIR) 55 python swig_gen.py > $(MY_SWIG_IF).tmp 56 57 $(MY_SWIG_WRAPPER).c: $(MY_SWIG_IF) $(MY_CALLBACKS).h $(MY_CALLBACKS).cpp $(MY_CALLBACKS).i 58 # Cleanup java outdir first, to remove any old/deprecated java files 42 $(MY_SWIG_WRAPPER).c: $(MY_SWIG_IF) callbacks.i my_typemaps.i 43 @# Cleanup java outdir first, to remove any old/deprecated java files 59 44 rm -rf $(MY_PACKAGE_SRC) 60 45 @mkdir -p $(MY_PACKAGE_SRC) 61 46 $(MY_SWIG) $(MY_SWIG_FLAG) -o $(MY_SWIG_WRAPPER).c -package $(MY_PACKAGE) \ 62 -outdir $(MY_PACKAGE_SRC) -java $(MY_SWIG_IF) > $(MY_SWIG_WRAPPER)-tm.txt 63 $(MY_SWIG) -c++ $(MY_SWIG_FLAG) -o $(MY_SWIG_WRAPPER)2.c -package $(MY_PACKAGE) \ 64 -outdir $(MY_PACKAGE_SRC) -java $(MY_CALLBACKS).i > $(MY_SWIG_WRAPPER)2-tm.txt 47 -outdir $(MY_PACKAGE_SRC) -java $(MY_SWIG_IF) > $(MY_SWIG_WRAPPER)-tm.log 65 48 66 $(MY_SWIG_WRAPPER).o: $(MY_SWIG_WRAPPER).c 67 $(MY_CC) -c $(MY_CFLAGS) $(MY_SWIG_WRAPPER).c -o $(MY_SWIG_WRAPPER).o 68 $(PJ_CXX) -c $(MY_CFLAGS) $(MY_SWIG_WRAPPER)2.c -o $(MY_SWIG_WRAPPER)2.o 69 70 $(MY_OUT_DIR)/$(MY_CALLBACKS).o: $(MY_CALLBACKS).cpp $(MY_CALLBACKS).h 71 $(PJ_CXX) -c $(MY_CFLAGS) $(MY_CALLBACKS).cpp -o $(MY_OUT_DIR)/$(MY_CALLBACKS).o 72 73 $(MY_JNI_LIB): $(MY_SWIG_WRAPPER).o $(MY_OUT_DIR)/$(MY_CALLBACKS).o 49 $(MY_JNI_LIB): $(MY_SWIG_WRAPPER).c 74 50 @mkdir -p $(MY_PACKAGE_BIN) 75 $(PJ_CXX) -shared -o $(MY_JNI_LIB) $(MY_SWIG_WRAPPER). o $(MY_OUT_DIR)/$(MY_CALLBACKS).o\76 $(MY_ SWIG_WRAPPER)2.o $(MY_LDFLAGS) -static-libstdc++51 $(PJ_CXX) -shared -o $(MY_JNI_LIB) $(MY_SWIG_WRAPPER).c $(MY_OUT_DIR)/callbacks.c \ 52 $(MY_CFLAGS) $(MY_LDFLAGS) 77 53 78 54 java: hello.java … … 82 58 83 59 test: $(MY_PACKAGE_BIN)/hello.class 84 # Need to specify classpath and library path, alternatively, they can be set via85 # CLASSPATH and java.library.path env settings60 @# Need to specify classpath and library path, alternatively, they can be set via 61 @# CLASSPATH and java.library.path env settings 86 62 $(MY_JAVA) -cp $(MY_PACKAGE_BIN) -Djava.library.path="$(MY_PACKAGE_BIN)" hello -
pjproject/branches/projects/jni/pjsip-apps/src/jni/callbacks.i
r4541 r4549 1 %module (directors="1") pjsua_cb 2 3 #pragma SWIG nowarn=312 /* nested struct/class/union */ 1 /* $Id$ */ 4 2 5 3 %header %{ 6 #include <pjsua-lib/pjsua.h>7 4 #include "callbacks.h" 8 5 %} 9 6 10 # Get pjsua definitions 11 %import "output/pjsua.i" 7 %feature("director") PjsuaCallback; 8 %ignore pjsua_config::cb; 9 %extend pjsua_config { 10 void setCb(PjsuaCallback *pjsuaCb) { 11 $self->cb = *PJSUA_CALLBACK_PROXY; 12 setPjsuaCallback(pjsuaCb); 13 } 14 } 12 15 13 %feature("director") PjsuaCallback; 14 %include "callbacks.h" 16 %include <callbacks.h> -
pjproject/branches/projects/jni/pjsip-apps/src/jni/header.i
r4541 r4549 1 %module pjsua 1 /* $Id$ */ 2 2 3 %include "typemaps.i" 3 %module (directors="1") pjsua 4 4 5 %include "enums.swg" 5 %include " arrays_java.i"6 %include "../my_typemaps.i" 6 7 7 8 %header %{ 8 9 #include <pjsua-lib/pjsua.h> 9 extern pjsua_callback* PJSUA_CALLBACK_PROXY;10 10 %} 11 11 12 /* 'void *' shall be handled as byte arrays */ 13 %typemap(jni) void * "void *" 14 %typemap(jtype) void * "byte[]" 15 %typemap(jstype) void * "byte[]" 16 %typemap(javain) void * "$javainput" 17 %typemap(javadirectorin) void * "$jniinput" 18 %typemap(in) void * { $1 = $input; } 19 %typemap(out) void * { $result = $1; } 20 %typemap(javaout) void * { return $jnicall; } 12 /* Strip "pjsua_" prefix from pjsua functions, for better compatibility with 13 * pjsip-jni & csipsimple. 14 */ 15 %rename("%(strip:[pjsua_])s", %$isfunction) ""; 21 16 22 /* Apply output args */ 23 %apply unsigned *INOUT { unsigned *count }; 24 %apply unsigned *OUTPUT { unsigned *tx_level }; 25 %apply unsigned *OUTPUT { unsigned *rx_level }; 26 %apply unsigned *OUTPUT { unsigned *p_tail_ms }; 27 %apply int *OUTPUT { pjsua_acc_id *p_acc_id }; 28 %apply int *OUTPUT { pjsua_call_id *p_call_id }; 29 %apply int *OUTPUT { pjsua_transport_id *p_id }; 30 %apply int *OUTPUT { pjsua_recorder_id *p_id }; 31 %apply int *OUTPUT { pjsua_player_id *p_id }; 32 %apply int *OUTPUT { pjsua_buddy_id *p_buddy_id }; 33 %apply int *OUTPUT { pjsua_conf_port_id *p_id }; 34 %apply int *OUTPUT { int *capture_dev }; 35 %apply int *OUTPUT { int *playback_dev }; 36 %apply int *OUTPUT { pj_stun_nat_type * }; 37 %apply int[ANY] { pjmedia_format_id dec_fmt_id[8] }; 17 /* Map 'void *' simply as long, app can use this "long" as index of its real user data */ 18 %apply long { void * }; 38 19 39 /* Array of pj_str_t */ 20 /* Handle void *[ANY], e.g: pjsip_tx_data::mod_data, pjsip_transaction::mod_data */ 21 //%ignore pjsip_tx_data::mod_data; 22 //%ignore pjsip_transaction::mod_data; 23 %apply long[ANY] { void *[ANY] }; 24 25 /* Map "int*" & "unsigned*" as input & output */ 26 %apply unsigned *INOUT { unsigned * }; 27 %apply int *INOUT { int * }; 28 29 /* Map the following args as input & output */ 30 %apply int *INOUT { pj_stun_nat_type * }; 31 %apply int *INOUT { pjsip_status_code * }; 32 %apply int[ANY] { pjmedia_format_id dec_fmt_id[ANY] }; 33 34 /* Handle array of pj_str_t */ 40 35 JAVA_ARRAYSOFCLASSES(pj_str_t) 41 #ifndef __cplusplus42 /* On C target, pj_str_t::cArrayWrap/Unwrap Java code are missing, this somehow 'fixes' it. */43 JAVA_ARRAYSOFCLASSES(struct pj_str_t)44 #endif45 36 46 /* Array of pj_ssl_cipher in pjsip_tls_setting. Warning: this breaks JAVA_ARRAYS_TYPEMAPS(int)! */ 47 %typemap(out) int[] %{$result = SWIG_JavaArrayOutInt(jenv, (int*)$1, arg1->ciphers_num); %} 48 %apply int[] { pj_ssl_cipher* }; 49 %ignore pjsip_tls_setting::ciphers; 50 %ignore pjsip_tls_setting::ciphers_num; 51 %extend pjsip_tls_setting { 52 void setCiphers(pj_ssl_cipher *ciphers, int num) { 53 int i; 54 $self->ciphers = (pj_ssl_cipher*)calloc(num, sizeof(pj_ssl_cipher)); 55 for (i=0; i<num; ++i) $self->ciphers[i] = ciphers[i]; 56 $self->ciphers_num = num; 57 } 58 pj_ssl_cipher* getCiphers() { 59 return $self->ciphers; 60 } 61 }; 37 /* Handle pointer-to-pointer-to-object as input & output */ 38 MY_JAVA_CLASS_INOUT(pjmedia_port, p_port) 39 MY_JAVA_CLASS_INOUT(pjsip_tx_data, p_tdata) 62 40 41 /* Handle array of pj_ssl_cipher in pjsip_tls_setting. */ 42 MY_JAVA_MEMBER_ARRAY_OF_ENUM(pjsip_tls_setting, pj_ssl_cipher, ciphers, ciphers_num) 63 43 64 /* C++ SWIG target doesn't support nested class (C version does though). 44 /* Handle array of pointer in struct/class member */ 45 MY_JAVA_MEMBER_ARRAY_OF_POINTER(pjsip_regc_cbparam, pjsip_contact_hdr, contact, contact_cnt) 46 MY_JAVA_MEMBER_ARRAY_OF_POINTER(pjmedia_sdp_session, pjmedia_sdp_media, media, media_count) 47 MY_JAVA_MEMBER_ARRAY_OF_POINTER(pjmedia_sdp_media, pjmedia_sdp_bandw, bandw, bandw_count) 48 MY_JAVA_MEMBER_ARRAY_OF_POINTER(pjmedia_sdp_media, pjmedia_sdp_attr, attr, attr_count) 49 50 /* C++ SWIG target doesn't support nested class (C version does though!). 65 51 * This is minimal workaround, ignore nested class as if it is not there. 66 52 * TODO: proper workaround will be moving out inner classes to global scope. … … 72 58 #endif 73 59 74 /* Typemaps for marshalling pjmedia_port ** */ 75 %typemap(jni) pjmedia_port **p_port "jobject" 76 %typemap(jtype) pjmedia_port **p_port "pjmedia_port" 77 %typemap(jstype) pjmedia_port **p_port "pjmedia_port" 78 79 /* Typemaps for pjmedia_port ** as a parameter output type */ 80 %typemap(in) pjmedia_port **p_port (pjmedia_port *ppMediaPort = 0) %{ $1 = &ppMediaPort; %} 81 %typemap(argout) pjmedia_port **p_port { 82 // Give Java proxy the C pointer (of newly created object) 83 jclass clazz = JCALL1(FindClass, jenv, "org/pjsip/pjsua/pjmedia_port"); 84 jfieldID fid = JCALL3(GetFieldID, jenv, clazz, "swigCPtr", "J"); 85 jlong cPtr = 0; 86 *(pjmedia_port **)&cPtr = *$1; 87 JCALL3(SetLongField, jenv, $input, fid, cPtr); 88 } 89 %typemap(javain) pjmedia_port **p_port "$javainput" 90 91 92 /* Strip "pjsua_" prefix from pjsua functions, for better compatibility with 93 * pjsip-jni & csipsimple. 94 */ 95 %rename("%(strip:[pjsua_])s", %$isfunction) ""; 96 97 /* Automatically init pjsua_config::cb to cb proxy via pjsua_config_default() */ 98 /* 1. Hide 'cb' from 'pjsua_config' */ 99 %ignore pjsua_config::cb; 100 /* 2. Ignore original pjsua_config_default() */ 101 %ignore pjsua_config_default; 102 /* 3. Optional, put back "pjsua_" prefix, if stripping is not preferred */ 103 //%rename(pjsua_config_default) config_default; 104 /* 4. Put custom implementation */ 105 %inline %{ 106 void config_default(pjsua_config *cfg) { 107 pjsua_config_default(cfg); 108 cfg->cb = *PJSUA_CALLBACK_PROXY; 109 } 110 %} 60 %include "../callbacks.i" 111 61 112 62 /* Global constants */ -
pjproject/branches/projects/jni/pjsip-apps/src/jni/hello.java
r4541 r4549 1 /* $Id$ */ 2 1 3 import java.io.BufferedReader; 2 4 import java.io.InputStreamReader; … … 12 14 import org.pjsip.pjsua.pj_str_t; 13 15 import org.pjsip.pjsua.PjsuaCallback; 14 import org.pjsip.pjsua.pjsua_cb;15 16 16 17 class MyPjsuaCallback extends PjsuaCallback { … … 68 69 pjsua_config cfg = new pjsua_config(); 69 70 pjsua.config_default(cfg); 70 /* Setup callback for callback proxy*/71 pjsua_cb.setPjsuaCallback(new MyPjsuaCallback());71 /* Setup callback */ 72 cfg.setCb(new MyPjsuaCallback()); 72 73 status = pjsua.init(cfg, null, null); 73 74 if (status != pjsua.PJ_SUCCESS) { … … 106 107 { 107 108 pj_str_t call_target = pj_str("sip:localhost"); 108 status = pjsua.call_make_call(acc_id[0], call_target, null, null, null, call_id);109 status = pjsua.call_make_call(acc_id[0], call_target, null, 0, null, call_id); 109 110 if (status != pjsua.PJ_SUCCESS) { 110 111 pj_error_exit("Error making call", status); -
pjproject/branches/projects/jni/pjsip-apps/src/jni/swig_gen.py
r4541 r4549 3 3 #!/usr/bin/python 4 4 5 #import re6 import sys #, os, traceback5 import re 6 import sys, os #, traceback 7 7 from collections import OrderedDict 8 8 from pycparser import parse_file, c_ast, c_generator … … 57 57 'pjmedia_transport', 58 58 'pjsua_media_transport', 59 'pjsua_callback' 59 'pjsua_callback', 60 'pjmedia_stream' 60 61 ] 61 62 62 63 FORCE_EXPORT = [ 64 'pjsip_event', 65 'pjsip_transaction', 66 'pjmedia_sdp_session', 63 67 #'pj_str' # plain export result doesn't work! 64 68 ] … … 101 105 if not self.deps_frozen: 102 106 for name in n.names: self._add_dep(name) 103 return ' '.join(n.names)107 return super(MyGen, self).visit_IdentifierType(n) 104 108 105 109 def _check_video(self, name): … … 129 133 return 130 134 131 if name in FORCE_STRUCT_AS_OPAQUE :135 if name in FORCE_STRUCT_AS_OPAQUE and (not name == 'pjsua_callback'): 132 136 self.deps.append(name) 133 137 return … … 171 175 return code 172 176 177 def _gen_pjsua_callback(self): 178 # init 179 cbclass = '' 180 cbproxy = '' 181 cbdef = [] 182 183 n = self.nodes['pjsua_callback'][0] 184 raw_lines = self._print_node(n).splitlines() 185 for idx, line in enumerate(raw_lines): 186 if idx in [0, 1, len(raw_lines)-1]: continue 187 fstrs = [] 188 # pointer to function type format 189 m = re.match('\s+(.*)\(\*(.*)\)(\(.*\));', line) 190 if m: 191 fstrs = [m.group(1).strip(), m.group(2), m.group(3)] 192 else: 193 # typedef'd format 194 m = re.match('\s+(.*)\s+(.*);', line) 195 if (not m) or (not self.nodes.has_key(m.group(1))): 196 cbdef.append(' NULL') 197 continue 198 fstrs = ['', m.group(2), ''] 199 n = self.nodes[m.group(1)][0] 200 raw = self._print_node(n) 201 m = re.match('typedef\s+(.*)\(\*(.*)\)(\(.*\));', raw) 202 if not m: 203 cbdef.append(' NULL') 204 continue 205 fstrs[0] = m.group(1).strip() 206 fstrs[2] = m.group(3) 207 208 cbclass += ' virtual ' + ' '.join(fstrs) 209 if fstrs[0] == 'void': 210 cbclass += ' {}\n' 211 elif fstrs[1] == 'on_create_media_transport': 212 cbclass += ' { return base_tp; }\n' 213 elif fstrs[1] == 'on_call_redirected': 214 cbclass += ' { return PJSIP_REDIRECT_STOP; }\n' 215 else: 216 cbclass += ' { return 0; }\n' 217 218 cbproxy += 'static ' + ' '.join(fstrs) 219 params = re.findall('(\w+)[,\)]', fstrs[2]) 220 if fstrs[0] == 'void': 221 cbproxy += ' { cb->'+fstrs[1]+'('+','.join(params)+'); }\n' 222 else: 223 cbproxy += ' { return cb->'+fstrs[1]+'('+','.join(params)+'); }\n' 224 225 cbdef.append(' &' + fstrs[1]) 226 227 # trail 228 229 return [cbclass, cbproxy, ',\n'.join(cbdef)+'\n'] 230 173 231 # Generate code from the specified node. 174 232 def _print_node(self, node): … … 189 247 s += self._process_opaque_struct(name, ss) 190 248 return s 249 250 def write_pjsua_callback(self, outdir): 251 cb = self._gen_pjsua_callback() 252 253 fout = open(outdir+'/callbacks.h', 'w+') 254 fin = open('callbacks.h.template', 'r') 255 for line in fin: 256 if line.find(r'$PJSUA_CALLBACK_CLASS$') >= 0: 257 fout.write(cb[0]) 258 else: 259 fout.write(line) 260 fin.close() 261 fout.close() 262 263 fout = open(outdir+'/callbacks.c', 'w+') 264 fin = open('callbacks.c.template', 'r') 265 for line in fin: 266 if line.find(r'$PJSUA_CALLBACK_PROXY$') >= 0: 267 fout.write(cb[1]) 268 elif line.find(r'$PJSUA_CALLBACK_DEF$') >= 0: 269 fout.write(cb[2]) 270 else: 271 fout.write(line) 272 fin.close() 273 fout.close() 191 274 192 275 # MAIN … … 205 288 # print d 206 289 290 sys.argv.pop(0) 291 outdir = sys.argv.pop() if len(sys.argv) else 'output' 292 mygen.write_pjsua_callback(outdir) 293 207 294 s = mygen.go() 208 295 print s 296 -
pjproject/branches/projects/jni/pjsip/include/pjsip-ua/sip_regc.h
r4173 r4549 61 61 * has finished. 62 62 */ 63 struct pjsip_regc_cbparam63 typedef struct pjsip_regc_cbparam 64 64 { 65 65 pjsip_regc *regc; /**< Client registration structure. */ … … 78 78 int contact_cnt;/**<Number of contacts in response. */ 79 79 pjsip_contact_hdr *contact[PJSIP_REGC_MAX_CONTACT]; /**< Contacts. */ 80 } ;80 } pjsip_regc_cbparam; 81 81 82 82 83 83 /** Type declaration for callback to receive registration result. */ 84 typedef void pjsip_regc_cb( structpjsip_regc_cbparam *param);84 typedef void pjsip_regc_cb(pjsip_regc_cbparam *param); 85 85 86 86 /** -
pjproject/branches/projects/jni/pjsip/include/pjsua-lib/pjsua.h
r4534 r4549 473 473 typedef struct pjsua_reg_info 474 474 { 475 struct pjsip_regc_cbparam *cbparam;/**< Parameters returned by476 475 pjsip_regc_cbparam *cbparam; /**< Parameters returned by 476 registration callback. */ 477 477 } pjsua_reg_info; 478 478
Note: See TracChangeset
for help on using the changeset viewer.