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