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