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