]> sjero.net Git - linphone/blob - coreapi/linphonecore_jni.cc
API and makefiles for ZRTP support.
[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 #include "mediastreamer2/msjava.h"
24
25 #include <cpu-features.h>
26
27 #ifdef ANDROID
28 #include <android/log.h>
29 extern "C" void libmsilbc_init();
30 #ifdef HAVE_X264
31 extern "C" void libmsx264_init();
32 #endif
33 #ifdef HAVE_AMR
34 extern "C" void libmsamr_init();
35 #endif
36 #endif /*ANDROID*/
37
38 static JavaVM *jvm=0;
39
40 #ifdef ANDROID
41 static void linphone_android_log_handler(OrtpLogLevel lev, const char *fmt, va_list args){
42         int prio;
43         switch(lev){
44         case ORTP_DEBUG:        prio = ANDROID_LOG_DEBUG;       break;
45         case ORTP_MESSAGE:      prio = ANDROID_LOG_INFO;        break;
46         case ORTP_WARNING:      prio = ANDROID_LOG_WARN;        break;
47         case ORTP_ERROR:        prio = ANDROID_LOG_ERROR;       break;
48         case ORTP_FATAL:        prio = ANDROID_LOG_FATAL;       break;
49         default:                prio = ANDROID_LOG_DEFAULT;     break;
50         }
51         __android_log_vprint(prio, LOG_DOMAIN, fmt, args);
52 }
53 #endif /*ANDROID*/
54
55 JNIEXPORT jint JNICALL  JNI_OnLoad(JavaVM *ajvm, void *reserved)
56 {
57 #ifdef ANDROID
58         ms_set_jvm(ajvm);
59 #endif /*ANDROID*/
60         jvm=ajvm;
61         return JNI_VERSION_1_2;
62 }
63
64
65 //LinphoneFactory
66 extern "C" void Java_org_linphone_core_LinphoneCoreFactoryImpl_setDebugMode(JNIEnv*  env
67                 ,jobject  thiz
68                 ,jboolean isDebug) {
69         if (isDebug) {
70                 linphone_core_enable_logs_with_cb(linphone_android_log_handler);
71         } else {
72                 linphone_core_disable_logs();
73         }
74 }
75 // LinphoneCore
76
77 class LinphoneCoreData {
78 public:
79         LinphoneCoreData(JNIEnv*  env, jobject lc,jobject alistener, jobject auserdata) {
80
81                 core = env->NewGlobalRef(lc);
82                 listener = env->NewGlobalRef(alistener);
83                 userdata = auserdata?env->NewGlobalRef(auserdata):0;
84                 memset(&vTable,0,sizeof(vTable));
85                 vTable.show = showInterfaceCb;
86                 vTable.auth_info_requested = authInfoRequested;
87                 vTable.display_status = displayStatusCb;
88                 vTable.display_message = displayMessageCb;
89                 vTable.display_warning = displayMessageCb;
90                 vTable.global_state_changed = globalStateChange;
91                 vTable.registration_state_changed = registrationStateChange;
92                 vTable.call_state_changed = callStateChange;
93                 //vTable.call_encryption_changed = callEncryptionChange;
94                 vTable.text_received = text_received;
95                 vTable.new_subscription_request = new_subscription_request;
96                 vTable.notify_presence_recv = notify_presence_recv;
97
98                 listernerClass = (jclass)env->NewGlobalRef(env->GetObjectClass( alistener));
99
100                 /*displayStatus(LinphoneCore lc,String message);*/
101                 displayStatusId = env->GetMethodID(listernerClass,"displayStatus","(Lorg/linphone/core/LinphoneCore;Ljava/lang/String;)V");
102
103                 /*void generalState(LinphoneCore lc,int state); */
104                 globalStateId = env->GetMethodID(listernerClass,"globalState","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCore$GlobalState;Ljava/lang/String;)V");
105                 globalStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCore$GlobalState"));
106                 globalStateFromIntId = env->GetStaticMethodID(globalStateClass,"fromInt","(I)Lorg/linphone/core/LinphoneCore$GlobalState;");
107
108                 /*registrationState(LinphoneCore lc, LinphoneProxyConfig cfg, LinphoneCore.RegistrationState cstate, String smessage);*/
109                 registrationStateId = env->GetMethodID(listernerClass,"registrationState","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneProxyConfig;Lorg/linphone/core/LinphoneCore$RegistrationState;Ljava/lang/String;)V");
110                 registrationStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCore$RegistrationState"));
111                 registrationStateFromIntId = env->GetStaticMethodID(registrationStateClass,"fromInt","(I)Lorg/linphone/core/LinphoneCore$RegistrationState;");
112
113                 /*callState(LinphoneCore lc, LinphoneCall call, LinphoneCall.State cstate,String message);*/
114                 callStateId = env->GetMethodID(listernerClass,"callState","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCall;Lorg/linphone/core/LinphoneCall$State;Ljava/lang/String;)V");
115                 callStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCall$State"));
116                 callStateFromIntId = env->GetStaticMethodID(callStateClass,"fromInt","(I)Lorg/linphone/core/LinphoneCall$State;");
117
118                 /*callEncryption(LinphoneCore lc, LinphoneCall call, boolean encrypted,String auth_token);*/
119                 callEncryptionChangedId=env->GetMethodID(listernerClass,"callEncryptionChanged","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCall;ZLjava/lang/String;)V");
120
121                 /*void ecCalibrationStatus(LinphoneCore.EcCalibratorStatus status, int delay_ms, Object data);*/
122                 ecCalibrationStatusId = env->GetMethodID(listernerClass,"ecCalibrationStatus","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCore$EcCalibratorStatus;ILjava/lang/Object;)V");
123                 ecCalibratorStatusClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCore$EcCalibratorStatus"));
124                 ecCalibratorStatusFromIntId = env->GetStaticMethodID(ecCalibratorStatusClass,"fromInt","(I)Lorg/linphone/core/LinphoneCore$EcCalibratorStatus;");
125
126                 /*void newSubscriptionRequest(LinphoneCore lc, LinphoneFriend lf, String url)*/
127                 newSubscriptionRequestId = env->GetMethodID(listernerClass,"newSubscriptionRequest","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneFriend;Ljava/lang/String;)V");
128
129                 /*void notifyPresenceReceived(LinphoneCore lc, LinphoneFriend lf);*/
130                 notifyPresenceReceivedId = env->GetMethodID(listernerClass,"notifyPresenceReceived","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneFriend;)V");
131
132                 /*void textReceived(LinphoneCore lc, LinphoneChatRoom cr,LinphoneAddress from,String message);*/
133                 textReceivedId = env->GetMethodID(listernerClass,"textReceived","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneChatRoom;Lorg/linphone/core/LinphoneAddress;Ljava/lang/String;)V");
134
135                 proxyClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneProxyConfigImpl"));
136                 proxyCtrId = env->GetMethodID(proxyClass,"<init>", "(J)V");
137
138                 callClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCallImpl"));
139                 callCtrId = env->GetMethodID(callClass,"<init>", "(J)V");
140
141                 chatRoomClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneChatRoomImpl"));
142                 chatRoomCtrId = env->GetMethodID(chatRoomClass,"<init>", "(J)V");
143
144                 friendClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneFriendImpl"));;
145                 friendCtrId =env->GetMethodID(friendClass,"<init>", "(J)V");
146
147                 addressClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneAddressImpl"));
148                 addressCtrId =env->GetMethodID(addressClass,"<init>", "(J)V");
149
150         }
151
152         ~LinphoneCoreData() {
153                 JNIEnv *env = 0;
154                 jvm->AttachCurrentThread(&env,NULL);
155                 env->DeleteGlobalRef(core);
156                 env->DeleteGlobalRef(listener);
157                 if (userdata) env->DeleteGlobalRef(userdata);
158                 env->DeleteGlobalRef(listernerClass);
159                 env->DeleteGlobalRef(globalStateClass);
160                 env->DeleteGlobalRef(registrationStateClass);
161                 env->DeleteGlobalRef(callStateClass);
162                 env->DeleteGlobalRef(proxyClass);
163                 env->DeleteGlobalRef(callClass);
164                 env->DeleteGlobalRef(chatRoomClass);
165                 env->DeleteGlobalRef(friendClass);
166
167         }
168         jobject core;
169         jobject listener;
170         jobject userdata;
171
172         jclass listernerClass;
173         jmethodID displayStatusId;
174         jmethodID newSubscriptionRequestId;
175         jmethodID notifyPresenceReceivedId;
176         jmethodID textReceivedId;
177
178         jclass globalStateClass;
179         jmethodID globalStateId;
180         jmethodID globalStateFromIntId;
181
182         jclass registrationStateClass;
183         jmethodID registrationStateId;
184         jmethodID registrationStateFromIntId;
185
186         jclass callStateClass;
187         jmethodID callStateId;
188         jmethodID callStateFromIntId;
189
190         jmethodID callEncryptionChangedId;
191
192         jclass ecCalibratorStatusClass;
193         jmethodID ecCalibrationStatusId;
194         jmethodID ecCalibratorStatusFromIntId;
195
196         jclass proxyClass;
197         jmethodID proxyCtrId;
198
199         jclass callClass;
200         jmethodID callCtrId;
201
202         jclass chatRoomClass;
203         jmethodID chatRoomCtrId;
204
205         jclass friendClass;
206         jmethodID friendCtrId;
207
208         jclass addressClass;
209         jmethodID addressCtrId;
210
211         LinphoneCoreVTable vTable;
212
213         static void showInterfaceCb(LinphoneCore *lc) {
214
215         }
216         static void byeReceivedCb(LinphoneCore *lc, const char *from) {
217
218         }
219         static void displayStatusCb(LinphoneCore *lc, const char *message) {
220                 JNIEnv *env = 0;
221                 jint result = jvm->AttachCurrentThread(&env,NULL);
222                 if (result != 0) {
223                         ms_error("cannot attach VM\n");
224                         return;
225                 }
226                 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
227                 env->CallVoidMethod(lcData->listener,lcData->displayStatusId,lcData->core,env->NewStringUTF(message));
228         }
229         static void displayMessageCb(LinphoneCore *lc, const char *message) {
230
231         }
232         static void authInfoRequested(LinphoneCore *lc, const char *realm, const char *username) {
233
234         }
235         static void globalStateChange(LinphoneCore *lc, LinphoneGlobalState gstate,const char* message) {
236                 JNIEnv *env = 0;
237                 jint result = jvm->AttachCurrentThread(&env,NULL);
238                 if (result != 0) {
239                         ms_error("cannot attach VM\n");
240                         return;
241                 }
242                 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
243                 env->CallVoidMethod(lcData->listener
244                                                         ,lcData->globalStateId
245                                                         ,lcData->core
246                                                         ,env->CallStaticObjectMethod(lcData->globalStateClass,lcData->globalStateFromIntId,(jint)gstate),
247                                                         message ? env->NewStringUTF(message) : NULL);
248         }
249         static void registrationStateChange(LinphoneCore *lc, LinphoneProxyConfig* proxy,LinphoneRegistrationState state,const char* message) {
250                 JNIEnv *env = 0;
251                 jint result = jvm->AttachCurrentThread(&env,NULL);
252                 if (result != 0) {
253                         ms_error("cannot attach VM\n");
254                         return;
255                 }
256                 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
257                 env->CallVoidMethod(lcData->listener
258                                                         ,lcData->registrationStateId
259                                                         ,lcData->core
260                                                         ,env->NewObject(lcData->proxyClass,lcData->proxyCtrId,(jlong)proxy)
261                                                         ,env->CallStaticObjectMethod(lcData->registrationStateClass,lcData->registrationStateFromIntId,(jint)state),
262                                                         message ? env->NewStringUTF(message) : NULL);
263         }
264         static void callStateChange(LinphoneCore *lc, LinphoneCall* call,LinphoneCallState state,const char* message) {
265                 JNIEnv *env = 0;
266                 jint result = jvm->AttachCurrentThread(&env,NULL);
267                 if (result != 0) {
268                         ms_error("cannot attach VM\n");
269                         return;
270                 }
271                 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
272                 env->CallVoidMethod(lcData->listener
273                                                         ,lcData->callStateId
274                                                         ,lcData->core
275                                                         ,env->NewObject(lcData->callClass,lcData->callCtrId,(jlong)call)
276                                                         ,env->CallStaticObjectMethod(lcData->callStateClass,lcData->callStateFromIntId,(jint)state),
277                                                         message ? env->NewStringUTF(message) : NULL);
278         }
279         static void callEncryptionChange(LinphoneCore *lc, LinphoneCall* call, bool_t encrypted,const char* authentication_token) {
280                 JNIEnv *env = 0;
281                 jint result = jvm->AttachCurrentThread(&env,NULL);
282                 if (result != 0) {
283                         ms_error("cannot attach VM\n");
284                         return;
285                 }
286                 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
287                 env->CallVoidMethod(lcData->listener
288                                                         ,lcData->callEncryptionChangedId
289                                                         ,lcData->core
290                                                         ,env->NewObject(lcData->callClass,lcData->callCtrId,(jlong)call)
291                                                         ,encrypted
292                                                         ,authentication_token ? env->NewStringUTF(authentication_token) : NULL);
293         }
294         static void notify_presence_recv (LinphoneCore *lc,  LinphoneFriend *my_friend) {
295                 JNIEnv *env = 0;
296                 jint result = jvm->AttachCurrentThread(&env,NULL);
297                 if (result != 0) {
298                         ms_error("cannot attach VM\n");
299                         return;
300                 }
301                 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
302                 env->CallVoidMethod(lcData->listener
303                                                         ,lcData->notifyPresenceReceivedId
304                                                         ,lcData->core
305                                                         ,env->NewObject(lcData->friendClass,lcData->friendCtrId,(jlong)my_friend));
306         }
307         static void new_subscription_request (LinphoneCore *lc,  LinphoneFriend *my_friend, const char* url) {
308                 JNIEnv *env = 0;
309                 jint result = jvm->AttachCurrentThread(&env,NULL);
310                 if (result != 0) {
311                         ms_error("cannot attach VM\n");
312                         return;
313                 }
314                 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
315                 env->CallVoidMethod(lcData->listener
316                                                         ,lcData->newSubscriptionRequestId
317                                                         ,lcData->core
318                                                         ,env->NewObject(lcData->friendClass,lcData->friendCtrId,(jlong)my_friend)
319                                                         ,url ? env->NewStringUTF(url) : NULL);
320         }
321         static void text_received(LinphoneCore *lc, LinphoneChatRoom *room, const LinphoneAddress *from, const char *message) {
322                 JNIEnv *env = 0;
323                 jint result = jvm->AttachCurrentThread(&env,NULL);
324                 if (result != 0) {
325                         ms_error("cannot attach VM\n");
326                         return;
327                 }
328                 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
329                 env->CallVoidMethod(lcData->listener
330                                                         ,lcData->textReceivedId
331                                                         ,lcData->core
332                                                         ,env->NewObject(lcData->chatRoomClass,lcData->chatRoomCtrId,(jlong)room)
333                                                         ,env->NewObject(lcData->addressClass,lcData->addressCtrId,(jlong)from)
334                                                         ,message ? env->NewStringUTF(message) : NULL);
335         }
336         static void ecCalibrationStatus(LinphoneCore *lc, LinphoneEcCalibratorStatus status, int delay_ms, void *data) {
337                 JNIEnv *env = 0;
338                 jint result = jvm->AttachCurrentThread(&env,NULL);
339                 if (result != 0) {
340                         ms_error("cannot attach VM\n");
341                         return;
342                 }
343                 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
344                 env->CallVoidMethod(lcData->listener
345                                                         ,lcData->ecCalibrationStatusId
346                                                         ,lcData->core
347                                                         ,env->CallStaticObjectMethod(lcData->ecCalibratorStatusClass,lcData->ecCalibratorStatusFromIntId,(jint)status)
348                                                         ,delay_ms
349                                                         ,data ? data : NULL);
350                 if (data != NULL &&status !=LinphoneEcCalibratorInProgress ) {
351                         //final state, releasing global ref
352                         env->DeleteGlobalRef((jobject)data);
353                 }
354
355         }
356
357
358 };
359 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_newLinphoneCore(JNIEnv*  env
360                 ,jobject  thiz
361                 ,jobject jlistener
362                 ,jstring juserConfig
363                 ,jstring jfactoryConfig
364                 ,jobject  juserdata){
365
366         const char* userConfig = juserConfig?env->GetStringUTFChars(juserConfig, NULL):NULL;
367         const char* factoryConfig = jfactoryConfig?env->GetStringUTFChars(jfactoryConfig, NULL):NULL;
368         LinphoneCoreData* ldata = new LinphoneCoreData(env,thiz,jlistener,juserdata);
369
370 #ifdef HAVE_ILBC
371         libmsilbc_init(); // requires an fpu
372 #endif
373 #ifdef HAVE_X264
374         libmsx264_init();
375 #endif
376 #ifdef HAVE_AMR
377         libmsamr_init();
378 #endif
379         jlong nativePtr = (jlong)linphone_core_new(     &ldata->vTable
380                         ,userConfig
381                         ,factoryConfig
382                         ,ldata);
383         //clear auth info list
384         linphone_core_clear_all_auth_info((LinphoneCore*) nativePtr);
385         //clear existing proxy config
386         linphone_core_clear_proxy_config((LinphoneCore*) nativePtr);
387
388         if (userConfig) env->ReleaseStringUTFChars(juserConfig, userConfig);
389         if (factoryConfig) env->ReleaseStringUTFChars(jfactoryConfig, factoryConfig);
390         return nativePtr;
391 }
392 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_delete(JNIEnv*  env
393                 ,jobject  thiz
394                 ,jlong lc) {
395         LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data((LinphoneCore*)lc);
396         linphone_core_destroy((LinphoneCore*)lc);
397         delete lcData;
398 }
399
400 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_clearProxyConfigs(JNIEnv* env, jobject thiz,jlong lc) {
401         linphone_core_clear_proxy_config((LinphoneCore*)lc);
402 }
403
404 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setDefaultProxyConfig(  JNIEnv*  env
405                 ,jobject  thiz
406                 ,jlong lc
407                 ,jlong pc) {
408         linphone_core_set_default_proxy((LinphoneCore*)lc,(LinphoneProxyConfig*)pc);
409 }
410 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_getDefaultProxyConfig( JNIEnv*  env
411                 ,jobject  thiz
412                 ,jlong lc) {
413         LinphoneProxyConfig *config=0;
414         linphone_core_get_default_proxy((LinphoneCore*)lc,&config);
415         return (jlong)config;
416 }
417
418 extern "C" int Java_org_linphone_core_LinphoneCoreImpl_addProxyConfig(  JNIEnv*  env
419                 ,jobject  thiz
420                 ,jobject jproxyCfg
421                 ,jlong lc
422                 ,jlong pc) {
423         LinphoneProxyConfig* proxy = (LinphoneProxyConfig*)pc;
424         linphone_proxy_config_set_user_data(proxy, env->NewGlobalRef(jproxyCfg));
425
426         return linphone_core_add_proxy_config((LinphoneCore*)lc,(LinphoneProxyConfig*)pc);
427 }
428
429 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_clearAuthInfos(JNIEnv* env, jobject thiz,jlong lc) {
430         linphone_core_clear_all_auth_info((LinphoneCore*)lc);
431 }
432
433 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_addAuthInfo(    JNIEnv*  env
434                 ,jobject  thiz
435                 ,jlong lc
436                 ,jlong pc) {
437         linphone_core_add_auth_info((LinphoneCore*)lc,(LinphoneAuthInfo*)pc);
438 }
439 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_iterate(        JNIEnv*  env
440                 ,jobject  thiz
441                 ,jlong lc) {
442         linphone_core_iterate((LinphoneCore*)lc);
443 }
444 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_invite(        JNIEnv*  env
445                 ,jobject  thiz
446                 ,jlong lc
447                 ,jstring juri) {
448         const char* uri = env->GetStringUTFChars(juri, NULL);
449         LinphoneCall* lCall = linphone_core_invite((LinphoneCore*)lc,uri);
450         env->ReleaseStringUTFChars(juri, uri);
451         return (jlong)lCall;
452 }
453 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_inviteAddress( JNIEnv*  env
454                 ,jobject  thiz
455                 ,jlong lc
456                 ,jlong to) {
457         return (jlong) linphone_core_invite_address((LinphoneCore*)lc,(LinphoneAddress*)to);
458 }
459
460 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_terminateCall(  JNIEnv*  env
461                 ,jobject  thiz
462                 ,jlong lc
463                 ,jlong call) {
464         linphone_core_terminate_call((LinphoneCore*)lc,(LinphoneCall*)call);
465 }
466
467 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_getRemoteAddress(      JNIEnv*  env
468                 ,jobject  thiz
469                 ,jlong lc) {
470         return (jlong)linphone_core_get_current_call_remote_address((LinphoneCore*)lc);
471 }
472 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isInCall(   JNIEnv*  env
473                 ,jobject  thiz
474                 ,jlong lc) {
475
476         return linphone_core_in_call((LinphoneCore*)lc);
477 }
478 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isInComingInvitePending(    JNIEnv*  env
479                 ,jobject  thiz
480                 ,jlong lc) {
481
482         return linphone_core_inc_invite_pending((LinphoneCore*)lc);
483 }
484 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_acceptCall(     JNIEnv*  env
485                 ,jobject  thiz
486                 ,jlong lc
487                 ,jlong call) {
488
489         linphone_core_accept_call((LinphoneCore*)lc,(LinphoneCall*)call);
490 }
491
492 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_getCallLog(    JNIEnv*  env
493                 ,jobject  thiz
494                 ,jlong lc
495                 ,jint position) {
496                 return (jlong)ms_list_nth_data(linphone_core_get_call_logs((LinphoneCore*)lc),position);
497 }
498 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getNumberOfCallLogs(    JNIEnv*  env
499                 ,jobject  thiz
500                 ,jlong lc) {
501                 return ms_list_size(linphone_core_get_call_logs((LinphoneCore*)lc));
502 }
503 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setNetworkStateReachable(       JNIEnv*  env
504                 ,jobject  thiz
505                 ,jlong lc
506                 ,jboolean isReachable) {
507                 linphone_core_set_network_reachable((LinphoneCore*)lc,isReachable);
508 }
509
510 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setPlaybackGain(        JNIEnv*  env
511                 ,jobject  thiz
512                 ,jlong lc
513                 ,jfloat gain) {
514                 linphone_core_set_playback_gain_db((LinphoneCore*)lc,gain);
515 }
516
517 extern "C" float Java_org_linphone_core_LinphoneCoreImpl_getPlaybackGain(       JNIEnv*  env
518                 ,jobject  thiz
519                 ,jlong lc) {
520                 return linphone_core_get_playback_gain_db((LinphoneCore*)lc);
521 }
522
523 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_muteMic(        JNIEnv*  env
524                 ,jobject  thiz
525                 ,jlong lc
526                 ,jboolean isMuted) {
527                 linphone_core_mute_mic((LinphoneCore*)lc,isMuted);
528 }
529
530 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_interpretUrl(  JNIEnv*  env
531                 ,jobject  thiz
532                 ,jlong lc
533                 ,jstring jurl) {
534         const char* url = env->GetStringUTFChars(jurl, NULL);
535         jlong result = (jlong)linphone_core_interpret_url((LinphoneCore*)lc,url);
536         env->ReleaseStringUTFChars(jurl, url);
537         return result;
538 }
539 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_sendDtmf(       JNIEnv*  env
540                 ,jobject  thiz
541                 ,jlong lc
542                 ,jchar dtmf) {
543         linphone_core_send_dtmf((LinphoneCore*)lc,dtmf);
544 }
545 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_playDtmf(       JNIEnv*  env
546                 ,jobject  thiz
547                 ,jlong lc
548                 ,jchar dtmf
549                 ,jint duration) {
550         linphone_core_play_dtmf((LinphoneCore*)lc,dtmf,duration);
551 }
552 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_stopDtmf(       JNIEnv*  env
553                 ,jobject  thiz
554                 ,jlong lc) {
555         linphone_core_stop_dtmf((LinphoneCore*)lc);
556 }
557
558 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_clearCallLogs(JNIEnv*  env
559                                                                                                                                                 ,jobject  thiz
560                                                                                                                                                 ,jlong lc) {
561         linphone_core_clear_call_logs((LinphoneCore*)lc);
562 }
563 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isMicMuted( JNIEnv*  env
564                 ,jobject  thiz
565                 ,jlong lc) {
566         return linphone_core_is_mic_muted((LinphoneCore*)lc);
567 }
568 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_findPayloadType(JNIEnv*  env
569                                                                                                                                                         ,jobject  thiz
570                                                                                                                                                         ,jlong lc
571                                                                                                                                                         ,jstring jmime
572                                                                                                                                                         ,jint rate) {
573         const char* mime = env->GetStringUTFChars(jmime, NULL);
574         jlong result = (jlong)linphone_core_find_payload_type((LinphoneCore*)lc,mime,rate);
575         env->ReleaseStringUTFChars(jmime, mime);
576         return result;
577 }
578 extern "C" jlongArray Java_org_linphone_core_LinphoneCoreImpl_listVideoPayloadTypes(JNIEnv*  env
579                                                                                                                                                         ,jobject  thiz
580                                                                                                                                                         ,jlong lc) {
581         const MSList* codecs = linphone_core_get_video_codecs((LinphoneCore*)lc);
582         int codecsCount = ms_list_size(codecs);
583         jlongArray jCodecs = env->NewLongArray(codecsCount);
584         jlong *jInternalArray = env->GetLongArrayElements(jCodecs, NULL);
585
586         for (int i = 0; i < codecsCount; i++ ) {
587                 jInternalArray[i] = (unsigned long) (codecs->data);
588                 codecs = codecs->next;
589         }
590
591         env->ReleaseLongArrayElements(jCodecs, jInternalArray, 0);
592
593         return jCodecs;
594 }
595
596 extern "C" jlongArray Java_org_linphone_core_LinphoneCoreImpl_listAudioPayloadTypes(JNIEnv*  env
597                                                                                                                                                         ,jobject  thiz
598                                                                                                                                                         ,jlong lc) {
599         const MSList* codecs = linphone_core_get_audio_codecs((LinphoneCore*)lc);
600         int codecsCount = ms_list_size(codecs);
601         jlongArray jCodecs = env->NewLongArray(codecsCount);
602         jlong *jInternalArray = env->GetLongArrayElements(jCodecs, NULL);
603
604         for (int i = 0; i < codecsCount; i++ ) {
605                 jInternalArray[i] = (unsigned long) (codecs->data);
606                 codecs = codecs->next;
607         }
608
609         env->ReleaseLongArrayElements(jCodecs, jInternalArray, 0);
610
611         return jCodecs;
612 }
613
614 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_enablePayloadType(JNIEnv*  env
615                                                                                                                                                         ,jobject  thiz
616                                                                                                                                                         ,jlong lc
617                                                                                                                                                         ,jlong pt
618                                                                                                                                                         ,jboolean enable) {
619         return linphone_core_enable_payload_type((LinphoneCore*)lc,(PayloadType*)pt,enable);
620 }
621 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_enableEchoCancellation(JNIEnv*  env
622                                                                                                                                                         ,jobject  thiz
623                                                                                                                                                         ,jlong lc
624                                                                                                                                                         ,jboolean enable) {
625         linphone_core_enable_echo_cancellation((LinphoneCore*)lc,enable);
626 }
627 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isEchoCancellationEnabled(JNIEnv*  env
628                                                                                                                                                         ,jobject  thiz
629                                                                                                                                                         ,jlong lc
630                                                                                                                                                         ) {
631         return linphone_core_echo_cancellation_enabled((LinphoneCore*)lc);
632 }
633
634 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_getCurrentCall(JNIEnv*  env
635                                                                                                                                                         ,jobject  thiz
636                                                                                                                                                         ,jlong lc
637                                                                                                                                                         ) {
638         return (jlong)linphone_core_get_current_call((LinphoneCore*)lc);
639 }
640 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_addFriend(JNIEnv*  env
641                                                                                                                                                         ,jobject  thiz
642                                                                                                                                                         ,jlong lc
643                                                                                                                                                         ,jlong aFriend
644                                                                                                                                                         ) {
645         linphone_core_add_friend((LinphoneCore*)lc,(LinphoneFriend*)aFriend);
646 }
647 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setPresenceInfo(JNIEnv*  env
648                                                                                                                                                         ,jobject  thiz
649                                                                                                                                                         ,jlong lc
650                                                                                                                                                         ,jint minute_away
651                                                                                                                                                         ,jstring jalternative_contact
652                                                                                                                                                         ,jint status) {
653         const char* alternative_contact = jalternative_contact?env->GetStringUTFChars(jalternative_contact, NULL):NULL;
654         linphone_core_set_presence_info((LinphoneCore*)lc,minute_away,alternative_contact,(LinphoneOnlineStatus)status);
655         if (alternative_contact) env->ReleaseStringUTFChars(jalternative_contact, alternative_contact);
656 }
657
658 extern "C" long Java_org_linphone_core_LinphoneCoreImpl_createChatRoom(JNIEnv*  env
659                                                                                                                                                         ,jobject  thiz
660                                                                                                                                                         ,jlong lc
661                                                                                                                                                         ,jstring jto) {
662
663         const char* to = env->GetStringUTFChars(jto, NULL);
664         LinphoneChatRoom* lResult = linphone_core_create_chat_room((LinphoneCore*)lc,to);
665         env->ReleaseStringUTFChars(jto, to);
666         return (long)lResult;
667 }
668
669 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_enableVideo(JNIEnv*  env
670                                                                                                                                                         ,jobject  thiz
671                                                                                                                                                         ,jlong lc
672                                                                                                                                                         ,jboolean vcap_enabled
673                                                                                                                                                         ,jboolean display_enabled) {
674         linphone_core_enable_video((LinphoneCore*)lc, vcap_enabled,display_enabled);
675
676 }
677 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isVideoEnabled(JNIEnv*  env
678                                                                                                                                                         ,jobject  thiz
679                                                                                                                                                         ,jlong lc) {
680         return linphone_core_video_enabled((LinphoneCore*)lc);
681 }
682 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setRing(JNIEnv*  env
683                                                                                                                                                         ,jobject  thiz
684                                                                                                                                                         ,jlong lc
685                                                                                                                                                         ,jstring jpath) {
686         const char* path = jpath?env->GetStringUTFChars(jpath, NULL):NULL;
687         linphone_core_set_ring((LinphoneCore*)lc,path);
688         if (path) env->ReleaseStringUTFChars(jpath, path);
689 }
690 extern "C" jstring Java_org_linphone_core_LinphoneCoreImpl_getRing(JNIEnv*  env
691                                                                                                                                                         ,jobject  thiz
692                                                                                                                                                         ,jlong lc
693                                                                                                                                                         ) {
694         const char* path = linphone_core_get_ring((LinphoneCore*)lc);
695         if (path) {
696                 return env->NewStringUTF(path);
697         } else {
698                 return NULL;
699         }
700 }
701 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_enableKeepAlive(JNIEnv*  env
702                                                                                                                                 ,jobject  thiz
703                                                                                                                                 ,jlong lc
704                                                                                                                                 ,jboolean enable) {
705         linphone_core_enable_keep_alive((LinphoneCore*)lc,enable);
706
707 }
708 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isKeepAliveEnabled(JNIEnv*  env
709                                                                                                                                 ,jobject  thiz
710                                                                                                                                 ,jlong lc) {
711         return linphone_core_keep_alive_enabled((LinphoneCore*)lc);
712
713 }
714 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_startEchoCalibration(JNIEnv*  env
715                                                                                                                                                                 ,jobject  thiz
716                                                                                                                                                                 ,jlong lc
717                                                                                                                                                                 ,jobject data) {
718         return linphone_core_start_echo_calibration((LinphoneCore*)lc
719                                                                                                         , LinphoneCoreData::ecCalibrationStatus
720                                                                                                         , data?env->NewGlobalRef(data):NULL);
721
722 }
723
724
725
726 //ProxyConfig
727
728 extern "C" jlong Java_org_linphone_core_LinphoneProxyConfigImpl_newLinphoneProxyConfig(JNIEnv*  env,jobject  thiz) {
729         LinphoneProxyConfig* proxy = linphone_proxy_config_new();
730         return  (jlong) proxy;
731 }
732
733 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_delete(JNIEnv*  env,jobject  thiz,jlong ptr) {
734         linphone_proxy_config_destroy((LinphoneProxyConfig*)ptr);
735 }
736 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setIdentity(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jidentity) {
737         const char* identity = env->GetStringUTFChars(jidentity, NULL);
738         linphone_proxy_config_set_identity((LinphoneProxyConfig*)proxyCfg,identity);
739         env->ReleaseStringUTFChars(jidentity, identity);
740 }
741 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getIdentity(JNIEnv* env,jobject thiz,jlong proxyCfg) {
742         const char* identity = linphone_proxy_config_get_identity((LinphoneProxyConfig*)proxyCfg);
743         if (identity) {
744                 return env->NewStringUTF(identity);
745         } else {
746                 return NULL;
747         }
748 }
749 extern "C" int Java_org_linphone_core_LinphoneProxyConfigImpl_setProxy(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jproxy) {
750         const char* proxy = env->GetStringUTFChars(jproxy, NULL);
751         int err=linphone_proxy_config_set_server_addr((LinphoneProxyConfig*)proxyCfg,proxy);
752         env->ReleaseStringUTFChars(jproxy, proxy);
753         return err;
754 }
755 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getProxy(JNIEnv* env,jobject thiz,jlong proxyCfg) {
756         const char* proxy = linphone_proxy_config_get_addr((LinphoneProxyConfig*)proxyCfg);
757         if (proxy) {
758                 return env->NewStringUTF(proxy);
759         } else {
760                 return NULL;
761         }
762 }
763 extern "C" int Java_org_linphone_core_LinphoneProxyConfigImpl_setRoute(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jroute) {
764         if (jroute != NULL) {
765                 const char* route = env->GetStringUTFChars(jroute, NULL);
766                 int err=linphone_proxy_config_set_route((LinphoneProxyConfig*)proxyCfg,route);
767                 env->ReleaseStringUTFChars(jroute, route);
768                 return err;
769         } else {
770                 return linphone_proxy_config_set_route((LinphoneProxyConfig*)proxyCfg,NULL);
771         }
772 }
773 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getRoute(JNIEnv* env,jobject thiz,jlong proxyCfg) {
774         const char* route = linphone_proxy_config_get_route((LinphoneProxyConfig*)proxyCfg);
775         if (route) {
776                 return env->NewStringUTF(route);
777         } else {
778                 return NULL;
779         }
780 }
781
782 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_enableRegister(JNIEnv* env,jobject thiz,jlong proxyCfg,jboolean enableRegister) {
783         linphone_proxy_config_enable_register((LinphoneProxyConfig*)proxyCfg,enableRegister);
784 }
785 extern "C" jboolean Java_org_linphone_core_LinphoneProxyConfigImpl_isRegistered(JNIEnv* env,jobject thiz,jlong proxyCfg) {
786         return linphone_proxy_config_is_registered((LinphoneProxyConfig*)proxyCfg);
787 }
788 extern "C" jboolean Java_org_linphone_core_LinphoneProxyConfigImpl_isRegisterEnabled(JNIEnv* env,jobject thiz,jlong proxyCfg) {
789         return linphone_proxy_config_register_enabled((LinphoneProxyConfig*)proxyCfg);
790 }
791 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_edit(JNIEnv* env,jobject thiz,jlong proxyCfg) {
792         linphone_proxy_config_edit((LinphoneProxyConfig*)proxyCfg);
793 }
794 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_done(JNIEnv* env,jobject thiz,jlong proxyCfg) {
795         linphone_proxy_config_done((LinphoneProxyConfig*)proxyCfg);
796 }
797 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_normalizePhoneNumber(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jnumber) {
798         if (jnumber == 0) {
799                 ms_error("cannot normalized null number");
800         }
801         const char* number = env->GetStringUTFChars(jnumber, NULL);
802         int len = env->GetStringLength(jnumber);
803         if (len == 0) {
804                 ms_warning("cannot normalize empty number");
805                 return jnumber;
806         }
807         char targetBuff[2*len];// returned number can be greater than origin (specially in case of prefix insertion
808         linphone_proxy_config_normalize_number((LinphoneProxyConfig*)proxyCfg,number,targetBuff,sizeof(targetBuff));
809         jstring normalizedNumber = env->NewStringUTF(targetBuff);
810         env->ReleaseStringUTFChars(jnumber, number);
811         return normalizedNumber;
812 }
813 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getDomain(JNIEnv* env
814                                                                                                                                                         ,jobject thiz
815                                                                                                                                                         ,jlong proxyCfg) {
816         const char* domain = linphone_proxy_config_get_domain((LinphoneProxyConfig*)proxyCfg);
817         if (domain) {
818                 return env->NewStringUTF(domain);
819         } else {
820                 return NULL;
821         }
822 }
823 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setDialEscapePlus(JNIEnv* env,jobject thiz,jlong proxyCfg,jboolean value) {
824         linphone_proxy_config_set_dial_escape_plus((LinphoneProxyConfig*)proxyCfg,value);
825 }
826
827 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setDialPrefix(JNIEnv* env
828                                                                                                                                         ,jobject thiz
829                                                                                                                                         ,jlong proxyCfg
830                                                                                                                                         ,jstring jprefix) {
831         const char* prefix = env->GetStringUTFChars(jprefix, NULL);
832         linphone_proxy_config_set_dial_prefix((LinphoneProxyConfig*)proxyCfg,prefix);
833         env->ReleaseStringUTFChars(jprefix, prefix);
834 }
835 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_enablePublish(JNIEnv* env
836                                                                                                                                                                 ,jobject thiz
837                                                                                                                                                                 ,jlong proxyCfg
838                                                                                                                                                                 ,jboolean val) {
839         linphone_proxy_config_enable_publish((LinphoneProxyConfig*)proxyCfg,val);
840 }
841 extern "C" jboolean Java_org_linphone_core_LinphoneProxyConfigImpl_publishEnabled(JNIEnv* env,jobject thiz,jlong proxyCfg) {
842         return linphone_proxy_config_publish_enabled((LinphoneProxyConfig*)proxyCfg);
843 }
844
845 //Auth Info
846
847 extern "C" jlong Java_org_linphone_core_LinphoneAuthInfoImpl_newLinphoneAuthInfo(JNIEnv* env
848                 , jobject thiz
849                 , jstring jusername
850                 , jstring juserid
851                 , jstring jpassword
852                 , jstring jha1
853                 , jstring jrealm) {
854
855         const char* username = env->GetStringUTFChars(jusername, NULL);
856         const char* password = env->GetStringUTFChars(jpassword, NULL);
857         jlong auth = (jlong)linphone_auth_info_new(username,NULL,password,NULL,NULL);
858
859         env->ReleaseStringUTFChars(jusername, username);
860         env->ReleaseStringUTFChars(jpassword, password);
861         return auth;
862
863 }
864 extern "C" void Java_org_linphone_core_LinphoneAuthInfoImpl_delete(JNIEnv* env
865                 , jobject thiz
866                 , jlong ptr) {
867         linphone_auth_info_destroy((LinphoneAuthInfo*)ptr);
868 }
869
870 //LinphoneAddress
871
872 extern "C" jlong Java_org_linphone_core_LinphoneAddressImpl_newLinphoneAddressImpl(JNIEnv*  env
873                                                                                                                                                                         ,jobject  thiz
874                                                                                                                                                                         ,jstring juri
875                                                                                                                                                                         ,jstring jdisplayName) {
876         const char* uri = env->GetStringUTFChars(juri, NULL);
877         LinphoneAddress* address = linphone_address_new(uri);
878         if (jdisplayName && address) {
879                 const char* displayName = env->GetStringUTFChars(jdisplayName, NULL);
880                 linphone_address_set_display_name(address,displayName);
881                 env->ReleaseStringUTFChars(jdisplayName, displayName);
882         }
883         env->ReleaseStringUTFChars(juri, uri);
884
885         return  (jlong) address;
886 }
887 extern "C" void Java_org_linphone_core_LinphoneAddressImpl_delete(JNIEnv*  env
888                                                                                                                                                 ,jobject  thiz
889                                                                                                                                                 ,jlong ptr) {
890         linphone_address_destroy((LinphoneAddress*)ptr);
891 }
892
893 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_getDisplayName(JNIEnv*  env
894                                                                                                                                                 ,jobject  thiz
895                                                                                                                                                 ,jlong ptr) {
896         const char* displayName = linphone_address_get_display_name((LinphoneAddress*)ptr);
897         if (displayName) {
898                 return env->NewStringUTF(displayName);
899         } else {
900                 return 0;
901         }
902 }
903 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_getUserName(JNIEnv*  env
904                                                                                                                                                 ,jobject  thiz
905                                                                                                                                                 ,jlong ptr) {
906         const char* userName = linphone_address_get_username((LinphoneAddress*)ptr);
907         if (userName) {
908                 return env->NewStringUTF(userName);
909         } else {
910                 return 0;
911         }
912 }
913 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_getDomain(JNIEnv*  env
914                                                                                                                                                 ,jobject  thiz
915                                                                                                                                                 ,jlong ptr) {
916         const char* domain = linphone_address_get_domain((LinphoneAddress*)ptr);
917         if (domain) {
918                 return env->NewStringUTF(domain);
919         } else {
920                 return 0;
921         }
922 }
923
924 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_toString(JNIEnv*  env
925                                                                                                                                                 ,jobject  thiz
926                                                                                                                                                 ,jlong ptr) {
927         char* uri = linphone_address_as_string((LinphoneAddress*)ptr);
928         jstring juri =env->NewStringUTF(uri);
929         ms_free(uri);
930         return juri;
931 }
932 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_toUri(JNIEnv*  env
933                                                                                                                                                 ,jobject  thiz
934                                                                                                                                                 ,jlong ptr) {
935         char* uri = linphone_address_as_string_uri_only((LinphoneAddress*)ptr);
936         jstring juri =env->NewStringUTF(uri);
937         ms_free(uri);
938         return juri;
939 }
940 extern "C" void Java_org_linphone_core_LinphoneAddressImpl_setDisplayName(JNIEnv*  env
941                                                                                                                                                 ,jobject  thiz
942                                                                                                                                                 ,jlong address
943                                                                                                                                                 ,jstring jdisplayName) {
944         const char* displayName = jdisplayName!= NULL?env->GetStringUTFChars(jdisplayName, NULL):NULL;
945         linphone_address_set_display_name((LinphoneAddress*)address,displayName);
946         if (displayName != NULL) env->ReleaseStringUTFChars(jdisplayName, displayName);
947 }
948
949
950 //CallLog
951 extern "C" jlong Java_org_linphone_core_LinphoneCallLogImpl_getFrom(JNIEnv*  env
952                                                                                                                                                 ,jobject  thiz
953                                                                                                                                                 ,jlong ptr) {
954         return (jlong)((LinphoneCallLog*)ptr)->from;
955 }
956 extern "C" jlong Java_org_linphone_core_LinphoneCallLogImpl_getTo(JNIEnv*  env
957                                                                                                                                                 ,jobject  thiz
958                                                                                                                                                 ,jlong ptr) {
959         return (jlong)((LinphoneCallLog*)ptr)->to;
960 }
961 extern "C" jboolean Java_org_linphone_core_LinphoneCallLogImpl_isIncoming(JNIEnv*  env
962                                                                                                                                                 ,jobject  thiz
963                                                                                                                                                 ,jlong ptr) {
964         return ((LinphoneCallLog*)ptr)->dir==LinphoneCallIncoming?JNI_TRUE:JNI_FALSE;
965 }
966
967 /*payloadType*/
968 extern "C" jstring Java_org_linphone_core_PayloadTypeImpl_toString(JNIEnv*  env,jobject  thiz,jlong ptr) {
969         PayloadType* pt = (PayloadType*)ptr;
970         char* value = ms_strdup_printf("[%s] clock [%i], bitrate [%i]"
971                                                                         ,payload_type_get_mime(pt)
972                                                                         ,payload_type_get_rate(pt)
973                                                                         ,payload_type_get_bitrate(pt));
974         jstring jvalue =env->NewStringUTF(value);
975         ms_free(value);
976         return jvalue;
977 }
978 extern "C" jstring Java_org_linphone_core_PayloadTypeImpl_getMime(JNIEnv*  env,jobject  thiz,jlong ptr) {
979         PayloadType* pt = (PayloadType*)ptr;
980         jstring jvalue =env->NewStringUTF(payload_type_get_mime(pt));
981         return jvalue;
982 }
983 extern "C" jint Java_org_linphone_core_PayloadTypeImpl_getRate(JNIEnv*  env,jobject  thiz, jlong ptr) {
984         PayloadType* pt = (PayloadType*)ptr;
985         return payload_type_get_rate(pt);
986 }
987
988 //LinphoneCall
989 extern "C" void Java_org_linphone_core_LinphoneCallImpl_ref(JNIEnv*  env
990                                                                                                                                                 ,jobject  thiz
991                                                                                                                                                 ,jlong ptr) {
992         linphone_call_ref((LinphoneCall*)ptr);
993 }
994
995 extern "C" void Java_org_linphone_core_LinphoneCallImpl_unref(JNIEnv*  env
996                                                                                                                                                 ,jobject  thiz
997                                                                                                                                                 ,jlong ptr) {
998         linphone_call_unref((LinphoneCall*)ptr);
999 }
1000
1001 extern "C" jlong Java_org_linphone_core_LinphoneCallImpl_getCallLog(    JNIEnv*  env
1002                                                                                                                                                 ,jobject  thiz
1003                                                                                                                                                 ,jlong ptr) {
1004         return (jlong)linphone_call_get_call_log((LinphoneCall*)ptr);
1005 }
1006
1007 extern "C" jboolean Java_org_linphone_core_LinphoneCallImpl_isIncoming( JNIEnv*  env
1008                                                                                                                                                 ,jobject  thiz
1009                                                                                                                                                 ,jlong ptr) {
1010         return linphone_call_get_dir((LinphoneCall*)ptr)==LinphoneCallIncoming?JNI_TRUE:JNI_FALSE;
1011 }
1012
1013 extern "C" jlong Java_org_linphone_core_LinphoneCallImpl_getRemoteAddress(      JNIEnv*  env
1014                                                                                                                                                 ,jobject  thiz
1015                                                                                                                                                 ,jlong ptr) {
1016         return (jlong)linphone_call_get_remote_address((LinphoneCall*)ptr);
1017 }
1018
1019 extern "C" jint Java_org_linphone_core_LinphoneCallImpl_getState(       JNIEnv*  env
1020                                                                                                                                                 ,jobject  thiz
1021                                                                                                                                                 ,jlong ptr) {
1022         return (jint)linphone_call_get_state((LinphoneCall*)ptr);
1023 }
1024 extern "C" void Java_org_linphone_core_LinphoneCallImpl_enableEchoCancellation( JNIEnv*  env
1025                                                                                                                                                 ,jobject  thiz
1026                                                                                                                                                 ,jlong ptr
1027                                                                                                                                                 ,jboolean value) {
1028         linphone_call_enable_echo_cancellation((LinphoneCall*)ptr,value);
1029 }
1030 extern "C" jboolean Java_org_linphone_core_LinphoneCallImpl_isEchoCancellationEnabled(  JNIEnv*  env
1031                                                                                                                                                 ,jobject  thiz
1032                                                                                                                                                 ,jlong ptr) {
1033         return linphone_call_echo_cancellation_enabled((LinphoneCall*)ptr);
1034 }
1035
1036 extern "C" void Java_org_linphone_core_LinphoneCallImpl_enableEchoLimiter(      JNIEnv*  env
1037                                                                                                                                                 ,jobject  thiz
1038                                                                                                                                                 ,jlong ptr
1039                                                                                                                                                 ,jboolean value) {
1040         linphone_call_enable_echo_limiter((LinphoneCall*)ptr,value);
1041 }
1042 extern "C" jboolean Java_org_linphone_core_LinphoneCallImpl_isEchoLimiterEnabled(       JNIEnv*  env
1043                                                                                                                                                 ,jobject  thiz
1044                                                                                                                                                 ,jlong ptr) {
1045         return linphone_call_echo_limiter_enabled((LinphoneCall*)ptr);
1046 }
1047
1048 extern "C" jlong Java_org_linphone_core_LinphoneCallImpl_getReplacedCall(       JNIEnv*  env
1049                                                                                                                                                 ,jobject  thiz
1050                                                                                                                                                 ,jlong ptr) {
1051         return (jlong)linphone_call_get_replaced_call((LinphoneCall*)ptr);
1052 }
1053
1054 extern "C" jfloat Java_org_linphone_core_LinphoneCallImpl_getCurrentQuality(    JNIEnv*  env
1055                                                                                                                                                 ,jobject  thiz
1056                                                                                                                                                 ,jlong ptr) {
1057         return (jfloat)linphone_call_get_current_quality((LinphoneCall*)ptr);
1058 }
1059
1060 extern "C" jfloat Java_org_linphone_core_LinphoneCallImpl_getAverageQuality(    JNIEnv*  env
1061                                                                                                                                                 ,jobject  thiz
1062                                                                                                                                                 ,jlong ptr) {
1063         return (jfloat)linphone_call_get_average_quality((LinphoneCall*)ptr);
1064 }
1065
1066
1067 //LinphoneFriend
1068 extern "C" long Java_org_linphone_core_LinphoneFriendImpl_newLinphoneFriend(JNIEnv*  env
1069                                                                                                                                                 ,jobject  thiz
1070                                                                                                                                                 ,jstring jFriendUri) {
1071         LinphoneFriend* lResult;
1072
1073         if (jFriendUri) {
1074                 const char* friendUri = env->GetStringUTFChars(jFriendUri, NULL);
1075                 lResult= linphone_friend_new_with_addr(friendUri);
1076                 env->ReleaseStringUTFChars(jFriendUri, friendUri);
1077         } else {
1078                 lResult = linphone_friend_new();
1079         }
1080         return (long)lResult;
1081 }
1082 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_setAddress(JNIEnv*  env
1083                                                                                                                                                 ,jobject  thiz
1084                                                                                                                                                 ,jlong ptr
1085                                                                                                                                                 ,jlong linphoneAddress) {
1086         linphone_friend_set_addr((LinphoneFriend*)ptr,(LinphoneAddress*)linphoneAddress);
1087 }
1088 extern "C" long Java_org_linphone_core_LinphoneFriendImpl_getAddress(JNIEnv*  env
1089                                                                                                                                                 ,jobject  thiz
1090                                                                                                                                                 ,jlong ptr) {
1091         return (long)linphone_friend_get_address((LinphoneFriend*)ptr);
1092 }
1093 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_setIncSubscribePolicy(JNIEnv*  env
1094                                                                                                                                                 ,jobject  thiz
1095                                                                                                                                                 ,jlong ptr
1096                                                                                                                                                 ,jint policy) {
1097         linphone_friend_set_inc_subscribe_policy((LinphoneFriend*)ptr,(LinphoneSubscribePolicy)policy);
1098 }
1099 extern "C" jint Java_org_linphone_core_LinphoneFriendImpl_getIncSubscribePolicy(JNIEnv*  env
1100                                                                                                                                                 ,jobject  thiz
1101                                                                                                                                                 ,jlong ptr) {
1102         return linphone_friend_get_inc_subscribe_policy((LinphoneFriend*)ptr);
1103 }
1104 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_enableSubscribes(JNIEnv*  env
1105                                                                                                                                                 ,jobject  thiz
1106                                                                                                                                                 ,jlong ptr
1107                                                                                                                                                 ,jboolean value) {
1108         linphone_friend_enable_subscribes((LinphoneFriend*)ptr,value);
1109 }
1110 extern "C" jboolean Java_org_linphone_core_LinphoneFriendImpl_isSubscribesEnabled(JNIEnv*  env
1111                                                                                                                                                 ,jobject  thiz
1112                                                                                                                                                 ,jlong ptr) {
1113         return linphone_friend_subscribes_enabled((LinphoneFriend*)ptr);
1114 }
1115 extern "C" jboolean Java_org_linphone_core_LinphoneFriendImpl_getStatus(JNIEnv*  env
1116                                                                                                                                                 ,jobject  thiz
1117                                                                                                                                                 ,jlong ptr) {
1118         return linphone_friend_get_status((LinphoneFriend*)ptr);
1119 }
1120 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_edit(JNIEnv*  env
1121                                                                                                                                                 ,jobject  thiz
1122                                                                                                                                                 ,jlong ptr) {
1123         return linphone_friend_edit((LinphoneFriend*)ptr);
1124 }
1125 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_done(JNIEnv*  env
1126                                                                                                                                                 ,jobject  thiz
1127                                                                                                                                                 ,jlong ptr) {
1128          linphone_friend_done((LinphoneFriend*)ptr);
1129 }
1130 //LinphoneChatRoom
1131 extern "C" long Java_org_linphone_core_LinphoneChatRoomImpl_getPeerAddress(JNIEnv*  env
1132                                                                                                                                                 ,jobject  thiz
1133                                                                                                                                                 ,jlong ptr) {
1134         return (long) linphone_chat_room_get_peer_address((LinphoneChatRoom*)ptr);
1135 }
1136 extern "C" void Java_org_linphone_core_LinphoneChatRoomImpl_sendMessage(JNIEnv*  env
1137                                                                                                                                                 ,jobject  thiz
1138                                                                                                                                                 ,jlong ptr
1139                                                                                                                                                 ,jstring jmessage) {
1140         const char* message = env->GetStringUTFChars(jmessage, NULL);
1141         linphone_chat_room_send_message((LinphoneChatRoom*)ptr,message);
1142         env->ReleaseStringUTFChars(jmessage, message);
1143
1144 }
1145
1146 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setVideoWindowId(JNIEnv* env
1147                                                                                                                                                 ,jobject thiz
1148                                                                                                                                                 ,jlong lc
1149                                                                                                                                                 ,jobject obj) {
1150         linphone_core_set_native_video_window_id((LinphoneCore*)lc,(unsigned long)obj);
1151 }
1152
1153
1154 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setFirewallPolicy(JNIEnv *env, jobject thiz, jlong lc, int enum_value){
1155         linphone_core_set_firewall_policy((LinphoneCore*)lc,(LinphoneFirewallPolicy)enum_value);
1156 }
1157
1158 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getFirewallPolicy(JNIEnv *env, jobject thiz, jlong lc){
1159         return linphone_core_get_firewall_policy((LinphoneCore*)lc);
1160 }
1161
1162 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setStunServer(JNIEnv *env, jobject thiz, jlong lc, jstring jserver){
1163         const char* server = NULL;
1164         if (jserver) server=env->GetStringUTFChars(jserver, NULL);
1165         linphone_core_set_stun_server((LinphoneCore*)lc,server);
1166         if (server) env->ReleaseStringUTFChars(jserver,server);
1167 }
1168
1169 extern "C" jstring Java_org_linphone_core_LinphoneCoreImpl_getStunServer(JNIEnv *env, jobject thiz, jlong lc){
1170         const char *ret= linphone_core_get_stun_server((LinphoneCore*)lc);
1171         if (ret==NULL) return NULL;
1172         jstring jvalue =env->NewStringUTF(ret);
1173         return jvalue;
1174 }
1175
1176 extern "C" void Java_org_linphone_core_LinphoneCallParamsImpl_audioBandwidth(JNIEnv *env, jobject thiz, jlong lcp, jint bw){
1177         linphone_call_params_set_audio_bandwidth_limit((LinphoneCallParams*)lcp, bw);
1178 }
1179
1180 extern "C" void Java_org_linphone_core_LinphoneCallParamsImpl_enableVideo(JNIEnv *env, jobject thiz, jlong lcp, jboolean b){
1181         linphone_call_params_enable_video((LinphoneCallParams*)lcp, b);
1182 }
1183
1184 extern "C" jboolean Java_org_linphone_core_LinphoneCallParamsImpl_getVideoEnabled(JNIEnv *env, jobject thiz, jlong lcp){
1185         return linphone_call_params_video_enabled((LinphoneCallParams*)lcp);
1186 }
1187 extern "C" void Java_org_linphone_core_LinphoneCallParamsImpl_destroy(JNIEnv *env, jobject thiz, jlong lc){
1188         return linphone_call_params_destroy((LinphoneCallParams*)lc);
1189 }
1190 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_createDefaultCallParams(JNIEnv *env, jobject thiz, jlong lc){
1191         return (jlong) linphone_core_create_default_call_parameters((LinphoneCore*)lc);
1192 }
1193
1194 extern "C" jlong Java_org_linphone_core_LinphoneCallImpl_getCurrentParamsCopy(JNIEnv *env, jobject thiz, jlong lc){
1195         return (jlong) linphone_call_params_copy(linphone_call_get_current_params((LinphoneCall*)lc));
1196 }
1197
1198 extern "C" jlong Java_org_linphone_core_LinphoneCallImpl_enableCamera(JNIEnv *env, jobject thiz, jlong lc, jboolean b){
1199         linphone_call_enable_camera((LinphoneCall *)lc, (bool_t) b);
1200 }
1201
1202 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_inviteAddressWithParams(JNIEnv *env, jobject thiz, jlong lc, jlong addr, jlong params){
1203         return (jlong) linphone_core_invite_address_with_params((LinphoneCore *)lc, (const LinphoneAddress *)addr, (const LinphoneCallParams *)params);
1204 }
1205
1206 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_updateAddressWithParams(JNIEnv *env, jobject thiz, jlong lc, jlong call, jlong params){
1207         return (jint) linphone_core_update_call((LinphoneCore *)lc, (LinphoneCall *)call, (LinphoneCallParams *)params);
1208 }
1209
1210 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_updateCall(JNIEnv *env, jobject thiz, jlong lc, jlong call, jlong params){
1211         return (jint) linphone_core_update_call((LinphoneCore *)lc, (LinphoneCall *)call, (const LinphoneCallParams *)params);
1212 }
1213
1214
1215 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setPreferredVideoSize(JNIEnv *env, jobject thiz, jlong lc, jint width, jint height){
1216         MSVideoSize vsize;
1217         vsize.width = (int)width;
1218         vsize.height = (int)height;
1219         linphone_core_set_preferred_video_size((LinphoneCore *)lc, vsize);
1220 }
1221
1222 extern "C" jintArray Java_org_linphone_core_LinphoneCoreImpl_getPreferredVideoSize(JNIEnv *env, jobject thiz, jlong lc){
1223         MSVideoSize vsize = linphone_core_get_preferred_video_size((LinphoneCore *)lc);
1224     jintArray arr = env->NewIntArray(2);
1225         int tVsize [2]= {vsize.width,vsize.height};
1226     env->SetIntArrayRegion(arr, 0, 2, tVsize);
1227     return arr;
1228 }
1229
1230 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setDownloadBandwidth(JNIEnv *env, jobject thiz, jlong lc, jint bw){
1231         linphone_core_set_download_bandwidth((LinphoneCore *)lc, (int) bw);
1232 }
1233
1234 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setUploadBandwidth(JNIEnv *env, jobject thiz, jlong lc, jint bw){
1235         linphone_core_set_upload_bandwidth((LinphoneCore *)lc, (int) bw);
1236 }
1237
1238 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setDownloadPtime(JNIEnv *env, jobject thiz, jlong lc, jint ptime){
1239         linphone_core_set_download_ptime((LinphoneCore *)lc, (int) ptime);
1240 }
1241
1242 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setUploadPtime(JNIEnv *env, jobject thiz, jlong lc, jint ptime){
1243         linphone_core_set_upload_ptime((LinphoneCore *)lc, (int) ptime);
1244 }
1245
1246 extern "C" int Java_org_linphone_core_LinphoneProxyConfigImpl_getState(JNIEnv*  env,jobject thiz,jlong ptr) {
1247         return (int) linphone_proxy_config_get_state((const LinphoneProxyConfig *) ptr);
1248 }
1249 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setExpires(JNIEnv*  env,jobject thiz,jlong ptr,jint delay) {
1250         linphone_proxy_config_expires((LinphoneProxyConfig *) ptr, (int) delay);
1251 }
1252
1253 extern "C" jint Java_org_linphone_core_LinphoneCallImpl_getDuration(JNIEnv*  env,jobject thiz,jlong ptr) {
1254         linphone_call_get_duration((LinphoneCall *) ptr);
1255 }
1256         
1257 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getSignalingTransportPort(JNIEnv* env,jobject thiz,jlong ptr, jint code) {
1258         LCSipTransports tr;
1259         linphone_core_get_sip_transports((LinphoneCore *) ptr, &tr);
1260                 switch (code) {
1261         case 0:
1262                 return tr.udp_port;
1263         case 1:
1264                 return tr.tcp_port;
1265         case 3:
1266                 return tr.tls_port;
1267         default:
1268                 return -2;
1269         }
1270 }
1271
1272 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setSignalingTransportPorts(JNIEnv*  env,jobject thiz,jlong ptr,jint udp, jint tcp, jint tls) {
1273         LinphoneCore *lc = (LinphoneCore *) ptr;
1274         LCSipTransports tr;
1275         tr.udp_port = udp;
1276         tr.tcp_port = tcp;
1277         tr.tls_port = tls;
1278         
1279         linphone_core_set_sip_transports(lc, &tr); // tr will be copied
1280 }
1281
1282 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_enableIpv6(JNIEnv* env,jobject  thiz
1283               ,jlong lc, jboolean enable) {
1284               linphone_core_enable_ipv6((LinphoneCore*)lc,enable);
1285 }
1286
1287 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_adjustSoftwareVolume(JNIEnv* env,jobject  thiz
1288               ,jlong ptr, jint db) {
1289         linphone_core_set_playback_gain_db((LinphoneCore *) ptr, db);
1290 }
1291
1292 extern "C" jboolean Java_org_linphone_core_Version_nativeHasNeon(JNIEnv *env){
1293         if (android_getCpuFamily() == ANDROID_CPU_FAMILY_ARM && (android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON) != 0)
1294         {
1295                 return 1;
1296         }
1297         return 0;
1298 }
1299 extern "C" jboolean Java_org_linphone_core_Version_nativeHasZrtp(JNIEnv *env){
1300         return ortp_zrtp_available();
1301 }
1302
1303 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_pauseCall(JNIEnv *env,jobject thiz,jlong pCore, jlong pCall) {
1304         return linphone_core_pause_call((LinphoneCore *) pCore, (LinphoneCall *) pCall);
1305 }
1306 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_pauseAllCalls(JNIEnv *env,jobject thiz,jlong pCore) {
1307         return linphone_core_pause_all_calls((LinphoneCore *) pCore);
1308 }
1309 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_resumeCall(JNIEnv *env,jobject thiz,jlong pCore, jlong pCall) {
1310         return linphone_core_resume_call((LinphoneCore *) pCore, (LinphoneCall *) pCall);
1311 }
1312
1313 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setZrtpSecretsCache(JNIEnv *env,jobject thiz,jlong pCore, jstring jFile) {
1314         if (jFile) {
1315                 const char* cFile=env->GetStringUTFChars(jFile, NULL);
1316                 linphone_core_set_zrtp_secrets_file((LinphoneCore *) pCore,cFile);
1317                 env->ReleaseStringUTFChars(jFile, cFile);
1318         } else {
1319                 linphone_core_set_zrtp_secrets_file((LinphoneCore *) pCore,NULL);
1320         }
1321 }
1322
1323 extern "C" jstring Java_org_linphone_core_LinphoneCallImpl_getAuthenticationToken(JNIEnv*  env,jobject thiz,jlong ptr) {
1324         LinphoneCall *call = (LinphoneCall *) ptr;
1325         const char* token = linphone_call_get_authentication_token(call);
1326         if (token == NULL) return NULL;
1327         return env->NewStringUTF(token);
1328 }
1329 extern "C" jboolean Java_org_linphone_core_LinphoneCallImpl_isAuthenticationTokenVerified(JNIEnv*  env,jobject thiz,jlong ptr) {
1330         LinphoneCall *call = (LinphoneCall *) ptr;
1331         return linphone_call_get_authentication_token_verified(call);
1332 }
1333 extern "C" jboolean Java_org_linphone_core_LinphoneCallImpl_areStreamsEncrypted(JNIEnv*  env,jobject thiz,jlong ptr) {
1334         return linphone_call_are_all_streams_encrypted((LinphoneCall *) ptr);
1335 }