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