]> sjero.net Git - linphone/blob - coreapi/linphonecore_jni.cc
Include linphonecore_jni.h to check validity of JNI at compilation time.
[linphone] / coreapi / linphonecore_jni.cc
1 /*
2 linphonecore_jni.cc
3 Copyright (C) 2010  Belledonne Communications, Grenoble, France
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18  */
19 #include <jni.h>
20 #include "linphonecore_jni.h"
21 #include "linphonecore_utils.h"
22 #include <ortp/zrtp.h>
23
24 #ifdef TUNNEL_ENABLED
25 #include "linphone_tunnel.h"
26 #endif
27
28 extern "C" {
29 #include "mediastreamer2/mediastream.h"
30 }
31 #include "mediastreamer2/msjava.h"
32 #include "private.h"
33 #include <cpu-features.h>
34
35 #ifdef ANDROID
36 #include <android/log.h>
37 extern "C" void libmsilbc_init();
38 #ifdef HAVE_X264
39 extern "C" void libmsx264_init();
40 #endif
41 #ifdef HAVE_AMR
42 extern "C" void libmsamr_init();
43 #endif
44 #ifdef HAVE_SILK
45 extern "C" void libmssilk_init();
46 #endif
47 #ifdef HAVE_G729
48 extern "C" void libmsbcg729_init();
49 #endif
50 #endif /*ANDROID*/
51
52 static JavaVM *jvm=0;
53
54 #ifdef ANDROID
55 static void linphone_android_log_handler(OrtpLogLevel lev, const char *fmt, va_list args){
56         int prio;
57         char str[4096];
58         char *current;
59         char *next;
60         switch(lev){
61         case ORTP_DEBUG:        prio = ANDROID_LOG_DEBUG;       break;
62         case ORTP_MESSAGE:      prio = ANDROID_LOG_INFO;        break;
63         case ORTP_WARNING:      prio = ANDROID_LOG_WARN;        break;
64         case ORTP_ERROR:        prio = ANDROID_LOG_ERROR;       break;
65         case ORTP_FATAL:        prio = ANDROID_LOG_FATAL;       break;
66         default:                prio = ANDROID_LOG_DEFAULT;     break;
67         }
68         vsnprintf(str, sizeof(str) - 1, fmt, args);
69         str[sizeof(str) - 1] = '\0';
70         if (strlen(str) < 512) {
71                 __android_log_write(prio, LOG_DOMAIN, str);
72         } else {
73                 current = str;
74                 while ((next = strchr(current, '\n')) != NULL) {
75                         *next = '\0';
76                         __android_log_write(prio, LOG_DOMAIN, current);
77                         current = next + 1;
78                 }
79                 __android_log_write(prio, LOG_DOMAIN, current);
80         }
81 }
82
83 int dumbMethodForAllowingUsageOfCpuFeaturesFromStaticLibMediastream() {
84         return (android_getCpuFamily() == ANDROID_CPU_FAMILY_ARM && (android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON) != 0);
85 }
86 #endif /*ANDROID*/
87
88 JNIEXPORT jint JNICALL  JNI_OnLoad(JavaVM *ajvm, void *reserved)
89 {
90 #ifdef ANDROID
91         ms_set_jvm(ajvm);
92 #endif /*ANDROID*/
93         jvm=ajvm;
94         return JNI_VERSION_1_2;
95 }
96
97
98 //LinphoneFactory
99 extern "C" void Java_org_linphone_core_LinphoneCoreFactoryImpl_setDebugMode(JNIEnv*  env
100                 ,jobject  thiz
101                 ,jboolean isDebug) {
102         if (isDebug) {
103                 linphone_core_enable_logs_with_cb(linphone_android_log_handler);
104         } else {
105                 linphone_core_disable_logs();
106         }
107 }
108 // LinphoneCore
109
110 class LinphoneCoreData {
111 public:
112         LinphoneCoreData(JNIEnv*  env, jobject lc,jobject alistener, jobject auserdata) {
113
114                 core = env->NewGlobalRef(lc);
115                 listener = env->NewGlobalRef(alistener);
116                 userdata = auserdata?env->NewGlobalRef(auserdata):0;
117                 memset(&vTable,0,sizeof(vTable));
118                 vTable.show = showInterfaceCb;
119                 vTable.auth_info_requested = authInfoRequested;
120                 vTable.display_status = displayStatusCb;
121                 vTable.display_message = displayMessageCb;
122                 vTable.display_warning = displayMessageCb;
123                 vTable.global_state_changed = globalStateChange;
124                 vTable.registration_state_changed = registrationStateChange;
125                 vTable.call_state_changed = callStateChange;
126                 vTable.call_encryption_changed = callEncryptionChange;
127                 vTable.text_received = text_received;
128                 vTable.message_received = message_received;
129                 vTable.dtmf_received = dtmf_received;
130                 vTable.new_subscription_request = new_subscription_request;
131                 vTable.notify_presence_recv = notify_presence_recv;
132                 vTable.call_stats_updated = callStatsUpdated;
133
134                 listenerClass = (jclass)env->NewGlobalRef(env->GetObjectClass( alistener));
135
136                 /*displayStatus(LinphoneCore lc,String message);*/
137                 displayStatusId = env->GetMethodID(listenerClass,"displayStatus","(Lorg/linphone/core/LinphoneCore;Ljava/lang/String;)V");
138
139                 /*void generalState(LinphoneCore lc,int state); */
140                 globalStateId = env->GetMethodID(listenerClass,"globalState","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCore$GlobalState;Ljava/lang/String;)V");
141                 globalStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCore$GlobalState"));
142                 globalStateFromIntId = env->GetStaticMethodID(globalStateClass,"fromInt","(I)Lorg/linphone/core/LinphoneCore$GlobalState;");
143
144                 /*registrationState(LinphoneCore lc, LinphoneProxyConfig cfg, LinphoneCore.RegistrationState cstate, String smessage);*/
145                 registrationStateId = env->GetMethodID(listenerClass,"registrationState","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneProxyConfig;Lorg/linphone/core/LinphoneCore$RegistrationState;Ljava/lang/String;)V");
146                 registrationStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCore$RegistrationState"));
147                 registrationStateFromIntId = env->GetStaticMethodID(registrationStateClass,"fromInt","(I)Lorg/linphone/core/LinphoneCore$RegistrationState;");
148
149                 /*callState(LinphoneCore lc, LinphoneCall call, LinphoneCall.State cstate,String message);*/
150                 callStateId = env->GetMethodID(listenerClass,"callState","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCall;Lorg/linphone/core/LinphoneCall$State;Ljava/lang/String;)V");
151                 callStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCall$State"));
152                 callStateFromIntId = env->GetStaticMethodID(callStateClass,"fromInt","(I)Lorg/linphone/core/LinphoneCall$State;");
153
154                 /*callStatsUpdated(LinphoneCore lc, LinphoneCall call, LinphoneCallStats stats);*/
155                 callStatsUpdatedId = env->GetMethodID(listenerClass, "callStatsUpdated", "(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCall;Lorg/linphone/core/LinphoneCallStats;)V");
156
157                 chatMessageStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneChatMessage$State"));
158                 chatMessageStateFromIntId = env->GetStaticMethodID(chatMessageStateClass,"fromInt","(I)Lorg/linphone/core/LinphoneChatMessage$State;");
159
160                 /*callEncryption(LinphoneCore lc, LinphoneCall call, boolean encrypted,String auth_token);*/
161                 callEncryptionChangedId=env->GetMethodID(listenerClass,"callEncryptionChanged","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCall;ZLjava/lang/String;)V");
162
163                 /*void ecCalibrationStatus(LinphoneCore.EcCalibratorStatus status, int delay_ms, Object data);*/
164                 ecCalibrationStatusId = env->GetMethodID(listenerClass,"ecCalibrationStatus","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCore$EcCalibratorStatus;ILjava/lang/Object;)V");
165                 ecCalibratorStatusClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCore$EcCalibratorStatus"));
166                 ecCalibratorStatusFromIntId = env->GetStaticMethodID(ecCalibratorStatusClass,"fromInt","(I)Lorg/linphone/core/LinphoneCore$EcCalibratorStatus;");
167
168                 /*void newSubscriptionRequest(LinphoneCore lc, LinphoneFriend lf, String url)*/
169                 newSubscriptionRequestId = env->GetMethodID(listenerClass,"newSubscriptionRequest","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneFriend;Ljava/lang/String;)V");
170
171                 /*void notifyPresenceReceived(LinphoneCore lc, LinphoneFriend lf);*/
172                 notifyPresenceReceivedId = env->GetMethodID(listenerClass,"notifyPresenceReceived","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneFriend;)V");
173
174                 /*void textReceived(LinphoneCore lc, LinphoneChatRoom cr,LinphoneAddress from,String message);*/
175                 textReceivedId = env->GetMethodID(listenerClass,"textReceived","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneChatRoom;Lorg/linphone/core/LinphoneAddress;Ljava/lang/String;)V");
176                 messageReceivedId = env->GetMethodID(listenerClass,"messageReceived","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneChatRoom;Lorg/linphone/core/LinphoneChatMessage;)V");
177                 dtmfReceivedId = env->GetMethodID(listenerClass,"dtmfReceived","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCall;I)V");
178
179                 proxyClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneProxyConfigImpl"));
180                 proxyCtrId = env->GetMethodID(proxyClass,"<init>", "(J)V");
181
182                 callClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCallImpl"));
183                 callCtrId = env->GetMethodID(callClass,"<init>", "(J)V");
184
185                 chatMessageClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneChatMessageImpl"));
186                 if (chatMessageClass) chatMessageCtrId = env->GetMethodID(chatMessageClass,"<init>", "(J)V");
187
188                 chatRoomClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneChatRoomImpl"));
189                 chatRoomCtrId = env->GetMethodID(chatRoomClass,"<init>", "(J)V");
190
191                 friendClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneFriendImpl"));;
192                 friendCtrId =env->GetMethodID(friendClass,"<init>", "(J)V");
193
194                 addressClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneAddressImpl"));
195                 addressCtrId =env->GetMethodID(addressClass,"<init>", "(J)V");
196
197                 callStatsClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCallStatsImpl"));
198                 callStatsId = env->GetMethodID(callStatsClass, "<init>", "(JJ)V");
199                 callSetAudioStatsId = env->GetMethodID(callClass, "setAudioStats", "(Lorg/linphone/core/LinphoneCallStats;)V");
200                 callSetVideoStatsId = env->GetMethodID(callClass, "setVideoStats", "(Lorg/linphone/core/LinphoneCallStats;)V");
201         }
202
203         ~LinphoneCoreData() {
204                 JNIEnv *env = 0;
205                 jvm->AttachCurrentThread(&env,NULL);
206                 env->DeleteGlobalRef(core);
207                 env->DeleteGlobalRef(listener);
208                 if (userdata) env->DeleteGlobalRef(userdata);
209                 env->DeleteGlobalRef(listenerClass);
210                 env->DeleteGlobalRef(globalStateClass);
211                 env->DeleteGlobalRef(registrationStateClass);
212                 env->DeleteGlobalRef(callStateClass);
213                 env->DeleteGlobalRef(callStatsClass);
214                 env->DeleteGlobalRef(chatMessageStateClass);
215                 env->DeleteGlobalRef(proxyClass);
216                 env->DeleteGlobalRef(callClass);
217                 env->DeleteGlobalRef(chatMessageClass);
218                 env->DeleteGlobalRef(chatRoomClass);
219                 env->DeleteGlobalRef(friendClass);
220
221         }
222         jobject core;
223         jobject listener;
224         jobject userdata;
225
226         jclass listenerClass;
227         jmethodID displayStatusId;
228         jmethodID newSubscriptionRequestId;
229         jmethodID notifyPresenceReceivedId;
230         jmethodID textReceivedId;
231         jmethodID messageReceivedId;
232         jmethodID dtmfReceivedId;
233         jmethodID callStatsUpdatedId;
234
235         jclass globalStateClass;
236         jmethodID globalStateId;
237         jmethodID globalStateFromIntId;
238
239         jclass registrationStateClass;
240         jmethodID registrationStateId;
241         jmethodID registrationStateFromIntId;
242
243         jclass callStateClass;
244         jmethodID callStateId;
245         jmethodID callStateFromIntId;
246
247         jclass callStatsClass;
248         jmethodID callStatsId;
249         jmethodID callSetAudioStatsId;
250         jmethodID callSetVideoStatsId;
251
252         jclass chatMessageStateClass;
253         jmethodID chatMessageStateFromIntId;
254
255         jmethodID callEncryptionChangedId;
256
257         jclass ecCalibratorStatusClass;
258         jmethodID ecCalibrationStatusId;
259         jmethodID ecCalibratorStatusFromIntId;
260
261         jclass proxyClass;
262         jmethodID proxyCtrId;
263
264         jclass callClass;
265         jmethodID callCtrId;
266
267         jclass chatMessageClass;
268         jmethodID chatMessageCtrId;
269
270         jclass chatRoomClass;
271         jmethodID chatRoomCtrId;
272
273         jclass friendClass;
274         jmethodID friendCtrId;
275
276         jclass addressClass;
277         jmethodID addressCtrId;
278
279         LinphoneCoreVTable vTable;
280
281         static void showInterfaceCb(LinphoneCore *lc) {
282
283         }
284         static void byeReceivedCb(LinphoneCore *lc, const char *from) {
285
286         }
287         static void displayStatusCb(LinphoneCore *lc, const char *message) {
288                 JNIEnv *env = 0;
289                 jint result = jvm->AttachCurrentThread(&env,NULL);
290                 if (result != 0) {
291                         ms_error("cannot attach VM\n");
292                         return;
293                 }
294                 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
295                 env->CallVoidMethod(lcData->listener,lcData->displayStatusId,lcData->core,message ? env->NewStringUTF(message) : NULL);
296         }
297         static void displayMessageCb(LinphoneCore *lc, const char *message) {
298
299         }
300         static void authInfoRequested(LinphoneCore *lc, const char *realm, const char *username) {
301
302         }
303         static void globalStateChange(LinphoneCore *lc, LinphoneGlobalState gstate,const char* message) {
304                 JNIEnv *env = 0;
305                 jint result = jvm->AttachCurrentThread(&env,NULL);
306                 if (result != 0) {
307                         ms_error("cannot attach VM\n");
308                         return;
309                 }
310                 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
311                 env->CallVoidMethod(lcData->listener
312                                                         ,lcData->globalStateId
313                                                         ,lcData->core
314                                                         ,env->CallStaticObjectMethod(lcData->globalStateClass,lcData->globalStateFromIntId,(jint)gstate),
315                                                         message ? env->NewStringUTF(message) : NULL);
316         }
317         static void registrationStateChange(LinphoneCore *lc, LinphoneProxyConfig* proxy,LinphoneRegistrationState state,const char* message) {
318                 JNIEnv *env = 0;
319                 jint result = jvm->AttachCurrentThread(&env,NULL);
320                 if (result != 0) {
321                         ms_error("cannot attach VM\n");
322                         return;
323                 }
324                 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
325                 env->CallVoidMethod(lcData->listener
326                                                         ,lcData->registrationStateId
327                                                         ,lcData->core
328                                                         ,env->NewObject(lcData->proxyClass,lcData->proxyCtrId,(jlong)proxy)
329                                                         ,env->CallStaticObjectMethod(lcData->registrationStateClass,lcData->registrationStateFromIntId,(jint)state),
330                                                         message ? env->NewStringUTF(message) : NULL);
331         }
332         jobject getCall(JNIEnv *env , LinphoneCall *call){
333                 jobject jobj=0;
334
335                 if (call!=NULL){
336                         void *up=linphone_call_get_user_pointer(call);
337                         
338                         if (up==NULL){
339                                 jobj=env->NewObject(callClass,callCtrId,(jlong)call);
340                                 jobj=env->NewGlobalRef(jobj);
341                                 linphone_call_set_user_pointer(call,(void*)jobj);
342                                 linphone_call_ref(call);
343                         }else{
344                                 jobj=(jobject)up;
345                         }
346                 }
347                 return jobj;
348         }
349
350         static void callStateChange(LinphoneCore *lc, LinphoneCall* call,LinphoneCallState state,const char* message) {
351                 JNIEnv *env = 0;
352                 jint result = jvm->AttachCurrentThread(&env,NULL);
353                 jobject jcall;
354                 if (result != 0) {
355                         ms_error("cannot attach VM\n");
356                         return;
357                 }
358                 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
359                 env->CallVoidMethod(lcData->listener
360                                                         ,lcData->callStateId
361                                                         ,lcData->core
362                                                         ,(jcall=lcData->getCall(env,call))
363                                                         ,env->CallStaticObjectMethod(lcData->callStateClass,lcData->callStateFromIntId,(jint)state),
364                                                         message ? env->NewStringUTF(message) : NULL);
365                 if (state==LinphoneCallReleased){
366                         linphone_call_set_user_pointer(call,NULL);
367                         env->DeleteGlobalRef(jcall);
368                 }
369         }
370         static void callEncryptionChange(LinphoneCore *lc, LinphoneCall* call, bool_t encrypted,const char* authentication_token) {
371                 JNIEnv *env = 0;
372                 jint result = jvm->AttachCurrentThread(&env,NULL);
373                 if (result != 0) {
374                         ms_error("cannot attach VM\n");
375                         return;
376                 }
377                 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
378                 env->CallVoidMethod(lcData->listener
379                                                         ,lcData->callEncryptionChangedId
380                                                         ,lcData->core
381                                                         ,lcData->getCall(env,call)
382                                                         ,encrypted
383                                                         ,authentication_token ? env->NewStringUTF(authentication_token) : NULL);
384         }
385         static void notify_presence_recv (LinphoneCore *lc,  LinphoneFriend *my_friend) {
386                 JNIEnv *env = 0;
387                 jint result = jvm->AttachCurrentThread(&env,NULL);
388                 if (result != 0) {
389                         ms_error("cannot attach VM\n");
390                         return;
391                 }
392                 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
393                 env->CallVoidMethod(lcData->listener
394                                                         ,lcData->notifyPresenceReceivedId
395                                                         ,lcData->core
396                                                         ,env->NewObject(lcData->friendClass,lcData->friendCtrId,(jlong)my_friend));
397         }
398         static void new_subscription_request (LinphoneCore *lc,  LinphoneFriend *my_friend, const char* url) {
399                 JNIEnv *env = 0;
400                 jint result = jvm->AttachCurrentThread(&env,NULL);
401                 if (result != 0) {
402                         ms_error("cannot attach VM\n");
403                         return;
404                 }
405                 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
406                 env->CallVoidMethod(lcData->listener
407                                                         ,lcData->newSubscriptionRequestId
408                                                         ,lcData->core
409                                                         ,env->NewObject(lcData->friendClass,lcData->friendCtrId,(jlong)my_friend)
410                                                         ,url ? env->NewStringUTF(url) : NULL);
411         }
412         static void dtmf_received(LinphoneCore *lc, LinphoneCall *call, int dtmf) {
413                 JNIEnv *env = 0;
414                 jint result = jvm->AttachCurrentThread(&env,NULL);
415                 if (result != 0) {
416                         ms_error("cannot attach VM\n");
417                         return;
418                 }
419                 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
420                 env->CallVoidMethod(lcData->listener
421                                                         ,lcData->dtmfReceivedId
422                                                         ,lcData->core
423                                                         ,lcData->getCall(env,call)
424                                                         ,dtmf);
425         }
426         static void text_received(LinphoneCore *lc, LinphoneChatRoom *room, const LinphoneAddress *from, const char *message) {
427                 JNIEnv *env = 0;
428                 jint result = jvm->AttachCurrentThread(&env,NULL);
429                 if (result != 0) {
430                         ms_error("cannot attach VM\n");
431                         return;
432                 }
433                 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
434                 env->CallVoidMethod(lcData->listener
435                                                         ,lcData->textReceivedId
436                                                         ,lcData->core
437                                                         ,env->NewObject(lcData->chatRoomClass,lcData->chatRoomCtrId,(jlong)room)
438                                                         ,env->NewObject(lcData->addressClass,lcData->addressCtrId,(jlong)from)
439                                                         ,message ? env->NewStringUTF(message) : NULL);
440         }
441         static void message_received(LinphoneCore *lc, LinphoneChatRoom *room, LinphoneChatMessage *msg) {
442                         JNIEnv *env = 0;
443                         jint result = jvm->AttachCurrentThread(&env,NULL);
444                         if (result != 0) {
445                                 ms_error("cannot attach VM\n");
446                                 return;
447                         }
448                         LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
449                         env->CallVoidMethod(lcData->listener
450                                                                 ,lcData->messageReceivedId
451                                                                 ,lcData->core
452                                                                 ,env->NewObject(lcData->chatRoomClass,lcData->chatRoomCtrId,(jlong)room)
453                                                                 ,env->NewObject(lcData->chatMessageClass,lcData->chatMessageCtrId,(jlong)msg));
454                 }
455         static void ecCalibrationStatus(LinphoneCore *lc, LinphoneEcCalibratorStatus status, int delay_ms, void *data) {
456                 JNIEnv *env = 0;
457                 jint result = jvm->AttachCurrentThread(&env,NULL);
458                 if (result != 0) {
459                         ms_error("cannot attach VM\n");
460                         return;
461                 }
462                 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
463                 env->CallVoidMethod(lcData->listener
464                                                         ,lcData->ecCalibrationStatusId
465                                                         ,lcData->core
466                                                         ,env->CallStaticObjectMethod(lcData->ecCalibratorStatusClass,lcData->ecCalibratorStatusFromIntId,(jint)status)
467                                                         ,delay_ms
468                                                         ,data ? data : NULL);
469                 if (data != NULL &&status !=LinphoneEcCalibratorInProgress ) {
470                         //final state, releasing global ref
471                         env->DeleteGlobalRef((jobject)data);
472                 }
473
474         }
475         static void callStatsUpdated(LinphoneCore *lc, LinphoneCall* call, const LinphoneCallStats *stats) {
476                 JNIEnv *env = 0;
477                 jobject statsobj;
478                 jobject callobj;
479                 jint result = jvm->AttachCurrentThread(&env,NULL);
480                 if (result != 0) {
481                         ms_error("cannot attach VM\n");
482                         return;
483                 }
484                 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
485                 statsobj = env->NewObject(lcData->callStatsClass, lcData->callStatsId, (jlong)call, (jlong)stats);
486                 callobj = lcData->getCall(env, call);
487                 if (stats->type == LINPHONE_CALL_STATS_AUDIO)
488                         env->CallVoidMethod(callobj, lcData->callSetAudioStatsId, statsobj);
489                 else
490                         env->CallVoidMethod(callobj, lcData->callSetVideoStatsId, statsobj);
491                 env->CallVoidMethod(lcData->listener, lcData->callStatsUpdatedId, lcData->core, callobj, statsobj);
492         }
493
494
495 };
496 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_newLinphoneCore(JNIEnv*  env
497                 ,jobject  thiz
498                 ,jobject jlistener
499                 ,jstring juserConfig
500                 ,jstring jfactoryConfig
501                 ,jobject  juserdata){
502
503         const char* userConfig = juserConfig?env->GetStringUTFChars(juserConfig, NULL):NULL;
504         const char* factoryConfig = jfactoryConfig?env->GetStringUTFChars(jfactoryConfig, NULL):NULL;
505         LinphoneCoreData* ldata = new LinphoneCoreData(env,thiz,jlistener,juserdata);
506
507 #ifdef HAVE_ILBC
508         libmsilbc_init(); // requires an fpu
509 #endif
510 #ifdef HAVE_X264
511         libmsx264_init();
512 #endif
513 #ifdef HAVE_AMR
514         libmsamr_init();
515 #endif
516 #ifdef HAVE_SILK
517         libmssilk_init();
518 #endif
519 #ifdef HAVE_G729
520         libmsbcg729_init();
521 #endif
522         jlong nativePtr = (jlong)linphone_core_new(     &ldata->vTable
523                         ,userConfig
524                         ,factoryConfig
525                         ,ldata);
526         //clear auth info list
527         linphone_core_clear_all_auth_info((LinphoneCore*) nativePtr);
528         //clear existing proxy config
529         linphone_core_clear_proxy_config((LinphoneCore*) nativePtr);
530
531         if (userConfig) env->ReleaseStringUTFChars(juserConfig, userConfig);
532         if (factoryConfig) env->ReleaseStringUTFChars(jfactoryConfig, factoryConfig);
533         return nativePtr;
534 }
535 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_delete(JNIEnv*  env
536                 ,jobject  thiz
537                 ,jlong lc) {
538         LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data((LinphoneCore*)lc);
539         linphone_core_destroy((LinphoneCore*)lc);
540         delete lcData;
541 }
542
543 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_clearProxyConfigs(JNIEnv* env, jobject thiz,jlong lc) {
544         linphone_core_clear_proxy_config((LinphoneCore*)lc);
545 }
546
547 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setDefaultProxyConfig(  JNIEnv*  env
548                 ,jobject  thiz
549                 ,jlong lc
550                 ,jlong pc) {
551         linphone_core_set_default_proxy((LinphoneCore*)lc,(LinphoneProxyConfig*)pc);
552 }
553 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_getDefaultProxyConfig( JNIEnv*  env
554                 ,jobject  thiz
555                 ,jlong lc) {
556         LinphoneProxyConfig *config=0;
557         linphone_core_get_default_proxy((LinphoneCore*)lc,&config);
558         return (jlong)config;
559 }
560
561 extern "C" jlongArray Java_org_linphone_core_LinphoneCoreImpl_getProxyConfigList(JNIEnv* env, jobject thiz, jlong lc) {
562         const MSList* proxies = linphone_core_get_proxy_config_list((LinphoneCore*)lc);
563         int proxyCount = ms_list_size(proxies);
564         jlongArray jProxies = env->NewLongArray(proxyCount);
565         jlong *jInternalArray = env->GetLongArrayElements(jProxies, NULL);
566
567         for (int i = 0; i < proxyCount; i++ ) {
568                 jInternalArray[i] = (unsigned long) (proxies->data);
569                 proxies = proxies->next;
570         }
571
572         env->ReleaseLongArrayElements(jProxies, jInternalArray, 0);
573
574         return jProxies;
575 }
576
577 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_addProxyConfig( JNIEnv*  env
578                 ,jobject  thiz
579                 ,jobject jproxyCfg
580                 ,jlong lc
581                 ,jlong pc) {
582         LinphoneProxyConfig* proxy = (LinphoneProxyConfig*)pc;
583         linphone_proxy_config_set_user_data(proxy, env->NewGlobalRef(jproxyCfg));
584
585         return (jint)linphone_core_add_proxy_config((LinphoneCore*)lc,(LinphoneProxyConfig*)pc);
586 }
587
588 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_clearAuthInfos(JNIEnv* env, jobject thiz,jlong lc) {
589         linphone_core_clear_all_auth_info((LinphoneCore*)lc);
590 }
591
592 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_refreshRegisters(JNIEnv* env, jobject thiz,jlong lc) {
593         linphone_core_refresh_registers((LinphoneCore*)lc);
594 }
595
596 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_addAuthInfo(    JNIEnv*  env
597                 ,jobject  thiz
598                 ,jlong lc
599                 ,jlong pc) {
600         linphone_core_add_auth_info((LinphoneCore*)lc,(LinphoneAuthInfo*)pc);
601 }
602 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_iterate(        JNIEnv*  env
603                 ,jobject  thiz
604                 ,jlong lc) {
605         linphone_core_iterate((LinphoneCore*)lc);
606 }
607 extern "C" jobject Java_org_linphone_core_LinphoneCoreImpl_invite(      JNIEnv*  env
608                 ,jobject  thiz
609                 ,jlong lc
610                 ,jstring juri) {
611         const char* uri = env->GetStringUTFChars(juri, NULL);
612         LinphoneCoreData *lcd=(LinphoneCoreData*)linphone_core_get_user_data((LinphoneCore*)lc);
613         LinphoneCall* lCall = linphone_core_invite((LinphoneCore*)lc,uri);
614         env->ReleaseStringUTFChars(juri, uri);
615         return lcd->getCall(env,lCall);
616 }
617 extern "C" jobject Java_org_linphone_core_LinphoneCoreImpl_inviteAddress(       JNIEnv*  env
618                 ,jobject  thiz
619                 ,jlong lc
620                 ,jlong to) {
621         LinphoneCoreData *lcd=(LinphoneCoreData*)linphone_core_get_user_data((LinphoneCore*)lc);
622         return lcd->getCall(env, linphone_core_invite_address((LinphoneCore*)lc,(LinphoneAddress*)to));
623 }
624
625 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_terminateCall(  JNIEnv*  env
626                 ,jobject  thiz
627                 ,jlong lc
628                 ,jlong call) {
629         linphone_core_terminate_call((LinphoneCore*)lc,(LinphoneCall*)call);
630 }
631
632 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_getRemoteAddress(      JNIEnv*  env
633                 ,jobject  thiz
634                 ,jlong lc) {
635         return (jlong)linphone_core_get_current_call_remote_address((LinphoneCore*)lc);
636 }
637 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isInCall(   JNIEnv*  env
638                 ,jobject  thiz
639                 ,jlong lc) {
640
641         return (jboolean)linphone_core_in_call((LinphoneCore*)lc);
642 }
643 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isInComingInvitePending(    JNIEnv*  env
644                 ,jobject  thiz
645                 ,jlong lc) {
646
647         return (jboolean)linphone_core_inc_invite_pending((LinphoneCore*)lc);
648 }
649 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_acceptCall(     JNIEnv*  env
650                 ,jobject  thiz
651                 ,jlong lc
652                 ,jlong call) {
653
654         linphone_core_accept_call((LinphoneCore*)lc,(LinphoneCall*)call);
655 }
656
657 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_acceptCallWithParams(JNIEnv *env,
658                 jobject thiz,
659                 jlong lc,
660                 jlong call,
661                 jlong params){
662         linphone_core_accept_call_with_params((LinphoneCore*)lc,(LinphoneCall*)call, (LinphoneCallParams*)params);
663 }
664
665 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_acceptCallUpdate(JNIEnv *env,
666                 jobject thiz,
667                 jlong lc,
668                 jlong call,
669                 jlong params){
670         linphone_core_accept_call_update((LinphoneCore*)lc,(LinphoneCall*)call, (LinphoneCallParams*)params);
671 }
672
673 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_deferCallUpdate(JNIEnv *env,
674                 jobject thiz,
675                 jlong lc,
676                 jlong call){
677         linphone_core_defer_call_update((LinphoneCore*)lc,(LinphoneCall*)call);
678 }
679
680 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_getCallLog(    JNIEnv*  env
681                 ,jobject  thiz
682                 ,jlong lc
683                 ,jint position) {
684                 return (jlong)ms_list_nth_data(linphone_core_get_call_logs((LinphoneCore*)lc),position);
685 }
686 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getNumberOfCallLogs(    JNIEnv*  env
687                 ,jobject  thiz
688                 ,jlong lc) {
689                 return (jint)ms_list_size(linphone_core_get_call_logs((LinphoneCore*)lc));
690 }
691 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setNetworkStateReachable(       JNIEnv*  env
692                 ,jobject  thiz
693                 ,jlong lc
694                 ,jboolean isReachable) {
695                 linphone_core_set_network_reachable((LinphoneCore*)lc,isReachable);
696 }
697
698 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isNetworkStateReachable(    JNIEnv*  env
699                 ,jobject  thiz
700                 ,jlong lc) {
701                 return (jboolean)linphone_core_is_network_reachable((LinphoneCore*)lc);
702 }
703
704 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setPlaybackGain(        JNIEnv*  env
705                 ,jobject  thiz
706                 ,jlong lc
707                 ,jfloat gain) {
708                 linphone_core_set_playback_gain_db((LinphoneCore*)lc,gain);
709 }
710
711 extern "C" jfloat Java_org_linphone_core_LinphoneCoreImpl_getPlaybackGain(      JNIEnv*  env
712                 ,jobject  thiz
713                 ,jlong lc) {
714                 return (jfloat)linphone_core_get_playback_gain_db((LinphoneCore*)lc);
715 }
716
717 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_muteMic(        JNIEnv*  env
718                 ,jobject  thiz
719                 ,jlong lc
720                 ,jboolean isMuted) {
721                 linphone_core_mute_mic((LinphoneCore*)lc,isMuted);
722 }
723
724 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_interpretUrl(  JNIEnv*  env
725                 ,jobject  thiz
726                 ,jlong lc
727                 ,jstring jurl) {
728         const char* url = env->GetStringUTFChars(jurl, NULL);
729         jlong result = (jlong)linphone_core_interpret_url((LinphoneCore*)lc,url);
730         env->ReleaseStringUTFChars(jurl, url);
731         return result;
732 }
733 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_sendDtmf(       JNIEnv*  env
734                 ,jobject  thiz
735                 ,jlong lc
736                 ,jchar dtmf) {
737         linphone_core_send_dtmf((LinphoneCore*)lc,dtmf);
738 }
739 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_playDtmf(       JNIEnv*  env
740                 ,jobject  thiz
741                 ,jlong lc
742                 ,jchar dtmf
743                 ,jint duration) {
744         linphone_core_play_dtmf((LinphoneCore*)lc,dtmf,duration);
745 }
746 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_stopDtmf(       JNIEnv*  env
747                 ,jobject  thiz
748                 ,jlong lc) {
749         linphone_core_stop_dtmf((LinphoneCore*)lc);
750 }
751
752 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getMissedCallsCount(JNIEnv*  env
753                                                                                                                                                 ,jobject  thiz
754                                                                                                                                                 ,jlong lc) {
755         return (jint)linphone_core_get_missed_calls_count((LinphoneCore*)lc);
756 }
757
758 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_resetMissedCallsCount(JNIEnv*  env
759                                                                                                                                                 ,jobject  thiz
760                                                                                                                                                 ,jlong lc) {
761         linphone_core_reset_missed_calls_count((LinphoneCore*)lc);
762 }
763
764 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_removeCallLog(JNIEnv*  env
765                                                                                                                                                 ,jobject  thiz
766                                                                                                                                                 ,jlong lc, jlong log) {
767         linphone_core_remove_call_log((LinphoneCore*)lc, (LinphoneCallLog*) log);
768 }
769
770 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_clearCallLogs(JNIEnv*  env
771                                                                                                                                                 ,jobject  thiz
772                                                                                                                                                 ,jlong lc) {
773         linphone_core_clear_call_logs((LinphoneCore*)lc);
774 }
775 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isMicMuted( JNIEnv*  env
776                 ,jobject  thiz
777                 ,jlong lc) {
778         return (jboolean)linphone_core_is_mic_muted((LinphoneCore*)lc);
779 }
780 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_findPayloadType(JNIEnv*  env
781                                                                                                                                                         ,jobject  thiz
782                                                                                                                                                         ,jlong lc
783                                                                                                                                                         ,jstring jmime
784                                                                                                                                                         ,jint rate
785                                                                                                                                                         ,jint channels) {
786         const char* mime = env->GetStringUTFChars(jmime, NULL);
787         jlong result = (jlong)linphone_core_find_payload_type((LinphoneCore*)lc,mime,rate,channels);
788         env->ReleaseStringUTFChars(jmime, mime);
789         return result;
790 }
791 extern "C" jlongArray Java_org_linphone_core_LinphoneCoreImpl_listVideoPayloadTypes(JNIEnv*  env
792                                                                                                                                                         ,jobject  thiz
793                                                                                                                                                         ,jlong lc) {
794         const MSList* codecs = linphone_core_get_video_codecs((LinphoneCore*)lc);
795         int codecsCount = ms_list_size(codecs);
796         jlongArray jCodecs = env->NewLongArray(codecsCount);
797         jlong *jInternalArray = env->GetLongArrayElements(jCodecs, NULL);
798
799         for (int i = 0; i < codecsCount; i++ ) {
800                 jInternalArray[i] = (unsigned long) (codecs->data);
801                 codecs = codecs->next;
802         }
803
804         env->ReleaseLongArrayElements(jCodecs, jInternalArray, 0);
805
806         return jCodecs;
807 }
808
809 extern "C" jlongArray Java_org_linphone_core_LinphoneCoreImpl_listAudioPayloadTypes(JNIEnv*  env
810                                                                                                                                                         ,jobject  thiz
811                                                                                                                                                         ,jlong lc) {
812         const MSList* codecs = linphone_core_get_audio_codecs((LinphoneCore*)lc);
813         int codecsCount = ms_list_size(codecs);
814         jlongArray jCodecs = env->NewLongArray(codecsCount);
815         jlong *jInternalArray = env->GetLongArrayElements(jCodecs, NULL);
816
817         for (int i = 0; i < codecsCount; i++ ) {
818                 jInternalArray[i] = (unsigned long) (codecs->data);
819                 codecs = codecs->next;
820         }
821
822         env->ReleaseLongArrayElements(jCodecs, jInternalArray, 0);
823
824         return jCodecs;
825 }
826
827 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_enablePayloadType(JNIEnv*  env
828                                                                                                                                                         ,jobject  thiz
829                                                                                                                                                         ,jlong lc
830                                                                                                                                                         ,jlong pt
831                                                                                                                                                         ,jboolean enable) {
832         return (jint)linphone_core_enable_payload_type((LinphoneCore*)lc,(PayloadType*)pt,enable);
833 }
834 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_enableEchoCancellation(JNIEnv*  env
835                                                                                                                                                         ,jobject  thiz
836                                                                                                                                                         ,jlong lc
837                                                                                                                                                         ,jboolean enable) {
838         linphone_core_enable_echo_cancellation((LinphoneCore*)lc,enable);
839 }
840 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_enableEchoLimiter(JNIEnv*  env
841                                                                                                                                                         ,jobject  thiz
842                                                                                                                                                         ,jlong lc
843                                                                                                                                                         ,jboolean enable) {
844         linphone_core_enable_echo_limiter((LinphoneCore*)lc,enable);
845 }
846 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isEchoCancellationEnabled(JNIEnv*  env
847                                                                                                                                                         ,jobject  thiz
848                                                                                                                                                         ,jlong lc
849                                                                                                                                                         ) {
850         return (jboolean)linphone_core_echo_cancellation_enabled((LinphoneCore*)lc);
851 }
852
853 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isEchoLimiterEnabled(JNIEnv*  env
854                                                                                                                                                         ,jobject  thiz
855                                                                                                                                                         ,jlong lc
856                                                                                                                                                         ) {
857         return (jboolean)linphone_core_echo_limiter_enabled((LinphoneCore*)lc);
858 }
859
860 extern "C" jobject Java_org_linphone_core_LinphoneCoreImpl_getCurrentCall(JNIEnv*  env
861                                                                                                                                                         ,jobject  thiz
862                                                                                                                                                         ,jlong lc
863                                                                                                                                                         ) {
864         LinphoneCoreData *lcdata=(LinphoneCoreData*)linphone_core_get_user_data((LinphoneCore*)lc);
865         
866         return lcdata->getCall(env,linphone_core_get_current_call((LinphoneCore*)lc));
867 }
868 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_addFriend(JNIEnv*  env
869                                                                                                                                                         ,jobject  thiz
870                                                                                                                                                         ,jlong lc
871                                                                                                                                                         ,jlong aFriend
872                                                                                                                                                         ) {
873         linphone_core_add_friend((LinphoneCore*)lc,(LinphoneFriend*)aFriend);
874 }
875 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setPresenceInfo(JNIEnv*  env
876                                                                                                                                                         ,jobject  thiz
877                                                                                                                                                         ,jlong lc
878                                                                                                                                                         ,jint minute_away
879                                                                                                                                                         ,jstring jalternative_contact
880                                                                                                                                                         ,jint status) {
881         const char* alternative_contact = jalternative_contact?env->GetStringUTFChars(jalternative_contact, NULL):NULL;
882         linphone_core_set_presence_info((LinphoneCore*)lc,minute_away,alternative_contact,(LinphoneOnlineStatus)status);
883         if (alternative_contact) env->ReleaseStringUTFChars(jalternative_contact, alternative_contact);
884 }
885
886 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_createChatRoom(JNIEnv*  env
887                                                                                                                                                         ,jobject  thiz
888                                                                                                                                                         ,jlong lc
889                                                                                                                                                         ,jstring jto) {
890
891         const char* to = env->GetStringUTFChars(jto, NULL);
892         LinphoneChatRoom* lResult = linphone_core_create_chat_room((LinphoneCore*)lc,to);
893         env->ReleaseStringUTFChars(jto, to);
894         return (jlong)lResult;
895 }
896
897 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_enableVideo(JNIEnv*  env
898                                                                                                                                                         ,jobject  thiz
899                                                                                                                                                         ,jlong lc
900                                                                                                                                                         ,jboolean vcap_enabled
901                                                                                                                                                         ,jboolean display_enabled) {
902         linphone_core_enable_video((LinphoneCore*)lc, vcap_enabled,display_enabled);
903
904 }
905 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isVideoEnabled(JNIEnv*  env
906                                                                                                                                                         ,jobject  thiz
907                                                                                                                                                         ,jlong lc) {
908         return (jboolean)linphone_core_video_enabled((LinphoneCore*)lc);
909 }
910 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setPlayFile(JNIEnv*  env
911                                                                                                                                                         ,jobject  thiz
912                                                                                                                                                         ,jlong lc
913                                                                                                                                                         ,jstring jpath) {
914         const char* path = jpath?env->GetStringUTFChars(jpath, NULL):NULL;
915         linphone_core_set_play_file((LinphoneCore*)lc,path);
916         if (path) env->ReleaseStringUTFChars(jpath, path);
917 }
918 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setRing(JNIEnv*  env
919                                                                                                                                                         ,jobject  thiz
920                                                                                                                                                         ,jlong lc
921                                                                                                                                                         ,jstring jpath) {
922         const char* path = jpath?env->GetStringUTFChars(jpath, NULL):NULL;
923         linphone_core_set_ring((LinphoneCore*)lc,path);
924         if (path) env->ReleaseStringUTFChars(jpath, path);
925 }
926 extern "C" jstring Java_org_linphone_core_LinphoneCoreImpl_getRing(JNIEnv*  env
927                                                                                                                                                         ,jobject  thiz
928                                                                                                                                                         ,jlong lc
929                                                                                                                                                         ) {
930         const char* path = linphone_core_get_ring((LinphoneCore*)lc);
931         if (path) {
932                 return env->NewStringUTF(path);
933         } else {
934                 return NULL;
935         }
936 }
937 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setRootCA(JNIEnv*  env
938                                                                                                                                                         ,jobject  thiz
939                                                                                                                                                         ,jlong lc
940                                                                                                                                                         ,jstring jpath) {
941         const char* path = jpath?env->GetStringUTFChars(jpath, NULL):NULL;
942         linphone_core_set_root_ca((LinphoneCore*)lc,path);
943         if (path) env->ReleaseStringUTFChars(jpath, path);
944 }
945 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_enableKeepAlive(JNIEnv*  env
946                                                                                                                                 ,jobject  thiz
947                                                                                                                                 ,jlong lc
948                                                                                                                                 ,jboolean enable) {
949         linphone_core_enable_keep_alive((LinphoneCore*)lc,enable);
950
951 }
952 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isKeepAliveEnabled(JNIEnv*  env
953                                                                                                                                 ,jobject  thiz
954                                                                                                                                 ,jlong lc) {
955         return (jboolean)linphone_core_keep_alive_enabled((LinphoneCore*)lc);
956
957 }
958 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_startEchoCalibration(JNIEnv*  env
959                                                                                                                                                                 ,jobject  thiz
960                                                                                                                                                                 ,jlong lc
961                                                                                                                                                                 ,jobject data) {
962         return (jint)linphone_core_start_echo_calibration((LinphoneCore*)lc
963                                                                                                         , LinphoneCoreData::ecCalibrationStatus
964                                                                                                         , data?env->NewGlobalRef(data):NULL);
965
966 }
967
968 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getMediaEncryption(JNIEnv*  env
969                                                                                                                                                         ,jobject  thiz
970                                                                                                                                                         ,jlong lc
971                                                                                                                                                         ) {
972         return (jint)linphone_core_get_media_encryption((LinphoneCore*)lc);
973 }
974
975 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setMediaEncryption(JNIEnv*  env
976                                                                                                                                                         ,jobject  thiz
977                                                                                                                                                         ,jlong lc
978                                                                                                                                                         ,jint menc) {
979         linphone_core_set_media_encryption((LinphoneCore*)lc,(LinphoneMediaEncryption)menc);
980 }
981
982 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_mediaEncryptionSupported(JNIEnv*  env
983                                                                                                                                                         ,jobject  thiz
984                                                                                                                                                         ,jlong lc, jint menc
985                                                                                                                                                         ) {
986         return (jboolean)linphone_core_media_encryption_supported((LinphoneCore*)lc,(LinphoneMediaEncryption)menc);
987 }
988
989 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isMediaEncryptionMandatory(JNIEnv*  env
990                                                                                                                                                         ,jobject  thiz
991                                                                                                                                                         ,jlong lc
992                                                                                                                                                         ) {
993         return (jboolean)linphone_core_is_media_encryption_mandatory((LinphoneCore*)lc);
994 }
995
996 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setMediaEncryptionMandatory(JNIEnv*  env
997                                                                                                                                                         ,jobject  thiz
998                                                                                                                                                         ,jlong lc
999                                                                                                                                                         , jboolean yesno
1000                                                                                                                                                         ) {
1001         linphone_core_set_media_encryption_mandatory((LinphoneCore*)lc, yesno);
1002 }
1003
1004 //ProxyConfig
1005
1006 extern "C" jlong Java_org_linphone_core_LinphoneProxyConfigImpl_newLinphoneProxyConfig(JNIEnv*  env,jobject  thiz) {
1007         LinphoneProxyConfig* proxy = linphone_proxy_config_new();
1008         return  (jlong) proxy;
1009 }
1010
1011 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_delete(JNIEnv*  env,jobject  thiz,jlong ptr) {
1012         linphone_proxy_config_destroy((LinphoneProxyConfig*)ptr);
1013 }
1014 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setIdentity(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jidentity) {
1015         const char* identity = env->GetStringUTFChars(jidentity, NULL);
1016         linphone_proxy_config_set_identity((LinphoneProxyConfig*)proxyCfg,identity);
1017         env->ReleaseStringUTFChars(jidentity, identity);
1018 }
1019 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getIdentity(JNIEnv* env,jobject thiz,jlong proxyCfg) {
1020         const char* identity = linphone_proxy_config_get_identity((LinphoneProxyConfig*)proxyCfg);
1021         if (identity) {
1022                 return env->NewStringUTF(identity);
1023         } else {
1024                 return NULL;
1025         }
1026 }
1027 extern "C" jint Java_org_linphone_core_LinphoneProxyConfigImpl_setProxy(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jproxy) {
1028         const char* proxy = env->GetStringUTFChars(jproxy, NULL);
1029         jint err=linphone_proxy_config_set_server_addr((LinphoneProxyConfig*)proxyCfg,proxy);
1030         env->ReleaseStringUTFChars(jproxy, proxy);
1031         return err;
1032 }
1033 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getProxy(JNIEnv* env,jobject thiz,jlong proxyCfg) {
1034         const char* proxy = linphone_proxy_config_get_addr((LinphoneProxyConfig*)proxyCfg);
1035         if (proxy) {
1036                 return env->NewStringUTF(proxy);
1037         } else {
1038                 return NULL;
1039         }
1040 }
1041 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setContactParameters(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jparams) {
1042         const char* params = env->GetStringUTFChars(jparams, NULL);
1043         linphone_proxy_config_set_contact_parameters((LinphoneProxyConfig*)proxyCfg, params);
1044         env->ReleaseStringUTFChars(jparams, params);
1045 }
1046 extern "C" jint Java_org_linphone_core_LinphoneProxyConfigImpl_setRoute(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jroute) {
1047         if (jroute != NULL) {
1048                 const char* route = env->GetStringUTFChars(jroute, NULL);
1049                 jint err=linphone_proxy_config_set_route((LinphoneProxyConfig*)proxyCfg,route);
1050                 env->ReleaseStringUTFChars(jroute, route);
1051                 return err;
1052         } else {
1053                 return (jint)linphone_proxy_config_set_route((LinphoneProxyConfig*)proxyCfg,NULL);
1054         }
1055 }
1056 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getRoute(JNIEnv* env,jobject thiz,jlong proxyCfg) {
1057         const char* route = linphone_proxy_config_get_route((LinphoneProxyConfig*)proxyCfg);
1058         if (route) {
1059                 return env->NewStringUTF(route);
1060         } else {
1061                 return NULL;
1062         }
1063 }
1064
1065 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_enableRegister(JNIEnv* env,jobject thiz,jlong proxyCfg,jboolean enableRegister) {
1066         linphone_proxy_config_enable_register((LinphoneProxyConfig*)proxyCfg,enableRegister);
1067 }
1068 extern "C" jboolean Java_org_linphone_core_LinphoneProxyConfigImpl_isRegistered(JNIEnv* env,jobject thiz,jlong proxyCfg) {
1069         return (jboolean)linphone_proxy_config_is_registered((LinphoneProxyConfig*)proxyCfg);
1070 }
1071 extern "C" jboolean Java_org_linphone_core_LinphoneProxyConfigImpl_isRegisterEnabled(JNIEnv* env,jobject thiz,jlong proxyCfg) {
1072         return (jboolean)linphone_proxy_config_register_enabled((LinphoneProxyConfig*)proxyCfg);
1073 }
1074 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_edit(JNIEnv* env,jobject thiz,jlong proxyCfg) {
1075         linphone_proxy_config_edit((LinphoneProxyConfig*)proxyCfg);
1076 }
1077 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_done(JNIEnv* env,jobject thiz,jlong proxyCfg) {
1078         linphone_proxy_config_done((LinphoneProxyConfig*)proxyCfg);
1079 }
1080 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_normalizePhoneNumber(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jnumber) {
1081         if (jnumber == 0) {
1082                 ms_error("cannot normalized null number");
1083         }
1084         const char* number = env->GetStringUTFChars(jnumber, NULL);
1085         int len = env->GetStringLength(jnumber);
1086         if (len == 0) {
1087                 ms_warning("cannot normalize empty number");
1088                 return jnumber;
1089         }
1090         char targetBuff[2*len];// returned number can be greater than origin (specially in case of prefix insertion
1091         linphone_proxy_config_normalize_number((LinphoneProxyConfig*)proxyCfg,number,targetBuff,sizeof(targetBuff));
1092         jstring normalizedNumber = env->NewStringUTF(targetBuff);
1093         env->ReleaseStringUTFChars(jnumber, number);
1094         return normalizedNumber;
1095 }
1096 extern "C" jint Java_org_linphone_core_LinphoneProxyConfigImpl_lookupCCCFromIso(JNIEnv* env, jobject thiz, jlong proxyCfg, jstring jiso) {
1097         const char* iso = env->GetStringUTFChars(jiso, NULL);
1098         int prefix = linphone_dial_plan_lookup_ccc_from_iso(iso);
1099         env->ReleaseStringUTFChars(jiso, iso);
1100         return (jint) prefix;
1101 }
1102 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getDomain(JNIEnv* env
1103                                                                                                                                                         ,jobject thiz
1104                                                                                                                                                         ,jlong proxyCfg) {
1105         const char* domain = linphone_proxy_config_get_domain((LinphoneProxyConfig*)proxyCfg);
1106         if (domain) {
1107                 return env->NewStringUTF(domain);
1108         } else {
1109                 return NULL;
1110         }
1111 }
1112 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setDialEscapePlus(JNIEnv* env,jobject thiz,jlong proxyCfg,jboolean value) {
1113         linphone_proxy_config_set_dial_escape_plus((LinphoneProxyConfig*)proxyCfg,value);
1114 }
1115
1116 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setDialPrefix(JNIEnv* env
1117                                                                                                                                         ,jobject thiz
1118                                                                                                                                         ,jlong proxyCfg
1119                                                                                                                                         ,jstring jprefix) {
1120         const char* prefix = env->GetStringUTFChars(jprefix, NULL);
1121         linphone_proxy_config_set_dial_prefix((LinphoneProxyConfig*)proxyCfg,prefix);
1122         env->ReleaseStringUTFChars(jprefix, prefix);
1123 }
1124 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_enablePublish(JNIEnv* env
1125                                                                                                                                                                 ,jobject thiz
1126                                                                                                                                                                 ,jlong proxyCfg
1127                                                                                                                                                                 ,jboolean val) {
1128         linphone_proxy_config_enable_publish((LinphoneProxyConfig*)proxyCfg,val);
1129 }
1130 extern "C" jboolean Java_org_linphone_core_LinphoneProxyConfigImpl_publishEnabled(JNIEnv* env,jobject thiz,jlong proxyCfg) {
1131         return (jboolean)linphone_proxy_config_publish_enabled((LinphoneProxyConfig*)proxyCfg);
1132 }
1133
1134 //Auth Info
1135
1136 extern "C" jlong Java_org_linphone_core_LinphoneAuthInfoImpl_newLinphoneAuthInfo(JNIEnv* env
1137                 , jobject thiz
1138                 , jstring jusername
1139                 , jstring juserid
1140                 , jstring jpassword
1141                 , jstring jha1
1142                 , jstring jrealm) {
1143
1144         const char* username = env->GetStringUTFChars(jusername, NULL);
1145         const char* userid = env->GetStringUTFChars(juserid, NULL);
1146         const char* password = env->GetStringUTFChars(jpassword, NULL);
1147         const char* ha1 = env->GetStringUTFChars(jha1, NULL);
1148         const char* realm = env->GetStringUTFChars(jrealm, NULL);
1149         jlong auth = (jlong)linphone_auth_info_new(username,userid,password,ha1,realm);
1150
1151         env->ReleaseStringUTFChars(jusername, username);
1152         env->ReleaseStringUTFChars(juserid, userid);
1153         env->ReleaseStringUTFChars(jpassword, password);
1154         env->ReleaseStringUTFChars(jha1, ha1);
1155         env->ReleaseStringUTFChars(jrealm, realm);
1156         return auth;
1157
1158 }
1159 extern "C" void Java_org_linphone_core_LinphoneAuthInfoImpl_delete(JNIEnv* env
1160                 , jobject thiz
1161                 , jlong ptr) {
1162         linphone_auth_info_destroy((LinphoneAuthInfo*)ptr);
1163 }
1164
1165 //LinphoneAddress
1166
1167 extern "C" jlong Java_org_linphone_core_LinphoneAddressImpl_newLinphoneAddressImpl(JNIEnv*  env
1168                                                                                                                                                                         ,jobject  thiz
1169                                                                                                                                                                         ,jstring juri
1170                                                                                                                                                                         ,jstring jdisplayName) {
1171         const char* uri = env->GetStringUTFChars(juri, NULL);
1172         LinphoneAddress* address = linphone_address_new(uri);
1173         if (jdisplayName && address) {
1174                 const char* displayName = env->GetStringUTFChars(jdisplayName, NULL);
1175                 linphone_address_set_display_name(address,displayName);
1176                 env->ReleaseStringUTFChars(jdisplayName, displayName);
1177         }
1178         env->ReleaseStringUTFChars(juri, uri);
1179
1180         return  (jlong) address;
1181 }
1182 extern "C" void Java_org_linphone_core_LinphoneAddressImpl_delete(JNIEnv*  env
1183                                                                                                                                                 ,jobject  thiz
1184                                                                                                                                                 ,jlong ptr) {
1185         linphone_address_destroy((LinphoneAddress*)ptr);
1186 }
1187
1188 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_getDisplayName(JNIEnv*  env
1189                                                                                                                                                 ,jobject  thiz
1190                                                                                                                                                 ,jlong ptr) {
1191         const char* displayName = linphone_address_get_display_name((LinphoneAddress*)ptr);
1192         if (displayName) {
1193                 return env->NewStringUTF(displayName);
1194         } else {
1195                 return NULL;
1196         }
1197 }
1198 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_getUserName(JNIEnv*  env
1199                                                                                                                                                 ,jobject  thiz
1200                                                                                                                                                 ,jlong ptr) {
1201         const char* userName = linphone_address_get_username((LinphoneAddress*)ptr);
1202         if (userName) {
1203                 return env->NewStringUTF(userName);
1204         } else {
1205                 return NULL;
1206         }
1207 }
1208 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_getDomain(JNIEnv*  env
1209                                                                                                                                                 ,jobject  thiz
1210                                                                                                                                                 ,jlong ptr) {
1211         const char* domain = linphone_address_get_domain((LinphoneAddress*)ptr);
1212         if (domain) {
1213                 return env->NewStringUTF(domain);
1214         } else {
1215                 return NULL;
1216         }
1217 }
1218
1219 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_toString(JNIEnv*  env
1220                                                                                                                                                 ,jobject  thiz
1221                                                                                                                                                 ,jlong ptr) {
1222         char* uri = linphone_address_as_string((LinphoneAddress*)ptr);
1223         jstring juri =env->NewStringUTF(uri);
1224         ms_free(uri);
1225         return juri;
1226 }
1227 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_toUri(JNIEnv*  env
1228                                                                                                                                                 ,jobject  thiz
1229                                                                                                                                                 ,jlong ptr) {
1230         char* uri = linphone_address_as_string_uri_only((LinphoneAddress*)ptr);
1231         jstring juri =env->NewStringUTF(uri);
1232         ms_free(uri);
1233         return juri;
1234 }
1235 extern "C" void Java_org_linphone_core_LinphoneAddressImpl_setDisplayName(JNIEnv*  env
1236                                                                                                                                                 ,jobject  thiz
1237                                                                                                                                                 ,jlong address
1238                                                                                                                                                 ,jstring jdisplayName) {
1239         const char* displayName = jdisplayName!= NULL?env->GetStringUTFChars(jdisplayName, NULL):NULL;
1240         linphone_address_set_display_name((LinphoneAddress*)address,displayName);
1241         if (displayName != NULL) env->ReleaseStringUTFChars(jdisplayName, displayName);
1242 }
1243
1244
1245 //CallLog
1246 extern "C" jlong Java_org_linphone_core_LinphoneCallLogImpl_getFrom(JNIEnv*  env
1247                                                                                                                                                 ,jobject  thiz
1248                                                                                                                                                 ,jlong ptr) {
1249         return (jlong)((LinphoneCallLog*)ptr)->from;
1250 }
1251 extern "C" jint Java_org_linphone_core_LinphoneCallLogImpl_getStatus(JNIEnv*  env
1252                                                                                                                                                 ,jobject  thiz
1253                                                                                                                                                 ,jlong ptr) {
1254         return (jint)((LinphoneCallLog*)ptr)->status;
1255 }
1256 extern "C" jlong Java_org_linphone_core_LinphoneCallLogImpl_getTo(JNIEnv*  env
1257                                                                                                                                                 ,jobject  thiz
1258                                                                                                                                                 ,jlong ptr) {
1259         return (jlong)((LinphoneCallLog*)ptr)->to;
1260 }
1261 extern "C" jboolean Java_org_linphone_core_LinphoneCallLogImpl_isIncoming(JNIEnv*  env
1262                                                                                                                                                 ,jobject  thiz
1263                                                                                                                                                 ,jlong ptr) {
1264         return ((LinphoneCallLog*)ptr)->dir==LinphoneCallIncoming?JNI_TRUE:JNI_FALSE;
1265 }
1266 extern "C" jstring Java_org_linphone_core_LinphoneCallLogImpl_getStartDate(JNIEnv*  env
1267                                                                                                                                                 ,jobject  thiz
1268                                                                                                                                                 ,jlong ptr) {
1269         jstring jvalue =env->NewStringUTF(((LinphoneCallLog*)ptr)->start_date);
1270         return jvalue;
1271 }
1272 extern "C" jint Java_org_linphone_core_LinphoneCallLogImpl_getCallDuration(JNIEnv*  env
1273                                                                                                                                                 ,jobject  thiz
1274                                                                                                                                                 ,jlong ptr) {
1275         return (jint)((LinphoneCallLog*)ptr)->duration;
1276 }
1277
1278 /* CallStats */
1279 extern "C" jint Java_org_linphone_core_LinphoneCallStatsImpl_getMediaType(JNIEnv *env, jobject thiz, jlong stats_ptr) {
1280         return (jint)((LinphoneCallStats *)stats_ptr)->type;
1281 }
1282 extern "C" jint Java_org_linphone_core_LinphoneCallStatsImpl_getIceState(JNIEnv *env, jobject thiz, jlong stats_ptr) {
1283         return (jint)((LinphoneCallStats *)stats_ptr)->ice_state;
1284 }
1285 extern "C" jfloat Java_org_linphone_core_LinphoneCallStatsImpl_getDownloadBandwidth(JNIEnv *env, jobject thiz, jlong stats_ptr) {
1286         return (jfloat)((LinphoneCallStats *)stats_ptr)->download_bandwidth;
1287 }
1288 extern "C" jfloat Java_org_linphone_core_LinphoneCallStatsImpl_getUploadBandwidth(JNIEnv *env, jobject thiz, jlong stats_ptr) {
1289         return (jfloat)((LinphoneCallStats *)stats_ptr)->upload_bandwidth;
1290 }
1291 extern "C" jfloat Java_org_linphone_core_LinphoneCallStatsImpl_getSenderLossRate(JNIEnv *env, jobject thiz, jlong stats_ptr) {
1292         const LinphoneCallStats *stats = (LinphoneCallStats *)stats_ptr;
1293         const report_block_t *srb = NULL;
1294
1295         if (!stats || !stats->sent_rtcp)
1296                 return (jfloat)0.0;
1297         /* Perform msgpullup() to prevent crashes in rtcp_is_SR() or rtcp_is_RR() if the RTCP packet is composed of several mblk_t structure */
1298         if (stats->sent_rtcp->b_cont != NULL)
1299                 msgpullup(stats->sent_rtcp, -1);
1300         if (rtcp_is_SR(stats->sent_rtcp))
1301                 srb = rtcp_SR_get_report_block(stats->sent_rtcp, 0);
1302         else if (rtcp_is_RR(stats->sent_rtcp))
1303                 srb = rtcp_RR_get_report_block(stats->sent_rtcp, 0);
1304         if (!srb)
1305                 return (jfloat)0.0;
1306         return (jfloat)(100.0 * report_block_get_fraction_lost(srb) / 256.0);
1307 }
1308 extern "C" jfloat Java_org_linphone_core_LinphoneCallStatsImpl_getReceiverLossRate(JNIEnv *env, jobject thiz, jlong stats_ptr) {
1309         const LinphoneCallStats *stats = (LinphoneCallStats *)stats_ptr;
1310         const report_block_t *rrb = NULL;
1311
1312         if (!stats || !stats->received_rtcp)
1313                 return (jfloat)0.0;
1314         /* Perform msgpullup() to prevent crashes in rtcp_is_SR() or rtcp_is_RR() if the RTCP packet is composed of several mblk_t structure */
1315         if (stats->received_rtcp->b_cont != NULL)
1316                 msgpullup(stats->received_rtcp, -1);
1317         if (rtcp_is_RR(stats->received_rtcp))
1318                 rrb = rtcp_RR_get_report_block(stats->received_rtcp, 0);
1319         else if (rtcp_is_SR(stats->received_rtcp))
1320                 rrb = rtcp_SR_get_report_block(stats->received_rtcp, 0);
1321         if (!rrb)
1322                 return (jfloat)0.0;
1323         return (jfloat)(100.0 * report_block_get_fraction_lost(rrb) / 256.0);
1324 }
1325 extern "C" jfloat Java_org_linphone_core_LinphoneCallStatsImpl_getSenderInterarrivalJitter(JNIEnv *env, jobject thiz, jlong stats_ptr, jlong call_ptr) {
1326         LinphoneCallStats *stats = (LinphoneCallStats *)stats_ptr;
1327         const LinphoneCall *call = (LinphoneCall *)call_ptr;
1328         const LinphoneCallParams *params;
1329         const PayloadType *pt;
1330         const report_block_t *srb = NULL;
1331
1332         if (!stats || !call || !stats->sent_rtcp)
1333                 return (jfloat)0.0;
1334         params = linphone_call_get_current_params(call);
1335         if (!params)
1336                 return (jfloat)0.0;
1337         /* Perform msgpullup() to prevent crashes in rtcp_is_SR() or rtcp_is_RR() if the RTCP packet is composed of several mblk_t structure */
1338         if (stats->sent_rtcp->b_cont != NULL)
1339                 msgpullup(stats->sent_rtcp, -1);
1340         if (rtcp_is_SR(stats->sent_rtcp))
1341                 srb = rtcp_SR_get_report_block(stats->sent_rtcp, 0);
1342         else if (rtcp_is_RR(stats->sent_rtcp))
1343                 srb = rtcp_RR_get_report_block(stats->sent_rtcp, 0);
1344         if (!srb)
1345                 return (jfloat)0.0;
1346         if (stats->type == LINPHONE_CALL_STATS_AUDIO)
1347                 pt = linphone_call_params_get_used_audio_codec(params);
1348         else
1349                 pt = linphone_call_params_get_used_video_codec(params);
1350         return (jfloat)((float)report_block_get_interarrival_jitter(srb) / (float)pt->clock_rate);
1351 }
1352 extern "C" jfloat Java_org_linphone_core_LinphoneCallStatsImpl_getReceiverInterarrivalJitter(JNIEnv *env, jobject thiz, jlong stats_ptr, jlong call_ptr) {
1353         LinphoneCallStats *stats = (LinphoneCallStats *)stats_ptr;
1354         const LinphoneCall *call = (LinphoneCall *)call_ptr;
1355         const LinphoneCallParams *params;
1356         const PayloadType *pt;
1357         const report_block_t *rrb = NULL;
1358
1359         if (!stats || !call || !stats->received_rtcp)
1360                 return (jfloat)0.0;
1361         params = linphone_call_get_current_params(call);
1362         if (!params)
1363                 return (jfloat)0.0;
1364         /* Perform msgpullup() to prevent crashes in rtcp_is_SR() or rtcp_is_RR() if the RTCP packet is composed of several mblk_t structure */
1365         if (stats->received_rtcp->b_cont != NULL)
1366                 msgpullup(stats->received_rtcp, -1);
1367         if (rtcp_is_SR(stats->received_rtcp))
1368                 rrb = rtcp_SR_get_report_block(stats->received_rtcp, 0);
1369         else if (rtcp_is_RR(stats->received_rtcp))
1370                 rrb = rtcp_RR_get_report_block(stats->received_rtcp, 0);
1371         if (!rrb)
1372                 return (jfloat)0.0;
1373         if (stats->type == LINPHONE_CALL_STATS_AUDIO)
1374                 pt = linphone_call_params_get_used_audio_codec(params);
1375         else
1376                 pt = linphone_call_params_get_used_video_codec(params);
1377         return (jfloat)((float)report_block_get_interarrival_jitter(rrb) / (float)pt->clock_rate);
1378 }
1379 extern "C" jfloat Java_org_linphone_core_LinphoneCallStatsImpl_getRoundTripDelay(JNIEnv *env, jobject thiz, jlong stats_ptr) {
1380         return (jfloat)((LinphoneCallStats *)stats_ptr)->round_trip_delay;
1381 }
1382 extern "C" jlong Java_org_linphone_core_LinphoneCallStatsImpl_getLatePacketsCumulativeNumber(JNIEnv *env, jobject thiz, jlong stats_ptr, jlong call_ptr) {
1383         LinphoneCallStats *stats = (LinphoneCallStats *)stats_ptr;
1384         LinphoneCall *call = (LinphoneCall *)call_ptr;
1385         rtp_stats_t rtp_stats;
1386
1387         if (!stats || !call)
1388                 return (jlong)0;
1389         memset(&rtp_stats, 0, sizeof(rtp_stats));
1390         if (stats->type == LINPHONE_CALL_STATS_AUDIO)
1391                 audio_stream_get_local_rtp_stats(call->audiostream, &rtp_stats);
1392 #ifdef VIDEO_ENABLED
1393         else
1394                 video_stream_get_local_rtp_stats(call->videostream, &rtp_stats);
1395 #endif
1396         return (jlong)rtp_stats.outoftime;
1397 }
1398 extern "C" jfloat Java_org_linphone_core_LinphoneCallStatsImpl_getJitterBufferSize(JNIEnv *env, jobject thiz, jlong stats_ptr) {
1399         return (jfloat)((LinphoneCallStats *)stats_ptr)->jitter_stats.jitter_buffer_size_ms;
1400 }
1401
1402 /*payloadType*/
1403 extern "C" jstring Java_org_linphone_core_PayloadTypeImpl_toString(JNIEnv*  env,jobject  thiz,jlong ptr) {
1404         PayloadType* pt = (PayloadType*)ptr;
1405         char* value = ms_strdup_printf("[%s] clock [%i], bitrate [%i]"
1406                                                                         ,payload_type_get_mime(pt)
1407                                                                         ,payload_type_get_rate(pt)
1408                                                                         ,payload_type_get_bitrate(pt));
1409         jstring jvalue =env->NewStringUTF(value);
1410         ms_free(value);
1411         return jvalue;
1412 }
1413 extern "C" jstring Java_org_linphone_core_PayloadTypeImpl_getMime(JNIEnv*  env,jobject  thiz,jlong ptr) {
1414         PayloadType* pt = (PayloadType*)ptr;
1415         jstring jvalue =env->NewStringUTF(payload_type_get_mime(pt));
1416         return jvalue;
1417 }
1418 extern "C" jint Java_org_linphone_core_PayloadTypeImpl_getRate(JNIEnv*  env,jobject  thiz, jlong ptr) {
1419         PayloadType* pt = (PayloadType*)ptr;
1420         return (jint)payload_type_get_rate(pt);
1421 }
1422
1423 //LinphoneCall
1424 extern "C" void Java_org_linphone_core_LinphoneCallImpl_finalize(JNIEnv*  env
1425                                                                                                                                                 ,jobject  thiz
1426                                                                                                                                                 ,jlong ptr) {
1427         LinphoneCall *call=(LinphoneCall*)ptr;
1428         linphone_call_unref(call);
1429 }
1430
1431 extern "C" jlong Java_org_linphone_core_LinphoneCallImpl_getCallLog(    JNIEnv*  env
1432                                                                                                                                                 ,jobject  thiz
1433                                                                                                                                                 ,jlong ptr) {
1434         return (jlong)linphone_call_get_call_log((LinphoneCall*)ptr);
1435 }
1436
1437 extern "C" void Java_org_linphone_core_LinphoneCallImpl_takeSnapshot(   JNIEnv*  env
1438                                                                                                                                                 ,jobject  thiz
1439                                                                                                                                                 ,jlong ptr, jstring path) {
1440         const char* filePath = path != NULL ? env->GetStringUTFChars(path, NULL) : NULL;
1441         linphone_call_take_video_snapshot((LinphoneCall*)ptr, filePath);
1442 }
1443
1444 extern "C" void Java_org_linphone_core_LinphoneCallImpl_zoomVideo(              JNIEnv*  env
1445                                                                                                                                                 ,jobject  thiz
1446                                                                                                                                                 ,jlong ptr, jfloat zoomFactor, jfloat cx, jfloat cy) {
1447         linphone_call_zoom_video((LinphoneCall*)ptr, zoomFactor, &cx, &cy);
1448 }
1449
1450 extern "C" jboolean Java_org_linphone_core_LinphoneCallImpl_isIncoming( JNIEnv*  env
1451                                                                                                                                                 ,jobject  thiz
1452                                                                                                                                                 ,jlong ptr) {
1453         return linphone_call_get_dir((LinphoneCall*)ptr)==LinphoneCallIncoming?JNI_TRUE:JNI_FALSE;
1454 }
1455
1456 extern "C" jlong Java_org_linphone_core_LinphoneCallImpl_getRemoteAddress(      JNIEnv*  env
1457                                                                                                                                                 ,jobject  thiz
1458                                                                                                                                                 ,jlong ptr) {
1459         return (jlong)linphone_call_get_remote_address((LinphoneCall*)ptr);
1460 }
1461
1462 extern "C" jint Java_org_linphone_core_LinphoneCallImpl_getState(       JNIEnv*  env
1463                                                                                                                                                 ,jobject  thiz
1464                                                                                                                                                 ,jlong ptr) {
1465         return (jint)linphone_call_get_state((LinphoneCall*)ptr);
1466 }
1467 extern "C" void Java_org_linphone_core_LinphoneCallImpl_enableEchoCancellation( JNIEnv*  env
1468                                                                                                                                                 ,jobject  thiz
1469                                                                                                                                                 ,jlong ptr
1470                                                                                                                                                 ,jboolean value) {
1471         linphone_call_enable_echo_cancellation((LinphoneCall*)ptr,value);
1472 }
1473 extern "C" jboolean Java_org_linphone_core_LinphoneCallImpl_isEchoCancellationEnabled(  JNIEnv*  env
1474                                                                                                                                                 ,jobject  thiz
1475                                                                                                                                                 ,jlong ptr) {
1476         return (jboolean)linphone_call_echo_cancellation_enabled((LinphoneCall*)ptr);
1477 }
1478
1479 extern "C" void Java_org_linphone_core_LinphoneCallImpl_enableEchoLimiter(      JNIEnv*  env
1480                                                                                                                                                 ,jobject  thiz
1481                                                                                                                                                 ,jlong ptr
1482                                                                                                                                                 ,jboolean value) {
1483         linphone_call_enable_echo_limiter((LinphoneCall*)ptr,value);
1484 }
1485 extern "C" jboolean Java_org_linphone_core_LinphoneCallImpl_isEchoLimiterEnabled(       JNIEnv*  env
1486                                                                                                                                                 ,jobject  thiz
1487                                                                                                                                                 ,jlong ptr) {
1488         return (jboolean)linphone_call_echo_limiter_enabled((LinphoneCall*)ptr);
1489 }
1490
1491 extern "C" jobject Java_org_linphone_core_LinphoneCallImpl_getReplacedCall(     JNIEnv*  env
1492                                                                                                                                                 ,jobject  thiz
1493                                                                                                                                                 ,jlong ptr) {
1494         LinphoneCoreData *lcd=(LinphoneCoreData*)linphone_core_get_user_data(linphone_call_get_core((LinphoneCall*)ptr));       
1495         return lcd->getCall(env,linphone_call_get_replaced_call((LinphoneCall*)ptr));
1496 }
1497
1498 extern "C" jfloat Java_org_linphone_core_LinphoneCallImpl_getCurrentQuality(    JNIEnv*  env
1499                                                                                                                                                 ,jobject  thiz
1500                                                                                                                                                 ,jlong ptr) {
1501         return (jfloat)linphone_call_get_current_quality((LinphoneCall*)ptr);
1502 }
1503
1504 extern "C" jfloat Java_org_linphone_core_LinphoneCallImpl_getAverageQuality(    JNIEnv*  env
1505                                                                                                                                                 ,jobject  thiz
1506                                                                                                                                                 ,jlong ptr) {
1507         return (jfloat)linphone_call_get_average_quality((LinphoneCall*)ptr);
1508 }
1509
1510
1511 //LinphoneFriend
1512 extern "C" jlong Java_org_linphone_core_LinphoneFriendImpl_newLinphoneFriend(JNIEnv*  env
1513                                                                                                                                                 ,jobject  thiz
1514                                                                                                                                                 ,jstring jFriendUri) {
1515         LinphoneFriend* lResult;
1516
1517         if (jFriendUri) {
1518                 const char* friendUri = env->GetStringUTFChars(jFriendUri, NULL);
1519                 lResult= linphone_friend_new_with_addr(friendUri);
1520                 env->ReleaseStringUTFChars(jFriendUri, friendUri);
1521         } else {
1522                 lResult = linphone_friend_new();
1523         }
1524         return (jlong)lResult;
1525 }
1526 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_setAddress(JNIEnv*  env
1527                                                                                                                                                 ,jobject  thiz
1528                                                                                                                                                 ,jlong ptr
1529                                                                                                                                                 ,jlong linphoneAddress) {
1530         linphone_friend_set_addr((LinphoneFriend*)ptr,(LinphoneAddress*)linphoneAddress);
1531 }
1532 extern "C" jlong Java_org_linphone_core_LinphoneFriendImpl_getAddress(JNIEnv*  env
1533                                                                                                                                                 ,jobject  thiz
1534                                                                                                                                                 ,jlong ptr) {
1535         return (jlong)linphone_friend_get_address((LinphoneFriend*)ptr);
1536 }
1537 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_setIncSubscribePolicy(JNIEnv*  env
1538                                                                                                                                                 ,jobject  thiz
1539                                                                                                                                                 ,jlong ptr
1540                                                                                                                                                 ,jint policy) {
1541         linphone_friend_set_inc_subscribe_policy((LinphoneFriend*)ptr,(LinphoneSubscribePolicy)policy);
1542 }
1543 extern "C" jint Java_org_linphone_core_LinphoneFriendImpl_getIncSubscribePolicy(JNIEnv*  env
1544                                                                                                                                                 ,jobject  thiz
1545                                                                                                                                                 ,jlong ptr) {
1546         return (jint)linphone_friend_get_inc_subscribe_policy((LinphoneFriend*)ptr);
1547 }
1548 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_enableSubscribes(JNIEnv*  env
1549                                                                                                                                                 ,jobject  thiz
1550                                                                                                                                                 ,jlong ptr
1551                                                                                                                                                 ,jboolean value) {
1552         linphone_friend_enable_subscribes((LinphoneFriend*)ptr,value);
1553 }
1554 extern "C" jboolean Java_org_linphone_core_LinphoneFriendImpl_isSubscribesEnabled(JNIEnv*  env
1555                                                                                                                                                 ,jobject  thiz
1556                                                                                                                                                 ,jlong ptr) {
1557         return (jboolean)linphone_friend_subscribes_enabled((LinphoneFriend*)ptr);
1558 }
1559 extern "C" jint Java_org_linphone_core_LinphoneFriendImpl_getStatus(JNIEnv*  env
1560                                                                                                                                                 ,jobject  thiz
1561                                                                                                                                                 ,jlong ptr) {
1562         return (jint)linphone_friend_get_status((LinphoneFriend*)ptr);
1563 }
1564 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_edit(JNIEnv*  env
1565                                                                                                                                                 ,jobject  thiz
1566                                                                                                                                                 ,jlong ptr) {
1567         return linphone_friend_edit((LinphoneFriend*)ptr);
1568 }
1569 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_done(JNIEnv*  env
1570                                                                                                                                                 ,jobject  thiz
1571                                                                                                                                                 ,jlong ptr) {
1572          linphone_friend_done((LinphoneFriend*)ptr);
1573 }
1574 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_removeFriend(JNIEnv*  env
1575                                                                                                                                                 ,jobject  thiz
1576                                                                                                                                                 ,jlong ptr
1577                                                                                                                                                 ,jlong lf) {
1578         linphone_core_remove_friend((LinphoneCore*)ptr, (LinphoneFriend*)lf);
1579 }
1580 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_getFriendByAddress(JNIEnv*  env
1581                                                                                                                                                 ,jobject  thiz
1582                                                                                                                                                 ,jlong ptr
1583                                                                                                                                                 ,jstring jaddress) {
1584         const char* address = env->GetStringUTFChars(jaddress, NULL);
1585         LinphoneFriend *lf = linphone_core_get_friend_by_address((LinphoneCore*)ptr, address);
1586         env->ReleaseStringUTFChars(jaddress, address);
1587         return (jlong) lf;
1588 }
1589 //LinphoneChatRoom
1590 extern "C" jlong Java_org_linphone_core_LinphoneChatRoomImpl_getPeerAddress(JNIEnv*  env
1591                                                                                                                                                 ,jobject  thiz
1592                                                                                                                                                 ,jlong ptr) {
1593         return (jlong) linphone_chat_room_get_peer_address((LinphoneChatRoom*)ptr);
1594 }
1595 extern "C" jlong Java_org_linphone_core_LinphoneChatRoomImpl_createLinphoneChatMessage(JNIEnv*  env
1596                                                                                                                                                 ,jobject  thiz
1597                                                                                                                                                 ,jlong ptr
1598                                                                                                                                                 ,jstring jmessage) {
1599         const char* message = env->GetStringUTFChars(jmessage, NULL);
1600         LinphoneChatMessage *chatMessage = linphone_chat_room_create_message((LinphoneChatRoom *)ptr, message);
1601         env->ReleaseStringUTFChars(jmessage, message);
1602
1603         return (jlong) chatMessage;
1604 }
1605 extern "C" void Java_org_linphone_core_LinphoneChatMessageImpl_setUserData(JNIEnv*  env
1606                                                                                                                                                 ,jobject  thiz
1607                                                                                                                                                 ,jlong ptr) {
1608         jobject ud = env->NewGlobalRef(thiz);
1609         linphone_chat_message_set_user_data((LinphoneChatMessage*)ptr,(void*) ud);
1610 }
1611 extern "C" jstring Java_org_linphone_core_LinphoneChatMessageImpl_getMessage(JNIEnv*  env
1612                                                                                                                                                 ,jobject  thiz
1613                                                                                                                                                 ,jlong ptr) {
1614         jstring jvalue =env->NewStringUTF(linphone_chat_message_get_message((LinphoneChatMessage*)ptr));
1615         return jvalue;
1616 }
1617 extern "C" jstring Java_org_linphone_core_LinphoneChatMessageImpl_getExternalBodyUrl(JNIEnv*  env
1618                                                                                                                                                 ,jobject  thiz
1619                                                                                                                                                 ,jlong ptr) {
1620         jstring jvalue =env->NewStringUTF(linphone_chat_message_get_external_body_url((LinphoneChatMessage*)ptr));
1621         return jvalue;
1622 }
1623 extern "C" void Java_org_linphone_core_LinphoneChatMessageImpl_setExternalBodyUrl(JNIEnv*  env
1624                                                                                                                                                 ,jobject  thiz
1625                                                                                                                                                 ,jlong ptr
1626                                                                                                                                                 ,jstring jurl) {
1627         const char* url = env->GetStringUTFChars(jurl, NULL);
1628         linphone_chat_message_set_external_body_url((LinphoneChatMessage *)ptr, url);
1629         env->ReleaseStringUTFChars(jurl, url);
1630 }
1631 extern "C" jlong Java_org_linphone_core_LinphoneChatMessageImpl_getFrom(JNIEnv*  env
1632                                                                                                                                                 ,jobject  thiz
1633                                                                                                                                                 ,jlong ptr) {
1634         return (jlong) linphone_chat_message_get_from((LinphoneChatMessage*)ptr);
1635 }
1636 extern "C" jlong Java_org_linphone_core_LinphoneChatMessageImpl_getPeerAddress(JNIEnv*  env
1637                                                                                                                                                 ,jobject  thiz
1638                                                                                                                                                 ,jlong ptr) {
1639         return (jlong) linphone_chat_message_get_peer_address((LinphoneChatMessage*)ptr);
1640 }
1641 extern "C" void Java_org_linphone_core_LinphoneChatRoomImpl_sendMessage(JNIEnv*  env
1642                                                                                                                                                 ,jobject  thiz
1643                                                                                                                                                 ,jlong ptr
1644                                                                                                                                                 ,jstring jmessage) {
1645         const char* message = env->GetStringUTFChars(jmessage, NULL);
1646         linphone_chat_room_send_message((LinphoneChatRoom*)ptr, message);
1647         env->ReleaseStringUTFChars(jmessage, message);
1648 }
1649
1650 static void chat_room_impl_callback(LinphoneChatMessage* msg, LinphoneChatMessageState state, void* ud) {
1651         JNIEnv *env = 0;
1652         jint result = jvm->AttachCurrentThread(&env,NULL);
1653         if (result != 0) {
1654                 ms_error("cannot attach VM\n");
1655                 return;
1656         }
1657
1658         jobject listener = (jobject) ud;
1659         jclass clazz = (jclass) env->GetObjectClass(listener);
1660         jmethodID method = env->GetMethodID(clazz, "onLinphoneChatMessageStateChanged","(Lorg/linphone/core/LinphoneChatMessage;Lorg/linphone/core/LinphoneChatMessage$State;)V");
1661
1662         LinphoneCore *lc = linphone_chat_room_get_lc(linphone_chat_message_get_chat_room(msg));
1663         LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
1664         env->CallVoidMethod(
1665                         listener,
1666                         method,
1667                         (jobject)linphone_chat_message_get_user_data(msg),
1668                         env->CallStaticObjectMethod(lcData->chatMessageStateClass,lcData->chatMessageStateFromIntId,(jint)state));
1669
1670         if (state == LinphoneChatMessageStateDelivered || state == LinphoneChatMessageStateNotDelivered) {
1671                 env->DeleteGlobalRef(listener);
1672         }
1673 }
1674 extern "C" void Java_org_linphone_core_LinphoneChatRoomImpl_sendMessage2(JNIEnv*  env
1675                                                                                                                                                 ,jobject  thiz
1676                                                                                                                                                 ,jlong ptr
1677                                                                                                                                                 ,jlong jmessage
1678                                                                                                                                                 ,jobject jlistener) {
1679         jobject listener = env->NewGlobalRef(jlistener);
1680         linphone_chat_room_send_message2((LinphoneChatRoom*)ptr, (LinphoneChatMessage*)jmessage, chat_room_impl_callback, (void*)listener);
1681 }
1682 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setVideoWindowId(JNIEnv* env
1683                                                                                                                                                 ,jobject thiz
1684                                                                                                                                                 ,jlong lc
1685                                                                                                                                                 ,jobject obj) {
1686         jobject oldWindow = (jobject) linphone_core_get_native_video_window_id((LinphoneCore*)lc);
1687         if (oldWindow != NULL) {
1688                 env->DeleteGlobalRef(oldWindow);
1689         }
1690         if (obj != NULL) {
1691                 obj = env->NewGlobalRef(obj);
1692         }
1693         linphone_core_set_native_video_window_id((LinphoneCore*)lc,(unsigned long)obj);
1694 }
1695
1696 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setPreviewWindowId(JNIEnv* env
1697                                                                                                                                                 ,jobject thiz
1698                                                                                                                                                 ,jlong lc
1699                                                                                                                                                 ,jobject obj) {
1700         jobject oldWindow = (jobject) linphone_core_get_native_preview_window_id((LinphoneCore*)lc);
1701         if (oldWindow != NULL) {
1702                 env->DeleteGlobalRef(oldWindow);
1703         }
1704         if (obj != NULL) {
1705                 obj = env->NewGlobalRef(obj);
1706         }
1707         linphone_core_set_native_preview_window_id((LinphoneCore*)lc,(unsigned long)obj);
1708 }
1709
1710 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setDeviceRotation(JNIEnv* env
1711                                                                                                                                                 ,jobject thiz
1712                                                                                                                                                 ,jlong lc
1713                                                                                                                                                 ,jint rotation) {
1714         linphone_core_set_device_rotation((LinphoneCore*)lc,rotation);
1715 }
1716
1717
1718 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setFirewallPolicy(JNIEnv *env, jobject thiz, jlong lc, jint enum_value){
1719         linphone_core_set_firewall_policy((LinphoneCore*)lc,(LinphoneFirewallPolicy)enum_value);
1720 }
1721
1722 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getFirewallPolicy(JNIEnv *env, jobject thiz, jlong lc){
1723         return (jint)linphone_core_get_firewall_policy((LinphoneCore*)lc);
1724 }
1725
1726 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setStunServer(JNIEnv *env, jobject thiz, jlong lc, jstring jserver){
1727         const char* server = NULL;
1728         if (jserver) server=env->GetStringUTFChars(jserver, NULL);
1729         linphone_core_set_stun_server((LinphoneCore*)lc,server);
1730         if (server) env->ReleaseStringUTFChars(jserver,server);
1731 }
1732
1733 extern "C" jstring Java_org_linphone_core_LinphoneCoreImpl_getStunServer(JNIEnv *env, jobject thiz, jlong lc){
1734         const char *ret= linphone_core_get_stun_server((LinphoneCore*)lc);
1735         if (ret==NULL) return NULL;
1736         jstring jvalue =env->NewStringUTF(ret);
1737         return jvalue;
1738 }
1739
1740 //CallParams
1741
1742 extern "C" jlong Java_org_linphone_core_LinphoneCallParamsImpl_getUsedAudioCodec(JNIEnv *env, jobject thiz, jlong cp) {
1743         return (jlong)linphone_call_params_get_used_audio_codec((LinphoneCallParams *)cp);
1744 }
1745
1746 extern "C" jlong Java_org_linphone_core_LinphoneCallParamsImpl_getUsedVideoCodec(JNIEnv *env, jobject thiz, jlong cp) {
1747         return (jlong)linphone_call_params_get_used_video_codec((LinphoneCallParams *)cp);
1748 }
1749
1750 extern "C" jint Java_org_linphone_core_LinphoneCallParamsImpl_getMediaEncryption(JNIEnv*  env
1751                                                                                                                                                         ,jobject  thiz
1752                                                                                                                                                         ,jlong cp
1753                                                                                                                                                         ) {
1754         return (jint)linphone_call_params_get_media_encryption((LinphoneCallParams*)cp);
1755 }
1756
1757 extern "C" void Java_org_linphone_core_LinphoneCallParamsImpl_setMediaEncryption(JNIEnv*  env
1758                                                                                                                                                         ,jobject  thiz
1759                                                                                                                                                         ,jlong cp
1760                                                                                                                                                         ,jint jmenc) {
1761         linphone_call_params_set_media_encryption((LinphoneCallParams*)cp,(LinphoneMediaEncryption)jmenc);
1762 }
1763
1764 extern "C" void Java_org_linphone_core_LinphoneCallParamsImpl_audioBandwidth(JNIEnv *env, jobject thiz, jlong lcp, jint bw){
1765         linphone_call_params_set_audio_bandwidth_limit((LinphoneCallParams*)lcp, bw);
1766 }
1767
1768 extern "C" void Java_org_linphone_core_LinphoneCallParamsImpl_enableVideo(JNIEnv *env, jobject thiz, jlong lcp, jboolean b){
1769         linphone_call_params_enable_video((LinphoneCallParams*)lcp, b);
1770 }
1771
1772 extern "C" jboolean Java_org_linphone_core_LinphoneCallParamsImpl_getVideoEnabled(JNIEnv *env, jobject thiz, jlong lcp){
1773         return (jboolean)linphone_call_params_video_enabled((LinphoneCallParams*)lcp);
1774 }
1775
1776 extern "C" jboolean Java_org_linphone_core_LinphoneCallParamsImpl_localConferenceMode(JNIEnv *env, jobject thiz, jlong lcp){
1777         return (jboolean)linphone_call_params_local_conference_mode((LinphoneCallParams*)lcp);
1778 }
1779
1780 extern "C" void Java_org_linphone_core_LinphoneCallParamsImpl_destroy(JNIEnv *env, jobject thiz, jlong lc){
1781         return linphone_call_params_destroy((LinphoneCallParams*)lc);
1782 }
1783 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_createDefaultCallParams(JNIEnv *env, jobject thiz, jlong lc){
1784         return (jlong) linphone_core_create_default_call_parameters((LinphoneCore*)lc);
1785 }
1786
1787 extern "C" jlong Java_org_linphone_core_LinphoneCallImpl_getRemoteParams(JNIEnv *env, jobject thiz, jlong lc){
1788         if (linphone_call_get_remote_params((LinphoneCall*)lc) == NULL) {
1789                         return (jlong) 0;
1790         }
1791         return (jlong) linphone_call_params_copy(linphone_call_get_remote_params((LinphoneCall*)lc));
1792 }
1793
1794 extern "C" jlong Java_org_linphone_core_LinphoneCallImpl_getCurrentParamsCopy(JNIEnv *env, jobject thiz, jlong lc){
1795         return (jlong) linphone_call_params_copy(linphone_call_get_current_params((LinphoneCall*)lc));
1796 }
1797
1798 extern "C" void Java_org_linphone_core_LinphoneCallImpl_enableCamera(JNIEnv *env, jobject thiz, jlong lc, jboolean b){
1799         linphone_call_enable_camera((LinphoneCall *)lc, (bool_t) b);
1800 }
1801
1802 extern "C" jboolean Java_org_linphone_core_LinphoneCallImpl_cameraEnabled(JNIEnv *env, jobject thiz, jlong lc){
1803         return (jboolean)linphone_call_camera_enabled((LinphoneCall *)lc);
1804 }
1805
1806 extern "C" jobject Java_org_linphone_core_LinphoneCoreImpl_inviteAddressWithParams(JNIEnv *env, jobject thiz, jlong lc, jlong addr, jlong params){
1807         LinphoneCoreData *lcd=(LinphoneCoreData*)linphone_core_get_user_data((LinphoneCore*)lc);
1808         return  lcd->getCall(env,linphone_core_invite_address_with_params((LinphoneCore *)lc, (const LinphoneAddress *)addr, (const LinphoneCallParams *)params));
1809 }
1810
1811 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_updateAddressWithParams(JNIEnv *env, jobject thiz, jlong lc, jlong call, jlong params){
1812         return (jint) linphone_core_update_call((LinphoneCore *)lc, (LinphoneCall *)call, (LinphoneCallParams *)params);
1813 }
1814
1815 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_updateCall(JNIEnv *env, jobject thiz, jlong lc, jlong call, jlong params){
1816         return (jint) linphone_core_update_call((LinphoneCore *)lc, (LinphoneCall *)call, (const LinphoneCallParams *)params);
1817 }
1818
1819
1820 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setPreferredVideoSize(JNIEnv *env, jobject thiz, jlong lc, jint width, jint height){
1821         MSVideoSize vsize;
1822         vsize.width = (int)width;
1823         vsize.height = (int)height;
1824         linphone_core_set_preferred_video_size((LinphoneCore *)lc, vsize);
1825 }
1826
1827 extern "C" jintArray Java_org_linphone_core_LinphoneCoreImpl_getPreferredVideoSize(JNIEnv *env, jobject thiz, jlong lc){
1828         MSVideoSize vsize = linphone_core_get_preferred_video_size((LinphoneCore *)lc);
1829     jintArray arr = env->NewIntArray(2);
1830         int tVsize [2]= {vsize.width,vsize.height};
1831     env->SetIntArrayRegion(arr, 0, 2, tVsize);
1832     return arr;
1833 }
1834
1835 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setDownloadBandwidth(JNIEnv *env, jobject thiz, jlong lc, jint bw){
1836         linphone_core_set_download_bandwidth((LinphoneCore *)lc, (int) bw);
1837 }
1838
1839 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setUploadBandwidth(JNIEnv *env, jobject thiz, jlong lc, jint bw){
1840         linphone_core_set_upload_bandwidth((LinphoneCore *)lc, (int) bw);
1841 }
1842
1843 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setDownloadPtime(JNIEnv *env, jobject thiz, jlong lc, jint ptime){
1844         linphone_core_set_download_ptime((LinphoneCore *)lc, (int) ptime);
1845 }
1846
1847 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setUploadPtime(JNIEnv *env, jobject thiz, jlong lc, jint ptime){
1848         linphone_core_set_upload_ptime((LinphoneCore *)lc, (int) ptime);
1849 }
1850
1851 extern "C" jint Java_org_linphone_core_LinphoneProxyConfigImpl_getState(JNIEnv*  env,jobject thiz,jlong ptr) {
1852         return (jint) linphone_proxy_config_get_state((const LinphoneProxyConfig *) ptr);
1853 }
1854 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setExpires(JNIEnv*  env,jobject thiz,jlong ptr,jint delay) {
1855         linphone_proxy_config_expires((LinphoneProxyConfig *) ptr, (int) delay);
1856 }
1857
1858 extern "C" jint Java_org_linphone_core_LinphoneCallImpl_getDuration(JNIEnv*  env,jobject thiz,jlong ptr) {
1859         return (jint)linphone_call_get_duration((LinphoneCall *) ptr);
1860 }
1861
1862 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getSignalingTransportPort(JNIEnv* env,jobject thiz,jlong ptr, jint code) {
1863         LCSipTransports tr;
1864         linphone_core_get_sip_transports((LinphoneCore *) ptr, &tr);
1865                 switch (code) {
1866         case 0:
1867                 return tr.udp_port;
1868         case 1:
1869                 return tr.tcp_port;
1870         case 3:
1871                 return tr.tls_port;
1872         default:
1873                 return -2;
1874         }
1875 }
1876
1877 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setSignalingTransportPorts(JNIEnv*  env,jobject thiz,jlong ptr,jint udp, jint tcp, jint tls) {
1878         LinphoneCore *lc = (LinphoneCore *) ptr;
1879         LCSipTransports tr;
1880         tr.udp_port = udp;
1881         tr.tcp_port = tcp;
1882         tr.tls_port = tls;
1883
1884         linphone_core_set_sip_transports(lc, &tr); // tr will be copied
1885 }
1886
1887 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_enableIpv6(JNIEnv* env,jobject  thiz
1888               ,jlong lc, jboolean enable) {
1889               linphone_core_enable_ipv6((LinphoneCore*)lc,enable);
1890 }
1891
1892 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_adjustSoftwareVolume(JNIEnv* env,jobject  thiz
1893               ,jlong ptr, jint db) {
1894         linphone_core_set_playback_gain_db((LinphoneCore *) ptr, db);
1895 }
1896
1897 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_pauseCall(JNIEnv *env,jobject thiz,jlong pCore, jlong pCall) {
1898         return (jint)linphone_core_pause_call((LinphoneCore *) pCore, (LinphoneCall *) pCall);
1899 }
1900 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_pauseAllCalls(JNIEnv *env,jobject thiz,jlong pCore) {
1901         return (jint)linphone_core_pause_all_calls((LinphoneCore *) pCore);
1902 }
1903 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_resumeCall(JNIEnv *env,jobject thiz,jlong pCore, jlong pCall) {
1904         return (jint)linphone_core_resume_call((LinphoneCore *) pCore, (LinphoneCall *) pCall);
1905 }
1906 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isInConference(JNIEnv *env,jobject thiz,jlong pCore) {
1907         return (jboolean)linphone_core_is_in_conference((LinphoneCore *) pCore);
1908 }
1909 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_enterConference(JNIEnv *env,jobject thiz,jlong pCore) {
1910         return (jboolean)(0 == linphone_core_enter_conference((LinphoneCore *) pCore));
1911 }
1912 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_leaveConference(JNIEnv *env,jobject thiz,jlong pCore) {
1913         linphone_core_leave_conference((LinphoneCore *) pCore);
1914 }
1915 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_addAllToConference(JNIEnv *env,jobject thiz,jlong pCore) {
1916         linphone_core_add_all_to_conference((LinphoneCore *) pCore);
1917 }
1918 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_addToConference(JNIEnv *env,jobject thiz,jlong pCore, jlong pCall) {
1919         linphone_core_add_to_conference((LinphoneCore *) pCore, (LinphoneCall *) pCall);
1920 }
1921 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_removeFromConference(JNIEnv *env,jobject thiz,jlong pCore, jlong pCall) {
1922         linphone_core_remove_from_conference((LinphoneCore *) pCore, (LinphoneCall *) pCall);
1923 }
1924
1925 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_terminateConference(JNIEnv *env,jobject thiz,jlong pCore) {
1926         linphone_core_terminate_conference((LinphoneCore *) pCore);
1927 }
1928 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getConferenceSize(JNIEnv *env,jobject thiz,jlong pCore) {
1929         return (jint)linphone_core_get_conference_size((LinphoneCore *) pCore);
1930 }
1931 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_terminateAllCalls(JNIEnv *env,jobject thiz,jlong pCore) {
1932         linphone_core_terminate_all_calls((LinphoneCore *) pCore);
1933 }
1934 extern "C" jobject Java_org_linphone_core_LinphoneCoreImpl_getCall(JNIEnv *env,jobject thiz,jlong pCore,jint position) {
1935         LinphoneCoreData *lcd=(LinphoneCoreData*)linphone_core_get_user_data((LinphoneCore*)pCore);
1936         LinphoneCall* lCall = (LinphoneCall*) ms_list_nth_data(linphone_core_get_calls((LinphoneCore *) pCore),position);
1937         return lcd->getCall(env,lCall);
1938 }
1939 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getCallsNb(JNIEnv *env,jobject thiz,jlong pCore) {
1940         return (jint)ms_list_size(linphone_core_get_calls((LinphoneCore *) pCore));
1941 }
1942
1943 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_transferCall(JNIEnv *env,jobject thiz,jlong pCore, jlong pCall, jstring jReferTo) {
1944         const char* cReferTo=env->GetStringUTFChars(jReferTo, NULL);
1945         jint err = linphone_core_transfer_call((LinphoneCore *) pCore, (LinphoneCall *) pCall, cReferTo);
1946         env->ReleaseStringUTFChars(jReferTo, cReferTo);
1947         return err;
1948 }
1949 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_transferCallToAnother(JNIEnv *env,jobject thiz,jlong pCore, jlong pCall, jlong pDestCall) {
1950         return (jint)linphone_core_transfer_call_to_another((LinphoneCore *) pCore, (LinphoneCall *) pCall, (LinphoneCall *) pDestCall);
1951 }
1952
1953 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setZrtpSecretsCache(JNIEnv *env,jobject thiz,jlong pCore, jstring jFile) {
1954         if (jFile) {
1955                 const char* cFile=env->GetStringUTFChars(jFile, NULL);
1956                 linphone_core_set_zrtp_secrets_file((LinphoneCore *) pCore,cFile);
1957                 env->ReleaseStringUTFChars(jFile, cFile);
1958         } else {
1959                 linphone_core_set_zrtp_secrets_file((LinphoneCore *) pCore,NULL);
1960         }
1961 }
1962
1963 extern "C" jobject Java_org_linphone_core_LinphoneCoreImpl_findCallFromUri(JNIEnv *env,jobject thiz,jlong pCore, jstring jUri) {
1964         const char* cUri=env->GetStringUTFChars(jUri, NULL);
1965         LinphoneCall *call= (LinphoneCall *) linphone_core_find_call_from_uri((LinphoneCore *) pCore,cUri);
1966         env->ReleaseStringUTFChars(jUri, cUri);
1967         LinphoneCoreData *lcdata=(LinphoneCoreData*)linphone_core_get_user_data((LinphoneCore*)pCore);
1968         return (jobject) lcdata->getCall(env,call);
1969 }
1970
1971
1972 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_setVideoDevice(JNIEnv *env,jobject thiz,jlong pCore,jint id) {
1973         LinphoneCore* lc = (LinphoneCore *) pCore;
1974         const char** devices = linphone_core_get_video_devices(lc);
1975         if (devices == NULL) {
1976                 ms_error("No existing video devices\n");
1977                 return -1;
1978         }
1979         int i;
1980         for(i=0; i<=id; i++) {
1981                 if (devices[i] == NULL)
1982                         break;
1983                 ms_message("Existing device %d : %s\n", i, devices[i]);
1984                 if (i==id) {
1985                         return (jint)linphone_core_set_video_device(lc, devices[i]);
1986                 }
1987         }
1988         return -1;
1989 }
1990
1991 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getVideoDevice(JNIEnv *env,jobject thiz,jlong pCore) {
1992         LinphoneCore* lc = (LinphoneCore *) pCore;
1993         const char** devices = linphone_core_get_video_devices(lc);
1994         if (devices == NULL) {
1995                 ms_error("No existing video devices\n");
1996                 return -1;
1997         }
1998         const char* cam = linphone_core_get_video_device(lc);
1999         if (cam == NULL) {
2000                 ms_error("No current video device\n");
2001         } else {
2002                 int i=0;
2003                 while(devices[i] != NULL) {
2004                         if (strcmp(devices[i], cam) == 0)
2005                                 return i;
2006                         i++;
2007                 }
2008         }
2009         ms_warning("Returning default (0) device\n");
2010         return 0;
2011 }
2012
2013 extern "C" jstring Java_org_linphone_core_LinphoneCallImpl_getAuthenticationToken(JNIEnv*  env,jobject thiz,jlong ptr) {
2014         LinphoneCall *call = (LinphoneCall *) ptr;
2015         const char* token = linphone_call_get_authentication_token(call);
2016         if (token == NULL) return NULL;
2017         return env->NewStringUTF(token);
2018 }
2019 extern "C" jboolean Java_org_linphone_core_LinphoneCallImpl_isAuthenticationTokenVerified(JNIEnv*  env,jobject thiz,jlong ptr) {
2020         LinphoneCall *call = (LinphoneCall *) ptr;
2021         return (jboolean)linphone_call_get_authentication_token_verified(call);
2022 }
2023 extern "C" void Java_org_linphone_core_LinphoneCallImpl_setAuthenticationTokenVerified(JNIEnv*  env,jobject thiz,jlong ptr,jboolean verified) {
2024         LinphoneCall *call = (LinphoneCall *) ptr;
2025         linphone_call_set_authentication_token_verified(call, verified);
2026 }
2027
2028 extern "C" jfloat Java_org_linphone_core_LinphoneCallImpl_getPlayVolume(JNIEnv* env, jobject thiz, jlong ptr) {
2029         LinphoneCall *call = (LinphoneCall *) ptr;
2030         return (jfloat)linphone_call_get_play_volume(call);
2031 }
2032
2033 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_soundResourcesLocked(JNIEnv* env,jobject thiz,jlong ptr){
2034         return (jboolean)linphone_core_sound_resources_locked((LinphoneCore *) ptr);
2035 }
2036
2037 // Needed by Galaxy S (can't switch to/from speaker while playing and still keep mic working)
2038 // Implemented directly in msandroid.cpp (sound filters for Android).
2039 extern "C" void msandroid_hack_speaker_state(bool speakerOn);
2040
2041 extern "C" void Java_org_linphone_LinphoneManager_hackSpeakerState(JNIEnv*  env,jobject thiz,jboolean speakerOn){
2042         msandroid_hack_speaker_state(speakerOn);
2043 }
2044 // End Galaxy S hack functions
2045
2046
2047 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getMaxCalls(JNIEnv *env,jobject thiz,jlong pCore) {
2048         return (jint) linphone_core_get_max_calls((LinphoneCore *) pCore);
2049 }
2050 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setMaxCalls(JNIEnv *env,jobject thiz,jlong pCore, jint max) {
2051         linphone_core_set_max_calls((LinphoneCore *) pCore, (int) max);
2052 }
2053
2054 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_tunnelAddServerAndMirror(JNIEnv *env,jobject thiz,jlong pCore,
2055                 jstring jHost, jint port, jint mirror, jint delay) {
2056         LinphoneTunnel *tunnel=((LinphoneCore *) pCore)->tunnel;
2057         if (!tunnel) return;
2058         const char* cHost=env->GetStringUTFChars(jHost, NULL);
2059         linphone_tunnel_add_server_and_mirror(tunnel, cHost, port, mirror, delay);
2060         env->ReleaseStringUTFChars(jHost, cHost);
2061 }
2062
2063 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_tunnelSetHttpProxy(JNIEnv *env,jobject thiz,jlong pCore,
2064                 jstring jHost, jint port, jstring username, jstring password) {
2065
2066         LinphoneTunnel *tunnel=((LinphoneCore *) pCore)->tunnel;
2067         if (!tunnel) return;
2068         const char* cHost=(jHost!=NULL) ? env->GetStringUTFChars(jHost, NULL) : NULL;
2069         const char* cUsername= (username!=NULL) ? env->GetStringUTFChars(username, NULL) : NULL;
2070         const char* cPassword= (password!=NULL) ? env->GetStringUTFChars(password, NULL) : NULL;
2071         linphone_tunnel_set_http_proxy(tunnel,cHost, port,cUsername,cPassword);
2072         if (cHost) env->ReleaseStringUTFChars(jHost, cHost);
2073         if (cUsername) env->ReleaseStringUTFChars(username, cUsername);
2074         if (cPassword) env->ReleaseStringUTFChars(password, cPassword);
2075 }
2076
2077
2078 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_tunnelAutoDetect(JNIEnv *env,jobject thiz,jlong pCore) {
2079         LinphoneTunnel *tunnel=((LinphoneCore *) pCore)->tunnel; if (!tunnel) return;
2080         linphone_tunnel_auto_detect(tunnel);
2081
2082 }
2083
2084 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_tunnelCleanServers(JNIEnv *env,jobject thiz,jlong pCore) {
2085         LinphoneTunnel *tunnel=((LinphoneCore *) pCore)->tunnel; if (!tunnel) return;
2086         linphone_tunnel_clean_servers(tunnel);
2087 }
2088
2089 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_tunnelEnable(JNIEnv *env,jobject thiz,jlong pCore, jboolean enable) {
2090         LinphoneTunnel *tunnel=((LinphoneCore *) pCore)->tunnel; if (!tunnel) return;
2091         linphone_tunnel_enable(tunnel, enable);
2092 }
2093
2094
2095 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setUserAgent(JNIEnv *env,jobject thiz,jlong pCore, jstring name, jstring version){
2096         const char* cname=env->GetStringUTFChars(name, NULL);
2097         const char* cversion=env->GetStringUTFChars(version, NULL);
2098         linphone_core_set_user_agent(cname,cversion);
2099         env->ReleaseStringUTFChars(name, cname);
2100         env->ReleaseStringUTFChars(version, cversion);
2101 }
2102
2103 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isTunnelAvailable(JNIEnv *env,jobject thiz){
2104         return (jboolean)linphone_core_tunnel_available();
2105 }
2106
2107 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setVideoPolicy(JNIEnv *env, jobject thiz, jlong lc, jboolean autoInitiate, jboolean autoAccept){
2108         LinphoneVideoPolicy vpol;
2109         vpol.automatically_initiate = autoInitiate;
2110         vpol.automatically_accept = autoAccept;
2111         linphone_core_set_video_policy((LinphoneCore *)lc, &vpol);
2112 }
2113
2114 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setCpuCountNative(JNIEnv *env, jobject thiz, jint count) {
2115         ms_set_cpu_count(count);
2116 }
2117
2118 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setAudioPort(JNIEnv *env, jobject thiz, jlong lc, jint port) {
2119         linphone_core_set_audio_port((LinphoneCore *)lc, port);
2120 }
2121
2122 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setVideoPort(JNIEnv *env, jobject thiz, jlong lc, jint port) {
2123         linphone_core_set_video_port((LinphoneCore *)lc, port);
2124 }
2125
2126 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setAudioPortRange(JNIEnv *env, jobject thiz, jlong lc, jint min_port, jint max_port) {
2127         linphone_core_set_audio_port_range((LinphoneCore *)lc, min_port, max_port);
2128 }
2129
2130 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setVideoPortRange(JNIEnv *env, jobject thiz, jlong lc, jint min_port, jint max_port) {
2131         linphone_core_set_video_port_range((LinphoneCore *)lc, min_port, max_port);
2132 }
2133
2134 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setIncomingTimeout(JNIEnv *env, jobject thiz, jlong lc, jint timeout) {
2135         linphone_core_set_inc_timeout((LinphoneCore *)lc, timeout);
2136 }
2137
2138 extern "C" jstring Java_org_linphone_core_LinphoneCoreImpl_getVersion(JNIEnv*  env,jobject  thiz,jlong ptr) {
2139         jstring jvalue =env->NewStringUTF(linphone_core_get_version());
2140         return jvalue;
2141 }