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