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