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