]> sjero.net Git - linphone/blob - coreapi/linphonecore_jni.cc
Merge branch 'master' of git://git.sv.gnu.org/linphone
[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" jlong 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         LinphoneCall* lCall = linphone_core_invite((LinphoneCore*)lc,uri);
475         env->ReleaseStringUTFChars(juri, uri);
476         return (jlong)lCall;
477 }
478 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_inviteAddress( JNIEnv*  env
479                 ,jobject  thiz
480                 ,jlong lc
481                 ,jlong to) {
482         return (jlong) linphone_core_invite_address((LinphoneCore*)lc,(LinphoneAddress*)to);
483 }
484
485 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_terminateCall(  JNIEnv*  env
486                 ,jobject  thiz
487                 ,jlong lc
488                 ,jlong call) {
489         linphone_core_terminate_call((LinphoneCore*)lc,(LinphoneCall*)call);
490 }
491
492 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_getRemoteAddress(      JNIEnv*  env
493                 ,jobject  thiz
494                 ,jlong lc) {
495         return (jlong)linphone_core_get_current_call_remote_address((LinphoneCore*)lc);
496 }
497 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isInCall(   JNIEnv*  env
498                 ,jobject  thiz
499                 ,jlong lc) {
500
501         return linphone_core_in_call((LinphoneCore*)lc);
502 }
503 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isInComingInvitePending(    JNIEnv*  env
504                 ,jobject  thiz
505                 ,jlong lc) {
506
507         return linphone_core_inc_invite_pending((LinphoneCore*)lc);
508 }
509 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_acceptCall(     JNIEnv*  env
510                 ,jobject  thiz
511                 ,jlong lc
512                 ,jlong call) {
513
514         linphone_core_accept_call((LinphoneCore*)lc,(LinphoneCall*)call);
515 }
516
517 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_getCallLog(    JNIEnv*  env
518                 ,jobject  thiz
519                 ,jlong lc
520                 ,jint position) {
521                 return (jlong)ms_list_nth_data(linphone_core_get_call_logs((LinphoneCore*)lc),position);
522 }
523 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getNumberOfCallLogs(    JNIEnv*  env
524                 ,jobject  thiz
525                 ,jlong lc) {
526                 return ms_list_size(linphone_core_get_call_logs((LinphoneCore*)lc));
527 }
528 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setNetworkStateReachable(       JNIEnv*  env
529                 ,jobject  thiz
530                 ,jlong lc
531                 ,jboolean isReachable) {
532                 linphone_core_set_network_reachable((LinphoneCore*)lc,isReachable);
533 }
534
535 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setPlaybackGain(        JNIEnv*  env
536                 ,jobject  thiz
537                 ,jlong lc
538                 ,jfloat gain) {
539                 linphone_core_set_playback_gain_db((LinphoneCore*)lc,gain);
540 }
541
542 extern "C" float Java_org_linphone_core_LinphoneCoreImpl_getPlaybackGain(       JNIEnv*  env
543                 ,jobject  thiz
544                 ,jlong lc) {
545                 return linphone_core_get_playback_gain_db((LinphoneCore*)lc);
546 }
547
548 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_muteMic(        JNIEnv*  env
549                 ,jobject  thiz
550                 ,jlong lc
551                 ,jboolean isMuted) {
552                 linphone_core_mute_mic((LinphoneCore*)lc,isMuted);
553 }
554
555 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_interpretUrl(  JNIEnv*  env
556                 ,jobject  thiz
557                 ,jlong lc
558                 ,jstring jurl) {
559         const char* url = env->GetStringUTFChars(jurl, NULL);
560         jlong result = (jlong)linphone_core_interpret_url((LinphoneCore*)lc,url);
561         env->ReleaseStringUTFChars(jurl, url);
562         return result;
563 }
564 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_sendDtmf(       JNIEnv*  env
565                 ,jobject  thiz
566                 ,jlong lc
567                 ,jchar dtmf) {
568         linphone_core_send_dtmf((LinphoneCore*)lc,dtmf);
569 }
570 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_playDtmf(       JNIEnv*  env
571                 ,jobject  thiz
572                 ,jlong lc
573                 ,jchar dtmf
574                 ,jint duration) {
575         linphone_core_play_dtmf((LinphoneCore*)lc,dtmf,duration);
576 }
577 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_stopDtmf(       JNIEnv*  env
578                 ,jobject  thiz
579                 ,jlong lc) {
580         linphone_core_stop_dtmf((LinphoneCore*)lc);
581 }
582
583 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_clearCallLogs(JNIEnv*  env
584                                                                                                                                                 ,jobject  thiz
585                                                                                                                                                 ,jlong lc) {
586         linphone_core_clear_call_logs((LinphoneCore*)lc);
587 }
588 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isMicMuted( JNIEnv*  env
589                 ,jobject  thiz
590                 ,jlong lc) {
591         return linphone_core_is_mic_muted((LinphoneCore*)lc);
592 }
593 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_findPayloadType(JNIEnv*  env
594                                                                                                                                                         ,jobject  thiz
595                                                                                                                                                         ,jlong lc
596                                                                                                                                                         ,jstring jmime
597                                                                                                                                                         ,jint rate) {
598         const char* mime = env->GetStringUTFChars(jmime, NULL);
599         jlong result = (jlong)linphone_core_find_payload_type((LinphoneCore*)lc,mime,rate);
600         env->ReleaseStringUTFChars(jmime, mime);
601         return result;
602 }
603 extern "C" jlongArray Java_org_linphone_core_LinphoneCoreImpl_listVideoPayloadTypes(JNIEnv*  env
604                                                                                                                                                         ,jobject  thiz
605                                                                                                                                                         ,jlong lc) {
606         const MSList* codecs = linphone_core_get_video_codecs((LinphoneCore*)lc);
607         int codecsCount = ms_list_size(codecs);
608         jlongArray jCodecs = env->NewLongArray(codecsCount);
609         jlong *jInternalArray = env->GetLongArrayElements(jCodecs, NULL);
610
611         for (int i = 0; i < codecsCount; i++ ) {
612                 jInternalArray[i] = (unsigned long) (codecs->data);
613                 codecs = codecs->next;
614         }
615
616         env->ReleaseLongArrayElements(jCodecs, jInternalArray, 0);
617
618         return jCodecs;
619 }
620
621 extern "C" jlongArray Java_org_linphone_core_LinphoneCoreImpl_listAudioPayloadTypes(JNIEnv*  env
622                                                                                                                                                         ,jobject  thiz
623                                                                                                                                                         ,jlong lc) {
624         const MSList* codecs = linphone_core_get_audio_codecs((LinphoneCore*)lc);
625         int codecsCount = ms_list_size(codecs);
626         jlongArray jCodecs = env->NewLongArray(codecsCount);
627         jlong *jInternalArray = env->GetLongArrayElements(jCodecs, NULL);
628
629         for (int i = 0; i < codecsCount; i++ ) {
630                 jInternalArray[i] = (unsigned long) (codecs->data);
631                 codecs = codecs->next;
632         }
633
634         env->ReleaseLongArrayElements(jCodecs, jInternalArray, 0);
635
636         return jCodecs;
637 }
638
639 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_enablePayloadType(JNIEnv*  env
640                                                                                                                                                         ,jobject  thiz
641                                                                                                                                                         ,jlong lc
642                                                                                                                                                         ,jlong pt
643                                                                                                                                                         ,jboolean enable) {
644         return linphone_core_enable_payload_type((LinphoneCore*)lc,(PayloadType*)pt,enable);
645 }
646 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_enableEchoCancellation(JNIEnv*  env
647                                                                                                                                                         ,jobject  thiz
648                                                                                                                                                         ,jlong lc
649                                                                                                                                                         ,jboolean enable) {
650         linphone_core_enable_echo_cancellation((LinphoneCore*)lc,enable);
651 }
652 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_enableEchoLimiter(JNIEnv*  env
653                                                                                                                                                         ,jobject  thiz
654                                                                                                                                                         ,jlong lc
655                                                                                                                                                         ,jboolean enable) {
656         linphone_core_enable_echo_limiter((LinphoneCore*)lc,enable);
657 }
658 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isEchoCancellationEnabled(JNIEnv*  env
659                                                                                                                                                         ,jobject  thiz
660                                                                                                                                                         ,jlong lc
661                                                                                                                                                         ) {
662         return linphone_core_echo_cancellation_enabled((LinphoneCore*)lc);
663 }
664
665 extern "C" jobject Java_org_linphone_core_LinphoneCoreImpl_getCurrentCall(JNIEnv*  env
666                                                                                                                                                         ,jobject  thiz
667                                                                                                                                                         ,jlong lc
668                                                                                                                                                         ) {
669         LinphoneCoreData *lcdata=(LinphoneCoreData*)linphone_core_get_user_data((LinphoneCore*)lc);
670         
671         return lcdata->getCall(env,linphone_core_get_current_call((LinphoneCore*)lc));
672 }
673 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_addFriend(JNIEnv*  env
674                                                                                                                                                         ,jobject  thiz
675                                                                                                                                                         ,jlong lc
676                                                                                                                                                         ,jlong aFriend
677                                                                                                                                                         ) {
678         linphone_core_add_friend((LinphoneCore*)lc,(LinphoneFriend*)aFriend);
679 }
680 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setPresenceInfo(JNIEnv*  env
681                                                                                                                                                         ,jobject  thiz
682                                                                                                                                                         ,jlong lc
683                                                                                                                                                         ,jint minute_away
684                                                                                                                                                         ,jstring jalternative_contact
685                                                                                                                                                         ,jint status) {
686         const char* alternative_contact = jalternative_contact?env->GetStringUTFChars(jalternative_contact, NULL):NULL;
687         linphone_core_set_presence_info((LinphoneCore*)lc,minute_away,alternative_contact,(LinphoneOnlineStatus)status);
688         if (alternative_contact) env->ReleaseStringUTFChars(jalternative_contact, alternative_contact);
689 }
690
691 extern "C" long Java_org_linphone_core_LinphoneCoreImpl_createChatRoom(JNIEnv*  env
692                                                                                                                                                         ,jobject  thiz
693                                                                                                                                                         ,jlong lc
694                                                                                                                                                         ,jstring jto) {
695
696         const char* to = env->GetStringUTFChars(jto, NULL);
697         LinphoneChatRoom* lResult = linphone_core_create_chat_room((LinphoneCore*)lc,to);
698         env->ReleaseStringUTFChars(jto, to);
699         return (long)lResult;
700 }
701
702 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_enableVideo(JNIEnv*  env
703                                                                                                                                                         ,jobject  thiz
704                                                                                                                                                         ,jlong lc
705                                                                                                                                                         ,jboolean vcap_enabled
706                                                                                                                                                         ,jboolean display_enabled) {
707         linphone_core_enable_video((LinphoneCore*)lc, vcap_enabled,display_enabled);
708
709 }
710 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isVideoEnabled(JNIEnv*  env
711                                                                                                                                                         ,jobject  thiz
712                                                                                                                                                         ,jlong lc) {
713         return linphone_core_video_enabled((LinphoneCore*)lc);
714 }
715 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setRing(JNIEnv*  env
716                                                                                                                                                         ,jobject  thiz
717                                                                                                                                                         ,jlong lc
718                                                                                                                                                         ,jstring jpath) {
719         const char* path = jpath?env->GetStringUTFChars(jpath, NULL):NULL;
720         linphone_core_set_ring((LinphoneCore*)lc,path);
721         if (path) env->ReleaseStringUTFChars(jpath, path);
722 }
723 extern "C" jstring Java_org_linphone_core_LinphoneCoreImpl_getRing(JNIEnv*  env
724                                                                                                                                                         ,jobject  thiz
725                                                                                                                                                         ,jlong lc
726                                                                                                                                                         ) {
727         const char* path = linphone_core_get_ring((LinphoneCore*)lc);
728         if (path) {
729                 return env->NewStringUTF(path);
730         } else {
731                 return NULL;
732         }
733 }
734 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setRootCA(JNIEnv*  env
735                                                                                                                                                         ,jobject  thiz
736                                                                                                                                                         ,jlong lc
737                                                                                                                                                         ,jstring jpath) {
738         const char* path = jpath?env->GetStringUTFChars(jpath, NULL):NULL;
739         linphone_core_set_root_ca((LinphoneCore*)lc,path);
740         if (path) env->ReleaseStringUTFChars(jpath, path);
741 }
742 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_enableKeepAlive(JNIEnv*  env
743                                                                                                                                 ,jobject  thiz
744                                                                                                                                 ,jlong lc
745                                                                                                                                 ,jboolean enable) {
746         linphone_core_enable_keep_alive((LinphoneCore*)lc,enable);
747
748 }
749 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isKeepAliveEnabled(JNIEnv*  env
750                                                                                                                                 ,jobject  thiz
751                                                                                                                                 ,jlong lc) {
752         return linphone_core_keep_alive_enabled((LinphoneCore*)lc);
753
754 }
755 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_startEchoCalibration(JNIEnv*  env
756                                                                                                                                                                 ,jobject  thiz
757                                                                                                                                                                 ,jlong lc
758                                                                                                                                                                 ,jobject data) {
759         return linphone_core_start_echo_calibration((LinphoneCore*)lc
760                                                                                                         , LinphoneCoreData::ecCalibrationStatus
761                                                                                                         , data?env->NewGlobalRef(data):NULL);
762
763 }
764
765
766
767 //ProxyConfig
768
769 extern "C" jlong Java_org_linphone_core_LinphoneProxyConfigImpl_newLinphoneProxyConfig(JNIEnv*  env,jobject  thiz) {
770         LinphoneProxyConfig* proxy = linphone_proxy_config_new();
771         return  (jlong) proxy;
772 }
773
774 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_delete(JNIEnv*  env,jobject  thiz,jlong ptr) {
775         linphone_proxy_config_destroy((LinphoneProxyConfig*)ptr);
776 }
777 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setIdentity(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jidentity) {
778         const char* identity = env->GetStringUTFChars(jidentity, NULL);
779         linphone_proxy_config_set_identity((LinphoneProxyConfig*)proxyCfg,identity);
780         env->ReleaseStringUTFChars(jidentity, identity);
781 }
782 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getIdentity(JNIEnv* env,jobject thiz,jlong proxyCfg) {
783         const char* identity = linphone_proxy_config_get_identity((LinphoneProxyConfig*)proxyCfg);
784         if (identity) {
785                 return env->NewStringUTF(identity);
786         } else {
787                 return NULL;
788         }
789 }
790 extern "C" int Java_org_linphone_core_LinphoneProxyConfigImpl_setProxy(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jproxy) {
791         const char* proxy = env->GetStringUTFChars(jproxy, NULL);
792         int err=linphone_proxy_config_set_server_addr((LinphoneProxyConfig*)proxyCfg,proxy);
793         env->ReleaseStringUTFChars(jproxy, proxy);
794         return err;
795 }
796 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getProxy(JNIEnv* env,jobject thiz,jlong proxyCfg) {
797         const char* proxy = linphone_proxy_config_get_addr((LinphoneProxyConfig*)proxyCfg);
798         if (proxy) {
799                 return env->NewStringUTF(proxy);
800         } else {
801                 return NULL;
802         }
803 }
804 extern "C" int Java_org_linphone_core_LinphoneProxyConfigImpl_setRoute(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jroute) {
805         if (jroute != NULL) {
806                 const char* route = env->GetStringUTFChars(jroute, NULL);
807                 int err=linphone_proxy_config_set_route((LinphoneProxyConfig*)proxyCfg,route);
808                 env->ReleaseStringUTFChars(jroute, route);
809                 return err;
810         } else {
811                 return linphone_proxy_config_set_route((LinphoneProxyConfig*)proxyCfg,NULL);
812         }
813 }
814 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getRoute(JNIEnv* env,jobject thiz,jlong proxyCfg) {
815         const char* route = linphone_proxy_config_get_route((LinphoneProxyConfig*)proxyCfg);
816         if (route) {
817                 return env->NewStringUTF(route);
818         } else {
819                 return NULL;
820         }
821 }
822
823 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_enableRegister(JNIEnv* env,jobject thiz,jlong proxyCfg,jboolean enableRegister) {
824         linphone_proxy_config_enable_register((LinphoneProxyConfig*)proxyCfg,enableRegister);
825 }
826 extern "C" jboolean Java_org_linphone_core_LinphoneProxyConfigImpl_isRegistered(JNIEnv* env,jobject thiz,jlong proxyCfg) {
827         return linphone_proxy_config_is_registered((LinphoneProxyConfig*)proxyCfg);
828 }
829 extern "C" jboolean Java_org_linphone_core_LinphoneProxyConfigImpl_isRegisterEnabled(JNIEnv* env,jobject thiz,jlong proxyCfg) {
830         return linphone_proxy_config_register_enabled((LinphoneProxyConfig*)proxyCfg);
831 }
832 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_edit(JNIEnv* env,jobject thiz,jlong proxyCfg) {
833         linphone_proxy_config_edit((LinphoneProxyConfig*)proxyCfg);
834 }
835 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_done(JNIEnv* env,jobject thiz,jlong proxyCfg) {
836         linphone_proxy_config_done((LinphoneProxyConfig*)proxyCfg);
837 }
838 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_normalizePhoneNumber(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jnumber) {
839         if (jnumber == 0) {
840                 ms_error("cannot normalized null number");
841         }
842         const char* number = env->GetStringUTFChars(jnumber, NULL);
843         int len = env->GetStringLength(jnumber);
844         if (len == 0) {
845                 ms_warning("cannot normalize empty number");
846                 return jnumber;
847         }
848         char targetBuff[2*len];// returned number can be greater than origin (specially in case of prefix insertion
849         linphone_proxy_config_normalize_number((LinphoneProxyConfig*)proxyCfg,number,targetBuff,sizeof(targetBuff));
850         jstring normalizedNumber = env->NewStringUTF(targetBuff);
851         env->ReleaseStringUTFChars(jnumber, number);
852         return normalizedNumber;
853 }
854 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getDomain(JNIEnv* env
855                                                                                                                                                         ,jobject thiz
856                                                                                                                                                         ,jlong proxyCfg) {
857         const char* domain = linphone_proxy_config_get_domain((LinphoneProxyConfig*)proxyCfg);
858         if (domain) {
859                 return env->NewStringUTF(domain);
860         } else {
861                 return NULL;
862         }
863 }
864 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setDialEscapePlus(JNIEnv* env,jobject thiz,jlong proxyCfg,jboolean value) {
865         linphone_proxy_config_set_dial_escape_plus((LinphoneProxyConfig*)proxyCfg,value);
866 }
867
868 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setDialPrefix(JNIEnv* env
869                                                                                                                                         ,jobject thiz
870                                                                                                                                         ,jlong proxyCfg
871                                                                                                                                         ,jstring jprefix) {
872         const char* prefix = env->GetStringUTFChars(jprefix, NULL);
873         linphone_proxy_config_set_dial_prefix((LinphoneProxyConfig*)proxyCfg,prefix);
874         env->ReleaseStringUTFChars(jprefix, prefix);
875 }
876 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_enablePublish(JNIEnv* env
877                                                                                                                                                                 ,jobject thiz
878                                                                                                                                                                 ,jlong proxyCfg
879                                                                                                                                                                 ,jboolean val) {
880         linphone_proxy_config_enable_publish((LinphoneProxyConfig*)proxyCfg,val);
881 }
882 extern "C" jboolean Java_org_linphone_core_LinphoneProxyConfigImpl_publishEnabled(JNIEnv* env,jobject thiz,jlong proxyCfg) {
883         return linphone_proxy_config_publish_enabled((LinphoneProxyConfig*)proxyCfg);
884 }
885
886 //Auth Info
887
888 extern "C" jlong Java_org_linphone_core_LinphoneAuthInfoImpl_newLinphoneAuthInfo(JNIEnv* env
889                 , jobject thiz
890                 , jstring jusername
891                 , jstring juserid
892                 , jstring jpassword
893                 , jstring jha1
894                 , jstring jrealm) {
895
896         const char* username = env->GetStringUTFChars(jusername, NULL);
897         const char* password = env->GetStringUTFChars(jpassword, NULL);
898         jlong auth = (jlong)linphone_auth_info_new(username,NULL,password,NULL,NULL);
899
900         env->ReleaseStringUTFChars(jusername, username);
901         env->ReleaseStringUTFChars(jpassword, password);
902         return auth;
903
904 }
905 extern "C" void Java_org_linphone_core_LinphoneAuthInfoImpl_delete(JNIEnv* env
906                 , jobject thiz
907                 , jlong ptr) {
908         linphone_auth_info_destroy((LinphoneAuthInfo*)ptr);
909 }
910
911 //LinphoneAddress
912
913 extern "C" jlong Java_org_linphone_core_LinphoneAddressImpl_newLinphoneAddressImpl(JNIEnv*  env
914                                                                                                                                                                         ,jobject  thiz
915                                                                                                                                                                         ,jstring juri
916                                                                                                                                                                         ,jstring jdisplayName) {
917         const char* uri = env->GetStringUTFChars(juri, NULL);
918         LinphoneAddress* address = linphone_address_new(uri);
919         if (jdisplayName && address) {
920                 const char* displayName = env->GetStringUTFChars(jdisplayName, NULL);
921                 linphone_address_set_display_name(address,displayName);
922                 env->ReleaseStringUTFChars(jdisplayName, displayName);
923         }
924         env->ReleaseStringUTFChars(juri, uri);
925
926         return  (jlong) address;
927 }
928 extern "C" void Java_org_linphone_core_LinphoneAddressImpl_delete(JNIEnv*  env
929                                                                                                                                                 ,jobject  thiz
930                                                                                                                                                 ,jlong ptr) {
931         linphone_address_destroy((LinphoneAddress*)ptr);
932 }
933
934 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_getDisplayName(JNIEnv*  env
935                                                                                                                                                 ,jobject  thiz
936                                                                                                                                                 ,jlong ptr) {
937         const char* displayName = linphone_address_get_display_name((LinphoneAddress*)ptr);
938         if (displayName) {
939                 return env->NewStringUTF(displayName);
940         } else {
941                 return 0;
942         }
943 }
944 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_getUserName(JNIEnv*  env
945                                                                                                                                                 ,jobject  thiz
946                                                                                                                                                 ,jlong ptr) {
947         const char* userName = linphone_address_get_username((LinphoneAddress*)ptr);
948         if (userName) {
949                 return env->NewStringUTF(userName);
950         } else {
951                 return 0;
952         }
953 }
954 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_getDomain(JNIEnv*  env
955                                                                                                                                                 ,jobject  thiz
956                                                                                                                                                 ,jlong ptr) {
957         const char* domain = linphone_address_get_domain((LinphoneAddress*)ptr);
958         if (domain) {
959                 return env->NewStringUTF(domain);
960         } else {
961                 return 0;
962         }
963 }
964
965 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_toString(JNIEnv*  env
966                                                                                                                                                 ,jobject  thiz
967                                                                                                                                                 ,jlong ptr) {
968         char* uri = linphone_address_as_string((LinphoneAddress*)ptr);
969         jstring juri =env->NewStringUTF(uri);
970         ms_free(uri);
971         return juri;
972 }
973 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_toUri(JNIEnv*  env
974                                                                                                                                                 ,jobject  thiz
975                                                                                                                                                 ,jlong ptr) {
976         char* uri = linphone_address_as_string_uri_only((LinphoneAddress*)ptr);
977         jstring juri =env->NewStringUTF(uri);
978         ms_free(uri);
979         return juri;
980 }
981 extern "C" void Java_org_linphone_core_LinphoneAddressImpl_setDisplayName(JNIEnv*  env
982                                                                                                                                                 ,jobject  thiz
983                                                                                                                                                 ,jlong address
984                                                                                                                                                 ,jstring jdisplayName) {
985         const char* displayName = jdisplayName!= NULL?env->GetStringUTFChars(jdisplayName, NULL):NULL;
986         linphone_address_set_display_name((LinphoneAddress*)address,displayName);
987         if (displayName != NULL) env->ReleaseStringUTFChars(jdisplayName, displayName);
988 }
989
990
991 //CallLog
992 extern "C" jlong Java_org_linphone_core_LinphoneCallLogImpl_getFrom(JNIEnv*  env
993                                                                                                                                                 ,jobject  thiz
994                                                                                                                                                 ,jlong ptr) {
995         return (jlong)((LinphoneCallLog*)ptr)->from;
996 }
997 extern "C" jlong Java_org_linphone_core_LinphoneCallLogImpl_getTo(JNIEnv*  env
998                                                                                                                                                 ,jobject  thiz
999                                                                                                                                                 ,jlong ptr) {
1000         return (jlong)((LinphoneCallLog*)ptr)->to;
1001 }
1002 extern "C" jboolean Java_org_linphone_core_LinphoneCallLogImpl_isIncoming(JNIEnv*  env
1003                                                                                                                                                 ,jobject  thiz
1004                                                                                                                                                 ,jlong ptr) {
1005         return ((LinphoneCallLog*)ptr)->dir==LinphoneCallIncoming?JNI_TRUE:JNI_FALSE;
1006 }
1007
1008 /*payloadType*/
1009 extern "C" jstring Java_org_linphone_core_PayloadTypeImpl_toString(JNIEnv*  env,jobject  thiz,jlong ptr) {
1010         PayloadType* pt = (PayloadType*)ptr;
1011         char* value = ms_strdup_printf("[%s] clock [%i], bitrate [%i]"
1012                                                                         ,payload_type_get_mime(pt)
1013                                                                         ,payload_type_get_rate(pt)
1014                                                                         ,payload_type_get_bitrate(pt));
1015         jstring jvalue =env->NewStringUTF(value);
1016         ms_free(value);
1017         return jvalue;
1018 }
1019 extern "C" jstring Java_org_linphone_core_PayloadTypeImpl_getMime(JNIEnv*  env,jobject  thiz,jlong ptr) {
1020         PayloadType* pt = (PayloadType*)ptr;
1021         jstring jvalue =env->NewStringUTF(payload_type_get_mime(pt));
1022         return jvalue;
1023 }
1024 extern "C" jint Java_org_linphone_core_PayloadTypeImpl_getRate(JNIEnv*  env,jobject  thiz, jlong ptr) {
1025         PayloadType* pt = (PayloadType*)ptr;
1026         return payload_type_get_rate(pt);
1027 }
1028
1029 //LinphoneCall
1030 extern "C" void Java_org_linphone_core_LinphoneCallImpl_finalize(JNIEnv*  env
1031                                                                                                                                                 ,jobject  thiz
1032                                                                                                                                                 ,jlong ptr) {
1033         LinphoneCall *call=(LinphoneCall*)ptr;  
1034         jobject jobj=(jobject)linphone_call_get_user_pointer(call);
1035         if (jobj==thiz){
1036                 //env->DeleteGlobalRef(jobj);
1037         }else{
1038                 ms_error("Call being destroyed is inconsistent: thiz=%lu, jobj=%lu",(unsigned long)thiz,(unsigned long)jobj);
1039         }
1040         linphone_call_set_user_pointer(call,NULL);
1041         linphone_call_unref(call);
1042 }
1043
1044 extern "C" jlong Java_org_linphone_core_LinphoneCallImpl_getCallLog(    JNIEnv*  env
1045                                                                                                                                                 ,jobject  thiz
1046                                                                                                                                                 ,jlong ptr) {
1047         return (jlong)linphone_call_get_call_log((LinphoneCall*)ptr);
1048 }
1049
1050 extern "C" jboolean Java_org_linphone_core_LinphoneCallImpl_isIncoming( JNIEnv*  env
1051                                                                                                                                                 ,jobject  thiz
1052                                                                                                                                                 ,jlong ptr) {
1053         return linphone_call_get_dir((LinphoneCall*)ptr)==LinphoneCallIncoming?JNI_TRUE:JNI_FALSE;
1054 }
1055
1056 extern "C" jlong Java_org_linphone_core_LinphoneCallImpl_getRemoteAddress(      JNIEnv*  env
1057                                                                                                                                                 ,jobject  thiz
1058                                                                                                                                                 ,jlong ptr) {
1059         return (jlong)linphone_call_get_remote_address((LinphoneCall*)ptr);
1060 }
1061
1062 extern "C" jint Java_org_linphone_core_LinphoneCallImpl_getState(       JNIEnv*  env
1063                                                                                                                                                 ,jobject  thiz
1064                                                                                                                                                 ,jlong ptr) {
1065         return (jint)linphone_call_get_state((LinphoneCall*)ptr);
1066 }
1067 extern "C" void Java_org_linphone_core_LinphoneCallImpl_enableEchoCancellation( JNIEnv*  env
1068                                                                                                                                                 ,jobject  thiz
1069                                                                                                                                                 ,jlong ptr
1070                                                                                                                                                 ,jboolean value) {
1071         linphone_call_enable_echo_cancellation((LinphoneCall*)ptr,value);
1072 }
1073 extern "C" jboolean Java_org_linphone_core_LinphoneCallImpl_isEchoCancellationEnabled(  JNIEnv*  env
1074                                                                                                                                                 ,jobject  thiz
1075                                                                                                                                                 ,jlong ptr) {
1076         return linphone_call_echo_cancellation_enabled((LinphoneCall*)ptr);
1077 }
1078
1079 extern "C" void Java_org_linphone_core_LinphoneCallImpl_enableEchoLimiter(      JNIEnv*  env
1080                                                                                                                                                 ,jobject  thiz
1081                                                                                                                                                 ,jlong ptr
1082                                                                                                                                                 ,jboolean value) {
1083         linphone_call_enable_echo_limiter((LinphoneCall*)ptr,value);
1084 }
1085 extern "C" jboolean Java_org_linphone_core_LinphoneCallImpl_isEchoLimiterEnabled(       JNIEnv*  env
1086                                                                                                                                                 ,jobject  thiz
1087                                                                                                                                                 ,jlong ptr) {
1088         return linphone_call_echo_limiter_enabled((LinphoneCall*)ptr);
1089 }
1090
1091 extern "C" jlong Java_org_linphone_core_LinphoneCallImpl_getReplacedCall(       JNIEnv*  env
1092                                                                                                                                                 ,jobject  thiz
1093                                                                                                                                                 ,jlong ptr) {
1094         return (jlong)linphone_call_get_replaced_call((LinphoneCall*)ptr);
1095 }
1096
1097 extern "C" jfloat Java_org_linphone_core_LinphoneCallImpl_getCurrentQuality(    JNIEnv*  env
1098                                                                                                                                                 ,jobject  thiz
1099                                                                                                                                                 ,jlong ptr) {
1100         return (jfloat)linphone_call_get_current_quality((LinphoneCall*)ptr);
1101 }
1102
1103 extern "C" jfloat Java_org_linphone_core_LinphoneCallImpl_getAverageQuality(    JNIEnv*  env
1104                                                                                                                                                 ,jobject  thiz
1105                                                                                                                                                 ,jlong ptr) {
1106         return (jfloat)linphone_call_get_average_quality((LinphoneCall*)ptr);
1107 }
1108
1109
1110 //LinphoneFriend
1111 extern "C" long Java_org_linphone_core_LinphoneFriendImpl_newLinphoneFriend(JNIEnv*  env
1112                                                                                                                                                 ,jobject  thiz
1113                                                                                                                                                 ,jstring jFriendUri) {
1114         LinphoneFriend* lResult;
1115
1116         if (jFriendUri) {
1117                 const char* friendUri = env->GetStringUTFChars(jFriendUri, NULL);
1118                 lResult= linphone_friend_new_with_addr(friendUri);
1119                 env->ReleaseStringUTFChars(jFriendUri, friendUri);
1120         } else {
1121                 lResult = linphone_friend_new();
1122         }
1123         return (long)lResult;
1124 }
1125 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_setAddress(JNIEnv*  env
1126                                                                                                                                                 ,jobject  thiz
1127                                                                                                                                                 ,jlong ptr
1128                                                                                                                                                 ,jlong linphoneAddress) {
1129         linphone_friend_set_addr((LinphoneFriend*)ptr,(LinphoneAddress*)linphoneAddress);
1130 }
1131 extern "C" long Java_org_linphone_core_LinphoneFriendImpl_getAddress(JNIEnv*  env
1132                                                                                                                                                 ,jobject  thiz
1133                                                                                                                                                 ,jlong ptr) {
1134         return (long)linphone_friend_get_address((LinphoneFriend*)ptr);
1135 }
1136 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_setIncSubscribePolicy(JNIEnv*  env
1137                                                                                                                                                 ,jobject  thiz
1138                                                                                                                                                 ,jlong ptr
1139                                                                                                                                                 ,jint policy) {
1140         linphone_friend_set_inc_subscribe_policy((LinphoneFriend*)ptr,(LinphoneSubscribePolicy)policy);
1141 }
1142 extern "C" jint Java_org_linphone_core_LinphoneFriendImpl_getIncSubscribePolicy(JNIEnv*  env
1143                                                                                                                                                 ,jobject  thiz
1144                                                                                                                                                 ,jlong ptr) {
1145         return linphone_friend_get_inc_subscribe_policy((LinphoneFriend*)ptr);
1146 }
1147 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_enableSubscribes(JNIEnv*  env
1148                                                                                                                                                 ,jobject  thiz
1149                                                                                                                                                 ,jlong ptr
1150                                                                                                                                                 ,jboolean value) {
1151         linphone_friend_enable_subscribes((LinphoneFriend*)ptr,value);
1152 }
1153 extern "C" jboolean Java_org_linphone_core_LinphoneFriendImpl_isSubscribesEnabled(JNIEnv*  env
1154                                                                                                                                                 ,jobject  thiz
1155                                                                                                                                                 ,jlong ptr) {
1156         return linphone_friend_subscribes_enabled((LinphoneFriend*)ptr);
1157 }
1158 extern "C" jboolean Java_org_linphone_core_LinphoneFriendImpl_getStatus(JNIEnv*  env
1159                                                                                                                                                 ,jobject  thiz
1160                                                                                                                                                 ,jlong ptr) {
1161         return linphone_friend_get_status((LinphoneFriend*)ptr);
1162 }
1163 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_edit(JNIEnv*  env
1164                                                                                                                                                 ,jobject  thiz
1165                                                                                                                                                 ,jlong ptr) {
1166         return linphone_friend_edit((LinphoneFriend*)ptr);
1167 }
1168 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_done(JNIEnv*  env
1169                                                                                                                                                 ,jobject  thiz
1170                                                                                                                                                 ,jlong ptr) {
1171          linphone_friend_done((LinphoneFriend*)ptr);
1172 }
1173 //LinphoneChatRoom
1174 extern "C" long Java_org_linphone_core_LinphoneChatRoomImpl_getPeerAddress(JNIEnv*  env
1175                                                                                                                                                 ,jobject  thiz
1176                                                                                                                                                 ,jlong ptr) {
1177         return (long) linphone_chat_room_get_peer_address((LinphoneChatRoom*)ptr);
1178 }
1179 extern "C" void Java_org_linphone_core_LinphoneChatRoomImpl_sendMessage(JNIEnv*  env
1180                                                                                                                                                 ,jobject  thiz
1181                                                                                                                                                 ,jlong ptr
1182                                                                                                                                                 ,jstring jmessage) {
1183         const char* message = env->GetStringUTFChars(jmessage, NULL);
1184         linphone_chat_room_send_message((LinphoneChatRoom*)ptr,message);
1185         env->ReleaseStringUTFChars(jmessage, message);
1186
1187 }
1188
1189 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setVideoWindowId(JNIEnv* env
1190                                                                                                                                                 ,jobject thiz
1191                                                                                                                                                 ,jlong lc
1192                                                                                                                                                 ,jobject obj) {
1193         linphone_core_set_native_video_window_id((LinphoneCore*)lc,(unsigned long)obj);
1194 }
1195
1196 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setPreviewWindowId(JNIEnv* env
1197                                                                                                                                                 ,jobject thiz
1198                                                                                                                                                 ,jlong lc
1199                                                                                                                                                 ,jobject obj) {
1200         linphone_core_set_native_preview_window_id((LinphoneCore*)lc,(unsigned long)obj);
1201 }
1202
1203 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setDeviceRotation(JNIEnv* env
1204                                                                                                                                                 ,jobject thiz
1205                                                                                                                                                 ,jlong lc
1206                                                                                                                                                 ,jint rotation) {
1207         linphone_core_set_device_rotation((LinphoneCore*)lc,rotation);
1208 }
1209
1210
1211 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setFirewallPolicy(JNIEnv *env, jobject thiz, jlong lc, int enum_value){
1212         linphone_core_set_firewall_policy((LinphoneCore*)lc,(LinphoneFirewallPolicy)enum_value);
1213 }
1214
1215 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getFirewallPolicy(JNIEnv *env, jobject thiz, jlong lc){
1216         return linphone_core_get_firewall_policy((LinphoneCore*)lc);
1217 }
1218
1219 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setStunServer(JNIEnv *env, jobject thiz, jlong lc, jstring jserver){
1220         const char* server = NULL;
1221         if (jserver) server=env->GetStringUTFChars(jserver, NULL);
1222         linphone_core_set_stun_server((LinphoneCore*)lc,server);
1223         if (server) env->ReleaseStringUTFChars(jserver,server);
1224 }
1225
1226 extern "C" jstring Java_org_linphone_core_LinphoneCoreImpl_getStunServer(JNIEnv *env, jobject thiz, jlong lc){
1227         const char *ret= linphone_core_get_stun_server((LinphoneCore*)lc);
1228         if (ret==NULL) return NULL;
1229         jstring jvalue =env->NewStringUTF(ret);
1230         return jvalue;
1231 }
1232
1233 extern "C" void Java_org_linphone_core_LinphoneCallParamsImpl_audioBandwidth(JNIEnv *env, jobject thiz, jlong lcp, jint bw){
1234         linphone_call_params_set_audio_bandwidth_limit((LinphoneCallParams*)lcp, bw);
1235 }
1236
1237 extern "C" void Java_org_linphone_core_LinphoneCallParamsImpl_enableVideo(JNIEnv *env, jobject thiz, jlong lcp, jboolean b){
1238         linphone_call_params_enable_video((LinphoneCallParams*)lcp, b);
1239 }
1240
1241 extern "C" jboolean Java_org_linphone_core_LinphoneCallParamsImpl_getVideoEnabled(JNIEnv *env, jobject thiz, jlong lcp){
1242         return linphone_call_params_video_enabled((LinphoneCallParams*)lcp);
1243 }
1244
1245 extern "C" jboolean Java_org_linphone_core_LinphoneCallParamsImpl_localConferenceMode(JNIEnv *env, jobject thiz, jlong lcp){
1246         return linphone_call_params_local_conference_mode((LinphoneCallParams*)lcp);
1247 }
1248
1249 extern "C" void Java_org_linphone_core_LinphoneCallParamsImpl_destroy(JNIEnv *env, jobject thiz, jlong lc){
1250         return linphone_call_params_destroy((LinphoneCallParams*)lc);
1251 }
1252 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_createDefaultCallParams(JNIEnv *env, jobject thiz, jlong lc){
1253         return (jlong) linphone_core_create_default_call_parameters((LinphoneCore*)lc);
1254 }
1255
1256 extern "C" jlong Java_org_linphone_core_LinphoneCallImpl_getCurrentParamsCopy(JNIEnv *env, jobject thiz, jlong lc){
1257         return (jlong) linphone_call_params_copy(linphone_call_get_current_params((LinphoneCall*)lc));
1258 }
1259
1260 extern "C" jlong Java_org_linphone_core_LinphoneCallImpl_enableCamera(JNIEnv *env, jobject thiz, jlong lc, jboolean b){
1261         linphone_call_enable_camera((LinphoneCall *)lc, (bool_t) b);
1262 }
1263
1264 extern "C" jboolean Java_org_linphone_core_LinphoneCallImpl_cameraEnabled(JNIEnv *env, jobject thiz, jlong lc){
1265         linphone_call_camera_enabled((LinphoneCall *)lc);
1266 }
1267
1268 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_inviteAddressWithParams(JNIEnv *env, jobject thiz, jlong lc, jlong addr, jlong params){
1269         return (jlong) linphone_core_invite_address_with_params((LinphoneCore *)lc, (const LinphoneAddress *)addr, (const LinphoneCallParams *)params);
1270 }
1271
1272 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_updateAddressWithParams(JNIEnv *env, jobject thiz, jlong lc, jlong call, jlong params){
1273         return (jint) linphone_core_update_call((LinphoneCore *)lc, (LinphoneCall *)call, (LinphoneCallParams *)params);
1274 }
1275
1276 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_updateCall(JNIEnv *env, jobject thiz, jlong lc, jlong call, jlong params){
1277         return (jint) linphone_core_update_call((LinphoneCore *)lc, (LinphoneCall *)call, (const LinphoneCallParams *)params);
1278 }
1279
1280
1281 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setPreferredVideoSize(JNIEnv *env, jobject thiz, jlong lc, jint width, jint height){
1282         MSVideoSize vsize;
1283         vsize.width = (int)width;
1284         vsize.height = (int)height;
1285         linphone_core_set_preferred_video_size((LinphoneCore *)lc, vsize);
1286 }
1287
1288 extern "C" jintArray Java_org_linphone_core_LinphoneCoreImpl_getPreferredVideoSize(JNIEnv *env, jobject thiz, jlong lc){
1289         MSVideoSize vsize = linphone_core_get_preferred_video_size((LinphoneCore *)lc);
1290     jintArray arr = env->NewIntArray(2);
1291         int tVsize [2]= {vsize.width,vsize.height};
1292     env->SetIntArrayRegion(arr, 0, 2, tVsize);
1293     return arr;
1294 }
1295
1296 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setDownloadBandwidth(JNIEnv *env, jobject thiz, jlong lc, jint bw){
1297         linphone_core_set_download_bandwidth((LinphoneCore *)lc, (int) bw);
1298 }
1299
1300 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setUploadBandwidth(JNIEnv *env, jobject thiz, jlong lc, jint bw){
1301         linphone_core_set_upload_bandwidth((LinphoneCore *)lc, (int) bw);
1302 }
1303
1304 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setDownloadPtime(JNIEnv *env, jobject thiz, jlong lc, jint ptime){
1305         linphone_core_set_download_ptime((LinphoneCore *)lc, (int) ptime);
1306 }
1307
1308 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setUploadPtime(JNIEnv *env, jobject thiz, jlong lc, jint ptime){
1309         linphone_core_set_upload_ptime((LinphoneCore *)lc, (int) ptime);
1310 }
1311
1312 extern "C" int Java_org_linphone_core_LinphoneProxyConfigImpl_getState(JNIEnv*  env,jobject thiz,jlong ptr) {
1313         return (int) linphone_proxy_config_get_state((const LinphoneProxyConfig *) ptr);
1314 }
1315 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setExpires(JNIEnv*  env,jobject thiz,jlong ptr,jint delay) {
1316         linphone_proxy_config_expires((LinphoneProxyConfig *) ptr, (int) delay);
1317 }
1318
1319 extern "C" jint Java_org_linphone_core_LinphoneCallImpl_getDuration(JNIEnv*  env,jobject thiz,jlong ptr) {
1320         linphone_call_get_duration((LinphoneCall *) ptr);
1321 }
1322
1323 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getSignalingTransportPort(JNIEnv* env,jobject thiz,jlong ptr, jint code) {
1324         LCSipTransports tr;
1325         linphone_core_get_sip_transports((LinphoneCore *) ptr, &tr);
1326                 switch (code) {
1327         case 0:
1328                 return tr.udp_port;
1329         case 1:
1330                 return tr.tcp_port;
1331         case 3:
1332                 return tr.tls_port;
1333         default:
1334                 return -2;
1335         }
1336 }
1337
1338 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setSignalingTransportPorts(JNIEnv*  env,jobject thiz,jlong ptr,jint udp, jint tcp, jint tls) {
1339         LinphoneCore *lc = (LinphoneCore *) ptr;
1340         LCSipTransports tr;
1341         tr.udp_port = udp;
1342         tr.tcp_port = tcp;
1343         tr.tls_port = tls;
1344
1345         linphone_core_set_sip_transports(lc, &tr); // tr will be copied
1346 }
1347
1348 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_enableIpv6(JNIEnv* env,jobject  thiz
1349               ,jlong lc, jboolean enable) {
1350               linphone_core_enable_ipv6((LinphoneCore*)lc,enable);
1351 }
1352
1353 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_adjustSoftwareVolume(JNIEnv* env,jobject  thiz
1354               ,jlong ptr, jint db) {
1355         linphone_core_set_playback_gain_db((LinphoneCore *) ptr, db);
1356 }
1357
1358 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_pauseCall(JNIEnv *env,jobject thiz,jlong pCore, jlong pCall) {
1359         return linphone_core_pause_call((LinphoneCore *) pCore, (LinphoneCall *) pCall);
1360 }
1361 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_pauseAllCalls(JNIEnv *env,jobject thiz,jlong pCore) {
1362         return linphone_core_pause_all_calls((LinphoneCore *) pCore);
1363 }
1364 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_resumeCall(JNIEnv *env,jobject thiz,jlong pCore, jlong pCall) {
1365         return linphone_core_resume_call((LinphoneCore *) pCore, (LinphoneCall *) pCall);
1366 }
1367 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isInConference(JNIEnv *env,jobject thiz,jlong pCore) {
1368         return linphone_core_is_in_conference((LinphoneCore *) pCore);
1369 }
1370 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_enterConference(JNIEnv *env,jobject thiz,jlong pCore) {
1371         linphone_core_enter_conference((LinphoneCore *) pCore);
1372 }
1373 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_leaveConference(JNIEnv *env,jobject thiz,jlong pCore) {
1374         linphone_core_leave_conference((LinphoneCore *) pCore);
1375 }
1376 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_addAllToConference(JNIEnv *env,jobject thiz,jlong pCore) {
1377         linphone_core_add_all_to_conference((LinphoneCore *) pCore);
1378 }
1379 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_addToConference(JNIEnv *env,jobject thiz,jlong pCore, jlong pCall) {
1380         linphone_core_add_to_conference((LinphoneCore *) pCore, (LinphoneCall *) pCall);
1381 }
1382 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_removeFromConference(JNIEnv *env,jobject thiz,jlong pCore, jlong pCall) {
1383         linphone_core_remove_from_conference((LinphoneCore *) pCore, (LinphoneCall *) pCall);
1384 }
1385
1386 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_terminateConference(JNIEnv *env,jobject thiz,jlong pCore) {
1387         linphone_core_terminate_conference((LinphoneCore *) pCore);
1388 }
1389 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getConferenceSize(JNIEnv *env,jobject thiz,jlong pCore) {
1390         return linphone_core_get_conference_size((LinphoneCore *) pCore);
1391 }
1392 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_terminateAllCalls(JNIEnv *env,jobject thiz,jlong pCore) {
1393         linphone_core_terminate_all_calls((LinphoneCore *) pCore);
1394 }
1395 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_getCall(JNIEnv *env,jobject thiz,jlong pCore,jint position) {
1396         return (jlong)ms_list_nth_data(linphone_core_get_calls((LinphoneCore *) pCore),position);
1397 }
1398 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getCallsNb(JNIEnv *env,jobject thiz,jlong pCore) {
1399         return ms_list_size(linphone_core_get_calls((LinphoneCore *) pCore));
1400 }
1401
1402 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_transferCall(JNIEnv *env,jobject thiz,jlong pCore, jlong pCall, jstring jReferTo) {
1403         const char* cReferTo=env->GetStringUTFChars(jReferTo, NULL);
1404         linphone_core_transfer_call((LinphoneCore *) pCore, (LinphoneCall *) pCall, cReferTo);
1405         env->ReleaseStringUTFChars(jReferTo, cReferTo);
1406 }
1407 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_transferCallToAnother(JNIEnv *env,jobject thiz,jlong pCore, jlong pCall, jlong pDestCall) {
1408         linphone_core_transfer_call_to_another((LinphoneCore *) pCore, (LinphoneCall *) pCall, (LinphoneCall *) pDestCall);
1409 }
1410
1411 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setZrtpSecretsCache(JNIEnv *env,jobject thiz,jlong pCore, jstring jFile) {
1412         if (jFile) {
1413                 const char* cFile=env->GetStringUTFChars(jFile, NULL);
1414                 linphone_core_set_zrtp_secrets_file((LinphoneCore *) pCore,cFile);
1415                 env->ReleaseStringUTFChars(jFile, cFile);
1416         } else {
1417                 linphone_core_set_zrtp_secrets_file((LinphoneCore *) pCore,NULL);
1418         }
1419 }
1420
1421 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_setVideoDevice(JNIEnv *env,jobject thiz,jlong pCore,jint id) {
1422         LinphoneCore* lc = (LinphoneCore *) pCore;
1423         const char** devices = linphone_core_get_video_devices(lc);
1424         if (devices == NULL) {
1425                 ms_error("No existing video devices\n");
1426                 return -1;
1427         }
1428         int i;
1429         for(i=0; i<=id; i++) {
1430                 if (devices[i] == NULL)
1431                         break;
1432                 ms_message("Existing device %d : %s\n", i, devices[i]);
1433                 if (i==id) {
1434                         return linphone_core_set_video_device(lc, devices[i]);
1435                 }
1436         }
1437         return -1;
1438 }
1439
1440 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getVideoDevice(JNIEnv *env,jobject thiz,jlong pCore) {
1441         LinphoneCore* lc = (LinphoneCore *) pCore;
1442         const char** devices = linphone_core_get_video_devices(lc);
1443         if (devices == NULL) {
1444                 ms_error("No existing video devices\n");
1445                 return -1;
1446         }
1447         const char* cam = linphone_core_get_video_device(lc);
1448         if (cam == NULL) {
1449                 ms_error("No current video device\n");
1450         } else {
1451                 int i=0;
1452                 while(devices[i] != NULL) {
1453                         if (strcmp(devices[i], cam) == 0)
1454                                 return i;
1455                         i++;
1456                 }
1457         }
1458         ms_warning("Returning default (0) device\n");
1459         return 0;
1460 }
1461
1462 extern "C" jstring Java_org_linphone_core_LinphoneCallImpl_getAuthenticationToken(JNIEnv*  env,jobject thiz,jlong ptr) {
1463         LinphoneCall *call = (LinphoneCall *) ptr;
1464         const char* token = linphone_call_get_authentication_token(call);
1465         if (token == NULL) return NULL;
1466         return env->NewStringUTF(token);
1467 }
1468 extern "C" jboolean Java_org_linphone_core_LinphoneCallImpl_isAuthenticationTokenVerified(JNIEnv*  env,jobject thiz,jlong ptr) {
1469         LinphoneCall *call = (LinphoneCall *) ptr;
1470         return linphone_call_get_authentication_token_verified(call);
1471 }
1472 extern "C" jboolean Java_org_linphone_core_LinphoneCallImpl_areStreamsEncrypted(JNIEnv*  env,jobject thiz,jlong ptr) {
1473         return linphone_call_are_all_streams_encrypted((LinphoneCall *) ptr);
1474 }
1475
1476 // Needed by Galaxy S (can't switch to/from speaker while playing and still keep mic working)
1477 // Implemented directly in msandroid.cpp (sound filters for Android).
1478 extern "C" void msandroid_hack_speaker_state(bool speakerOn);
1479
1480 extern "C" void Java_org_linphone_LinphoneManager_hackSpeakerState(JNIEnv*  env,jobject thiz,jboolean speakerOn){
1481         msandroid_hack_speaker_state(speakerOn);
1482 // End Galaxy S hack functions
1483 }