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