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