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